[Viking-devel] [PATCH] Add support for any device known by gpsbabel

2011-09-10 Thread Guilhem Bonnefille
There is no specific reason to restrict the list of supported devices
to a small number. Now, we directly offer the ability to use any
device supported by gpsbabel.

Signed-off-by: Guilhem Bonnefille guilhem.bonnefi...@gmail.com

---
 src/datasource_gps.c |   47 +--
 1 files changed, 17 insertions(+), 30 deletions(-)

diff --git a/src/datasource_gps.c b/src/datasource_gps.c
index 3e6ccce..388a802 100644
--- a/src/datasource_gps.c
+++ b/src/datasource_gps.c
@@ -43,6 +43,8 @@
 
 static gboolean gps_acquire_in_progress = FALSE;
 
+static gint last_active = 0;
+
 static gpointer datasource_gps_init_func ( );
 static void datasource_gps_get_cmd_string ( gpointer 
add_widgets_data_not_used, gchar **babelargs, gchar **input_file );
 static void datasource_gps_cleanup ( gpointer user_data );
@@ -105,7 +107,6 @@ static gpointer datasource_gps_init_func ()
 
 static void datasource_gps_get_cmd_string ( gpointer user_data, gchar 
**babelargs, gchar **input_file )
 {
-  char *proto = NULL;
   char *ser = NULL;
   char *device = NULL;
 #ifndef USE_NEW_COMBO_BOX
@@ -119,22 +120,8 @@ static void datasource_gps_get_cmd_string ( gpointer 
user_data, gchar **babelarg
   
   gps_acquire_in_progress = TRUE;
 
-#ifdef USE_NEW_COMBO_BOX
-  proto = gtk_combo_box_get_active_text(GTK_COMBO_BOX(w-proto_b));
-#else
-  proto = gtk_combo_box_get_active_iter(GTK_COMBO_BOX(w-proto_b),iter);
-#endif
-  if (!strcmp(proto, Garmin)) {
-device = garmin;
-  } else if (!strcmp(proto, Magellan)) {
-device = magellan;
-  }
-  else if (!strcmp(proto, DeLorme)) {
-device = delbin;
-  }
-  else {
-device = navilink;
-  }
+  last_active = gtk_combo_box_get_active(GTK_COMBO_BOX(w-proto_b));
+  device = ((BabelDevice*)g_list_nth_data(a_babel_device_list, 
last_active))-name;
 
   *babelargs = g_strdup_printf(-D 9 -t -w -i %s, device);
   /* device points to static content = no free */
@@ -154,7 +141,6 @@ static void datasource_gps_get_cmd_string ( gpointer 
user_data, gchar **babelarg
 
 static void datasource_gps_off ( gpointer user_data, gchar **babelargs, gchar 
**input_file )
 {
-  char *proto = NULL;
   char *ser = NULL;
   char *device = NULL;
 #ifndef USE_NEW_COMBO_BOX
@@ -171,15 +157,12 @@ static void datasource_gps_off ( gpointer user_data, 
gchar **babelargs, gchar **
 return;
   }
   
-#ifdef USE_NEW_COMBO_BOX
-  proto = gtk_combo_box_get_active_text(GTK_COMBO_BOX(w-proto_b));
-#else
-  proto = gtk_combo_box_get_active_iter(GTK_COMBO_BOX(w-proto_b),iter);
-#endif
-  if (!strcmp(proto, Garmin)) {
+  last_active = gtk_combo_box_get_active(GTK_COMBO_BOX(w-proto_b));
+  device = ((BabelDevice*)g_list_nth_data(a_babel_device_list, 
last_active))-name;
+  if (!strcmp(device, garmin)) {
 device = garmin,power_off;
   }
-  else if (!strcmp(proto, NAViLink)) {
+  else if (!strcmp(device, navilink)) {
 device = navilink,power_off;
   }
   else {
@@ -333,6 +316,13 @@ static void datasource_gps_progress ( BabelProgressCode c, 
gpointer data, acq_di
   }
 }
 
+void append_element (gpointer elem, gpointer user_data)
+{
+  GtkComboBox *combo = GTK_COMBO_BOX (user_data);
+  const gchar *text = ((BabelDevice*)elem)-label;
+  gtk_combo_box_append_text (combo, text);
+}
+
 void datasource_gps_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, 
gpointer user_data )
 {
   gps_user_data_t *w = (gps_user_data_t *)user_data;
@@ -340,11 +330,8 @@ void datasource_gps_add_setup_widgets ( GtkWidget *dialog, 
VikViewport *vvp, gpo
 
   w-proto_l = gtk_label_new (_(GPS Protocol:));
   w-proto_b = GTK_COMBO_BOX(gtk_combo_box_new_text ());
-  gtk_combo_box_append_text (w-proto_b, Garmin);
-  gtk_combo_box_append_text (w-proto_b, Magellan);
-  gtk_combo_box_append_text (w-proto_b, DeLorme);
-  gtk_combo_box_append_text (w-proto_b, NAViLink);
-  gtk_combo_box_set_active (w-proto_b, 0);
+  g_list_foreach (a_babel_device_list, append_element, w-proto_b);
+  gtk_combo_box_set_active (w-proto_b, last_active);
   g_object_ref(w-proto_b);
 
   w-ser_l = gtk_label_new (_(Serial Port:));
-- 
tg: (1611d03..) t/acquire/improve-gps (depends on: 
t/acquire/introspect-gpsbabel)

--
Malware Security Report: Protecting Your Business, Customers, and the 
Bottom Line. Protect your business and customers by understanding the 
threat from malware and how it can impact your online business. 
http://www.accelacomm.com/jaw/sfnl/114/51427462/
___
Viking-devel mailing list
Viking-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/viking-devel
Viking home page: http://viking.sf.net/


Re: [Viking-devel] [PATCH] Add support for any device known by gpsbabel

2011-09-10 Thread Guilhem Bonnefille
2011/9/10 Guilhem Bonnefille guilhem.bonnefi...@gmail.com:
 There is no specific reason to restrict the list of supported devices
 to a small number. Now, we directly offer the ability to use any
 device supported by gpsbabel.

 Signed-off-by: Guilhem Bonnefille guilhem.bonnefi...@gmail.com


Waiting for an improvement of the patch to import files, I suggest to
apply this patch. It use the previous patches to introspect gpsbabel
and discover the list of supported device.

A future path can certainly improve the dialog box to acquire data
from device. For example, adding track/route/waypoint options, or
other usefull options (I do not use this feature as my GPS device
implement usb_storage support).

Any comment?
-- 
Guilhem BONNEFILLE
-=- JID: gu...@im.apinc.org MSN: guilhem_bonnefi...@hotmail.com
-=- mailto:guilhem.bonnefi...@gmail.com
-=- http://nathguil.free.fr/

--
Malware Security Report: Protecting Your Business, Customers, and the 
Bottom Line. Protect your business and customers by understanding the 
threat from malware and how it can impact your online business. 
http://www.accelacomm.com/jaw/sfnl/114/51427462/
___
Viking-devel mailing list
Viking-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/viking-devel
Viking home page: http://viking.sf.net/


Re: [Viking-devel] [PATCH] Add support for any device known by gpsbabel

2011-09-10 Thread Guilhem Bonnefille
2011/9/10 Robert Norris rw_nor...@hotmail.com:


 A future path can certainly improve the dialog box to acquire data
 from device. For example, adding track/route/waypoint options, or
 other usefull options (I do not use this feature as my GPS device
 implement usb_storage support).

 Any comment?

 I have been working on this for a while see (newly published):

 https://github.com/rnorris/viking/commits/GPS-DataTypes

 [No routes yet...]


 However I was waiting to complete the Route support first:

 https://github.com/rnorris/viking/commits/GPX-RouteSupport

 I also have code for GPS Device Defaults stored in new preferences - but that 
 will have to be reworked now that the list of protocols is dynamic.

 I was also working on putting the Acquire menu into the trackwaypoint layer 
 menu (newly published):
 https://github.com/rnorris/viking/commits/TrackWaypoint-Acquire-GPSUp

 This will need addition for your File import method.

 Also I'm working on a GPS upload from the trackwaypoint layer.
 This involves reworking the all the GPS code and commonizing stuff, and is a 
 work in progress. (and better if route support changes applied first too).

Nice.

Following your previous comments, I will keep my ImportFile patch in
work-in-progress state for some time.

As other patches do not conflict, I propose:
- you push TrackWaypoint-Acquire-GPSUp onto master
- if ready, you push GPS-Device-Defaults onto master
- I push the needed patches for my Dynamic-Device-List (updating it if
you decided to push GPS-Device-Defaults)

All this job can be done in the week-end.
-- 
Guilhem BONNEFILLE
-=- JID: gu...@im.apinc.org MSN: guilhem_bonnefi...@hotmail.com
-=- mailto:guilhem.bonnefi...@gmail.com
-=- http://nathguil.free.fr/

--
Malware Security Report: Protecting Your Business, Customers, and the 
Bottom Line. Protect your business and customers by understanding the 
threat from malware and how it can impact your online business. 
http://www.accelacomm.com/jaw/sfnl/114/51427462/
___
Viking-devel mailing list
Viking-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/viking-devel
Viking home page: http://viking.sf.net/