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.10 by gbeauche, 2005-11-29T22:59:44Z vs.
Revision 1.11 by gbeauche, 2006-04-23T15:40:23Z

# Line 32 | Line 32
32   #include "xpram.h"
33   #include "prefs.h"
34   #include "prefs_editor.h"
35 + #include "util_windows.h"
36   #include "b2ether/inc/b2ether_hl.h"
37  
38  
# Line 66 | Line 67 | enum {
67          STR_SERIALB_CTRL = STR_SERPORTB_CTRL,
68   };
69   #else
70 + #define DISABLE_SCSI 1 /* XXX merge code from original Basilisk II for Windows */
71   #define PROGRAM_NAME "BasiliskII"
72   #endif
73  
# Line 116 | Line 118 | static GtkWidget *make_browse_button(Gtk
118          return button;
119   }
120  
121 < static void add_menu_item(GtkWidget *menu, int label_id, GtkSignalFunc func)
121 > static void add_menu_item(GtkWidget *menu, const char *label, GtkSignalFunc func, gpointer data = NULL)
122   {
123 <        GtkWidget *item = gtk_menu_item_new_with_label(GetString(label_id));
123 >        GtkWidget *item = gtk_menu_item_new_with_label(label);
124          gtk_widget_show(item);
125 <        gtk_signal_connect(GTK_OBJECT(item), "activate", func, NULL);
125 >        gtk_signal_connect(GTK_OBJECT(item), "activate", func, data);
126          gtk_menu_append(GTK_MENU(menu), item);
127   }
128  
129 + static void add_menu_item(GtkWidget *menu, int label_id, GtkSignalFunc func)
130 + {
131 +        add_menu_item(menu, GetString(label_id), func, NULL);
132 + }
133 +
134   static GtkWidget *make_pane(GtkWidget *notebook, int title_id)
135   {
136          GtkWidget *frame, *label, *box;
# Line 458 | Line 465 | static GtkItemFactoryEntry menu_items[]
465          {(gchar *)GetString(STR_HELP_ITEM_ABOUT_GTK),           "<control>H",   GTK_SIGNAL_FUNC(cb_about),              0, NULL}
466   };
467  
468 + void PrefsMigrate(void)
469 + {
470 +        // Ethernet
471 +        const char *ether = PrefsFindString("ether");
472 +        if (ether && ether[0] == '{') {
473 +                PrefsReplaceString("etherguid", ether);
474 +                PrefsReplaceString("ether", "b2ether");
475 +        }
476 +        if (PrefsFindBool("routerenabled")) {
477 +                PrefsRemoveItem("etherguid");
478 +                PrefsReplaceString("ether", "router");
479 +        }
480 + }
481 +
482   bool PrefsEditor(void)
483   {
484          // Create window
# Line 490 | Line 511 | bool PrefsEditor(void)
511          gtk_box_pack_start(GTK_BOX(box), notebook, TRUE, TRUE, 0);
512  
513          create_volumes_pane(notebook);
514 < //      create_scsi_pane(notebook); XXX not ready yet (merge scsi_windows.cpp from original B2/Win)
514 > #ifndef DISABLE_SCSI
515 >        create_scsi_pane(notebook);
516 > #endif
517          create_graphics_pane(notebook);
518          create_input_pane(notebook);
519          create_serial_pane(notebook);
# Line 1319 | Line 1342 | static void create_serial_pane(GtkWidget
1342   *  "Ethernet" pane
1343   */
1344  
1322 static GtkWidget *w_ether;
1345   static GtkWidget *w_ftp_port_list, *w_tcp_port_list;
1324 static const char s_nat_router[] = "NAT/Router module";
1325 static const char s_ndis_tag[] = "NDIS ";
1346  
1347   // Set sensitivity of widgets
1348   static void set_ethernet_sensitive(void)
1349   {
1350 <        const char *str = gtk_entry_get_text(GTK_ENTRY(w_ether));
1350 >        const char *str = PrefsFindString("ether");
1351  
1352 <        bool is_nat_router = strcmp(str, s_nat_router) == 0;
1353 <        gtk_widget_set_sensitive(w_ftp_port_list, is_nat_router);
1354 <        gtk_widget_set_sensitive(w_tcp_port_list, is_nat_router);
1352 >        bool is_router = str && strcmp(str, "router") == 0;
1353 >        gtk_widget_set_sensitive(w_ftp_port_list, is_router);
1354 >        gtk_widget_set_sensitive(w_tcp_port_list, is_router);
1355   }
1356  
1357   // Read settings from widgets and set preferences
1358   static void read_ethernet_settings(void)
1359   {
1360 <        const char *str = gtk_entry_get_text(GTK_ENTRY(w_ether));
1341 <        if (str && strlen(str) > sizeof(s_ndis_tag) && strncmp(str, s_ndis_tag, sizeof(s_ndis_tag) - 1) == 0)
1342 <                PrefsReplaceString("ether", &str[sizeof(s_ndis_tag) - 1]);
1343 <        else
1344 <                PrefsRemoveItem("ether");
1360 >        const char *str = PrefsFindString("ether");
1361  
1362 <        const bool router_enabled = str && strcmp(str, s_nat_router) == 0;
1363 <        PrefsReplaceBool("routerenabled", router_enabled);
1348 <        if (router_enabled) {
1362 >        bool is_router = str && strcmp(str, "router") == 0;
1363 >        if (is_router) {
1364                  str = gtk_entry_get_text(GTK_ENTRY(w_ftp_port_list));
1365                  PrefsReplaceString("ftp_port_list", str);
1366                  str = gtk_entry_get_text(GTK_ENTRY(w_tcp_port_list));
# Line 1359 | Line 1374 | static void cb_ether_changed(...)
1374          set_ethernet_sensitive();
1375   }
1376  
1377 < // Add names of ethernet interfaces
1378 < // XXX use radio buttons instead (None/NDIS/NAT)
1364 < static GList *add_ether_names(void)
1377 > // Ethernet option "None" selected
1378 > static void mn_ether_none(void)
1379   {
1380 <        GList *glist = NULL;
1381 <
1382 <        glist = g_list_append(glist, (void *)GetString(STR_NONE_LAB));
1369 <        glist = g_list_append(glist, (void *)s_nat_router);
1380 >        PrefsRemoveItem("ether");
1381 >        PrefsRemoveItem("etherguid");
1382 > }
1383  
1384 <        {       // Get NDIS ethernet adapters (XXX handle "ethermulticastmode")
1385 <                PacketOpenAdapter("", 0);
1386 <                {
1387 <                        ULONG sz;
1388 <                        char names[1024];
1389 <                        sz = sizeof(names);
1390 <                        if (PacketGetAdapterNames(NULL, names, &sz) == ERROR_SUCCESS) {
1391 <                                char *p = names;
1392 <                                while (*p) {
1393 <                                        const char DEVICE_HEADER[] = "\\Device\\B2ether_";
1394 <                                        if (strnicmp(p, DEVICE_HEADER, sizeof(DEVICE_HEADER) - 1) == 0) {
1395 <                                                LPADAPTER fd = PacketOpenAdapter(p + sizeof(DEVICE_HEADER) - 1, 0);
1396 <                                                if (fd) {
1397 <                                                        char str[256];
1398 <                                                        sprintf(str, "%s%s", s_ndis_tag, p + sizeof(DEVICE_HEADER) - 1);
1399 <                                                        glist = g_list_append(glist, strdup(str));
1400 <                                                        PacketCloseAdapter(fd);
1384 > // Ethernet option "Basilisk II Router" selected
1385 > static void mn_ether_router(void)
1386 > {
1387 >        PrefsReplaceString("ether", "router");
1388 >        PrefsRemoveItem("etherguid");
1389 > }
1390 >
1391 > // Ethernet option for Basilisk II driver selected
1392 > static void mn_ether_b2ether(GtkWidget *, const char *guid)
1393 > {
1394 >        PrefsReplaceString("ether", "b2ether");
1395 >        PrefsReplaceString("etherguid", guid);
1396 > }
1397 >
1398 > // Create ethernet interfaces menu
1399 > static int create_ether_menu(GtkWidget *menu)
1400 > {
1401 >        int active = -1;
1402 >        int n_items = 0;
1403 >        const char *ether = PrefsFindString("ether");
1404 >        const char *etherguid = PrefsFindString("etherguid");
1405 >
1406 >        add_menu_item(menu, STR_NONE_LAB, (GtkSignalFunc)mn_ether_none);
1407 >        if (ether == NULL)
1408 >                active = n_items;
1409 >        n_items++;
1410 >
1411 >        add_menu_item(menu, "Basilisk II Router", (GtkSignalFunc)mn_ether_router);
1412 >        if (ether && strcmp(ether, "router") == 0)
1413 >                active = n_items;
1414 >        n_items++;
1415 >
1416 >        PacketOpenAdapter("", 0);
1417 >        {
1418 >                ULONG sz;
1419 >                char names[1024];
1420 >                sz = sizeof(names);
1421 >                if (PacketGetAdapterNames(NULL, names, &sz) == ERROR_SUCCESS) {
1422 >                        char *p = names;
1423 >                        while (*p) {
1424 >                                const char DEVICE_HEADER[] = "\\Device\\B2ether_";
1425 >                                if (strnicmp(p, DEVICE_HEADER, sizeof(DEVICE_HEADER) - 1) == 0) {
1426 >                                        LPADAPTER fd = PacketOpenAdapter(p + sizeof(DEVICE_HEADER) - 1, 0);
1427 >                                        if (fd) {
1428 >                                                char guid[256];
1429 >                                                sprintf(guid, "%s", p + sizeof(DEVICE_HEADER) - 1);
1430 >                                                const char *name = ether_guid_to_name(guid);
1431 >                                                if (name && (name = g_locale_to_utf8(name, -1, NULL, NULL, NULL))) {
1432 >                                                        add_menu_item(menu, name, (GtkSignalFunc)mn_ether_b2ether, strdup(guid));
1433 >                                                        if (etherguid && strcmp(guid, etherguid) == 0 &&
1434 >                                                                ether && strcmp(ether, "b2ether") == 0)
1435 >                                                                active = n_items;
1436 >                                                        n_items++;
1437                                                  }
1438 +                                                PacketCloseAdapter(fd);
1439                                          }
1390                                        p += strlen(p) + 1;
1440                                  }
1441 +                                p += strlen(p) + 1;
1442                          }
1443                  }
1394                PacketCloseAdapter(NULL);
1444          }
1445 <        return glist;
1397 < }
1445 >        PacketCloseAdapter(NULL);
1446  
1447 +        return active;
1448 + }
1449  
1450   // Create "Ethernet" pane
1451   static void create_ethernet_pane(GtkWidget *top)
1452   {
1453 <        GtkWidget *box, *hbox, *table, *label, *combo, *sep, *entry;
1453 >        GtkWidget *box, *hbox, *table, *label, *sep, *entry, *opt, *menu, *item;
1454  
1455          box = make_pane(top, STR_NETWORK_PANE_TITLE);
1456          table = make_table(box, 2, 5);
# Line 1409 | Line 1459 | static void create_ethernet_pane(GtkWidg
1459          gtk_widget_show(label);
1460          gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
1461  
1462 <        GList *glist = add_ether_names();
1463 <        combo = gtk_combo_new();
1464 <        gtk_widget_show(combo);
1465 <        gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
1466 <        const char *str = PrefsFindString("ether");
1467 <        if (str == NULL || str[0] == '\0') {
1468 <                if (PrefsFindBool("routerenabled"))
1469 <                        str = s_nat_router;
1470 <                else
1421 <                        str = GetString(STR_NONE_LAB);
1422 <        }
1423 <        else if (str[0] == '{') {
1424 <                static char s_device[256];
1425 <                sprintf(s_device, "%s%s", s_ndis_tag, str);
1426 <                str = s_device;
1427 <        }
1428 <        gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str);
1429 <        gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 0, 1, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
1430 <        w_ether = GTK_COMBO(combo)->entry;
1431 <        gtk_signal_connect(GTK_OBJECT(w_ether), "changed", GTK_SIGNAL_FUNC(cb_ether_changed), NULL);
1462 >        opt = gtk_option_menu_new();
1463 >        gtk_widget_show(opt);
1464 >        menu = gtk_menu_new();
1465 >        int active = create_ether_menu(menu);
1466 >        if (active >= 0)
1467 >                gtk_menu_set_active(GTK_MENU(menu), active);
1468 >        gtk_option_menu_set_menu(GTK_OPTION_MENU(opt), menu);
1469 >        gtk_table_attach(GTK_TABLE(table), opt, 1, 2, 0, 1, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
1470 >        gtk_signal_connect(GTK_OBJECT(opt), "changed", GTK_SIGNAL_FUNC(cb_ether_changed), NULL);
1471  
1472          sep = gtk_hseparator_new();
1473          gtk_widget_show(sep);
# Line 1439 | Line 1478 | static void create_ethernet_pane(GtkWidg
1478          gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
1479  
1480          entry = gtk_entry_new();
1481 <        str = PrefsFindString("ftp_port_list");
1481 >        const char *str = PrefsFindString("ftp_port_list");
1482          if (str == NULL)
1483                  str = "";
1484          gtk_entry_set_text(GTK_ENTRY(entry), str);
# Line 1611 | Line 1650 | static void read_settings(void)
1650   uint8 XPRAM[XPRAM_SIZE];
1651   void MountVolume(void *fh) { }
1652   void FileDiskLayout(loff_t size, uint8 *data, loff_t &start_byte, loff_t &real_size) { }
1614 void WarningAlert(const char *text) { }
1653   void recycle_write_packet(LPPACKET) { }
1654   VOID CALLBACK packet_read_completion(DWORD, DWORD, LPOVERLAPPED) { }
1655  
# Line 1636 | Line 1674 | static void display_alert(int title_id,
1674          MessageBox(NULL, text, GetString(title_id), MB_OK | flags);
1675   }
1676  
1677 < static void ErrorAlert(const char *text)
1677 > void ErrorAlert(const char *text)
1678   {
1679          display_alert(STR_ERROR_ALERT_TITLE, text, MB_ICONSTOP);
1680   }
1681  
1682 + void WarningAlert(const char *text)
1683 + {
1684 +        display_alert(STR_WARNING_ALERT_TITLE, text, MB_ICONSTOP);
1685 + }
1686 +
1687  
1688   /*
1689   *  Start standalone GUI
# Line 1655 | Line 1698 | int main(int argc, char *argv[])
1698          // Read preferences
1699          PrefsInit(argc, argv);
1700  
1701 +        // Migrate preferences
1702 +        PrefsMigrate();
1703 +
1704          // Show preferences editor
1705          bool start = PrefsEditor();
1706  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines