]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikwindow.c
Add a script to compute po/ChangeLog fragment
[andy/viking.git] / src / vikwindow.c
index 492cfac4f0f8fb44d9db6f6d0a0eecadd6d5c02d..e2a15c2a6ca4e5ac44b67355fa5720007d380c2d 100644 (file)
 #include "background.h"
 #include "acquire.h"
 #include "datasources.h"
+#ifdef VIK_CONFIG_GOOGLE
 #include "googlesearch.h"
+#endif
+#ifdef VIK_CONFIG_GEONAMES
+#include "geonamessearch.h"
+#endif
 #include "dems.h"
 #include "print.h"
 #include "preferences.h"
 #include "icons/icons.h"
+#include "vikexttools.h"
 
+#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
+#endif
+#ifdef HAVE_MATH_H
 #include <math.h>
+#endif
+#ifdef HAVE_STRING_H
 #include <string.h>
+#endif
 #include <ctype.h>
 #include <glib.h>
 #include <glib/gstdio.h>
@@ -288,6 +300,7 @@ static void window_init ( VikWindow *vw )
   gtk_toolbar_set_icon_size(GTK_TOOLBAR(gtk_ui_manager_get_widget (vw->uim, "/MainToolbar")), GTK_ICON_SIZE_SMALL_TOOLBAR);
   gtk_toolbar_set_style (GTK_TOOLBAR(gtk_ui_manager_get_widget (vw->uim, "/MainToolbar")), GTK_TOOLBAR_ICONS);
 
+  vik_ext_tools_add_menu_items ( vw, vw->uim );
 
   g_signal_connect (G_OBJECT (vw), "delete_event", G_CALLBACK (delete_event), NULL);
 
@@ -396,7 +409,8 @@ static void draw_status ( VikWindow *vw )
 void vik_window_set_redraw_trigger(VikLayer *vl)
 {
   VikWindow *vw = VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(vl));
-  vw->trigger = vl;
+  if (NULL != vw)
+    vw->trigger = vl;
 }
 
 static void window_configure_event ( VikWindow *vw )
@@ -488,7 +502,9 @@ static void draw_mouse_motion (VikWindow *vw, GdkEventMotion *event)
   static VikCoord coord;
   static struct UTM utm;
   static struct LatLon ll;
-  static char pointer_buf[36];
+  #define BUFFER_SIZE 50
+  static char pointer_buf[BUFFER_SIZE];
+  gchar *lat = NULL, *lon = NULL;
   gint16 alt;
   gdouble zoom;
   VikDemInterpol interpol_method;
@@ -498,6 +514,7 @@ static void draw_mouse_motion (VikWindow *vw, GdkEventMotion *event)
   vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord );
   vik_coord_to_utm ( &coord, &utm );
   a_coords_utm_to_latlon ( &utm, &ll );
+  a_coords_latlon_to_string ( &ll, &lat, &lon );
   /* Change interpolate method according to scale */
   zoom = vik_viewport_get_zoom(vw->viking_vvp);
   if (zoom > 2.0)
@@ -507,9 +524,13 @@ static void draw_mouse_motion (VikWindow *vw, GdkEventMotion *event)
   else
     interpol_method = VIK_DEM_INTERPOL_BEST;
   if ((alt = a_dems_get_elev_by_coord(&coord, interpol_method)) != VIK_DEM_INVALID_ELEVATION)
-    g_snprintf ( pointer_buf, 36, _("Cursor: %f %f %dm"), ll.lat, ll.lon, alt );
+    g_snprintf ( pointer_buf, BUFFER_SIZE, _("%s %s %dm"), lat, lon, alt );
   else
-    g_snprintf ( pointer_buf, 36, _("Cursor: %f %f"), ll.lat, ll.lon );
+    g_snprintf ( pointer_buf, BUFFER_SIZE, _("%s %s"), lat, lon );
+  g_free (lat);
+  lat = NULL;
+  g_free (lon);
+  lon = NULL;
   vik_statusbar_set_message ( vw->viking_vs, 4, pointer_buf );
 
   vik_window_pan_move ( vw, event );
