[tracker/tracker-needle-model: 6/25] needle: Add back the pixbuf column/renderer.



commit 0a94b4499ff3fa626e92549a58a7c95fde60f660
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Mar 17 19:10:08 2011 +0100

    needle: Add back the pixbuf column/renderer.

 src/tracker-needle/tracker-result-store.vala |   57 +++++++++++++++++++++++--
 src/tracker-needle/tracker-view.vala         |   12 +++---
 2 files changed, 58 insertions(+), 11 deletions(-)
---
diff --git a/src/tracker-needle/tracker-result-store.vala b/src/tracker-needle/tracker-result-store.vala
index cfd7d71..0771a42 100644
--- a/src/tracker-needle/tracker-result-store.vala
+++ b/src/tracker-needle/tracker-result-store.vala
@@ -29,6 +29,7 @@ public class Tracker.ResultStore : Gtk.TreeModel, GLib.Object {
 		Tracker.Query.Type type;
 		string [] args;
 		ResultNode [] results;
+		Gdk.Pixbuf pixbuf;
 	}
 	private CategoryNode [] categories;
 
@@ -94,7 +95,7 @@ public class Tracker.ResultStore : Gtk.TreeModel, GLib.Object {
 
 				result = &op.node.results[i];
 
-				for (j = 0; j < n_columns; j++) {
+				for (j = 0; j < n_columns - 1; j++) {
 					result.values[j] = cursor.get_string (j);
 				}
 
@@ -314,7 +315,11 @@ public class Tracker.ResultStore : Gtk.TreeModel, GLib.Object {
 	}
 
 	public GLib.Type get_column_type (int index_) {
-		return typeof (string);
+		if (index_ == n_columns - 1) {
+			return typeof (Gdk.Pixbuf);
+		} else {
+			return typeof (string);
+		}
 	}
 
 	public Gtk.TreeModelFlags get_flags () {
@@ -409,6 +414,41 @@ public class Tracker.ResultStore : Gtk.TreeModel, GLib.Object {
 					value.set_string (_("Folders"));
 					break;
 				}
+			} else if (column == n_columns - 1) {
+				Gdk.Pixbuf pixbuf;
+
+				pixbuf = cat.pixbuf;
+
+				if (pixbuf == null) {
+					var theme = IconTheme.get_for_screen (Gdk.Screen.get_default ());
+					int size = 24;
+
+					switch (cat.type) {
+					case Tracker.Query.Type.APPLICATIONS:
+						pixbuf = tracker_pixbuf_new_from_name (theme, "package-x-generic", size);
+						break;
+					case Tracker.Query.Type.MUSIC:
+						pixbuf = tracker_pixbuf_new_from_name (theme, "audio-x-generic", size);
+						break;
+					case Tracker.Query.Type.IMAGES:
+						pixbuf = tracker_pixbuf_new_from_name (theme, "image-x-generic", size);
+						break;
+					case Tracker.Query.Type.VIDEOS:
+						pixbuf = tracker_pixbuf_new_from_name (theme, "video-x-generic", size);
+						break;
+					case Tracker.Query.Type.DOCUMENTS:
+						pixbuf = tracker_pixbuf_new_from_name (theme, "x-office-presentation", size);
+						break;
+					case Tracker.Query.Type.MAIL:
+						pixbuf = tracker_pixbuf_new_from_name (theme, "emblem-mail", size);
+						break;
+					case Tracker.Query.Type.FOLDERS:
+						pixbuf = tracker_pixbuf_new_from_name (theme, "folder", size);
+						break;
+					}
+				}
+
+				value.set_object (pixbuf);
 			}
 		} else {
 			ResultNode *result;
@@ -418,7 +458,12 @@ public class Tracker.ResultStore : Gtk.TreeModel, GLib.Object {
 			n_node = (int) iter.user_data3;
 
 			if (result.values[0] != null) {
-				value.set_string (result.values[column]);
+				if (column == n_columns - 1) {
+					// No pixbuf ATM
+					//value.set_object (null);
+				} else {
+					value.set_string (result.values[column]);
+				}
 			} else {
 				n_node /= 100;
 				n_node *= 100;
@@ -569,7 +614,9 @@ public class Tracker.ResultStore : Gtk.TreeModel, GLib.Object {
 	public ResultStore (int _n_columns) {
 		running_operations = new GenericArray<Operation?> ();
 		delayed_operations = new GenericArray<Operation?> ();
-		n_columns = _n_columns;
+
+		// Add an extra one for the pixbuf
+		n_columns = _n_columns + 1;
 	}
 
 	public void add_query (Tracker.Query.Type type, ...) {
@@ -588,7 +635,7 @@ public class Tracker.ResultStore : Gtk.TreeModel, GLib.Object {
 			}
 		} while (str != null);
 
-		if (args.length != n_columns) {
+		if (args.length != n_columns - 1) {
 			warning ("Arguments and number of columns doesn't match");
 			return;
 		}
diff --git a/src/tracker-needle/tracker-view.vala b/src/tracker-needle/tracker-view.vala
index 9216534..832b1e0 100644
--- a/src/tracker-needle/tracker-view.vala
+++ b/src/tracker-needle/tracker-view.vala
@@ -252,10 +252,10 @@ public class Tracker.View : ScrolledWindow {
 
 			col = new TreeViewColumn ();
 			col.set_sizing (TreeViewColumnSizing.FIXED);
-			// col.pack_start (renderer1, false);
-			// col.add_attribute (renderer1, "pixbuf", 0);
-			// renderer1.xpad = 5;
-			// renderer1.ypad = 5;
+			col.pack_start (renderer1, false);
+			col.add_attribute (renderer1, "pixbuf", 6);
+			renderer1.xpad = 5;
+			renderer1.ypad = 5;
 
 			col.pack_start (renderer2, true);
 			col.set_cell_data_func (renderer2, text_renderer_func);
@@ -269,7 +269,7 @@ public class Tracker.View : ScrolledWindow {
 			col.set_resizable (true);
 			col.set_expand (true);
 			col.set_sizing (TreeViewColumnSizing.AUTOSIZE);
-//			col.set_cell_data_func (renderer1, cell_renderer_func);
+			col.set_cell_data_func (renderer1, renderer_background_func);
 			tv.append_column (col);
 
 //			var renderer3 = new Gtk.CellRendererText ();
@@ -325,7 +325,7 @@ public class Tracker.View : ScrolledWindow {
 		path = tree_model.get_path (iter);
 
 		// Set odd/even colours
-		if (path.get_indices()[0] % 2 == 0) {
+		if (path.get_indices()[0] % 2 != 0) {
 			cell.set ("cell-background-gdk", color);
 		} else {
 			cell.set ("cell-background-gdk", null);



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