<varlistentry>
<term>url</term>
<listitem>
- <para>the parametrized URL to open in the spirit of C printf format, with up to 7 "%s" values. e.g. <literal>http://hostname/getfile?lat=%s&lon=%s</literal></para>
+ <para>the parametrized URL to open in the spirit of C printf format, with up to 9 "%s" values. e.g. <literal>http://hostname/getfile?lat=%s&lon=%s</literal></para>
<para>The order and meaning of these parameters is given by the url_format_code below</para>
</listitem>
</varlistentry>
<para>A = center lAtitude of the current view</para>
<para>O = center lOngitude of the current view</para>
<para>Z = OSM Zoom value of the current view. See <ulink url="http://wiki.openstreetmap.org/wiki/Zoom_levels">Zoom Levels</ulink></para>
+ <para>P = selected Point's latitude</para>
+ <para>N = selected poiNt's longitude</para>
<para>S = A user specified input string requested from the user via a dialog box</para>
<para>Thus for the url example above then the format code should be <emphasis>AO</emphasis></para>
</listitem>
{
VIK_EXT_TOOL_GET_CLASS( self )->open( self, vwindow );
}
+
+void vik_ext_tool_open_at_position ( VikExtTool *self, VikWindow *vwindow, VikCoord *vc )
+{
+ if ( VIK_EXT_TOOL_GET_CLASS( self )->open_at_position )
+ VIK_EXT_TOOL_GET_CLASS( self )->open_at_position( self, vwindow, vc );
+}
#include <glib.h>
#include "vikwindow.h"
+#include "vikcoord.h"
G_BEGIN_DECLS
GObjectClass object_class;
gchar *(* get_label) (VikExtTool *self);
void (* open) (VikExtTool *self, VikWindow *vwindow);
+ void (* open_at_position) (VikExtTool *self, VikWindow *vwindow, VikCoord *vc);
};
GType vik_ext_tool_get_type ();
gchar *vik_ext_tool_get_label ( VikExtTool *self );
void vik_ext_tool_open ( VikExtTool *self, VikWindow *vwindow );
+void vik_ext_tool_open_at_position ( VikExtTool *self, VikWindow *vwindow, VikCoord *vc );
G_END_DECLS
#include <glib/gi18n.h>
#define VIK_TOOL_DATA_KEY "vik-tool-data"
+#define VIK_TOOL_WIN_KEY "vik-tool-win"
static GList *ext_tools_list = NULL;
}
}
}
+
+static void ext_tool_open_at_position_cb ( GtkWidget *widget, VikCoord *vc )
+{
+ gpointer ptr = g_object_get_data ( G_OBJECT(widget), VIK_TOOL_DATA_KEY );
+ VikExtTool *ext_tool = VIK_EXT_TOOL ( ptr );
+ gpointer wptr = g_object_get_data ( G_OBJECT(widget), VIK_TOOL_WIN_KEY );
+ VikWindow *vw = VIK_WINDOW ( wptr );
+ vik_ext_tool_open_at_position ( ext_tool, vw, vc );
+}
+
+/**
+ * Add to any menu
+ * mostly for allowing to assign for TrackWaypoint layer menus
+ */
+void vik_ext_tools_add_menu_items_to_menu ( VikWindow *vw, GtkMenu *menu, VikCoord *vc )
+{
+ for (GList *iter = ext_tools_list; iter; iter = iter->next) {
+ VikExtTool *ext_tool = NULL;
+ gchar *label = NULL;
+ ext_tool = VIK_EXT_TOOL ( iter->data );
+ label = vik_ext_tool_get_label ( ext_tool );
+ if ( label ) {
+ GtkWidget *item = NULL;
+ item = gtk_menu_item_new_with_label ( _(label) );
+ g_free ( label ); label = NULL;
+ // Store some data into the menu entry
+ g_object_set_data ( G_OBJECT(item), VIK_TOOL_DATA_KEY, ext_tool );
+ g_object_set_data ( G_OBJECT(item), VIK_TOOL_WIN_KEY, vw );
+ if ( vc )
+ g_signal_connect ( G_OBJECT(item), "activate", G_CALLBACK(ext_tool_open_at_position_cb), vc );
+ else
+ g_signal_connect ( G_OBJECT(item), "activate", G_CALLBACK(ext_tools_open_cb), vw );
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show ( item );
+ }
+ }
+}
void vik_ext_tools_register ( VikExtTool *tool );
void vik_ext_tools_unregister_all ();
void vik_ext_tools_add_action_items ( VikWindow *vwindow, GtkUIManager *uim, GtkActionGroup *action_group, guint mid );
+void vik_ext_tools_add_menu_items_to_menu ( VikWindow *vw, GtkMenu *menu, VikCoord *vc );
G_END_DECLS
#include "acquire.h"
#include "datasources.h"
#include "datasource_gps.h"
+#include "vikexttools.h"
#include "vikexttool_datasources.h"
#include "ui_util.h"
#include "vikutils.h"
}
}
+static GtkWidget* create_external_submenu ( GtkMenu *menu )
+{
+ GtkWidget *external_submenu = gtk_menu_new ();
+ GtkWidget *item = gtk_image_menu_item_new_with_mnemonic ( _("Externa_l") );
+ gtk_image_menu_item_set_image ( (GtkImageMenuItem*)item, gtk_image_new_from_stock (GTK_STOCK_EXECUTE, GTK_ICON_SIZE_MENU) );
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show ( item );
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), external_submenu );
+ return external_submenu;
+}
+
static void trw_layer_add_menu_items ( VikTrwLayer *vtl, GtkMenu *menu, gpointer vlp )
{
static menu_array_layer pass_along;
gtk_menu_shell_append ( GTK_MENU_SHELL(menu), item );
gtk_widget_show ( item );
gtk_widget_set_sensitive ( item, (gboolean)(g_hash_table_size (vtl->waypoints)) );
+
+ GtkWidget *external_submenu = create_external_submenu ( menu );
+ // TODO: Should use selected layer's centre - rather than implicitly using the current viewport
+ vik_ext_tools_add_menu_items_to_menu ( VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(vtl)), GTK_MENU (external_submenu), NULL );
}
// Fake Waypoint UUIDs vi simple increasing integer
}
}
- // Only made available if a suitable program is installed
+ GtkWidget *external_submenu = create_external_submenu ( menu );
+
+ // These are only made available if a suitable program is installed
if ( (have_astro_program || have_diary_program) &&
(subtype == VIK_TRW_LAYER_SUBLAYER_TRACK || subtype == VIK_TRW_LAYER_SUBLAYER_WAYPOINT) ) {
- GtkWidget *external_submenu;
- external_submenu = gtk_menu_new ();
- item = gtk_image_menu_item_new_with_mnemonic ( _("Externa_l") );
- gtk_image_menu_item_set_image ( (GtkImageMenuItem*)item, gtk_image_new_from_stock (GTK_STOCK_EXECUTE, GTK_ICON_SIZE_MENU) );
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_widget_show ( item );
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), external_submenu );
if ( have_diary_program ) {
item = gtk_image_menu_item_new_with_mnemonic ( _("_Diary") );
gtk_image_menu_item_set_image ( (GtkImageMenuItem*)item, gtk_image_new_from_stock (GTK_STOCK_SPELL_CHECK, GTK_ICON_SIZE_MENU) );
g_signal_connect_swapped ( G_OBJECT(item), "activate", G_CALLBACK(trw_layer_diary), pass_along );
gtk_menu_shell_append ( GTK_MENU_SHELL(external_submenu), item );
+ gtk_widget_set_tooltip_text (item, _("Open diary program at this date"));
gtk_widget_show ( item );
}
item = gtk_image_menu_item_new_with_mnemonic ( _("_Astronomy") );
g_signal_connect_swapped ( G_OBJECT(item), "activate", G_CALLBACK(trw_layer_astro), pass_along );
gtk_menu_shell_append ( GTK_MENU_SHELL(external_submenu), item );
+ gtk_widget_set_tooltip_text (item, _("Open astronomy program at this date and location"));
gtk_widget_show ( item );
}
}
+ if ( l->current_tpl || l->current_wp ) {
+ // For the selected point
+ VikCoord *vc;
+ if ( l->current_tpl )
+ vc = &(VIK_TRACKPOINT(l->current_tpl->data)->coord);
+ else
+ vc = &(l->current_wp->coord);
+ vik_ext_tools_add_menu_items_to_menu ( VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(l)), GTK_MENU (external_submenu), vc );
+ }
+ else {
+ // Otherwise for the selected sublayer
+ // TODO: Should use selected items centre - rather than implicitly using the current viewport
+ vik_ext_tools_add_menu_items_to_menu ( VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(l)), GTK_MENU (external_submenu), NULL );
+ }
+
+
#ifdef VIK_CONFIG_GOOGLE
if ( subtype == VIK_TRW_LAYER_SUBLAYER_ROUTE && is_valid_google_route ( l, sublayer ) )
{
static void webtool_finalize ( GObject *gob );
static void webtool_open ( VikExtTool *self, VikWindow *vwindow );
+static void webtool_open_at_position ( VikExtTool *self, VikWindow *vwindow, VikCoord *vc );
G_DEFINE_ABSTRACT_TYPE (VikWebtool, vik_webtool, VIK_EXT_TOOL_TYPE)
ext_tool_class = VIK_EXT_TOOL_CLASS ( klass );
ext_tool_class->open = webtool_open;
+ ext_tool_class->open_at_position = webtool_open_at_position;
}
VikWebtool *vik_webtool_new ()
g_free ( url );
}
+static void webtool_open_at_position ( VikExtTool *self, VikWindow *vwindow, VikCoord *vc )
+{
+ VikWebtool *vwd = VIK_WEBTOOL ( self );
+ gchar *url = vik_webtool_get_url_at_position ( vwd, vwindow, vc );
+ if ( url ) {
+ open_url ( GTK_WINDOW(vwindow), url );
+ g_free ( url );
+ }
+}
+
gchar *vik_webtool_get_url ( VikWebtool *self, VikWindow *vwindow )
{
return VIK_WEBTOOL_GET_CLASS( self )->get_url( self, vwindow );
}
+
+gchar *vik_webtool_get_url_at_position ( VikWebtool *self, VikWindow *vwindow, VikCoord *vc )
+{
+ if ( VIK_WEBTOOL_GET_CLASS( self )->get_url_at_position )
+ return VIK_WEBTOOL_GET_CLASS( self )->get_url_at_position( self, vwindow, vc );
+ else
+ return NULL;
+}
{
VikExtToolClass object_class;
gchar *(* get_url) (VikWebtool *self, VikWindow *vwindow);
+ gchar *(* get_url_at_position) (VikWebtool *self, VikWindow *vwindow, VikCoord *vc);
};
GType vik_webtool_get_type ();
};
gchar *vik_webtool_get_url ( VikWebtool *self, VikWindow *vwindow );
+gchar *vik_webtool_get_url_at_position ( VikWebtool *self, VikWindow *vwindow, VikCoord *vc );
G_END_DECLS
/*
* viking -- GPS Data and Topo Analyzer, Explorer, and Manager
*
- * Copyright (C) 2011, Rob Norris <rw_norris@hotmail.com>
+ * Copyright (C) 2011-2015, Rob Norris <rw_norris@hotmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
static GObjectClass *parent_class;
static void webtool_bounds_finalize ( GObject *gob );
-
static gchar *webtool_bounds_get_url ( VikWebtool *vw, VikWindow *vwindow );
+static gchar *webtool_bounds_get_url_at_position ( VikWebtool *vw, VikWindow *vwindow, VikCoord *vc );
typedef struct _VikWebtoolBoundsPrivate VikWebtoolBoundsPrivate;
base_class = VIK_WEBTOOL_CLASS ( klass );
base_class->get_url = webtool_bounds_get_url;
-
- //klass->mpp_to_zoom = webtool_bounds_mpp_to_zoom;
+ base_class->get_url_at_position = webtool_bounds_get_url_at_position;
g_type_class_add_private (klass, sizeof (VikWebtoolBoundsPrivate));
}
return g_strdup_printf ( priv->url, sminlon, smaxlon, sminlat, smaxlat );
}
+
+static gchar *webtool_bounds_get_url_at_position ( VikWebtool *self, VikWindow *vwindow, VikCoord *vc )
+{
+ // TODO: could use zoom level to generate an offset from center lat/lon to get the bounds
+ // For now simply use the existing function to use bounds from the viewport
+ return webtool_bounds_get_url ( self, vwindow );
+}
static guint8 webtool_center_mpp_to_zoom ( VikWebtool *self, gdouble mpp );
static gchar *webtool_center_get_url ( VikWebtool *vw, VikWindow *vwindow );
+static gchar *webtool_center_get_url_at_position ( VikWebtool *vw, VikWindow *vwindow, VikCoord *vc );
typedef struct _VikWebtoolCenterPrivate VikWebtoolCenterPrivate;
base_class = VIK_WEBTOOL_CLASS ( klass );
base_class->get_url = webtool_center_get_url;
+ base_class->get_url_at_position = webtool_center_get_url_at_position;
klass->mpp_to_zoom = webtool_center_mpp_to_zoom;
return map_utils_mpp_to_zoom_level ( mpp );
}
-static gchar *webtool_center_get_url ( VikWebtool *self, VikWindow *vwindow )
+static gchar *webtool_center_get_url_at_position ( VikWebtool *self, VikWindow *vwindow, VikCoord *vc )
{
VikWebtoolCenterPrivate *priv = NULL;
VikViewport *viewport = NULL;
- const VikCoord *coord = NULL;
guint8 zoom = 17;
struct LatLon ll;
gchar strlat[G_ASCII_DTOSTR_BUF_SIZE], strlon[G_ASCII_DTOSTR_BUF_SIZE];
priv = WEBTOOL_CENTER_GET_PRIVATE (self);
viewport = vik_window_viewport ( vwindow );
-
// Coords
- coord = vik_viewport_get_center ( viewport );
- vik_coord_to_latlon ( coord, &ll );
+ // Use the provided position otherwise use center of the viewport
+ if ( vc )
+ vik_coord_to_latlon ( vc, &ll );
+ else {
+ const VikCoord *coord = NULL;
+ coord = vik_viewport_get_center ( viewport );
+ vik_coord_to_latlon ( coord, &ll );
+ }
// zoom - ideally x & y factors need to be the same otherwise use the default
if ( vik_viewport_get_xmpp ( viewport ) == vik_viewport_get_ympp ( viewport ) )
return g_strdup_printf ( priv->url, strlat, strlon, zoom );
}
+static gchar *webtool_center_get_url ( VikWebtool *self, VikWindow *vwindow )
+{
+ return webtool_center_get_url_at_position ( self, vwindow, NULL );
+}
+
guint8 vik_webtool_center_mpp_to_zoom (VikWebtool *self, gdouble mpp)
{
return VIK_WEBTOOL_CENTER_GET_CLASS( self )->mpp_to_zoom( self, mpp );
static guint8 webtool_format_mpp_to_zoom ( VikWebtool *self, gdouble mpp );
static gchar *webtool_format_get_url ( VikWebtool *vw, VikWindow *vwindow );
+static gchar *webtool_format_get_url_at_position ( VikWebtool *vw, VikWindow *vwindow, VikCoord *vc );
typedef struct _VikWebtoolFormatPrivate VikWebtoolFormatPrivate;
base_class = VIK_WEBTOOL_CLASS ( klass );
base_class->get_url = webtool_format_get_url;
+ base_class->get_url_at_position = webtool_format_get_url_at_position;
klass->mpp_to_zoom = webtool_format_mpp_to_zoom;
return map_utils_mpp_to_zoom_level ( mpp );
}
-#define MAX_NUMBER_CODES 7
+#define MAX_NUMBER_CODES 9
-static gchar *webtool_format_get_url ( VikWebtool *self, VikWindow *vw )
+static gchar *webtool_format_get_url_at_position ( VikWebtool *self, VikWindow *vw, VikCoord *vc )
{
VikWebtoolFormatPrivate *priv = NULL;
priv = WEBTOOL_FORMAT_GET_PRIVATE (self);
g_ascii_dtostr (scenterlat, G_ASCII_DTOSTR_BUF_SIZE, ll.lat);
g_ascii_dtostr (scenterlon, G_ASCII_DTOSTR_BUF_SIZE, ll.lon);
+ struct LatLon llpt;
+ llpt.lat = 0.0;
+ llpt.lon = 0.0;
+ if ( vc )
+ vik_coord_to_latlon ( vc, &ll );
+ gchar spointlat[G_ASCII_DTOSTR_BUF_SIZE];
+ gchar spointlon[G_ASCII_DTOSTR_BUF_SIZE];
+ g_ascii_dtostr (spointlat, G_ASCII_DTOSTR_BUF_SIZE, llpt.lat);
+ g_ascii_dtostr (spointlon, G_ASCII_DTOSTR_BUF_SIZE, llpt.lon);
+
guint8 zoom = 17; // A zoomed in default
// zoom - ideally x & y factors need to be the same otherwise use the default
if ( vik_viewport_get_xmpp ( viewport ) == vik_viewport_get_ympp ( viewport ) )
case 'A': values[i] = g_strdup ( scenterlat ); break;
case 'O': values[i] = g_strdup ( scenterlon ); break;
case 'Z': values[i] = g_strdup ( szoom ); break;
+ case 'P': values[i] = g_strdup ( spointlat ); break;
+ case 'N': values[i] = g_strdup ( spointlon ); break;
default: break;
}
}
- gchar *url = g_strdup_printf ( priv->url, values[0], values[1], values[2], values[3], values[4], values[5], values[6] );
+ gchar *url = g_strdup_printf ( priv->url, values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], values[8] );
for ( i = 0; i < MAX_NUMBER_CODES; i++ ) {
if ( values[i] != '\0' )
return url;
}
+static gchar *webtool_format_get_url ( VikWebtool *self, VikWindow *vw )
+{
+ return webtool_format_get_url_at_position ( self, vw, NULL );
+}
+
guint8 vik_webtool_format_mpp_to_zoom (VikWebtool *self, gdouble mpp)
{
return VIK_WEBTOOL_FORMAT_GET_CLASS( self )->mpp_to_zoom( self, mpp );