filename | src/gui/gtkcb.c |
changeset | 450:207461e79f21 |
prev | 447:3e095bfcb476 |
next | 455:3080881d00d4 |
author | nkeynes |
date | Wed Oct 17 11:26:45 2007 +0000 (16 years ago) |
permissions | -rw-r--r-- |
last change | Split config management out to config.[ch] Manage config filename Check home dir + sysconfdir for conf file Initial work on a path settings dialog |
view | annotate | diff | log | raw |
1 /**
2 * $Id: gtkcb.c,v 1.4 2007-10-17 11:26:45 nkeynes Exp $
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 "gui/gtkui.h"
25 typedef gboolean (*file_callback_t)( const gchar *filename );
27 static gboolean dreamcast_paused = FALSE;
29 void dreamcast_pause()
30 {
31 if( dreamcast_is_running() ) {
32 dreamcast_paused = TRUE;
33 dreamcast_stop();
34 }
35 }
37 void dreamcast_unpause()
38 {
39 if( dreamcast_paused ) {
40 dreamcast_paused = FALSE;
41 if( !dreamcast_is_running() ) {
42 dreamcast_run();
43 }
44 }
45 }
48 void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
49 GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
50 if( result == GTK_RESPONSE_ACCEPT ) {
51 gchar *filename =gtk_file_chooser_get_filename(
52 GTK_FILE_CHOOSER(file) );
53 file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
54 gtk_widget_destroy(GTK_WIDGET(file));
55 action( filename );
56 g_free(filename);
57 } else {
58 gtk_widget_destroy(GTK_WIDGET(file));
59 }
60 dreamcast_unpause();
61 }
63 static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
64 {
65 if( pattern != NULL ) {
66 GtkFileFilter *filter = gtk_file_filter_new();
67 gtk_file_filter_add_pattern( filter, pattern );
68 gtk_file_filter_set_name( filter, patname );
69 gtk_file_chooser_add_filter( chooser, filter );
70 filter = gtk_file_filter_new();
71 gtk_file_filter_set_name( filter, "All files" );
72 gtk_file_filter_add_pattern( filter, "*" );
73 gtk_file_chooser_add_filter( chooser, filter );
74 }
75 }
77 void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
78 gchar const *initial_dir )
79 {
80 GtkWidget *file;
81 dreamcast_pause();
82 file = gtk_file_chooser_dialog_new( title, NULL,
83 GTK_FILE_CHOOSER_ACTION_OPEN,
84 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
85 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
86 NULL );
87 add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
88 g_signal_connect( GTK_OBJECT(file), "response",
89 GTK_SIGNAL_FUNC(open_file_callback), file );
90 gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
91 gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
92 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
93 gtk_widget_show( file );
94 }
96 void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
97 gchar const *initial_dir )
98 {
99 GtkWidget *file;
100 dreamcast_pause();
101 file = gtk_file_chooser_dialog_new( title, NULL,
102 GTK_FILE_CHOOSER_ACTION_SAVE,
103 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
104 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
105 NULL );
106 add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
107 g_signal_connect( GTK_OBJECT(file), "response",
108 GTK_SIGNAL_FUNC(open_file_callback), file );
109 gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
110 gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
111 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
112 gtk_widget_show( file );
113 }
115 void mount_action_callback( GtkAction *action, gpointer user_data)
116 {
117 const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
118 open_file_dialog( "Open...", gdrom_mount_image, NULL, NULL, dir );
119 }
120 void reset_action_callback( GtkAction *action, gpointer user_data)
121 {
122 dreamcast_reset();
123 }
125 void pause_action_callback( GtkAction *action, gpointer user_data)
126 {
127 dreamcast_stop();
128 }
130 void resume_action_callback( GtkAction *action, gpointer user_data)
131 {
132 dreamcast_run();
133 }
135 void load_state_action_callback( GtkAction *action, gpointer user_data)
136 {
137 const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
138 open_file_dialog( "Load state...", dreamcast_load_state, "*.dst", "lxDream Save State (*.dst)", dir );
139 }
140 void save_state_action_callback( GtkAction *action, gpointer user_data)
141 {
142 const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
143 save_file_dialog( "Save state...", dreamcast_save_state, "*.dst", "lxDream Save State (*.dst)", dir );
144 }
145 void about_action_callback( GtkAction *action, gpointer user_data)
146 {
148 GtkWidget *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
149 "name", APP_NAME,
150 "version", APP_VERSION,
151 "copyright", "(C) 2003-2007 Nathan Keynes",
152 NULL);
153 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
154 gtk_dialog_run(GTK_DIALOG(dialog));
155 gtk_widget_destroy(dialog);
157 }
159 void exit_action_callback( GtkAction *action, gpointer user_data)
160 {
161 exit(0);
162 }
164 void debugger_action_callback( GtkAction *action, gpointer user_data)
165 {
166 gtk_gui_show_debugger();
167 }
169 void path_settings_callback( GtkAction *action, gpointer user_data)
170 {
171 path_dialog_run();
172 }
174 void audio_settings_callback( GtkAction *action, gpointer user_data)
175 {
176 }
178 void controller_settings_callback( GtkAction *action, gpointer user_data)
179 {
180 controller_dialog_run( );
181 }
183 void network_settings_callback( GtkAction *action, gpointer user_data)
184 {
185 }
187 void video_settings_callback( GtkAction *action, gpointer user_data)
188 {
189 }
191 void fullscreen_toggle_callback( GtkToggleAction *action, gpointer user_data)
192 {
193 }
.