]>
Commit | Line | Data |
---|---|---|
7f95fd54 GB |
1 | /* |
2 | * viking -- GPS Data and Topo Analyzer, Explorer, and Manager | |
3 | * | |
4 | * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net> | |
5 | * Copyright (C) 2013, Guilhem Bonnefille <guilhem.bonnefille@gmail.com> | |
17acdaec | 6 | * Copyright (C) 2015, Rob Norris <rw_norris@hotmail.com> |
7f95fd54 GB |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | * | |
22 | */ | |
23 | #ifdef HAVE_CONFIG_H | |
24 | #include "config.h" | |
25 | #endif | |
26 | ||
27 | #include <string.h> | |
28 | ||
29 | #include <glib/gprintf.h> | |
30 | #include <glib/gi18n.h> | |
31 | ||
32 | #include "viking.h" | |
33 | #include "babel.h" | |
34 | #include "gpx.h" | |
35 | #include "acquire.h" | |
36 | #include "vikrouting.h" | |
37 | ||
38 | typedef struct { | |
39 | GtkWidget *engines_combo; | |
40 | GtkWidget *from_entry, *to_entry; | |
41 | } datasource_routing_widgets_t; | |
42 | ||
43 | /* Memory of previous selection */ | |
44 | static gint last_engine = 0; | |
45 | static gchar *last_from_str = NULL; | |
46 | static gchar *last_to_str = NULL; | |
47 | ||
48 | static gpointer datasource_routing_init ( acq_vik_t *avt ); | |
49 | static void datasource_routing_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data ); | |
686baff0 | 50 | static void datasource_routing_get_process_options ( datasource_routing_widgets_t *widgets, ProcessOptions *po, DownloadFileOptions *options, const gchar *not_used2, const gchar *not_used3 ); |
7f95fd54 GB |
51 | static void datasource_routing_cleanup ( gpointer data ); |
52 | ||
53 | VikDataSourceInterface vik_datasource_routing_interface = { | |
54 | N_("Directions"), | |
55 | N_("Directions"), | |
9cc13848 | 56 | VIK_DATASOURCE_AUTO_LAYER_MANAGEMENT, |
7f95fd54 GB |
57 | VIK_DATASOURCE_INPUTTYPE_NONE, |
58 | TRUE, | |
59 | TRUE, | |
60 | TRUE, | |
61 | (VikDataSourceInitFunc) datasource_routing_init, | |
62 | (VikDataSourceCheckExistenceFunc) NULL, | |
63 | (VikDataSourceAddSetupWidgetsFunc) datasource_routing_add_setup_widgets, | |
17acdaec RN |
64 | (VikDataSourceGetProcessOptionsFunc) datasource_routing_get_process_options, |
65 | (VikDataSourceProcessFunc) a_babel_convert_from, | |
7f95fd54 GB |
66 | (VikDataSourceProgressFunc) NULL, |
67 | (VikDataSourceAddProgressWidgetsFunc) NULL, | |
68 | (VikDataSourceCleanupFunc) datasource_routing_cleanup, | |
69 | (VikDataSourceOffFunc) NULL, | |
63959706 RN |
70 | |
71 | NULL, | |
72 | 0, | |
73 | NULL, | |
74 | NULL, | |
75 | 0 | |
7f95fd54 GB |
76 | }; |
77 | ||
78 | static gpointer datasource_routing_init ( acq_vik_t *avt ) | |
79 | { | |
80 | datasource_routing_widgets_t *widgets = g_malloc(sizeof(*widgets)); | |
81 | return widgets; | |
82 | } | |
83 | ||
84 | static void datasource_routing_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data ) | |
85 | { | |
86 | datasource_routing_widgets_t *widgets = (datasource_routing_widgets_t *)user_data; | |
87 | GtkWidget *engine_label, *from_label, *to_label; | |
88 | ||
89 | /* Engine selector */ | |
90 | engine_label = gtk_label_new (_("Engine:")); | |
91 | widgets->engines_combo = vik_routing_ui_selector_new ((Predicate)vik_routing_engine_supports_direction, NULL); | |
92 | gtk_combo_box_set_active (GTK_COMBO_BOX (widgets->engines_combo), last_engine); | |
93 | ||
94 | /* From and To entries */ | |
95 | from_label = gtk_label_new (_("From:")); | |
96 | widgets->from_entry = gtk_entry_new(); | |
97 | to_label = gtk_label_new (_("To:")); | |
98 | widgets->to_entry = gtk_entry_new(); | |
99 | if (last_from_str) | |
100 | gtk_entry_set_text(GTK_ENTRY(widgets->from_entry), last_from_str); | |
101 | if (last_to_str) | |
102 | gtk_entry_set_text(GTK_ENTRY(widgets->to_entry), last_to_str); | |
103 | ||
104 | /* Packing all these widgets */ | |
105 | GtkBox *box = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))); | |
106 | gtk_box_pack_start ( box, engine_label, FALSE, FALSE, 5 ); | |
107 | gtk_box_pack_start ( box, widgets->engines_combo, FALSE, FALSE, 5 ); | |
108 | gtk_box_pack_start ( box, from_label, FALSE, FALSE, 5 ); | |
109 | gtk_box_pack_start ( box, widgets->from_entry, FALSE, FALSE, 5 ); | |
110 | gtk_box_pack_start ( box, to_label, FALSE, FALSE, 5 ); | |
111 | gtk_box_pack_start ( box, widgets->to_entry, FALSE, FALSE, 5 ); | |
112 | gtk_widget_show_all(dialog); | |
113 | } | |
114 | ||
686baff0 | 115 | static void datasource_routing_get_process_options ( datasource_routing_widgets_t *widgets, ProcessOptions *po, DownloadFileOptions *options, const gchar *not_used2, const gchar *not_used3 ) |
7f95fd54 GB |
116 | { |
117 | const gchar *from, *to; | |
118 | ||
119 | /* Retrieve directions */ | |
120 | from = gtk_entry_get_text ( GTK_ENTRY(widgets->from_entry) ); | |
121 | to = gtk_entry_get_text ( GTK_ENTRY(widgets->to_entry) ); | |
122 | ||
123 | /* Retrieve engine */ | |
124 | last_engine = gtk_combo_box_get_active ( GTK_COMBO_BOX(widgets->engines_combo) ); | |
125 | VikRoutingEngine *engine = vik_routing_ui_selector_get_nth ( widgets->engines_combo, last_engine ); | |
b02ade75 RN |
126 | if ( !engine ) return; |
127 | ||
17acdaec RN |
128 | po->url = vik_routing_engine_get_url_from_directions ( engine, from, to ); |
129 | po->input_file_type = g_strdup ( vik_routing_engine_get_format (engine) ); | |
130 | options = NULL; // i.e. use the default download settings | |
7f95fd54 GB |
131 | |
132 | /* Save last selection */ | |
133 | g_free ( last_from_str ); | |
134 | g_free ( last_to_str ); | |
135 | ||
136 | last_from_str = g_strdup( from ); | |
137 | last_to_str = g_strdup( to ); | |
138 | } | |
139 | ||
140 | static void datasource_routing_cleanup ( gpointer data ) | |
141 | { | |
142 | g_free ( data ); | |
143 | } |