]> git.street.me.uk Git - andy/viking.git/blobdiff - src/dialog.c
gtk_object_sink has been deprecated since gtk version 2.10, use g_object_ref_sink...
[andy/viking.git] / src / dialog.c
index 891c34307c7f3ced0591b907bbb68ecc16173557..641355595ebbba072762270d26519576a2395199 100644 (file)
@@ -2,6 +2,8 @@
  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
  *
  * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
  *
  * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
+ * Copyright (C) 2008, Hein Ragas <viking@ragas.nl>
+ * Copyright (C) 2010, Rob Norris <rw_norris@hotmail.com>
  *
  * 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
  *
  * 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
@@ -28,6 +30,7 @@
 #include "garminsymbols.h"
 #include "degrees_converters.h"
 #include "authors.h"
 #include "garminsymbols.h"
 #include "degrees_converters.h"
 #include "authors.h"
+#include "documenters.h"
 #include "vikgoto.h"
 #include "util.h"
 
 #include "vikgoto.h"
 #include "util.h"
 
@@ -80,6 +83,8 @@ gboolean a_dialog_goto_latlon ( GtkWindow *parent, struct LatLon *ll, const stru
   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(dialog)->vbox), lonlabel,  FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), lon,  FALSE, FALSE, 0);
 
+  gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
+
   if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
   {
     ll->lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lat) ) );
   if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
   {
     ll->lat = convert_dms_to_dec ( gtk_entry_get_text ( GTK_ENTRY(lat) ) );
@@ -94,7 +99,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 )
 {
 
 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,
                                                   parent,
                                                   GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                                   GTK_STOCK_CANCEL,
@@ -121,7 +126,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 );
 
   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 ();
   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 ();
@@ -145,6 +150,8 @@ gboolean a_dialog_goto_utm ( GtkWindow *parent, struct UTM *utm, const struct UT
   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(dialog)->vbox), eas,  FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), zonehbox,  FALSE, FALSE, 0);
 
+  gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
+
   if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
   {
     const gchar *letter;
   if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
   {
     const gchar *letter;
@@ -181,8 +188,13 @@ static void symbol_entry_changed_cb(GtkWidget *combo, GtkListStore *store)
   g_free(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 */
 /* todo: less on this side, like add track */
-gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *wp, GHashTable *waypoints, VikCoordMode coord_mode )
+gchar *a_dialog_waypoint ( GtkWindow *parent, gchar *default_name, VikWaypoint *wp, GHashTable *waypoints, VikCoordMode coord_mode, gboolean is_new, gboolean *updated )
 {
   GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Waypoint Properties"),
                                                    parent,
 {
   GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Waypoint Properties"),
                                                    parent,
@@ -197,30 +209,44 @@ gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *w
     *commententry, *imagelabel, *imageentry, *symbollabel, *symbolentry;
   GtkListStore *store;
 
     *commententry, *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 );
   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 );
-  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", 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);
+  }
 
 
-  if ( dest != NULL )
+  *updated = FALSE;
+
+  namelabel = gtk_label_new (_("Name:"));
+  gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), namelabel, FALSE, FALSE, 0);
+  if ( is_new )
   {
   {
-    namelabel = gtk_label_new (_("Name:"));
+    // New waypoint, so name is still changeable
     nameentry = gtk_entry_new ();
     nameentry = gtk_entry_new ();
-    if ( *dest ) {
-      gtk_entry_set_text( GTK_ENTRY(nameentry), *dest );
-      g_free ( *dest );
-      *dest = NULL;
-    }
+    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) );
     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);
   }
   }
+  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 ();
 
   latlabel = gtk_label_new (_("Latitude:"));
   latentry = gtk_entry_new ();
@@ -255,8 +281,8 @@ 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), 6);
     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);
+
+    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);
     gtk_list_store_append (store, &iter);
     gtk_list_store_set (store, &iter, 0, NULL, 1, NULL, 2, _("(none)"), -1);
     a_populate_sym_list(store);
@@ -269,7 +295,7 @@ gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *w
     gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (symbolentry), r, FALSE);
     gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (symbolentry), r, "text", 2, NULL);
 
     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 ( dest == NULL && wp->symbol ) {
+    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)) {
       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)) {
@@ -281,14 +307,18 @@ gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *w
          g_free(sym);
        }
       }
          g_free(sym);
        }
       }
