- w->ser_l = gtk_label_new ("Serial Port:");
- w->ser_b = GTK_COMBO_BOX(gtk_combo_box_entry_new_text ());
- gtk_combo_box_append_text (w->ser_b, "/dev/ttyS0");
- gtk_combo_box_append_text (w->ser_b, "/dev/ttyS1");
- gtk_combo_box_append_text (w->ser_b, "/dev/ttyUSB0");
- gtk_combo_box_append_text (w->ser_b, "/dev/ttyUSB1");
- gtk_combo_box_append_text (w->ser_b, "usb:");
- gtk_combo_box_set_active (w->ser_b, 0);
+ w->ser_l = gtk_label_new (_("Serial Port:"));
+#if GTK_CHECK_VERSION (2, 24, 0)
+ w->ser_b = gtk_combo_box_text_new_with_entry ();
+#else
+ w->ser_b = gtk_combo_box_entry_new_text ();
+#endif
+ // Value from the settings is promoted to the top
+ gchar *gps_port = NULL;
+ if ( a_settings_get_string ( VIK_SETTINGS_GPS_PORT, &gps_port ) ) {
+ // Use setting if available
+ if ( gps_port ) {
+#ifndef WINDOWS
+ if ( !strncmp (gps_port, "/dev/tty", 6) ) {
+ if (g_access (gps_port, R_OK) == 0) {
+ vik_combo_box_text_append (w->ser_b, gps_port);
+ }
+ }
+ else
+#endif
+ vik_combo_box_text_append (w->ser_b, gps_port);
+ }
+ }
+
+ // Note avoid appending the port selected from the settings
+#ifdef WINDOWS
+ if ( gps_port && strcmp (gps_port, "com1") )
+ vik_combo_box_text_append (w->ser_b, "com1");
+#else
+ /* Here just try to see if the device is available which gets passed onto gpsbabel
+ List USB devices first as these will generally only be present if autogenerated by udev or similar
+ User is still able to set their own free text entry */
+ if ( gps_port && strcmp (gps_port, "/dev/ttyUSB0") )
+ if (g_access ("/dev/ttyUSB0", R_OK) == 0)
+ vik_combo_box_text_append (w->ser_b, "/dev/ttyUSB0");
+ if ( gps_port && strcmp (gps_port, "/dev/ttyUSB1") )
+ if (g_access ("/dev/ttyUSB1", R_OK) == 0)
+ vik_combo_box_text_append (w->ser_b, "/dev/ttyUSB1");
+ if ( gps_port && strcmp (gps_port, "/dev/ttyS0") )
+ if (g_access ("/dev/ttyS0", R_OK) == 0)
+ vik_combo_box_text_append (w->ser_b, "/dev/ttyS0");
+ if ( gps_port && strcmp (gps_port, "/dev/ttyS1") )
+ if (g_access ("/dev/ttyS1", R_OK) == 0)
+ vik_combo_box_text_append (w->ser_b, "/dev/ttyS1");
+#endif
+ if ( gps_port && strcmp (gps_port, "usb:") )
+ vik_combo_box_text_append (w->ser_b, "usb:");
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX(w->ser_b), 0);