]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikmapslayer.c
Update libjpeg utilities from exif command line tool to version 0.6.21
[andy/viking.git] / src / vikmapslayer.c
index 1b6ce54a9eef930f6c9bc5398dfdc95fc324de92..c8d027b9cde6381ef5ccb5dd1c086d80183d9ee5 100644 (file)
@@ -121,16 +121,16 @@ static VikLayerParamData alpha_default ( void ) { return VIK_LPD_UINT ( 255 ); }
 static VikLayerParamData mapzoom_default ( void ) { return VIK_LPD_UINT ( 0 ); }
 
 VikLayerParam maps_layer_params[] = {
 static VikLayerParamData mapzoom_default ( void ) { return VIK_LPD_UINT ( 0 ); }
 
 VikLayerParam maps_layer_params[] = {
-  { VIK_LAYER_MAPS, "mode", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Map Type:"), VIK_LAYER_WIDGET_COMBOBOX, NULL, NULL, NULL, mode_default },
-  { VIK_LAYER_MAPS, "directory", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("Maps Directory:"), VIK_LAYER_WIDGET_FOLDERENTRY, NULL, NULL, NULL, directory_default },
+  { VIK_LAYER_MAPS, "mode", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Map Type:"), VIK_LAYER_WIDGET_COMBOBOX, NULL, NULL, NULL, mode_default, NULL, NULL },
+  { VIK_LAYER_MAPS, "directory", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("Maps Directory:"), VIK_LAYER_WIDGET_FOLDERENTRY, NULL, NULL, NULL, directory_default, NULL, NULL },
   { VIK_LAYER_MAPS, "alpha", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Alpha:"), VIK_LAYER_WIDGET_HSCALE, params_scales, NULL,
   { VIK_LAYER_MAPS, "alpha", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Alpha:"), VIK_LAYER_WIDGET_HSCALE, params_scales, NULL,
-    N_("Control the Alpha value for transparency effects"), alpha_default },
-  { VIK_LAYER_MAPS, "autodownload", VIK_LAYER_PARAM_BOOLEAN, VIK_LAYER_GROUP_NONE, N_("Autodownload maps:"), VIK_LAYER_WIDGET_CHECKBUTTON, NULL, NULL, NULL, vik_lpd_true_default },
+    N_("Control the Alpha value for transparency effects"), alpha_default, NULL, NULL },
+  { VIK_LAYER_MAPS, "autodownload", VIK_LAYER_PARAM_BOOLEAN, VIK_LAYER_GROUP_NONE, N_("Autodownload maps:"), VIK_LAYER_WIDGET_CHECKBUTTON, NULL, NULL, NULL, vik_lpd_true_default, NULL, NULL },
   { VIK_LAYER_MAPS, "adlonlymissing", VIK_LAYER_PARAM_BOOLEAN, VIK_LAYER_GROUP_NONE, N_("Autodownload Only Gets Missing Maps:"), VIK_LAYER_WIDGET_CHECKBUTTON, NULL, NULL,
   { VIK_LAYER_MAPS, "adlonlymissing", VIK_LAYER_PARAM_BOOLEAN, VIK_LAYER_GROUP_NONE, N_("Autodownload Only Gets Missing Maps:"), VIK_LAYER_WIDGET_CHECKBUTTON, NULL, NULL,
-    N_("Using this option avoids attempting to update already acquired tiles. This can be useful if you want to restrict the network usage, without having to resort to manual control. Only applies when 'Autodownload Maps' is on."), vik_lpd_false_default },
+    N_("Using this option avoids attempting to update already acquired tiles. This can be useful if you want to restrict the network usage, without having to resort to manual control. Only applies when 'Autodownload Maps' is on."), vik_lpd_false_default, NULL, NULL },
   { VIK_LAYER_MAPS, "mapzoom", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Zoom Level:"), VIK_LAYER_WIDGET_COMBOBOX, params_mapzooms, NULL,
     N_("Determines the method of displaying map tiles for the current zoom level. 'Viking Zoom Level' uses the best matching level, otherwise setting a fixed value will always use map tiles of the specified value regardless of the actual zoom level."),
   { VIK_LAYER_MAPS, "mapzoom", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Zoom Level:"), VIK_LAYER_WIDGET_COMBOBOX, params_mapzooms, NULL,
     N_("Determines the method of displaying map tiles for the current zoom level. 'Viking Zoom Level' uses the best matching level, otherwise setting a fixed value will always use map tiles of the specified value regardless of the actual zoom level."),
-    mapzoom_default },
+    mapzoom_default, NULL, NULL },
 };
 
 enum {
 };
 
 enum {
@@ -244,9 +244,6 @@ struct _VikMapsLayer {
   GtkMenu *dl_right_click_menu;
   VikCoord redownload_ul, redownload_br; /* right click menu only */
   VikViewport *redownload_vvp;
   GtkMenu *dl_right_click_menu;
   VikCoord redownload_ul, redownload_br; /* right click menu only */
   VikViewport *redownload_vvp;
-
-  gboolean license_notice_shown; // FALSE for new maps only, otherwise
-                                 // TRUE for saved maps & other layer changes as we don't need to show it again
 };
 
 enum { REDOWNLOAD_NONE = 0,    /* download only missing maps */
 };
 
 enum { REDOWNLOAD_NONE = 0,    /* download only missing maps */
@@ -284,18 +281,6 @@ void maps_layer_init ()
 /******** MAPS LAYER TYPES **************/
 /****************************************/
 
 /******** MAPS LAYER TYPES **************/
 /****************************************/
 
-int _get_index_for_id ( guint id )
-{
-  int index = 0 ;
-  while (params_maptypes_ids[index] != 0)
-  {
-    if (params_maptypes_ids[index] == id)
-      return index;
-    index++;
-  }
-  return -1;
-}
-
 void _add_map_source ( guint id, const char *label, VikMapSource *map )
 {
   gsize len = 0;
 void _add_map_source ( guint id, const char *label, VikMapSource *map )
 {
   gsize len = 0;
@@ -501,7 +486,7 @@ GType vik_maps_layer_get_type ()
 /************** PARAMETERS **************/
 /****************************************/
 
 /************** PARAMETERS **************/
 /****************************************/
 
-static guint map_index_to_uniq_id (guint8 index)
+static guint map_index_to_uniq_id (guint16 index)
 {
   g_assert ( index < NUM_MAP_TYPES );
   return vik_map_source_get_uniq_id(MAPS_LAYER_NTH_TYPE(index));
 {
   g_assert ( index < NUM_MAP_TYPES );
   return vik_map_source_get_uniq_id(MAPS_LAYER_NTH_TYPE(index));
@@ -516,24 +501,47 @@ static guint map_uniq_id_to_index ( guint uniq_id )
   return NUM_MAP_TYPES; /* no such thing */
 }
 
   return NUM_MAP_TYPES; /* no such thing */
 }
 
-void vik_maps_layer_pretend_licence_shown ( VikMapsLayer *vml )
+#define VIK_SETTINGS_MAP_LICENSE_SHOWN "map_license_shown"
+
+/**
+ * Convenience function to display the license
+ */
+static void maps_show_license ( GtkWindow *parent, VikMapSource *map )
 {
 {
-  vml->license_notice_shown = TRUE;
+  a_dialog_license ( parent,
+                    vik_map_source_get_label (map),
+                    vik_map_source_get_license (map),
+                    vik_map_source_get_license_url (map) );
 }
 
 static gboolean maps_layer_set_param ( VikMapsLayer *vml, guint16 id, VikLayerParamData data, VikViewport *vvp, gboolean is_file_operation )
 {
 }
 
 static gboolean maps_layer_set_param ( VikMapsLayer *vml, guint16 id, VikLayerParamData data, VikViewport *vvp, gboolean is_file_operation )
 {
-  // When loading from a file don't need the license reminder
-  if ( is_file_operation )
-    vml->license_notice_shown = TRUE;
-
   switch ( id )
   {
     case PARAM_CACHE_DIR: maps_layer_set_cache_dir ( vml, data.s ); break;
     case PARAM_MAPTYPE: {
       gint maptype = map_uniq_id_to_index(data.u);
   switch ( id )
   {
     case PARAM_CACHE_DIR: maps_layer_set_cache_dir ( vml, data.s ); break;
     case PARAM_MAPTYPE: {
       gint maptype = map_uniq_id_to_index(data.u);
-      if ( maptype == NUM_MAP_TYPES ) g_warning(_("Unknown map type"));
-      else vml->maptype = maptype;
+      if ( maptype == NUM_MAP_TYPES )
+        g_warning(_("Unknown map type"));
+      else {
+        vml->maptype = maptype;
+
+        // When loading from a file don't need the license reminder - ensure it's saved into the 'seen' list
+        if ( is_file_operation ) {
+          a_settings_set_integer_list_containing ( VIK_SETTINGS_MAP_LICENSE_SHOWN, maptype );
+        }
+        else {
+          VikMapSource *map = MAPS_LAYER_NTH_TYPE(vml->maptype);
+          if (vik_map_source_get_license (map) != NULL) {
+            // Check if licence for this map type has been shown before
+            if ( ! a_settings_get_integer_list_contains ( VIK_SETTINGS_MAP_LICENSE_SHOWN, maptype ) ) {
+              if ( vvp )
+                maps_show_license ( VIK_GTK_WINDOW_FROM_WIDGET(vvp), map );
+              a_settings_set_integer_list_containing ( VIK_SETTINGS_MAP_LICENSE_SHOWN, maptype );
+            }
+          }
+        }
+      }
       break;
     }
     case PARAM_ALPHA: if ( data.u <= 255 ) vml->alpha = data.u; break;
       break;
     }
     case PARAM_ALPHA: if ( data.u <= 255 ) vml->alpha = data.u; break;
@@ -603,7 +611,7 @@ static VikMapsLayer *maps_layer_new ( VikViewport *vvp )
   vml->last_ympp = 0.0;
 
   vml->dl_right_click_menu = NULL;
   vml->last_ympp = 0.0;
 
   vml->dl_right_click_menu = NULL;
-  vml->license_notice_shown = FALSE;
+  //vml->license_notice_shown = FALSE;
 
   return vml;
 }
 
   return vml;
 }
@@ -637,14 +645,6 @@ static void maps_layer_post_read (VikLayer *vl, VikViewport *vp, gboolean from_f
       a_dialog_warning_msg ( VIK_GTK_WINDOW_FROM_WIDGET(vp), msg );
       g_free(msg);
     }
       a_dialog_warning_msg ( VIK_GTK_WINDOW_FROM_WIDGET(vp), msg );
       g_free(msg);
     }
-
-    if (vik_map_source_get_license (map) != NULL) {
-      if ( ! vml->license_notice_shown ) {
-       a_dialog_license (VIK_GTK_WINDOW_FROM_WIDGET(vp), vik_map_source_get_label (map),
-                         vik_map_source_get_license (map), vik_map_source_get_license_url (map) );
-       vml->license_notice_shown = TRUE;
-      }
-    }
   }
 }
 
   }
 }
 
@@ -679,6 +679,8 @@ static GdkPixbuf *pixbuf_set_alpha ( GdkPixbuf *pixbuf, guint8 alpha )
     GdkPixbuf *tmp = gdk_pixbuf_add_alpha(pixbuf,FALSE,0,0,0);
     g_object_unref(G_OBJECT(pixbuf));
     pixbuf = tmp;
     GdkPixbuf *tmp = gdk_pixbuf_add_alpha(pixbuf,FALSE,0,0,0);
     g_object_unref(G_OBJECT(pixbuf));
     pixbuf = tmp;
+    if ( !pixbuf )
+      return NULL;
   }
 
   pixels = gdk_pixbuf_get_pixels(pixbuf);
   }
 
   pixels = gdk_pixbuf_get_pixels(pixbuf);
@@ -741,9 +743,10 @@ static GdkPixbuf *get_pixbuf( VikMapsLayer *vml, gint mode, MapCoord *mapcoord,
           if ( xshrinkfactor != 1.0 || yshrinkfactor != 1.0 )
             pixbuf = pixbuf_shrink ( pixbuf, xshrinkfactor, yshrinkfactor );
 
           if ( xshrinkfactor != 1.0 || yshrinkfactor != 1.0 )
             pixbuf = pixbuf_shrink ( pixbuf, xshrinkfactor, yshrinkfactor );
 
-          a_mapcache_add ( pixbuf, mapcoord->x, mapcoord->y, 
-              mapcoord->z, vik_map_source_get_uniq_id(MAPS_LAYER_NTH_TYPE(vml->maptype)),
-              mapcoord->scale, vml->alpha, xshrinkfactor, yshrinkfactor );
+          if ( pixbuf )
+            a_mapcache_add ( pixbuf, mapcoord->x, mapcoord->y,
+                             mapcoord->z, vik_map_source_get_uniq_id(MAPS_LAYER_NTH_TYPE(vml->maptype)),
+                             mapcoord->scale, vml->alpha, xshrinkfactor, yshrinkfactor );
       }
     }
   }
       }
     }
   }
