diff options
Diffstat (limited to 'panels/camera')
-rw-r--r-- | panels/camera/camera.gresource.xml | 6 | ||||
-rw-r--r-- | panels/camera/cc-camera-panel.c | 416 | ||||
-rw-r--r-- | panels/camera/cc-camera-panel.h | 30 | ||||
-rw-r--r-- | panels/camera/cc-camera-panel.ui | 75 | ||||
-rw-r--r-- | panels/camera/gnome-camera-panel.desktop.in.in | 19 | ||||
-rw-r--r-- | panels/camera/icons/meson.build | 4 | ||||
-rw-r--r-- | panels/camera/icons/scalable/org.gnome.Settings-camera-symbolic.svg | 4 | ||||
-rw-r--r-- | panels/camera/meson.build | 41 |
8 files changed, 595 insertions, 0 deletions
diff --git a/panels/camera/camera.gresource.xml b/panels/camera/camera.gresource.xml new file mode 100644 index 0000000..1d077c3 --- /dev/null +++ b/panels/camera/camera.gresource.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<gresources> + <gresource prefix="/org/gnome/control-center/camera"> + <file preprocess="xml-stripblanks">cc-camera-panel.ui</file> + </gresource> +</gresources> diff --git a/panels/camera/cc-camera-panel.c b/panels/camera/cc-camera-panel.c new file mode 100644 index 0000000..3965b67 --- /dev/null +++ b/panels/camera/cc-camera-panel.c @@ -0,0 +1,416 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2018 Red Hat, Inc + * + * 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, see <http://www.gnu.org/licenses/>. + * + * Author: Matthias Clasen <mclasen@redhat.com> + */ + +#include "cc-camera-panel.h" +#include "cc-camera-resources.h" +#include "cc-util.h" + +#include <adwaita.h> +#include <gio/gdesktopappinfo.h> +#include <glib/gi18n.h> + +#define APP_PERMISSIONS_TABLE "devices" +#define APP_PERMISSIONS_ID "camera" + +struct _CcCameraPanel +{ + CcPanel parent_instance; + + GtkStack *stack; + GtkListBox *camera_apps_list_box; + GtkSwitch *main_switch; + + GSettings *privacy_settings; + + GDBusProxy *perm_store; + GVariant *camera_apps_perms; + GVariant *camera_apps_data; + GHashTable *camera_app_switches; + + GtkSizeGroup *camera_icon_size_group; +}; + +CC_PANEL_REGISTER (CcCameraPanel, cc_camera_panel) + +typedef struct +{ + CcCameraPanel *self; + GtkWidget *widget; + gchar *app_id; + gboolean changing_state; + gboolean pending_state; +} CameraAppStateData; + +static void +camera_app_state_data_free (CameraAppStateData *data) +{ + g_free (data->app_id); + g_slice_free (CameraAppStateData, data); +} + +static void +on_perm_store_set_done (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + g_autoptr(GVariant) results = NULL; + g_autoptr(GError) error = NULL; + CameraAppStateData *data; + + results = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), + res, + &error); + if (results == NULL) + { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning ("Failed to store permissions: %s", error->message); + return; + } + + data = (CameraAppStateData *) user_data; + data->changing_state = FALSE; + gtk_switch_set_state (GTK_SWITCH (data->widget), data->pending_state); +} + +static gboolean +on_camera_app_state_set (GtkSwitch *widget, + gboolean state, + gpointer user_data) +{ + CameraAppStateData *data = (CameraAppStateData *) user_data; + GVariantBuilder builder; + CcCameraPanel *self; + GVariantIter iter; + GVariant *params; + const gchar *key; + gchar **value; + + self = data->self; + + if (data->changing_state) + return TRUE; + + data->changing_state = TRUE; + data->pending_state = state; + + g_variant_iter_init (&iter, self->camera_apps_perms); + g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); + while (g_variant_iter_loop (&iter, "{&s^a&s}", &key, &value)) + { + gchar *tmp = NULL; + + /* It's OK to drop the entry if it's not in expected format */ + if (g_strv_length (value) != 1) + continue; + + if (g_strcmp0 (data->app_id, key) == 0) + { + tmp = value[0]; + value[0] = state ? "yes" : "no"; + } + + g_variant_builder_add (&builder, "{s^as}", key, value); + + if (tmp != NULL) + value[0] = tmp; + } + + params = g_variant_new ("(sbsa{sas}v)", + APP_PERMISSIONS_TABLE, + TRUE, + APP_PERMISSIONS_ID, + &builder, + self->camera_apps_data); + + g_dbus_proxy_call (self->perm_store, + "Set", + params, + G_DBUS_CALL_FLAGS_NONE, + -1, + cc_panel_get_cancellable (CC_PANEL (self)), + on_perm_store_set_done, + data); + + return TRUE; +} + +static void +add_camera_app (CcCameraPanel *self, + const gchar *app_id, + gboolean enabled) +{ + g_autofree gchar *desktop_id = NULL; + CameraAppStateData *data; + GDesktopAppInfo *app_info; + GtkWidget *row, *w; + GIcon *icon; + + w = g_hash_table_lookup (self->camera_app_switches, app_id); + if (w != NULL) + { + gtk_switch_set_active (GTK_SWITCH (w), enabled); + return; + } + + desktop_id = g_strdup_printf ("%s.desktop", app_id); + app_info = g_desktop_app_info_new (desktop_id); + if (!app_info) + return; + + row = adw_action_row_new (); + gtk_list_box_append (self->camera_apps_list_box, row); + + icon = g_app_info_get_icon (G_APP_INFO (app_info)); + w = gtk_image_new_from_gicon (icon); + gtk_widget_set_valign (w, GTK_ALIGN_CENTER); + gtk_size_group_add_widget (self->camera_icon_size_group, w); + adw_action_row_add_prefix (ADW_ACTION_ROW (row), w); + + adw_preferences_row_set_title (ADW_PREFERENCES_ROW (row), + g_app_info_get_name (G_APP_INFO (app_info))); + + w = gtk_switch_new (); + gtk_switch_set_active (GTK_SWITCH (w), enabled); + gtk_widget_set_valign (w, GTK_ALIGN_CENTER); + adw_action_row_add_suffix (ADW_ACTION_ROW (row), w); + g_settings_bind (self->privacy_settings, + "disable-camera", + w, + "sensitive", + G_SETTINGS_BIND_INVERT_BOOLEAN); + g_hash_table_insert (self->camera_app_switches, + g_strdup (app_id), + g_object_ref (w)); + + data = g_slice_new (CameraAppStateData); + data->self = self; + data->app_id = g_strdup (app_id); + data->widget = w; + data->changing_state = FALSE; + g_signal_connect_data (G_OBJECT (w), + "state-set", + G_CALLBACK (on_camera_app_state_set), + data, + (GClosureNotify) camera_app_state_data_free, + 0); +} + +/* Steals permissions and permissions_data references */ + +static gboolean +to_child_name (GBinding *binding, + const GValue *from, + GValue *to, + gpointer user_data) +{ + if (g_value_get_boolean (from)) + g_value_set_string (to, "content"); + else + g_value_set_string (to, "empty"); + return TRUE; +} + +static void +update_perm_store (CcCameraPanel *self, + GVariant *permissions, + GVariant *permissions_data) +{ + GVariantIter iter; + const gchar *key; + gchar **value; + + g_clear_pointer (&self->camera_apps_perms, g_variant_unref); + self->camera_apps_perms = permissions; + g_clear_pointer (&self->camera_apps_data, g_variant_unref); + self->camera_apps_data = permissions_data; + + g_variant_iter_init (&iter, permissions); + while (g_variant_iter_loop (&iter, "{&s^a&s}", &key, &value)) + { + gboolean enabled; + + if (g_strv_length (value) != 1) + { + g_debug ("Permissions for %s in incorrect format, ignoring..", key); + continue; + } + + enabled = (g_strcmp0 (value[0], "no") != 0); + + add_camera_app (self, key, enabled); + } +} + +static void +on_perm_store_signal (GDBusProxy *proxy, + gchar *sender_name, + gchar *signal_name, + GVariant *parameters, + gpointer user_data) +{ + GVariant *permissions, *permissions_data; + + if (g_strcmp0 (signal_name, "Changed") != 0) + return; + + permissions = g_variant_get_child_value (parameters, 4); + permissions_data = g_variant_get_child_value (parameters, 3); + update_perm_store (user_data, permissions, permissions_data); +} + +static void +on_perm_store_lookup_done (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + CcCameraPanel *self = user_data; + GVariant *ret, *permissions, *permissions_data; + g_autoptr(GError) error = NULL; + + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), + res, + &error); + if (ret == NULL) + { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning ("Failed fetch permissions from flatpak permission store: %s", error->message); + return; + } + + permissions = g_variant_get_child_value (ret, 0); + permissions_data = g_variant_get_child_value (ret, 1); + update_perm_store (user_data, permissions, permissions_data); + + g_signal_connect_object (source_object, + "g-signal", + G_CALLBACK (on_perm_store_signal), + self, + 0); +} + +static void +on_perm_store_ready (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + CcCameraPanel *self; + g_autoptr(GVariant) params = NULL; + g_autoptr(GError) error = NULL; + GDBusProxy *proxy; + + proxy = g_dbus_proxy_new_for_bus_finish (res, &error); + if (proxy == NULL) + { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning ("Failed to connect to flatpak permission store: %s", error->message); + return; + } + self = user_data; + self->perm_store = proxy; + + params = g_variant_new ("(ss)", + APP_PERMISSIONS_TABLE, + APP_PERMISSIONS_ID); + g_dbus_proxy_call (self->perm_store, + "Lookup", + params, + G_DBUS_CALL_FLAGS_NONE, + -1, + cc_panel_get_cancellable (CC_PANEL (self)), + on_perm_store_lookup_done, + self); +} + +static void +cc_camera_panel_finalize (GObject *object) +{ + CcCameraPanel *self = CC_CAMERA_PANEL (object); + + g_clear_object (&self->privacy_settings); + g_clear_object (&self->perm_store); + g_clear_object (&self->camera_icon_size_group); + g_clear_pointer (&self->camera_apps_perms, g_variant_unref); + g_clear_pointer (&self->camera_apps_data, g_variant_unref); + g_clear_pointer (&self->camera_app_switches, g_hash_table_unref); + + G_OBJECT_CLASS (cc_camera_panel_parent_class)->finalize (object); +} + +static const char * +cc_camera_panel_get_help_uri (CcPanel *panel) +{ + return "help:gnome-help/camera"; +} + +static void +cc_camera_panel_class_init (CcCameraPanelClass *klass) +{ + CcPanelClass *panel_class = CC_PANEL_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + panel_class->get_help_uri = cc_camera_panel_get_help_uri; + + object_class->finalize = cc_camera_panel_finalize; + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/camera/cc-camera-panel.ui"); + + gtk_widget_class_bind_template_child (widget_class, CcCameraPanel, stack); + gtk_widget_class_bind_template_child (widget_class, CcCameraPanel, camera_apps_list_box); + gtk_widget_class_bind_template_child (widget_class, CcCameraPanel, main_switch); +} + +static void +cc_camera_panel_init (CcCameraPanel *self) +{ + g_resources_register (cc_camera_get_resource ()); + + gtk_widget_init_template (GTK_WIDGET (self)); + + self->camera_icon_size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH); + + self->privacy_settings = g_settings_new ("org.gnome.desktop.privacy"); + + g_settings_bind (self->privacy_settings, "disable-camera", + self->main_switch, "active", + G_SETTINGS_BIND_INVERT_BOOLEAN); + + g_object_bind_property_full (self->main_switch, "active", + self->stack, "visible-child-name", + G_BINDING_SYNC_CREATE, + to_child_name, + NULL, + NULL, NULL); + + self->camera_app_switches = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + g_object_unref); + + g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.freedesktop.impl.portal.PermissionStore", + "/org/freedesktop/impl/portal/PermissionStore", + "org.freedesktop.impl.portal.PermissionStore", + cc_panel_get_cancellable (CC_PANEL (self)), + on_perm_store_ready, + self); +} diff --git a/panels/camera/cc-camera-panel.h b/panels/camera/cc-camera-panel.h new file mode 100644 index 0000000..dfc45ab --- /dev/null +++ b/panels/camera/cc-camera-panel.h @@ -0,0 +1,30 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2018 Red Hat, Inc + * + * 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, see <http://www.gnu.org/licenses/>. + * + * Author: Matthias Clasen <mclasen@redhat.com> + */ + +#pragma once + +#include <shell/cc-panel.h> + +G_BEGIN_DECLS + +#define CC_TYPE_CAMERA_PANEL (cc_camera_panel_get_type ()) +G_DECLARE_FINAL_TYPE (CcCameraPanel, cc_camera_panel, CC, CAMERA_PANEL, CcPanel) + +G_END_DECLS diff --git a/panels/camera/cc-camera-panel.ui b/panels/camera/cc-camera-panel.ui new file mode 100644 index 0000000..b357cec --- /dev/null +++ b/panels/camera/cc-camera-panel.ui @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <template class="CcCameraPanel" parent="CcPanel"> + + <child type="titlebar-end"> + <object class="GtkSwitch" id="main_switch"> + <accessibility> + <property name="label" translatable="yes">Enable</property> + </accessibility> + <property name="valign">center</property> + </object> + </child> + + <child type="content"> + <object class="GtkStack" id="stack"> + + <!-- Empty page --> + <child> + <object class="GtkStackPage"> + <property name="name">empty</property> + <property name="child"> + <object class="AdwStatusPage"> + <property name="icon-name">camera-disabled-symbolic</property> + <property name="title" translatable="yes">Camera is Turned Off</property> + <property name="description" translatable="yes">No applications can capture photos or video.</property> + </object> + </property> + </object> + </child> + + <!-- Cameras --> + <child> + <object class="GtkStackPage"> + <property name="name">content</property> + <property name="child"> + <object class="AdwPreferencesPage"> + <child> + <object class="AdwPreferencesGroup"> + <property name="description" translatable="yes">Use of the camera allows applications to capture photos and video. Disabling the camera may cause some applications to not function properly. + +Allow the applications below to use your camera.</property> + <child> + <object class="GtkListBox" id="camera_apps_list_box"> + <property name="selection-mode">none</property> + <style> + <class name="boxed-list"/> + </style> + + <child type="placeholder"> + <object class="GtkLabel"> + <property name="margin-start">18</property> + <property name="margin-end">18</property> + <property name="margin-top">18</property> + <property name="margin-bottom">18</property> + <property name="label" translatable="yes">No Applications Have Asked for Camera Access</property> + <property name="wrap">true</property> + <property name="max-width-chars">50</property> + <style> + <class name="dim-label" /> + </style> + </object> + </child> + </object> + </child> + </object> + </child> + </object> + </property> + </object> + </child> + + </object> + </child> + </template> +</interface> diff --git a/panels/camera/gnome-camera-panel.desktop.in.in b/panels/camera/gnome-camera-panel.desktop.in.in new file mode 100644 index 0000000..e05d5a2 --- /dev/null +++ b/panels/camera/gnome-camera-panel.desktop.in.in @@ -0,0 +1,19 @@ +[Desktop Entry] +Name=Camera +Comment=Protect your pictures +Exec=gnome-control-center camera +# FIXME +# Translators: Do NOT translate or transliterate this text (this is an icon file name)! +Icon=org.gnome.Settings-camera-symbolic +Terminal=false +Type=Application +NoDisplay=true +StartupNotify=true +Categories=GNOME;GTK;Settings;DesktopSettings;X-GNOME-Settings-Panel;X-GNOME-PrivacySettings; +OnlyShowIn=GNOME;Unity; +X-GNOME-Bugzilla-Bugzilla=GNOME +X-GNOME-Bugzilla-Product=gnome-control-center +X-GNOME-Bugzilla-Component=privacy +X-GNOME-Bugzilla-Version=@VERSION@ +# Translators: Search terms to find the Camera panel. Do NOT translate or localize the semicolons! The list MUST also end with a semicolon! +Keywords=camera;photos;video;webcam;lock;private;privacy; diff --git a/panels/camera/icons/meson.build b/panels/camera/icons/meson.build new file mode 100644 index 0000000..c0372b2 --- /dev/null +++ b/panels/camera/icons/meson.build @@ -0,0 +1,4 @@ +install_data( + 'scalable/org.gnome.Settings-camera-symbolic.svg', + install_dir: join_paths(control_center_icondir, 'hicolor', 'scalable', 'apps') +) diff --git a/panels/camera/icons/scalable/org.gnome.Settings-camera-symbolic.svg b/panels/camera/icons/scalable/org.gnome.Settings-camera-symbolic.svg new file mode 100644 index 0000000..1219b9c --- /dev/null +++ b/panels/camera/icons/scalable/org.gnome.Settings-camera-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 6.414062 0 c -0.265624 0 -0.519531 0.105469 -0.707031 0.292969 l -1.707031 1.707031 h -1.085938 c -1.644531 0 -2.9999995 1.355469 -2.9999995 3 v 7 c 0 1.644531 1.3554685 3 2.9999995 3 h 10 c 1.644532 0 3 -1.355469 3 -3 v -7 c 0 -1.644531 -1.355468 -3 -3 -3 h -1.085937 l -1.707031 -1.707031 c -0.1875 -0.1875 -0.441406 -0.292969 -0.707032 -0.292969 z m 0.414063 2 h 2.171875 l 1.707031 1.707031 c 0.1875 0.1875 0.441407 0.292969 0.707031 0.292969 h 1.5 c 0.570313 0 1 0.429688 1 1 v 7 c 0 0.570312 -0.429687 1 -1 1 h -10 c -0.570312 0 -1 -0.429688 -1 -1 v -7 c 0 -0.570312 0.429688 -1 1 -1 h 1.5 c 0.265626 0 0.519532 -0.105469 0.707032 -0.292969 z m 1.085937 3 c -1.644531 0 -3 1.355469 -3 3 s 1.585938 3 3 3 c 1.414063 0 3 -1.355469 3 -3 s -1.355468 -3 -3 -3 z m 0 2 c 0.5625 0 1 0.4375 1 1 s -0.4375 1 -1 1 s -1 -0.4375 -1 -1 s 0.4375 -1 1 -1 z m 0 0" fill="#2e3434"/> +</svg> diff --git a/panels/camera/meson.build b/panels/camera/meson.build new file mode 100644 index 0000000..a69227b --- /dev/null +++ b/panels/camera/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-camera-panel.c') + +resource_data = files('cc-camera-panel.ui') + +sources += gnome.compile_resources( + 'cc-' + cappletname + '-resources', + cappletname + '.gresource.xml', + c_name: 'cc_' + cappletname, + dependencies: resource_data, + export: true +) + +cflags += '-DGNOMELOCALEDIR="@0@"'.format(control_center_localedir) + +panels_libs += static_library( + cappletname, + sources: sources, + include_directories: [top_inc, common_inc], + dependencies: common_deps, + c_args: cflags +) + +subdir('icons') |