summaryrefslogtreecommitdiffstats
path: root/panels/bluetooth
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:45:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:45:20 +0000
commitae1c76ff830d146d41e88d6fba724c0a54bce868 (patch)
tree3c354bec95af07be35fc71a4b738268496f1a1c4 /panels/bluetooth
parentInitial commit. (diff)
downloadgnome-control-center-ae1c76ff830d146d41e88d6fba724c0a54bce868.tar.xz
gnome-control-center-ae1c76ff830d146d41e88d6fba724c0a54bce868.zip
Adding upstream version 1:43.6.upstream/1%43.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'panels/bluetooth')
-rwxr-xr-xpanels/bluetooth/bluetooth-panel-scenario-tester.py226
-rw-r--r--panels/bluetooth/bluetooth.gresource.xml6
-rw-r--r--panels/bluetooth/cc-bluetooth-panel.c269
-rw-r--r--panels/bluetooth/cc-bluetooth-panel.h34
-rw-r--r--panels/bluetooth/cc-bluetooth-panel.ui69
-rw-r--r--panels/bluetooth/dbusmock-templates/gsd_rfkill.py75
-rw-r--r--panels/bluetooth/gnome-bluetooth-panel.desktop.in.in18
-rw-r--r--panels/bluetooth/icons/meson.build4
-rw-r--r--panels/bluetooth/icons/scalable/org.gnome.Settings-bluetooth-symbolic.svg4
-rw-r--r--panels/bluetooth/meson.build41
10 files changed, 746 insertions, 0 deletions
diff --git a/panels/bluetooth/bluetooth-panel-scenario-tester.py b/panels/bluetooth/bluetooth-panel-scenario-tester.py
new file mode 100755
index 0000000..45b021c
--- /dev/null
+++ b/panels/bluetooth/bluetooth-panel-scenario-tester.py
@@ -0,0 +1,226 @@
+#!/usr/bin/env python3
+
+# Copyright (C) 2021 Red Hat Inc.
+#
+# Author: Bastien Nocera <hadess@hadess.net>
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+import dbus
+import sys
+import os
+import fcntl
+import gi
+import subprocess
+import time
+from collections import OrderedDict
+from dbusmock import DBusTestCase, mockobject
+from dbus.mainloop.glib import DBusGMainLoop
+from consolemenu import *
+from consolemenu.items import *
+
+from gi.repository import Gio
+from gi.repository import GLib
+
+DBusGMainLoop(set_as_default=True)
+
+
+def set_nonblock(fd):
+ '''Set a file object to non-blocking'''
+ flags = fcntl.fcntl(fd, fcntl.F_GETFL)
+ fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
+
+def get_templates_dir():
+ return os.path.join(os.path.dirname(__file__), 'dbusmock-templates')
+
+def get_template_path(template_name):
+ return os.path.join(get_templates_dir(), template_name + '.py')
+
+class GccDBusTestCase(DBusTestCase):
+ @classmethod
+ def setUpClass(klass):
+ klass.mocks = OrderedDict()
+
+ # Start system bus
+ DBusTestCase.setUpClass()
+ klass.test_bus = Gio.TestDBus.new(Gio.TestDBusFlags.NONE)
+ klass.test_bus.up()
+ os.environ['DBUS_SYSTEM_BUS_ADDRESS'] = klass.test_bus.get_bus_address()
+
+ # Start session bus
+ klass.session_test_bus = Gio.TestDBus.new(Gio.TestDBusFlags.NONE)
+ klass.session_test_bus.up()
+ os.environ['DBUS_SESSION_BUS_ADDRESS'] = klass.session_test_bus.get_bus_address()
+
+ # process = subprocess.Popen(['gdbus', 'monitor', '--session', '--dest', 'org.gnome.SettingsDaemon.Rfkill'])
+ # process = subprocess.Popen(['gdbus', 'monitor', '--system', '--dest', 'org.bluez'])
+
+ # Start bluez and gsd-rfkill
+ klass.start_from_template('bluez5')
+ klass.start_from_local_template(
+ 'gsd_rfkill', {'templates-dir': get_templates_dir()})
+
+ klass.system_bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
+
+ @classmethod
+ def tearDownClass(klass):
+ for (mock_server, mock_obj) in reversed(klass.mocks.values()):
+ mock_server.terminate()
+ mock_server.wait()
+
+ DBusTestCase.tearDownClass()
+
+ @classmethod
+ def start_from_template(klass, template, params={}):
+ mock_server, mock_obj = \
+ klass.spawn_server_template(template,
+ params,
+ stdout=subprocess.PIPE)
+ set_nonblock(mock_server.stdout)
+
+ mocks = (mock_server, mock_obj)
+ assert klass.mocks.setdefault(template, mocks) == mocks
+ return mocks
+
+ @classmethod
+ def start_from_local_template(klass, template_file_name, params={}):
+ template = get_template_path(template_file_name)
+ ret = klass.start_from_template(template, params)
+ klass.mocks.setdefault(template_file_name, ret)
+ return ret
+
+ def __init__(self):
+ self.devices = {}
+ self.rfkill = self.mocks['gsd_rfkill'][1]
+
+ self.bluez_mock = self.mocks['bluez5'][1]
+ self.hci0_powered = True
+ self.hci0_plugged_in = True
+ self.add_adapter()
+ bus = dbus.SystemBus()
+ self.hci0_props = dbus.Interface(bus.get_object('org.bluez', '/org/bluez/hci0'), 'org.freedesktop.DBus.Properties')
+
+ def adapter_exists(self):
+ try:
+ self.get_dbus(True).get_object('org.bluez', '/org/bluez/hci0').Get('org.bluez.Adapter1', 'Name')
+ except:
+ return False
+ return True
+
+ def add_adapter(self):
+ if self.adapter_exists():
+ return
+ self.bluez_mock.AddAdapter('hci0', 'hci0')
+ adapter = self.get_dbus(True).get_object('org.bluez', '/org/bluez/hci0')
+ adapter.AddProperties('org.bluez.Adapter1',
+ {'Blocked': dbus.Boolean(not self.hci0_powered, variant_level=1)})
+ adapter.UpdateProperties('org.bluez.Adapter1',
+ {'Powered': dbus.Boolean(self.hci0_powered, variant_level=1)})
+ self.devices = []
+ self.add_device('hci0', '22:33:44:55:66:77', "Bastienʼs mouse", True, 0x580, 'input-mouse')
+ self.add_device('hci0', '22:33:44:55:66:78', 'Bloutouf keyboard & keys', True, 0x540, 'input-keyboard')
+ self.add_device('hci0', '60:8B:0E:55:66:79', 'iPhoone 19S', True, 0x20C, 'phone')
+ # Uncategorised audio device
+ self.add_device('hci0', '22:33:44:55:66:79', 'MEGA Speakers', True, 0x200400, 'audio-card')
+ self.add_device('hci0', '22:33:44:55:66:80', 'Ski-bi dibby dib yo da dub dub Yo da dub dub Ski-bi dibby dib yo da dub dub Yo da dub dub (I\'m the Scatman) Ski-bi dibby dib yo da dub dub Yo da dub dub Ski-bi dibby dib yo da dub dub Yo da dub dub Ba-da-ba-da-ba-be bop bop bodda bope Bop ba bodda bope Be bop ba bodda bope Bop ba bodda Ba-da-ba-da-ba-be bop ba bodda bope Bop ba bodda bope Be bop ba bodda bope Bop ba bodda bope', True, 0x80C, '')
+ self.rfkill.Set('org.gnome.SettingsDaemon.Rfkill', 'BluetoothHasAirplaneMode', dbus.Boolean(True))
+
+ def remove_adapter(self):
+ if not self.adapter_exists():
+ return
+ for dev in self.devices:
+ adapter = self.get_dbus(True).get_object('org.bluez', '/org/bluez/hci0')
+ adapter.RemoveDevice(dev)
+ self.devices = []
+ self.bluez_mock.RemoveAdapter('hci0')
+ if self.rfkill.Get('org.gnome.SettingsDaemon.Rfkill', 'BluetoothHardwareAirplaneMode') == 0:
+ self.rfkill.Set('org.gnome.SettingsDaemon.Rfkill', 'BluetoothHasAirplaneMode', dbus.Boolean(False))
+
+ def add_device(self, adapter, address, name, paired, klass, icon):
+ dev_path = self.bluez_mock.AddDevice(adapter, address, name)
+ dev = self.get_dbus(True).get_object('org.bluez', str(dev_path))
+ dev.UpdateProperties('org.bluez.Device1',
+ {'Paired': dbus.Boolean(paired, variant_level=1),
+ 'Class': dbus.UInt32(klass, variant_level=1),
+ 'Icon': dbus.String(icon, variant_level=1)})
+ self.devices.append(dev)
+
+ def get_rfkill_prop(self, prop_name):
+ return self.rfkill.Get('org.gnome.SettingsDaemon.Rfkill', prop_name)
+
+ def toggle_hw_rfkill(self):
+ if self.rfkill.Get('org.gnome.SettingsDaemon.Rfkill', 'BluetoothHardwareAirplaneMode') == 0:
+ self.rfkill.Set('org.gnome.SettingsDaemon.Rfkill', 'BluetoothHardwareAirplaneMode', dbus.Boolean(True))
+ if self.adapter_exists():
+ self.remove_adapter()
+ else:
+ self.rfkill.Set('org.gnome.SettingsDaemon.Rfkill', 'BluetoothHardwareAirplaneMode', dbus.Boolean(False))
+ if not self.adapter_exists():
+ self.add_adapter()
+
+ def set_unpowered(self):
+ if self.hci0_powered:
+ print('hci0 will now default to unpowered')
+ self.hci0_powered = False
+ else:
+ print('hci0 will now default to powered')
+ self.hci0_powered = True
+
+ def unplug_default_adapter(self):
+ if self.hci0_plugged_in:
+ print('default adapter is unplugged')
+ self.hci0_plugged_in = False
+ self.remove_adapter()
+ else:
+ print('default adapter is plugged in')
+ self.hci0_plugged_in = True
+ self.add_adapter()
+
+ def toggle_airplane_mode(self):
+ if self.rfkill.Get('org.gnome.SettingsDaemon.Rfkill', 'AirplaneMode') == 0:
+ self.rfkill.Set('org.gnome.SettingsDaemon.Rfkill', 'AirplaneMode', dbus.Boolean(True))
+ self.rfkill.Set('org.gnome.SettingsDaemon.Rfkill', 'BluetoothAirplaneMode', dbus.Boolean(True))
+ else:
+ self.rfkill.Set('org.gnome.SettingsDaemon.Rfkill', 'AirplaneMode', dbus.Boolean(False))
+ self.rfkill.Set('org.gnome.SettingsDaemon.Rfkill', 'BluetoothAirplaneMode', dbus.Boolean(False))
+
+ def start_menu(self):
+ menu = ConsoleMenu("Bluetooth Panel", "Scenario Tester", clear_screen = False)
+ function_item = FunctionItem("Toggle Bluetooth hardware rfkill", self.toggle_hw_rfkill)
+ menu.append_item(function_item)
+
+ function_item = FunctionItem("Toggle default adapter unpowered", self.set_unpowered)
+ menu.append_item(function_item)
+
+ function_item = FunctionItem("Unplug/plug default adapter", self.unplug_default_adapter)
+ menu.append_item(function_item)
+
+ function_item = FunctionItem("Toggle airplane mode", self.toggle_airplane_mode)
+ menu.append_item(function_item)
+
+ menu.start(show_exit_option=False)
+
+ def wrap_call(self):
+ os.environ['GSETTINGS_BACKEND'] = 'memory'
+
+ wrapper = os.environ.get('META_DBUS_RUNNER_WRAPPER')
+ args = ['gnome-control-center', '-v', 'bluetooth']
+ if wrapper == 'gdb':
+ args = ['gdb', '-ex', 'r', '-ex', 'bt full', '--args'] + args
+ elif wrapper:
+ args = wrapper.split(' ') + args
+
+ p = subprocess.Popen(args, env=os.environ)
+ p.wait()
+
+if __name__ == '__main__':
+ #if 'umockdev' not in os.environ.get('LD_PRELOAD', ''):
+ # os.execvp('umockdev-wrapper', ['umockdev-wrapper'] + sys.argv)
+
+ GccDBusTestCase.setUpClass()
+ test_case = GccDBusTestCase()
+ test_case.start_menu()
+ try:
+ test_case.wrap_call()
+ finally:
+ GccDBusTestCase.tearDownClass()
diff --git a/panels/bluetooth/bluetooth.gresource.xml b/panels/bluetooth/bluetooth.gresource.xml
new file mode 100644
index 0000000..75b960a
--- /dev/null
+++ b/panels/bluetooth/bluetooth.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/control-center/bluetooth">
+ <file preprocess="xml-stripblanks">cc-bluetooth-panel.ui</file>
+ </gresource>
+</gresources>
diff --git a/panels/bluetooth/cc-bluetooth-panel.c b/panels/bluetooth/cc-bluetooth-panel.c
new file mode 100644
index 0000000..175e365
--- /dev/null
+++ b/panels/bluetooth/cc-bluetooth-panel.c
@@ -0,0 +1,269 @@
+/*
+ *
+ * Copyright (C) 2013 Bastien Nocera <hadess@hadess.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <adwaita.h>
+
+#include <shell/cc-shell.h>
+#include <shell/cc-object-storage.h>
+#include <bluetooth-settings-widget.h>
+
+#include "cc-bluetooth-panel.h"
+#include "cc-bluetooth-resources.h"
+
+struct _CcBluetoothPanel {
+ CcPanel parent_instance;
+
+ AdwStatusPage *airplane_page;
+ AdwStatusPage *disabled_page;
+ GtkSwitch *enable_switch;
+ GtkBox *header_box;
+ AdwStatusPage *hw_airplane_page;
+ AdwStatusPage *no_devices_page;
+ BluetoothSettingsWidget *settings_widget;
+ GtkStack *stack;
+
+ /* Killswitch */
+ GDBusProxy *rfkill;
+ GDBusProxy *properties;
+ gboolean airplane_mode;
+ gboolean bt_airplane_mode;
+ gboolean hardware_airplane_mode;
+ gboolean has_airplane_mode;
+};
+
+CC_PANEL_REGISTER (CcBluetoothPanel, cc_bluetooth_panel)
+
+static const char *
+cc_bluetooth_panel_get_help_uri (CcPanel *panel)
+{
+ return "help:gnome-help/bluetooth";
+}
+
+static void
+cc_bluetooth_panel_finalize (GObject *object)
+{
+ CcBluetoothPanel *self;
+
+ self = CC_BLUETOOTH_PANEL (object);
+
+ g_clear_object (&self->properties);
+ g_clear_object (&self->rfkill);
+
+ G_OBJECT_CLASS (cc_bluetooth_panel_parent_class)->finalize (object);
+}
+
+static void
+airplane_mode_changed_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ g_autoptr(GVariant) ret = NULL;
+ g_autoptr(GError) error = NULL;
+ gboolean state = GPOINTER_TO_UINT (user_data);
+
+ if (!g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object),
+ res, &error)) {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("Failed to change Bluetooth killswitch state to %s: %s",
+ state ? "on" : "off", error->message);
+ } else {
+ CcBluetoothPanel *self = user_data;
+
+ g_debug ("Changed Bluetooth killswitch state to %s",
+ state ? "on" : "off");
+
+ if (!bluetooth_settings_widget_get_default_adapter_powered (self->settings_widget))
+ bluetooth_settings_widget_set_default_adapter_powered(self->settings_widget, TRUE);
+ }
+}
+
+static void
+enable_switch_state_set_cb (CcBluetoothPanel *self, gboolean state)
+{
+ g_debug ("Power switched to %s", state ? "on" : "off");
+ g_dbus_proxy_call (self->properties,
+ "Set",
+ g_variant_new_parsed ("('org.gnome.SettingsDaemon.Rfkill', 'BluetoothAirplaneMode', %v)",
+ g_variant_new_boolean (!state)),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ cc_panel_get_cancellable (CC_PANEL (self)),
+ airplane_mode_changed_cb, self);
+}
+
+static void
+adapter_status_changed_cb (CcBluetoothPanel *self)
+{
+ GtkAlign valign;
+ gboolean sensitive, powered;
+ GtkWidget *page;
+
+ g_debug ("Updating airplane mode: BluetoothHasAirplaneMode %d, BluetoothHardwareAirplaneMode %d, BluetoothAirplaneMode %d, AirplaneMode %d",
+ self->has_airplane_mode, self->hardware_airplane_mode, self->bt_airplane_mode, self->airplane_mode);
+
+ valign = GTK_ALIGN_CENTER;
+
+ if (self->has_airplane_mode == FALSE) {
+ g_debug ("No Bluetooth available");
+ sensitive = FALSE;
+ powered = FALSE;
+ page = GTK_WIDGET (self->no_devices_page);
+ } else if (self->hardware_airplane_mode) {
+ g_debug ("Bluetooth is Hard blocked");
+ sensitive = FALSE;
+ powered = FALSE;
+ page = GTK_WIDGET (self->hw_airplane_page);
+ } else if (self->airplane_mode) {
+ g_debug ("Airplane mode is on, Wi-Fi and Bluetooth are disabled");
+ sensitive = FALSE;
+ powered = FALSE;
+ page = GTK_WIDGET (self->airplane_page);
+ } else if (self->bt_airplane_mode ||
+ !bluetooth_settings_widget_get_default_adapter_powered (self->settings_widget)) {
+ g_debug ("Default adapter is unpowered");
+ sensitive = TRUE;
+ powered = FALSE;
+ page = GTK_WIDGET (self->disabled_page);
+ } else {
+ g_debug ("Bluetooth is available and powered");
+ sensitive = TRUE;
+ powered = TRUE;
+ page = GTK_WIDGET (self->settings_widget);
+ valign = GTK_ALIGN_FILL;
+ }
+
+ gtk_widget_set_valign (GTK_WIDGET (self->stack), valign);
+ gtk_widget_set_sensitive (GTK_WIDGET (self->header_box), sensitive);
+ g_signal_handlers_block_by_func (self->enable_switch, enable_switch_state_set_cb, self);
+ gtk_switch_set_state (self->enable_switch, powered);
+ g_signal_handlers_unblock_by_func (self->enable_switch, enable_switch_state_set_cb, self);
+
+ gtk_stack_set_visible_child (self->stack, page);
+}
+
+static void
+airplane_mode_changed (CcBluetoothPanel *self)
+{
+ g_autoptr(GVariant) airplane_mode = NULL;
+ g_autoptr(GVariant) bluetooth_airplane_mode = NULL;
+ g_autoptr(GVariant) bluetooth_hardware_airplane_mode = NULL;
+ g_autoptr(GVariant) bluetooth_has_airplane_mode = NULL;
+
+ airplane_mode = g_dbus_proxy_get_cached_property (self->rfkill, "AirplaneMode");
+ self->airplane_mode = g_variant_get_boolean (airplane_mode);
+
+ bluetooth_airplane_mode = g_dbus_proxy_get_cached_property (self->rfkill, "BluetoothAirplaneMode");
+ self->bt_airplane_mode = g_variant_get_boolean (bluetooth_airplane_mode);
+
+ bluetooth_hardware_airplane_mode = g_dbus_proxy_get_cached_property (self->rfkill, "BluetoothHardwareAirplaneMode");
+ g_message ("BluetoothHardwareAirplaneMode: %d", self->hardware_airplane_mode);
+ self->hardware_airplane_mode = g_variant_get_boolean (bluetooth_hardware_airplane_mode);
+
+ bluetooth_has_airplane_mode = g_dbus_proxy_get_cached_property (self->rfkill, "BluetoothHasAirplaneMode");
+ self->has_airplane_mode = g_variant_get_boolean (bluetooth_has_airplane_mode);
+
+ adapter_status_changed_cb (self);
+}
+
+static void
+airplane_mode_off_button_clicked_cb (CcBluetoothPanel *self)
+{
+ g_debug ("Airplane Mode Off clicked, disabling airplane mode");
+ g_dbus_proxy_call (self->rfkill,
+ "org.freedesktop.DBus.Properties.Set",
+ g_variant_new_parsed ("('org.gnome.SettingsDaemon.Rfkill',"
+ "'AirplaneMode', %v)",
+ g_variant_new_boolean (FALSE)),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ cc_panel_get_cancellable (CC_PANEL (self)),
+ NULL, NULL);
+}
+
+static void
+panel_changed_cb (CcBluetoothPanel *self,
+ const char *panel)
+{
+ CcShell *shell;
+ g_autoptr(GError) error = NULL;
+
+ shell = cc_panel_get_shell (CC_PANEL (self));
+ if (cc_shell_set_active_panel_from_id (shell, panel, NULL, &error) == FALSE)
+ g_warning ("Failed to activate '%s' panel: %s", panel, error->message);
+}
+
+static void
+cc_bluetooth_panel_class_init (CcBluetoothPanelClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ CcPanelClass *panel_class = CC_PANEL_CLASS (klass);
+
+ object_class->finalize = cc_bluetooth_panel_finalize;
+
+ panel_class->get_help_uri = cc_bluetooth_panel_get_help_uri;
+
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/bluetooth/cc-bluetooth-panel.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, CcBluetoothPanel, airplane_page);
+ gtk_widget_class_bind_template_child (widget_class, CcBluetoothPanel, disabled_page);
+ gtk_widget_class_bind_template_child (widget_class, CcBluetoothPanel, enable_switch);
+ gtk_widget_class_bind_template_child (widget_class, CcBluetoothPanel, header_box);
+ gtk_widget_class_bind_template_child (widget_class, CcBluetoothPanel, no_devices_page);
+ gtk_widget_class_bind_template_child (widget_class, CcBluetoothPanel, hw_airplane_page);
+ gtk_widget_class_bind_template_child (widget_class, CcBluetoothPanel, settings_widget);
+ gtk_widget_class_bind_template_child (widget_class, CcBluetoothPanel, stack);
+
+ gtk_widget_class_bind_template_callback (widget_class, adapter_status_changed_cb);
+ gtk_widget_class_bind_template_callback (widget_class, airplane_mode_off_button_clicked_cb);
+ gtk_widget_class_bind_template_callback (widget_class, enable_switch_state_set_cb);
+ gtk_widget_class_bind_template_callback (widget_class, panel_changed_cb);
+}
+
+static void
+cc_bluetooth_panel_init (CcBluetoothPanel *self)
+{
+ bluetooth_settings_widget_get_type ();
+ g_resources_register (cc_bluetooth_get_resource ());
+
+ gtk_widget_init_template (GTK_WIDGET (self));
+
+ /* RFKill */
+ self->rfkill = cc_object_storage_create_dbus_proxy_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.gnome.SettingsDaemon.Rfkill",
+ "/org/gnome/SettingsDaemon/Rfkill",
+ "org.gnome.SettingsDaemon.Rfkill",
+ NULL, NULL);
+ self->properties = cc_object_storage_create_dbus_proxy_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.gnome.SettingsDaemon.Rfkill",
+ "/org/gnome/SettingsDaemon/Rfkill",
+ "org.freedesktop.DBus.Properties",
+ NULL, NULL);
+
+ airplane_mode_changed (self);
+ g_signal_connect_object (self->rfkill, "g-properties-changed",
+ G_CALLBACK (airplane_mode_changed), self, G_CONNECT_SWAPPED);
+}
diff --git a/panels/bluetooth/cc-bluetooth-panel.h b/panels/bluetooth/cc-bluetooth-panel.h
new file mode 100644
index 0000000..2252cd2
--- /dev/null
+++ b/panels/bluetooth/cc-bluetooth-panel.h
@@ -0,0 +1,34 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org>
+ * Copyright (C) 2006-2010 Bastien Nocera <hadess@hadess.net>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#pragma once
+
+#include <shell/cc-shell.h>
+
+G_BEGIN_DECLS
+
+#define CC_TYPE_BLUETOOTH_PANEL (cc_bluetooth_panel_get_type ())
+G_DECLARE_FINAL_TYPE (CcBluetoothPanel, cc_bluetooth_panel, CC, BLUETOOTH_PANEL, CcPanel)
+
+G_END_DECLS
diff --git a/panels/bluetooth/cc-bluetooth-panel.ui b/panels/bluetooth/cc-bluetooth-panel.ui
new file mode 100644
index 0000000..94ad137
--- /dev/null
+++ b/panels/bluetooth/cc-bluetooth-panel.ui
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="CcBluetoothPanel" parent="CcPanel">
+
+ <child type="titlebar-end">
+ <object class="GtkBox" id="header_box">
+ <child>
+ <object class="GtkSwitch" id="enable_switch">
+ <property name="valign">center</property>
+ <accessibility>
+ <property name="label" translatable="yes">Enable</property>
+ </accessibility>
+ <signal name="state-set" handler="enable_switch_state_set_cb" object="CcBluetoothPanel" swapped="yes"/>
+ </object>
+ </child>
+ </object>
+ </child>
+
+ <child type="content">
+ <object class="GtkStack" id="stack">
+ <child>
+ <object class="AdwStatusPage" id="no_devices_page">
+ <property name="icon-name">bluetooth-active-symbolic</property>
+ <property name="title" translatable="yes">No Bluetooth Found</property>
+ <property name="description" translatable="yes">Plug in a dongle to use Bluetooth.</property>
+ </object>
+ </child>
+ <child>
+ <object class="AdwStatusPage" id="disabled_page">
+ <property name="icon-name">bluetooth-active-symbolic</property>
+ <property name="title" translatable="yes">Bluetooth Turned Off</property>
+ <property name="description" translatable="yes">Turn on to connect devices and receive file transfers.</property>
+ </object>
+ </child>
+ <child>
+ <object class="AdwStatusPage" id="airplane_page">
+ <property name="icon-name">airplane-mode-symbolic</property>
+ <property name="title" translatable="yes">Airplane Mode is On</property>
+ <property name="description" translatable="yes">Bluetooth is disabled when airplane mode is on.</property>
+ <property name="child">
+ <object class="GtkButton">
+ <property name="label" translatable="yes">Turn Off Airplane Mode</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <signal name="clicked" handler="airplane_mode_off_button_clicked_cb" object="CcBluetoothPanel" swapped="yes"/>
+ <style>
+ <class name="pill"/>
+ </style>
+ </object>
+ </property>
+ </object>
+ </child>
+ <child>
+ <object class="AdwStatusPage" id="hw_airplane_page">
+ <property name="icon-name">airplane-mode-symbolic</property>
+ <property name="title" translatable="yes">Hardware Airplane Mode is On</property>
+ <property name="description" translatable="yes">Turn off the Airplane mode switch to enable Bluetooth.</property>
+ </object>
+ </child>
+ <child>
+ <object class="BluetoothSettingsWidget" id="settings_widget">
+ <signal name="panel-changed" handler="panel_changed_cb" object="CcBluetoothPanel" swapped="yes"/>
+ <signal name="adapter-status-changed" handler="adapter_status_changed_cb" object="CcBluetoothPanel" swapped="yes"/>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/panels/bluetooth/dbusmock-templates/gsd_rfkill.py b/panels/bluetooth/dbusmock-templates/gsd_rfkill.py
new file mode 100644
index 0000000..1a57b4c
--- /dev/null
+++ b/panels/bluetooth/dbusmock-templates/gsd_rfkill.py
@@ -0,0 +1,75 @@
+'''gsd-rfkill mock template
+
+This creates the expected methods and properties of the main
+org.gnome.SettingsDaemon.Rfkill object.
+'''
+
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 3 of the License, or (at your option) any
+# later version. See http://www.gnu.org/copyleft/lgpl.html for the full text
+# of the license.
+
+__author__ = 'Bastien Nocera'
+__copyright__ = '(c) 2022, Red Hat Inc.'
+
+import dbus
+import os
+from dbusmock import mockobject
+
+BUS_NAME = 'org.gnome.SettingsDaemon.Rfkill'
+MAIN_OBJ = '/org/gnome/SettingsDaemon/Rfkill'
+MAIN_IFACE = 'org.gnome.SettingsDaemon.Rfkill'
+SYSTEM_BUS = False
+
+ADAPTER_IFACE = 'org.bluez.Adapter1'
+
+def rfkill_changed(*args, **kwargs):
+ [iface, changed, _invalidated] = args
+
+ rfkill = mockobject.objects[MAIN_OBJ]
+ adapter = dbus.bus.BusConnection(os.environ['DBUS_SYSTEM_BUS_ADDRESS']).get_object('org.bluez', '/org/bluez/hci0')
+ try:
+ adapter.Get(ADAPTER_IFACE, 'Name')
+ except:
+ adapter = None
+
+ if 'BluetoothAirplaneMode' in changed:
+ if adapter and rfkill.props[MAIN_IFACE]['BluetoothAirplaneMode'] == 1:
+ adapter.UpdateProperties(ADAPTER_IFACE,
+ {'Powered': dbus.Boolean(False),
+ 'Blocked': dbus.Boolean(True)})
+ elif adapter:
+ adapter.UpdateProperties(ADAPTER_IFACE,
+ {'Blocked': dbus.Boolean(False)})
+ if 'BluetoothHardwareAirplaneMode' in changed:
+ if rfkill.props[MAIN_IFACE]['BluetoothAirplaneMode'] == 0:
+ rfkill.Set(MAIN_IFACE, 'BluetoothAirplaneMode', dbus.Boolean(False))
+
+def load(mock, parameters):
+ # Loaded!
+ mock.loaded = True
+
+ props = {
+ 'AirplaneMode': parameters.get('AirplaneMode', dbus.Boolean(False)),
+ 'HardwareAirplaneMode': parameters.get('HardwareAirplaneMode', dbus.Boolean(False)),
+ 'HasAirplaneMode': parameters.get('HasAirplaneMode', dbus.Boolean(True)),
+ # True if not desktop, server, vm or container
+ 'ShouldShowAirplaneMode': parameters.get('ShouldShowAirplaneMode', dbus.Boolean(True)),
+ 'BluetoothAirplaneMode': parameters.get('BluetoothAirplaneMode', dbus.Boolean(False)),
+ 'BluetoothHardwareAirplaneMode': parameters.get('BluetoothAirplaneMode', dbus.Boolean(False)),
+ 'BluetoothHasAirplaneMode': parameters.get('BluetoothHasAirplaneMode', dbus.Boolean(True)),
+ 'WwanAirplaneMode': parameters.get('WwanAirplaneMode', dbus.Boolean(False)),
+ 'WwanHardwareAirplaneMode': parameters.get('WwanHardwareAirplaneMode', dbus.Boolean(False)),
+ 'WwanHasAirplaneMode': parameters.get('WwanHasAirplaneMode', dbus.Boolean(False)),
+ }
+ mock.AddProperties(MAIN_IFACE, dbus.Dictionary(props, signature='sv'))
+
+ rfkill = mockobject.objects[MAIN_OBJ]
+ rfkill.hci0_power = True
+
+ session_bus = dbus.SessionBus()
+ session_bus.add_signal_receiver(rfkill_changed,
+ signal_name='PropertiesChanged',
+ path=MAIN_OBJ,
+ dbus_interface='org.freedesktop.DBus.Properties')
diff --git a/panels/bluetooth/gnome-bluetooth-panel.desktop.in.in b/panels/bluetooth/gnome-bluetooth-panel.desktop.in.in
new file mode 100644
index 0000000..4d81f07
--- /dev/null
+++ b/panels/bluetooth/gnome-bluetooth-panel.desktop.in.in
@@ -0,0 +1,18 @@
+[Desktop Entry]
+Name=Bluetooth
+Comment=Turn Bluetooth on and off and connect your devices
+# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
+Icon=org.gnome.Settings-bluetooth-symbolic
+Exec=gnome-control-center bluetooth
+Terminal=false
+Type=Application
+NoDisplay=true
+Categories=GTK;GNOME;Settings;X-GNOME-NetworkSettings;HardwareSettings;X-GNOME-Settings-Panel;X-GNOME-ConnectivitySettings;
+OnlyShowIn=GNOME;Unity;
+StartupNotify=true
+X-GNOME-Bugzilla-Bugzilla=GNOME
+X-GNOME-Bugzilla-Product=gnome-bluetooth
+X-GNOME-Bugzilla-Component=properties
+X-GNOME-Bugzilla-Version=@VERSION@
+# Translators: Search terms to find the Bluetooth panel. Do NOT translate or localize the semicolons! The list MUST also end with a semicolon!
+Keywords=share;sharing;bluetooth;obex;
diff --git a/panels/bluetooth/icons/meson.build b/panels/bluetooth/icons/meson.build
new file mode 100644
index 0000000..ffaee3f
--- /dev/null
+++ b/panels/bluetooth/icons/meson.build
@@ -0,0 +1,4 @@
+install_data(
+ 'scalable/org.gnome.Settings-bluetooth-symbolic.svg',
+ install_dir: join_paths(control_center_icondir, 'hicolor', 'scalable', 'apps')
+)
diff --git a/panels/bluetooth/icons/scalable/org.gnome.Settings-bluetooth-symbolic.svg b/panels/bluetooth/icons/scalable/org.gnome.Settings-bluetooth-symbolic.svg
new file mode 100644
index 0000000..f086eb3
--- /dev/null
+++ b/panels/bluetooth/icons/scalable/org.gnome.Settings-bluetooth-symbolic.svg
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg height="16px" viewBox="0 0 16 16" width="16px" xmlns="http://www.w3.org/2000/svg">
+ <path d="m 7.585938 0.0898438 c -0.355469 0.1640622 -0.585938 0.5195312 -0.585938 0.9101562 v 5.296875 l -2.34375 -2.046875 c -0.414062 -0.363281 -1.042969 -0.324219 -1.40625 0.089844 c -0.363281 0.417968 -0.324219 1.046875 0.09375 1.410156 l 2.566406 2.25 l -2.566406 2.25 c -0.417969 0.363281 -0.457031 0.992188 -0.09375 1.40625 c 0.363281 0.417969 0.992188 0.457031 1.40625 0.09375 l 2.34375 -2.046875 v 5.296875 c 0 0.390625 0.230469 0.746094 0.585938 0.910156 c 0.359374 0.160156 0.777343 0.101563 1.070312 -0.160156 l 4 -3.5 c 0.21875 -0.1875 0.34375 -0.460938 0.34375 -0.75 s -0.125 -0.5625 -0.34375 -0.75 l -3.140625 -2.75 l 3.140625 -2.75 c 0.21875 -0.1875 0.34375 -0.460938 0.34375 -0.75 s -0.125 -0.5625 -0.34375 -0.75 l -4 -3.5 c -0.292969 -0.2617188 -0.710938 -0.3242188 -1.070312 -0.1601562 z m 1.414062 3.1132812 l 1.484375 1.296875 l -1.484375 1.296875 z m 0 7 l 1.484375 1.296875 l -1.484375 1.296875 z m 0 0" fill="#2e3436"/>
+</svg>
diff --git a/panels/bluetooth/meson.build b/panels/bluetooth/meson.build
new file mode 100644
index 0000000..e5be2b4
--- /dev/null
+++ b/panels/bluetooth/meson.build
@@ -0,0 +1,41 @@
+panels_list += cappletname
+desktop = 'gnome-@0@-panel.desktop'.format(cappletname)
+
+desktop_in = configure_file(
+ input: desktop + '.in.in',
+ output: desktop + '.in',
+ configuration: desktop_conf
+)
+
+i18n.merge_file(
+ type: 'desktop',
+ input: desktop_in,
+ output: desktop,
+ po_dir: po_dir,
+ install: true,
+ install_dir: control_center_desktopdir
+)
+
+sources = files('cc-bluetooth-panel.c')
+
+resource_data = files('cc-bluetooth-panel.ui')
+
+sources += gnome.compile_resources(
+ 'cc-' + cappletname + '-resources',
+ cappletname + '.gresource.xml',
+ c_name: 'cc_' + cappletname,
+ dependencies: resource_data,
+ export: true
+)
+
+deps = common_deps + [gnome_bluetooth_dep]
+
+panels_libs += static_library(
+ cappletname,
+ sources: sources,
+ include_directories: top_inc,
+ dependencies: deps,
+ c_args: cflags
+)
+
+subdir('icons')