-      gtk_combo_box_set_active_iter(GTK_COMBO_BOX(symbolentry), &iter);
+      // 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 ( dest == NULL && wp->comment )
+  if ( !is_new && wp->comment )
     gtk_entry_set_text ( GTK_ENTRY(commententry), wp->comment );
 
     gtk_entry_set_text ( GTK_ENTRY(commententry), wp->comment );
 
-  if ( dest == NULL && wp->image )
+  if ( !is_new && wp->image )
     vik_file_entry_set_filename ( VIK_FILE_ENTRY(imageentry), wp->image );
 
 
     vik_file_entry_set_filename ( VIK_FILE_ENTRY(imageentry), wp->image );
 
 
@@ -305,28 +335,41 @@ gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *w
   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_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 )
   {
   gtk_widget_show_all ( GTK_DIALOG(dialog)->vbox );
 
   while ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
   {
-    if ( dest )
+    if ( is_new )
     {
     {
-      const gchar *constname = gtk_entry_get_text ( GTK_ENTRY(nameentry) );
-      if ( strlen(constname) == 0 ) /* TODO: other checks (isalpha or whatever ) */
+      const gchar *entered_name = gtk_entry_get_text ( GTK_ENTRY(nameentry) );
+      if ( strlen(entered_name) == 0 ) /* TODO: other checks (isalpha or whatever ) */
         a_dialog_info_msg ( parent, _("Please enter a name for the waypoint.") );
       else {
         a_dialog_info_msg ( parent, _("Please enter a name for the waypoint.") );
       else {
-        gchar *name = g_strdup ( constname );
 
 
-        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 );
+        gchar *use_name = g_strdup ( entered_name );
+
+        if ( g_hash_table_lookup ( waypoints, use_name ) && !a_dialog_yes_or_no ( parent, _("The waypoint \"%s\" exists, do you want to overwrite it?"), use_name ) )
+          g_free ( use_name );
         else
         {
           /* Do It */
         else
         {
           /* Do It */
-          *dest = name;
           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 );
           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) ) );
+           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_image ( wp, vik_file_entry_get_filename ( VIK_FILE_ENTRY(imageentry) ) );
           if ( wp->image && *(wp->image) && (!a_thumbnails_exists(wp->image)) )
           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)) )
@@ -346,7 +389,7 @@ gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *w
          }             
 
           gtk_widget_destroy ( dialog );
          }             
 
           gtk_widget_destroy ( dialog );
-          return TRUE;
+          return use_name;
         }
       } /* else (valid name) */
     }
         }
       } /* else (valid name) */
     }
@@ -355,7 +398,17 @@ 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 );
       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) ) );
+       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->image) || strcmp ( wp->image, vik_file_entry_get_filename ( VIK_FILE_ENTRY ( imageentry ) ) ) != 0 )
       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 )
@@ -379,12 +432,13 @@ gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *w
       }                
 
       gtk_widget_destroy ( dialog );
       }                
 
       gtk_widget_destroy ( dialog );
-
-      return TRUE;
+      
+      *updated = TRUE;
+      return NULL;
     }
   }
   gtk_widget_destroy ( dialog );
     }
   }
   gtk_widget_destroy ( dialog );
-  return FALSE;
+  return NULL;
 }
 
 static void get_selected_foreach_func(GtkTreeModel *model,
 }
 
 static void get_selected_foreach_func(GtkTreeModel *model,
@@ -398,7 +452,7 @@ static void get_selected_foreach_func(GtkTreeModel *model,
   *list = g_list_prepend(*list, name);
 }
 
   *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 )
+GList *a_dialog_select_from_list ( GtkWindow *parent, GList *names, gboolean multiple_selection_allowed, const gchar *title, const gchar *msg )
 {
   GtkTreeIter iter;
   GtkCellRenderer *renderer;
 {
   GtkTreeIter iter;
   GtkCellRenderer *renderer;
@@ -412,30 +466,48 @@ GList *a_dialog_select_from_list ( GtkWindow *parent, GHashTable *tracks, GList
                                                   GTK_STOCK_OK,
                                                   GTK_RESPONSE_ACCEPT,
                                                   NULL);
                                                   GTK_STOCK_OK,
                                                   GTK_RESPONSE_ACCEPT,
                                                   NULL);
-  GtkWidget *label = gtk_label_new ( msg );
+  /* When something is selected then OK */
+  gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
+  GtkWidget *response_w = NULL;
+#if GTK_CHECK_VERSION (2, 20, 0)
+  /* Default to not apply - as initially nothing is selected! */
+  response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_REJECT );
+#endif
   GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING);
 
   GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING);
 
