コード例 #1
0
        // FIXME: Refactor, try to use one common method....
        public void RevertAllUris(int last_index)
        {
            gui_controller.remove_progress_dialog();
            Photo photo = null;

            for (int k = last_index; k >= 0; k--)
            {
                if (gui_controller.UpdateProgressBar("Reverting changes to database", "Reverting photo", last_index))
                {
                }                          // do nothing, ignore trying to abort the revert...
                if ((photo != null) && !StillOnSamePhotoId(k + 1, k, photo_id_array))
                {
                    photo_store.Commit(photo);
                    photo = null;
                }

                UpdateThisUri(k, old_path_array[k], ref photo);
                Log.DebugFormat("R : {0} - {1}", k, old_path_array[k]);
            }
            if (photo != null)
            {
                photo_store.Commit(photo);
            }
            Log.Debug("Changing path failed due to above error. Have reverted any modification that took place.");
        }
コード例 #2
0
 public bool Execute(PhotoStore store, Photo [] photos, Photo new_parent, Gtk.Window parent_window)
 {
     foreach (Photo photo in photos)
     {
         new_parent.AddTag(photo.Tags);
         foreach (uint version_id in photo.VersionIds)
         {
             try {
                 new_parent.DefaultVersionId = new_parent.CreateReparentedVersion(photo.GetVersion(version_id) as PhotoVersion);
                 store.Commit(new_parent);
             } catch (Exception e) {
                 Console.WriteLine(e);
             }
         }
         uint [] version_ids = photo.VersionIds;
         Array.Reverse(version_ids);
         foreach (uint version_id in version_ids)
         {
             try {
                 photo.DeleteVersion(version_id, true, true);
             } catch (Exception e) {
                 Console.WriteLine(e);
             }
         }
         store.Commit(photo);
         MainWindow.Toplevel.Database.Photos.Remove(photo);
     }
     return(true);
 }
コード例 #3
0
        public bool Execute(PhotoStore store, Photo[] photos, Photo new_parent, Gtk.Window parent_window)
        {
            string ok_caption = Strings.ReparentButton;
            string msg        = Catalog.GetPluralString(
                Strings.ReallyReparentXAsVersionOfYQuestion(new_parent.Name.Replace("_", "__"), photos[0].Name.Replace("_", "__")),
                Strings.ReallyReparentXPhotosAsVersionOfYQuestion(new_parent.Name.Replace("_", "__"), photos[0].Name.Replace("_", "__")),
                photos.Length);

            string desc = Strings.ThisMakesThePhotosAppearAsASingleOneInTheLibraryTheVersionsCanBeDetachedUsingThePhotoMenu;

            try {
                if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent,
                                                                           MessageType.Warning, msg, desc, ok_caption))
                {
                    uint   highest_rating  = new_parent.Rating;
                    string new_description = new_parent.Description;
                    foreach (var photo in photos)
                    {
                        highest_rating = Math.Max(photo.Rating, highest_rating);
                        if (string.IsNullOrEmpty(new_description))
                        {
                            new_description = photo.Description;
                        }
                        new_parent.AddTag(photo.Tags);

                        foreach (uint version_id in photo.VersionIds)
                        {
                            new_parent.DefaultVersionId = new_parent.CreateReparentedVersion(photo.GetVersion(version_id) as PhotoVersion);
                            store.Commit(new_parent);
                        }
                        uint[] version_ids = photo.VersionIds;
                        Array.Reverse(version_ids);
                        foreach (uint version_id in version_ids)
                        {
                            photo.DeleteVersion(version_id, true, true);
                        }
                        store.Remove(photo);
                    }
                    new_parent.Rating      = highest_rating;
                    new_parent.Description = new_description;
                    store.Commit(new_parent);
                    return(true);
                }
            } catch (Exception e) {
                HandleException("Could not reparent photos", e, parent_window);
            }
            return(false);
        }
コード例 #4
0
        private void OnPhotoUploaded(IPhoto item)
        {
            Debug.Assert(null != item);

            if (!model.AttachTags && !model.RemoveTags)
            {
                return;
            }

            PhotoStore photo_store = FSpot.App.Instance.Database.Photos;

            FSpot.Photo photo = photo_store.GetByUri(
                item.DefaultVersion.Uri);
            Debug.Assert(null != photo);
            if (null == photo)
            {
                return;
            }

            if (model.AttachTags)
            {
                photo.AddTag(model.AttachedTags);
            }
            if (model.RemoveTags)
            {
                photo.RemoveTag(model.RemovedTags);
            }
            photo_store.Commit(photo);
        }
