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