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

Fix join groupchat dialog with multiple accounts

The dialog didnt show the account combobox when activated
via CTRL + J from the Roster

Also add a application action for join groupchat
parent 129f72bf
......@@ -120,16 +120,17 @@ def on_service_disco(action, param):
def on_join_gc(action, param):
account = param.get_string()
invisible_show = app.SHOW_LIST.index('invisible')
if app.connections[account].connected == invisible_show:
app.interface.raise_dialog('join-while-invisible')
return
if 'join_gc' in interface.instances[account]:
interface.instances[account]['join_gc'].present()
account = None
if param is None:
if not app.get_connected_accounts():
return
else:
account = param.get_string()
window = app.get_app_window(dialogs.JoinGroupchatWindow)
if window is None:
dialogs.JoinGroupchatWindow(account, None)
else:
interface.instances[account]['join_gc'] = \
dialogs.JoinGroupchatWindow(account, None)
window.present()
def on_add_contact(action, param):
......
......@@ -303,6 +303,7 @@ class GajimApplication(Gtk.Application):
('quit', app_actions.on_quit),
('accounts', app_actions.on_accounts),
('add-account', app_actions.on_add_account),
('join-groupchat', app_actions.on_join_gc),
('manage-proxies', app_actions.on_manage_proxies),
('start-chat', app_actions.on_new_chat),
('bookmarks', app_actions.on_manage_bookmarks),
......
......@@ -577,3 +577,9 @@ def prefers_app_menu():
if sys.platform == 'win32':
return False
return app.prefers_app_menu()
def get_app_window(cls):
for win in app.get_windows():
if isinstance(win, cls):
return win
return None
......@@ -2351,10 +2351,10 @@ class JoinGroupchatWindow(Gtk.ApplicationWindow):
else:
for widget in extended_widgets:
getattr(self, widget).show()
self._fill_recent_and_servers(account)
if account is None:
connected_accounts = app.get_connected_accounts()
account = connected_accounts[0]
for acc in connected_accounts:
self.account_combo.append_text(acc)
else:
......@@ -2378,8 +2378,6 @@ class JoinGroupchatWindow(Gtk.ApplicationWindow):
# Select first account
self.account_combo.set_active(0)
if self.minimal_mode == 0:
self.recent_combo.set_active(0)
if self.password is not None:
self.password_entry.set_text(self.password)
......@@ -2393,7 +2391,7 @@ class JoinGroupchatWindow(Gtk.ApplicationWindow):
# Show password field if we are in extended mode or
# The MUC is passwordprotected
if self.minimal_mode == 0 or muc_caps_cache.supports(
room_jid, 'muc_passwordprotected'):
room_jid, 'muc_passwordprotected'):
self.password_entry.show()
self.password_label.show()
......@@ -2405,12 +2403,15 @@ class JoinGroupchatWindow(Gtk.ApplicationWindow):
self.server_combo.get_child().set_text(server)
def _fill_recent_and_servers(self, account):
self.recent_combo.remove_all()
self.server_combo.remove_all()
recent = app.get_recent_groupchats(account)
servers = []
for groupchat in recent:
text = '%s on %s@%s' % (groupchat.nickname,
groupchat.room,
groupchat.server)
self.recent_combo.append_text(text)
servers.append(groupchat.server)
......@@ -2435,7 +2436,11 @@ class JoinGroupchatWindow(Gtk.ApplicationWindow):
def _on_account_combo_changed(self, combo):
account = combo.get_active_text()
self.account = account
self.nick_entry.set_text(app.nicks[account])
if self.minimal_mode == 0:
self._fill_recent_and_servers(account)
self.recent_combo.set_active(0)
def _on_key_press_event(self, widget, event):
if event.keyval == Gdk.KEY_Escape:
......@@ -2448,6 +2453,11 @@ class JoinGroupchatWindow(Gtk.ApplicationWindow):
account = self.account_combo.get_active_text()
nickname = self.nick_entry.get_text()
invisible_show = app.SHOW_LIST.index('invisible')
if app.connections[account].connected == invisible_show:
app.interface.raise_dialog('join-while-invisible')
return
if self.minimal_mode < 2:
if self.minimal_mode == 0:
server = self.server_combo.get_active_text()
......@@ -2526,7 +2536,6 @@ class JoinGroupchatWindow(Gtk.ApplicationWindow):
def _on_destroy(self, *args):
if self.minimal_mode == 0:
del app.interface.instances[self.account]['join_gc']
app.ged.remove_event_handler('agent-info-received', ged.GUI1,
self._nec_agent_info_received)
app.ged.remove_event_handler('agent-info-error-received', ged.GUI1,
......
......@@ -3626,16 +3626,7 @@ class RosterWindow:
"""
When the join gc menuitem is clicked, show the join gc window
"""
invisible_show = app.SHOW_LIST.index('invisible')
if app.connections[account].connected == invisible_show:
dialogs.ErrorDialog(_('You cannot join a group chat while you are '
'invisible'))
return
if 'join_gc' in app.interface.instances[account]:
app.interface.instances[account]['join_gc'].present()
else:
app.interface.instances[account]['join_gc'] = \
dialogs.JoinGroupchatWindow(account, None)
app.app.activate_action('join-groupchat')
def on_show_transports_action(self, action, param):
app.config.set('show_transports_group', param.get_boolean())
......
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