ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/prefs_editor_gtk.cpp
(Generate patch)

Comparing BasiliskII/src/Unix/prefs_editor_gtk.cpp (file contents):
Revision 1.14 by cebix, 2001-01-04T19:50:22Z vs.
Revision 1.34 by gbeauche, 2006-04-17T14:25:57Z

# Line 1 | Line 1
1   /*
2   *  prefs_editor_gtk.cpp - Preferences editor, Unix implementation using GTK+
3   *
4 < *  Basilisk II (C) 1997-2000 Christian Bauer
4 > *  Basilisk II (C) 1997-2005 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
# Line 28 | Line 28
28   #include <net/if.h>
29   #include <net/if_arp.h>
30  
31 + #ifdef HAVE_GNOMEUI
32 + #include <gnome.h>
33 + #endif
34 +
35   #include "user_strings.h"
36   #include "version.h"
37   #include "cdrom.h"
# Line 35 | Line 39
39   #include "prefs.h"
40   #include "prefs_editor.h"
41  
42 + #define DEBUG 0
43 + #include "debug.h"
44 +
45  
46   // Global variables
47   static GtkWidget *win;                          // Preferences window
# Line 48 | Line 55 | static void create_graphics_pane(GtkWidg
55   static void create_input_pane(GtkWidget *top);
56   static void create_serial_pane(GtkWidget *top);
57   static void create_memory_pane(GtkWidget *top);
58 + static void create_jit_pane(GtkWidget *top);
59   static void read_settings(void);
60  
61  
# Line 55 | Line 63 | static void read_settings(void);
63   *  Utility functions
64   */
65  
66 + #if ! GLIB_CHECK_VERSION(2,0,0)
67 + #define G_OBJECT(obj)                                                   GTK_OBJECT(obj)
68 + #define g_object_get_data(obj, key)                             gtk_object_get_data((obj), (key))
69 + #define g_object_set_data(obj, key, data)               gtk_object_set_data((obj), (key), (data))
70 + #endif
71 +
72   struct opt_desc {
73          int label_id;
74          GtkSignalFunc func;
75   };
76  
77 + struct combo_desc {
78 +        int label_id;
79 + };
80 +
81 + struct file_req_assoc {
82 +        file_req_assoc(GtkWidget *r, GtkWidget *e) : req(r), entry(e) {}
83 +        GtkWidget *req;
84 +        GtkWidget *entry;
85 + };
86 +
87 + static void cb_browse_ok(GtkWidget *button, file_req_assoc *assoc)
88 + {
89 +        gchar *file = (char *)gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req));
90 +        gtk_entry_set_text(GTK_ENTRY(assoc->entry), file);
91 +        gtk_widget_destroy(assoc->req);
92 +        delete assoc;
93 + }
94 +
95 + static void cb_browse(GtkWidget *widget, void *user_data)
96 + {
97 +        GtkWidget *req = gtk_file_selection_new(GetString(STR_BROWSE_TITLE));
98 +        gtk_signal_connect_object(GTK_OBJECT(req), "delete_event", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(req));
99 +        gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(req)->ok_button), "clicked", GTK_SIGNAL_FUNC(cb_browse_ok), new file_req_assoc(req, (GtkWidget *)user_data));
100 +        gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(req)->cancel_button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(req));
101 +        gtk_widget_show(req);
102 + }
103 +
104 + static GtkWidget *make_browse_button(GtkWidget *entry)
105 + {
106 +        GtkWidget *button;
107 +
108 +        button = gtk_button_new_with_label(GetString(STR_BROWSE_CTRL));
109 +        gtk_widget_show(button);
110 +        gtk_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc)cb_browse, (void *)entry);
111 +        return button;
112 + }
113 +
114   static void add_menu_item(GtkWidget *menu, int label_id, GtkSignalFunc func)
115   {
116          GtkWidget *item = gtk_menu_item_new_with_label(GetString(label_id));
# Line 73 | Line 124 | static GtkWidget *make_pane(GtkWidget *n
124          GtkWidget *frame, *label, *box;
125  
126          frame = gtk_frame_new(NULL);
127 <        gtk_widget_show(frame);
77 <        gtk_container_border_width(GTK_CONTAINER(frame), 4);
78 <
79 <        label = gtk_label_new(GetString(title_id));
80 <        gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, label);
127 >        gtk_container_set_border_width(GTK_CONTAINER(frame), 4);
128  
129          box = gtk_vbox_new(FALSE, 4);
83        gtk_widget_show(box);
130          gtk_container_set_border_width(GTK_CONTAINER(box), 4);
131          gtk_container_add(GTK_CONTAINER(frame), box);
132 +
133 +        gtk_widget_show_all(frame);
134 +
135 +        label = gtk_label_new(GetString(title_id));
136 +        gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, label);
137          return box;
138   }
139  
# Line 123 | Line 174 | static GtkWidget *make_table(GtkWidget *
174          return table;
175   }
176  
177 + static GtkWidget *table_make_option_menu(GtkWidget *table, int row, int label_id, const opt_desc *options, int active)
178 + {
179 +        GtkWidget *label, *opt, *menu;
180 +
181 +        label = gtk_label_new(GetString(label_id));
182 +        gtk_widget_show(label);
183 +        gtk_table_attach(GTK_TABLE(table), label, 0, 1, row, row + 1, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
184 +
185 +        opt = gtk_option_menu_new();
186 +        gtk_widget_show(opt);
187 +        menu = gtk_menu_new();
188 +
189 +        while (options->label_id) {
190 +                add_menu_item(menu, options->label_id, options->func);
191 +                options++;
192 +        }
193 +        gtk_menu_set_active(GTK_MENU(menu), active);
194 +
195 +        gtk_option_menu_set_menu(GTK_OPTION_MENU(opt), menu);
196 +        gtk_table_attach(GTK_TABLE(table), opt, 1, 2, row, row + 1, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
197 +        return menu;
198 + }
199 +
200 + static GtkWidget *table_make_combobox(GtkWidget *table, int row, int label_id, const char *default_value, GList *glist)
201 + {
202 +        GtkWidget *label, *combo;
203 +        char str[32];
204 +
205 +        label = gtk_label_new(GetString(label_id));
206 +        gtk_widget_show(label);
207 +        gtk_table_attach(GTK_TABLE(table), label, 0, 1, row, row + 1, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
208 +        
209 +        combo = gtk_combo_new();
210 +        gtk_widget_show(combo);
211 +        gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
212 +
213 +        gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), default_value);
214 +        gtk_table_attach(GTK_TABLE(table), combo, 1, 2, row, row + 1, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
215 +        
216 +        return combo;
217 + }
218 +
219 + static GtkWidget *table_make_combobox(GtkWidget *table, int row, int label_id, const char *default_value, const combo_desc *options)
220 + {
221 +        GList *glist = NULL;
222 +        while (options->label_id) {
223 +                glist = g_list_append(glist, (void *)GetString(options->label_id));
224 +                options++;
225 +        }
226 +
227 +        return table_make_combobox(table, row, label_id, default_value, glist);
228 + }
229 +
230 + static GtkWidget *table_make_file_entry(GtkWidget *table, int row, int label_id, const char *prefs_item, bool only_dirs = false)
231 + {
232 +        GtkWidget *box, *label, *entry, *button;
233 +
234 +        label = gtk_label_new(GetString(label_id));
235 +        gtk_widget_show(label);
236 +        gtk_table_attach(GTK_TABLE(table), label, 0, 1, row, row + 1, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
237 +
238 +        const char *str = PrefsFindString(prefs_item);
239 +        if (str == NULL)
240 +                str = "";
241 +
242 +        box = gtk_hbox_new(FALSE, 4);
243 +        gtk_widget_show(box);
244 +        gtk_table_attach(GTK_TABLE(table), box, 1, 2, row, row + 1, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
245 +
246 +        entry = gtk_entry_new();
247 +        gtk_entry_set_text(GTK_ENTRY(entry), str);
248 +        gtk_widget_show(entry);
249 +        gtk_box_pack_start(GTK_BOX(box), entry, TRUE, TRUE, 0);
250 +
251 +        button = make_browse_button(entry);
252 +        gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
253 +        g_object_set_data(G_OBJECT(entry), "chooser_button", button);
254 +        return entry;
255 + }
256 +
257   static GtkWidget *make_option_menu(GtkWidget *top, int label_id, const opt_desc *options, int active)
258   {
259          GtkWidget *box, *label, *opt, *menu;
# Line 150 | Line 281 | static GtkWidget *make_option_menu(GtkWi
281          return menu;
282   }
283  
284 < static GtkWidget *make_entry(GtkWidget *top, int label_id, const char *prefs_item)
284 > static GtkWidget *make_file_entry(GtkWidget *top, int label_id, const char *prefs_item, bool only_dirs = false)
285   {
286          GtkWidget *box, *label, *entry;
287  
# Line 162 | Line 293 | static GtkWidget *make_entry(GtkWidget *
293          gtk_widget_show(label);
294          gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
295  
165        entry = gtk_entry_new();
166        gtk_widget_show(entry);
296          const char *str = PrefsFindString(prefs_item);
297          if (str == NULL)
298                  str = "";
299 +
300 + #ifdef HAVE_GNOMEUI
301 +        entry = gnome_file_entry_new(NULL, GetString(label_id));
302 +        if (only_dirs)
303 +                gnome_file_entry_set_directory(GNOME_FILE_ENTRY(entry), true);
304 +        gtk_entry_set_text(GTK_ENTRY(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(entry))), str);
305 + #else
306 +        entry = gtk_entry_new();
307          gtk_entry_set_text(GTK_ENTRY(entry), str);
308 + #endif
309 +        gtk_widget_show(entry);
310          gtk_box_pack_start(GTK_BOX(box), entry, TRUE, TRUE, 0);
311          return entry;
312   }
313  
314 + static const gchar *get_file_entry_path(GtkWidget *entry)
315 + {
316 + #ifdef HAVE_GNOMEUI
317 +        return gnome_file_entry_get_full_path(GNOME_FILE_ENTRY(entry), false);
318 + #else
319 +        return gtk_entry_get_text(GTK_ENTRY(entry));
320 + #endif
321 + }
322 +
323   static GtkWidget *make_checkbox(GtkWidget *top, int label_id, const char *prefs_item, GtkSignalFunc func)
324   {
325          GtkWidget *button = gtk_check_button_new_with_label(GetString(label_id));
# Line 182 | Line 330 | static GtkWidget *make_checkbox(GtkWidge
330          return button;
331   }
332  
333 + static GtkWidget *make_combobox(GtkWidget *top, int label_id, const char *prefs_item, const combo_desc *options)
334 + {
335 +        GtkWidget *box, *label, *combo;
336 +        char str[32];
337 +
338 +        box = gtk_hbox_new(FALSE, 4);
339 +        gtk_widget_show(box);
340 +        gtk_box_pack_start(GTK_BOX(top), box, FALSE, FALSE, 0);
341 +
342 +        label = gtk_label_new(GetString(label_id));
343 +        gtk_widget_show(label);
344 +        gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
345 +
346 +        GList *glist = NULL;
347 +        while (options->label_id) {
348 +                glist = g_list_append(glist, (void *)GetString(options->label_id));
349 +                options++;
350 +        }
351 +        
352 +        combo = gtk_combo_new();
353 +        gtk_widget_show(combo);
354 +        gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
355 +        
356 +        sprintf(str, "%d", PrefsFindInt32(prefs_item));
357 +        gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str);
358 +        gtk_box_pack_start(GTK_BOX(box), combo, TRUE, TRUE, 0);
359 +        
360 +        return combo;
361 + }
362  
363 +
364   /*
365   *  Show preferences editor
366   *  Returns true when user clicked on "Start", false otherwise
# Line 225 | Line 403 | static void dl_quit(GtkWidget *dialog)
403   // "About" selected
404   static void mn_about(...)
405   {
406 <        GtkWidget *dialog, *label, *button;
406 >        GtkWidget *dialog;
407  
408 <        char str[256];
409 <        sprintf(str, GetString(STR_ABOUT_TEXT1), VERSION_MAJOR, VERSION_MINOR);
410 <        strncat(str, "\n", 255);
411 <        strncat(str, GetString(STR_ABOUT_TEXT2), 255);
408 > #ifdef HAVE_GNOMEUI
409 >
410 >        char version[32];
411 >        sprintf(version, "Version %d.%d", VERSION_MAJOR, VERSION_MINOR);
412 >        const char *authors[] = {
413 >                "Christian Bauer",
414 >                "Orlando Bassotto",
415 >                "Gwenolé Beauchesne",
416 >                "Marc Chabanas",
417 >                "Marc Hellwig",
418 >                "Biill Huey",
419 >                "Brian J. Johnson",
420 >                "Jürgen Lachmann",
421 >                "Samuel Lander",
422 >                "David Lawrence",
423 >                "Lauri Pesonen",
424 >                "Bernd Schmidt",
425 >                "and others",
426 >                NULL
427 >        };
428 >        dialog = gnome_about_new(
429 >                "Basilisk II",
430 >                version,
431 >                "Copyright (C) 1997-2005 Christian Bauer",
432 >                authors,
433 >                "Basilisk II comes with ABSOLUTELY NO WARRANTY."
434 >                "This is free software, and you are welcome to redistribute it"
435 >                "under the terms of the GNU General Public License.",
436 >                NULL
437 >        );
438 >        gnome_dialog_set_parent(GNOME_DIALOG(dialog), GTK_WINDOW(win));
439 >
440 > #else
441 >
442 >        GtkWidget *label, *button;
443 >
444 >        char str[512];
445 >        sprintf(str,
446 >                "Basilisk II\nVersion %d.%d\n\n"
447 >                "Copyright (C) 1997-2005 Christian Bauer et al.\n"
448 >                "E-mail: Christian.Bauer@uni-mainz.de\n"
449 >                "http://www.uni-mainz.de/~bauec002/B2Main.html\n\n"
450 >                "Basilisk II comes with ABSOLUTELY NO\n"
451 >                "WARRANTY. This is free software, and\n"
452 >                "you are welcome to redistribute it\n"
453 >                "under the terms of the GNU General\n"
454 >                "Public License.\n",
455 >                VERSION_MAJOR, VERSION_MINOR
456 >        );
457  
458          dialog = gtk_dialog_new();
236        gtk_widget_set_usize(GTK_WIDGET(dialog), strlen(GetString(STR_ABOUT_TEXT2)) + 200, 120);
459          gtk_window_set_title(GTK_WINDOW(dialog), GetString(STR_ABOUT_TITLE));
460          gtk_container_border_width(GTK_CONTAINER(dialog), 5);
461          gtk_widget_set_uposition(GTK_WIDGET(dialog), 100, 150);
# Line 248 | Line 470 | static void mn_about(...)
470          gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), button, FALSE, FALSE, 0);
471          GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
472          gtk_widget_grab_default(button);
473 +
474 + #endif
475 +
476          gtk_widget_show(dialog);
477   }
478  
# Line 260 | Line 485 | static void mn_zap_pram(...)
485   // Menu item descriptions
486   static GtkItemFactoryEntry menu_items[] = {
487          {(gchar *)GetString(STR_PREFS_MENU_FILE_GTK),           NULL,                   NULL,                                                   0, "<Branch>"},
488 <        {(gchar *)GetString(STR_PREFS_ITEM_START_GTK),          NULL,                   GTK_SIGNAL_FUNC(cb_start),              0, NULL},
488 >        {(gchar *)GetString(STR_PREFS_ITEM_START_GTK),          "<control>S",   GTK_SIGNAL_FUNC(cb_start),              0, NULL},
489          {(gchar *)GetString(STR_PREFS_ITEM_ZAP_PRAM_GTK),       NULL,                   GTK_SIGNAL_FUNC(mn_zap_pram),   0, NULL},
490          {(gchar *)GetString(STR_PREFS_ITEM_SEPL_GTK),           NULL,                   NULL,                                                   0, "<Separator>"},
491          {(gchar *)GetString(STR_PREFS_ITEM_QUIT_GTK),           "<control>Q",   GTK_SIGNAL_FUNC(cb_quit),               0, NULL},
# Line 284 | Line 509 | bool PrefsEditor(void)
509          GtkAccelGroup *accel_group = gtk_accel_group_new();
510          GtkItemFactory *item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", accel_group);
511          gtk_item_factory_create_items(item_factory, sizeof(menu_items) / sizeof(menu_items[0]), menu_items, NULL);
512 + #if GTK_CHECK_VERSION(1,3,15)
513 +        gtk_window_add_accel_group(GTK_WINDOW(win), accel_group);
514 + #else
515          gtk_accel_group_attach(accel_group, GTK_OBJECT(win));
516 + #endif
517          GtkWidget *menu_bar = gtk_item_factory_get_widget(item_factory, "<main>");
518          gtk_widget_show(menu_bar);
519          gtk_box_pack_start(GTK_BOX(box), menu_bar, FALSE, TRUE, 0);
520  
521          GtkWidget *notebook = gtk_notebook_new();
293        gtk_widget_show(notebook);
522          gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP);
523          gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), FALSE);
524          gtk_box_pack_start(GTK_BOX(box), notebook, TRUE, TRUE, 0);
525 +        gtk_widget_realize(notebook);
526  
527          create_volumes_pane(notebook);
528          create_scsi_pane(notebook);
# Line 301 | Line 530 | bool PrefsEditor(void)
530          create_input_pane(notebook);
531          create_serial_pane(notebook);
532          create_memory_pane(notebook);
533 +        create_jit_pane(notebook);
534 +        gtk_widget_show(notebook);
535  
536          static const opt_desc buttons[] = {
537                  {STR_START_BUTTON, GTK_SIGNAL_FUNC(cb_start)},
# Line 329 | Line 560 | static void cl_selected(GtkWidget *list,
560          selected_volume = row;
561   }
562  
332 struct file_req_assoc {
333        file_req_assoc(GtkWidget *r, GtkWidget *e) : req(r), entry(e) {}
334        GtkWidget *req;
335        GtkWidget *entry;
336 };
337
563   // Volume selected for addition
564   static void add_volume_ok(GtkWidget *button, file_req_assoc *assoc)
565   {
566 <        char *file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req));
566 >        gchar *file = (gchar *)gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req));
567          gtk_clist_append(GTK_CLIST(volume_list), &file);
568          gtk_widget_destroy(assoc->req);
569          delete assoc;
# Line 347 | Line 572 | static void add_volume_ok(GtkWidget *but
572   // Volume selected for creation
573   static void create_volume_ok(GtkWidget *button, file_req_assoc *assoc)
574   {
575 <        char *file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req));
575 >        gchar *file = (gchar *)gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req));
576  
577 <        char *str = gtk_entry_get_text(GTK_ENTRY(assoc->entry));
577 >        const gchar *str = gtk_entry_get_text(GTK_ENTRY(assoc->entry));
578          int size = atoi(str);
579  
580          char cmd[1024];
# Line 423 | Line 648 | static void read_volumes_settings(void)
648                  PrefsAddString("disk", str);
649          }
650  
651 <        PrefsReplaceString("extfs", gtk_entry_get_text(GTK_ENTRY(w_extfs)));
651 >        PrefsReplaceString("extfs", get_file_entry_path(w_extfs));
652   }
653  
654   // Create "Volumes" pane
# Line 444 | Line 669 | static void create_volumes_pane(GtkWidge
669          gtk_signal_connect(GTK_OBJECT(volume_list), "select_row", GTK_SIGNAL_FUNC(cl_selected), NULL);
670          char *str;
671          int32 index = 0;
672 <        while ((str = (char *)PrefsFindString("disk", index++)) != NULL)
672 >        while ((str = const_cast<char *>(PrefsFindString("disk", index++))) != NULL)
673                  gtk_clist_append(GTK_CLIST(volume_list), &str);
674          gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), volume_list);
675          gtk_box_pack_start(GTK_BOX(box), scroll, TRUE, TRUE, 0);
# Line 459 | Line 684 | static void create_volumes_pane(GtkWidge
684          make_button_box(box, 0, buttons);
685          make_separator(box);
686  
687 <        w_extfs = make_entry(box, STR_EXTFS_CTRL, "extfs");
687 >        w_extfs = make_file_entry(box, STR_EXTFS_CTRL, "extfs", true);
688  
689          static const opt_desc options[] = {
690                  {STR_BOOT_ANY_LAB, GTK_SIGNAL_FUNC(mn_boot_any)},
# Line 478 | Line 703 | static void create_volumes_pane(GtkWidge
703  
704  
705   /*
706 + *  "JIT Compiler" pane
707 + */
708 +
709 + static GtkWidget *w_jit_fpu;
710 + static GtkWidget *w_jit_atraps;
711 + static GtkWidget *w_jit_cache_size;
712 + static GtkWidget *w_jit_lazy_flush;
713 + static GtkWidget *w_jit_follow_const_jumps;
714 +
715 + // Set sensitivity of widgets
716 + static void set_jit_sensitive(void)
717 + {
718 +        const bool jit_enabled = PrefsFindBool("jit");
719 +        gtk_widget_set_sensitive(w_jit_fpu, jit_enabled);
720 +        gtk_widget_set_sensitive(w_jit_cache_size, jit_enabled);
721 +        gtk_widget_set_sensitive(w_jit_lazy_flush, jit_enabled);
722 +        gtk_widget_set_sensitive(w_jit_follow_const_jumps, jit_enabled);
723 + }
724 +
725 + // "Use JIT Compiler" button toggled
726 + static void tb_jit(GtkWidget *widget)
727 + {
728 +        PrefsReplaceBool("jit", GTK_TOGGLE_BUTTON(widget)->active);
729 +        set_jit_sensitive();
730 + }
731 +
732 + // "Compile FPU Instructions" button toggled
733 + static void tb_jit_fpu(GtkWidget *widget)
734 + {
735 +        PrefsReplaceBool("jitfpu", GTK_TOGGLE_BUTTON(widget)->active);
736 + }
737 +
738 + // "Lazy translation cache invalidation" button toggled
739 + static void tb_jit_lazy_flush(GtkWidget *widget)
740 + {
741 +        PrefsReplaceBool("jitlazyflush", GTK_TOGGLE_BUTTON(widget)->active);
742 + }
743 +
744 + // "Translate through constant jumps (inline blocks)" button toggled
745 + static void tb_jit_follow_const_jumps(GtkWidget *widget)
746 + {
747 +        PrefsReplaceBool("jitinline", GTK_TOGGLE_BUTTON(widget)->active);
748 + }
749 +
750 + // Read settings from widgets and set preferences
751 + static void read_jit_settings(void)
752 + {
753 + #if USE_JIT
754 +        bool jit_enabled = PrefsFindBool("jit");
755 +        if (jit_enabled) {
756 +                const char *str = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(w_jit_cache_size)->entry));
757 +                PrefsReplaceInt32("jitcachesize", atoi(str));
758 +        }
759 + #endif
760 + }
761 +
762 + // Create "JIT Compiler" pane
763 + static void create_jit_pane(GtkWidget *top)
764 + {
765 + #if USE_JIT
766 +        GtkWidget *box, *table, *label, *menu;
767 +        char str[32];
768 +        
769 +        box = make_pane(top, STR_JIT_PANE_TITLE);
770 +        make_checkbox(box, STR_JIT_CTRL, "jit", GTK_SIGNAL_FUNC(tb_jit));
771 +        
772 +        w_jit_fpu = make_checkbox(box, STR_JIT_FPU_CTRL, "jitfpu", GTK_SIGNAL_FUNC(tb_jit_fpu));
773 +        
774 +        // Translation cache size
775 +        static const combo_desc options[] = {
776 +                STR_JIT_CACHE_SIZE_2MB_LAB,
777 +                STR_JIT_CACHE_SIZE_4MB_LAB,
778 +                STR_JIT_CACHE_SIZE_8MB_LAB,
779 +                STR_JIT_CACHE_SIZE_16MB_LAB,
780 +                0
781 +        };
782 +        w_jit_cache_size = make_combobox(box, STR_JIT_CACHE_SIZE_CTRL, "jitcachesize", options);
783 +        
784 +        // Lazy translation cache invalidation
785 +        w_jit_lazy_flush = make_checkbox(box, STR_JIT_LAZY_CINV_CTRL, "jitlazyflush", GTK_SIGNAL_FUNC(tb_jit_lazy_flush));
786 +
787 +        // Follow constant jumps (inline basic blocks)
788 +        w_jit_follow_const_jumps = make_checkbox(box, STR_JIT_FOLLOW_CONST_JUMPS, "jitinline", GTK_SIGNAL_FUNC(tb_jit_follow_const_jumps));
789 +
790 +        set_jit_sensitive();
791 + #endif
792 + }
793 +
794 + /*
795   *  "SCSI" pane
796   */
797  
# Line 489 | Line 803 | static void read_scsi_settings(void)
803          for (int id=0; id<7; id++) {
804                  char prefs_name[32];
805                  sprintf(prefs_name, "scsi%d", id);
806 <                const char *str = gtk_entry_get_text(GTK_ENTRY(w_scsi[id]));
806 >                const char *str = get_file_entry_path(w_scsi[id]);
807                  if (str && strlen(str))
808                          PrefsReplaceString(prefs_name, str);
809                  else
# Line 507 | Line 821 | static void create_scsi_pane(GtkWidget *
821          for (int id=0; id<7; id++) {
822                  char prefs_name[32];
823                  sprintf(prefs_name, "scsi%d", id);
824 <                w_scsi[id] = make_entry(box, STR_SCSI_ID_0 + id, prefs_name);
824 >                w_scsi[id] = make_file_entry(box, STR_SCSI_ID_0 + id, prefs_name);
825          }
826   }
827  
# Line 533 | Line 847 | static GtkWidget *l_fbdev_name, *l_fbdev
847   static char fbdev_name[256];
848   #endif
849  
850 + static GtkWidget *w_dspdevice_file, *w_mixerdevice_file;
851 +
852   // Hide/show graphics widgets
853   static void hide_show_graphics_widgets(void)
854   {
# Line 579 | Line 895 | static void mn_30hz(...) {PrefsReplaceIn
895   static void mn_60hz(...) {PrefsReplaceInt32("frameskip", 1);}
896   static void mn_dynamic(...) {PrefsReplaceInt32("frameskip", 0);}
897  
898 + // Set sensitivity of widgets
899 + static void set_graphics_sensitive(void)
900 + {
901 +        const bool sound_enabled = !PrefsFindBool("nosound");
902 +        gtk_widget_set_sensitive(w_dspdevice_file, sound_enabled);
903 +        gtk_widget_set_sensitive(w_mixerdevice_file, sound_enabled);
904 + }
905 +
906   // "Disable Sound Output" button toggled
907   static void tb_nosound(GtkWidget *widget)
908   {
909          PrefsReplaceBool("nosound", GTK_TOGGLE_BUTTON(widget)->active);
910 +        set_graphics_sensitive();
911   }
912  
913   // Read graphics preferences
# Line 637 | Line 962 | static void read_graphics_settings(void)
962                          return;
963          }
964          PrefsReplaceString("screen", pref);
965 +
966 + #ifdef ENABLE_FBDEV_DGA
967 +        str = get_file_entry_path(w_fbdevice_file);
968 +        if (str && strlen(str))
969 +                PrefsReplaceString("fbdevicefile", str);
970 +        else
971 +                PrefsRemoveItem("fbdevicefile");
972 + #endif
973 +        PrefsReplaceString("dsp", get_file_entry_path(w_dspdevice_file));
974 +        PrefsReplaceString("mixer", get_file_entry_path(w_mixerdevice_file));
975   }
976  
977   // Create "Graphics/Sound" pane
# Line 752 | Line 1087 | static void create_graphics_pane(GtkWidg
1087          gtk_entry_set_text(GTK_ENTRY(w_fbdev_name), fbdev_name);
1088          gtk_table_attach(GTK_TABLE(table), w_fbdev_name, 1, 2, 4, 5, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
1089  
1090 <        w_fbdevice_file = make_entry(box, STR_FBDEVICE_FILE_CTRL, "fbdevicefile");
1090 >        w_fbdevice_file = make_file_entry(box, STR_FBDEVICE_FILE_CTRL, "fbdevicefile");
1091   #endif
1092  
1093          make_separator(box);
1094          make_checkbox(box, STR_NOSOUND_CTRL, "nosound", GTK_SIGNAL_FUNC(tb_nosound));
1095 +        w_dspdevice_file = make_file_entry(box, STR_DSPDEVICE_FILE_CTRL, "dsp");
1096 +        w_mixerdevice_file = make_file_entry(box, STR_MIXERDEVICE_FILE_CTRL, "mixer");
1097 +
1098 +        set_graphics_sensitive();
1099  
1100          hide_show_graphics_widgets();
1101   }
# Line 772 | Line 1111 | static GtkWidget *w_mouse_wheel_lines;
1111   // Set sensitivity of widgets
1112   static void set_input_sensitive(void)
1113   {
1114 <        gtk_widget_set_sensitive(w_keycode_file, PrefsFindBool("keycodes"));
1114 >        const bool use_keycodes = PrefsFindBool("keycodes");
1115 >        gtk_widget_set_sensitive(w_keycode_file, use_keycodes);
1116 >        gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data(G_OBJECT(w_keycode_file), "chooser_button")), use_keycodes);
1117          gtk_widget_set_sensitive(w_mouse_wheel_lines, PrefsFindInt32("mousewheelmode") == 1);
1118   }
1119  
# Line 790 | Line 1131 | static void mn_wheel_cursor(...) {PrefsR
1131   // Read settings from widgets and set preferences
1132   static void read_input_settings(void)
1133   {
1134 <        const char *str = gtk_entry_get_text(GTK_ENTRY(w_keycode_file));
1134 >        const char *str = get_file_entry_path(w_keycode_file);
1135          if (str && strlen(str))
1136                  PrefsReplaceString("keycodefile", str);
1137          else
# Line 802 | Line 1143 | static void read_input_settings(void)
1143   // Create "Input" pane
1144   static void create_input_pane(GtkWidget *top)
1145   {
1146 <        GtkWidget *box, *hbox, *menu, *label;
1146 >        GtkWidget *box, *hbox, *menu, *label, *button;
1147          GtkObject *adj;
1148  
1149          box = make_pane(top, STR_INPUT_PANE_TITLE);
1150  
1151          make_checkbox(box, STR_KEYCODES_CTRL, "keycodes", GTK_SIGNAL_FUNC(tb_keycodes));
1152 <        w_keycode_file = make_entry(box, STR_KEYCODE_FILE_CTRL, "keycodefile");
1152 >
1153 >        hbox = gtk_hbox_new(FALSE, 4);
1154 >        gtk_widget_show(hbox);
1155 >        gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
1156 >
1157 >        label = gtk_label_new(GetString(STR_KEYCODES_CTRL));
1158 >        gtk_widget_show(label);
1159 >        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1160 >
1161 >        const char *str = PrefsFindString("keycodefile");
1162 >        if (str == NULL)
1163 >                str = "";
1164 >
1165 >        w_keycode_file = gtk_entry_new();
1166 >        gtk_entry_set_text(GTK_ENTRY(w_keycode_file), str);
1167 >        gtk_widget_show(w_keycode_file);
1168 >        gtk_box_pack_start(GTK_BOX(hbox), w_keycode_file, TRUE, TRUE, 0);
1169 >
1170 >        button = make_browse_button(w_keycode_file);
1171 >        gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1172 >        g_object_set_data(G_OBJECT(w_keycode_file), "chooser_button", button);
1173  
1174          make_separator(box);
1175  
# Line 845 | Line 1206 | static void create_input_pane(GtkWidget
1206   *  "Serial/Network" pane
1207   */
1208  
1209 < static GtkWidget *w_seriala, *w_serialb, *w_ether;
1209 > static GtkWidget *w_seriala, *w_serialb, *w_ether, *w_udp_port;
1210 >
1211 > // Set sensitivity of widgets
1212 > static void set_serial_sensitive(void)
1213 > {
1214 > #if SUPPORTS_UDP_TUNNEL
1215 >        gtk_widget_set_sensitive(w_ether, !PrefsFindBool("udptunnel"));
1216 >        gtk_widget_set_sensitive(w_udp_port, PrefsFindBool("udptunnel"));
1217 > #endif
1218 > }
1219 >
1220 > // "Tunnel AppleTalk over IP" button toggled
1221 > static void tb_udptunnel(GtkWidget *widget)
1222 > {
1223 >        PrefsReplaceBool("udptunnel", GTK_TOGGLE_BUTTON(widget)->active);
1224 >        set_serial_sensitive();
1225 > }
1226  
1227   // Read settings from widgets and set preferences
1228   static void read_serial_settings(void)
# Line 863 | Line 1240 | static void read_serial_settings(void)
1240                  PrefsReplaceString("ether", str);
1241          else
1242                  PrefsRemoveItem("ether");
1243 +
1244 + #if SUPPORTS_UDP_TUNNEL
1245 +        PrefsReplaceInt32("udpport", gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(w_udp_port)));
1246 + #endif
1247   }
1248  
1249   // Add names of serial devices
# Line 936 | Line 1317 | static GList *add_ether_names(void)
1317                  }
1318                  close(s);
1319          }
1320 + #ifdef HAVE_SLIRP
1321 +        static char s_slirp[] = "slirp";
1322 +        glist = g_list_append(glist, s_slirp);
1323 + #endif
1324          if (glist)
1325                  g_list_sort(glist, gl_str_cmp);
1326          else
# Line 946 | Line 1331 | static GList *add_ether_names(void)
1331   // Create "Serial/Network" pane
1332   static void create_serial_pane(GtkWidget *top)
1333   {
1334 <        GtkWidget *box, *table, *label, *combo, *sep;
1335 <        GList *glist = add_serial_names();
1334 >        GtkWidget *box, *hbox, *table, *label, *combo, *sep;
1335 >        GtkObject *adj;
1336  
1337          box = make_pane(top, STR_SERIAL_NETWORK_PANE_TITLE);
1338          table = make_table(box, 2, 4);
# Line 956 | Line 1341 | static void create_serial_pane(GtkWidget
1341          gtk_widget_show(label);
1342          gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
1343  
1344 +        GList *glist = add_serial_names();
1345          combo = gtk_combo_new();
1346          gtk_widget_show(combo);
1347          gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
# Line 998 | Line 1384 | static void create_serial_pane(GtkWidget
1384          gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str);
1385          gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 3, 4, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
1386          w_ether = GTK_COMBO(combo)->entry;
1387 +
1388 + #if SUPPORTS_UDP_TUNNEL
1389 +        make_checkbox(box, STR_UDPTUNNEL_CTRL, "udptunnel", GTK_SIGNAL_FUNC(tb_udptunnel));
1390 +
1391 +        hbox = gtk_hbox_new(FALSE, 4);
1392 +        gtk_widget_show(hbox);
1393 +        gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
1394 +
1395 +        label = gtk_label_new(GetString(STR_UDPPORT_CTRL));
1396 +        gtk_widget_show(label);
1397 +        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1398 +
1399 +        adj = gtk_adjustment_new(PrefsFindInt32("udpport"), 1, 65535, 1, 5, 0);
1400 +        w_udp_port = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 0.0, 0);
1401 +        gtk_widget_show(w_udp_port);
1402 +        gtk_box_pack_start(GTK_BOX(hbox), w_udp_port, FALSE, FALSE, 0);
1403 + #endif
1404 +
1405 +        set_serial_sensitive();
1406   }
1407  
1408  
# Line 1005 | Line 1410 | static void create_serial_pane(GtkWidget
1410   *  "Memory/Misc" pane
1411   */
1412  
1413 < static GtkObject *w_ramsize_adj;
1413 > static GtkWidget *w_ramsize;
1414   static GtkWidget *w_rom_file;
1415  
1416 + // "Ignore SEGV" button toggled
1417 + #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
1418 + static void tb_ignoresegv(GtkWidget *widget)
1419 + {
1420 +        PrefsReplaceBool("ignoresegv", GTK_TOGGLE_BUTTON(widget)->active);
1421 + }
1422 + #endif
1423 +
1424   // Model ID selected
1425   static void mn_modelid_5(...) {PrefsReplaceInt32("modelid", 5);}
1426   static void mn_modelid_14(...) {PrefsReplaceInt32("modelid", 14);}
# Line 1022 | Line 1435 | static void mn_cpu_68040(...) {PrefsRepl
1435   // Read settings from widgets and set preferences
1436   static void read_memory_settings(void)
1437   {
1438 <        PrefsReplaceInt32("ramsize", int(GTK_ADJUSTMENT(w_ramsize_adj)->value) << 20);
1438 >        const char *str = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(w_ramsize)->entry));
1439 >        PrefsReplaceInt32("ramsize", atoi(str) << 20);
1440  
1441 <        const char *str = gtk_entry_get_text(GTK_ENTRY(w_rom_file));
1441 >        str = get_file_entry_path(w_rom_file);
1442          if (str && strlen(str))
1443                  PrefsReplaceString("rom", str);
1444          else
# Line 1035 | Line 1449 | static void read_memory_settings(void)
1449   // Create "Memory/Misc" pane
1450   static void create_memory_pane(GtkWidget *top)
1451   {
1452 <        GtkWidget *box, *hbox, *vbox, *hbox2, *label, *scale, *menu;
1452 >        GtkWidget *box, *hbox, *table, *label, *menu;
1453  
1454          box = make_pane(top, STR_MEMORY_MISC_PANE_TITLE);
1455 +        table = make_table(box, 2, 5);
1456  
1457 <        hbox = gtk_hbox_new(FALSE, 4);
1458 <        gtk_widget_show(hbox);
1459 <
1460 <        label = gtk_label_new(GetString(STR_RAMSIZE_SLIDER));
1461 <        gtk_widget_show(label);
1462 <        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1463 <
1464 <        vbox = gtk_vbox_new(FALSE, 4);
1465 <        gtk_widget_show(vbox);
1466 <
1467 <        gfloat min, max;
1468 <        min = 1;
1469 <        max = 1024;
1470 <        w_ramsize_adj = gtk_adjustment_new(min, min, max, 1, 16, 0);
1471 <        gtk_adjustment_set_value(GTK_ADJUSTMENT(w_ramsize_adj), PrefsFindInt32("ramsize") >> 20);
1472 <
1058 <        scale = gtk_hscale_new(GTK_ADJUSTMENT(w_ramsize_adj));
1059 <        gtk_widget_show(scale);
1060 <        gtk_scale_set_digits(GTK_SCALE(scale), 0);
1061 <        gtk_box_pack_start(GTK_BOX(vbox), scale, TRUE, TRUE, 0);
1062 <
1063 <        hbox2 = gtk_hbox_new(FALSE, 4);
1064 <        gtk_widget_show(hbox2);
1065 <
1066 <        char val[32];
1067 <        sprintf(val, GetString(STR_RAMSIZE_FMT), int(min));
1068 <        label = gtk_label_new(val);
1069 <        gtk_widget_show(label);
1070 <        gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0);
1071 <
1072 <        sprintf(val, GetString(STR_RAMSIZE_FMT), int(max));
1073 <        label = gtk_label_new(val);
1074 <        gtk_widget_show(label);
1075 <        gtk_box_pack_end(GTK_BOX(hbox2), label, FALSE, FALSE, 0);
1076 <        gtk_box_pack_start(GTK_BOX(vbox), hbox2, TRUE, TRUE, 0);
1077 <        gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
1078 <        gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
1457 >        static const combo_desc options[] = {
1458 >                STR_RAMSIZE_2MB_LAB,
1459 >                STR_RAMSIZE_4MB_LAB,
1460 >                STR_RAMSIZE_8MB_LAB,
1461 >                STR_RAMSIZE_16MB_LAB,
1462 >                STR_RAMSIZE_32MB_LAB,
1463 >                STR_RAMSIZE_64MB_LAB,
1464 >                STR_RAMSIZE_128MB_LAB,
1465 >                STR_RAMSIZE_256MB_LAB,
1466 >                STR_RAMSIZE_512MB_LAB,
1467 >                STR_RAMSIZE_1024MB_LAB,
1468 >                0
1469 >        };
1470 >        char default_ramsize[10];
1471 >        sprintf(default_ramsize, "%d", PrefsFindInt32("ramsize") >> 20);
1472 >        w_ramsize = table_make_combobox(table, 0, STR_RAMSIZE_CTRL, default_ramsize, options);
1473  
1474          static const opt_desc model_options[] = {
1475                  {STR_MODELID_5_LAB, GTK_SIGNAL_FUNC(mn_modelid_5)},
# Line 1087 | Line 1481 | static void create_memory_pane(GtkWidget
1481                  case 5: active = 0; break;
1482                  case 14: active = 1; break;
1483          }
1484 <        make_option_menu(box, STR_MODELID_CTRL, model_options, active);
1484 >        table_make_option_menu(table, 2, STR_MODELID_CTRL, model_options, active);
1485  
1486   #if EMULATED_68K
1487          static const opt_desc cpu_options[] = {
# Line 1106 | Line 1500 | static void create_memory_pane(GtkWidget
1500                  case 3: active = fpu ? 3 : 2; break;
1501                  case 4: active = 4;
1502          }
1503 <        make_option_menu(box, STR_CPU_CTRL, cpu_options, active);
1503 >        table_make_option_menu(table, 3, STR_CPU_CTRL, cpu_options, active);
1504   #endif
1505  
1506 <        w_rom_file = make_entry(box, STR_ROM_FILE_CTRL, "rom");
1506 >        w_rom_file = table_make_file_entry(table, 4, STR_ROM_FILE_CTRL, "rom");
1507 >
1508 > #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
1509 >        make_checkbox(box, STR_IGNORESEGV_CTRL, "ignoresegv", GTK_SIGNAL_FUNC(tb_ignoresegv));
1510 > #endif
1511   }
1512  
1513  
# Line 1125 | Line 1523 | static void read_settings(void)
1523          read_input_settings();
1524          read_serial_settings();
1525          read_memory_settings();
1526 +        read_jit_settings();
1527 + }
1528 +
1529 +
1530 + #ifdef STANDALONE_GUI
1531 + #include <errno.h>
1532 + #include <sys/wait.h>
1533 + #include "rpc.h"
1534 +
1535 + /*
1536 + *  Fake unused data and functions
1537 + */
1538 +
1539 + uint8 XPRAM[XPRAM_SIZE];
1540 + void MountVolume(void *fh) { }
1541 + void FileDiskLayout(loff_t size, uint8 *data, loff_t &start_byte, loff_t &real_size) { }
1542 +
1543 +
1544 + /*
1545 + *  Display alert
1546 + */
1547 +
1548 + static void dl_destroyed(void)
1549 + {
1550 +        gtk_main_quit();
1551   }
1552 +
1553 + static void display_alert(int title_id, int prefix_id, int button_id, const char *text)
1554 + {
1555 +        char str[256];
1556 +        sprintf(str, GetString(prefix_id), text);
1557 +
1558 +        GtkWidget *dialog = gtk_dialog_new();
1559 +        gtk_window_set_title(GTK_WINDOW(dialog), GetString(title_id));
1560 +        gtk_container_border_width(GTK_CONTAINER(dialog), 5);
1561 +        gtk_widget_set_uposition(GTK_WIDGET(dialog), 100, 150);
1562 +        gtk_signal_connect(GTK_OBJECT(dialog), "destroy", GTK_SIGNAL_FUNC(dl_destroyed), NULL);
1563 +
1564 +        GtkWidget *label = gtk_label_new(str);
1565 +        gtk_widget_show(label);
1566 +        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), label, TRUE, TRUE, 0);
1567 +
1568 +        GtkWidget *button = gtk_button_new_with_label(GetString(button_id));
1569 +        gtk_widget_show(button);
1570 +        gtk_signal_connect_object(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(dl_quit), GTK_OBJECT(dialog));
1571 +        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), button, FALSE, FALSE, 0);
1572 +        GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
1573 +        gtk_widget_grab_default(button);
1574 +        gtk_widget_show(dialog);
1575 +
1576 +        gtk_main();
1577 + }
1578 +
1579 +
1580 + /*
1581 + *  Display error alert
1582 + */
1583 +
1584 + void ErrorAlert(const char *text)
1585 + {
1586 +        display_alert(STR_ERROR_ALERT_TITLE, STR_GUI_ERROR_PREFIX, STR_QUIT_BUTTON, text);
1587 + }
1588 +
1589 +
1590 + /*
1591 + *  Display warning alert
1592 + */
1593 +
1594 + void WarningAlert(const char *text)
1595 + {
1596 +        display_alert(STR_WARNING_ALERT_TITLE, STR_GUI_WARNING_PREFIX, STR_OK_BUTTON, text);
1597 + }
1598 +
1599 +
1600 + /*
1601 + *  RPC handlers
1602 + */
1603 +
1604 + static int handle_ErrorAlert(rpc_connection_t *connection)
1605 + {
1606 +        D(bug("handle_ErrorAlert\n"));
1607 +
1608 +        int error;
1609 +        char *str;
1610 +        if ((error = rpc_method_get_args(connection, RPC_TYPE_STRING, &str, RPC_TYPE_INVALID)) < 0)
1611 +                return error;
1612 +
1613 +        ErrorAlert(str);
1614 +        free(str);
1615 +        return RPC_ERROR_NO_ERROR;
1616 + }
1617 +
1618 + static int handle_WarningAlert(rpc_connection_t *connection)
1619 + {
1620 +        D(bug("handle_WarningAlert\n"));
1621 +
1622 +        int error;
1623 +        char *str;
1624 +        if ((error = rpc_method_get_args(connection, RPC_TYPE_STRING, &str, RPC_TYPE_INVALID)) < 0)
1625 +                return error;
1626 +
1627 +        WarningAlert(str);
1628 +        free(str);
1629 +        return RPC_ERROR_NO_ERROR;
1630 + }
1631 +
1632 + static int handle_Exit(rpc_connection_t *connection)
1633 + {
1634 +        D(bug("handle_Exit\n"));
1635 +
1636 +        return RPC_ERROR_NO_ERROR;
1637 + }
1638 +
1639 +
1640 + /*
1641 + *  Start standalone GUI
1642 + */
1643 +
1644 + int main(int argc, char *argv[])
1645 + {
1646 + #ifdef HAVE_GNOMEUI
1647 +        // Init GNOME/GTK
1648 +        char version[16];
1649 +        sprintf(version, "%d.%d", VERSION_MAJOR, VERSION_MINOR);
1650 +        gnome_init("Basilisk II", version, argc, argv);
1651 + #else
1652 +        // Init GTK
1653 +        gtk_set_locale();
1654 +        gtk_init(&argc, &argv);
1655 + #endif
1656 +
1657 +        // Read preferences
1658 +        PrefsInit(argc, argv);
1659 +
1660 +        // Show preferences editor
1661 +        bool start = PrefsEditor();
1662 +
1663 +        // Exit preferences
1664 +        PrefsExit();
1665 +
1666 +        // Transfer control to the executable
1667 +        if (start) {
1668 +                char gui_connection_path[64];
1669 +                sprintf(gui_connection_path, "/org/BasiliskII/GUI/%d", getpid());
1670 +                
1671 +                int pid = fork();
1672 +                if (pid == 0) {                 // Child
1673 +                        char b2_path[PATH_MAX];
1674 +                        strcpy(b2_path, argv[0]);
1675 +                        char *p = strrchr(b2_path, '/');
1676 +                        p = p ? p + 1 : b2_path;
1677 +                        *p = '\0';
1678 +                        strcat(b2_path, "BasiliskII");
1679 +                        execl(b2_path, b2_path, "--gui-connection", gui_connection_path, (char *)NULL);
1680 +
1681 +                        char str[256];
1682 +                        sprintf(str, GetString(STR_NO_B2_EXE_FOUND), b2_path, strerror(errno));
1683 +                        ErrorAlert(str);
1684 +                        return 1;
1685 +                }
1686 +                else {                                  // Parent
1687 +                        rpc_connection_t *connection;
1688 +                        if ((connection = rpc_init_server(gui_connection_path)) == NULL) {
1689 +                                printf("ERROR: failed to initialize GUI-side RPC server connection\n");
1690 +                                return 1;
1691 +                        }
1692 +
1693 +                        static const rpc_method_descriptor_t vtable[] = {
1694 +                                { RPC_METHOD_ERROR_ALERT,                       handle_ErrorAlert },
1695 +                                { RPC_METHOD_WARNING_ALERT,                     handle_WarningAlert },
1696 +                                { RPC_METHOD_EXIT,                                      handle_Exit }
1697 +                        };
1698 +                        if (rpc_method_add_callbacks(connection, vtable, sizeof(vtable) / sizeof(vtable[0])) < 0) {
1699 +                                printf("ERROR: failed to setup GUI method callbacks\n");
1700 +                                return 1;
1701 +                        }
1702 +
1703 +                        if (rpc_listen(connection) < 0) {
1704 +                                printf("ERROR: failed to initialize RPC server thread\n");
1705 +                                return 1;
1706 +                        }
1707 +
1708 +                        int status, ret = -1;
1709 +                        while (waitpid(pid, &status, 0) != pid)
1710 +                                ;
1711 +                        if (WIFEXITED(status))
1712 +                                ret = WEXITSTATUS(status);
1713 +
1714 +                        rpc_exit(connection);
1715 +                        return ret;
1716 +                }
1717 +        }
1718 +
1719 +        return 0;
1720 + }
1721 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines