[f-spot: 1/3] make auto-creating tag icons optional



commit 348dd63c69b4f7a9b26fe81f631cf67c782ce676
Author: Johannes Berg <johannes sipsolutions net>
Date:   Wed Jun 10 10:07:34 2009 +0200

    make auto-creating tag icons optional
    
    When a tag is newly created, it defaults to getting an icon
    automatically assigned on first use. Make this optional, with
    a checkbox whether an icon should be auto-created, and make
    the checkbox remember its state.
    
    Additionally, when an icon was manually removed from a tag,
    do not auto-create one again.

 extensions/Services/DBusService/DBusProxy.cs |    2 +-
 extensions/Tools/MergeDb/MergeDb.cs          |    2 +-
 src/Core/Tag.cs                              |    3 ++
 src/ImportCommand.cs                         |    4 +-
 src/MainWindow.cs                            |    4 +-
 src/Preferences.cs                           |    4 ++
 src/TagCommands.cs                           |    9 ++++-
 src/TagStore.cs                              |   44 ++++++++++++++++---------
 src/XmpTagsImporter.cs                       |    3 +-
 src/f-spot.glade                             |   21 ++++++++++++
 10 files changed, 71 insertions(+), 25 deletions(-)
---
diff --git a/extensions/Services/DBusService/DBusProxy.cs b/extensions/Services/DBusService/DBusProxy.cs
index 3677199..549c5f8 100644
--- a/extensions/Services/DBusService/DBusProxy.cs
+++ b/extensions/Services/DBusService/DBusProxy.cs
@@ -226,7 +226,7 @@ namespace DBusService {
 		private int CreateTagPriv (Category parent_tag, string name)
 		{
 			try {
-				Tag created = tag_store.CreateCategory (parent_tag, name);
+				Tag created = tag_store.CreateCategory (parent_tag, name, false);
 				return (int)created.Id;
 			}
 			catch {
diff --git a/extensions/Tools/MergeDb/MergeDb.cs b/extensions/Tools/MergeDb/MergeDb.cs
index 03862ab..1525c2a 100644
--- a/extensions/Tools/MergeDb/MergeDb.cs
+++ b/extensions/Tools/MergeDb/MergeDb.cs
@@ -143,7 +143,7 @@ namespace MergeDbExtension
 					Category parent = (tag_to_merge.Category == from_store.RootCategory) ?
 							to_store.RootCategory :
 							to_store.GetTagByName (tag_to_merge.Category.Name) as Category;
-					dest_tag = to_store.CreateTag (parent, tag_to_merge.Name);
+					dest_tag = to_store.CreateTag (parent, tag_to_merge.Name, false);
 					//FIXME: copy the tag icon and commit
 				}
 				tag_map [tag_to_merge.Id] = dest_tag;
diff --git a/src/Core/Tag.cs b/src/Core/Tag.cs
index 78c44db..dbe5404 100644
--- a/src/Core/Tag.cs
+++ b/src/Core/Tag.cs
@@ -69,8 +69,11 @@ namespace FSpot
 					icon.Dispose ();
 				icon = value;
 				cached_icon_size = IconSize.Hidden;
+				IconWasCleared = value == null;
 			}
 		}
+
+		public bool IconWasCleared = false;
 	
 		public enum IconSize {
 			Hidden = 0,
diff --git a/src/ImportCommand.cs b/src/ImportCommand.cs
index bcd58b2..83238f1 100644
--- a/src/ImportCommand.cs
+++ b/src/ImportCommand.cs
@@ -724,10 +724,10 @@ public class ImportCommand : GladeDialog
 				// Note for translators: 'Import Tags' is no command, it means 'Tags used in Import'
 				Category default_category = db.Tags.GetTagByName (Catalog.GetString ("Import Tags")) as Category;
 				if (default_category == null) {
-					default_category = db.Tags.CreateCategory (null, Catalog.GetString ("Import Tags"));
+					default_category = db.Tags.CreateCategory (null, Catalog.GetString ("Import Tags"), false);
 					default_category.ThemeIconName = "f-spot-imported-xmp-tags.png"; 
 				}
-				t = db.Tags.CreateCategory (default_category, tagname) as Tag;
+				t = db.Tags.CreateCategory (default_category, tagname, false) as Tag;
 				db.Tags.Commit (t);
 			}
 
