Beispiel #1
0
        private uint CreateVersion(string name, string extension, uint base_version_id, bool create, bool is_protected)
        {
            extension = extension ?? VersionUri(base_version_id).GetExtension();
            SafeUri new_base_uri = DefaultVersion.BaseUri;
            string  filename     = GetFilenameForVersionName(name, extension);
            SafeUri original_uri = VersionUri(base_version_id);
            SafeUri new_uri      = new_base_uri.Append(filename);
            string  import_md5   = DefaultVersion.ImportMD5;

            if (VersionNameExists(name))
            {
                throw new Exception("This version name already exists");
            }

            if (create)
            {
                GLib.File destination = GLib.FileFactory.NewForUri(new_uri);
                if (destination.Exists)
                {
                    throw new Exception(string.Format("An object at this uri {0} already exists", new_uri));
                }

                //FIXME. or better, fix the copy api !
                GLib.File source = GLib.FileFactory.NewForUri(original_uri);
                source.Copy(destination, GLib.FileCopyFlags.None, null, null);
            }
            highest_version_id++;

            versions [highest_version_id] = new PhotoVersion(this, highest_version_id, new_base_uri, filename, import_md5, name, is_protected);

            changes.AddVersion(highest_version_id);

            return(highest_version_id);
        }
Beispiel #2
0
        protected void RenameNewVersion()
        {
            try {
                System.Uri original_uri = GetUriForVersionFileName(this.currentphoto, this.currentphoto.DefaultVersion.Uri.LocalPath);
                System.Uri new_uri      = GetUriForVersionFileName(this.currentphoto, new_filename);
                //Console.WriteLine ("ok pressed: old: " + this.currentphoto.DefaultVersionUri.LocalPath + "; " + original_uri.ToString() + " new: " + new_filename + "; " + new_uri.ToString() + "to open with: " );

                // check if new version exist and remove
                foreach (uint id in currentphoto.VersionIds)
                {
                    if (currentphoto.GetVersion(id).Name == new_version_entry.Text)
                    {
                        this.currentphoto.DeleteVersion(id);
                    }
                }
                GLib.File destination = GLib.FileFactory.NewForUri(new_uri);
                if (destination.Exists)
                {
                    throw new Exception(String.Format("An object at this uri {0} already exists", new_uri));
                }

                //FIXME. or better, fix the copy api !
                GLib.File source = GLib.FileFactory.NewForUri(original_uri);
                source.Copy(destination, GLib.FileCopyFlags.None, null, null);

                this.currentphoto.DefaultVersionId = this.currentphoto.AddVersion(new SafeUri(new_uri).GetBaseUri(), new SafeUri(new_uri).GetFilename(), new_version_entry.Text, true);
                uint currentid = this.currentphoto.DefaultVersionId;
                foreach (uint id in currentphoto.VersionIds)
                {
                    if (currentphoto.GetVersion(id).Uri.ToString() == original_uri.ToString())
                    {
                        this.currentphoto.DeleteVersion(id, false, false);
                    }
                }
                this.currentphoto.DefaultVersionId = currentid;
                App.Instance.Database.Photos.Commit(this.currentphoto);

                this.currentphoto.Changes.DataChanged = true;
            } finally {
                Gtk.Application.Invoke(delegate { dialog.Destroy(); });
            }
        }