Refator DataFormDialog
This commit is contained in:
parent
731aaab633
commit
b2b249c60b
|
@ -38,8 +38,6 @@ from gi.repository import Gtk
|
|||
from gi.repository import Gdk
|
||||
from gi.repository import GLib
|
||||
|
||||
from gajim import dataforms_widget
|
||||
|
||||
from gajim.common import ged
|
||||
from gajim.common.i18n import _
|
||||
from gajim.common.const import ACTIVITIES
|
||||
|
@ -48,7 +46,6 @@ from gajim.common.const import MOODS
|
|||
from gajim.common import app
|
||||
from gajim.common import helpers
|
||||
from gajim.common import i18n
|
||||
from gajim.common.modules import dataforms
|
||||
from gajim.common.exceptions import GajimGeneralException
|
||||
|
||||
from gajim.gtk.dialogs import ErrorDialog
|
||||
|
@ -57,7 +54,6 @@ from gajim.gtk.dialogs import InputDialog
|
|||
from gajim.gtk.dialogs import InformationDialog
|
||||
from gajim.gtk.dialogs import AspellDictError
|
||||
from gajim.gtk.util import get_icon_name
|
||||
from gajim.gtk.util import resize_window
|
||||
from gajim.gtk.util import get_builder
|
||||
from gajim.gtk.util import get_activity_icon_name
|
||||
|
||||
|
@ -1355,30 +1351,6 @@ class Dialog(Gtk.Dialog):
|
|||
self.destroy()
|
||||
|
||||
|
||||
class DataFormWindow(Dialog):
|
||||
def __init__(self, form, on_response_ok):
|
||||
self.df_response_ok = on_response_ok
|
||||
Dialog.__init__(self, None, 'test', [(Gtk.STOCK_CANCEL,
|
||||
Gtk.ResponseType.CANCEL), (Gtk.STOCK_OK, Gtk.ResponseType.OK)],
|
||||
on_response_ok=self.on_ok)
|
||||
self.set_resizable(True)
|
||||
resize_window(self, 600, 400)
|
||||
self.dataform_widget = dataforms_widget.DataFormWidget()
|
||||
self.dataform = dataforms.extend_form(node=form)
|
||||
self.dataform_widget.set_sensitive(True)
|
||||
self.dataform_widget.data_form = self.dataform
|
||||
self.dataform_widget.show_all()
|
||||
self.get_content_area().pack_start(self.dataform_widget, True, True, 0)
|
||||
|
||||
def on_ok(self):
|
||||
form = self.dataform_widget.data_form
|
||||
if isinstance(self.df_response_ok, tuple):
|
||||
self.df_response_ok[0](form, *self.df_response_ok[1:])
|
||||
else:
|
||||
self.df_response_ok(form)
|
||||
self.destroy()
|
||||
|
||||
|
||||
class ResourceConflictDialog(TimeoutDialog, InputDialog):
|
||||
def __init__(self, title, text, resource, ok_handler):
|
||||
TimeoutDialog.__init__(self, 15)
|
||||
|
|
|
@ -21,6 +21,7 @@ from gajim.gtkgui_helpers import scale_pixbuf_from_data
|
|||
|
||||
from gajim.common import app
|
||||
from gajim.common.i18n import _
|
||||
from gajim.common.modules.dataforms import extend_form
|
||||
|
||||
from gajim.gtk.util import MultiLineLabel
|
||||
|
||||
|
@ -551,3 +552,33 @@ class ImageMediaField():
|
|||
|
||||
def add(self, form_grid, row_number):
|
||||
form_grid.attach(self._image, 1, row_number, 1, 1)
|
||||
|
||||
|
||||
class DataFormDialog(Gtk.Dialog):
|
||||
def __init__(self, title, transient_for, form, node, submit_callback):
|
||||
Gtk.Dialog.__init__(self,
|
||||
title=title,
|
||||
transient_for=transient_for,
|
||||
modal=False)
|
||||
self.set_default_size(600, 500)
|
||||
|
||||
self._submit_callback = submit_callback
|
||||
self._form = DataFormWidget(extend_form(node=form))
|
||||
self._node = node
|
||||
|
||||
self.get_content_area().get_style_context().add_class('dialog-margin')
|
||||
self.get_content_area().add(self._form)
|
||||
|
||||
self.add_button(_('Cancel'), Gtk.ResponseType.CANCEL)
|
||||
|
||||
submit_button = self.add_button(_('Submit'), Gtk.ResponseType.OK)
|
||||
submit_button.get_style_context().add_class('suggested-action')
|
||||
self.set_default_response(Gtk.ResponseType.OK)
|
||||
|
||||
self.connect('response', self._on_response)
|
||||
self.show_all()
|
||||
|
||||
def _on_response(self, _dialog, response):
|
||||
if response == Gtk.ResponseType.OK:
|
||||
self._submit_callback(self._form.get_submit_form(), self._node)
|
||||
self.destroy()
|
||||
|
|
|
@ -20,6 +20,7 @@ from gajim.common.i18n import _
|
|||
|
||||
from gajim.gtk.dialogs import ErrorDialog
|
||||
from gajim.gtk.dialogs import WarningDialog
|
||||
from gajim.gtk.dataform import DataFormDialog
|
||||
from gajim.gtk.util import get_builder
|
||||
|
||||
|
||||
|
@ -122,14 +123,14 @@ class ManagePEPServicesWindow:
|
|||
con = app.connections[self.account]
|
||||
con.get_module('PubSub').request_pb_configuration(our_jid, node)
|
||||
|
||||
def _on_config_submit(self, form, node):
|
||||
our_jid = app.get_jid_from_account(self.account)
|
||||
con = app.connections[self.account]
|
||||
con.get_module('PubSub').send_pb_configure(our_jid, node, form)
|
||||
|
||||
def _nec_pep_config_received(self, obj):
|
||||
def on_ok(form, node):
|
||||
form.type_ = 'submit'
|
||||
our_jid = app.get_jid_from_account(self.account)
|
||||
con = app.connections[self.account]
|
||||
con.get_module('PubSub').send_pb_configure(our_jid, node, form)
|
||||
from gajim.dialogs import DataFormWindow
|
||||
window = DataFormWindow(obj.form, (on_ok, obj.node))
|
||||
title = _('Configure %s') % obj.node
|
||||
window.set_title(title)
|
||||
window.show_all()
|
||||
DataFormDialog(_('Configure %s') % obj.node,
|
||||
self.window,
|
||||
obj.form,
|
||||
obj.node,
|
||||
self._on_config_submit)
|
||||
|
|
Loading…
Reference in New Issue