diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 14:36:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 14:36:24 +0000 |
commit | 9b6d8e63db85c30007b463e91f91a791969fa83f (patch) | |
tree | 0899af51d73c1bf986f73ae39a03c4436083018a /panels/bluetooth | |
parent | Initial commit. (diff) | |
download | gnome-control-center-9b6d8e63db85c30007b463e91f91a791969fa83f.tar.xz gnome-control-center-9b6d8e63db85c30007b463e91f91a791969fa83f.zip |
Adding upstream version 1:3.38.4.upstream/1%3.38.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'panels/bluetooth')
-rw-r--r-- | panels/bluetooth/bluetooth.gresource.xml | 6 | ||||
-rw-r--r-- | panels/bluetooth/cc-bluetooth-panel.c | 261 | ||||
-rw-r--r-- | panels/bluetooth/cc-bluetooth-panel.h | 34 | ||||
-rw-r--r-- | panels/bluetooth/cc-bluetooth-panel.ui | 200 | ||||
-rw-r--r-- | panels/bluetooth/gnome-bluetooth-panel.desktop.in.in | 18 | ||||
-rw-r--r-- | panels/bluetooth/meson.build | 40 |
6 files changed, 559 insertions, 0 deletions
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..5985ab0 --- /dev/null +++ b/panels/bluetooth/cc-bluetooth-panel.c @@ -0,0 +1,261 @@ +/* + * + * 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 <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; + + GtkBox *airplane_box; + GtkBox *disabled_box; + GtkSwitch *enable_switch; + GtkBox *header_box; + GtkBox *hw_airplane_box; + GtkBox *no_devices_box; + 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 +cc_bluetooth_panel_constructed (GObject *object) +{ + CcBluetoothPanel *self = CC_BLUETOOTH_PANEL (object); + + G_OBJECT_CLASS (cc_bluetooth_panel_parent_class)->constructed (object); + + /* add kill switch widgets */ + cc_shell_embed_widget_in_header (cc_panel_get_shell (CC_PANEL (self)), + GTK_WIDGET (self->header_box), GTK_POS_RIGHT); +} + +static void +enable_switch_changed_cb (CcBluetoothPanel *self) +{ + gboolean state; + + state = gtk_switch_get_active (self->enable_switch); + 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)), + NULL, NULL); +} + +static void +adapter_status_changed_cb (CcBluetoothPanel *self) +{ + GtkAlign valign; + gboolean sensitive, powered, change_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); + + change_powered = TRUE; + 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_box); + } else if (self->hardware_airplane_mode) { + g_debug ("Bluetooth is Hard blocked"); + sensitive = FALSE; + powered = FALSE; + page = GTK_WIDGET (self->hw_airplane_box); + } 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_box); + } else if (self->bt_airplane_mode || + !bluetooth_settings_widget_get_default_adapter_powered (self->settings_widget)) { + g_debug ("Default adapter is unpowered, but should be available"); + sensitive = TRUE; + change_powered = FALSE; + page = GTK_WIDGET (self->disabled_box); + } 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); + + if (change_powered) { + g_signal_handlers_block_by_func (self->enable_switch, enable_switch_changed_cb, self); + gtk_switch_set_active (self->enable_switch, powered); + g_signal_handlers_unblock_by_func (self->enable_switch, enable_switch_changed_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"); + 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->constructed = cc_bluetooth_panel_constructed; + 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_box); + gtk_widget_class_bind_template_child (widget_class, CcBluetoothPanel, disabled_box); + 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_box); + gtk_widget_class_bind_template_child (widget_class, CcBluetoothPanel, hw_airplane_box); + 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_changed_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..c4f36ce --- /dev/null +++ b/panels/bluetooth/cc-bluetooth-panel.ui @@ -0,0 +1,200 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <!-- interface-requires gtk+ 3.0 --> + <template class="CcBluetoothPanel" parent="CcPanel"> + <property name="visible">True</property> + <child> + <object class="GtkStack" id="stack"> + <property name="visible">True</property> + <child> + <object class="GtkBox" id="no_devices_box"> + <property name="visible">True</property> + <property name="orientation">vertical</property> + <property name="margin_top">64</property> + <property name="margin_bottom">64</property> + <property name="margin_start">12</property> + <property name="margin_end">12</property> + <property name="spacing">24</property> + <child> + <object class="GtkImage"> + <property name="visible">True</property> + <property name="icon_name">bluetooth-active-symbolic</property> + <property name="pixel_size">192</property> + <style> + <class name="dim-label"/> + </style> + </object> + </child> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="label" translatable="yes">No Bluetooth Found</property> + <attributes> + <attribute name="weight" value="bold"/> + <attribute name="scale" value="1.2"/> + </attributes> + </object> + </child> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="wrap">True</property> + <property name="label" translatable="yes">Plug in a dongle to use Bluetooth.</property> + </object> + </child> + </object> + </child> + <child> + <object class="GtkBox" id="disabled_box"> + <property name="visible">True</property> + <property name="orientation">vertical</property> + <property name="margin_top">64</property> + <property name="margin_bottom">64</property> + <property name="margin_start">12</property> + <property name="margin_end">12</property> + <property name="spacing">24</property> + <child> + <object class="GtkImage"> + <property name="visible">True</property> + <property name="icon_name">bluetooth-active-symbolic</property> + <property name="pixel_size">192</property> + <style> + <class name="dim-label"/> + </style> + </object> + </child> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="label" translatable="yes">Bluetooth Turned Off</property> + <attributes> + <attribute name="weight" value="bold"/> + <attribute name="scale" value="1.2"/> + </attributes> + </object> + </child> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="wrap">True</property> + <property name="label" translatable="yes">Turn on to connect devices and receive file transfers.</property> + </object> + </child> + </object> + </child> + <child> + <object class="GtkBox" id="airplane_box"> + <property name="visible">True</property> + <property name="orientation">vertical</property> + <property name="margin_top">64</property> + <property name="margin_bottom">64</property> + <property name="margin_start">12</property> + <property name="margin_end">12</property> + <property name="spacing">24</property> + <child> + <object class="GtkImage"> + <property name="visible">True</property> + <property name="icon_name">airplane-mode-symbolic</property> + <property name="pixel_size">192</property> + <style> + <class name="dim-label"/> + </style> + </object> + </child> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="label" translatable="yes">Airplane Mode is on</property> + <attributes> + <attribute name="weight" value="bold"/> + <attribute name="scale" value="1.2"/> + </attributes> + </object> + </child> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="wrap">True</property> + <property name="label" translatable="yes">Bluetooth is disabled when airplane mode is on.</property> + </object> + </child> + <child> + <object class="GtkButton"> + <property name="visible">True</property> + <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"/> + </object> + </child> + </object> + </child> + <child> + <object class="GtkBox" id="hw_airplane_box"> + <property name="visible">True</property> + <property name="orientation">vertical</property> + <property name="margin_top">64</property> + <property name="margin_bottom">64</property> + <property name="margin_start">12</property> + <property name="margin_end">12</property> + <property name="spacing">24</property> + <child> + <object class="GtkImage"> + <property name="visible">True</property> + <property name="icon_name">airplane-mode-symbolic</property> + <property name="pixel_size">192</property> + <style> + <class name="dim-label"/> + </style> + </object> + </child> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="label" translatable="yes">Hardware Airplane Mode is on</property> + <attributes> + <attribute name="weight" value="bold"/> + <attribute name="scale" value="1.2"/> + </attributes> + </object> + </child> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="wrap">True</property> + <property name="label" translatable="yes">Turn off the Airplane mode switch to enable Bluetooth.</property> + </object> + </child> + </object> + </child> + <child> + <object class="BluetoothSettingsWidget" id="settings_widget"> + <property name="visible">True</property> + <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> + <object class="GtkBox" id="header_box"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkSwitch" id="enable_switch"> + <property name="use_action_appearance">False</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="valign">center</property> + <signal name="notify::active" handler="enable_switch_changed_cb" object="CcBluetoothPanel" swapped="yes"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="padding">4</property> + <property name="pack_type">end</property> + <property name="position">2</property> + </packing> + </child> + </object> +</interface> 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..d460700 --- /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=bluetooth +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/meson.build b/panels/bluetooth/meson.build new file mode 100644 index 0000000..c3fce74 --- /dev/null +++ b/panels/bluetooth/meson.build @@ -0,0 +1,40 @@ +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( + desktop, + 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 +) |