]> git.street.me.uk Git - andy/viking.git/blame - src/datasource_google.c
Filter out irrelevant modifiers.
[andy/viking.git] / src / datasource_google.c
CommitLineData
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 */
8aad4ca3
GB
21#ifdef HAVE_CONFIG_H
22#include "config.h"
23#endif
7b3479e3 24#include <string.h>
4c77d5e0 25
7b3479e3 26#include <glib/gprintf.h>
4c77d5e0 27#include <glib/gi18n.h>
7b3479e3
EB
28
29#include "viking.h"
30#include "babel.h"
31#include "gpx.h"
32#include "acquire.h"
33
533bbf34 34#define GOOGLE_DIRECTIONS_STRING "maps.google.com/maps?q=from:%s+to:%s&output=js"
7b3479e3
EB
35
36typedef struct {
37 GtkWidget *from_entry, *to_entry;
38} datasource_google_widgets_t;
39
d03413f2
QT
40static gchar *last_from_str = NULL;
41static gchar *last_to_str = NULL;
7b3479e3 42
65f0ccab
AF
43static gpointer datasource_google_init( );
44static void datasource_google_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data );
28c82d8b 45static void datasource_google_get_cmd_string ( datasource_google_widgets_t *widgets, gchar **cmd, gchar **input_file_type );
65f0ccab 46static void datasource_google_cleanup ( gpointer data );
7b3479e3
EB
47
48VikDataSourceInterface vik_datasource_google_interface = {
4c77d5e0
GB
49 N_("Google Directions"),
50 N_("Google Directions"),
533bbf34 51 VIK_DATASOURCE_URL,
805d282e 52 VIK_DATASOURCE_ADDTOLAYER,
28c82d8b
EB
53 VIK_DATASOURCE_INPUTTYPE_NONE,
54 TRUE,
65f0ccab 55 (VikDataSourceInitFunc) datasource_google_init,
92255687 56 (VikDataSourceCheckExistenceFunc) NULL,
65f0ccab 57 (VikDataSourceAddSetupWidgetsFunc) datasource_google_add_setup_widgets,
7b3479e3 58 (VikDataSourceGetCmdStringFunc) datasource_google_get_cmd_string,
7b3479e3
EB
59 (VikDataSourceProgressFunc) NULL,
60 (VikDataSourceAddProgressWidgetsFunc) NULL,
65f0ccab 61 (VikDataSourceCleanupFunc) datasource_google_cleanup,
7b3479e3
EB
62};
63
65f0ccab 64static gpointer datasource_google_init ( )
7b3479e3
EB
65{
66 datasource_google_widgets_t *widgets = g_malloc(sizeof(*widgets));
65f0ccab
AF
67 return widgets;
68}
69
70static void datasource_google_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data )
71{
72 datasource_google_widgets_t *widgets = (datasource_google_widgets_t *)user_data;
7b3479e3 73 GtkWidget *from_label, *to_label;
4c77d5e0 74 from_label = gtk_label_new (_("From:"));
7b3479e3 75 widgets->from_entry = gtk_entry_new();
4c77d5e0 76 to_label = gtk_label_new (_("To:"));
7b3479e3 77 widgets->to_entry = gtk_entry_new();
d03413f2 78 if (last_from_str)
8ece78c0 79 gtk_entry_set_text(GTK_ENTRY(widgets->from_entry), last_from_str);
d03413f2 80 if (last_to_str)
8ece78c0 81 gtk_entry_set_text(GTK_ENTRY(widgets->to_entry), last_to_str);
7b3479e3
EB
82 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), from_label, FALSE, FALSE, 5 );
83 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), widgets->from_entry, FALSE, FALSE, 5 );
84 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), to_label, FALSE, FALSE, 5 );
85 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), widgets->to_entry, FALSE, FALSE, 5 );
86 gtk_widget_show_all(dialog);
7b3479e3
EB
87}
88
28c82d8b 89static void datasource_google_get_cmd_string ( datasource_google_widgets_t *widgets, gchar **cmd, gchar **input_file_type )
7b3479e3
EB
90{
91 /* TODO: special characters handling!!! */
a8d46e0b 92 gchar *from_quoted, *to_quoted;
533bbf34 93 gchar **from_split, **to_split;
a8d46e0b
EB
94 from_quoted = g_shell_quote ( gtk_entry_get_text ( GTK_ENTRY(widgets->from_entry) ) );
95 to_quoted = g_shell_quote ( gtk_entry_get_text ( GTK_ENTRY(widgets->to_entry) ) );
96
533bbf34
MA
97 from_split = g_strsplit( from_quoted, " ", 0);
98 to_split = g_strsplit( to_quoted, " ", 0);
99 from_quoted = g_strjoinv( "%20", from_split);
100 to_quoted = g_strjoinv( "%20", to_split);
101
a8d46e0b 102 *cmd = g_strdup_printf( GOOGLE_DIRECTIONS_STRING, from_quoted, to_quoted );
28c82d8b 103 *input_file_type = g_strdup("google");
7b3479e3 104
a24870d6
GB
105 g_free(last_from_str);
106 g_free(last_to_str);
d03413f2 107
533bbf34
MA
108 last_from_str = g_strdup( gtk_entry_get_text ( GTK_ENTRY(widgets->from_entry) ));
109 last_to_str = g_strdup( gtk_entry_get_text ( GTK_ENTRY(widgets->to_entry) ));
d03413f2 110
a8d46e0b
EB
111 g_free(from_quoted);
112 g_free(to_quoted);
533bbf34
MA
113 g_strfreev(from_split);
114 g_strfreev(to_split);
115
7b3479e3
EB
116}
117
65f0ccab 118static void datasource_google_cleanup ( gpointer data )
7b3479e3
EB
119{
120 g_free ( data );
121}