Example #1
0
    def do_startup(self):
        Gtk.Application.do_startup(self)

        debug = False
        if len(sys.argv) > 1 and sys.argv[1] == "debug":
            debug = True

        self.rfkill = rfkillMagic.Interface(self.update_icon_callback, debug)
        self.settings = Gio.Settings("org.blueberry")
        self.settings.connect("changed::tray-enabled", self.on_settings_changed_cb)

        # If we have no adapter, or disabled tray, end early
        if (not self.rfkill.have_adapter) or (not self.settings.get_boolean("tray-enabled")):
            self.rfkill.terminate()
            sys.exit(0)

        self.client = GnomeBluetooth.Client()
        self.model = self.client.get_model()
        self.model.connect('row-changed', self.update_icon_callback)
        self.model.connect('row-deleted', self.update_icon_callback)
        self.model.connect('row-inserted', self.update_icon_callback)

        self.icon = Gtk.StatusIcon()
        self.icon.set_title(_("Bluetooth"))
        self.icon.connect("popup-menu", self.on_popup_menu)
        self.icon.connect("activate", self.on_activate)

        self.update_icon_callback(None, None, None)
Example #2
0
    def do_startup(self):
        Gtk.Application.do_startup(self)

        debug = False
        if len(sys.argv) > 1 and sys.argv[1] == "debug":
            debug = True

        self.rfkill = rfkillMagic.Interface(self.update_icon_callback, debug)
        self.settings = Gio.Settings(schema="org.blueberry")
        self.settings.connect("changed::tray-enabled",
                              self.on_settings_changed_cb)

        # If we have no adapter, or disabled tray, end early
        if (not self.rfkill.have_adapter) or (
                not self.settings.get_boolean("tray-enabled")):
            self.rfkill.terminate()
            sys.exit(0)

        self.client = GnomeBluetooth.Client()
        self.model = self.client.get_model()
        self.model.connect('row-changed', self.update_icon_callback)
        self.model.connect('row-deleted', self.update_icon_callback)
        self.model.connect('row-inserted', self.update_icon_callback)

        self.icon = XApp.StatusIcon()
        self.icon.set_name("blueberry")
        self.icon.set_tooltip_text(_("Bluetooth"))
        self.icon.connect("button-press-event", self.on_statusicon_pressed)
        self.icon.connect("button-release-event", self.on_statusicon_released)

        self.update_icon_callback(None, None, None)
Example #3
0
    def create_window(self):

        self.window.set_title(_("Bluetooth"))
        self.window.set_icon_name("bluetooth")
        self.window.set_default_size(640, 400)

        self.main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)

        # Toolbar
        toolbar = Gtk.Toolbar()
        toolbar.get_style_context().add_class("primary-toolbar")
        self.main_box.pack_start(toolbar, False, False, 0)

        self.main_stack = Gtk.Stack()
        self.main_stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
        self.main_stack.set_transition_duration(150)
        self.main_box.pack_start(self.main_stack, True, True, 0)

        stack_switcher = Gtk.StackSwitcher()
        stack_switcher.set_stack(self.main_stack)

        tool_item = Gtk.ToolItem()
        tool_item.set_expand(True)
        tool_item.get_style_context().add_class("raised")
        toolbar.insert(tool_item, 0)
        switch_holder = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        switch_holder.set_border_width(1)
        tool_item.add(switch_holder)
        switch_holder.pack_start(stack_switcher, True, True, 0)
        stack_switcher.set_halign(Gtk.Align.CENTER)
        toolbar.show_all()

        self.settings = Gio.Settings(schema="org.blueberry")

        debug = False
        if len(sys.argv) > 1 and sys.argv[1] == "debug":
            debug = True

        # Devices
        self.devices_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.devices_box.set_border_width(12)

        self.rf_switch = Gtk.Switch()
        self.rfkill = rfkillMagic.Interface(self.update_ui_callback, debug)
        self.rf_handler_id = self.rf_switch.connect("state-set", self.on_switch_changed)

        self.status_image = Gtk.Image()
        self.status_image.set_from_icon_name("blueberry", Gtk.IconSize.DIALOG)
        self.status_image.show()

        self.stack = Gtk.Stack()
        self.error_label = self.add_stack_page(_("An error has occurred"), BLUETOOTH_RFKILL_ERR);
        self.add_stack_page(_("Bluetooth is disabled"), BLUETOOTH_DISABLED_PAGE);
        self.add_stack_page(_("No Bluetooth adapters found"), BLUETOOTH_NO_DEVICES_PAGE);
        self.add_stack_page(_("Bluetooth is disabled by hardware switch"), BLUETOOTH_HW_DISABLED_PAGE);

        self.lib_widget = GnomeBluetooth.SettingsWidget.new();
        self.lib_widget.connect("panel-changed", self.panel_changed);
        self.stack.add_named(self.lib_widget, BLUETOOTH_WORKING_PAGE)
        self.lib_widget.show()
        self.stack.show();

        switchbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        hbox.pack_end(self.rf_switch, False, False, 10)
        switchbox.pack_start(hbox, False, False, 0)
        switchbox.pack_start(self.status_image, False, False, 0)
        switchbox.show_all()

        self.devices_box.pack_start(switchbox, False, False, 0)
        self.devices_box.pack_start(self.stack, True, True, 0)

        self.main_stack.add_titled(self.devices_box, "devices", _("Devices"))

        # Settings

        page = SettingsPage()

        section = page.add_section(_("Bluetooth settings"))
        self.adapter_name_entry = Gtk.Entry()
        adapter_name = self.get_default_adapter_name()
        if adapter_name is not None:
            self.adapter_name_entry.set_text(adapter_name)
        self.adapter_name_entry.connect("changed", self.on_adapter_name_changed)
        row = SettingsRow(Gtk.Label(label=_("Name")), self.adapter_name_entry)
        row.set_tooltip_text(_("This is the Bluetooth name of your computer"))
        section.add_row(row)

        self.obex_switch = Gtk.Switch()
        self.obex_switch.set_active(self.settings.get_boolean("obex-enabled"))
        self.obex_switch.connect("notify::active", self.on_obex_switch_toggled)
        self.settings.connect("changed", self.on_settings_changed)
        row = SettingsRow(Gtk.Label(label=_("Receive files from remote devices")), self.obex_switch)
        row.set_tooltip_text(_("This option allows your computer to receive files transferred over Bluetooth (OBEX)"))
        section.add_row(row)

        self.tray_switch = Gtk.Switch()
        self.tray_switch.set_active(self.settings.get_boolean("tray-enabled"))
        self.tray_switch.connect("notify::active", self.on_tray_switch_toggled)
        self.settings.connect("changed", self.on_settings_changed)
        section.add_row(SettingsRow(Gtk.Label(label=_("Show a tray icon")), self.tray_switch))

        self.window.add(self.main_box)

        self.main_stack.add_titled(page, "settings", _("Settings"))

        self.devices_box.show_all()

        self.update_ui_callback()

        self.add_window(self.window)
        self.window.show_all()

        self.client = GnomeBluetooth.Client()
        self.model = self.client.get_model()
        self.model.connect('row-changed', self.update_status)
        self.model.connect('row-deleted', self.update_status)
        self.model.connect('row-inserted', self.update_status)
        self.update_status()
