Exemple #1
0
    def inquiry(self):
        def prop_changed(lst, adapter, key_value):
            key, value = key_value
            if key == "Discovering" and not value:
                prog.finalize()
                self.List.disconnect(s1)
                self.List.disconnect(s2)

        def on_progress(lst, frac):
            if abs(1.0 - frac) <= 0.00001:
                if not prog.started():
                    prog.start()
            else:
                prog.fraction(frac)

        prog = ManagerProgressbar(self, text=_("Searching"))
        prog.connect("cancelled", lambda x: self.List.stop_discovery())
        try:
            self.List.discover_devices()
        except Exception as e:
            prog.finalize()
            MessageArea.show_message(*e_(e))

        s1 = self.List.connect("discovery-progress", on_progress)
        s2 = self.List.connect("adapter-property-changed", prop_changed)
Exemple #2
0
        def fail(*args):
            prog.message(_("Failed"))

            self.unset_op(device)
            dprint("fail", args)
            MessageArea.show_message(
                _("Connection Failed: ") + e_(str(args[0])))
        def fail(obj, result, _user_data):
            prog.message(_("Failed"))

            self.unset_op(device)
            logging.warning("fail %s" % result)
            msg, tb = e_(result.message)
            MessageArea.show_message(_("Connection Failed: ") + msg, tb)
Exemple #4
0
        def success(_obj: AppletService, _result: None, _user_data: None) -> None:
            logging.info("success")
            prog.message(_("Success!"))

            MessageArea.close()

            self.unset_op(device)
    def _handle_error_message(self, error: GLib.Error) -> None:
        err = self._get_errno(error)

        if err == errno.ENOPROTOOPT:
            logging.warning(
                "No audio endpoints registered to bluetoothd. "
                "Pulseaudio Bluetooth module, bluez-alsa, PipeWire or other audio support missing."
            )
            msg = _("No audio endpoints registered")
        elif err == errno.EIO:
            logging.warning(
                "bluetoothd reported input/output error. Check its logs for context."
            )
            msg = _("Input/output error")
        elif err == errno.EHOSTDOWN:
            msg = _("Device did not respond")
        elif err == errno.EAGAIN:
            logging.warning(
                "bluetoothd reported resource temporarily unavailable. "
                "Retry or check its logs for context.")
            msg = _("Resource temporarily unavailable")
        else:
            msg = error.message.split(":", 3)[-1].strip()

        if msg != "Cancelled":
            MessageArea.show_message(_("Connection Failed: ") + msg)
Exemple #6
0
 def fail(_obj: AppletService, result: GLib.Error,
          _user_data: None) -> None:
     logging.info(f"fail: {result}")
     prog.message(_("Failed"))
     self.unset_op(device)
     msg, tb = e_(result.message)
     MessageArea.show_message(_("Connection Failed: ") + msg)
Exemple #7
0
    def _handle_error_message(self, msg: str) -> None:
        msg = msg.split(":", 3)[-1].strip()

        # https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/gnu/errlist.h
        # https://git.musl-libc.org/cgit/musl/tree/src/errno/__strerror.h
        # https://git.uclibc.org/uClibc/tree/libc/string/_string_syserrmsgs.c
        if msg == "Protocol not available":
            # ENOPROTOOPT
            logging.warning(
                "No audio endpoints registered to bluetoothd. "
                "Pulseaudio Bluetooth module, bluez-alsa, PipeWire or other audio support missing."
            )
            msg = _("No audio endpoints registered")
        elif msg in ("Input/output error", "I/O error"):
            # EIO
            logging.warning(
                "bluetoothd reported input/output error. Check its logs for context."
            )
            msg = _("Input/output error")
        elif msg == "Host is down":
            # EHOSTDOWN (Bluetooth errors 0x04 (Page Timeout) or 0x3c (Advertising Timeout))
            msg = _("Device did not respond")
        elif msg == "Resource temporarily unavailable":
            # EAGAIN
            logging.warning(
                "bluetoothd reported resource temporarily unavailable. "
                "Retry or check its logs for context.")
            msg = _("Resource temporarily unavailable")

        if msg != "Cancelled":
            MessageArea.show_message(_("Connection Failed: ") + msg)
