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