1 |
cebix |
1.1 |
/* |
2 |
|
|
* prefs_editor_gtk.cpp - Preferences editor, Unix implementation using GTK+ |
3 |
|
|
* |
4 |
|
|
* Basilisk II (C) 1997-1999 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 "sysdeps.h" |
22 |
|
|
|
23 |
|
|
#include <gtk/gtk.h> |
24 |
|
|
#include <stdlib.h> |
25 |
|
|
#include <dirent.h> |
26 |
|
|
#include <sys/socket.h> |
27 |
|
|
#include <sys/ioctl.h> |
28 |
|
|
#include <net/if.h> |
29 |
|
|
#include <net/if_arp.h> |
30 |
|
|
|
31 |
|
|
#include "user_strings.h" |
32 |
|
|
#include "version.h" |
33 |
|
|
#include "cdrom.h" |
34 |
|
|
#include "xpram.h" |
35 |
|
|
#include "prefs.h" |
36 |
|
|
#include "prefs_editor.h" |
37 |
|
|
|
38 |
|
|
|
39 |
|
|
// Global variables |
40 |
|
|
static GtkWidget *win; // Preferences window |
41 |
|
|
static bool start_clicked = true; // Return value of PrefsEditor() function |
42 |
|
|
|
43 |
|
|
|
44 |
|
|
// Prototypes |
45 |
|
|
static void create_volumes_pane(GtkWidget *top); |
46 |
|
|
static void create_scsi_pane(GtkWidget *top); |
47 |
|
|
static void create_graphics_pane(GtkWidget *top); |
48 |
|
|
static void create_serial_pane(GtkWidget *top); |
49 |
|
|
static void create_memory_pane(GtkWidget *top); |
50 |
|
|
static void read_settings(void); |
51 |
|
|
|
52 |
|
|
|
53 |
|
|
/* |
54 |
|
|
* Utility functions |
55 |
|
|
*/ |
56 |
|
|
|
57 |
|
|
struct opt_desc { |
58 |
|
|
int label_id; |
59 |
|
|
GtkSignalFunc func; |
60 |
|
|
}; |
61 |
|
|
|
62 |
|
|
static void add_menu_item(GtkWidget *menu, int label_id, GtkSignalFunc func) |
63 |
|
|
{ |
64 |
|
|
GtkWidget *item = gtk_menu_item_new_with_label(GetString(label_id)); |
65 |
|
|
gtk_widget_show(item); |
66 |
|
|
gtk_signal_connect(GTK_OBJECT(item), "activate", func, NULL); |
67 |
|
|
gtk_menu_append(GTK_MENU(menu), item); |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
static GtkWidget *make_pane(GtkWidget *notebook, int title_id) |
71 |
|
|
{ |
72 |
|
|
GtkWidget *frame, *label, *box; |
73 |
|
|
|
74 |
|
|
frame = gtk_frame_new(NULL); |
75 |
|
|
gtk_widget_show(frame); |
76 |
|
|
gtk_container_border_width(GTK_CONTAINER(frame), 4); |
77 |
|
|
|
78 |
|
|
label = gtk_label_new(GetString(title_id)); |
79 |
|
|
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, label); |
80 |
|
|
|
81 |
|
|
box = gtk_vbox_new(FALSE, 4); |
82 |
|
|
gtk_widget_show(box); |
83 |
|
|
gtk_container_set_border_width(GTK_CONTAINER(box), 4); |
84 |
|
|
gtk_container_add(GTK_CONTAINER(frame), box); |
85 |
|
|
return box; |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
static GtkWidget *make_button_box(GtkWidget *top, int border, const opt_desc *buttons) |
89 |
|
|
{ |
90 |
|
|
GtkWidget *bb, *button; |
91 |
|
|
|
92 |
|
|
bb = gtk_hbutton_box_new(); |
93 |
|
|
gtk_widget_show(bb); |
94 |
|
|
gtk_container_set_border_width(GTK_CONTAINER(bb), border); |
95 |
|
|
gtk_button_box_set_layout(GTK_BUTTON_BOX(bb), GTK_BUTTONBOX_DEFAULT_STYLE); |
96 |
|
|
gtk_button_box_set_spacing(GTK_BUTTON_BOX(bb), 4); |
97 |
|
|
gtk_box_pack_start(GTK_BOX(top), bb, FALSE, FALSE, 0); |
98 |
|
|
|
99 |
|
|
while (buttons->label_id) { |
100 |
|
|
button = gtk_button_new_with_label(GetString(buttons->label_id)); |
101 |
|
|
gtk_widget_show(button); |
102 |
|
|
gtk_signal_connect_object(GTK_OBJECT(button), "clicked", buttons->func, NULL); |
103 |
|
|
gtk_box_pack_start(GTK_BOX(bb), button, TRUE, TRUE, 0); |
104 |
|
|
buttons++; |
105 |
|
|
} |
106 |
|
|
return bb; |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
static GtkWidget *make_separator(GtkWidget *top) |
110 |
|
|
{ |
111 |
|
|
GtkWidget *sep = gtk_hseparator_new(); |
112 |
|
|
gtk_box_pack_start(GTK_BOX(top), sep, FALSE, FALSE, 0); |
113 |
|
|
gtk_widget_show(sep); |
114 |
|
|
return sep; |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
static GtkWidget *make_table(GtkWidget *top, int x, int y) |
118 |
|
|
{ |
119 |
|
|
GtkWidget *table = gtk_table_new(x, y, FALSE); |
120 |
|
|
gtk_widget_show(table); |
121 |
|
|
gtk_box_pack_start(GTK_BOX(top), table, FALSE, FALSE, 0); |
122 |
|
|
return table; |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
static GtkWidget *make_option_menu(GtkWidget *top, int label_id, const opt_desc *options, int active) |
126 |
|
|
{ |
127 |
|
|
GtkWidget *box, *label, *opt, *menu; |
128 |
|
|
|
129 |
|
|
box = gtk_hbox_new(FALSE, 4); |
130 |
|
|
gtk_widget_show(box); |
131 |
|
|
gtk_box_pack_start(GTK_BOX(top), box, FALSE, FALSE, 0); |
132 |
|
|
|
133 |
|
|
label = gtk_label_new(GetString(label_id)); |
134 |
|
|
gtk_widget_show(label); |
135 |
|
|
gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0); |
136 |
|
|
|
137 |
|
|
opt = gtk_option_menu_new(); |
138 |
|
|
gtk_widget_show(opt); |
139 |
|
|
menu = gtk_menu_new(); |
140 |
|
|
|
141 |
|
|
while (options->label_id) { |
142 |
|
|
add_menu_item(menu, options->label_id, options->func); |
143 |
|
|
options++; |
144 |
|
|
} |
145 |
|
|
gtk_menu_set_active(GTK_MENU(menu), active); |
146 |
|
|
|
147 |
|
|
gtk_option_menu_set_menu(GTK_OPTION_MENU(opt), menu); |
148 |
|
|
gtk_box_pack_start(GTK_BOX(box), opt, FALSE, FALSE, 0); |
149 |
|
|
return menu; |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
static GtkWidget *make_entry(GtkWidget *top, int label_id, const char *prefs_item) |
153 |
|
|
{ |
154 |
|
|
GtkWidget *box, *label, *entry; |
155 |
|
|
|
156 |
|
|
box = gtk_hbox_new(FALSE, 4); |
157 |
|
|
gtk_widget_show(box); |
158 |
|
|
gtk_box_pack_start(GTK_BOX(top), box, FALSE, FALSE, 0); |
159 |
|
|
|
160 |
|
|
label = gtk_label_new(GetString(label_id)); |
161 |
|
|
gtk_widget_show(label); |
162 |
|
|
gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0); |
163 |
|
|
|
164 |
|
|
entry = gtk_entry_new(); |
165 |
|
|
gtk_widget_show(entry); |
166 |
|
|
const char *str = PrefsFindString(prefs_item); |
167 |
|
|
if (str == NULL) |
168 |
|
|
str = ""; |
169 |
|
|
gtk_entry_set_text(GTK_ENTRY(entry), str); |
170 |
|
|
gtk_box_pack_start(GTK_BOX(box), entry, TRUE, TRUE, 0); |
171 |
|
|
return entry; |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
static GtkWidget *make_checkbox(GtkWidget *top, int label_id, const char *prefs_item, GtkSignalFunc func) |
175 |
|
|
{ |
176 |
|
|
GtkWidget *button = gtk_check_button_new_with_label(GetString(label_id)); |
177 |
|
|
gtk_widget_show(button); |
178 |
|
|
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), PrefsFindBool(prefs_item)); |
179 |
|
|
gtk_signal_connect(GTK_OBJECT(button), "toggled", func, button); |
180 |
|
|
gtk_box_pack_start(GTK_BOX(top), button, FALSE, FALSE, 0); |
181 |
|
|
return button; |
182 |
|
|
} |
183 |
|
|
|
184 |
|
|
|
185 |
|
|
/* |
186 |
|
|
* Show preferences editor |
187 |
|
|
* Returns true when user clicked on "Start", false otherwise |
188 |
|
|
*/ |
189 |
|
|
|
190 |
|
|
// Window closed |
191 |
|
|
static gint window_closed(void) |
192 |
|
|
{ |
193 |
|
|
return FALSE; |
194 |
|
|
} |
195 |
|
|
|
196 |
|
|
// Window destroyed |
197 |
|
|
static void window_destroyed(void) |
198 |
|
|
{ |
199 |
|
|
gtk_main_quit(); |
200 |
|
|
} |
201 |
|
|
|
202 |
|
|
// "Start" button clicked |
203 |
|
|
static void cb_start(...) |
204 |
|
|
{ |
205 |
|
|
start_clicked = true; |
206 |
|
|
read_settings(); |
207 |
|
|
SavePrefs(); |
208 |
|
|
gtk_widget_destroy(win); |
209 |
|
|
} |
210 |
|
|
|
211 |
|
|
// "Quit" button clicked |
212 |
|
|
static void cb_quit(...) |
213 |
|
|
{ |
214 |
|
|
start_clicked = false; |
215 |
|
|
gtk_widget_destroy(win); |
216 |
|
|
} |
217 |
|
|
|
218 |
|
|
// "OK" button of "About" dialog clicked |
219 |
|
|
static void dl_quit(GtkWidget *dialog) |
220 |
|
|
{ |
221 |
|
|
gtk_widget_destroy(dialog); |
222 |
|
|
} |
223 |
|
|
|
224 |
|
|
// "About" selected |
225 |
|
|
static void mn_about(...) |
226 |
|
|
{ |
227 |
|
|
GtkWidget *dialog, *label, *button; |
228 |
|
|
|
229 |
|
|
char str[256]; |
230 |
|
|
sprintf(str, GetString(STR_ABOUT_TEXT1), VERSION_MAJOR, VERSION_MINOR); |
231 |
|
|
strncat(str, "\n", 255); |
232 |
|
|
strncat(str, GetString(STR_ABOUT_TEXT2), 255); |
233 |
|
|
|
234 |
|
|
dialog = gtk_dialog_new(); |
235 |
|
|
gtk_widget_set_usize(GTK_WIDGET(dialog), strlen(GetString(STR_ABOUT_TEXT2)) + 200, 120); |
236 |
|
|
gtk_window_set_title(GTK_WINDOW(dialog), GetString(STR_ABOUT_TITLE)); |
237 |
|
|
gtk_container_border_width(GTK_CONTAINER(dialog), 5); |
238 |
|
|
gtk_widget_set_uposition(GTK_WIDGET(dialog), 100, 150); |
239 |
|
|
|
240 |
|
|
label = gtk_label_new(str); |
241 |
|
|
gtk_widget_show(label); |
242 |
|
|
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), label, TRUE, TRUE, 0); |
243 |
|
|
|
244 |
|
|
button = gtk_button_new_with_label(GetString(STR_OK_BUTTON)); |
245 |
|
|
gtk_widget_show(button); |
246 |
|
|
gtk_signal_connect_object(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(dl_quit), GTK_OBJECT(dialog)); |
247 |
|
|
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), button, FALSE, FALSE, 0); |
248 |
|
|
GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); |
249 |
|
|
gtk_widget_grab_default(button); |
250 |
|
|
gtk_widget_show(dialog); |
251 |
|
|
} |
252 |
|
|
|
253 |
|
|
// "Zap PRAM" selected |
254 |
|
|
static void mn_zap_pram(...) |
255 |
|
|
{ |
256 |
|
|
ZapPRAM(); |
257 |
|
|
} |
258 |
|
|
|
259 |
|
|
// Menu item descriptions |
260 |
|
|
static GtkItemFactoryEntry menu_items[] = { |
261 |
cebix |
1.4 |
{(gchar *)GetString(STR_PREFS_MENU_FILE_GTK), NULL, NULL, 0, "<Branch>"}, |
262 |
|
|
{(gchar *)GetString(STR_PREFS_ITEM_START_GTK), NULL, GTK_SIGNAL_FUNC(cb_start), 0, NULL}, |
263 |
|
|
{(gchar *)GetString(STR_PREFS_ITEM_ZAP_PRAM_GTK), NULL, GTK_SIGNAL_FUNC(mn_zap_pram), 0, NULL}, |
264 |
|
|
{(gchar *)GetString(STR_PREFS_ITEM_SEPL_GTK), NULL, NULL, 0, "<Separator>"}, |
265 |
|
|
{(gchar *)GetString(STR_PREFS_ITEM_QUIT_GTK), "<control>Q", GTK_SIGNAL_FUNC(cb_quit), 0, NULL}, |
266 |
|
|
{(gchar *)GetString(STR_HELP_MENU_GTK), NULL, NULL, 0, "<LastBranch>"}, |
267 |
|
|
{(gchar *)GetString(STR_HELP_ITEM_ABOUT_GTK), NULL, GTK_SIGNAL_FUNC(mn_about), 0, NULL} |
268 |
cebix |
1.1 |
}; |
269 |
|
|
|
270 |
|
|
bool PrefsEditor(void) |
271 |
|
|
{ |
272 |
|
|
// Create window |
273 |
|
|
win = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
274 |
|
|
gtk_window_set_title(GTK_WINDOW(win), GetString(STR_PREFS_TITLE)); |
275 |
|
|
gtk_signal_connect(GTK_OBJECT(win), "delete_event", GTK_SIGNAL_FUNC(window_closed), NULL); |
276 |
|
|
gtk_signal_connect(GTK_OBJECT(win), "destroy", GTK_SIGNAL_FUNC(window_destroyed), NULL); |
277 |
|
|
|
278 |
|
|
// Create window contents |
279 |
|
|
GtkWidget *box = gtk_vbox_new(FALSE, 4); |
280 |
|
|
gtk_widget_show(box); |
281 |
|
|
gtk_container_add(GTK_CONTAINER(win), box); |
282 |
|
|
|
283 |
|
|
GtkAccelGroup *accel_group = gtk_accel_group_new(); |
284 |
|
|
GtkItemFactory *item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", accel_group); |
285 |
|
|
gtk_item_factory_create_items(item_factory, sizeof(menu_items) / sizeof(menu_items[0]), menu_items, NULL); |
286 |
|
|
gtk_accel_group_attach(accel_group, GTK_OBJECT(win)); |
287 |
|
|
GtkWidget *menu_bar = gtk_item_factory_get_widget(item_factory, "<main>"); |
288 |
|
|
gtk_widget_show(menu_bar); |
289 |
|
|
gtk_box_pack_start(GTK_BOX(box), menu_bar, FALSE, TRUE, 0); |
290 |
|
|
|
291 |
|
|
GtkWidget *notebook = gtk_notebook_new(); |
292 |
|
|
gtk_widget_show(notebook); |
293 |
|
|
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP); |
294 |
cebix |
1.8 |
gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), FALSE); |
295 |
cebix |
1.1 |
gtk_box_pack_start(GTK_BOX(box), notebook, TRUE, TRUE, 0); |
296 |
|
|
|
297 |
|
|
create_volumes_pane(notebook); |
298 |
|
|
create_scsi_pane(notebook); |
299 |
|
|
create_graphics_pane(notebook); |
300 |
|
|
create_serial_pane(notebook); |
301 |
|
|
create_memory_pane(notebook); |
302 |
|
|
|
303 |
|
|
static const opt_desc buttons[] = { |
304 |
|
|
{STR_START_BUTTON, GTK_SIGNAL_FUNC(cb_start)}, |
305 |
|
|
{STR_QUIT_BUTTON, GTK_SIGNAL_FUNC(cb_quit)}, |
306 |
|
|
{0, NULL} |
307 |
|
|
}; |
308 |
|
|
make_button_box(box, 4, buttons); |
309 |
|
|
|
310 |
|
|
// Show window and enter main loop |
311 |
|
|
gtk_widget_show(win); |
312 |
|
|
gtk_main(); |
313 |
|
|
return start_clicked; |
314 |
|
|
} |
315 |
|
|
|
316 |
|
|
|
317 |
|
|
/* |
318 |
|
|
* "Volumes" pane |
319 |
|
|
*/ |
320 |
|
|
|
321 |
cebix |
1.6 |
static GtkWidget *volume_list, *w_extfs; |
322 |
cebix |
1.1 |
static int selected_volume; |
323 |
|
|
|
324 |
|
|
// Volume in list selected |
325 |
|
|
static void cl_selected(GtkWidget *list, int row, int column) |
326 |
|
|
{ |
327 |
|
|
selected_volume = row; |
328 |
|
|
} |
329 |
|
|
|
330 |
|
|
struct file_req_assoc { |
331 |
|
|
file_req_assoc(GtkWidget *r, GtkWidget *e) : req(r), entry(e) {} |
332 |
|
|
GtkWidget *req; |
333 |
|
|
GtkWidget *entry; |
334 |
|
|
}; |
335 |
|
|
|
336 |
|
|
// Volume selected for addition |
337 |
|
|
static void add_volume_ok(GtkWidget *button, file_req_assoc *assoc) |
338 |
|
|
{ |
339 |
|
|
char *file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req)); |
340 |
|
|
gtk_clist_append(GTK_CLIST(volume_list), &file); |
341 |
|
|
gtk_widget_destroy(assoc->req); |
342 |
|
|
delete assoc; |
343 |
|
|
} |
344 |
|
|
|
345 |
|
|
// Volume selected for creation |
346 |
|
|
static void create_volume_ok(GtkWidget *button, file_req_assoc *assoc) |
347 |
|
|
{ |
348 |
|
|
char *file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req)); |
349 |
|
|
|
350 |
|
|
char *str = gtk_entry_get_text(GTK_ENTRY(assoc->entry)); |
351 |
|
|
int size = atoi(str); |
352 |
|
|
|
353 |
|
|
char cmd[1024]; |
354 |
|
|
sprintf(cmd, "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", file, size); |
355 |
|
|
int ret = system(cmd); |
356 |
|
|
if (ret == 0) |
357 |
|
|
gtk_clist_append(GTK_CLIST(volume_list), &file); |
358 |
|
|
gtk_widget_destroy(GTK_WIDGET(assoc->req)); |
359 |
|
|
delete assoc; |
360 |
|
|
} |
361 |
|
|
|
362 |
|
|
// "Add Volume" button clicked |
363 |
|
|
static void cb_add_volume(...) |
364 |
|
|
{ |
365 |
|
|
GtkWidget *req = gtk_file_selection_new(GetString(STR_ADD_VOLUME_TITLE)); |
366 |
|
|
gtk_signal_connect_object(GTK_OBJECT(req), "delete_event", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(req)); |
367 |
|
|
gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(req)->ok_button), "clicked", GTK_SIGNAL_FUNC(add_volume_ok), new file_req_assoc(req, NULL)); |
368 |
|
|
gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(req)->cancel_button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(req)); |
369 |
|
|
gtk_widget_show(req); |
370 |
|
|
} |
371 |
|
|
|
372 |
|
|
// "Create Hardfile" button clicked |
373 |
|
|
static void cb_create_volume(...) |
374 |
|
|
{ |
375 |
|
|
GtkWidget *req = gtk_file_selection_new(GetString(STR_CREATE_VOLUME_TITLE)); |
376 |
|
|
|
377 |
|
|
GtkWidget *box = gtk_hbox_new(FALSE, 4); |
378 |
|
|
gtk_widget_show(box); |
379 |
|
|
GtkWidget *label = gtk_label_new(GetString(STR_HARDFILE_SIZE_CTRL)); |
380 |
|
|
gtk_widget_show(label); |
381 |
|
|
GtkWidget *entry = gtk_entry_new(); |
382 |
|
|
gtk_widget_show(entry); |
383 |
|
|
char str[32]; |
384 |
|
|
sprintf(str, "%d", 40); |
385 |
|
|
gtk_entry_set_text(GTK_ENTRY(entry), str); |
386 |
|
|
gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0); |
387 |
|
|
gtk_box_pack_start(GTK_BOX(box), entry, FALSE, FALSE, 0); |
388 |
|
|
gtk_box_pack_start(GTK_BOX(GTK_FILE_SELECTION(req)->main_vbox), box, FALSE, FALSE, 0); |
389 |
|
|
|
390 |
|
|
gtk_signal_connect_object(GTK_OBJECT(req), "delete_event", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(req)); |
391 |
|
|
gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(req)->ok_button), "clicked", GTK_SIGNAL_FUNC(create_volume_ok), new file_req_assoc(req, entry)); |
392 |
|
|
gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(req)->cancel_button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(req)); |
393 |
|
|
gtk_widget_show(req); |
394 |
|
|
} |
395 |
|
|
|
396 |
|
|
// "Remove Volume" button clicked |
397 |
|
|
static void cb_remove_volume(...) |
398 |
|
|
{ |
399 |
|
|
gtk_clist_remove(GTK_CLIST(volume_list), selected_volume); |
400 |
|
|
} |
401 |
|
|
|
402 |
|
|
// "Boot From" selected |
403 |
|
|
static void mn_boot_any(...) {PrefsReplaceInt16("bootdriver", 0);} |
404 |
|
|
static void mn_boot_cdrom(...) {PrefsReplaceInt16("bootdriver", CDROMRefNum);} |
405 |
|
|
|
406 |
|
|
// "No CD-ROM Driver" button toggled |
407 |
|
|
static void tb_nocdrom(GtkWidget *widget) |
408 |
|
|
{ |
409 |
|
|
PrefsReplaceBool("nocdrom", GTK_TOGGLE_BUTTON(widget)->active); |
410 |
|
|
} |
411 |
|
|
|
412 |
|
|
// Read settings from widgets and set preferences |
413 |
|
|
static void read_volumes_settings(void) |
414 |
|
|
{ |
415 |
|
|
while (PrefsFindString("disk")) |
416 |
|
|
PrefsRemoveItem("disk"); |
417 |
|
|
|
418 |
|
|
for (int i=0; i<GTK_CLIST(volume_list)->rows; i++) { |
419 |
|
|
char *str; |
420 |
|
|
gtk_clist_get_text(GTK_CLIST(volume_list), i, 0, &str); |
421 |
|
|
PrefsAddString("disk", str); |
422 |
|
|
} |
423 |
cebix |
1.6 |
|
424 |
|
|
PrefsReplaceString("extfs", gtk_entry_get_text(GTK_ENTRY(w_extfs))); |
425 |
cebix |
1.1 |
} |
426 |
|
|
|
427 |
|
|
// Create "Volumes" pane |
428 |
|
|
static void create_volumes_pane(GtkWidget *top) |
429 |
|
|
{ |
430 |
|
|
GtkWidget *box, *scroll, *menu; |
431 |
|
|
|
432 |
|
|
box = make_pane(top, STR_VOLUMES_PANE_TITLE); |
433 |
|
|
|
434 |
|
|
scroll = gtk_scrolled_window_new(NULL, NULL); |
435 |
|
|
gtk_widget_show(scroll); |
436 |
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
437 |
|
|
volume_list = gtk_clist_new(1); |
438 |
|
|
gtk_widget_show(volume_list); |
439 |
|
|
gtk_clist_set_selection_mode(GTK_CLIST(volume_list), GTK_SELECTION_SINGLE); |
440 |
|
|
gtk_clist_set_shadow_type(GTK_CLIST(volume_list), GTK_SHADOW_NONE); |
441 |
cebix |
1.5 |
gtk_clist_set_reorderable(GTK_CLIST(volume_list), true); |
442 |
cebix |
1.1 |
gtk_signal_connect(GTK_OBJECT(volume_list), "select_row", GTK_SIGNAL_FUNC(cl_selected), NULL); |
443 |
|
|
char *str; |
444 |
|
|
int32 index = 0; |
445 |
|
|
while ((str = (char *)PrefsFindString("disk", index++)) != NULL) |
446 |
|
|
gtk_clist_append(GTK_CLIST(volume_list), &str); |
447 |
|
|
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), volume_list); |
448 |
|
|
gtk_box_pack_start(GTK_BOX(box), scroll, TRUE, TRUE, 0); |
449 |
|
|
selected_volume = 0; |
450 |
|
|
|
451 |
|
|
static const opt_desc buttons[] = { |
452 |
|
|
{STR_ADD_VOLUME_BUTTON, GTK_SIGNAL_FUNC(cb_add_volume)}, |
453 |
|
|
{STR_CREATE_VOLUME_BUTTON, GTK_SIGNAL_FUNC(cb_create_volume)}, |
454 |
|
|
{STR_REMOVE_VOLUME_BUTTON, GTK_SIGNAL_FUNC(cb_remove_volume)}, |
455 |
|
|
{0, NULL}, |
456 |
|
|
}; |
457 |
|
|
make_button_box(box, 0, buttons); |
458 |
|
|
make_separator(box); |
459 |
cebix |
1.6 |
|
460 |
|
|
w_extfs = make_entry(box, STR_EXTFS_CTRL, "extfs"); |
461 |
cebix |
1.1 |
|
462 |
|
|
static const opt_desc options[] = { |
463 |
|
|
{STR_BOOT_ANY_LAB, GTK_SIGNAL_FUNC(mn_boot_any)}, |
464 |
|
|
{STR_BOOT_CDROM_LAB, GTK_SIGNAL_FUNC(mn_boot_cdrom)}, |
465 |
|
|
{0, NULL} |
466 |
|
|
}; |
467 |
|
|
int bootdriver = PrefsFindInt16("bootdriver"), active = 0; |
468 |
|
|
switch (bootdriver) { |
469 |
|
|
case 0: active = 0; break; |
470 |
|
|
case CDROMRefNum: active = 1; break; |
471 |
|
|
} |
472 |
|
|
menu = make_option_menu(box, STR_BOOTDRIVER_CTRL, options, active); |
473 |
|
|
|
474 |
|
|
make_checkbox(box, STR_NOCDROM_CTRL, "nocdrom", GTK_SIGNAL_FUNC(tb_nocdrom)); |
475 |
|
|
} |
476 |
|
|
|
477 |
|
|
|
478 |
|
|
/* |
479 |
|
|
* "SCSI" pane |
480 |
|
|
*/ |
481 |
|
|
|
482 |
|
|
static GtkWidget *w_scsi[7]; |
483 |
|
|
|
484 |
|
|
// Read settings from widgets and set preferences |
485 |
|
|
static void read_scsi_settings(void) |
486 |
|
|
{ |
487 |
|
|
for (int id=0; id<7; id++) { |
488 |
|
|
char prefs_name[32]; |
489 |
|
|
sprintf(prefs_name, "scsi%d", id); |
490 |
|
|
const char *str = gtk_entry_get_text(GTK_ENTRY(w_scsi[id])); |
491 |
|
|
if (str && strlen(str)) |
492 |
|
|
PrefsReplaceString(prefs_name, str); |
493 |
|
|
else |
494 |
|
|
PrefsRemoveItem(prefs_name); |
495 |
|
|
} |
496 |
|
|
} |
497 |
|
|
|
498 |
|
|
// Create "SCSI" pane |
499 |
|
|
static void create_scsi_pane(GtkWidget *top) |
500 |
|
|
{ |
501 |
|
|
GtkWidget *box; |
502 |
|
|
|
503 |
|
|
box = make_pane(top, STR_SCSI_PANE_TITLE); |
504 |
|
|
|
505 |
|
|
for (int id=0; id<7; id++) { |
506 |
|
|
char prefs_name[32]; |
507 |
|
|
sprintf(prefs_name, "scsi%d", id); |
508 |
|
|
w_scsi[id] = make_entry(box, STR_SCSI_ID_0 + id, prefs_name); |
509 |
|
|
} |
510 |
|
|
} |
511 |
|
|
|
512 |
|
|
|
513 |
|
|
/* |
514 |
|
|
* "Graphics/Sound" pane |
515 |
|
|
*/ |
516 |
|
|
|
517 |
|
|
// Display types |
518 |
|
|
enum { |
519 |
|
|
DISPLAY_WINDOW, |
520 |
|
|
DISPLAY_SCREEN |
521 |
|
|
}; |
522 |
|
|
|
523 |
|
|
static GtkWidget *w_frameskip, *w_display_x, *w_display_y; |
524 |
|
|
static GtkWidget *l_frameskip, *l_display_x, *l_display_y; |
525 |
|
|
static int display_type; |
526 |
|
|
static int dis_width, dis_height; |
527 |
|
|
|
528 |
cebix |
1.7 |
#if ENABLE_FBDEV_DGA |
529 |
|
|
static GtkWidget *w_fbdev_name, *w_fbdevice_file; |
530 |
|
|
static GtkWidget *l_fbdev_name, *l_fbdevice_file; |
531 |
|
|
static char fbdev_name[256]; |
532 |
|
|
#endif |
533 |
|
|
|
534 |
cebix |
1.1 |
// Hide/show graphics widgets |
535 |
|
|
static void hide_show_graphics_widgets(void) |
536 |
|
|
{ |
537 |
|
|
switch (display_type) { |
538 |
|
|
case DISPLAY_WINDOW: |
539 |
|
|
gtk_widget_show(w_frameskip); gtk_widget_show(l_frameskip); |
540 |
cebix |
1.7 |
#if ENABLE_FBDEV_DGA |
541 |
|
|
gtk_widget_show(w_display_x); gtk_widget_show(l_display_x); |
542 |
|
|
gtk_widget_show(w_display_y); gtk_widget_show(l_display_y); |
543 |
|
|
gtk_widget_hide(w_fbdev_name); gtk_widget_hide(l_fbdev_name); |
544 |
|
|
#endif |
545 |
cebix |
1.1 |
break; |
546 |
|
|
case DISPLAY_SCREEN: |
547 |
|
|
gtk_widget_hide(w_frameskip); gtk_widget_hide(l_frameskip); |
548 |
cebix |
1.7 |
#if ENABLE_FBDEV_DGA |
549 |
|
|
gtk_widget_hide(w_display_x); gtk_widget_hide(l_display_x); |
550 |
|
|
gtk_widget_hide(w_display_y); gtk_widget_hide(l_display_y); |
551 |
|
|
gtk_widget_show(w_fbdev_name); gtk_widget_show(l_fbdev_name); |
552 |
|
|
#endif |
553 |
cebix |
1.1 |
break; |
554 |
|
|
} |
555 |
|
|
} |
556 |
|
|
|
557 |
|
|
// "Window" video type selected |
558 |
|
|
static void mn_window(...) |
559 |
|
|
{ |
560 |
|
|
display_type = DISPLAY_WINDOW; |
561 |
|
|
hide_show_graphics_widgets(); |
562 |
|
|
} |
563 |
|
|
|
564 |
|
|
// "Fullscreen" video type selected |
565 |
|
|
static void mn_fullscreen(...) |
566 |
|
|
{ |
567 |
|
|
display_type = DISPLAY_SCREEN; |
568 |
|
|
hide_show_graphics_widgets(); |
569 |
|
|
} |
570 |
|
|
|
571 |
|
|
// "5 Hz".."60Hz" selected |
572 |
|
|
static void mn_5hz(...) {PrefsReplaceInt32("frameskip", 12);} |
573 |
|
|
static void mn_7hz(...) {PrefsReplaceInt32("frameskip", 8);} |
574 |
|
|
static void mn_10hz(...) {PrefsReplaceInt32("frameskip", 6);} |
575 |
|
|
static void mn_15hz(...) {PrefsReplaceInt32("frameskip", 4);} |
576 |
|
|
static void mn_30hz(...) {PrefsReplaceInt32("frameskip", 2);} |
577 |
|
|
static void mn_60hz(...) {PrefsReplaceInt32("frameskip", 1);} |
578 |
|
|
|
579 |
|
|
// "Disable Sound Output" button toggled |
580 |
|
|
static void tb_nosound(GtkWidget *widget) |
581 |
|
|
{ |
582 |
|
|
PrefsReplaceBool("nosound", GTK_TOGGLE_BUTTON(widget)->active); |
583 |
|
|
} |
584 |
|
|
|
585 |
|
|
// Read graphics preferences |
586 |
|
|
static void parse_graphics_prefs(void) |
587 |
|
|
{ |
588 |
|
|
display_type = DISPLAY_WINDOW; |
589 |
|
|
dis_width = 512; |
590 |
|
|
dis_height = 384; |
591 |
cebix |
1.7 |
#if ENABLE_FBDEV_DGA |
592 |
|
|
fbdev_name[0] = 0; |
593 |
|
|
#endif |
594 |
cebix |
1.1 |
|
595 |
|
|
const char *str = PrefsFindString("screen"); |
596 |
|
|
if (str) { |
597 |
|
|
if (sscanf(str, "win/%d/%d", &dis_width, &dis_height) == 2) |
598 |
|
|
display_type = DISPLAY_WINDOW; |
599 |
cebix |
1.7 |
#if ENABLE_FBDEV_DGA |
600 |
|
|
else if (sscanf(str, "dga/%255s", fbdev_name) == 1) |
601 |
|
|
#else |
602 |
cebix |
1.2 |
else if (sscanf(str, "dga/%d/%d", &dis_width, &dis_height) == 2) |
603 |
cebix |
1.7 |
#endif |
604 |
cebix |
1.1 |
display_type = DISPLAY_SCREEN; |
605 |
|
|
} |
606 |
|
|
} |
607 |
|
|
|
608 |
|
|
// Read settings from widgets and set preferences |
609 |
|
|
static void read_graphics_settings(void) |
610 |
|
|
{ |
611 |
|
|
const char *str; |
612 |
|
|
|
613 |
|
|
str = gtk_entry_get_text(GTK_ENTRY(w_display_x)); |
614 |
|
|
dis_width = atoi(str); |
615 |
|
|
|
616 |
|
|
str = gtk_entry_get_text(GTK_ENTRY(w_display_y)); |
617 |
|
|
dis_height = atoi(str); |
618 |
|
|
|
619 |
|
|
char pref[256]; |
620 |
|
|
switch (display_type) { |
621 |
|
|
case DISPLAY_WINDOW: |
622 |
|
|
sprintf(pref, "win/%d/%d", dis_width, dis_height); |
623 |
|
|
break; |
624 |
|
|
case DISPLAY_SCREEN: |
625 |
cebix |
1.7 |
#if ENABLE_FBDEV_DGA |
626 |
|
|
str = gtk_entry_get_text(GTK_ENTRY(w_fbdev_name)); |
627 |
|
|
sprintf(pref, "dga/%s", str); |
628 |
|
|
#else |
629 |
cebix |
1.2 |
sprintf(pref, "dga/%d/%d", dis_width, dis_height); |
630 |
cebix |
1.7 |
#endif |
631 |
cebix |
1.1 |
break; |
632 |
|
|
default: |
633 |
|
|
PrefsRemoveItem("screen"); |
634 |
|
|
return; |
635 |
|
|
} |
636 |
|
|
PrefsReplaceString("screen", pref); |
637 |
|
|
} |
638 |
|
|
|
639 |
|
|
// Create "Graphics/Sound" pane |
640 |
|
|
static void create_graphics_pane(GtkWidget *top) |
641 |
|
|
{ |
642 |
cebix |
1.2 |
GtkWidget *box, *table, *label, *opt, *menu, *combo; |
643 |
cebix |
1.1 |
char str[32]; |
644 |
|
|
|
645 |
|
|
parse_graphics_prefs(); |
646 |
|
|
|
647 |
|
|
box = make_pane(top, STR_GRAPHICS_SOUND_PANE_TITLE); |
648 |
cebix |
1.7 |
table = make_table(box, 2, 5); |
649 |
cebix |
1.1 |
|
650 |
|
|
label = gtk_label_new(GetString(STR_VIDEO_TYPE_CTRL)); |
651 |
|
|
gtk_widget_show(label); |
652 |
|
|
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4); |
653 |
|
|
|
654 |
|
|
opt = gtk_option_menu_new(); |
655 |
|
|
gtk_widget_show(opt); |
656 |
|
|
menu = gtk_menu_new(); |
657 |
|
|
add_menu_item(menu, STR_WINDOW_LAB, GTK_SIGNAL_FUNC(mn_window)); |
658 |
|
|
add_menu_item(menu, STR_FULLSCREEN_LAB, GTK_SIGNAL_FUNC(mn_fullscreen)); |
659 |
|
|
switch (display_type) { |
660 |
|
|
case DISPLAY_WINDOW: |
661 |
|
|
gtk_menu_set_active(GTK_MENU(menu), 0); |
662 |
|
|
break; |
663 |
|
|
case DISPLAY_SCREEN: |
664 |
|
|
gtk_menu_set_active(GTK_MENU(menu), 1); |
665 |
|
|
break; |
666 |
|
|
} |
667 |
|
|
gtk_option_menu_set_menu(GTK_OPTION_MENU(opt), menu); |
668 |
|
|
gtk_table_attach(GTK_TABLE(table), opt, 1, 2, 0, 1, (GtkAttachOptions)GTK_FILL, (GtkAttachOptions)0, 4, 4); |
669 |
|
|
|
670 |
|
|
l_frameskip = gtk_label_new(GetString(STR_FRAMESKIP_CTRL)); |
671 |
|
|
gtk_widget_show(l_frameskip); |
672 |
|
|
gtk_table_attach(GTK_TABLE(table), l_frameskip, 0, 1, 1, 2, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4); |
673 |
|
|
|
674 |
|
|
w_frameskip = gtk_option_menu_new(); |
675 |
|
|
gtk_widget_show(w_frameskip); |
676 |
|
|
menu = gtk_menu_new(); |
677 |
|
|
add_menu_item(menu, STR_REF_5HZ_LAB, GTK_SIGNAL_FUNC(mn_5hz)); |
678 |
|
|
add_menu_item(menu, STR_REF_7_5HZ_LAB, GTK_SIGNAL_FUNC(mn_7hz)); |
679 |
|
|
add_menu_item(menu, STR_REF_10HZ_LAB, GTK_SIGNAL_FUNC(mn_10hz)); |
680 |
|
|
add_menu_item(menu, STR_REF_15HZ_LAB, GTK_SIGNAL_FUNC(mn_15hz)); |
681 |
|
|
add_menu_item(menu, STR_REF_30HZ_LAB, GTK_SIGNAL_FUNC(mn_30hz)); |
682 |
|
|
add_menu_item(menu, STR_REF_60HZ_LAB, GTK_SIGNAL_FUNC(mn_60hz)); |
683 |
|
|
int frameskip = PrefsFindInt32("frameskip"); |
684 |
|
|
switch (frameskip) { |
685 |
|
|
case 12: |
686 |
|
|
gtk_menu_set_active(GTK_MENU(menu), 0); |
687 |
|
|
break; |
688 |
|
|
case 8: |
689 |
|
|
gtk_menu_set_active(GTK_MENU(menu), 1); |
690 |
|
|
break; |
691 |
|
|
case 6: |
692 |
|
|
gtk_menu_set_active(GTK_MENU(menu), 2); |
693 |
|
|
break; |
694 |
|
|
case 4: |
695 |
|
|
gtk_menu_set_active(GTK_MENU(menu), 3); |
696 |
|
|
break; |
697 |
|
|
case 2: |
698 |
|
|
gtk_menu_set_active(GTK_MENU(menu), 4); |
699 |
|
|
break; |
700 |
|
|
case 1: |
701 |
|
|
gtk_menu_set_active(GTK_MENU(menu), 5); |
702 |
|
|
break; |
703 |
|
|
} |
704 |
|
|
gtk_option_menu_set_menu(GTK_OPTION_MENU(w_frameskip), menu); |
705 |
|
|
gtk_table_attach(GTK_TABLE(table), w_frameskip, 1, 2, 1, 2, (GtkAttachOptions)GTK_FILL, (GtkAttachOptions)0, 4, 4); |
706 |
|
|
|
707 |
|
|
l_display_x = gtk_label_new(GetString(STR_DISPLAY_X_CTRL)); |
708 |
|
|
gtk_widget_show(l_display_x); |
709 |
|
|
gtk_table_attach(GTK_TABLE(table), l_display_x, 0, 1, 2, 3, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4); |
710 |
|
|
|
711 |
cebix |
1.2 |
combo = gtk_combo_new(); |
712 |
|
|
gtk_widget_show(combo); |
713 |
|
|
GList *glist1 = NULL; |
714 |
cebix |
1.4 |
glist1 = g_list_append(glist1, (void *)GetString(STR_SIZE_512_LAB)); |
715 |
|
|
glist1 = g_list_append(glist1, (void *)GetString(STR_SIZE_640_LAB)); |
716 |
|
|
glist1 = g_list_append(glist1, (void *)GetString(STR_SIZE_800_LAB)); |
717 |
|
|
glist1 = g_list_append(glist1, (void *)GetString(STR_SIZE_1024_LAB)); |
718 |
|
|
glist1 = g_list_append(glist1, (void *)GetString(STR_SIZE_MAX_LAB)); |
719 |
cebix |
1.2 |
gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist1); |
720 |
|
|
if (dis_width) |
721 |
|
|
sprintf(str, "%d", dis_width); |
722 |
|
|
else |
723 |
cebix |
1.3 |
strcpy(str, GetString(STR_SIZE_MAX_LAB)); |
724 |
cebix |
1.2 |
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str); |
725 |
|
|
gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 2, 3, (GtkAttachOptions)GTK_FILL, (GtkAttachOptions)0, 4, 4); |
726 |
|
|
w_display_x = GTK_COMBO(combo)->entry; |
727 |
cebix |
1.1 |
|
728 |
|
|
l_display_y = gtk_label_new(GetString(STR_DISPLAY_Y_CTRL)); |
729 |
|
|
gtk_widget_show(l_display_y); |
730 |
|
|
gtk_table_attach(GTK_TABLE(table), l_display_y, 0, 1, 3, 4, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4); |
731 |
|
|
|
732 |
cebix |
1.2 |
combo = gtk_combo_new(); |
733 |
|
|
gtk_widget_show(combo); |
734 |
|
|
GList *glist2 = NULL; |
735 |
cebix |
1.4 |
glist2 = g_list_append(glist2, (void *)GetString(STR_SIZE_384_LAB)); |
736 |
|
|
glist2 = g_list_append(glist2, (void *)GetString(STR_SIZE_480_LAB)); |
737 |
|
|
glist2 = g_list_append(glist2, (void *)GetString(STR_SIZE_600_LAB)); |
738 |
|
|
glist2 = g_list_append(glist2, (void *)GetString(STR_SIZE_768_LAB)); |
739 |
|
|
glist2 = g_list_append(glist2, (void *)GetString(STR_SIZE_MAX_LAB)); |
740 |
cebix |
1.2 |
gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist2); |
741 |
|
|
if (dis_height) |
742 |
|
|
sprintf(str, "%d", dis_height); |
743 |
|
|
else |
744 |
cebix |
1.3 |
strcpy(str, GetString(STR_SIZE_MAX_LAB)); |
745 |
cebix |
1.2 |
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str); |
746 |
|
|
gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 3, 4, (GtkAttachOptions)GTK_FILL, (GtkAttachOptions)0, 4, 4); |
747 |
|
|
w_display_y = GTK_COMBO(combo)->entry; |
748 |
cebix |
1.7 |
|
749 |
|
|
#if ENABLE_FBDEV_DGA |
750 |
|
|
l_fbdev_name = gtk_label_new(GetString(STR_FBDEV_NAME_CTRL)); |
751 |
|
|
gtk_widget_show(l_fbdev_name); |
752 |
|
|
gtk_table_attach(GTK_TABLE(table), l_fbdev_name, 0, 1, 4, 5, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4); |
753 |
|
|
|
754 |
|
|
w_fbdev_name = gtk_entry_new(); |
755 |
|
|
gtk_widget_show(w_fbdev_name); |
756 |
|
|
gtk_entry_set_text(GTK_ENTRY(w_fbdev_name), fbdev_name); |
757 |
|
|
gtk_table_attach(GTK_TABLE(table), w_fbdev_name, 1, 2, 4, 5, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4); |
758 |
|
|
|
759 |
|
|
w_fbdevice_file = make_entry(box, STR_FBDEVICE_FILE_CTRL, "fbdevicefile"); |
760 |
|
|
#endif |
761 |
cebix |
1.1 |
|
762 |
|
|
make_checkbox(box, STR_NOSOUND_CTRL, "nosound", GTK_SIGNAL_FUNC(tb_nosound)); |
763 |
|
|
|
764 |
|
|
hide_show_graphics_widgets(); |
765 |
|
|
} |
766 |
|
|
|
767 |
|
|
|
768 |
|
|
/* |
769 |
|
|
* "Serial/Network" pane |
770 |
|
|
*/ |
771 |
|
|
|
772 |
|
|
static GtkWidget *w_seriala, *w_serialb, *w_ether; |
773 |
|
|
|
774 |
|
|
// Read settings from widgets and set preferences |
775 |
|
|
static void read_serial_settings(void) |
776 |
|
|
{ |
777 |
|
|
const char *str; |
778 |
|
|
|
779 |
|
|
str = gtk_entry_get_text(GTK_ENTRY(w_seriala)); |
780 |
|
|
PrefsReplaceString("seriala", str); |
781 |
|
|
|
782 |
|
|
str = gtk_entry_get_text(GTK_ENTRY(w_serialb)); |
783 |
|
|
PrefsReplaceString("serialb", str); |
784 |
|
|
|
785 |
|
|
str = gtk_entry_get_text(GTK_ENTRY(w_ether)); |
786 |
|
|
if (str && strlen(str)) |
787 |
|
|
PrefsReplaceString("ether", str); |
788 |
|
|
else |
789 |
|
|
PrefsRemoveItem("ether"); |
790 |
|
|
} |
791 |
|
|
|
792 |
|
|
// Add names of serial devices |
793 |
|
|
static gint gl_str_cmp(gconstpointer a, gconstpointer b) |
794 |
|
|
{ |
795 |
|
|
return strcmp((char *)a, (char *)b); |
796 |
|
|
} |
797 |
|
|
|
798 |
|
|
static GList *add_serial_names(void) |
799 |
|
|
{ |
800 |
|
|
GList *glist = NULL; |
801 |
|
|
|
802 |
|
|
// Search /dev for ttyS* and lp* |
803 |
|
|
DIR *d = opendir("/dev"); |
804 |
|
|
if (d) { |
805 |
|
|
struct dirent *de; |
806 |
|
|
while ((de = readdir(d)) != NULL) { |
807 |
|
|
#if defined(__linux__) |
808 |
|
|
if (strncmp(de->d_name, "ttyS", 4) == 0 || strncmp(de->d_name, "lp", 2) == 0) { |
809 |
|
|
#elif defined(__FreeBSD__) |
810 |
|
|
if (strncmp(de->d_name, "cuaa", 4) == 0 || strncmp(de->d_name, "lpt", 3) == 0) { |
811 |
cebix |
1.4 |
#elif defined(__NetBSD__) |
812 |
|
|
if (strncmp(de->d_name, "tty0", 4) == 0 || strncmp(de->d_name, "lpt", 3) == 0) { |
813 |
cebix |
1.1 |
#elif defined(sgi) |
814 |
|
|
if (strncmp(de->d_name, "ttyf", 4) == 0 || strncmp(de->d_name, "plp", 3) == 0) { |
815 |
|
|
#else |
816 |
|
|
if (false) { |
817 |
|
|
#endif |
818 |
|
|
char *str = new char[64]; |
819 |
|
|
sprintf(str, "/dev/%s", de->d_name); |
820 |
|
|
glist = g_list_append(glist, str); |
821 |
|
|
} |
822 |
|
|
} |
823 |
|
|
closedir(d); |
824 |
|
|
} |
825 |
|
|
if (glist) |
826 |
|
|
g_list_sort(glist, gl_str_cmp); |
827 |
|
|
else |
828 |
cebix |
1.4 |
glist = g_list_append(glist, (void *)GetString(STR_NONE_LAB)); |
829 |
cebix |
1.1 |
return glist; |
830 |
|
|
} |
831 |
|
|
|
832 |
|
|
// Add names of ethernet interfaces |
833 |
|
|
static GList *add_ether_names(void) |
834 |
|
|
{ |
835 |
|
|
GList *glist = NULL; |
836 |
|
|
|
837 |
|
|
// Get list of all Ethernet interfaces |
838 |
|
|
int s = socket(PF_INET, SOCK_DGRAM, 0); |
839 |
|
|
if (s >= 0) { |
840 |
|
|
char inbuf[8192]; |
841 |
|
|
struct ifconf ifc; |
842 |
|
|
ifc.ifc_len = sizeof(inbuf); |
843 |
|
|
ifc.ifc_buf = inbuf; |
844 |
|
|
if (ioctl(s, SIOCGIFCONF, &ifc) == 0) { |
845 |
|
|
struct ifreq req, *ifr = ifc.ifc_req; |
846 |
|
|
for (int i=0; i<ifc.ifc_len; i+=sizeof(ifreq), ifr++) { |
847 |
|
|
req = *ifr; |
848 |
cebix |
1.4 |
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(sgi) |
849 |
cebix |
1.1 |
if (ioctl(s, SIOCGIFADDR, &req) == 0 && (req.ifr_addr.sa_family == ARPHRD_ETHER || req.ifr_addr.sa_family == ARPHRD_ETHER+1)) { |
850 |
cebix |
1.4 |
#elif defined(__linux__) |
851 |
|
|
if (ioctl(s, SIOCGIFHWADDR, &req) == 0 && req.ifr_hwaddr.sa_family == ARPHRD_ETHER) { |
852 |
cebix |
1.1 |
#else |
853 |
cebix |
1.4 |
if (false) { |
854 |
cebix |
1.1 |
#endif |
855 |
|
|
char *str = new char[64]; |
856 |
|
|
strncpy(str, ifr->ifr_name, 63); |
857 |
|
|
glist = g_list_append(glist, str); |
858 |
|
|
} |
859 |
|
|
} |
860 |
|
|
} |
861 |
|
|
close(s); |
862 |
|
|
} |
863 |
|
|
if (glist) |
864 |
|
|
g_list_sort(glist, gl_str_cmp); |
865 |
|
|
else |
866 |
cebix |
1.4 |
glist = g_list_append(glist, (void *)GetString(STR_NONE_LAB)); |
867 |
cebix |
1.1 |
return glist; |
868 |
|
|
} |
869 |
|
|
|
870 |
|
|
// Create "Serial/Network" pane |
871 |
|
|
static void create_serial_pane(GtkWidget *top) |
872 |
|
|
{ |
873 |
|
|
GtkWidget *box, *table, *label, *combo; |
874 |
|
|
GList *glist = add_serial_names(); |
875 |
|
|
|
876 |
|
|
box = make_pane(top, STR_SERIAL_NETWORK_PANE_TITLE); |
877 |
|
|
table = make_table(box, 2, 3); |
878 |
|
|
|
879 |
|
|
label = gtk_label_new(GetString(STR_SERIALA_CTRL)); |
880 |
|
|
gtk_widget_show(label); |
881 |
|
|
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4); |
882 |
|
|
|
883 |
|
|
combo = gtk_combo_new(); |
884 |
|
|
gtk_widget_show(combo); |
885 |
|
|
gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist); |
886 |
|
|
const char *str = PrefsFindString("seriala"); |
887 |
|
|
if (str == NULL) |
888 |
|
|
str = ""; |
889 |
|
|
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str); |
890 |
|
|
gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 0, 1, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4); |
891 |
|
|
w_seriala = GTK_COMBO(combo)->entry; |
892 |
|
|
|
893 |
|
|
label = gtk_label_new(GetString(STR_SERIALB_CTRL)); |
894 |
|
|
gtk_widget_show(label); |
895 |
|
|
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4); |
896 |
|
|
|
897 |
|
|
combo = gtk_combo_new(); |
898 |
|
|
gtk_widget_show(combo); |
899 |
|
|
gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist); |
900 |
|
|
str = PrefsFindString("serialb"); |
901 |
|
|
if (str == NULL) |
902 |
|
|
str = ""; |
903 |
|
|
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str); |
904 |
|
|
gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 1, 2, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4); |
905 |
|
|
w_serialb = GTK_COMBO(combo)->entry; |
906 |
|
|
|
907 |
|
|
label = gtk_label_new(GetString(STR_ETHERNET_IF_CTRL)); |
908 |
|
|
gtk_widget_show(label); |
909 |
|
|
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4); |
910 |
|
|
|
911 |
|
|
glist = add_ether_names(); |
912 |
|
|
combo = gtk_combo_new(); |
913 |
|
|
gtk_widget_show(combo); |
914 |
|
|
gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist); |
915 |
|
|
str = PrefsFindString("ether"); |
916 |
|
|
if (str == NULL) |
917 |
|
|
str = ""; |
918 |
|
|
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str); |
919 |
|
|
gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 2, 3, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4); |
920 |
|
|
w_ether = GTK_COMBO(combo)->entry; |
921 |
|
|
} |
922 |
|
|
|
923 |
|
|
|
924 |
|
|
/* |
925 |
|
|
* "Memory/Misc" pane |
926 |
|
|
*/ |
927 |
|
|
|
928 |
|
|
static GtkObject *w_ramsize_adj; |
929 |
|
|
static GtkWidget *w_rom_file; |
930 |
|
|
static GtkWidget *w_keycode_file; |
931 |
|
|
|
932 |
|
|
// Model ID selected |
933 |
|
|
static void mn_modelid_5(...) {PrefsReplaceInt32("modelid", 5);} |
934 |
|
|
static void mn_modelid_14(...) {PrefsReplaceInt32("modelid", 14);} |
935 |
|
|
|
936 |
cebix |
1.8 |
// "FPU Emulation" button toggled |
937 |
|
|
static void tb_fpu(GtkWidget *widget) |
938 |
|
|
{ |
939 |
|
|
PrefsReplaceBool("fpu", GTK_TOGGLE_BUTTON(widget)->active); |
940 |
|
|
} |
941 |
|
|
|
942 |
cebix |
1.1 |
// "Use Raw Keycodes" button toggled |
943 |
|
|
static void tb_keycodes(GtkWidget *widget) |
944 |
|
|
{ |
945 |
|
|
PrefsReplaceBool("keycodes", GTK_TOGGLE_BUTTON(widget)->active); |
946 |
|
|
} |
947 |
|
|
|
948 |
|
|
// Read settings from widgets and set preferences |
949 |
|
|
static void read_memory_settings(void) |
950 |
|
|
{ |
951 |
|
|
PrefsReplaceInt32("ramsize", int(GTK_ADJUSTMENT(w_ramsize_adj)->value) << 20); |
952 |
|
|
|
953 |
|
|
const char *str = gtk_entry_get_text(GTK_ENTRY(w_rom_file)); |
954 |
|
|
if (str && strlen(str)) |
955 |
|
|
PrefsReplaceString("rom", str); |
956 |
|
|
else |
957 |
|
|
PrefsRemoveItem("rom"); |
958 |
|
|
|
959 |
|
|
str = gtk_entry_get_text(GTK_ENTRY(w_keycode_file)); |
960 |
|
|
if (str && strlen(str)) |
961 |
|
|
PrefsReplaceString("keycodefile", str); |
962 |
|
|
else |
963 |
|
|
PrefsRemoveItem("keycodefile"); |
964 |
|
|
} |
965 |
|
|
|
966 |
|
|
// Create "Memory/Misc" pane |
967 |
|
|
static void create_memory_pane(GtkWidget *top) |
968 |
|
|
{ |
969 |
cebix |
1.4 |
GtkWidget *box, *vbox, *hbox, *hbox2, *label, *scale, *menu; |
970 |
cebix |
1.1 |
|
971 |
|
|
box = make_pane(top, STR_MEMORY_MISC_PANE_TITLE); |
972 |
|
|
|
973 |
|
|
hbox = gtk_hbox_new(FALSE, 4); |
974 |
|
|
gtk_widget_show(hbox); |
975 |
|
|
|
976 |
|
|
label = gtk_label_new(GetString(STR_RAMSIZE_SLIDER)); |
977 |
|
|
gtk_widget_show(label); |
978 |
|
|
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
979 |
|
|
|
980 |
|
|
vbox = gtk_vbox_new(FALSE, 4); |
981 |
|
|
gtk_widget_show(vbox); |
982 |
|
|
|
983 |
|
|
gfloat min, max; |
984 |
|
|
min = 1; |
985 |
|
|
max = 1024; |
986 |
|
|
w_ramsize_adj = gtk_adjustment_new(min, min, max, 1, 16, 0); |
987 |
|
|
gtk_adjustment_set_value(GTK_ADJUSTMENT(w_ramsize_adj), PrefsFindInt32("ramsize") >> 20); |
988 |
|
|
|
989 |
|
|
scale = gtk_hscale_new(GTK_ADJUSTMENT(w_ramsize_adj)); |
990 |
|
|
gtk_widget_show(scale); |
991 |
|
|
gtk_scale_set_digits(GTK_SCALE(scale), 0); |
992 |
|
|
gtk_box_pack_start(GTK_BOX(vbox), scale, TRUE, TRUE, 0); |
993 |
|
|
|
994 |
|
|
hbox2 = gtk_hbox_new(FALSE, 4); |
995 |
|
|
gtk_widget_show(hbox2); |
996 |
|
|
|
997 |
|
|
char val[32]; |
998 |
|
|
sprintf(val, GetString(STR_RAMSIZE_FMT), int(min)); |
999 |
|
|
label = gtk_label_new(val); |
1000 |
|
|
gtk_widget_show(label); |
1001 |
|
|
gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0); |
1002 |
|
|
|
1003 |
|
|
sprintf(val, GetString(STR_RAMSIZE_FMT), int(max)); |
1004 |
|
|
label = gtk_label_new(val); |
1005 |
|
|
gtk_widget_show(label); |
1006 |
|
|
gtk_box_pack_end(GTK_BOX(hbox2), label, FALSE, FALSE, 0); |
1007 |
|
|
gtk_box_pack_start(GTK_BOX(vbox), hbox2, TRUE, TRUE, 0); |
1008 |
|
|
gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0); |
1009 |
|
|
gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0); |
1010 |
|
|
|
1011 |
|
|
static const opt_desc options[] = { |
1012 |
|
|
{STR_MODELID_5_LAB, GTK_SIGNAL_FUNC(mn_modelid_5)}, |
1013 |
|
|
{STR_MODELID_14_LAB, GTK_SIGNAL_FUNC(mn_modelid_14)}, |
1014 |
|
|
{0, NULL} |
1015 |
|
|
}; |
1016 |
|
|
int modelid = PrefsFindInt32("modelid"), active = 0; |
1017 |
|
|
switch (modelid) { |
1018 |
|
|
case 5: active = 0; break; |
1019 |
|
|
case 14: active = 1; break; |
1020 |
|
|
} |
1021 |
|
|
menu = make_option_menu(box, STR_MODELID_CTRL, options, active); |
1022 |
|
|
|
1023 |
|
|
w_rom_file = make_entry(box, STR_ROM_FILE_CTRL, "rom"); |
1024 |
cebix |
1.8 |
|
1025 |
|
|
make_checkbox(box, STR_FPU_CTRL, "fpu", GTK_SIGNAL_FUNC(tb_fpu)); |
1026 |
cebix |
1.1 |
|
1027 |
|
|
make_checkbox(box, STR_KEYCODES_CTRL, "keycodes", GTK_SIGNAL_FUNC(tb_keycodes)); |
1028 |
|
|
w_keycode_file = make_entry(box, STR_KEYCODE_FILE_CTRL, "keycodefile"); |
1029 |
|
|
} |
1030 |
|
|
|
1031 |
|
|
|
1032 |
|
|
/* |
1033 |
|
|
* Read settings from widgets and set preferences |
1034 |
|
|
*/ |
1035 |
|
|
|
1036 |
|
|
static void read_settings(void) |
1037 |
|
|
{ |
1038 |
|
|
read_volumes_settings(); |
1039 |
|
|
read_scsi_settings(); |
1040 |
|
|
read_graphics_settings(); |
1041 |
|
|
read_serial_settings(); |
1042 |
|
|
read_memory_settings(); |
1043 |
|
|
} |