コード例 #5
0
        public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window)
        {
            VersionNameRequest request = new VersionNameRequest(VersionNameRequest.RequestType.Create,
                                                                photo, parent_window);

            string       name;
            ResponseType response = request.Run(out name);

            if (response != ResponseType.Ok)
            {
                return(false);
            }

            try {
                photo.DefaultVersionId = photo.CreateVersion(name, photo.DefaultVersionId, true);
                store.Commit(photo);
            } catch (Exception e) {
                string msg  = Catalog.GetString("Could not create a new version");
                string desc = String.Format(Catalog.GetString("Received exception \"{0}\". Unable to create version \"{1}\""),
                                            e.Message, name);

                HigMessageDialog md = new HigMessageDialog(parent_window, DialogFlags.DestroyWithParent,
                                                           Gtk.MessageType.Error, ButtonsType.Ok,
                                                           msg,
                                                           desc);
                md.Run();
                md.Destroy();
                return(false);
            }

            return(true);
        }
コード例 #6
0
        public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window)
        {
            VersionNameRequest request = new VersionNameRequest (VersionNameRequest.RequestType.Create,
                                         photo, parent_window);

            string name;
            ResponseType response = request.Run (out name);

            if (response != ResponseType.Ok)
                return false;

            try {
                photo.DefaultVersionId = photo.CreateVersion (name, photo.DefaultVersionId, true);
                store.Commit (photo);
            } catch (Exception e) {
                    string msg = Catalog.GetString ("Could not create a new version");
                    string desc = String.Format (Catalog.GetString ("Received exception \"{0}\". Unable to create version \"{1}\""),
                                     e.Message, name);

                    HigMessageDialog md = new HigMessageDialog (parent_window, DialogFlags.DestroyWithParent,
                                            Gtk.MessageType.Error, ButtonsType.Ok,
                                            msg,
                                            desc);
                    md.Run ();
                    md.Destroy ();
                    return false;
            }

            return true;
        }
コード例 #7
0
        public bool Execute(PhotoStore store, Photo [] photos, Photo new_parent, Gtk.Window parent_window)
        {
            string ok_caption = Catalog.GetString("Re_parent");
            string msg        = String.Format(Catalog.GetPluralString("Really reparent \"{0}\" as version of \"{1}\"?",
                                                                      "Really reparent {2} photos as versions of \"{1}\"?", photos.Length),
                                              new_parent.Name.Replace("_", "__"), photos[0].Name.Replace("_", "__"), photos.Length);
            string desc = Catalog.GetString("This makes the photos appear as a single one in the library. The versions can be detached using the Photo menu.");

            try {
                if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent,
                                                                           MessageType.Warning, msg, desc, ok_caption))
                {
                    uint   highest_rating  = new_parent.Rating;
                    string new_description = new_parent.Description;
                    foreach (Photo photo in photos)
                    {
                        highest_rating = Math.Max(photo.Rating, highest_rating);
                        if (string.IsNullOrEmpty(new_description))
                        {
                            new_description = photo.Description;
                        }
                        new_parent.AddTag(photo.Tags);

                        foreach (uint version_id in photo.VersionIds)
                        {
                            new_parent.DefaultVersionId = new_parent.CreateReparentedVersion(photo.GetVersion(version_id) as PhotoVersion);
                            store.Commit(new_parent);
                        }
                        uint [] version_ids = photo.VersionIds;
                        Array.Reverse(version_ids);
                        foreach (uint version_id in version_ids)
                        {
                            photo.DeleteVersion(version_id, true, true);
                        }
                        store.Remove(photo);
                    }
                    new_parent.Rating      = highest_rating;
                    new_parent.Description = new_description;
                    store.Commit(new_parent);
                    return(true);
                }
            }
            catch (Exception e) {
                HandleException("Could not reparent photos", e, parent_window);
            }
            return(false);
        }
