Пример #1
0
        private bool ChangeThisVersionUri(PhotoVersion version, string old_base, string new_base)
        {
            // Change to path from URI, since easier to compare with old_base which is not in URI format.
            string tmp_path = System.IO.Path.GetDirectoryName(version.Uri.AbsolutePath);

            return(tmp_path.StartsWith(old_base));
        }
Пример #2
0
        private PhotoVersion CreatePhotoVersion(string path, PhotoTypeEnum type, int width, int height)
        {
            var photoVersion = new PhotoVersion();

            photoVersion.Width  = width;
            photoVersion.Height = height;
            photoVersion.Path   = path;
            photoVersion.Type   = type;

            return(photoVersion);
        }
Пример #3
0
        public void UpdateThisUri(int index, string path, ref Photo photo)
        {
            if (photo == null)
            {
                photo = photo_store.Get((uint)photo_id_array[index]) as Photo;
            }
            PhotoVersion version = photo.GetVersion((uint)version_id_array[index]) as PhotoVersion;

            version.Uri = new System.Uri(path);
            photo.Changes.UriChanged = true;
            photo.Changes.ChangeVersion((uint)version_id_array[index]);
        }
Пример #4
0
 void InsertVersion(DbItem photo, PhotoVersion version)
 {
     Database.Execute(new HyenaSqliteCommand(
                          "INSERT OR IGNORE INTO photo_versions (photo_id, version_id, name, base_uri, filename, protected, import_md5) " +
                          "VALUES (?, ?, ?, ?, ?, ?, ?)",
                          photo.Id,
                          version.VersionId,
                          version.Name,
                          version.BaseUri.ToString(),
                          version.Filename,
                          version.IsProtected,
                          (version.ImportMD5 != string.Empty ? version.ImportMD5 : null)));
 }
Пример #5
0
        public void UpdateThisUri(int index, string path, ref Photo photo)
        {
            if (photo == null)
            {
                photo = photo_store.Get(photo_id_array[index]);
            }
            PhotoVersion version = photo.GetVersion((uint)version_id_array[index]) as PhotoVersion;

            version.BaseUri          = new SafeUri(path).GetBaseUri();
            version.Filename         = new SafeUri(path).GetFilename();
            photo.Changes.UriChanged = true;
            photo.Changes.ChangeVersion((uint)version_id_array[index]);
        }
Пример #6
0
        private void SavePhotoVersionToDatabase(int photoId, PhotoVersion version)
        {
            var photoVersion = db.PhotoVersions.Create();

            photoVersion.Width   = version.Width;
            photoVersion.Height  = version.Height;
            photoVersion.Path    = version.Path;
            photoVersion.Type    = version.Type;
            photoVersion.PhotoID = photoId;

            db.PhotoVersions.Add(photoVersion);
            db.SaveChanges();
        }
Пример #7
0
        private void SearchVersionUriToChange(Photo photo, string old_base, string new_base)
        {
            foreach (uint version_id in photo.VersionIds)
            {
                PhotoVersion version = photo.GetVersion(version_id) as PhotoVersion;
                if (ChangeThisVersionUri(version, old_base, new_base))
                {
                    AddVersionToArrays(photo.Id,
                                       version_id,
                                       version.Uri.AbsolutePath,
                                       CreateNewPath(old_base, new_base, version));
                }
//					else
//						System.Console.WriteLine ("L : {0}", version.Uri.AbsolutePath);
            }
        }
Пример #8
0
        private Photo GetDefaultPhoto(Album album)//trebuie modificata asta
        {
            var defaultPhoto = new Photo();

            defaultPhoto.AlbumID = album.ID;

            var photoVersion = new PhotoVersion();

            photoVersion.Path = defaultThumbnailPath;

            photoVersion.Type = PhotoTypeEnum.Thumbnail;

            defaultPhoto.PhotoVersions.Add(photoVersion);

            return(defaultPhoto);
        }
Пример #9
0
        public void Run(object o, EventArgs e)
        {
            Console.WriteLine("EXECUTING ExiflowRunWithExigui Extension");

            string filelist = "";

            foreach (Photo p in App.Instance.Organizer.SelectedPhotos())
            {
                foreach (uint version_id in p.VersionIds)
                {
                    PhotoVersion pv = p.GetVersion(version_id) as PhotoVersion;
                    filelist = filelist + " " + CheapEscape(pv.Uri.AbsolutePath);
                }
                Console.WriteLine(filelist);
            }

            System.Diagnostics.Process exigui = System.Diagnostics.Process.Start("exigui", filelist);
            exigui.WaitForExit();
        }
