Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public PhotoQuery(PhotoStore store, params IQueryCondition [] conditions)
        {
            this.store = store;
            this.store.ItemsChanged += MarkChanged;
            cache          = new PhotoCache(store, temp_table);
            reverse_lookup = new Dictionary <uint, int> ();
            SetCondition(OrderByTime.OrderByTimeDesc);

            foreach (IQueryCondition condition in conditions)
            {
                SetCondition(condition);
            }

            RequestReload();
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public static Photo [] GetPhotosData(this SelectionData selection_data)
        {
            int size   = sizeof(uint);
            int length = selection_data.Length / size;

            PhotoStore photo_store = App.Instance.Database.Photos;

            Photo [] photos = new Photo [length];

            for (int i = 0; i < length; i++)
            {
                uint id = System.BitConverter.ToUInt32(selection_data.Data, i * size);
                photos [i] = photo_store.Get(id);
            }

            return(photos);
        }
Ejemplo n.º 6
0
        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(Catalog.GetString("Original"), photo.DefaultVersion.Name);
            Assert.AreEqual(uri, photo.DefaultVersion.BaseUri);
            Assert.AreEqual(1, photo.Versions.Count());

            Assert.AreEqual(1, store.TotalPhotos);
        }
Ejemplo n.º 7
0
        // Constructor
        public PhotoQuery(PhotoStore store, params IQueryCondition [] conditions)
        {
            this.store = store;
            // Note: this is to let the query pick up
            //   photos that were added or removed over dbus
            this.store.ItemsAddedOverDBus   += delegate { RequestReload(); };
            this.store.ItemsRemovedOverDBus += delegate { RequestReload(); };
            this.store.ItemsChanged         += MarkChanged;
            cache          = new PhotoCache(store, temp_table);
            reverse_lookup = new Dictionary <uint, int> ();
            SetCondition(OrderByTime.OrderByTimeDesc);

            foreach (IQueryCondition condition in conditions)
            {
                SetCondition(condition);
            }

            store.QueryToTemp(temp_table, (Tag [])null, null, Range, RollSet, RatingRange, OrderByTime);
        }
Ejemplo n.º 8
0
        public void DeleteVersion(uint version_id, bool remove_original, bool keep_file)
        {
            if (version_id == OriginalVersionId && !remove_original)
            {
                throw new Exception("Cannot delete original version");
            }

            System.Uri uri = VersionUri(version_id);

            if (!keep_file)
            {
                if ((new Gnome.Vfs.Uri(uri.ToString())).Exists)
                {
                    if ((new Gnome.Vfs.Uri(uri.ToString()).Unlink()) != Result.Ok)
                    {
                        throw new System.UnauthorizedAccessException();
                    }
                }

                try {
                    string thumb_path = ThumbnailGenerator.ThumbnailPath(uri);
                    System.IO.File.Delete(thumb_path);
                } catch (System.Exception) {
                    //ignore an error here we don't really care.
                }
                PhotoStore.DeleteThumbnail(uri);
            }
            Versions.Remove(version_id);

            changes.RemoveVersion(version_id);

            do
            {
                version_id--;
                if (Versions.ContainsKey(version_id))
                {
                    DefaultVersionId = version_id;
                    break;
                }
            } while (version_id > OriginalVersionId);
        }
Ejemplo n.º 9
0
 public PhotoCache(PhotoStore store, string temp_table)
 {
     this.temp_table = temp_table;
     this.store      = store;
     cache           = new Dictionary <int, Photo[]> ();
 }
Ejemplo n.º 10
0
 // Constructor
 public PhotoQuery(PhotoStore store)
 {
     this.store = store;
     photos     = store.Query((Tag [])null, null, range, roll_set);
 }