Exemple #8
0
    def inquiry(self):
        def prop_changed(lst, adapter, key_value):
            key, value = key_value
            if key == "Discovering" and not value:
                prog.finalize()
                self.List.disconnect(s1)
                self.List.disconnect(s2)

        def on_progress(lst, frac):
            if abs(1.0 - frac) <= 0.00001:
                if not prog.started():
                    prog.start()
            else:
                prog.fraction(frac)

        prog = ManagerProgressbar(self, text=_("Searching"))
        prog.connect("cancelled", lambda x: self.List.stop_discovery())
        try:
            self.List.discover_devices()
        except Exception as e:
            prog.finalize()
            MessageArea.show_message(*e_(e))

        s1 = self.List.connect("discovery-progress", on_progress)
        s2 = self.List.connect("adapter-property-changed", prop_changed)
        def fail(obj, result, _user_data):
            prog.message(_("Failed"))

            self.unset_op(device)
            logging.warning("fail %s" % result)
            msg, tb = e_(result.message)
            MessageArea.show_message(_("Connection Failed: ") + msg, tb)
Exemple #10
0
        def fail(_obj: Optional[AppletService], result: GLib.Error,
                 _user_data: None) -> None:
            prog.message(_("Failed"))

            self.unset_op(device)
            logging.warning(f"fail {result}")
            msg, tb = e_(result.message)
            MessageArea.show_message(_("Connection Failed: ") + msg, tb)
Exemple #11
0
        def success(obj, result, _user_data):
            logging.info("success")
            prog.message(_("Success!"))

            if isinstance(service, SerialPort) and SERIAL_PORT_SVCLASS_ID == service.short_uuid:
                MessageArea.show_message(_("Serial port connected to %s") % result, None, "dialog-information")
            else:
                MessageArea.close()

            self.unset_op(device)
Exemple #12
0
        def success(obj, result, _user_data):
            dprint("success")
            prog.message(_("Success!"))

            if isinstance(service, SerialPort) and SERIAL_PORT_SVCLASS_ID == uuid128_to_uuid16(service.uuid):
                MessageArea.show_message(_("Serial port connected to %s") % result, "dialog-information")
            else:
                MessageArea.close()

            self.unset_op(device)
Exemple #13
0
        def success(obj, result, _user_data):
            logging.info("success")
            prog.message(_("Success!"))

            if isinstance(service, SerialPort) and SERIAL_PORT_SVCLASS_ID == service.short_uuid:
                MessageArea.show_message(_("Serial port connected to %s") % result, None, "dialog-information")
            else:
                MessageArea.close()

            self.unset_op(device)
Exemple #14
0
        def success(*args2):
            dprint("success", " ".join(args2))
            prog.message(_("Success!"))

            if isinstance(service, SerialPort) and SERIAL_PORT_SVCLASS_ID == uuid128_to_uuid16(service.uuid):
                MessageArea.show_message(_("Serial port connected to %s") % args2[0], "dialog-information")
            else:
                MessageArea.close()

            self.unset_op(device)
Exemple #15
0
        def success(*args2):
            try:
                uuid16 = sdp_get_serial_type(device.Address, args[0])
            except:
                uuid16 = 0

            dprint("success", args2)
            prog.message(_("Success!"))

            if service_id == "serial" and SERIAL_PORT_SVCLASS_ID in uuid16:
                MessageArea.show_message(_("Serial port connected to %s") % args2[0], "dialog-information")
            else:
                MessageArea.close()

            self.unset_op(device)
