X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/7760b0cf65bcc0e133c0e968b669c1f3e5012020..3e9ca23e1344df0bd26ba826048f41bf136ddc1f:/src/dialog.c diff --git a/src/dialog.c b/src/dialog.c index bcd0fc35..a3c4bdba 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -28,7 +28,13 @@ #include "garminsymbols.h" #include "degrees_converters.h" #include "authors.h" +#ifdef VIK_CONFIG_GOOGLE #include "googlesearch.h" +#endif +#ifdef VIK_CONFIG_GEONAMES +#include "geonamessearch.h" +#endif +#include "util.h" #include @@ -166,10 +172,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, @@ -197,6 +217,11 @@ gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *w { namelabel = gtk_label_new (_("Name:")); nameentry = gtk_entry_new (); + if ( *dest ) { + gtk_entry_set_text( GTK_ENTRY(nameentry), *dest ); + g_free ( *dest ); + *dest = NULL; + } g_signal_connect_swapped ( nameentry, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) ); gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), namelabel, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), nameentry, FALSE, FALSE, 0); @@ -219,12 +244,20 @@ 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; +#if defined(VIK_CONFIG_GOOGLE) && VIK_CONFIG_SEARCH==VIK_CONFIG_SEARCH_GOOGLE + //if (strcmp(VIK_CONFIG_SEARCH,"google")) + cmt = a_googlesearch_get_search_string_for_this_place(VIK_WINDOW(parent)); +#endif +#if defined(VIK_CONFIG_GEONAMES) && VIK_CONFIG_SEARCH==VIK_CONFIG_SEARCH_GEONAMES + //if (strcmp(VIK_CONFIG_SEARCH,"geonames")) + cmt = a_geonamessearch_get_search_string_for_this_place(VIK_WINDOW(parent)); +#endif 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; @@ -233,7 +266,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); @@ -292,12 +327,8 @@ gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *w if ( strlen(constname) == 0 ) /* TODO: other checks (isalpha or whatever ) */ a_dialog_info_msg ( parent, _("Please enter a name for the waypoint.") ); else { - int i; gchar *name = g_strdup ( constname ); - for ( i = strlen ( name ) - 1; i >= 0; i-- ) - name[i] = toupper(name[i]); /* all caps for stardandization */ - if ( g_hash_table_lookup ( waypoints, name ) && !a_dialog_overwrite ( parent, _("The waypoint \"%s\" exists, do you want to overwrite it?"), name ) ) g_free ( name ); else @@ -368,6 +399,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"), @@ -396,10 +493,6 @@ gchar *a_dialog_new_track ( GtkWindow *parent, GHashTable *tracks ) a_dialog_info_msg ( parent, _("Please enter a name for the track.") ); else { gchar *name = g_strdup ( constname ); - gint i; - - for ( i = strlen ( name ) - 1; i >= 0; i-- ) - name[i] = toupper(name[i]); /* all caps for stardandization */ if ( g_hash_table_lookup( tracks, name ) && !a_dialog_overwrite ( parent, _("The track \"%s\" exists, do you want to overwrite it?"), gtk_entry_get_text ( GTK_ENTRY(entry) ) ) ) { @@ -575,32 +668,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"; + 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." @@ -612,10 +701,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)