[tracker/tracker-needle-model] needle: Make model load icons for file queries
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/tracker-needle-model] needle: Make model load icons for file queries
- Date: Tue, 22 Mar 2011 17:54:54 +0000 (UTC)
commit 277f3361f02a4cd61a2d2d50763052f1c60f3660
Author: Carlos Garnacho <carlosg gnome org>
Date: Tue Mar 22 18:34:33 2011 +0100
needle: Make model load icons for file queries
src/tracker-needle/tracker-needle.vala | 10 ++--
src/tracker-needle/tracker-result-store.vala | 65 +++++++++++++++++++++++++-
src/tracker-needle/tracker-view.vala | 7 +--
3 files changed, 72 insertions(+), 10 deletions(-)
---
diff --git a/src/tracker-needle/tracker-needle.vala b/src/tracker-needle/tracker-needle.vala
index 4e47021..3105a62 100644
--- a/src/tracker-needle/tracker-needle.vala
+++ b/src/tracker-needle/tracker-needle.vala
@@ -113,23 +113,25 @@ public class Tracker.Needle {
"?tooltip");
// Files model
- files_model = new ResultStore (6);
+ files_model = new ResultStore (7);
files_model.add_query (Tracker.Query.Type.ALL,
"?urn",
- "nfo:fileLastModified(?urn)",
+ "nie:url(?urn)",
"tracker:coalesce(nie:title(?urn), nfo:fileName(?urn))",
"nie:url(?urn)",
"nfo:fileSize(?urn)",
+ "nfo:fileLastModified(?urn)",
"nie:url(?urn)");
// Files model, search in titles
- files_in_title_model = new ResultStore (6);
+ files_in_title_model = new ResultStore (7);
files_in_title_model.add_query (Tracker.Query.Type.ALL_ONLY_IN_TITLES,
"?urn",
- "nfo:fileLastModified(?urn)",
+ "nie:url(?urn)",
"tracker:coalesce(nie:title(?urn), nfo:fileName(?urn))",
"nie:url(?urn)",
"nfo:fileSize(?urn)",
+ "nfo:fileLastModified(?urn)",
"nie:url(?urn)");
}
diff --git a/src/tracker-needle/tracker-result-store.vala b/src/tracker-needle/tracker-result-store.vala
index 43fd019..7248eaf 100644
--- a/src/tracker-needle/tracker-result-store.vala
+++ b/src/tracker-needle/tracker-result-store.vala
@@ -24,6 +24,7 @@ public class Tracker.ResultStore : Gtk.TreeModel, GLib.Object {
private struct ResultNode {
string [] values;
+ Gdk.Pixbuf pixbuf;
}
private class CategoryNode {
public Tracker.Query.Type type;
@@ -443,6 +444,63 @@ public class Tracker.ResultStore : Gtk.TreeModel, GLib.Object {
return path;
}
+ private async void fetch_thumbnail (TreeIter iter) {
+ GLib.File file;
+ GLib.FileInfo info;
+ GLib.Icon icon;
+ TreePath path;
+ Gtk.IconInfo icon_info;
+ ResultNode *result;
+ string thumb_path;
+ Gdk.Pixbuf pixbuf = null;
+
+ result = iter.user_data2;
+
+ // Query thumbnail to GIO
+ file = GLib.File.new_for_uri (result.values[1]);
+
+ try {
+ info = yield file.query_info_async ("thumbnail::path,standard::icon",
+ GLib.FileQueryInfoFlags.NONE,
+ GLib.Priority.DEFAULT,
+ cancellable);
+ } catch (GLib.Error ie) {
+ warning ("Could not get thumbnail: %s", ie.message);
+ return;
+ }
+
+ thumb_path = info.get_attribute_byte_string ("thumbnail::path");
+
+ try {
+ if (thumb_path != null) {
+ pixbuf = new Gdk.Pixbuf.from_file_at_size (thumb_path, 24, 24);
+ } else {
+ icon = (GLib.Icon) info.get_attribute_object ("standard::icon");
+
+ if (icon == null) {
+ return;
+ }
+
+ var theme = IconTheme.get_for_screen (Gdk.Screen.get_default ());
+ icon_info = theme.lookup_by_gicon (icon, 24, 0);
+
+ if (icon_info == null) {
+ return;
+ }
+
+ pixbuf = icon_info.load_icon ();
+ }
+ } catch (GLib.Error e) {
+ warning ("Could not get icon pixbuf: %s\n", e.message);
+ }
+
+ if (pixbuf != null) {
+ result.pixbuf = pixbuf;
+ path = get_path (iter);
+ row_changed (path, iter);
+ }
+ }
+
public void get_value (Gtk.TreeIter iter,
int column,
out GLib.Value value) {
@@ -526,8 +584,11 @@ public class Tracker.ResultStore : Gtk.TreeModel, GLib.Object {
if (result.values[0] != null) {
if (column == n_columns - 1) {
- // No pixbuf ATM
- //value.set_object (null);
+ if (result.pixbuf != null) {
+ value.set_object (result.pixbuf);
+ } else if (queries.length == 1) {
+ fetch_thumbnail.begin (iter);
+ }
} else {
value.set_string (result.values[column]);
}
diff --git a/src/tracker-needle/tracker-view.vala b/src/tracker-needle/tracker-view.vala
index fe580db..96f3cd3 100644
--- a/src/tracker-needle/tracker-view.vala
+++ b/src/tracker-needle/tracker-view.vala
@@ -142,7 +142,7 @@ public class Tracker.View : ScrolledWindow {
TreeView tv = (TreeView) view;
tv.set_model (store);
- tv.set_tooltip_column (8);
+ tv.set_tooltip_column (6);
tv.set_rules_hint (false);
tv.set_grid_lines (TreeViewGridLines.VERTICAL);
tv.set_headers_visible (true);
@@ -153,12 +153,11 @@ public class Tracker.View : ScrolledWindow {
col = new TreeViewColumn ();
col.set_sizing (TreeViewColumnSizing.AUTOSIZE);
col.pack_start (renderer1, false);
- col.add_attribute (renderer1, "pixbuf", 6);
+ col.add_attribute (renderer1, "pixbuf", 7);
renderer1.xpad = 5;
renderer1.ypad = 5;
col.pack_start (renderer2, true);
- //col.add_attribute (renderer2, "text", 2);
renderer2.set_fixed_height_from_font (2);
renderer2.ellipsize = Pango.EllipsizeMode.MIDDLE;
@@ -174,7 +173,7 @@ public class Tracker.View : ScrolledWindow {
col = new TreeViewColumn ();
col.set_sizing (TreeViewColumnSizing.AUTOSIZE);
col.pack_start (renderer3, true);
- col.add_attribute (renderer3, "text", 1);
+ col.add_attribute (renderer3, "text", 5);
col.set_title (_("Last Changed"));
col.set_cell_data_func (renderer3, renderer_background_func);
tv.append_column (col);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]