[gnome-keysign: 45/65] infobar discovery: prevent displaying it if we also have Bluetooth



commit 2719bdbd067c8c60760fad5547cf83684898e505
Author: RyuzakiKK <aasonykk gmail com>
Date:   Wed Aug 23 16:31:05 2017 +0200

    infobar discovery: prevent displaying it if we also have Bluetooth

 keysign/receive.py |  6 ++++--
 keysign/util.py    | 12 ++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/keysign/receive.py b/keysign/receive.py
index 43dbc23..8a7d9b1 100755
--- a/keysign/receive.py
+++ b/keysign/receive.py
@@ -51,7 +51,7 @@ from .keyfprscan import KeyFprScanWidget
 from .keyconfirm import PreSignWidget
 from .gpgmh import openpgpkey_from_data
 from .i18n import _
-from .util import sign_keydata_and_send, fix_infobar
+from .util import sign_keydata_and_send, fix_infobar, is_bt_available
 from .discover import Discover
 
 log = logging.getLogger(__name__)
@@ -162,8 +162,10 @@ class ReceiveApp:
         # Do we also want to add an infobar message or so..?
 
     def on_list_changed(self, discovery, number, userdata):
+        """We show an infobar if we can only receive with Avahi and
+        there are zero nearby servers"""
         ib = userdata
-        if number == 0:
+        if number == 0 and not is_bt_available():
             ib.show()
         elif ib.is_visible():
             ib.hide()
diff --git a/keysign/util.py b/keysign/util.py
index 90ed36a..8543172 100644
--- a/keysign/util.py
+++ b/keysign/util.py
@@ -239,3 +239,15 @@ def get_local_bt_address(hci_number=0):
     adapter = dbus.Interface(bus.get_object("org.bluez", "/org/bluez/hci%i" % hci_number),
                              "org.freedesktop.DBus.Properties")
     return adapter.Get("org.bluez.Adapter1", "Address")
+
+
+def is_bt_available(hci_number=0):
+    """If the bluez object is available it means that there is a working Bluetooth"""
+    bus = dbus.SystemBus()
+    try:
+        dbus.Interface(bus.get_object("org.bluez", "/org/bluez/hci%i" % hci_number),
+                             "org.freedesktop.DBus.Properties")
+        return True
+    except dbus.exceptions.DBusException as e:
+        log.debug("Bluetooth is not available: %s", e)
+        return False


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]