From 68c0ddeb299d30d0f5dc5502489ca882369ecc8b Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 26 Nov 2011 23:08:41 +0100 Subject: Add save() methods to save bookmarks in every way --- src/bookmark.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src') diff --git a/src/bookmark.py b/src/bookmark.py index 5f1fe508..67ef5eba 100644 --- a/src/bookmark.py +++ b/src/bookmark.py @@ -76,6 +76,60 @@ class Bookmark(object): bookmarks = [] +def get_by_jid(value): + """ + Get a bookmark by bare jid + """ + for item in bookmarks: + if item.jid == value: + return item + +def remove(value): + """ + Remove a bookmark + """ + if isinstance(value, str): + value = get_by_jid(value) + bookmarks.remove(value) + +def save_pep(xmpp): + xmpp.plugin['xep_0048'].set_bookmarks(stanza_pep()) + +def save_privatexml(xmpp): + xmpp.plugin['xep_0048'].set_bookmarks_old(stanza_privatexml()) + +def save_remote(xmpp, core=None): + method = config.get('use_bookmarks_method', '') + if method not in ('pep', 'privatexml'): + try: + save_pep(xmpp) + except: + if core: + core.information('Could not save bookmarks.', 'Error') + else: + try: + if method == 'pep': + save_pep(xmpp) + else: + save_privatexml(xmpp) + except: + if core: + core.information('Could not save bookmarks.', 'Error') + +def save_local(): + all = '' + for bookmark in filter(lambda b: b.method == "local", bookmarks): + st = bookmark.jid + if bookmark.nick: + st += '/' + nick + st += ':' + all += st + config.set_and_save('rooms', all) + +def save(xmpp, core=None): + save_local() + save_remote(xmpp, core) + def get_pep(xmpp): try: iq = xmpp.plugin['xep_0048'].get_bookmarks() -- cgit v1.2.3