]> git.street.me.uk Git - andy/viking.git/blob - src/datasource_google.c
Fixed Google Directions
[andy/viking.git] / src / datasource_google.c
1 /*
2  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
3  *
4  * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21 #include <string.h>
22 #include <glib/gprintf.h>
23
24 #include "viking.h"
25 #include "babel.h"
26 #include "gpx.h"
27 #include "acquire.h"
28
29 #define GOOGLE_DIRECTIONS_STRING "(wget -O - \"http://maps.google.com/maps?q=%s to %s&output=js\" 2>/dev/null)"
30
31 typedef struct {
32   GtkWidget *from_entry, *to_entry;
33 } datasource_google_widgets_t;
34
35
36 static gpointer datasource_google_init( );
37 static void datasource_google_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data );
38 static void datasource_google_get_cmd_string ( datasource_google_widgets_t *widgets, gchar **cmd, gchar **input_type ); 
39 static void datasource_google_cleanup ( gpointer data );
40
41 VikDataSourceInterface vik_datasource_google_interface = {
42   "Google Directions",
43   "Google Directions",
44   VIK_DATASOURCE_SHELL_CMD,
45   VIK_DATASOURCE_ADDTOLAYER,
46   (VikDataSourceInitFunc)               datasource_google_init,
47   (VikDataSourceCheckExistenceFunc)     NULL,
48   (VikDataSourceAddSetupWidgetsFunc)    datasource_google_add_setup_widgets,
49   (VikDataSourceGetCmdStringFunc)       datasource_google_get_cmd_string,
50   (VikDataSourceProgressFunc)           NULL,
51   (VikDataSourceAddProgressWidgetsFunc) NULL,
52   (VikDataSourceCleanupFunc)            datasource_google_cleanup,
53 };
54
55 static gpointer datasource_google_init ( )
56 {
57   datasource_google_widgets_t *widgets = g_malloc(sizeof(*widgets));
58   return widgets;
59 }
60
61 static void datasource_google_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data )
62 {
63   datasource_google_widgets_t *widgets = (datasource_google_widgets_t *)user_data;
64   GtkWidget *from_label, *to_label;
65   from_label = gtk_label_new ("From:");
66   widgets->from_entry = gtk_entry_new();
67   to_label = gtk_label_new ("To:");
68   widgets->to_entry = gtk_entry_new();
69   gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), from_label, FALSE, FALSE, 5 );
70   gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), widgets->from_entry, FALSE, FALSE, 5 );
71   gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), to_label, FALSE, FALSE, 5 );
72   gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), widgets->to_entry, FALSE, FALSE, 5 );
73   gtk_widget_show_all(dialog);
74 }
75
76 static void datasource_google_get_cmd_string ( datasource_google_widgets_t *widgets, gchar **cmd, gchar **input_type )
77 {
78   /* TODO: special characters handling!!! */
79   gchar *from_quoted, *to_quoted;
80   from_quoted = g_shell_quote ( gtk_entry_get_text ( GTK_ENTRY(widgets->from_entry) ) );
81   to_quoted = g_shell_quote ( gtk_entry_get_text ( GTK_ENTRY(widgets->to_entry) ) );
82
83   *cmd = g_strdup_printf( GOOGLE_DIRECTIONS_STRING, from_quoted, to_quoted );
84   *input_type = g_strdup("google");
85
86   g_free(from_quoted);
87   g_free(to_quoted);
88 }
89
90 static void datasource_google_cleanup ( gpointer data )
91 {
92   g_free ( data );
93 }