]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikwindow.c
[QA] Tidy up vikgoto header usage.
[andy/viking.git] / src / vikwindow.c
index 55f58ea0f903dc7966b930a20f623ea96e2fff02..0ca52b09c5a0b41c293f7407a17015fdccbe21fe 100644 (file)
@@ -38,6 +38,7 @@
 #include "vikexttools.h"
 #include "garminsymbols.h"
 #include "vikmapslayer.h"
+#include "geonamessearch.h"
 
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
@@ -72,6 +73,7 @@ static void window_finalize ( GObject *gob );
 static GObjectClass *parent_class;
 
 static void window_set_filename ( VikWindow *vw, const gchar *filename );
+static const gchar *window_get_filename ( VikWindow *vw );
 
 static VikWindow *window_new ();
 
@@ -181,6 +183,7 @@ struct _VikWindow {
   gboolean only_updating_coord_mode_ui; /* hack for a bug in GTK */
   GtkUIManager *uim;
 
+  GThread  *thread;
   /* half-drawn update */
   VikLayer *trigger;
   VikCoord trigger_center;
@@ -188,15 +191,11 @@ struct _VikWindow {
   /* Store at this level for highlighted selection drawing since it applies to the viewport and the layers panel */
   /* Only one of these items can be selected at the same time */
   gpointer selected_vtl; /* notionally VikTrwLayer */
-  gpointer selected_tracks; /* notionally GList */
+  GHashTable *selected_tracks;
   gpointer selected_track; /* notionally VikTrack */
-  gpointer selected_waypoints; /* notionally GList */
+  GHashTable *selected_waypoints;
   gpointer selected_waypoint; /* notionally VikWaypoint */
   /* only use for individual track or waypoint */
-  ////// NEED TO THINK ABOUT VALIDITY OF THESE             //////
-  ////// i.e. what happens when stuff is deleted elsewhere //////
-  ////// Generally seems alright as can not access them    //////
-  ////// containing_vtl now seems unecessary               //////
   /* For track(s) & waypoint(s) it is the layer they are in - this helps refering to the individual item easier */
   gpointer containing_vtl; /* notionally VikTrwLayer */
 };
@@ -382,7 +381,7 @@ static void vik_window_class_init ( VikWindowClass *klass )
 
 static void set_toolbar_zoom ( VikWindow *vw, gdouble mpp )
 {
-  gint active = 2 + ( log (mpp) / log (2) );
+  gint active = 2 + round ( log (mpp) / log (2) );
   // Can we not hard code size here?
   if ( active > 17 )
     active = 17;
@@ -513,6 +512,11 @@ static void vik_window_init ( VikWindow *vw )
   vw->save_dia = NULL;
   vw->save_img_dia = NULL;
   vw->save_img_dir_dia = NULL;
+
+  // Store the thread value so comparisons can be made to determine the gdk update method
+  // Hopefully we are storing the main thread value here :)
+  //  [ATM any window initialization is always be performed by the main thread]
+  vw->thread = g_thread_self();
 }
 
 static VikWindow *window_new ()
@@ -616,7 +620,7 @@ static gboolean delete_event( VikWindow *vw )
       _("Do you want to save the changes you made to the document \"%s\"?\n"
        "\n"
        "Your changes will be lost if you don't save them."),
-      vw->filename ? a_file_basename ( vw->filename ) : _("Untitled") ) );
+      window_get_filename ( vw ) ) );
     gtk_dialog_add_buttons ( dia, _("Don't Save"), GTK_RESPONSE_NO, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_YES, NULL );
     switch ( gtk_dialog_run ( dia ) )
     {
@@ -960,29 +964,8 @@ static void draw_ruler(VikViewport *vvp, GdkDrawable *d, GdkGC *gc, gint x1, gin
   /* draw compass */
 #define CR 80
 #define CW 4
-  angle = atan2(dy, dx) + M_PI_2;
-
-  if ( vik_viewport_get_drawmode ( vvp ) == VIK_VIEWPORT_DRAWMODE_UTM) {
-    VikCoord test;
-    struct LatLon ll;
-    struct UTM u;
-    gint tx, ty;
-
-    vik_viewport_screen_to_coord ( vvp, x1, y1, &test );
-    vik_coord_to_latlon ( &test, &ll );
-    ll.lat += vik_viewport_get_ympp ( vvp ) * vik_viewport_get_height ( vvp ) / 11000.0; // about 11km per degree latitude
-    a_coords_latlon_to_utm ( &ll, &u );
-    vik_coord_load_from_utm ( &test, VIK_VIEWPORT_DRAWMODE_UTM, &u );
-    vik_viewport_coord_to_screen ( vvp, &test, &tx, &ty );
-
-    baseangle = M_PI - atan2(tx-x1, ty-y1);
-    angle -= baseangle;
-  }
 
-  if (angle<0) 
-    angle+=2*M_PI;
-  if (angle>2*M_PI)
-    angle-=2*M_PI;
+  vik_viewport_compute_bearing ( vvp, x1, y1, x2, y2, &angle, &baseangle );
 
   {
     GdkColor color;
@@ -2063,18 +2046,24 @@ static void window_set_filename ( VikWindow *vw, const gchar *filename )
   if ( filename == NULL )
   {
     vw->filename = NULL;
-    file = _("Untitled");
   }
   else
   {
     vw->filename = g_strdup(filename);
-    file = a_file_basename ( filename );
   }
+
+  /* Refresh window's title */
+  file = window_get_filename ( vw );
   title = g_strdup_printf( "%s - Viking", file );
   gtk_window_set_title ( GTK_WINDOW(vw), title );
   g_free ( title );
 }
 
+static const gchar *window_get_filename ( VikWindow *vw )
+{
+  return vw->filename ? a_file_basename ( vw->filename ) : _("Untitled");
+}
+
 GtkWidget *vik_window_get_drawmode_button ( VikWindow *vw, VikViewportDrawMode mode )
 {
   GtkWidget *mode_button;
@@ -2383,7 +2372,7 @@ static gboolean save_file_as ( GtkAction *a, VikWindow *vw )
     gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_dia), TRUE );
   }
   // Auto append / replace extension with '.vik' to the suggested file name as it's going to be a Viking File
