[tracker/needle: 14/41] tracker-needle: Added statistics dialog
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/needle: 14/41] tracker-needle: Added statistics dialog
- Date: Mon, 20 Sep 2010 22:14:33 +0000 (UTC)
commit 81177274d87294764d090df0e7c5f036007af7b0
Author: Martyn Russell <martyn lanedo com>
Date: Wed Jun 30 10:38:48 2010 +0100
tracker-needle: Added statistics dialog
src/tracker-needle/Makefile.am | 3 +-
src/tracker-needle/tracker-needle.ui | 21 ++++
src/tracker-needle/tracker-needle.vala | 17 +++-
src/tracker-needle/tracker-stats.vala | 170 ++++++++++++++++++++++++++++++++
4 files changed, 207 insertions(+), 4 deletions(-)
---
diff --git a/src/tracker-needle/Makefile.am b/src/tracker-needle/Makefile.am
index 762b831..03e79de 100644
--- a/src/tracker-needle/Makefile.am
+++ b/src/tracker-needle/Makefile.am
@@ -3,7 +3,8 @@ include $(top_srcdir)/Makefile.decl
bin_PROGRAMS = tracker-needle
tracker_needle_VALASOURCES = \
- tracker-needle.vala
+ tracker-needle.vala \
+ tracker-stats.vala
tracker_needle_SOURCES = \
$(tracker_needle_VALASOURCES:.vala=.c)
diff --git a/src/tracker-needle/tracker-needle.ui b/src/tracker-needle/tracker-needle.ui
index 5a3ea70..8f3187d 100644
--- a/src/tracker-needle/tracker-needle.ui
+++ b/src/tracker-needle/tracker-needle.ui
@@ -125,6 +125,27 @@
<property name="homogeneous">True</property>
</packing>
</child>
+ <child>
+ <object class="GtkSeparatorToolItem" id="<separator>1">
+ <property name="visible">True</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>
+ <property name="use_underline">True</property>
+ <property name="stock_id">gtk-about</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
diff --git a/src/tracker-needle/tracker-needle.vala b/src/tracker-needle/tracker-needle.vala
index e3bb16b..725beff 100644
--- a/src/tracker-needle/tracker-needle.vala
+++ b/src/tracker-needle/tracker-needle.vala
@@ -25,14 +25,15 @@ extern static const string UIDIR;
[CCode (cname = "SRCDIR")]
extern static const string SRCDIR;
-private const string some_unique_name = Config.APPNAME;
+// Added to fix #error for GETTEXT_PACKAGE
+private const string a = Config.APPNAME;
[DBus (name = "org.freedesktop.Tracker1.Resources")]
interface Resources : GLib.Object {
public abstract string[,] SparqlQuery (string query) throws DBus.Error;
}
-public class Needle {
+public class TrackerNeedle {
private const string UI_FILE = "tracker-needle.ui";
private Resources tracker;
private Window window;
@@ -41,6 +42,7 @@ public class Needle {
private ToggleToolButton find_in_contents;
private ToggleToolButton find_in_titles;
private Entry search;
+ private ToolButton show_stats;
private ScrolledWindow sw_treeview;
private TreeView treeview;
private ScrolledWindow sw_iconview;
@@ -117,6 +119,9 @@ public class Needle {
search = builder.get_object ("entry_search") as Entry;
search.changed.connect (search_changed);
+ show_stats = builder.get_object ("toolbutton_show_stats") as ToolButton;
+ show_stats.clicked.connect (show_stats_clicked);
+
sw_treeview = builder.get_object ("scrolledwindow_treeview") as ScrolledWindow;
treeview = builder.get_object ("treeview_results") as TreeView;
sw_iconview = builder.get_object ("scrolledwindow_iconview") as ScrolledWindow;
@@ -380,6 +385,12 @@ public class Needle {
debug ("Selected filename:'%s'", filename);
}
+
+ private void show_stats_clicked () {
+ debug ("Showing stats dialog");
+ TrackerStats s = new TrackerStats ();
+ s.show ();
+ }
}
static int main (string[] args) {
@@ -389,7 +400,7 @@ static int main (string[] args) {
Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
Intl.textdomain (Config.GETTEXT_PACKAGE);
- Needle n = new Needle();
+ TrackerNeedle n = new TrackerNeedle ();
n.show();
Gtk.main ();
diff --git a/src/tracker-needle/tracker-stats.vala b/src/tracker-needle/tracker-stats.vala
new file mode 100644
index 0000000..bdaa315
--- /dev/null
+++ b/src/tracker-needle/tracker-stats.vala
@@ -0,0 +1,170 @@
+//
+// 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;
+
+// Added to fix #error for GETTEXT_PACKAGE
+private const string b = Config.APPNAME;
+
+[DBus (name = "org.freedesktop.Tracker1.Statistics")]
+interface Statistics : GLib.Object {
+ public abstract string[,] Get () throws DBus.Error;
+}
+
+public class TrackerStats : Dialog {
+ private Statistics tracker;
+
+ public TrackerStats () {
+ this.title = "Statistics";
+ this.has_separator = false;
+ this.border_width = 12;
+ this.resizable = false;
+
+ setup_dbus ();
+ setup_ui ();
+ }
+
+ private void setup_dbus () {
+ debug ("Setting up statistics D-Bus connection");
+
+ try {
+ var conn = DBus.Bus.get (DBus.BusType.SESSION);
+ tracker = (Statistics) conn.get_object ("org.freedesktop.Tracker1",
+ "/org/freedesktop/Tracker1/Statistics",
+ "org.freedesktop.Tracker1.Statistics");
+ } catch (DBus.Error e) {
+ var msg = new MessageDialog (null,
+ DialogFlags.MODAL,
+ MessageType.ERROR,
+ ButtonsType.CANCEL,
+ "Error connecting to D-Bus session bus, %s",
+ e.message);
+ msg.run ();
+ Gtk.main_quit ();
+ }
+ }
+
+ private void setup_ui () {
+ debug ("Setting up statistics UI");
+
+ // Spacing between major units
+ this.vbox.spacing = 18;
+ this.vbox.border_width = 0;
+
+ // Label for dialog
+ var label = new Label ("The statistics represented here do not reflect their availability, rather the total data stored:");
+ label.set_line_wrap (true);
+ label.set_alignment (0.0f, 0.5f);
+ this.vbox.pack_start (label, true, true, 0);
+
+ // Size group to line up labels
+ var sizegroup = new SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
+
+ try {
+ var result = tracker.Get ();
+
+ for (int i = 0; i < result.length[0]; i++) {
+ var key = result[i,0];
+ var val = result[i,1];
+ string key_used;
+
+ debug ("--> %s = %s", key, val);
+
+ switch (key) {
+ case "nao:Tag":
+ key_used = ngettext ("Tag", "Tags", val.to_int ());
+ break;
+ case "nco:Contact":
+ key_used = ngettext ("Contact", "Contacts", val.to_int ());
+ break;
+ case "nfo:Audio":
+ key_used = ngettext ("Audio", "Audios", val.to_int ());
+ break;
+ case "nfo:Document":
+ key_used = ngettext ("Document", "Documents", val.to_int ());
+ break;
+ case "nfo:FileDataObject":
+ key_used = ngettext ("File", "Files", val.to_int ());
+ break;
+ case "nfo:Folder":
+ key_used = ngettext ("Folder", "Folders", val.to_int ());
+ break;
+ case "nfo:Image":
+ key_used = ngettext ("Image", "Images", val.to_int ());
+ break;
+ case "nfo:SoftwareApplication":
+ key_used = ngettext ("Application", "Applications", val.to_int ());
+ break;
+ case "nfo:Video":
+// case "nmm:Video":
+ key_used = ngettext ("Video", "Videos", val.to_int ());
+ break;
+ case "nmm:MusicAlbum":
+ key_used = ngettext ("Album", "Albums", val.to_int ());
+ break;
+ case "nmm:MusicPiece":
+ key_used = ngettext ("Music Track", "Music Tracks", val.to_int ());
+ break;
+ case "nmm:Photo":
+ key_used = ngettext ("Photo", "Photos", val.to_int ());
+ break;
+ case "nmm:Playlist":
+ key_used = ngettext ("Playlist", "Playlists", val.to_int ());
+ break;
+ default:
+ continue;
+ }
+
+ var hbox = new HBox (false, 12);
+ var label_key = new Label (key_used);
+ var label_val = new Label (val);
+
+ label_key.set_alignment (0.0f, 0.5f);
+ label_val.set_alignment (0.0f, 0.5f);
+ hbox.pack_start (label_key, true, true, 0);
+ hbox.pack_start (label_val, false, true, 0);
+
+ sizegroup.add_widget (label_key);
+
+ this.vbox.pack_start (hbox, true, true, 0);
+ }
+ } catch (DBus.Error e) {
+ warning ("Could not get Tracker statistics: " + e.message);
+ }
+
+ // Layout widgets
+ this.vbox.spacing = 10;
+
+ // Add buttons to button area at the bottom
+ add_button (STOCK_CLOSE, ResponseType.CLOSE);
+
+ // Connect signals
+ this.response.connect (on_response);
+
+ show_all ();
+ }
+
+ private void on_response (Dialog source, int response_id) {
+ switch (response_id) {
+ case ResponseType.CLOSE:
+ destroy ();
+ break;
+ }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]