1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# Copyright (C) 2018 Philipp Hörist <philipp AT hoerist.com>
#
# This file is part of Form Handler.
#
# Form Handler 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.
#
# Form Handler 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 Form Handler. If not, see <http://www.gnu.org/licenses/>.
import nbxmpp
from nbxmpp.modules.dataforms import extend_form
from gi.repository import Gtk
from gajim.common import app
from gajim.common.structs import OutgoingMessage
from gajim.gui.dataform import DataFormWidget
from gajim.plugins.plugins_i18n import _
from form_handler.gtk.util import find_control
class FormDialog(Gtk.ApplicationWindow):
def __init__(self, data):
transient = app.app.get_active_window()
Gtk.ApplicationWindow.__init__(self, title=_('Data Form'))
self.set_transient_for(transient)
self.set_default_size(600, 400)
self._account = data['account']
self._jid = data['jid']
self._form_widget = DataFormWidget(
extend_form(node=nbxmpp.Node(node=data['form'])))
box = Gtk.Box(orientation='vertical', spacing=12)
box.add(self._form_widget)
button = Gtk.Button(label=data['submit-text'])
button.connect('clicked', self._on_send_clicked)
button.set_halign(Gtk.Align.END)
box.add(button)
self.add(box)
self.show_all()
def _on_send_clicked(self, _button):
form = self._form_widget.get_submit_form()
contact = app.contacts.get_contact(self._account, self._jid)
if contact is None:
return
message = OutgoingMessage(account=self._account,
contact=contact,
message=_('Form sent'),
type_='chat',
nodes=[form])
message.is_loggable = False
app.connections[self._account].send_message(message)
control = find_control(self._account, self._jid)
if control is None:
return
control.add_status_message(_('Form has successfully been sent'))
self.destroy()
|