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/
This commit is contained in:
Umang Jain
2020-03-26 00:02:59 +05:30
committed by Philip Withnall
parent d86cc0d7a4
commit dbf1b0dafb
4 changed files with 82 additions and 0 deletions

View File

@@ -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)

View File

@@ -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')

View File

@@ -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 users 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 ();

View File

@@ -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,