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-2016, 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 "degrees_converters.h"
31 #include "documenters.h"
34 #include <glib/gi18n.h>
40 void a_dialog_msg ( GtkWindow *parent, gint type, const gchar *info, const gchar *extra )
42 GtkWidget *msgbox = gtk_message_dialog_new ( parent, GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_OK, info, extra );
43 gtk_dialog_run ( GTK_DIALOG(msgbox) );
44 gtk_widget_destroy ( msgbox );
48 * a_dialog_goto_latlon:
50 * @parent: Parent window
51 * @ll: The returned #LatLon location
52 * @old: Initialize the dialog with this #LatLon location
54 * A simple dialog to get a lat/lon location
56 * Returns: FALSE if the dialog was cancelled
58 gboolean a_dialog_goto_latlon ( GtkWindow *parent, struct LatLon *ll, const struct LatLon *old )
60 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to Lat/Lon"),
62 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
69 GtkWidget *latlabel = gtk_label_new (_("Latitude:"));
70 GtkWidget *lat = ui_spin_button_new ( (GtkAdjustment*)gtk_adjustment_new(old->lat,-90,90.0,0.05,0.1,0), 0.1, 6 );
72 GtkWidget *lonlabel = gtk_label_new (_("Longitude:"));
73 GtkWidget *lon = ui_spin_button_new ( (GtkAdjustment*)gtk_adjustment_new(old->lon,-180.0,180.0,0.05,0.1,0), 0.1, 6 );
75 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), latlabel, FALSE, FALSE, 0);
76 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), lat, FALSE, FALSE, 0);
77 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), lonlabel, FALSE, FALSE, 0);
78 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), lon, FALSE, FALSE, 0);
80 // 'ok' when press return on an entry
81 g_signal_connect_swapped (lat, "activate", G_CALLBACK(a_dialog_response_accept), dialog);
82 g_signal_connect_swapped (lon, "activate", G_CALLBACK(a_dialog_response_accept), dialog);
84 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
86 gtk_widget_show_all ( dialog );
88 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
90 ll->lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lat) ) );
91 ll->lon = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lon) ) );
92 gtk_widget_destroy ( dialog );
96 gtk_widget_destroy ( dialog );
100 gboolean a_dialog_goto_utm ( GtkWindow *parent, struct UTM *utm, const struct UTM *old )
102 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to UTM"),
104 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
110 GtkWidget *norlabel, *easlabel, *nor, *eas;
111 GtkWidget *zonehbox, *zonespin, *letterentry;
114 norlabel = gtk_label_new (_("Northing:"));
115 nor = ui_spin_button_new ( (GtkAdjustment*)gtk_adjustment_new(old->northing,0,9999999,1,250,0), 1, 0 );
117 easlabel = gtk_label_new (_("Easting:"));
118 eas = ui_spin_button_new ( (GtkAdjustment*)gtk_adjustment_new(old->easting,0,9999999,1,250,0), 1, 0 );
120 zonehbox = gtk_hbox_new ( FALSE, 0 );
121 gtk_box_pack_start ( GTK_BOX(zonehbox), gtk_label_new ( _("Zone:") ), FALSE, FALSE, 5 );
122 zonespin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( old->zone, 1, 60, 1, 5, 0 ), 1, 0 );
123 gtk_box_pack_start ( GTK_BOX(zonehbox), zonespin, TRUE, TRUE, 5 );
124 gtk_box_pack_start ( GTK_BOX(zonehbox), gtk_label_new ( _("Letter:") ), FALSE, FALSE, 5 );
125 letterentry = gtk_entry_new ();
126 gtk_entry_set_max_length ( GTK_ENTRY(letterentry), 1 );
127 gtk_entry_set_width_chars ( GTK_ENTRY(letterentry), 2 );
128 tmp_letter[0] = old->letter;
129 tmp_letter[1] = '\0';
130 gtk_entry_set_text ( GTK_ENTRY(letterentry), tmp_letter );
131 gtk_box_pack_start ( GTK_BOX(zonehbox), letterentry, FALSE, FALSE, 5 );
133 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), norlabel, FALSE, FALSE, 0);
134 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), nor, FALSE, FALSE, 0);
135 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), easlabel, FALSE, FALSE, 0);
136 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), eas, FALSE, FALSE, 0);
137 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), zonehbox, FALSE, FALSE, 2);
139 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
141 gtk_widget_show_all ( dialog );
143 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
146 utm->northing = atof ( gtk_entry_get_text ( GTK_ENTRY(nor) ) );
147 utm->easting = atof ( gtk_entry_get_text ( GTK_ENTRY(eas) ) );
148 utm->zone = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(zonespin) );
149 letter = gtk_entry_get_text ( GTK_ENTRY(letterentry) );
151 utm->letter = toupper(*letter);
152 gtk_widget_destroy ( dialog );
156 gtk_widget_destroy ( dialog );
160 void a_dialog_response_accept ( GtkDialog *dialog )
162 gtk_dialog_response ( dialog, GTK_RESPONSE_ACCEPT );
165 static void get_selected_foreach_func(GtkTreeModel *model,
172 gtk_tree_model_get (model, iter, 0, &name, -1);
173 *list = g_list_prepend(*list, name);
176 GList *a_dialog_select_from_list ( GtkWindow *parent, GList *names, gboolean multiple_selection_allowed, const gchar *title, const gchar *msg )
179 GtkCellRenderer *renderer;
182 GtkWidget *dialog = gtk_dialog_new_with_buttons (title,
184 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
190 /* When something is selected then OK */
191 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
192 GtkWidget *response_w = NULL;
193 #if GTK_CHECK_VERSION (2, 20, 0)
194 /* Default to not apply - as initially nothing is selected! */
195 response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_REJECT );
197 GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING);
199 GtkWidget *scrolledwindow;
201 GList *runner = names;
204 gtk_list_store_append(store, &iter);
205 gtk_list_store_set(store, &iter, 0, runner->data, -1);
206 runner = g_list_next(runner);
209 view = gtk_tree_view_new();
210 renderer = gtk_cell_renderer_text_new();
211 // Use the column header to display the message text,
212 // this makes the overall widget allocation simple as treeview takes up all the space
213 GtkTreeViewColumn *column;
214 column = gtk_tree_view_column_new_with_attributes (msg, renderer, "text", 0, NULL );
215 gtk_tree_view_column_set_sort_column_id (column, 0);
216 gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
218 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
219 gtk_tree_selection_set_mode( gtk_tree_view_get_selection(GTK_TREE_VIEW(view)),
220 multiple_selection_allowed ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_BROWSE );
221 g_object_unref(store);
223 scrolledwindow = gtk_scrolled_window_new ( NULL, NULL );
224 gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
225 gtk_container_add ( GTK_CONTAINER(scrolledwindow), view );
227 gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), scrolledwindow, TRUE, TRUE, 0 );
228 // Ensure a reasonable number of items are shown, but let the width be automatically sized
229 gtk_widget_set_size_request ( dialog, -1, 400) ;
231 gtk_widget_show_all ( dialog );
234 gtk_widget_grab_focus ( response_w );
236 while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
238 GList *names_selected = NULL;
239 GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
240 gtk_tree_selection_selected_foreach(selection, get_selected_foreach_func, &names_selected);
243 gtk_widget_destroy ( dialog );
244 return names_selected;
246 a_dialog_error_msg(parent, _("Nothing was selected"));
248 gtk_widget_destroy ( dialog );
252 gchar *a_dialog_new_track ( GtkWindow *parent, gchar *default_name, gboolean is_route )
254 GtkWidget *dialog = gtk_dialog_new_with_buttons ( is_route ? _("Add Route") : _("Add Track"),
256 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
262 GtkWidget *label = gtk_label_new ( is_route ? _("Route Name:") : _("Track Name:") );
263 GtkWidget *entry = gtk_entry_new ();
266 gtk_entry_set_text ( GTK_ENTRY(entry), default_name );
268 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), label, FALSE, FALSE, 0);
269 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), entry, FALSE, FALSE, 0);
271 g_signal_connect_swapped ( entry, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
273 gtk_widget_show ( label );
274 gtk_widget_show ( entry );
276 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
278 while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
280 const gchar *constname = gtk_entry_get_text ( GTK_ENTRY(entry) );
281 if ( *constname == '\0' )
282 a_dialog_info_msg ( parent, _("Please enter a name for the track.") );
284 gchar *name = g_strdup ( constname );
285 gtk_widget_destroy ( dialog );
289 gtk_widget_destroy ( dialog );
293 static void today_clicked (GtkWidget *cal)
295 GDateTime *now = g_date_time_new_now_local ();
296 gtk_calendar_select_month ( GTK_CALENDAR(cal), g_date_time_get_month(now)-1, g_date_time_get_year(now) );
297 gtk_calendar_select_day ( GTK_CALENDAR(cal), g_date_time_get_day_of_month(now) );
298 g_date_time_unref ( now );
304 * Returns: a date as a string - always in ISO8601 format (YYYY-MM-DD)
305 * This string can be NULL (especially when the dialog is cancelled)
306 * Free the string after use
308 gchar *a_dialog_get_date ( GtkWindow *parent, const gchar *title )
310 GtkWidget *dialog = gtk_dialog_new_with_buttons ( title,
312 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
318 GtkWidget *cal = gtk_calendar_new ();
319 GtkWidget *today = gtk_button_new_with_label ( _("Today") );
321 static guint year = 0;
322 static guint month = 0;
323 static guint day = 0;
326 // restore the last selected date
327 gtk_calendar_select_month ( GTK_CALENDAR(cal), month, year );
328 gtk_calendar_select_day ( GTK_CALENDAR(cal), day );
331 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), today, FALSE, FALSE, 0);
332 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), cal, FALSE, FALSE, 0);
334 g_signal_connect_swapped ( G_OBJECT(today), "clicked", G_CALLBACK(today_clicked), cal );
336 gtk_widget_show_all ( dialog );
338 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
340 gchar *date_str = NULL;
341 if ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
343 gtk_calendar_get_date ( GTK_CALENDAR(cal), &year, &month, &day );
344 date_str = g_strdup_printf ( "%d-%02d-%02d", year, month+1, day );
346 gtk_widget_destroy ( dialog );
350 /* creates a vbox full of labels */
351 GtkWidget *a_dialog_create_label_vbox ( gchar **texts, int label_count, gint spacing, gint padding )
353 GtkWidget *vbox, *label;
355 vbox = gtk_vbox_new( TRUE, spacing );
357 for ( i = 0; i < label_count; i++ )
359 label = gtk_label_new(NULL);
360 gtk_label_set_markup ( GTK_LABEL(label), _(texts[i]) );
361 if ( strchr(texts[i], ':') ) {
362 // Align label to the right
363 gtk_misc_set_alignment ( GTK_MISC(label), 1.0, 0.5 );
365 gtk_box_pack_start ( GTK_BOX(vbox), label, FALSE, TRUE, padding );
370 gboolean a_dialog_yes_or_no ( GtkWindow *parent, const gchar *message, const gchar *extra )
373 dia = gtk_message_dialog_new ( parent,
374 GTK_DIALOG_DESTROY_WITH_PARENT,
375 GTK_MESSAGE_QUESTION,
379 if ( gtk_dialog_run ( GTK_DIALOG(dia) ) == GTK_RESPONSE_YES )
381 gtk_widget_destroy ( dia );
386 gtk_widget_destroy ( dia );
391 static void zoom_spin_changed ( GtkSpinButton *spin, GtkWidget *pass_along[3] )
393 if ( gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(pass_along[2]) ) )
394 gtk_spin_button_set_value (
395 GTK_SPIN_BUTTON(pass_along[GTK_WIDGET(spin) == pass_along[0] ? 1 : 0]),
396 gtk_spin_button_get_value ( spin ) );
399 gboolean a_dialog_custom_zoom ( GtkWindow *parent, gdouble *xmpp, gdouble *ympp )
401 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Zoom Factors..."),
403 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
409 GtkWidget *table, *label, *xlabel, *xspin, *ylabel, *yspin, *samecheck;
410 GtkWidget *pass_along[3];
412 table = gtk_table_new ( 4, 2, FALSE );
413 gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 );
415 label = gtk_label_new ( _("Zoom factor (in meters per pixel):") );
416 xlabel = gtk_label_new ( _("X (easting): "));
417 ylabel = gtk_label_new ( _("Y (northing): "));
419 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 );
420 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 );
422 pass_along[2] = samecheck = gtk_check_button_new_with_label ( _("X and Y zoom factors must be equal") );
423 /* TODO -- same factor */
424 /* samecheck = gtk_check_button_new_with_label ( "Same x/y zoom factor" ); */
426 if ( *xmpp == *ympp )
427 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(samecheck), TRUE );
429 gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 2, 0, 1 );
430 gtk_table_attach_defaults ( GTK_TABLE(table), xlabel, 0, 1, 1, 2 );
431 gtk_table_attach_defaults ( GTK_TABLE(table), xspin, 1, 2, 1, 2 );
432 gtk_table_attach_defaults ( GTK_TABLE(table), ylabel, 0, 1, 2, 3 );
433 gtk_table_attach_defaults ( GTK_TABLE(table), yspin, 1, 2, 2, 3 );
434 gtk_table_attach_defaults ( GTK_TABLE(table), samecheck, 0, 2, 3, 4 );
436 gtk_widget_show_all ( table );
438 g_signal_connect ( G_OBJECT(xspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along );
439 g_signal_connect ( G_OBJECT(yspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along );
441 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
443 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
445 *xmpp = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(xspin) );
446 *ympp = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(yspin) );
447 gtk_widget_destroy ( dialog );
450 gtk_widget_destroy ( dialog );
454 static void split_spin_focused ( GtkSpinButton *spin, GtkWidget *pass_along[1] )
456 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(pass_along[0]), 1);
459 gboolean a_dialog_time_threshold ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint *thr )
461 GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text,
463 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
469 GtkWidget *table, *t1, *t2, *t3, *t4, *spin, *label;
470 GtkWidget *pass_along[1];
472 table = gtk_table_new ( 4, 2, FALSE );
473 gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 );
475 label = gtk_label_new (label_text);
477 t1 = gtk_radio_button_new_with_label ( NULL, _("1 min") );
478 t2 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t1), _("1 hour") );
479 t3 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t2), _("1 day") );
480 t4 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t3), _("Custom (in minutes):") );
484 spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *thr, 0, 65536, 1, 5, 0 ), 1, 0 );
486 gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 2, 0, 1 );
487 gtk_table_attach_defaults ( GTK_TABLE(table), t1, 0, 1, 1, 2 );
488 gtk_table_attach_defaults ( GTK_TABLE(table), t2, 0, 1, 2, 3 );
489 gtk_table_attach_defaults ( GTK_TABLE(table), t3, 0, 1, 3, 4 );
490 gtk_table_attach_defaults ( GTK_TABLE(table), t4, 0, 1, 4, 5 );
491 gtk_table_attach_defaults ( GTK_TABLE(table), spin, 1, 2, 4, 5 );
493 gtk_widget_show_all ( table );
495 g_signal_connect ( G_OBJECT(spin), "grab-focus", G_CALLBACK(split_spin_focused), pass_along );
497 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
499 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
501 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t1))) {
503 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t2))) {
505 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t3))) {
507 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t4))) {
508 *thr = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) );
510 gtk_widget_destroy ( dialog );
513 gtk_widget_destroy ( dialog );
518 * a_dialog_get_positive_number:
520 * Dialog to return a positive number via a spinbox within the supplied limits
522 * Returns: A value of zero indicates the dialog was cancelled
524 guint a_dialog_get_positive_number ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint default_num, guint min, guint max, guint step )
526 GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text,
528 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
534 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
535 GtkWidget *response_w = NULL;
536 #if GTK_CHECK_VERSION (2, 20, 0)
537 response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
540 GtkWidget *table, *spin, *label;
541 guint result = default_num;
543 table = gtk_table_new ( 2, 1, FALSE );
544 gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 );
546 label = gtk_label_new (label_text);
547 spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( default_num, min, max, step, 5, 0 ), 1, 0 );
549 gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 1, 0, 1 );
550 gtk_table_attach_defaults ( GTK_TABLE(table), spin, 0, 1, 1, 2 );
553 gtk_widget_grab_focus ( response_w );
555 gtk_widget_show_all ( table );
557 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
559 result = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) );
560 gtk_widget_destroy ( dialog );
565 gtk_widget_destroy ( dialog );
569 #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 24)
570 static void about_url_hook (GtkAboutDialog *about,
574 open_url (GTK_WINDOW(about), link);
577 static void about_email_hook (GtkAboutDialog *about,
581 new_email (GTK_WINDOW(about), email);
586 * Creates a dialog with list of text
587 * Mostly useful for longer messages that have several lines of information.
589 void a_dialog_list ( GtkWindow *parent, const gchar *title, GArray *array, gint padding )
591 GtkWidget *dialog = gtk_dialog_new_with_buttons ( title,
593 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
598 GtkBox *vbox = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog)));
601 for ( int i = 0; i < array->len; i++ ) {
602 label = ui_label_new_selectable (NULL);
603 gtk_label_set_markup ( GTK_LABEL(label), g_array_index(array,gchar*,i) );
604 gtk_box_pack_start ( GTK_BOX(vbox), label, FALSE, TRUE, padding );
607 gtk_widget_show_all ( dialog );
608 gtk_dialog_run ( GTK_DIALOG(dialog) );
609 gtk_widget_destroy ( dialog );
612 void a_dialog_about ( GtkWindow *parent )
614 const gchar *version = VIKING_VERSION;
615 const gchar *website = VIKING_URL;
616 gchar *copyright = g_strdup_printf(_("2003-2008, Evan Battaglia\n2008-%s, Viking's contributors"), THEYEAR);
617 const gchar *comments = _("GPS Data and Topo Analyzer, Explorer, and Manager.");
618 const gchar *license = _("This program is free software; you can redistribute it and/or modify "
619 "it under the terms of the GNU General Public License as published by "
620 "the Free Software Foundation; either version 2 of the License, or "
621 "(at your option) any later version."
623 "This program is distributed in the hope that it will be useful, "
624 "but WITHOUT ANY WARRANTY; without even the implied warranty of "
625 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
626 "GNU General Public License for more details."
628 "You should have received a copy of the GNU General Public License "
629 "along with this program; if not, write to the Free Software "
630 "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA");
632 // Would be nice to use gtk_about_dialog_add_credit_section (), but that requires gtk 3.4
633 // For now shove it in the 'artists' section so at least the information is easily visible
634 // Something more advanced might have proper version information too...
635 const gchar *libs[] = {
636 "Compiled in libraries:",
642 // Potentially optional libs (but probably couldn't build without them)
655 // Actually optional libs
659 #ifdef HAVE_LIBGEXIV2
677 #ifdef HAVE_LIBSQLITE3
680 #ifdef HAVE_LIBMAPNIK
683 #ifdef HAVE_LIBNETTLE
688 // Newer versions of GTK 'just work', calling gtk_show_uri() on the URL or email and opens up the appropriate program
689 // This is the old method:
690 #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 24)
691 gtk_about_dialog_set_url_hook (about_url_hook, NULL, NULL);
692 gtk_about_dialog_set_email_hook (about_email_hook, NULL, NULL);
695 gtk_show_about_dialog (parent,
698 "comments", comments,
699 "copyright", copyright,
701 "wrap-license", TRUE,
702 /* logo automatically retrieved via gtk_window_get_default_icon_list */
704 "documenters", DOCUMENTERS,
705 "translator-credits", _("Translation is coordinated on http://launchpad.net/viking"),
711 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)
715 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 );
716 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
717 GtkWidget *response_w = NULL;
718 #if GTK_CHECK_VERSION (2, 20, 0)
719 response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
722 GtkWidget *map_label = gtk_label_new(_("Map type:"));
723 GtkWidget *map_combo = vik_combo_box_text_new();
724 for (s = mapnames; *s; s++)
725 vik_combo_box_text_append (GTK_COMBO_BOX(map_combo), *s);
726 gtk_combo_box_set_active (GTK_COMBO_BOX(map_combo), default_map);
728 GtkWidget *zoom_label = gtk_label_new(_("Zoom level:"));
729 GtkWidget *zoom_combo = vik_combo_box_text_new();
730 for (s = zoom_list; *s; s++)
731 vik_combo_box_text_append (GTK_COMBO_BOX(zoom_combo), *s);
732 gtk_combo_box_set_active (GTK_COMBO_BOX(zoom_combo), default_zoom);
734 GtkTable *box = GTK_TABLE(gtk_table_new(2, 2, FALSE));
735 gtk_table_attach_defaults(box, map_label, 0, 1, 0, 1);
736 gtk_table_attach_defaults(box, map_combo, 1, 2, 0, 1);
737 gtk_table_attach_defaults(box, zoom_label, 0, 1, 1, 2);
738 gtk_table_attach_defaults(box, zoom_combo, 1, 2, 1, 2);
740 gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), GTK_WIDGET(box), FALSE, FALSE, 5 );
743 gtk_widget_grab_focus ( response_w );
745 gtk_widget_show_all ( dialog );
746 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) != GTK_RESPONSE_ACCEPT ) {
747 gtk_widget_destroy(dialog);
751 *selected_map = gtk_combo_box_get_active(GTK_COMBO_BOX(map_combo));
752 *selected_zoom = gtk_combo_box_get_active(GTK_COMBO_BOX(zoom_combo));
754 gtk_widget_destroy(dialog);
759 * Display a dialog presenting the license of a map.
760 * Allow to read the license by launching a web browser.
762 void a_dialog_license ( GtkWindow *parent, const gchar *map, const gchar *license, const gchar *url)
764 GtkWidget *dialog = gtk_message_dialog_new (parent,
765 GTK_DIALOG_DESTROY_WITH_PARENT,
768 _("The map data is licensed: %s."),
770 gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
771 _("The data provided by '<b>%s</b>' are licensed under the following license: <b>%s</b>."),
773 #define RESPONSE_OPEN_LICENSE 600
775 gtk_dialog_add_button (GTK_DIALOG (dialog), _("Open license"), RESPONSE_OPEN_LICENSE);
779 response = gtk_dialog_run (GTK_DIALOG (dialog));
780 if (response == RESPONSE_OPEN_LICENSE) {
781 open_url (parent, url);
783 } while (response != GTK_RESPONSE_DELETE_EVENT && response != GTK_RESPONSE_OK);
784 gtk_widget_destroy (dialog);