Пример #1
0
    def __init__(self, selected_hci_dev, socket_id):
        super().__init__(title=_("Bluetooth Adapters"),
                         border_width=5,
                         resizable=False,
                         icon_name="blueman-device",
                         name="BluemanAdapters")
        self.connect("delete-event", self._on_close)

        self.notebook = Gtk.Notebook(visible=True)

        if socket_id:
            plug = Gtk.Plug.new(socket_id)
            plug.show()
            plug.connect('delete-event', self._on_close)
            plug.add(self.notebook)
        else:
            self.add(self.notebook)
            self.connect("delete-event", self._on_close)
            self.show()

        self.tabs: Dict[str, "Tab"] = {}
        self._adapters: Dict[str, Adapter] = {}

        setup_icon_path()
        Manager.watch_name_owner(self._on_dbus_name_appeared,
                                 self._on_dbus_name_vanished)
        self.manager = Manager()

        check_single_instance("blueman-adapters",
                              lambda time: self.present_with_time(time))

        check_bluetooth_status(
            _("Bluetooth needs to be turned on for the adapter manager to work"
              ), lambda: exit())

        adapters = self.manager.get_adapters()
        if not adapters:
            logging.error('No adapter(s) found')
            exit(1)

        self.manager.connect_signal('adapter-added', self.on_adapter_added)
        self.manager.connect_signal('adapter-removed', self.on_adapter_removed)
        for adapter in adapters:
            path = adapter.get_object_path()
            hci_dev = os.path.basename(path)
            self._adapters[hci_dev] = adapter
            self.on_adapter_added(self.manager, path)

        # activate a particular tab according to command line option
        if selected_hci_dev is not None:
            if selected_hci_dev in self.tabs:
                hci_dev_num = int(selected_hci_dev[3:])
                self.notebook.set_current_page(hci_dev_num)
            else:
                logging.error('Error: the selected adapter does not exist')
        self.notebook.show_all()
Пример #2
0
    def __init__(self, selected_hci_dev: Optional[str],
                 socket_id: Optional[int]) -> None:
        super().__init__(application_id="org.blueman.Adapters")

        def do_quit(_: object) -> bool:
            self.quit()
            return False

        s = GLib.unix_signal_source_new(signal.SIGINT)
        s.set_callback(do_quit)
        s.attach()

        self.socket_id = socket_id
        self.selected_hci_dev = selected_hci_dev

        self.notebook = Gtk.Notebook(visible=True)

        self.window: Optional[Gtk.ApplicationWindow] = None

        self.tabs: Dict[str, "Tab"] = {}
        self._adapters: Dict[str, Adapter] = {}

        setup_icon_path()
        Manager.watch_name_owner(self._on_dbus_name_appeared,
                                 self._on_dbus_name_vanished)
        self.manager = Manager()

        check_bluetooth_status(
            _("Bluetooth needs to be turned on for the adapter manager to work"
              ), bmexit)

        adapters = self.manager.get_adapters()
        if not adapters:
            logging.error('No adapter(s) found')
            bmexit()

        self.manager.connect_signal('adapter-added', self.on_adapter_added)
        self.manager.connect_signal('adapter-removed', self.on_adapter_removed)
        for adapter in adapters:
            path = adapter.get_object_path()
            self.on_adapter_added(self.manager, path)

        # activate a particular tab according to command line option
        if selected_hci_dev is not None:
            if selected_hci_dev in self.tabs:
                hci_dev_num = int(selected_hci_dev[3:])
                self.notebook.set_current_page(hci_dev_num)
            else:
                logging.error('Error: the selected adapter does not exist')
        self.notebook.show_all()
Пример #3
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()

        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._applethandlerid:
                self.Applet.disconnect(self._applethandlerid)
                self._applethandlerid = 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")
                bmexit()

            check_bluetooth_status(
                _("Bluetooth needs to be turned on for the device manager to function"
                  ), lambda: Gtk.main_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)

            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()

        Manager.watch_name_owner(on_dbus_name_appeared, on_dbus_name_vanished)