コード例 #8
0
        public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window)
        {
            // FIXME HIG-ify.
            Dialog dialog = new Dialog();

            dialog.BorderWidth  = 6;
            dialog.TransientFor = parent_window;
            dialog.HasSeparator = false;
            dialog.Title        = Catalog.GetString("Really Delete?");
            dialog.AddButton(Catalog.GetString("Cancel"), (int)ResponseType.Cancel);
            dialog.AddButton(Catalog.GetString("Delete"), (int)ResponseType.Ok);
            dialog.DefaultResponse = ResponseType.Ok;

            string version_name = photo.GetVersionName(photo.DefaultVersionId);
            Label  label        = new Label(String.Format(Catalog.GetString("Really delete version \"{0}\"?"), version_name));

            label.Show();
            dialog.VBox.PackStart(label, false, true, 6);;

            if (dialog.Run() == (int)ResponseType.Ok)
            {
                try {
                    photo.DeleteVersion(photo.DefaultVersionId);
                    store.Commit(photo);
                } catch (Exception e) {
                    // FIXME show error dialog.
                    string msg  = Catalog.GetString("Could not delete a version");
                    string desc = String.Format(Catalog.GetString("Received exception \"{0}\". Unable to delete version \"{1}\""),
                                                e.Message, photo.Name);

                    HigMessageDialog md = new HigMessageDialog(parent_window, DialogFlags.DestroyWithParent,
                                                               Gtk.MessageType.Error, ButtonsType.Ok,
                                                               msg,
                                                               desc);
                    md.Run();
                    md.Destroy();
                    dialog.Destroy();                      // Delete confirmation window.
                    return(false);
                }

                dialog.Destroy();
                return(true);
            }

            dialog.Destroy();
            return(false);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window)
        {
            string ok_caption = Strings.Delete;
            string msg        = Strings.ReallyDeleteVersionXQuestion(photo.DefaultVersion.Name);
            string desc       = Strings.ThisRemovesTheVersionAndDeletesTheCorrespondingFileFromDisk;

            try {
                if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent, MessageType.Warning, msg, desc, ok_caption))
                {
                    photo.DeleteVersion(photo.DefaultVersionId);
                    store.Commit(photo);
                    return(true);
                }
            } catch (Exception e) {
                HandleException("Could not delete a version", e, parent_window);
            }
            return(false);
        }
コード例 #11
0
        public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window)
        {
            // FIXME HIG-ify.
            Dialog dialog = new Dialog ();
            dialog.BorderWidth = 6;
            dialog.TransientFor = parent_window;
            dialog.HasSeparator = false;
            dialog.Title = Catalog.GetString ("Really Delete?");
            dialog.AddButton (Catalog.GetString ("Cancel"), (int) ResponseType.Cancel);
            dialog.AddButton (Catalog.GetString ("Delete"), (int) ResponseType.Ok);
            dialog.DefaultResponse = ResponseType.Ok;

            string version_name = photo.GetVersion (photo.DefaultVersionId).Name;
            Label label = new Label (String.Format (Catalog.GetString ("Really delete version \"{0}\"?"), version_name));
            label.Show ();
            dialog.VBox.PackStart (label, false, true, 6);;

            if (dialog.Run () == (int) ResponseType.Ok) {
                try {
                    photo.DeleteVersion (photo.DefaultVersionId);
                    store.Commit (photo);
                } catch (Exception e) {
                    Log.DebugException (e);
                    string msg = Catalog.GetString ("Could not delete a version");
                    string desc = String.Format (Catalog.GetString ("Received exception \"{0}\". Unable to delete version \"{1}\""),
                                     e.Message, photo.Name);

                    HigMessageDialog md = new HigMessageDialog (parent_window, DialogFlags.DestroyWithParent,
                                            Gtk.MessageType.Error, ButtonsType.Ok,
                                            msg,
                                            desc);
                    md.Run ();
                    md.Destroy ();
                    dialog.Destroy (); // Delete confirmation window.
                    return false;
                }

                dialog.Destroy ();
                return true;
            }

            dialog.Destroy ();
            return false;
        }
