[tracker] Added text in RSS example. Updated to lastest tracker API.
- From: Ivan Frade <ifrade src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker] Added text in RSS example. Updated to lastest tracker API.
- Date: Thu, 12 Nov 2009 17:34:05 +0000 (UTC)
commit 2572d5aaab23c6c0c4a3748998b8699660e5bfc6
Author: Ivan Frade <ivan frade nokia com>
Date: Wed Nov 11 17:43:56 2009 +0200
Added text in RSS example. Updated to lastest tracker API.
python/rss_reader/main.py | 39 +++++++++++++++++++++++++++-------
python/rss_reader/signaler.py | 30 +++++++++++++++++++++----
python/rss_reader/tracker_backend.py | 20 +++++++++++++++-
3 files changed, 74 insertions(+), 15 deletions(-)
---
diff --git a/python/rss_reader/main.py b/python/rss_reader/main.py
index 13be60e..81b8bbc 100755
--- a/python/rss_reader/main.py
+++ b/python/rss_reader/main.py
@@ -33,7 +33,7 @@ channels_model = gtk.ListStore (str, str, str, bool)
posts_treeview = None
channels_treeview = None
-
+text_view = None
sources_dialog = None
# Convenience defines
@@ -44,6 +44,19 @@ BOLD = pango.WEIGHT_BOLD
tracker = TrackerRSS ()
+class SimpleTextView (gtk.TextView):
+
+ def __init__ (self, buffer=None):
+ gtk.TextView.__init__ (self, buffer)
+ self.set_wrap_mode (gtk.WRAP_WORD)
+
+ def set_plain_text (self, text):
+ self.get_buffer().set_text (text)
+
+ def get_plain_text (self):
+ ini, end = self.get_buffer().get_bounds ()
+ return self.get_buffer ().get_text (ini, end)
+
def populate_initial_posts ():
results = tracker.get_post_sorted_by_date (10)
@@ -67,6 +80,8 @@ def create_posts_tree_view ():
treeview.append_column (column_title)
treeview.append_column (column_date)
+ treeview.connect ("cursor-changed", cursor_changed_cb)
+
return treeview
def create_channels_tree_view ():
@@ -117,6 +132,14 @@ def clicked_toggle_cb (widget):
selected.selected_foreach (toggle_row_foreach)
+def cursor_changed_cb (tv):
+ selection = tv.get_selection ()
+ if (selection.count_selected_rows () > 0):
+ model, it = selection.get_selected ()
+ uri = model.get_value (it, 0)
+ text = tracker.get_text_for_uri (uri)
+ text_view.set_plain_text (text)
+
def clicked_sources_cb (widget, dialog):
# Dont do this all the time!
if (len (channels_model) == 0):
@@ -132,7 +155,6 @@ def clicked_sources_cb (widget, dialog):
dialog.hide ()
def notification_addition (added_uris):
- print "Received signal"
print "%d add: %s" % (len(added_uris), [str(n) for n in added_uris])
for uri in added_uris:
details = tracker.get_info_for_entry (uri)
@@ -152,16 +174,13 @@ def remove_uris (model, path, iter, user_data):
return True
def notification_removal (removed_uris):
- print "Received signal"
print "%d remove: %s" % (len(removed_uris), [str(n) for n in removed_uris])
posts_model.foreach (remove_uris, removed_uris)
def update_uri (model, path, iter, user_data):
updated_uri = user_data [0]
uri = model.get (iter, 0)
- print "Comparing ", uri[0], "with", updated_uri
if (uri[0] == updated_uri):
- print "Setting new values", user_data
model.set(iter,
1, user_data[1],
2, user_data[2],
@@ -170,8 +189,7 @@ def update_uri (model, path, iter, user_data):
return True
-def notification_update (updated_uris):
- print "Received signal"
+def notification_update (updated_uris, update_predicates):
print "%d update: %s" % (len(updated_uris), [str(n) for n in updated_uris])
for uri in updated_uris:
details = tracker.get_info_for_entry (uri)
@@ -212,6 +230,11 @@ if __name__ == "__main__":
posts_treeview.set_model (posts_model)
vbox.add (posts_treeview)
+ frame = gtk.Frame ()
+ text_view = SimpleTextView ()
+ frame.add (text_view)
+ vbox.add (frame)
+
channels_treeview = create_channels_tree_view ()
channels_treeview.set_model (channels_model)
@@ -230,7 +253,7 @@ if __name__ == "__main__":
button_sources.connect ("clicked", clicked_sources_cb, dialog)
button_box.add (button_sources)
- vbox.add (button_box)
+ vbox.pack_start (button_box, expand=False)
window.add (vbox)
populate_initial_posts ()
diff --git a/python/rss_reader/signaler.py b/python/rss_reader/signaler.py
index 6d19b80..efd9005 100755
--- a/python/rss_reader/signaler.py
+++ b/python/rss_reader/signaler.py
@@ -25,6 +25,13 @@ import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
import datetime, random
+try:
+ import barnum.gen_data as gen_data
+ barnum_available = True
+except ImportException:
+ print "No barnum. Crappy random"
+ barnum_available = False
+
TRACKER = 'org.freedesktop.Tracker1'
TRACKER_OBJ = '/org/freedesktop/Tracker1/Resources'
@@ -34,6 +41,7 @@ INSERT {
<%s> a mfo:FeedMessage ;
nie:contentLastModified "%s" ;
nmo:communicationChannel <http://maemo.org/news/planet-maemo/atom.xml>;
+ nmo:plainTextMessageContent "%s" ;
nie:title "%s".
}
"""
@@ -71,8 +79,9 @@ class SignalerUI (gtk.Window):
hbox_uri = gtk.HBox ()
hbox_uri.add (uri_label)
hbox_uri.add (self.uri_entry)
- #self.uri_entry.set_property ("editable", False)
+ self.uri_entry.set_property ("sensitive", False)
post_frame_vbox.add (hbox_uri)
+
date_label = gtk.Label ("Date")
self.date_entry = gtk.Entry ()
self.date_entry.set_property ("editable", False)
@@ -80,6 +89,10 @@ class SignalerUI (gtk.Window):
date_hbox.add (date_label)
date_hbox.add (self.date_entry)
post_frame_vbox.add (date_hbox)
+
+ self.post_text = gtk.TextView ()
+ post_frame_vbox.add (self.post_text)
+
button_gen = gtk.Button (stock=gtk.STOCK_NEW)
button_gen.connect ("clicked", self.gen_new_post_cb)
post_frame_vbox.add (button_gen)
@@ -89,11 +102,11 @@ class SignalerUI (gtk.Window):
button_new = gtk.Button (stock=gtk.STOCK_ADD)
button_new.connect ("clicked", self.clicked_add_cb)
- vbox.add (button_new)
+ vbox.pack_start (button_new, expand=False)
button_remove = gtk.Button (stock=gtk.STOCK_REMOVE)
button_remove.connect ("clicked", self.clicked_remove_cb)
- vbox.add (button_remove)
+ vbox.pack_start (button_remove, expand=False)
self.add (vbox)
self.connect ("destroy", gtk.main_quit)
@@ -108,7 +121,9 @@ class SignalerUI (gtk.Window):
date = self.date_entry.get_text ()
uri = self.uri_entry.get_text ()
title = self.title_entry.get_text ()
-
+ buf = self.post_text.get_buffer()
+ init, end = buf.get_bounds ()
+ text = buf.get_text (init, end).replace ("\n", "\\n")
if (not date or (len(date) == 0)):
pass
if (not uri or (len(uri) == 0)):
@@ -120,7 +135,7 @@ class SignalerUI (gtk.Window):
print "Generate a new URI!"
return
- sparql_insert = INSERT_SPARQL % (uri, date, title)
+ sparql_insert = INSERT_SPARQL % (uri, date, text, title)
print sparql_insert
self.iface.SparqlUpdate (sparql_insert)
@@ -141,6 +156,11 @@ class SignalerUI (gtk.Window):
post_no = str(random.randint (100, 1000000))
self.uri_entry.set_text ("http://test.maemo.org/feed/" + post_no)
self.title_entry.set_text ("Title %s" % (post_no))
+ if barnum_available :
+ buf = gtk.TextBuffer ()
+ buf.set_text (gen_data.create_paragraphs (2, 5, 5))
+ self.post_text.set_wrap_mode (gtk.WRAP_WORD)
+ self.post_text.set_buffer (buf)
if __name__ == "__main__":
diff --git a/python/rss_reader/tracker_backend.py b/python/rss_reader/tracker_backend.py
index 4679594..63baa0c 100644
--- a/python/rss_reader/tracker_backend.py
+++ b/python/rss_reader/tracker_backend.py
@@ -38,6 +38,7 @@ QUERY_FIRST_ENTRIES = """
"""
SET_URI_AS_READED = """
+ DELETE {<%s> nmo:isRead "%s".}
INSERT {<%s> nmo:isRead "%s".}
"""
@@ -62,6 +63,12 @@ QUERY_FOR_URI = """
}
"""
+QUERY_FOR_TEXT = """
+ SELECT ?text WHERE {
+ <%s> nmo:plainTextMessageContent ?text .
+ }
+"""
+
CONF_FILE = os.path.expanduser ("~/.config/rss_tracker/rss.conf")
class TrackerRSS:
@@ -96,11 +103,13 @@ class TrackerRSS:
def set_is_read (self, uri, value):
if (value):
dbus_value = TRUE
+ anti_value = FALSE
else:
dbus_value = FALSE
+ anti_value = TRUE
- print "Sending ", SET_URI_AS_READED % (uri, dbus_value)
- self.iface.SparqlUpdate (SET_URI_AS_READED % (uri, dbus_value))
+ print "Sending ", SET_URI_AS_READED % (uri, anti_value, uri, dbus_value)
+ self.iface.SparqlUpdate (SET_URI_AS_READED % (uri, anti_value, uri, dbus_value))
def get_all_subscribed_feeds (self):
""" Returns [(uri, feed channel name, entries, visible)]
@@ -139,6 +148,13 @@ class TrackerRSS:
else:
return (info[0], info[1], False)
+ def get_text_for_uri (self, uri):
+ text = self.iface.SparqlQuery (QUERY_FOR_TEXT % (uri))
+ if (text[0]):
+ text = text[0][0].replace ("\\n", "\n")
+ else:
+ text = ""
+ return text
def mark_as_invisible (self, uri):
self.invisible_feeds.append (uri)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]