]> git.street.me.uk Git - andy/viking.git/blobdiff - src/dialog.c
Use less precise images when wanted image is not present
[andy/viking.git] / src / dialog.c
index eb91244a2232b93af1c43047fc66824b9143075a..a3c4bdba27a5b6ff8b053831a312a5c6891d795b 100644 (file)
 #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 <glib/gi18n.h>
 
@@ -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,
@@ -224,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;
@@ -238,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);
@@ -369,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"),
@@ -572,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 (
-    _(_("<span font_desc='20' weight='bold'>Viking %s</span>\n\n"
-    "GPS Data and Topo Analyzer, Explorer, and Manager.\n\n"
-    "<small>(C) 2003-2007, Evan Battaglia</small>\n\n"
-    "<small>Web site: %s</small>")),
-    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."
@@ -609,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)