コード例 #12
0
        public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window)
        {
            string ok_caption = Catalog.GetString("Delete");
            string msg        = String.Format(Catalog.GetString("Really delete version \"{0}\"?"), photo.DefaultVersion.Name);
            string desc       = Catalog.GetString("This removes the version and deletes the corresponding file from disk.");

            try {
                if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent,
                                                                           MessageType.Warning, msg, desc, ok_caption))
                {
                    photo.DeleteVersion(photo.DefaultVersionId);
                    store.Commit(photo);
                    return(true);
                }
            } catch (Exception e) {
                HandleException("Could not delete a version", e, parent_window);
            }
            return(false);
        }
コード例 #13
0
        public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window)
        {
            var request = new VersionNameDialog(VersionNameDialog.RequestType.Create, photo, parent_window);

            var response = request.Run(out var name);

            if (response != ResponseType.Ok)
            {
                return(false);
            }

            try {
                photo.DefaultVersionId = photo.CreateVersion(name, photo.DefaultVersionId, true);
                store.Commit(photo);
                return(true);
            } catch (Exception e) {
                HandleException("Could not create a new version", e, parent_window);
                return(false);
            }
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window)
        {
            VersionNameRequest request = new VersionNameRequest(VersionNameRequest.RequestType.Rename,
                                                                photo, parent_window);

            string       new_name;
            ResponseType response = request.Run(out new_name);

            if (response != ResponseType.Ok)
            {
                return(false);
            }

            try {
                photo.RenameVersion(photo.DefaultVersionId, new_name);
                store.Commit(photo);
                return(true);
            } catch (Exception e) {
                HandleException("Could not rename a version", e, parent_window);
                return(false);
            }
        }
コード例 #17
0
    public int ImportFromFile(PhotoStore store, string path)
    {
        this.store = store;
        this.CreateDialog("import_dialog");

        this.Dialog.TransientFor   = main_window;
        this.Dialog.WindowPosition = Gtk.WindowPosition.CenterOnParent;
        this.Dialog.Response      += HandleDialogResponse;

        AllowFinish = false;

        this.Dialog.DefaultResponse = ResponseType.Ok;

        //import_folder_entry.Activated += HandleEntryActivate;
        recurse_check.Toggled += HandleRecurseToggled;
        copy_check.Toggled    += HandleRecurseToggled;

        menu = new SourceMenu(this);
        source_option_menu.Menu = menu;

        collection              = new FSpot.PhotoList(new Photo [0]);
        tray                    = new FSpot.ScalingIconView(collection);
        tray.Selection.Changed += HandleTraySelectionChanged;
        icon_scrolled.SetSizeRequest(200, 200);
        icon_scrolled.Add(tray);
        //icon_scrolled.Visible = false;
        tray.DisplayTags = false;
        tray.Show();

        photo_view = new FSpot.PhotoImageView(collection);
        photo_scrolled.Add(photo_view);
        photo_scrolled.SetSizeRequest(200, 200);
        photo_view.Show();

        //FSpot.Global.ModifyColors (frame_eventbox);
        FSpot.Global.ModifyColors(photo_scrolled);
        FSpot.Global.ModifyColors(photo_view);

        photo_view.Pixbuf = PixbufUtils.LoadFromAssembly("f-spot-48.png");
        photo_view.Fit    = true;

        tag_entry = new FSpot.Widgets.TagEntry(MainWindow.Toplevel.Database.Tags, false);
        tag_entry.UpdateFromTagNames(new string [] {});
        tagentry_box.Add(tag_entry);

        tag_entry.Show();

        this.Dialog.Show();
        //source_option_menu.Changed += HandleSourceChanged;
        if (path != null)
        {
            SetImportPath(path);
            int i = menu.FindItemPosition(path);

            if (i > 0)
            {
                source_option_menu.SetHistory((uint)i);
            }
            else if (Directory.Exists(path))
            {
                SourceItem path_item = new SourceItem(new VfsSource(path));
                menu.Prepend(path_item);
                path_item.ShowAll();
                SetImportPath(path);
                source_option_menu.SetHistory(0);
            }
            idle_start.Start();
        }

        ResponseType response = (ResponseType)this.Dialog.Run();

        while (response == ResponseType.Ok)
        {
            try {
                if (Directory.Exists(this.ImportPath))
                {
                    break;
                }
            } catch (System.Exception e) {
                System.Console.WriteLine(e);
                break;
            }

            HigMessageDialog md = new HigMessageDialog(this.Dialog,
                                                       DialogFlags.DestroyWithParent,
                                                       MessageType.Error,
                                                       ButtonsType.Ok,
                                                       Catalog.GetString("Directory does not exist."),
                                                       String.Format(Catalog.GetString("The directory you selected \"{0}\" does not exist.  " +
                                                                                       "Please choose a different directory"), this.ImportPath));

            md.Run();
            md.Destroy();

            response = (Gtk.ResponseType) this.Dialog.Run();
        }

        if (response == ResponseType.Ok)
        {
            this.UpdateTagStore(tag_entry.GetTypedTagNames());
            this.Finish();

            if (tags_selected != null && tags_selected.Count > 0)
            {
                for (int i = 0; i < collection.Count; i++)
                {
                    Photo p = collection [i] as Photo;

                    if (p == null)
                    {
                        continue;
                    }

                    p.AddTag((Tag [])tags_selected.ToArray(typeof(Tag)));
                    store.Commit(p);
                }
            }

            this.Dialog.Destroy();
            return(collection.Count);
        }
        else
        {
            this.Cancel();
            //this.Dialog.Destroy();
            return(0);
        }
    }
