diff options
author | Sayamindu Dasgupta <sayamindu@gmail.com> | 2009-08-05 18:00:28 (GMT) |
---|---|---|
committer | Sayamindu Dasgupta <sayamindu@gmail.com> | 2009-08-05 18:00:28 (GMT) |
commit | 9dc4ad107a90811ae3b000f9d84536604d865893 (patch) | |
tree | 06743a4b1f5ea021f3b6f0e006148464d0491bba | |
parent | 98e358b9f712aa02a86e076387e6e567fb48167a (diff) |
Add method to Bookmark class to retrieve note title and body
-rw-r--r-- | readbookmark.py | 22 | ||||
-rw-r--r-- | readdialog.py | 4 | ||||
-rw-r--r-- | readsidebar.py | 14 |
3 files changed, 28 insertions, 12 deletions
diff --git a/readbookmark.py b/readbookmark.py index e4a410e..5ac9b24 100644 --- a/readbookmark.py +++ b/readbookmark.py @@ -15,11 +15,13 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +import cjson + class Bookmark: def __init__(self, data): self.md5 = data[0] self.page_no = data[1] - self.title = data[2] + self.content = data[2] self.timestamp = data[3] self.nick = data[4] self.color = data[5] @@ -29,4 +31,20 @@ class Bookmark: return self.page_no == page_no def is_local(self): - return bool(self.local)
\ No newline at end of file + return bool(self.local) + + def get_note_title(self): + if self.content == '' or self.content is None: + return '' + + note = cjson.decode(self.content) + return note['title'] + + def get_note_body(self): + if self.content == '' or self.content is None: + return '' + + note = cjson.decode(self.content) + return note['body'] + + diff --git a/readdialog.py b/readdialog.py index 24e7d33..c60d1a0 100644 --- a/readdialog.py +++ b/readdialog.py @@ -165,7 +165,7 @@ class BookmarkAddDialog(BookmarkDialog): def accept_clicked_cb(self, widget): title = self._title_entry.get_text() details = self._content_entry.get_buffer().props.text - content = {'title' : unicode(title), 'content' : unicode(details)} + content = {'title' : unicode(title), 'body' : unicode(details)} self._sidebarinstance._real_add_bookmark(self._page, cjson.encode(content)) self.destroy() @@ -176,7 +176,7 @@ class BookmarkEditDialog(BookmarkDialog): def accept_clicked_cb(self, widget): title = self._title_entry.get_text() details = self._content_entry.get_buffer().props.text - content = {'title' : unicode(title), 'content' : unicode(details)} + content = {'title' : unicode(title), 'body' : unicode(details)} self._sidebarinstance.del_bookmark(self._page) self._sidebarinstance._real_add_bookmark(self._page, cjson.encode(content)) self.destroy() diff --git a/readsidebar.py b/readsidebar.py index 0b745c2..d8bb895 100644 --- a/readsidebar.py +++ b/readsidebar.py @@ -16,7 +16,7 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import logging -import time, cjson +import time import gtk @@ -76,10 +76,8 @@ class Sidebar(gtk.EventBox): self._is_showing_local_bookmark = True def __bookmark_icon_query_tooltip_cb(self, widget, x, y, keyboard_mode, tip, bookmark): - content = cjson.decode(bookmark.title) - - tooltip_header = content['title'] - tooltip_body = content['content'] + tooltip_header = bookmark.get_note_title() + tooltip_body = bookmark.get_note_body() #TRANS: This goes like Bookmark added by User 5 days ago (the elapsed string gets translated #TRANS: automatically) tooltip_footer = (_('Bookmark added by %(user)s %(time)s') \ @@ -118,9 +116,9 @@ class Sidebar(gtk.EventBox): def __event_cb(self, widget, event, bookmark): if event.type == gtk.gdk.BUTTON_PRESS and \ self._bookmark_icon is not None: - content = cjson.decode(bookmark.title) - bookmark_title = content['title'] - bookmark_content = content['content'] + + bookmark_title = bookmark.get_note_title() + bookmark_content = bookmark.get_note_body() dialog = BookmarkEditDialog(parent_xid = self.get_toplevel().window.xid, \ dialog_title = _("Add notes for bookmark: "), \ |