Example #4
0
    def do_activate(self):
        if self.settings.get_boolean("tray-enabled"):
            subprocess.Popen(['blueberry-tray'])

        if len(self.get_windows()) > 0:
            # Blueberry is already running, focus the window
            self.get_active_window().present()
            return

        builder = Gtk.Builder.new_from_file(
            os.path.join(SCRIPT_DIR, "blueberry.ui"))

        window = builder.get_object("window")
        window.set_title(_("Bluetooth"))

        builder.get_object("settings-button").set_tooltip_text(_("Settings"))

        self.stack = builder.get_object("stack")

        debug = False
        if len(sys.argv) > 1 and sys.argv[1] == "debug":
            debug = True

        self.header_icon = builder.get_object("header-icon")
        self.status_icon = builder.get_object("status-icon")
        self.status_label = builder.get_object("status-label")

        # Devices
        self.rf_switch = builder.get_object("bluetooth-switch")
        self.rfkill = rfkillMagic.Interface(self.update_ui_callback, debug)
        self.rf_handler_id = self.rf_switch.connect("state-set",
                                                    self.on_switch_changed)

        self.rfkill_error_image = builder.get_object("rfkill-error-image")

        # Settings
        settings_box = SettingsBox()
        settings_container = builder.get_object("settings-container")
        settings_container.pack_start(settings_box, True, True, 0)

        self.adapter_name_entry = Gtk.Entry(width_chars=30)
        self.adapter_name_entry.connect("focus-out-event",
                                        self.update_name_from_entry)
        self.adapter_name_entry.connect("activate",
                                        self.update_name_from_entry)
        self.adapter_name_entry.set_sensitive(False)
        self.adapter_name_entry.set_placeholder_text(
            _("Enable Bluetooth to edit"))
        row = SettingsRow(Gtk.Label(label=_("Name")), self.adapter_name_entry)
        row.set_tooltip_text(_("This is the Bluetooth name of your computer"))
        settings_box.add_row(row)

        self.obex_switch = Gtk.Switch()
        self.obex_switch.set_active(self.settings.get_boolean("obex-enabled"))
        self.obex_switch.connect("notify::active", self.on_obex_switch_toggled)
        self.settings.connect("changed", self.on_settings_changed)
        row = SettingsRow(
            Gtk.Label(label=_("Receive files from remote devices")),
            self.obex_switch)
        row.set_tooltip_text(
            _("This option allows your computer to receive files transferred over Bluetooth (OBEX)"
              ))
        settings_box.add_row(row)

        self.tray_switch = Gtk.Switch()
        self.tray_switch.set_active(self.settings.get_boolean("tray-enabled"))
        self.tray_switch.connect("notify::active", self.on_tray_switch_toggled)
        self.settings.connect("changed", self.on_settings_changed)
        settings_box.add_row(
            SettingsRow(Gtk.Label(label=_("Show a tray icon")),
                        self.tray_switch))

        settings_box.show_all()

        self.lib_widget = GnomeBluetooth.SettingsWidget.new()
        self.lib_widget.connect("panel-changed", self.panel_changed)
        builder.get_object("bluetooth-widget-box").pack_start(
            self.lib_widget, True, True, 0)

        self.add_window(window)
        window.show_all()
        self.update_ui_callback()

        # attempt to apply overrides and if we fail don't setup update hooks
        if self.get_label_widget_and_spinner(self.lib_widget):
            self.label_widget.set_text("")
            self.client = GnomeBluetooth.Client()
            self.model = self.client.get_model()
            self.model.connect('row-changed', self.on_adapter_status_changed)
            self.model.connect('row-deleted', self.on_adapter_status_changed)
            self.model.connect('row-inserted', self.on_adapter_status_changed)
            self.on_adapter_status_changed(self.lib_widget)