Пример #10
0
        public void CalculateMD5Sum(Photo photo)
        {
            foreach (uint version_id in photo.VersionIds)
            {
                PhotoVersion version = photo.GetVersion(version_id);

                // Don't overwrite MD5 sums that are already calculated.
                if (version.ImportMD5 != string.Empty && version.ImportMD5 != null)
                {
                    continue;
                }

                string version_md5_sum = HashUtils.GenerateMD5(version.Uri);
                version.ImportMD5 = version_md5_sum;
                photo.Changes.ChangeVersion(version_id);
            }

            Commit(photo);
        }
Пример #11
0
    public void UpdateMD5Sum(Photo photo)
    {
        string md5_sum = Photo.GenerateMD5(photo.VersionUri(Photo.OriginalVersionId));

        photo.MD5Sum = md5_sum;

        Database.ExecuteNonQuery(
            new DbCommand(
                "UPDATE photos " +
                "SET    md5_sum = :md5_sum " +
                "WHERE  ID = :id",
                "md5_sum", md5_sum,
                "id", photo.Id
                )
            );

        foreach (uint version_id in photo.VersionIds)
        {
            if (version_id == Photo.OriginalVersionId)
            {
                continue;
            }

            PhotoVersion version = photo.GetVersion(version_id) as PhotoVersion;

            string version_md5_sum = Photo.GenerateMD5(version.Uri);

            if (version.MD5Sum == version_md5_sum)
            {
                continue;
            }

            version.MD5Sum = version_md5_sum;
            photo.Changes.ChangeVersion(version_id);
        }

        Commit(photo);
    }
Пример #12
0
        void ImportPhoto(Photo photo, bool copy)
        {
            Log.WarningFormat("Importing {0}", photo.Name);
            PhotoStore from_store = from_db.Photos;
            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
                {
                    Console.WriteLine("point me to the file");
                }
                Console.WriteLine("FNF: {0}", photo_path);
            }

            string destination;

            Gdk.Pixbuf pixbuf;
            Photo      newp;

            if (copy)
            {
                destination = FileImportBackend.ChooseLocation(photo_path, null);
            }
            else
            {
                destination = photo_path;
            }

            // Don't copy if we are already home
            if (photo_path == destination)
            {
                newp = to_store.Create(destination, roll_map [photo.RollId], out pixbuf);
            }
            else
            {
                System.IO.File.Copy(photo_path, destination);

                newp = to_store.Create(destination, photo_path, roll_map [photo.RollId], out pixbuf);
                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.
                }
            }

            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.Uri, 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);
        }
Пример #13
0
        PhotoChanges Update(Photo photo)
        {
            PhotoChanges changes = photo.Changes;

            // Update photo.
            if (changes.DescriptionChanged || changes.DefaultVersionIdChanged || changes.TimeChanged || changes.UriChanged || changes.RatingChanged || changes.MD5SumChanged)
            {
                Database.Execute(
                    new HyenaSqliteCommand(
                        "UPDATE photos " +
                        "SET description = ?, " +
                        "    default_version_id = ?, " +
                        "    time = ?, " +
                        "    base_uri = ?, " +
                        "    filename = ?, " +
                        "    rating = ? " +
                        "WHERE id = ? ",
                        photo.Description,
                        photo.DefaultVersionId,
                        DateTimeUtil.FromDateTime(photo.Time),
                        photo.VersionUri(Photo.OriginalVersionId).GetBaseUri().ToString(),
                        photo.VersionUri(Photo.OriginalVersionId).GetFilename(),
                        string.Format("{0}", photo.Rating),
                        photo.Id
                        )
                    );
            }

            // Update tags.
            if (changes.TagsRemoved != null)
            {
                foreach (Tag tag in changes.TagsRemoved)
                {
                    Database.Execute(new HyenaSqliteCommand(
                                         "DELETE FROM photo_tags WHERE photo_id = ? AND tag_id = ?",
                                         photo.Id,
                                         tag.Id));
                }
            }

            if (changes.TagsAdded != null)
            {
                foreach (Tag tag in changes.TagsAdded)
                {
                    Database.Execute(new HyenaSqliteCommand(
                                         "INSERT OR IGNORE INTO photo_tags (photo_id, tag_id) " +
                                         "VALUES (?, ?)",
                                         photo.Id,
                                         tag.Id));
                }
            }

            // Update versions.
            if (changes.VersionsRemoved != null)
            {
                foreach (uint version_id in changes.VersionsRemoved)
                {
                    Database.Execute(new HyenaSqliteCommand(
                                         "DELETE FROM photo_versions WHERE photo_id = ? AND version_id = ?",
                                         photo.Id,
                                         version_id));
                }
            }

            if (changes.VersionsAdded != null)
            {
                foreach (uint version_id in changes.VersionsAdded)
                {
                    PhotoVersion version = photo.GetVersion(version_id);
                    InsertVersion(photo, version);
                }
            }

            if (changes.VersionsModified != null)
            {
                foreach (uint version_id in changes.VersionsModified)
                {
                    PhotoVersion version = photo.GetVersion(version_id);
                    Database.Execute(new HyenaSqliteCommand(
                                         "UPDATE photo_versions SET name = ?, " +
                                         "base_uri = ?, filename = ?, protected = ?, import_md5 = ? " +
                                         "WHERE photo_id = ? AND version_id = ?",
                                         version.Name,
                                         version.BaseUri.ToString(),
                                         version.Filename,
                                         version.IsProtected,
                                         (version.ImportMD5 != string.Empty ? version.ImportMD5 : null),
                                         photo.Id,
                                         version_id));
                }
            }

            photo.Changes = null;
            return(changes);
        }
