Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
 public void Merge()
 {
     Log.DebugFormat("Merging {0} and {1}", raw.VersionUri(Photo.OriginalVersionId), jpeg.VersionUri(Photo.OriginalVersionId));
     foreach (uint version_id in jpeg.VersionIds)
     {
         string name = jpeg.GetVersion(version_id).Name;
         try {
             raw.DefaultVersionId = raw.CreateReparentedVersion(jpeg.GetVersion(version_id) as PhotoVersion, version_id == Photo.OriginalVersionId);
             if (version_id == Photo.OriginalVersionId)
             {
                 raw.RenameVersion(raw.DefaultVersionId, "Jpeg");
             }
             else
             {
                 raw.RenameVersion(raw.DefaultVersionId, name);
             }
         } catch (Exception e) {
             Log.Exception(e);
         }
     }
     raw.AddTag(jpeg.Tags);
     uint [] version_ids = jpeg.VersionIds;
     Array.Reverse(version_ids);
     foreach (uint version_id in version_ids)
     {
         try {
             jpeg.DeleteVersion(version_id, true, true);
         } catch (Exception e) {
             Log.Exception(e);
         }
     }
     raw.Changes.DataChanged = true;
     App.Instance.Database.Photos.Commit(raw);
     App.Instance.Database.Photos.Remove(jpeg);
 }
Exemplo n.º 3
0
    private void OnTagClicked(object o, ItemActivatedArgs args)
    {
        TreePath  childpath = _filter.ConvertPathToChildPath(args.Path);
        string    tag       = (string)_tags[childpath.Indices[0]];
        ArrayList tagschosen;

        if (checkbutton1.Active || !checkbutton1.Sensitive)
        {
            Photo p = ((DeskFlickrUI.SelectedPhoto)_selectedphotos[_curphotoindex]).photo;
            p.AddTag(tag);
            tagschosen = p.Tags;
        }
        else
        {
            foreach (DeskFlickrUI.SelectedPhoto sel in _selectedphotos)
            {
                Photo p = sel.photo;
                p.AddTag(tag);
            }
            tagschosen = ((DeskFlickrUI.SelectedPhoto)_selectedphotos[0]).photo.Tags;
            foreach (DeskFlickrUI.SelectedPhoto sel in _selectedphotos)
            {
                Photo p = sel.photo;
                tagschosen = Utils.GetIntersection(tagschosen, p.Tags);
            }
        }
        ActivateRevertButton();
        _ignorechangedevent   = true;
        textview3.Buffer.Text = Utils.GetDelimitedString(tagschosen, " ");
        _ignorechangedevent   = false;
    }
Exemplo n.º 4
0
        public int ImportPhoto(string path, bool copy, string [] tags)
        {
            if (current_roll == null)
            {
                throw new DBusException("You must use PrepareRoll before you can import a photo.");
            }

            // add tags that exist in tag store
            List <Tag> tag_list = GetTagsByNames(tags);

            Gdk.Pixbuf pixbuf = null;

            // FIXME: this is more or less a copy of the file import backend code
            // this should be streamlined
            try {
                string new_path = path;

                if (copy)
                {
                    new_path = FileImportBackend.ChooseLocation(path);
                }

                if (new_path != path)
                {
                    System.IO.File.Copy(path, new_path);
                }

                Photo created = db.Photos.CreateOverDBus(new_path, path, current_roll.Id, out pixbuf);

                try {
                    File.SetAttributes(new_path, File.GetAttributes(new_path) & ~FileAttributes.ReadOnly);
                    DateTime create = File.GetCreationTime(path);
                    File.SetCreationTime(new_path, create);
                    DateTime mod = File.GetLastWriteTime(path);
                    File.SetLastWriteTime(new_path, mod);
                } catch (IOException) {
                    // we don't want an exception here to be fatal.
                }

                // attach tags we got
                if (tag_list.Count > 0)
                {
                    created.AddTag(tag_list.ToArray());
                    db.Photos.Commit(created);
                }

                return((int)created.Id);
                // indicate failure
            } catch {
                throw new DBusException("Failed to import the photo.");
            }
        }
Exemplo n.º 5
0
        private void AddTagToPhoto(Photo photo, string new_tag_name)
        {
            if (string.IsNullOrEmpty(new_tag_name))
            {
                return;
            }

            Tag parent = EnsureTag(li_root_tag, tag_store.RootCategory);
            Tag tag    = EnsureTag(new TagInfo(new_tag_name), parent as Category);

            // Now we have the tag for this place, add the photo to it
            photo.AddTag(tag);
        }
