Last Import patch



Hi Guys

I played around abit with Gunnar's "Last Import" patch, and added a bit
here and there...

The current version tracks the last 6 imports with the following tag
structure.

Last Imports
  __0
  __1
  __2
  __3
  __4
  __5

The reason for the __0 etc is that the tags has to be unique, and wanted
to minimize the risk that the user had already created a tag like this.

I also prepared with a Bool (const right now) to enable/disable tracking
the imports. Should be fairly easy to put this into Preferences.

I moved all database updates to TagStore.cs

If the tags are not there, they are created automatically during import.
My small timings (played with 123 photos) indicate not much difference
from just tagging the pictures normally during import.

Outstanding items
-----------------
1) Ensure that no new tags can be created that contains the above tag names.
2) Ensure that the above tag names do not show up in the "Attach tag
during import" list.

Any comments?
Is it overkill with tracking 6 imports?
I do think only have the last is not enough though.


/Bengt

Both attached it as a diff file, as well as included it below.

--- ImportCommand.CVS.cs        2006-05-19 16:48:03.000000000 +0800
+++ ImportCommand.cs    2006-05-19 15:31:12.000000000 +0800
@@ -320,6 +320,8 @@ public class ImportCommand : FSpot.Glade
        IconView tray;

        FSpot.Delay idle_start;
+
+       bool Track_Last_Imports = true;  // If user wants to track the
latest import sessions or not. Should be in preferences.

        string loading_string;

