]> git.street.me.uk Git - andy/viking.git/blobdiff - src/dialog.c
Add kdtree C code version 0.5.6 from https://code.google.com/p/kdtree/
[andy/viking.git] / src / dialog.c
index 5b7fa7e84f1338b7baaa8e1dfd529f87fdebcb74..1f590ee57b54f69adc252589f7c5b9443b227160 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) 2010-2013, 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
 #include "authors.h"
 #include "documenters.h"
 #include "vikgoto.h"
+#include "vikutils.h"
 #include "util.h"
+#include "geotag_exif.h"
+#include "vikdatetime_edit_dialog.h"
 
 #include <glib/gi18n.h>
 
@@ -179,6 +182,38 @@ void a_dialog_response_accept ( GtkDialog *dialog )
   gtk_dialog_response ( dialog, GTK_RESPONSE_ACCEPT );
 }
 
+static void update_time ( GtkWidget *widget, VikWaypoint *wp )
+{
+  gchar *msg = vu_get_time_string ( &(wp->timestamp), "%c", &(wp->coord), NULL );
+  gtk_button_set_label ( GTK_BUTTON(widget), msg );
+  g_free ( msg );
+}
+
+static VikWaypoint *edit_wp;
+
+static void time_edit_click ( GtkWidget *widget, VikWaypoint *wp )
+{
+  GTimeZone *gtz = g_time_zone_new_local ();
+  time_t mytime = vik_datetime_edit_dialog ( GTK_WINDOW(gtk_widget_get_toplevel(widget)),
+                                             _("Date/Time Edit"),
+                                             wp->timestamp,
+                                             gtz );
+  g_time_zone_unref ( gtz );
+
+  // Was the dialog cancelled?
+  if ( mytime == 0 )
+    return;
+
+  // Otherwise use new value in the edit buffer
+  edit_wp->timestamp = mytime;
+
+  // Clear the previous 'Add' image as now a time is set
+  if ( gtk_button_get_image ( GTK_BUTTON(widget) ) )
+    gtk_button_set_image ( GTK_BUTTON(widget), NULL );
+
+  update_time ( widget, edit_wp );
+}
+
 static void symbol_entry_changed_cb(GtkWidget *combo, GtkListStore *store)
 {
   GtkTreeIter iter;
@@ -212,7 +247,9 @@ gchar *a_dialog_waypoint ( GtkWindow *parent, gchar *default_name, VikTrwLayer *
   GtkWidget *latlabel, *lonlabel, *namelabel, *latentry, *lonentry, *altentry, *altlabel, *nameentry=NULL;
   GtkWidget *commentlabel, *commententry, *descriptionlabel, *descriptionentry, *imagelabel, *imageentry, *symbollabel, *symbolentry;
   GtkWidget *timelabel = NULL;
-  GtkWidget *timevaluelabel = NULL; // No editing of time allowed ATM
+  GtkWidget *timevaluebutton = NULL;
+  GtkWidget *hasGeotagCB = NULL;
+  GtkWidget *consistentGeotagCB = NULL;
   GtkListStore *store;
 
   gchar *lat, *lon, *alt;
@@ -322,25 +359,56 @@ 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->image )
+  if ( !is_new && 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) );
+    }
+  }
+
+  timelabel = gtk_label_new ( _("Time:") );
+  timevaluebutton = gtk_button_new();
+  gtk_button_set_relief ( GTK_BUTTON(timevaluebutton), GTK_RELIEF_NONE );
+
+  if ( !edit_wp )
+    edit_wp = vik_waypoint_new ();
+  edit_wp = vik_waypoint_copy ( wp );
+
+  // TODO: Consider if there should be a remove time button...
+
   if ( !is_new && wp->has_timestamp ) {
-    gchar tmp_str[64];
-    timelabel = gtk_label_new ( _("Time:") );
-    timevaluelabel = gtk_label_new ( NULL );
-    strftime ( tmp_str, sizeof(tmp_str), "%c", localtime(&(wp->timestamp)) );
-    gtk_label_set_text ( GTK_LABEL(timevaluelabel), tmp_str );
+    update_time ( timevaluebutton, wp );
+  }
+  else {
+    GtkWidget *img = gtk_image_new_from_stock ( GTK_STOCK_ADD, GTK_ICON_SIZE_MENU );
+    gtk_button_set_image ( GTK_BUTTON(timevaluebutton), img );
+    // Initially use current time or otherwise whatever the last value used was
+    if ( edit_wp->timestamp == 0 ) {
+      time ( &edit_wp->timestamp );
+    }
   }
+  g_signal_connect ( G_OBJECT(timevaluebutton), "clicked", G_CALLBACK(time_edit_click), edit_wp );
 
   gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), latlabel, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), latentry, 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))), lonentry, FALSE, FALSE, 0);
-  if ( timelabel ) {
-    gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), timelabel, FALSE, FALSE, 0);
-    gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), timevaluelabel, FALSE, FALSE, 0);
-  }
+  gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), timelabel, FALSE, FALSE, 0);
+  gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), timevaluebutton, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), altlabel, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), altentry, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), commentlabel, FALSE, FALSE, 0);
@@ -349,6 +417,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);
+  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);
 
@@ -393,6 +467,10 @@ gchar *a_dialog_waypoint ( GtkWindow *parent, gchar *default_name, VikTrwLayer *
         vik_waypoint_set_image ( wp, vik_file_entry_get_filename ( VIK_FILE_ENTRY(imageentry) ) );
       if ( wp->image && *(wp->image) && (!a_thumbnails_exists(wp->image)) )
         a_thumbnails_create ( wp->image );
+      if ( edit_wp->timestamp ) {
+        wp->timestamp = edit_wp->timestamp;
+        wp->has_timestamp = TRUE;
+      }
 
       GtkTreeIter iter, first;
       gtk_tree_model_get_iter_first ( GTK_TREE_MODEL(store), &first );
@@ -495,13 +573,13 @@ GList *a_dialog_select_from_list ( GtkWindow *parent, GList *names, gboolean mul
 
   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));
-    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 );
-      return (names);
+      return names_selected;
     }
     a_dialog_error_msg(parent, _("Nothing was selected"));
   }
@@ -550,6 +628,14 @@ gchar *a_dialog_new_track ( GtkWindow *parent, gchar *default_name, gboolean is_
   return NULL;
 }
 
+static void today_clicked (GtkWidget *cal)
+{
+  GDateTime *now = g_date_time_new_now_local ();
+  gtk_calendar_select_month ( GTK_CALENDAR(cal), g_date_time_get_month(now)-1, g_date_time_get_year(now) );
+  gtk_calendar_select_day ( GTK_CALENDAR(cal), g_date_time_get_day_of_month(now) );
+  g_date_time_unref ( now );
+}
+
 /**
  * a_dialog_get_date:
  *
@@ -568,22 +654,32 @@ gchar *a_dialog_get_date ( GtkWindow *parent, const gchar *title )
                                                     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 ) {
+    // 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);
 
-  gtk_widget_show ( cal );
+  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 )
   {
-    guint year;
-    guint month;
-    guint day;
     gtk_calendar_get_date ( GTK_CALENDAR(cal), &year, &month, &day );
-    month = month+1;
-    date_str = g_strdup_printf ( "%d-%02d-%02d", year, month, day );
+    date_str = g_strdup_printf ( "%d-%02d-%02d", year, month+1, day );
   }
   gtk_widget_destroy ( dialog );
   return date_str;