~meese/pantheon-photos/fix-1273847

« back to all changes in this revision

Viewing changes to src/Photo.vala

  • Committer: madelynn-r-may
  • Date: 2014-09-11 02:45:29 UTC
  • Revision ID: madelynn.r.may@gmail.com-20140911024529-k1fjhjaxffgvnhw0
adds location search entry for setting gps markers and other fixes from review

Show diffs side-by-side

added added

removed removed

Lines of Context:
241
241
 
242
242
        public PhotoTransformationStateImpl (Photo photo, Orientation orientation,
243
243
                                             Gee.HashMap<string, KeyValueMap>? transformations, PixelTransformer? transformer,
244
 
                                             PixelTransformationBundle? adjustments,Gee.HashMap<string, KeyValueMap>? original_transformations, bool enhanced) {
 
244
                                             PixelTransformationBundle? adjustments, Gee.HashMap<string, KeyValueMap>? original_transformations, bool enhanced) {
245
245
            this.photo = photo;
246
246
            this.orientation = orientation;
247
247
            this.transformations = copy_transformations (transformations);
266
266
 
267
267
        public Gee.HashMap<string, KeyValueMap>? get_transformations () {
268
268
            return copy_transformations (transformations);
269
 
        }        
 
269
        }
270
270
 
271
271
        public Gee.HashMap<string, KeyValueMap>? get_original_transformations () {
272
272
            return copy_transformations (original_transformations);
1215
1215
        params.row.master.original_orientation = orientation;
1216
1216
        params.row.import_id = params.import_id;
1217
1217
        params.row.event_id = EventID ();
 
1218
        params.row.location_id = LocationID ();
1218
1219
        params.row.transformations = null;
1219
1220
        params.row.md5 = detected.md5;
1220
1221
        params.row.thumbnail_md5 = detected.thumbnail_md5;
1256
1257
        params.row.master.original_orientation = Orientation.TOP_LEFT;
1257
1258
        params.row.import_id = params.import_id;
1258
1259
        params.row.event_id = EventID ();
 
1260
        params.row.location_id = LocationID ();
1259
1261
        params.row.transformations = null;
1260
1262
        params.row.md5 = null;
1261
1263
        params.row.thumbnail_md5 = null;
1562
1564
        }
1563
1565
 
1564
1566
        if (reimport_state.metadata != null) {
1565
 
            set_gps_coords(reimport_state.metadata.get_gps_coords());
 
1567
            set_gps_coords (reimport_state.metadata.get_gps_coords());
1566
1568
            set_title (reimport_state.metadata.get_title ());
1567
1569
            set_comment (reimport_state.metadata.get_comment ());
1568
1570
            set_rating (reimport_state.metadata.get_rating ());
1973
1975
        return row.event_id;
1974
1976
    }
1975
1977
 
 
1978
    public LocationID get_location_id () {
 
1979
        lock (row) {
 
1980
            return row.location_id;
 
1981
        }
 
1982
    }
 
1983
 
1976
1984
    // This is NOT thread-safe.
1977
1985
    public inline int64 get_raw_event_id () {
1978
1986
        return row.event_id.id;
2144
2152
 
2145
2153
        if (committed)
2146
2154
            notify_altered (new Alteration ("metadata", "master-dirty"));
2147
 
    }    
 
2155
    }
2148
2156
 
2149
2157
    public bool is_enhanced () {
2150
2158
        lock (row) {
2228
2236
        }
2229
2237
    }
2230
2238
 
 
2239
    public bool set_location_id (LocationID location_id) {
 
2240
        lock (row) {
 
2241
            bool committed = PhotoTable.get_instance ().set_location (row.photo_id, location_id);
 
2242
 
 
2243
            if (committed)
 
2244
                row.location_id = location_id;
 
2245
 
 
2246
            return committed;
 
2247
        }
 
2248
    }
 
2249
 
2231
2250
    public override string to_string () {
2232
2251
        return "[%s] %s%s".printf (get_photo_id ().id.to_string (), get_master_reader ().get_filepath (),
2233
2252
                                   !is_master_baseline () ? " (" + get_actual_file ().get_path () + ")" : "");
2564
2583
 
2565
2584
            return adjustments.copy ();
2566
2585
        }
