[tracker] Add pane with objects that have a realtionship with the selected object.



commit e54f4284e029934864f837dd4bd47d7f980ad563
Author: Rob Taylor <rob taylor codethink co uk>
Date:   Sat May 9 19:49:16 2009 +0100

    Add pane with objects that have a realtionship with the selected object.

 src/tracker-explorer/Makefile.am   |    7 ++
 src/tracker-explorer/explorer.ui   |   92 ++++++++++++++++++++-----
 src/tracker-explorer/explorer.vala |  129 +++++++++++++++++++++++++-----------
 3 files changed, 170 insertions(+), 58 deletions(-)
---
diff --git a/src/tracker-explorer/Makefile.am b/src/tracker-explorer/Makefile.am
index 5327075..d57adce 100644
--- a/src/tracker-explorer/Makefile.am
+++ b/src/tracker-explorer/Makefile.am
@@ -14,6 +14,8 @@ tracker_explorer.vala.stamp: $(tracker_explorer_VALASOURCES)
 	touch tracker_explorer.vala.stamp
 
 tracker_explorer_CFLAGS = \
+	-DTRACKER_UI_DIR=\"$(datadir)/tracker/\"		\
+	-DSRCDIR=\"$(abssrcdir)/\"				\
 	$(WARN_CFLAGS)						\
 	$(GLIB2_CFLAGS)						\
 	$(GCOV_CFLAGS)						\
@@ -32,6 +34,11 @@ tracker_explorer_LDADD = \
 	$(LIBGEE_LIBS)						\
 	$(NULL)
 
+uidir = $(datadir)/tracker
+ui_DATA = \
+	explorer.ui
+
+
 EXTRA_DIST = \
 	$(tracker_explorer_SOURCES) \
 	$(tracker_explorer_VALASOURCES) \
diff --git a/src/tracker-explorer/explorer.ui b/src/tracker-explorer/explorer.ui
index 2ed43b6..adb63fa 100644
--- a/src/tracker-explorer/explorer.ui
+++ b/src/tracker-explorer/explorer.ui
@@ -69,41 +69,95 @@
           </packing>
         </child>
         <child>
-          <object class="GtkFrame" id="frame1">
+          <object class="GtkVPaned" id="vpaned2">
             <property name="visible">True</property>
-            <property name="label_xalign">0</property>
-            <property name="shadow_type">none</property>
+            <property name="can_focus">True</property>
+            <property name="orientation">vertical</property>
             <child>
-              <object class="GtkAlignment" id="alignment1">
+              <object class="GtkFrame" id="frame1">
                 <property name="visible">True</property>
-                <property name="left_padding">12</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
                 <child>
-                  <object class="GtkScrolledWindow" id="scrolledwindow2">
+                  <object class="GtkAlignment" id="alignment1">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="hscrollbar_policy">automatic</property>
-                    <property name="vscrollbar_policy">automatic</property>
+                    <property name="left_padding">12</property>
                     <child>
-                      <object class="GtkTreeView" id="relationshipsview">
+                      <object class="GtkScrolledWindow" id="scrolledwindow2">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
-                        <property name="search_column">0</property>
+                        <property name="hscrollbar_policy">automatic</property>
+                        <property name="vscrollbar_policy">automatic</property>
+                        <child>
+                          <object class="GtkTreeView" id="relationshipsview">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="search_column">0</property>
+                          </object>
+                        </child>
                       </object>
                     </child>
                   </object>
                 </child>
+                <child type="label">
+                  <object class="GtkLabel" id="current-object">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">&lt;b&gt;No object selected&lt;/b&gt;</property>
+                    <property name="use_markup">True</property>
+                    <property name="justify">fill</property>
+                    <property name="ellipsize">start</property>
+                    <property name="single_line_mode">True</property>
+                    <property name="max_width_chars">50</property>
+                  </object>
+                </child>
               </object>
+              <packing>
+                <property name="resize">True</property>
+                <property name="shrink">True</property>
+              </packing>
             </child>
-            <child type="label">
-              <object class="GtkLabel" id="current-object">
+            <child>
+              <object class="GtkFrame" id="frame2">
                 <property name="visible">True</property>
-                <property name="label" translatable="yes">&lt;b&gt;No object selected&lt;/b&gt;</property>
-                <property name="use_markup">True</property>
-                <property name="justify">fill</property>
-                <property name="ellipsize">start</property>
-                <property name="single_line_mode">True</property>
-                <property name="max_width_chars">50</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkAlignment" id="alignment2">
+                    <property name="visible">True</property>
+                    <property name="left_padding">12</property>
+                    <child>
+                      <object class="GtkScrolledWindow" id="scrolledwindow3">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="hscrollbar_policy">automatic</property>
+                        <property name="vscrollbar_policy">automatic</property>
+                        <child>
+                          <object class="GtkTreeView" id="reverserelationshipsview">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="search_column">0</property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel" id="current-object-reverse">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">&lt;b&gt;No object selected&lt;/b&gt;</property>
+                    <property name="use_markup">True</property>
+                    <property name="justify">fill</property>
+                    <property name="ellipsize">start</property>
+                    <property name="single_line_mode">True</property>
+                    <property name="max_width_chars">50</property>
+                  </object>
+                </child>
               </object>
+              <packing>
+                <property name="resize">True</property>
+                <property name="shrink">True</property>
+              </packing>
             </child>
           </object>
           <packing>
diff --git a/src/tracker-explorer/explorer.vala b/src/tracker-explorer/explorer.vala
index de26a4d..f241b2c 100644
--- a/src/tracker-explorer/explorer.vala
+++ b/src/tracker-explorer/explorer.vala
@@ -1,5 +1,11 @@
 using Gtk;
 
