X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/29c93cc57d2f7715c58b4e577440bc580a47bd8a..e8bab170981ff0e1cd572107ca4de122d4aafe8c:/src/dialog.c diff --git a/src/dialog.c b/src/dialog.c index c9d35060..9bc2848f 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -3,7 +3,7 @@ * * Copyright (C) 2003-2005, Evan Battaglia * Copyright (C) 2008, Hein Ragas - * Copyright (C) 2010, Rob Norris + * Copyright (C) 2010-2014, Rob Norris * * 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 @@ -26,13 +26,10 @@ #endif #include "viking.h" -#include "thumbnails.h" -#include "garminsymbols.h" #include "degrees_converters.h" #include "authors.h" #include "documenters.h" -#include "vikgoto.h" -#include "util.h" +#include "ui_util.h" #include @@ -78,10 +75,14 @@ gboolean a_dialog_goto_latlon ( GtkWindow *parent, struct LatLon *ll, const stru gtk_widget_show ( lat ); gtk_widget_show ( lon ); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), latlabel, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lat, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lonlabel, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lon, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), latlabel, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), lat, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), lonlabel, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), lon, FALSE, FALSE, 0); + + // 'ok' when press return in the entry + g_signal_connect_swapped (lat, "activate", G_CALLBACK(a_dialog_response_accept), dialog); + g_signal_connect_swapped (lon, "activate", G_CALLBACK(a_dialog_response_accept), dialog); gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); @@ -144,11 +145,11 @@ gboolean a_dialog_goto_utm ( GtkWindow *parent, struct UTM *utm, const struct UT gtk_widget_show_all ( zonehbox ); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), norlabel, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), nor, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), easlabel, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), eas, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), zonehbox, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), norlabel, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), nor, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), easlabel, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), eas, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), zonehbox, FALSE, FALSE, 0); gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); @@ -174,277 +175,6 @@ void a_dialog_response_accept ( GtkDialog *dialog ) gtk_dialog_response ( dialog, GTK_RESPONSE_ACCEPT ); } -static void symbol_entry_changed_cb(GtkWidget *combo, GtkListStore *store) -{ - GtkTreeIter iter; - gchar *sym; - - if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) - return; - - gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 ); - /* Note: symm is NULL when "(none)" is select (first cell is empty) */ - gtk_widget_set_tooltip_text(combo, sym); - g_free(sym); -} - -/* Specify if a new waypoint or not */ -/* If a new waypoint then it uses the default_name for the suggested name allowing the user to change it. - The name to use is returned - When an existing waypoint the default name is shown but is not allowed to be changed and NULL is returned - */ -/* todo: less on this side, like add track */ -gchar *a_dialog_waypoint ( GtkWindow *parent, gchar *default_name, VikWaypoint *wp, VikCoordMode coord_mode, gboolean is_new, gboolean *updated ) -{ - GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Waypoint Properties"), - parent, - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CANCEL, - GTK_RESPONSE_REJECT, - GTK_STOCK_OK, - GTK_RESPONSE_ACCEPT, - NULL); - struct LatLon ll; - GtkWidget *latlabel, *lonlabel, *namelabel, *latentry, *lonentry, *altentry, *altlabel, *nameentry=NULL; - GtkWidget *commentlabel, *commententry, *descriptionlabel, *descriptionentry, *imagelabel, *imageentry, *symbollabel, *symbolentry; - GtkListStore *store; - - gchar *lat, *lon, *alt; - - vik_coord_to_latlon ( &(wp->coord), &ll ); - - lat = g_strdup_printf ( "%f", ll.lat ); - lon = g_strdup_printf ( "%f", ll.lon ); - vik_units_height_t height_units = a_vik_get_units_height (); - switch (height_units) { - case VIK_UNITS_HEIGHT_METRES: - alt = g_strdup_printf ( "%f", wp->altitude ); - break; - case VIK_UNITS_HEIGHT_FEET: - alt = g_strdup_printf ( "%f", VIK_METERS_TO_FEET(wp->altitude) ); - break; - default: - alt = g_strdup_printf ( "%f", wp->altitude ); - g_critical("Houston, we've had a problem. height=%d", height_units); - } - - *updated = FALSE; - - namelabel = gtk_label_new (_("Name:")); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), namelabel, FALSE, FALSE, 0); - if ( is_new ) - { - // New waypoint, so name is still changeable - nameentry = gtk_entry_new (); - if ( default_name ) - gtk_entry_set_text( GTK_ENTRY(nameentry), default_name ); - g_signal_connect_swapped ( nameentry, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) ); - } - else { - // Existing waypoint - so can not change the name this way - but at least can see it - if ( default_name ) - nameentry = gtk_label_new ( default_name ); - } - if ( nameentry ) - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), nameentry, FALSE, FALSE, 0); - - latlabel = gtk_label_new (_("Latitude:")); - latentry = gtk_entry_new (); - gtk_entry_set_text ( GTK_ENTRY(latentry), lat ); - g_free ( lat ); - - lonlabel = gtk_label_new (_("Longitude:")); - lonentry = gtk_entry_new (); - gtk_entry_set_text ( GTK_ENTRY(lonentry), lon ); - g_free ( lon ); - - altlabel = gtk_label_new (_("Altitude:")); - altentry = gtk_entry_new (); - gtk_entry_set_text ( GTK_ENTRY(altentry), alt ); - g_free ( alt ); - - commentlabel = gtk_label_new (_("Comment:")); - commententry = gtk_entry_new (); - gchar *cmt = NULL; - // Auto put in some kind of 'name' as a comment if one previously 'goto'ed this exact location - cmt = a_vik_goto_get_search_string_for_this_place(VIK_WINDOW(parent)); - if (cmt) - gtk_entry_set_text(GTK_ENTRY(commententry), cmt); - - descriptionlabel = gtk_label_new (_("Description:")); - descriptionentry = gtk_entry_new (); - - imagelabel = gtk_label_new (_("Image:")); - imageentry = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN); - - { - GtkCellRenderer *r; - symbollabel = gtk_label_new (_("Symbol:")); - GtkTreeIter iter; - - store = gtk_list_store_new(3, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING); - symbolentry = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); - gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(symbolentry), 6); - - g_signal_connect(symbolentry, "changed", G_CALLBACK(symbol_entry_changed_cb), store); - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, NULL, 1, NULL, 2, _("(none)"), -1); - a_populate_sym_list(store); - - r = gtk_cell_renderer_pixbuf_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (symbolentry), r, FALSE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (symbolentry), r, "pixbuf", 1, NULL); - - r = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (symbolentry), r, FALSE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (symbolentry), r, "text", 2, NULL); - - if ( !is_new && wp->symbol ) { - gboolean ok; - gchar *sym; - 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)) { - gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 ); - if (sym && !strcmp(sym, wp->symbol)) { - g_free(sym); - break; - } else { - g_free(sym); - } - } - // Ensure is it a valid symbol in the given symbol set (large vs small) - // Not all symbols are available in both - // The check prevents a Gtk Critical message - if ( iter.stamp ) - gtk_combo_box_set_active_iter(GTK_COMBO_BOX(symbolentry), &iter); - } - } - - if ( !is_new && wp->comment ) - gtk_entry_set_text ( GTK_ENTRY(commententry), wp->comment ); - - if ( !is_new && wp->description ) - gtk_entry_set_text ( GTK_ENTRY(descriptionentry), wp->description ); - - if ( !is_new && wp->image ) - vik_file_entry_set_filename ( VIK_FILE_ENTRY(imageentry), wp->image ); - - - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), latlabel, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), latentry, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lonlabel, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lonentry, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), altlabel, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), altentry, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), commentlabel, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), commententry, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), descriptionlabel, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), descriptionentry, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), imagelabel, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), imageentry, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), symbollabel, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), GTK_WIDGET(symbolentry), FALSE, FALSE, 0); - - gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); - - gtk_widget_show_all ( GTK_DIALOG(dialog)->vbox ); - - while ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) - { - if ( is_new ) - { - if ( strlen((gchar*)gtk_entry_get_text ( GTK_ENTRY(nameentry) )) == 0 ) /* TODO: other checks (isalpha or whatever ) */ - a_dialog_info_msg ( parent, _("Please enter a name for the waypoint.") ); - else { - // NB: No check for unique names - this allows generation of same named entries. - gchar *entered_name = g_strdup ( (gchar*)gtk_entry_get_text ( GTK_ENTRY(nameentry) ) ); - - /* Do It */ - ll.lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(latentry) ) ); - ll.lon = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lonentry) ) ); - vik_coord_load_from_latlon ( &(wp->coord), coord_mode, &ll ); - // Always store in metres - switch (height_units) { - case VIK_UNITS_HEIGHT_METRES: - wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ); - break; - case VIK_UNITS_HEIGHT_FEET: - wp->altitude = VIK_FEET_TO_METERS(atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) )); - break; - default: - wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ); - g_critical("Houston, we've had a problem. height=%d", height_units); - } - vik_waypoint_set_comment ( wp, gtk_entry_get_text ( GTK_ENTRY(commententry) ) ); - vik_waypoint_set_description ( wp, gtk_entry_get_text ( GTK_ENTRY(descriptionentry) ) ); - vik_waypoint_set_image ( wp, vik_file_entry_get_filename ( VIK_FILE_ENTRY(imageentry) ) ); - if ( wp->image && *(wp->image) && (!a_thumbnails_exists(wp->image)) ) - a_thumbnails_create ( wp->image ); - - GtkTreeIter iter, first; - gtk_tree_model_get_iter_first ( GTK_TREE_MODEL(store), &first ); - if ( !gtk_combo_box_get_active_iter ( GTK_COMBO_BOX(symbolentry), &iter ) || !memcmp(&iter, &first, sizeof(GtkTreeIter)) ) { - vik_waypoint_set_symbol ( wp, NULL ); - } else { - gchar *sym; - gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 ); - vik_waypoint_set_symbol ( wp, sym ); - g_free(sym); - } - - gtk_widget_destroy ( dialog ); - return entered_name; - } - } - else - { - ll.lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(latentry) ) ); - ll.lon = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lonentry) ) ); - vik_coord_load_from_latlon ( &(wp->coord), coord_mode, &ll ); - switch (height_units) { - case VIK_UNITS_HEIGHT_METRES: - wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ); - break; - case VIK_UNITS_HEIGHT_FEET: - wp->altitude = VIK_FEET_TO_METERS(atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) )); - break; - default: - wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ); - g_critical("Houston, we've had a problem. height=%d", height_units); - } - if ( (! wp->comment) || strcmp ( wp->comment, gtk_entry_get_text ( GTK_ENTRY(commententry) ) ) != 0 ) - vik_waypoint_set_comment ( wp, gtk_entry_get_text ( GTK_ENTRY(commententry) ) ); - if ( (! wp->description) || strcmp ( wp->description, gtk_entry_get_text ( GTK_ENTRY(descriptionentry) ) ) != 0 ) - vik_waypoint_set_description ( wp, gtk_entry_get_text ( GTK_ENTRY(descriptionentry) ) ); - if ( (! wp->image) || strcmp ( wp->image, vik_file_entry_get_filename ( VIK_FILE_ENTRY ( imageentry ) ) ) != 0 ) - { - vik_waypoint_set_image ( wp, vik_file_entry_get_filename ( VIK_FILE_ENTRY(imageentry) ) ); - if ( wp->image && *(wp->image) && (!a_thumbnails_exists(wp->image)) ) - a_thumbnails_create ( wp->image ); - } - - { - GtkTreeIter iter, first; - gtk_tree_model_get_iter_first ( GTK_TREE_MODEL(store), &first ); - if ( !gtk_combo_box_get_active_iter ( GTK_COMBO_BOX(symbolentry), &iter ) || !memcmp(&iter, &first, sizeof(GtkTreeIter)) ) { - vik_waypoint_set_symbol ( wp, NULL ); - } else { - gchar *sym; - gtk_tree_model_get ( GTK_TREE_MODEL(store), &iter, 0, (void *)&sym, -1 ); - vik_waypoint_set_symbol ( wp, sym ); - g_free(sym); - } - } - - gtk_widget_destroy ( dialog ); - - *updated = TRUE; - return NULL; - } - } - gtk_widget_destroy ( dialog ); - return NULL; -} - static void get_selected_foreach_func(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, @@ -507,7 +237,7 @@ GList *a_dialog_select_from_list ( GtkWindow *parent, GList *names, gboolean mul gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC ); gtk_container_add ( GTK_CONTAINER(scrolledwindow), view ); - gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), scrolledwindow, TRUE, TRUE, 0 ); + gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), scrolledwindow, TRUE, TRUE, 0 ); // Ensure a reasonable number of items are shown, but let the width be automatically sized gtk_widget_set_size_request ( dialog, -1, 400) ; @@ -518,13 +248,13 @@ GList *a_dialog_select_from_list ( GtkWindow *parent, GList *names, gboolean mul while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT ) { - GList *names = NULL; + GList *names_selected = NULL; GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); - gtk_tree_selection_selected_foreach(selection, get_selected_foreach_func, &names); - if (names) + gtk_tree_selection_selected_foreach(selection, get_selected_foreach_func, &names_selected); + if (names_selected) { gtk_widget_destroy ( dialog ); - return (names); + return names_selected; } a_dialog_error_msg(parent, _("Nothing was selected")); } @@ -532,7 +262,7 @@ GList *a_dialog_select_from_list ( GtkWindow *parent, GList *names, gboolean mul return NULL; } -gchar *a_dialog_new_track ( GtkWindow *parent, GHashTable *tracks, gchar *default_name, gboolean is_route ) +gchar *a_dialog_new_track ( GtkWindow *parent, gchar *default_name, gboolean is_route ) { GtkWidget *dialog = gtk_dialog_new_with_buttons ( is_route ? _("Add Route") : _("Add Track"), parent, @@ -548,8 +278,8 @@ gchar *a_dialog_new_track ( GtkWindow *parent, GHashTable *tracks, gchar *defaul if (default_name) gtk_entry_set_text ( GTK_ENTRY(entry), default_name ); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), label, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), label, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), entry, FALSE, FALSE, 0); g_signal_connect_swapped ( entry, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) ); @@ -573,18 +303,75 @@ gchar *a_dialog_new_track ( GtkWindow *parent, GHashTable *tracks, gchar *defaul return NULL; } +static void today_clicked (GtkWidget *cal) +{ + GDateTime *now = g_date_time_new_now_local (); + gtk_calendar_select_month ( GTK_CALENDAR(cal), g_date_time_get_month(now)-1, g_date_time_get_year(now) ); + gtk_calendar_select_day ( GTK_CALENDAR(cal), g_date_time_get_day_of_month(now) ); + g_date_time_unref ( now ); +} + +/** + * a_dialog_get_date: + * + * Returns: a date as a string - always in ISO8601 format (YYYY-MM-DD) + * This string can be NULL (especially when the dialog is cancelled) + * Free the string after use + */ +gchar *a_dialog_get_date ( GtkWindow *parent, const gchar *title ) +{ + GtkWidget *dialog = gtk_dialog_new_with_buttons ( title, + parent, + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_CANCEL, + GTK_RESPONSE_REJECT, + GTK_STOCK_OK, + GTK_RESPONSE_ACCEPT, + NULL); + GtkWidget *cal = gtk_calendar_new (); + GtkWidget *today = gtk_button_new_with_label ( _("Today") ); + + static guint year = 0; + static guint month = 0; + static guint day = 0; + + if ( year != 0 ) { + // restore the last selected date + gtk_calendar_select_month ( GTK_CALENDAR(cal), month, year ); + gtk_calendar_select_day ( GTK_CALENDAR(cal), day ); + } + + gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), today, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), cal, FALSE, FALSE, 0); + + g_signal_connect_swapped ( G_OBJECT(today), "clicked", G_CALLBACK(today_clicked), cal ); + + gtk_widget_show_all ( dialog ); + + gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); + + gchar *date_str = NULL; + if ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT ) + { + gtk_calendar_get_date ( GTK_CALENDAR(cal), &year, &month, &day ); + date_str = g_strdup_printf ( "%d-%02d-%02d", year, month+1, day ); + } + gtk_widget_destroy ( dialog ); + return date_str; +} + /* creates a vbox full of labels */ -GtkWidget *a_dialog_create_label_vbox ( gchar **texts, int label_count ) +GtkWidget *a_dialog_create_label_vbox ( gchar **texts, int label_count, gint spacing, gint padding ) { GtkWidget *vbox, *label; int i; - vbox = gtk_vbox_new( TRUE, 3 ); + vbox = gtk_vbox_new( TRUE, spacing ); for ( i = 0; i < label_count; i++ ) { label = gtk_label_new(NULL); gtk_label_set_markup ( GTK_LABEL(label), _(texts[i]) ); - gtk_box_pack_start ( GTK_BOX(vbox), label, FALSE, TRUE, 5 ); + gtk_box_pack_start ( GTK_BOX(vbox), label, FALSE, TRUE, padding ); } return vbox; } @@ -632,7 +419,7 @@ gboolean a_dialog_custom_zoom ( GtkWindow *parent, gdouble *xmpp, gdouble *ympp GtkWidget *pass_along[3]; table = gtk_table_new ( 4, 2, FALSE ); - gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), table, TRUE, TRUE, 0 ); + gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 ); label = gtk_label_new ( _("Zoom factor (in meters per pixel):") ); xlabel = gtk_label_new ( _("X (easting): ")); @@ -692,7 +479,7 @@ gboolean a_dialog_time_threshold ( GtkWindow *parent, gchar *title_text, gchar * GtkWidget *pass_along[1]; table = gtk_table_new ( 4, 2, FALSE ); - gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), table, TRUE, TRUE, 0 ); + gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, TRUE, TRUE, 0 ); label = gtk_label_new (label_text); @@ -737,8 +524,11 @@ gboolean a_dialog_time_threshold ( GtkWindow *parent, gchar *title_text, gchar * } /** + * a_dialog_get_positive_number: + * * Dialog to return a positive number via a spinbox within the supplied limits - * A return value of zero indicates the dialog was cancelled + * + * 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 ) { @@ -760,7 +550,7 @@ guint a_dialog_get_positive_number ( GtkWindow *parent, gchar *title_text, gchar guint result = default_num; table = gtk_table_new ( 2, 1, FALSE ); - gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), table, TRUE, TRUE, 0 ); + 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 ); @@ -785,6 +575,7 @@ guint a_dialog_get_positive_number ( GtkWindow *parent, gchar *title_text, gchar return 0; } +#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 24) static void about_url_hook (GtkAboutDialog *about, const gchar *link, gpointer data) @@ -798,13 +589,41 @@ static void about_email_hook (GtkAboutDialog *about, { 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-2010, Viking's contributors"; + 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 " @@ -820,8 +639,60 @@ void a_dialog_about ( GtkWindow *parent ) "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, @@ -835,6 +706,7 @@ void a_dialog_about ( GtkWindow *parent ) "authors", AUTHORS, "documenters", DOCUMENTERS, "translator-credits", _("Translation is coordinated on http://launchpad.net/viking"), + "artists", libs, NULL); } @@ -848,24 +720,26 @@ gboolean a_dialog_map_n_zoom(GtkWindow *parent, gchar *mapnames[], gint default_ #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:")); - GtkComboBox *map_combo = GTK_COMBO_BOX(gtk_combo_box_new_text()); + GtkWidget *map_combo = vik_combo_box_text_new(); for (s = mapnames; *s; s++) - gtk_combo_box_append_text(map_combo, *s); - gtk_combo_box_set_active (map_combo, default_map); + 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:")); - GtkComboBox *zoom_combo = GTK_COMBO_BOX(gtk_combo_box_new_text()); + GtkWidget *zoom_combo = vik_combo_box_text_new(); for (s = zoom_list; *s; s++) - gtk_combo_box_append_text(zoom_combo, *s); - gtk_combo_box_set_active (zoom_combo, default_zoom); + 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, GTK_WIDGET(map_label), 0, 1, 0, 1); - gtk_table_attach_defaults(box, GTK_WIDGET(map_combo), 1, 2, 0, 1); - gtk_table_attach_defaults(box, GTK_WIDGET(zoom_label), 0, 1, 1, 2); - gtk_table_attach_defaults(box, GTK_WIDGET(zoom_combo), 1, 2, 1, 2); + 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(dialog)->vbox), GTK_WIDGET(box), FALSE, FALSE, 5 ); + 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 ); @@ -876,8 +750,8 @@ gboolean a_dialog_map_n_zoom(GtkWindow *parent, gchar *mapnames[], gint default_ return FALSE; } - *selected_map = gtk_combo_box_get_active(map_combo); - *selected_zoom = gtk_combo_box_get_active(zoom_combo); + *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; @@ -896,8 +770,7 @@ void a_dialog_license ( GtkWindow *parent, const gchar *map, const gchar *licens _("The map data is licensed: %s."), license); gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog), - _("The data provided by '%s' are licensed under the following license: %s.\n" - "Please, read the license before continuing."), + _("The data provided by '%s' are licensed under the following license: %s."), map, license); #define RESPONSE_OPEN_LICENSE 600 if (url != NULL) {