X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/8499a412948056d494f375f55a0a330b9e826c0a..cca9f97b05c31a51ce886d5b14db93aa741cd95e:/src/dialog.c?ds=inline diff --git a/src/dialog.c b/src/dialog.c index eb91244a..c5068c81 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -28,7 +28,8 @@ #include "garminsymbols.h" #include "degrees_converters.h" #include "authors.h" -#include "googlesearch.h" +#include "vikgoto.h" +#include "util.h" #include @@ -93,7 +94,7 @@ gboolean a_dialog_goto_latlon ( GtkWindow *parent, struct LatLon *ll, const stru gboolean a_dialog_goto_utm ( GtkWindow *parent, struct UTM *utm, const struct UTM *old ) { - GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to Lat/Lon"), + GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Go to UTM"), parent, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, @@ -120,7 +121,7 @@ gboolean a_dialog_goto_utm ( GtkWindow *parent, struct UTM *utm, const struct UT zonehbox = gtk_hbox_new ( FALSE, 0 ); gtk_box_pack_start ( GTK_BOX(zonehbox), gtk_label_new ( _("Zone:") ), FALSE, FALSE, 5 ); - zonespin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( old->zone, 1, 60, 1, 5, 5 ), 1, 0 ); + zonespin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( old->zone, 1, 60, 1, 5, 0 ), 1, 0 ); gtk_box_pack_start ( GTK_BOX(zonehbox), zonespin, TRUE, TRUE, 5 ); gtk_box_pack_start ( GTK_BOX(zonehbox), gtk_label_new ( _("Letter:") ), FALSE, FALSE, 5 ); letterentry = gtk_entry_new (); @@ -166,10 +167,24 @@ 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); +} + /* todo: less on this side, like add track */ gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *wp, GHashTable *waypoints, VikCoordMode coord_mode ) { - GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Create"), + GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Waypoint Properties"), parent, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, @@ -191,7 +206,18 @@ gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *w lat = g_strdup_printf ( "%f", ll.lat ); lon = g_strdup_printf ( "%f", ll.lon ); - alt = g_strdup_printf ( "%f", wp->altitude ); + 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", wp->altitude*3.2808399 ); + break; + default: + alt = g_strdup_printf ( "%f", wp->altitude ); + g_critical("Houston, we've had a problem. height=%d", height_units); + } if ( dest != NULL ) { @@ -224,12 +250,13 @@ gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *w commentlabel = gtk_label_new (_("Comment:")); commententry = gtk_entry_new (); - gchar *cmt = a_googlesearch_get_search_string_for_this_place(VIK_WINDOW(parent)); + gchar *cmt = NULL; + cmt = a_vik_goto_get_search_string_for_this_place(VIK_WINDOW(parent)); if (cmt) gtk_entry_set_text(GTK_ENTRY(commententry), cmt); imagelabel = gtk_label_new (_("Image:")); - imageentry = vik_file_entry_new (); + imageentry = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN); { GtkCellRenderer *r; @@ -238,7 +265,9 @@ gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *w 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), 3); + 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); @@ -308,7 +337,19 @@ gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *w 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 ); - wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ); + // Always store in metres + switch (height_units) { + case VIK_UNITS_HEIGHT_METRES: + wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ); + alt = g_strdup_printf ( "%f", wp->altitude ); + break; + case VIK_UNITS_HEIGHT_FEET: + wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ) / 3.2808399; + 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_image ( wp, vik_file_entry_get_filename ( VIK_FILE_ENTRY(imageentry) ) ); if ( wp->image && *(wp->image) && (!a_thumbnails_exists(wp->image)) ) @@ -337,7 +378,18 @@ gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *w 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 ); - wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ); + switch (height_units) { + case VIK_UNITS_HEIGHT_METRES: + wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ); + alt = g_strdup_printf ( "%f", wp->altitude ); + break; + case VIK_UNITS_HEIGHT_FEET: + wp->altitude = atof ( gtk_entry_get_text ( GTK_ENTRY(altentry) ) ) / 3.2808399; + 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->image) || strcmp ( wp->image, vik_file_entry_get_filename ( VIK_FILE_ENTRY ( imageentry ) ) ) != 0 ) @@ -369,6 +421,72 @@ gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *w return FALSE; } +static void get_selected_foreach_func(GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + gpointer data) +{ + GList **list = data; + gchar *name; + gtk_tree_model_get (model, iter, 0, &name, -1); + *list = g_list_prepend(*list, name); +} + +GList *a_dialog_select_from_list ( GtkWindow *parent, GHashTable *tracks, GList *track_names, gboolean multiple_selection_allowed, const gchar *title, const gchar *msg ) +{ + GtkTreeIter iter; + GtkCellRenderer *renderer; + GtkWidget *view; + + 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 *label = gtk_label_new ( msg ); + GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING); + + GList *track_runner = track_names; + while (track_runner) + { + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, 0, track_runner->data, -1); + track_runner = g_list_next(track_runner); + } + + view = gtk_tree_view_new(); + renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_insert_column_with_attributes( GTK_TREE_VIEW(view), -1, NULL, renderer, "text", 0, NULL); + gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store)); + gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(view), FALSE); + gtk_tree_selection_set_mode( gtk_tree_view_get_selection(GTK_TREE_VIEW(view)), + multiple_selection_allowed ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_BROWSE ); + g_object_unref(store); + + gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), label, FALSE, FALSE, 0); + gtk_widget_show ( label ); + gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), view, FALSE, FALSE, 0); + gtk_widget_show ( view ); + + while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT ) + { + GList *names = 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_widget_destroy ( dialog ); + return (names); + } + a_dialog_error_msg(parent, _("Nothing was selected")); + } + gtk_widget_destroy ( dialog ); + return NULL; +} + gchar *a_dialog_new_track ( GtkWindow *parent, GHashTable *tracks ) { GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Add Track"), @@ -474,12 +592,12 @@ gboolean a_dialog_custom_zoom ( GtkWindow *parent, gdouble *xmpp, gdouble *ympp table = gtk_table_new ( 4, 2, FALSE ); gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), table, TRUE, TRUE, 0 ); - label = gtk_label_new ( _("Zoom factor (in meters per pixel:") ); + label = gtk_label_new ( _("Zoom factor (in meters per pixel):") ); xlabel = gtk_label_new ( _("X (easting): ")); ylabel = gtk_label_new ( _("Y (northing): ")); - pass_along[0] = xspin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *xmpp, VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM, 1, 5, 5 ), 1, 8 ); - pass_along[1] = yspin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *ympp, VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM, 1, 5, 5 ), 1, 8 ); + 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 ); + 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 ); pass_along[2] = samecheck = gtk_check_button_new_with_label ( _("X and Y zoom factors must be equal") ); /* TODO -- same factor */ @@ -541,7 +659,7 @@ gboolean a_dialog_time_threshold ( GtkWindow *parent, gchar *title_text, gchar * pass_along[0] = t4; - spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( *thr, 0, 65536, 1, 5, 5 ), 1, 0 ); + 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 ); @@ -572,32 +690,28 @@ gboolean a_dialog_time_threshold ( GtkWindow *parent, gchar *title_text, gchar * return FALSE; } +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); +} void a_dialog_about ( GtkWindow *parent ) { - int re; - char *msg = g_markup_printf_escaped ( - _(_("Viking %s\n\n" - "GPS Data and Topo Analyzer, Explorer, and Manager.\n\n" - "(C) 2003-2007, Evan Battaglia\n\n" - "Web site: %s")), - VIKING_VERSION, VIKING_URL); - GtkWidget *msgbox = gtk_message_dialog_new_with_markup ( parent, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, - GTK_BUTTONS_NONE, - msg); - - gtk_dialog_add_buttons (GTK_DIALOG(msgbox), _("Credits"), 1, _("License"), 2, _("Close"), 3, NULL, NULL); - - while ((re = gtk_dialog_run ( GTK_DIALOG(msgbox))) != 3) { - if (re==1) { - /* creds */ - a_dialog_info_msg(parent, AUTHORS); - } - if (re==2) { - a_dialog_info_msg(parent, _("\n\n" - "This program is free software; you can redistribute it and/or modify " + 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 *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." @@ -609,10 +723,22 @@ void a_dialog_about ( GtkWindow *parent ) "\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")); - } - } - gtk_widget_destroy ( msgbox ); + "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA"); + + gtk_about_dialog_set_url_hook (about_url_hook, NULL, NULL); + gtk_about_dialog_set_email_hook (about_email_hook, NULL, NULL); + 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, + 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)