+[CCode (cname = "TRACKER_UI_DIR")]
+extern static const string UIDIR;
+
+[CCode (cname = "SRCDIR")]
+extern static const string SRCDIR;
+
 [DBus (name = "org.freedesktop.Tracker.Resources")]
 interface Resources : GLib.Object {
 	public abstract void Delete (string subject, string predicate, string object_) throws DBus.Error;
@@ -16,48 +22,65 @@ public class Explorer {
 	private ListStore uris;
 	private ListStore relationships;
 	private Label current_object;
+	private ListStore reverserelationships;
+	private Label current_object_reverse;
 	private Gee.HashMap<string,string> namespaces = new Gee.HashMap<string,string>(str_hash, str_equal, str_equal);
 
 	public void show() {
+
 		try {
 			var conn = DBus.Bus.get (DBus.BusType.SESSION);
 			tracker = (Resources) conn.get_object ("org.freedesktop.Tracker",
 							       "/org/freedesktop/Tracker/Resources",
 							       "org.freedesktop.Tracker.Resources");
+		} catch (DBus.Error e) {
+			var msg = new MessageDialog (null, DialogFlags.MODAL,
+					 MessageType.ERROR, ButtonsType.CANCEL,
+					 "Error connecting to D-Bus session bus\n%s", e.message);
+			msg.run ();
+			Gtk.main_quit();
+		}
 
 
-			var builder = new Builder ();
-			builder.add_from_file (UI_FILE);
+		var builder = new Builder ();
 
-			var window = builder.get_object ("explorer") as Window;
-			window.destroy += Gtk.main_quit;
+		try {
+			//try load from source tree first.
+			builder.add_from_file (SRCDIR + UI_FILE);
+		} catch (GLib.Error e) {
+			//now the install location
+			try {
+				builder.add_from_file (UIDIR + UI_FILE);
+			} catch (GLib.Error e) {
+				var msg = new MessageDialog (null, DialogFlags.MODAL,
+						 MessageType.ERROR, ButtonsType.CANCEL,
+						 "Failed to load UI\n%s", e.message);
+				msg.run ();
+				Gtk.main_quit();
+			}
+		}
 
-			var entry = builder.get_object ("text-search") as Entry;
-			entry.changed += entry_changed;
+		var window = builder.get_object ("explorer") as Window;
+		window.destroy += Gtk.main_quit;
 
-			var urisview = builder.get_object ("uris") as TreeView;
-			setup_uris(urisview);
+		var entry = builder.get_object ("text-search") as Entry;
+		entry.changed += entry_changed;
 
-			var relationshipsview = builder.get_object ("relationshipsview") as TreeView;
-			setup_relationships(relationshipsview);
+		var urisview = builder.get_object ("uris") as TreeView;
+		setup_uris(urisview);
 
-			current_object = builder.get_object ("current-object") as Label;
-			fetch_prefixes();
+		var relationshipsview = builder.get_object ("relationshipsview") as TreeView;
+		setup_relationships(relationshipsview);
 
-			window.show_all();
-		} catch (GLib.Error e) {
-			var msg = new MessageDialog (null, DialogFlags.MODAL,
-					 MessageType.ERROR, ButtonsType.CANCEL,
-					 "Failed to load UI\n%s", e.message);
-			msg.run ();
-			Gtk.main_quit();
-		} catch (DBus.Error e) {
-			var msg = new MessageDialog (null, DialogFlags.MODAL,
-					 MessageType.ERROR, ButtonsType.CANCEL,
-					 "Error connecting to D-Bus session bus\n%s", e.message);
-			msg.run ();
-			Gtk.main_quit();
-		}
+		current_object = builder.get_object ("current-object") as Label;
+		var reverserelationshipsview = builder.get_object ("reverserelationshipsview") as TreeView;
+		setup_reverserelationships(reverserelationshipsview);
+
+		current_object_reverse = builder.get_object ("current-object-reverse") as Label;
+
+		fetch_prefixes();
+
+		window.show_all();
 	}
 
 	private void setup_uris (TreeView urisview) {
@@ -77,6 +100,16 @@ public class Explorer {
 		relationshipsview.row_activated += object_selected;
 	}
 
+	private void setup_reverserelationships(TreeView reverserelationshipsview) {
+		reverserelationships = new ListStore (2, typeof(string), typeof(string));
+		reverserelationshipsview.set_model(reverserelationships);
+
+		reverserelationshipsview.insert_column_with_attributes (-1, "Subject", new CellRendererText (), "text", 1, null);
+		reverserelationshipsview.insert_column_with_attributes (-1, "Relationship", new CellRendererText (), "text", 0, null);
+		reverserelationshipsview.row_activated += object_selected;
+	}
+
+
 	private void fetch_prefixes () {
 		string query = "SELECT ?s ?prefix WHERE { ?s a tracker:Namespace ; tracker:prefix ?prefix }";
 		try {
@@ -108,33 +141,51 @@ public class Explorer {
 		}
 	}
 
+	//split at '#' and look up to see if we have
+	//a human-readable prefix
+	private string subst_prefix(string uri) {
+		string[] parts = uri.split("#");
+		string? prefix = namespaces[parts[0]];
+		string relationship;
+
+		if (prefix != null) {
+			relationship = string.join("#", prefix, parts[1]);
+		} else {
+			relationship = uri;
+		}
+		return relationship;
+	}
+
 	private void update_pane(string uri) {
 		//debug ("updating pane: %s", uri);
 		current_object.set_text (uri);
+		current_object_reverse.set_text (uri);
 
-		string query = "SELECT ?r ?o  WHERE { <%s> ?r ?o }".printf(uri);
-		TreeIter iter;
 		try {
+			string query = "SELECT ?r ?o  WHERE { <%s> ?r ?o }".printf(uri);
+			TreeIter iter;
 			var result = tracker.SparqlQuery(query);
 			relationships.clear();
 
 			for (int i=0; i<result.length[0]; i++) {
-				//split at '#' and look up to see if we have
-				//a human-readable prefix
-				string[] parts = result[i,0].split("#");
-				string? prefix = namespaces[parts[0]];
-				string relationship;
-
-				if (prefix != null) {
-					relationship = string.join("#", prefix, parts[1]);
-				} else {
-					relationship = result[i,0];
-				}
+				var relationship = subst_prefix(result[i,0]);
 				relationships.append (out iter);
 				relationships.set (iter, 0, relationship, -1);
 				relationships.set (iter, 1, result[i,1], -1);
 			}
 
+			query = "SELECT ?s ?r WHERE { ?s ?r  <%s> }".printf(uri);
+			result = tracker.SparqlQuery(query);
+			reverserelationships.clear();
+
+			for (int i=0; i<result.length[0]; i++) {
+				var relationship = subst_prefix(result[i,1]);
+				reverserelationships.append (out iter);
+				reverserelationships.set (iter, 0, result[i,0], -1);
+				reverserelationships.set (iter, 1, relationship, -1);
+			}
+
+
 		} catch (DBus.Error e) {
 		}
 	}



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