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