]> git.street.me.uk Git - andy/viking.git/commitdiff
Use combobox to select map type
authorGuilhem Bonnefille <guilhem.bonnefille@gmail.com>
Sun, 24 Jan 2010 16:01:39 +0000 (17:01 +0100)
committerGuilhem Bonnefille <guilhem.bonnefille@gmail.com>
Sun, 24 Jan 2010 16:01:39 +0000 (17:01 +0100)
Since recent changes, it is now possible for the user to add some map types.
So, the list of available map type can become really important.
The previous UI, based on a radio group, became less appropriate than a
combobox menu.
This is particularly true on devices with small screen.

src/uibuilder.c
src/util.h
src/vikmapslayer.c

index afc675870875b0fa9a5406eda8fcbf8441592948..81c689882f8420cf475cf4fbfa8361f943ffe6d3 100644 (file)
@@ -65,12 +65,13 @@ GtkWidget *a_uibuilder_new_widget ( VikLayerParam *param, VikLayerParamData data
               break;
             }
         }
               break;
             }
         }
-        gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), data.u );
+        else
+          gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), data.u );
       }
       else if ( param->type == VIK_LAYER_PARAM_STRING && param->widget_data )
       {
         gchar **pstr = param->widget_data;
       }
       else if ( param->type == VIK_LAYER_PARAM_STRING && param->widget_data )
       {
         gchar **pstr = param->widget_data;
-        rv = GTK_COMBO_BOX ( gtk_combo_box_entry_new_text () );
+        rv = GTK_WIDGET ( gtk_combo_box_entry_new_text () );
         if ( data.s )
           gtk_combo_box_append_text ( GTK_COMBO_BOX ( rv ), data.s );
         while ( *pstr )
         if ( data.s )
           gtk_combo_box_append_text ( GTK_COMBO_BOX ( rv ), data.s );
         while ( *pstr )
@@ -88,7 +89,7 @@ GtkWidget *a_uibuilder_new_widget ( VikLayerParam *param, VikLayerParamData data
         if ( param->extra_widget_data ) /* map of alternate uint values for options */
         {
           int i;
         if ( param->extra_widget_data ) /* map of alternate uint values for options */
         {
           int i;
-         int nb_elem = g_list_length(param->widget_data);
+          int nb_elem = g_list_length(param->widget_data);
           for ( i = 0; i < nb_elem; i++ )
             if ( GPOINTER_TO_UINT ( g_list_nth_data(param->extra_widget_data, i) ) == data.u )
             {
           for ( i = 0; i < nb_elem; i++ )
             if ( GPOINTER_TO_UINT ( g_list_nth_data(param->extra_widget_data, i) ) == data.u )
             {
index 8bb12e75f609efdf0ba1f979f26d12dba20a2c31..955b812eb11ced678b8cff712c9261dd211fc141 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
  *
 /*
  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
  *
- * Copyright (C) 2007 Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+ * Copyright (C) 2007-2009 Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
  * Based on:
  * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@linuxmag.com.br>
  *
  * Based on:
  * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@linuxmag.com.br>
  *
index 04a6fd9615085bb32ba987d9161738577025848e..2f65002a173c307a5ef708261f0d06073676c369 100644 (file)
@@ -2,6 +2,7 @@
  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
  *
  * Copyright (C) 2005, Evan Battaglia <viking@greentorch.org>
  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
  *
  * Copyright (C) 2005, Evan Battaglia <viking@greentorch.org>
+ * Copyright (C) 2010, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
  * UTM multi-zone stuff by Kit Transue <notlostyet@didactek.com>
  * Dynamic map type by Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
  *
  * UTM multi-zone stuff by Kit Transue <notlostyet@didactek.com>
  * Dynamic map type by Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
  *
@@ -78,10 +79,10 @@ static GList *__map_types = NULL;
 #define NUM_MAP_TYPES g_list_length(__map_types)
 
 /* List of label for each map type */
 #define NUM_MAP_TYPES g_list_length(__map_types)
 
 /* List of label for each map type */
-static GList *params_maptypes = NULL;
+static gchar **params_maptypes = NULL;
 
 /* Corresponding IDS. (Cf. field uniq_id in VikMapsLayer struct) */
 
 /* Corresponding IDS. (Cf. field uniq_id in VikMapsLayer struct) */
-static GList *params_maptypes_ids = NULL;
+static guint *params_maptypes_ids = NULL;
 
 /******** MAPZOOMS *********/
 
 
 /******** MAPZOOMS *********/
 
@@ -116,11 +117,11 @@ static VikLayerParamScale params_scales[] = {
 };
 
 VikLayerParam maps_layer_params[] = {
 };
 
 VikLayerParam maps_layer_params[] = {
-  { "mode", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Map Type:"), VIK_LAYER_WIDGET_RADIOGROUP, NULL, NULL },
+  { "mode", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Map Type:"), VIK_LAYER_WIDGET_COMBOBOX, NULL, NULL },
   { "directory", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("Maps Directory:"), VIK_LAYER_WIDGET_FOLDERENTRY },
   { "alpha", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Alpha:"), VIK_LAYER_WIDGET_HSCALE, params_scales },
   { "autodownload", VIK_LAYER_PARAM_BOOLEAN, VIK_LAYER_GROUP_NONE, N_("Autodownload maps:"), VIK_LAYER_WIDGET_CHECKBUTTON },
   { "directory", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("Maps Directory:"), VIK_LAYER_WIDGET_FOLDERENTRY },
   { "alpha", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Alpha:"), VIK_LAYER_WIDGET_HSCALE, params_scales },
   { "autodownload", VIK_LAYER_PARAM_BOOLEAN, VIK_LAYER_GROUP_NONE, N_("Autodownload maps:"), VIK_LAYER_WIDGET_CHECKBUTTON },
-  { "mapzoom", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Zoom Level:"), VIK_LAYER_WIDGET_COMBOBOX, params_mapzooms },
+  { "mapzoom", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Zoom Level:"), VIK_LAYER_WIDGET_COMBOBOX, params_mapzooms, NULL },
 };
 
 enum { PARAM_MAPTYPE=0, PARAM_CACHE_DIR, PARAM_ALPHA, PARAM_AUTODOWNLOAD, PARAM_MAPZOOM, NUM_PARAMS };
 };
 
 enum { PARAM_MAPTYPE=0, PARAM_CACHE_DIR, PARAM_ALPHA, PARAM_AUTODOWNLOAD, PARAM_MAPZOOM, NUM_PARAMS };
@@ -218,11 +219,18 @@ void maps_layer_register_map_source ( VikMapSource *map )
   const char *label = vik_map_source_get_label(map);
   g_assert(label != NULL);
 
   const char *label = vik_map_source_get_label(map);
   g_assert(label != NULL);
 
+  gsize len = 0;
+  if (params_maptypes)
+    len = g_strv_length (params_maptypes);
   /* Add the label */
   /* Add the label */
-  params_maptypes = g_list_append(params_maptypes, g_strdup(label));
+  params_maptypes = g_realloc (params_maptypes, (len+2)*sizeof(gchar*));
+  params_maptypes[len] = g_strdup (label);
+  params_maptypes[len+1] = NULL;
 
   /* Add the id */
 
   /* Add the id */
-  params_maptypes_ids = g_list_append(params_maptypes_ids, GUINT_TO_POINTER (id));
+  params_maptypes_ids = g_realloc (params_maptypes_ids, (len+2)*sizeof(guint));
+  params_maptypes_ids[len] = id;
+  params_maptypes_ids[len+1] = 0;
 
   /* We have to clone */
   VikMapSource *clone = VIK_MAP_SOURCE(g_object_ref(map));
 
   /* We have to clone */
   VikMapSource *clone = VIK_MAP_SOURCE(g_object_ref(map));
@@ -241,8 +249,8 @@ void maps_layer_register_map_source ( VikMapSource *map )
   maps_layer_params[0].extra_widget_data = params_maptypes_ids;
 }
 
   maps_layer_params[0].extra_widget_data = params_maptypes_ids;
 }
 
-#define MAPS_LAYER_NTH_LABEL(n) ((gchar*)g_list_nth_data(params_maptypes, (n)))
-#define MAPS_LAYER_NTH_ID(n) ((guint)g_list_nth_data(params_maptypes_ids, (n)))
+#define MAPS_LAYER_NTH_LABEL(n) (params_maptypes[n])
+#define MAPS_LAYER_NTH_ID(n) (params_maptypes_ids[n])
 #define MAPS_LAYER_NTH_TYPE(n) (VIK_MAP_SOURCE(g_list_nth_data(__map_types, (n))))
 
 gint vik_maps_layer_get_map_type(VikMapsLayer *vml)
 #define MAPS_LAYER_NTH_TYPE(n) (VIK_MAP_SOURCE(g_list_nth_data(__map_types, (n))))
 
 gint vik_maps_layer_get_map_type(VikMapsLayer *vml)