Пример #14
0
        protected void DevelopPhoto(Photo p)
        {
            LoadPreference(UFRAW_JPEG_QUALITY_KEY);
            LoadPreference(UFRAW_ARGUMENTS_KEY);
            LoadPreference(UFRAW_BATCH_ARGUMENTS_KEY);

            PhotoVersion raw = p.GetVersion(Photo.OriginalVersionId) as PhotoVersion;

            if (!App.Instance.Container.Resolve <IImageFileFactory> ().IsRaw(raw.Uri))
            {
                Log.Warning("The original version of this image is not a (supported) RAW file");
                return;
            }

            string name = GetNextVersionFileName(p);

            System.Uri developed = GetUriForVersionFileName(p, name);
            string     idfile    = "";


            if (ufraw_jpeg_quality < 1 || ufraw_jpeg_quality > 100)
            {
                Log.Debug("Invalid JPEG quality specified, defaulting to quality 98");
                ufraw_jpeg_quality = 98;
            }

            string args = "";

            switch (executable)
            {
            case "ufraw":
                args += ufraw_args;
                if (GLib.FileFactory.NewForUri(Path.ChangeExtension(raw.Uri.ToString(), ".ufraw")).Exists)
                {
                    // We found an ID file, use that instead of the raw file
                    idfile = "--conf=" + GLib.Shell.Quote(Path.ChangeExtension(raw.Uri.LocalPath, ".ufraw"));
                }
                break;

            case "ufraw-batch":
                args += ufraw_batch_args;
                if (GLib.FileFactory.NewForUri(Path.Combine(Global.BaseDirectory, "batch.ufraw")).Exists)
                {
                    // We found an ID file, use that instead of the raw file
                    idfile = "--conf=" + GLib.Shell.Quote(Path.Combine(Global.BaseDirectory, "batch.ufraw"));
                }
                break;
            }

            args += String.Format(" --exif --overwrite --create-id=also --compression={0} --out-type=jpeg {1} --output={2} {3}",
                                  ufraw_jpeg_quality,
                                  idfile,
                                  GLib.Shell.Quote(developed.LocalPath),
                                  GLib.Shell.Quote(raw.Uri.LocalPath));
            Log.Debug(executable + " " + args);

            System.Diagnostics.Process ufraw = System.Diagnostics.Process.Start(executable, args);
            ufraw.WaitForExit();
            if (!(GLib.FileFactory.NewForUri(developed.ToString())).Exists)
            {
                Log.Warning("UFRaw quit with an error. Check that you have UFRaw 0.13 or newer. Or did you simply clicked on Cancel?");
                return;
            }

            if (GLib.FileFactory.NewForUri(Path.ChangeExtension(developed.ToString(), ".ufraw")).Exists)
            {
                // We save our own copy of the last ufraw settings, as ufraw can overwrite it's own last used settings outside f-spot
                File.Delete(Path.Combine(Global.BaseDirectory, "batch.ufraw"));
                File.Copy(Path.ChangeExtension(developed.LocalPath, ".ufraw"), Path.Combine(Global.BaseDirectory, "batch.ufraw"));

                // Rename the ufraw file to match the original RAW filename, instead of the (Developed In UFRaw) filename
                if (!(Path.ChangeExtension(raw.Uri.LocalPath, ".ufraw") == Path.ChangeExtension(developed.LocalPath, ".ufraw")))
                {
                    File.Delete(Path.ChangeExtension(raw.Uri.LocalPath, ".ufraw"));
                    File.Move(Path.ChangeExtension(developed.LocalPath, ".ufraw"), Path.ChangeExtension(raw.Uri.LocalPath, ".ufraw"));
                }
            }

            p.DefaultVersionId    = p.AddVersion(new SafeUri(developed).GetBaseUri(), new SafeUri(developed).GetFilename(), name, true);
            p.Changes.DataChanged = true;
            App.Instance.Database.Photos.Commit(p);
        }