@@ -782,14 +803,16 @@ static VikLayerToolFuncStatus ruler_click (VikLayer *vl, GdkEventButton *event,
   VikCoord coord;
   gchar *temp;
   if ( event->button == 1 ) {
+    gchar *lat=NULL, *lon=NULL;
     vik_viewport_screen_to_coord ( s->vvp, (gint) event->x, (gint) event->y, &coord );
     vik_coord_to_latlon ( &coord, &ll );
+    a_coords_latlon_to_string ( &ll, &lat, &lon );
     if ( s->has_oldcoord ) {
-      temp = g_strdup_printf ( "%f %f DIFF %f meters", ll.lat, ll.lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
+      temp = g_strdup_printf ( "%s %s DIFF %f meters", lat, lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
       s->has_oldcoord = FALSE;
     }
     else {
-      temp = g_strdup_printf ( "%f %f", ll.lat, ll.lon );
+      temp = g_strdup_printf ( "%s %s", lat, lon );
       s->has_oldcoord = TRUE;
     }
 
@@ -817,6 +840,7 @@ static VikLayerToolFuncStatus ruler_move (VikLayer *vl, GdkEventMotion *event, r
   if ( s->has_oldcoord ) {
     int oldx, oldy, w1, h1, w2, h2;
     static GdkPixmap *buf = NULL;
+    gchar *lat=NULL, *lon=NULL;
     w1 = vik_viewport_get_width(vvp); 
     h1 = vik_viewport_get_height(vvp);
     if (!buf) {
@@ -843,8 +867,8 @@ static VikLayerToolFuncStatus ruler_move (VikLayer *vl, GdkEventMotion *event, r
       g_idle_add_full (G_PRIORITY_HIGH_IDLE + 10, draw_buf, pass_along, NULL);
       draw_buf_done = FALSE;
     }
-
-    temp = g_strdup_printf ( "%f %f DIFF %f meters", ll.lat, ll.lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
+    a_coords_latlon_to_string(&ll, &lat, &lon);
+    temp = g_strdup_printf ( "%s %s DIFF %f meters", lat, lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
     vik_statusbar_set_message ( vw->viking_vs, 3, temp );
     g_free ( temp );
   }
@@ -1304,11 +1328,11 @@ GtkWidget *vik_window_get_drawmode_button ( VikWindow *vw, VikViewportDrawMode m
   GtkWidget *mode_button;
   gchar *buttonname;
   switch ( mode ) {
-    case VIK_VIEWPORT_DRAWMODE_UTM: buttonname = "/ui/MainMenu/View/ModeUTM"; break;
+#ifdef VIK_CONFIG_EXPEDIA
     case VIK_VIEWPORT_DRAWMODE_EXPEDIA: buttonname = "/ui/MainMenu/View/ModeExpedia"; break;
-    case VIK_VIEWPORT_DRAWMODE_GOOGLE: buttonname = "/ui/MainMenu/View/ModeGoogle"; break;
+#endif
     case VIK_VIEWPORT_DRAWMODE_MERCATOR: buttonname = "/ui/MainMenu/View/ModeMercator"; break;
-    default: buttonname = "/ui/MainMenu/View/ModeKH";
+    default: buttonname = "/ui/MainMenu/View/ModeUTM";
   }
   mode_button = gtk_ui_manager_get_widget ( vw->uim, buttonname );
   g_assert ( mode_button );
@@ -1472,7 +1496,13 @@ static void acquire_from_gc ( GtkAction *a, VikWindow *vw )
 
 static void goto_address( GtkAction *a, VikWindow *vw)
 {
+#if defined(VIK_CONFIG_GOOGLE) && VIK_CONFIG_SEARCH==VIK_CONFIG_SEARCH_GOOGLE
   a_google_search(vw, vw->viking_vlp, vw->viking_vvp);
+#endif
+#if defined(VIK_CONFIG_GEONAMES) && VIK_CONFIG_SEARCH==VIK_CONFIG_SEARCH_GEONAMES
+  a_geonames_search(vw, vw->viking_vlp, vw->viking_vvp);
+#endif
+
 }
 
 static void preferences_cb ( GtkAction *a, VikWindow *vw )
@@ -1842,12 +1872,6 @@ static void window_change_coord_mode_cb ( GtkAction *old_a, GtkAction *a, VikWin
   else if (!strcmp(gtk_action_get_name(a), "ModeExpedia")) {
     drawmode = VIK_VIEWPORT_DRAWMODE_EXPEDIA;
   }
-  else if (!strcmp(gtk_action_get_name(a), "ModeGoogle")) {
-    drawmode = VIK_VIEWPORT_DRAWMODE_GOOGLE;
-  }
-  else if (!strcmp(gtk_action_get_name(a), "ModeKH")) {
-    drawmode = VIK_VIEWPORT_DRAWMODE_KH;
-  }
   else if (!strcmp(gtk_action_get_name(a), "ModeMercator")) {
     drawmode = VIK_VIEWPORT_DRAWMODE_MERCATOR;
   }
@@ -1921,6 +1945,7 @@ static GtkActionEntry entries[] = {
   { "SetPan", NULL, N_("_Pan"), 0, 0, 0 },
   { "Layers", NULL, N_("_Layers"), 0, 0, 0 },
   { "Tools", NULL, N_("_Tools"), 0, 0, 0 },
+  { "Exttools", NULL, N_("_Webtools"), 0, 0, 0 },
   { "Help", NULL, N_("_Help"), 0, 0, 0 },
 
   { "New",       GTK_STOCK_NEW,          N_("_New"),                          "<control>N", N_("New file"),                                     (GCallback)newwindow_cb          },
@@ -1944,13 +1969,13 @@ static GtkActionEntry entries[] = {
   { "Exit",      GTK_STOCK_QUIT,         N_("E_xit"),                         "<control>W", N_("Exit the program"),                             (GCallback)window_close          },
   { "SaveExit",  GTK_STOCK_QUIT,         N_("Save and Exit"),                 NULL, N_("Save and Exit the program"),                             (GCallback)save_file_and_exit          },
 
-  { "GoogleMapsSearch",   GTK_STOCK_GO_FORWARD,                 N_("Go To Google Maps location"),                NULL,         N_("Go to address/place using Google Maps search"),            (GCallback)goto_address       },
+  { "GotoSearch",   GTK_STOCK_JUMP_TO,                 N_("Go To location"),                     NULL,         N_("Go to address/place using text search"),            (GCallback)goto_address       },
   { "GotoLL",    GTK_STOCK_QUIT,         N_("_Go to Lat\\/Lon..."),           NULL,         N_("Go to arbitrary lat\\/lon coordinate"),         (GCallback)draw_goto_cb          },
   { "GotoUTM",   GTK_STOCK_QUIT,         N_("Go to UTM..."),                  NULL,         N_("Go to arbitrary UTM coordinate"),               (GCallback)draw_goto_cb          },
   { "SetBGColor",GTK_STOCK_SELECT_COLOR, N_("Set Background Color..."),       NULL,         NULL,                                           (GCallback)set_bg_color          },
   { "ZoomIn",    GTK_STOCK_ZOOM_IN,      N_("Zoom _In"),                   "<control>plus", NULL,                                           (GCallback)draw_zoom_cb          },
   { "ZoomOut",   GTK_STOCK_ZOOM_OUT,     N_("Zoom _Out"),                 "<control>minus", NULL,                                           (GCallback)draw_zoom_cb          },
-  { "ZoomTo",    GTK_STOCK_ZOOM_FIT,     N_("Zoom _To"),               "<control><shift>Z", NULL,                                           (GCallback)zoom_to_cb            },
+  { "ZoomTo",    GTK_STOCK_ZOOM_FIT,     N_("Zoom _To"),               "<control>Z", NULL,                                           (GCallback)zoom_to_cb            },
   { "Zoom0.25",  NULL,                   N_("0.25"),                          NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
   { "Zoom0.5",   NULL,                   N_("0.5"),                           NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
   { "Zoom1",     NULL,                   N_("1"),                             NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
@@ -1982,9 +2007,7 @@ static GtkActionEntry entries[] = {
 static GtkRadioActionEntry mode_entries[] = {
   { "ModeUTM",         NULL,         N_("_UTM Mode"),               "<control>u", NULL, 0 },
   { "ModeExpedia",     NULL,         N_("_Expedia Mode"),           "<control>e", NULL, 1 },
-  { "ModeGoogle",      NULL,         N_("_Old Google Mode"),        "<control>o", NULL, 2 },
-  { "ModeKH",          NULL,         N_("Old _KH Mode"),            "<control>k", NULL, 3 },
-  { "ModeMercator",    NULL,         N_("_Google Mode"),            "<control>g", NULL, 4 }
+  { "ModeMercator",    NULL,         N_("_Mercator Mode"),            "<control>g", NULL, 4 }
 };
 
 static GtkRadioActionEntry tool_entries[] = {
@@ -1994,10 +2017,10 @@ static GtkRadioActionEntry tool_entries[] = {
 };
 
 static GtkToggleActionEntry toggle_entries[] = {
-  { "ShowScale", NULL,                   N_("Show Scale"),                    NULL,         NULL,                                           (GCallback)set_draw_scale, TRUE   },
-  { "ShowCenterMark", NULL,                   N_("Show Center Mark"),                    NULL,         NULL,                                           (GCallback)set_draw_centermark, TRUE   },
-  { "FullScreen",    GTK_STOCK_FULLSCREEN,      N_("Full Screen"),                   "F11", NULL,                                           (GCallback)full_screen_cb, FALSE },
-  { "ViewSidePanel", GTK_STOCK_INDEX,   N_("View Side Panel "),                   "F9",         NULL,                                           (GCallback)view_side_panel_cb, TRUE    },
+  { "ShowScale", NULL,                   N_("Show Scale"),                    NULL,         N_("Show Scale"),                                           (GCallback)set_draw_scale, TRUE   },
+  { "ShowCenterMark", NULL,                   N_("Show Center Mark"),                    NULL,         N_("Show Center Mark"),                                           (GCallback)set_draw_centermark, TRUE   },
+  { "FullScreen",    GTK_STOCK_FULLSCREEN,      N_("Full Screen"),                   "F11", N_("Activate full screen mode"),                                           (GCallback)full_screen_cb, FALSE },
+  { "ViewSidePanel", GTK_STOCK_INDEX,   N_("Show Side Panel"),                   "F9",         N_("Show Side Panel"),                                           (GCallback)view_side_panel_cb, TRUE    },
 };
 
 #include "menu.xml.h"