ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/Prefs_glade.h
Revision: 1.1
Committed: 2004-01-13T19:52:49Z (20 years, 2 months ago) by cebix
Content type: text/plain
Branch: MAIN
Log Message:
first attempt at Glade-based prefs editor for Unix

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * Prefs_glade.h - Global preferences, Glade/Gnome/Gtk+ specific stuff
3     *
4     * Frodo (C) 1994-1997,2002-2004 Christian Bauer
5     *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19     */
20    
21     #include <gnome.h>
22     #include <glade/glade.h>
23    
24     #include <SDL.h>
25    
26    
27     // Glade XML tree
28     static GladeXML *xml = NULL;
29    
30     // Result of ShowEditor()
31     static bool result = false;
32    
33     // Pointer to preferences being edited
34     static Prefs *prefs = NULL;
35    
36     // Prefs file name
37     static char *prefs_path = NULL;
38    
39     // Prototypes
40     static void set_values();
41     static void get_values();
42     static void ghost_widgets();
43    
44    
45     /*
46     * Show preferences editor (synchronously)
47     * prefs_name points to the file name of the preferences (which may be changed)
48     */
49    
50     bool Prefs::ShowEditor(bool startup, char *path)
51     {
52     prefs = this;
53     prefs_path = path;
54    
55     // Load XML user interface file on startup
56     if (startup) {
57     xml = glade_xml_new(DATADIR "Frodo.glade", NULL, NULL);
58     if (xml) {
59     glade_xml_signal_autoconnect(xml);
60     set_values();
61     }
62     }
63    
64     // No XML means no prefs editor
65     if (!xml)
66     return false;
67    
68     // Run editor
69     result = false;
70     gtk_main();
71     return result;
72     }
73    
74    
75     /*
76     * Set the values of the widgets
77     */
78    
79     static void create_joystick_menu(const char *widget_name)
80     {
81     GtkWidget *w = glade_xml_get_widget(xml, widget_name);
82     gtk_option_menu_remove_menu(GTK_OPTION_MENU(w));
83    
84     GtkWidget *menu = gtk_menu_new();
85    
86     for (int i = -1; i < SDL_NumJoysticks(); ++i) {
87     GtkWidget *item = gtk_menu_item_new_with_label(i < 0 ? "None" : SDL_JoystickName(i));
88     gtk_widget_show(item);
89     gtk_menu_append(GTK_MENU(menu), item);
90     }
91    
92     gtk_option_menu_set_menu(GTK_OPTION_MENU(w), menu);
93     }
94    
95     static void set_values()
96     {
97     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "emul1541_proc")), prefs->Emul1541Proc);
98     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "map_slash")), prefs->MapSlash);
99    
100     gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "drive8_type")), prefs->DriveType[0]);
101     gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "drive9_type")), prefs->DriveType[1]);
102     gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "drive10_type")), prefs->DriveType[2]);
103     gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "drive11_type")), prefs->DriveType[3]);
104    
105     gtk_entry_set_text(GTK_ENTRY(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(glade_xml_get_widget(xml, "drive8_path")))), prefs->DrivePath[0]);
106     gtk_entry_set_text(GTK_ENTRY(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(glade_xml_get_widget(xml, "drive9_path")))), prefs->DrivePath[1]);
107     gtk_entry_set_text(GTK_ENTRY(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(glade_xml_get_widget(xml, "drive10_path")))), prefs->DrivePath[2]);
108     gtk_entry_set_text(GTK_ENTRY(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(glade_xml_get_widget(xml, "drive11_path")))), prefs->DrivePath[3]);
109    
110     gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "display_type")), prefs->DisplayType);
111     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sprites_on")), prefs->SpritesOn);
112     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sprite_collisions")), prefs->SpriteCollisions);
113    
114     gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "sid_type")), prefs->SIDType);
115     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sid_filters")), prefs->SIDFilters);
116    
117     create_joystick_menu("joystick1_port");
118     create_joystick_menu("joystick2_port");
119    
120     gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "joystick1_port")), prefs->Joystick1Port);
121     gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "joystick2_port")), prefs->Joystick2Port);
122     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "joystick_swap")), prefs->JoystickSwap);
123    
124     gtk_spin_button_set_value(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "skip_frames")), prefs->SkipFrames);
125     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "limit_speed")), prefs->LimitSpeed);
126     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "fast_reset")), prefs->FastReset);
127    
128     gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "reu_size")), prefs->REUSize);
129    
130     gtk_spin_button_set_value(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "normal_cycles")), prefs->NormalCycles);
131     gtk_spin_button_set_value(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "bad_line_cycles")), prefs->BadLineCycles);
132     gtk_spin_button_set_value(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "cia_cycles")), prefs->CIACycles);
133     gtk_spin_button_set_value(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "floppy_cycles")), prefs->FloppyCycles);
134    
135     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "cia_irq_hack")), prefs->CIAIRQHack);
136    
137     ghost_widgets();
138     }
139    
140    
141     /*
142     * Get the values of the widgets
143     */
144    
145     static void get_drive_path(int num, const char *widget_name)
146     {
147     prefs->DrivePath[num][0] = 0;
148     const char *path = gnome_file_entry_get_full_path(GNOME_FILE_ENTRY(glade_xml_get_widget(xml, widget_name)), false);
149     if (path)
150     strncpy(prefs->DrivePath[num], path, 255);
151     prefs->DrivePath[num][255] = 0;
152     }
153    
154     static void get_values()
155     {
156     prefs->Emul1541Proc = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "emul1541_proc")));
157     prefs->MapSlash = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "map_slash")));
158    
159     prefs->DriveType[0] = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "drive8_type")));
160     prefs->DriveType[1] = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "drive9_type")));
161     prefs->DriveType[2] = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "drive10_type")));
162     prefs->DriveType[3] = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "drive11_type")));
163    
164     get_drive_path(0, "drive8_path");
165     get_drive_path(1, "drive9_path");
166     get_drive_path(2, "drive10_path");
167     get_drive_path(3, "drive11_path");
168    
169     prefs->DisplayType = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "display_type")));
170     prefs->SpritesOn = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sprites_on")));
171     prefs->SpriteCollisions = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sprite_collisions")));
172    
173     prefs->SIDType = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "sid_type")));
174     prefs->SIDFilters = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sid_filters")));
175    
176     prefs->Joystick1Port = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "joystick1_port")));
177     prefs->Joystick2Port = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "joystick2_port")));
178     prefs->JoystickSwap = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "joystick_swap")));
179    
180     prefs->SkipFrames = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "skip_frames")));
181     prefs->LimitSpeed = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "limit_speed")));
182     prefs->FastReset = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "fast_reset")));
183    
184     prefs->REUSize = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "reu_size")));
185    
186     prefs->NormalCycles = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "normal_cycles")));
187     prefs->BadLineCycles = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "bad_line_cycles")));
188     prefs->CIACycles = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "cia_cycles")));
189     prefs->FloppyCycles = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "floppy_cycles")));
190    
191     prefs->CIAIRQHack = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "cia_irq_hack")));
192     }
193    
194    
195     /*
196     * Ghost/unghost widgets
197     */
198    
199     static void ghost_widget(const char *name, bool ghosted)
200     {
201     gtk_widget_set_sensitive(glade_xml_get_widget(xml, name), !ghosted);
202     }
203    
204     static void ghost_widgets()
205     {
206     ghost_widget("drive9_type", prefs->Emul1541Proc);
207     ghost_widget("drive10_type", prefs->Emul1541Proc);
208     ghost_widget("drive11_type", prefs->Emul1541Proc);
209     ghost_widget("drive9_path", prefs->Emul1541Proc);
210     ghost_widget("drive10_path", prefs->Emul1541Proc);
211     ghost_widget("drive11_path", prefs->Emul1541Proc);
212    
213     ghost_widget("sid_filters", prefs->SIDType != SIDTYPE_DIGITAL);
214     }
215    
216    
217     /*
218     * Signal handlers
219     */
220    
221     extern "C" gboolean on_prefs_win_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
222     {
223     return false;
224     }
225    
226     extern "C" void on_ok_clicked(GtkButton *button, gpointer user_data)
227     {
228     result = true;
229     get_values();
230     prefs->Save(prefs_path);
231     gtk_main_quit();
232     }
233    
234     extern "C" void on_quit_clicked(GtkButton *button, gpointer user_data)
235     {
236     result = false;
237     gtk_main_quit();
238     }
239    
240     extern "C" void on_about_activate(GtkMenuItem *menuitem, gpointer user_data)
241     {
242     gtk_widget_show(glade_xml_get_widget(xml, "about_win"));
243     }
244    
245     extern "C" void on_emul1541_proc_toggled(GtkToggleButton *button, gpointer user_data)
246     {
247     prefs->Emul1541Proc = gtk_toggle_button_get_active(button);
248     ghost_widgets();
249     }
250    
251     extern "C" void on_sid_type_activate(GtkMenuItem *menuitem, gpointer user_data)
252     {
253     prefs->SIDType = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "sid_type")));
254     ghost_widgets();
255     }