-  gchar* auto_save_name = strdup ( vw->filename ? a_file_basename ( vw->filename ) : _("Untitled") );
+  gchar* auto_save_name = g_strdup ( window_get_filename ( vw ) );
   if ( ! check_file_ext ( auto_save_name, ".vik" ) )
     auto_save_name = g_strconcat ( auto_save_name, ".vik", NULL );
 
@@ -2445,7 +2434,7 @@ static void acquire_from_file ( GtkAction *a, VikWindow *vw )
   a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_file_interface );
 }
 
-#ifdef VIK_CONFIG_GOOGLE_DIRECTIONS
+#ifdef VIK_CONFIG_GOOGLE
 static void acquire_from_google ( GtkAction *a, VikWindow *vw )
 {
   a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_google_interface );
@@ -2474,6 +2463,13 @@ static void acquire_from_geotag ( GtkAction *a, VikWindow *vw )
 }
 #endif
 
+#ifdef VIK_CONFIG_GEONAMES
+static void acquire_from_wikipedia ( GtkAction *a, VikWindow *vw )
+{
+  a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_wikipedia_interface );
+}
+#endif
+
 static void goto_default_location( GtkAction *a, VikWindow *vw)
 {
   struct LatLon ll;
@@ -2486,7 +2482,8 @@ static void goto_default_location( GtkAction *a, VikWindow *vw)
 
 static void goto_address( GtkAction *a, VikWindow *vw)
 {
-  a_vik_goto(vw, vw->viking_vlp, vw->viking_vvp);
+  a_vik_goto ( vw, vw->viking_vvp );
+  vik_layers_panel_emit_update ( vw->viking_vlp );
 }
 
 static void mapcache_flush_cb ( GtkAction *a, VikWindow *vw )
@@ -2518,6 +2515,7 @@ static void default_location_cb ( GtkAction *a, VikWindow *vw )
       NULL,
       VIK_LAYER_WIDGET_SPINBUTTON,
       NULL,
+      NULL,
       NULL },
   };
   VikLayerParam pref_lon[] = {
@@ -2527,6 +2525,7 @@ static void default_location_cb ( GtkAction *a, VikWindow *vw )
       NULL,
       VIK_LAYER_WIDGET_SPINBUTTON,
       NULL,
+      NULL,
       NULL },
   };
 
@@ -2882,7 +2881,7 @@ static void draw_to_image_file ( VikWindow *vw, gboolean one_image_only )
   zoom_combo = create_zoom_combo_all_levels();
 
   gdouble mpp = vik_viewport_get_xmpp(vw->viking_vvp);