@@ -643,14 +645,34 @@ public class ImportCommand : FSpot.Glade
                if (response == ResponseType.Ok) {
                        this.Finish ();

-                       if (attach_check.Active && tag_selected != null) {
+                        Tag tag_last_roll = null;
+
+                        // If the user have requested to track the latest
imports, then
+                        // we have to make room for this import session.
+                        // Either create the import tags (Root + 0), or
shift the import tags one step (4->5, 3->4
etc)
+                        if (Track_Last_Imports) {
+                                TagStore tag_store =
MainWindow.Toplevel.Database.Tags;
+                               tag_last_roll =
tag_store.Prepare_New_Import();
+                       }
+
+                        // Only update the tags, if user wants to add a
tag and/or last imports are tracked.
+                       if (Track_Last_Imports || (attach_check.Active &&
tag_selected != null)) {
+
+                               // Loop through each imported photo and
attach tag(s)
                                for (int i = 0; i < collection.Count; i++) {
                                        Photo p = collection [i] as Photo;

                                        if (p == null)
                                                continue;

-                                       p.AddTag (tag_selected);
+                                       // Attach user specified tag
+                                       if (attach_check.Active &&
tag_selected != null)
+                                               p.AddTag (tag_selected);
+
+                                       // Attach Import Session tag if
user requests it.
+                                       if (Track_Last_Imports)
+                                               p.AddTag (tag_last_roll);
+
                                        store.Commit (p);
                                }
                        }
--- TagStore.CVS.cs     2006-05-19 16:48:03.000000000 +0800
+++ TagStore.cs 2006-05-19 15:54:27.000000000 +0800
@@ -247,6 +247,13 @@ public class TagStore : DbStore {
        }

        private const string STOCK_ICON_DB_PREFIX = "stock_icon:";
+       private const string LAST_IMPORT_STR   = "Last Imports";
+       private const string LAST_IMPORT_0_STR = "__0";
+       private const string LAST_IMPORT_1_STR = "__1";
+       private const string LAST_IMPORT_2_STR = "__2";
+       private const string LAST_IMPORT_3_STR = "__3";
+       private const string LAST_IMPORT_4_STR = "__4";
+       private const string LAST_IMPORT_5_STR = "__5";

        private void SetIconFromString (Tag tag, string icon_string)
        {
@@ -297,6 +304,77 @@ public class TagStore : DbStore {
                return (Tag []) (l.ToArray (typeof (Tag)));
        }

+        private void Change_Tag1_to_Tag2 (SqliteCommand command, Tag
tag1, Tag _tag2,
+                                          string tag2_str, Tag tagParent)
+        {
+                // This function will simply change so all photos that
have "tag1" now has "tag2" instead.
+
+                // Only do the below if the first tag exist
+                if (tag1 != null) {
+
+                        // Create tag2 if it does not exist
+                        Tag tag2 = _tag2;
+                        if (tag2 == null) {
+                                tag2 = CreateTag (tagParent as Category,
Catalog.GetString (tag2_str));
+                        }
+
+                        // Move younger one to older one (4-->5)
+                       command.CommandText = String.Format
+                             ("UPDATE photo_tags SET tag_id = {0} WHERE
tag_id = {1}", tag2.Id, tag1.Id);
+                       command.ExecuteNonQuery ();
+               }
+
+        }
+
+       public Tag Prepare_New_Import ()
+        {
+
+                // Ensure we have a Last Import tag
+                Tag tag_last_roll_root = GetTagByName(Catalog.GetString
(LAST_IMPORT_STR));
+
+                if (tag_last_roll_root == null) { // Last Import tag do
not exist. Create it.
+                        tag_last_roll_root = CreateCategory
(RootCategory, Catalog.GetString (LAST_IMPORT_STR));
+                        tag_last_roll_root.StockIconName =
"f-spot-other.png";
+                        tag_last_roll_root.SortPriority = -11;
+                        Commit (tag_last_roll_root);
+               }
+
+               SqliteCommand command = new SqliteCommand ();
+               command.Connection = Connection;
+
+                // Get the various tags
+                Tag tmp_tag_0 = GetTagByName (Catalog.GetString
(LAST_IMPORT_0_STR));
+                Tag tmp_tag_1 = GetTagByName (Catalog.GetString
(LAST_IMPORT_1_STR));
+                Tag tmp_tag_2 = GetTagByName (Catalog.GetString
(LAST_IMPORT_2_STR));
+                Tag tmp_tag_3 = GetTagByName (Catalog.GetString
(LAST_IMPORT_3_STR));
+                Tag tmp_tag_4 = GetTagByName (Catalog.GetString
(LAST_IMPORT_4_STR));
+                Tag tmp_tag_5 = GetTagByName (Catalog.GetString
(LAST_IMPORT_5_STR));
+
+                // Delete the oldest import tag
+                if (tmp_tag_5 != null) {
+                       command.CommandText = String.Format
+                             ("DELETE FROM photo_tags WHERE tag_id =
{0}", tmp_tag_5.Id);
+                       command.ExecuteNonQuery ();
+               }
+
+                Change_Tag1_to_Tag2 (command, tmp_tag_4, tmp_tag_5,
LAST_IMPORT_5_STR, tag_last_roll_root);
+                Change_Tag1_to_Tag2 (command, tmp_tag_3, tmp_tag_4,
LAST_IMPORT_4_STR, tag_last_roll_root);
+                Change_Tag1_to_Tag2 (command, tmp_tag_2, tmp_tag_3,
LAST_IMPORT_3_STR, tag_last_roll_root);
+                Change_Tag1_to_Tag2 (command, tmp_tag_1, tmp_tag_2,
LAST_IMPORT_2_STR, tag_last_roll_root);
+                Change_Tag1_to_Tag2 (command, tmp_tag_0, tmp_tag_1,
LAST_IMPORT_1_STR, tag_last_roll_root);
+
+                // Ensure we have the Most Recent Import tag (0)
+                if (tmp_tag_0 == null)
+                        tmp_tag_0 = CreateTag (tag_last_roll_root as
Category, Catalog.GetString (LAST_IMPORT_0_STR));
+
+
+               command.Dispose ();
+
+                // Return the tag wich points to "0" which is the most
recent import tag.
+                return tmp_tag_0;
+        }
+
+
        // In this store we keep all the items (i.e. the tags) in memory
at all times.  This is
        // mostly to simplify handling of the parent relationship between
tags, but it also makes it
        // a little bit faster.  We achieve this by passing "true" as the
cache_is_immortal to our

-- 
Bengt Thuree   bengt thuree com
--- ImportCommand.CVS.cs	2006-05-19 16:48:03.000000000 +0800
+++ ImportCommand.cs	2006-05-19 15:31:12.000000000 +0800
@@ -320,6 +320,8 @@ public class ImportCommand : FSpot.Glade
 	IconView tray;
 
 	FSpot.Delay idle_start; 
+	
+	bool Track_Last_Imports = true;  // If user wants to track the latest import sessions or not. Should be in preferences.
 
 	string loading_string;
 
@@ -643,14 +645,34 @@ public class ImportCommand : FSpot.Glade
 		if (response == ResponseType.Ok) {
 			this.Finish ();
 
-			if (attach_check.Active && tag_selected != null) {
+                        Tag tag_last_roll = null;
+                        
+                        // If the user have requested to track the latest imports, then
+                        // we have to make room for this import session. 
+                        // Either create the import tags (Root + 0), or shift the import tags one step (4->5, 3->4 etc)
+                        if (Track_Last_Imports) {
+                                TagStore tag_store = MainWindow.Toplevel.Database.Tags; 
+			        tag_last_roll = tag_store.Prepare_New_Import();        
+			}
+
+                        // Only update the tags, if user wants to add a tag and/or last imports are tracked.
+			if (Track_Last_Imports || (attach_check.Active && tag_selected != null)) {
+			
+			        // Loop through each imported photo and attach tag(s)
 				for (int i = 0; i < collection.Count; i++) {
 					Photo p = collection [i] as Photo;
 					
 					if (p == null)
 						continue;
 					
-					p.AddTag (tag_selected);
+					// Attach user specified tag
+					if (attach_check.Active && tag_selected != null)
+					        p.AddTag (tag_selected);
+					        
+					// Attach Import Session tag if user requests it.
+					if (Track_Last_Imports)
+					        p.AddTag (tag_last_roll);
+					        
 					store.Commit (p);
 				}
 			}
--- TagStore.CVS.cs	2006-05-19 16:48:03.000000000 +0800
+++ TagStore.cs	2006-05-19 15:54:27.000000000 +0800
@@ -247,6 +247,13 @@ public class TagStore : DbStore {
 	}
 
 	private const string STOCK_ICON_DB_PREFIX = "stock_icon:";
+	private const string LAST_IMPORT_STR   = "Last Imports";
+	private const string LAST_IMPORT_0_STR = "__0";
+	private const string LAST_IMPORT_1_STR = "__1";
+	private const string LAST_IMPORT_2_STR = "__2";
+	private const string LAST_IMPORT_3_STR = "__3";
+	private const string LAST_IMPORT_4_STR = "__4";
+	private const string LAST_IMPORT_5_STR = "__5";
 
 	private void SetIconFromString (Tag tag, string icon_string)
 	{
@@ -297,6 +304,77 @@ public class TagStore : DbStore {
 		return (Tag []) (l.ToArray (typeof (Tag)));
 	}
 
+        private void Change_Tag1_to_Tag2 (SqliteCommand command, Tag tag1, Tag _tag2, 
+                                          string tag2_str, Tag tagParent)
+        {
+                // This function will simply change so all photos that have "tag1" now has "tag2" instead.
+
+                // Only do the below if the first tag exist
+                if (tag1 != null) { 
+                        
+                        // Create tag2 if it does not exist
+                        Tag tag2 = _tag2;
+                        if (tag2 == null) { 
+                                tag2 = CreateTag (tagParent as Category, Catalog.GetString (tag2_str));
+                        }
+                        
+                        // Move younger one to older one (4-->5)
+		        command.CommandText = String.Format 
+		              ("UPDATE photo_tags SET tag_id = {0} WHERE tag_id = {1}", tag2.Id, tag1.Id);
+		        command.ExecuteNonQuery ();
+		}
+                
+        }
+
+	public Tag Prepare_New_Import ()
+        {
+                
+                // Ensure we have a Last Import tag
+                Tag tag_last_roll_root = GetTagByName(Catalog.GetString (LAST_IMPORT_STR));
+
+                if (tag_last_roll_root == null) { // Last Import tag do not exist. Create it.
+                        tag_last_roll_root = CreateCategory (RootCategory, Catalog.GetString (LAST_IMPORT_STR));
+                        tag_last_roll_root.StockIconName = "f-spot-other.png";
+                        tag_last_roll_root.SortPriority = -11;
+                        Commit (tag_last_roll_root);
+		}
+		
+		SqliteCommand command = new SqliteCommand ();
+		command.Connection = Connection;
+
+                // Get the various tags
+                Tag tmp_tag_0 = GetTagByName (Catalog.GetString (LAST_IMPORT_0_STR));
+                Tag tmp_tag_1 = GetTagByName (Catalog.GetString (LAST_IMPORT_1_STR));
+                Tag tmp_tag_2 = GetTagByName (Catalog.GetString (LAST_IMPORT_2_STR));
+                Tag tmp_tag_3 = GetTagByName (Catalog.GetString (LAST_IMPORT_3_STR));
+                Tag tmp_tag_4 = GetTagByName (Catalog.GetString (LAST_IMPORT_4_STR));
+                Tag tmp_tag_5 = GetTagByName (Catalog.GetString (LAST_IMPORT_5_STR));
+
+                // Delete the oldest import tag
+                if (tmp_tag_5 != null) {
+		        command.CommandText = String.Format 
+		              ("DELETE FROM photo_tags WHERE tag_id = {0}", tmp_tag_5.Id);
+		        command.ExecuteNonQuery ();
+		}
+
+                Change_Tag1_to_Tag2 (command, tmp_tag_4, tmp_tag_5, LAST_IMPORT_5_STR, tag_last_roll_root);
+                Change_Tag1_to_Tag2 (command, tmp_tag_3, tmp_tag_4, LAST_IMPORT_4_STR, tag_last_roll_root);
+                Change_Tag1_to_Tag2 (command, tmp_tag_2, tmp_tag_3, LAST_IMPORT_3_STR, tag_last_roll_root);
+                Change_Tag1_to_Tag2 (command, tmp_tag_1, tmp_tag_2, LAST_IMPORT_2_STR, tag_last_roll_root);
+                Change_Tag1_to_Tag2 (command, tmp_tag_0, tmp_tag_1, LAST_IMPORT_1_STR, tag_last_roll_root);
+
+                // Ensure we have the Most Recent Import tag (0)
+                if (tmp_tag_0 == null) 
+                        tmp_tag_0 = CreateTag (tag_last_roll_root as Category, Catalog.GetString (LAST_IMPORT_0_STR));
+
+
+		command.Dispose ();
+
+                // Return the tag wich points to "0" which is the most recent import tag.
+                return tmp_tag_0;
+        }
+
+
 	// In this store we keep all the items (i.e. the tags) in memory at all times.  This is
 	// mostly to simplify handling of the parent relationship between tags, but it also makes it
 	// a little bit faster.  We achieve this by passing "true" as the cache_is_immortal to our


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