]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikdemlayer.c
Fix translatable string with variable argument
[andy/viking.git] / src / vikdemlayer.c
index d6f7ca00088b21f62733d86aca5b9970a4a9ccc8..f1242a0d6b38bb463528a19f562750da49dc4a84 100644 (file)
 #include <string.h>
 #endif
 #include <stdlib.h>
+#include <glib/gstdio.h>
 #include <glib/gi18n.h>
 
-#include "config.h"
-#include "globals.h"
-#include "coords.h"
-#include "vikcoord.h"
-#include "download.h"
 #include "background.h"
-#include "vikwaypoint.h"
-#include "viktrack.h"
-#include "vikviewport.h"
-#include "viktreeview.h"
-#include "viklayer.h"
-#include "vikaggregatelayer.h"
-#include "viklayerspanel.h"
+#include "viking.h"
 #include "vikmapslayer.h"
 #include "vikdemlayer.h"
-#include "dialog.h"
-
 #include "dem.h"
 #include "dems.h"
-
 #include "icons/icons.h"
 
 #define MAPS_CACHE_DIR maps_layer_default_dir()
 
 #define UNUSED_LINE_THICKNESS 3
 
+static VikDEMLayer *dem_layer_new ( VikViewport *vvp );
+static void dem_layer_draw ( VikDEMLayer *vdl, VikViewport *vp );
+static void dem_layer_free ( VikDEMLayer *vdl );
+static VikDEMLayer *dem_layer_create ( VikViewport *vp );
 static const gchar* dem_layer_tooltip( VikDEMLayer *vdl );
 static void dem_layer_marshall( VikDEMLayer *vdl, guint8 **data, gint *len );
 static VikDEMLayer *dem_layer_unmarshall( guint8 *data, gint len, VikViewport *vvp );
@@ -114,13 +105,22 @@ enum { DEM_TYPE_HEIGHT = 0,
        DEM_TYPE_NONE,
 };
 
+static VikLayerParamData color_default ( void ) {
+  VikLayerParamData data; gdk_color_parse ( "blue", &data.c ); return data;
+}
+
+static VikLayerParamData source_default ( void ) { return VIK_LPD_UINT ( DEM_SOURCE_SRTM ); }
+static VikLayerParamData type_default ( void ) { return VIK_LPD_UINT ( DEM_TYPE_HEIGHT ); }
+static VikLayerParamData min_elev_default ( void ) { return VIK_LPD_DOUBLE ( 0.0 ); }
+static VikLayerParamData max_elev_default ( void ) { return VIK_LPD_DOUBLE ( 1000.0 ); }
+
 static VikLayerParam dem_layer_params[] = {
-  { "files", VIK_LAYER_PARAM_STRING_LIST, VIK_LAYER_GROUP_NONE, N_("DEM Files:"), VIK_LAYER_WIDGET_FILELIST },
-  { "source", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Download Source:"), VIK_LAYER_WIDGET_RADIOGROUP_STATIC, params_source, NULL },
-  { "color", VIK_LAYER_PARAM_COLOR, VIK_LAYER_GROUP_NONE, N_("Min Elev Color:"), VIK_LAYER_WIDGET_COLOR, 0 },
-  { "type", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Type:"), VIK_LAYER_WIDGET_RADIOGROUP_STATIC, params_type, NULL },
-  { "min_elev", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_GROUP_NONE, N_("Min Elev:"), VIK_LAYER_WIDGET_SPINBUTTON, param_scales + 0 },
-  { "max_elev", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_GROUP_NONE, N_("Max Elev:"), VIK_LAYER_WIDGET_SPINBUTTON, param_scales + 0 },
+  { VIK_LAYER_DEM, "files", VIK_LAYER_PARAM_STRING_LIST, VIK_LAYER_GROUP_NONE, N_("DEM Files:"), VIK_LAYER_WIDGET_FILELIST, NULL, NULL, NULL, NULL, NULL, NULL },
+  { VIK_LAYER_DEM, "source", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Download Source:"), VIK_LAYER_WIDGET_RADIOGROUP_STATIC, params_source, NULL, NULL, source_default, NULL, NULL },
+  { VIK_LAYER_DEM, "color", VIK_LAYER_PARAM_COLOR, VIK_LAYER_GROUP_NONE, N_("Min Elev Color:"), VIK_LAYER_WIDGET_COLOR, NULL, NULL, NULL, color_default, NULL, NULL },
+  { VIK_LAYER_DEM, "type", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Type:"), VIK_LAYER_WIDGET_RADIOGROUP_STATIC, params_type, NULL, NULL, type_default, NULL, NULL },
+  { VIK_LAYER_DEM, "min_elev", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_GROUP_NONE, N_("Min Elev:"), VIK_LAYER_WIDGET_SPINBUTTON, param_scales + 0, NULL, NULL, min_elev_default, NULL, NULL },
+  { VIK_LAYER_DEM, "max_elev", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_GROUP_NONE, N_("Max Elev:"), VIK_LAYER_WIDGET_SPINBUTTON, param_scales + 0, NULL, NULL, max_elev_default, NULL, NULL },
 };
 
 
@@ -134,7 +134,9 @@ static VikToolInterface dem_tools[] = {
   { { "DEMDownload", "vik-icon-DEM Download", N_("_DEM Download"), NULL, N_("DEM Download"), 0 },
     (VikToolConstructorFunc) dem_layer_download_create, NULL, NULL, NULL,
     (VikToolMouseFunc) dem_layer_download_click, NULL,  (VikToolMouseFunc) dem_layer_download_release,
-    (VikToolKeyFunc) NULL, GDK_CURSOR_IS_PIXMAP, &cursor_demdl_pixbuf },
+    (VikToolKeyFunc) NULL,
+    FALSE,
+    GDK_CURSOR_IS_PIXMAP, &cursor_demdl_pixbuf },
 };
 
 
@@ -182,7 +184,9 @@ static const guint DEM_N_GRADIENT_COLORS = sizeof(dem_gradient_colors)/sizeof(de
 
 
 VikLayerInterface vik_dem_layer_interface = {
+  "DEM",
   N_("DEM"),
+  "<control><shift>D",
   &vikdemlayer_pixbuf,
 
   dem_tools,
@@ -195,13 +199,13 @@ VikLayerInterface vik_dem_layer_interface = {
 
   VIK_MENU_ITEM_ALL,
 
-  (VikLayerFuncCreate)                  vik_dem_layer_create,
+  (VikLayerFuncCreate)                  dem_layer_create,
   (VikLayerFuncRealize)                 NULL,
   (VikLayerFuncPostRead)                dem_layer_post_read,
-  (VikLayerFuncFree)                    vik_dem_layer_free,
+  (VikLayerFuncFree)                    dem_layer_free,
 
   (VikLayerFuncProperties)              NULL,
-  (VikLayerFuncDraw)                    vik_dem_layer_draw,
+  (VikLayerFuncDraw)                    dem_layer_draw,
   (VikLayerFuncChangeCoordMode)         NULL,
 
   (VikLayerFuncSetMenuItemsSelection)   NULL,
@@ -221,6 +225,7 @@ VikLayerInterface vik_dem_layer_interface = {
 
   (VikLayerFuncSetParam)                dem_layer_set_param,
   (VikLayerFuncGetParam)                dem_layer_get_param,
+  (VikLayerFuncChangeParam)             NULL,
 
   (VikLayerFuncReadFileData)            NULL,
   (VikLayerFuncWriteFileData)           NULL,
@@ -245,9 +250,12 @@ struct _VikDEMLayer {
   GList *files;
   gdouble min_elev;
   gdouble max_elev;
-  GdkGC *color;
+  GdkColor color;
   guint source;
   guint type;
+
+  // right click menu only stuff - similar to mapslayer
+  GtkMenu *right_click_menu;
 };
 
 GType vik_dem_layer_get_type ()
@@ -288,13 +296,16 @@ static void dem_layer_marshall( VikDEMLayer *vdl, guint8 **data, gint *len )
 
 static VikDEMLayer *dem_layer_unmarshall( guint8 *data, gint len, VikViewport *vvp )
 {
-  VikDEMLayer *rv = vik_dem_layer_new ();
+  VikDEMLayer *rv = dem_layer_new ( vvp );
   gint i;
 
   /* TODO: share GCS between layers */
-  for ( i = 0; i < DEM_N_HEIGHT_COLORS; i++ )
-    rv->gcs[i] = vik_viewport_new_gc ( vvp, dem_height_colors[i], UNUSED_LINE_THICKNESS );
-
+  for ( i = 0; i < DEM_N_HEIGHT_COLORS; i++ ) {
+    if ( i == 0 )
+      rv->gcs[i] = vik_viewport_new_gc_from_color ( vvp, &(rv->color), UNUSED_LINE_THICKNESS );
+    else
+      rv->gcs[i] = vik_viewport_new_gc ( vvp, dem_height_colors[i], UNUSED_LINE_THICKNESS );
+  }
   for ( i = 0; i < DEM_N_GRADIENT_COLORS; i++ )
     rv->gcsgradient[i] = vik_viewport_new_gc ( vvp, dem_gradient_colors[i], UNUSED_LINE_THICKNESS );
 
@@ -324,7 +335,7 @@ static int dem_layer_load_list_thread ( dem_load_thread_data *dltd, gpointer thr
   //gdk_threads_enter();
   // Test is helpful to prevent Gtk-CRITICAL warnings if the program is exitted whilst loading
   if ( IS_VIK_LAYER(dltd->vdl) )
-    vik_layer_emit_update ( VIK_LAYER(dltd->vdl), TRUE ); // Yes update from background thread
+    vik_layer_emit_update ( VIK_LAYER(dltd->vdl) ); // NB update from background thread
   //gdk_threads_leave();
 
   return result;
@@ -343,11 +354,45 @@ static void dem_layer_thread_cancel ( dem_load_thread_data *data )
   // Thus we can see/use what was done
 }
 
+/**
+ * Process the list of DEM files and convert each one to a relative path
+ */
+static GList *dem_layer_convert_to_relative_filenaming ( GList *files )
+{
+  gchar *cwd = g_get_current_dir();
+  if ( !cwd )
+    return files;
+
+  GList *relfiles = NULL;
+
+  while ( files ) {
+    gchar *file = g_strdup ( file_GetRelativeFilename ( cwd, files->data ) );
+    relfiles = g_list_prepend ( relfiles, file );
+    files = files->next;
+  }
+
+  g_free ( cwd );
+
+  if ( relfiles ) {
+    // Replacing current list, so delete old values first.
+    GList *iter = files;
+    while ( iter ) {
+      g_free ( iter->data );
+      iter = iter->next;
+    }
+    g_list_free ( files );
+
+    return relfiles;
+  }
+
+  return files;
+}
+
 gboolean dem_layer_set_param ( VikDEMLayer *vdl, guint16 id, VikLayerParamData data, VikViewport *vp, gboolean is_file_operation )
 {
   switch ( id )
   {
-    case PARAM_COLOR: gdk_gc_set_rgb_fg_color ( vdl->gcs[0], &(data.c) ); break;
+    case PARAM_COLOR: vdl->color = data.c; gdk_gc_set_rgb_fg_color ( vdl->gcs[0], &(vdl->color) ); break;
     case PARAM_SOURCE: vdl->source = data.u; break;
     case PARAM_TYPE: vdl->type = data.u; break;
     case PARAM_MIN_ELEV:
@@ -372,18 +417,21 @@ gboolean dem_layer_set_param ( VikDEMLayer *vdl, guint16 id, VikLayerParamData d
       a_dems_list_free ( vdl->files );
       // Set file list so any other intermediate screen drawing updates will show currently loaded DEMs by the working thread
       vdl->files = data.sl;
-      // Thread Load
-      dem_load_thread_data *dltd = g_malloc ( sizeof(dem_load_thread_data) );
-      dltd->vdl = vdl;
-      dltd->vdl->files = data.sl;
-
-      a_background_thread ( VIK_GTK_WINDOW_FROM_WIDGET(vp),
-                           _("DEM Loading"),
-                           (vik_thr_func) dem_layer_load_list_thread,
-                           dltd,
-                           (vik_thr_free_func) dem_layer_thread_data_free,
-                           (vik_thr_free_func) dem_layer_thread_cancel,
-                           g_list_length ( data.sl ) ); // Number of DEM files
+      // No need for thread if no files
+      if ( vdl->files ) {
+        // Thread Load
+        dem_load_thread_data *dltd = g_malloc ( sizeof(dem_load_thread_data) );
+        dltd->vdl = vdl;
+        dltd->vdl->files = data.sl;
+
+        a_background_thread ( VIK_GTK_WINDOW_FROM_WIDGET(vp),
+                              _("DEM Loading"),
+                              (vik_thr_func) dem_layer_load_list_thread,
+                              dltd,
+                              (vik_thr_free_func) dem_layer_thread_data_free,
+                              (vik_thr_free_func) dem_layer_thread_cancel,
+                              g_list_length ( data.sl ) ); // Number of DEM files
+      }
       break;
     }
   }
@@ -395,10 +443,16 @@ static VikLayerParamData dem_layer_get_param ( VikDEMLayer *vdl, guint16 id, gbo
   VikLayerParamData rv;
   switch ( id )
   {
-    case PARAM_FILES: rv.sl = vdl->files; break;
+    case PARAM_FILES:
+      rv.sl = vdl->files;
+      if ( is_file_operation )
+        // Save in relative format if necessary
+        if ( a_vik_get_file_ref_format() == VIK_FILE_REF_FORMAT_RELATIVE )
+          rv.sl = dem_layer_convert_to_relative_filenaming ( rv.sl );
+      break;
     case PARAM_SOURCE: rv.u = vdl->source; break;
     case PARAM_TYPE: rv.u = vdl->type; break;
-    case PARAM_COLOR: vik_gc_get_fg_color ( vdl->gcs[0], &(rv.c) ); break;
+    case PARAM_COLOR: rv.c = vdl->color; break;
     case PARAM_MIN_ELEV:
       /* Convert for display in desired units
          NB file operation always in internal units (metres) */
@@ -424,11 +478,11 @@ static void dem_layer_post_read ( VikLayer *vl, VikViewport *vp, gboolean from_f
   /* nothing ATM, but keep in case it's needed the future */
 }
 
-VikDEMLayer *vik_dem_layer_new ( )
+static VikDEMLayer *dem_layer_new ( VikViewport *vvp )
 {
   VikDEMLayer *vdl = VIK_DEM_LAYER ( g_object_new ( VIK_DEM_LAYER_TYPE, NULL ) );
 
-  vik_layer_init ( VIK_LAYER(vdl), VIK_LAYER_DEM );
+  vik_layer_set_type ( VIK_LAYER(vdl), VIK_LAYER_DEM );
 
   vdl->files = NULL;
 
@@ -436,10 +490,11 @@ VikDEMLayer *vik_dem_layer_new ( )
   vdl->gcsgradient = g_malloc(sizeof(GdkGC *)*DEM_N_GRADIENT_COLORS);
   /* make new gcs only if we need it (copy layer -> use old) */
 
-  vdl->min_elev = 0.0;
-  vdl->max_elev = 1000.0;
-  vdl->source = DEM_SOURCE_SRTM;
-  vdl->type = DEM_TYPE_HEIGHT;
+  // Ensure the base GC is available so the default colour can be applied
+  if ( vvp ) vdl->gcs[0] = vik_viewport_new_gc ( vvp, "#0000FF", 1 );
+
+  vik_layer_set_defaults ( VIK_LAYER(vdl), vvp );
+
   return vdl;
 }
 
@@ -515,7 +570,7 @@ static void vik_dem_layer_draw_dem ( VikDEMLayer *vdl, VikViewport *vp, VikDEM *
     if ( y2 > vik_viewport_get_height(vp) ) y2=vik_viewport_get_height(vp);
     if ( x2 < 0 ) x2 = 0;
     if ( y1 < 0 ) y1 = 0;
-    vik_viewport_draw_rectangle ( vp, GTK_WIDGET(vp)->style->black_gc, 
+    vik_viewport_draw_rectangle ( vp, gtk_widget_get_style(GTK_WIDGET(vp))->black_gc,
        FALSE, x2, y1, x1-x2, y2-y1 );
     return;
   }
@@ -567,7 +622,7 @@ static void vik_dem_layer_draw_dem ( VikDEMLayer *vdl, VikViewport *vp, VikDEM *
     for ( x=start_x, counter.lon = start_lon; counter.lon <= end_lon+escale_deg*skip_factor; counter.lon += escale_deg * skip_factor, x += skip_factor ) {
       // NOTE: ( counter.lon <= end_lon + ESCALE_DEG*SKIP_FACTOR ) is neccessary so in high zoom modes,
       // the leftmost column does also get drawn, if the center point is out of viewport.
-      if ( x >= 0 && x < dem->n_columns ) {
+      if ( x < dem->n_columns ) {
         column = g_ptr_array_index ( dem->columns, x );
         // get previous and next column. catch out-of-bound.
        gint32 new_x = x;
@@ -797,9 +852,8 @@ static const gchar *srtm_continent_dir ( gint lat, gint lon )
   return(g_hash_table_lookup(srtm_continent, name));
 }
 
-void vik_dem_layer_draw ( VikDEMLayer *vdl, gpointer data )
+static void dem_layer_draw ( VikDEMLayer *vdl, VikViewport *vp )
 {
-  VikViewport *vp = (VikViewport *) data;
   GList *dems_iter = vdl->files;
   VikDEM *dem;
 
@@ -821,12 +875,9 @@ void vik_dem_layer_draw ( VikDEMLayer *vdl, gpointer data )
   }
 }
 
-void vik_dem_layer_free ( VikDEMLayer *vdl )
+static void dem_layer_free ( VikDEMLayer *vdl )
 {
   gint i;
-  if ( vdl->color != NULL )
-    g_object_unref ( vdl->color );
-
   if ( vdl->gcs )
     for ( i = 0; i < DEM_N_HEIGHT_COLORS; i++ )
       g_object_unref ( vdl->gcs[i] );
@@ -840,18 +891,19 @@ void vik_dem_layer_free ( VikDEMLayer *vdl )
   a_dems_list_free ( vdl->files );
 }
 
-VikDEMLayer *vik_dem_layer_create ( VikViewport *vp )
+VikDEMLayer *dem_layer_create ( VikViewport *vp )
 {
-  VikDEMLayer *vdl = vik_dem_layer_new ();
+  VikDEMLayer *vdl = dem_layer_new ( vp );
   gint i;
-
-  /* TODO: share GCS between layers */
-  for ( i = 0; i < DEM_N_HEIGHT_COLORS; i++ )
-    vdl->gcs[i] = vik_viewport_new_gc ( vp, dem_height_colors[i], UNUSED_LINE_THICKNESS );
-
-  for ( i = 0; i < DEM_N_GRADIENT_COLORS; i++ )
-    vdl->gcsgradient[i] = vik_viewport_new_gc ( vp, dem_gradient_colors[i], UNUSED_LINE_THICKNESS );
-
+  if ( vp ) {
+    /* TODO: share GCS between layers */
+    for ( i = 0; i < DEM_N_HEIGHT_COLORS; i++ ) {
+      if ( i > 0 )
+        vdl->gcs[i] = vik_viewport_new_gc ( vp, dem_height_colors[i], UNUSED_LINE_THICKNESS );
+    }
+    for ( i = 0; i < DEM_N_GRADIENT_COLORS; i++ )
+      vdl->gcsgradient[i] = vik_viewport_new_gc ( vp, dem_gradient_colors[i], UNUSED_LINE_THICKNESS );
+  }
   return vdl;
 }
 /**************************************************************
@@ -882,7 +934,11 @@ static void srtm_dem_download_thread ( DEMDownloadParams *p, gpointer threaddata
   continent_dir = srtm_continent_dir(intlat, intlon);
 
   if (!continent_dir) {
-    g_warning(N_("No SRTM data available for %f, %f"), p->lat, p->lon);
+    if ( p->vdl ) {
+      gchar *msg = g_strdup_printf ( _("No SRTM data available for %f, %f"), p->lat, p->lon );
+      vik_window_statusbar_update ( (VikWindow*)VIK_GTK_WINDOW_FROM_LAYER(p->vdl), msg, VIK_STATUSBAR_INFO );
+      g_free ( msg );
+    }
     return;
   }
 
@@ -894,7 +950,7 @@ static void srtm_dem_download_thread ( DEMDownloadParams *p, gpointer threaddata
                (intlon >= 0) ? 'E' : 'W',
                ABS(intlon) );
 
-  static DownloadMapOptions options = { FALSE, FALSE, NULL, 0, a_check_map_file };
+  static DownloadMapOptions options = { FALSE, FALSE, NULL, 0, a_check_map_file, NULL };
   a_http_download_get_url ( SRTM_HTTP_SITE, src_fn, p->dest, &options, NULL );
   g_free ( src_fn );
 }
@@ -956,7 +1012,7 @@ static void srtm_draw_existence ( VikViewport *vp )
         vik_viewport_coord_to_screen ( vp, &ne, &x2, &y2 );
         if ( x1 < 0 ) x1 = 0;
         if ( y2 < 0 ) y2 = 0;
-        vik_viewport_draw_rectangle ( vp, GTK_WIDGET(vp)->style->black_gc, 
+        vik_viewport_draw_rectangle ( vp, gtk_widget_get_style(GTK_WIDGET(vp))->black_gc,
                FALSE, x1, y2, x2-x1, y1-y2 );
       }
     }
@@ -1034,7 +1090,7 @@ static void dem24k_draw_existence ( VikViewport *vp )
         vik_viewport_coord_to_screen ( vp, &ne, &x2, &y2 );
         if ( x1 < 0 ) x1 = 0;
         if ( y2 < 0 ) y2 = 0;
-        vik_viewport_draw_rectangle ( vp, GTK_WIDGET(vp)->style->black_gc, 
+        vik_viewport_draw_rectangle ( vp, gtk_widget_get_style(GTK_WIDGET(vp))->black_gc,
                FALSE, x1, y2, x2-x1, y1-y2 );
       }
     }
@@ -1056,17 +1112,17 @@ static void weak_ref_cb ( gpointer ptr, GObject * dead_vdl )
 }
 
 /* Try to add file full_path.
- * full_path will be copied.
+ * filename will be copied.
  * returns FALSE if file does not exists, TRUE otherwise.
  */
-static gboolean dem_layer_add_file ( VikDEMLayer *vdl, const gchar *full_path )
+static gboolean dem_layer_add_file ( VikDEMLayer *vdl, const gchar *filename )
 {
-  if ( g_file_test(full_path, G_FILE_TEST_EXISTS ) == TRUE ) {
+  if ( g_file_test(filename, G_FILE_TEST_EXISTS) == TRUE ) {
     /* only load if file size is not 0 (not in progress) */
     struct stat sb;
-    stat (full_path, &sb);
+    stat ( filename, &sb );
     if ( sb.st_size ) {
-      gchar *duped_path = g_strdup(full_path);
+      gchar *duped_path = g_strdup(filename);
       vdl->files = g_list_prepend ( vdl->files, duped_path );
       a_dems_load ( duped_path );
       g_debug("%s: %s", __FUNCTION__, duped_path);
@@ -1093,7 +1149,7 @@ static void dem_download_thread ( DEMDownloadParams *p, gpointer threaddata )
     g_object_weak_unref ( G_OBJECT(p->vdl), weak_ref_cb, p );
 
     if ( dem_layer_add_file ( p->vdl, p->dest ) )
-      vik_layer_emit_update ( VIK_LAYER(p->vdl), TRUE ); // Yes update from background thread
+      vik_layer_emit_update ( VIK_LAYER(p->vdl) ); // NB update from background thread
   }
   g_mutex_unlock ( p->mutex );
   //gdk_threads_leave();
@@ -1112,11 +1168,67 @@ static gpointer dem_layer_download_create ( VikWindow *vw, VikViewport *vvp)
   return vvp;
 }
 
+/**
+ * Display a simple dialog with information about the DEM file at this location
+ */
+static void dem_layer_file_info ( GtkWidget *widget, struct LatLon *ll )
+{
+  gint intlat, intlon;
+  const gchar *continent_dir;
+
+  intlat = (int)floor(ll->lat);
+  intlon = (int)floor(ll->lon);
+  continent_dir = srtm_continent_dir(intlat, intlon);
+
+  gchar *source = NULL;
+  if ( continent_dir )
+    source = g_strdup_printf ( "http:/%s%s/%c%02d%c%03d.hgt.zip",
+                               SRTM_HTTP_URI,
+                               continent_dir,
+                               (intlat >= 0) ? 'N' : 'S',
+                               ABS(intlat),
+                               (intlon >= 0) ? 'E' : 'W',
+                               ABS(intlon) );
+  else
+    // Probably not over any land...
+    source = g_strdup ( _("No DEM File Available") );
+
+  gchar *filename = NULL;
+  gchar *dem_file = NULL;
+#ifdef VIK_CONFIG_DEM24K
+  dem_file = dem24k_lat_lon_to_dest_fn ( ll->lat, ll->lon );
+#else
+  dem_file = srtm_lat_lon_to_dest_fn ( ll->lat, ll->lon );
+#endif
+  gchar *message = NULL;
+
+  filename = g_strdup_printf ( "%s%s", MAPS_CACHE_DIR, dem_file );
+
+  if ( g_file_test ( filename, G_FILE_TEST_EXISTS ) ) {
+    // Get some timestamp information of the file
+    struct stat stat_buf;
+    if ( g_stat ( filename, &stat_buf ) == 0 ) {
+      gchar time_buf[64];
+      strftime ( time_buf, sizeof(time_buf), "%c", gmtime((const time_t *)&stat_buf.st_mtime) );
+      message = g_strdup_printf ( _("\nSource: %s\n\nDEM File: %s\nDEM File Timestamp: %s"), source, filename, time_buf );
+    }
+  }
+  else
+    message = g_strdup_printf ( _("Source: %s\n\nNo DEM File!"), source );
+
+  // Show the info
+  a_dialog_info_msg ( GTK_WINDOW(gtk_widget_get_toplevel(widget)), message );
+
+  g_free ( message );
+  g_free ( source );
+  g_free ( dem_file );
+  g_free ( filename );
+}
 
 static gboolean dem_layer_download_release ( VikDEMLayer *vdl, GdkEventButton *event, VikViewport *vvp )
 {
   VikCoord coord;
-  struct LatLon ll;
+  static struct LatLon ll;
 
   gchar *full_path;
   gchar *dem_file = NULL;
@@ -1139,27 +1251,42 @@ static gboolean dem_layer_download_release ( VikDEMLayer *vdl, GdkEventButton *e
 
   g_debug("%s: %s", __FUNCTION__, full_path);
 
-  // TODO: check if already in filelist
-
-  if ( ! dem_layer_add_file(vdl, full_path) ) {
-    gchar *tmp = g_strdup_printf ( _("Downloading DEM %s"), dem_file );
-    DEMDownloadParams *p = g_malloc(sizeof(DEMDownloadParams));
-    p->dest = g_strdup(full_path);
-    p->lat = ll.lat;
-    p->lon = ll.lon;
-    p->vdl = vdl;
-    p->mutex = g_mutex_new();
-    p->source = vdl->source;
-    g_object_weak_ref(G_OBJECT(p->vdl), weak_ref_cb, p );
-
-    a_background_thread ( VIK_GTK_WINDOW_FROM_LAYER(vdl), tmp,
-               (vik_thr_func) dem_download_thread, p,
-               (vik_thr_free_func) free_dem_download_params, NULL, 1 );
+  if ( event->button == 1 ) {
+    // TODO: check if already in filelist
+    if ( ! dem_layer_add_file(vdl, full_path) ) {
+      gchar *tmp = g_strdup_printf ( _("Downloading DEM %s"), dem_file );
+      DEMDownloadParams *p = g_malloc(sizeof(DEMDownloadParams));
+      p->dest = g_strdup(full_path);
+      p->lat = ll.lat;
+      p->lon = ll.lon;
+      p->vdl = vdl;
+      p->mutex = g_mutex_new();
+      p->source = vdl->source;
+      g_object_weak_ref(G_OBJECT(p->vdl), weak_ref_cb, p );
+
+      a_background_thread ( VIK_GTK_WINDOW_FROM_LAYER(vdl), tmp,
+                            (vik_thr_func) dem_download_thread, p,
+                            (vik_thr_free_func) free_dem_download_params, NULL, 1 );
+
+      g_free ( tmp );
+    }
+    else
+      vik_layer_emit_update ( VIK_LAYER(vdl) );
+  }
+  else {
+    if ( !vdl->right_click_menu ) {
+      GtkWidget *item;
+      vdl->right_click_menu = GTK_MENU ( gtk_menu_new () );
+
+      item = gtk_image_menu_item_new_with_mnemonic ( _("_Show DEM File Information") );
+      gtk_image_menu_item_set_image ( (GtkImageMenuItem*)item, gtk_image_new_from_stock (GTK_STOCK_INFO, GTK_ICON_SIZE_MENU) );
+      g_signal_connect ( G_OBJECT(item), "activate", G_CALLBACK(dem_layer_file_info), &ll );
+      gtk_menu_shell_append (GTK_MENU_SHELL(vdl->right_click_menu), item);
+    }
 
-    g_free ( tmp );
+    gtk_menu_popup ( vdl->right_click_menu, NULL, NULL, NULL, NULL, event->button, event->time );
+    gtk_widget_show_all ( GTK_WIDGET(vdl->right_click_menu) );
   }
-  else
-    vik_layer_emit_update ( VIK_LAYER(vdl), FALSE );
 
   g_free ( dem_file );
   g_free ( full_path );