Exemple #16
0
        def success(*args2):
            try:
                uuid16 = sdp_get_serial_type(device.Address, args[0])
            except:
                uuid16 = 0

            dprint("success", args2)
            prog.message(_("Success!"))

            if service_id == "serial" and SERIAL_PORT_SVCLASS_ID in uuid16:
                MessageArea.show_message(
                    _("Serial port connected to %s") % args2[0],
                    gtk.STOCK_DIALOG_INFO)
            else:
                MessageArea.close()

            self.unset_op(device)
Exemple #17
0
 def reply():
     self.unset_op(device)
     prog.message(_("Success!"))
     MessageArea.close()
Exemple #18
0
    def do_activate(self) -> None:
        if not self.window:
            self.window = Gtk.ApplicationWindow(application=self,
                                                name="BluemanManager",
                                                icon_name="blueman",
                                                title=_("Bluetooth Devices"))
            w, h, x, y = self.Config["window-properties"]
            if w and h:
                self.window.resize(w, h)
            if x and y:
                self.window.move(x, y)

            # Connect to configure event to store new window position and size
            self.window.connect("configure-event", self._on_configure)

            self.builder = Builder("manager-main.ui")
            box = self.builder.get_widget("box", Gtk.Box)
            self.window.add(box)

            grid = self.builder.get_widget("grid", Gtk.Grid)

            toolbar = self.builder.get_widget("toolbar", Gtk.Toolbar)
            statusbar = self.builder.get_widget("statusbar", Gtk.Box)

            self.Plugins = PluginManager(ManagerPlugin,
                                         blueman.plugins.manager, self)
            self.Plugins.load_plugin()

            area = MessageArea()
            grid.attach(area, 0, 1, 1, 1)

            self._applethandlerid: Optional[int] = None

            # Add margin for resize grip or it will overlap
            if self.window.get_has_resize_grip():
                margin_right = statusbar.get_margin_right()
                statusbar.set_margin_right(margin_right + 10)

            def bt_status_changed(status: bool) -> None:
                assert self.window is not None
                if not status:
                    self.window.hide()
                    check_bluetooth_status(
                        _("Bluetooth needs to be turned on for the device manager to function"
                          ), self.quit)
                else:
                    self.window.show()

            def on_applet_signal(_proxy: AppletService, _sender: str,
                                 signal_name: str,
                                 params: GLib.Variant) -> None:
                if signal_name == 'BluetoothStatusChanged':
                    status = params.unpack()
                    bt_status_changed(status)

            def on_dbus_name_vanished(_connection: Gio.DBusConnection,
                                      name: str) -> None:
                logging.info(name)
                if self._applethandlerid:
                    self.Applet.disconnect(self._applethandlerid)
                    self._applethandlerid = None

                if self.window is not None:
                    self.window.hide()

                d = ErrorDialog(
                    _("Connection to BlueZ failed"),
                    _("Bluez daemon is not running, blueman-manager cannot continue.\n"
                      "This probably means that there were no Bluetooth adapters detected "
                      "or Bluetooth daemon was not started."),
                    icon_name="blueman")
                d.run()
                d.destroy()

                # FIXME ui can handle BlueZ start/stop but we should inform user
                self.quit()

            def on_dbus_name_appeared(_connection: Gio.DBusConnection,
                                      name: str, owner: str) -> None:
                logging.info(f"{name} {owner}")
                setup_icon_path()

                try:
                    self.Applet = AppletService()
                except DBusProxyFailed:
                    print("Blueman applet needs to be running")
                    bmexit()

                check_bluetooth_status(
                    _("Bluetooth needs to be turned on for the device manager to function"
                      ), lambda: self.quit())

                manager = Manager()
                try:
                    manager.get_adapter(self.Config['last-adapter'])
                except DBusNoSuchAdapterError:
                    logging.error(
                        'Default adapter not found, trying first available.')
                    try:
                        manager.get_adapter(None)
                    except DBusNoSuchAdapterError:
                        logging.error('No adapter(s) found, exiting')
                        bmexit()

                self._applethandlerid = self.Applet.connect(
                    'g-signal', on_applet_signal)

                sw = self.builder.get_widget("scrollview", Gtk.ScrolledWindow)
                # Disable overlay scrolling
                if Gtk.get_minor_version() >= 16:
                    sw.props.overlay_scrolling = False

                self.List = ManagerDeviceList(
                    adapter=self.Config["last-adapter"], inst=self)

                self.List.show()
                sw.add(self.List)

                self.Toolbar = ManagerToolbar(self)
                self.Menu = ManagerMenu(self)
                self.Stats = ManagerStats(self)

                if self.List.is_valid_adapter():
                    self.List.populate_devices()

                self.List.connect("adapter-changed", self.on_adapter_changed)

                self.Config.bind_to_widget("show-toolbar", toolbar, "visible")
                self.Config.bind_to_widget("show-statusbar", statusbar,
                                           "visible")

            Manager.watch_name_owner(on_dbus_name_appeared,
                                     on_dbus_name_vanished)

        self.window.present_with_time(Gtk.get_current_event_time())
