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.9 by gbeauche, 2005-11-29T20:54:57Z vs.
Revision 1.12 by gbeauche, 2006-04-29T14:15:01Z

# 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  
39   // Global variables
# Line 65 | 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 115 | 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 457 | 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 489 | 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 1318 | Line 1342 | static void create_serial_pane(GtkWidget
1342   *  "Ethernet" pane
1343   */
1344  
1321 static GtkWidget *w_ether;
1345   static GtkWidget *w_ftp_port_list, *w_tcp_port_list;
1323 static const char s_nat_router[] = "NAT/Router module";
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));
1339 <        if (str && strlen(str) > 6 && strncmp(str, "NDIS: ", 6) == 0)
1340 <                PrefsReplaceString("ether", &str[6]);
1341 <        else
1342 <                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);
1346 <        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 1357 | Line 1374 | static void cb_ether_changed(...)
1374          set_ethernet_sensitive();
1375   }
1376  
1377 < // Add names of ethernet interfaces
1378 < static GList *add_ether_names(void)
1377 > // Ethernet option "None" selected
1378 > static void mn_ether_none(void)
1379   {
1380 <        GList *glist = NULL;
1381 <
1365 <        // TODO: Get list of all Ethernet interfaces
1366 <        glist = g_list_append(glist, (void *)s_nat_router);
1367 <        glist = g_list_append(glist, (void *)GetString(STR_NONE_LAB));
1368 <        return glist;
1380 >        PrefsRemoveItem("ether");
1381 >        PrefsRemoveItem("etherguid");
1382   }
1383  
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 "Basilisk II Slirp" selected
1392 + static void mn_ether_slirp(void)
1393 + {
1394 +        PrefsReplaceString("ether", "slirp");
1395 +        PrefsRemoveItem("etherguid");
1396 + }
1397 +
1398 + // Ethernet option for Basilisk II driver selected
1399 + static void mn_ether_b2ether(GtkWidget *, const char *guid)
1400 + {
1401 +        PrefsReplaceString("ether", "b2ether");
1402 +        PrefsReplaceString("etherguid", guid);
1403 + }
1404 +
1405 + // Create ethernet interfaces menu
1406 + static int create_ether_menu(GtkWidget *menu)
1407 + {
1408 +        int active = -1;
1409 +        int n_items = 0;
1410 +        const char *ether = PrefsFindString("ether");
1411 +        const char *etherguid = PrefsFindString("etherguid");
1412 +
1413 +        add_menu_item(menu, STR_NONE_LAB, (GtkSignalFunc)mn_ether_none);
1414 +        if (ether == NULL)
1415 +                active = n_items;
1416 +        n_items++;
1417 +
1418 +        add_menu_item(menu, "Basilisk II Router", (GtkSignalFunc)mn_ether_router);
1419 +        if (ether && strcmp(ether, "router") == 0)
1420 +                active = n_items;
1421 +        n_items++;
1422 +
1423 +        add_menu_item(menu, "Basilisk II Slirp", (GtkSignalFunc)mn_ether_router);
1424 +        if (ether && strcmp(ether, "slirp") == 0)
1425 +                active = n_items;
1426 +        n_items++;
1427 +
1428 +        PacketOpenAdapter("", 0);
1429 +        {
1430 +                ULONG sz;
1431 +                char names[1024];
1432 +                sz = sizeof(names);
1433 +                if (PacketGetAdapterNames(NULL, names, &sz) == ERROR_SUCCESS) {
1434 +                        char *p = names;
1435 +                        while (*p) {
1436 +                                const char DEVICE_HEADER[] = "\\Device\\B2ether_";
1437 +                                if (strnicmp(p, DEVICE_HEADER, sizeof(DEVICE_HEADER) - 1) == 0) {
1438 +                                        LPADAPTER fd = PacketOpenAdapter(p + sizeof(DEVICE_HEADER) - 1, 0);
1439 +                                        if (fd) {
1440 +                                                char guid[256];
1441 +                                                sprintf(guid, "%s", p + sizeof(DEVICE_HEADER) - 1);
1442 +                                                const char *name = ether_guid_to_name(guid);
1443 +                                                if (name && (name = g_locale_to_utf8(name, -1, NULL, NULL, NULL))) {
1444 +                                                        add_menu_item(menu, name, (GtkSignalFunc)mn_ether_b2ether, strdup(guid));
1445 +                                                        if (etherguid && strcmp(guid, etherguid) == 0 &&
1446 +                                                                ether && strcmp(ether, "b2ether") == 0)
1447 +                                                                active = n_items;
1448 +                                                        n_items++;
1449 +                                                }
1450 +                                                PacketCloseAdapter(fd);
1451 +                                        }
1452 +                                }
1453 +                                p += strlen(p) + 1;
1454 +                        }
1455 +                }
1456 +        }
1457 +        PacketCloseAdapter(NULL);
1458 +
1459 +        return active;
1460 + }
1461  
1462   // Create "Ethernet" pane
1463   static void create_ethernet_pane(GtkWidget *top)
1464   {
1465 <        GtkWidget *box, *hbox, *table, *label, *combo, *sep, *entry;
1465 >        GtkWidget *box, *hbox, *table, *label, *sep, *entry, *opt, *menu, *item;
1466  
1467          box = make_pane(top, STR_NETWORK_PANE_TITLE);
1468          table = make_table(box, 2, 5);
# Line 1381 | Line 1471 | static void create_ethernet_pane(GtkWidg
1471          gtk_widget_show(label);
1472          gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
1473  
1474 <        GList *glist = add_ether_names();
1475 <        combo = gtk_combo_new();
1476 <        gtk_widget_show(combo);
1477 <        gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
1478 <        const char *str = PrefsFindString("ether");
1479 <        if (str == NULL || str[0] == '\0') {
1480 <                if (PrefsFindBool("routerenabled"))
1481 <                        str = s_nat_router;
1482 <                else
1393 <                        str = GetString(STR_NONE_LAB);
1394 <        }
1395 <        gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str);
1396 <        gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 0, 1, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
1397 <        w_ether = GTK_COMBO(combo)->entry;
1398 <        gtk_signal_connect(GTK_OBJECT(w_ether), "changed", GTK_SIGNAL_FUNC(cb_ether_changed), NULL);
1474 >        opt = gtk_option_menu_new();
1475 >        gtk_widget_show(opt);
1476 >        menu = gtk_menu_new();
1477 >        int active = create_ether_menu(menu);
1478 >        if (active >= 0)
1479 >                gtk_menu_set_active(GTK_MENU(menu), active);
1480 >        gtk_option_menu_set_menu(GTK_OPTION_MENU(opt), menu);
1481 >        gtk_table_attach(GTK_TABLE(table), opt, 1, 2, 0, 1, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
1482 >        gtk_signal_connect(GTK_OBJECT(opt), "changed", GTK_SIGNAL_FUNC(cb_ether_changed), NULL);
1483  
1484          sep = gtk_hseparator_new();
1485          gtk_widget_show(sep);
# Line 1406 | Line 1490 | static void create_ethernet_pane(GtkWidg
1490          gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
1491  
1492          entry = gtk_entry_new();
1493 <        str = PrefsFindString("ftp_port_list");
1493 >        const char *str = PrefsFindString("ftp_port_list");
1494          if (str == NULL)
1495                  str = "";
1496          gtk_entry_set_text(GTK_ENTRY(entry), str);
# Line 1578 | Line 1662 | static void read_settings(void)
1662   uint8 XPRAM[XPRAM_SIZE];
1663   void MountVolume(void *fh) { }
1664   void FileDiskLayout(loff_t size, uint8 *data, loff_t &start_byte, loff_t &real_size) { }
1665 < void WarningAlert(const char *text) { }
1665 > void recycle_write_packet(LPPACKET) { }
1666 > VOID CALLBACK packet_read_completion(DWORD, DWORD, LPOVERLAPPED) { }
1667  
1668  
1669   /*
# Line 1601 | Line 1686 | static void display_alert(int title_id,
1686          MessageBox(NULL, text, GetString(title_id), MB_OK | flags);
1687   }
1688  
1689 < static void ErrorAlert(const char *text)
1689 > void ErrorAlert(const char *text)
1690   {
1691          display_alert(STR_ERROR_ALERT_TITLE, text, MB_ICONSTOP);
1692   }
1693  
1694 + void WarningAlert(const char *text)
1695 + {
1696 +        display_alert(STR_WARNING_ALERT_TITLE, text, MB_ICONSTOP);
1697 + }
1698 +
1699  
1700   /*
1701   *  Start standalone GUI
# Line 1620 | Line 1710 | int main(int argc, char *argv[])
1710          // Read preferences
1711          PrefsInit(argc, argv);
1712  
1713 +        // Migrate preferences
1714 +        PrefsMigrate();
1715 +
1716          // Show preferences editor
1717          bool start = PrefsEditor();
1718  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines