</para>
</section>
+<section>
+<title>From Routing</title>
+<para>
+<menuchoice><guimenu>File</guimenu><guimenuitem>Acquire</guimenuitem><guimenuitem>From Directions</guimenuitem></menuchoice>
+</para>
+<para>
+This gets a route from given directions.
+</para>
+</section>
+
</section> <!-- End Acquire -->
<section><title>Print</title>
<term>url-stop-ll</term>
<listitem><para>the part of the URL setting the end point location, parametrized in the spirit of C printf format, with 2 "%s" for coordinates (eg. "&start=%s,%s")</para></listitem>
</varlistentry>
+ <varlistentry>
+ <term>url-start-dir</term>
+ <listitem><para>the part of the URL setting the starting point location for direction based routing, parametrized in the spirit of C printf format, with one "%s" for direction (eg. "&start=%s")</para>
+ <para>(Optional)</para></listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>url-stop-dir</term>
+ <listitem><para>the part of the URL setting the end point location for direction based routing, parametrized in the spirit of C printf format, with one "%s" for direction (eg. "&start=%s")</para>
+ <para>(Optional)</para></listitem>
+ </varlistentry>
<varlistentry>
<term>referer</term>
<listitem><para>an URL to serve as referer for the HTTP request (eg. "http://hostname/")</para></listitem>
src/datasource_file.c
src/datasource_gc.c
src/datasource_geotag.c
-src/datasource_google.c
src/datasource_gps.c
src/datasource_osm.c
src/datasource_osm_my_traces.c
+src/datasource_routing.c
src/datasource_wikipedia.c
src/dem.c
src/download.c
babel.c babel.h \
datasource_file.c \
datasource_gps.c datasource_gps.h \
- datasource_google.c \
+ datasource_routing.c \
datasource_gc.c \
datasource_bfilter.c \
datasource_wikipedia.c \
*
* Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
* Copyright (C) 2006, Quy Tonthat <qtonthat@gmail.com>
+ * Copyright (C) 2013, Guilhem Bonnefille <guilhem.bonnefille@gmail.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
/* TODO in the future we could have support for other shells (change command strings), or not use a shell at all */
#define BASH_LOCATION "/bin/bash"
+/**
+ * List of supported protocols.
+ */
+const gchar *PROTOS[] = { "http://", "https://", "ftp://", NULL };
+
/**
* Path to gpsbabel
*/
return ret;
}
+/**
+ * a_babel_convert_from_url_or_shell:
+ * @vt: The #VikTrwLayer where to insert the collected data
+ * @url: the URL to fetch
+ * @cb: Optional callback function. Same usage as in a_babel_convert().
+ * @user_data: passed along to cb
+ * @options: download options. Maybe NULL.
+ *
+ * Download the file pointed by the URL and optionally uses GPSBabel to convert from input_file_type.
+ * If input_file_type is %NULL, doesn't use GPSBabel. Input must be GPX.
+ *
+ * Returns: %TRUE on successful invocation of GPSBabel or read of the GPX
+ *
+ */
+gboolean a_babel_convert_from_url_or_shell ( VikTrwLayer *vt, const char *input, const char *input_type, BabelStatusFunc cb, gpointer user_data, DownloadMapOptions *options )
+{
+
+ /* Check nature of input */
+ gboolean isUrl = FALSE;
+ int i = 0;
+ for (i = 0 ; PROTOS[i] != NULL ; i++)
+ {
+ const gchar *proto = PROTOS[i];
+ if (strncmp (input, proto, strlen(proto)) == 0)
+ {
+ /* Procotol matches: save result */
+ isUrl = TRUE;
+ }
+ }
+
+ /* Do the job */
+ if (isUrl)
+ return a_babel_convert_from_url (vt, input, input_type, cb, user_data, options);
+ else
+ return a_babel_convert_from_shellcommand (vt, input, input_type, cb, user_data, options);
+}
+
static gboolean babel_general_convert_to( VikTrwLayer *vt, VikTrack *trk, BabelStatusFunc cb, gchar **args, const gchar *name_src, gpointer user_data )
{
// Now strips out invisible tracks and waypoints
gboolean a_babel_convert_from( VikTrwLayer *vt, const char *babelargs, const char *file, BabelStatusFunc cb, gpointer user_data, gpointer options );
gboolean a_babel_convert_from_shellcommand ( VikTrwLayer *vt, const char *input_cmd, const char *input_file_type, BabelStatusFunc cb, gpointer user_data, gpointer options );
gboolean a_babel_convert_from_url ( VikTrwLayer *vt, const char *url, const char *input_type, BabelStatusFunc cb, gpointer user_data, DownloadMapOptions *options );
+gboolean a_babel_convert_from_url_or_shell ( VikTrwLayer *vt, const char *input, const char *input_type, BabelStatusFunc cb, gpointer user_data, DownloadMapOptions *options );
gboolean a_babel_convert_to( VikTrwLayer *vt, VikTrack *track, const char *babelargs, const char *file, BabelStatusFunc cb, gpointer user_data );
void a_babel_init ();
+++ /dev/null
-/*
- * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
- *
- * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-#include <string.h>
-
-#include <glib/gprintf.h>
-#include <glib/gi18n.h>
-
-#include "viking.h"
-#include "babel.h"
-#include "gpx.h"
-#include "acquire.h"
-
-#define GOOGLE_DIRECTIONS_STRING "maps.google.com/maps?q=from:%s+to:%s&output=js"
-
-typedef struct {
- GtkWidget *from_entry, *to_entry;
-} datasource_google_widgets_t;
-
-static gchar *last_from_str = NULL;
-static gchar *last_to_str = NULL;
-
-static gpointer datasource_google_init ( acq_vik_t *avt );
-static void datasource_google_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data );
-static void datasource_google_get_cmd_string ( datasource_google_widgets_t *widgets, gchar **cmd, gchar **input_file_type, DownloadMapOptions *options );
-static void datasource_google_cleanup ( gpointer data );
-
-VikDataSourceInterface vik_datasource_google_interface = {
- N_("Google Directions"),
- N_("Google Directions"),
- VIK_DATASOURCE_ADDTOLAYER,
- VIK_DATASOURCE_INPUTTYPE_NONE,
- TRUE,
- TRUE,
- TRUE,
- (VikDataSourceInitFunc) datasource_google_init,
- (VikDataSourceCheckExistenceFunc) NULL,
- (VikDataSourceAddSetupWidgetsFunc) datasource_google_add_setup_widgets,
- (VikDataSourceGetCmdStringFunc) datasource_google_get_cmd_string,
- (VikDataSourceProcessFunc) a_babel_convert_from_url,
- (VikDataSourceProgressFunc) NULL,
- (VikDataSourceAddProgressWidgetsFunc) NULL,
- (VikDataSourceCleanupFunc) datasource_google_cleanup,
- (VikDataSourceOffFunc) NULL,
-};
-
-static gpointer datasource_google_init ( acq_vik_t *avt )
-{
- datasource_google_widgets_t *widgets = g_malloc(sizeof(*widgets));
- return widgets;
-}
-
-static void datasource_google_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data )
-{
- datasource_google_widgets_t *widgets = (datasource_google_widgets_t *)user_data;
- GtkWidget *from_label, *to_label;
- from_label = gtk_label_new (_("From:"));
- widgets->from_entry = gtk_entry_new();
- to_label = gtk_label_new (_("To:"));
- widgets->to_entry = gtk_entry_new();
- if (last_from_str)
- gtk_entry_set_text(GTK_ENTRY(widgets->from_entry), last_from_str);
- if (last_to_str)
- gtk_entry_set_text(GTK_ENTRY(widgets->to_entry), last_to_str);
-
- /* Packing all these widgets */
- GtkBox *box = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog)));
- gtk_box_pack_start ( box, from_label, FALSE, FALSE, 5 );
- gtk_box_pack_start ( box, widgets->from_entry, FALSE, FALSE, 5 );
- gtk_box_pack_start ( box, to_label, FALSE, FALSE, 5 );
- gtk_box_pack_start ( box, widgets->to_entry, FALSE, FALSE, 5 );
- gtk_widget_show_all(dialog);
-}
-
-static void datasource_google_get_cmd_string ( datasource_google_widgets_t *widgets, gchar **cmd, gchar **input_file_type, DownloadMapOptions *options )
-{
- /* TODO: special characters handling!!! */
- gchar *from_quoted, *to_quoted;
- gchar **from_split, **to_split;
- from_quoted = g_shell_quote ( gtk_entry_get_text ( GTK_ENTRY(widgets->from_entry) ) );
- to_quoted = g_shell_quote ( gtk_entry_get_text ( GTK_ENTRY(widgets->to_entry) ) );
-
- from_split = g_strsplit( from_quoted, " ", 0);
- to_split = g_strsplit( to_quoted, " ", 0);
- from_quoted = g_strjoinv( "%20", from_split);
- to_quoted = g_strjoinv( "%20", to_split);
-
- *cmd = g_strdup_printf( GOOGLE_DIRECTIONS_STRING, from_quoted, to_quoted );
- *input_file_type = g_strdup("google");
- options = NULL;
-
- g_free(last_from_str);
- g_free(last_to_str);
-
- last_from_str = g_strdup( gtk_entry_get_text ( GTK_ENTRY(widgets->from_entry) ));
- last_to_str = g_strdup( gtk_entry_get_text ( GTK_ENTRY(widgets->to_entry) ));
-
- g_free(from_quoted);
- g_free(to_quoted);
- g_strfreev(from_split);
- g_strfreev(to_split);
-
-}
-
-static void datasource_google_cleanup ( gpointer data )
-{
- g_free ( data );
-}
--- /dev/null
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
+ * Copyright (C) 2013, Guilhem Bonnefille <guilhem.bonnefille@gmail.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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+
+#include <glib/gprintf.h>
+#include <glib/gi18n.h>
+
+#include "viking.h"
+#include "babel.h"
+#include "gpx.h"
+#include "acquire.h"
+#include "vikrouting.h"
+
+typedef struct {
+ GtkWidget *engines_combo;
+ GtkWidget *from_entry, *to_entry;
+} datasource_routing_widgets_t;
+
+/* Memory of previous selection */
+static gint last_engine = 0;
+static gchar *last_from_str = NULL;
+static gchar *last_to_str = NULL;
+
+static gpointer datasource_routing_init ( acq_vik_t *avt );
+static void datasource_routing_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data );
+static void datasource_routing_get_cmd_string ( datasource_routing_widgets_t *widgets, gchar **cmd, gchar **input_file_type, DownloadMapOptions *options );
+static void datasource_routing_cleanup ( gpointer data );
+
+VikDataSourceInterface vik_datasource_routing_interface = {
+ N_("Directions"),
+ N_("Directions"),
+ VIK_DATASOURCE_ADDTOLAYER,
+ VIK_DATASOURCE_INPUTTYPE_NONE,
+ TRUE,
+ TRUE,
+ TRUE,
+ (VikDataSourceInitFunc) datasource_routing_init,
+ (VikDataSourceCheckExistenceFunc) NULL,
+ (VikDataSourceAddSetupWidgetsFunc) datasource_routing_add_setup_widgets,
+ (VikDataSourceGetCmdStringFunc) datasource_routing_get_cmd_string,
+ (VikDataSourceProcessFunc) a_babel_convert_from_url_or_shell,
+ (VikDataSourceProgressFunc) NULL,
+ (VikDataSourceAddProgressWidgetsFunc) NULL,
+ (VikDataSourceCleanupFunc) datasource_routing_cleanup,
+ (VikDataSourceOffFunc) NULL,
+};
+
+static gpointer datasource_routing_init ( acq_vik_t *avt )
+{
+ datasource_routing_widgets_t *widgets = g_malloc(sizeof(*widgets));
+ return widgets;
+}
+
+static void datasource_routing_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data )
+{
+ datasource_routing_widgets_t *widgets = (datasource_routing_widgets_t *)user_data;
+ GtkWidget *engine_label, *from_label, *to_label;
+
+ /* Engine selector */
+ engine_label = gtk_label_new (_("Engine:"));
+ widgets->engines_combo = vik_routing_ui_selector_new ((Predicate)vik_routing_engine_supports_direction, NULL);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (widgets->engines_combo), last_engine);
+
+ /* From and To entries */
+ from_label = gtk_label_new (_("From:"));
+ widgets->from_entry = gtk_entry_new();
+ to_label = gtk_label_new (_("To:"));
+ widgets->to_entry = gtk_entry_new();
+ if (last_from_str)
+ gtk_entry_set_text(GTK_ENTRY(widgets->from_entry), last_from_str);
+ if (last_to_str)
+ gtk_entry_set_text(GTK_ENTRY(widgets->to_entry), last_to_str);
+
+ /* Packing all these widgets */
+ GtkBox *box = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog)));
+ gtk_box_pack_start ( box, engine_label, FALSE, FALSE, 5 );
+ gtk_box_pack_start ( box, widgets->engines_combo, FALSE, FALSE, 5 );
+ gtk_box_pack_start ( box, from_label, FALSE, FALSE, 5 );
+ gtk_box_pack_start ( box, widgets->from_entry, FALSE, FALSE, 5 );
+ gtk_box_pack_start ( box, to_label, FALSE, FALSE, 5 );
+ gtk_box_pack_start ( box, widgets->to_entry, FALSE, FALSE, 5 );
+ gtk_widget_show_all(dialog);
+}
+
+static void datasource_routing_get_cmd_string ( datasource_routing_widgets_t *widgets, gchar **cmd, gchar **input_file_type, DownloadMapOptions *options )
+{
+ const gchar *from, *to;
+
+ /* Retrieve directions */
+ from = gtk_entry_get_text ( GTK_ENTRY(widgets->from_entry) );
+ to = gtk_entry_get_text ( GTK_ENTRY(widgets->to_entry) );
+
+ /* Retrieve engine */
+ last_engine = gtk_combo_box_get_active ( GTK_COMBO_BOX(widgets->engines_combo) );
+ VikRoutingEngine *engine = vik_routing_ui_selector_get_nth ( widgets->engines_combo, last_engine );
+
+ *cmd = vik_routing_engine_get_cmd_from_directions ( engine, from, to );
+ *input_file_type = g_strdup ( vik_routing_engine_get_format (engine) );
+ options = NULL;
+
+ /* Save last selection */
+ g_free ( last_from_str );
+ g_free ( last_to_str );
+
+ last_from_str = g_strdup( from );
+ last_to_str = g_strdup( to );
+}
+
+static void datasource_routing_cleanup ( gpointer data )
+{
+ g_free ( data );
+}
extern VikDataSourceInterface vik_datasource_gps_interface;
extern VikDataSourceInterface vik_datasource_file_interface;
-#ifdef VIK_CONFIG_GOOGLE
-extern VikDataSourceInterface vik_datasource_google_interface;
-#endif
+extern VikDataSourceInterface vik_datasource_routing_interface;
#ifdef VIK_CONFIG_OPENSTREETMAP
extern VikDataSourceInterface vik_datasource_osm_interface;
extern VikDataSourceInterface vik_datasource_osm_my_traces_interface;
"url-base", "http://maps.google.com/maps?output=js&q=",
"url-start-ll", "from:%s,%s",
"url-stop-ll", "+to:%s,%s",
+ "url-start-dir", "from:%s",
+ "url-stop-dir", "+to:%s",
"referer", "http://maps.google.com/",
NULL);
vik_routing_register ( VIK_ROUTING_ENGINE ( routing ) );
" <menu action='Acquire'>"
" <menuitem action='AcquireGPS'/>"
" <menuitem action='AcquireGPSBabel'/>"
-#ifdef VIK_CONFIG_GOOGLE
- " <menuitem action='AcquireGoogle'/>"
-#endif
+ " <menuitem action='AcquireRouting'/>"
#ifdef VIK_CONFIG_OPENSTREETMAP
" <menuitem action='AcquireOSM'/>"
" <menuitem action='AcquireMyOSM'/>"
G_BEGIN_DECLS
-
/* Default */
void vik_routing_default_find ( VikTrwLayer *vt, struct LatLon start, struct LatLon end );
routing_class = VIK_ROUTING_ENGINE_CLASS ( klass );
routing_class->find = NULL;
-
+ routing_class->supports_direction = NULL;
+ routing_class->get_cmd_from_directions = NULL;
pspec = g_param_spec_string ("id",
"Identifier",
return priv->format;
}
+
+/**
+ * vik_routing_engine_supports_direction:
+ *
+ * Returns: %TRUE if this engine supports the route finding based on directions
+ */
+gboolean
+vik_routing_engine_supports_direction ( VikRoutingEngine *self )
+{
+ VikRoutingEngineClass *klass;
+
+ g_return_val_if_fail ( VIK_IS_ROUTING_ENGINE (self), FALSE );
+ klass = VIK_ROUTING_ENGINE_GET_CLASS( self );
+ g_return_val_if_fail ( klass->supports_direction != NULL, FALSE );
+
+ return klass->supports_direction( self );
+}
+
+/**
+ * vik_routing_engine_get_cmd_from_directions:
+ * @self: routing engine
+ * @start: the start direction
+ * @end: the end direction
+ *
+ * Compute a "cmd" for acquire framework.
+ *
+ * Returns: the computed cmd
+ */
+gchar *
+vik_routing_engine_get_cmd_from_directions ( VikRoutingEngine *self, const gchar *start, const gchar *end )
+{
+ VikRoutingEngineClass *klass;
+
+ g_return_val_if_fail ( VIK_IS_ROUTING_ENGINE (self), NULL );
+ klass = VIK_ROUTING_ENGINE_GET_CLASS( self );
+ g_return_val_if_fail ( klass->get_cmd_from_directions != NULL, NULL );
+
+ return klass->get_cmd_from_directions( self, start, end );
+}
{
GObjectClass object_class;
int (*find)(VikRoutingEngine *self, VikTrwLayer *vt, struct LatLon start, struct LatLon end);
+ gchar *(*get_cmd_from_directions)(VikRoutingEngine *self, const gchar *start, const gchar *end);
+ gboolean (*supports_direction)(VikRoutingEngine *self);
};
GType vik_routing_engine_get_type ();
};
int vik_routing_engine_find ( VikRoutingEngine *self, VikTrwLayer *vt, struct LatLon start, struct LatLon end );
+gchar *vik_routing_engine_get_cmd_from_directions ( VikRoutingEngine *self, const gchar *start, const gchar *end );
/* Acessors */
gchar *vik_routing_engine_get_id ( VikRoutingEngine *self );
gchar *vik_routing_engine_get_label ( VikRoutingEngine *self );
gchar *vik_routing_engine_get_format ( VikRoutingEngine *self );
+gboolean vik_routing_engine_supports_direction ( VikRoutingEngine *self );
+
G_END_DECLS
#endif
static void vik_routing_web_engine_finalize ( GObject *gob );
static int vik_routing_web_engine_find ( VikRoutingEngine *self, VikTrwLayer *vtl, struct LatLon start, struct LatLon end );
+static gchar *vik_routing_web_engine_get_cmd_from_directions(VikRoutingEngine *self, const gchar *start, const gchar *end);
+static gboolean vik_routing_web_engine_supports_direction(VikRoutingEngine *self);
typedef struct _VikRoutingWebEnginePrivate VikRoutingWebEnginePrivate;
struct _VikRoutingWebEnginePrivate
{
gchar *url_base;
+
+ /* LatLon */
gchar *url_start_ll_fmt;
gchar *url_stop_ll_fmt;
gchar *url_via_ll_fmt;
+ /* Directions */
+ gchar *url_start_dir_fmt;
+ gchar *url_stop_dir_fmt;
+
DownloadMapOptions options;
};
PROP_0,
PROP_URL_BASE,
+
+ /* LatLon */
PROP_URL_START_LL,
PROP_URL_STOP_LL,
PROP_URL_VIA_LL,
+ /* Direction */
+ PROP_URL_START_DIR,
+ PROP_URL_STOP_DIR,
+
PROP_REFERER,
PROP_FOLLOW_LOCATION,
};
priv->url_via_ll_fmt = g_strdup(g_value_get_string (value));
break;
+ case PROP_URL_START_DIR:
+ g_free (priv->url_start_dir_fmt);
+ priv->url_start_dir_fmt = g_strdup(g_value_get_string (value));
+ break;
+
+ case PROP_URL_STOP_DIR:
+ g_free (priv->url_stop_dir_fmt);
+ priv->url_stop_dir_fmt = g_strdup(g_value_get_string (value));
+ break;
+
case PROP_REFERER:
g_free (priv->options.referer);
priv->options.referer = g_value_dup_string (value);
g_value_set_string (value, priv->url_via_ll_fmt);
break;
+ case PROP_URL_START_DIR:
+ g_value_set_string (value, priv->url_start_dir_fmt);
+ break;
+
+ case PROP_URL_STOP_DIR:
+ g_value_set_string (value, priv->url_stop_dir_fmt);
+ break;
+
case PROP_REFERER:
g_value_set_string (value, priv->options.referer);
break;
parent_class = VIK_ROUTING_ENGINE_CLASS (klass);
parent_class->find = vik_routing_web_engine_find;
+ parent_class->supports_direction = vik_routing_web_engine_supports_direction;
+ parent_class->get_cmd_from_directions = vik_routing_web_engine_get_cmd_from_directions;
/**
* VikRoutingWebEngine:url-base:
g_object_class_install_property (object_class, PROP_URL_VIA_LL, pspec);
+ /**
+ * VikRoutingWebEngine:url-start-dir:
+ *
+ * The part of the request hosting the end point.
+ */
+ pspec = g_param_spec_string ("url-start-dir",
+ "Start part of the URL",
+ "The part of the request hosting the start point",
+ NULL /* default value */,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_URL_START_DIR, pspec);
+
+
+ /**
+ * VikRoutingWebEngine:url-stop-dir:
+ *
+ * The part of the request hosting the end point.
+ */
+ pspec = g_param_spec_string ("url-stop-dir",
+ "Stop part of the URL",
+ "The part of the request hosting the end point",
+ NULL /* default value */,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_URL_STOP_DIR, pspec);
+
+
/**
* VikRoutingWebEngine:referer:
*
VikRoutingWebEnginePrivate *priv = VIK_ROUTING_WEB_ENGINE_PRIVATE ( self );
priv->url_base = NULL;
+
+ /* LatLon */
priv->url_start_ll_fmt = NULL;
priv->url_stop_ll_fmt = NULL;
priv->url_via_ll_fmt = NULL;
+ /* Directions */
+ priv->url_start_dir_fmt = NULL;
+ priv->url_stop_dir_fmt = NULL;
+
priv->options.referer = NULL;
priv->options.follow_location = 0;
priv->options.check_file = NULL;
g_free (priv->url_base);
priv->url_base = NULL;
+
+ /* LatLon */
g_free (priv->url_start_ll_fmt);
priv->url_start_ll_fmt = NULL;
g_free (priv->url_stop_ll_fmt);
g_free (priv->url_via_ll_fmt);
priv->url_via_ll_fmt = NULL;
+ /* Directions */
+ g_free (priv->url_start_dir_fmt);
+ priv->url_start_dir_fmt = NULL;
+ g_free (priv->url_stop_dir_fmt);
+ priv->url_stop_dir_fmt = NULL;
+
g_free (priv->options.referer);
priv->options.referer = NULL;
gchar *startURL;
gchar *endURL;
gchar *url;
-
+
g_return_val_if_fail ( VIK_IS_ROUTING_WEB_ENGINE (self), NULL);
VikRoutingWebEnginePrivate *priv = VIK_ROUTING_WEB_ENGINE_PRIVATE ( self );
return ret;
}
+
+static gchar *
+vik_routing_web_engine_get_cmd_from_directions ( VikRoutingEngine *self, const gchar *start, const gchar *end )
+{
+ g_return_val_if_fail ( VIK_IS_ROUTING_WEB_ENGINE (self), NULL);
+
+ VikRoutingWebEnginePrivate *priv = VIK_ROUTING_WEB_ENGINE_PRIVATE ( self );
+
+ g_return_val_if_fail ( priv->url_base != NULL, NULL);
+ g_return_val_if_fail ( priv->url_start_dir_fmt != NULL, NULL);
+ g_return_val_if_fail ( priv->url_stop_dir_fmt != NULL, NULL);
+
+ gchar *from_quoted, *to_quoted;
+ gchar **from_split, **to_split;
+ from_quoted = g_shell_quote ( start );
+ to_quoted = g_shell_quote ( end );
+
+ from_split = g_strsplit( from_quoted, " ", 0);
+ to_split = g_strsplit( to_quoted, " ", 0);
+
+ from_quoted = g_strjoinv( "%20", from_split);
+ to_quoted = g_strjoinv( "%20", to_split);
+
+ gchar *url_fmt = g_strconcat ( priv->url_base, priv->url_start_dir_fmt, priv->url_stop_dir_fmt, NULL );
+ gchar *url = g_strdup_printf ( url_fmt, from_quoted, to_quoted );
+
+ g_free ( url_fmt );
+
+ g_free(from_quoted);
+ g_free(to_quoted);
+ g_strfreev(from_split);
+ g_strfreev(to_split);
+
+ return url;
+}
+
+static gboolean
+vik_routing_web_engine_supports_direction ( VikRoutingEngine *self )
+{
+ g_return_val_if_fail ( VIK_IS_ROUTING_WEB_ENGINE (self), FALSE);
+
+ VikRoutingWebEnginePrivate *priv = VIK_ROUTING_WEB_ENGINE_PRIVATE ( self );
+
+ return (priv->url_start_dir_fmt) != NULL;
+}
static void trw_layer_geotagging ( gpointer lav[2] );
#endif
static void trw_layer_acquire_gps_cb ( gpointer lav[2] );
-#ifdef VIK_CONFIG_GOOGLE
-static void trw_layer_acquire_google_cb ( gpointer lav[2] );
-#endif
+static void trw_layer_acquire_routing_cb ( gpointer lav[2] );
#ifdef VIK_CONFIG_OPENSTREETMAP
static void trw_layer_acquire_osm_cb ( gpointer lav[2] );
static void trw_layer_acquire_osm_my_traces_cb ( gpointer lav[2] );
a_acquire ( vw, vlp, vvp, &vik_datasource_gps_interface, NULL, NULL );
}
-#ifdef VIK_CONFIG_GOOGLE
/*
- * Acquire into this TRW Layer from Google Directions
+ * Acquire into this TRW Layer from Directions
*/
-static void trw_layer_acquire_google_cb ( gpointer lav[2] )
+static void trw_layer_acquire_routing_cb ( gpointer lav[2] )
{
VikTrwLayer *vtl = VIK_TRW_LAYER(lav[0]);
VikLayersPanel *vlp = VIK_LAYERS_PANEL(lav[1]);
VikWindow *vw = (VikWindow *)(VIK_GTK_WINDOW_FROM_LAYER(vtl));
VikViewport *vvp = vik_window_viewport(vw);
- a_acquire ( vw, vlp, vvp, &vik_datasource_google_interface, NULL, NULL );
+ a_acquire ( vw, vlp, vvp, &vik_datasource_routing_interface, NULL, NULL );
}
-#endif
#ifdef VIK_CONFIG_OPENSTREETMAP
/*
gtk_menu_shell_append (GTK_MENU_SHELL (acquire_submenu), item);
gtk_widget_show ( item );
-#ifdef VIK_CONFIG_GOOGLE
- item = gtk_menu_item_new_with_mnemonic ( _("From Google _Directions...") );
- g_signal_connect_swapped ( G_OBJECT(item), "activate", G_CALLBACK(trw_layer_acquire_google_cb), pass_along );
+ /* FIXME: only add menu when at least a routing engine has support for Directions */
+ item = gtk_menu_item_new_with_mnemonic ( _("From _Directions...") );
+ g_signal_connect_swapped ( G_OBJECT(item), "activate", G_CALLBACK(trw_layer_acquire_routing_cb), pass_along );
gtk_menu_shell_append (GTK_MENU_SHELL (acquire_submenu), item);
gtk_widget_show ( item );
-#endif
#ifdef VIK_CONFIG_OPENSTREETMAP
item = gtk_menu_item_new_with_mnemonic ( _("From _OSM Traces...") );
a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_file_interface, NULL, NULL );
}
-#ifdef VIK_CONFIG_GOOGLE
-static void acquire_from_google ( GtkAction *a, VikWindow *vw )
+static void acquire_from_routing ( GtkAction *a, VikWindow *vw )
{
- a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_google_interface, NULL, NULL );
+ a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_routing_interface, NULL, NULL );
}
-#endif
#ifdef VIK_CONFIG_OPENSTREETMAP
static void acquire_from_osm ( GtkAction *a, VikWindow *vw )
{ "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
- { "AcquireGoogle", NULL, N_("Google _Directions..."), NULL, N_("Get driving directions from Google"), (GCallback)acquire_from_google },
-#endif
+ { "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 },
{ "AcquireMyOSM", NULL, N_("_My OSM Traces..."), NULL, N_("Get Your Own Traces from OpenStreetMap"), (GCallback)acquire_from_my_osm },