gui: hook up the auth signal with a re-register workflow

When we get an authorization error, show a revealer to re-register the device.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2019-08-22 12:24:26 +10:00 committed by Benjamin Tissoires
parent f21af42131
commit 02ca3a7058
3 changed files with 111 additions and 12 deletions

View File

@ -120,12 +120,85 @@
</object>
</child>
<child>
<object class="GtkStack" id="stack_perspectives">
<object class="GtkOverlay">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="transition_type">crossfade</property>
<child>
<placeholder/>
<object class="GtkStack" id="stack_perspectives">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="transition_type">crossfade</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="index">-1</property>
</packing>
</child>
<child type="overlay">
<object class="GtkRevealer" id="overlay_reauth">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">start</property>
<property name="transition_type">none</property>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">start</property>
<property name="margin_left">12</property>
<property name="margin_right">4</property>
<property name="margin_start">12</property>
<property name="margin_end">4</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_right">10</property>
<property name="label" translatable="yes">Authorization error while connecting to the device </property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="notification_reauth">
<property name="label" translatable="yes">Register</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="no_show_all">True</property>
<property name="margin_right">6</property>
<property name="margin_end">6</property>
<signal name="clicked" handler="_on_reauth_clicked" swapped="no"/>
<style>
<class name="text-button"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<style>
<class name="app-notification"/>
</style>
</object>
</child>
</object>
</child>
</object>
</child>

View File

@ -156,7 +156,7 @@ class TuhiKeteDevice(_DBusObject):
'registered':
(GObject.SignalFlags.RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)),
'device-error':
(GObject.SignalFlags.RUN_FIRST, None, (GObject.TYPE_PYOBJECT, int)),
(GObject.SignalFlags.RUN_FIRST, None, (int,)),
}
def __init__(self, manager, objpath):
@ -248,7 +248,7 @@ class TuhiKeteDevice(_DBusObject):
logger.error(f'{self}: wrong device, please re-register.')
elif err < 0:
logger.error(f'{self}: an error occured: {os.strerror(-err)}')
self.emit('device-error', self, err)
self.emit('device-error', err)
self.notify('listening')
elif signal == 'SyncState':
self._sync_state = parameters[0]

View File

@ -126,6 +126,7 @@ class MainWindow(Gtk.ApplicationWindow):
spinner_sync = Gtk.Template.Child()
image_battery = Gtk.Template.Child()
image_missing_tablet = Gtk.Template.Child()
overlay_reauth = Gtk.Template.Child()
def __init__(self, **kwargs):
super().__init__(**kwargs)
@ -147,12 +148,20 @@ class MainWindow(Gtk.ApplicationWindow):
self._add_perspective(ep)
self.stack_perspectives.set_visible_child_name(ep.name)
self._signals = []
# the dbus bindings need more async...
if not self._tuhi.online:
self._tuhi.connect('notify::online', self._on_dbus_online)
else:
self._on_dbus_online()
def _register_device(self):
dialog = SetupDialog(self._tuhi)
dialog.set_transient_for(self)
dialog.connect('response', self._on_setup_dialog_closed)
dialog.show()
def _on_dbus_online(self, *args, **kwargs):
logger.debug('dbus is online')
@ -162,10 +171,7 @@ class MainWindow(Gtk.ApplicationWindow):
self.stack_perspectives.set_visible_child_name(dp.name)
if not self._tuhi.devices:
dialog = SetupDialog(self._tuhi)
dialog.set_transient_for(self)
dialog.connect('response', self._on_setup_dialog_closed)
dialog.show()
self._register_device()
else:
device = self._tuhi.devices[0]
self._init_device(device)
@ -173,9 +179,14 @@ class MainWindow(Gtk.ApplicationWindow):
self.headerbar.set_title(f'Tuhi - {dp.device.name}')
def _init_device(self, device):
device.connect('notify::sync-state', self._on_sync_state)
device.connect('notify::battery-percent', self._on_battery_changed)
device.connect('notify::battery-state', self._on_battery_changed)
sig = device.connect('notify::sync-state', self._on_sync_state)
self._signals.append(sig)
sig = device.connect('notify::battery-percent', self._on_battery_changed)
self._signals.append(sig)
sig = device.connect('notify::battery-state', self._on_battery_changed)
self._signals.append(sig)
sig = device.connect('device-error', self._on_device_error)
self._signals.append(sig)
self._on_battery_changed(device, None)
def _on_battery_changed(self, device, pspec):
@ -208,6 +219,7 @@ class MainWindow(Gtk.ApplicationWindow):
self.spinner_sync.stop()
def _on_setup_dialog_closed(self, dialog, response):
self.overlay_reauth.set_reveal_child(False)
device = dialog.device
dialog.destroy()
@ -223,6 +235,16 @@ class MainWindow(Gtk.ApplicationWindow):
self._init_device(device)
self.stack_perspectives.set_visible_child_name(dp.name)
def _on_device_error(self, device, err):
import errno
logger.info(f'Device error: {err}')
if err == -errno.EACCES:
self.overlay_reauth.set_reveal_child(True)
# No point to keep getting notified, it won't be able to
# register.
for sig in self._signals:
device.disconnect(sig)
def _add_perspective(self, perspective):
self.stack_perspectives.add_named(perspective, perspective.name)
@ -240,3 +262,7 @@ class MainWindow(Gtk.ApplicationWindow):
def _on_zoom_changed(self, adjustment):
dp = self._get_child('drawing_perspective')
dp.zoom = int(adjustment.get_value())
@Gtk.Template.Callback('_on_reauth_clicked')
def _on_reauth_clicked(self, button):
self._register_device()