[gnome-control-center/uajain/parental-control-integration: 142/143] applications: Integrate with malcontent's restrictions



commit e97b7ac8695671288a802ff5482677ffb7b7871d
Author: Umang Jain <mailumangjain gmail com>
Date:   Thu Mar 26 00:02:59 2020 +0530

    applications: Integrate with malcontent's restrictions
    
    malcontent[1] is  parental(or admin) controlled interface which
    can restrict a application's visibility and interactivity for a
    standard user. Hence, if the current uid has any restrictions
    on its installed applications, filter them out from the applications
    panel.
    
    Make the malcontent support enable or disable by setting it up as
    a build-time meson option.
    
    [1]: https://gitlab.freedesktop.org/pwithnall/malcontent/

 meson.build                                 |  9 ++++
 meson_options.txt                           |  1 +
 panels/applications/cc-applications-panel.c | 68 +++++++++++++++++++++++++++++
 panels/applications/meson.build             |  4 ++
 4 files changed, 82 insertions(+)
---
diff --git a/meson.build b/meson.build
index ecebc6ac1..eff37e2a0 100644
--- a/meson.build
+++ b/meson.build
@@ -207,6 +207,14 @@ endif
 config_h.set('HAVE_SNAP', enable_snap,
              description: 'Define to 1 if Snap support is enabled')
 
+# malcontent support
+enable_malcontent = get_option('malcontent')
+if enable_malcontent
+  malcontent_dep = dependency('malcontent-0', version: '>= 0.7.0')
+endif
+config_h.set('HAVE_MALCONTENT', enable_malcontent,
+             description: 'Define to 1 if malcontent support is enabled')
+
 if host_is_linux
   # network manager
   network_manager_deps = [
@@ -299,5 +307,6 @@ output += '     IBus (Region panel IBus support) ........... ' + enable_ibus.to_
 output += '     NetworkManager (Network panel) ............. ' + host_is_linux.to_string() + '\n'
 output += '     Wacom (Wacom tablet panel) ................. ' + host_is_linux_not_s390.to_string() + '\n'
 output += '     Snap support ............................... ' + enable_snap.to_string() + '\n'
+output += '     Malcontent support ......................... ' + enable_malcontent.to_string() + '\n'
 
 message(output)
diff --git a/meson_options.txt b/meson_options.txt
index e76308e8a..1b7b54810 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -7,3 +7,4 @@ option('tests', type: 'boolean', value: true, description: 'build tests')
 option('tracing', type: 'boolean', value: false, description: 'add extra debugging information')
 option('wayland', type: 'boolean', value: true, description: 'build with Wayland support')
 option('profile', type: 'combo', choices: ['default','development'], value: 'default')
+option('malcontent', type: 'boolean', value: false, description: 'build with malcontent support')
diff --git a/panels/applications/cc-applications-panel.c b/panels/applications/cc-applications-panel.c
index 457667a36..0e192fe91 100644
--- a/panels/applications/cc-applications-panel.c
+++ b/panels/applications/cc-applications-panel.c
@@ -26,6 +26,9 @@
 #ifdef HAVE_SNAP
 #include <snapd-glib/snapd-glib.h>
 #endif
+#ifdef HAVE_MALCONTENT
+#include <libmalcontent/malcontent.h>
+#endif
 
 #include <gio/gdesktopappinfo.h>
 
@@ -61,6 +64,13 @@ struct _CcApplicationsPanel
   GtkLabel        *title_label;
   GAppInfoMonitor *monitor;
   gulong           monitor_id;
+#ifdef HAVE_MALCONTENT
+  GCancellable    *cancellable;
+
+  MctAppFilter    *app_filter;
+  MctManager      *manager;
+  guint            app_filter_id;
+#endif
 
   gchar           *current_app_id;
   gchar           *current_portal_app_id;
@@ -1613,6 +1623,9 @@ populate_applications (CcApplicationsPanel *self)
   GList *l;
 
   container_remove_all (GTK_CONTAINER (self->sidebar_listbox));
+#ifdef HAVE_MALCONTENT
+  g_signal_handler_block (self->manager, self->app_filter_id);
+#endif
 
   infos = g_app_info_get_all ();
 
@@ -1625,6 +1638,11 @@ populate_applications (CcApplicationsPanel *self)
       if (!g_app_info_should_show (info))
         continue;
 
+#ifdef HAVE_MALCONTENT
+      if (!mct_app_filter_is_appinfo_allowed (self->app_filter, info))
+        continue;
+#endif
+
       row = GTK_WIDGET (cc_applications_row_new (info));
       gtk_list_box_insert (self->sidebar_listbox, row, -1);
 
@@ -1632,6 +1650,9 @@ populate_applications (CcApplicationsPanel *self)
       if (g_strcmp0 (id, self->current_app_id) == 0)
         gtk_list_box_select_row (self->sidebar_listbox, GTK_LIST_BOX_ROW (row));
     }