-  GList *track_runner = track_names;
-  while (track_runner)
+  GtkWidget *scrolledwindow;
+
+  GList *runner = names;
+  while (runner)
   {
     gtk_list_store_append(store, &iter);
   {
     gtk_list_store_append(store, &iter);
-    gtk_list_store_set(store, &iter, 0, track_runner->data, -1);
-    track_runner = g_list_next(track_runner);
+    gtk_list_store_set(store, &iter, 0, runner->data, -1);
+    runner = g_list_next(runner);
   }
 
   view = gtk_tree_view_new();
   renderer = gtk_cell_renderer_text_new();
   }
 
   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);
+  // Use the column header to display the message text,
+  // this makes the overall widget allocation simple as treeview takes up all the space
+  gtk_tree_view_insert_column_with_attributes( GTK_TREE_VIEW(view), -1, msg, renderer, "text", 0, NULL);
   gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
   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_view_set_headers_visible( GTK_TREE_VIEW(view), TRUE);
   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_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 );
+  scrolledwindow = gtk_scrolled_window_new ( NULL, NULL );
+  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 );
+  // Ensure a reasonable number of items are shown, but let the width be automatically sized
+  gtk_widget_set_size_request ( dialog, -1, 400) ;
+
+  gtk_widget_show_all ( dialog );
+
+  if ( response_w )
+    gtk_widget_grab_focus ( response_w );
 
   while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
   {
 
   while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
   {
@@ -453,7 +525,7 @@ GList *a_dialog_select_from_list ( GtkWindow *parent, GHashTable *tracks, GList
   return NULL;
 }
 
   return NULL;
 }
 
-gchar *a_dialog_new_track ( GtkWindow *parent, GHashTable *tracks )
+gchar *a_dialog_new_track ( GtkWindow *parent, GHashTable *tracks, gchar *default_name )
 {
   GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Add Track"),
                                                   parent,
 {
   GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Add Track"),
                                                   parent,
@@ -466,6 +538,9 @@ gchar *a_dialog_new_track ( GtkWindow *parent, GHashTable *tracks )
   GtkWidget *label = gtk_label_new ( _("Track Name:") );
   GtkWidget *entry = gtk_entry_new ();
 
   GtkWidget *label = gtk_label_new ( _("Track Name:") );
   GtkWidget *entry = gtk_entry_new ();
 
+  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(dialog)->vbox), label, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry, FALSE, FALSE, 0);
 
@@ -474,6 +549,8 @@ gchar *a_dialog_new_track ( GtkWindow *parent, GHashTable *tracks )
   gtk_widget_show ( label );
   gtk_widget_show ( entry );
 
   gtk_widget_show ( label );
   gtk_widget_show ( entry );
 
+  gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
+
   while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
   {
     const gchar *constname = gtk_entry_get_text ( GTK_ENTRY(entry) );
   while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
   {
     const gchar *constname = gtk_entry_get_text ( GTK_ENTRY(entry) );
@@ -482,7 +559,7 @@ gchar *a_dialog_new_track ( GtkWindow *parent, GHashTable *tracks )
     else {
       gchar *name = g_strdup ( constname );
 
     else {
       gchar *name = g_strdup ( constname );
 
-      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) ) ) )
+      if ( g_hash_table_lookup( tracks, name ) && !a_dialog_yes_or_no ( parent, _("The track \"%s\" exists, do you want to overwrite it?"), gtk_entry_get_text ( GTK_ENTRY(entry) ) ) )
       {
         g_free ( name );
       }
       {
         g_free ( name );
       }
@@ -513,7 +590,7 @@ GtkWidget *a_dialog_create_label_vbox ( gchar **texts, int label_count )
   return vbox;
 }
 
   return vbox;
 }
 