diff --git a/src/MainWindow.cs b/src/MainWindow.cs
index b96f599..0f304d2 100644
--- a/src/MainWindow.cs
+++ b/src/MainWindow.cs
@@ -941,7 +941,7 @@ public class MainWindow {
 		query.Commit (nums);
 
 		foreach (Tag t in tags) {
-			if (t.Icon != null)
+			if (t.Icon != null || t.IconWasCleared)
 				continue;
 			// FIXME this needs a lot more work.
 			Pixbuf icon = null;
@@ -3212,7 +3212,7 @@ public class MainWindow {
 		foreach (string tagname in new_tags) {
 			Tag t = db.Tags.GetTagByName (tagname);
 			if (t == null) {
-				t = db.Tags.CreateCategory (default_category, tagname) as Tag;
+				t = db.Tags.CreateCategory (default_category, tagname, true) as Tag;
 				db.Tags.Commit (t);
 			}
 			tags [i++] = t;
diff --git a/src/Preferences.cs b/src/Preferences.cs
index 0c74fab..29c5803 100644
--- a/src/Preferences.cs
+++ b/src/Preferences.cs
@@ -48,6 +48,7 @@ namespace FSpot
 		public const string EXPANDED_TAGS = APP_FSPOT + "ui/expanded_tags";
 		public const string SHOW_RATINGS = APP_FSPOT + "ui/show_ratings";
 		public const string TAG_ICON_SIZE = APP_FSPOT + "ui/tag_icon_size";
+		public const string TAG_ICON_AUTOMATIC = APP_FSPOT + "ui/tag_icon_automatic";
 		
 		public const string GLASS_POSITION = APP_FSPOT + "ui/glass_position";
 		public const string GROUP_ADAPTOR = APP_FSPOT + "ui/group_adaptor";
@@ -133,6 +134,9 @@ namespace FSpot
 			
 			case TAG_ICON_SIZE:
 				return (int) Tag.IconSize.Medium;
+
+			case TAG_ICON_AUTOMATIC:
+				return true;
 		
 			case SIDEBAR_POSITION:
 				return 130;
diff --git a/src/TagCommands.cs b/src/TagCommands.cs
index d7fab11..082c671 100644
--- a/src/TagCommands.cs
+++ b/src/TagCommands.cs
@@ -37,6 +37,7 @@ public class TagCommands {
 		[Glade.Widget] private Label photo_label;
 		[Glade.Widget] private ScrolledWindow photo_scrolled_window;
 		[Glade.Widget] private OptionMenu category_option_menu;
+		[Glade.Widget] private CheckButton auto_icon_checkbutton;
 
 		Gtk.Widget parent_window;
 
@@ -138,6 +139,7 @@ public class TagCommands {
 
 			this.Dialog.Title = Catalog.GetString ("Create New Tag");
 			prompt_label.Text = Catalog.GetString ("Name of New Tag:");
+			this.auto_icon_checkbutton.Active = Preferences.Get<bool> (Preferences.TAG_ICON_AUTOMATIC);
 
 			PopulateCategoryOptionMenu ();
 			this.Category = default_category;
@@ -146,15 +148,18 @@ public class TagCommands {
 
 			ResponseType response = (ResponseType) this.Dialog.Run ();
 
+
 			Tag new_tag = null;
 			if (response == ResponseType.Ok) {
+				bool autoicon = this.auto_icon_checkbutton.Active;
+				Preferences.Set (Preferences.TAG_ICON_AUTOMATIC, autoicon);
 				try {
 					Category parent_category = Category;
 
 					if (type == TagType.Category)
-						new_tag = tag_store.CreateCategory (parent_category, tag_name_entry.Text) as Tag;
+						new_tag = tag_store.CreateCategory (parent_category, tag_name_entry.Text, autoicon) as Tag;
 					else
-						new_tag = tag_store.CreateTag (parent_category, tag_name_entry.Text);
+						new_tag = tag_store.CreateTag (parent_category, tag_name_entry.Text, autoicon);
 				} catch (Exception ex) {
 					// FIXME error dialog.
 					Console.WriteLine ("error {0}", ex);
diff --git a/src/TagStore.cs b/src/TagStore.cs
index e1b1f56..ab0ecd3 100644
--- a/src/TagStore.cs
+++ b/src/TagStore.cs
@@ -62,7 +62,12 @@ public class TagStore : DbStore<Tag> {
 
 	static void SetIconFromString (Tag tag, string icon_string)
 	{
-		if (icon_string == null || icon_string == String.Empty)
+		if (icon_string == null) {
+			tag.Icon = null;
+			// IconWasCleared automatically set already, override
+			// it in this case since it was NULL in the db.
+			tag.IconWasCleared = false;
+		} else if (icon_string == String.Empty)
 			tag.Icon = null;
 		else if (icon_string.StartsWith (STOCK_ICON_DB_PREFIX))
 			tag.ThemeIconName = icon_string.Substring (STOCK_ICON_DB_PREFIX.Length);
@@ -195,12 +200,12 @@ public class TagStore : DbStore<Tag> {
 
 	private void CreateDefaultTags ()
 	{
-		Category favorites_category = CreateCategory (RootCategory, Catalog.GetString ("Favorites"));
+		Category favorites_category = CreateCategory (RootCategory, Catalog.GetString ("Favorites"), false);
 		favorites_category.ThemeIconName = "emblem-favorite";
 		favorites_category.SortPriority = -10;
 		Commit (favorites_category);
 
-		Tag hidden_tag = CreateTag (RootCategory, Catalog.GetString ("Hidden"));
+		Tag hidden_tag = CreateTag (RootCategory, Catalog.GetString ("Hidden"), false);
 		hidden_tag.ThemeIconName = "emblem-readonly";
 		hidden_tag.SortPriority = -9;
 		this.hidden = hidden_tag;
@@ -208,17 +213,17 @@ public class TagStore : DbStore<Tag> {
 		FSpot.Core.Database.Meta.HiddenTagId.ValueAsInt = (int) hidden_tag.Id;
 		FSpot.Core.Database.Meta.Commit (FSpot.Core.Database.Meta.HiddenTagId);
 
-		Tag people_category = CreateCategory (RootCategory, Catalog.GetString ("People"));
+		Tag people_category = CreateCategory (RootCategory, Catalog.GetString ("People"), false);
 		people_category.ThemeIconName = "emblem-people";
 		people_category.SortPriority = -8;
 		Commit (people_category);
 
-		Tag places_category = CreateCategory (RootCategory, Catalog.GetString ("Places"));
+		Tag places_category = CreateCategory (RootCategory, Catalog.GetString ("Places"), false);
 		places_category.ThemeIconName = "emblem-places";
 		places_category.SortPriority = -8;
 		Commit (places_category);
 
-		Tag events_category = CreateCategory (RootCategory, Catalog.GetString ("Events"));
+		Tag events_category = CreateCategory (RootCategory, Catalog.GetString ("Events"), false);
 		events_category.ThemeIconName = "emblem-event";
 		events_category.SortPriority = -7;
 		Commit (events_category);
@@ -241,29 +246,32 @@ public class TagStore : DbStore<Tag> {
 		}
 	}
 
-	private uint InsertTagIntoTable (Category parent_category, string name, bool is_category)
+	private uint InsertTagIntoTable (Category parent_category, string name, bool is_category, bool autoicon)
 	{
 
 		uint parent_category_id = parent_category.Id;
+		String default_tag_icon_value = autoicon ? null : String.Empty;
 
-		int id = Database.Execute (new DbCommand ("INSERT INTO tags (name, category_id, is_category, sort_priority)"
-                          + "VALUES (:name, :category_id, :is_category, 0)",
+		int id = Database.Execute (new DbCommand ("INSERT INTO tags (name, category_id, is_category, sort_priority, icon)"
+                          + "VALUES (:name, :category_id, :is_category, 0, :icon)",
 						  "name", name,
 						  "category_id", parent_category_id,
-						  "is_category", is_category ? 1 : 0));
+						  "is_category", is_category ? 1 : 0,
+						  "icon", default_tag_icon_value));
 
 
 		return (uint) id;
 	}
 
-	public Tag CreateTag (Category category, string name)
+	public Tag CreateTag (Category category, string name, bool autoicon)
 	{
 		if (category == null)
 			category = RootCategory;
 
-		uint id = InsertTagIntoTable (category, name, false);
+		uint id = InsertTagIntoTable (category, name, false, autoicon);
 
 		Tag tag = new Tag (category, id, name);
+		tag.IconWasCleared = !autoicon;
 
 		AddToCache (tag);
 		EmitAdded (tag);
@@ -271,14 +279,15 @@ public class TagStore : DbStore<Tag> {
 		return tag;
 	}
 
-	public Category CreateCategory (Category parent_category, string name)
+	public Category CreateCategory (Category parent_category, string name, bool autoicon)
 	{
 		if (parent_category == null)
 			parent_category = RootCategory;
 
-		uint id = InsertTagIntoTable (parent_category, name, true);
+		uint id = InsertTagIntoTable (parent_category, name, true, autoicon);
 
 		Category new_category = new Category (parent_category, id, name);
+		new_category.IconWasCleared = !autoicon;
 
 		AddToCache (new_category);
 		EmitAdded (new_category);
@@ -316,8 +325,11 @@ public class TagStore : DbStore<Tag> {
 	{
 		if (tag.ThemeIconName != null)
 			return STOCK_ICON_DB_PREFIX + tag.ThemeIconName;
-		if (tag.Icon == null)
-			return String.Empty;
+		if (tag.Icon == null) {
+			if (tag.IconWasCleared)
+				return String.Empty;
+			return null;
+		}
 
 		byte [] data = GdkUtils.Serialize (tag.Icon);
 		return Convert.ToBase64String (data);
diff --git a/src/XmpTagsImporter.cs b/src/XmpTagsImporter.cs
index 31d2d32..93b43cc 100644
--- a/src/XmpTagsImporter.cs
+++ b/src/XmpTagsImporter.cs
@@ -101,7 +101,8 @@ namespace FSpot.Xmp {
 				return tag;
 			
 			tag = tag_store.CreateCategory (parent,
-							info.TagName);
+							info.TagName,
+							false);
 			
 			if (info.HasIcon) {
 				tag.ThemeIconName = info.IconName;
diff --git a/src/f-spot.glade b/src/f-spot.glade
index 8b1ad14..e5f7161 100644
--- a/src/f-spot.glade
+++ b/src/f-spot.glade
@@ -199,6 +199,27 @@
             <property name="position">2</property>
           </packing>
         </child>
+        <child>
+          <widget class="GtkAlignment" id="alignment3">
+            <property name="visible">True</property>
+            <property name="xalign">0</property>
+            <property name="xscale">0</property>
+            <child>
+              <widget class="GtkCheckButton" id="auto_icon_checkbutton">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="label" translatable="yes">Create _icon for this tag when first used</property>
+                <property name="use_underline">True</property>
+                <property name="response_id">0</property>
+                <property name="draw_indicator">True</property>
+              </widget>
+            </child>
+          </widget>
+          <packing>
+            <property name="fill">False</property>
+            <property name="position">3</property>
+          </packing>
+        </child>
         <child internal-child="action_area">
           <widget class="GtkHButtonBox" id="hbuttonbox1">
             <property name="visible">True</property>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]