]> err.no Git - mapper/commitdiff
Fix GPS settings dialog so it works.
authorKaj-Michael Lang <milang@onion.tal.org>
Mon, 28 Jan 2008 17:12:39 +0000 (19:12 +0200)
committerKaj-Michael Lang <milang@onion.tal.org>
Mon, 28 Jan 2008 17:12:39 +0000 (19:12 +0200)
src/settings-gui.c
src/settings-gui.h

index ae16b1ff304ea610f7d5f76d42650a9b5f75d814..a8c5354584e082aeb39b7d5490862b80ed75d7b3 100644 (file)
@@ -256,7 +256,7 @@ return TRUE;
 }
 
 gboolean
-settings_dialog_gps(void)
+settings_dialog_gps(Gps *gps)
 {
 GtkWidget *dialog;
 GtkWidget *notebook;
@@ -266,16 +266,23 @@ GtkWidget *vbox;
 GtkWidget *label;
 GtkWidget *cmb_gps_type;
 GtkWidget *txt_rcvr_mac;
+GtkWidget *spn_rcvr_port;
 GtkWidget *btn_scan;
 GtkCellRenderer *renderer;
 GtkTreeIter active;
 GtkListStore *store;
 GtkTreeIter iter;
 ScanInfo scan_info = { 0 };
-gboolean rcvr_changed=TRUE;
+gboolean rcvr_changed=TRUE, settype=FALSE;
 GpsTypes *gpstypes;
 gint i=0;
 
+/* Don't allow configuring GPS if it's connected */
+if (gps->io.conn!=RCVR_OFF) {
+       popup_error(_window, "Disable GPS before re-configuring.");
+       return FALSE;
+}
+
 dialog = gtk_dialog_new_with_buttons(_("GPS Settings"), GTK_WINDOW(_window), GTK_DIALOG_MODAL, 
        GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
 help_dialog_help_enable(GTK_DIALOG(dialog), HELP_ID_SETTINGS_GPS);
@@ -305,19 +312,24 @@ gpstypes=gps_get_supported_types();
 while (gpstypes->type!=0) {
        gtk_list_store_append(store, &iter);
        gtk_list_store_set(store, &iter, 0, gpstypes->type, 1, gpstypes->name, -1);
+       if (gps->io.type==gpstypes->type) {
+               active=iter;
+               settype=TRUE;
+       }
        gpstypes++;
 }
 
-#if 0
-gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &active);
+if (settype==FALSE)
+       gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &active);
+
 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(cmb_gps_type), &active);
-#endif
 
 /* Receiver MAC Address. */
 hbox = gtk_hbox_new(FALSE, 3);
 gtk_box_pack_start(GTK_BOX(hbox), label = gtk_label_new(_("Address")), TRUE, TRUE, 0);
 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
 gtk_box_pack_start(GTK_BOX(hbox), txt_rcvr_mac = gtk_entry_new(), TRUE, TRUE, 0);
+gtk_box_pack_start(GTK_BOX(hbox), spn_rcvr_port = gtk_spin_button_new_with_range(0, 65535, 1), TRUE, TRUE, 0);
 gtk_box_pack_start(GTK_BOX(hbox), btn_scan = gtk_button_new_with_label(_("Scan...")), FALSE, FALSE, 0);
 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
 
@@ -325,40 +337,47 @@ gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
 scan_info.settings_dialog = dialog;
 scan_info.txt_rcvr_mac = txt_rcvr_mac;
 g_signal_connect(G_OBJECT(btn_scan), "clicked", G_CALLBACK(scan_bluetooth), &scan_info);
-gtk_entry_set_text(GTK_ENTRY(txt_rcvr_mac), _gps->io.address ? _gps->io.address : "");
+gtk_entry_set_text(GTK_ENTRY(txt_rcvr_mac), gps->io.address ? gps->io.address : "");
+gtk_spin_button_set_value(spn_rcvr_port, gps->io.port);
 
 gtk_window_set_default_size(GTK_WINDOW(dialog), 500, -1);
 gtk_widget_show_all(dialog);
 