Пример #4
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())
Пример #5
0
class BluemanApplet(Gio.Application):
    def __init__(self):
        super().__init__(application_id="org.blueman.Applet",
                         flags=Gio.ApplicationFlags.FLAGS_NONE)
        setup_icon_path()

        self.plugin_run_state_changed = False
        self.manager_state = False
        self._active = False

        self.Manager = Manager()
        self.Manager.connect_signal('adapter-added', self.on_adapter_added)
        self.Manager.connect_signal('adapter-removed', self.on_adapter_removed)
        self.Manager.connect_signal('device-created', self.on_device_created)
        self.Manager.connect_signal('device-removed', self.on_device_removed)

        self.DbusSvc = DbusService("org.blueman.Applet", "org.blueman.Applet",
                                   "/org/blueman/Applet", Gio.BusType.SESSION)
        self.DbusSvc.register()

        self.Plugins = PersistentPluginManager(AppletPlugin,
                                               blueman.plugins.applet, self)
        self.Plugins.load_plugin()

        self.Plugins.run("on_plugins_loaded")

        self.Manager.watch_name_owner(self._on_dbus_name_appeared,
                                      self._on_dbus_name_vanished)

        self._any_adapter = AnyAdapter()
        self._any_adapter.connect_signal('property-changed',
                                         self._on_adapter_property_changed)

        self._any_device = AnyDevice()
        self._any_device.connect_signal('property-changed',
                                        self._on_device_property_changed)

    def do_activate(self):
        if not self._active:
            self.hold()
            self._active = True

    def _on_dbus_name_appeared(self, _connection, name, owner):
        logging.info(f"{name} {owner}")
        self.manager_state = True
        self.plugin_run_state_changed = True
        self.Plugins.run("on_manager_state_changed", self.manager_state)

    def _on_dbus_name_vanished(self, _connection, name):
        logging.info(name)
        self.manager_state = False
        self.plugin_run_state_changed = True
        self.Plugins.run("on_manager_state_changed", self.manager_state)

    def _on_adapter_property_changed(self, _adapter, key, value, path):
        self.Plugins.run("on_adapter_property_changed", path, key, value)

    def _on_device_property_changed(self, _device, key, value, path):
        self.Plugins.run("on_device_property_changed", path, key, value)

    def on_adapter_added(self, _manager, path):
        logging.info(f"Adapter added {path}")
        self.Plugins.run("on_adapter_added", path)

    def on_adapter_removed(self, _manager, path):
        logging.info(f"Adapter removed {path}")
        self.Plugins.run("on_adapter_removed", path)

    def on_device_created(self, _manager, path):
        logging.info(f"Device created {path}")
        self.Plugins.run("on_device_created", path)

    def on_device_removed(self, _manager, path):
        logging.info(f"Device removed {path}")
        self.Plugins.run("on_device_removed", path)
Пример #6
0
class BluemanApplet(object):
    def __init__(self):
        setup_icon_path()

        check_single_instance("blueman-applet")

        self.plugin_run_state_changed = False
        self.manager_state = False

        self.Manager = Manager()
        self.Manager.connect_signal('adapter-added', self.on_adapter_added)
        self.Manager.connect_signal('adapter-removed', self.on_adapter_removed)
        self.Manager.connect_signal('device-created', self.on_device_created)
        self.Manager.connect_signal('device-removed', self.on_device_removed)

        self.DbusSvc = DbusService("org.blueman.Applet", "org.blueman.Applet",
                                   "/org/blueman/applet", Gio.BusType.SESSION)

        self.Plugins = PersistentPluginManager(AppletPlugin,
                                               blueman.plugins.applet, self)
        self.Plugins.load_plugin()

        self.Plugins.run("on_plugins_loaded")

        self.Manager.watch_name_owner(self._on_dbus_name_appeared,
                                      self._on_dbus_name_vanished)

        self._any_adapter = AnyAdapter()
        self._any_adapter.connect_signal('property-changed',
                                         self._on_adapter_property_changed)

        self._any_device = AnyDevice()
        self._any_device.connect_signal('property-changed',
                                        self._on_device_property_changed)

        self.DbusSvc.register()

        Gtk.main()

    def _on_dbus_name_appeared(self, _connection, name, owner):
        logging.info("%s %s" % (name, owner))
        self.manager_state = True
        self.plugin_run_state_changed = True
        self.Plugins.run("on_manager_state_changed", self.manager_state)

    def _on_dbus_name_vanished(self, _connection, name):
        logging.info(name)
        self.manager_state = False
        self.plugin_run_state_changed = True
        self.Plugins.run("on_manager_state_changed", self.manager_state)

    def _on_adapter_property_changed(self, _adapter, key, value, path):
        self.Plugins.run("on_adapter_property_changed", path, key, value)

    def _on_device_property_changed(self, _device, key, value, path):
        self.Plugins.run("on_device_property_changed", path, key, value)

    def on_adapter_added(self, _manager, path):
        logging.info("Adapter added %s" % path)
        self.Plugins.run("on_adapter_added", path)

    def on_adapter_removed(self, _manager, path):
        logging.info("Adapter removed %s" % path)
        self.Plugins.run("on_adapter_removed", path)

    def on_device_created(self, _manager, path):
        logging.info("Device created %s" % path)
        self.Plugins.run("on_device_created", path)

    def on_device_removed(self, _manager, path):
        logging.info("Device removed %s" % path)
        self.Plugins.run("on_device_removed", path)