コード例 #18
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);
        }
コード例 #19
0
    public override bool Step(out StepStatusInfo status_info)
    {
        Photo  photo        = null;
        Pixbuf thumbnail    = null;
        bool   is_duplicate = false;

        if (import_info == null)
        {
            throw new ImportException("Prepare() was not called");
        }

        if (this.count == import_info.Count)
        {
            throw new ImportException("Already finished");
        }

        // FIXME Need to get the EXIF info etc.
        ImportInfo info         = (ImportInfo)import_info [this.count];
        bool       needs_commit = false;
        bool       abort        = false;

        try {
            string destination = info.OriginalPath;
            if (copy)
            {
                destination = ChooseLocation(info.OriginalPath, directories);
            }

            // Don't copy if we are already home
            if (info.OriginalPath == destination)
            {
                info.DestinationPath = destination;

                if (detect_duplicates)
                {
                    photo = store.CheckForDuplicate(UriUtils.PathToFileUri(destination));
                }

                if (photo == null)
                {
                    photo = store.Create(info.DestinationPath, roll.Id, out thumbnail);
                }
                else
                {
                    is_duplicate = true;
                }
            }
            else
            {
                System.IO.File.Copy(info.OriginalPath, destination);
                info.DestinationPath = destination;

                if (detect_duplicates)
                {
                    photo = store.CheckForDuplicate(UriUtils.PathToFileUri(destination));
                }

                if (photo == null)
                {
                    photo = store.Create(info.DestinationPath, info.OriginalPath, roll.Id, out thumbnail);


                    try {
                        File.SetAttributes(destination, File.GetAttributes(info.DestinationPath) & ~FileAttributes.ReadOnly);
                        DateTime create = File.GetCreationTime(info.OriginalPath);
                        File.SetCreationTime(info.DestinationPath, create);
                        DateTime mod = File.GetLastWriteTime(info.OriginalPath);
                        File.SetLastWriteTime(info.DestinationPath, mod);
                    } catch (IOException) {
                        // we don't want an exception here to be fatal.
                    }
                }
                else
                {
                    is_duplicate = true;
                    System.IO.File.Delete(destination);
                }
            }

            if (!is_duplicate)
            {
                if (tags != null)
                {
                    foreach (Tag t in tags)
                    {
                        photo.AddTag(t);
                    }
                    needs_commit = true;
                }

                needs_commit |= xmptags.Import(photo, info.DestinationPath, info.OriginalPath);

                if (needs_commit)
                {
                    store.Commit(photo);
                }

                info.Photo = photo;
            }
        } catch (System.Exception e) {
            System.Console.WriteLine("Error importing {0}{2}{1}", info.OriginalPath, e.ToString(), Environment.NewLine);
            if (thumbnail != null)
            {
                thumbnail.Dispose();
            }

            thumbnail = null;
            photo     = null;

            HigMessageDialog errordialog = new HigMessageDialog(parent,
                                                                Gtk.DialogFlags.Modal | Gtk.DialogFlags.DestroyWithParent,
                                                                Gtk.MessageType.Error,
                                                                Gtk.ButtonsType.Cancel,
                                                                Catalog.GetString("Import error"),
                                                                String.Format(Catalog.GetString("Error importing {0}{2}{2}{1}"), info.OriginalPath, e.Message, Environment.NewLine));
            errordialog.AddButton(Catalog.GetString("Skip"), Gtk.ResponseType.Reject, false);
            ResponseType response = (ResponseType)errordialog.Run();
            errordialog.Destroy();
            if (response == ResponseType.Cancel)
            {
                abort = true;
            }
        }

        this.count++;

        if (is_duplicate)
        {
            this.duplicate_count++;
        }

        status_info = new StepStatusInfo(photo, thumbnail, this.count, is_duplicate);

        return(!abort && count != import_info.Count);
    }