Exemplo n.º 6
0
            public void Merge()
            {
                photos.Sort(new CompareNameWithRaw());
                Console.WriteLine("Maybe merging these photos:");
                foreach (Photo photo in this.photos)
                {
                    Console.WriteLine(photo.Name);
                }

                Photo raw = (Photo)this.photos[0];

                foreach (Photo jpeg in this.photos.GetRange(1, this.photos.Count - 1))
                {
                    Console.WriteLine("...merging {0} into {1}...", jpeg.Name, raw.Name);

                    Console.WriteLine("Merging {0} and {1}", raw.VersionUri(Photo.OriginalVersionId), jpeg.VersionUri(Photo.OriginalVersionId));
                    foreach (uint version_id in jpeg.VersionIds)
                    {
                        string name = jpeg.GetVersion(version_id).Name;
                        try {
                            raw.DefaultVersionId = raw.CreateReparentedVersion(jpeg.GetVersion(version_id) as PhotoVersion, version_id == Photo.OriginalVersionId);
                            if (version_id == Photo.OriginalVersionId)
                            {
                                // Just the filename part that follows the last "-", e.g. "xy100.jpg".
                                raw.RenameVersion(raw.DefaultVersionId, jpeg.Name.Substring(jpeg.Name.LastIndexOf('-') + 1));
                            }
                            else
                            {
                                raw.RenameVersion(raw.DefaultVersionId, name);
                            }
                        } catch (Exception e) {
                            Console.WriteLine(e);
                        }
                    }
                    raw.AddTag(jpeg.Tags);
                    uint [] version_ids = jpeg.VersionIds;
                    Array.Reverse(version_ids);
                    foreach (uint version_id in version_ids)
                    {
                        try {
                            jpeg.DeleteVersion(version_id, true, true);
                        } catch (Exception e) {
                            Console.WriteLine(e);
                        }
                    }
                    raw.Changes.DataChanged = true;
                    App.Instance.Database.Photos.Commit(raw);
                    App.Instance.Database.Photos.Remove(jpeg);
                }
            }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        private void AddTagToPhoto(Photo photo, string new_tag_name, TagInfo sub_tag)
        {
            if (new_tag_name == null)
            {
                return;
            }

            Tag parent = EnsureTag(li_root_tag, tag_store.RootCategory);

            // If we should have a sub root make sure it exists
            if (sub_tag != null)
            {
                parent = EnsureTag(sub_tag, parent as Category);
            }

            Tag tag = EnsureTag(new TagInfo(new_tag_name), parent as Category);

            // Now we have the tag for this place, add the photo to it
            photo.AddTag(tag);
        }
Exemplo n.º 10
0
        public override void Handle(string requested, Stream stream)
        {
            bool addTag = requested.StartsWith("add");

            if (!addTag && !requested.StartsWith("remove"))
            {
                SendError(stream, "400 Bad request " + requested);
                return;
            }
            int slash_pos = requested.IndexOf('/');

            requested = requested.Substring(slash_pos + 1);
            slash_pos = requested.IndexOf('/');
            uint   photo_id = uint.Parse(requested.Substring(0, slash_pos));
            string tag_name = requested.Substring(slash_pos + 1);

            if (!options.TaggingAllowed || !options.EditableTag.Name.Equals(tag_name))
            {
                SendError(stream, "403 Forbidden to change tag " + tag_name);
                return;
            }

            Photo photo = App.Instance.Database.Photos.Get(photo_id);

            if (addTag)
            {
                photo.AddTag(options.EditableTag);
            }
            else
            {
                photo.RemoveTag(options.EditableTag);
            }
            App.Instance.Database.Photos.Commit(photo);

            SendHeadersAndStartContent(stream, "Content-type: text/plain;charset=UTF-8");
            SendLine(stream, TagsToString(photo));
        }
	public override bool Step (out Photo photo, out Pixbuf thumbnail, out int count)
	{
		thumbnail = null;

		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;
				photo = store.Create (info.DestinationPath, roll.Id, out thumbnail);
			} else {
				System.IO.File.Copy (info.OriginalPath, destination);
				info.DestinationPath = destination;

				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.
				}
			} 

			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 ("Skip", Gtk.ResponseType.Reject, false);
			ResponseType response = (ResponseType) errordialog.Run ();
			errordialog.Destroy ();
			if (response == ResponseType.Cancel)
				abort = true;
		}

		this.count ++;
		count = this.count;

		return (!abort && count != import_info.Count);
	}
Exemplo n.º 12
0
		void AddTagToPhoto (Photo photo, string newTagName)
		{
			if (string.IsNullOrEmpty(newTagName))
				return;

			Tag parent = EnsureTag (li_root_tag, tag_store.RootCategory);
			Tag tag = EnsureTag (new TagInfo (newTagName), parent as Category);

			// Now we have the tag for this place, add the photo to it
			photo.AddTag (tag);
		}
Exemplo n.º 13
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;
 }
        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;
        }
    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);
        }
    }
Exemplo n.º 16
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);
    }
Exemplo n.º 17
0
    static void Main(string [] args)
    {
        Program program = new Program("PhotoStoreTest", "0.0", Modules.UI, args);

        const string path = "/tmp/PhotoStoreTest.db";

        try {
            File.Delete(path);
        } catch {}

        Db db = new Db(path, true);

        Tag portraits_tag  = db.Tags.CreateTag(null, "Portraits");
        Tag landscapes_tag = db.Tags.CreateTag(null, "Landscapes");
        Tag favorites_tag  = db.Tags.CreateTag(null, "Street");

        uint portraits_tag_id  = portraits_tag.Id;
        uint landscapes_tag_id = landscapes_tag.Id;
        uint favorites_tag_id  = favorites_tag.Id;

        Pixbuf unused_thumbnail;

        Photo ny_landscape = db.Photos.Create(DateTime.Now.ToUniversalTime(), 1, "/home/ettore/Photos/ny_landscape.jpg",
                                              out unused_thumbnail);

        ny_landscape.Description = "Pretty NY skyline";
        ny_landscape.AddTag(landscapes_tag);
        ny_landscape.AddTag(favorites_tag);
        db.Photos.Commit(ny_landscape);

        Photo me_in_sf = db.Photos.Create(DateTime.Now.ToUniversalTime(), 2, "/home/ettore/Photos/me_in_sf.jpg",
                                          out unused_thumbnail);

        me_in_sf.AddTag(landscapes_tag);
        me_in_sf.AddTag(portraits_tag);
        me_in_sf.AddTag(favorites_tag);
        db.Photos.Commit(me_in_sf);

        me_in_sf.RemoveTag(favorites_tag);
        me_in_sf.Description = "Myself and the SF skyline";
        me_in_sf.CreateVersion("cropped", Photo.OriginalVersionId);
        me_in_sf.CreateVersion("UM-ed", Photo.OriginalVersionId);
        db.Photos.Commit(me_in_sf);

        Photo macro_shot = db.Photos.Create(DateTime.Now.ToUniversalTime(), 2, "/home/ettore/Photos/macro_shot.jpg",
                                            out unused_thumbnail);

        db.Dispose();

        db = new Db(path, false);

        DumpAll(db);

        portraits_tag  = db.Tags.Get(portraits_tag_id) as Tag;
        landscapes_tag = db.Tags.Get(landscapes_tag_id) as Tag;
        favorites_tag  = db.Tags.Get(favorites_tag_id) as Tag;

        ArrayList query_tags = new ArrayList();

        query_tags.Add(portraits_tag);
        query_tags.Add(landscapes_tag);
        DumpForTags(db, query_tags);

        query_tags.Clear();
        query_tags.Add(favorites_tag);
        DumpForTags(db, query_tags);
    }
Exemplo n.º 18
0
        private void AddTagToPhoto(Photo photo, string new_tag_name, TagInfo sub_tag)
        {
            if (new_tag_name == null)
                return;

            Tag parent = EnsureTag (li_root_tag, tag_store.RootCategory);

            // If we should have a sub root make sure it exists
            if (sub_tag != null)
                parent = EnsureTag (sub_tag, parent as Category);

            Tag tag = EnsureTag (new TagInfo (new_tag_name), parent as Category);

            // Now we have the tag for this place, add the photo to it
            photo.AddTag (tag);
        }
        private void AddTagToPhoto(Photo photo, string new_tag_name)
        {
            if (new_tag_name == null || new_tag_name.Length == 0)
                return;

            Tag parent = EnsureTag (li_root_tag, tag_store.RootCategory);
            Tag tag = EnsureTag (new TagInfo (new_tag_name), parent as Category);

            // Now we have the tag for this place, add the photo to it
            photo.AddTag (tag);
        }