| 1 | # -*- coding:utf-8 -*- |
|---|
| 2 | ## src/negotiation.py |
|---|
| 3 | ## |
|---|
| 4 | ## Copyright (C) 2007 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. |
|---|
| 12 | ## |
|---|
| 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. |
|---|
| 17 | ## |
|---|
| 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/>. |
|---|
| 20 | ## |
|---|
| 21 | |
|---|
| 22 | import gtkgui_helpers |
|---|
| 23 | import dataforms_widget |
|---|
| 24 | |
|---|
| 25 | import dialogs |
|---|
| 26 | |
|---|
| 27 | from common import dataforms |
|---|
| 28 | from common import gajim |
|---|
| 29 | from common import xmpp |
|---|
| 30 | |
|---|
| 31 | def describe_features(features): |
|---|
| 32 | '''a human-readable description of the features that have been negotiated''' |
|---|
| 33 | if features['logging'] == 'may': |
|---|
| 34 | return _('- messages will be logged') |
|---|
| 35 | elif features['logging'] == 'mustnot': |
|---|
| 36 | return _('- messages will not be logged') |
|---|
| 37 | |
|---|
| 38 | class FeatureNegotiationWindow: |
|---|
| 39 | '''FeatureNegotiotionWindow class''' |
|---|
| 40 | def __init__(self, account, jid, session, form): |
|---|
| 41 | self.account = account |
|---|
| 42 | self.jid = jid |
|---|
| 43 | self.form = form |
|---|
| 44 | self.session = session |
|---|
| 45 | |
|---|
| 46 | self.xml = gtkgui_helpers.get_glade('data_form_window.glade', 'data_form_window') |
|---|
| 47 | self.window = self.xml.get_widget('data_form_window') |
|---|
| 48 | |
|---|
| 49 | config_vbox = self.xml.get_widget('config_vbox') |
|---|
| 50 | dataform = dataforms.ExtendForm(node = self.form) |
|---|
| 51 | self.data_form_widget = dataforms_widget.DataFormWidget(dataform) |
|---|
| 52 | self.data_form_widget.show() |
|---|
| 53 | config_vbox.pack_start(self.data_form_widget) |
|---|
| 54 | |
|---|
| 55 | self.xml.signal_autoconnect(self) |
|---|
| 56 | self.window.show_all() |
|---|
| 57 | |
|---|
| 58 | def on_ok_button_clicked(self, widget): |
|---|
| 59 | acceptance = xmpp.Message(self.jid) |
|---|
| 60 | acceptance.setThread(self.session.thread_id) |
|---|
| 61 | feature = acceptance.NT.feature |
|---|
| 62 | feature.setNamespace(xmpp.NS_FEATURE) |
|---|
| 63 | |
|---|
| 64 | form = self.data_form_widget.data_form |
|---|
| 65 | form.setAttr('type', 'submit') |
|---|
| 66 | |
|---|
| 67 | feature.addChild(node=form) |
|---|
| 68 | |
|---|
| 69 | gajim.connections[self.account].send_stanza(acceptance) |
|---|
| 70 | |
|---|
| 71 | self.window.destroy() |
|---|
| 72 | |
|---|
| 73 | def on_cancel_button_clicked(self, widget): |
|---|
| 74 | rejection = xmpp.Message(self.jid) |
|---|
| 75 | rejection.setThread(self.session.thread_id) |
|---|
| 76 | feature = rejection.NT.feature |
|---|
| 77 | feature.setNamespace(xmpp.NS_FEATURE) |
|---|
| 78 | |
|---|
| 79 | x = xmpp.DataForm(typ='submit') |
|---|
| 80 | x.addChild(node=xmpp.DataField('FORM_TYPE', value='urn:xmpp:ssn')) |
|---|
| 81 | x.addChild(node=xmpp.DataField('accept', value='false', typ='boolean')) |
|---|
| 82 | |
|---|
| 83 | feature.addChild(node=x) |
|---|
| 84 | |
|---|
| 85 | gajim.connections[self.account].send_stanza(rejection) |
|---|
| 86 | |
|---|
| 87 | self.window.destroy() |
|---|
| 88 | |
|---|
| 89 | # vim: se ts=3: |
|---|