-gboolean a_dialog_overwrite ( GtkWindow *parent, const gchar *message, const gchar *extra )
+gboolean a_dialog_yes_or_no ( GtkWindow *parent, const gchar *message, const gchar *extra )
 {
   GtkWidget *dia;
   dia = gtk_message_dialog_new ( parent,
 {
   GtkWidget *dia;
   dia = gtk_message_dialog_new ( parent,
@@ -558,12 +635,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 );
 
   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): "));
 
   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 */
 
   pass_along[2] = samecheck = gtk_check_button_new_with_label ( _("X and Y zoom factors must be equal") );
   /* TODO -- same factor */
@@ -584,6 +661,8 @@ gboolean a_dialog_custom_zoom ( GtkWindow *parent, gdouble *xmpp, gdouble *ympp
   g_signal_connect ( G_OBJECT(xspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along );
   g_signal_connect ( G_OBJECT(yspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along );
 
   g_signal_connect ( G_OBJECT(xspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along );
   g_signal_connect ( G_OBJECT(yspin), "value-changed", G_CALLBACK(zoom_spin_changed), pass_along );
 
+  gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
+
   if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
   {
     *xmpp = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(xspin) );
   if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
   {
     *xmpp = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(xspin) );
@@ -625,7 +704,7 @@ gboolean a_dialog_time_threshold ( GtkWindow *parent, gchar *title_text, gchar *
 
   pass_along[0] = t4;
 
 
   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 );
 
   gtk_table_attach_defaults ( GTK_TABLE(table), label, 0, 2, 0, 1 );
   gtk_table_attach_defaults ( GTK_TABLE(table), t1, 0, 1, 1, 2 );
@@ -638,6 +717,8 @@ gboolean a_dialog_time_threshold ( GtkWindow *parent, gchar *title_text, gchar *
 
   g_signal_connect ( G_OBJECT(spin), "grab-focus", G_CALLBACK(split_spin_focused), pass_along );
 
 
   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))) {
   if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
   {
     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t1))) {
@@ -656,6 +737,55 @@ gboolean a_dialog_time_threshold ( GtkWindow *parent, gchar *title_text, gchar *
   return FALSE;
 }
 
   return FALSE;
 }
 
+/**
+ * Dialog to return a positive number via a spinbox within the supplied limits
+ * A return 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(dialog)->vbox), 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;
+}
+
 static void about_url_hook (GtkAboutDialog *about,
                             const gchar    *link,
                             gpointer        data)
 static void about_url_hook (GtkAboutDialog *about,
                             const gchar    *link,
                             gpointer        data)
@@ -675,7 +805,7 @@ void a_dialog_about ( GtkWindow *parent )
   const gchar *program_name = PACKAGE_NAME;
   const gchar *version = VIKING_VERSION;
   const gchar *website = VIKING_URL;
   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 *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 "
   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 "
@@ -704,6 +834,8 @@ void a_dialog_about ( GtkWindow *parent )
        "wrap-license", TRUE,
        /* logo automatically retrieved via gtk_window_get_default_icon_list */
        "authors", AUTHORS,
        "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"),
        NULL);
 }
 
        NULL);
 }
 
@@ -712,7 +844,11 @@ gboolean a_dialog_map_n_zoom(GtkWindow *parent, gchar *mapnames[], gint default_
   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 );
   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:"));
   GtkComboBox *map_combo = GTK_COMBO_BOX(gtk_combo_box_new_text());
   for (s = mapnames; *s; s++)
   GtkWidget *map_label = gtk_label_new(_("Map type:"));
   GtkComboBox *map_combo = GTK_COMBO_BOX(gtk_combo_box_new_text());
   for (s = mapnames; *s; s++)
@@ -732,6 +868,9 @@ gboolean a_dialog_map_n_zoom(GtkWindow *parent, gchar *mapnames[], gint default_
 
   gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), GTK_WIDGET(box), FALSE, FALSE, 5 );
 
 
   gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), 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);
   gtk_widget_show_all ( dialog );
   if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) != GTK_RESPONSE_ACCEPT ) {
     gtk_widget_destroy(dialog);
@@ -744,3 +883,33 @@ gboolean a_dialog_map_n_zoom(GtkWindow *parent, gchar *mapnames[], gint default_
   gtk_widget_destroy(dialog);
   return TRUE;
 }
   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>.\n"
+    "Please, read the license before continuing."),
+    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);
+}