2 * $Id: gtkcb.c,v 1.5 2007-10-21 05:21:35 nkeynes Exp $
4 * Action callbacks from the main window
6 * Copyright (c) 2005 Nathan Keynes.
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.
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.
21 #include "dreamcast.h"
22 #include "gdrom/gdrom.h"
23 #include "gui/gtkui.h"
24 #include "pvr2/pvr2.h"
26 typedef gboolean (*file_callback_t)( const gchar *filename );
28 static gboolean dreamcast_paused = FALSE;
30 void dreamcast_pause()
32 if( dreamcast_is_running() ) {
33 dreamcast_paused = TRUE;
38 void dreamcast_unpause()
40 if( dreamcast_paused ) {
41 dreamcast_paused = FALSE;
42 if( !dreamcast_is_running() ) {
49 void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
50 GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
51 if( result == GTK_RESPONSE_ACCEPT ) {
52 gchar *filename =gtk_file_chooser_get_filename(
53 GTK_FILE_CHOOSER(file) );
54 file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
55 gtk_widget_destroy(GTK_WIDGET(file));
59 gtk_widget_destroy(GTK_WIDGET(file));
64 static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
66 if( pattern != NULL ) {
67 GtkFileFilter *filter = gtk_file_filter_new();
68 gtk_file_filter_add_pattern( filter, pattern );
69 gtk_file_filter_set_name( filter, patname );
70 gtk_file_chooser_add_filter( chooser, filter );
71 filter = gtk_file_filter_new();
72 gtk_file_filter_set_name( filter, "All files" );
73 gtk_file_filter_add_pattern( filter, "*" );
74 gtk_file_chooser_add_filter( chooser, filter );
78 void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
79 gchar const *initial_dir )
83 file = gtk_file_chooser_dialog_new( title, NULL,
84 GTK_FILE_CHOOSER_ACTION_OPEN,
85 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
86 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
88 add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
89 g_signal_connect( GTK_OBJECT(file), "response",
90 GTK_SIGNAL_FUNC(open_file_callback), file );
91 gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
92 gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
93 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
94 gtk_widget_show( file );
97 void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
98 gchar const *initial_dir )
102 file = gtk_file_chooser_dialog_new( title, NULL,
103 GTK_FILE_CHOOSER_ACTION_SAVE,
104 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
105 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
107 add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
108 g_signal_connect( GTK_OBJECT(file), "response",
109 GTK_SIGNAL_FUNC(open_file_callback), file );
110 gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
111 gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
112 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
113 gtk_widget_show( file );
116 void mount_action_callback( GtkAction *action, gpointer user_data)
118 const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
119 open_file_dialog( "Open...", gdrom_mount_image, NULL, NULL, dir );
121 void reset_action_callback( GtkAction *action, gpointer user_data)
126 void pause_action_callback( GtkAction *action, gpointer user_data)
131 void resume_action_callback( GtkAction *action, gpointer user_data)
136 void load_state_action_callback( GtkAction *action, gpointer user_data)
138 const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
139 open_file_dialog( "Load state...", dreamcast_load_state, "*.dst", "lxDream Save State (*.dst)", dir );
141 void save_state_action_callback( GtkAction *action, gpointer user_data)
143 const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
144 save_file_dialog( "Save state...", dreamcast_save_state, "*.dst", "lxDream Save State (*.dst)", dir );
146 void about_action_callback( GtkAction *action, gpointer user_data)
149 GtkWidget *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
151 "version", APP_VERSION,
152 "copyright", "(C) 2003-2007 Nathan Keynes",
154 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
155 gtk_dialog_run(GTK_DIALOG(dialog));
156 gtk_widget_destroy(dialog);
160 void exit_action_callback( GtkAction *action, gpointer user_data)
165 void path_settings_callback( GtkAction *action, gpointer user_data)
170 void audio_settings_callback( GtkAction *action, gpointer user_data)
174 void maple_settings_callback( GtkAction *action, gpointer user_data)
179 void network_settings_callback( GtkAction *action, gpointer user_data)
183 void video_settings_callback( GtkAction *action, gpointer user_data)
187 void fullscreen_toggle_callback( GtkToggleAction *action, gpointer user_data)
191 void debugger_action_callback( GtkAction *action, gpointer user_data)
193 gtk_gui_show_debugger();
196 void debug_memory_action_callback( GtkAction *action, gpointer user_data)
198 dump_window_new( APP_NAME " " APP_VERSION " :: Memory dump" );
201 void debug_mmio_action_callback( GtkAction *action, gpointer user_data)
206 void save_scene_action_callback( GtkAction *action, gpointer user_data)
208 const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
209 save_file_dialog( "Save next scene...", pvr2_save_next_scene, "*.dsc", "lxdream scene file (*.dsc)", dir );
212 void debug_step_action_callback( GtkAction *action, gpointer user_data)
214 debug_window_single_step(gtk_gui_get_debugger());
217 void debug_runto_action_callback( GtkAction *action, gpointer user_data)
219 debug_window_t debug = gtk_gui_get_debugger();
220 int selected_row = debug_window_get_selected_row(debug);
221 if( selected_row == -1 ) {
222 WARN( "No address selected, so can't run to it", NULL );
224 debug_window_set_oneshot_breakpoint( debug, selected_row );
229 void debug_breakpoint_action_callback( GtkAction *action, gpointer user_data)
231 debug_window_t debug = gtk_gui_get_debugger();
232 int selected_row = debug_window_get_selected_row(debug);
233 if( selected_row != -1 ) {
234 debug_window_toggle_breakpoint( debug, selected_row );
.