]>
Commit | Line | Data |
---|---|---|
7b3479e3 EB |
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 | ||
69b825fe | 29 | #define GOOGLE_DIRECTIONS_STRING "(wget -O - \"http://maps.google.com/maps?q=%s to %s&output=js\" 2>/dev/null)" |
7b3479e3 EB |
30 | |
31 | typedef struct { | |
32 | GtkWidget *from_entry, *to_entry; | |
33 | } datasource_google_widgets_t; | |
34 | ||
d03413f2 QT |
35 | static gchar *last_from_str = NULL; |
36 | static gchar *last_to_str = NULL; | |
7b3479e3 | 37 | |
65f0ccab AF |
38 | static gpointer datasource_google_init( ); |
39 | static void datasource_google_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data ); | |
7b3479e3 | 40 | static void datasource_google_get_cmd_string ( datasource_google_widgets_t *widgets, gchar **cmd, gchar **input_type ); |
65f0ccab | 41 | static void datasource_google_cleanup ( gpointer data ); |
7b3479e3 EB |
42 | |
43 | VikDataSourceInterface vik_datasource_google_interface = { | |
a8d46e0b EB |
44 | "Google Directions", |
45 | "Google Directions", | |
7b3479e3 | 46 | VIK_DATASOURCE_SHELL_CMD, |
805d282e | 47 | VIK_DATASOURCE_ADDTOLAYER, |
65f0ccab | 48 | (VikDataSourceInitFunc) datasource_google_init, |
92255687 | 49 | (VikDataSourceCheckExistenceFunc) NULL, |
65f0ccab | 50 | (VikDataSourceAddSetupWidgetsFunc) datasource_google_add_setup_widgets, |
7b3479e3 | 51 | (VikDataSourceGetCmdStringFunc) datasource_google_get_cmd_string, |
7b3479e3 EB |
52 | (VikDataSourceProgressFunc) NULL, |
53 | (VikDataSourceAddProgressWidgetsFunc) NULL, | |
65f0ccab | 54 | (VikDataSourceCleanupFunc) datasource_google_cleanup, |
7b3479e3 EB |
55 | }; |
56 | ||
65f0ccab | 57 | static gpointer datasource_google_init ( ) |
7b3479e3 EB |
58 | { |
59 | datasource_google_widgets_t *widgets = g_malloc(sizeof(*widgets)); | |
65f0ccab AF |
60 | return widgets; |
61 | } | |
62 | ||
63 | static void datasource_google_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data ) | |
64 | { | |
65 | datasource_google_widgets_t *widgets = (datasource_google_widgets_t *)user_data; | |
7b3479e3 EB |
66 | GtkWidget *from_label, *to_label; |
67 | from_label = gtk_label_new ("From:"); | |
68 | widgets->from_entry = gtk_entry_new(); | |
69 | to_label = gtk_label_new ("To:"); | |
70 | widgets->to_entry = gtk_entry_new(); | |
d03413f2 | 71 | if (last_from_str) |
8ece78c0 | 72 | gtk_entry_set_text(GTK_ENTRY(widgets->from_entry), last_from_str); |
d03413f2 | 73 | if (last_to_str) |
8ece78c0 | 74 | gtk_entry_set_text(GTK_ENTRY(widgets->to_entry), last_to_str); |
7b3479e3 EB |
75 | gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), from_label, FALSE, FALSE, 5 ); |
76 | gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), widgets->from_entry, FALSE, FALSE, 5 ); | |
77 | gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), to_label, FALSE, FALSE, 5 ); | |
78 | gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), widgets->to_entry, FALSE, FALSE, 5 ); | |
79 | gtk_widget_show_all(dialog); | |
7b3479e3 EB |
80 | } |
81 | ||
82 | static void datasource_google_get_cmd_string ( datasource_google_widgets_t *widgets, gchar **cmd, gchar **input_type ) | |
83 | { | |
84 | /* TODO: special characters handling!!! */ | |
a8d46e0b EB |
85 | gchar *from_quoted, *to_quoted; |
86 | from_quoted = g_shell_quote ( gtk_entry_get_text ( GTK_ENTRY(widgets->from_entry) ) ); | |
87 | to_quoted = g_shell_quote ( gtk_entry_get_text ( GTK_ENTRY(widgets->to_entry) ) ); | |
88 | ||
89 | *cmd = g_strdup_printf( GOOGLE_DIRECTIONS_STRING, from_quoted, to_quoted ); | |
7b3479e3 EB |
90 | *input_type = g_strdup("google"); |
91 | ||
a24870d6 GB |
92 | g_free(last_from_str); |
93 | g_free(last_to_str); | |
d03413f2 QT |
94 | |
95 | last_from_str = g_strdup(gtk_entry_get_text ( GTK_ENTRY(widgets->from_entry) ) ); | |
96 | last_to_str = g_strdup(gtk_entry_get_text ( GTK_ENTRY(widgets->to_entry) ) ); | |
97 | ||
a8d46e0b EB |
98 | g_free(from_quoted); |
99 | g_free(to_quoted); | |
7b3479e3 EB |
100 | } |
101 | ||
65f0ccab | 102 | static void datasource_google_cleanup ( gpointer data ) |
7b3479e3 EB |
103 | { |
104 | g_free ( data ); | |
105 | } |