diff options
author | mathieui <mathieui@mathieui.net> | 2011-11-26 23:08:41 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2011-11-26 23:08:41 +0100 |
commit | 68c0ddeb299d30d0f5dc5502489ca882369ecc8b (patch) | |
tree | e9547e3a8764cdccdfb5ae8d4067b114f9a85e3f /src/bookmark.py | |
parent | 1d5b33166362291ccfe101b6f609e551ac03351b (diff) | |
download | poezio-68c0ddeb299d30d0f5dc5502489ca882369ecc8b.tar.gz poezio-68c0ddeb299d30d0f5dc5502489ca882369ecc8b.tar.bz2 poezio-68c0ddeb299d30d0f5dc5502489ca882369ecc8b.tar.xz poezio-68c0ddeb299d30d0f5dc5502489ca882369ecc8b.zip |
Add save() methods to save bookmarks in every way
Diffstat (limited to 'src/bookmark.py')
-rw-r--r-- | src/bookmark.py | 54 |
1 files changed, 54 insertions, 0 deletions
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() |