[gnome-control-center/gbsneto/screenshot-permission-for-review: 8/8] applications: Add support for the screenshot permission




commit 17b018a9fbb076f3dd989f09759018f10210e52d
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Aug 5 19:40:03 2022 -0300

    applications: Add support for the screenshot permission
    
    Add support for managing the screenshot permission, used by apps
    who request non-interactive screenshots from the portal.
    
    See also https://github.com/flatpak/xdg-desktop-portal/pull/851

 panels/applications/cc-applications-panel.c  | 40 ++++++++++++++++++++++++++++
 panels/applications/cc-applications-panel.ui |  7 +++++
 2 files changed, 47 insertions(+)
---
diff --git a/panels/applications/cc-applications-panel.c b/panels/applications/cc-applications-panel.c
index ff823f48e..9d2d52147 100644
--- a/panels/applications/cc-applications-panel.c
+++ b/panels/applications/cc-applications-panel.c
@@ -96,6 +96,7 @@ struct _CcApplicationsPanel
   CcToggleRow     *notification;
   CcToggleRow     *background;
   CcToggleRow     *wallpaper;
+  CcToggleRow     *screenshot;
   CcToggleRow     *sound;
   CcInfoRow       *no_sound;
   CcToggleRow     *search;
@@ -515,6 +516,37 @@ wallpaper_cb (CcApplicationsPanel *self)
     set_wallpaper_allowed (self, cc_toggle_row_get_allowed (self->wallpaper));
 }
 
+/* --- screenshot --- */
+
+static void
+get_screenshot_allowed (CcApplicationsPanel *self,
+                        const gchar         *app_id,
+                        gboolean            *set,
+                        gboolean            *allowed)
+{
+  g_auto(GStrv) perms = get_portal_permissions (self, "screenshot", "screenshot", app_id);
+
+  *set = perms != NULL;
+  *allowed = perms == NULL || strcmp (perms[0], "no") != 0;
+}
+
+static void
+set_screenshot_allowed (CcApplicationsPanel *self,
+                        gboolean             allowed)
+{
+  const gchar *perms[2] = { NULL, NULL };
+
+  perms[0] = allowed ? "yes" : "no";
+  set_portal_permissions (self, "screenshot", "screenshot", self->current_app_id, perms);
+}
+
+static void
+screenshot_cb (CcApplicationsPanel *self)
+{
+  if (self->current_app_id)
+    set_screenshot_allowed (self, cc_toggle_row_get_allowed (self->screenshot));
+}
+
 /* --- shortcuts permissions (flatpak) --- */
 
 static void
@@ -894,6 +926,11 @@ update_integration_section (CcApplicationsPanel *self,
       gtk_widget_set_visible (GTK_WIDGET (self->wallpaper), set);
       has_any |= set;
 
+      get_screenshot_allowed (self, portal_app_id, &set, &allowed);
+      cc_toggle_row_set_allowed (self->screenshot, allowed);
+      gtk_widget_set_visible (GTK_WIDGET (self->screenshot), set);
+      has_any |= set;
+
       disabled = g_settings_get_boolean (self->privacy_settings, "disable-sound-output");
       get_device_allowed (self, "speakers", portal_app_id, &set, &allowed);
       cc_toggle_row_set_allowed (self->sound, allowed);
@@ -935,6 +972,7 @@ update_integration_section (CcApplicationsPanel *self,
 
       gtk_widget_hide (GTK_WIDGET (self->background));
       gtk_widget_hide (GTK_WIDGET (self->wallpaper));
+      gtk_widget_hide (GTK_WIDGET (self->screenshot));
       gtk_widget_hide (GTK_WIDGET (self->sound));
       gtk_widget_hide (GTK_WIDGET (self->no_sound));
       gtk_widget_hide (GTK_WIDGET (self->camera));
@@ -1744,6 +1782,7 @@ cc_applications_panel_class_init (CcApplicationsPanelClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, notification);
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, background);
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, wallpaper);
+  gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, screenshot);
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, shortcuts);
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, sidebar_box);
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, sidebar_listbox);
@@ -1765,6 +1804,7 @@ cc_applications_panel_class_init (CcApplicationsPanelClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, notification_cb);
   gtk_widget_class_bind_template_callback (widget_class, background_cb);
   gtk_widget_class_bind_template_callback (widget_class, wallpaper_cb);
+  gtk_widget_class_bind_template_callback (widget_class, screenshot_cb);
   gtk_widget_class_bind_template_callback (widget_class, shortcuts_cb);
   gtk_widget_class_bind_template_callback (widget_class, privacy_link_cb);
   gtk_widget_class_bind_template_callback (widget_class, sound_cb);
diff --git a/panels/applications/cc-applications-panel.ui b/panels/applications/cc-applications-panel.ui
index c28017456..53147e8a5 100644
--- a/panels/applications/cc-applications-panel.ui
+++ b/panels/applications/cc-applications-panel.ui
@@ -135,6 +135,13 @@
                     <signal name="notify::allowed" handler="background_cb" swapped="yes"/>
                   </object>
                 </child>
+                <child>
+                  <object class="CcToggleRow" id="screenshot">
+                    <property name="title" translatable="yes">Screenshots</property>
+                    <property name="subtitle" translatable="yes">Take screenshots of application windows and 
the desktop.</property>
+                    <signal name="notify::allowed" handler="screenshot_cb" object="CcApplicationsPanel" 
swapped="yes"/>
+                  </object>
+                </child>
                 <child>
                   <object class="CcToggleRow" id="wallpaper">
                     <property name="title" translatable="yes">Change Wallpaper</property>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]