[tracker/rss-enclosures] fixes GB#620354 make TST history persistent



commit 6aadd2d420cb2ce1293140f800a6e583ada48cd5
Author: Tshepang Lekhonkhobe <tshepang gmail com>
Date:   Wed Jun 2 14:29:59 2010 +0200

    fixes GB#620354 make TST history persistent

 src/tracker-search-tool/tracker-entry.gs       |   38 ++++++++++++++++++++----
 src/tracker-search-tool/tracker-result-grid.gs |    9 ++----
 2 files changed, 35 insertions(+), 12 deletions(-)
---
diff --git a/src/tracker-search-tool/tracker-entry.gs b/src/tracker-search-tool/tracker-entry.gs
index 4ea9c3c..00b0633 100644
--- a/src/tracker-search-tool/tracker-entry.gs
+++ b/src/tracker-search-tool/tracker-entry.gs
@@ -27,10 +27,15 @@ uses
 /* wait 0.5s after each keystroke before performing a search */
 const static RUN_DELAY : int = 500
 
+/* acceptable length of string for history */
+const static TOO_SHORT : int = 2
+
 class TrackerSearchEntry  : ComboBoxEntry implements Gtk.Activatable
     id_invoker : uint = 0
     entry : Entry
     history : list of string
+    histfilename : string
+    histfile : FileStream
 
     prop Query : TrackerQuery
 
@@ -56,8 +61,21 @@ class TrackerSearchEntry  : ComboBoxEntry implements Gtk.Activatable
             if p0 is EntryIconPosition.SECONDARY
                 entry.text = ""
 
+        histfilename = Path.build_filename (Environment.get_user_data_dir(),
+            "tracker", "history", null)
+        var temp = ""
         history = new list of string
 
+        /* load history from file */
+        try
+            FileUtils.get_contents(histfilename, out temp)
+            for item in temp.split("\n")
+                if item.len() > TOO_SHORT
+                    prepend_text(item)
+                    history.add(item)
+        except e : FileError
+            print (e.message)
+
     def private entry_changed ()
         if entry.text is null
             Query.SearchTerms = ""
@@ -80,26 +98,34 @@ class TrackerSearchEntry  : ComboBoxEntry implements Gtk.Activatable
 
         Query.SearchTerms = EscapeSparql (txt, true)
 
+        history_handler(txt)
+        return false
+
+    def history_handler (text : string)
         /* remove leading and trailing whitespace before inserting items into
          * history; this avoids having both "term" and " term " in there;
          */
-        txt = txt.strip()
+        var txt = text.strip()
 
         /* ensure that accented chars are represented the same way to
          * avoid duplicated entries in history
          */
         txt = txt.normalize(-1, NormalizeMode.NFC)
 
-        if txt.len() > 2
-            /* do not store items in history */
+        if txt.len() > TOO_SHORT
+
+            /* do not store duplicate items in history */
             for item in history
                 if txt == item
-                    return false
+                    return
 
             history.add(txt)
             prepend_text(txt)
-
-        return false
+            histfile = FileStream.open(histfilename, "a")
+            if (FileStream.open(histfilename, "a") != null)
+                histfile.printf("%s\n", txt)
+            else
+                print("error: '%s' is not writable", histfilename)
 
     def sync_action_properties (action : Action)
         return
diff --git a/src/tracker-search-tool/tracker-result-grid.gs b/src/tracker-search-tool/tracker-result-grid.gs
index f1ee1ff..0941844 100644
--- a/src/tracker-search-tool/tracker-result-grid.gs
+++ b/src/tracker-search-tool/tracker-result-grid.gs
@@ -59,6 +59,7 @@ class TrackerResultGrid : ScrolledWindow
                 _query.ClearSearchResults += def ()
                     store.clear ()
 
+
     def GetSelectedPath () : TreePath?
         if iconview.get_selected_items () is not null
             return (Gtk.TreePath) iconview.get_selected_items ().data
@@ -69,8 +70,8 @@ class TrackerResultGrid : ScrolledWindow
     def GetSelectedUri () : weak string
         iter : TreeIter
         uri : weak string
-
         var path = GetSelectedPath ()
+
         if path is not null
             store.get_iter (out iter, path)
             store.get (iter, ResultColumns.Uri, out uri);
@@ -131,9 +132,7 @@ class TrackerResultGrid : ScrolledWindow
                 var id = results[i]
                 var mime = results[i+2]                     
                 i += 3
-            
-                
-            
+
                 if uri.has_prefix ("file://")
 
                     has_results = true
@@ -160,8 +159,6 @@ class TrackerResultGrid : ScrolledWindow
                     iconview.select_path (path)
 
 
-
-
     def ActivateUri (path : TreePath)
         iter : TreeIter
         is_dir : bool = false



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