gajim-plural/src/negotiation.py

87 lines
2.8 KiB
Python
Raw Normal View History

# -*- coding:utf-8 -*-
## src/negotiation.py
##
## Copyright (C) 2007 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/>.
##
2007-06-01 19:12:49 +02:00
import gtkgui_helpers
import dataforms_widget
from common import dataforms
2007-06-01 20:19:19 +02:00
from common import gajim
from common import xmpp
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)
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 = xmpp.Message(self.jid)
acceptance.setThread(self.session.thread_id)
feature = acceptance.NT.feature
feature.setNamespace(xmpp.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
gajim.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 = xmpp.Message(self.jid)
rejection.setThread(self.session.thread_id)
feature = rejection.NT.feature
feature.setNamespace(xmpp.NS_FEATURE)
2007-06-01 20:19:19 +02:00
x = xmpp.DataForm(typ='submit')
x.addChild(node=xmpp.DataField('FORM_TYPE', value='urn:xmpp:ssn'))
x.addChild(node=xmpp.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
gajim.connections[self.account].send_stanza(rejection)
2007-06-01 20:19:19 +02:00
self.window.destroy()