ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/prefs_editor_gtk.cpp
Revision: 1.1.1.1 (vendor branch)
Committed: 1999-10-03T14:16:25Z (25 years, 2 months ago) by cebix
Branch: cebix
CVS Tags: start
Changes since 1.1: +0 -0 lines
Error occurred while calculating annotation data.
Log Message:
Imported sources

File Contents

# Content
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 {GetString(STR_PREFS_MENU_FILE_GTK), NULL, NULL, 0, "<Branch>"},
262 {GetString(STR_PREFS_ITEM_START_GTK), NULL, GTK_SIGNAL_FUNC(cb_start), 0, NULL},
263 {GetString(STR_PREFS_ITEM_ZAP_PRAM_GTK), NULL, GTK_SIGNAL_FUNC(mn_zap_pram), 0, NULL},
264 {GetString(STR_PREFS_ITEM_SEPL_GTK), NULL, NULL, 0, "<Separator>"},
265 {GetString(STR_PREFS_ITEM_QUIT_GTK), "<control>Q", GTK_SIGNAL_FUNC(cb_quit), 0, NULL},
266 {GetString(STR_HELP_MENU_GTK), NULL, NULL, 0, "<LastBranch>"},
267 {GetString(STR_HELP_ITEM_ABOUT_GTK), NULL, GTK_SIGNAL_FUNC(mn_about), 0, NULL}
268 };
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 gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), TRUE);
295 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 static GtkWidget *volume_list;
322 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 }
424
425 // Create "Volumes" pane
426 static void create_volumes_pane(GtkWidget *top)
427 {
428 GtkWidget *box, *scroll, *menu;
429
430 box = make_pane(top, STR_VOLUMES_PANE_TITLE);
431
432 scroll = gtk_scrolled_window_new(NULL, NULL);
433 gtk_widget_show(scroll);
434 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
435 volume_list = gtk_clist_new(1);
436 gtk_widget_show(volume_list);
437 gtk_clist_set_selection_mode(GTK_CLIST(volume_list), GTK_SELECTION_SINGLE);
438 gtk_clist_set_shadow_type(GTK_CLIST(volume_list), GTK_SHADOW_NONE);
439 gtk_signal_connect(GTK_OBJECT(volume_list), "select_row", GTK_SIGNAL_FUNC(cl_selected), NULL);
440 char *str;
441 int32 index = 0;
442 while ((str = (char *)PrefsFindString("disk", index++)) != NULL)
443 gtk_clist_append(GTK_CLIST(volume_list), &str);
444 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), volume_list);
445 gtk_box_pack_start(GTK_BOX(box), scroll, TRUE, TRUE, 0);
446 selected_volume = 0;
447
448 static const opt_desc buttons[] = {
449 {STR_ADD_VOLUME_BUTTON, GTK_SIGNAL_FUNC(cb_add_volume)},
450 {STR_CREATE_VOLUME_BUTTON, GTK_SIGNAL_FUNC(cb_create_volume)},
451 {STR_REMOVE_VOLUME_BUTTON, GTK_SIGNAL_FUNC(cb_remove_volume)},
452 {0, NULL},
453 };
454 make_button_box(box, 0, buttons);
455 make_separator(box);
456
457 static const opt_desc options[] = {
458 {STR_BOOT_ANY_LAB, GTK_SIGNAL_FUNC(mn_boot_any)},
459 {STR_BOOT_CDROM_LAB, GTK_SIGNAL_FUNC(mn_boot_cdrom)},
460 {0, NULL}
461 };
462 int bootdriver = PrefsFindInt16("bootdriver"), active = 0;
463 switch (bootdriver) {
464 case 0: active = 0; break;
465 case CDROMRefNum: active = 1; break;
466 }
467 menu = make_option_menu(box, STR_BOOTDRIVER_CTRL, options, active);
468
469 make_checkbox(box, STR_NOCDROM_CTRL, "nocdrom", GTK_SIGNAL_FUNC(tb_nocdrom));
470 }
471
472
473 /*
474 * "SCSI" pane
475 */
476
477 static GtkWidget *w_scsi[7];
478
479 // Read settings from widgets and set preferences
480 static void read_scsi_settings(void)
481 {
482 for (int id=0; id<7; id++) {
483 char prefs_name[32];
484 sprintf(prefs_name, "scsi%d", id);
485 const char *str = gtk_entry_get_text(GTK_ENTRY(w_scsi[id]));
486 if (str && strlen(str))
487 PrefsReplaceString(prefs_name, str);
488 else
489 PrefsRemoveItem(prefs_name);
490 }
491 }
492
493 // Create "SCSI" pane
494 static void create_scsi_pane(GtkWidget *top)
495 {
496 GtkWidget *box;
497
498 box = make_pane(top, STR_SCSI_PANE_TITLE);
499
500 for (int id=0; id<7; id++) {
501 char prefs_name[32];
502 sprintf(prefs_name, "scsi%d", id);
503 w_scsi[id] = make_entry(box, STR_SCSI_ID_0 + id, prefs_name);
504 }
505 }
506
507
508 /*
509 * "Graphics/Sound" pane
510 */
511
512 // Display types
513 enum {
514 DISPLAY_WINDOW,
515 DISPLAY_SCREEN
516 };
517
518 static GtkWidget *w_frameskip, *w_display_x, *w_display_y;
519 static GtkWidget *l_frameskip, *l_display_x, *l_display_y;
520 static int display_type;
521 static int dis_width, dis_height;
522
523 // Hide/show graphics widgets
524 static void hide_show_graphics_widgets(void)
525 {
526 switch (display_type) {
527 case DISPLAY_WINDOW:
528 gtk_widget_show(w_frameskip); gtk_widget_show(l_frameskip);
529 gtk_widget_show(w_display_x); gtk_widget_show(l_display_x);
530 gtk_widget_show(w_display_y); gtk_widget_show(l_display_y);
531 break;
532 case DISPLAY_SCREEN:
533 gtk_widget_hide(w_frameskip); gtk_widget_hide(l_frameskip);
534 gtk_widget_hide(w_display_x); gtk_widget_hide(l_display_x);
535 gtk_widget_hide(w_display_y); gtk_widget_hide(l_display_y);
536 break;
537 }
538 }
539
540 // "Window" video type selected
541 static void mn_window(...)
542 {
543 display_type = DISPLAY_WINDOW;
544 hide_show_graphics_widgets();
545 }
546
547 // "Fullscreen" video type selected
548 static void mn_fullscreen(...)
549 {
550 display_type = DISPLAY_SCREEN;
551 hide_show_graphics_widgets();
552 }
553
554 // "5 Hz".."60Hz" selected
555 static void mn_5hz(...) {PrefsReplaceInt32("frameskip", 12);}
556 static void mn_7hz(...) {PrefsReplaceInt32("frameskip", 8);}
557 static void mn_10hz(...) {PrefsReplaceInt32("frameskip", 6);}
558 static void mn_15hz(...) {PrefsReplaceInt32("frameskip", 4);}
559 static void mn_30hz(...) {PrefsReplaceInt32("frameskip", 2);}
560 static void mn_60hz(...) {PrefsReplaceInt32("frameskip", 1);}
561
562 // "Disable Sound Output" button toggled
563 static void tb_nosound(GtkWidget *widget)
564 {
565 PrefsReplaceBool("nosound", GTK_TOGGLE_BUTTON(widget)->active);
566 }
567
568 // Read graphics preferences
569 static void parse_graphics_prefs(void)
570 {
571 display_type = DISPLAY_WINDOW;
572 dis_width = 512;
573 dis_height = 384;
574
575 const char *str = PrefsFindString("screen");
576 if (str) {
577 if (sscanf(str, "win/%d/%d", &dis_width, &dis_height) == 2)
578 display_type = DISPLAY_WINDOW;
579 else if (strcmp(str, "dga") == 0)
580 display_type = DISPLAY_SCREEN;
581 }
582 }
583
584 // Read settings from widgets and set preferences
585 static void read_graphics_settings(void)
586 {
587 const char *str;
588
589 str = gtk_entry_get_text(GTK_ENTRY(w_display_x));
590 dis_width = atoi(str);
591
592 str = gtk_entry_get_text(GTK_ENTRY(w_display_y));
593 dis_height = atoi(str);
594
595 char pref[256];
596 switch (display_type) {
597 case DISPLAY_WINDOW:
598 sprintf(pref, "win/%d/%d", dis_width, dis_height);
599 break;
600 case DISPLAY_SCREEN:
601 strcpy(pref, "dga");
602 break;
603 default:
604 PrefsRemoveItem("screen");
605 return;
606 }
607 PrefsReplaceString("screen", pref);
608 }
609
610 // Create "Graphics/Sound" pane
611 static void create_graphics_pane(GtkWidget *top)
612 {
613 GtkWidget *box, *table, *label, *opt, *menu;
614 char str[32];
615
616 parse_graphics_prefs();
617
618 box = make_pane(top, STR_GRAPHICS_SOUND_PANE_TITLE);
619 table = make_table(box, 2, 4);
620
621 label = gtk_label_new(GetString(STR_VIDEO_TYPE_CTRL));
622 gtk_widget_show(label);
623 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
624
625 opt = gtk_option_menu_new();
626 gtk_widget_show(opt);
627 menu = gtk_menu_new();
628 add_menu_item(menu, STR_WINDOW_LAB, GTK_SIGNAL_FUNC(mn_window));
629 add_menu_item(menu, STR_FULLSCREEN_LAB, GTK_SIGNAL_FUNC(mn_fullscreen));
630 switch (display_type) {
631 case DISPLAY_WINDOW:
632 gtk_menu_set_active(GTK_MENU(menu), 0);
633 break;
634 case DISPLAY_SCREEN:
635 gtk_menu_set_active(GTK_MENU(menu), 1);
636 break;
637 }
638 gtk_option_menu_set_menu(GTK_OPTION_MENU(opt), menu);
639 gtk_table_attach(GTK_TABLE(table), opt, 1, 2, 0, 1, (GtkAttachOptions)GTK_FILL, (GtkAttachOptions)0, 4, 4);
640
641 l_frameskip = gtk_label_new(GetString(STR_FRAMESKIP_CTRL));
642 gtk_widget_show(l_frameskip);
643 gtk_table_attach(GTK_TABLE(table), l_frameskip, 0, 1, 1, 2, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
644
645 w_frameskip = gtk_option_menu_new();
646 gtk_widget_show(w_frameskip);
647 menu = gtk_menu_new();
648 add_menu_item(menu, STR_REF_5HZ_LAB, GTK_SIGNAL_FUNC(mn_5hz));
649 add_menu_item(menu, STR_REF_7_5HZ_LAB, GTK_SIGNAL_FUNC(mn_7hz));
650 add_menu_item(menu, STR_REF_10HZ_LAB, GTK_SIGNAL_FUNC(mn_10hz));
651 add_menu_item(menu, STR_REF_15HZ_LAB, GTK_SIGNAL_FUNC(mn_15hz));
652 add_menu_item(menu, STR_REF_30HZ_LAB, GTK_SIGNAL_FUNC(mn_30hz));
653 add_menu_item(menu, STR_REF_60HZ_LAB, GTK_SIGNAL_FUNC(mn_60hz));
654 int frameskip = PrefsFindInt32("frameskip");
655 switch (frameskip) {
656 case 12:
657 gtk_menu_set_active(GTK_MENU(menu), 0);
658 break;
659 case 8:
660 gtk_menu_set_active(GTK_MENU(menu), 1);
661 break;
662 case 6:
663 gtk_menu_set_active(GTK_MENU(menu), 2);
664 break;
665 case 4:
666 gtk_menu_set_active(GTK_MENU(menu), 3);
667 break;
668 case 2:
669 gtk_menu_set_active(GTK_MENU(menu), 4);
670 break;
671 case 1:
672 gtk_menu_set_active(GTK_MENU(menu), 5);
673 break;
674 }
675 gtk_option_menu_set_menu(GTK_OPTION_MENU(w_frameskip), menu);
676 gtk_table_attach(GTK_TABLE(table), w_frameskip, 1, 2, 1, 2, (GtkAttachOptions)GTK_FILL, (GtkAttachOptions)0, 4, 4);
677
678 l_display_x = gtk_label_new(GetString(STR_DISPLAY_X_CTRL));
679 gtk_widget_show(l_display_x);
680 gtk_table_attach(GTK_TABLE(table), l_display_x, 0, 1, 2, 3, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
681
682 w_display_x = gtk_entry_new();
683 gtk_widget_show(w_display_x);
684 sprintf(str, "%d", dis_width);
685 gtk_entry_set_text(GTK_ENTRY(w_display_x), str);
686 gtk_table_attach(GTK_TABLE(table), w_display_x, 1, 2, 2, 3, (GtkAttachOptions)GTK_FILL, (GtkAttachOptions)0, 4, 4);
687
688 l_display_y = gtk_label_new(GetString(STR_DISPLAY_Y_CTRL));
689 gtk_widget_show(l_display_y);
690 gtk_table_attach(GTK_TABLE(table), l_display_y, 0, 1, 3, 4, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
691
692 w_display_y = gtk_entry_new();
693 gtk_widget_show(w_display_y);
694 sprintf(str, "%d", dis_height);
695 gtk_entry_set_text(GTK_ENTRY(w_display_y), str);
696 gtk_table_attach(GTK_TABLE(table), w_display_y, 1, 2, 3, 4, (GtkAttachOptions)GTK_FILL, (GtkAttachOptions)0, 4, 4);
697
698 make_checkbox(box, STR_NOSOUND_CTRL, "nosound", GTK_SIGNAL_FUNC(tb_nosound));
699
700 hide_show_graphics_widgets();
701 }
702
703
704 /*
705 * "Serial/Network" pane
706 */
707
708 static GtkWidget *w_seriala, *w_serialb, *w_ether;
709
710 // Read settings from widgets and set preferences
711 static void read_serial_settings(void)
712 {
713 const char *str;
714
715 str = gtk_entry_get_text(GTK_ENTRY(w_seriala));
716 PrefsReplaceString("seriala", str);
717
718 str = gtk_entry_get_text(GTK_ENTRY(w_serialb));
719 PrefsReplaceString("serialb", str);
720
721 str = gtk_entry_get_text(GTK_ENTRY(w_ether));
722 if (str && strlen(str))
723 PrefsReplaceString("ether", str);
724 else
725 PrefsRemoveItem("ether");
726 }
727
728 // Add names of serial devices
729 static gint gl_str_cmp(gconstpointer a, gconstpointer b)
730 {
731 return strcmp((char *)a, (char *)b);
732 }
733
734 static GList *add_serial_names(void)
735 {
736 GList *glist = NULL;
737
738 // Search /dev for ttyS* and lp*
739 DIR *d = opendir("/dev");
740 if (d) {
741 struct dirent *de;
742 while ((de = readdir(d)) != NULL) {
743 #if defined(__linux__)
744 if (strncmp(de->d_name, "ttyS", 4) == 0 || strncmp(de->d_name, "lp", 2) == 0) {
745 #elif defined(__FreeBSD__)
746 if (strncmp(de->d_name, "cuaa", 4) == 0 || strncmp(de->d_name, "lpt", 3) == 0) {
747 #elif defined(sgi)
748 if (strncmp(de->d_name, "ttyf", 4) == 0 || strncmp(de->d_name, "plp", 3) == 0) {
749 #else
750 if (false) {
751 #endif
752 char *str = new char[64];
753 sprintf(str, "/dev/%s", de->d_name);
754 glist = g_list_append(glist, str);
755 }
756 }
757 closedir(d);
758 }
759 if (glist)
760 g_list_sort(glist, gl_str_cmp);
761 else
762 glist = g_list_append(glist, "<none>");
763 return glist;
764 }
765
766 // Add names of ethernet interfaces
767 static GList *add_ether_names(void)
768 {
769 GList *glist = NULL;
770
771 // Get list of all Ethernet interfaces
772 int s = socket(PF_INET, SOCK_DGRAM, 0);
773 if (s >= 0) {
774 char inbuf[8192];
775 struct ifconf ifc;
776 ifc.ifc_len = sizeof(inbuf);
777 ifc.ifc_buf = inbuf;
778 if (ioctl(s, SIOCGIFCONF, &ifc) == 0) {
779 struct ifreq req, *ifr = ifc.ifc_req;
780 for (int i=0; i<ifc.ifc_len; i+=sizeof(ifreq), ifr++) {
781 req = *ifr;
782 #if defined(__FreeBSD__) || defined(sgi)
783 if (ioctl(s, SIOCGIFADDR, &req) == 0 && (req.ifr_addr.sa_family == ARPHRD_ETHER || req.ifr_addr.sa_family == ARPHRD_ETHER+1)) {
784 #else
785 if (ioctl(s, SIOCGIFHWADDR, &req) == 0 && req.ifr_hwaddr.sa_family == ARPHRD_ETHER) {
786 #endif
787 char *str = new char[64];
788 strncpy(str, ifr->ifr_name, 63);
789 glist = g_list_append(glist, str);
790 }
791 }
792 }
793 close(s);
794 }
795 if (glist)
796 g_list_sort(glist, gl_str_cmp);
797 else
798 glist = g_list_append(glist, "<none>");
799 return glist;
800 }
801
802 // Create "Serial/Network" pane
803 static void create_serial_pane(GtkWidget *top)
804 {
805 GtkWidget *box, *table, *label, *combo;
806 GList *glist = add_serial_names();
807
808 box = make_pane(top, STR_SERIAL_NETWORK_PANE_TITLE);
809 table = make_table(box, 2, 3);
810
811 label = gtk_label_new(GetString(STR_SERIALA_CTRL));
812 gtk_widget_show(label);
813 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
814
815 combo = gtk_combo_new();
816 gtk_widget_show(combo);
817 gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
818 const char *str = PrefsFindString("seriala");
819 if (str == NULL)
820 str = "";
821 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str);
822 gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 0, 1, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
823 w_seriala = GTK_COMBO(combo)->entry;
824
825 label = gtk_label_new(GetString(STR_SERIALB_CTRL));
826 gtk_widget_show(label);
827 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
828
829 combo = gtk_combo_new();
830 gtk_widget_show(combo);
831 gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
832 str = PrefsFindString("serialb");
833 if (str == NULL)
834 str = "";
835 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str);
836 gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 1, 2, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
837 w_serialb = GTK_COMBO(combo)->entry;
838
839 label = gtk_label_new(GetString(STR_ETHERNET_IF_CTRL));
840 gtk_widget_show(label);
841 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
842
843 glist = add_ether_names();
844 combo = gtk_combo_new();
845 gtk_widget_show(combo);
846 gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
847 str = PrefsFindString("ether");
848 if (str == NULL)
849 str = "";
850 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str);
851 gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 2, 3, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
852 w_ether = GTK_COMBO(combo)->entry;
853 }
854
855
856 /*
857 * "Memory/Misc" pane
858 */
859
860 static GtkObject *w_ramsize_adj;
861 static GtkWidget *w_rom_file;
862 static GtkWidget *w_keycode_file;
863
864 // Model ID selected
865 static void mn_modelid_5(...) {PrefsReplaceInt32("modelid", 5);}
866 static void mn_modelid_14(...) {PrefsReplaceInt32("modelid", 14);}
867
868 // "Use Raw Keycodes" button toggled
869 static void tb_keycodes(GtkWidget *widget)
870 {
871 PrefsReplaceBool("keycodes", GTK_TOGGLE_BUTTON(widget)->active);
872 }
873
874 // Read settings from widgets and set preferences
875 static void read_memory_settings(void)
876 {
877 PrefsReplaceInt32("ramsize", int(GTK_ADJUSTMENT(w_ramsize_adj)->value) << 20);
878
879 const char *str = gtk_entry_get_text(GTK_ENTRY(w_rom_file));
880 if (str && strlen(str))
881 PrefsReplaceString("rom", str);
882 else
883 PrefsRemoveItem("rom");
884
885 str = gtk_entry_get_text(GTK_ENTRY(w_keycode_file));
886 if (str && strlen(str))
887 PrefsReplaceString("keycodefile", str);
888 else
889 PrefsRemoveItem("keycodefile");
890 }
891
892 // Create "Memory/Misc" pane
893 static void create_memory_pane(GtkWidget *top)
894 {
895 GtkWidget *box, *vbox, *hbox, *hbox2, *label, *scale, *opt, *menu;
896
897 box = make_pane(top, STR_MEMORY_MISC_PANE_TITLE);
898
899 hbox = gtk_hbox_new(FALSE, 4);
900 gtk_widget_show(hbox);
901
902 label = gtk_label_new(GetString(STR_RAMSIZE_SLIDER));
903 gtk_widget_show(label);
904 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
905
906 vbox = gtk_vbox_new(FALSE, 4);
907 gtk_widget_show(vbox);
908
909 gfloat min, max;
910 min = 1;
911 max = 1024;
912 w_ramsize_adj = gtk_adjustment_new(min, min, max, 1, 16, 0);
913 gtk_adjustment_set_value(GTK_ADJUSTMENT(w_ramsize_adj), PrefsFindInt32("ramsize") >> 20);
914
915 scale = gtk_hscale_new(GTK_ADJUSTMENT(w_ramsize_adj));
916 gtk_widget_show(scale);
917 gtk_scale_set_digits(GTK_SCALE(scale), 0);
918 gtk_box_pack_start(GTK_BOX(vbox), scale, TRUE, TRUE, 0);
919
920 hbox2 = gtk_hbox_new(FALSE, 4);
921 gtk_widget_show(hbox2);
922
923 char val[32];
924 sprintf(val, GetString(STR_RAMSIZE_FMT), int(min));
925 label = gtk_label_new(val);
926 gtk_widget_show(label);
927 gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0);
928
929 sprintf(val, GetString(STR_RAMSIZE_FMT), int(max));
930 label = gtk_label_new(val);
931 gtk_widget_show(label);
932 gtk_box_pack_end(GTK_BOX(hbox2), label, FALSE, FALSE, 0);
933 gtk_box_pack_start(GTK_BOX(vbox), hbox2, TRUE, TRUE, 0);
934 gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
935 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
936
937 static const opt_desc options[] = {
938 {STR_MODELID_5_LAB, GTK_SIGNAL_FUNC(mn_modelid_5)},
939 {STR_MODELID_14_LAB, GTK_SIGNAL_FUNC(mn_modelid_14)},
940 {0, NULL}
941 };
942 int modelid = PrefsFindInt32("modelid"), active = 0;
943 switch (modelid) {
944 case 5: active = 0; break;
945 case 14: active = 1; break;
946 }
947 menu = make_option_menu(box, STR_MODELID_CTRL, options, active);
948
949 w_rom_file = make_entry(box, STR_ROM_FILE_CTRL, "rom");
950
951 make_checkbox(box, STR_KEYCODES_CTRL, "keycodes", GTK_SIGNAL_FUNC(tb_keycodes));
952 w_keycode_file = make_entry(box, STR_KEYCODE_FILE_CTRL, "keycodefile");
953 }
954
955
956 /*
957 * Read settings from widgets and set preferences
958 */
959
960 static void read_settings(void)
961 {
962 read_volumes_settings();
963 read_scsi_settings();
964 read_graphics_settings();
965 read_serial_settings();
966 read_memory_settings();
967 }