Пример #15
0
 private string CreateNewPath(string old_base, string new_base, PhotoVersion version)
 {
     return(string.Format("{0}{1}", new_base, version.Uri.AbsolutePath.Substring(old_base.Length)));
 }
Пример #16
0
        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);
        }
Пример #17
0
    private PhotoChanges Update(Photo photo)
    {
        PhotoChanges changes = photo.Changes;

        // Update photo.
        if (changes.DescriptionChanged || changes.DefaultVersionIdChanged || changes.TimeChanged || changes.UriChanged || changes.RatingChanged || changes.MD5SumChanged)
        {
            Database.ExecuteNonQuery(
                new DbCommand(
                    "UPDATE photos " +
                    "SET description = :description, " +
                    "    default_version_id = :default_version_id, " +
                    "    time = :time, " +
                    "    uri = :uri, " +
                    "    rating = :rating, " +
                    "    md5_sum = :md5_sum	" +
                    "WHERE id = :id ",
                    "description", photo.Description,
                    "default_version_id", photo.DefaultVersionId,
                    "time", DbUtils.UnixTimeFromDateTime(photo.Time),
                    "uri", photo.VersionUri(Photo.OriginalVersionId).OriginalString,
                    "rating", String.Format("{0}", photo.Rating),
                    "md5_sum", photo.MD5Sum,
                    "id", photo.Id
                    )
                );
        }

        // Update tags.
        if (changes.TagsRemoved != null)
        {
            foreach (Tag tag in changes.TagsRemoved)
            {
                Database.ExecuteNonQuery(new DbCommand(
                                             "DELETE FROM photo_tags WHERE photo_id = :photo_id AND tag_id = :tag_id",
                                             "photo_id", photo.Id,
                                             "tag_id", tag.Id));
            }
        }

        if (changes.TagsAdded != null)
        {
            foreach (Tag tag in changes.TagsAdded)
            {
                Database.ExecuteNonQuery(new DbCommand(
                                             "INSERT OR IGNORE INTO photo_tags (photo_id, tag_id) " +
                                             "VALUES (:photo_id, :tag_id)",
                                             "photo_id", photo.Id,
                                             "tag_id", tag.Id));
            }
        }

        // Update versions.
        if (changes.VersionsRemoved != null)
        {
            foreach (uint version_id in changes.VersionsRemoved)
            {
                Database.ExecuteNonQuery(new DbCommand(
                                             "DELETE FROM photo_versions WHERE photo_id = :photo_id AND version_id = :version_id",
                                             "photo_id", photo.Id,
                                             "version_id", version_id));
            }
        }

        if (changes.VersionsAdded != null)
        {
            foreach (uint version_id in changes.VersionsAdded)
            {
                PhotoVersion version = photo.GetVersion(version_id) as PhotoVersion;
                Database.ExecuteNonQuery(new DbCommand(
                                             "INSERT OR IGNORE INTO photo_versions (photo_id, version_id, name, uri, protected, md5_sum) " +
                                             "VALUES (:photo_id, :version_id, :name, :uri, :is_protected, :md5_sum)",
                                             "photo_id", photo.Id,
                                             "version_id", version_id,
                                             "name", version.Name,
                                             "uri", version.Uri.ToString(),
                                             "is_protected", version.IsProtected,
                                             "md5_sum", version.MD5Sum));
            }
        }
        if (changes.VersionsModified != null)
        {
            foreach (uint version_id in changes.VersionsModified)
            {
                PhotoVersion version = photo.GetVersion(version_id) as PhotoVersion;
                Database.ExecuteNonQuery(new DbCommand(
                                             "UPDATE photo_versions SET name = :name, " +
                                             "uri = :uri, protected = :protected, md5_sum = :md5_sum " +
                                             "WHERE photo_id = :photo_id AND version_id = :version_id",
                                             "name", version.Name,
                                             "uri", version.Uri.ToString(),
                                             "protected", version.IsProtected,
                                             "photo_id", photo.Id,
                                             "md5_sum", version.MD5Sum,
                                             "version_id", version_id));
            }
        }
        photo.Changes = null;
        return(changes);
    }