Exemple #19
0
 def on_error(e: Exception) -> None:
     prog.finalize()
     MessageArea.show_message(*e_(e))
 def on_result(res):
     if not res:
         MessageArea.show_message(_("Failed to change profile to %s" % profile))
Exemple #21
0
 def success(obj, result, user_data):
     logging.info("success")
     prog.message(_("Success!"))
     MessageArea.close()
     self.unset_op(device)
Exemple #22
0
 def err(obj, result, user_date):
     logging.warning("disconnect failed %s" % result)
     msg, tb = e_(result.message)
     MessageArea.show_message(_("Disconnection Failed: ") + msg, tb)
     self.generate()
Exemple #23
0
    def __init__(self):
        super().__init__(title=_("Bluetooth Devices"))

        self._applet_sig = None

        self.Config = Config("org.blueman.general")

        self.Builder = Gtk.Builder()
        self.Builder.set_translation_domain("blueman")
        #        bind_textdomain_codeset("blueman", "UTF-8")
        self.Builder.add_from_file(UI_PATH + "/manager-main.ui")

        grid = self.Builder.get_object("grid")
        self.add(grid)
        self.set_name("BluemanManager")

        self.Plugins = PluginManager(ManagerPlugin, blueman.plugins.manager,
                                     self)
        self.Plugins.load_plugin()

        area = MessageArea()
        grid.attach(area, 0, 3, 1, 1)

        # Add margin for resize grip or it will overlap
        if self.get_has_resize_grip():
            statusbar = self.Builder.get_object("statusbar")
            margin_right = statusbar.get_margin_right()
            statusbar.set_margin_right(margin_right + 10)

        def do_present(time):
            if self.props.visible:
                self.present_with_time(time)

        check_single_instance("blueman-manager", do_present)

        def on_window_delete(window, event):
            w, h = self.get_size()
            x, y = self.get_position()
            self.Config["window-properties"] = [w, h, x, y]
            Gtk.main_quit()

        def bt_status_changed(status):
            if not status:
                self.hide()
                check_bluetooth_status(
                    _("Bluetooth needs to be turned on for the device manager to function"
                      ), lambda: Gtk.main_quit())
            else:
                self.show()

        def on_applet_signal(_proxy, _sender, signal_name, params):
            if signal_name == 'BluetoothStatusChanged':
                status = params.unpack()
                bt_status_changed(status)

        def on_dbus_name_vanished(_connection, name):
            logging.info(name)
            if self._applet_sig is not None:
                self.Applet.disconnect(self._applet_sig)
                self._applet_sig = None

            self.hide()

            d = ErrorDialog(
                _("Connection to BlueZ failed"),
                _("Bluez daemon is not running, blueman-manager cannot continue.\n"
                  "This probably means that there were no Bluetooth adapters detected "
                  "or Bluetooth daemon was not started."),
                icon_name="blueman")
            d.run()
            d.destroy()

            # FIXME ui can handle BlueZ start/stop but we should inform user
            Gtk.main_quit()

        def on_dbus_name_appeared(_connection, name, owner):
            logging.info("%s %s" % (name, owner))
            setup_icon_path()

            try:
                self.Applet = AppletService()
            except DBusProxyFailed:
                print("Blueman applet needs to be running")
                exit()

            check_bluetooth_status(
                _("Bluetooth needs to be turned on for the device manager to function"
                  ), lambda: Gtk.main_quit())

            manager = bluez.Manager()
            try:
                manager.get_adapter(self.Config['last-adapter'])
            except bluez.errors.DBusNoSuchAdapterError:
                logging.error(
                    'Default adapter not found, trying first available.')
                try:
                    manager.get_adapter(None)
                except bluez.errors.DBusNoSuchAdapterError:
                    logging.error('No adapter(s) found, exiting')
                    exit(1)

            self._applet_sig = self.Applet.connect('g-signal',
                                                   on_applet_signal)

            self.connect("delete-event", on_window_delete)
            self.props.icon_name = "blueman"

            w, h, x, y = self.Config["window-properties"]
            if w and h:
                self.resize(w, h)
            if x and y:
                self.move(x, y)

            sw = self.Builder.get_object("scrollview")
            # Disable overlay scrolling
            if Gtk.get_minor_version() >= 16:
                sw.props.overlay_scrolling = False

            self.List = ManagerDeviceList(adapter=self.Config["last-adapter"],
                                          inst=self)

            self.List.show()
            sw.add(self.List)

            self.Toolbar = ManagerToolbar(self)
            self.Menu = ManagerMenu(self)
            self.Stats = ManagerStats(self)

            if self.List.is_valid_adapter():
                self.List.display_known_devices(autoselect=True)

            self.List.connect("adapter-changed", self.on_adapter_changed)

            toolbar = self.Builder.get_object("toolbar")
            statusbar = self.Builder.get_object("statusbar")

            self.Config.bind_to_widget("show-toolbar", toolbar, "visible")
            self.Config.bind_to_widget("show-statusbar", statusbar, "visible")

            self.show()

        bluez.Manager.watch_name_owner(on_dbus_name_appeared,
                                       on_dbus_name_vanished)
