2018-08-04 19:47:25 +02:00
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
import logging
|
|
|
|
from enum import IntEnum
|
|
|
|
|
|
|
|
from gi.repository import Gtk
|
|
|
|
|
|
|
|
from gajim.common import app
|
|
|
|
from gajim.common.modules import dataforms
|
2018-09-13 23:56:12 +02:00
|
|
|
from gajim.common.i18n import _
|
2018-08-05 20:34:02 +02:00
|
|
|
from gajim.gtk.dataform import DataFormWidget
|
2018-08-04 19:47:25 +02:00
|
|
|
|
|
|
|
log = logging.getLogger('gajim.gtk.registration')
|
|
|
|
|
|
|
|
|
|
|
|
class Page(IntEnum):
|
|
|
|
REQUEST = 0
|
|
|
|
FORM = 1
|
|
|
|
SENDING = 2
|
|
|
|
SUCCESS = 3
|
|
|
|
ERROR = 4
|
|
|
|
|
|
|
|
|
|
|
|
class ServiceRegistration(Gtk.Assistant):
|
|
|
|
def __init__(self, account, agent):
|
|
|
|
Gtk.Assistant.__init__(self)
|
|
|
|
|
|
|
|
self._con = app.connections[account]
|
|
|
|
self._agent = agent
|
|
|
|
self._account = account
|
|
|
|
self._data_form_widget = None
|
|
|
|
self._is_form = None
|
|
|
|
|
|
|
|
self.set_application(app.app)
|
|
|
|
self.set_resizable(True)
|
|
|
|
self.set_position(Gtk.WindowPosition.CENTER)
|
|
|
|
|
2018-08-05 20:34:02 +02:00
|
|
|
self.set_default_size(600, 400)
|
2018-08-04 19:47:25 +02:00
|
|
|
self.get_style_context().add_class('dialog-margin')
|
|
|
|
|
2018-08-05 20:34:02 +02:00
|
|
|
self._add_page(RequestPage())
|
|
|
|
self._add_page(FormPage())
|
|
|
|
self._add_page(SendingPage())
|
|
|
|
self._add_page(SuccessfulPage())
|
|
|
|
self._add_page(ErrorPage())
|
2018-08-04 19:47:25 +02:00
|
|
|
|
|
|
|
self.connect('prepare', self._on_page_change)
|
|
|
|
self.connect('cancel', self._on_cancel)
|
|
|
|
self.connect('close', self._on_cancel)
|
|
|
|
|
2018-08-05 20:34:02 +02:00
|
|
|
self._remove_sidebar()
|
2018-08-04 19:47:25 +02:00
|
|
|
self.show_all()
|
|
|
|
|
2018-08-05 20:34:02 +02:00
|
|
|
def _add_page(self, page):
|
|
|
|
self.append_page(page)
|
|
|
|
self.set_page_type(page, page.type_)
|
|
|
|
self.set_page_title(page, page.title)
|
|
|
|
self.set_page_complete(page, page.complete)
|
|
|
|
|
|
|
|
def _remove_sidebar(self):
|
|
|
|
main_box = self.get_children()[0]
|
|
|
|
sidebar = main_box.get_children()[0]
|
|
|
|
main_box.remove(sidebar)
|
|
|
|
|
2018-08-04 19:47:25 +02:00
|
|
|
def _on_page_change(self, assistant, page):
|
|
|
|
if self.get_current_page() == Page.REQUEST:
|
|
|
|
self._con.get_module('Register').get_register_form(
|
|
|
|
self._agent, self._on_get_success, self._on_error)
|
|
|
|
elif self.get_current_page() == Page.SENDING:
|
|
|
|
self._register()
|
|
|
|
self.commit()
|
|
|
|
|
|
|
|
def _on_get_success(self, form, is_form):
|
|
|
|
log.info('Show Form page')
|
|
|
|
self._is_form = is_form
|
|
|
|
if is_form:
|
2018-09-12 00:01:54 +02:00
|
|
|
dataform = dataforms.extend_form(node=form)
|
2018-08-05 20:34:02 +02:00
|
|
|
self._data_form_widget = DataFormWidget(dataform)
|
2018-08-04 19:47:25 +02:00
|
|
|
else:
|
|
|
|
from gajim import config
|
|
|
|
self._data_form_widget = config.FakeDataForm(form)
|
|
|
|
|
|
|
|
page = self.get_nth_page(Page.FORM)
|
|
|
|
page.pack_start(self._data_form_widget, True, True, 0)
|
2018-08-05 20:34:02 +02:00
|
|
|
self._data_form_widget.show_all()
|
2018-08-04 19:47:25 +02:00
|
|
|
self.set_current_page(Page.FORM)
|
|
|
|
|
|
|
|
def _on_error(self, error_text):
|
|
|
|
log.info('Show Error page')
|
|
|
|
page = self.get_nth_page(Page.ERROR)
|
|
|
|
page.set_text(error_text)
|
|
|
|
self.set_current_page(Page.ERROR)
|
|
|
|
|
|
|
|
def _on_cancel(self, widget):
|
|
|
|
self.destroy()
|
|
|
|
|
|
|
|
def _register(self):
|
|
|
|
log.info('Show Sending page')
|
|
|
|
if self._is_form:
|
2018-08-05 20:34:02 +02:00
|
|
|
form = self._data_form_widget.get_submit_form()
|
2018-08-04 19:47:25 +02:00
|
|
|
else:
|
|
|
|
form = self._data_form_widget.get_infos()
|
|
|
|
if 'instructions' in form:
|
|
|
|
del form['instructions']
|
|
|
|
if 'registered' in form:
|
|
|
|
del form['registered']
|
|
|
|
|
|
|
|
self._con.get_module('Register').register_agent(
|
|
|
|
self._agent,
|
|
|
|
form,
|
|
|
|
self._is_form,
|
|
|
|
self._on_register_success,
|
|
|
|
self._on_error)
|
|
|
|
|
|
|
|
def _on_register_success(self):
|
|
|
|
log.info('Show Success page')
|
|
|
|
self.set_current_page(Page.SUCCESS)
|
|
|
|
|
|
|
|
|
|
|
|
class RequestPage(Gtk.Box):
|
2018-08-05 20:34:02 +02:00
|
|
|
|
|
|
|
type_ = Gtk.AssistantPageType.INTRO
|
|
|
|
title = _('Register')
|
|
|
|
complete = False
|
|
|
|
|
2018-08-04 19:47:25 +02:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__(orientation=Gtk.Orientation.VERTICAL)
|
|
|
|
self.set_spacing(18)
|
|
|
|
spinner = Gtk.Spinner()
|
|
|
|
self.pack_start(spinner, True, True, 0)
|
|
|
|
spinner.start()
|
|
|
|
|
|
|
|
|
|
|
|
class SendingPage(RequestPage):
|
2018-08-05 20:34:02 +02:00
|
|
|
|
|
|
|
type_ = Gtk.AssistantPageType.PROGRESS
|
|
|
|
title = _('Register')
|
|
|
|
complete = False
|
|
|
|
|
2018-08-04 19:47:25 +02:00
|
|
|
|
|
|
|
class FormPage(Gtk.Box):
|
2018-08-05 20:34:02 +02:00
|
|
|
|
|
|
|
type_ = Gtk.AssistantPageType.INTRO
|
|
|
|
title = _('Register')
|
|
|
|
complete = True
|
|
|
|
|
2018-08-04 19:47:25 +02:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__(orientation=Gtk.Orientation.VERTICAL)
|
|
|
|
|
|
|
|
|
|
|
|
class SuccessfulPage(Gtk.Box):
|
2018-08-05 20:34:02 +02:00
|
|
|
|
|
|
|
type_ = Gtk.AssistantPageType.SUMMARY
|
2018-08-06 20:23:53 +02:00
|
|
|
title = _('Registration successful')
|
2018-08-05 20:34:02 +02:00
|
|
|
complete = True
|
|
|
|
|
2018-08-04 19:47:25 +02:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__(orientation=Gtk.Orientation.VERTICAL)
|
|
|
|
self.set_spacing(12)
|
|
|
|
self.set_homogeneous(True)
|
|
|
|
|
|
|
|
icon = Gtk.Image.new_from_icon_name('object-select-symbolic',
|
|
|
|
Gtk.IconSize.DIALOG)
|
|
|
|
icon.get_style_context().add_class('success-color')
|
|
|
|
icon.set_valign(Gtk.Align.END)
|
|
|
|
label = Gtk.Label(label=_('Registration successful'))
|
|
|
|
label.get_style_context().add_class('bold16')
|
|
|
|
label.set_valign(Gtk.Align.START)
|
|
|
|
|
|
|
|
self.add(icon)
|
|
|
|
self.add(label)
|
|
|
|
|
|
|
|
|
|
|
|
class ErrorPage(Gtk.Box):
|
2018-08-05 20:34:02 +02:00
|
|
|
|
|
|
|
type_ = Gtk.AssistantPageType.SUMMARY
|
|
|
|
title = _('Registration failed')
|
|
|
|
complete = True
|
|
|
|
|
2018-08-04 19:47:25 +02:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__(orientation=Gtk.Orientation.VERTICAL)
|
|
|
|
self.set_spacing(12)
|
|
|
|
self.set_homogeneous(True)
|
|
|
|
|
|
|
|
icon = Gtk.Image.new_from_icon_name('dialog-error-symbolic',
|
|
|
|
Gtk.IconSize.DIALOG)
|
|
|
|
icon.get_style_context().add_class('error-color')
|
|
|
|
icon.set_valign(Gtk.Align.END)
|
|
|
|
self._label = Gtk.Label()
|
|
|
|
self._label.get_style_context().add_class('bold16')
|
|
|
|
self._label.set_valign(Gtk.Align.START)
|
|
|
|
|
|
|
|
self.add(icon)
|
|
|
|
self.add(self._label)
|
|
|
|
|
|
|
|
def set_text(self, text):
|
|
|
|
self._label.set_text(text)
|