gajim-plural/gajim/negotiation.py

87 lines
2.9 KiB
Python
Raw Normal View History

# -*- coding:utf-8 -*-
## src/negotiation.py
##
2014-01-02 09:33:54 +01:00
## Copyright (C) 2007-2014 Yann Leboulanger <asterix AT lagaule.org>
## 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
2018-07-21 14:35:28 +02:00
from gajim.common.modules import dataforms
from gajim.common import app
import nbxmpp
2007-06-01 19:12:49 +02:00
def describe_features(features):
"""
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:
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
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
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()
config_vbox.pack_start(self.data_form_widget, True, True, 0)
2007-06-01 19:12:49 +02:00
self.xml.connect_signals(self)
self.window.show_all()
2007-06-01 20:19:19 +02:00
def on_ok_button_clicked(self, widget):
acceptance = nbxmpp.Message(self.jid)
acceptance.setThread(self.session.thread_id)
feature = acceptance.NT.feature
feature.setNamespace(nbxmpp.NS_FEATURE)
2007-06-02 00:08:23 +02:00
form = self.data_form_widget.data_form
form.setAttr('type', 'submit')
2007-06-02 00:08:23 +02:00
feature.addChild(node=form)
2007-06-02 00:08:23 +02:00
app.connections[self.account].send_stanza(acceptance)
2007-06-02 00:08:23 +02:00
self.window.destroy()
2007-06-02 00:08:23 +02:00
def on_cancel_button_clicked(self, widget):
rejection = nbxmpp.Message(self.jid)
rejection.setThread(self.session.thread_id)
feature = rejection.NT.feature
feature.setNamespace(nbxmpp.NS_FEATURE)
2007-06-01 20:19:19 +02: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
feature.addChild(node=x)
2007-06-01 20:19:19 +02:00
app.connections[self.account].send_stanza(rejection)
2007-06-01 20:19:19 +02:00
self.window.destroy()