Exemple #24
0
 def fail(obj, result, user_date):
     logging.info("fail", result)
     prog.message(_("Failed"))
     self.unset_op(device)
     msg, tb = e_(result.message)
     MessageArea.show_message(_("Connection Failed: ") + msg)
Exemple #25
0
        def fail(obj, result, _user_data):
            prog.message(_("Failed"))

            self.unset_op(device)
            dprint("fail", result)
            MessageArea.show_message(_("Connection Failed: ") + e_(str(result.message)))
				def reply():
					self.unset_op(device)
					prog.message(_("Success!"))
					MessageArea.close()
Exemple #27
0
    def __init__(self):
        super().__init__(title=_("Bluetooth Devices"))

        self.Config = Config("org.blueman.general")

        self.Builder = Gtk.Builder()
        self.Builder.set_translation_domain("blueman")
        bind_textdomain_codeset("blueman", "UTF-8")
        self.Builder.add_from_file(UI_PATH + "/manager-main.ui")

        grid = self.Builder.get_object("grid")
        self.add(grid)
        self.set_name("BluemanManager")

        self.Plugins = PluginManager(ManagerPlugin, blueman.plugins.manager,
                                     self)
        self.Plugins.load_plugin()

        area = MessageArea()
        grid.attach(area, 0, 3, 1, 1)

        self._applethandlerid: Optional[int] = None

        # Add margin for resize grip or it will overlap
        if self.get_has_resize_grip():
            statusbar = self.Builder.get_object("statusbar")
            margin_right = statusbar.get_margin_right()
            statusbar.set_margin_right(margin_right + 10)

        def do_present(time):
            if self.props.visible:
                self.present_with_time(time)

        check_single_instance("blueman-manager", do_present)

        def on_window_delete(window, event):
            w, h = self.get_size()
            x, y = self.get_position()
            self.Config["window-properties"] = [w, h, x, y]
            Gtk.main_quit()

        setup_icon_path()

        try:
            self.Applet = AppletService()
        except DBusProxyFailed:
            print("Blueman applet needs to be running")
            exit()

        manager = Manager()
        try:
            manager.get_adapter(self.Config['last-adapter'])
        except DBusNoSuchAdapterError:
            logging.error('Default adapter not found, trying first available.')
            try:
                manager.get_adapter(None)
            except DBusNoSuchAdapterError:
                logging.error('No adapter(s) found')

        self.connect("delete-event", on_window_delete)
        self.props.icon_name = "blueman"

        w, h, x, y = self.Config["window-properties"]
        if w and h:
            self.resize(w, h)
        if x and y:
            self.move(x, y)

        sw = self.Builder.get_object("scrollview")
        # Disable overlay scrolling
        if Gtk.get_minor_version() >= 16:
            sw.props.overlay_scrolling = False

        self.List = ManagerDeviceList(adapter=self.Config["last-adapter"],
                                      inst=self)

        self.List.show()
        sw.add(self.List)

        self.Toolbar = ManagerToolbar(self)
        self.Menu = ManagerMenu(self)
        self.Stats = ManagerStats(self)

        if self.List.is_valid_adapter():
            self.List.display_known_devices(autoselect=True)

        self.List.connect("adapter-changed", self.on_adapter_changed)

        toolbar = self.Builder.get_object("toolbar")
        statusbar = self.Builder.get_object("statusbar")

        self.Config.bind_to_widget("show-toolbar", toolbar, "visible")
        self.Config.bind_to_widget("show-statusbar", statusbar, "visible")

        self.show()