コード例 #20
0
 public bool Execute(PhotoStore store, Photo [] photos, Photo new_parent, Gtk.Window parent_window)
 {
     foreach (Photo photo in photos) {
         new_parent.AddTag (photo.Tags);
         foreach (uint version_id in photo.VersionIds) {
             try {
                 new_parent.DefaultVersionId = new_parent.CreateReparentedVersion (photo.GetVersion (version_id) as PhotoVersion);
                 store.Commit (new_parent);
             } catch (Exception e) {
                 Log.DebugException (e);
             }
         }
         uint [] version_ids = photo.VersionIds;
         Array.Reverse (version_ids);
         foreach (uint version_id in version_ids) {
             try {
                 photo.DeleteVersion (version_id, true, true);
             } catch (Exception e) {
                 Log.DebugException (e);
             }
         }
         MainWindow.Toplevel.Database.Photos.Remove (photo);
     }
     return true;
 }
コード例 #21
0
 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;
 }
コード例 #22
0
	public int ImportFromFile (PhotoStore store, string path)
	{
		this.store = store;
		this.CreateDialog ("import_dialog");
		
		this.Dialog.TransientFor = main_window;
		this.Dialog.WindowPosition = Gtk.WindowPosition.CenterOnParent;
		this.Dialog.Response += HandleDialogResponse;

	        AllowFinish = false;
		
		this.Dialog.DefaultResponse = ResponseType.Ok;
		
		//import_folder_entry.Activated += HandleEntryActivate;
		recurse_check.Toggled += HandleRecurseToggled;
		copy_check.Toggled += HandleRecurseToggled;

		menu = new SourceMenu (this);
		source_option_menu.Menu = menu;

		collection = new FSpot.PhotoList (new Photo [0]);
		tray = new FSpot.ScalingIconView (collection);
		tray.Selection.Changed += HandleTraySelectionChanged;
		icon_scrolled.SetSizeRequest (200, 200);
		icon_scrolled.Add (tray);
		//icon_scrolled.Visible = false;
		tray.DisplayTags = false;
		tray.Show ();

		photo_view = new FSpot.PhotoImageView (collection);
		photo_scrolled.Add (photo_view);
		photo_scrolled.SetSizeRequest (200, 200);
		photo_view.Show ();

		//FSpot.Global.ModifyColors (frame_eventbox);
		FSpot.Global.ModifyColors (photo_scrolled);
		FSpot.Global.ModifyColors (photo_view);

		photo_view.Pixbuf = PixbufUtils.LoadFromAssembly ("f-spot-48.png");
		photo_view.Fit = true;
			
		tag_entry = new FSpot.Widgets.TagEntry (MainWindow.Toplevel.Database.Tags, false);
		tag_entry.UpdateFromTagNames (new string []{});
		tagentry_box.Add (tag_entry);

		tag_entry.Show ();

		this.Dialog.Show ();
		//source_option_menu.Changed += HandleSourceChanged;
		if (path != null) {
			SetImportPath (path);
			int i = menu.FindItemPosition (path);

			if (i > 0) {
				source_option_menu.SetHistory ((uint)i);
			} else if (Directory.Exists (path)) {
				SourceItem path_item = new SourceItem (new VfsSource (path));
				menu.Prepend (path_item);
				path_item.ShowAll ();
				SetImportPath (path);
				source_option_menu.SetHistory (0);
			} 
			idle_start.Start ();
		}
						
		ResponseType response = (ResponseType) this.Dialog.Run ();
		
		while (response == ResponseType.Ok) {
			try {
				if (Directory.Exists (this.ImportPath))
					break;
			} catch (System.Exception e){
				System.Console.WriteLine (e);
				break;
			}

			HigMessageDialog md = new HigMessageDialog (this.Dialog,
			        DialogFlags.DestroyWithParent,
				MessageType.Error,
				ButtonsType.Ok,
				Catalog.GetString ("Directory does not exist."),
				String.Format (Catalog.GetString ("The directory you selected \"{0}\" does not exist.  " + 
								  "Please choose a different directory"), this.ImportPath));

			md.Run ();
			md.Destroy ();

			response = (Gtk.ResponseType) this.Dialog.Run ();
		}

		if (response == ResponseType.Ok) {
			this.UpdateTagStore (tag_entry.GetTypedTagNames ());
			this.Finish ();

			if (tags_selected != null && tags_selected.Count > 0) {
				for (int i = 0; i < collection.Count; i++) {
					Photo p = collection [i] as Photo;
					
					if (p == null)
						continue;
					
					p.AddTag ((Tag [])tags_selected.ToArray(typeof(Tag)));
					store.Commit (p);
				}
			}

			this.Dialog.Destroy ();
			return collection.Count;
		} else {
			this.Cancel ();
			//this.Dialog.Destroy();
			return 0;
		}
	}