+#ifdef HAVE_MALCONTENT
+  g_signal_handler_unblock (self->manager, self->app_filter_id);
+#endif
 }
 
 static gint
@@ -1665,6 +1686,16 @@ filter_sidebar_rows (GtkListBoxRow *row,
   return g_strstr_len (app_name, -1, search_text) != NULL;
 }
 
+#ifdef HAVE_MALCONTENT
+static void
+app_filter_changed_cb (MctAppFilter        *app_filter,
+                       uid_t               uid,
+                       CcApplicationsPanel *self)
+{
+  populate_applications (self);
+}
+#endif
+
 static void
 apps_changed (CcApplicationsPanel *self)
 {
@@ -1768,7 +1799,16 @@ static void
 cc_applications_panel_finalize (GObject *object)
 {
   CcApplicationsPanel *self = CC_APPLICATIONS_PANEL (object);
+#ifdef HAVE_MALCONTENT
+  if (self->app_filter != NULL && self->app_filter_id != 0)
+    {
+      g_signal_handler_disconnect (self->manager, self->app_filter_id);
+      self->app_filter_id = 0;
+    }
+  g_clear_pointer (&self->app_filter, mct_app_filter_unref);
 
+  g_clear_object (&self->manager);
+#endif
   g_clear_object (&self->notification_settings);
   g_clear_object (&self->location_settings);
   g_clear_object (&self->privacy_settings);
@@ -1932,6 +1972,10 @@ cc_applications_panel_init (CcApplicationsPanel *self)
 {
   g_autoptr(GtkStyleProvider) provider = NULL;
   GtkListBoxRow *row;
+#ifdef HAVE_MALCONTENT
+  g_autoptr(GDBusConnection) system_bus = NULL;
+  g_autoptr(GError) error = NULL;
+#endif
 
   g_resources_register (cc_applications_get_resource ());
 
@@ -1985,7 +2029,31 @@ cc_applications_panel_init (CcApplicationsPanel *self)
   self->location_settings = g_settings_new ("org.gnome.system.location");
   self->privacy_settings = g_settings_new ("org.gnome.desktop.privacy");
   self->search_settings = g_settings_new ("org.gnome.desktop.search-providers");
+#ifdef HAVE_MALCONTENT
+   /* FIXME: should become asynchronous */
+  system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, self->cancellable, &error);
+  if (system_bus == NULL)
+    {
+      g_warning ("Error getting system bus while setting up app permissions: %s", error->message);
+      return;
+    }
 
+  /* Load the user’s parental controls settings too, so we can filter the list. */
+  self->manager = mct_manager_new (system_bus);
+  self->app_filter = mct_manager_get_app_filter (self->manager,
+                                                 getuid (),
+                                                 MCT_GET_APP_FILTER_FLAGS_NONE,
+                                                 self->cancellable,
+                                                 &error);
+  if (error)
+    {
+      g_warning ("Error retrieving app filter: %s", error->message);
+      return;
+    }
+
+  self->app_filter_id = g_signal_connect (self->manager, "app-filter-changed",
+                                          G_CALLBACK (app_filter_changed_cb), self);
+#endif
   populate_applications (self);
 
   self->monitor = g_app_info_monitor_get ();
diff --git a/panels/applications/meson.build b/panels/applications/meson.build
index 4e324c33e..d511bf640 100644
--- a/panels/applications/meson.build
+++ b/panels/applications/meson.build
@@ -45,6 +45,10 @@ if enable_snap
   sources += files('cc-snap-row.c')
 endif
 
+if enable_malcontent
+  deps += malcontent_dep
+endif
+
 panels_libs += static_library(
            cappletname,
               sources : sources,


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