-if (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
+while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
        /* Set _rcvr_mac if necessary. */
+       if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(cmb_gps_type), &iter)==TRUE) {
+               gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 0, &(gps->io.type), -1);
+               g_debug("GPS: %d", gps->io.type);
+       } else {
+               popup_error(_window, "Please select GPS type");
+               continue;
+       }
+
        if (!*gtk_entry_get_text(GTK_ENTRY(txt_rcvr_mac))) {
                /* User specified no rcvr mac - set _rcvr_mac to NULL. */
-               if (_gps->io.address) {
-                       g_free(_gps->io.address);
-                       _gps->io.address=NULL;
+               if (gps->io.address) {
+                       g_free(gps->io.address);
+                       gps->io.address=NULL;
                        rcvr_changed=TRUE;
                        set_action_sensitive("gps_details", FALSE);
                }
-               if (_enable_gps) {
+               gps->io.type=GPS_IO_SIMULATION;
+               if (gps->io.type!=GPS_IO_SIMULATION) {
                        set_action_activate("gps_details", FALSE);
                        popup_error(dialog, _("No GPS Receiver MAC provided.\nGPS will be disabled."));
                        rcvr_changed=TRUE;
                        set_action_sensitive("gps_details", FALSE);
                }
-       } else if (!_gps->io.address || strcmp(_gps->io.address, gtk_entry_get_text(GTK_ENTRY(txt_rcvr_mac)))) {
+       } else if (!gps->io.address || strcmp(gps->io.address, gtk_entry_get_text(GTK_ENTRY(txt_rcvr_mac)))) {
                /* User specified a new rcvr mac. */
-               g_free(_gps->io.address);
-               _gps->io.address=g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_rcvr_mac)));
+               g_free(gps->io.address);
+               gps->io.address=g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_rcvr_mac)));
+               gps->io.port=(guint)gtk_spin_button_get_value(spn_rcvr_port);
                rcvr_changed=TRUE;
        }
 
-       /* Sensitize menus based on whether we have a database conn. */
-       gtk_widget_set_sensitive(_cmenu_loc_add_poi, _db != NULL);
-       gtk_widget_set_sensitive(_cmenu_way_add_poi, _db != NULL);
-       gtk_widget_set_sensitive(_cmenu_poi, _db != NULL);
-
        config_save();
+       break;
 }
 gtk_widget_destroy(dialog);    
 return rcvr_changed;
@@ -417,14 +436,16 @@ if (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
        } else {
                _mapper_db=NULL;
        }
-       /* Sensitize menus based on whether we have a database conn. */
-       gtk_widget_set_sensitive(_cmenu_loc_add_poi, _db != NULL);
-       gtk_widget_set_sensitive(_cmenu_way_add_poi, _db != NULL);
-       gtk_widget_set_sensitive(_cmenu_poi, _db != NULL);
 
        config_save();
 }
 gtk_widget_destroy(dialog);    
+
+/* Sensitize menus based on whether we have a database conn. */
+gtk_widget_set_sensitive(_cmenu_loc_add_poi, _db != NULL);
+gtk_widget_set_sensitive(_cmenu_way_add_poi, _db != NULL);
+gtk_widget_set_sensitive(_cmenu_poi, _db != NULL);
+
 return TRUE;
 }
 
index ab94a9c4c292c511eb50ebbbf65cac59c9c394b9..6ecc2440c80458676af31692c582543c6767d7e5 100644 (file)
@@ -2,7 +2,7 @@
 #define _SETTINGS_GUI_H
 
 gboolean settings_dialog(void);
-gboolean settings_dialog_gps(void);
+gboolean settings_dialog_gps(Gps *gps);
 gboolean settings_dialog_osm(void);
 void update_gcs(void);