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

Comparing BasiliskII/src/Windows/prefs_editor_gtk.cpp (file contents):
Revision 1.3 by gbeauche, 2005-11-20T17:26:16Z vs.
Revision 1.6 by gbeauche, 2005-11-20T23:59:18Z

# Line 20 | Line 20
20  
21   #include "sysdeps.h"
22  
23 #include <gtk/gtk.h>
23   #include <stdlib.h>
24 + #include <string.h>
25 + #include <fcntl.h>
26 + #include <sys/stat.h>
27 + #include <gtk/gtk.h>
28  
29   #include "user_strings.h"
30   #include "version.h"
# Line 421 | Line 424 | static void cb_about(...)
424   // Menu item descriptions
425   static GtkItemFactoryEntry menu_items[] = {
426          {(gchar *)GetString(STR_PREFS_MENU_FILE_GTK),           NULL,                   NULL,                                                   0, "<Branch>"},
427 <        {(gchar *)GetString(STR_PREFS_ITEM_START_GTK),          NULL,                   GTK_SIGNAL_FUNC(cb_start),              0, NULL},
427 >        {(gchar *)GetString(STR_PREFS_ITEM_START_GTK),          "<control>S",   GTK_SIGNAL_FUNC(cb_start),              0, NULL},
428          {(gchar *)GetString(STR_PREFS_ITEM_ZAP_PRAM_GTK),       NULL,                   GTK_SIGNAL_FUNC(cb_zap_pram),   0, NULL},
429          {(gchar *)GetString(STR_PREFS_ITEM_SEPL_GTK),           NULL,                   NULL,                                                   0, "<Separator>"},
430          {(gchar *)GetString(STR_PREFS_ITEM_QUIT_GTK),           "<control>Q",   GTK_SIGNAL_FUNC(cb_quit),               0, NULL},
431          {(gchar *)GetString(STR_HELP_MENU_GTK),                         NULL,                   NULL,                                                   0, "<LastBranch>"},
432 <        {(gchar *)GetString(STR_HELP_ITEM_ABOUT_GTK),           NULL,                   GTK_SIGNAL_FUNC(cb_about),              0, NULL}
432 >        {(gchar *)GetString(STR_HELP_ITEM_ABOUT_GTK),           "<control>H",   GTK_SIGNAL_FUNC(cb_about),              0, NULL}
433   };
434  
435   bool PrefsEditor(void)
# Line 461 | Line 464 | bool PrefsEditor(void)
464          gtk_box_pack_start(GTK_BOX(box), notebook, TRUE, TRUE, 0);
465  
466          create_volumes_pane(notebook);
467 <        create_scsi_pane(notebook);
467 > //      create_scsi_pane(notebook); XXX not ready yet (merge scsi_windows.cpp from original B2/Win)
468          create_graphics_pane(notebook);
469          create_input_pane(notebook);
470          create_serial_pane(notebook);
# Line 471 | Line 474 | bool PrefsEditor(void)
474  
475          static const opt_desc buttons[] = {
476                  {STR_START_BUTTON, GTK_SIGNAL_FUNC(cb_start)},
474                {STR_PREFS_ITEM_ZAP_PRAM, GTK_SIGNAL_FUNC(cb_zap_pram)},
475                {STR_ABOUT_BUTTON, GTK_SIGNAL_FUNC(cb_about)},
477                  {STR_QUIT_BUTTON, GTK_SIGNAL_FUNC(cb_quit)},
478                  {0, NULL}
479          };
# Line 489 | Line 490 | bool PrefsEditor(void)
490   *  "Volumes" pane
491   */
492  
493 + static GtkWidget *w_enableextfs, *w_extdrives;
494   static GtkWidget *volume_list;
495   static int selected_volume;
496  
497 + // Set sensitivity of widgets
498 + static void set_volumes_sensitive(void)
499 + {
500 +        const bool enable_extfs = PrefsFindBool("enableextfs");
501 +        gtk_widget_set_sensitive(w_extdrives, enable_extfs);
502 + }
503 +
504   // Volume in list selected
505   static void cl_selected(GtkWidget *list, int row, int column)
506   {
# Line 513 | Line 522 | static void create_volume_ok(GtkWidget *
522          gchar *file = (gchar *)gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req));
523  
524          const gchar *str = gtk_entry_get_text(GTK_ENTRY(assoc->entry));
525 <        int size = atoi(str);
525 >        size_t size = atoi(str) << 20;
526  
527 <        char cmd[1024];
528 <        sprintf(cmd, "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", file, size);
529 <        int ret = system(cmd);
521 <        if (ret == 0)
527 >        int fd = _open(file, _O_WRONLY | _O_CREAT | _O_BINARY | _O_TRUNC, _S_IREAD | _S_IWRITE);
528 >        if (fd >= 0) {
529 >          if (_chsize(fd, size) == 0)
530                  gtk_clist_append(GTK_CLIST(volume_list), &file);
531 +          _close(fd);
532 +        }
533          gtk_widget_destroy(GTK_WIDGET(assoc->req));
534          delete assoc;
535   }
# Line 568 | Line 578 | static void cb_remove_volume(...)
578   static void mn_boot_any(...) {PrefsReplaceInt32("bootdriver", 0);}
579   static void mn_boot_cdrom(...) {PrefsReplaceInt32("bootdriver", CDROMRefNum);}
580  
581 + // "Enable external file system" button toggled
582 + static void tb_enableextfs(GtkWidget *widget)
583 + {
584 +        PrefsReplaceBool("enableextfs", GTK_TOGGLE_BUTTON(widget)->active);
585 +        set_volumes_sensitive();
586 + }
587 +
588   // "No CD-ROM Driver" button toggled
589   static void tb_nocdrom(GtkWidget *widget)
590   {
591          PrefsReplaceBool("nocdrom", GTK_TOGGLE_BUTTON(widget)->active);
592   }
593  
594 + // "Enable polling" button toggled
595 + static void tb_pollmedia(GtkWidget *widget)
596 + {
597 +        PrefsReplaceBool("pollmedia", GTK_TOGGLE_BUTTON(widget)->active);
598 + }
599 +
600   // Read settings from widgets and set preferences
601   static void read_volumes_settings(void)
602   {
# Line 585 | Line 608 | static void read_volumes_settings(void)
608                  gtk_clist_get_text(GTK_CLIST(volume_list), i, 0, &str);
609                  PrefsAddString("disk", str);
610          }
611 +
612 +        PrefsReplaceString("extdrives", get_file_entry_path(w_extdrives));
613   }
614  
615   // Create "Volumes" pane
# Line 633 | Line 658 | static void create_volumes_pane(GtkWidge
658          menu = make_option_menu(box, STR_BOOTDRIVER_CTRL, options, active);
659  
660          make_checkbox(box, STR_NOCDROM_CTRL, "nocdrom", GTK_SIGNAL_FUNC(tb_nocdrom));
661 +
662 +        make_checkbox(box, STR_POLLMEDIA_CTRL, "pollmedia", GTK_SIGNAL_FUNC(tb_pollmedia));
663 +
664 +        make_separator(box);
665 +        w_enableextfs = make_checkbox(box, STR_EXTFS_ENABLE_CTRL, "enableextfs", GTK_SIGNAL_FUNC(tb_enableextfs));
666 +        w_extdrives = make_file_entry(box, STR_EXTFS_DRIVES_CTRL, "extdrives", true);
667 +
668 +        set_volumes_sensitive();
669   }
670  
671  
# Line 988 | Line 1021 | static GtkWidget *w_mouse_wheel_lines;
1021   // Set sensitivity of widgets
1022   static void set_input_sensitive(void)
1023   {
1024 <        gtk_widget_set_sensitive(w_keycode_file, PrefsFindBool("keycodes"));
1024 >        const bool use_keycodes = PrefsFindBool("keycodes");
1025 >        gtk_widget_set_sensitive(w_keycode_file, use_keycodes);
1026 >        gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data(G_OBJECT(w_keycode_file), "chooser_button")), use_keycodes);
1027          gtk_widget_set_sensitive(w_mouse_wheel_lines, PrefsFindInt32("mousewheelmode") == 1);
1028   }
1029  
# Line 1018 | Line 1053 | static void read_input_settings(void)
1053   // Create "Input" pane
1054   static void create_input_pane(GtkWidget *top)
1055   {
1056 <        GtkWidget *box, *hbox, *menu, *label;
1056 >        GtkWidget *box, *hbox, *menu, *label, *button;
1057          GtkObject *adj;
1058  
1059          box = make_pane(top, STR_INPUT_PANE_TITLE);
1060  
1061          make_checkbox(box, STR_KEYCODES_CTRL, "keycodes", GTK_SIGNAL_FUNC(tb_keycodes));
1062 <        w_keycode_file = make_file_entry(box, STR_KEYCODE_FILE_CTRL, "keycodefile");
1062 >
1063 >        hbox = gtk_hbox_new(FALSE, 4);
1064 >        gtk_widget_show(hbox);
1065 >        gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
1066 >
1067 >        label = gtk_label_new(GetString(STR_KEYCODES_CTRL));
1068 >        gtk_widget_show(label);
1069 >        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1070 >
1071 >        const char *str = PrefsFindString("keycodefile");
1072 >        if (str == NULL)
1073 >                str = "";
1074 >
1075 >        w_keycode_file = gtk_entry_new();
1076 >        gtk_entry_set_text(GTK_ENTRY(w_keycode_file), str);
1077 >        gtk_widget_show(w_keycode_file);
1078 >        gtk_box_pack_start(GTK_BOX(hbox), w_keycode_file, TRUE, TRUE, 0);
1079 >
1080 >        button = make_browse_button(w_keycode_file);
1081 >        gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1082 >        g_object_set_data(G_OBJECT(w_keycode_file), "chooser_button", button);
1083  
1084          make_separator(box);
1085  
# Line 1102 | Line 1157 | static void read_serial_settings(void)
1157   // Port changed in combo
1158   static void cb_serial_port_changed(...)
1159   {
1105        printf("serial port changed\n");
1160          set_serial_sensitive();
1161   }
1162  
# Line 1160 | Line 1214 | static void create_serial_pane(GtkWidget
1214   *  "Ethernet" pane
1215   */
1216  
1217 < static GtkWidget *w_ether, *w_udp_port;
1217 > static GtkWidget *w_ether;
1218 > static GtkWidget *w_ftp_port_list, *w_tcp_port_list;
1219 > static const char s_nat_router[] = "NAT/Router module";
1220  
1221   // Set sensitivity of widgets
1222   static void set_ethernet_sensitive(void)
1223   {
1224 +        const char *str = gtk_entry_get_text(GTK_ENTRY(w_ether));
1225 +
1226 +        bool is_nat_router = strcmp(str, s_nat_router) == 0;
1227 +        gtk_widget_set_sensitive(w_ftp_port_list, is_nat_router);
1228 +        gtk_widget_set_sensitive(w_tcp_port_list, is_nat_router);
1229   }
1230  
1231   // Read settings from widgets and set preferences
1232   static void read_ethernet_settings(void)
1233   {
1234          const char *str = gtk_entry_get_text(GTK_ENTRY(w_ether));
1235 <        if (str && strlen(str))
1236 <                PrefsReplaceString("ether", str);
1235 >        if (str && strlen(str) > 6 && strncmp(str, "NDIS: ", 6) == 0)
1236 >                PrefsReplaceString("ether", &str[6]);
1237          else
1238                  PrefsRemoveItem("ether");
1239 +
1240 +        const bool router_enabled = str && strcmp(str, s_nat_router) == 0;
1241 +        PrefsReplaceBool("routerenabled", router_enabled);
1242 +        if (router_enabled) {
1243 +                str = gtk_entry_get_text(GTK_ENTRY(w_ftp_port_list));
1244 +                PrefsReplaceString("ftp_port_list", str);
1245 +                str = gtk_entry_get_text(GTK_ENTRY(w_tcp_port_list));
1246 +                PrefsReplaceString("tcp_port", str);
1247 +        }
1248 + }
1249 +
1250 + // Ethernet emulation type changed in menulist
1251 + static void cb_ether_changed(...)
1252 + {
1253 +        set_ethernet_sensitive();
1254   }
1255  
1256   // Add names of ethernet interfaces
# Line 1184 | Line 1260 | static GList *add_ether_names(void)
1260  
1261          // TODO: Get list of all Ethernet interfaces
1262   #ifdef HAVE_SLIRP
1263 <        static char s_slirp[] = "slirp";
1264 <        glist = g_list_append(glist, s_slirp);
1189 < #endif
1190 < #if 0
1191 <        if (glist)
1192 <                g_list_sort(glist, gl_str_cmp);
1193 <        else
1263 >        static const char s_slirp[] = "slirp";
1264 >        glist = g_list_append(glist, (void *)s_slirp);
1265   #endif
1266 <                glist = g_list_append(glist, (void *)GetString(STR_NONE_LAB));
1266 >        glist = g_list_append(glist, (void *)s_nat_router);
1267 >        glist = g_list_append(glist, (void *)GetString(STR_NONE_LAB));
1268          return glist;
1269   }
1270  
# Line 1214 | Line 1286 | static void create_ethernet_pane(GtkWidg
1286          gtk_widget_show(combo);
1287          gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
1288          const char *str = PrefsFindString("ether");
1289 <        if (str == NULL)
1290 <                str = "";
1289 >        if (str == NULL || str[0] == '\0') {
1290 >                if (PrefsFindBool("routerenabled"))
1291 >                        str = s_nat_router;
1292 >                else
1293 >                        str = GetString(STR_NONE_LAB);
1294 >        }
1295          gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str);
1296          gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 0, 1, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
1297          w_ether = GTK_COMBO(combo)->entry;
1298 +        gtk_signal_connect(GTK_OBJECT(w_ether), "changed", GTK_SIGNAL_FUNC(cb_ether_changed), NULL);
1299 +
1300 +        sep = gtk_hseparator_new();
1301 +        gtk_widget_show(sep);
1302 +        gtk_table_attach(GTK_TABLE(table), sep, 0, 2, 1, 2, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
1303 +
1304 +        label = gtk_label_new(GetString(STR_ETHER_FTP_PORT_LIST_CTRL));
1305 +        gtk_widget_show(label);
1306 +        gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
1307 +
1308 +        entry = gtk_entry_new();
1309 +        str = PrefsFindString("ftp_port_list");
1310 +        if (str == NULL)
1311 +                str = "";
1312 +        gtk_entry_set_text(GTK_ENTRY(entry), str);
1313 +        gtk_widget_show(entry);
1314 +        gtk_table_attach(GTK_TABLE(table), entry, 1, 2, 2, 3, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
1315 +        w_ftp_port_list = entry;
1316 +
1317 +        label = gtk_label_new(GetString(STR_ETHER_TCP_PORT_LIST_CTRL));
1318 +        gtk_widget_show(label);
1319 +        gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
1320 +
1321 +        entry = gtk_entry_new();
1322 +        str = PrefsFindString("tcp_port");
1323 +        if (str == NULL)
1324 +                str = "";
1325 +        gtk_entry_set_text(GTK_ENTRY(entry), str);
1326 +        gtk_widget_show(entry);
1327 +        gtk_table_attach(GTK_TABLE(table), entry, 1, 2, 3, 4, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
1328 +        w_tcp_port_list = entry;
1329  
1330          set_ethernet_sensitive();
1331   }
# Line 1368 | Line 1475 | void SysAddSerialPrefs(void)
1475  
1476  
1477   /*
1478 + *  Display alerts
1479 + */
1480 +
1481 + static void display_alert(int title_id, const char *text, int flags)
1482 + {
1483 +        MessageBox(NULL, text, GetString(title_id), MB_OK | flags);
1484 + }
1485 +
1486 + static void ErrorAlert(const char *text)
1487 + {
1488 +        display_alert(STR_ERROR_ALERT_TITLE, text, MB_ICONSTOP);
1489 + }
1490 +
1491 +
1492 + /*
1493   *  Start standalone GUI
1494   */
1495  
# Line 1388 | Line 1510 | int main(int argc, char *argv[])
1510  
1511          // Transfer control to the Basilisk II executable
1512          if (start) {
1513 <                printf("Start Basilisk II\n");
1513 >                char path[_MAX_PATH];
1514 >                bool ok = GetModuleFileName(NULL, path, sizeof(path)) != 0;
1515 >                if (ok) {
1516 >                        char b2_path[_MAX_PATH];
1517 >                        char *p = strrchr(path, '\\');
1518 >                        *++p = '\0';
1519 >                        SetCurrentDirectory(path);
1520 >                        strcpy(b2_path, path);
1521 >                        strcat(b2_path, "BasiliskII.exe");
1522 >                        HINSTANCE h = ShellExecute(GetDesktopWindow(), "open",
1523 >                                                                           b2_path, "", path, SW_SHOWNORMAL);
1524 >                        if ((int)h <= 32)
1525 >                                ok = false;
1526 >                }
1527 >                if (!ok) {
1528 >                        ErrorAlert("Coult not start BasiliskII executable");
1529 >                        return 1;
1530 >                }
1531          }
1532  
1533          return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines