2008-08-15 19:31:51 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## src/negotiation.py
|
|
|
|
##
|
2014-01-02 09:33:54 +01:00
|
|
|
## Copyright (C) 2007-2014 Yann Leboulanger <asterix AT lagaule.org>
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2007-2008 Brendan Taylor <whateley AT gmail.com>
|
|
|
|
##
|
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
|
|
|
## it under the terms of the GNU General Public License as published
|
|
|
|
## by the Free Software Foundation; version 3 only.
|
|
|
|
##
|
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
|
|
|
## You should have received a copy of the GNU General Public License
|
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
##
|
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim import gtkgui_helpers
|
|
|
|
from gajim import dataforms_widget
|
2007-06-01 19:12:49 +02:00
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common import dataforms
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2012-12-09 21:37:51 +01:00
|
|
|
import nbxmpp
|
2007-06-01 19:12:49 +02:00
|
|
|
|
2007-07-02 18:53:19 +02:00
|
|
|
def describe_features(features):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
A human-readable description of the features that have been negotiated
|
|
|
|
"""
|
|
|
|
if features['logging'] == 'may':
|
|
|
|
return _('- messages will be logged')
|
|
|
|
elif features['logging'] == 'mustnot':
|
|
|
|
return _('- messages will not be logged')
|
2007-07-04 20:55:53 +02:00
|
|
|
|
2007-06-01 19:12:49 +02:00
|
|
|
class FeatureNegotiationWindow:
|
2010-02-08 15:08:40 +01:00
|
|
|
def __init__(self, account, jid, session, form):
|
|
|
|
self.account = account
|
|
|
|
self.jid = jid
|
|
|
|
self.form = form
|
|
|
|
self.session = session
|
2007-06-01 19:12:49 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.xml = gtkgui_helpers.get_gtk_builder('data_form_window.ui', 'data_form_window')
|
|
|
|
self.window = self.xml.get_object('data_form_window')
|
2007-06-01 19:12:49 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
config_vbox = self.xml.get_object('config_vbox')
|
|
|
|
dataform = dataforms.ExtendForm(node = self.form)
|
|
|
|
self.data_form_widget = dataforms_widget.DataFormWidget(dataform)
|
|
|
|
self.data_form_widget.show()
|
2012-12-23 16:23:43 +01:00
|
|
|
config_vbox.pack_start(self.data_form_widget, True, True, 0)
|
2007-06-01 19:12:49 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.xml.connect_signals(self)
|
|
|
|
self.window.show_all()
|
2007-06-01 20:19:19 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def on_ok_button_clicked(self, widget):
|
2012-12-09 21:37:51 +01:00
|
|
|
acceptance = nbxmpp.Message(self.jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
acceptance.setThread(self.session.thread_id)
|
|
|
|
feature = acceptance.NT.feature
|
2012-12-09 21:37:51 +01:00
|
|
|
feature.setNamespace(nbxmpp.NS_FEATURE)
|
2007-06-02 00:08:23 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
form = self.data_form_widget.data_form
|
|
|
|
form.setAttr('type', 'submit')
|
2007-06-02 00:08:23 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
feature.addChild(node=form)
|
2007-06-02 00:08:23 +02:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
app.connections[self.account].send_stanza(acceptance)
|
2007-06-02 00:08:23 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.window.destroy()
|
2007-06-02 00:08:23 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def on_cancel_button_clicked(self, widget):
|
2012-12-09 21:37:51 +01:00
|
|
|
rejection = nbxmpp.Message(self.jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
rejection.setThread(self.session.thread_id)
|
|
|
|
feature = rejection.NT.feature
|
2012-12-09 21:37:51 +01:00
|
|
|
feature.setNamespace(nbxmpp.NS_FEATURE)
|
2007-06-01 20:19:19 +02:00
|
|
|
|
2012-12-09 21:37:51 +01:00
|
|
|
x = nbxmpp.DataForm(typ='submit')
|
|
|
|
x.addChild(node=nbxmpp.DataField('FORM_TYPE', value='urn:xmpp:ssn'))
|
|
|
|
x.addChild(node=nbxmpp.DataField('accept', value='false', typ='boolean'))
|
2007-06-01 20:19:19 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
feature.addChild(node=x)
|
2007-06-01 20:19:19 +02:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
app.connections[self.account].send_stanza(rejection)
|
2007-06-01 20:19:19 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.window.destroy()
|