Add a SyncState signal to the DBus interface
Propagated whenever we start talking to the device (and then again when we stop). The purpose of this signal is merely that a UI can show e.g. a progress bar while we're talking to the device to ensure the user something is happening. Fixes #138
This commit is contained in:
parent
05fd213940
commit
b16a16abde
|
@ -378,6 +378,15 @@ org.freedesktop.tuhi1.Device
|
|||
|
||||
These errnos indicate a bug in the daemon, and the client should
|
||||
display a message to that effect.
|
||||
|
||||
Signal: SyncState(i)
|
||||
An enum to represent the current synchronization state of the device.
|
||||
When on (1), Tuhi is currently trying to download data from the
|
||||
device. When off (0), Tuhi is not currently connecting to the device.
|
||||
|
||||
This signal should be used for UI feedback.
|
||||
|
||||
This signal is only send when the device is **not** in Live mode.
|
||||
```
|
||||
|
||||
JSON File Format
|
||||
|
|
|
@ -285,6 +285,13 @@ class TuhiKeteDevice(_DBusObject):
|
|||
elif err < 0:
|
||||
logger.error(f'{self}: an error occured: {os.strerror(-err)}')
|
||||
self.notify('listening')
|
||||
elif signal == 'SyncState':
|
||||
state = parameters[0]
|
||||
if state:
|
||||
logger.debug(f'{self}: Downloading from device')
|
||||
else:
|
||||
logger.debug(f'{self}: Download done')
|
||||
|
||||
|
||||
def _on_properties_changed(self, proxy, changed_props, invalidated_props):
|
||||
if changed_props is None:
|
||||
|
|
|
@ -146,6 +146,10 @@ class TuhiDevice(GObject.Object):
|
|||
def battery_state(self, value):
|
||||
self._battery_state = value
|
||||
|
||||
@GObject.Property
|
||||
def sync_state(self):
|
||||
return self._sync_state
|
||||
|
||||
def _connect_device(self, mode):
|
||||
self._signals['connected'] = self._bluez_device.connect('connected', self._on_bluez_device_connected, mode)
|
||||
self._signals['disconnected'] = self._bluez_device.connect('disconnected', self._on_bluez_device_disconnected)
|
||||
|
@ -166,6 +170,7 @@ class TuhiDevice(GObject.Object):
|
|||
self._wacom_device.connect('button-press-required', self._on_button_press_required)
|
||||
self._wacom_device.connect('notify::uuid', self._on_uuid_updated, bluez_device)
|
||||
self._wacom_device.connect('battery-status', self._on_battery_status, bluez_device)
|
||||
self._wacom_device.connect('notify::sync-state', self._on_sync_state)
|
||||
|
||||
if mode == DeviceMode.REGISTER:
|
||||
self._wacom_device.start_register()
|
||||
|
@ -180,6 +185,10 @@ class TuhiDevice(GObject.Object):
|
|||
except KeyError:
|
||||
pass
|
||||
|
||||
def _on_sync_state(self, device, pspec):
|
||||
self._sync_state = device.sync_state
|
||||
self.notify('sync-state')
|
||||
|
||||
def _on_bluez_device_disconnected(self, bluez_device):
|
||||
logger.debug(f'{bluez_device.address}: disconnected')
|
||||
try:
|
||||
|
|
|
@ -106,6 +106,10 @@ INTROSPECTION_XML = '''
|
|||
<signal name='LiveStopped'>
|
||||
<arg name='status' type='i' />
|
||||
</signal>
|
||||
|
||||
<signal name='SyncState'>
|
||||
<arg name='status' type='i' />
|
||||
</signal>
|
||||
</interface>
|
||||
</node>
|
||||
'''
|
||||
|
@ -182,6 +186,7 @@ class TuhiDBusDevice(_TuhiDBus):
|
|||
device.connect('notify::battery-percent', self._on_battery_percent)
|
||||
device.connect('notify::battery-state', self._on_battery_state)
|
||||
device.connect('device-error', self._on_device_error)
|
||||
device.connect('notify::sync-state', self._on_sync_state)
|
||||
|
||||
@GObject.Property
|
||||
def listening(self):
|
||||
|
@ -330,6 +335,14 @@ class TuhiDBusDevice(_TuhiDBus):
|
|||
self._stop_listening(self.connection, self._listening_client[0],
|
||||
-exception.errno)
|
||||
|
||||
def _on_sync_state(self, device, pspec):
|
||||
if self._listening_client is None:
|
||||
return
|
||||
|
||||
dest = self._listening_client[0]
|
||||
status = GLib.Variant.new_int32(device.sync_state)
|
||||
self.signal('SyncState', status, dest=dest)
|
||||
|
||||
def _start_listening(self, connection, sender):
|
||||
if self.listening:
|
||||
logger.debug(f'{self} - already listening')
|
||||
|
|
|
@ -1115,6 +1115,7 @@ class WacomDevice(GObject.Object):
|
|||
self._is_running = False
|
||||
self._config = None
|
||||
self._wacom_protocol = None
|
||||
self._sync_state = 0
|
||||
|
||||
try:
|
||||
self._config = config.devices[device.address]
|
||||
|
@ -1168,6 +1169,14 @@ class WacomDevice(GObject.Object):
|
|||
assert self._wacom_protocol is not None
|
||||
return self._wacom_protocol.protocol
|
||||
|
||||
@GObject.Property
|
||||
def sync_state(self):
|
||||
return self._sync_state
|
||||
|
||||
@sync_state.setter
|
||||
def sync_state(self, state):
|
||||
self._sync_state = state
|
||||
|
||||
def register_device(self):
|
||||
self._uuid = uuid.uuid4().hex[:12]
|
||||
logger.debug(f'{self._device.address}: registering device, assigned {self.uuid}')
|
||||
|
@ -1204,10 +1213,13 @@ class WacomDevice(GObject.Object):
|
|||
self.register_device()
|
||||
else:
|
||||
assert self._wacom_protocol is not None
|
||||
self.sync_state = 1
|
||||
self._wacom_protocol.retrieve_data()
|
||||
self.sync_state = 0
|
||||
except WacomException as e:
|
||||
logger.error(f'**** Exception: {e} ****')
|
||||
exception = e
|
||||
self.sync_state = 0
|
||||
finally:
|
||||
self._is_running = False
|
||||
self.emit('done', exception)
|
||||
|
|
Loading…
Reference in New Issue