[tracker/needle: 28/41] tracker-needle: Added support for detailed view



commit 460e0b8e4ff34c1cf480d4d36b861c2585073d28
Author: Martyn Russell <martyn lanedo com>
Date:   Mon Aug 16 00:26:29 2010 +0100

    tracker-needle: Added support for detailed view
    
    Applications: show details
    Music: shows artist/album
    Documents: show path (will show page count, etc later)
    Images: show width x height
    Videos: show duration

 src/tracker-needle/tracker-cell-renderer-text.vala |    2 +-
 src/tracker-needle/tracker-needle.vala             |  158 +++++++++++++++++---
 src/tracker-needle/tracker-query.vala              |  103 ++++++++++++-
 src/tracker-needle/tracker-utils.vala              |   58 +++++++-
 4 files changed, 295 insertions(+), 26 deletions(-)
---
diff --git a/src/tracker-needle/tracker-cell-renderer-text.vala b/src/tracker-needle/tracker-cell-renderer-text.vala
index 841a5a5..a6fd603 100644
--- a/src/tracker-needle/tracker-cell-renderer-text.vala
+++ b/src/tracker-needle/tracker-cell-renderer-text.vala
@@ -54,7 +54,7 @@ class Tracker.CellRendererText : Gtk.CellRendererText {
 		if (is_valid && is_selected == selected) {
 			return;
 		}
-
+		//subtext = "foo";
 		var style = widget.get_style ();
 		var attr_list = new Pango.AttrList ();
 
diff --git a/src/tracker-needle/tracker-needle.vala b/src/tracker-needle/tracker-needle.vala
index f7ae539..c35a2f4 100644
--- a/src/tracker-needle/tracker-needle.vala
+++ b/src/tracker-needle/tracker-needle.vala
@@ -43,6 +43,7 @@ public class TrackerNeedle {
 	private uint last_search_id = 0;
 	private ListStore store;
 	private int size_small = 0;
+	private int size_medium = 0;
 	private int size_big = 0;
 	static bool current_view = true;
 	static bool current_find_in = true;
@@ -76,6 +77,7 @@ public class TrackerNeedle {
 		}
 
 		Gtk.icon_size_lookup (Gtk.IconSize.MENU, out size_small, null);
+		Gtk.icon_size_lookup (Gtk.IconSize.DND, out size_medium, null);
 		Gtk.icon_size_lookup (Gtk.IconSize.DIALOG, out size_big, null);
 
 		window = builder.get_object ("window_needle") as Window;
@@ -113,17 +115,18 @@ public class TrackerNeedle {
 
 	private void setup_ui_results (TreeView treeview, IconView iconview) {
 		// Setup treeview
-		store = new ListStore (8,
+		store = new ListStore (9,
 		                       typeof (Gdk.Pixbuf),  // Icon small
 		                       typeof (Gdk.Pixbuf),  // Icon big
 		                       typeof (string),      // URN
 		                       typeof (string),      // URL
-		                       typeof (string),      // File name
+		                       typeof (string),      // Title
+		                       typeof (string),      // Subtitle
 		                       typeof (string),      // File last changed
 		                       typeof (string),      // File size
 		                       typeof (string));     // Tooltip
 		treeview.set_model (store);
-		treeview.set_tooltip_column (7);
+		treeview.set_tooltip_column (8);
 
 		var col = new Gtk.TreeViewColumn ();
 
@@ -134,6 +137,7 @@ public class TrackerNeedle {
 		var renderer2 = new Tracker.CellRendererText ();
 		col.pack_start (renderer2, true);
 		col.add_attribute (renderer2, "text", 4);
+		col.add_attribute (renderer2, "subtext", 5);
 
 		col.set_title ("File");
 		col.set_resizable (true);
@@ -141,8 +145,8 @@ public class TrackerNeedle {
 		col.set_sizing (Gtk.TreeViewColumnSizing.AUTOSIZE);
 		treeview.append_column (col);
 
-		treeview.insert_column_with_attributes (-1, "Last Changed", new CellRendererText (), "text", 5, null);
-		treeview.insert_column_with_attributes (-1, "Size", new CellRendererText (), "text", 6, null);
+		treeview.insert_column_with_attributes (-1, "Last Changed", new CellRendererText (), "text", 6, null);
+		treeview.insert_column_with_attributes (-1, "Size", new CellRendererText (), "text", 7, null);
 		treeview.row_activated.connect (view_row_selected);
 
 		// Setup iconview
@@ -162,9 +166,7 @@ public class TrackerNeedle {
 		last_search_id = Timeout.add_seconds (1, search_run);
 	}
 
-	private bool search_run () {
-		last_search_id = 0;
-
+	private void search_simple () {
 		Tracker.Query query = new Tracker.Query ();
 		Tracker.Sparql.Cursor cursor = null;
 
@@ -179,7 +181,7 @@ public class TrackerNeedle {
 
 		if (cursor == null) {
 			// FIXME: Print "no results" some where
-			return false;
+			return;
 		}
 
 		store.clear ();
@@ -198,7 +200,6 @@ public class TrackerNeedle {
 						debug ("  --> %s", cursor.get_string (i));
 					}
 				}
-				debug ("\n");
 
 				// Get icon
 				string urn = cursor.get_string (0);
@@ -207,8 +208,8 @@ public class TrackerNeedle {
 				string _file_time = cursor.get_string (3);
 				string _file_size = cursor.get_string (4);
 				string tooltip = cursor.get_string (7);
-				Gdk.Pixbuf pixbuf_small = tracker_pixbuf_new_from_file (theme, _file, size_small);
-				Gdk.Pixbuf pixbuf_big = tracker_pixbuf_new_from_file (theme, _file, size_big);
+				Gdk.Pixbuf pixbuf_small = tracker_pixbuf_new_from_file (theme, _file, size_small, false);
+				Gdk.Pixbuf pixbuf_big = tracker_pixbuf_new_from_file (theme, _file, size_big, false);
 				string file_size = GLib.format_size_for_display (_file_size.to_int());
 				string file_time = tracker_time_format_from_iso8601 (_file_time);
 
@@ -218,19 +219,117 @@ public class TrackerNeedle {
 
 				// FIXME: should optimise this a bit more, inserting 2 images into a list eek
 				store.set (iter,
-					       0, pixbuf_small,
-					       1, pixbuf_big,
-					       2, urn,
-					       3, _file,
-					       4, title,
-					       5, file_time,
-					       6, file_size,
-					       7, tooltip,
+					       0, pixbuf_small, // Small Image
+					       1, pixbuf_big,   // Large Image
+					       2, urn,          // URN
+					       3, _file,        // URL
+					       4, title,        // Title
+					       5, null,         // Subtitle
+					       6, file_time,    // Time
+					       7, file_size,    // Size
+					       8, tooltip,      // Tooltip
 					       -1);
 			}
 		} catch (GLib.Error e) {
 			warning ("Could not iterate query results: %s", e.message);
-			return false;
+			return;
+		}
+	}
+
+	private void search_detailed () {
+		Tracker.Query.Type[] categories = { 
+			Tracker.Query.Type.APPLICATIONS,
+			Tracker.Query.Type.MUSIC,
+			Tracker.Query.Type.IMAGES,
+			Tracker.Query.Type.VIDEOS,
+			Tracker.Query.Type.DOCUMENTS
+		};
+		Tracker.Query query = new Tracker.Query ();
+
+		store.clear ();
+
+		var screen = window.get_screen ();
+		var theme = IconTheme.get_for_screen (screen);
+
+		foreach (Tracker.Query.Type type in categories) {
+			Tracker.Sparql.Cursor cursor;
+
+			query.limit = 100;
+			query.criteria = search.get_text ();
+
+			cursor = query.perform (type);
+
+			if (cursor == null) {
+				// FIXME: Print "no results" some where
+				return;
+			}
+
+			try {
+				while (cursor.next()) {
+					int i;
+
+					for (i = 0; i < cursor.n_columns; i++) {
+						if (i == 0) {
+							debug ("--> %s", cursor.get_string (i));
+						} else {
+							debug ("  --> %s", cursor.get_string (i));
+						}
+					}
+
+					bool is_image = type == Tracker.Query.Type.IMAGES;
+
+					string urn = cursor.get_string (0);
+					string _file = cursor.get_string (1);
+					string title = cursor.get_string (2);
+					string subtitle = null;
+					string tooltip = cursor.get_string (4);
+					Gdk.Pixbuf pixbuf_small = tracker_pixbuf_new_from_file (theme, _file, size_medium, is_image);
+
+					// Special cases
+					switch (type) {
+					case Tracker.Query.Type.VIDEOS:
+						subtitle = tracker_time_format_from_seconds (cursor.get_string (3));
+						break;
+						
+					default:
+						break;
+					}
+
+					if (subtitle == null) {
+						subtitle = cursor.get_string (3);
+					}
+
+					// Insert into model
+					TreeIter iter;
+					store.append (out iter);
+
+					// FIXME: should optimise this a bit more, inserting 2 images into a list eek
+					store.set (iter,
+							   0, pixbuf_small, // Small Image
+							   1, null,         // Large Image
+							   2, urn,          // URN
+							   3, _file,        // URL
+							   4, title,        // Title
+							   5, subtitle,     // Subtitle
+							   6, null,         // Time
+							   7, null,         // Size
+							   8, tooltip,      // Tooltip
+							   -1);
+				}
+			} catch (GLib.Error e) {
+				warning ("Could not iterate query results: %s", e.message);
+				return;
+			}
+		}
+	}
+
+	private bool search_run () {
+		last_search_id = 0;
+
+		if (view_details.active) {
+			search_detailed ();
+		} else {
+			search_simple ();
 		}
 
 		return false;
@@ -250,12 +349,29 @@ public class TrackerNeedle {
 			sw_iconview.hide ();
 			sw_treeview.show_all ();
 			debug ("View toggled to 'list' or 'details'");
+			
+			if (view_details.active) {
+				treeview.get_column (1).visible = false;
+				treeview.get_column (2).visible = false;
+				treeview.set_headers_visible (false);
+				find_in_contents.sensitive = false;
+				find_in_titles.sensitive = false;
+			} else {
+				treeview.get_column (1).visible = true;
+				treeview.get_column (2).visible = true;
+				treeview.set_headers_visible (true);
+				find_in_contents.sensitive = true;
+				find_in_titles.sensitive = true;
+			}
 		} else {
 			sw_iconview.show_all ();
 			sw_treeview.hide ();
+			find_in_contents.sensitive = true;
+			find_in_titles.sensitive = true;
 			debug ("View toggled to 'icons'");
 		}
 
+		search_run ();
 		current_view = rows;
 	}
 
diff --git a/src/tracker-needle/tracker-query.vala b/src/tracker-needle/tracker-query.vala
index ed76b42..3909b5a 100644
--- a/src/tracker-needle/tracker-query.vala
+++ b/src/tracker-needle/tracker-query.vala
@@ -23,7 +23,14 @@ public class Tracker.Query {
 	public enum Type {
 		ALL,
 		ALL_ONLY_IN_TITLES,
-		MUSIC
+		CONTACTS,
+		APPLICATIONS,
+		MUSIC,
+		IMAGES,
+		VIDEOS,
+		DOCUMENTS,
+		MAIL,
+		CALENDAR
 	}
 
 	public string criteria { get; set; }
@@ -59,14 +66,102 @@ public class Tracker.Query {
 
 		switch (query_type) {
 		case Type.ALL:
-			query = @"SELECT ?u nie:url(?u) tracker:coalesce(nie:title(?u), nfo:fileName(?u), \"Unknown\") nfo:fileLastModified(?u) nfo:fileSize(?u) nie:url(?c) WHERE { ?u fts:match \"$criteria_escaped\" . ?u nfo:belongsToContainer ?c ; tracker:available true . } ORDER BY DESC(fts:rank(?u)) OFFSET 0 LIMIT 100";
+			query = @"SELECT ?u nie:url(?u) tracker:coalesce(nie:title(?u), nfo:fileName(?u), \"Unknown\") nfo:fileLastModified(?u) nfo:fileSize(?u) nie:url(?c) WHERE { ?u fts:match \"$criteria_escaped\" . ?u nfo:belongsToContainer ?c ; tracker:available true . } ORDER BY DESC(fts:rank(?u)) OFFSET $offset LIMIT $limit";
 			break;
 			
 		case Type.ALL_ONLY_IN_TITLES:
-			query = @"SELECT ?u nie:url(?u) tracker:coalesce(nfo:fileName(?u), \"Unknown\") nfo:fileLastModified(?u) nfo:fileSize(?u) nie:url(?c) WHERE { ?u a nfo:FileDataObject ; nfo:belongsToContainer ?c ; tracker:available true . FILTER(fn:contains(nfo:fileName(?u), \"$criteria_escaped\")) } ORDER BY DESC(nfo:fileName(?u)) OFFSET 0 LIMIT 100";
+			query = @"SELECT ?u nie:url(?u) tracker:coalesce(nfo:fileName(?u), \"Unknown\") nfo:fileLastModified(?u) nfo:fileSize(?u) nie:url(?c) WHERE { ?u a nfo:FileDataObject ; nfo:belongsToContainer ?c ; tracker:available true . FILTER(fn:contains(nfo:fileName(?u), \"$criteria_escaped\")) } ORDER BY DESC(nfo:fileName(?u)) OFFSET $offset LIMIT $limit";
+			break;
+
+		case Type.APPLICATIONS:
+			query = @"
+			        SELECT
+			          ?urn 
+			          nie:url(?urn) 
+			          tracker:coalesce(nie:title(?urn), nfo:fileName(?urn), \"Unknown\") 
+			          nie:comment(?urn)
+			          nfo:softwareCmdLine (?urn)
+			        WHERE {
+			          ?urn a nfo:Software .
+			          ?urn fts:match \"$criteria_escaped\" .
+			        }
+			        ORDER BY DESC(fts:rank(?urn)) DESC(nie:title(?urn)) 
+			        OFFSET $offset LIMIT $limit
+			        ";
 			break;
 
 		case Type.MUSIC:
+			query = @"
+			        SELECT
+			          ?urn 
+			          nie:url(?urn) 
+			          tracker:coalesce(nie:title(?urn), nfo:fileName(?urn), \"Unknown\") 
+			          fn:string-join((?performer, ?album), \" - \") 
+			          ?tooltip
+			        WHERE {
+			          ?urn a nfo:Audio ;
+			          nmm:performer [ nmm:artistName ?performer ] ;
+			          nmm:musicAlbum [ nie:title ?album ] ;
+			          nfo:belongsToContainer [ nie:url ?tooltip ] .
+			          ?urn fts:match \"$criteria_escaped\" 
+			        }
+			        ORDER BY DESC(fts:rank(?urn)) DESC(nie:title(?urn)) 
+			        OFFSET $offset LIMIT $limit
+			        ";
+			break;
+
+		case Type.IMAGES:
+			query = @"
+			        SELECT
+			          ?urn 
+			          nie:url(?urn) 
+			          tracker:coalesce(nie:title(?urn), nfo:fileName(?urn), \"Unknown\") 
+			          fn:string-join((nfo:height(?urn), nfo:width(?urn)), \" x \") 
+			          ?tooltip
+			        WHERE {
+			          ?urn a nfo:Image ;
+			          nfo:belongsToContainer [ nie:url ?tooltip ] .
+			          ?urn fts:match \"$criteria_escaped\" 
+			        }
+			        ORDER BY DESC(fts:rank(?urn)) DESC(nie:title(?urn)) 
+			        OFFSET $offset LIMIT $limit
+			        ";
+			break;
+
+		case Type.VIDEOS:
+			query = @"
+			        SELECT
+			          ?urn 
+			          nie:url(?urn) 
+			          tracker:coalesce(nie:title(?urn), nfo:fileName(?urn), \"Unknown\") 
+			          nfo:duration(?urn)
+			          ?tooltip
+			        WHERE {
+			          ?urn a nfo:Video ;
+			          nfo:belongsToContainer [ nie:url ?tooltip ] .
+			          ?urn fts:match \"$criteria_escaped\" .
+			        }
+			        ORDER BY DESC(fts:rank(?urn)) DESC(nie:title(?urn)) 
+			        OFFSET $offset LIMIT $limit
+			        ";
+			break;
+
+		case Type.DOCUMENTS:
+//			          fn:concat(nco:pageCount(?urn), \" pages\")
+			query = @"
+			        SELECT
+			          ?urn 
+			          nie:url(?urn) 
+			          tracker:coalesce(nie:title(?urn), nfo:fileName(?urn), \"Unknown\") 
+			          ?tooltip
+			        WHERE {
+			          ?urn a nfo:Document ;
+			          nfo:belongsToContainer [ nie:url ?tooltip ] .
+			          ?urn fts:match \"$criteria_escaped\" .
+			        }
+			        ORDER BY DESC(fts:rank(?urn)) DESC(nie:title(?urn)) 
+			        OFFSET $offset LIMIT $limit
+			        ";
 			break;
 
 		default:
@@ -83,6 +178,8 @@ public class Tracker.Query {
 			warning ("Could not run Sparql query: %s", eb.message);
 		}
 
+		debug ("Done");
+
 		return cursor;
 	}
 }
diff --git a/src/tracker-needle/tracker-utils.vala b/src/tracker-needle/tracker-utils.vala
index 873486e..335ec85 100644
--- a/src/tracker-needle/tracker-utils.vala
+++ b/src/tracker-needle/tracker-utils.vala
@@ -67,11 +67,67 @@ public string tracker_time_format_from_iso8601 (string s) {
 	}
 }
 
-public Gdk.Pixbuf tracker_pixbuf_new_from_file (IconTheme theme, string filename, int size) {
+public string tracker_time_format_from_seconds (string seconds_str) {
+	double seconds = seconds_str.to_int ();
+	double total;
+	int d, h, m, s;
+	
+	if (seconds == 0.0) {
+		return _("Less than one second");
+	}
+
+	total = seconds;
+	s = (int) total % 60;
+	total /= 60;
+	m = (int) total % 60;
+	total /= 60;
+	h = (int) total % 24;
+	d = (int) total / 24;
+
+	var output = new StringBuilder ("");
+
+	if (d > 0) {
+		output.append (" %dd".printf (d));
+	}
+
+	if (h > 0) {
+		output.append (" %2.2dh".printf (h));
+	}
+
+	if (m > 0) {
+		output.append (" %2.2dm".printf (m));
+	}
+
+	if (s > 0) {
+		output.append (" %2.2ds".printf (s));
+	}
+
+	if (output.len < 1) {
+		return _("Less than one second");
+	}
+
+	string str = output.str;
+
+	return str._chug ();
+}
+
+public Gdk.Pixbuf tracker_pixbuf_new_from_file (IconTheme theme, string filename, int size, bool is_image) {
 	// Get Icon
 	var file = File.new_for_uri (filename);
 	var pixbuf = null as Gdk.Pixbuf;
 
+	if (is_image) {
+		try {
+			pixbuf = new Gdk.Pixbuf.from_file_at_size (file.get_path (), size, size);
+		} catch (GLib.Error e) {
+			warning ("Error loading icon pixbuf: " + e.message);
+		}
+		
+		if (pixbuf != null) {
+			return pixbuf;
+		}
+	}
+
 	if (file.query_exists (null)) {
 		try {
 			var file_info = file.query_info ("standard::icon",



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