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-2013, 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"
37 #include <glib/gi18n.h>
44 void a_dialog_msg ( GtkWindow *parent, gint type, const gchar *info, const gchar *extra )
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 );
51 gboolean a_dialog_goto_latlon ( GtkWindow *parent, struct LatLon *ll, const struct LatLon *old )
53 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to Lat/Lon"),
55 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
61 GtkWidget *latlabel, *lonlabel;
63 gchar *tmp_lat, *tmp_lon;
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 );
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 );
77 gtk_widget_show ( latlabel );
78 gtk_widget_show ( lonlabel );
79 gtk_widget_show ( lat );
80 gtk_widget_show ( lon );
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);
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);
91 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
93 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
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 );
101 gtk_widget_destroy ( dialog );
105 gboolean a_dialog_goto_utm ( GtkWindow *parent, struct UTM *utm, const struct UTM *old )
107 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to UTM"),
109 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
115 GtkWidget *norlabel, *easlabel, *nor, *eas;
116 GtkWidget *zonehbox, *zonespin, *letterentry;
117 gchar *tmp_eas, *tmp_nor;
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 );
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 );
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 );
145 gtk_widget_show ( norlabel );
146 gtk_widget_show ( easlabel );
147 gtk_widget_show ( nor );
148 gtk_widget_show ( eas );
150 gtk_widget_show_all ( zonehbox );
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);
158 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
160 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
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) );
168 utm->letter = toupper(*letter);
169 gtk_widget_destroy ( dialog );
173 gtk_widget_destroy ( dialog );
177 void a_dialog_response_accept ( GtkDialog *dialog )
179 gtk_dialog_response ( dialog, GTK_RESPONSE_ACCEPT );
182 static void symbol_entry_changed_cb(GtkWidget *combo, GtkListStore *store)
187 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter))
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);
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
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 )
203 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Waypoint Properties"),
205 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
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
218 gchar *lat, *lon, *alt;
220 vik_coord_to_latlon ( &(wp->coord), &ll );
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 );
229 case VIK_UNITS_HEIGHT_FEET:
230 alt = g_strdup_printf ( "%f", VIK_METERS_TO_FEET(wp->altitude) );
233 alt = g_strdup_printf ( "%f", wp->altitude );
234 g_critical("Houston, we've had a problem. height=%d", height_units);
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 ();
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);
248 latlabel = gtk_label_new (_("Latitude:"));
249 latentry = gtk_entry_new ();
250 gtk_entry_set_text ( GTK_ENTRY(latentry), lat );
253 lonlabel = gtk_label_new (_("Longitude:"));
254 lonentry = gtk_entry_new ();
255 gtk_entry_set_text ( GTK_ENTRY(lonentry), lon );
258 altlabel = gtk_label_new (_("Altitude:"));
259 altentry = gtk_entry_new ();
260 gtk_entry_set_text ( GTK_ENTRY(altentry), alt );
263 commentlabel = gtk_label_new (_("Comment:"));
264 commententry = gtk_entry_new ();
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));
269 gtk_entry_set_text(GTK_ENTRY(commententry), cmt);
271 descriptionlabel = gtk_label_new (_("Description:"));
272 descriptionentry = gtk_entry_new ();
274 imagelabel = gtk_label_new (_("Image:"));
275 imageentry = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN);
279 symbollabel = gtk_label_new (_("Symbol:"));
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);
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);
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);
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);
299 if ( !is_new && wp->symbol ) {
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)) {
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
315 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(symbolentry), &iter);
319 if ( !is_new && wp->comment )
320 gtk_entry_set_text ( GTK_ENTRY(commententry), wp->comment );
322 if ( !is_new && wp->description )
323 gtk_entry_set_text ( GTK_ENTRY(descriptionentry), wp->description );
325 if ( !is_new && wp->image )
326 vik_file_entry_set_filename ( VIK_FILE_ENTRY(imageentry), wp->image );
328 if ( !is_new && wp->has_timestamp ) {
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 );
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);
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);
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);
355 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
357 gtk_widget_show_all ( gtk_dialog_get_content_area(GTK_DIALOG(dialog)) );
360 // Shift left<->right to try not to obscure the waypoint.
361 trw_layer_dialog_shift ( vtl, GTK_WINDOW(dialog), &(wp->coord), FALSE );
364 while ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
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.") );
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) ) );
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) ) );
381 case VIK_UNITS_HEIGHT_FEET:
382 wp->altitude = VIK_FEET_TO_METERS(atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ));
385 wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) );
386 g_critical("Houston, we've had a problem. height=%d", height_units);
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 );
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 );
403 gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 );
404 vik_waypoint_set_symbol ( wp, sym );
408 gtk_widget_destroy ( dialog );
413 // See if name has been changed
414 if ( g_strcmp0 (default_name, entered_name ) )
421 gtk_widget_destroy ( dialog );
425 static void get_selected_foreach_func(GtkTreeModel *model,
432 gtk_tree_model_get (model, iter, 0, &name, -1);
433 *list = g_list_prepend(*list, name);
436 GList *a_dialog_select_from_list ( GtkWindow *parent, GList *names, gboolean multiple_selection_allowed, const gchar *title, const gchar *msg )
439 GtkCellRenderer *renderer;
442 GtkWidget *dialog = gtk_dialog_new_with_buttons (title,
444 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
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 );
457 GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING);
459 GtkWidget *scrolledwindow;
461 GList *runner = names;
464 gtk_list_store_append(store, &iter);
465 gtk_list_store_set(store, &iter, 0, runner->data, -1);
466 runner = g_list_next(runner);
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);
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);
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 );
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) ;
491 gtk_widget_show_all ( dialog );
494 gtk_widget_grab_focus ( response_w );
496 while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
499 GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
500 gtk_tree_selection_selected_foreach(selection, get_selected_foreach_func, &names);
503 gtk_widget_destroy ( dialog );
506 a_dialog_error_msg(parent, _("Nothing was selected"));
508 gtk_widget_destroy ( dialog );
512 gchar *a_dialog_new_track ( GtkWindow *parent, gchar *default_name, gboolean is_route )
514 GtkWidget *dialog = gtk_dialog_new_with_buttons ( is_route ? _("Add Route") : _("Add Track"),
516 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
522 GtkWidget *label = gtk_label_new ( is_route ? _("Route Name:") : _("Track Name:") );
523 GtkWidget *entry = gtk_entry_new ();
526 gtk_entry_set_text ( GTK_ENTRY(entry), default_name );
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);
531 g_signal_connect_swapped ( entry, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
533 gtk_widget_show ( label );
534 gtk_widget_show ( entry );
536 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
538 while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
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.") );
544 gchar *name = g_strdup ( constname );
545 gtk_widget_destroy ( dialog );
549 gtk_widget_destroy ( dialog );
553 /* creates a vbox full of labels */
554 GtkWidget *a_dialog_create_label_vbox ( gchar **texts, int label_count, gint spacing, gint padding )
556 GtkWidget *vbox, *label;
558 vbox = gtk_vbox_new( TRUE, spacing );
560 for ( i = 0; i < label_count; i++ )
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 );
569 gboolean a_dialog_yes_or_no ( GtkWindow *parent, const gchar *message, const gchar *extra )
572 dia = gtk_message_dialog_new ( parent,
573 GTK_DIALOG_DESTROY_WITH_PARENT,
574 GTK_MESSAGE_QUESTION,
578 if ( gtk_dialog_run ( GTK_DIALOG(dia) ) == GTK_RESPONSE_YES )
580 gtk_widget_destroy ( dia );
585 gtk_widget_destroy ( dia );
590 static void zoom_spin_changed ( GtkSpinButton *spin, GtkWidget *pass_along[3] )
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 ) );
598 gboolean a_dialog_custom_zoom ( GtkWindow *parent, gdouble *xmpp, gdouble *ympp )
600 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Zoom Factors..."),
602 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
608 GtkWidget *table, *label, *xlabel, *xspin, *ylabel, *yspin, *samecheck;
609 GtkWidget *pass_along[3];
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 );
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): "));
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 );
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" ); */
625 if ( *xmpp == *ympp )
626 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(samecheck), TRUE );
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 );
635 gtk_widget_show_all ( table );
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 );
640 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
642 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
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 );
649 gtk_widget_destroy ( dialog );
653 static void split_spin_focused ( GtkSpinButton *spin, GtkWidget *pass_along[1] )
655 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(pass_along[0]), 1);
658 gboolean a_dialog_time_threshold ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint *thr )
660 GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text,
662 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
668 GtkWidget *table, *t1, *t2, *t3, *t4, *spin, *label;
669 GtkWidget *pass_along[1];
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 );
674 label = gtk_label_new (label_text);
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):") );
683 spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *thr, 0, 65536, 1, 5, 0 ), 1, 0 );
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 );
692 gtk_widget_show_all ( table );
694 g_signal_connect ( G_OBJECT(spin), "grab-focus", G_CALLBACK(split_spin_focused), pass_along );
696 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
698 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
700 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t1))) {
702 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t2))) {
704 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t3))) {
706 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t4))) {
707 *thr = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) );
709 gtk_widget_destroy ( dialog );
712 gtk_widget_destroy ( dialog );
717 * a_dialog_get_positive_number:
719 * Dialog to return a positive number via a spinbox within the supplied limits
721 * Returns: A value of zero indicates the dialog was cancelled
723 guint a_dialog_get_positive_number ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint default_num, guint min, guint max, guint step )
725 GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text,
727 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
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 );
739 GtkWidget *table, *spin, *label;
740 guint result = default_num;
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 );
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 );
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 );
752 gtk_widget_grab_focus ( response_w );
754 gtk_widget_show_all ( table );
756 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
758 result = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) );
759 gtk_widget_destroy ( dialog );
764 gtk_widget_destroy ( dialog );
768 #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 24)
769 static void about_url_hook (GtkAboutDialog *about,
773 open_url (GTK_WINDOW(about), link);
776 static void about_email_hook (GtkAboutDialog *about,
780 new_email (GTK_WINDOW(about), email);
784 void a_dialog_about ( GtkWindow *parent )
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."
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."
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");
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:",
815 // Potentially optional libs (but probably couldn't build without them)
825 // Actually optional libs
843 // Newer versions of GTK 'just work', calling gtk_show_uri() on the URL or email and opens up the appropriate program
844 // This is the old method:
845 #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 24)
846 gtk_about_dialog_set_url_hook (about_url_hook, NULL, NULL);
847 gtk_about_dialog_set_email_hook (about_email_hook, NULL, NULL);
850 gtk_show_about_dialog (parent,
851 /* TODO do not set program-name and correctly set info for g_get_application_name */
852 "program-name", program_name,
855 "comments", comments,
856 "copyright", copyright,
858 "wrap-license", TRUE,
859 /* logo automatically retrieved via gtk_window_get_default_icon_list */
861 "documenters", DOCUMENTERS,
862 "translator-credits", _("Translation is coordinated on http://launchpad.net/viking"),
867 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 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 );
872 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
873 GtkWidget *response_w = NULL;
874 #if GTK_CHECK_VERSION (2, 20, 0)
875 response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
878 GtkWidget *map_label = gtk_label_new(_("Map type:"));
879 GtkWidget *map_combo = vik_combo_box_text_new();
880 for (s = mapnames; *s; s++)
881 vik_combo_box_text_append (GTK_COMBO_BOX(map_combo), *s);
882 gtk_combo_box_set_active (GTK_COMBO_BOX(map_combo), default_map);
884 GtkWidget *zoom_label = gtk_label_new(_("Zoom level:"));
885 GtkWidget *zoom_combo = vik_combo_box_text_new();
886 for (s = zoom_list; *s; s++)
887 vik_combo_box_text_append (GTK_COMBO_BOX(zoom_combo), *s);
888 gtk_combo_box_set_active (GTK_COMBO_BOX(zoom_combo), default_zoom);
890 GtkTable *box = GTK_TABLE(gtk_table_new(2, 2, FALSE));
891 gtk_table_attach_defaults(box, map_label, 0, 1, 0, 1);
892 gtk_table_attach_defaults(box, map_combo, 1, 2, 0, 1);
893 gtk_table_attach_defaults(box, zoom_label, 0, 1, 1, 2);
894 gtk_table_attach_defaults(box, zoom_combo, 1, 2, 1, 2);
896 gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), GTK_WIDGET(box), FALSE, FALSE, 5 );
899 gtk_widget_grab_focus ( response_w );
901 gtk_widget_show_all ( dialog );
902 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) != GTK_RESPONSE_ACCEPT ) {
903 gtk_widget_destroy(dialog);
907 *selected_map = gtk_combo_box_get_active(GTK_COMBO_BOX(map_combo));
908 *selected_zoom = gtk_combo_box_get_active(GTK_COMBO_BOX(zoom_combo));
910 gtk_widget_destroy(dialog);
915 * Display a dialog presenting the license of a map.
916 * Allow to read the license by launching a web browser.
918 void a_dialog_license ( GtkWindow *parent, const gchar *map, const gchar *license, const gchar *url)
920 GtkWidget *dialog = gtk_message_dialog_new (parent,
921 GTK_DIALOG_DESTROY_WITH_PARENT,
924 _("The map data is licensed: %s."),
926 gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
927 _("The data provided by '<b>%s</b>' are licensed under the following license: <b>%s</b>."),
929 #define RESPONSE_OPEN_LICENSE 600
931 gtk_dialog_add_button (GTK_DIALOG (dialog), _("Open license"), RESPONSE_OPEN_LICENSE);
935 response = gtk_dialog_run (GTK_DIALOG (dialog));
936 if (response == RESPONSE_OPEN_LICENSE) {
937 open_url (parent, url);
939 } while (response != GTK_RESPONSE_DELETE_EVENT && response != GTK_RESPONSE_OK);
940 gtk_widget_destroy (dialog);