~ubuntu-branches/debian/squeeze/f-spot/squeeze

« back to all changes in this revision

Viewing changes to src/FileImportBackend.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane, Mirco Bauer, Iain Lane
  • Date: 2009-02-07 20:23:32 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20090207202332-oc93rfjo1st0571s
Tags: 0.5.0.3-2
[ Mirco Bauer]
* Upload to unstable.
* debian/control:
  + Lowered GNOME# build-deps to 2.0 ABI as that transition didn't happen
    yet in unstable.

[ Iain Lane ]
* debian/patches/svn-r4545_locales-import.dpatch: Patch backported from SVN
  trunk revision 4545 - initialize the translation catalog earlier (LP: #293305)
  (Closes: #514457). Thanks to Florian Heinle for finding the patch and to
  Chris Coulson for preparing the update.
* debian/control: Build-depend on libmono-dev (>= 1.2.4) to match configure
  checks.
* debian/rules: Pass CSC=/usr/bin/csc to configure for gio-sharp to fix FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
        TagStore tag_store = FSpot.Core.Database.Tags;
24
24
        bool recurse;
25
25
        bool copy;
 
26
        bool detect_duplicates;
26
27
        string [] base_paths;
27
28
        Tag [] tags;
28
29
        Gtk.Window parent;
29
30
 
30
31
        int count;
 
32
        int duplicate_count;
31
33
        XmpTagsImporter xmptags;
32
34
 
33
35
        ArrayList import_info;
74
76
 
75
77
        private void GetListing (System.IO.DirectoryInfo dirinfo, System.IO.FileInfo [] files, bool recurse)
76
78
        {
77
 
                System.Console.WriteLine ("Scanning {0}", dirinfo.FullName);
 
79
                Log.DebugFormat ("Scanning {0} for new photos", dirinfo.FullName);
78
80
                List<Uri> existing_entries = new List<Uri> ();
79
81
 
80
 
                foreach (Photo p in store.Query (dirinfo)) {
81
 
                        foreach (uint id in p.VersionIds) {
 
82
                foreach (Photo p in store.Query (new Uri (dirinfo.FullName)))
 
83
                        foreach (uint id in p.VersionIds)
82
84
                                existing_entries.Add (p.VersionUri (id));
83
 
                        }
84
 
                }
85
85
 
86
 
                foreach (System.IO.FileInfo f in files) {
 
86
                foreach (System.IO.FileInfo f in files)
87
87
                        if (! existing_entries.Contains (UriUtils.PathToFileUri (f.FullName)) && !f.Name.StartsWith (".")) {
88
88
                                AddPath (f.FullName);
89
89
                        }
90
 
                }
91
90
 
92
91
                if (recurse) {
93
92
                        foreach (System.IO.DirectoryInfo d in dirinfo.GetDirectories ()){
120
119
                xmptags = new XmpTagsImporter (store, tag_store);
121
120
 
122
121
                roll = rolls.Create ();
 
122
                Photo.ResetMD5Cache ();
123
123
 
124
124
                return import_info.Count;
125
125
        }
194
194
                return dest;
195
195
        }
196
196
 
197
 
        public override bool Step (out Photo photo, out Pixbuf thumbnail, out int count)
 
197
        public override bool Step (out StepStatusInfo status_info)
198
198
        {
199
 
                thumbnail = null;
 
199
                Photo photo = null;
 
200
                Pixbuf thumbnail = null;
 
201
                bool is_duplicate = false;
200
202
 
201
203
                if (import_info == null)
202
204
                        throw new ImportException ("Prepare() was not called");
212
214
                        string destination = info.OriginalPath;
213
215
                        if (copy)
214
216
                                destination = ChooseLocation (info.OriginalPath, directories);
215
 
                        
 
217
 
216
218
                        // Don't copy if we are already home
217
219
                        if (info.OriginalPath == destination) {
218
220
                                info.DestinationPath = destination;
219
 
                                photo = store.Create (info.DestinationPath, roll.Id, out thumbnail);
 
221
 
 
222
                                if (detect_duplicates)
 
223
                                        photo = store.CheckForDuplicate (UriUtils.PathToFileUri (destination));
 
224
 
 
225
                                if (photo == null)
 
226
                                        photo = store.Create (info.DestinationPath, roll.Id, out thumbnail);
 
227
                                else
 
228
                                        is_duplicate = true;
220
229
                        } else {
221
230
                                System.IO.File.Copy (info.OriginalPath, destination);
222
231
                                info.DestinationPath = destination;
223
232
 
224
 
                                photo = store.Create (info.DestinationPath, info.OriginalPath, roll.Id, out thumbnail);
225
 
 
226
 
                                try {
227
 
                                        File.SetAttributes (destination, File.GetAttributes (info.DestinationPath) & ~FileAttributes.ReadOnly);
228
 
                                        DateTime create = File.GetCreationTime (info.OriginalPath);
229
 
                                        File.SetCreationTime (info.DestinationPath, create);
230
 
                                        DateTime mod = File.GetLastWriteTime (info.OriginalPath);
231
 
                                        File.SetLastWriteTime (info.DestinationPath, mod);
232
 
                                } catch (IOException) {
233
 
                                        // we don't want an exception here to be fatal.
 
233
                                if (detect_duplicates)
 
234
                                        photo = store.CheckForDuplicate (UriUtils.PathToFileUri (destination));
 
235
 
 
236
                                if (photo == null)
 
237
                                {
 
238
                                        photo = store.Create (info.DestinationPath, info.OriginalPath, roll.Id, out thumbnail);
 
239
                                        
 
240
 
 
241
                                        try {
 
242
                                                File.SetAttributes (destination, File.GetAttributes (info.DestinationPath) & ~FileAttributes.ReadOnly);
 
243
                                                DateTime create = File.GetCreationTime (info.OriginalPath);
 
244
                                                File.SetCreationTime (info.DestinationPath, create);
 
245
                                                DateTime mod = File.GetLastWriteTime (info.OriginalPath);
 
246
                                                File.SetLastWriteTime (info.DestinationPath, mod);
 
247
                                        } catch (IOException) {
 
248
                                                // we don't want an exception here to be fatal.
 
249
                                        }
 
250
                                }
 
251
                                else
 
252
                                {
 
253
                                        is_duplicate = true; 
 
254
                                        System.IO.File.Delete (destination);
234
255
                                }
235
256
                        } 
236
257
 
237
 
                        if (tags != null) {
238
 
                                foreach (Tag t in tags) {
239
 
                                        photo.AddTag (t);
 
258
                        if (!is_duplicate)
 
259
                        {
 
260
                                if (tags != null) {
 
261
                                        foreach (Tag t in tags) {
 
262
                                                photo.AddTag (t);
 
263
                                        }
 
264
                                        needs_commit = true;
240
265
                                }
241
 
                                needs_commit = true;
 
266
 
 
267
                                needs_commit |= xmptags.Import (photo, info.DestinationPath, info.OriginalPath);
 
268
 
 
269
                                if (needs_commit)
 
270
                                        store.Commit(photo);
 
271
 
 
272
                                info.Photo = photo;
242
273
                        }
243
 
 
244
 
                        needs_commit |= xmptags.Import (photo, info.DestinationPath, info.OriginalPath);
245
 
 
246
 
                        if (needs_commit)
247
 
                                store.Commit(photo);
248
 
                        
249
 
                        info.Photo = photo;
250
274
                } catch (System.Exception e) {
251
275
                        System.Console.WriteLine ("Error importing {0}{2}{1}", info.OriginalPath, e.ToString (), Environment.NewLine);
252
276
                        if (thumbnail != null)
269
293
                }
270
294
 
271
295
                this.count ++;
272
 
                count = this.count;
 
296
 
 
297
                if (is_duplicate)
 
298
                        this.duplicate_count ++;
 
299
 
 
300
                status_info = new StepStatusInfo (photo, thumbnail, this.count, is_duplicate);
273
301
 
274
302
                return (!abort && count != import_info.Count);
275
303
        }
325
353
 
326
354
                import_info = null;
327
355
                xmptags.Finish();
328
 
                count = 0;
329
 
        //rolls.EndImport();    // Clean up the imported session.
 
356
                Photo.ResetMD5Cache ();
 
357
 
 
358
                if (count == duplicate_count)
 
359
                        rolls.Remove (roll);
 
360
 
 
361
                count = duplicate_count = 0;
 
362
                //rolls.EndImport();    // Clean up the imported session.
330
363
        }
331
364
 
332
 
        public FileImportBackend (PhotoStore store, string [] base_paths, bool recurse, Gtk.Window parent) : this (store, base_paths, false, recurse, null, parent) {}
333
 
 
334
 
        public FileImportBackend (PhotoStore store, string [] base_paths, bool copy, bool recurse, Tag [] tags, Gtk.Window parent)
 
365
        public FileImportBackend (PhotoStore store, string [] base_paths, bool recurse, Gtk.Window parent) : this (store, base_paths, false, recurse, false, null, parent) {}
 
366
 
 
367
        public FileImportBackend (PhotoStore store, string [] base_paths, bool copy, bool recurse, Tag [] tags, Gtk.Window parent) : this (store, base_paths, copy, recurse, false, null, parent) {}
 
368
 
 
369
        public FileImportBackend (PhotoStore store, string [] base_paths, bool copy, bool recurse, bool detect_duplicates, Tag [] tags, Gtk.Window parent)
335
370
        {
336
371
                this.store = store;
337
372
                this.copy = copy;
338
373
                this.base_paths = base_paths;
339
374
                this.recurse = recurse;
 
375
                this.detect_duplicates = detect_duplicates;
340
376
                this.tags = tags;
341
377
                this.parent = parent;
342
378
        }