Commit a89bec0b authored by Philipp Hörist's avatar Philipp Hörist

Refactor Bookmarks

- Simplify modules because nbxmpp handles more stuff
parent fa7f6f2b
Pipeline #3019 passed with stages
in 4 minutes and 4 seconds
......@@ -1497,7 +1497,7 @@ class Connection(CommonConnection, ConnectionHandlers):
self.get_module('VCardTemp').request_vcard()
# Get bookmarks
self.get_module('Bookmarks').get_bookmarks()
self.get_module('Bookmarks').request_bookmarks()
# Get annotations
self.get_module('Annotations').get_annotations()
......@@ -1625,7 +1625,7 @@ class Connection(CommonConnection, ConnectionHandlers):
# ask our VCard
self.get_module('VCardTemp').request_vcard()
self.get_module('Bookmarks').get_bookmarks()
self.get_module('Bookmarks').request_bookmarks()
self.get_module('Annotations').get_annotations()
self.get_module('Blocking').get_blocking_list()
......
This diff is collapsed.
......@@ -468,7 +468,7 @@ class GroupchatControl(ChatControlBase):
# Bookmarks
con = app.connections[self.account]
bookmarked = self.room_jid in con.get_module('Bookmarks').bookmarks
bookmarked = con.get_module('Bookmarks').is_bookmark(self.room_jid)
self._get_action('bookmark-').set_enabled(self.is_connected and
not bookmarked)
......
......@@ -16,6 +16,7 @@ from enum import IntEnum
from gi.repository import Gtk
from gi.repository import Gdk
from nbxmpp.structs import BookmarkData
from gajim.common import app
from gajim.common import helpers
......@@ -57,14 +58,14 @@ class ManageBookmarksWindow:
con = app.connections[account]
bookmarks = con.get_module('Bookmarks').get_sorted_bookmarks()
for jid, bookmark in bookmarks.items():
for bookmark in bookmarks:
self.treestore.append(iter_, [account,
bookmark['name'],
jid,
bookmark['autojoin'],
bookmark['password'],
bookmark['nick'],
bookmark['name']])
bookmark.name,
bookmark.jid,
bookmark.autojoin,
bookmark.password,
bookmark.nick,
bookmark.name])
self.view = self.xml.get_object('bookmarks_treeview')
self.view.set_model(self.treestore)
......@@ -190,20 +191,17 @@ class ManageBookmarksWindow:
for account in self.treestore:
acct = account[1]
con = app.connections[acct]
con.get_module('Bookmarks').bookmarks = {}
bookmarks = []
for bm in account.iterchildren():
# create the bookmark-dict
bmdict = {
'name': bm[Row.ROOM_NAME],
'autojoin': bm[Row.AUTOJOIN],
'password': bm[Row.PASSWORD],
'nick': bm[Row.NICK],
}
jid = bm[Row.ROOM_JID]
con.get_module('Bookmarks').bookmarks[jid] = bmdict
bookmark = BookmarkData(jid=bm[Row.ROOM_JID],
name=bm[Row.ROOM_NAME],
autojoin=bm[Row.AUTOJOIN],
password=bm[Row.PASSWORD],
nick=bm[Row.NICK])
bookmarks.append(bookmark)
con.get_module('Bookmarks').bookmarks = bookmarks
con.get_module('Bookmarks').store_bookmarks()
self.window.destroy()
......
......@@ -1707,7 +1707,7 @@ class MucBrowser(AgentBrowser):
return
room_jid = model[iter_][0]
if room_jid in con.get_module('Bookmarks').bookmarks:
if con.get_module('Bookmarks').is_bookmark(room_jid):
ErrorDialog(
_('Bookmark already set'),
_('Group Chat "%s" is already in your bookmarks.') % room_jid,
......
......@@ -92,8 +92,8 @@ class StartChatDialog(Gtk.ApplicationWindow):
con = app.connections[account]
bookmarks = con.get_module('Bookmarks').bookmarks
groupchats = {}
for jid, bookmark in bookmarks.items():
groupchats[jid] = bookmark['name']
for bookmark in bookmarks:
groupchats[bookmark.jid] = bookmark.name
for jid in app.contacts.get_gc_list(account):
if jid in groupchats:
......
......@@ -1552,11 +1552,10 @@ class Interface:
return
con = app.connections[account]
bookmarks = con.get_module('Bookmarks').bookmarks
bookmark = bookmarks.get(room_jid, None)
bookmark = con.get_module('Bookmarks').get_bookmark_from_jid(room_jid)
if bookmark is not None:
app.interface.join_gc_room(
account, room_jid, bookmark['nick'], bookmark['password'])
account, bookmark.jid, bookmark.nick, bookmark.password)
return
try:
......
......@@ -167,14 +167,13 @@ show_bookmarked=False, force_resource=False):
r_jids = [] # list of room jids
for account in connected_accounts:
con = app.connections[account]
boomarks = con.get_module('Bookmarks').bookmarks
for jid in boomarks.keys():
if jid in r_jids:
for bookmark in con.get_module('Bookmarks').bookmarks:
if bookmark.jid in r_jids:
continue
if jid not in app.gc_connected[account] or not \
app.gc_connected[account][jid]:
rooms2.append((jid, account))
r_jids.append(jid)
if bookmark.jid not in app.gc_connected[account] or not \
app.gc_connected[account][bookmark.jid]:
rooms2.append((bookmark.jid, account))
r_jids.append(bookmark.jid)
if not rooms2:
return
......@@ -736,7 +735,7 @@ def get_groupchat_menu(control_id, account, jid):
def get_bookmarks_menu(account, rebuild=False):
con = app.connections[account]
boomarks = con.get_module('Bookmarks').get_sorted_bookmarks(short_name=True)
bookmarks = con.get_module('Bookmarks').get_sorted_bookmarks(short_name=True)
menu = Gio.Menu()
......@@ -749,19 +748,17 @@ def get_bookmarks_menu(account, rebuild=False):
# Build Bookmarks
section = Gio.Menu()
for jid, bookmark in boomarks.items():
name = bookmark['name']
for bookmark in bookmarks:
action = 'app.{}-activate-bookmark'.format(account)
menuitem = Gio.MenuItem.new(name, action)
menuitem = Gio.MenuItem.new(bookmark.name, action)
# Create Variant Dict
dict_ = {'account': GLib.Variant('s', account),
'jid': GLib.Variant('s', jid)}
if bookmark['nick']:
dict_['nick'] = GLib.Variant('s', bookmark['nick'])
if bookmark['password']:
dict_['password'] = GLib.Variant('s', bookmark['password'])
'jid': GLib.Variant('s', bookmark.jid)}
if bookmark.nick:
dict_['nick'] = GLib.Variant('s', bookmark.nick)
if bookmark.password:
dict_['password'] = GLib.Variant('s', bookmark.password)
variant_dict = GLib.Variant('a{sv}', dict_)
menuitem.set_action_and_target_value(action, variant_dict)
......
......@@ -2706,9 +2706,9 @@ class RosterWindow:
### FIXME: order callbacks in itself...
################################################################################
def on_bookmark_menuitem_activate(self, widget, account, jid, bookmark):
def on_bookmark_menuitem_activate(self, widget, account, bookmark):
app.interface.join_gc_room(
account, jid, bookmark['nick'], bookmark['password'])
account, bookmark.jid, bookmark.nick, bookmark.password)
def on_info(self, widget, contact, account):
"""
......@@ -5421,15 +5421,13 @@ class RosterWindow:
bookmarks = con.get_module('Bookmarks').get_sorted_bookmarks(
short_name=True)
for jid, bookmark in bookmarks.items():
name = bookmark['name']
for bookmark in bookmarks:
# Do not use underline.
item = Gtk.MenuItem.new_with_label(name)
item = Gtk.MenuItem.new_with_label(bookmark.name)
item.set_use_underline(False)
item.connect(
'activate', self.on_bookmark_menuitem_activate,
account, jid, bookmark)
account, bookmark)
gc_sub_menu.append(item)
def show_appropriate_context_menu(self, event, iters):
......
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