Exemple #28
0
 def err(_obj: Optional[AppletService], result: GLib.Error, _user_date: None) -> None:
     logging.warning(f"disconnect failed {result}")
     msg, tb = e_(result.message)
     MessageArea.show_message(_("Disconnection Failed: ") + msg, tb)
     self.generate()
Exemple #29
0
 def success(obj, result, user_data):
     logging.info("success")
     prog.message(_("Success!"))
     MessageArea.close()
     self.unset_op(device)
Exemple #30
0
				def reply():
					prog_msg(_("Success!"))
					MessageArea.close()
Exemple #31
0
				def error(*args):
					dprint("err", args)
					prog_msg(_("Fail"))
					MessageArea.show_message(e_(str(args[0])))					
Exemple #32
0
 def fail(obj, result, user_date):
     logging.info("fail", result)
     prog.message(_("Failed"))
     self.unset_op(device)
     msg, tb = e_(result.message)
     MessageArea.show_message(_("Connection Failed: ") + msg)
Exemple #33
0
 def on_result(res: int) -> None:
     if not res:
         MessageArea.show_message(_("Failed to change profile to %s" % profile))
		def fail(*args):
			prog.message(_("Failed"))
			
			self.unset_op(device)
			dprint("fail", args)
			MessageArea.show_message(_("Connection Failed: ") + e_(str(args[0])))
Exemple #35
0
 def error(*args):
     self.unset_op(device)
     prog.message(_("Fail"))
     MessageArea.show_message(e_(str(args[0])))
				def error(*args):
					self.unset_op(device)
					prog.message(_("Fail"))
					MessageArea.show_message(e_(str(args[0])))					
Exemple #37
0
 def err(obj, result, user_date):
     logging.warning("disconnect failed %s" % result)
     msg, tb = e_(result.message)
     MessageArea.show_message(_("Disconnection Failed: ") + msg, tb)
     self.Generate()