]>
Commit | Line | Data |
---|---|---|
50a14534 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 | ||
4c77d5e0 GB |
22 | #ifdef HAVE_CONFIG_H |
23 | #include "config.h" | |
24 | #endif | |
25 | ||
50a14534 EB |
26 | #include "viking.h" |
27 | #include "thumbnails.h" | |
acaf7113 | 28 | #include "garminsymbols.h" |
dfad9456 | 29 | #include "degrees_converters.h" |
e8947958 | 30 | #include "authors.h" |
014128f6 | 31 | #include "googlesearch.h" |
50a14534 | 32 | |
4c77d5e0 GB |
33 | #include <glib/gi18n.h> |
34 | ||
50a14534 EB |
35 | #include <stdlib.h> |
36 | #include <string.h> | |
37 | #include <ctype.h> | |
38 | ||
39 | void a_dialog_msg ( GtkWindow *parent, gint type, const gchar *info, const gchar *extra ) | |
40 | { | |
41 | GtkWidget *msgbox = gtk_message_dialog_new ( parent, GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_OK, info, extra ); | |
42 | gtk_dialog_run ( GTK_DIALOG(msgbox) ); | |
43 | gtk_widget_destroy ( msgbox ); | |
44 | } | |
45 | ||
46 | gboolean a_dialog_goto_latlon ( GtkWindow *parent, struct LatLon *ll, const struct LatLon *old ) | |
47 | { | |
7760b0cf | 48 | GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to Lat/Lon"), |
50a14534 EB |
49 | parent, |
50 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
51 | GTK_STOCK_CANCEL, | |
52 | GTK_RESPONSE_REJECT, | |
53 | GTK_STOCK_OK, | |
54 | GTK_RESPONSE_ACCEPT, | |
55 | NULL); | |
56 | GtkWidget *latlabel, *lonlabel; | |
57 | GtkWidget *lat, *lon; | |
58 | gchar *tmp_lat, *tmp_lon; | |
59 | ||
7760b0cf | 60 | latlabel = gtk_label_new (_("Latitude:")); |
50a14534 EB |
61 | lat = gtk_entry_new (); |
62 | tmp_lat = g_strdup_printf ( "%f", old->lat ); | |
63 | gtk_entry_set_text ( GTK_ENTRY(lat), tmp_lat ); | |
64 | g_free ( tmp_lat ); | |
65 | ||
7760b0cf | 66 | lonlabel = gtk_label_new (_("Longitude:")); |
50a14534 EB |
67 | lon = gtk_entry_new (); |
68 | tmp_lon = g_strdup_printf ( "%f", old->lon ); | |
69 | gtk_entry_set_text ( GTK_ENTRY(lon), tmp_lon ); | |
70 | g_free ( tmp_lon ); | |
71 | ||
72 | gtk_widget_show ( latlabel ); | |
73 | gtk_widget_show ( lonlabel ); | |
74 | gtk_widget_show ( lat ); | |
75 | gtk_widget_show ( lon ); | |
76 | ||
77 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), latlabel, FALSE, FALSE, 0); | |
78 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lat, FALSE, FALSE, 0); | |
79 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lonlabel, FALSE, FALSE, 0); | |
80 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lon, FALSE, FALSE, 0); | |
81 | ||
82 | if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) | |
83 | { | |
dfad9456 GB |
84 | ll->lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lat) ) ); |
85 | ll->lon = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lon) ) ); | |
50a14534 EB |
86 | gtk_widget_destroy ( dialog ); |
87 | return TRUE; | |
88 | } | |
89 | ||
90 | gtk_widget_destroy ( dialog ); | |
91 | return FALSE; | |
92 | } | |
93 | ||
94 | gboolean a_dialog_goto_utm ( GtkWindow *parent, struct UTM *utm, const struct UTM *old ) | |
95 | { | |
7760b0cf | 96 | GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to Lat/Lon"), |
50a14534 EB |
97 | parent, |
98 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
99 | GTK_STOCK_CANCEL, | |
100 | GTK_RESPONSE_REJECT, | |
101 | GTK_STOCK_OK, | |
102 | GTK_RESPONSE_ACCEPT, | |
103 | NULL); | |
104 | GtkWidget *norlabel, *easlabel, *nor, *eas; | |
105 | GtkWidget *zonehbox, *zonespin, *letterentry; | |
106 | gchar *tmp_eas, *tmp_nor; | |
107 | gchar tmp_letter[2]; | |
108 | ||
7760b0cf | 109 | norlabel = gtk_label_new (_("Northing:")); |
50a14534 EB |
110 | nor = gtk_entry_new (); |
111 | tmp_nor = g_strdup_printf("%ld", (long) old->northing ); | |
112 | gtk_entry_set_text ( GTK_ENTRY(nor), tmp_nor ); | |
113 | g_free ( tmp_nor ); | |
114 | ||
7760b0cf | 115 | easlabel = gtk_label_new (_("Easting:")); |
50a14534 EB |
116 | eas = gtk_entry_new (); |
117 | tmp_eas = g_strdup_printf("%ld", (long) old->easting ); | |
118 | gtk_entry_set_text ( GTK_ENTRY(eas), tmp_eas ); | |
119 | g_free ( tmp_eas ); | |
120 | ||
121 | zonehbox = gtk_hbox_new ( FALSE, 0 ); | |
7760b0cf | 122 | gtk_box_pack_start ( GTK_BOX(zonehbox), gtk_label_new ( _("Zone:") ), FALSE, FALSE, 5 ); |
50a14534 EB |
123 | zonespin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( old->zone, 1, 60, 1, 5, 5 ), 1, 0 ); |
124 | gtk_box_pack_start ( GTK_BOX(zonehbox), zonespin, TRUE, TRUE, 5 ); | |
7760b0cf | 125 | gtk_box_pack_start ( GTK_BOX(zonehbox), gtk_label_new ( _("Letter:") ), FALSE, FALSE, 5 ); |
50a14534 EB |
126 | letterentry = gtk_entry_new (); |
127 | gtk_entry_set_max_length ( GTK_ENTRY(letterentry), 1 ); | |
128 | gtk_entry_set_width_chars ( GTK_ENTRY(letterentry), 2 ); | |
129 | tmp_letter[0] = old->letter; | |
130 | tmp_letter[1] = '\0'; | |
131 | gtk_entry_set_text ( GTK_ENTRY(letterentry), tmp_letter ); | |
132 | gtk_box_pack_start ( GTK_BOX(zonehbox), letterentry, FALSE, FALSE, 5 ); | |
133 | ||
134 | gtk_widget_show ( norlabel ); | |
135 | gtk_widget_show ( easlabel ); | |
136 | gtk_widget_show ( nor ); | |
137 | gtk_widget_show ( eas ); | |
138 | ||
139 | gtk_widget_show_all ( zonehbox ); | |
140 | ||
141 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), norlabel, FALSE, FALSE, 0); | |
142 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), nor, FALSE, FALSE, 0); | |
143 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), easlabel, FALSE, FALSE, 0); | |
144 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), eas, FALSE, FALSE, 0); | |
145 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), zonehbox, FALSE, FALSE, 0); | |
146 | ||
147 | if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) | |
148 | { | |
149 | const gchar *letter; | |
150 | utm->northing = atof ( gtk_entry_get_text ( GTK_ENTRY(nor) ) ); | |
151 | utm->easting = atof ( gtk_entry_get_text ( GTK_ENTRY(eas) ) ); | |
152 | utm->zone = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(zonespin) ); | |
153 | letter = gtk_entry_get_text ( GTK_ENTRY(letterentry) ); | |
154 | if (*letter) | |
155 | utm->letter = toupper(*letter); | |
156 | gtk_widget_destroy ( dialog ); | |
157 | return TRUE; | |
158 | } | |
159 | ||
160 | gtk_widget_destroy ( dialog ); | |
161 | return FALSE; | |
162 | } | |
163 | ||
164 | void a_dialog_response_accept ( GtkDialog *dialog ) | |
165 | { | |
166 | gtk_dialog_response ( dialog, GTK_RESPONSE_ACCEPT ); | |
167 | } | |
168 | ||
169 | /* todo: less on this side, like add track */ | |
170 | gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *wp, GHashTable *waypoints, VikCoordMode coord_mode ) | |
171 | { | |
7760b0cf | 172 | GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Create"), |
50a14534 EB |
173 | parent, |
174 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
175 | GTK_STOCK_CANCEL, | |
176 | GTK_RESPONSE_REJECT, | |
177 | GTK_STOCK_OK, | |
178 | GTK_RESPONSE_ACCEPT, | |
179 | NULL); | |
180 | struct LatLon ll; | |
e1e6f7fa | 181 | GtkWidget *latlabel, *lonlabel, *namelabel, *latentry, *lonentry, *altentry, *altlabel, *nameentry=NULL, *commentlabel, |
acaf7113 AF |
182 | *commententry, *imagelabel, *imageentry, *symbollabel, *symbolentry; |
183 | GtkListStore *store; | |
184 | ||
185 | ||
186 | ||
50a14534 EB |
187 | |
188 | gchar *lat, *lon, *alt; | |
189 | ||
190 | vik_coord_to_latlon ( &(wp->coord), &ll ); | |
191 | ||
192 | lat = g_strdup_printf ( "%f", ll.lat ); | |
193 | lon = g_strdup_printf ( "%f", ll.lon ); | |
194 | alt = g_strdup_printf ( "%f", wp->altitude ); | |
195 | ||
196 | if ( dest != NULL ) | |
197 | { | |
7760b0cf | 198 | namelabel = gtk_label_new (_("Name:")); |
50a14534 | 199 | nameentry = gtk_entry_new (); |
a8fe53f8 EB |
200 | if ( *dest ) { |
201 | gtk_entry_set_text( GTK_ENTRY(nameentry), *dest ); | |
202 | g_free ( *dest ); | |
203 | *dest = NULL; | |
204 | } | |
50a14534 EB |
205 | g_signal_connect_swapped ( nameentry, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) ); |
206 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), namelabel, FALSE, FALSE, 0); | |
207 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), nameentry, FALSE, FALSE, 0); | |
208 | } | |
209 | ||
7760b0cf | 210 | latlabel = gtk_label_new (_("Latitude:")); |
50a14534 EB |
211 | latentry = gtk_entry_new (); |
212 | gtk_entry_set_text ( GTK_ENTRY(latentry), lat ); | |
213 | g_free ( lat ); | |
214 | ||
7760b0cf | 215 | lonlabel = gtk_label_new (_("Longitude:")); |
50a14534 EB |
216 | lonentry = gtk_entry_new (); |
217 | gtk_entry_set_text ( GTK_ENTRY(lonentry), lon ); | |
218 | g_free ( lon ); | |
219 | ||
7760b0cf | 220 | altlabel = gtk_label_new (_("Altitude:")); |
50a14534 EB |
221 | altentry = gtk_entry_new (); |
222 | gtk_entry_set_text ( GTK_ENTRY(altentry), alt ); | |
223 | g_free ( alt ); | |
224 | ||
7760b0cf | 225 | commentlabel = gtk_label_new (_("Comment:")); |
50a14534 | 226 | commententry = gtk_entry_new (); |
8ece78c0 | 227 | gchar *cmt = a_googlesearch_get_search_string_for_this_place(VIK_WINDOW(parent)); |
014128f6 QT |
228 | if (cmt) |
229 | gtk_entry_set_text(GTK_ENTRY(commententry), cmt); | |
50a14534 | 230 | |
7760b0cf | 231 | imagelabel = gtk_label_new (_("Image:")); |
50a14534 EB |
232 | imageentry = vik_file_entry_new (); |
233 | ||
acaf7113 AF |
234 | { |
235 | GtkCellRenderer *r; | |
7760b0cf | 236 | symbollabel = gtk_label_new (_("Symbol:")); |
acaf7113 AF |
237 | GtkTreeIter iter; |
238 | ||
ea3933fc | 239 | store = gtk_list_store_new(3, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING); |
acaf7113 | 240 | symbolentry = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); |
886031df | 241 | gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(symbolentry), 3); |
acaf7113 | 242 | gtk_list_store_append (store, &iter); |
7760b0cf | 243 | gtk_list_store_set (store, &iter, 0, NULL, 1, NULL, 2, _("(none)"), -1); |
acaf7113 AF |
244 | a_populate_sym_list(store); |
245 | ||
246 | r = gtk_cell_renderer_pixbuf_new (); | |
247 | gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (symbolentry), r, FALSE); | |
248 | gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (symbolentry), r, "pixbuf", 1, NULL); | |
249 | ||
ea3933fc EB |
250 | r = gtk_cell_renderer_text_new (); |
251 | gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (symbolentry), r, FALSE); | |
252 | gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (symbolentry), r, "text", 2, NULL); | |
253 | ||
acaf7113 AF |
254 | if ( dest == NULL && wp->symbol ) { |
255 | gboolean ok; | |
256 | gchar *sym; | |
257 | for (ok = gtk_tree_model_get_iter_first ( GTK_TREE_MODEL(store), &iter ); ok; ok = gtk_tree_model_iter_next ( GTK_TREE_MODEL(store), &iter)) { | |
258 | gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 ); | |
ea3933fc | 259 | if (sym && !strcmp(sym, wp->symbol)) { |
acaf7113 AF |
260 | g_free(sym); |
261 | break; | |
262 | } else { | |
263 | g_free(sym); | |
264 | } | |
265 | } | |
886031df | 266 | gtk_combo_box_set_active_iter(GTK_COMBO_BOX(symbolentry), &iter); |
acaf7113 AF |
267 | } |
268 | } | |
269 | ||
50a14534 EB |
270 | if ( dest == NULL && wp->comment ) |
271 | gtk_entry_set_text ( GTK_ENTRY(commententry), wp->comment ); | |
272 | ||
273 | if ( dest == NULL && wp->image ) | |
274 | vik_file_entry_set_filename ( VIK_FILE_ENTRY(imageentry), wp->image ); | |
275 | ||
50a14534 EB |
276 | |
277 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), latlabel, FALSE, FALSE, 0); | |
278 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), latentry, FALSE, FALSE, 0); | |
279 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lonlabel, FALSE, FALSE, 0); | |
280 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lonentry, FALSE, FALSE, 0); | |
281 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), altlabel, FALSE, FALSE, 0); | |
282 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), altentry, FALSE, FALSE, 0); | |
283 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), commentlabel, FALSE, FALSE, 0); | |
284 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), commententry, FALSE, FALSE, 0); | |
285 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), imagelabel, FALSE, FALSE, 0); | |
286 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), imageentry, FALSE, FALSE, 0); | |
acaf7113 AF |
287 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), symbollabel, FALSE, FALSE, 0); |
288 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), GTK_WIDGET(symbolentry), FALSE, FALSE, 0); | |
50a14534 EB |
289 | |
290 | gtk_widget_show_all ( GTK_DIALOG(dialog)->vbox ); | |
acaf7113 | 291 | |
50a14534 EB |
292 | while ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) |
293 | { | |
294 | if ( dest ) | |
295 | { | |
296 | const gchar *constname = gtk_entry_get_text ( GTK_ENTRY(nameentry) ); | |
297 | if ( strlen(constname) == 0 ) /* TODO: other checks (isalpha or whatever ) */ | |
7760b0cf | 298 | a_dialog_info_msg ( parent, _("Please enter a name for the waypoint.") ); |
50a14534 EB |
299 | else { |
300 | int i; | |
301 | gchar *name = g_strdup ( constname ); | |
302 | ||
303 | for ( i = strlen ( name ) - 1; i >= 0; i-- ) | |
304 | name[i] = toupper(name[i]); /* all caps for stardandization */ | |
305 | ||
7760b0cf | 306 | if ( g_hash_table_lookup ( waypoints, name ) && !a_dialog_overwrite ( parent, _("The waypoint \"%s\" exists, do you want to overwrite it?"), name ) ) |
50a14534 EB |
307 | g_free ( name ); |
308 | else | |
309 | { | |
310 | /* Do It */ | |
311 | *dest = name; | |
dfad9456 GB |
312 | ll.lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(latentry) ) ); |
313 | ll.lon = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lonentry) ) ); | |
50a14534 EB |
314 | vik_coord_load_from_latlon ( &(wp->coord), coord_mode, &ll ); |
315 | wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ); | |
316 | vik_waypoint_set_comment ( wp, gtk_entry_get_text ( GTK_ENTRY(commententry) ) ); | |
317 | vik_waypoint_set_image ( wp, vik_file_entry_get_filename ( VIK_FILE_ENTRY(imageentry) ) ); | |
318 | if ( wp->image && *(wp->image) && (!a_thumbnails_exists(wp->image)) ) | |
319 | a_thumbnails_create ( wp->image ); | |
acaf7113 AF |
320 | |
321 | { | |
322 | GtkTreeIter iter, first; | |
323 | gtk_tree_model_get_iter_first ( GTK_TREE_MODEL(store), &first ); | |
886031df | 324 | if ( !gtk_combo_box_get_active_iter ( GTK_COMBO_BOX(symbolentry), &iter ) || !memcmp(&iter, &first, sizeof(GtkTreeIter)) ) { |
acaf7113 AF |
325 | vik_waypoint_set_symbol ( wp, NULL ); |
326 | } else { | |
327 | gchar *sym; | |
328 | gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 ); | |
329 | vik_waypoint_set_symbol ( wp, sym ); | |
330 | g_free(sym); | |
331 | } | |
332 | } | |
333 | ||
50a14534 EB |
334 | gtk_widget_destroy ( dialog ); |
335 | return TRUE; | |
336 | } | |
337 | } /* else (valid name) */ | |
338 | } | |
339 | else | |
340 | { | |
dfad9456 GB |
341 | ll.lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(latentry) ) ); |
342 | ll.lon = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lonentry) ) ); | |
50a14534 EB |
343 | vik_coord_load_from_latlon ( &(wp->coord), coord_mode, &ll ); |
344 | wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ); | |
345 | if ( (! wp->comment) || strcmp ( wp->comment, gtk_entry_get_text ( GTK_ENTRY(commententry) ) ) != 0 ) | |
346 | vik_waypoint_set_comment ( wp, gtk_entry_get_text ( GTK_ENTRY(commententry) ) ); | |
347 | if ( (! wp->image) || strcmp ( wp->image, vik_file_entry_get_filename ( VIK_FILE_ENTRY ( imageentry ) ) ) != 0 ) | |
348 | { | |
349 | vik_waypoint_set_image ( wp, vik_file_entry_get_filename ( VIK_FILE_ENTRY(imageentry) ) ); | |
350 | if ( wp->image && *(wp->image) && (!a_thumbnails_exists(wp->image)) ) | |
351 | a_thumbnails_create ( wp->image ); | |
352 | } | |
353 | ||
acaf7113 AF |
354 | { |
355 | GtkTreeIter iter, first; | |
356 | gtk_tree_model_get_iter_first ( GTK_TREE_MODEL(store), &first ); | |
886031df | 357 | if ( !gtk_combo_box_get_active_iter ( GTK_COMBO_BOX(symbolentry), &iter ) || !memcmp(&iter, &first, sizeof(GtkTreeIter)) ) { |
acaf7113 AF |
358 | vik_waypoint_set_symbol ( wp, NULL ); |
359 | } else { | |
360 | gchar *sym; | |
361 | gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 ); | |
362 | vik_waypoint_set_symbol ( wp, sym ); | |
363 | g_free(sym); | |
364 | } | |
365 | } | |
366 | ||
50a14534 EB |
367 | gtk_widget_destroy ( dialog ); |
368 | ||
369 | return TRUE; | |
370 | } | |
371 | } | |
372 | gtk_widget_destroy ( dialog ); | |
373 | return FALSE; | |
374 | } | |
375 | ||
376 | gchar *a_dialog_new_track ( GtkWindow *parent, GHashTable *tracks ) | |
377 | { | |
7760b0cf | 378 | GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Add Track"), |
50a14534 EB |
379 | parent, |
380 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
381 | GTK_STOCK_CANCEL, | |
382 | GTK_RESPONSE_REJECT, | |
383 | GTK_STOCK_OK, | |
384 | GTK_RESPONSE_ACCEPT, | |
385 | NULL); | |
7760b0cf | 386 | GtkWidget *label = gtk_label_new ( _("Track Name:") ); |
50a14534 EB |
387 | GtkWidget *entry = gtk_entry_new (); |
388 | ||
389 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), label, FALSE, FALSE, 0); | |
390 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry, FALSE, FALSE, 0); | |
391 | ||
392 | g_signal_connect_swapped ( entry, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) ); | |
393 | ||
394 | gtk_widget_show ( label ); | |
395 | gtk_widget_show ( entry ); | |
396 | ||
397 | while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT ) | |
398 | { | |
399 | const gchar *constname = gtk_entry_get_text ( GTK_ENTRY(entry) ); | |
400 | if ( *constname == '\0' ) | |
7760b0cf | 401 | a_dialog_info_msg ( parent, _("Please enter a name for the track.") ); |
50a14534 EB |
402 | else { |
403 | gchar *name = g_strdup ( constname ); | |
404 | gint i; | |
405 | ||
406 | for ( i = strlen ( name ) - 1; i >= 0; i-- ) | |
407 | name[i] = toupper(name[i]); /* all caps for stardandization */ | |
408 | ||
7760b0cf | 409 | if ( g_hash_table_lookup( tracks, name ) && !a_dialog_overwrite ( parent, _("The track \"%s\" exists, do you want to overwrite it?"), gtk_entry_get_text ( GTK_ENTRY(entry) ) ) ) |
50a14534 EB |
410 | { |
411 | g_free ( name ); | |
412 | } | |
413 | else | |
414 | { | |
415 | gtk_widget_destroy ( dialog ); | |
416 | return name; | |
417 | } | |
418 | } | |
419 | } | |
420 | gtk_widget_destroy ( dialog ); | |
421 | return NULL; | |
422 | } | |
423 | ||
424 | /* creates a vbox full of labels */ | |
425 | GtkWidget *a_dialog_create_label_vbox ( gchar **texts, int label_count ) | |
426 | { | |
427 | GtkWidget *vbox, *label; | |
428 | int i; | |
429 | vbox = gtk_vbox_new( TRUE, 3 ); | |
430 | ||
431 | for ( i = 0; i < label_count; i++ ) | |
432 | { | |
433 | label = gtk_label_new(NULL); | |
4c77d5e0 | 434 | gtk_label_set_markup ( GTK_LABEL(label), _(texts[i]) ); |
50a14534 EB |
435 | gtk_box_pack_start ( GTK_BOX(vbox), label, FALSE, TRUE, 5 ); |
436 | } | |
437 | return vbox; | |
438 | } | |
439 | ||
440 | gboolean a_dialog_overwrite ( GtkWindow *parent, const gchar *message, const gchar *extra ) | |
441 | { | |
442 | GtkWidget *dia; | |
443 | dia = gtk_message_dialog_new ( parent, | |
444 | GTK_DIALOG_DESTROY_WITH_PARENT, | |
445 | GTK_MESSAGE_QUESTION, | |
446 | GTK_BUTTONS_YES_NO, | |
447 | message, extra ); | |
448 | ||
449 | if ( gtk_dialog_run ( GTK_DIALOG(dia) ) == GTK_RESPONSE_YES ) | |
450 | { | |
451 | gtk_widget_destroy ( dia ); | |
452 | return TRUE; | |
453 | } | |
454 | else | |
455 | { | |
456 | gtk_widget_destroy ( dia ); | |
457 | return FALSE; | |
458 | } | |
459 | } | |
460 | ||
461 | static void zoom_spin_changed ( GtkSpinButton *spin, GtkWidget *pass_along[3] ) | |
462 | { | |
463 | if ( gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(pass_along[2]) ) ) | |
464 | gtk_spin_button_set_value ( | |
465 | GTK_SPIN_BUTTON(pass_along[GTK_WIDGET(spin) == pass_along[0] ? 1 : 0]), | |
466 | gtk_spin_button_get_value ( spin ) ); | |
467 | } | |
468 | ||
469 | gboolean a_dialog_custom_zoom ( GtkWindow *parent, gdouble *xmpp, gdouble *ympp ) | |
470 | { | |
7760b0cf | 471 | GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Zoom Factors..."), |
50a14534 EB |
472 | parent, |
473 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
474 | GTK_STOCK_CANCEL, | |
475 | GTK_RESPONSE_REJECT, | |
476 | GTK_STOCK_OK, | |
477 | GTK_RESPONSE_ACCEPT, | |
478 | NULL); | |
479 | GtkWidget *table, *label, *xlabel, *xspin, *ylabel, *yspin, *samecheck; | |
480 | GtkWidget *pass_along[3]; | |
481 | ||
482 | table = gtk_table_new ( 4, 2, FALSE ); | |
483 | gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), table, TRUE, TRUE, 0 ); | |
484 | ||
7760b0cf JJ |
485 | label = gtk_label_new ( _("Zoom factor (in meters per pixel:") ); |
486 | xlabel = gtk_label_new ( _("X (easting): ")); | |
487 | ylabel = gtk_label_new ( _("Y (northing): ")); | |
50a14534 EB |
488 | |
489 | pass_along[0] = xspin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *xmpp, VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM, 1, 5, 5 ), 1, 8 ); | |
490 | pass_along[1] = yspin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *ympp, VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM, 1, 5, 5 ), 1, 8 ); | |
491 | ||
7760b0cf | 492 | pass_along[2] = samecheck = gtk_check_button_new_with_label ( _("X and Y zoom factors must be equal") ); |
50a14534 EB |
493 | /* TODO -- same factor */ |
494 | /* samecheck = gtk_check_button_new_with_label ( "Same x/y zoom factor" ); */ | |
495 | ||
496 | if ( *xmpp == *ympp ) | |
497 | gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(samecheck), TRUE ); | |
498 | ||
499 | gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 2, 0, 1 ); | |
500 | gtk_table_attach_defaults ( GTK_TABLE(table), xlabel, 0, 1, 1, 2 ); | |
501 | gtk_table_attach_defaults ( GTK_TABLE(table), xspin, 1, 2, 1, 2 ); | |
502 | gtk_table_attach_defaults ( GTK_TABLE(table), ylabel, 0, 1, 2, 3 ); | |
503 | gtk_table_attach_defaults ( GTK_TABLE(table), yspin, 1, 2, 2, 3 ); | |
504 | gtk_table_attach_defaults ( GTK_TABLE(table), samecheck, 0, 2, 3, 4 ); | |
505 | ||
506 | gtk_widget_show_all ( table ); | |
507 | ||
508 | g_signal_connect ( G_OBJECT(xspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along ); | |
509 | g_signal_connect ( G_OBJECT(yspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along ); | |
510 | ||
511 | if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) | |
512 | { | |
513 | *xmpp = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(xspin) ); | |
514 | *ympp = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(yspin) ); | |
515 | gtk_widget_destroy ( dialog ); | |
516 | return TRUE; | |
517 | } | |
518 | gtk_widget_destroy ( dialog ); | |
519 | return FALSE; | |
520 | } | |
111fa174 AF |
521 | |
522 | static void split_spin_focused ( GtkSpinButton *spin, GtkWidget *pass_along[1] ) | |
523 | { | |
524 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(pass_along[0]), 1); | |
525 | } | |
526 | ||
527 | gboolean a_dialog_time_threshold ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint *thr ) | |
528 | { | |
529 | GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text, | |
530 | parent, | |
531 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
532 | GTK_STOCK_CANCEL, | |
533 | GTK_RESPONSE_REJECT, | |
534 | GTK_STOCK_OK, | |
535 | GTK_RESPONSE_ACCEPT, | |
536 | NULL); | |
537 | GtkWidget *table, *t1, *t2, *t3, *t4, *spin, *label; | |
538 | GtkWidget *pass_along[1]; | |
539 | ||
540 | table = gtk_table_new ( 4, 2, FALSE ); | |
541 | gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), table, TRUE, TRUE, 0 ); | |
542 | ||
543 | label = gtk_label_new (label_text); | |
544 | ||
7760b0cf JJ |
545 | t1 = gtk_radio_button_new_with_label ( NULL, _("1 min") ); |
546 | t2 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t1), _("1 hour") ); | |
547 | t3 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t2), _("1 day") ); | |
548 | t4 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t3), _("Custom (in minutes):") ); | |
111fa174 AF |
549 | |
550 | pass_along[0] = t4; | |
551 | ||
552 | spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *thr, 0, 65536, 1, 5, 5 ), 1, 0 ); | |
553 | ||
554 | gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 2, 0, 1 ); | |
555 | gtk_table_attach_defaults ( GTK_TABLE(table), t1, 0, 1, 1, 2 ); | |
556 | gtk_table_attach_defaults ( GTK_TABLE(table), t2, 0, 1, 2, 3 ); | |
557 | gtk_table_attach_defaults ( GTK_TABLE(table), t3, 0, 1, 3, 4 ); | |
558 | gtk_table_attach_defaults ( GTK_TABLE(table), t4, 0, 1, 4, 5 ); | |
559 | gtk_table_attach_defaults ( GTK_TABLE(table), spin, 1, 2, 4, 5 ); | |
560 | ||
561 | gtk_widget_show_all ( table ); | |
562 | ||
563 | g_signal_connect ( G_OBJECT(spin), "grab-focus", G_CALLBACK(split_spin_focused), pass_along ); | |
564 | ||
565 | if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) | |
566 | { | |
567 | if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t1))) { | |
568 | *thr = 1; | |
569 | } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t2))) { | |
570 | *thr = 60; | |
571 | } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t3))) { | |
572 | *thr = 60 * 24; | |
573 | } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t4))) { | |
574 | *thr = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) ); | |
575 | } | |
576 | gtk_widget_destroy ( dialog ); | |
577 | return TRUE; | |
578 | } | |
579 | gtk_widget_destroy ( dialog ); | |
580 | return FALSE; | |
581 | } | |
d0a5f320 AF |
582 | |
583 | ||
584 | void a_dialog_about ( GtkWindow *parent ) | |
585 | { | |
586 | int re; | |
2c8f64b4 | 587 | char *msg = g_markup_printf_escaped ( |
7760b0cf | 588 | _(_("<span font_desc='20' weight='bold'>Viking %s</span>\n\n" |
2c8f64b4 GB |
589 | "GPS Data and Topo Analyzer, Explorer, and Manager.\n\n" |
590 | "<small>(C) 2003-2007, Evan Battaglia</small>\n\n" | |
7760b0cf | 591 | "<small>Web site: %s</small>")), |
2c8f64b4 | 592 | VIKING_VERSION, VIKING_URL); |
d0a5f320 AF |
593 | GtkWidget *msgbox = gtk_message_dialog_new_with_markup ( parent, |
594 | GTK_DIALOG_DESTROY_WITH_PARENT, | |
595 | GTK_MESSAGE_INFO, | |
596 | GTK_BUTTONS_NONE, | |
2c8f64b4 | 597 | msg); |
d0a5f320 | 598 | |
7760b0cf | 599 | gtk_dialog_add_buttons (GTK_DIALOG(msgbox), _("Credits"), 1, _("License"), 2, _("Close"), 3, NULL, NULL); |
d0a5f320 AF |
600 | |
601 | while ((re = gtk_dialog_run ( GTK_DIALOG(msgbox))) != 3) { | |
602 | if (re==1) { | |
603 | /* creds */ | |
e8947958 | 604 | a_dialog_info_msg(parent, AUTHORS); |
d0a5f320 AF |
605 | } |
606 | if (re==2) { | |
7760b0cf | 607 | a_dialog_info_msg(parent, _("\n\n" |
d0a5f320 AF |
608 | "This program is free software; you can redistribute it and/or modify " |
609 | "it under the terms of the GNU General Public License as published by " | |
610 | "the Free Software Foundation; either version 2 of the License, or " | |
611 | "(at your option) any later version." | |
612 | "\n\n" | |
613 | "This program is distributed in the hope that it will be useful, " | |
614 | "but WITHOUT ANY WARRANTY; without even the implied warranty of " | |
615 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " | |
616 | "GNU General Public License for more details." | |
617 | "\n\n" | |
618 | "You should have received a copy of the GNU General Public License " | |
619 | "along with this program; if not, write to the Free Software " | |
7760b0cf | 620 | "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA")); |
d0a5f320 AF |
621 | } |
622 | } | |
623 | gtk_widget_destroy ( msgbox ); | |
624 | } | |
7114e879 QT |
625 | |
626 | gboolean a_dialog_map_n_zoom(GtkWindow *parent, gchar *mapnames[], gint default_map, gchar *zoom_list[], gint default_zoom, gint *selected_map, gint *selected_zoom) | |
627 | { | |
628 | gchar **s; | |
629 | ||
7760b0cf | 630 | GtkWidget *dialog = gtk_dialog_new_with_buttons ( _("Download along track"), parent, 0, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL ); |
7114e879 | 631 | |
7760b0cf | 632 | GtkWidget *map_label = gtk_label_new(_("Map type:")); |
8ece78c0 | 633 | GtkComboBox *map_combo = GTK_COMBO_BOX(gtk_combo_box_new_text()); |
7114e879 QT |
634 | for (s = mapnames; *s; s++) |
635 | gtk_combo_box_append_text(map_combo, *s); | |
636 | gtk_combo_box_set_active (map_combo, default_map); | |
7760b0cf | 637 | GtkWidget *zoom_label = gtk_label_new(_("Zoom level:")); |
8ece78c0 | 638 | GtkComboBox *zoom_combo = GTK_COMBO_BOX(gtk_combo_box_new_text()); |
7114e879 QT |
639 | for (s = zoom_list; *s; s++) |
640 | gtk_combo_box_append_text(zoom_combo, *s); | |
641 | gtk_combo_box_set_active (zoom_combo, default_zoom); | |
642 | ||
643 | GtkTable *box = GTK_TABLE(gtk_table_new(2, 2, FALSE)); | |
644 | gtk_table_attach_defaults(box, GTK_WIDGET(map_label), 0, 1, 0, 1); | |
645 | gtk_table_attach_defaults(box, GTK_WIDGET(map_combo), 1, 2, 0, 1); | |
646 | gtk_table_attach_defaults(box, GTK_WIDGET(zoom_label), 0, 1, 1, 2); | |
647 | gtk_table_attach_defaults(box, GTK_WIDGET(zoom_combo), 1, 2, 1, 2); | |
648 | ||
649 | gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), GTK_WIDGET(box), FALSE, FALSE, 5 ); | |
650 | ||
651 | gtk_widget_show_all ( dialog ); | |
652 | if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) != GTK_RESPONSE_ACCEPT ) { | |
653 | gtk_widget_destroy(dialog); | |
654 | return FALSE; | |
655 | } | |
656 | ||
657 | *selected_map = gtk_combo_box_get_active(map_combo); | |
658 | *selected_zoom = gtk_combo_box_get_active(zoom_combo); | |
659 | ||
660 | gtk_widget_destroy(dialog); | |
661 | return TRUE; | |
662 | } |