@@ -1544,6 +1547,18 @@ static void maps_layer_redownload_all_onscreen_maps ( gpointer vml_vvp[2] )
   download_onscreen_maps( vml_vvp, REDOWNLOAD_ALL);
 }
 
   download_onscreen_maps( vml_vvp, REDOWNLOAD_ALL);
 }
 
+static void maps_layers_about ( gpointer vml_vvp[2] )
+{
+  VikMapsLayer *vml = vml_vvp[0];
+  VikMapSource *map = MAPS_LAYER_NTH_TYPE(vml->maptype);
+
+  if ( vik_map_source_get_license (map) )
+    maps_show_license ( VIK_GTK_WINDOW_FROM_LAYER(vml), map );
+  else
+    a_dialog_info_msg ( VIK_GTK_WINDOW_FROM_LAYER(vml),
+                        vik_map_source_get_label (map) );
+}
+
 /**
  * maps_layer_how_many_maps:
  * Copied from maps_layer_download_section but without the actual download and this returns a value
 /**
  * maps_layer_how_many_maps:
  * Copied from maps_layer_download_section but without the actual download and this returns a value
@@ -1841,6 +1856,11 @@ static void maps_layer_add_menu_items ( VikMapsLayer *vml, GtkMenu *menu, VikLay
   g_signal_connect_swapped ( G_OBJECT(item), "activate", G_CALLBACK(maps_layer_download_all), pass_along );
   gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
   gtk_widget_show ( item );
   g_signal_connect_swapped ( G_OBJECT(item), "activate", G_CALLBACK(maps_layer_download_all), pass_along );
   gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
   gtk_widget_show ( item );
+
+  item = gtk_image_menu_item_new_from_stock ( GTK_STOCK_ABOUT, NULL );
+  g_signal_connect_swapped ( G_OBJECT(item), "activate", G_CALLBACK(maps_layers_about), pass_along );
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+  gtk_widget_show ( item );
 }
 
 /**
 }
 
 /**