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 "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 );
47 gboolean a_dialog_goto_latlon ( GtkWindow *parent, struct LatLon *ll, const struct LatLon *old )
49 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to Lat/Lon"),
51 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
57 GtkWidget *latlabel, *lonlabel;
59 gchar *tmp_lat, *tmp_lon;
61 latlabel = gtk_label_new (_("Latitude:"));
62 lat = gtk_entry_new ();
63 tmp_lat = g_strdup_printf ( "%f", old->lat );
64 gtk_entry_set_text ( GTK_ENTRY(lat), tmp_lat );
67 lonlabel = gtk_label_new (_("Longitude:"));
68 lon = gtk_entry_new ();
69 tmp_lon = g_strdup_printf ( "%f", old->lon );
70 gtk_entry_set_text ( GTK_ENTRY(lon), tmp_lon );
73 gtk_widget_show ( latlabel );
74 gtk_widget_show ( lonlabel );
75 gtk_widget_show ( lat );
76 gtk_widget_show ( lon );
78 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), latlabel, FALSE, FALSE, 0);
79 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), lat, FALSE, FALSE, 0);
80 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), lonlabel, FALSE, FALSE, 0);
81 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), lon, FALSE, FALSE, 0);
83 // 'ok' when press return in the entry
84 g_signal_connect_swapped (lat, "activate", G_CALLBACK(a_dialog_response_accept), dialog);
85 g_signal_connect_swapped (lon, "activate", G_CALLBACK(a_dialog_response_accept), dialog);
87 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
89 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
91 ll->lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lat) ) );
92 ll->lon = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lon) ) );
93 gtk_widget_destroy ( dialog );
97 gtk_widget_destroy ( dialog );
101 gboolean a_dialog_goto_utm ( GtkWindow *parent, struct UTM *utm, const struct UTM *old )
103 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to UTM"),
105 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
111 GtkWidget *norlabel, *easlabel, *nor, *eas;
112 GtkWidget *zonehbox, *zonespin, *letterentry;
113 gchar *tmp_eas, *tmp_nor;
116 norlabel = gtk_label_new (_("Northing:"));
117 nor = gtk_entry_new ();
118 tmp_nor = g_strdup_printf("%ld", (long) old->northing );
119 gtk_entry_set_text ( GTK_ENTRY(nor), tmp_nor );
122 easlabel = gtk_label_new (_("Easting:"));
123 eas = gtk_entry_new ();
124 tmp_eas = g_strdup_printf("%ld", (long) old->easting );
125 gtk_entry_set_text ( GTK_ENTRY(eas), tmp_eas );
128 zonehbox = gtk_hbox_new ( FALSE, 0 );
129 gtk_box_pack_start ( GTK_BOX(zonehbox), gtk_label_new ( _("Zone:") ), FALSE, FALSE, 5 );
130 zonespin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( old->zone, 1, 60, 1, 5, 0 ), 1, 0 );
131 gtk_box_pack_start ( GTK_BOX(zonehbox), zonespin, TRUE, TRUE, 5 );
132 gtk_box_pack_start ( GTK_BOX(zonehbox), gtk_label_new ( _("Letter:") ), FALSE, FALSE, 5 );
133 letterentry = gtk_entry_new ();
134 gtk_entry_set_max_length ( GTK_ENTRY(letterentry), 1 );
135 gtk_entry_set_width_chars ( GTK_ENTRY(letterentry), 2 );
136 tmp_letter[0] = old->letter;
137 tmp_letter[1] = '\0';
138 gtk_entry_set_text ( GTK_ENTRY(letterentry), tmp_letter );
139 gtk_box_pack_start ( GTK_BOX(zonehbox), letterentry, FALSE, FALSE, 5 );
141 gtk_widget_show ( norlabel );
142 gtk_widget_show ( easlabel );
143 gtk_widget_show ( nor );
144 gtk_widget_show ( eas );
146 gtk_widget_show_all ( zonehbox );
148 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), norlabel, FALSE, FALSE, 0);
149 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), nor, FALSE, FALSE, 0);
150 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), easlabel, FALSE, FALSE, 0);
151 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), eas, FALSE, FALSE, 0);
152 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), zonehbox, FALSE, FALSE, 0);
154 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
156 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
159 utm->northing = atof ( gtk_entry_get_text ( GTK_ENTRY(nor) ) );
160 utm->easting = atof ( gtk_entry_get_text ( GTK_ENTRY(eas) ) );
161 utm->zone = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(zonespin) );
162 letter = gtk_entry_get_text ( GTK_ENTRY(letterentry) );
164 utm->letter = toupper(*letter);
165 gtk_widget_destroy ( dialog );
169 gtk_widget_destroy ( dialog );
173 void a_dialog_response_accept ( GtkDialog *dialog )
175 gtk_dialog_response ( dialog, GTK_RESPONSE_ACCEPT );
178 static void get_selected_foreach_func(GtkTreeModel *model,
185 gtk_tree_model_get (model, iter, 0, &name, -1);
186 *list = g_list_prepend(*list, name);
189 GList *a_dialog_select_from_list ( GtkWindow *parent, GList *names, gboolean multiple_selection_allowed, const gchar *title, const gchar *msg )
192 GtkCellRenderer *renderer;
195 GtkWidget *dialog = gtk_dialog_new_with_buttons (title,
197 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
203 /* When something is selected then OK */
204 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
205 GtkWidget *response_w = NULL;
206 #if GTK_CHECK_VERSION (2, 20, 0)
207 /* Default to not apply - as initially nothing is selected! */
208 response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_REJECT );
210 GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING);
212 GtkWidget *scrolledwindow;
214 GList *runner = names;
217 gtk_list_store_append(store, &iter);
218 gtk_list_store_set(store, &iter, 0, runner->data, -1);
219 runner = g_list_next(runner);
222 view = gtk_tree_view_new();
223 renderer = gtk_cell_renderer_text_new();
224 // Use the column header to display the message text,
225 // this makes the overall widget allocation simple as treeview takes up all the space
226 GtkTreeViewColumn *column;
227 column = gtk_tree_view_column_new_with_attributes (msg, renderer, "text", 0, NULL );
228 gtk_tree_view_column_set_sort_column_id (column, 0);
229 gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
231 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
232 gtk_tree_selection_set_mode( gtk_tree_view_get_selection(GTK_TREE_VIEW(view)),
233 multiple_selection_allowed ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_BROWSE );
234 g_object_unref(store);
236 scrolledwindow = gtk_scrolled_window_new ( NULL, NULL );
237 gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
238 gtk_container_add ( GTK_CONTAINER(scrolledwindow), view );
240 gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), scrolledwindow, TRUE, TRUE, 0 );
241 // Ensure a reasonable number of items are shown, but let the width be automatically sized
242 gtk_widget_set_size_request ( dialog, -1, 400) ;
244 gtk_widget_show_all ( dialog );
247 gtk_widget_grab_focus ( response_w );
249 while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
251 GList *names_selected = NULL;
252 GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
253 gtk_tree_selection_selected_foreach(selection, get_selected_foreach_func, &names_selected);
256 gtk_widget_destroy ( dialog );
257 return names_selected;
259 a_dialog_error_msg(parent, _("Nothing was selected"));
261 gtk_widget_destroy ( dialog );
265 gchar *a_dialog_new_track ( GtkWindow *parent, gchar *default_name, gboolean is_route )
267 GtkWidget *dialog = gtk_dialog_new_with_buttons ( is_route ? _("Add Route") : _("Add Track"),
269 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
275 GtkWidget *label = gtk_label_new ( is_route ? _("Route Name:") : _("Track Name:") );
276 GtkWidget *entry = gtk_entry_new ();
279 gtk_entry_set_text ( GTK_ENTRY(entry), default_name );
281 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), label, FALSE, FALSE, 0);
282 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), entry, FALSE, FALSE, 0);
284 g_signal_connect_swapped ( entry, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
286 gtk_widget_show ( label );
287 gtk_widget_show ( entry );
289 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
291 while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
293 const gchar *constname = gtk_entry_get_text ( GTK_ENTRY(entry) );
294 if ( *constname == '\0' )
295 a_dialog_info_msg ( parent, _("Please enter a name for the track.") );
297 gchar *name = g_strdup ( constname );
298 gtk_widget_destroy ( dialog );
302 gtk_widget_destroy ( dialog );
306 static void today_clicked (GtkWidget *cal)
308 GDateTime *now = g_date_time_new_now_local ();
309 gtk_calendar_select_month ( GTK_CALENDAR(cal), g_date_time_get_month(now)-1, g_date_time_get_year(now) );
310 gtk_calendar_select_day ( GTK_CALENDAR(cal), g_date_time_get_day_of_month(now) );
311 g_date_time_unref ( now );
317 * Returns: a date as a string - always in ISO8601 format (YYYY-MM-DD)
318 * This string can be NULL (especially when the dialog is cancelled)
319 * Free the string after use
321 gchar *a_dialog_get_date ( GtkWindow *parent, const gchar *title )
323 GtkWidget *dialog = gtk_dialog_new_with_buttons ( title,
325 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
331 GtkWidget *cal = gtk_calendar_new ();
332 GtkWidget *today = gtk_button_new_with_label ( _("Today") );
334 static guint year = 0;
335 static guint month = 0;
336 static guint day = 0;
339 // restore the last selected date
340 gtk_calendar_select_month ( GTK_CALENDAR(cal), month, year );
341 gtk_calendar_select_day ( GTK_CALENDAR(cal), day );
344 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), today, FALSE, FALSE, 0);
345 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), cal, FALSE, FALSE, 0);
347 g_signal_connect_swapped ( G_OBJECT(today), "clicked", G_CALLBACK(today_clicked), cal );
349 gtk_widget_show_all ( dialog );
351 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
353 gchar *date_str = NULL;
354 if ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
356 gtk_calendar_get_date ( GTK_CALENDAR(cal), &year, &month, &day );
357 date_str = g_strdup_printf ( "%d-%02d-%02d", year, month+1, day );
359 gtk_widget_destroy ( dialog );
363 /* creates a vbox full of labels */
364 GtkWidget *a_dialog_create_label_vbox ( gchar **texts, int label_count, gint spacing, gint padding )
366 GtkWidget *vbox, *label;
368 vbox = gtk_vbox_new( TRUE, spacing );
370 for ( i = 0; i < label_count; i++ )
372 label = gtk_label_new(NULL);
373 gtk_label_set_markup ( GTK_LABEL(label), _(texts[i]) );
374 if ( strchr(texts[i], ':') ) {
375 // Align label to the right
376 gtk_misc_set_alignment ( GTK_MISC(label), 1.0, 0.5 );
378 gtk_box_pack_start ( GTK_BOX(vbox), label, FALSE, TRUE, padding );
383 gboolean a_dialog_yes_or_no ( GtkWindow *parent, const gchar *message, const gchar *extra )
386 dia = gtk_message_dialog_new ( parent,
387 GTK_DIALOG_DESTROY_WITH_PARENT,
388 GTK_MESSAGE_QUESTION,
392 if ( gtk_dialog_run ( GTK_DIALOG(dia) ) == GTK_RESPONSE_YES )
394 gtk_widget_destroy ( dia );
399 gtk_widget_destroy ( dia );
404 static void zoom_spin_changed ( GtkSpinButton *spin, GtkWidget *pass_along[3] )
406 if ( gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(pass_along[2]) ) )
407 gtk_spin_button_set_value (
408 GTK_SPIN_BUTTON(pass_along[GTK_WIDGET(spin) == pass_along[0] ? 1 : 0]),
409 gtk_spin_button_get_value ( spin ) );
412 gboolean a_dialog_custom_zoom ( GtkWindow *parent, gdouble *xmpp, gdouble *ympp )
414 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Zoom Factors..."),
416 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
422 GtkWidget *table, *label, *xlabel, *xspin, *ylabel, *yspin, *samecheck;
423 GtkWidget *pass_along[3];
425 table = gtk_table_new ( 4, 2, FALSE );
426 gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 );
428 label = gtk_label_new ( _("Zoom factor (in meters per pixel):") );
429 xlabel = gtk_label_new ( _("X (easting): "));
430 ylabel = gtk_label_new ( _("Y (northing): "));
432 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 );
433 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 );
435 pass_along[2] = samecheck = gtk_check_button_new_with_label ( _("X and Y zoom factors must be equal") );
436 /* TODO -- same factor */
437 /* samecheck = gtk_check_button_new_with_label ( "Same x/y zoom factor" ); */
439 if ( *xmpp == *ympp )
440 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(samecheck), TRUE );
442 gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 2, 0, 1 );
443 gtk_table_attach_defaults ( GTK_TABLE(table), xlabel, 0, 1, 1, 2 );
444 gtk_table_attach_defaults ( GTK_TABLE(table), xspin, 1, 2, 1, 2 );
445 gtk_table_attach_defaults ( GTK_TABLE(table), ylabel, 0, 1, 2, 3 );
446 gtk_table_attach_defaults ( GTK_TABLE(table), yspin, 1, 2, 2, 3 );
447 gtk_table_attach_defaults ( GTK_TABLE(table), samecheck, 0, 2, 3, 4 );
449 gtk_widget_show_all ( table );
451 g_signal_connect ( G_OBJECT(xspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along );
452 g_signal_connect ( G_OBJECT(yspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along );
454 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
456 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
458 *xmpp = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(xspin) );
459 *ympp = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(yspin) );
460 gtk_widget_destroy ( dialog );
463 gtk_widget_destroy ( dialog );
467 static void split_spin_focused ( GtkSpinButton *spin, GtkWidget *pass_along[1] )
469 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(pass_along[0]), 1);
472 gboolean a_dialog_time_threshold ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint *thr )
474 GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text,
476 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
482 GtkWidget *table, *t1, *t2, *t3, *t4, *spin, *label;
483 GtkWidget *pass_along[1];
485 table = gtk_table_new ( 4, 2, FALSE );
486 gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 );
488 label = gtk_label_new (label_text);
490 t1 = gtk_radio_button_new_with_label ( NULL, _("1 min") );
491 t2 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t1), _("1 hour") );
492 t3 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t2), _("1 day") );
493 t4 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t3), _("Custom (in minutes):") );
497 spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *thr, 0, 65536, 1, 5, 0 ), 1, 0 );
499 gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 2, 0, 1 );
500 gtk_table_attach_defaults ( GTK_TABLE(table), t1, 0, 1, 1, 2 );
501 gtk_table_attach_defaults ( GTK_TABLE(table), t2, 0, 1, 2, 3 );
502 gtk_table_attach_defaults ( GTK_TABLE(table), t3, 0, 1, 3, 4 );
503 gtk_table_attach_defaults ( GTK_TABLE(table), t4, 0, 1, 4, 5 );
504 gtk_table_attach_defaults ( GTK_TABLE(table), spin, 1, 2, 4, 5 );
506 gtk_widget_show_all ( table );
508 g_signal_connect ( G_OBJECT(spin), "grab-focus", G_CALLBACK(split_spin_focused), pass_along );
510 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
512 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
514 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t1))) {
516 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t2))) {
518 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t3))) {
520 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t4))) {
521 *thr = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) );
523 gtk_widget_destroy ( dialog );
526 gtk_widget_destroy ( dialog );
531 * a_dialog_get_positive_number:
533 * Dialog to return a positive number via a spinbox within the supplied limits
535 * Returns: A value of zero indicates the dialog was cancelled
537 guint a_dialog_get_positive_number ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint default_num, guint min, guint max, guint step )
539 GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text,
541 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
547 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
548 GtkWidget *response_w = NULL;
549 #if GTK_CHECK_VERSION (2, 20, 0)
550 response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
553 GtkWidget *table, *spin, *label;
554 guint result = default_num;
556 table = gtk_table_new ( 2, 1, FALSE );
557 gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 );
559 label = gtk_label_new (label_text);
560 spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( default_num, min, max, step, 5, 0 ), 1, 0 );
562 gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 1, 0, 1 );
563 gtk_table_attach_defaults ( GTK_TABLE(table), spin, 0, 1, 1, 2 );
566 gtk_widget_grab_focus ( response_w );
568 gtk_widget_show_all ( table );
570 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
572 result = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) );
573 gtk_widget_destroy ( dialog );
578 gtk_widget_destroy ( dialog );
582 #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 24)
583 static void about_url_hook (GtkAboutDialog *about,
587 open_url (GTK_WINDOW(about), link);
590 static void about_email_hook (GtkAboutDialog *about,
594 new_email (GTK_WINDOW(about), email);
599 * Creates a dialog with list of text
600 * Mostly useful for longer messages that have several lines of information.
602 void a_dialog_list ( GtkWindow *parent, const gchar *title, GArray *array, gint padding )
604 GtkWidget *dialog = gtk_dialog_new_with_buttons ( title,
606 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
611 GtkBox *vbox = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog)));
614 for ( int i = 0; i < array->len; i++ ) {
615 label = ui_label_new_selectable (NULL);
616 gtk_label_set_markup ( GTK_LABEL(label), g_array_index(array,gchar*,i) );
617 gtk_box_pack_start ( GTK_BOX(vbox), label, FALSE, TRUE, padding );
620 gtk_widget_show_all ( dialog );
621 gtk_dialog_run ( GTK_DIALOG(dialog) );
622 gtk_widget_destroy ( dialog );
625 void a_dialog_about ( GtkWindow *parent )
627 const gchar *program_name = PACKAGE_NAME;
628 const gchar *version = VIKING_VERSION;
629 const gchar *website = VIKING_URL;
630 const gchar *copyright = "2003-2008, Evan Battaglia\n2008-2013, Viking's contributors";
631 const gchar *comments = _("GPS Data and Topo Analyzer, Explorer, and Manager.");
632 const gchar *license = _("This program is free software; you can redistribute it and/or modify "
633 "it under the terms of the GNU General Public License as published by "
634 "the Free Software Foundation; either version 2 of the License, or "
635 "(at your option) any later version."
637 "This program is distributed in the hope that it will be useful, "
638 "but WITHOUT ANY WARRANTY; without even the implied warranty of "
639 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
640 "GNU General Public License for more details."
642 "You should have received a copy of the GNU General Public License "
643 "along with this program; if not, write to the Free Software "
644 "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA");
646 // Would be nice to use gtk_about_dialog_add_credit_section (), but that requires gtk 3.4
647 // For now shove it in the 'artists' section so at least the information is easily visible
648 // Something more advanced might have proper version information too...
649 const gchar *libs[] = {
650 "Compiled in libraries:",
656 // Potentially optional libs (but probably couldn't build without them)
666 // Actually optional libs
670 #ifdef HAVE_LIBGEXIV2
685 #ifdef HAVE_LIBSQLITE3
688 #ifdef HAVE_LIBMAPNIK
693 // Newer versions of GTK 'just work', calling gtk_show_uri() on the URL or email and opens up the appropriate program
694 // This is the old method:
695 #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 24)
696 gtk_about_dialog_set_url_hook (about_url_hook, NULL, NULL);
697 gtk_about_dialog_set_email_hook (about_email_hook, NULL, NULL);
700 gtk_show_about_dialog (parent,
701 /* TODO do not set program-name and correctly set info for g_get_application_name */
702 "program-name", program_name,
705 "comments", comments,
706 "copyright", copyright,
708 "wrap-license", TRUE,
709 /* logo automatically retrieved via gtk_window_get_default_icon_list */
711 "documenters", DOCUMENTERS,
712 "translator-credits", _("Translation is coordinated on http://launchpad.net/viking"),
717 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)
721 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 );
722 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
723 GtkWidget *response_w = NULL;
724 #if GTK_CHECK_VERSION (2, 20, 0)
725 response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
728 GtkWidget *map_label = gtk_label_new(_("Map type:"));
729 GtkWidget *map_combo = vik_combo_box_text_new();
730 for (s = mapnames; *s; s++)
731 vik_combo_box_text_append (GTK_COMBO_BOX(map_combo), *s);
732 gtk_combo_box_set_active (GTK_COMBO_BOX(map_combo), default_map);
734 GtkWidget *zoom_label = gtk_label_new(_("Zoom level:"));
735 GtkWidget *zoom_combo = vik_combo_box_text_new();
736 for (s = zoom_list; *s; s++)
737 vik_combo_box_text_append (GTK_COMBO_BOX(zoom_combo), *s);
738 gtk_combo_box_set_active (GTK_COMBO_BOX(zoom_combo), default_zoom);
740 GtkTable *box = GTK_TABLE(gtk_table_new(2, 2, FALSE));
741 gtk_table_attach_defaults(box, map_label, 0, 1, 0, 1);
742 gtk_table_attach_defaults(box, map_combo, 1, 2, 0, 1);
743 gtk_table_attach_defaults(box, zoom_label, 0, 1, 1, 2);
744 gtk_table_attach_defaults(box, zoom_combo, 1, 2, 1, 2);
746 gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), GTK_WIDGET(box), FALSE, FALSE, 5 );
749 gtk_widget_grab_focus ( response_w );
751 gtk_widget_show_all ( dialog );
752 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) != GTK_RESPONSE_ACCEPT ) {
753 gtk_widget_destroy(dialog);
757 *selected_map = gtk_combo_box_get_active(GTK_COMBO_BOX(map_combo));
758 *selected_zoom = gtk_combo_box_get_active(GTK_COMBO_BOX(zoom_combo));
760 gtk_widget_destroy(dialog);
765 * Display a dialog presenting the license of a map.
766 * Allow to read the license by launching a web browser.
768 void a_dialog_license ( GtkWindow *parent, const gchar *map, const gchar *license, const gchar *url)
770 GtkWidget *dialog = gtk_message_dialog_new (parent,
771 GTK_DIALOG_DESTROY_WITH_PARENT,
774 _("The map data is licensed: %s."),
776 gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
777 _("The data provided by '<b>%s</b>' are licensed under the following license: <b>%s</b>."),
779 #define RESPONSE_OPEN_LICENSE 600
781 gtk_dialog_add_button (GTK_DIALOG (dialog), _("Open license"), RESPONSE_OPEN_LICENSE);
785 response = gtk_dialog_run (GTK_DIALOG (dialog));
786 if (response == RESPONSE_OPEN_LICENSE) {
787 open_url (parent, url);
789 } while (response != GTK_RESPONSE_DELETE_EVENT && response != GTK_RESPONSE_OK);
790 gtk_widget_destroy (dialog);