2567
 
    } 
 
2586
    }
2568
2587
 
2569
2588
    // This method *must* be called with row locked.
2570
2589
    private PixelTransformationBundle locked_original_color_adjustments () {
2575
2594
            map = row.original_transforms.get ("adjustments");
2576
2595
            if (map != null)
2577
2596
                map = map.copy ();
2578
 
        } else 
 
2597
        } else
2579
2598
            map = new KeyValueMap ("adjustments");
2580
2599
 
2581
2600
        if (map == null)
2582
2601
            original_adjustments.set_to_identity ();
2583
2602
        else
2584
2603
            original_adjustments.load (map);
2585
 
            
 
2604
 
2586
2605
        return original_adjustments;
2587
2606
    }
2588
2607
 
2592
2611
        lock (row) {
2593
2612
            KeyValueMap map = get_transformation ("adjustments");
2594
2613
            if (map == null)
2595
 
                map = new KeyValueMap("adjustments");
 
2614
                map = new KeyValueMap ("adjustments");
2596
2615
            return map;
2597
2616
        }
2598
2617
    }
2614
2633
        return get_color_adjustments ().get_transformation (type);
2615
2634
    }
2616
2635
 
2617
 
    public void set_color_adjustments (PixelTransformationBundle new_adjustments) {  
 
2636
    public void set_color_adjustments (PixelTransformationBundle new_adjustments) {
2618
2637
        /* if every transformation in 'new_adjustments' is the identity, then just remove all
2619
2638
           adjustments from the database */
2620
2639
        set_enhanced (false);
2964
2983
 
2965
2984
            return PhotoTable.get_instance ().set_original_transforms (row.photo_id, trans);
2966
2985
        }
2967
 
    }    
 
2986
    }
2968
2987
 
2969
2988
    private bool clear_original_transforms () {
2970
2989
        lock (row) {
3609
3628
        debug ("Exporting full-sized copy of %s to %s", to_string (), writer.get_filepath ());
3610
3629
 
3611
3630
        export_reader.get_file ().copy (dest_file,
3612
 
                                       FileCopyFlags.OVERWRITE | FileCopyFlags.TARGET_DEFAULT_PERMS, null, null);
 
3631
                                        FileCopyFlags.OVERWRITE | FileCopyFlags.TARGET_DEFAULT_PERMS, null, null);
3613
3632
 
3614
3633
        // If asking for an full-sized file and there are no alterations (transformations or EXIF)
3615
3634
        // *and* this is a copy of the original backing *and* there's no user metadata or title *and* metadata should be exported, then done
4456
4475
        apply_timer.stop ();
4457
4476
        debug ("Auto-Enhance apply time: %f sec", apply_timer.elapsed ());
4458
4477
#endif
4459
 
        set_enhanced(true);
 
4478
        set_enhanced (true);
4460
4479
        return true;
4461
4480
    }
4462
4481
 
4471
4490
                    transformer = null;
4472
4491
                    if (result)
4473
4492
                        notify_altered (new Alteration ("image", "color-adjustments"));
4474
 
                }
4475
 
                else
 
4493
                } else
4476
4494
                    set_color_adjustments (locked_original_color_adjustments ());
4477
4495
                set_enhanced (false);
4478
4496
                return true;
5007
5025
        thumbnail_scheduler = new OneShotScheduler ("LibraryPhoto", generate_thumbnails);
5008
5026
        // import gps coords of photos imported with prior versions of shotwell
5009
5027
        if (row.gps_coords.has_gps == -1) {
5010
 
            var gps_import_scheduler = new OneShotScheduler("LibraryPhoto", import_gps_metadata);
5011
 
            gps_import_scheduler.at_priority_idle(Priority.LOW);
 
5028
            var gps_import_scheduler = new OneShotScheduler ("LibraryPhoto", import_gps_metadata);
 
5029
            gps_import_scheduler.at_priority_idle (Priority.LOW);
5012
5030
        }
5013
5031
 
5014
5032
        // if marked in a state where they're held in an orphanage, rehydrate their backlinks