[kepi] ability to use subkeys. Fixes #6051
[gajim.git] / src / negotiation.py
blob869e2fb8b407287b50806597ffa007136fa59fd3
1 # -*- coding:utf-8 -*-
2 ## src/negotiation.py
3 ##
4 ## Copyright (C) 2007-2010 Yann Leboulanger <asterix AT lagaule.org>
5 ## Copyright (C) 2007-2008 Brendan Taylor <whateley AT gmail.com>
6 ##
7 ## This file is part of Gajim.
8 ##
9 ## Gajim is free software; you can redistribute it and/or modify
10 ## it under the terms of the GNU General Public License as published
11 ## by the Free Software Foundation; version 3 only.
13 ## Gajim is distributed in the hope that it will be useful,
14 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ## GNU General Public License for more details.
18 ## You should have received a copy of the GNU General Public License
19 ## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
22 import gtkgui_helpers
23 import dataforms_widget
25 from common import dataforms
26 from common import gajim
27 from common import xmpp
29 def describe_features(features):
30 """
31 A human-readable description of the features that have been negotiated
32 """
33 if features['logging'] == 'may':
34 return _('- messages will be logged')
35 elif features['logging'] == 'mustnot':
36 return _('- messages will not be logged')
38 class FeatureNegotiationWindow:
39 def __init__(self, account, jid, session, form):
40 self.account = account
41 self.jid = jid
42 self.form = form
43 self.session = session
45 self.xml = gtkgui_helpers.get_gtk_builder('data_form_window.ui', 'data_form_window')
46 self.window = self.xml.get_object('data_form_window')
48 config_vbox = self.xml.get_object('config_vbox')
49 dataform = dataforms.ExtendForm(node = self.form)
50 self.data_form_widget = dataforms_widget.DataFormWidget(dataform)
51 self.data_form_widget.show()
52 config_vbox.pack_start(self.data_form_widget)
54 self.xml.connect_signals(self)
55 self.window.show_all()
57 def on_ok_button_clicked(self, widget):
58 acceptance = xmpp.Message(self.jid)
59 acceptance.setThread(self.session.thread_id)
60 feature = acceptance.NT.feature
61 feature.setNamespace(xmpp.NS_FEATURE)
63 form = self.data_form_widget.data_form
64 form.setAttr('type', 'submit')
66 feature.addChild(node=form)
68 gajim.connections[self.account].send_stanza(acceptance)
70 self.window.destroy()
72 def on_cancel_button_clicked(self, widget):
73 rejection = xmpp.Message(self.jid)
74 rejection.setThread(self.session.thread_id)
75 feature = rejection.NT.feature
76 feature.setNamespace(xmpp.NS_FEATURE)
78 x = xmpp.DataForm(typ='submit')
79 x.addChild(node=xmpp.DataField('FORM_TYPE', value='urn:xmpp:ssn'))
80 x.addChild(node=xmpp.DataField('accept', value='false', typ='boolean'))
82 feature.addChild(node=x)
84 gajim.connections[self.account].send_stanza(rejection)
86 self.window.destroy()