コード例 #23
0
        public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window)
        {
            VersionNameRequest request = new VersionNameRequest (VersionNameRequest.RequestType.Create,
                                         photo, parent_window);

            string name;
            ResponseType response = request.Run (out name);

            if (response != ResponseType.Ok)
                return false;

            try {
                photo.DefaultVersionId = photo.CreateVersion (name, photo.DefaultVersionId, true);
                store.Commit (photo);
                return true;
            } catch (Exception e) {
                HandleException ("Could not create a new version", e, parent_window);
                return false;
            }
        }
コード例 #24
0
        public bool Execute(PhotoStore store, Photo [] photos, Photo new_parent, Gtk.Window parent_window)
        {
            string ok_caption = Catalog.GetString ("Re_parent");
            string msg = String.Format (Catalog.GetPluralString ("Really reparent \"{0}\" as version of \"{1}\"?",
                                                                 "Really reparent {2} photos as versions of \"{1}\"?", photos.Length),
                                        new_parent.Name.Replace ("_", "__"), photos[0].Name.Replace ("_", "__"), photos.Length);
            string desc = Catalog.GetString ("This makes the photos appear as a single one in the library. The versions can be detached using the Photo menu.");

            try {
                if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent,
                                       MessageType.Warning, msg, desc, ok_caption)) {
                    uint highest_rating = new_parent.Rating;
                    string new_description = new_parent.Description;
                    foreach (Photo photo in photos) {
                        highest_rating = Math.Max(photo.Rating, highest_rating);
                        if (string.IsNullOrEmpty(new_description))
                            new_description = photo.Description;
                        new_parent.AddTag (photo.Tags);

                        foreach (uint version_id in photo.VersionIds) {
                            new_parent.DefaultVersionId = new_parent.CreateReparentedVersion (photo.GetVersion (version_id) as PhotoVersion);
                            store.Commit (new_parent);
                        }
                        uint [] version_ids = photo.VersionIds;
                        Array.Reverse (version_ids);
                        foreach (uint version_id in version_ids) {
                            photo.DeleteVersion (version_id, true, true);
                        }
                        store.Remove (photo);
                    }
                    new_parent.Rating = highest_rating;
                    new_parent.Description = new_description;
                    store.Commit (new_parent);
                    return true;
                }
            }
            catch (Exception e) {
                HandleException ("Could not reparent photos", e, parent_window);
            }
            return false;
        }
コード例 #25
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);
        }
コード例 #26
0
 public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window)
 {
     string ok_caption = Catalog.GetString ("Delete");
     string msg = String.Format (Catalog.GetString ("Really delete version \"{0}\"?"), photo.DefaultVersion.Name);
     string desc = Catalog.GetString ("This removes the version and deletes the corresponding file from disk.");
     try {
         if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent,
                                MessageType.Warning, msg, desc, ok_caption)) {
             photo.DeleteVersion (photo.DefaultVersionId);
             store.Commit (photo);
             return true;
         }
     } catch (Exception e) {
         HandleException ("Could not delete a version", e, parent_window);
     }
     return false;
 }