Commit 38061a63 authored by mathieui's avatar mathieui

Improve /bookmark *

- /bookmark{_local,} * now keeps the order of the tabs, and puts the
  currently non-opened tabs at the end of the list.
- also fix a bug in remote bookmark saving
parent d2de6236
...@@ -133,7 +133,7 @@ def save_privatexml(xmpp): ...@@ -133,7 +133,7 @@ def save_privatexml(xmpp):
def save_remote(xmpp, method=preferred): def save_remote(xmpp, method=preferred):
"""Save the remote bookmarks.""" """Save the remote bookmarks."""
method = "privatexml" if method != 'pep' else 'pep' method = 'privatexml' if method != 'pep' else 'pep'
try: try:
if method is 'privatexml': if method is 'privatexml':
...@@ -144,7 +144,7 @@ def save_remote(xmpp, method=preferred): ...@@ -144,7 +144,7 @@ def save_remote(xmpp, method=preferred):
method='xep_0223') method='xep_0223')
except: except:
import traceback import traceback
log.debug("Could not save the bookmarks:\n%s" % traceback.format_exc()) log.error("Could not save the bookmarks:\n%s" % traceback.format_exc())
return False return False
return True return True
......
...@@ -1973,21 +1973,26 @@ class Core(object): ...@@ -1973,21 +1973,26 @@ class Core(object):
args = common.shell_split(arg) args = common.shell_split(arg)
nick = None nick = None
password = None password = None
if len(args) == 0 and not isinstance(self.current_tab(), tabs.MucTab): if not args and not isinstance(self.current_tab(), tabs.MucTab):
return return
if len(args) == 0: if not args:
tab = self.current_tab() tab = self.current_tab()
roomname = tab.get_name() roomname = tab.get_name()
if tab.joined and tab.own_nick != self.own_nick: if tab.joined and tab.own_nick != self.own_nick:
nick = tab.own_nick nick = tab.own_nick
elif args[0] == '*': elif args[0] == '*':
new_bookmarks = []
for tab in self.get_tabs(tabs.MucTab): for tab in self.get_tabs(tabs.MucTab):
b = bookmark.get_by_jid(tab.get_name()) b = bookmark.get_by_jid(tab.get_name())
if not b: if not b:
b = bookmark.Bookmark(tab.get_name(), autojoin=True, method="local") b = bookmark.Bookmark(tab.get_name(), autojoin=True, method="local")
bookmark.bookmarks.append(b) new_bookmarks.append(b)
else: else:
b.method = "local" b.method = "local"
new_bookmarks.append(b)
bookmark.bookmarks.remove(b)
new_bookmarks.extend(bookmark.bookmarks)
bookmark.bookmarks = new_bookmarks
bookmark.save_local() bookmark.save_local()
bookmark.save_remote(self.xmpp) bookmark.save_remote(self.xmpp)
self.information('Bookmarks added and saved.', 'Info') self.information('Bookmarks added and saved.', 'Info')
...@@ -2058,9 +2063,9 @@ class Core(object): ...@@ -2058,9 +2063,9 @@ class Core(object):
return return
args = common.shell_split(arg) args = common.shell_split(arg)
nick = None nick = None
if len(args) == 0 and not isinstance(self.current_tab(), tabs.MucTab): if not args and not isinstance(self.current_tab(), tabs.MucTab):
return return
if len(args) == 0: if not args:
tab = self.current_tab() tab = self.current_tab()
roomname = tab.get_name() roomname = tab.get_name()
if tab.joined: if tab.joined:
...@@ -2072,15 +2077,21 @@ class Core(object): ...@@ -2072,15 +2077,21 @@ class Core(object):
autojoin = False if args[1].lower() != 'true' else True autojoin = False if args[1].lower() != 'true' else True
else: else:
autojoin = True autojoin = True
new_bookmarks = []
for tab in self.get_tabs(tabs.MucTab): for tab in self.get_tabs(tabs.MucTab):
b = bookmark.get_by_jid(tab.get_name()) b = bookmark.get_by_jid(tab.get_name())
if not b: if not b:
b = bookmark.Bookmark(tab.get_name(), autojoin=autojoin, b = bookmark.Bookmark(tab.get_name(), autojoin=autojoin,
method=bookmark.preferred) method=bookmark.preferred)
bookmark.bookmarks.append(b) new_bookmarks.append(b)
else: else:
b.method = bookmark.preferred b.method = bookmark.preferred
if bookmark.save_remote(self.xmpp, self): bookmark.bookmarks.remove(b)
new_bookmarks.append(b)
new_bookmarks.extend(bookmark.bookmarks)
bookmark.bookmarks = new_bookmarks
if bookmark.save_remote(self.xmpp):
bookmark.save_local() bookmark.save_local()
self.information("Bookmarks added.", "Info") self.information("Bookmarks added.", "Info")
else: else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment