From 43aef76dd9099df689bbd08bce1ae0a7061c5e55 Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Sun, 11 Sep 2005 15:02:22 +0000 Subject: [PATCH] [sef and me] now we also handle receiving invitations --- src/common/connection.py | 12 +++++++++-- src/common/gajim.py | 11 +++++++++- src/dialogs.py | 43 ++++++++++++++-------------------------- src/gajim.py | 16 +++++++++++++++ src/groupchat_window.py | 2 +- src/gtkgui.glade | 34 +++++++++++++++++++++++++------ 6 files changed, 80 insertions(+), 38 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index e6211456e..4e3b3b8e4 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -252,11 +252,16 @@ class Connection: xtags = msg.getTags('x') encTag = None decmsg = '' + invite = None for xtag in xtags: if xtag.getNamespace() == common.xmpp.NS_ENCRYPTED: encTag = xtag break - + #invitations + for xtag in xtags: + if xtag.getNamespace() == common.xmpp.NS_MUC_USER and xtag.getTag('invite'): + invite = xtag + # chatstates - look for chatstate tags in a message children = msg.getChildren() for child in children: @@ -292,7 +297,10 @@ class Connection: log_msgtxt = _('Subject: %s\n%s') % (subject, msgtxt) gajim.logger.write('incoming', log_msgtxt, unicode(msg.getFrom()), tim = tim) - self.dispatch('MSG', (unicode(msg.getFrom()), msgtxt, tim, + if invite is not None: + self.dispatch('GC_INVITATION',(unicode(msg.getFrom()), invite)) + else: + self.dispatch('MSG', (unicode(msg.getFrom()), msgtxt, tim, encrypted, mtype, subject, None)) else: # it's type 'chat' if not msg.getTag('body') and chatstate is None: #no diff --git a/src/common/gajim.py b/src/common/gajim.py index 4d3741d4f..8081813bb 100644 --- a/src/common/gajim.py +++ b/src/common/gajim.py @@ -77,11 +77,20 @@ def get_nick_from_jid(jid): pos = jid.find('@') return jid[:pos] +def get_server_from_jid(jid): + pos = jid.find('@') + return jid[pos:] + def get_nick_from_fjid(jid): # fake jid is the jid for a contact in a room # gaim@conference.jabber.no/nick/nick-continued return jid.split('/', 1)[1] +def get_room_name_and_server_from_room_jid(jid): + room_name = get_nick_from_jid(jid) + server = get_server_from_jid(jid) + return room_name, server + def get_room_and_nick_from_fjid(jid): # fake jid is the jid for a contact in a room # gaim@conference.jabber.no/nick/nick-continued @@ -132,7 +141,7 @@ def construct_fjid(room_jid, nick): ''' nick is in utf8 (taken from treeview); room_jid is in unicode''' # fake jid is the jid for a contact in a room # gaim@conference.jabber.org/nick - if type(nick) is str: + if isinstance(nick, str): nick = unicode(nick, 'utf-8') return room_jid + '/' + nick diff --git a/src/dialogs.py b/src/dialogs.py index c56c2bfd6..8d4bf4d21 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -456,7 +456,8 @@ class HigDialog(gtk.MessageDialog): def get_response(self): self.show_all() - response = gtk.Dialog.run(self) + response = self.run() + #response = gtk.Dialog.run(self) self.destroy() return response @@ -1151,37 +1152,23 @@ class XMLConsoleWindow: # it's expanded!! self.input_textview.grab_focus() -class InvitationReceivedDialog(HigDialog): +class InvitationReceivedDialog: def __init__(self, plugin, account, room_jid, contact_jid, password = None, comment = None): - self.plugin = plugin - self.account = account - items = [('inv-deny', _('_Deny'), 0, 0, None), - ('inv-accept', ('_Accept'), 0, 0, None)] - - # use regular stock icons. - aliases = [('inv-deny', gtk.STOCK_CANCEL), - ('inv-accept', gtk.STOCK_APPLY),] - - gtk.stock_add(items) - factory = gtk.IconFactory() - factory.add_default() - style= window.get_style() - for new_stock, alias in aliases: - icon_set = style.lookup_icon_set(alias) - factory.add(new_stock, icon_set) - - # Create the relabeled buttons - btn_deny = gtk.Button(stock = 'inv-deny') - btn_accept = gtk.Button(stock = 'inv-accept') - - #FIXME: add pango markup + xml = gtk.glade.XML(GTKGUI_GLADE, 'invitation_received_dialog', APP) + dialog = xml.get_widget('invitation_received_dialog') + pritext = _('You have been invited to the %(room_jid)s room by %(contact_jid)s') % { 'room_jid': room_jid, 'contact_jid': contact_jid } if comment is not None: - string += '\n' + _('Comment: %s') % comment + sectext = _('Comment: %s') % comment - HigDialog.__init__(self, None, pritext, sectext, - gtk.STOCK_DIALOG_WARNING, [ [btn_deny, gtk.RESPONSE_NO], - [ btn_accept, gtk.RESPONSE_YES ] ]) + xml.get_widget('label').set_markup( + '' + pritext + '\n\n' + sectext) + response = dialog.run() + dialog.destroy() + if response == gtk.RESPONSE_YES: + room, server = gajim.get_room_name_and_server_from_room_jid(room_jid) + JoinGroupchatWindow(plugin, account, server = server, room = room) + diff --git a/src/gajim.py b/src/gajim.py index 7586bc4e9..6965e93fd 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -671,7 +671,22 @@ class Interface: if not self.windows[account]['gc_config'].has_key(jid): self.windows[account]['gc_config'][jid] = \ config.GroupchatConfigWindow(self, account, jid, array[1]) + + def handle_event_gc_invitation(self, account, array): + #('GC_INVITATION', (unicode(msg.getFrom()), invite)) + items = array[1].getChildren() + password = None + reason = None + for item in items: + if item.getName() == 'invite': + contact_jid = item.getAttr('from') + reason = item.getTagData('reason') + if item.getName() == 'password': + password = item.getData() + dialogs.InvitationReceivedDialog(self, account, array[0], contact_jid, + password, reason) + def handle_event_bad_passphrase(self, account, array): use_gpg_agent = gajim.config.get('use_gpg_agent') if use_gpg_agent: @@ -987,6 +1002,7 @@ class Interface: 'GC_MSG': self.handle_event_gc_msg, 'GC_SUBJECT': self.handle_event_gc_subject, 'GC_CONFIG': self.handle_event_gc_config, + 'GC_INVITATION': self.handle_event_gc_invitation, 'BAD_PASSPHRASE': self.handle_event_bad_passphrase, 'ROSTER_INFO': self.handle_event_roster_info, 'BOOKMARKS': self.handle_event_bookmarks, diff --git a/src/groupchat_window.py b/src/groupchat_window.py index 2350e1d7f..db80331e2 100644 --- a/src/groupchat_window.py +++ b/src/groupchat_window.py @@ -665,7 +665,7 @@ class GroupchatWindow(chat.Chat): splitted_arg = after_command.split() if len(splitted_arg): jid_to_invite = splitted_arg[0] - reason = ' '.join(a[1:]) + reason = ' '.join(splitted_arg[1:]) gajim.connections[self.account].send_invite(room_jid, jid_to_invite, reason) return # don't print the command diff --git a/src/gtkgui.glade b/src/gtkgui.glade index 2eeb9f2c4..490ca4898 100644 --- a/src/gtkgui.glade +++ b/src/gtkgui.glade @@ -18991,7 +18991,6 @@ Maybe I'll refactor later 6 - True Invitation Received GTK_WINDOW_TOPLEVEL GTK_WIN_POS_NONE @@ -19018,13 +19017,13 @@ Maybe I'll refactor later GTK_BUTTONBOX_END - + True True True GTK_RELIEF_NORMAL True - 0 + -9 @@ -19093,13 +19092,14 @@ Maybe I'll refactor later - + True True + True True GTK_RELIEF_NORMAL True - 0 + -8 @@ -19176,7 +19176,29 @@ Maybe I'll refactor later - + + True + True + + False + True + GTK_JUSTIFY_LEFT + True + True + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False +