]> git.street.me.uk Git - andy/viking.git/blobdiff - src/viktrwlayer_geotag.c
Add Refresh to consider reloading a Mapnik Rendering configuration.
[andy/viking.git] / src / viktrwlayer_geotag.c
index f867be33f8cd9fc262dc9534941dd73939038a6c..09f151662d2ea0759df50ad2832ac2e9235b99cf 100644 (file)
@@ -91,6 +91,7 @@ typedef struct {
        GtkWidget *dialog;
        VikFileList *files;
        VikTrwLayer *vtl;    // to pass on
+       VikWaypoint *wpt;    // Use specified waypoint or otherwise the track(s) if NULL
        VikTrack *track;     // Use specified track or all tracks if NULL
        GtkCheckButton *create_waypoints_b;
        GtkLabel *overwrite_waypoints_l; // Referenced so the sensitivity can be changed
@@ -132,6 +133,7 @@ typedef struct {
 typedef struct {
        VikTrwLayer *vtl;
        gchar *image;
+       VikWaypoint *wpt;    // Use specified waypoint or otherwise the track(s) if NULL
        VikTrack *track;     // Use specified track or all tracks if NULL
        // User options...
        option_values_t ov;
@@ -265,7 +267,28 @@ static void trw_layer_geotag_track ( const gpointer id, VikTrack *track, geotag_
                        options->altitude = trkpt->altitude + ((trkpt_next->altitude - trkpt->altitude) * scale);
                        break;
                }
-                       
+       }
+}
+
+/**
+ * Simply align the images the waypoint position
+ */
+static void trw_layer_geotag_waypoint ( geotag_options_t *options )
+{
+       // Write EXIF if specified - although a fairly useless process if you've turned it off!
+       if ( options->ov.write_exif ) {
+               gboolean has_gps_exif = FALSE;
+               gchar* datetime = a_geotag_get_exif_date_from_file ( options->image, &has_gps_exif );
+               // If image already has gps info - don't attempt to change it unless forced
+               if ( options->ov.overwrite_gps_exif || !has_gps_exif ) {
+                       gint ans = a_geotag_write_exif_gps ( options->image, options->wpt->coord, options->wpt->altitude, options->ov.no_change_mtime );
+                       if ( ans != 0 ) {
+                               gchar *message = g_strdup_printf ( _("Failed updating EXIF on %s"), options->image );
+                               vik_window_statusbar_update ( VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(options->vtl)), message, VIK_STATUSBAR_INFO );
+                               g_free ( message );
+                       }
+               }
+               g_free ( datetime );
        }
 }
 
@@ -280,6 +303,11 @@ static void trw_layer_geotag_process ( geotag_options_t *options )
        if ( !options->image )
                return;
 
+       if ( options->wpt ) {
+               trw_layer_geotag_waypoint ( options );
+               return;
+       }
+
        gboolean has_gps_exif = FALSE;
        gchar* datetime = a_geotag_get_exif_date_from_file ( options->image, &has_gps_exif );
 
@@ -382,7 +410,12 @@ static void trw_layer_geotag_process ( geotag_options_t *options )
 
                        // Write EXIF if specified
                        if ( options->ov.write_exif ) {
-                               a_geotag_write_exif_gps ( options->image, options->coord, options->altitude, options->ov.no_change_mtime );
+                               gint ans = a_geotag_write_exif_gps ( options->image, options->coord, options->altitude, options->ov.no_change_mtime );
+                               if ( ans != 0 ) {
+                                       gchar *message = g_strdup_printf ( _("Failed updating EXIF on %s"), options->image );
+                                       vik_window_statusbar_update ( VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(options->vtl)), message, VIK_STATUSBAR_INFO );
+                                       g_free ( message );
+                               }
                        }
                }
        }
