+
+static void split_spin_focused ( GtkSpinButton *spin, GtkWidget *pass_along[1] )
+{
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(pass_along[0]), 1);
+}
+
+gboolean a_dialog_time_threshold ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint *thr )
+{
+ GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text,
+ parent,
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_REJECT,
+ GTK_STOCK_OK,
+ GTK_RESPONSE_ACCEPT,
+ NULL);
+ GtkWidget *table, *t1, *t2, *t3, *t4, *spin, *label;
+ GtkWidget *pass_along[1];
+
+ table = gtk_table_new ( 4, 2, FALSE );
+ gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 );
+
+ label = gtk_label_new (label_text);
+
+ t1 = gtk_radio_button_new_with_label ( NULL, _("1 min") );
+ t2 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t1), _("1 hour") );
+ t3 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t2), _("1 day") );
+ t4 = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(t3), _("Custom (in minutes):") );
+
+ pass_along[0] = t4;
+
+ spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *thr, 0, 65536, 1, 5, 0 ), 1, 0 );
+
+ gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 2, 0, 1 );
+ gtk_table_attach_defaults ( GTK_TABLE(table), t1, 0, 1, 1, 2 );
+ gtk_table_attach_defaults ( GTK_TABLE(table), t2, 0, 1, 2, 3 );
+ gtk_table_attach_defaults ( GTK_TABLE(table), t3, 0, 1, 3, 4 );
+ gtk_table_attach_defaults ( GTK_TABLE(table), t4, 0, 1, 4, 5 );
+ gtk_table_attach_defaults ( GTK_TABLE(table), spin, 1, 2, 4, 5 );
+
+ gtk_widget_show_all ( table );
+
+ g_signal_connect ( G_OBJECT(spin), "grab-focus", G_CALLBACK(split_spin_focused), pass_along );
+
+ gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
+
+ if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
+ {
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t1))) {
+ *thr = 1;
+ } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t2))) {
+ *thr = 60;
+ } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t3))) {
+ *thr = 60 * 24;
+ } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t4))) {
+ *thr = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) );
+ }
+ gtk_widget_destroy ( dialog );
+ return TRUE;
+ }
+ gtk_widget_destroy ( dialog );
+ return FALSE;
+}
+
+/**
+ * a_dialog_get_positive_number:
+ *
+ * Dialog to return a positive number via a spinbox within the supplied limits
+ *
+ * Returns: A value of zero indicates the dialog was cancelled
+ */
+guint a_dialog_get_positive_number ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint default_num, guint min, guint max, guint step )
+{
+ GtkWidget *dialog = gtk_dialog_new_with_buttons (title_text,
+ parent,
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_REJECT,
+ GTK_STOCK_OK,
+ GTK_RESPONSE_ACCEPT,
+ NULL);
+ gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
+ GtkWidget *response_w = NULL;
+#if GTK_CHECK_VERSION (2, 20, 0)
+ response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
+#endif
+
+ GtkWidget *table, *spin, *label;
+ guint result = default_num;
+
+ table = gtk_table_new ( 2, 1, FALSE );
+ gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 );
+
+ label = gtk_label_new (label_text);
+ spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( default_num, min, max, step, 5, 0 ), 1, 0 );
+
+ gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 1, 0, 1 );
+ gtk_table_attach_defaults ( GTK_TABLE(table), spin, 0, 1, 1, 2 );
+
+ if ( response_w )
+ gtk_widget_grab_focus ( response_w );
+
+ gtk_widget_show_all ( table );
+
+ if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
+ {
+ result = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(spin) );
+ gtk_widget_destroy ( dialog );
+ return result;
+ }
+
+ // Dialog cancelled
+ gtk_widget_destroy ( dialog );
+ return 0;
+}
+
+#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 24)
+static void about_url_hook (GtkAboutDialog *about,
+ const gchar *link,
+ gpointer data)
+{
+ open_url (GTK_WINDOW(about), link);
+}
+
+static void about_email_hook (GtkAboutDialog *about,
+ const gchar *email,
+ gpointer data)
+{
+ new_email (GTK_WINDOW(about), email);
+}
+#endif
+
+/**
+ * Creates a dialog with list of text
+ * Mostly useful for longer messages that have several lines of information.
+ */
+void a_dialog_list ( GtkWindow *parent, const gchar *title, GArray *array, gint padding )
+{
+ GtkWidget *dialog = gtk_dialog_new_with_buttons ( title,
+ parent,
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_CLOSE,
+ GTK_RESPONSE_CLOSE,
+ NULL);
+
+ GtkBox *vbox = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog)));
+ GtkWidget *label;
+
+ for ( int i = 0; i < array->len; i++ ) {
+ label = ui_label_new_selectable (NULL);
+ gtk_label_set_markup ( GTK_LABEL(label), g_array_index(array,gchar*,i) );
+ gtk_box_pack_start ( GTK_BOX(vbox), label, FALSE, TRUE, padding );
+ }
+
+ gtk_widget_show_all ( dialog );
+ gtk_dialog_run ( GTK_DIALOG(dialog) );
+ gtk_widget_destroy ( dialog );
+}
+
+void a_dialog_about ( GtkWindow *parent )
+{
+ const gchar *program_name = PACKAGE_NAME;
+ const gchar *version = VIKING_VERSION;
+ const gchar *website = VIKING_URL;
+ const gchar *copyright = "2003-2008, Evan Battaglia\n2008-2013, Viking's contributors";
+ const gchar *comments = _("GPS Data and Topo Analyzer, Explorer, and Manager.");
+ const gchar *license = _("This program is free software; you can redistribute it and/or modify "
+ "it under the terms of the GNU General Public License as published by "
+ "the Free Software Foundation; either version 2 of the License, or "
+ "(at your option) any later version."
+ "\n\n"
+ "This program is distributed in the hope that it will be useful, "
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of "
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
+ "GNU General Public License for more details."
+ "\n\n"
+ "You should have received a copy of the GNU General Public License "
+ "along with this program; if not, write to the Free Software "
+ "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA");
+
+ // Would be nice to use gtk_about_dialog_add_credit_section (), but that requires gtk 3.4
+ // For now shove it in the 'artists' section so at least the information is easily visible
+ // Something more advanced might have proper version information too...
+ const gchar *libs[] = {
+ "Compiled in libraries:",
+ // Default libs
+ "libglib-2.0",
+ "libgthread-2.0",
+ "libgtk+-2.0",
+ "libgio-2.0",
+ // Potentially optional libs (but probably couldn't build without them)
+#ifdef HAVE_LIBM
+ "libm",
+#endif
+#ifdef HAVE_LIBZ
+ "libz",
+#endif
+#ifdef HAVE_LIBCURL
+ "libcurl",
+#endif
+ // Actually optional libs
+#ifdef HAVE_LIBGPS
+ "libgps",
+#endif
+#ifdef HAVE_LIBGEXIV2
+ "libgexiv2",
+#endif
+#ifdef HAVE_LIBEXIF
+ "libexif",
+#endif
+#ifdef HAVE_LIBX11
+ "libX11",
+#endif
+#ifdef HAVE_LIBMAGIC
+ "libmagic",
+#endif
+#ifdef HAVE_LIBBZ2
+ "libbz2",
+#endif
+#ifdef HAVE_LIBSQLITE3
+ "libsqlite3",
+#endif
+#ifdef HAVE_LIBMAPNIK
+ "libmapnik",
+#endif
+ NULL
+ };
+ // Newer versions of GTK 'just work', calling gtk_show_uri() on the URL or email and opens up the appropriate program
+ // This is the old method:
+#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 24)
+ gtk_about_dialog_set_url_hook (about_url_hook, NULL, NULL);
+ gtk_about_dialog_set_email_hook (about_email_hook, NULL, NULL);
+#endif
+
+ gtk_show_about_dialog (parent,
+ /* TODO do not set program-name and correctly set info for g_get_application_name */
+ "program-name", program_name,
+ "version", version,
+ "website", website,
+ "comments", comments,
+ "copyright", copyright,
+ "license", license,
+ "wrap-license", TRUE,
+ /* logo automatically retrieved via gtk_window_get_default_icon_list */
+ "authors", AUTHORS,
+ "documenters", DOCUMENTERS,
+ "translator-credits", _("Translation is coordinated on http://launchpad.net/viking"),
+ "artists", libs,
+ NULL);
+}
+
+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)
+{
+ gchar **s;
+
+ 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 );
+ gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
+ GtkWidget *response_w = NULL;
+#if GTK_CHECK_VERSION (2, 20, 0)
+ response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
+#endif
+
+ GtkWidget *map_label = gtk_label_new(_("Map type:"));
+ GtkWidget *map_combo = vik_combo_box_text_new();
+ for (s = mapnames; *s; s++)
+ vik_combo_box_text_append (GTK_COMBO_BOX(map_combo), *s);
+ gtk_combo_box_set_active (GTK_COMBO_BOX(map_combo), default_map);
+
+ GtkWidget *zoom_label = gtk_label_new(_("Zoom level:"));
+ GtkWidget *zoom_combo = vik_combo_box_text_new();
+ for (s = zoom_list; *s; s++)
+ vik_combo_box_text_append (GTK_COMBO_BOX(zoom_combo), *s);
+ gtk_combo_box_set_active (GTK_COMBO_BOX(zoom_combo), default_zoom);
+
+ GtkTable *box = GTK_TABLE(gtk_table_new(2, 2, FALSE));
+ gtk_table_attach_defaults(box, map_label, 0, 1, 0, 1);
+ gtk_table_attach_defaults(box, map_combo, 1, 2, 0, 1);
+ gtk_table_attach_defaults(box, zoom_label, 0, 1, 1, 2);
+ gtk_table_attach_defaults(box, zoom_combo, 1, 2, 1, 2);
+
+ gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), GTK_WIDGET(box), FALSE, FALSE, 5 );
+
+ if ( response_w )
+ gtk_widget_grab_focus ( response_w );
+
+ gtk_widget_show_all ( dialog );
+ if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) != GTK_RESPONSE_ACCEPT ) {
+ gtk_widget_destroy(dialog);
+ return FALSE;
+ }
+
+ *selected_map = gtk_combo_box_get_active(GTK_COMBO_BOX(map_combo));
+ *selected_zoom = gtk_combo_box_get_active(GTK_COMBO_BOX(zoom_combo));
+
+ gtk_widget_destroy(dialog);
+ return TRUE;
+}
+
+/**
+ * Display a dialog presenting the license of a map.
+ * Allow to read the license by launching a web browser.
+ */
+void a_dialog_license ( GtkWindow *parent, const gchar *map, const gchar *license, const gchar *url)
+{
+ GtkWidget *dialog = gtk_message_dialog_new (parent,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK,
+ _("The map data is licensed: %s."),
+ license);
+ gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
+ _("The data provided by '<b>%s</b>' are licensed under the following license: <b>%s</b>."),
+ map, license);
+#define RESPONSE_OPEN_LICENSE 600
+ if (url != NULL) {
+ gtk_dialog_add_button (GTK_DIALOG (dialog), _("Open license"), RESPONSE_OPEN_LICENSE);
+ }
+ gint response;
+ do {
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+ if (response == RESPONSE_OPEN_LICENSE) {
+ open_url (parent, url);
+ }
+ } while (response != GTK_RESPONSE_DELETE_EVENT && response != GTK_RESPONSE_OK);
+ gtk_widget_destroy (dialog);
+}