]> git.street.me.uk Git - andy/viking.git/blame - src/dialog.c
[Geotagging] Update RPM spec for new dependency.
[andy/viking.git] / src / dialog.c
CommitLineData
50a14534
EB
1/*
2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
3 *
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
a482007a
GB
5 * Copyright (C) 2008, Hein Ragas <viking@ragas.nl>
6 * Copyright (C) 2010, Rob Norris <rw_norris@hotmail.com>
50a14534
EB
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
4c77d5e0
GB
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
50a14534
EB
28#include "viking.h"
29#include "thumbnails.h"
acaf7113 30#include "garminsymbols.h"
dfad9456 31#include "degrees_converters.h"
e8947958 32#include "authors.h"
eb6a42c9 33#include "documenters.h"
34e71b99 34#include "vikgoto.h"
85beadba 35#include "util.h"
50a14534 36
4c77d5e0
GB
37#include <glib/gi18n.h>
38
50a14534
EB
39#include <stdlib.h>
40#include <string.h>
41#include <ctype.h>
42
43void a_dialog_msg ( GtkWindow *parent, gint type, const gchar *info, const gchar *extra )
44{
45 GtkWidget *msgbox = gtk_message_dialog_new ( parent, GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_OK, info, extra );
46 gtk_dialog_run ( GTK_DIALOG(msgbox) );
47 gtk_widget_destroy ( msgbox );
48}
49
50gboolean a_dialog_goto_latlon ( GtkWindow *parent, struct LatLon *ll, const struct LatLon *old )
51{
7760b0cf 52 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to Lat/Lon"),
50a14534
EB
53 parent,
54 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
55 GTK_STOCK_CANCEL,
56 GTK_RESPONSE_REJECT,
57 GTK_STOCK_OK,
58 GTK_RESPONSE_ACCEPT,
59 NULL);
60 GtkWidget *latlabel, *lonlabel;
61 GtkWidget *lat, *lon;
62 gchar *tmp_lat, *tmp_lon;
63
7760b0cf 64 latlabel = gtk_label_new (_("Latitude:"));
50a14534
EB
65 lat = gtk_entry_new ();
66 tmp_lat = g_strdup_printf ( "%f", old->lat );
67 gtk_entry_set_text ( GTK_ENTRY(lat), tmp_lat );
68 g_free ( tmp_lat );
69
7760b0cf 70 lonlabel = gtk_label_new (_("Longitude:"));
50a14534
EB
71 lon = gtk_entry_new ();
72 tmp_lon = g_strdup_printf ( "%f", old->lon );
73 gtk_entry_set_text ( GTK_ENTRY(lon), tmp_lon );
74 g_free ( tmp_lon );
75
76 gtk_widget_show ( latlabel );
77 gtk_widget_show ( lonlabel );
78 gtk_widget_show ( lat );
79 gtk_widget_show ( lon );
80
81 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), latlabel, FALSE, FALSE, 0);
82 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lat, FALSE, FALSE, 0);
83 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lonlabel, FALSE, FALSE, 0);
84 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lon, FALSE, FALSE, 0);
85
355fba11
RN
86 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
87
50a14534
EB
88 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
89 {
dfad9456
GB
90 ll->lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lat) ) );
91 ll->lon = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lon) ) );
50a14534
EB
92 gtk_widget_destroy ( dialog );
93 return TRUE;
94 }
95
96 gtk_widget_destroy ( dialog );
97 return FALSE;
98}
99
100gboolean a_dialog_goto_utm ( GtkWindow *parent, struct UTM *utm, const struct UTM *old )
101{
a0f3579f 102 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to UTM"),
50a14534
EB
103 parent,
104 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
105 GTK_STOCK_CANCEL,
106 GTK_RESPONSE_REJECT,
107 GTK_STOCK_OK,
108 GTK_RESPONSE_ACCEPT,
109 NULL);
110 GtkWidget *norlabel, *easlabel, *nor, *eas;
111 GtkWidget *zonehbox, *zonespin, *letterentry;
112 gchar *tmp_eas, *tmp_nor;
113 gchar tmp_letter[2];
114
7760b0cf 115 norlabel = gtk_label_new (_("Northing:"));
50a14534
EB
116 nor = gtk_entry_new ();
117 tmp_nor = g_strdup_printf("%ld", (long) old->northing );
118 gtk_entry_set_text ( GTK_ENTRY(nor), tmp_nor );
119 g_free ( tmp_nor );
120
7760b0cf 121 easlabel = gtk_label_new (_("Easting:"));
50a14534
EB
122 eas = gtk_entry_new ();
123 tmp_eas = g_strdup_printf("%ld", (long) old->easting );
124 gtk_entry_set_text ( GTK_ENTRY(eas), tmp_eas );
125 g_free ( tmp_eas );
126
127 zonehbox = gtk_hbox_new ( FALSE, 0 );
7760b0cf 128 gtk_box_pack_start ( GTK_BOX(zonehbox), gtk_label_new ( _("Zone:") ), FALSE, FALSE, 5 );
ac33062d 129 zonespin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( old->zone, 1, 60, 1, 5, 0 ), 1, 0 );
50a14534 130 gtk_box_pack_start ( GTK_BOX(zonehbox), zonespin, TRUE, TRUE, 5 );
7760b0cf 131 gtk_box_pack_start ( GTK_BOX(zonehbox), gtk_label_new ( _("Letter:") ), FALSE, FALSE, 5 );
50a14534
EB
132 letterentry = gtk_entry_new ();
133 gtk_entry_set_max_length ( GTK_ENTRY(letterentry), 1 );
134 gtk_entry_set_width_chars ( GTK_ENTRY(letterentry), 2 );
135 tmp_letter[0] = old->letter;
136 tmp_letter[1] = '\0';
137 gtk_entry_set_text ( GTK_ENTRY(letterentry), tmp_letter );
138 gtk_box_pack_start ( GTK_BOX(zonehbox), letterentry, FALSE, FALSE, 5 );
139
140 gtk_widget_show ( norlabel );
141 gtk_widget_show ( easlabel );
142 gtk_widget_show ( nor );
143 gtk_widget_show ( eas );
144
145 gtk_widget_show_all ( zonehbox );
146
147 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), norlabel, FALSE, FALSE, 0);
148 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), nor, FALSE, FALSE, 0);
149 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), easlabel, FALSE, FALSE, 0);
150 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), eas, FALSE, FALSE, 0);
151 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), zonehbox, FALSE, FALSE, 0);
152
355fba11
RN
153 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
154
50a14534
EB
155 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
156 {
157 const gchar *letter;
158 utm->northing = atof ( gtk_entry_get_text ( GTK_ENTRY(nor) ) );
159 utm->easting = atof ( gtk_entry_get_text ( GTK_ENTRY(eas) ) );
160 utm->zone = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(zonespin) );
161 letter = gtk_entry_get_text ( GTK_ENTRY(letterentry) );
162 if (*letter)
163 utm->letter = toupper(*letter);
164 gtk_widget_destroy ( dialog );
165 return TRUE;
166 }
167
168 gtk_widget_destroy ( dialog );
169 return FALSE;
170}
171
172void a_dialog_response_accept ( GtkDialog *dialog )
173{
174 gtk_dialog_response ( dialog, GTK_RESPONSE_ACCEPT );
175}
176
8eb76f51
QT
177static void symbol_entry_changed_cb(GtkWidget *combo, GtkListStore *store)
178{
179 GtkTreeIter iter;
180 gchar *sym;
181
182 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter))
183 return;
184
185 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 );
186 /* Note: symm is NULL when "(none)" is select (first cell is empty) */
187 gtk_widget_set_tooltip_text(combo, sym);
188 g_free(sym);
189}
190
ac1bde8b
RN
191/* Specify if a new waypoint or not */
192/* If a new waypoint then it uses the default_name for the suggested name allowing the user to change it.
193 The name to use is returned
194 When an existing waypoint the default name is shown but is not allowed to be changed and NULL is returned
195 */
50a14534 196/* todo: less on this side, like add track */
c9570f86 197gchar *a_dialog_waypoint ( GtkWindow *parent, gchar *default_name, VikWaypoint *wp, VikCoordMode coord_mode, gboolean is_new, gboolean *updated )
50a14534 198{
490b1aa6 199 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Waypoint Properties"),
50a14534
EB
200 parent,
201 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
202 GTK_STOCK_CANCEL,
203 GTK_RESPONSE_REJECT,
204 GTK_STOCK_OK,
205 GTK_RESPONSE_ACCEPT,
206 NULL);
207 struct LatLon ll;
e1e6f7fa 208 GtkWidget *latlabel, *lonlabel, *namelabel, *latentry, *lonentry, *altentry, *altlabel, *nameentry=NULL, *commentlabel,
acaf7113
AF
209 *commententry, *imagelabel, *imageentry, *symbollabel, *symbolentry;
210 GtkListStore *store;
211
50a14534
EB
212 gchar *lat, *lon, *alt;
213
214 vik_coord_to_latlon ( &(wp->coord), &ll );
215
216 lat = g_strdup_printf ( "%f", ll.lat );
217 lon = g_strdup_printf ( "%f", ll.lon );
6027a9c5
RN
218 vik_units_height_t height_units = a_vik_get_units_height ();
219 switch (height_units) {
220 case VIK_UNITS_HEIGHT_METRES:
221 alt = g_strdup_printf ( "%f", wp->altitude );
222 break;
223 case VIK_UNITS_HEIGHT_FEET:
6c20e59a 224 alt = g_strdup_printf ( "%f", VIK_METERS_TO_FEET(wp->altitude) );
6027a9c5
RN
225 break;
226 default:
227 alt = g_strdup_printf ( "%f", wp->altitude );
228 g_critical("Houston, we've had a problem. height=%d", height_units);
229 }
50a14534 230
ac1bde8b
RN
231 *updated = FALSE;
232
233 namelabel = gtk_label_new (_("Name:"));
234 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), namelabel, FALSE, FALSE, 0);
235 if ( is_new )
50a14534 236 {
ac1bde8b 237 // New waypoint, so name is still changeable
50a14534 238 nameentry = gtk_entry_new ();
ac1bde8b
RN
239 if ( default_name )
240 gtk_entry_set_text( GTK_ENTRY(nameentry), default_name );
50a14534 241 g_signal_connect_swapped ( nameentry, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
50a14534 242 }
ac1bde8b
RN
243 else {
244 // Existing waypoint - so can not change the name this way - but at least can see it
245 if ( default_name )
246 nameentry = gtk_label_new ( default_name );
247 }
248 if ( nameentry )
249 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), nameentry, FALSE, FALSE, 0);
50a14534 250
7760b0cf 251 latlabel = gtk_label_new (_("Latitude:"));
50a14534
EB
252 latentry = gtk_entry_new ();
253 gtk_entry_set_text ( GTK_ENTRY(latentry), lat );
254 g_free ( lat );
255
7760b0cf 256 lonlabel = gtk_label_new (_("Longitude:"));
50a14534
EB
257 lonentry = gtk_entry_new ();
258 gtk_entry_set_text ( GTK_ENTRY(lonentry), lon );
259 g_free ( lon );
260
7760b0cf 261 altlabel = gtk_label_new (_("Altitude:"));
50a14534
EB
262 altentry = gtk_entry_new ();
263 gtk_entry_set_text ( GTK_ENTRY(altentry), alt );
264 g_free ( alt );
265
7760b0cf 266 commentlabel = gtk_label_new (_("Comment:"));
50a14534 267 commententry = gtk_entry_new ();
ba4a5e11 268 gchar *cmt = NULL;
34e71b99 269 cmt = a_vik_goto_get_search_string_for_this_place(VIK_WINDOW(parent));
014128f6
QT
270 if (cmt)
271 gtk_entry_set_text(GTK_ENTRY(commententry), cmt);
50a14534 272
7760b0cf 273 imagelabel = gtk_label_new (_("Image:"));
79672b85 274 imageentry = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN);
50a14534 275
acaf7113
AF
276 {
277 GtkCellRenderer *r;
7760b0cf 278 symbollabel = gtk_label_new (_("Symbol:"));
acaf7113
AF
279 GtkTreeIter iter;
280
ea3933fc 281 store = gtk_list_store_new(3, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING);
acaf7113 282 symbolentry = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
8eb76f51 283 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(symbolentry), 6);
9be0449f
RN
284
285 g_signal_connect(symbolentry, "changed", G_CALLBACK(symbol_entry_changed_cb), store);
acaf7113 286 gtk_list_store_append (store, &iter);
7760b0cf 287 gtk_list_store_set (store, &iter, 0, NULL, 1, NULL, 2, _("(none)"), -1);
acaf7113
AF
288 a_populate_sym_list(store);
289
290 r = gtk_cell_renderer_pixbuf_new ();
291 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (symbolentry), r, FALSE);
292 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (symbolentry), r, "pixbuf", 1, NULL);
293
ea3933fc
EB
294 r = gtk_cell_renderer_text_new ();
295 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (symbolentry), r, FALSE);
296 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (symbolentry), r, "text", 2, NULL);
297
ac1bde8b 298 if ( !is_new && wp->symbol ) {
acaf7113
AF
299 gboolean ok;
300 gchar *sym;
301 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)) {
302 gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 );
ea3933fc 303 if (sym && !strcmp(sym, wp->symbol)) {
acaf7113
AF
304 g_free(sym);
305 break;
306 } else {
307 g_free(sym);
308 }
309 }
705af621
RN
310 // Ensure is it a valid symbol in the given symbol set (large vs small)
311 // Not all symbols are available in both
312 // The check prevents a Gtk Critical message
313 if ( iter.stamp )
314 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(symbolentry), &iter);
acaf7113
AF
315 }
316 }
317
ac1bde8b 318 if ( !is_new && wp->comment )
50a14534
EB
319 gtk_entry_set_text ( GTK_ENTRY(commententry), wp->comment );
320
ac1bde8b 321 if ( !is_new && wp->image )
50a14534
EB
322 vik_file_entry_set_filename ( VIK_FILE_ENTRY(imageentry), wp->image );
323
50a14534
EB
324
325 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), latlabel, FALSE, FALSE, 0);
326 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), latentry, FALSE, FALSE, 0);
327 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lonlabel, FALSE, FALSE, 0);
328 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lonentry, FALSE, FALSE, 0);
329 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), altlabel, FALSE, FALSE, 0);
330 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), altentry, FALSE, FALSE, 0);
331 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), commentlabel, FALSE, FALSE, 0);
332 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), commententry, FALSE, FALSE, 0);
333 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), imagelabel, FALSE, FALSE, 0);
334 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), imageentry, FALSE, FALSE, 0);
acaf7113
AF
335 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), symbollabel, FALSE, FALSE, 0);
336 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), GTK_WIDGET(symbolentry), FALSE, FALSE, 0);
50a14534 337
f703e735
RN
338 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
339
50a14534 340 gtk_widget_show_all ( GTK_DIALOG(dialog)->vbox );
acaf7113 341
50a14534
EB
342 while ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
343 {
ac1bde8b 344 if ( is_new )
50a14534 345 {
c9570f86 346 gchar *entered_name = g_strdup ( (gchar*)gtk_entry_get_text ( GTK_ENTRY(nameentry) ) );
ac1bde8b 347 if ( strlen(entered_name) == 0 ) /* TODO: other checks (isalpha or whatever ) */
7760b0cf 348 a_dialog_info_msg ( parent, _("Please enter a name for the waypoint.") );
50a14534 349 else {
50a14534 350
c9570f86
RN
351 // NB: No check for unique names - this allows generation of same named entries.
352
353 /* Do It */
354 ll.lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(latentry) ) );
355 ll.lon = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lonentry) ) );
356 vik_coord_load_from_latlon ( &(wp->coord), coord_mode, &ll );
357 // Always store in metres
358 switch (height_units) {
359 case VIK_UNITS_HEIGHT_METRES:
360 wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) );
361 break;
362 case VIK_UNITS_HEIGHT_FEET:
363 wp->altitude = VIK_FEET_TO_METERS(atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ));
364 break;
365 default:
366 wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) );
367 g_critical("Houston, we've had a problem. height=%d", height_units);
368 }
369 vik_waypoint_set_comment ( wp, gtk_entry_get_text ( GTK_ENTRY(commententry) ) );
370 vik_waypoint_set_image ( wp, vik_file_entry_get_filename ( VIK_FILE_ENTRY(imageentry) ) );
371 if ( wp->image && *(wp->image) && (!a_thumbnails_exists(wp->image)) )
372 a_thumbnails_create ( wp->image );
373
374 GtkTreeIter iter, first;
375 gtk_tree_model_get_iter_first ( GTK_TREE_MODEL(store), &first );
376 if ( !gtk_combo_box_get_active_iter ( GTK_COMBO_BOX(symbolentry), &iter ) || !memcmp(&iter, &first, sizeof(GtkTreeIter)) ) {
377 vik_waypoint_set_symbol ( wp, NULL );
378 } else {
379 gchar *sym;
380 gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 );
381 vik_waypoint_set_symbol ( wp, sym );
382 g_free(sym);
383 }
384
385 gtk_widget_destroy ( dialog );
386 return entered_name;
387 }
50a14534
EB
388 }
389 else
390 {
dfad9456
GB
391 ll.lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(latentry) ) );
392 ll.lon = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lonentry) ) );
50a14534 393 vik_coord_load_from_latlon ( &(wp->coord), coord_mode, &ll );
6027a9c5
RN
394 switch (height_units) {
395 case VIK_UNITS_HEIGHT_METRES:
396 wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) );
6027a9c5
RN
397 break;
398 case VIK_UNITS_HEIGHT_FEET:
ab1e0693 399 wp->altitude = VIK_FEET_TO_METERS(atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ));
6027a9c5
RN
400 break;
401 default:
402 wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) );
403 g_critical("Houston, we've had a problem. height=%d", height_units);
404 }
50a14534
EB
405 if ( (! wp->comment) || strcmp ( wp->comment, gtk_entry_get_text ( GTK_ENTRY(commententry) ) ) != 0 )
406 vik_waypoint_set_comment ( wp, gtk_entry_get_text ( GTK_ENTRY(commententry) ) );
407 if ( (! wp->image) || strcmp ( wp->image, vik_file_entry_get_filename ( VIK_FILE_ENTRY ( imageentry ) ) ) != 0 )
408 {
409 vik_waypoint_set_image ( wp, vik_file_entry_get_filename ( VIK_FILE_ENTRY(imageentry) ) );
410 if ( wp->image && *(wp->image) && (!a_thumbnails_exists(wp->image)) )
411 a_thumbnails_create ( wp->image );
412 }
413
acaf7113
AF
414 {
415 GtkTreeIter iter, first;
416 gtk_tree_model_get_iter_first ( GTK_TREE_MODEL(store), &first );
886031df 417 if ( !gtk_combo_box_get_active_iter ( GTK_COMBO_BOX(symbolentry), &iter ) || !memcmp(&iter, &first, sizeof(GtkTreeIter)) ) {
acaf7113
AF
418 vik_waypoint_set_symbol ( wp, NULL );
419 } else {
420 gchar *sym;
421 gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 );
422 vik_waypoint_set_symbol ( wp, sym );
423 g_free(sym);
424 }
425 }
426
50a14534 427 gtk_widget_destroy ( dialog );
ac1bde8b
RN
428
429 *updated = TRUE;
430 return NULL;
50a14534
EB
431 }
432 }
433 gtk_widget_destroy ( dialog );
ac1bde8b 434 return NULL;
50a14534
EB
435}
436
7767aa02
QT
437static void get_selected_foreach_func(GtkTreeModel *model,
438 GtkTreePath *path,
439 GtkTreeIter *iter,
440 gpointer data)
441{
442 GList **list = data;
443 gchar *name;
444 gtk_tree_model_get (model, iter, 0, &name, -1);
445 *list = g_list_prepend(*list, name);
446}
447
02bba540 448GList *a_dialog_select_from_list ( GtkWindow *parent, GList *names, gboolean multiple_selection_allowed, const gchar *title, const gchar *msg )
291edcab
HR
449{
450 GtkTreeIter iter;
451 GtkCellRenderer *renderer;
452 GtkWidget *view;
453
7767aa02 454 GtkWidget *dialog = gtk_dialog_new_with_buttons (title,
291edcab
HR
455 parent,
456 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
457 GTK_STOCK_CANCEL,
458 GTK_RESPONSE_REJECT,
459 GTK_STOCK_OK,
460 GTK_RESPONSE_ACCEPT,
461 NULL);
93ece96d
RN
462 /* When something is selected then OK */
463 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
464 GtkWidget *response_w = NULL;
465#if GTK_CHECK_VERSION (2, 20, 0)
466 /* Default to not apply - as initially nothing is selected! */
467 response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_REJECT );
468#endif
291edcab
HR
469 GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING);
470
a814d755
RN
471 GtkWidget *scrolledwindow;
472
02bba540
RN
473 GList *runner = names;
474 while (runner)
291edcab 475 {
15f45edc 476 gtk_list_store_append(store, &iter);
02bba540
RN
477 gtk_list_store_set(store, &iter, 0, runner->data, -1);
478 runner = g_list_next(runner);
291edcab 479 }
291edcab
HR
480
481 view = gtk_tree_view_new();
482 renderer = gtk_cell_renderer_text_new();
a814d755
RN
483 // Use the column header to display the message text,
484 // this makes the overall widget allocation simple as treeview takes up all the space
485 gtk_tree_view_insert_column_with_attributes( GTK_TREE_VIEW(view), -1, msg, renderer, "text", 0, NULL);
291edcab 486 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
a814d755 487 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(view), TRUE);
7767aa02
QT
488 gtk_tree_selection_set_mode( gtk_tree_view_get_selection(GTK_TREE_VIEW(view)),
489 multiple_selection_allowed ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_BROWSE );
291edcab
HR
490 g_object_unref(store);
491
a814d755
RN
492 scrolledwindow = gtk_scrolled_window_new ( NULL, NULL );
493 gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
494 gtk_container_add ( GTK_CONTAINER(scrolledwindow), view );
495
496 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), scrolledwindow, TRUE, TRUE, 0 );
497 // Ensure a reasonable number of items are shown, but let the width be automatically sized
498 gtk_widget_set_size_request ( dialog, -1, 400) ;
499
500 gtk_widget_show_all ( dialog );
291edcab 501
93ece96d
RN
502 if ( response_w )
503 gtk_widget_grab_focus ( response_w );
504
291edcab
HR
505 while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
506 {
7767aa02 507 GList *names = NULL;
291edcab 508 GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
7767aa02
QT
509 gtk_tree_selection_selected_foreach(selection, get_selected_foreach_func, &names);
510 if (names)
291edcab 511 {
291edcab 512 gtk_widget_destroy ( dialog );
7767aa02 513 return (names);
291edcab 514 }
7767aa02 515 a_dialog_error_msg(parent, _("Nothing was selected"));
291edcab
HR
516 }
517 gtk_widget_destroy ( dialog );
518 return NULL;
519}
520
e13ab673 521gchar *a_dialog_new_track ( GtkWindow *parent, GHashTable *tracks, gchar *default_name )
50a14534 522{
7760b0cf 523 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Add Track"),
50a14534
EB
524 parent,
525 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
526 GTK_STOCK_CANCEL,
527 GTK_RESPONSE_REJECT,
528 GTK_STOCK_OK,
529 GTK_RESPONSE_ACCEPT,
530 NULL);
7760b0cf 531 GtkWidget *label = gtk_label_new ( _("Track Name:") );
50a14534
EB
532 GtkWidget *entry = gtk_entry_new ();
533
e13ab673
RN
534 if (default_name)
535 gtk_entry_set_text ( GTK_ENTRY(entry), default_name );
536
50a14534
EB
537 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), label, FALSE, FALSE, 0);
538 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry, FALSE, FALSE, 0);
539
540 g_signal_connect_swapped ( entry, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
541
542 gtk_widget_show ( label );
543 gtk_widget_show ( entry );
544
79d73727
RN
545 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
546
50a14534
EB
547 while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
548 {
549 const gchar *constname = gtk_entry_get_text ( GTK_ENTRY(entry) );
550 if ( *constname == '\0' )
7760b0cf 551 a_dialog_info_msg ( parent, _("Please enter a name for the track.") );
50a14534
EB
552 else {
553 gchar *name = g_strdup ( constname );
50a14534 554
d91e5f2b 555 if ( g_hash_table_lookup( tracks, name ) && !a_dialog_yes_or_no ( parent, _("The track \"%s\" exists, do you want to overwrite it?"), gtk_entry_get_text ( GTK_ENTRY(entry) ) ) )
50a14534
EB
556 {
557 g_free ( name );
558 }
559 else
560 {
561 gtk_widget_destroy ( dialog );
562 return name;
563 }
564 }
565 }
566 gtk_widget_destroy ( dialog );
567 return NULL;
568}
569
570/* creates a vbox full of labels */
571GtkWidget *a_dialog_create_label_vbox ( gchar **texts, int label_count )
572{
573 GtkWidget *vbox, *label;
574 int i;
575 vbox = gtk_vbox_new( TRUE, 3 );
576
577 for ( i = 0; i < label_count; i++ )
578 {
579 label = gtk_label_new(NULL);
4c77d5e0 580 gtk_label_set_markup ( GTK_LABEL(label), _(texts[i]) );
50a14534
EB
581 gtk_box_pack_start ( GTK_BOX(vbox), label, FALSE, TRUE, 5 );
582 }
583 return vbox;
584}
585
d91e5f2b 586gboolean a_dialog_yes_or_no ( GtkWindow *parent, const gchar *message, const gchar *extra )
50a14534
EB
587{
588 GtkWidget *dia;
589 dia = gtk_message_dialog_new ( parent,
590 GTK_DIALOG_DESTROY_WITH_PARENT,
591 GTK_MESSAGE_QUESTION,
592 GTK_BUTTONS_YES_NO,
593 message, extra );
594
595 if ( gtk_dialog_run ( GTK_DIALOG(dia) ) == GTK_RESPONSE_YES )
596 {
597 gtk_widget_destroy ( dia );
598 return TRUE;
599 }
600 else
601 {
602 gtk_widget_destroy ( dia );
603 return FALSE;
604 }
605}
606
607static void zoom_spin_changed ( GtkSpinButton *spin, GtkWidget *pass_along[3] )
608{
609 if ( gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(pass_along[2]) ) )
610 gtk_spin_button_set_value (
611 GTK_SPIN_BUTTON(pass_along[GTK_WIDGET(spin) == pass_along[0] ? 1 : 0]),
612 gtk_spin_button_get_value ( spin ) );
613}
614
615gboolean a_dialog_custom_zoom ( GtkWindow *parent, gdouble *xmpp, gdouble *ympp )
616{
7760b0cf 617 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Zoom Factors..."),
50a14534
EB
618 parent,
619 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
620 GTK_STOCK_CANCEL,
621 GTK_RESPONSE_REJECT,
622 GTK_STOCK_OK,
623 GTK_RESPONSE_ACCEPT,
624 NULL);
625 GtkWidget *table, *label, *xlabel, *xspin, *ylabel, *yspin, *samecheck;
626 GtkWidget *pass_along[3];
627
628 table = gtk_table_new ( 4, 2, FALSE );
629 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), table, TRUE, TRUE, 0 );
630
da0a736b 631 label = gtk_label_new ( _("Zoom factor (in meters per pixel):") );
7760b0cf
JJ
632 xlabel = gtk_label_new ( _("X (easting): "));
633 ylabel = gtk_label_new ( _("Y (northing): "));
50a14534 634
ac33062d
RN
635 pass_along[0] = xspin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *xmpp, VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM, 1, 5, 0 ), 1, 8 );
636 pass_along[1] = yspin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *ympp, VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM, 1, 5, 0 ), 1, 8 );
50a14534 637
7760b0cf 638 pass_along[2] = samecheck = gtk_check_button_new_with_label ( _("X and Y zoom factors must be equal") );
50a14534
EB
639 /* TODO -- same factor */
640 /* samecheck = gtk_check_button_new_with_label ( "Same x/y zoom factor" ); */
641
642 if ( *xmpp == *ympp )
643 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(samecheck), TRUE );
644
645 gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 2, 0, 1 );
646 gtk_table_attach_defaults ( GTK_TABLE(table), xlabel, 0, 1, 1, 2 );
647 gtk_table_attach_defaults ( GTK_TABLE(table), xspin, 1, 2, 1, 2 );
648 gtk_table_attach_defaults ( GTK_TABLE(table), ylabel, 0, 1, 2, 3 );
649 gtk_table_attach_defaults ( GTK_TABLE(table), yspin, 1, 2, 2, 3 );
650 gtk_table_attach_defaults ( GTK_TABLE(table), samecheck, 0, 2, 3, 4 );
651
652 gtk_widget_show_all ( table );
653
654 g_signal_connect ( G_OBJECT(xspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along );
655 g_signal_connect ( G_OBJECT(yspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along );
656
79d73727
RN
657 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
658
50a14534
EB
659 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
660 {
661 *xmpp = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(xspin) );
662 *ympp = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(yspin) );
663 gtk_widget_destroy ( dialog );
664 return TRUE;
665 }
666 gtk_widget_destroy ( dialog );
667 return FALSE;
668}
111fa174
AF
669
670static void split_spin_focused ( GtkSpinButton *spin, GtkWidget *pass_along[1] )
671{
672 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(pass_along[0]), 1);
673}
674
675gboolean a_dialog_time_threshold ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint *thr )
676{
677 GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text,
678 parent,
679 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
680 GTK_STOCK_CANCEL,
681 GTK_RESPONSE_REJECT,
682 GTK_STOCK_OK,
683 GTK_RESPONSE_ACCEPT,
684 NULL);
685 GtkWidget *table, *t1, *t2, *t3, *t4, *spin, *label;
686 GtkWidget *pass_along[1];
687
688 table = gtk_table_new ( 4, 2, FALSE );
689 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), table, TRUE, TRUE, 0 );
690
691 label = gtk_label_new (label_text);
692
7760b0cf
JJ
693 t1 = gtk_radio_button_new_with_label ( NULL, _("1 min") );
694 t2 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t1), _("1 hour") );
695 t3 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t2), _("1 day") );
696 t4 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t3), _("Custom (in minutes):") );
111fa174
AF
697
698 pass_along[0] = t4;
699
ac33062d 700 spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *thr, 0, 65536, 1, 5, 0 ), 1, 0 );
111fa174
AF
701
702 gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 2, 0, 1 );
703 gtk_table_attach_defaults ( GTK_TABLE(table), t1, 0, 1, 1, 2 );
704 gtk_table_attach_defaults ( GTK_TABLE(table), t2, 0, 1, 2, 3 );
705 gtk_table_attach_defaults ( GTK_TABLE(table), t3, 0, 1, 3, 4 );
706 gtk_table_attach_defaults ( GTK_TABLE(table), t4, 0, 1, 4, 5 );
707 gtk_table_attach_defaults ( GTK_TABLE(table), spin, 1, 2, 4, 5 );
708
709 gtk_widget_show_all ( table );
710
711 g_signal_connect ( G_OBJECT(spin), "grab-focus", G_CALLBACK(split_spin_focused), pass_along );
712
79d73727
RN
713 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
714
111fa174
AF
715 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
716 {
717 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t1))) {
718 *thr = 1;
719 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t2))) {
720 *thr = 60;
721 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t3))) {
722 *thr = 60 * 24;
723 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t4))) {
724 *thr = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) );
725 }
726 gtk_widget_destroy ( dialog );
727 return TRUE;
728 }
729 gtk_widget_destroy ( dialog );
730 return FALSE;
731}
d0a5f320 732
16c7d8fc
RN
733/**
734 * Dialog to return a positive number via a spinbox within the supplied limits
735 * A return value of zero indicates the dialog was cancelled
736 */
737guint a_dialog_get_positive_number ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint default_num, guint min, guint max, guint step )
738{
739 GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text,
740 parent,
741 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
742 GTK_STOCK_CANCEL,
743 GTK_RESPONSE_REJECT,
744 GTK_STOCK_OK,
745 GTK_RESPONSE_ACCEPT,
746 NULL);
747 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
748 GtkWidget *response_w = NULL;
749#if GTK_CHECK_VERSION (2, 20, 0)
750 response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
751#endif
752
753 GtkWidget *table, *spin, *label;
754 guint result = default_num;
755
756 table = gtk_table_new ( 2, 1, FALSE );
757 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), table, TRUE, TRUE, 0 );
758
759 label = gtk_label_new (label_text);
760 spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( default_num, min, max, step, 5, 0 ), 1, 0 );
761
762 gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 1, 0, 1 );
763 gtk_table_attach_defaults ( GTK_TABLE(table), spin, 0, 1, 1, 2 );
764
765 if ( response_w )
766 gtk_widget_grab_focus ( response_w );
767
768 gtk_widget_show_all ( table );
769
770 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
771 {
772 result = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) );
773 gtk_widget_destroy ( dialog );
774 return result;
775 }
776
777 // Dialog cancelled
778 gtk_widget_destroy ( dialog );
779 return 0;
780}
781
3530c91e
GB
782static void about_url_hook (GtkAboutDialog *about,
783 const gchar *link,
784 gpointer data)
85beadba 785{
3530c91e
GB
786 open_url (GTK_WINDOW(about), link);
787}
788
789static void about_email_hook (GtkAboutDialog *about,
790 const gchar *email,
791 gpointer data)
792{
793 new_email (GTK_WINDOW(about), email);
85beadba 794}
d0a5f320
AF
795
796void a_dialog_about ( GtkWindow *parent )
797{
85beadba
GB
798 const gchar *program_name = PACKAGE_NAME;
799 const gchar *version = VIKING_VERSION;
800 const gchar *website = VIKING_URL;
8192ebe3 801 const gchar *copyright = "2003-2008, Evan Battaglia\n2008-2010, Viking's contributors";
85beadba
GB
802 const gchar *comments = _("GPS Data and Topo Analyzer, Explorer, and Manager.");
803 const gchar *license = _("This program is free software; you can redistribute it and/or modify "
d0a5f320
AF
804 "it under the terms of the GNU General Public License as published by "
805 "the Free Software Foundation; either version 2 of the License, or "
806 "(at your option) any later version."
807 "\n\n"
808 "This program is distributed in the hope that it will be useful, "
809 "but WITHOUT ANY WARRANTY; without even the implied warranty of "
810 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
811 "GNU General Public License for more details."
812 "\n\n"
813 "You should have received a copy of the GNU General Public License "
814 "along with this program; if not, write to the Free Software "
85beadba
GB
815 "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA");
816
3530c91e
GB
817 gtk_about_dialog_set_url_hook (about_url_hook, NULL, NULL);
818 gtk_about_dialog_set_email_hook (about_email_hook, NULL, NULL);
85beadba
GB
819 gtk_show_about_dialog (parent,
820 /* TODO do not set program-name and correctly set info for g_get_application_name */
821 "program-name", program_name,
822 "version", version,
823 "website", website,
824 "comments", comments,
825 "copyright", copyright,
826 "license", license,
827 "wrap-license", TRUE,
828 /* logo automatically retrieved via gtk_window_get_default_icon_list */
829 "authors", AUTHORS,
eb6a42c9 830 "documenters", DOCUMENTERS,
551e7a38 831 "translator-credits", _("Translation is coordinated on http://launchpad.net/viking"),
85beadba 832 NULL);
d0a5f320 833}
7114e879
QT
834
835gboolean a_dialog_map_n_zoom(GtkWindow *parent, gchar *mapnames[], gint default_map, gchar *zoom_list[], gint default_zoom, gint *selected_map, gint *selected_zoom)
836{
837 gchar **s;
838
7760b0cf 839 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 );
6e450795
RN
840 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
841 GtkWidget *response_w = NULL;
842#if GTK_CHECK_VERSION (2, 20, 0)
843 response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
844#endif
7760b0cf 845 GtkWidget *map_label = gtk_label_new(_("Map type:"));
8ece78c0 846 GtkComboBox *map_combo = GTK_COMBO_BOX(gtk_combo_box_new_text());
7114e879
QT
847 for (s = mapnames; *s; s++)
848 gtk_combo_box_append_text(map_combo, *s);
849 gtk_combo_box_set_active (map_combo, default_map);
7760b0cf 850 GtkWidget *zoom_label = gtk_label_new(_("Zoom level:"));
8ece78c0 851 GtkComboBox *zoom_combo = GTK_COMBO_BOX(gtk_combo_box_new_text());
7114e879
QT
852 for (s = zoom_list; *s; s++)
853 gtk_combo_box_append_text(zoom_combo, *s);
854 gtk_combo_box_set_active (zoom_combo, default_zoom);
855
856 GtkTable *box = GTK_TABLE(gtk_table_new(2, 2, FALSE));
857 gtk_table_attach_defaults(box, GTK_WIDGET(map_label), 0, 1, 0, 1);
858 gtk_table_attach_defaults(box, GTK_WIDGET(map_combo), 1, 2, 0, 1);
859 gtk_table_attach_defaults(box, GTK_WIDGET(zoom_label), 0, 1, 1, 2);
860 gtk_table_attach_defaults(box, GTK_WIDGET(zoom_combo), 1, 2, 1, 2);
861
862 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), GTK_WIDGET(box), FALSE, FALSE, 5 );
863
6e450795
RN
864 if ( response_w )
865 gtk_widget_grab_focus ( response_w );
866
7114e879
QT
867 gtk_widget_show_all ( dialog );
868 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) != GTK_RESPONSE_ACCEPT ) {
869 gtk_widget_destroy(dialog);
870 return FALSE;
871 }
872
873 *selected_map = gtk_combo_box_get_active(map_combo);
874 *selected_zoom = gtk_combo_box_get_active(zoom_combo);
875
876 gtk_widget_destroy(dialog);
877 return TRUE;
878}
53ac8302
GB
879
880/**
881 * Display a dialog presenting the license of a map.
882 * Allow to read the license by launching a web browser.
883 */
4033fba0 884void a_dialog_license ( GtkWindow *parent, const gchar *map, const gchar *license, const gchar *url)
53ac8302
GB
885{
886 GtkWidget *dialog = gtk_message_dialog_new (parent,
887 GTK_DIALOG_DESTROY_WITH_PARENT,
888 GTK_MESSAGE_INFO,
889 GTK_BUTTONS_OK,
890 _("The map data is licensed: %s."),
891 license);
892 gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
893 _("The data provided by '<b>%s</b>' are licensed under the following license: <b>%s</b>.\n"
894 "Please, read the license before continuing."),
895 map, license);
896#define RESPONSE_OPEN_LICENSE 600
897 if (url != NULL) {
898 gtk_dialog_add_button (GTK_DIALOG (dialog), _("Open license"), RESPONSE_OPEN_LICENSE);
899 }
900 gint response;
901 do {
902 response = gtk_dialog_run (GTK_DIALOG (dialog));
903 if (response == RESPONSE_OPEN_LICENSE) {
904 open_url (parent, url);
905 }
906 } while (response != GTK_RESPONSE_DELETE_EVENT && response != GTK_RESPONSE_OK);
907 gtk_widget_destroy (dialog);
908}