[form_handler] Remove Plugin
Not compatible with 1.4 anymore
This commit is contained in:
@@ -1 +0,0 @@
|
||||
from form_handler.plugin import FormHandlerPlugin
|
||||
@@ -1,72 +0,0 @@
|
||||
# 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 _
|
||||
|
||||
|
||||
class FormDialog(Gtk.ApplicationWindow):
|
||||
def __init__(self, data):
|
||||
Gtk.ApplicationWindow.__init__(self, title=_('Data Form'))
|
||||
self.set_transient_for(app.window)
|
||||
self.set_default_size(600, 400)
|
||||
|
||||
self._account = data['account']
|
||||
self._client = app.get_client(self._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 = self._client.get_module('Contacts').get_contact(self._jid)
|
||||
|
||||
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 = app.window.get_control(self._account, self._jid)
|
||||
if control is None:
|
||||
return
|
||||
control.add_info_message(_('Form has successfully been sent'))
|
||||
self.destroy()
|
||||
@@ -1,23 +0,0 @@
|
||||
# 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/>.
|
||||
|
||||
from gi.repository import Gtk
|
||||
|
||||
|
||||
def get_button(label, data, callback):
|
||||
button = Gtk.Button(label=label)
|
||||
button.connect('clicked', callback, data)
|
||||
return button
|
||||
@@ -1,97 +0,0 @@
|
||||
# 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 logging
|
||||
|
||||
from nbxmpp.modules.dataforms import extend_form
|
||||
from nbxmpp.namespaces import Namespace
|
||||
|
||||
from gajim.common import ged
|
||||
|
||||
from gajim.plugins import GajimPlugin
|
||||
from gajim.plugins.plugins_i18n import _
|
||||
|
||||
from form_handler.gtk.util import get_button
|
||||
from form_handler.gtk.form import FormDialog
|
||||
|
||||
log = logging.getLogger('gajim.p.form_handler')
|
||||
|
||||
|
||||
class FormHandlerPlugin(GajimPlugin):
|
||||
def init(self):
|
||||
self.description = _('Lets the user display and answer forms attached '
|
||||
'to messages.')
|
||||
self.config_dialog = None
|
||||
|
||||
self.events_handlers = {
|
||||
'message-received': (ged.CORE, self._on_message_received),
|
||||
}
|
||||
|
||||
self.gui_extension_points = {
|
||||
'print_real_text': (self._print_text, None),
|
||||
}
|
||||
|
||||
def _on_message_received(self, event):
|
||||
form = event.stanza.getTag('x', namespace=Namespace.DATA)
|
||||
if form is None:
|
||||
return
|
||||
|
||||
if form.getAttr('type') != 'form':
|
||||
return
|
||||
|
||||
data = self._parse_form(form)
|
||||
|
||||
data['form'] = str(form)
|
||||
data['jid'] = event.jid
|
||||
|
||||
event.additional_data['form_handler'] = data
|
||||
|
||||
@staticmethod
|
||||
def _parse_form(form):
|
||||
dataform = extend_form(node=form)
|
||||
result = {}
|
||||
try:
|
||||
result['submit-text'] = dataform['submit-button-text'].value
|
||||
except KeyError:
|
||||
result['submit-text'] = _('Submit')
|
||||
|
||||
try:
|
||||
result['open-text'] = dataform['open-button-text'].value
|
||||
except KeyError:
|
||||
result['open-text'] = _('Open')
|
||||
|
||||
return result
|
||||
|
||||
def _print_text(self, tv, _real_text, _text_tags, _graphics,
|
||||
iter_, additional_data):
|
||||
if 'form_handler' not in additional_data:
|
||||
return
|
||||
|
||||
data = additional_data['form_handler']
|
||||
data['account'] = tv.account
|
||||
|
||||
button = get_button(data['open-text'], data, self._show_form)
|
||||
|
||||
buffer_ = tv.tv.get_buffer()
|
||||
anchor = buffer_.create_child_anchor(iter_)
|
||||
anchor.plaintext = ''
|
||||
|
||||
button.show_all()
|
||||
tv.tv.add_child_at_anchor(button, anchor)
|
||||
|
||||
@staticmethod
|
||||
def _show_form(_button, data):
|
||||
FormDialog(data)
|
||||
Reference in New Issue
Block a user