[gnome-keysign: 1/5] Create a dialog at startup informing about the missing Avahi service
- From: Tobias Mueller <tobiasmue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keysign: 1/5] Create a dialog at startup informing about the missing Avahi service
- Date: Thu, 15 Nov 2018 22:39:55 +0000 (UTC)
commit 951e59ca2029a655ddb9a615e8f098aafe652fb8
Author: RyuzakiKK <aasonykk gmail com>
Date: Thu Jul 12 13:54:10 2018 +0200
Create a dialog at startup informing about the missing Avahi service
This gracefully handles the error reported in the issue #56
keysign/app.py | 54 ++++++++++++++++++++++++++---------------
keysign/dialog_avahi.ui | 45 ++++++++++++++++++++++++++++++++++
keysign/errors.py | 6 +++++
keysign/network/AvahiBrowser.py | 12 +++++++--
4 files changed, 96 insertions(+), 21 deletions(-)
---
diff --git a/keysign/app.py b/keysign/app.py
index 22341b1..51d51d3 100755
--- a/keysign/app.py
+++ b/keysign/app.py
@@ -48,6 +48,7 @@ if __name__ == "__main__" and __package__ is None:
from .avahioffer import AvahiHTTPOffer
from .avahidiscovery import AvahiKeysignDiscoveryWithMac
+from .errors import NoAvahiDbus
from .keyconfirm import PreSignWidget
from .keyfprscan import KeyFprScanWidget
from .keylistwidget import KeyListWidget
@@ -149,31 +150,46 @@ class KeysignApp(Gtk.Application):
# Load Receive part
- self.receive = PswMappingReceiveApp(self.on_presign_mapped)
- rs = self.receive.stack
+ try:
+ self.receive = PswMappingReceiveApp(self.on_presign_mapped)
+ except NoAvahiDbus as de:
+ log.info("Probably Avahi needs to be manually started: %s", de)
+ ui_file_path = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ "dialog_avahi.ui")
+ appwindow = 'dialog_avahi'
+ builder = Gtk.Builder()
+ builder.add_objects_from_file(ui_file_path, [appwindow])
+ window.set_wmclass("GNOME Keysign", "GNOME Keysign")
+ window.set_title("GNOME Keysign")
+ ok_button = builder.get_object("avahi_ok")
+ ok_button.connect('clicked', self.on_delete_window)
+ window = builder.get_object(appwindow)
+ else:
+ rs = self.receive.stack
- rs.connect('notify::visible-child',
- self.on_receive_stack_switch)
+ rs.connect('notify::visible-child',
+ self.on_receive_stack_switch)
- scanner = self.receive.scanner
- scanner.connect("map", self.on_scanner_mapped)
- self.receive_stack = rs
+ scanner = self.receive.scanner
+ scanner.connect("map", self.on_scanner_mapped)
+ self.receive_stack = rs
- # Hm. Leaving comments for translators does not seem to work
- self.send_receive_stack.add_titled(self.send_stack,
- "send_stack", _("Send"))
- self.send_receive_stack.add_titled(rs,
- "receive_stack", _("Receive"))
+ # Hm. Leaving comments for translators does not seem to work
+ self.send_receive_stack.add_titled(self.send_stack,
+ "send_stack", _("Send"))
+ self.send_receive_stack.add_titled(rs,
+ "receive_stack", _("Receive"))
- # These properties must be set after the stacks has been added to the window
- # because they require a window element that "receive.ui" file doesn't provide.
- accel_group = Gtk.AccelGroup()
- window.add_accel_group(accel_group)
- self.receive.accept_button.add_accelerator("clicked", accel_group, ord('o'),
Gdk.ModifierType.MOD1_MASK,
- Gtk.AccelFlags.VISIBLE)
- self.receive.accept_button.set_can_default(True)
+ # These properties must be set after the stacks has been added to the window
+ # because they require a window element that "receive.ui" file doesn't provide.
+ accel_group = Gtk.AccelGroup()
+ window.add_accel_group(accel_group)
+ self.receive.accept_button.add_accelerator("clicked", accel_group, ord('o'),
Gdk.ModifierType.MOD1_MASK,
+ Gtk.AccelFlags.VISIBLE)
+ self.receive.accept_button.set_can_default(True)
window.show_all()
self.add_window(window)
diff --git a/keysign/dialog_avahi.ui b/keysign/dialog_avahi.ui
new file mode 100644
index 0000000..0a615ca
--- /dev/null
+++ b/keysign/dialog_avahi.ui
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
+<interface>
+ <requires lib="gtk+" version="3.20"/>
+ <object class="GtkMessageDialog" id="dialog_avahi">
+ <property name="can_focus">False</property>
+ <property name="type_hint">dialog</property>
+ <property name="text" translatable="yes">Unable to Start Avahi</property>
+ <property name="secondary_text" translatable="yes">Keysign is unable to automatically start Avahi. You
can try to execute `systemctl start avahi-daemon` for solving this problem.</property>
+ <child internal-child="vbox">
+ <object class="GtkBox">
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox">
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="homogeneous">True</property>
+ <property name="layout_style">expand</property>
+ <child>
+ <object class="GtkButton" id="avahi_ok">
+ <property name="label" translatable="yes">OK</property>
+ <property name="name">avahi_ok</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/keysign/errors.py b/keysign/errors.py
index 1016972..d712130 100644
--- a/keysign/errors.py
+++ b/keysign/errors.py
@@ -14,3 +14,9 @@ class UnpoweredAdapter(BluetoothException):
"""The Bluetooth adapter is turned off"""
+class AvahiException(Exception):
+ """Parent class for all Avahi-related errors"""
+
+
+class NoAvahiDbus(AvahiException):
+ """The required avahi dbus is not available"""
diff --git a/keysign/network/AvahiBrowser.py b/keysign/network/AvahiBrowser.py
index c021af9..5ef2402 100644
--- a/keysign/network/AvahiBrowser.py
+++ b/keysign/network/AvahiBrowser.py
@@ -27,10 +27,14 @@ from gi.repository import GObject
import logging
+from ..errors import NoAvahiDbus
+
__all__ = ["AvahiBrowser"]
DBusGMainLoop( set_as_default=True )
+log = logging.getLogger(__name__)
+
# This should probably be upstreamed.
# Unfortunately, upstream seems rather inactive.
if getattr(avahi, 'txt_array_to_dict', None) is None:
@@ -83,8 +87,12 @@ class AvahiBrowser(GObject.GObject):
self.loop = loop or DBusGMainLoop()
self.bus = dbus.SystemBus(mainloop=self.loop)
- self.server = dbus.Interface( self.bus.get_object(avahi.DBUS_NAME, '/'),
- 'org.freedesktop.Avahi.Server')
+ try:
+ self.server = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, '/'),
+ 'org.freedesktop.Avahi.Server')
+ except dbus.exceptions.DBusException as de:
+ log.exception("Avahi cannot be started: %s", de)
+ raise NoAvahiDbus(de)
self.sbrowser = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME,
self.server.ServiceBrowserNew(avahi.IF_UNSPEC,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]