@@ -421,6 +454,7 @@ static int trw_layer_geotag_thread ( geotag_options_t *options, gpointer threadd
 
        if ( options->redraw ) {
                if ( IS_VIK_LAYER(options->vtl) ) {
+                       trw_layer_calculate_bounds_waypoints ( options->vtl );
                        // Ensure any new images get shown
                        trw_layer_verify_thumbnails ( options->vtl, NULL ); // NB second parameter not used ATM
                        // Force redraw as verify only redraws if there are new thumbnails (they may already exist)
@@ -445,6 +479,7 @@ static void trw_layer_geotag_response_cb ( GtkDialog *dialog, gint resp, GeoTagW
                // Get options
                geotag_options_t *options = g_malloc ( sizeof(geotag_options_t) );
                options->vtl = widgets->vtl;
+               options->wpt = widgets->wpt;
                options->track = widgets->track;
                // Values extracted from the widgets:
                options->ov.create_waypoints = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(widgets->create_waypoints_b) );
@@ -481,13 +516,14 @@ static void trw_layer_geotag_response_cb ( GtkDialog *dialog, gint resp, GeoTagW
                gchar *tmp = g_strdup_printf ( _("Geotagging %d Images..."), len );
 
                // Processing lots of files can take time - so run a background effort
-               a_background_thread ( VIK_GTK_WINDOW_FROM_LAYER(options->vtl),
-                                                         tmp,
-                                                         (vik_thr_func) trw_layer_geotag_thread,
-                                                         options,
-                                                         (vik_thr_free_func) trw_layer_geotag_thread_free,
-                                                         NULL,
-                                                         len );
+               a_background_thread ( BACKGROUND_POOL_LOCAL,
+                                     VIK_GTK_WINDOW_FROM_LAYER(options->vtl),
+                                     tmp,
+                                     (vik_thr_func) trw_layer_geotag_thread,
+                                     options,
+                                     (vik_thr_free_func) trw_layer_geotag_thread_free,
+                                     NULL,
+                                     len );
 
                g_free ( tmp );
 
@@ -538,7 +574,10 @@ static void create_waypoints_b_cb ( GtkWidget *gw, GeoTagWidgets *gtw )
  * @track: Optional - The particular track to use (if specified) for correlating images
  * @track_name: Optional - The name of specified track to use
  */
-void trw_layer_geotag_dialog ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *track, const gchar *track_name )
+void trw_layer_geotag_dialog ( GtkWindow *parent,
+                               VikTrwLayer *vtl,
+                               VikWaypoint *wpt,
+                               VikTrack *track )
 {
        GeoTagWidgets *widgets = geotag_widgets_new();
 
@@ -548,8 +587,13 @@ void trw_layer_geotag_dialog ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *tr
                                                                                                        GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
                                                                                                        GTK_STOCK_OK,     GTK_RESPONSE_ACCEPT,
                                                                                                        NULL );
-       widgets->files = VIK_FILE_LIST(vik_file_list_new ( _("Images") )); // TODO would be nice to be able to set a filefilter
+       GtkFileFilter *filter = gtk_file_filter_new ();
+       gtk_file_filter_set_name ( filter, _("JPG") );
+       gtk_file_filter_add_mime_type ( filter, "image/jpeg");
+
+       widgets->files = VIK_FILE_LIST(vik_file_list_new ( _("Images"), filter ));
        widgets->vtl = vtl;
+       widgets->wpt = wpt;
        widgets->track = track;
        widgets->create_waypoints_b = GTK_CHECK_BUTTON ( gtk_check_button_new () );
        widgets->overwrite_waypoints_l = GTK_LABEL ( gtk_label_new ( _("Overwrite Existing Waypoints:") ) );
@@ -589,7 +633,8 @@ void trw_layer_geotag_dialog ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *tr
        g_signal_connect ( G_OBJECT(widgets->create_waypoints_b), "toggled", G_CALLBACK(create_waypoints_b_cb), widgets );
 
        GtkWidget *cw_hbox = gtk_hbox_new ( FALSE, 0 );
-       gtk_box_pack_start ( GTK_BOX(cw_hbox), gtk_label_new ( _("Create Waypoints:") ), FALSE, FALSE, 5 );
+       GtkWidget *create_waypoints_l = gtk_label_new ( _("Create Waypoints:") );
+       gtk_box_pack_start ( GTK_BOX(cw_hbox), create_waypoints_l, FALSE, FALSE, 5 );
        gtk_box_pack_start ( GTK_BOX(cw_hbox), GTK_WIDGET(widgets->create_waypoints_b), FALSE, FALSE, 5 );
 
        GtkWidget *ow_hbox = gtk_hbox_new ( FALSE, 0 );
@@ -609,22 +654,39 @@ void trw_layer_geotag_dialog ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *tr
        gtk_box_pack_start ( GTK_BOX(fm_hbox), GTK_WIDGET(widgets->no_change_mtime_b), FALSE, FALSE, 5 );
 
        GtkWidget *is_hbox = gtk_hbox_new ( FALSE, 0 );
-       gtk_box_pack_start ( GTK_BOX(is_hbox), gtk_label_new ( _("Interpolate Between Track Segments:") ), FALSE, FALSE, 5 );
+       GtkWidget *interpolate_segments_l = gtk_label_new ( _("Interpolate Between Track Segments:") );
+       gtk_box_pack_start ( GTK_BOX(is_hbox), interpolate_segments_l, FALSE, FALSE, 5 );
        gtk_box_pack_start ( GTK_BOX(is_hbox), GTK_WIDGET(widgets->interpolate_segments_b), FALSE, FALSE, 5 );
 
        GtkWidget *to_hbox = gtk_hbox_new ( FALSE, 0 );
-       gtk_box_pack_start ( GTK_BOX(to_hbox), gtk_label_new ( _("Image Time Offset (Seconds):") ), FALSE, FALSE, 5 );
+       GtkWidget *time_offset_l = gtk_label_new ( _("Image Time Offset (Seconds):") );
+       gtk_box_pack_start ( GTK_BOX(to_hbox), time_offset_l, FALSE, FALSE, 5 );
        gtk_box_pack_start ( GTK_BOX(to_hbox), GTK_WIDGET(widgets->time_offset_b), FALSE, FALSE, 5 );
        gtk_widget_set_tooltip_text ( GTK_WIDGET(widgets->time_offset_b), _("The number of seconds to ADD to the photos time to make it match the GPS data. Calculate this with (GPS - Photo). Can be negative or positive. Useful to adjust times when a camera's timestamp was incorrect.") );
 
        GtkWidget *tz_hbox = gtk_hbox_new ( FALSE, 0 );
-       gtk_box_pack_start ( GTK_BOX(tz_hbox), gtk_label_new ( _("Image Timezone:") ), FALSE, FALSE, 5 );
+       GtkWidget *time_zone_l = gtk_label_new ( _("Image Timezone:") );
+       gtk_box_pack_start ( GTK_BOX(tz_hbox), time_zone_l, FALSE, FALSE, 5 );
        gtk_box_pack_start ( GTK_BOX(tz_hbox), GTK_WIDGET(widgets->time_zone_b), FALSE, FALSE, 5 );
        gtk_widget_set_tooltip_text ( GTK_WIDGET(widgets->time_zone_b), _("The timezone that was used when the images were created. For example, if a camera is set to AWST or +8:00 hours. Enter +8:00 here so that the correct adjustment to the images' time can be made. GPS data is always in UTC.") );
 
        gchar *track_string = NULL;
-       if ( widgets->track )
-               track_string = g_strdup_printf ( _("Using track: %s"), track_name );
+       if ( widgets->wpt ) {
+               track_string = g_strdup_printf ( _("Using waypoint: %s"), wpt->name );
+               // Control sensitivities
+               gtk_widget_set_sensitive ( GTK_WIDGET(widgets->create_waypoints_b), FALSE );
+               gtk_widget_set_sensitive ( GTK_WIDGET(create_waypoints_l), FALSE );
+               gtk_widget_set_sensitive ( GTK_WIDGET(widgets->overwrite_waypoints_b), FALSE );
+               gtk_widget_set_sensitive ( GTK_WIDGET(widgets->overwrite_waypoints_l), FALSE );
+               gtk_widget_set_sensitive ( GTK_WIDGET(widgets->interpolate_segments_b), FALSE );
+               gtk_widget_set_sensitive ( GTK_WIDGET(interpolate_segments_l), FALSE );
+               gtk_widget_set_sensitive ( GTK_WIDGET(widgets->time_offset_b), FALSE );
+               gtk_widget_set_sensitive ( GTK_WIDGET(time_offset_l), FALSE );
+               gtk_widget_set_sensitive ( GTK_WIDGET(widgets->time_zone_b), FALSE );
+               gtk_widget_set_sensitive ( GTK_WIDGET(time_zone_l), FALSE );
+       }
+       else if ( widgets->track )
+               track_string = g_strdup_printf ( _("Using track: %s"), track->name );
        else
                track_string = g_strdup_printf ( _("Using all tracks in: %s"), VIK_LAYER(widgets->vtl)->name );