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.5 by gbeauche, 2005-11-20T23:47:42Z

# 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 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 489 | Line 492 | bool PrefsEditor(void)
492   *  "Volumes" pane
493   */
494  
495 + static GtkWidget *w_enableextfs, *w_extdrives;
496   static GtkWidget *volume_list;
497   static int selected_volume;
498  
499 + // Set sensitivity of widgets
500 + static void set_volumes_sensitive(void)
501 + {
502 +        const bool enable_extfs = PrefsFindBool("enableextfs");
503 +        gtk_widget_set_sensitive(w_extdrives, enable_extfs);
504 + }
505 +
506   // Volume in list selected
507   static void cl_selected(GtkWidget *list, int row, int column)
508   {
# Line 513 | Line 524 | static void create_volume_ok(GtkWidget *
524          gchar *file = (gchar *)gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req));
525  
526          const gchar *str = gtk_entry_get_text(GTK_ENTRY(assoc->entry));
527 <        int size = atoi(str);
527 >        size_t size = atoi(str) << 20;
528  
529 <        char cmd[1024];
530 <        sprintf(cmd, "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", file, size);
531 <        int ret = system(cmd);
521 <        if (ret == 0)
529 >        int fd = _open(file, _O_WRONLY | _O_CREAT | _O_BINARY | _O_TRUNC, _S_IREAD | _S_IWRITE);
530 >        if (fd >= 0) {
531 >          if (_chsize(fd, size) == 0)
532                  gtk_clist_append(GTK_CLIST(volume_list), &file);
533 +          _close(fd);
534 +        }
535          gtk_widget_destroy(GTK_WIDGET(assoc->req));
536          delete assoc;
537   }
# Line 568 | Line 580 | static void cb_remove_volume(...)
580   static void mn_boot_any(...) {PrefsReplaceInt32("bootdriver", 0);}
581   static void mn_boot_cdrom(...) {PrefsReplaceInt32("bootdriver", CDROMRefNum);}
582  
583 + // "Enable external file system" button toggled
584 + static void tb_enableextfs(GtkWidget *widget)
585 + {
586 +        PrefsReplaceBool("enableextfs", GTK_TOGGLE_BUTTON(widget)->active);
587 +        set_volumes_sensitive();
588 + }
589 +
590   // "No CD-ROM Driver" button toggled
591   static void tb_nocdrom(GtkWidget *widget)
592   {
593          PrefsReplaceBool("nocdrom", GTK_TOGGLE_BUTTON(widget)->active);
594   }
595  
596 + // "Enable polling" button toggled
597 + static void tb_pollmedia(GtkWidget *widget)
598 + {
599 +        PrefsReplaceBool("pollmedia", GTK_TOGGLE_BUTTON(widget)->active);
600 + }
601 +
602   // Read settings from widgets and set preferences
603   static void read_volumes_settings(void)
604   {
# Line 585 | Line 610 | static void read_volumes_settings(void)
610                  gtk_clist_get_text(GTK_CLIST(volume_list), i, 0, &str);
611                  PrefsAddString("disk", str);
612          }
613 +
614 +        PrefsReplaceString("extdrives", get_file_entry_path(w_extdrives));
615   }
616  
617   // Create "Volumes" pane
# Line 633 | Line 660 | static void create_volumes_pane(GtkWidge
660          menu = make_option_menu(box, STR_BOOTDRIVER_CTRL, options, active);
661  
662          make_checkbox(box, STR_NOCDROM_CTRL, "nocdrom", GTK_SIGNAL_FUNC(tb_nocdrom));
663 +
664 +        make_checkbox(box, STR_POLLMEDIA_CTRL, "pollmedia", GTK_SIGNAL_FUNC(tb_pollmedia));
665 +
666 +        make_separator(box);
667 +        w_enableextfs = make_checkbox(box, STR_EXTFS_ENABLE_CTRL, "enableextfs", GTK_SIGNAL_FUNC(tb_enableextfs));
668 +        w_extdrives = make_file_entry(box, STR_EXTFS_DRIVES_CTRL, "extdrives", true);
669 +
670 +        set_volumes_sensitive();
671   }
672  
673  
# Line 988 | Line 1023 | static GtkWidget *w_mouse_wheel_lines;
1023   // Set sensitivity of widgets
1024   static void set_input_sensitive(void)
1025   {
1026 <        gtk_widget_set_sensitive(w_keycode_file, PrefsFindBool("keycodes"));
1026 >        const bool use_keycodes = PrefsFindBool("keycodes");
1027 >        gtk_widget_set_sensitive(w_keycode_file, use_keycodes);
1028 >        gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data(G_OBJECT(w_keycode_file), "chooser_button")), use_keycodes);
1029          gtk_widget_set_sensitive(w_mouse_wheel_lines, PrefsFindInt32("mousewheelmode") == 1);
1030   }
1031  
# Line 1018 | Line 1055 | static void read_input_settings(void)
1055   // Create "Input" pane
1056   static void create_input_pane(GtkWidget *top)
1057   {
1058 <        GtkWidget *box, *hbox, *menu, *label;
1058 >        GtkWidget *box, *hbox, *menu, *label, *button;
1059          GtkObject *adj;
1060  
1061          box = make_pane(top, STR_INPUT_PANE_TITLE);
1062  
1063          make_checkbox(box, STR_KEYCODES_CTRL, "keycodes", GTK_SIGNAL_FUNC(tb_keycodes));
1064 <        w_keycode_file = make_file_entry(box, STR_KEYCODE_FILE_CTRL, "keycodefile");
1064 >
1065 >        hbox = gtk_hbox_new(FALSE, 4);
1066 >        gtk_widget_show(hbox);
1067 >        gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
1068 >
1069 >        label = gtk_label_new(GetString(STR_KEYCODES_CTRL));
1070 >        gtk_widget_show(label);
1071 >        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1072 >
1073 >        const char *str = PrefsFindString("keycodefile");
1074 >        if (str == NULL)
1075 >                str = "";
1076 >
1077 >        w_keycode_file = gtk_entry_new();
1078 >        gtk_entry_set_text(GTK_ENTRY(w_keycode_file), str);
1079 >        gtk_widget_show(w_keycode_file);
1080 >        gtk_box_pack_start(GTK_BOX(hbox), w_keycode_file, TRUE, TRUE, 0);
1081 >
1082 >        button = make_browse_button(w_keycode_file);
1083 >        gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1084 >        g_object_set_data(G_OBJECT(w_keycode_file), "chooser_button", button);
1085  
1086          make_separator(box);
1087  
# Line 1102 | Line 1159 | static void read_serial_settings(void)
1159   // Port changed in combo
1160   static void cb_serial_port_changed(...)
1161   {
1105        printf("serial port changed\n");
1162          set_serial_sensitive();
1163   }
1164  
# Line 1160 | Line 1216 | static void create_serial_pane(GtkWidget
1216   *  "Ethernet" pane
1217   */
1218  
1219 < static GtkWidget *w_ether, *w_udp_port;
1219 > static GtkWidget *w_ether;
1220 > static GtkWidget *w_ftp_port_list, *w_tcp_port_list;
1221 > static const char s_nat_router[] = "NAT/Router module";
1222  
1223   // Set sensitivity of widgets
1224   static void set_ethernet_sensitive(void)
1225   {
1226 +        const char *str = gtk_entry_get_text(GTK_ENTRY(w_ether));
1227 +
1228 +        bool is_nat_router = strcmp(str, s_nat_router) == 0;
1229 +        gtk_widget_set_sensitive(w_ftp_port_list, is_nat_router);
1230 +        gtk_widget_set_sensitive(w_tcp_port_list, is_nat_router);
1231   }
1232  
1233   // Read settings from widgets and set preferences
1234   static void read_ethernet_settings(void)
1235   {
1236          const char *str = gtk_entry_get_text(GTK_ENTRY(w_ether));
1237 <        if (str && strlen(str))
1238 <                PrefsReplaceString("ether", str);
1237 >        if (str && strlen(str) > 6 && strncmp(str, "NDIS: ", 6) == 0)
1238 >                PrefsReplaceString("ether", &str[6]);
1239          else
1240                  PrefsRemoveItem("ether");
1241 +
1242 +        const bool router_enabled = str && strcmp(str, s_nat_router) == 0;
1243 +        PrefsReplaceBool("routerenabled", router_enabled);
1244 +        if (router_enabled) {
1245 +                str = gtk_entry_get_text(GTK_ENTRY(w_ftp_port_list));
1246 +                PrefsReplaceString("ftp_port_list", str);
1247 +                str = gtk_entry_get_text(GTK_ENTRY(w_tcp_port_list));
1248 +                PrefsReplaceString("tcp_port", str);
1249 +        }
1250 + }
1251 +
1252 + // Ethernet emulation type changed in menulist
1253 + static void cb_ether_changed(...)
1254 + {
1255 +        set_ethernet_sensitive();
1256   }
1257  
1258   // Add names of ethernet interfaces
# Line 1184 | Line 1262 | static GList *add_ether_names(void)
1262  
1263          // TODO: Get list of all Ethernet interfaces
1264   #ifdef HAVE_SLIRP
1265 <        static char s_slirp[] = "slirp";
1266 <        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
1265 >        static const char s_slirp[] = "slirp";
1266 >        glist = g_list_append(glist, (void *)s_slirp);
1267   #endif
1268 <                glist = g_list_append(glist, (void *)GetString(STR_NONE_LAB));
1268 >        glist = g_list_append(glist, (void *)s_nat_router);
1269 >        glist = g_list_append(glist, (void *)GetString(STR_NONE_LAB));
1270          return glist;
1271   }
1272  
# Line 1214 | Line 1288 | static void create_ethernet_pane(GtkWidg
1288          gtk_widget_show(combo);
1289          gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
1290          const char *str = PrefsFindString("ether");
1291 <        if (str == NULL)
1292 <                str = "";
1291 >        if (str == NULL || str[0] == '\0') {
1292 >                if (PrefsFindBool("routerenabled"))
1293 >                        str = s_nat_router;
1294 >                else
1295 >                        str = GetString(STR_NONE_LAB);
1296 >        }
1297          gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str);
1298          gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 0, 1, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
1299          w_ether = GTK_COMBO(combo)->entry;
1300 +        gtk_signal_connect(GTK_OBJECT(w_ether), "changed", GTK_SIGNAL_FUNC(cb_ether_changed), NULL);
1301 +
1302 +        sep = gtk_hseparator_new();
1303 +        gtk_widget_show(sep);
1304 +        gtk_table_attach(GTK_TABLE(table), sep, 0, 2, 1, 2, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
1305 +
1306 +        label = gtk_label_new(GetString(STR_ETHER_FTP_PORT_LIST_CTRL));
1307 +        gtk_widget_show(label);
1308 +        gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
1309 +
1310 +        entry = gtk_entry_new();
1311 +        str = PrefsFindString("ftp_port_list");
1312 +        if (str == NULL)
1313 +                str = "";
1314 +        gtk_entry_set_text(GTK_ENTRY(entry), str);
1315 +        gtk_widget_show(entry);
1316 +        gtk_table_attach(GTK_TABLE(table), entry, 1, 2, 2, 3, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
1317 +        w_ftp_port_list = entry;
1318 +
1319 +        label = gtk_label_new(GetString(STR_ETHER_TCP_PORT_LIST_CTRL));
1320 +        gtk_widget_show(label);
1321 +        gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
1322 +
1323 +        entry = gtk_entry_new();
1324 +        str = PrefsFindString("tcp_port");
1325 +        if (str == NULL)
1326 +                str = "";
1327 +        gtk_entry_set_text(GTK_ENTRY(entry), str);
1328 +        gtk_widget_show(entry);
1329 +        gtk_table_attach(GTK_TABLE(table), entry, 1, 2, 3, 4, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
1330 +        w_tcp_port_list = entry;
1331  
1332          set_ethernet_sensitive();
1333   }
# Line 1368 | Line 1477 | void SysAddSerialPrefs(void)
1477  
1478  
1479   /*
1480 + *  Display alerts
1481 + */
1482 +
1483 + static void display_alert(int title_id, const char *text, int flags)
1484 + {
1485 +        MessageBox(NULL, text, GetString(title_id), MB_OK | flags);
1486 + }
1487 +
1488 + static void ErrorAlert(const char *text)
1489 + {
1490 +        display_alert(STR_ERROR_ALERT_TITLE, text, MB_ICONSTOP);
1491 + }
1492 +
1493 +
1494 + /*
1495   *  Start standalone GUI
1496   */
1497  
# Line 1388 | Line 1512 | int main(int argc, char *argv[])
1512  
1513          // Transfer control to the Basilisk II executable
1514          if (start) {
1515 <                printf("Start Basilisk II\n");
1515 >                char path[_MAX_PATH];
1516 >                bool ok = GetModuleFileName(NULL, path, sizeof(path)) != 0;
1517 >                if (ok) {
1518 >                        char b2_path[_MAX_PATH];
1519 >                        char *p = strrchr(path, '\\');
1520 >                        *++p = '\0';
1521 >                        SetCurrentDirectory(path);
1522 >                        strcpy(b2_path, path);
1523 >                        strcat(b2_path, "BasiliskII.exe");
1524 >                        HINSTANCE h = ShellExecute(GetDesktopWindow(), "open",
1525 >                                                                           b2_path, "", path, SW_SHOWNORMAL);
1526 >                        if ((int)h <= 32)
1527 >                                ok = false;
1528 >                }
1529 >                if (!ok) {
1530 >                        ErrorAlert("Coult not start BasiliskII executable");
1531 >                        return 1;
1532 >                }
1533          }
1534  
1535          return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines