]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikwindow.c
[DOC] Mention map tilesize configuration.
[andy/viking.git] / src / vikwindow.c
index b89791fbcceab64d1f9d751402a66b65d4287115..3ebda9d822d6eae253e884df89f0e453dbb688d7 100644 (file)
@@ -42,8 +42,8 @@
 #include "vikexttool_datasources.h"
 #include "garminsymbols.h"
 #include "vikmapslayer.h"
+#include "vikrouting.h"
 #include "geonamessearch.h"
-#include "vikutils.h"
 #include "dir.h"
 #include "kmz.h"
 
@@ -330,6 +330,7 @@ void vik_window_statusbar_update ( VikWindow *vw, const gchar* message, vik_stat
 static void destroy_window ( GtkWidget *widget,
                              gpointer   data )
 {
+    g_debug ( "%s", __FUNCTION__ );
     if ( ! --window_count ) {
       g_free ( last_folder_files_uri );
       g_free ( last_folder_images_uri );
@@ -351,6 +352,10 @@ VikWindow *vik_window_new_window ()
   {
     VikWindow *vw = window_new ();
 
+    if ( window_count == 0 ) {
+       vik_window_statusbar_update ( vw, _("This is Viking "VIKING_VERSION), VIK_STATUSBAR_INFO );
+    }
+
     g_signal_connect (G_OBJECT (vw), "destroy",
                      G_CALLBACK (destroy_window), NULL);
     g_signal_connect (G_OBJECT (vw), "newwindow",
@@ -463,12 +468,6 @@ void vik_window_new_window_finish ( VikWindow *vw )
   if ( vw->filename )
     return;
 
-  if ( a_vik_get_startup_method ( ) == VIK_STARTUP_METHOD_SPECIFIED_FILE ) {
-    vik_window_open_file ( vw, a_vik_get_startup_file(), TRUE );
-    if ( vw->filename )
-      return;
-  }
-
   // Maybe add a default map layer
   if ( a_vik_get_add_default_map_layer () ) {
     VikMapsLayer *vml = VIK_MAPS_LAYER ( vik_layer_create(VIK_LAYER_MAPS, vw->viking_vvp, FALSE) );
@@ -1205,11 +1204,9 @@ gboolean draw_buf_done = TRUE;
 static gboolean draw_buf(gpointer data)
 {
   gpointer *pass_along = data;
-  gdk_threads_enter();
   gdk_draw_drawable (pass_along[0], pass_along[1],
                     pass_along[2], 0, 0, 0, 0, -1, -1);
   draw_buf_done = TRUE;
-  gdk_threads_leave();
   return FALSE;
 }
 
@@ -2732,7 +2729,7 @@ static void view_main_menu_cb ( GtkAction *a, VikWindow *vw )
       toggle_main_menu ( vw );
   }
   else
-    toggle_toolbar ( vw );
+    toggle_main_menu ( vw );
 }
 
 /***************************************
@@ -2807,8 +2804,7 @@ static const GdkCursor *toolbox_get_cursor(toolbox_tools_t *vt, const gchar *too
   toolbox_tool_t *t = &vt->tools[tool];
   if (t->ti.cursor == NULL) {
     if (t->ti.cursor_type == GDK_CURSOR_IS_PIXMAP && t->ti.cursor_data != NULL) {
-      GError *cursor_load_err = NULL;
-      GdkPixbuf *cursor_pixbuf = gdk_pixbuf_from_pixdata (t->ti.cursor_data, FALSE, &cursor_load_err);
+      GdkPixbuf *cursor_pixbuf = gdk_pixbuf_from_pixdata (t->ti.cursor_data, FALSE, NULL);
       /* TODO: settable offeset */
       t->ti.cursor = gdk_cursor_new_from_pixbuf ( gdk_display_get_default(), cursor_pixbuf, 3, 3 );
       g_object_unref ( G_OBJECT(cursor_pixbuf) );
@@ -2973,6 +2969,22 @@ gboolean vik_window_get_pan_move ( VikWindow *vw )
   return vw->pan_move;
 }
 
+/**
+ * Remove the potentially auto added map
+ */
+static void remove_default_map_layer ( VikWindow *vw )
+{
+  if ( a_vik_get_add_default_map_layer () ) {
+    VikAggregateLayer *top = vik_layers_panel_get_top_layer(vw->viking_vlp);
+    if ( vik_aggregate_layer_count(top) == 1 ) {
+      VikLayer *vl = vik_aggregate_layer_get_top_visible_layer_of_type (top, VIK_LAYER_MAPS);
+      // Could try to compare name vs _("Default Map") but this might have i8n issues if not translated
+      if ( vl )
+        vik_aggregate_layer_delete_layer ( top, vl );
+    }
+  }
+}
+
 static void on_activate_recent_item (GtkRecentChooser *chooser,
                                      VikWindow *self)
 {
@@ -2992,6 +3004,7 @@ static void on_activate_recent_item (GtkRecentChooser *chooser,
       // NB: GSList & contents are freed by main.open_window
     }
     else {
+      remove_default_map_layer ( self );
       vik_window_open_file ( self, path, TRUE );
       g_free ( path );
     }
@@ -3089,8 +3102,7 @@ void vik_window_open_file ( VikWindow *vw, const gchar *filename, gboolean chang
   vw->filename = g_strdup ( filename );
   gboolean success = FALSE;
   gboolean restore_original_filename = FALSE;
-
-  vw->loaded_type = a_file_load ( vik_layers_panel_get_top_layer(vw->viking_vlp), vw->viking_vvp, filename );
+  vw->loaded_type = a_file_load ( vik_layers_panel_get_top_layer(vw->viking_vlp), vw->viking_vvp, vw->containing_vtl, filename );
   switch ( vw->loaded_type )
   {
     case LOAD_TYPE_READ_FAILURE:
@@ -3264,6 +3276,7 @@ static void load_file ( GtkAction *a, VikWindow *vw )
         if ( newwindow && check_file_magic_vik ( file_name ) ) {
           // Load first of many .vik files in current window
           if ( first_vik_file ) {
+            remove_default_map_layer ( vw );
             vik_window_open_file ( vw, file_name, TRUE );
             first_vik_file = FALSE;
           }
@@ -3491,10 +3504,6 @@ static void export_to_kml ( GtkAction *a, VikWindow *vw )
   export_to_common ( vw, FILE_TYPE_KML, ".kml" );
 }
 
-#if !GLIB_CHECK_VERSION(2,26,0)
-typedef struct stat GStatBuf;
-#endif
-
 static void file_properties_cb ( GtkAction *a, VikWindow *vw )
 {
   gchar *message = NULL;
@@ -3710,7 +3719,7 @@ static void default_location_cb ( GtkAction *a, VikWindow *vw )
     { VIK_LAYER_NUM_TYPES,
       VIKING_PREFERENCES_NAMESPACE "default_latitude",
       VIK_LAYER_PARAM_DOUBLE,
-      VIK_LOCATION_LAT,
+      VIK_LAYER_GROUP_NONE,
       NULL,
       VIK_LAYER_WIDGET_SPINBUTTON,
       NULL,
@@ -3725,7 +3734,7 @@ static void default_location_cb ( GtkAction *a, VikWindow *vw )
     { VIK_LAYER_NUM_TYPES,
       VIKING_PREFERENCES_NAMESPACE "default_longitude",
       VIK_LAYER_PARAM_DOUBLE,
-      VIK_LOCATION_LONG,
+      VIK_LAYER_GROUP_NONE,
       NULL,
       VIK_LAYER_WIDGET_SPINBUTTON,
       NULL,
@@ -3751,11 +3760,20 @@ static void default_location_cb ( GtkAction *a, VikWindow *vw )
   a_preferences_save_to_file();
 }
 
+/**
+ * Delete All
+ */
 static void clear_cb ( GtkAction *a, VikWindow *vw )
 {
-  vik_layers_panel_clear ( vw->viking_vlp );
-  window_set_filename ( vw, NULL );
-  draw_update ( vw );
+  // Do nothing if empty
+  VikAggregateLayer *top = vik_layers_panel_get_top_layer(vw->viking_vlp);
+  if ( ! vik_aggregate_layer_is_empty(top) ) {
+    if ( a_dialog_yes_or_no ( GTK_WINDOW(vw), _("Are you sure you wish to delete all layers?"), NULL ) ) {
+      vik_layers_panel_clear ( vw->viking_vlp );
+      window_set_filename ( vw, NULL );
+      draw_update ( vw );
+    }
+  }
 }
 
 static void window_close ( GtkAction *a, VikWindow *vw )
@@ -4455,8 +4473,6 @@ static GtkActionEntry entries[] = {
   { "Export",    GTK_STOCK_CONVERT,      N_("_Export All"),               NULL,         N_("Export All TrackWaypoint Layers"),              (GCallback)NULL                  },
   { "ExportGPX", NULL,                   N_("_GPX..."),                      NULL,         N_("Export as GPX"),                                (GCallback)export_to_gpx         },
   { "Acquire",   GTK_STOCK_GO_DOWN,      N_("A_cquire"),                  NULL,         NULL,                                               (GCallback)NULL },
-  { "AcquireGPS",   NULL,                N_("From _GPS..."),                     NULL,         N_("Transfer data from a GPS device"),              (GCallback)acquire_from_gps      },
-  { "AcquireGPSBabel",   NULL,                N_("Import File With GPS_Babel..."),               NULL,         N_("Import file via GPSBabel converter"),              (GCallback)acquire_from_file      },
   { "AcquireRouting",   NULL,             N_("_Directions..."),     NULL,         N_("Get driving directions"),           (GCallback)acquire_from_routing   },
 #ifdef VIK_CONFIG_OPENSTREETMAP
   { "AcquireOSM",   NULL,                 N_("_OSM Traces..."),          NULL,         N_("Get traces from OpenStreetMap"),            (GCallback)acquire_from_osm       },
@@ -4526,6 +4542,8 @@ static GtkActionEntry debug_entries[] = {
 
 static GtkActionEntry entries_gpsbabel[] = {
   { "ExportKML", NULL,                   N_("_KML..."),                      NULL,         N_("Export as KML"),                                (GCallback)export_to_kml },
+  { "AcquireGPS",   NULL,                N_("From _GPS..."),                     NULL,         N_("Transfer data from a GPS device"),              (GCallback)acquire_from_gps      },
+  { "AcquireGPSBabel", NULL,             N_("Import File With GPS_Babel..."), NULL,     N_("Import file via GPSBabel converter"),           (GCallback)acquire_from_file },
 };
 
 static GtkActionEntry entries_geojson[] = {
@@ -4631,10 +4649,16 @@ static void window_create_ui( VikWindow *window )
 
   // Use this to see if GPSBabel is available:
   if ( a_babel_available () ) {
-       // If going to add more entries then might be worth creating a menu_gpsbabel.xml.h file
-       if ( gtk_ui_manager_add_ui_from_string ( uim,
-         "<ui><menubar name='MainMenu'><menu action='File'><menu action='Export'><menuitem action='ExportKML'/></menu></menu></menubar></ui>",
-         -1, &error ) )
+    // If going to add more entries then might be worth creating a menu_gpsbabel.xml.h file
+    if ( gtk_ui_manager_add_ui_from_string ( uim,
+         "<ui>" \
+         "<menubar name='MainMenu'>" \
+         "<menu action='File'><menu action='Export'><menuitem action='ExportKML'/></menu></menu>" \
+         "<menu action='File'><menu action='Acquire'><menuitem action='AcquireGPS'/></menu></menu>" \
+         "<menu action='File'><menu action='Acquire'><menuitem action='AcquireGPSBabel'/></menu></menu>" \
+         "</menubar>" \
+         "</ui>",
+         -1, &error ) )
       gtk_action_group_add_actions ( action_group, entries_gpsbabel, G_N_ELEMENTS (entries_gpsbabel), window );
   }
 
@@ -4675,7 +4699,7 @@ static void window_create_ui( VikWindow *window )
 
     action.name = vik_layer_get_interface(i)->name;
     action.stock_id = vik_layer_get_interface(i)->name;
-    action.label = g_strdup_printf( _("New _%s Layer"), vik_layer_get_interface(i)->name);
+    action.label = g_strdup_printf( _("New _%s Layer"), _(vik_layer_get_interface(i)->name));
     action.accelerator = vik_layer_get_interface(i)->accelerator;
     action.tooltip = NULL;
     action.callback = (GCallback)menu_addlayer_cb;
@@ -4718,7 +4742,7 @@ static void window_create_ui( VikWindow *window )
     // This is to avoid clashing with just the layer name used above for the tool actions
     action_dl.name = g_strconcat("Layer", vik_layer_get_interface(i)->fixed_layer_name, NULL);
     action_dl.stock_id = NULL;
-    action_dl.label = g_strconcat("_", vik_layer_get_interface(i)->name, "...", NULL); // Prepend marker for keyboard accelerator
+    action_dl.label = g_strconcat(_(vik_layer_get_interface(i)->name), _("..."), NULL);
     action_dl.accelerator = NULL;
     action_dl.tooltip = NULL;
     action_dl.callback = (GCallback)layer_defaults_cb;
@@ -4751,6 +4775,14 @@ static void window_create_ui( VikWindow *window )
   gtk_ui_manager_ensure_update (uim);
   
   setup_recent_files(window);
+
+  if ( vik_routing_number_of_engines(VIK_ROUTING_METHOD_DIRECTIONS) == 0 ) {
+    GtkWidget *widget = gtk_ui_manager_get_widget ( uim, "/ui/MainMenu/File/Acquire/AcquireRouting" );
+    if ( widget ) {
+      g_object_set ( widget, "sensitive", FALSE, NULL );
+    }
+    g_warning ( "No direction routing engines available" );
+  }
 }
 
 
@@ -4882,6 +4914,7 @@ void vik_window_set_selected_waypoint ( VikWindow *vw, gpointer *vwp, gpointer v
 gboolean vik_window_clear_highlight ( VikWindow *vw )
 {
   gboolean need_redraw = FALSE;
+  vw->containing_vtl = NULL;
   if ( vw->selected_vtl != NULL ) {
     vw->selected_vtl = NULL;
     need_redraw = TRUE;