2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
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>
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.
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.
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
29 #include "thumbnails.h"
30 #include "garminsymbols.h"
31 #include "degrees_converters.h"
33 #include "documenters.h"
36 #include "geotag_exif.h"
38 #include <glib/gi18n.h>
45 void a_dialog_msg ( GtkWindow *parent, gint type, const gchar *info, const gchar *extra )
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 );
52 gboolean a_dialog_goto_latlon ( GtkWindow *parent, struct LatLon *ll, const struct LatLon *old )
54 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to Lat/Lon"),
56 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
62 GtkWidget *latlabel, *lonlabel;
64 gchar *tmp_lat, *tmp_lon;
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 );
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 );
78 gtk_widget_show ( latlabel );
79 gtk_widget_show ( lonlabel );
80 gtk_widget_show ( lat );
81 gtk_widget_show ( lon );
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);
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);
92 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
94 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
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 );
102 gtk_widget_destroy ( dialog );
106 gboolean a_dialog_goto_utm ( GtkWindow *parent, struct UTM *utm, const struct UTM *old )
108 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to UTM"),
110 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
116 GtkWidget *norlabel, *easlabel, *nor, *eas;
117 GtkWidget *zonehbox, *zonespin, *letterentry;
118 gchar *tmp_eas, *tmp_nor;
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 );
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 );
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 );
146 gtk_widget_show ( norlabel );
147 gtk_widget_show ( easlabel );
148 gtk_widget_show ( nor );
149 gtk_widget_show ( eas );
151 gtk_widget_show_all ( zonehbox );
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);
159 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
161 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
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) );
169 utm->letter = toupper(*letter);
170 gtk_widget_destroy ( dialog );
174 gtk_widget_destroy ( dialog );
178 void a_dialog_response_accept ( GtkDialog *dialog )
180 gtk_dialog_response ( dialog, GTK_RESPONSE_ACCEPT );
183 static void symbol_entry_changed_cb(GtkWidget *combo, GtkListStore *store)
188 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter))
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);
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
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 )
204 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Waypoint Properties"),
206 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
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;
221 gchar *lat, *lon, *alt;
223 vik_coord_to_latlon ( &(wp->coord), &ll );
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 );
232 case VIK_UNITS_HEIGHT_FEET:
233 alt = g_strdup_printf ( "%f", VIK_METERS_TO_FEET(wp->altitude) );
236 alt = g_strdup_printf ( "%f", wp->altitude );
237 g_critical("Houston, we've had a problem. height=%d", height_units);
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 ();
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);
251 latlabel = gtk_label_new (_("Latitude:"));
252 latentry = gtk_entry_new ();
253 gtk_entry_set_text ( GTK_ENTRY(latentry), lat );
256 lonlabel = gtk_label_new (_("Longitude:"));
257 lonentry = gtk_entry_new ();
258 gtk_entry_set_text ( GTK_ENTRY(lonentry), lon );
261 altlabel = gtk_label_new (_("Altitude:"));
262 altentry = gtk_entry_new ();
263 gtk_entry_set_text ( GTK_ENTRY(altentry), alt );
266 commentlabel = gtk_label_new (_("Comment:"));
267 commententry = gtk_entry_new ();
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));
272 gtk_entry_set_text(GTK_ENTRY(commententry), cmt);
274 descriptionlabel = gtk_label_new (_("Description:"));
275 descriptionentry = gtk_entry_new ();
277 imagelabel = gtk_label_new (_("Image:"));
278 imageentry = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN, VF_FILTER_IMAGE);
282 symbollabel = gtk_label_new (_("Symbol:"));
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);
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);
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);
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);
302 if ( !is_new && wp->symbol ) {
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)) {
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
318 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(symbolentry), &iter);
322 if ( !is_new && wp->comment )
323 gtk_entry_set_text ( GTK_ENTRY(commententry), wp->comment );
325 if ( !is_new && wp->description )
326 gtk_entry_set_text ( GTK_ENTRY(descriptionentry), wp->description );
328 if ( !is_new && wp->image ) {
329 vik_file_entry_set_filename ( VIK_FILE_ENTRY(imageentry), wp->image );
331 // Geotag Info [readonly]
332 hasGeotagCB = gtk_check_button_new_with_label ( _("Has Geotag") );
333 gtk_widget_set_sensitive ( hasGeotagCB, FALSE );
335 gchar *ignore = a_geotag_get_exif_date_from_file ( wp->image, &hasGeotag );
337 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(hasGeotagCB), hasGeotag );
339 consistentGeotagCB = gtk_check_button_new_with_label ( _("Consistent Position") );
340 gtk_widget_set_sensitive ( consistentGeotagCB, FALSE );
342 struct LatLon ll = a_geotag_get_position ( wp->image );
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) );
349 if ( !is_new && wp->has_timestamp ) {
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 );
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);
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);
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);
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);
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);
382 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
384 gtk_widget_show_all ( gtk_dialog_get_content_area(GTK_DIALOG(dialog)) );
387 // Shift left<->right to try not to obscure the waypoint.
388 trw_layer_dialog_shift ( vtl, GTK_WINDOW(dialog), &(wp->coord), FALSE );
391 while ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
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.") );
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) ) );
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) ) );
408 case VIK_UNITS_HEIGHT_FEET:
409 wp->altitude = VIK_FEET_TO_METERS(atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ));
412 wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) );
413 g_critical("Houston, we've had a problem. height=%d", height_units);
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 );
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 );
430 gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 );
431 vik_waypoint_set_symbol ( wp, sym );
435 gtk_widget_destroy ( dialog );
440 // See if name has been changed
441 if ( g_strcmp0 (default_name, entered_name ) )
448 gtk_widget_destroy ( dialog );
452 static void get_selected_foreach_func(GtkTreeModel *model,
459 gtk_tree_model_get (model, iter, 0, &name, -1);
460 *list = g_list_prepend(*list, name);
463 GList *a_dialog_select_from_list ( GtkWindow *parent, GList *names, gboolean multiple_selection_allowed, const gchar *title, const gchar *msg )
466 GtkCellRenderer *renderer;
469 GtkWidget *dialog = gtk_dialog_new_with_buttons (title,
471 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
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 );
484 GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING);
486 GtkWidget *scrolledwindow;
488 GList *runner = names;
491 gtk_list_store_append(store, &iter);
492 gtk_list_store_set(store, &iter, 0, runner->data, -1);
493 runner = g_list_next(runner);
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);
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);
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 );
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) ;
518 gtk_widget_show_all ( dialog );
521 gtk_widget_grab_focus ( response_w );
523 while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
525 GList *names_selected = 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_selected);
530 gtk_widget_destroy ( dialog );
531 return names_selected;
533 a_dialog_error_msg(parent, _("Nothing was selected"));
535 gtk_widget_destroy ( dialog );
539 gchar *a_dialog_new_track ( GtkWindow *parent, gchar *default_name, gboolean is_route )
541 GtkWidget *dialog = gtk_dialog_new_with_buttons ( is_route ? _("Add Route") : _("Add Track"),
543 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
549 GtkWidget *label = gtk_label_new ( is_route ? _("Route Name:") : _("Track Name:") );
550 GtkWidget *entry = gtk_entry_new ();
553 gtk_entry_set_text ( GTK_ENTRY(entry), default_name );
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);
558 g_signal_connect_swapped ( entry, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
560 gtk_widget_show ( label );
561 gtk_widget_show ( entry );
563 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
565 while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
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.") );
571 gchar *name = g_strdup ( constname );
572 gtk_widget_destroy ( dialog );
576 gtk_widget_destroy ( dialog );
580 static guint today_year = 0;
581 static guint today_month = 0;
582 static guint today_day = 0;
584 static void today_clicked (GtkWidget *cal)
586 gtk_calendar_select_month ( GTK_CALENDAR(cal), today_month, today_year );
587 gtk_calendar_select_day ( GTK_CALENDAR(cal), today_day );
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
597 gchar *a_dialog_get_date ( GtkWindow *parent, const gchar *title )
599 GtkWidget *dialog = gtk_dialog_new_with_buttons ( title,
601 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
607 GtkWidget *cal = gtk_calendar_new ();
608 GtkWidget *today = gtk_button_new_with_label ( _("Today") );
610 static guint year = 0;
611 static guint month = 0;
612 static guint day = 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 );
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 );
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);
630 g_signal_connect_swapped ( G_OBJECT(today), "clicked", G_CALLBACK(today_clicked), cal );
632 gtk_widget_show_all ( dialog );
634 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
636 gchar *date_str = NULL;
637 if ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
639 gtk_calendar_get_date ( GTK_CALENDAR(cal), &year, &month, &day );
640 date_str = g_strdup_printf ( "%d-%02d-%02d", year, month+1, day );
642 gtk_widget_destroy ( dialog );
646 /* creates a vbox full of labels */
647 GtkWidget *a_dialog_create_label_vbox ( gchar **texts, int label_count, gint spacing, gint padding )
649 GtkWidget *vbox, *label;
651 vbox = gtk_vbox_new( TRUE, spacing );
653 for ( i = 0; i < label_count; i++ )
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 );
662 gboolean a_dialog_yes_or_no ( GtkWindow *parent, const gchar *message, const gchar *extra )
665 dia = gtk_message_dialog_new ( parent,
666 GTK_DIALOG_DESTROY_WITH_PARENT,
667 GTK_MESSAGE_QUESTION,
671 if ( gtk_dialog_run ( GTK_DIALOG(dia) ) == GTK_RESPONSE_YES )
673 gtk_widget_destroy ( dia );
678 gtk_widget_destroy ( dia );
683 static void zoom_spin_changed ( GtkSpinButton *spin, GtkWidget *pass_along[3] )
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 ) );
691 gboolean a_dialog_custom_zoom ( GtkWindow *parent, gdouble *xmpp, gdouble *ympp )
693 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Zoom Factors..."),
695 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
701 GtkWidget *table, *label, *xlabel, *xspin, *ylabel, *yspin, *samecheck;
702 GtkWidget *pass_along[3];
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 );
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): "));
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 );
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" ); */
718 if ( *xmpp == *ympp )
719 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(samecheck), TRUE );
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 );
728 gtk_widget_show_all ( table );
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 );
733 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
735 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
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 );
742 gtk_widget_destroy ( dialog );
746 static void split_spin_focused ( GtkSpinButton *spin, GtkWidget *pass_along[1] )
748 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(pass_along[0]), 1);
751 gboolean a_dialog_time_threshold ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint *thr )
753 GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text,
755 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
761 GtkWidget *table, *t1, *t2, *t3, *t4, *spin, *label;
762 GtkWidget *pass_along[1];
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 );
767 label = gtk_label_new (label_text);
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):") );
776 spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *thr, 0, 65536, 1, 5, 0 ), 1, 0 );
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 );
785 gtk_widget_show_all ( table );
787 g_signal_connect ( G_OBJECT(spin), "grab-focus", G_CALLBACK(split_spin_focused), pass_along );
789 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
791 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
793 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t1))) {
795 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t2))) {
797 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t3))) {
799 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t4))) {
800 *thr = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) );
802 gtk_widget_destroy ( dialog );
805 gtk_widget_destroy ( dialog );
810 * a_dialog_get_positive_number:
812 * Dialog to return a positive number via a spinbox within the supplied limits
814 * Returns: A value of zero indicates the dialog was cancelled
816 guint a_dialog_get_positive_number ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint default_num, guint min, guint max, guint step )
818 GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text,
820 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
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 );
832 GtkWidget *table, *spin, *label;
833 guint result = default_num;
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 );
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 );
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 );
845 gtk_widget_grab_focus ( response_w );
847 gtk_widget_show_all ( table );
849 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
851 result = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) );
852 gtk_widget_destroy ( dialog );
857 gtk_widget_destroy ( dialog );
861 #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 24)
862 static void about_url_hook (GtkAboutDialog *about,
866 open_url (GTK_WINDOW(about), link);
869 static void about_email_hook (GtkAboutDialog *about,
873 new_email (GTK_WINDOW(about), email);
877 void a_dialog_about ( GtkWindow *parent )
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."
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."
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");
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:",
908 // Potentially optional libs (but probably couldn't build without them)
918 // Actually optional libs
934 #ifdef HAVE_LIBSQLITE3
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);
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,
951 "comments", comments,
952 "copyright", copyright,
954 "wrap-license", TRUE,
955 /* logo automatically retrieved via gtk_window_get_default_icon_list */
957 "documenters", DOCUMENTERS,
958 "translator-credits", _("Translation is coordinated on http://launchpad.net/viking"),
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)
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 );
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);
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);
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);
992 gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), GTK_WIDGET(box), FALSE, FALSE, 5 );
995 gtk_widget_grab_focus ( response_w );
997 gtk_widget_show_all ( dialog );
998 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) != GTK_RESPONSE_ACCEPT ) {
999 gtk_widget_destroy(dialog);
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));
1006 gtk_widget_destroy(dialog);
1011 * Display a dialog presenting the license of a map.
1012 * Allow to read the license by launching a web browser.
1014 void a_dialog_license ( GtkWindow *parent, const gchar *map, const gchar *license, const gchar *url)
1016 GtkWidget *dialog = gtk_message_dialog_new (parent,
1017 GTK_DIALOG_DESTROY_WITH_PARENT,
1020 _("The map data is licensed: %s."),
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>."),
1025 #define RESPONSE_OPEN_LICENSE 600
1027 gtk_dialog_add_button (GTK_DIALOG (dialog), _("Open license"), RESPONSE_OPEN_LICENSE);
1031 response = gtk_dialog_run (GTK_DIALOG (dialog));
1032 if (response == RESPONSE_OPEN_LICENSE) {
1033 open_url (parent, url);
1035 } while (response != GTK_RESPONSE_DELETE_EVENT && response != GTK_RESPONSE_OK);
1036 gtk_widget_destroy (dialog);