Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
9f4adbdd
by Philipp Hörist at 2019-04-19T17:36:43Z
-
8bfe90c5
by Philipp Hörist at 2019-04-19T17:36:43Z
8 changed files:
- gajim/common/modules/register.py
- − gajim/config.py
- gajim/gtk/account_wizard.py
- gajim/gtk/dataform.py
- gajim/gtk/discovery_search.py
- gajim/gtk/service_registration.py
- gajim/roster_window.py
- + test/gtk/fake_dataform.py
Changes:
| ... | ... | @@ -134,9 +134,14 @@ class Register(BaseModule): |
| 134 | 134 |
is_form = form is not None
|
| 135 | 135 |
if not is_form:
|
| 136 | 136 |
form = {}
|
| 137 |
+ oob = stanza.getQuery().getTag('x', namespace=nbxmpp.NS_X_OOB)
|
|
| 138 |
+ if oob is not None:
|
|
| 139 |
+ form['redirect-url'] = oob.getTagData('url')
|
|
| 137 | 140 |
for field in stanza.getQueryPayload():
|
| 138 | 141 |
if not isinstance(field, nbxmpp.Node):
|
| 139 | 142 |
continue
|
| 143 |
+ if field.getName() == 'x':
|
|
| 144 |
+ continue
|
|
| 140 | 145 |
form[field.getName()] = field.getData()
|
| 141 | 146 |
|
| 142 | 147 |
return form, is_form
|
| 1 |
-# Copyright (C) 2003-2005 Vincent Hanquez <tab AT snarc.org>
|
|
| 2 |
-# Copyright (C) 2003-2014 Yann Leboulanger <asterix AT lagaule.org>
|
|
| 3 |
-# Copyright (C) 2005 Alex Podaras <bigpod AT gmail.com>
|
|
| 4 |
-# Stéphan Kochen <stephan AT kochen.nl>
|
|
| 5 |
-# Copyright (C) 2005-2006 Dimitur Kirov <dkirov AT gmail.com>
|
|
| 6 |
-# Nikos Kouremenos <kourem AT gmail.com>
|
|
| 7 |
-# Copyright (C) 2006 Junglecow J <junglecow AT gmail.com>
|
|
| 8 |
-# Copyright (C) 2006-2007 Travis Shirk <travis AT pobox.com>
|
|
| 9 |
-# Stefan Bethge <stefan AT lanpartei.de>
|
|
| 10 |
-# Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
|
|
| 11 |
-# Copyright (C) 2007 James Newton <redshodan AT gmail.com>
|
|
| 12 |
-# Julien Pivotto <roidelapluie AT gmail.com>
|
|
| 13 |
-# Copyright (C) 2007-2008 Stephan Erb <steve-e AT h3c.de>
|
|
| 14 |
-# Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
|
|
| 15 |
-#
|
|
| 16 |
-# This file is part of Gajim.
|
|
| 17 |
-#
|
|
| 18 |
-# Gajim is free software; you can redistribute it and/or modify
|
|
| 19 |
-# it under the terms of the GNU General Public License as published
|
|
| 20 |
-# by the Free Software Foundation; version 3 only.
|
|
| 21 |
-#
|
|
| 22 |
-# Gajim is distributed in the hope that it will be useful,
|
|
| 23 |
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 24 |
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 25 |
-# GNU General Public License for more details.
|
|
| 26 |
-#
|
|
| 27 |
-# You should have received a copy of the GNU General Public License
|
|
| 28 |
-# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
| 29 |
- |
|
| 30 |
-from gi.repository import Gtk
|
|
| 31 |
-from gi.repository import GObject
|
|
| 32 |
- |
|
| 33 |
- |
|
| 34 |
-class FakeDataForm(Gtk.Table):
|
|
| 35 |
- """
|
|
| 36 |
- Class for forms that are in XML format <entry1>value1</entry1> infos in a
|
|
| 37 |
- table {entry1: value1}
|
|
| 38 |
- """
|
|
| 39 |
- |
|
| 40 |
- def __init__(self, infos, selectable=False):
|
|
| 41 |
- GObject.GObject.__init__(self)
|
|
| 42 |
- self.infos = infos
|
|
| 43 |
- self.selectable = selectable
|
|
| 44 |
- self.entries = {}
|
|
| 45 |
- self._draw_table()
|
|
| 46 |
- |
|
| 47 |
- def _draw_table(self):
|
|
| 48 |
- """
|
|
| 49 |
- Draw the table
|
|
| 50 |
- """
|
|
| 51 |
- nbrow = 0
|
|
| 52 |
- if 'instructions' in self.infos:
|
|
| 53 |
- nbrow = 1
|
|
| 54 |
- self.resize(rows=nbrow, columns=2)
|
|
| 55 |
- label = Gtk.Label(label=self.infos['instructions'])
|
|
| 56 |
- if self.selectable:
|
|
| 57 |
- label.set_selectable(True)
|
|
| 58 |
- self.attach(label, 0, 2, 0, 1, 0, 0, 0, 0)
|
|
| 59 |
- for name in self.infos.keys():
|
|
| 60 |
- if name in ('key', 'instructions', 'x', 'registered'):
|
|
| 61 |
- continue
|
|
| 62 |
- if not name:
|
|
| 63 |
- continue
|
|
| 64 |
- |
|
| 65 |
- nbrow = nbrow + 1
|
|
| 66 |
- self.resize(rows=nbrow, columns=2)
|
|
| 67 |
- label = Gtk.Label(label=name.capitalize() + ':')
|
|
| 68 |
- self.attach(label, 0, 1, nbrow - 1, nbrow, 0, 0, 0, 0)
|
|
| 69 |
- entry = Gtk.Entry()
|
|
| 70 |
- entry.set_activates_default(True)
|
|
| 71 |
- if self.infos[name]:
|
|
| 72 |
- entry.set_text(self.infos[name])
|
|
| 73 |
- if name == 'password':
|
|
| 74 |
- entry.set_visibility(False)
|
|
| 75 |
- self.attach(entry, 1, 2, nbrow - 1, nbrow, 0, 0, 0, 0)
|
|
| 76 |
- self.entries[name] = entry
|
|
| 77 |
- if nbrow == 1:
|
|
| 78 |
- entry.grab_focus()
|
|
| 79 |
- |
|
| 80 |
- def get_infos(self):
|
|
| 81 |
- for name in self.entries:
|
|
| 82 |
- self.infos[name] = self.entries[name].get_text()
|
|
| 83 |
- return self.infos
|
| ... | ... | @@ -29,11 +29,10 @@ from gajim.common.modules import dataforms |
| 29 | 29 |
from gajim import dataforms_widget
|
| 30 | 30 |
from gajim import gui_menu_builder
|
| 31 | 31 |
|
| 32 |
-from gajim.config import FakeDataForm
|
|
| 33 |
- |
|
| 34 | 32 |
from gajim.gtk.util import get_builder
|
| 35 | 33 |
from gajim.gtk.dialogs import ErrorDialog
|
| 36 | 34 |
from gajim.gtk.proxies import ManageProxies
|
| 35 |
+from gajim.gtk.dataform import FakeDataFormWidget
|
|
| 37 | 36 |
|
| 38 | 37 |
|
| 39 | 38 |
class AccountCreationWizard:
|
| ... | ... | @@ -325,7 +324,7 @@ class AccountCreationWizard: |
| 325 | 324 |
if self.is_form:
|
| 326 | 325 |
form = self.data_form_widget.data_form
|
| 327 | 326 |
else:
|
| 328 |
- form = self.data_form_widget.get_infos()
|
|
| 327 |
+ form = self.data_form_widget.get_submit_form()
|
|
| 329 | 328 |
app.connections[self.account].send_new_account_infos(
|
| 330 | 329 |
form, self.is_form)
|
| 331 | 330 |
self.xml.get_object('form_vbox').remove(self.data_form_widget)
|
| ... | ... | @@ -381,7 +380,7 @@ class AccountCreationWizard: |
| 381 | 380 |
self.data_form_widget.set_data_form(dataform)
|
| 382 | 381 |
empty_config = False
|
| 383 | 382 |
else:
|
| 384 |
- self.data_form_widget = FakeDataForm(obj.config, selectable=True)
|
|
| 383 |
+ self.data_form_widget = FakeDataFormWidget(obj.config)
|
|
| 385 | 384 |
for field in obj.config:
|
| 386 | 385 |
if field in ('key', 'instructions', 'x', 'registered'):
|
| 387 | 386 |
continue
|
| ... | ... | @@ -21,6 +21,7 @@ from gajim.gtkgui_helpers import scale_pixbuf_from_data |
| 21 | 21 |
|
| 22 | 22 |
from gajim.common import app
|
| 23 | 23 |
from gajim.common.i18n import _
|
| 24 |
+from gajim.common.helpers import launch_browser_mailer
|
|
| 24 | 25 |
from gajim.common.modules.dataforms import extend_form
|
| 25 | 26 |
|
| 26 | 27 |
from gajim.gtk.util import MultiLineLabel
|
| ... | ... | @@ -554,6 +555,76 @@ class ImageMediaField(): |
| 554 | 555 |
form_grid.attach(self._image, 1, row_number, 1, 1)
|
| 555 | 556 |
|
| 556 | 557 |
|
| 558 |
+class FakeDataFormWidget(Gtk.ScrolledWindow):
|
|
| 559 |
+ def __init__(self, fields):
|
|
| 560 |
+ Gtk.ScrolledWindow.__init__(self)
|
|
| 561 |
+ self.set_hexpand(True)
|
|
| 562 |
+ self.set_vexpand(True)
|
|
| 563 |
+ self.set_overlay_scrolling(False)
|
|
| 564 |
+ self.get_style_context().add_class('data-form-widget')
|
|
| 565 |
+ |
|
| 566 |
+ self._grid = Gtk.Grid()
|
|
| 567 |
+ self._grid.set_column_spacing(12)
|
|
| 568 |
+ self._grid.set_row_spacing(12)
|
|
| 569 |
+ self._grid.set_halign(Gtk.Align.CENTER)
|
|
| 570 |
+ |
|
| 571 |
+ self._fields = fields
|
|
| 572 |
+ self._entries = {}
|
|
| 573 |
+ self._row_count = 0
|
|
| 574 |
+ |
|
| 575 |
+ instructions = fields.pop('instructions', None)
|
|
| 576 |
+ if instructions is not None:
|
|
| 577 |
+ label = Gtk.Label(label=instructions)
|
|
| 578 |
+ label.set_justify(Gtk.Justification.CENTER)
|
|
| 579 |
+ label.set_max_width_chars(40)
|
|
| 580 |
+ label.set_line_wrap(True)
|
|
| 581 |
+ label.set_line_wrap_mode(Pango.WrapMode.WORD)
|
|
| 582 |
+ self._grid.attach(label, 0, self._row_count, 2, 1)
|
|
| 583 |
+ self._row_count += 1
|
|
| 584 |
+ |
|
| 585 |
+ redirect_url = fields.pop('redirect-url', None)
|
|
| 586 |
+ if not fields and redirect_url is not None:
|
|
| 587 |
+ # Server wants to redirect registration
|
|
| 588 |
+ button = Gtk.Button(label='Register')
|
|
| 589 |
+ button.set_halign(Gtk.Align.CENTER)
|
|
| 590 |
+ button.get_style_context().add_class('suggested-action')
|
|
| 591 |
+ button.connect('clicked',
|
|
| 592 |
+ lambda *args: launch_browser_mailer('url',
|
|
| 593 |
+ redirect_url))
|
|
| 594 |
+ self._grid.attach(button, 0, self._row_count, 2, 1)
|
|
| 595 |
+ else:
|
|
| 596 |
+ self._add_fields()
|
|
| 597 |
+ self.add(self._grid)
|
|
| 598 |
+ self.show_all()
|
|
| 599 |
+ |
|
| 600 |
+ def _add_fields(self):
|
|
| 601 |
+ for name, value in self._fields.items():
|
|
| 602 |
+ if name in ('key', 'x', 'registered'):
|
|
| 603 |
+ continue
|
|
| 604 |
+ |
|
| 605 |
+ label = Gtk.Label(label=name.capitalize())
|
|
| 606 |
+ label.set_xalign(1)
|
|
| 607 |
+ self._grid.attach(label, 0, self._row_count, 1, 1)
|
|
| 608 |
+ self._row_count += 1
|
|
| 609 |
+ |
|
| 610 |
+ entry = Gtk.Entry()
|
|
| 611 |
+ entry.set_text(value)
|
|
| 612 |
+ if name == 'password':
|
|
| 613 |
+ entry.set_input_purpose(Gtk.InputPurpose.PASSWORD)
|
|
| 614 |
+ entry.set_visibility(False)
|
|
| 615 |
+ self._entries[name] = entry
|
|
| 616 |
+ |
|
| 617 |
+ self._grid.attach_next_to(entry, label,
|
|
| 618 |
+ Gtk.PositionType.RIGHT, 1, 1)
|
|
| 619 |
+ |
|
| 620 |
+ def get_submit_form(self):
|
|
| 621 |
+ fields = {}
|
|
| 622 |
+ for name, entry in self._entries.items():
|
|
| 623 |
+ fields[name] = entry.get_text()
|
|
| 624 |
+ return fields
|
|
| 625 |
+ |
|
| 626 |
+ |
|
| 627 |
+ |
|
| 557 | 628 |
class DataFormDialog(Gtk.Dialog):
|
| 558 | 629 |
def __init__(self, title, transient_for, form, node, submit_callback):
|
| 559 | 630 |
Gtk.Dialog.__init__(self,
|
| ... | ... | @@ -25,11 +25,11 @@ from gajim.common.modules import dataforms |
| 25 | 25 |
from gajim.common.i18n import _
|
| 26 | 26 |
|
| 27 | 27 |
from gajim import vcard
|
| 28 |
-from gajim import config
|
|
| 29 | 28 |
from gajim import dataforms_widget
|
| 30 | 29 |
|
| 31 | 30 |
from gajim.gtk.util import get_builder
|
| 32 | 31 |
from gajim.gtk.add_contact import AddNewContactWindow
|
| 32 |
+from gajim.gtk.dataform import FakeDataFormWidget
|
|
| 33 | 33 |
|
| 34 | 34 |
|
| 35 | 35 |
class SearchWindow:
|
| ... | ... | @@ -92,7 +92,7 @@ class SearchWindow: |
| 92 | 92 |
con.get_module('Search').send_search_form(
|
| 93 | 93 |
self.jid, self.data_form_widget.data_form.get_purged(), True)
|
| 94 | 94 |
else:
|
| 95 |
- infos = self.data_form_widget.get_infos()
|
|
| 95 |
+ infos = self.data_form_widget.get_submit_form()
|
|
| 96 | 96 |
if 'instructions' in infos:
|
| 97 | 97 |
del infos['instructions']
|
| 98 | 98 |
con.get_module('Search').send_search_form(self.jid, infos, False)
|
| ... | ... | @@ -146,7 +146,7 @@ class SearchWindow: |
| 146 | 146 |
'%s - Search - Gajim' % self.data_form_widget.title)
|
| 147 | 147 |
else:
|
| 148 | 148 |
self.is_form = False
|
| 149 |
- self.data_form_widget = config.FakeDataForm(obj.data)
|
|
| 149 |
+ self.data_form_widget = FakeDataFormWidget(obj.data)
|
|
| 150 | 150 |
|
| 151 | 151 |
self.data_form_widget.show_all()
|
| 152 | 152 |
self._ui.search_vbox.pack_start(self.data_form_widget, True, True, 0)
|
| ... | ... | @@ -22,6 +22,7 @@ from gajim.common.modules import dataforms |
| 22 | 22 |
from gajim.common.i18n import _
|
| 23 | 23 |
|
| 24 | 24 |
from gajim.gtk.dataform import DataFormWidget
|
| 25 |
+from gajim.gtk.dataform import FakeDataFormWidget
|
|
| 25 | 26 |
|
| 26 | 27 |
log = logging.getLogger('gajim.gtk.registration')
|
| 27 | 28 |
|
| ... | ... | @@ -77,8 +78,7 @@ class ServiceRegistration(Gtk.Assistant): |
| 77 | 78 |
|
| 78 | 79 |
def _build_dataform(self, form, is_form):
|
| 79 | 80 |
if not is_form:
|
| 80 |
- from gajim import config
|
|
| 81 |
- return config.FakeDataForm(form)
|
|
| 81 |
+ return FakeDataFormWidget(form)
|
|
| 82 | 82 |
|
| 83 | 83 |
dataform = dataforms.extend_form(node=form)
|
| 84 | 84 |
|
| ... | ... | @@ -122,15 +122,7 @@ class ServiceRegistration(Gtk.Assistant): |
| 122 | 122 |
|
| 123 | 123 |
def _register(self):
|
| 124 | 124 |
log.info('Show Sending page')
|
| 125 |
- if self._is_form:
|
|
| 126 |
- form = self._data_form_widget.get_submit_form()
|
|
| 127 |
- else:
|
|
| 128 |
- form = self._data_form_widget.get_infos()
|
|
| 129 |
- if 'instructions' in form:
|
|
| 130 |
- del form['instructions']
|
|
| 131 |
- if 'registered' in form:
|
|
| 132 |
- del form['registered']
|
|
| 133 |
- |
|
| 125 |
+ form = self._data_form_widget.get_submit_form()
|
|
| 134 | 126 |
self._con.get_module('Register').register_agent(
|
| 135 | 127 |
self._agent,
|
| 136 | 128 |
form,
|
| ... | ... | @@ -4823,7 +4823,7 @@ class RosterWindow: |
| 4823 | 4823 |
pep_submenu = Gtk.Menu()
|
| 4824 | 4824 |
pep_menuitem.set_submenu(pep_submenu)
|
| 4825 | 4825 |
|
| 4826 |
- item = Gtk.CheckMenuItem(_('Publish Tune'))
|
|
| 4826 |
+ item = Gtk.CheckMenuItem(label=_('Publish Tune'))
|
|
| 4827 | 4827 |
pep_submenu.append(item)
|
| 4828 | 4828 |
if sys.platform in ('win32', 'darwin'):
|
| 4829 | 4829 |
item.set_sensitive(False)
|
| ... | ... | @@ -4834,7 +4834,7 @@ class RosterWindow: |
| 4834 | 4834 |
item.connect('toggled', self.on_publish_tune_toggled,
|
| 4835 | 4835 |
account)
|
| 4836 | 4836 |
|
| 4837 |
- item = Gtk.CheckMenuItem(_('Publish Location'))
|
|
| 4837 |
+ item = Gtk.CheckMenuItem(label=_('Publish Location'))
|
|
| 4838 | 4838 |
pep_submenu.append(item)
|
| 4839 | 4839 |
if not app.is_installed('GEOCLUE'):
|
| 4840 | 4840 |
item.set_sensitive(False)
|
| 1 |
+from gi.repository import Gtk
|
|
| 2 |
+ |
|
| 3 |
+from gajim.gtk.dataform import FakeDataFormWidget
|
|
| 4 |
+from gajim.common.const import CSSPriority
|
|
| 5 |
+ |
|
| 6 |
+from test.gtk import util
|
|
| 7 |
+util.load_style('gajim.css', CSSPriority.APPLICATION)
|
|
| 8 |
+ |
|
| 9 |
+ |
|
| 10 |
+fake_form = {
|
|
| 11 |
+ 'instructions': 'This is the a long long long long long long test instruction',
|
|
| 12 |
+ 'username': '',
|
|
| 13 |
+ 'nick': '',
|
|
| 14 |
+ 'password': '',
|
|
| 15 |
+ 'name': '',
|
|
| 16 |
+ 'first': '',
|
|
| 17 |
+ 'last': '',
|
|
| 18 |
+ 'email': '',
|
|
| 19 |
+ 'address': '',
|
|
| 20 |
+ 'city': '',
|
|
| 21 |
+ 'state': '',
|
|
| 22 |
+ 'zip': '',
|
|
| 23 |
+ 'phone': '',
|
|
| 24 |
+ 'url': '',
|
|
| 25 |
+ 'date': '',
|
|
| 26 |
+ 'misc': '',
|
|
| 27 |
+ 'text': '',
|
|
| 28 |
+ 'key': '',
|
|
| 29 |
+}
|
|
| 30 |
+ |
|
| 31 |
+fake_form2 = {
|
|
| 32 |
+ 'instructions': 'To register, visit https://jabber.at/account/register/',
|
|
| 33 |
+ 'redirect-url': 'https://jabber.at/account/register/'
|
|
| 34 |
+}
|
|
| 35 |
+ |
|
| 36 |
+class DataFormWindow(Gtk.Window):
|
|
| 37 |
+ def __init__(self):
|
|
| 38 |
+ Gtk.Window.__init__(self, title="Data Form Test")
|
|
| 39 |
+ self.set_default_size(600, 600)
|
|
| 40 |
+ self._widget = FakeDataFormWidget(fake_form2)
|
|
| 41 |
+ self.add(self._widget)
|
|
| 42 |
+ self.show()
|
|
| 43 |
+ |
|
| 44 |
+win = DataFormWindow()
|
|
| 45 |
+win.connect("destroy", Gtk.main_quit)
|
|
| 46 |
+win.show_all()
|
|
| 47 |
+Gtk.main()
|