[tracker/needle: 44/53] tracker-needle: Added a tag list



commit d992960034ea62fe3f23420e436188b209726e85
Author: Martyn Russell <martyn lanedo com>
Date:   Fri Oct 1 21:27:16 2010 +0100

    tracker-needle: Added a tag list
    
    NOTE: For some reason searching for tags doesn't work, I would expect fts:match to work here??
    Need to investigate that so searching normally finds these.
    Next task is to allow setting/unsetting tags by the new list

 src/tracker-needle/Makefile.am          |    1 +
 src/tracker-needle/tracker-needle.ui    |   17 +++-
 src/tracker-needle/tracker-needle.vala  |   38 +++++++--
 src/tracker-needle/tracker-stats.vala   |    4 +-
 src/tracker-needle/tracker-taglist.vala |  146 +++++++++++++++++++++++++++++++
 5 files changed, 194 insertions(+), 12 deletions(-)
---
diff --git a/src/tracker-needle/Makefile.am b/src/tracker-needle/Makefile.am
index ef3e4d7..65692e4 100644
--- a/src/tracker-needle/Makefile.am
+++ b/src/tracker-needle/Makefile.am
@@ -8,6 +8,7 @@ tracker_needle_VALASOURCES = 					\
 	tracker-needle.vala \
 	tracker-query.vala \
 	tracker-stats.vala \
+	tracker-taglist.vala \
 	tracker-utils.vala \
 	tracker-view.vala
 
diff --git a/src/tracker-needle/tracker-needle.ui b/src/tracker-needle/tracker-needle.ui
index b654273..58a9d44 100644
--- a/src/tracker-needle/tracker-needle.ui
+++ b/src/tracker-needle/tracker-needle.ui
@@ -4,7 +4,7 @@
   <!-- interface-naming-policy project-wide -->
   <object class="GtkWindow" id="window_needle">
     <property name="title" translatable="yes">Needle</property>
-    <property name="default_width">640</property>
+    <property name="default_width">720</property>
     <property name="default_height">480</property>
     <child>
       <object class="GtkVBox" id="vbox_main">
@@ -69,7 +69,6 @@
               <object class="GtkRadioToolButton" id="toolbutton_find_in_contents">
                 <property name="visible">True</property>
                 <property name="tooltip_text" translatable="yes">Find search criteria inside files</property>
-                <property name="label" translatable="yes">toolbutton3</property>
                 <property name="use_underline">True</property>
                 <property name="stock_id">gtk-find</property>
                 <property name="active">True</property>
@@ -83,7 +82,6 @@
               <object class="GtkRadioToolButton" id="toolbutton_find_in_titles">
                 <property name="visible">True</property>
                 <property name="tooltip_text" translatable="yes">Find search criteria in file titles</property>
-                <property name="label" translatable="yes">toolbutton4</property>
                 <property name="use_underline">True</property>
                 <property name="stock_id">gtk-bold</property>
                 <property name="group">toolbutton_find_in_contents</property>
@@ -168,6 +166,18 @@
               </packing>
             </child>
             <child>
+              <object class="GtkToggleToolButton" id="toolbutton_show_tags">
+                <property name="visible">True</property>
+                <property name="tooltip_text" translatable="yes">Tags</property>
+                <property name="use_underline">True</property>
+                <property name="icon_name">emblem-default</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
+            <child>
               <object class="GtkToolButton" id="toolbutton_show_stats">
                 <property name="visible">True</property>
                 <property name="tooltip_text" translatable="yes">Show statistics about the data stored</property>
@@ -188,6 +198,7 @@
         <child>
           <object class="GtkHBox" id="hbox_view">
             <property name="visible">True</property>
+            <property name="spacing">6</property>
             <child>
               <placeholder/>
             </child>
diff --git a/src/tracker-needle/tracker-needle.vala b/src/tracker-needle/tracker-needle.vala
index bf3bc15..1fd1d91 100644
--- a/src/tracker-needle/tracker-needle.vala
+++ b/src/tracker-needle/tracker-needle.vala
@@ -19,8 +19,10 @@
 
 using Gtk;
 using Tracker.Sparql;