-  gint active = 2 + ( log (mpp) / log (2) );
+  gint active = 2 + round ( log (mpp) / log (2) );
 
   // Can we not hard code size here?
   if ( active > 17 )
@@ -3122,7 +3121,7 @@ static GtkActionEntry entries[] = {
   { "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      },
-#ifdef VIK_CONFIG_GOOGLE_DIRECTIONS
+#ifdef VIK_CONFIG_GOOGLE
   { "AcquireGoogle",   NULL,             N_("Google _Directions..."),     NULL,         N_("Get driving directions from Google"),           (GCallback)acquire_from_google   },
 #endif
 #ifdef VIK_CONFIG_OPENSTREETMAP
@@ -3133,6 +3132,9 @@ static GtkActionEntry entries[] = {
 #endif
 #ifdef VIK_CONFIG_GEOTAG
   { "AcquireGeotag", NULL,               N_("From Geotagged _Images..."), NULL,         N_("Create waypoints from geotagged images"),       (GCallback)acquire_from_geotag   },
+#endif
+#ifdef VIK_CONFIG_GEONAMES
+  { "AcquireWikipedia", NULL,            N_("From _Wikipedia Waypoints"), NULL,         N_("Create waypoints from Wikipedia items in the current view"), (GCallback)acquire_from_wikipedia },
 #endif
   { "Save",      GTK_STOCK_SAVE,         N_("_Save"),                         "<control>S", N_("Save the file"),                                (GCallback)save_file             },
   { "SaveAs",    GTK_STOCK_SAVE_AS,      N_("Save _As..."),                      NULL,  N_("Save the file under different name"),           (GCallback)save_file_as          },
@@ -3343,7 +3345,7 @@ static struct {
   { &zoom_18_pixbuf,           "vik-icon-zoom"     },
   { &ruler_18_pixbuf,          "vik-icon-ruler"    },
   { &select_18_pixbuf,         "vik-icon-select"   },
-  { &begintr_18_pixbuf,                "vik-icon-Begin Track"      },
+  { &vik_new_route_18_pixbuf,   "vik-icon-Create Route"     },
   { &route_finder_18_pixbuf,   "vik-icon-Route Finder"     },
   { &demdl_18_pixbuf,          "vik-icon-DEM Download"     },
   { &showpic_18_pixbuf,                "vik-icon-Show Picture"     },
@@ -3390,14 +3392,14 @@ void vik_window_set_selected_trw_layer ( VikWindow *vw, gpointer vtl )
   vik_viewport_set_highlight_thickness ( vw->viking_vvp, vik_trw_layer_get_property_tracks_line_thickness (vw->containing_vtl) );
 }
 
-gpointer vik_window_get_selected_tracks ( VikWindow *vw )
+GHashTable *vik_window_get_selected_tracks ( VikWindow *vw )
 {
   return vw->selected_tracks;
 }
 
-void vik_window_set_selected_tracks ( VikWindow *vw, gpointer gl, gpointer vtl )
+void vik_window_set_selected_tracks ( VikWindow *vw, GHashTable *ght, gpointer vtl )
 {
-  vw->selected_tracks = gl;
+  vw->selected_tracks = ght;
   vw->containing_vtl  = vtl;
   /* Clear others */
   vw->selected_vtl       = NULL;
@@ -3426,14 +3428,14 @@ void vik_window_set_selected_track ( VikWindow *vw, gpointer *vt, gpointer vtl )
   vik_viewport_set_highlight_thickness ( vw->viking_vvp, vik_trw_layer_get_property_tracks_line_thickness (vw->containing_vtl) );
 }
 
-gpointer vik_window_get_selected_waypoints ( VikWindow *vw )
+GHashTable *vik_window_get_selected_waypoints ( VikWindow *vw )
 {
   return vw->selected_waypoints;
 }
 
-void vik_window_set_selected_waypoints ( VikWindow *vw, gpointer gl, gpointer vtl )
+void vik_window_set_selected_waypoints ( VikWindow *vw, GHashTable *ght, gpointer vtl )
 {
-  vw->selected_waypoints = gl;
+  vw->selected_waypoints = ght;
   vw->containing_vtl     = vtl;
   /* Clear others */
   vw->selected_vtl       = NULL;
@@ -3483,3 +3485,8 @@ gboolean vik_window_clear_highlight ( VikWindow *vw )
   }
   return need_redraw;
 }
+
+GThread *vik_window_get_thread ( VikWindow *vw )
+{
+  return vw->thread;
+}