]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikwindow.c
Add OSM GPS Tiles in default data config
[andy/viking.git] / src / vikwindow.c
index ed99b974ea4de3ea51612188db6b38167af7ef8e..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",
@@ -1199,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;
 }
 
@@ -2726,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 );
 }
 
 /***************************************
@@ -2966,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)
 {
@@ -2985,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 );
     }
@@ -3082,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:
@@ -3257,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;
           }
@@ -4453,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       },
@@ -4524,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[] = {
@@ -4629,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 );
   }
 
@@ -4673,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;
@@ -4716,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;
@@ -4749,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" );
+  }
 }
 
 
@@ -4880,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;