]> git.street.me.uk Git - andy/viking.git/blobdiff - src/dialog.c
Remove mistaken need to change directory.
[andy/viking.git] / src / dialog.c
index 3713a63325bad2573fa7f3f7e6208fe4b59b4968..79d0f38b9157987bc904aa1aefd962dbe2760f58 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
  * Copyright (C) 2008, Hein Ragas <viking@ragas.nl>
  *
  * 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>
+ * Copyright (C) 2010-2014, 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
@@ -33,6 +33,7 @@
 #include "documenters.h"
 #include "vikgoto.h"
 #include "util.h"
 #include "documenters.h"
 #include "vikgoto.h"
 #include "util.h"
+#include "geotag_exif.h"
 
 #include <glib/gi18n.h>
 
 
 #include <glib/gi18n.h>
 
@@ -84,6 +85,10 @@ gboolean a_dialog_goto_latlon ( GtkWindow *parent, struct LatLon *ll, const stru
   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);
 
   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 );
 
   if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
   gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
 
   if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
@@ -209,6 +214,8 @@ gchar *a_dialog_waypoint ( GtkWindow *parent, gchar *default_name, VikTrwLayer *
   GtkWidget *commentlabel, *commententry, *descriptionlabel, *descriptionentry, *imagelabel, *imageentry, *symbollabel, *symbolentry;
   GtkWidget *timelabel = NULL;
   GtkWidget *timevaluelabel = NULL; // No editing of time allowed ATM
   GtkWidget *commentlabel, *commententry, *descriptionlabel, *descriptionentry, *imagelabel, *imageentry, *symbollabel, *symbolentry;
   GtkWidget *timelabel = NULL;
   GtkWidget *timevaluelabel = NULL; // No editing of time allowed ATM
+  GtkWidget *hasGeotagCB = NULL;
+  GtkWidget *consistentGeotagCB = NULL;
   GtkListStore *store;
 
   gchar *lat, *lon, *alt;
   GtkListStore *store;
 
   gchar *lat, *lon, *alt;
@@ -268,7 +275,7 @@ gchar *a_dialog_waypoint ( GtkWindow *parent, gchar *default_name, VikTrwLayer *
   descriptionentry = gtk_entry_new ();
 
   imagelabel = gtk_label_new (_("Image:"));
   descriptionentry = gtk_entry_new ();
 
   imagelabel = gtk_label_new (_("Image:"));
-  imageentry = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN);
+  imageentry = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN, VF_FILTER_IMAGE);
 
   {
     GtkCellRenderer *r;
 
   {
     GtkCellRenderer *r;
@@ -318,11 +325,29 @@ gchar *a_dialog_waypoint ( GtkWindow *parent, gchar *default_name, VikTrwLayer *
   if ( !is_new && wp->description )
     gtk_entry_set_text ( GTK_ENTRY(descriptionentry), wp->description );
 
   if ( !is_new && wp->description )
     gtk_entry_set_text ( GTK_ENTRY(descriptionentry), wp->description );
 
-  if ( !is_new && 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 );
 
+    // Geotag Info [readonly]
+    hasGeotagCB = gtk_check_button_new_with_label ( _("Has Geotag") );
+    gtk_widget_set_sensitive ( hasGeotagCB, FALSE );
+    gboolean hasGeotag;
+    gchar *ignore = a_geotag_get_exif_date_from_file ( wp->image, &hasGeotag );
+    g_free ( ignore );
+    gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(hasGeotagCB), hasGeotag );
+
+    consistentGeotagCB = gtk_check_button_new_with_label ( _("Consistent Position") );
+    gtk_widget_set_sensitive ( consistentGeotagCB, FALSE );
+    if ( hasGeotag ) {
+      struct LatLon ll = a_geotag_get_position ( wp->image );
+      VikCoord coord;
+      vik_coord_load_from_latlon ( &coord, coord_mode, &ll );
+      gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(consistentGeotagCB), vik_coord_equals(&coord, &wp->coord) );
+    }
+  }
+
   if ( !is_new && wp->has_timestamp ) {
   if ( !is_new && wp->has_timestamp ) {
-    gchar tmp_str[32];
+    gchar tmp_str[64];
     timelabel = gtk_label_new ( _("Time:") );
     timevaluelabel = gtk_label_new ( NULL );
     strftime ( tmp_str, sizeof(tmp_str), "%c", localtime(&(wp->timestamp)) );
     timelabel = gtk_label_new ( _("Time:") );
     timevaluelabel = gtk_label_new ( NULL );
     strftime ( tmp_str, sizeof(tmp_str), "%c", localtime(&(wp->timestamp)) );
@@ -345,6 +370,12 @@ gchar *a_dialog_waypoint ( GtkWindow *parent, gchar *default_name, VikTrwLayer *
   gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), descriptionentry, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), imagelabel, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), imageentry, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), descriptionentry, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), imagelabel, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), imageentry, FALSE, FALSE, 0);
+  if ( hasGeotagCB ) {
+    GtkWidget *hbox =  gtk_hbox_new ( FALSE, 0 );
+    gtk_box_pack_start (GTK_BOX(hbox), hasGeotagCB, FALSE, FALSE, 0);
+    gtk_box_pack_start (GTK_BOX(hbox), consistentGeotagCB, FALSE, FALSE, 0);
+    gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), hbox, FALSE, FALSE, 0);
+  }
   gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), symbollabel, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), GTK_WIDGET(symbolentry), FALSE, FALSE, 0);
 
   gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), symbollabel, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), GTK_WIDGET(symbolentry), FALSE, FALSE, 0);
 
@@ -491,13 +522,13 @@ GList *a_dialog_select_from_list ( GtkWindow *parent, GList *names, gboolean mul
 
   while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
   {
 
   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));
     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 );
     {
       gtk_widget_destroy ( dialog );
-      return (names);
+      return names_selected;
     }
     a_dialog_error_msg(parent, _("Nothing was selected"));
   }
     }
     a_dialog_error_msg(parent, _("Nothing was selected"));
   }
@@ -505,7 +536,7 @@ GList *a_dialog_select_from_list ( GtkWindow *parent, GList *names, gboolean mul
   return NULL;
 }
 
   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,
 {
   GtkWidget *dialog = gtk_dialog_new_with_buttons ( is_route ? _("Add Route") : _("Add Track"),
                                                   parent,
@@ -546,18 +577,84 @@ gchar *a_dialog_new_track ( GtkWindow *parent, GHashTable *tracks, gchar *defaul
   return NULL;
 }
 
   return NULL;
 }
 
+static guint today_year = 0;
+static guint today_month = 0;
+static guint today_day = 0;
+
+static void today_clicked (GtkWidget *cal)
+{
+  gtk_calendar_select_month ( GTK_CALENDAR(cal), today_month, today_year );
+  gtk_calendar_select_day ( GTK_CALENDAR(cal), today_day );
+}
+
+/**
+ * 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 ) {
+    // Store today's date so we can return to it on the button callback
+    gtk_calendar_get_date ( GTK_CALENDAR(cal), &year, &month, &day );
+    today_year = year;
+    today_month = month;
+    today_day = day;
+  }
+  else {
+    // Otherwise 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 */
 /* 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;
 {
   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]) );
 
   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;
 }
   }
   return vbox;
 }
@@ -710,8 +807,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
  * 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 )
 {
  */
 guint a_dialog_get_positive_number ( GtkWindow *parent, gchar *title_text, gchar *label_text, guint default_num, guint min, guint max, guint step )
 {
@@ -779,7 +879,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\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 "
   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 "
@@ -795,12 +895,54 @@ 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");
 
                        "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_LIBEXIF
+    "libexif",
+#endif
+#ifdef HAVE_LIBX11
+    "libX11",
+#endif
+#ifdef HAVE_LIBMAGIC
+    "libmagic",
+#endif
+#ifdef HAVE_LIBBZ2
+    "libbz2",
+#endif
+#ifdef HAVE_LIBSQLITE3
+    "libsqlite3",
+#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
   // 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,
   gtk_show_about_dialog (parent,
        /* TODO do not set program-name and correctly set info for g_get_application_name */
        "program-name", program_name,
@@ -814,6 +956,7 @@ void a_dialog_about ( GtkWindow *parent )
        "authors", AUTHORS,
        "documenters", DOCUMENTERS,
        "translator-credits", _("Translation is coordinated on http://launchpad.net/viking"),
        "authors", AUTHORS,
        "documenters", DOCUMENTERS,
        "translator-credits", _("Translation is coordinated on http://launchpad.net/viking"),
+       "artists", libs,
        NULL);
 }
 
        NULL);
 }
 
@@ -877,8 +1020,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 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."),
+    _("The data provided by '<b>%s</b>' are licensed under the following license: <b>%s</b>."),
     map, license);
 #define RESPONSE_OPEN_LICENSE 600
   if (url != NULL) {
     map, license);
 #define RESPONSE_OPEN_LICENSE 600
   if (url != NULL) {