[tracker/needle: 3/45] tracker-needle: Added icon support for results and fixed timestamps
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/needle: 3/45] tracker-needle: Added icon support for results and fixed timestamps
- Date: Mon, 25 Oct 2010 08:12:52 +0000 (UTC)
commit a9475c14d073eefdc20d48a59b13e7552f8bd8f8
Author: Martyn Russell <martyn lanedo com>
Date: Tue Jun 29 20:46:02 2010 +0100
tracker-needle: Added icon support for results and fixed timestamps
src/needle/Makefile.am | 22 ++++---
src/needle/needle.vala | 148 +++++++++++++++++++++++++++++++++---------------
2 files changed, 115 insertions(+), 55 deletions(-)
---
diff --git a/src/needle/Makefile.am b/src/needle/Makefile.am
index 6e45acc..8782082 100644
--- a/src/needle/Makefile.am
+++ b/src/needle/Makefile.am
@@ -5,22 +5,23 @@ bin_PROGRAMS = needle
needle_VALASOURCES = \
needle.vala
-needle_SOURCES = \
+needle_SOURCES = \
$(needle_VALASOURCES:.vala=.c)
-needle.vala.stamp: $(needle_VALASOURCES)
+needle.vala.stamp: $(needle_VALASOURCES) config.vapi
$(VALAC) -C -g --pkg dbus-glib-1 --pkg gtk+-2.0 $^
touch needle.vala.stamp
-needle_CFLAGS = \
- -DTRACKER_UI_DIR=\"$(datadir)/tracker/\" \
+needle_CFLAGS = \
+ -DTRACKER_UI_DIR=\"$(datadir)/tracker/\"\
+ -DLOCALEDIR=\""$(localedir)"\" \
-DSRCDIR=\"$(abs_srcdir)/\" \
$(TRACKER_APPS_CFLAGS) \
$(TRACKER_VALA_CFLAGS) \
- $(WARN_CFLAGS) \
+ $(WARN_CFLAGS) \
$(GCOV_CFLAGS)
-needle_LDADD = \
+needle_LDADD = \
$(TRACKER_APPS_LIBS) \
$(TRACKER_VALA_LIBS) \
$(GCOV_LIBS)
@@ -28,15 +29,16 @@ needle_LDADD = \
uidir = $(datadir)/tracker
ui_DATA = needle.ui
-EXTRA_DIST = \
+EXTRA_DIST = \
$(needle_VALASOURCES) \
- $(ui_DATA) \
+ $(ui_DATA) \
+ config.vapi \
needle.vala.stamp
MAINTAINERCLEANFILES = \
- needle.vala.stamp \
+ needle.vala.stamp \
$(needle_VALASOURCES:.vala=.c)
-BUILT_SOURCES = \
+BUILT_SOURCES = \
needle.vala.stamp
diff --git a/src/needle/needle.vala b/src/needle/needle.vala
index a407e76..5d78035 100644
--- a/src/needle/needle.vala
+++ b/src/needle/needle.vala
@@ -25,6 +25,8 @@ extern static const string UIDIR;
[CCode (cname = "SRCDIR")]
extern static const string SRCDIR;
+private const string some_unique_name = Config.APPNAME;
+
[DBus (name = "org.freedesktop.Tracker1.Resources")]
interface Resources : GLib.Object {
public abstract string[,] SparqlQuery (string query) throws DBus.Error;
@@ -46,6 +48,8 @@ public class Needle {
private uint last_search_id = 0;
private ListStore store;
+ private const int secs_per_day = 60 * 60 * 24;
+
public void show () {
setup_dbus ();
setup_ui ();
@@ -171,6 +175,93 @@ public class Needle {
last_search_id = Timeout.add_seconds (1, search_run);
}
+ private Gdk.Pixbuf item_get_pixbuf (IconTheme theme, string filename, int size) {
+ // Get Icon
+ var file = File.new_for_uri (filename);
+ var pixbuf = null as Gdk.Pixbuf;
+
+ if (file.query_exists (null)) {
+ try {
+ var file_info = file.query_info ("standard::icon",
+ FileQueryInfoFlags.NONE,
+ null);
+
+ if (file_info != null) {
+ var icon = file_info.get_icon ();
+
+ try {
+ if (icon is FileIcon) {
+ pixbuf = new Gdk.Pixbuf.from_file (((FileIcon) icon).get_file ().get_path ());
+ } else if (icon is ThemedIcon) {
+ pixbuf = theme.load_icon (((ThemedIcon) icon).get_names ()[0], size, Gtk.IconLookupFlags.USE_BUILTIN);
+ }
+ } catch (GLib.Error error) {
+ warning ("Error loading icon pixbuf: " + error.message);
+ }
+ }
+ } catch (GLib.Error error) {
+ warning ("Error looking up file for pixbuf: " + error.message);
+ }
+ }
+
+ if (pixbuf == null) {
+ try {
+ // pixbuf = theme.load_icon (theme.get_example_icon_name (), 48, IconLookupFlags.USE_BUILTIN);
+ pixbuf = theme.load_icon ("text-x-generic", size, IconLookupFlags.USE_BUILTIN);
+ } catch (GLib.Error e) {
+ // Do something
+ }
+ }
+
+ return pixbuf;
+ }
+
+ private string item_get_time (string s) {
+ GLib.Time t = GLib.Time ();
+ t.strptime (s, "%FT%T");
+
+ var tv_now = GLib.TimeVal ();
+ tv_now.get_current_time ();
+
+ var tv_then = GLib.TimeVal ();
+ tv_then.from_iso8601 (s);
+
+ var diff_sec = tv_now.tv_sec - tv_then.tv_sec;
+ var diff_days = diff_sec / secs_per_day;
+ var diff_days_abs = diff_days.abs ();
+
+ stdout.printf ("timeval now:%ld, then:%ld, diff secs:%ld, diff days:%ld, abs: %ld, seconds per day:%d\n", tv_now.tv_sec, tv_then.tv_sec, diff_sec, diff_days, diff_days_abs, secs_per_day);
+
+ /* if it's more than a week, use the default date format */
+ if (diff_days_abs > 7) {
+ return t.format ("%x");
+ }
+
+ if (diff_days_abs == 0) {
+ return "Today";
+ } else {
+ bool future = false;
+
+ if (diff_days < 0)
+ future = true;
+
+ if (diff_days <= 1) {
+ if (future)
+ return "Tomorrow";
+ else
+ return "Yesterday";
+ } else {
+ if (future) {
+ /* Translators: %d is replaced with a number of days. It's always greater than 1 */
+ return ngettext ("%ld day from now", "%ld days from now", diff_days_abs).printf (diff_days_abs);
+ } else {
+ /* Translators: %d is replaced with a number of days. It's always greater than 1 */
+ return ngettext ("%ld day ago", "%ld days ago", diff_days_abs).printf (diff_days_abs);
+ }
+ }
+ }
+ }
+
private bool search_run () {
// Need to escape this string
string query;
@@ -185,7 +276,8 @@ public class Needle {
var screen = window.get_screen ();
var theme = IconTheme.get_for_screen (screen);
- var size = 24;
+
+ int size = 24;
for (int i = 0; i < result.length[0]; i++) {
debug ("--> %s", result[i,0]);
@@ -194,59 +286,21 @@ public class Needle {
debug (" --> %s", result[i,3]);
debug (" --> %s", result[i,4]);
- // Get Icon
- var file = File.new_for_uri (result[i,1]);
- var pixbuf = null as Gdk.Pixbuf;
-
- if (file.query_exists (null)) {
- try {
- var file_info = file.query_info ("standard::icon",
- FileQueryInfoFlags.NONE,
- null);
-
- if (file_info != null) {
- var icon = file_info.get_icon ();
-
- if (icon != null) {
- var names = ((ThemedIcon) icon).get_names ();
+ // Get icon
+ Gdk.Pixbuf pixbuf = item_get_pixbuf (theme, result[i,1], size);
+ string file_size = GLib.format_size_for_display (result[i,4].to_int());
+ string file_time = item_get_time (result[i,3]);
- // See bug #618574
- var icon_info = theme.choose_icon (names, size, IconLookupFlags.USE_BUILTIN);
-
- if (icon_info != null) {
- try {
- pixbuf = icon_info.load_icon ();
- } catch (GLib.Error e) {
- // Do something
- }
- }
- }
- }
- } catch (GLib.Error e) {
- // Do something
- }
- }
-
- if (pixbuf == null) {
- try {
- // pixbuf = theme.load_icon (theme.get_example_icon_name (), 48, IconLookupFlags.USE_BUILTIN);
- pixbuf = theme.load_icon ("text-x-generic", size, IconLookupFlags.USE_BUILTIN);
- } catch (GLib.Error e) {
- // Do something
- }
- }
-
// Insert into model
TreeIter iter;
- string file_size = GLib.format_size_for_display (result[i,4].to_int());
-
store.append (out iter);
+
store.set (iter,
0, pixbuf,
1, result[i,0],
2, result[i,1],
3, result[i,2],
- 4, result[i,3],
+ 4, file_time,
5, file_size,
6, result[i,5],
-1);
@@ -293,6 +347,10 @@ public class Needle {
static int main (string[] args) {
Gtk.init (ref args);
+
+ Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
+ Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
+ Intl.textdomain (Config.GETTEXT_PACKAGE);
Needle n = new Needle();
n.show();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]