[sef and me] now we also handle receiving invitations

This commit is contained in:
Nikos Kouremenos 2005-09-11 15:02:22 +00:00
parent a311b5dd61
commit 43aef76dd9
6 changed files with 80 additions and 38 deletions

View File

@ -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 <body>

View File

@ -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

View File

@ -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(
'<span size="larger" weight="bold">' + pritext + '</span>\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)

View File

@ -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,

View File

@ -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

View File

@ -18991,7 +18991,6 @@ Maybe I'll refactor later</property>
<widget class="GtkDialog" id="invitation_received_dialog">
<property name="border_width">6</property>
<property name="visible">True</property>
<property name="title" translatable="yes">Invitation Received</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
@ -19018,13 +19017,13 @@ Maybe I'll refactor later</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="button28">
<widget class="GtkButton" id="deny_button">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">0</property>
<property name="response_id">-9</property>
<child>
<widget class="GtkAlignment" id="alignment95">
@ -19093,13 +19092,14 @@ Maybe I'll refactor later</property>
</child>
<child>
<widget class="GtkButton" id="button29">
<widget class="GtkButton" id="accept_button">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">0</property>
<property name="response_id">-8</property>
<child>
<widget class="GtkAlignment" id="alignment94">
@ -19176,7 +19176,29 @@ Maybe I'll refactor later</property>
</child>
<child>
<placeholder/>
<widget class="GtkLabel" id="label">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">True</property>
<property name="selectable">True</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>