-using Tracker.View;
 using Tracker.Config;
+using Tracker.Stats;
+using Tracker.TagList;
+using Tracker.View;
 
 [CCode (cname = "TRACKER_UI_DIR")]
 extern static const string UIDIR;
@@ -42,6 +44,7 @@ public class Tracker.Needle {
 	private Entry search;
 	private Spinner spinner;
 	private ToolItem spinner_shell;
+	private ToggleToolButton show_tags;
 	private ToolButton show_stats;
 	private HBox view;
 	private Tracker.View sw_noresults;
@@ -49,6 +52,7 @@ public class Tracker.Needle {
 	private TreeView treeview;
 	private Tracker.View sw_iconview;
 	private IconView iconview;
+	private Tracker.TagList taglist;
 	private uint last_search_id = 0;
 	private ListStore store;
 	private int size_small = 0;
@@ -122,6 +126,9 @@ public class Tracker.Needle {
 		spinner_shell = builder.get_object ("toolcustom_spinner") as ToolItem;
 		spinner_shell.add (spinner);
 
+		show_tags = builder.get_object ("toolbutton_show_tags") as ToggleToolButton;
+		show_tags.clicked.connect (show_tags_clicked);
+
 		show_stats = builder.get_object ("toolbutton_show_stats") as ToolButton;
 		show_stats.clicked.connect (show_stats_clicked);
 
@@ -141,6 +148,11 @@ public class Tracker.Needle {
 
 		// Set up view models
 		setup_ui_results (treeview, iconview);
+		
+		// Set up taglist
+		taglist = new Tracker.TagList ();
+		taglist.hide ();
+		view.pack_end (taglist, false, true, 0);
 
 		view_details.set_active (true);
 	}
@@ -473,6 +485,13 @@ public class Tracker.Needle {
 		// Hide spinner
 		spinner.stop ();
 		spinner_shell.hide ();
+
+		// Check if we have any results, if we don't change the view
+		if (store.iter_n_children (null) < 1) {
+			sw_noresults.show ();
+			sw_iconview.hide ();
+			sw_treeview.hide ();
+		}
 	}
 
 	private TreeIter? search_history_find_or_insert (string criteria, bool? add_to_model = false) {
@@ -527,11 +546,6 @@ public class Tracker.Needle {
 		string criteria = str.strip ();
 
 		if (criteria.length < 1) {
-			// Show no results window
-			sw_noresults.show ();
-			sw_iconview.hide ();
-			sw_treeview.hide ();
-
 			search_finished ();
 
 			return false;
@@ -647,9 +661,19 @@ public class Tracker.Needle {
 		}
 	}
 
+	private void show_tags_clicked () {
+		if (show_tags.active) {
+			debug ("Showing tags");
+			taglist.show ();
+		} else {
+			debug ("Hiding tags");
+			taglist.hide ();
+		}
+	}
+
 	private void show_stats_clicked () {
 		debug ("Showing stats dialog");
-		TrackerStats s = new TrackerStats ();
+		Tracker.Stats s = new Tracker.Stats ();
 		s.show ();
 	}
 }
diff --git a/src/tracker-needle/tracker-stats.vala b/src/tracker-needle/tracker-stats.vala
index 6ac3001..9cb14bc 100644
--- a/src/tracker-needle/tracker-stats.vala
+++ b/src/tracker-needle/tracker-stats.vala
@@ -27,10 +27,10 @@ interface Statistics : GLib.Object {
 	public abstract string[,] Get () throws DBus.Error;
 }
 
-public class TrackerStats : Dialog {
+public class Tracker.Stats : Dialog {
 	private Statistics tracker;
 
-	public TrackerStats () {
+	public Stats () {
 		this.title = "Statistics";
 		this.has_separator = false;
 		this.border_width = 12;
diff --git a/src/tracker-needle/tracker-taglist.vala b/src/tracker-needle/tracker-taglist.vala
new file mode 100644
index 0000000..a780359
--- /dev/null
+++ b/src/tracker-needle/tracker-taglist.vala
@@ -0,0 +1,146 @@
+//
+// Copyright 2010, Martyn Russell <martyn lanedo com>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+// 02110-1301, USA.
+//
+
+using Gtk;
+
+public class Tracker.TagList : ScrolledWindow {
+	static Sparql.Connection connection;
+	private TreeView treeview;
+	private ListStore store;
+	private int offset;
+	private int limit;
+
+	public TagList () {
+		limit = 100;
+
+		// Set scrolling
+		set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC);
+		set_size_request (175, -1);
+
+		// Add widgets
+		store = new ListStore (4,
+		                       typeof (bool),    // Enabled
+		                       typeof (string),  // Name
+		                       typeof (string),  // Description
+		                       typeof (string)); // Count
+		treeview = new TreeView.with_model (store);
+
+		treeview.set_headers_visible (true);
+
+		Gtk.TreeViewColumn col;
+		Gtk.CellRenderer renderer;
+
+		col = new Gtk.TreeViewColumn ();
+		col.set_title (_("Tags"));
+		col.set_resizable (true);
+		col.set_expand (true);
+		col.set_sizing (Gtk.TreeViewColumnSizing.AUTOSIZE);
+
+		// Do this later when we have more time
+//		renderer = new CellRendererToggle ();
+//		renderer.xpad = 5;
+//		renderer.ypad = 5;
+//		col.pack_start (renderer, false);
+//		col.add_attribute (renderer, "active", 0);
+
+		renderer = new Tracker.CellRendererText ();
+		col.pack_start (renderer, true);
+		col.add_attribute (renderer, "text", 1);
+		col.add_attribute (renderer, "subtext", 2);
+
+		renderer = new CellRendererText ();
+		renderer.xpad = 5;
+		renderer.ypad = 5;
+		col.pack_end (renderer, false);
+		col.add_attribute (renderer, "text", 3);
+		treeview.append_column (col);
+
+		add (treeview);
+		base.show_all ();
+
+		// Add data
+		try {
+			connection = Sparql.Connection.get ();
+		} catch (Sparql.Error e) {
+			warning ("Could not get Sparql connection: %s", e.message);
+			return;
+		}
+
+		get_tags.begin ();
+	}
+
+	private async void get_tags () {
+		string query = @"
+		               SELECT 
+		                 ?tag 
+		                 ?label
+		                 nao:description(?tag)
+		                 COUNT(?urns) AS urns
+		               WHERE {
+		                 ?tag a nao:Tag ;
+		                 nao:prefLabel ?label .
+		                 OPTIONAL {
+		                   ?urns nao:hasTag ?tag
+		                 }
+		               } 
+		               GROUP BY ?tag 
+		               ORDER BY ASC(?label) 
+		               OFFSET $offset 
+		               LIMIT $limit
+		               ";
+		
+		debug ("Getting tags");
+
+		Sparql.Cursor cursor = null;
+
+		try {
+			cursor = yield connection.query_async (query, null);
+
+			while (yield cursor.next_async ()) {
+				for (int i = 0; i < cursor.n_columns; i++) {
+					if (i == 0) {
+						debug ("--> %s", cursor.get_string (i));
+					} else {
+						debug ("  --> %s", cursor.get_string (i));
+					}
+				}
+
+				// Insert into model
+				TreeIter iter;
+				store.append (out iter);
+
+				store.set (iter,
+				           0, false,                      // Enabled
+				           1, cursor.get_string (1),      // Name
+				           2, cursor.get_string (2),      // Description
+				           3, cursor.get_string (3),      // Count
+				           -1);
+			}
+		} catch (Sparql.Error ea) {
+			warning ("Could not run Sparql query: %s", ea.message);
+		} catch (GLib.IOError eb) {
+			warning ("Could not run Sparql query: %s", eb.message);
+		} catch (GLib.Error ec) {
+			warning ("Could not run Sparql query: %s", ec.message);
+		}
+
+		debug ("  Done");
+	}
+}
+



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