public void CreateFromWithVersionIgnored() { var store = new PhotoStore (new FSpotDatabaseConnection (database), true); var photoMock = PhotoMock.CreateWithVersion (uri, originalName, modifiedUri, modifiedName); var photo = store.CreateFrom (photoMock, true, 1); Assert.AreEqual (Catalog.GetString ("Original"), photo.DefaultVersion.Name); Assert.AreEqual (uri, photo.DefaultVersion.BaseUri); // CreateFrom ignores any versions except the default version Assert.AreEqual (1, photo.Versions.Count ()); Assert.AreEqual (1, store.TotalPhotos); }
public void CreateFrom() { var store = new PhotoStore (new FSpotDatabaseConnection (database), true); var photoMock = PhotoMock.Create (uri, originalName); var photo = store.CreateFrom (photoMock, true, 1); // default version name is ignored on import Assert.AreEqual (Catalog.GetString ("Original"), photo.DefaultVersion.Name); Assert.AreEqual (uri, photo.DefaultVersion.BaseUri); Assert.AreEqual (1, photo.Versions.Count ()); Assert.AreEqual (1, store.TotalPhotos); }
void ImportPhoto(IPhoto item, DbItem roll) { if (item is IInvalidPhotoCheck && (item as IInvalidPhotoCheck).IsInvalid) { throw new Exception("Failed to parse metadata, probably not a photo"); } // Do duplicate detection if (DuplicateDetect && store.HasDuplicate(item)) { return; } if (CopyFiles) { var destinationBase = FindImportDestination(item, Global.PhotoUri); EnsureDirectory(destinationBase); // Copy into photo folder. photo_file_tracker.CopyIfNeeded(item, destinationBase); } // Import photo var photo = store.CreateFrom(item, false, roll.Id); bool needs_commit = false; // Add tags if (attach_tags.Count > 0) { photo.AddTag(attach_tags); needs_commit = true; } // Import XMP metadata needs_commit |= metadata_importer.Import(photo, item); if (needs_commit) { store.Commit(photo); } // Prepare thumbnail (Import is I/O bound anyway) ThumbnailLoader.Default.Request(item.DefaultVersion.Uri, ThumbnailSize.Large, 10); imported_photos.Add(photo.Id); }
public void CreateFromWithVersionIgnored() { var databaseConnection = new FSpotDatabaseConnection(database); var dbMock = new Mock <IDb> (); dbMock.Setup(m => m.Database).Returns(databaseConnection); var store = new PhotoStore(null, null, dbMock.Object, true); var photoMock = PhotoMock.CreateWithVersion(uri, originalName, modifiedUri, modifiedName); var photo = store.CreateFrom(photoMock, true, 1); Assert.AreEqual(Strings.Original, photo.DefaultVersion.Name); Assert.AreEqual(uri, photo.DefaultVersion.BaseUri); // CreateFrom ignores any versions except the default version Assert.AreEqual(1, photo.Versions.Count()); Assert.AreEqual(1, store.TotalPhotos); }
public void CreateFrom() { var databaseConnection = new FSpotDatabaseConnection(database); var dbMock = new Mock <IDb> (); dbMock.Setup(m => m.Database).Returns(databaseConnection); var store = new PhotoStore(null, null, dbMock.Object, true); var photoMock = PhotoMock.Create(uri, originalName); var photo = store.CreateFrom(photoMock, true, 1); // default version name is ignored on import Assert.AreEqual(Strings.Original, photo.DefaultVersion.Name); Assert.AreEqual(uri, photo.DefaultVersion.BaseUri); Assert.AreEqual(1, photo.Versions.Count()); Assert.AreEqual(1, store.TotalPhotos); }
public void CreateFromWithVersionAdded() { var databaseConnection = new FSpotDatabaseConnection(database); var dbMock = new Mock <IDb> (); dbMock.Setup(m => m.Database).Returns(databaseConnection); var store = new PhotoStore(null, null, dbMock.Object, true); var photoMock = PhotoMock.CreateWithVersion(uri, originalName, modifiedUri, modifiedName); var photo = store.CreateFrom(photoMock, false, 1); Assert.AreEqual(modifiedName, photo.DefaultVersion.Name); Assert.AreEqual(modifiedUri, photo.DefaultVersion.BaseUri); Assert.AreEqual(2, photo.Versions.Count()); // version id 1 is the first photo added - the original photo Assert.AreEqual(originalName, photo.GetVersion(1).Name); Assert.AreEqual(uri, photo.GetVersion(1).BaseUri); Assert.AreEqual(1, store.TotalPhotos); }
public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window) { string ok_caption = Catalog.GetString("De_tach"); string msg = String.Format(Catalog.GetString("Really detach version \"{0}\" from \"{1}\"?"), photo.DefaultVersion.Name, photo.Name.Replace("_", "__")); string desc = Catalog.GetString("This makes the version appear as a separate photo in the library. To undo, drag the new photo back to its parent."); try { if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent, MessageType.Warning, msg, desc, ok_caption)) { Photo new_photo = store.CreateFrom(photo, photo.RollId); new_photo.CopyAttributesFrom(photo); photo.DeleteVersion(photo.DefaultVersionId, false, true); store.Commit(new Photo[] { new_photo, photo }); return(true); } } catch (Exception e) { HandleException("Could not detach a version", e, parent_window); } return(false); }
public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window) { string ok_caption = Strings.DetachButton; string msg = Strings.ReallyDetachVersionXFromYQuestion(photo.DefaultVersion.Name, photo.Name.Replace("_", "__")); string desc = Strings.ThisMakesTheVersionAppearAsASeperatePhotoInTheLibraryToUndoDragTheNewPhotoBackToItsParent; try { if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent, MessageType.Warning, msg, desc, ok_caption)) { var new_photo = store.CreateFrom(photo, true, photo.RollId); new_photo.CopyAttributesFrom(photo); photo.DeleteVersion(photo.DefaultVersionId, false, true); store.Commit(new Photo[] { new_photo, photo }); return(true); } } catch (Exception e) { HandleException("Could not detach a version", e, parent_window); } return(false); }
void ImportPhoto(Photo photo, bool copy) { Log.WarningFormat("Importing {0}", photo.Name); PhotoStore to_store = to_db.Photos; string photo_path = photo.VersionUri(Photo.OriginalVersionId).AbsolutePath; while (!System.IO.File.Exists(photo_path)) { Log.Debug("Not found, trying the mappings..."); foreach (string key in PathMap.Keys) { string path = photo_path; path = path.Replace(key, PathMap [key]); Log.DebugFormat("Replaced path {0}", path); if (System.IO.File.Exists(path)) { photo_path = path; break;; } } if (System.IO.File.Exists(photo_path)) { Log.Debug("Exists!!!"); continue; } string [] parts = photo_path.Split(new char[] { '/' }); if (parts.Length > 6) { string folder = String.Join("/", parts, 0, parts.Length - 4); PickFolderDialog pfd = new PickFolderDialog(mdd.Dialog, folder); string new_folder = pfd.Run(); pfd.Dialog.Destroy(); if (new_folder == null) //Skip { return; } Log.DebugFormat("{0} maps to {1}", folder, new_folder); PathMap[folder] = new_folder; } else { Log.Debug("point me to the file"); } Log.DebugFormat("FNF: {0}", photo_path); } string destination; Photo newp; if (copy) { destination = FindImportDestination(new Hyena.SafeUri(photo_path), photo.Time).AbsolutePath; } else { destination = photo_path; } var dest_uri = new SafeUri(photo_path); photo.DefaultVersionId = 1; photo.DefaultVersion.Uri = dest_uri; if (photo.DefaultVersion.ImportMD5 == String.Empty) { (photo.DefaultVersion as PhotoVersion).ImportMD5 = HashUtils.GenerateMD5(photo.DefaultVersion.Uri); } if (photo_path != destination) { System.IO.File.Copy(photo_path, destination); try { File.SetAttributes(destination, File.GetAttributes(destination) & ~FileAttributes.ReadOnly); DateTime create = File.GetCreationTime(photo_path); File.SetCreationTime(destination, create); DateTime mod = File.GetLastWriteTime(photo_path); File.SetLastWriteTime(destination, mod); } catch (IOException) { // we don't want an exception here to be fatal. } } //FIXME simplify the following code by letting CreateFrom import all versions // instead of looping over all versions here newp = to_store.CreateFrom(photo, true, roll_map [photo.RollId]); if (newp == null) { return; } foreach (Tag t in photo.Tags) { Log.WarningFormat("Tagging with {0}", t.Name); newp.AddTag(tag_map [t.Id]); } foreach (uint version_id in photo.VersionIds) { if (version_id != Photo.OriginalVersionId) { PhotoVersion version = photo.GetVersion(version_id) as PhotoVersion; uint newv = newp.AddVersion(version.BaseUri, version.Filename, version.Name, version.IsProtected); if (version_id == photo.DefaultVersionId) { newp.DefaultVersionId = newv; } } } //FIXME Import extra info (time, description, rating) newp.Time = photo.Time; newp.Description = photo.Description; newp.Rating = photo.Rating; to_store.Commit(newp); }
public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window) { string ok_caption = Catalog.GetString ("De_tach"); string msg = String.Format (Catalog.GetString ("Really detach version \"{0}\" from \"{1}\"?"), photo.DefaultVersion.Name, photo.Name.Replace("_", "__")); string desc = Catalog.GetString ("This makes the version appear as a separate photo in the library. To undo, drag the new photo back to its parent."); try { if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent, MessageType.Warning, msg, desc, ok_caption)) { Photo new_photo = store.CreateFrom (photo, photo.RollId); new_photo.CopyAttributesFrom (photo); photo.DeleteVersion (photo.DefaultVersionId, false, true); store.Commit (new Photo[] {new_photo, photo}); return true; } } catch (Exception e) { HandleException ("Could not detach a version", e, parent_window); } return false; }
public void CreateFromWithVersionAdded() { var store = new PhotoStore (new FSpotDatabaseConnection (database), true); var photoMock = PhotoMock.CreateWithVersion (uri, originalName, modifiedUri, modifiedName); var photo = store.CreateFrom (photoMock, false, 1); Assert.AreEqual (modifiedName, photo.DefaultVersion.Name); Assert.AreEqual (modifiedUri, photo.DefaultVersion.BaseUri); Assert.AreEqual (2, photo.Versions.Count ()); // version id 1 is the first photo added - the original photo Assert.AreEqual (originalName, photo.GetVersion(1).Name); Assert.AreEqual (uri, photo.GetVersion(1).BaseUri); Assert.AreEqual (1, store.TotalPhotos); }