From: Kaj-Michael Lang Date: Mon, 28 Jan 2008 17:12:39 +0000 (+0200) Subject: Fix GPS settings dialog so it works. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48bad6a3967484498795082bc73d2fb1835d3651;p=mapper Fix GPS settings dialog so it works. --- diff --git a/src/settings-gui.c b/src/settings-gui.c index ae16b1f..a8c5354 100644 --- a/src/settings-gui.c +++ b/src/settings-gui.c @@ -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; } diff --git a/src/settings-gui.h b/src/settings-gui.h index ab94a9c..6ecc244 100644 --- a/src/settings-gui.h +++ b/src/settings-gui.h @@ -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);