From 682d6f838ae2fbe5299f40c0fb87dc100ca614ee Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 2 Sep 2009 23:45:16 +0200 Subject: [PATCH] add account combobox to join groupchat dialog when we try to join a groupchat from another chat / groupchat. Fixes #3344 --- data/glade/join_groupchat_window.glade | 620 ++++++++++--------------- src/conversation_textview.py | 3 +- src/dialogs.py | 87 ++-- src/groupchat_control.py | 5 +- 4 files changed, 318 insertions(+), 397 deletions(-) diff --git a/data/glade/join_groupchat_window.glade b/data/glade/join_groupchat_window.glade index 4c13f84fc..6e08f2826 100644 --- a/data/glade/join_groupchat_window.glade +++ b/data/glade/join_groupchat_window.glade @@ -1,365 +1,259 @@ - - - + - - - 6 - Join Group Chat - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - True - False - True - False - False - GDK_WINDOW_TYPE_HINT_NORMAL - GDK_GRAVITY_NORTH_WEST - True - False - - - - - - True - False - 12 - - - - True - 5 - 2 - False - 6 - 12 - - - - True - True - True - True - True - 0 - - True - True - - - - 1 - 2 - 2 - 3 - - - - - - - True - True - True - True - 0 - - True - True - - - - 1 - 2 - 1 - 2 - - - - - - - True - Room: - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 2 - 3 - fill - - - - - - - True - Nickname: - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 1 - 2 - fill - - - - - - - True - Recently: - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 0 - 1 - fill - - - - - - - True - False - True - - - - 1 - 2 - 0 - 1 - fill - fill - - - - - - True - Password: - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 3 - 4 - fill - - - - - - - True - True - True - False - 0 - - True - True - - - 1 - 2 - 3 - 4 - - - - - - - True - True - Join this room automatically when I connect - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - 2 - 4 - 5 - fill - - - - - - 0 - True - True - - - - - - True - GTK_BUTTONBOX_END - 12 - - - - True - True - True - gtk-cancel - True - GTK_RELIEF_NORMAL - True - - - - - - - True - True - True - True - GTK_RELIEF_NORMAL - True - - - - - True - 0.5 - 0.5 - 0 - 0 - 0 - 0 - 0 - 0 - - - - True - False - 2 - - - - True - gtk-apply - 4 - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - _Join - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - - - - - - 0 - False - True - - - - - - + + + + 6 + Join Group Chat + + + + + True + 12 + + + True + 6 + 2 + 12 + 6 + + + True + True + True + True + + + + 1 + 2 + 3 + 4 + + + + + + True + True + True + + + + 1 + 2 + 2 + 3 + + + + + + True + 0 + Room: + + + 3 + 4 + GTK_FILL + + + + + + True + 0 + Nickname: + + + 2 + 3 + GTK_FILL + + + + + + True + 0 + Recently: + + + 1 + 2 + GTK_FILL + + + + + + True + + + + 1 + 2 + 1 + 2 + GTK_FILL + GTK_FILL + + + + + True + 0 + Password: + + + 4 + 5 + GTK_FILL + + + + + + True + True + False + True + + + 1 + 2 + 4 + 5 + + + + + + Join this room automatically when I connect + True + True + False + True + True + + + 2 + 5 + 6 + GTK_FILL + + + + + + True + 0 + Account + + + GTK_FILL + + + + + + True + + + + 1 + 2 + GTK_FILL + GTK_FILL + + + + + 0 + + + + + True + 12 + end + + + gtk-cancel + True + True + True + False + True + + + + False + False + 0 + + + + + True + True + True + True + False + + + + True + 0 + 0 + + + True + 2 + + + True + gtk-apply + + + False + False + 0 + + + + + True + _Join + True + + + False + False + 1 + + + + + + + + + False + False + 1 + + + + + False + 1 + + + + + diff --git a/src/conversation_textview.py b/src/conversation_textview.py index 83d88e683..5d91ca05f 100644 --- a/src/conversation_textview.py +++ b/src/conversation_textview.py @@ -827,8 +827,7 @@ class ConversationTextview(gobject.GObject): gajim.interface.instances[self.account]['join_gc'].window.present() else: try: - gajim.interface.instances[self.account]['join_gc'] = \ - dialogs.JoinGroupchatWindow(self.account, room_jid) + dialogs.JoinGroupchatWindow(account=None, room_jid=room_jid) except GajimGeneralException: pass diff --git a/src/dialogs.py b/src/dialogs.py index c945889da..a12ceee8a 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -1893,28 +1893,42 @@ class SubscriptionRequestWindow: class JoinGroupchatWindow: - def __init__(self, account, room_jid='', nick='', password='', + def __init__(self, account=None, room_jid='', nick='', password='', automatic=False): '''automatic is a dict like {'invities': []} If automatic is not empty, this means room must be automaticaly configured and when done, invities must be automatically invited''' - if room_jid != '': - if room_jid in gajim.gc_connected[account] and\ - gajim.gc_connected[account][room_jid]: + self.xml = gtkgui_helpers.get_glade('join_groupchat_window.glade') + if account: + if room_jid != '' and room_jid in gajim.gc_connected[account] and\ + gajim.gc_connected[account][room_jid]: ErrorDialog(_('You are already in group chat %s') % room_jid) raise GajimGeneralException, 'You are already in this group chat' + if nick == '': + nick = gajim.nicks[account] + if gajim.connections[account].connected < 2: + ErrorDialog(_('You are not connected to the server'), + _('You can not join a group chat unless you are connected.')) + raise GajimGeneralException, 'You must be connected to join a groupchat' + else: + account_label = self.xml.get_widget('account_label') + account_combobox = self.xml.get_widget('account_combobox') + account_label.set_no_show_all(False) + account_combobox.set_no_show_all(False) + liststore = gtk.ListStore(str) + account_combobox.set_model(liststore) + cell = gtk.CellRendererText() + account_combobox.pack_start(cell, True) + account_combobox.add_attribute(cell, 'text', 0) + for acct in [a for a in gajim.connections if \ + gajim.account_is_connected(a)]: + account_combobox.append_text(acct) + account_combobox.set_active(-1) + self.account = account self.automatic = automatic - if nick == '': - nick = gajim.nicks[self.account] - if gajim.connections[account].connected < 2: - ErrorDialog(_('You are not connected to the server'), - _('You can not join a group chat unless you are connected.')) - raise GajimGeneralException, 'You must be connected to join a groupchat' - self._empty_required_widgets = [] - self.xml = gtkgui_helpers.get_glade('join_groupchat_window.glade') self.window = self.xml.get_widget('join_groupchat_window') self._room_jid_entry = self.xml.get_widget('room_jid_entry') self._nickname_entry = self.xml.get_widget('nickname_entry') @@ -1925,11 +1939,13 @@ class JoinGroupchatWindow: if password: self._password_entry.set_text(password) self.xml.signal_autoconnect(self) - # now add us to open windows - gajim.interface.instances[account]['join_gc'] = self - if len(gajim.connections) > 1: - title = _('Join Group Chat with account %s') % account - else: + title = None + if account: + # now add us to open windows + gajim.interface.instances[account]['join_gc'] = self + if len(gajim.connections) > 1: + title = _('Join Group Chat with account %s') % account + if title is None: title = _('Join Group Chat') self.window.set_title(title) @@ -1957,15 +1973,16 @@ class JoinGroupchatWindow: if len(self._empty_required_widgets): self.xml.get_widget('join_button').set_sensitive(False) - if not gajim.connections[account].private_storage_supported: + if account and not gajim.connections[account].private_storage_supported: self.xml.get_widget('auto_join_checkbutton').set_sensitive(False) self.window.show_all() def on_join_groupchat_window_destroy(self, widget): '''close window''' - # remove us from open windows - del gajim.interface.instances[self.account]['join_gc'] + if self.account and 'join_gc' in gajim.interface.instances[self.account]: + # remove us from open windows + del gajim.interface.instances[self.account]['join_gc'] def on_join_groupchat_window_key_press_event(self, widget, event): if event.keyval == gtk.keysyms.Escape: # ESCAPE @@ -1978,8 +1995,14 @@ class JoinGroupchatWindow: else: if widget in self._empty_required_widgets: self._empty_required_widgets.remove(widget) - if len(self._empty_required_widgets) == 0: - self.xml.get_widget('join_button').set_sensitive(True) + if len(self._empty_required_widgets) == 0 and self.account: + self.xml.get_widget('join_button').set_sensitive(True) + + def on_account_combobox_changed(self, widget): + model = widget.get_model() + iter_ = widget.get_active_iter() + self.account = model[iter_][0].decode('utf-8') + self.on_required_entry_changed(self._nickname_entry) def on_recently_combobox_changed(self, widget): model = widget.get_model() @@ -1993,6 +2016,11 @@ class JoinGroupchatWindow: def on_join_button_clicked(self, widget): '''When Join button is clicked''' + if not self.account: + ErrorDialog(_('Invalid Account'), + _('You have to choose an account from which you want to join the ' + 'groupchat.')) + return nickname = self._nickname_entry.get_text().decode('utf-8') room_jid = self._room_jid_entry.get_text().decode('utf-8') password = self._password_entry.get_text().decode('utf-8') @@ -2000,25 +2028,26 @@ class JoinGroupchatWindow: nickname = helpers.parse_resource(nickname) except Exception: ErrorDialog(_('Invalid Nickname'), - _('The nickname has not allowed characters.')) + _('The nickname has not allowed characters.')) return user, server, resource = helpers.decompose_jid(room_jid) if not user or not server or resource: ErrorDialog(_('Invalid group chat Jabber ID'), - _('The group chat Jabber ID has not allowed characters.')) + _('The group chat Jabber ID has not allowed characters.')) return try: room_jid = helpers.parse_jid(room_jid) except Exception: ErrorDialog(_('Invalid group chat Jabber ID'), - _('The group chat Jabber ID has not allowed characters.')) + _('The group chat Jabber ID has not allowed characters.')) return if gajim.interface.msg_win_mgr.has_window(room_jid, self.account): - ctrl = gajim.interface.msg_win_mgr.get_gc_control(room_jid, self.account) + ctrl = gajim.interface.msg_win_mgr.get_gc_control(room_jid, + self.account) if ctrl.type_id != message_control.TYPE_GC: ErrorDialog(_('This is not a group chat'), - _('%s is not the name of a group chat.') % room_jid) + _('%s is not the name of a group chat.') % room_jid) return if room_jid in self.recently_groupchat: self.recently_groupchat.remove(room_jid) @@ -2026,13 +2055,13 @@ class JoinGroupchatWindow: if len(self.recently_groupchat) > 10: self.recently_groupchat = self.recently_groupchat[0:10] gajim.config.set('recently_groupchat', - ' '.join(self.recently_groupchat)) + ' '.join(self.recently_groupchat)) if self.xml.get_widget('auto_join_checkbutton').get_active(): # Add as bookmark, with autojoin and not minimized name = gajim.get_nick_from_jid(room_jid) gajim.interface.add_gc_bookmark(self.account, name, room_jid, '1', \ - '0', password, nickname) + '0', password, nickname) if self.automatic: gajim.automatic_rooms[self.account][room_jid] = self.automatic diff --git a/src/groupchat_control.py b/src/groupchat_control.py index 99fdb6ab9..3439f8f9b 100644 --- a/src/groupchat_control.py +++ b/src/groupchat_control.py @@ -1592,9 +1592,8 @@ class GroupchatControl(ChatControlBase): window.present() else: try: - gajim.interface.instances[self.account]['join_gc'] =\ - dialogs.JoinGroupchatWindow(self.account, - room_jid = room_jid, nick=nick) + dialogs.JoinGroupchatWindow(account=None, room_jid=room_jid, + nick=nick) except GajimGeneralException: pass self.clear(self.msg_textview)