Search
lxdream.org :: lxdream/src/gtkui/gtkcb.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtkcb.c
changeset 1036:af7b0c5905dd
prev1034:7044e01148f0
next1040:9e3e41eab2db
author nkeynes
date Wed Jun 24 06:06:40 2009 +0000 (12 years ago)
permissions -rw-r--r--
last change Support shell substitutions in config paths
Keep track of last folder in file dialogs
Fix out-of-dateness in GTK path dialog
view annotate diff log raw
     1 /**
     2  * $Id$
     3  *
     4  * Action callbacks from the main window
     5  *
     6  * Copyright (c) 2005 Nathan Keynes.
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  */
    19 #include "dream.h"
    20 #include "config.h"
    21 #include "dreamcast.h"
    22 #include "gdrom/gdrom.h"
    23 #include "gtkui/gtkui.h"
    24 #include "pvr2/pvr2.h"
    25 #include "loader.h"
    28 static void add_file_pattern( GtkFileChooser *chooser, const char *pattern, const char *patname )
    29 {
    30     if( pattern != NULL ) {
    31         GtkFileFilter *filter = gtk_file_filter_new();
    32         gtk_file_filter_add_pattern( filter, pattern );
    33         gtk_file_filter_set_name( filter, patname );
    34         gtk_file_chooser_add_filter( chooser, filter );
    35         filter = gtk_file_filter_new();
    36         gtk_file_filter_set_name( filter, _("All files") );
    37         gtk_file_filter_add_pattern( filter, "*" );
    38         gtk_file_chooser_add_filter( chooser, filter );
    39     }
    40 }
    42 gchar *open_file_dialog( const char *title, const char *pattern, const char *patname,
    43                          int initial_dir_key )
    44 {
    45     GtkWidget *file;
    46     gchar *filename = NULL;
    48     file = gtk_file_chooser_dialog_new( title, NULL,
    49             GTK_FILE_CHOOSER_ACTION_OPEN,
    50             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    51             GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
    52             NULL );
    53     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
    54     if( initial_dir_key != -1 ) {
    55         gchar *initial_path = get_absolute_path(gui_get_configurable_path(initial_dir_key));
    56         gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
    57         g_free(initial_path);
    58     }
    59     gtk_window_set_modal( GTK_WINDOW(file), TRUE );
    60     gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
    61     int result = gtk_dialog_run( GTK_DIALOG(file) );
    62     if( result == GTK_RESPONSE_ACCEPT ) {
    63         filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
    64         if( initial_dir_key != -1 ) {
    65             gchar *end_path = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER(file) );
    66             gui_set_configurable_path(initial_dir_key,end_path);
    67             g_free(end_path);
    68         }
    69     }
    70     gtk_widget_destroy(file);
    72     return filename;
    73 }
    75 gchar *save_file_dialog( const char *title, const char *pattern, const char *patname,
    76                          int initial_dir_key )
    77 {
    78     GtkWidget *file;
    79     gchar *filename;
    81     file = gtk_file_chooser_dialog_new( title, NULL,
    82             GTK_FILE_CHOOSER_ACTION_SAVE,
    83             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    84             GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
    85             NULL );
    86     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
    87     if( initial_dir_key != -1 ) {
    88         gchar *initial_path = get_absolute_path(gui_get_configurable_path(initial_dir_key));
    89         gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
    90         g_free(initial_path);
    91     }
    92     gtk_window_set_modal( GTK_WINDOW(file), TRUE );
    93     gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
    94     int result = gtk_dialog_run( GTK_DIALOG(file) );
    95     if( result == GTK_RESPONSE_ACCEPT ) {
    96         filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
    97         if( initial_dir_key != -1 ) {
    98             gchar *end_path = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER(file) );
    99             gui_set_configurable_path(initial_dir_key,end_path);
   100             g_free(end_path);
   101         }
   102     }
   103     gtk_widget_destroy(file);
   104     return filename;
   105 }
   107 void open_file_dialog_cb( const char *title, file_callback_t action, const char *pattern, const char *patname,
   108                           int initial_dir_key )
   109 {
   110     gchar *filename = open_file_dialog( title, pattern, patname, initial_dir_key ); 
   111     if( filename != NULL ) {
   112         action( filename );
   113         g_free(filename);
   114     }
   115 }
   117 void save_file_dialog_cb( const char *title, file_callback_t action, const char *pattern, const char *patname,
   118                           int initial_dir_key )
   119 {
   120     gchar *filename = save_file_dialog( title, pattern, patname, initial_dir_key );
   121     if( filename != NULL ) {
   122         action(filename);
   123         g_free(filename);
   124     }
   125 }
   127 void mount_action_callback( GtkAction *action, gpointer user_data)
   128 {
   129     open_file_dialog_cb( "Open...", gdrom_mount_image, NULL, NULL, CONFIG_DEFAULT_PATH );
   130 }
   131 void reset_action_callback( GtkAction *action, gpointer user_data)
   132 {
   133     dreamcast_reset();
   134 }
   136 void pause_action_callback( GtkAction *action, gpointer user_data)
   137 {
   138     dreamcast_stop();
   139 }
   141 void resume_action_callback( GtkAction *action, gpointer user_data)
   142 {
   143     dreamcast_run();
   144 }
   146 void load_binary_action_callback( GtkAction *action, gpointer user_data)
   147 {
   148     open_file_dialog_cb( "Open Binary...", file_load_magic, NULL, NULL, CONFIG_DEFAULT_PATH );
   149 }
   151 void load_state_preview_callback( GtkFileChooser *chooser, gpointer user_data )
   152 {
   153     GtkWidget *preview = GTK_WIDGET(user_data);
   154     gchar *filename = gtk_file_chooser_get_preview_filename(chooser);
   156     frame_buffer_t data = dreamcast_load_preview(filename);
   157     if( data != NULL ) {
   158         GdkPixbuf *pixbuf = gdk_pixbuf_new_from_frame_buffer(data);
   159         GdkPixbuf *scaled = gdk_pixbuf_scale_simple(pixbuf, 320, 240,
   160                 GDK_INTERP_BILINEAR);
   161         g_object_unref(pixbuf);
   162         gtk_image_set_from_pixbuf( GTK_IMAGE(preview), scaled );
   163         g_object_unref(scaled);
   164         gtk_widget_show(preview);
   165     } else {
   166         gtk_widget_hide(preview);
   167     }
   168 }
   170 void load_state_action_callback( GtkAction *action, gpointer user_data)
   171 {
   172     GtkWidget *file, *preview, *frame, *align;
   173     GtkRequisition size;
   174     const gchar *dir = gui_get_configurable_path(CONFIG_SAVE_PATH);
   175     gchar *path = get_absolute_path(dir);
   176     file = gtk_file_chooser_dialog_new( _("Load state..."), NULL,
   177             GTK_FILE_CHOOSER_ACTION_OPEN,
   178             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
   179             GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
   180             NULL );
   181     add_file_pattern( GTK_FILE_CHOOSER(file), "*.dst", _("lxDream Save State (*.dst)") );
   182     gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
   184     preview = gtk_image_new( );
   186     frame = gtk_frame_new(NULL);
   187     gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
   188     gtk_container_add( GTK_CONTAINER(frame), preview );
   189     gtk_widget_show(frame);
   190     gtk_widget_size_request(frame, &size);
   191     gtk_widget_set_size_request(frame, size.width + 320, size.height + 240);
   192     align = gtk_alignment_new(0.5, 0.5, 0, 0 );
   193     gtk_container_add( GTK_CONTAINER(align), frame );
   194     gtk_widget_show( align );
   195     gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(file), align);
   196     g_signal_connect( file, "update-preview", G_CALLBACK(load_state_preview_callback),
   197                       preview );
   198     gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), path );
   199     gtk_window_set_modal( GTK_WINDOW(file), TRUE );
   200     int result = gtk_dialog_run( GTK_DIALOG(file) );
   201     if( result == GTK_RESPONSE_ACCEPT ) {
   202         gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
   203         gchar *end_path = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER(file) );
   204         gui_set_configurable_path(CONFIG_SAVE_PATH,end_path);
   205         g_free(end_path);
   206         dreamcast_load_state( filename );
   207     }
   208     gtk_widget_destroy(file);
   209     g_free(path);
   210 }
   212 void save_state_action_callback( GtkAction *action, gpointer user_data)
   213 {
   214     save_file_dialog_cb( "Save state...", dreamcast_save_state, "*.dst", _("lxDream Save State (*.dst)"), CONFIG_SAVE_PATH );
   215 }
   216 void about_action_callback( GtkAction *action, gpointer user_data)
   217 {
   219     GtkWidget *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
   220             "name", APP_NAME, 
   221             "version", lxdream_full_version,
   222             "copyright", lxdream_copyright,
   223             "logo-icon-name", "lxdream",
   224             NULL);
   225     gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
   226     gtk_dialog_run(GTK_DIALOG(dialog));
   227     gtk_widget_destroy(dialog);
   229 }
   231 void exit_action_callback( GtkAction *action, gpointer user_data)
   232 {
   233     dreamcast_shutdown();
   234     exit(0);
   235 }
   237 void path_settings_callback( GtkAction *action, gpointer user_data)
   238 {
   239     path_dialog_run();
   240 }
   242 void audio_settings_callback( GtkAction *action, gpointer user_data)
   243 {
   244 }
   246 void maple_settings_callback( GtkAction *action, gpointer user_data)
   247 {
   248     maple_dialog_run( );
   249 }
   251 void network_settings_callback( GtkAction *action, gpointer user_data)
   252 {
   253 }
   255 void video_settings_callback( GtkAction *action, gpointer user_data)
   256 {
   257 }
   259 void hotkey_settings_callback( GtkAction *action, gpointer user_data)
   260 {
   261     hotkeys_dialog_run();
   262 }
   264 void fullscreen_toggle_callback( GtkToggleAction *action, gpointer user_data)
   265 {
   266     main_window_set_fullscreen(gtk_gui_get_main(), gtk_toggle_action_get_active(action));
   267 }
   269 void debugger_action_callback( GtkAction *action, gpointer user_data)
   270 {
   271     gtk_gui_show_debugger();
   272 }
   274 void debug_memory_action_callback( GtkAction *action, gpointer user_data)
   275 {
   276     gchar *title = g_strdup_printf( "%s :: %s", lxdream_package_name, _("Memory dump") );
   277     dump_window_new( title );
   278     g_free(title);
   279 }
   281 void debug_mmio_action_callback( GtkAction *action, gpointer user_data)
   282 {
   283     gtk_gui_show_mmio();
   284 }
   286 void save_scene_action_callback( GtkAction *action, gpointer user_data)
   287 {
   288     save_file_dialog_cb( _("Save next scene..."), pvr2_save_next_scene, "*.dsc", _("lxdream scene file (*.dsc)"), CONFIG_SAVE_PATH );
   289 }
   291 int debug_window_get_selected_row( debug_window_t data );
   293 void debug_step_action_callback( GtkAction *action, gpointer user_data)
   294 {
   295     debug_window_single_step(gtk_gui_get_debugger());
   296 }
   298 void debug_runto_action_callback( GtkAction *action, gpointer user_data)
   299 {
   300     debug_window_t debug = gtk_gui_get_debugger();
   301     int selected_row = debug_window_get_selected_row(debug);
   302     if( selected_row == -1 ) {
   303         WARN( _("No address selected, so can't run to it"), NULL );
   304     } else {
   305         debug_window_set_oneshot_breakpoint( debug, selected_row );
   306         dreamcast_run();
   307     }
   308 }
   310 void debug_breakpoint_action_callback( GtkAction *action, gpointer user_data)
   311 {
   312     debug_window_t debug = gtk_gui_get_debugger();
   313     int selected_row = debug_window_get_selected_row(debug);
   314     if( selected_row != -1 ) {
   315         debug_window_toggle_breakpoint( debug, selected_row );
   316     }
   317 }
.