LCOV - code coverage report
Current view: top level - libmalcontent-ui - user-controls.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 39 509 7.7 %
Date: 2022-11-29 07:38:08 Functions: 4 46 8.7 %
Branches: 4 216 1.9 %

           Branch data     Line data    Source code
       1                 :            : /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
       2                 :            :  *
       3                 :            :  * Copyright © 2018, 2019, 2020 Endless Mobile, Inc.
       4                 :            :  *
       5                 :            :  * This program is free software; you can redistribute it and/or modify
       6                 :            :  * it under the terms of the GNU General Public License as published by
       7                 :            :  * the Free Software Foundation; either version 2 of the License, or
       8                 :            :  * (at your option) any later version.
       9                 :            :  *
      10                 :            :  * This program is distributed in the hope that it will be useful,
      11                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      12                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13                 :            :  * GNU General Public License for more details.
      14                 :            :  *
      15                 :            :  * You should have received a copy of the GNU General Public License
      16                 :            :  * along with this program; if not, see <http://www.gnu.org/licenses/>.
      17                 :            :  *
      18                 :            :  * Authors:
      19                 :            :  *  - Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
      20                 :            :  *  - Philip Withnall <withnall@endlessm.com>
      21                 :            :  */
      22                 :            : 
      23                 :            : #include "config.h"
      24                 :            : 
      25                 :            : #include <appstream.h>
      26                 :            : #include <libmalcontent/malcontent.h>
      27                 :            : #include <locale.h>
      28                 :            : #include <gio/gio.h>
      29                 :            : #include <gio/gdesktopappinfo.h>
      30                 :            : #include <glib/gi18n-lib.h>
      31                 :            : #include <strings.h>
      32                 :            : 
      33                 :            : #include "restrict-applications-dialog.h"
      34                 :            : #include "user-controls.h"
      35                 :            : 
      36                 :            : 
      37                 :            : #define WEB_BROWSERS_CONTENT_TYPE "x-scheme-handler/http"
      38                 :            : 
      39                 :            : /* The value which we store as an age to indicate that OARS filtering is disabled. */
      40                 :            : static const guint32 oars_disabled_age = (guint32) -1;
      41                 :            : 
      42                 :            : /**
      43                 :            :  * MctUserControls:
      44                 :            :  *
      45                 :            :  * A group of widgets which allow setting the parental controls for a given
      46                 :            :  * user.
      47                 :            :  *
      48                 :            :  * If #MctUserControls:user is set, the current parental controls settings for
      49                 :            :  * that user will be loaded and displayed, and any changes made via the controls
      50                 :            :  * will be automatically saved for that user (potentially after a short
      51                 :            :  * timeout).
      52                 :            :  *
      53                 :            :  * If #MctUserControls:user is unset (for example, if setting the parental
      54                 :            :  * controls for a user account which hasn’t yet been created), the controls can
      55                 :            :  * be initialised by setting:
      56                 :            :  *  * #MctUserControls:app-filter
      57                 :            :  *  * #MctUserControls:user-account-type
      58                 :            :  *  * #MctUserControls:user-locale
      59                 :            :  *  * #MctUserControls:user-display-name
      60                 :            :  *
      61                 :            :  * When #MctUserControls:user is unset, changes made to the parental controls
      62                 :            :  * cannot be saved automatically, and must be queried using
      63                 :            :  * mct_user_controls_build_app_filter(), then saved by the calling code.
      64                 :            :  *
      65                 :            :  * As parental controls are system settings, privileges are needed to view and
      66                 :            :  * edit them (for the current user or for other users). These can be acquired
      67                 :            :  * using polkit. #MctUserControls:permission is used to query the current
      68                 :            :  * permissions for getting/setting parental controls. If it’s %NULL, or if
      69                 :            :  * permissions are not currently granted, the #MctUserControls will be
      70                 :            :  * insensitive.
      71                 :            :  *
      72                 :            :  * Since: 0.5.0
      73                 :            :  */
      74                 :            : struct _MctUserControls
      75                 :            : {
      76                 :            :   AdwBin     parent_instance;
      77                 :            : 
      78                 :            :   GtkLabel *description_label;
      79                 :            :   GMenu      *age_menu;
      80                 :            :   GtkSwitch  *restrict_software_installation_switch;
      81                 :            :   AdwActionRow *restrict_software_installation_row;
      82                 :            :   GtkSwitch  *restrict_web_browsers_switch;
      83                 :            :   AdwActionRow *restrict_web_browsers_row;
      84                 :            :   GtkMenuButton *oars_button;
      85                 :            :   GtkPopoverMenu *oars_popover;
      86                 :            :   MctRestrictApplicationsDialog *restrict_applications_dialog;
      87                 :            :   GtkLabel   *restrict_applications_description;
      88                 :            :   AdwActionRow *restrict_applications_row;
      89                 :            : 
      90                 :            :   GSimpleActionGroup *action_group; /* (owned) */
      91                 :            : 
      92                 :            :   ActUser    *user; /* (owned) (nullable) */
      93                 :            :   gulong      user_changed_id;
      94                 :            : 
      95                 :            :   GPermission *permission;  /* (owned) (nullable) */
      96                 :            :   gulong permission_allowed_id;
      97                 :            : 
      98                 :            :   GDBusConnection *dbus_connection;  /* (owned) */
      99                 :            :   GCancellable *cancellable; /* (owned) */
     100                 :            :   MctManager   *manager; /* (owned) */
     101                 :            :   MctAppFilter *filter; /* (owned) (nullable); updated by the user of #MctUserControls */
     102                 :            :   MctAppFilter *last_saved_filter; /* (owned) (nullable); updated each time we internally time out and save the app filter */
     103                 :            :   guint         selected_age; /* @oars_disabled_age to disable OARS */
     104                 :            : 
     105                 :            :   guint         blocklist_apps_source_id;
     106                 :            :   gboolean      flushed_on_dispose;
     107                 :            : 
     108                 :            :   ActUserAccountType  user_account_type;
     109                 :            :   gchar              *user_locale;  /* (nullable) (owned) */
     110                 :            :   gchar              *user_display_name;  /* (nullable) (owned) */
     111                 :            :   gchar              *description;  /* (nullable) (owned) */
     112                 :            : };
     113                 :            : 
     114                 :            : static gboolean blocklist_apps_cb (gpointer data);
     115                 :            : 
     116                 :            : static void on_restrict_installation_switch_active_changed_cb (GtkSwitch        *s,
     117                 :            :                                                                GParamSpec       *pspec,
     118                 :            :                                                                MctUserControls *self);
     119                 :            : 
     120                 :            : static void on_restrict_web_browsers_switch_active_changed_cb (GtkSwitch        *s,
     121                 :            :                                                                GParamSpec       *pspec,
     122                 :            :                                                                MctUserControls *self);
     123                 :            : 
     124                 :            : static void on_restrict_applications_action_activated (GSimpleAction *action,
     125                 :            :                                                        GVariant      *param,
     126                 :            :                                                        gpointer       user_data);
     127                 :            : 
     128                 :            : static gboolean on_restrict_applications_dialog_close_request_cb (GtkWidget *widget,
     129                 :            :                                                                   gpointer   user_data);
     130                 :            : 
     131                 :            : static void on_set_age_action_activated (GSimpleAction *action,
     132                 :            :                                          GVariant      *param,
     133                 :            :                                          gpointer       user_data);
     134                 :            : 
     135                 :            : static void on_permission_allowed_cb (GObject    *obj,
     136                 :            :                                       GParamSpec *pspec,
     137                 :            :                                       gpointer    user_data);
     138                 :            : 
     139   [ +  +  +  -  :          3 : G_DEFINE_TYPE (MctUserControls, mct_user_controls, ADW_TYPE_BIN)
                   +  - ]
     140                 :            : 
     141                 :            : typedef enum
     142                 :            : {
     143                 :            :   PROP_USER = 1,
     144                 :            :   PROP_PERMISSION,
     145                 :            :   PROP_APP_FILTER,
     146                 :            :   PROP_USER_ACCOUNT_TYPE,
     147                 :            :   PROP_USER_LOCALE,
     148                 :            :   PROP_USER_DISPLAY_NAME,
     149                 :            :   PROP_DBUS_CONNECTION,
     150                 :            :   PROP_DESCRIPTION,
     151                 :            : } MctUserControlsProperty;
     152                 :            : 
     153                 :            : static GParamSpec *properties[PROP_DESCRIPTION + 1];
     154                 :            : 
     155                 :            : static const GActionEntry actions[] = {
     156                 :            :   { "set-age", on_set_age_action_activated, "u", NULL, NULL, { 0, }},
     157                 :            :   { "restrict-applications", on_restrict_applications_action_activated, NULL, NULL, NULL, { 0, }}
     158                 :            : };
     159                 :            : 
     160                 :            : /* Auxiliary methods */
     161                 :            : 
     162                 :            : static AsContentRatingSystem
     163                 :          0 : get_content_rating_system (MctUserControls *self)
     164                 :            : {
     165         [ #  # ]:          0 :   if (self->user_locale == NULL)
     166                 :          0 :     return AS_CONTENT_RATING_SYSTEM_UNKNOWN;
     167                 :            : 
     168                 :          0 :   return as_content_rating_system_from_locale (self->user_locale);
     169                 :            : }
     170                 :            : 
     171                 :            : static const gchar *
     172                 :          0 : get_user_locale (ActUser *user)
     173                 :            : {
     174                 :            :   const gchar *locale;
     175                 :            : 
     176                 :          0 :   g_return_val_if_fail (ACT_IS_USER (user), "C");
     177                 :            : 
     178                 :            :   /* accounts-service can return %NULL if loading over D-Bus failed. */
     179                 :          0 :   locale = act_user_get_language (user);
     180         [ #  # ]:          0 :   if (locale == NULL)
     181                 :          0 :     return NULL;
     182                 :            : 
     183                 :            :   /* It can return the empty string if the user uses the system default locale. */
     184         [ #  # ]:          0 :   if (*locale == '\0')
     185                 :          0 :     locale = setlocale (LC_MESSAGES, NULL);
     186                 :            : 
     187   [ #  #  #  # ]:          0 :   if (locale == NULL || *locale == '\0')
     188                 :          0 :     locale = "C";
     189                 :            : 
     190                 :          0 :   return locale;
     191                 :            : }
     192                 :            : 
     193                 :            : static const gchar *
     194                 :          0 : get_user_display_name (ActUser *user)
     195                 :            : {
     196                 :            :   const gchar *display_name;
     197                 :            : 
     198                 :          0 :   g_return_val_if_fail (ACT_IS_USER (user), _("unknown"));
     199                 :            : 
     200                 :          0 :   display_name = act_user_get_real_name (user);
     201         [ #  # ]:          0 :   if (display_name != NULL)
     202                 :          0 :     return display_name;
     203                 :            : 
     204                 :          0 :   display_name = act_user_get_user_name (user);
     205         [ #  # ]:          0 :   if (display_name != NULL)
     206                 :          0 :     return display_name;
     207                 :            : 
     208                 :            :   /* Translators: this is the full name for an unknown user account. */
     209                 :          0 :   return _("unknown");
     210                 :            : }
     211                 :            : 
     212                 :            : static void
     213                 :          0 : schedule_update_blocklisted_apps (MctUserControls *self)
     214                 :            : {
     215         [ #  # ]:          0 :   if (self->blocklist_apps_source_id > 0)
     216                 :          0 :     return;
     217                 :            : 
     218                 :            :   /* Use a timeout to batch multiple quick changes into a single
     219                 :            :    * update. 1 second is an arbitrary sufficiently small number */
     220                 :          0 :   self->blocklist_apps_source_id = g_timeout_add_seconds (1, blocklist_apps_cb, self);
     221                 :            : }
     222                 :            : 
     223                 :            : static void
     224                 :          0 : flush_update_blocklisted_apps (MctUserControls *self)
     225                 :            : {
     226         [ #  # ]:          0 :   if (self->blocklist_apps_source_id > 0)
     227                 :            :     {
     228                 :            :       /* Remove the timer and forcefully call the timer callback. */
     229                 :          0 :       g_source_remove (self->blocklist_apps_source_id);
     230                 :          0 :       self->blocklist_apps_source_id = 0;
     231                 :            : 
     232                 :          0 :       blocklist_apps_cb (self);
     233                 :            :     }
     234                 :          0 : }
     235                 :            : 
     236                 :            : static void
     237                 :          0 : update_app_filter_from_user (MctUserControls *self)
     238                 :            : {
     239         [ #  # ]:          0 :   g_autoptr(GError) error = NULL;
     240                 :            : 
     241         [ #  # ]:          0 :   if (self->user == NULL)
     242                 :          0 :     return;
     243                 :            : 
     244                 :            :   /* FIXME: It’s expected that, unless authorised already, a user cannot read
     245                 :            :    * another user’s app filter. accounts-service currently (incorrectly) ignores
     246                 :            :    * the missing ‘interactive’ flag and prompts the user for permission if so,
     247                 :            :    * so don’t query at all in that case. */
     248         [ #  # ]:          0 :   if (act_user_get_uid (self->user) != getuid () &&
     249   [ #  #  #  # ]:          0 :       (self->permission == NULL ||
     250                 :          0 :        !g_permission_get_allowed (self->permission)))
     251                 :          0 :     return;
     252                 :            : 
     253                 :            :   /* FIXME: make it asynchronous */
     254         [ #  # ]:          0 :   g_clear_pointer (&self->filter, mct_app_filter_unref);
     255         [ #  # ]:          0 :   g_clear_pointer (&self->last_saved_filter, mct_app_filter_unref);
     256                 :          0 :   self->filter = mct_manager_get_app_filter (self->manager,
     257                 :            :                                              act_user_get_uid (self->user),
     258                 :            :                                              MCT_MANAGER_GET_VALUE_FLAGS_NONE,
     259                 :            :                                              self->cancellable,
     260                 :            :                                              &error);
     261                 :            : 
     262         [ #  # ]:          0 :   if (error)
     263                 :            :     {
     264                 :          0 :       g_warning ("Error retrieving app filter for user '%s': %s",
     265                 :            :                  act_user_get_user_name (self->user),
     266                 :            :                  error->message);
     267                 :          0 :       return;
     268                 :            :     }
     269                 :            : 
     270                 :          0 :   self->last_saved_filter = mct_app_filter_ref (self->filter);
     271                 :            : 
     272                 :          0 :   g_debug ("Retrieved new app filter for user '%s'", act_user_get_user_name (self->user));
     273                 :            : }
     274                 :            : 
     275                 :            : static void
     276                 :          0 : update_restricted_apps (MctUserControls *self)
     277                 :            : {
     278                 :          0 :   mct_restrict_applications_dialog_set_app_filter (self->restrict_applications_dialog, self->filter);
     279                 :          0 : }
     280                 :            : 
     281                 :            : static void
     282                 :          0 : update_categories_from_language (MctUserControls *self)
     283                 :            : {
     284                 :            :   AsContentRatingSystem rating_system;
     285                 :          0 :   g_auto(GStrv) entries = NULL;
     286                 :            :   const gchar *rating_system_str;
     287                 :            :   const guint *ages;
     288                 :            :   gsize i, n_ages;
     289                 :          0 :   g_autofree gchar *disabled_action = NULL;
     290                 :            : 
     291                 :          0 :   rating_system = get_content_rating_system (self);
     292                 :          0 :   rating_system_str = as_content_rating_system_to_string (rating_system);
     293                 :            : 
     294                 :          0 :   g_debug ("Using rating system %s", rating_system_str);
     295                 :            : 
     296                 :          0 :   entries = as_content_rating_system_get_formatted_ages (rating_system);
     297                 :          0 :   ages = as_content_rating_system_get_csm_ages (rating_system, &n_ages);
     298                 :            : 
     299                 :            :   /* Fill in the age menu */
     300                 :          0 :   g_menu_remove_all (self->age_menu);
     301                 :            : 
     302                 :          0 :   disabled_action = g_strdup_printf ("permissions.set-age(uint32 %u)", oars_disabled_age);
     303                 :          0 :   g_menu_append (self->age_menu, _("All Ages"), disabled_action);
     304                 :            : 
     305         [ #  # ]:          0 :   for (i = 0; entries[i] != NULL; i++)
     306                 :            :     {
     307                 :          0 :       g_autofree gchar *action = g_strdup_printf ("permissions.set-age(uint32 %u)", ages[i]);
     308                 :            : 
     309                 :            :       /* Prevent the unlikely case that one of the real ages is the same as our
     310                 :            :        * special ‘disabled’ value. */
     311                 :          0 :       g_assert (ages[i] != oars_disabled_age);
     312                 :            : 
     313                 :          0 :       g_menu_append (self->age_menu, entries[i], action);
     314                 :            :     }
     315                 :            : 
     316                 :          0 :   g_assert (i == n_ages);
     317                 :          0 : }
     318                 :            : 
     319                 :            : /* Returns a human-readable but untranslated string, not suitable
     320                 :            :  * to be shown in any UI */
     321                 :            : static const gchar *
     322                 :          0 : oars_value_to_string (MctAppFilterOarsValue oars_value)
     323                 :            : {
     324   [ #  #  #  #  :          0 :   switch (oars_value)
                   #  # ]
     325                 :            :     {
     326                 :          0 :     case MCT_APP_FILTER_OARS_VALUE_UNKNOWN:
     327                 :          0 :       return "unknown";
     328                 :          0 :     case MCT_APP_FILTER_OARS_VALUE_NONE:
     329                 :          0 :       return "none";
     330                 :          0 :     case MCT_APP_FILTER_OARS_VALUE_MILD:
     331                 :          0 :       return "mild";
     332                 :          0 :     case MCT_APP_FILTER_OARS_VALUE_MODERATE:
     333                 :          0 :       return "moderate";
     334                 :          0 :     case MCT_APP_FILTER_OARS_VALUE_INTENSE:
     335                 :          0 :       return "intense";
     336                 :          0 :     default:
     337                 :          0 :       return "";
     338                 :            :     }
     339                 :            : }
     340                 :            : 
     341                 :            : /* Ensure the enum casts below are safe. */
     342                 :            : G_STATIC_ASSERT ((int) MCT_APP_FILTER_OARS_VALUE_UNKNOWN == (int) AS_CONTENT_RATING_VALUE_UNKNOWN);
     343                 :            : G_STATIC_ASSERT ((int) MCT_APP_FILTER_OARS_VALUE_NONE == (int) AS_CONTENT_RATING_VALUE_NONE);
     344                 :            : G_STATIC_ASSERT ((int) MCT_APP_FILTER_OARS_VALUE_MILD == (int) AS_CONTENT_RATING_VALUE_MILD);
     345                 :            : G_STATIC_ASSERT ((int) MCT_APP_FILTER_OARS_VALUE_MODERATE == (int) AS_CONTENT_RATING_VALUE_MODERATE);
     346                 :            : G_STATIC_ASSERT ((int) MCT_APP_FILTER_OARS_VALUE_INTENSE == (int) AS_CONTENT_RATING_VALUE_INTENSE);
     347                 :            : 
     348                 :            : static void
     349                 :          0 : update_oars_level (MctUserControls *self)
     350                 :            : {
     351                 :            :   AsContentRatingSystem rating_system;
     352                 :          0 :   g_autofree gchar *rating_age_category = NULL;
     353                 :            :   guint maximum_age, selected_age;
     354                 :            :   gsize i;
     355                 :            :   gboolean all_categories_unset;
     356                 :          0 :   g_autofree const gchar **oars_categories = as_content_rating_get_all_rating_ids ();
     357                 :            : 
     358                 :          0 :   g_assert (self->filter != NULL);
     359                 :            : 
     360                 :          0 :   maximum_age = 0;
     361                 :          0 :   all_categories_unset = TRUE;
     362                 :            : 
     363         [ #  # ]:          0 :   for (i = 0; oars_categories[i] != NULL; i++)
     364                 :            :     {
     365                 :            :       MctAppFilterOarsValue oars_value;
     366                 :            :       guint age;
     367                 :            : 
     368                 :          0 :       oars_value = mct_app_filter_get_oars_value (self->filter, oars_categories[i]);
     369                 :          0 :       all_categories_unset &= (oars_value == MCT_APP_FILTER_OARS_VALUE_UNKNOWN);
     370                 :          0 :       age = as_content_rating_attribute_to_csm_age (oars_categories[i], (AsContentRatingValue) oars_value);
     371                 :            : 
     372                 :          0 :       g_debug ("OARS value for '%s': %s", oars_categories[i], oars_value_to_string (oars_value));
     373                 :            : 
     374         [ #  # ]:          0 :       if (age > maximum_age)
     375                 :          0 :         maximum_age = age;
     376                 :            :     }
     377                 :            : 
     378         [ #  # ]:          0 :   g_debug ("Effective age for this user: %u; %s", maximum_age,
     379                 :            :            all_categories_unset ? "all categories unset" : "some categories set");
     380                 :            : 
     381                 :          0 :   rating_system = get_content_rating_system (self);
     382                 :          0 :   rating_age_category = as_content_rating_system_format_age (rating_system, maximum_age);
     383                 :            : 
     384                 :            :   /* Unrestricted? */
     385   [ #  #  #  # ]:          0 :   if (rating_age_category == NULL || all_categories_unset)
     386                 :            :     {
     387         [ #  # ]:          0 :       g_clear_pointer (&rating_age_category, g_free);
     388                 :          0 :       rating_age_category = g_strdup (_("All Ages"));
     389                 :          0 :       selected_age = oars_disabled_age;
     390                 :            :     }
     391                 :            :   else
     392                 :            :     {
     393                 :          0 :       selected_age = maximum_age;
     394                 :            :     }
     395                 :            : 
     396                 :          0 :   gtk_menu_button_set_label (self->oars_button, rating_age_category);
     397                 :          0 :   self->selected_age = selected_age;
     398                 :          0 : }
     399                 :            : 
     400                 :            : static void
     401                 :          0 : update_allow_app_installation (MctUserControls *self)
     402                 :            : {
     403                 :            :   gboolean restrict_software_installation;
     404                 :          0 :   gboolean non_admin_user = TRUE;
     405                 :            : 
     406         [ #  # ]:          0 :   if (self->user_account_type == ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR)
     407                 :          0 :     non_admin_user = FALSE;
     408                 :            : 
     409                 :            :   /* Admins are always allowed to install apps for all users. This behaviour is governed
     410                 :            :    * by flatpak polkit rules. Hence, these hide these defunct switches for admins. */
     411                 :          0 :   gtk_widget_set_visible (GTK_WIDGET (self->restrict_software_installation_switch), non_admin_user);
     412                 :            : 
     413                 :            :   /* If user is admin, we are done here, bail out. */
     414         [ #  # ]:          0 :   if (!non_admin_user)
     415                 :            :     {
     416                 :          0 :       g_debug ("User ‘%s’ is an administrator, hiding app installation controls",
     417                 :            :                self->user_display_name);
     418                 :          0 :       return;
     419                 :            :     }
     420                 :            : 
     421                 :            :   /* While the underlying permissions storage allows the system and user settings
     422                 :            :    * to be stored completely independently, force the system setting to OFF if
     423                 :            :    * the user setting is OFF in the UI. This keeps the policy in use for most
     424                 :            :    * people simpler. */
     425                 :          0 :   restrict_software_installation = !mct_app_filter_is_user_installation_allowed (self->filter);
     426                 :            : 
     427                 :          0 :   g_signal_handlers_block_by_func (self->restrict_software_installation_switch,
     428                 :            :                                    on_restrict_installation_switch_active_changed_cb,
     429                 :            :                                    self);
     430                 :            : 
     431                 :          0 :   gtk_switch_set_active (self->restrict_software_installation_switch, restrict_software_installation);
     432                 :            : 
     433         [ #  # ]:          0 :   g_debug ("Restrict system installation: %s", restrict_software_installation ? "yes" : "no");
     434         [ #  # ]:          0 :   g_debug ("Restrict user installation: %s", restrict_software_installation ? "yes" : "no");
     435                 :            : 
     436                 :          0 :   g_signal_handlers_unblock_by_func (self->restrict_software_installation_switch,
     437                 :            :                                      on_restrict_installation_switch_active_changed_cb,
     438                 :            :                                      self);
     439                 :            : }
     440                 :            : 
     441                 :            : static void
     442                 :          0 : update_restrict_web_browsers (MctUserControls *self)
     443                 :            : {
     444                 :            :   gboolean restrict_web_browsers;
     445                 :            : 
     446                 :          0 :   restrict_web_browsers = !mct_app_filter_is_content_type_allowed (self->filter,
     447                 :            :                                                                    WEB_BROWSERS_CONTENT_TYPE);
     448                 :            : 
     449                 :          0 :   g_signal_handlers_block_by_func (self->restrict_web_browsers_switch,
     450                 :            :                                    on_restrict_web_browsers_switch_active_changed_cb,
     451                 :            :                                    self);
     452                 :            : 
     453                 :          0 :   gtk_switch_set_active (self->restrict_web_browsers_switch, restrict_web_browsers);
     454                 :            : 
     455         [ #  # ]:          0 :   g_debug ("Restrict web browsers: %s", restrict_web_browsers ? "yes" : "no");
     456                 :            : 
     457                 :          0 :   g_signal_handlers_unblock_by_func (self->restrict_web_browsers_switch,
     458                 :            :                                      on_restrict_web_browsers_switch_active_changed_cb,
     459                 :            :                                      self);
     460                 :          0 : }
     461                 :            : 
     462                 :            : static void
     463                 :          0 : update_labels_from_name (MctUserControls *self)
     464                 :            : {
     465                 :          0 :   g_autofree gchar *l = NULL;
     466                 :            : 
     467                 :          0 :   gtk_label_set_markup (self->description_label, self->description);
     468                 :            : 
     469                 :            :   /* Translators: The placeholder is a user’s display name. */
     470                 :          0 :   l = g_strdup_printf (_("Prevents %s from running web browsers. Limited web content may still be available in other applications."), self->user_display_name);
     471                 :          0 :   adw_action_row_set_subtitle (self->restrict_web_browsers_row, l);
     472         [ #  # ]:          0 :   g_clear_pointer (&l, g_free);
     473                 :            : 
     474                 :            :   /* Translators: The placeholder is a user’s display name. */
     475                 :          0 :   l = g_strdup_printf (_("Prevents specified applications from being used by %s."), self->user_display_name);
     476                 :          0 :   adw_action_row_set_subtitle (self->restrict_applications_row, l);
     477         [ #  # ]:          0 :   g_clear_pointer (&l, g_free);
     478                 :            : 
     479                 :            :   /* Translators: The placeholder is a user’s display name. */
     480                 :          0 :   l = g_strdup_printf (_("Prevents %s from installing applications."), self->user_display_name);
     481                 :          0 :   adw_action_row_set_subtitle (self->restrict_software_installation_row, l);
     482         [ #  # ]:          0 :   g_clear_pointer (&l, g_free);
     483                 :          0 : }
     484                 :            : 
     485                 :            : static void
     486                 :          0 : setup_parental_control_settings (MctUserControls *self)
     487                 :            : {
     488                 :            :   gboolean is_authorized;
     489                 :            : 
     490                 :          0 :   gtk_widget_set_visible (GTK_WIDGET (self), self->filter != NULL);
     491                 :            : 
     492         [ #  # ]:          0 :   if (!self->filter)
     493                 :          0 :     return;
     494                 :            : 
     495                 :            :   /* We only want to make the controls sensitive if we have permission to save
     496                 :            :    * changes (@is_authorized). */
     497         [ #  # ]:          0 :   if (self->permission != NULL)
     498                 :          0 :     is_authorized = g_permission_get_allowed (G_PERMISSION (self->permission));
     499                 :            :   else
     500                 :          0 :     is_authorized = FALSE;
     501                 :            : 
     502                 :          0 :   gtk_widget_set_sensitive (GTK_WIDGET (self), is_authorized);
     503                 :            : 
     504                 :          0 :   update_restricted_apps (self);
     505                 :          0 :   update_categories_from_language (self);
     506                 :          0 :   update_oars_level (self);
     507                 :          0 :   update_allow_app_installation (self);
     508                 :          0 :   update_restrict_web_browsers (self);
     509                 :          0 :   update_labels_from_name (self);
     510                 :            : }
     511                 :            : 
     512                 :            : /* Callbacks */
     513                 :            : 
     514                 :            : static gboolean
     515                 :          0 : blocklist_apps_cb (gpointer data)
     516                 :            : {
     517                 :          0 :   g_auto(MctAppFilterBuilder) builder = MCT_APP_FILTER_BUILDER_INIT ();
     518                 :          0 :   g_autoptr(MctAppFilter) new_filter = NULL;
     519                 :          0 :   g_autoptr(GError) error = NULL;
     520                 :          0 :   MctUserControls *self = data;
     521                 :            : 
     522                 :          0 :   self->blocklist_apps_source_id = 0;
     523                 :            : 
     524         [ #  # ]:          0 :   if (self->user == NULL)
     525                 :            :     {
     526                 :          0 :       g_debug ("Not saving app filter as user is unset");
     527                 :          0 :       return G_SOURCE_REMOVE;
     528                 :            :     }
     529                 :            : 
     530                 :          0 :   mct_user_controls_build_app_filter (self, &builder);
     531                 :          0 :   new_filter = mct_app_filter_builder_end (&builder);
     532                 :            : 
     533                 :            :   /* Don’t bother saving the app filter (which could result in asking the user
     534                 :            :    * for admin permission) if it hasn’t changed. */
     535   [ #  #  #  # ]:          0 :   if (self->last_saved_filter != NULL &&
     536                 :          0 :       mct_app_filter_equal (new_filter, self->last_saved_filter))
     537                 :            :     {
     538                 :          0 :       g_debug ("Not saving app filter as it hasn’t changed");
     539                 :          0 :       return G_SOURCE_REMOVE;
     540                 :            :     }
     541                 :            : 
     542                 :            :   /* FIXME: should become asynchronous */
     543                 :          0 :   mct_manager_set_app_filter (self->manager,
     544                 :            :                               act_user_get_uid (self->user),
     545                 :            :                               new_filter,
     546                 :            :                               MCT_MANAGER_SET_VALUE_FLAGS_INTERACTIVE,
     547                 :            :                               self->cancellable,
     548                 :            :                               &error);
     549                 :            : 
     550         [ #  # ]:          0 :   if (error)
     551                 :            :     {
     552                 :          0 :       g_warning ("Error updating app filter: %s", error->message);
     553                 :          0 :       setup_parental_control_settings (self);
     554                 :            :     }
     555                 :            : 
     556                 :            :   /* Update the cached copy */
     557                 :          0 :   mct_app_filter_unref (self->last_saved_filter);
     558                 :          0 :   self->last_saved_filter = g_steal_pointer (&new_filter);
     559                 :            : 
     560                 :          0 :   return G_SOURCE_REMOVE;
     561                 :            : }
     562                 :            : 
     563                 :            : static void
     564                 :          0 : on_restrict_installation_switch_active_changed_cb (GtkSwitch        *s,
     565                 :            :                                                    GParamSpec       *pspec,
     566                 :            :                                                    MctUserControls *self)
     567                 :            : {
     568                 :            :   /* Save the changes. */
     569                 :          0 :   schedule_update_blocklisted_apps (self);
     570                 :          0 : }
     571                 :            : 
     572                 :            : static void
     573                 :          0 : on_restrict_web_browsers_switch_active_changed_cb (GtkSwitch        *s,
     574                 :            :                                                    GParamSpec       *pspec,
     575                 :            :                                                    MctUserControls *self)
     576                 :            : {
     577                 :            :   /* Save the changes. */
     578                 :          0 :   schedule_update_blocklisted_apps (self);
     579                 :          0 : }
     580                 :            : 
     581                 :            : static void
     582                 :          0 : on_restrict_applications_action_activated (GSimpleAction *action,
     583                 :            :                                            GVariant      *param,
     584                 :            :                                            gpointer       user_data)
     585                 :            : {
     586                 :          0 :   MctUserControls *self = MCT_USER_CONTROLS (user_data);
     587                 :            :   GtkRoot *root;
     588                 :            : 
     589                 :            :   /* Show the restrict applications dialogue modally, making sure to update its
     590                 :            :    * state first. */
     591                 :          0 :   root = gtk_widget_get_root (GTK_WIDGET (self));
     592   [ #  #  #  #  :          0 :   if (GTK_IS_WINDOW (root))
             #  #  #  # ]
     593                 :          0 :     gtk_window_set_transient_for (GTK_WINDOW (self->restrict_applications_dialog),
     594                 :          0 :                                   GTK_WINDOW (root));
     595                 :            : 
     596                 :          0 :   mct_restrict_applications_dialog_set_user_display_name (self->restrict_applications_dialog, self->user_display_name);
     597                 :          0 :   mct_restrict_applications_dialog_set_app_filter (self->restrict_applications_dialog, self->filter);
     598                 :            : 
     599                 :          0 :   gtk_window_present (GTK_WINDOW (self->restrict_applications_dialog));
     600                 :          0 : }
     601                 :            : 
     602                 :            : static gboolean
     603                 :          0 : on_restrict_applications_dialog_close_request_cb (GtkWidget *widget,
     604                 :            :                                                   gpointer   user_data)
     605                 :            : {
     606                 :          0 :   MctUserControls *self = MCT_USER_CONTROLS (user_data);
     607                 :            : 
     608                 :            :   /* When the ‘Restrict Applications’ dialogue is closed, don’t destroy it,
     609                 :            :    * since it contains the app filter settings which we’ll want to reuse next
     610                 :            :    * time the dialogue is shown or the app filter is saved. */
     611                 :          0 :   gtk_widget_hide (GTK_WIDGET (self->restrict_applications_dialog));
     612                 :            : 
     613                 :            :   /* Schedule an update to the saved state. */
     614                 :          0 :   schedule_update_blocklisted_apps (self);
     615                 :            : 
     616                 :          0 :   return TRUE;
     617                 :            : }
     618                 :            : 
     619                 :            : static void
     620                 :          0 : on_set_age_action_activated (GSimpleAction *action,
     621                 :            :                              GVariant      *param,
     622                 :            :                              gpointer       user_data)
     623                 :            : {
     624                 :            :   AsContentRatingSystem rating_system;
     625                 :            :   MctUserControls *self;
     626                 :          0 :   g_auto(GStrv) entries = NULL;
     627                 :            :   const guint *ages;
     628                 :            :   guint age;
     629                 :            :   guint i;
     630                 :            :   gsize n_ages;
     631                 :            : 
     632                 :          0 :   self = MCT_USER_CONTROLS (user_data);
     633                 :          0 :   age = g_variant_get_uint32 (param);
     634                 :            : 
     635                 :          0 :   rating_system = get_content_rating_system (self);
     636                 :          0 :   entries = as_content_rating_system_get_formatted_ages (rating_system);
     637                 :          0 :   ages = as_content_rating_system_get_csm_ages (rating_system, &n_ages);
     638                 :            : 
     639                 :            :   /* Update the button */
     640         [ #  # ]:          0 :   if (age == oars_disabled_age)
     641                 :          0 :     gtk_menu_button_set_label (self->oars_button, _("All Ages"));
     642                 :            : 
     643   [ #  #  #  # ]:          0 :   for (i = 0; age != oars_disabled_age && entries[i] != NULL; i++)
     644                 :            :     {
     645         [ #  # ]:          0 :       if (ages[i] == age)
     646                 :            :         {
     647                 :          0 :           gtk_menu_button_set_label (self->oars_button, entries[i]);
     648                 :          0 :           break;
     649                 :            :         }
     650                 :            :     }
     651                 :            : 
     652                 :          0 :   g_assert (age == oars_disabled_age || entries[i] != NULL);
     653                 :            : 
     654         [ #  # ]:          0 :   if (age == oars_disabled_age)
     655                 :          0 :     g_debug ("Selected to disable OARS");
     656                 :            :   else
     657                 :          0 :     g_debug ("Selected OARS age: %u", age);
     658                 :            : 
     659                 :          0 :   self->selected_age = age;
     660                 :            : 
     661                 :          0 :   schedule_update_blocklisted_apps (self);
     662                 :          0 : }
     663                 :            : 
     664                 :            : /* GObject overrides */
     665                 :            : 
     666                 :            : static void
     667                 :          0 : mct_user_controls_constructed (GObject *object)
     668                 :            : {
     669                 :          0 :   MctUserControls *self = MCT_USER_CONTROLS (object);
     670                 :            : 
     671                 :            :   /* Chain up. */
     672                 :          0 :   G_OBJECT_CLASS (mct_user_controls_parent_class)->constructed (object);
     673                 :            : 
     674                 :            :   /* FIXME: Ideally there wouldn’t be this sync call in a constructor, but there
     675                 :            :    * seems to be no way around it if #MctUserControls is to be used from a
     676                 :            :    * GtkBuilder template: templates are initialised from within the parent
     677                 :            :    * widget’s init() function (not its constructed() function), so none of its
     678                 :            :    * properties will have been set and it won’t reasonably have been able to
     679                 :            :    * make an async call to initialise the bus connection itself. Binding
     680                 :            :    * construct-only properties in GtkBuilder doesn’t work (and wouldn’t help if
     681                 :            :    * it did). */
     682         [ #  # ]:          0 :   if (self->dbus_connection == NULL)
     683                 :          0 :     self->dbus_connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL);
     684                 :            : 
     685                 :          0 :   g_assert (self->dbus_connection != NULL);
     686                 :          0 :   self->manager = mct_manager_new (self->dbus_connection);
     687                 :          0 : }
     688                 :            : 
     689                 :            : static void
     690                 :          0 : mct_user_controls_finalize (GObject *object)
     691                 :            : {
     692                 :          0 :   MctUserControls *self = (MctUserControls *)object;
     693                 :            : 
     694                 :          0 :   g_assert (self->blocklist_apps_source_id == 0);
     695                 :            : 
     696                 :          0 :   g_cancellable_cancel (self->cancellable);
     697         [ #  # ]:          0 :   g_clear_object (&self->action_group);
     698         [ #  # ]:          0 :   g_clear_object (&self->cancellable);
     699   [ #  #  #  # ]:          0 :   if (self->user != NULL && self->user_changed_id != 0)
     700                 :          0 :     g_signal_handler_disconnect (self->user, self->user_changed_id);
     701                 :          0 :   self->user_changed_id = 0;
     702         [ #  # ]:          0 :   g_clear_object (&self->user);
     703         [ #  # ]:          0 :   g_clear_pointer (&self->user_locale, g_free);
     704         [ #  # ]:          0 :   g_clear_pointer (&self->user_display_name, g_free);
     705                 :            : 
     706   [ #  #  #  # ]:          0 :   if (self->permission != NULL && self->permission_allowed_id != 0)
     707                 :            :     {
     708                 :          0 :       g_signal_handler_disconnect (self->permission, self->permission_allowed_id);
     709                 :          0 :       self->permission_allowed_id = 0;
     710                 :            :     }
     711         [ #  # ]:          0 :   g_clear_object (&self->permission);
     712                 :            : 
     713         [ #  # ]:          0 :   g_clear_pointer (&self->filter, mct_app_filter_unref);
     714         [ #  # ]:          0 :   g_clear_pointer (&self->last_saved_filter, mct_app_filter_unref);
     715         [ #  # ]:          0 :   g_clear_object (&self->manager);
     716         [ #  # ]:          0 :   g_clear_object (&self->dbus_connection);
     717                 :            : 
     718                 :            :   /* Hopefully we don’t have data loss. */
     719                 :          0 :   g_assert (self->flushed_on_dispose);
     720                 :            : 
     721                 :          0 :   G_OBJECT_CLASS (mct_user_controls_parent_class)->finalize (object);
     722                 :          0 : }
     723                 :            : 
     724                 :            : 
     725                 :            : static void
     726                 :          0 : mct_user_controls_dispose (GObject *object)
     727                 :            : {
     728                 :          0 :   MctUserControls *self = (MctUserControls *)object;
     729                 :            : 
     730                 :            :   /* Since GTK calls g_object_run_dispose(), dispose() may be called multiple
     731                 :            :    * times. We definitely want to save any unsaved changes, but don’t need to
     732                 :            :    * do it multiple times, and after the first g_object_run_dispose() call,
     733                 :            :    * none of our child widgets are still around to extract data from anyway. */
     734         [ #  # ]:          0 :   if (!self->flushed_on_dispose)
     735                 :          0 :     flush_update_blocklisted_apps (self);
     736                 :          0 :   self->flushed_on_dispose = TRUE;
     737                 :            : 
     738                 :          0 :   G_OBJECT_CLASS (mct_user_controls_parent_class)->dispose (object);
     739                 :          0 : }
     740                 :            : 
     741                 :            : static void
     742                 :          0 : mct_user_controls_get_property (GObject    *object,
     743                 :            :                                 guint       prop_id,
     744                 :            :                                 GValue     *value,
     745                 :            :                                 GParamSpec *pspec)
     746                 :            : {
     747                 :          0 :   MctUserControls *self = MCT_USER_CONTROLS (object);
     748                 :            : 
     749   [ #  #  #  #  :          0 :   switch ((MctUserControlsProperty) prop_id)
             #  #  #  #  
                      # ]
     750                 :            :     {
     751                 :          0 :     case PROP_USER:
     752                 :          0 :       g_value_set_object (value, self->user);
     753                 :          0 :       break;
     754                 :            : 
     755                 :          0 :     case PROP_PERMISSION:
     756                 :          0 :       g_value_set_object (value, self->permission);
     757                 :          0 :       break;
     758                 :            : 
     759                 :          0 :     case PROP_APP_FILTER:
     760                 :          0 :       g_value_set_boxed (value, self->filter);
     761                 :          0 :       break;
     762                 :            : 
     763                 :          0 :     case PROP_USER_ACCOUNT_TYPE:
     764                 :          0 :       g_value_set_enum (value, self->user_account_type);
     765                 :          0 :       break;
     766                 :            : 
     767                 :          0 :     case PROP_USER_LOCALE:
     768                 :          0 :       g_value_set_string (value, self->user_locale);
     769                 :          0 :       break;
     770                 :            : 
     771                 :          0 :     case PROP_USER_DISPLAY_NAME:
     772                 :          0 :       g_value_set_string (value, self->user_display_name);
     773                 :          0 :       break;
     774                 :            : 
     775                 :          0 :     case PROP_DBUS_CONNECTION:
     776                 :          0 :       g_value_set_object (value, self->dbus_connection);
     777                 :          0 :       break;
     778                 :            : 
     779                 :          0 :     case PROP_DESCRIPTION:
     780                 :          0 :       g_value_set_string (value, self->description);
     781                 :          0 :       break;
     782                 :            : 
     783                 :          0 :     default:
     784                 :          0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     785                 :            :     }
     786                 :          0 : }
     787                 :            : 
     788                 :            : static void
     789                 :          0 : mct_user_controls_set_property (GObject      *object,
     790                 :            :                                 guint         prop_id,
     791                 :            :                                 const GValue *value,
     792                 :            :                                 GParamSpec   *pspec)
     793                 :            : {
     794                 :          0 :   MctUserControls *self = MCT_USER_CONTROLS (object);
     795                 :            : 
     796   [ #  #  #  #  :          0 :   switch ((MctUserControlsProperty) prop_id)
             #  #  #  #  
                      # ]
     797                 :            :     {
     798                 :          0 :     case PROP_USER:
     799                 :          0 :       mct_user_controls_set_user (self, g_value_get_object (value));
     800                 :          0 :       break;
     801                 :            : 
     802                 :          0 :     case PROP_PERMISSION:
     803                 :          0 :       mct_user_controls_set_permission (self, g_value_get_object (value));
     804                 :          0 :       break;
     805                 :            : 
     806                 :          0 :     case PROP_APP_FILTER:
     807                 :          0 :       mct_user_controls_set_app_filter (self, g_value_get_boxed (value));
     808                 :          0 :       break;
     809                 :            : 
     810                 :          0 :     case PROP_USER_ACCOUNT_TYPE:
     811                 :          0 :       mct_user_controls_set_user_account_type (self, g_value_get_enum (value));
     812                 :          0 :       break;
     813                 :            : 
     814                 :          0 :     case PROP_USER_LOCALE:
     815                 :          0 :       mct_user_controls_set_user_locale (self, g_value_get_string (value));
     816                 :          0 :       break;
     817                 :            : 
     818                 :          0 :     case PROP_USER_DISPLAY_NAME:
     819                 :          0 :       mct_user_controls_set_user_display_name (self, g_value_get_string (value));
     820                 :          0 :       break;
     821                 :            : 
     822                 :          0 :     case PROP_DBUS_CONNECTION:
     823                 :            :       /* Construct only. */
     824                 :          0 :       g_assert (self->dbus_connection == NULL);
     825                 :          0 :       self->dbus_connection = g_value_dup_object (value);
     826                 :          0 :       break;
     827                 :            : 
     828                 :          0 :     case PROP_DESCRIPTION:
     829                 :          0 :       mct_user_controls_set_description (self, g_value_get_string (value));
     830                 :          0 :       break;
     831                 :            : 
     832                 :          0 :     default:
     833                 :          0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     834                 :            :     }
     835                 :          0 : }
     836                 :            : 
     837                 :            : static void
     838                 :          1 : mct_user_controls_class_init (MctUserControlsClass *klass)
     839                 :            : {
     840                 :          1 :   GObjectClass *object_class = G_OBJECT_CLASS (klass);
     841                 :          1 :   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
     842                 :            : 
     843                 :          1 :   object_class->constructed = mct_user_controls_constructed;
     844                 :          1 :   object_class->finalize = mct_user_controls_finalize;
     845                 :          1 :   object_class->dispose = mct_user_controls_dispose;
     846                 :          1 :   object_class->get_property = mct_user_controls_get_property;
     847                 :          1 :   object_class->set_property = mct_user_controls_set_property;
     848                 :            : 
     849                 :          1 :   properties[PROP_USER] = g_param_spec_object ("user",
     850                 :            :                                                "User",
     851                 :            :                                                "User",
     852                 :            :                                                ACT_TYPE_USER,
     853                 :            :                                                G_PARAM_READWRITE |
     854                 :            :                                                G_PARAM_STATIC_STRINGS |
     855                 :            :                                                G_PARAM_EXPLICIT_NOTIFY);
     856                 :            : 
     857                 :          1 :   properties[PROP_PERMISSION] = g_param_spec_object ("permission",
     858                 :            :                                                      "Permission",
     859                 :            :                                                      "Permission to change parental controls",
     860                 :            :                                                      G_TYPE_PERMISSION,
     861                 :            :                                                      G_PARAM_READWRITE |
     862                 :            :                                                      G_PARAM_STATIC_STRINGS |
     863                 :            :                                                      G_PARAM_EXPLICIT_NOTIFY);
     864                 :            : 
     865                 :            :   /**
     866                 :            :    * MctUserControls:app-filter: (nullable)
     867                 :            :    *
     868                 :            :    * The user’s current app filter, used to set up the user controls. As app
     869                 :            :    * filters are immutable, it is not updated as the user controls are changed.
     870                 :            :    * Use mct_user_controls_build_app_filter() to build the new app filter.
     871                 :            :    *
     872                 :            :    * This may be %NULL if the app filter is unknown, or if querying it from
     873                 :            :    * #MctUserControls:user fails.
     874                 :            :    *
     875                 :            :    * Since: 0.5.0
     876                 :            :    */
     877                 :          1 :   properties[PROP_APP_FILTER] =
     878                 :          1 :       g_param_spec_boxed ("app-filter",
     879                 :            :                           "App Filter",
     880                 :            :                           "The user’s current app filter, used to set up the user controls, or %NULL if unknown.",
     881                 :            :                           MCT_TYPE_APP_FILTER,
     882                 :            :                           G_PARAM_READWRITE |
     883                 :            :                           G_PARAM_STATIC_STRINGS |
     884                 :            :                           G_PARAM_EXPLICIT_NOTIFY);
     885                 :            : 
     886                 :            :   /**
     887                 :            :    * MctUserControls:user-account-type:
     888                 :            :    *
     889                 :            :    * The type of the currently selected user account.
     890                 :            :    *
     891                 :            :    * Since: 0.5.0
     892                 :            :    */
     893                 :          1 :   properties[PROP_USER_ACCOUNT_TYPE] =
     894                 :          1 :       g_param_spec_enum ("user-account-type",
     895                 :            :                          "User Account Type",
     896                 :            :                          "The type of the currently selected user account.",
     897                 :            :                          /* FIXME: Not a typo here; libaccountsservice uses the wrong namespace.
     898                 :            :                           * See: https://gitlab.freedesktop.org/accountsservice/accountsservice/issues/84 */
     899                 :            :                          ACT_USER_TYPE_USER_ACCOUNT_TYPE,
     900                 :            :                          ACT_USER_ACCOUNT_TYPE_STANDARD,
     901                 :            :                          G_PARAM_READWRITE |
     902                 :            :                          G_PARAM_STATIC_STRINGS |
     903                 :            :                          G_PARAM_EXPLICIT_NOTIFY);
     904                 :            : 
     905                 :            :   /**
     906                 :            :    * MctUserControls:user-locale: (nullable)
     907                 :            :    *
     908                 :            :    * The locale for the currently selected user account, or %NULL if no
     909                 :            :    * user is selected.
     910                 :            :    *
     911                 :            :    * If set, it must be in the format documented by [`setlocale()`](man:setlocale(3)):
     912                 :            :    * ```
     913                 :            :    * language[_territory][.codeset][@modifier]
     914                 :            :    * ```
     915                 :            :    * where `language` is an ISO 639 language code, `territory` is an ISO 3166
     916                 :            :    * country code, and `codeset` is a character set or encoding identifier like
     917                 :            :    * `ISO-8859-1` or `UTF-8`.
     918                 :            :    *
     919                 :            :    * Since: 0.5.0
     920                 :            :    */
     921                 :          1 :   properties[PROP_USER_LOCALE] =
     922                 :          1 :       g_param_spec_string ("user-locale",
     923                 :            :                            "User Locale",
     924                 :            :                            "The locale for the currently selected user account, or %NULL if no user is selected.",
     925                 :            :                            NULL,
     926                 :            :                            G_PARAM_READWRITE |
     927                 :            :                            G_PARAM_STATIC_STRINGS |
     928                 :            :                            G_PARAM_EXPLICIT_NOTIFY);
     929                 :            : 
     930                 :            :   /**
     931                 :            :    * MctUserControls:user-display-name: (nullable)
     932                 :            :    *
     933                 :            :    * The display name for the currently selected user account, or %NULL if no
     934                 :            :    * user is selected. This will typically be the user’s full name (if known)
     935                 :            :    * or their username.
     936                 :            :    *
     937                 :            :    * If set, it must be valid UTF-8 and non-empty.
     938                 :            :    *
     939                 :            :    * Since: 0.5.0
     940                 :            :    */
     941                 :          1 :   properties[PROP_USER_DISPLAY_NAME] =
     942                 :          1 :       g_param_spec_string ("user-display-name",
     943                 :            :                            "User Display Name",
     944                 :            :                            "The display name for the currently selected user account, or %NULL if no user is selected.",
     945                 :            :                            NULL,
     946                 :            :                            G_PARAM_READWRITE |
     947                 :            :                            G_PARAM_STATIC_STRINGS |
     948                 :            :                            G_PARAM_EXPLICIT_NOTIFY);
     949                 :            : 
     950                 :            :   /**
     951                 :            :    * MctUserControls:description: (nullable)
     952                 :            :    *
     953                 :            :    * The description for the currently selected user account, or %NULL if no
     954                 :            :    * user is selected.
     955                 :            :    *
     956                 :            :    * If set, it must be valid UTF-8 and non-empty.
     957                 :            :    *
     958                 :            :    * Since: 0.11.0
     959                 :            :    */
     960                 :          1 :   properties[PROP_DESCRIPTION] =
     961                 :          1 :       g_param_spec_string ("description",
     962                 :            :                            "Description",
     963                 :            :                            "The description for the currently selected user account, or %NULL if no user is selected.",
     964                 :            :                            NULL,
     965                 :            :                            G_PARAM_READWRITE |
     966                 :            :                            G_PARAM_STATIC_STRINGS |
     967                 :            :                            G_PARAM_EXPLICIT_NOTIFY);
     968                 :            : 
     969                 :            :   /**
     970                 :            :    * MctUserControls:dbus-connection: (not nullable)
     971                 :            :    *
     972                 :            :    * A connection to the system bus. This will be used for retrieving details
     973                 :            :    * of user accounts, and must be provided at construction time.
     974                 :            :    *
     975                 :            :    * Since: 0.7.0
     976                 :            :    */
     977                 :          1 :   properties[PROP_DBUS_CONNECTION] =
     978                 :          1 :       g_param_spec_object ("dbus-connection",
     979                 :            :                            "D-Bus Connection",
     980                 :            :                            "A connection to the system bus.",
     981                 :            :                            G_TYPE_DBUS_CONNECTION,
     982                 :            :                            G_PARAM_READWRITE |
     983                 :            :                            G_PARAM_CONSTRUCT_ONLY |
     984                 :            :                            G_PARAM_STATIC_STRINGS |
     985                 :            :                            G_PARAM_EXPLICIT_NOTIFY);
     986                 :            : 
     987                 :          1 :   g_object_class_install_properties (object_class, G_N_ELEMENTS (properties), properties);
     988                 :            : 
     989                 :          1 :   gtk_widget_class_set_template_from_resource (widget_class, "/org/freedesktop/MalcontentUi/ui/user-controls.ui");
     990                 :            : 
     991                 :          1 :   gtk_widget_class_bind_template_child (widget_class, MctUserControls, age_menu);
     992                 :          1 :   gtk_widget_class_bind_template_child (widget_class, MctUserControls, description_label);
     993                 :          1 :   gtk_widget_class_bind_template_child (widget_class, MctUserControls, restrict_software_installation_switch);
     994                 :          1 :   gtk_widget_class_bind_template_child (widget_class, MctUserControls, restrict_software_installation_row);
     995                 :          1 :   gtk_widget_class_bind_template_child (widget_class, MctUserControls, restrict_web_browsers_switch);
     996                 :          1 :   gtk_widget_class_bind_template_child (widget_class, MctUserControls, restrict_web_browsers_row);
     997                 :          1 :   gtk_widget_class_bind_template_child (widget_class, MctUserControls, oars_button);
     998                 :          1 :   gtk_widget_class_bind_template_child (widget_class, MctUserControls, oars_popover);
     999                 :          1 :   gtk_widget_class_bind_template_child (widget_class, MctUserControls, restrict_applications_dialog);
    1000                 :          1 :   gtk_widget_class_bind_template_child (widget_class, MctUserControls, restrict_applications_row);
    1001                 :            : 
    1002                 :          1 :   gtk_widget_class_bind_template_callback (widget_class, on_restrict_installation_switch_active_changed_cb);
    1003                 :          1 :   gtk_widget_class_bind_template_callback (widget_class, on_restrict_web_browsers_switch_active_changed_cb);
    1004                 :          1 :   gtk_widget_class_bind_template_callback (widget_class, on_restrict_applications_dialog_close_request_cb);
    1005                 :          1 : }
    1006                 :            : 
    1007                 :            : static void
    1008                 :          0 : mct_user_controls_init (MctUserControls *self)
    1009                 :            : {
    1010                 :          0 :   g_autoptr(GtkCssProvider) provider = NULL;
    1011                 :            : 
    1012                 :            :   /* Ensure the types used in the UI are registered. */
    1013                 :          0 :   g_type_ensure (MCT_TYPE_RESTRICT_APPLICATIONS_DIALOG);
    1014                 :            : 
    1015                 :          0 :   gtk_widget_init_template (GTK_WIDGET (self));
    1016                 :            : 
    1017                 :          0 :   provider = gtk_css_provider_new ();
    1018                 :          0 :   gtk_css_provider_load_from_resource (provider,
    1019                 :            :                                        "/org/freedesktop/MalcontentUi/ui/restricts-switch.css");
    1020                 :          0 :   gtk_style_context_add_provider_for_display (gdk_display_get_default (),
    1021                 :          0 :                                               GTK_STYLE_PROVIDER (provider),
    1022                 :            :                                               GTK_STYLE_PROVIDER_PRIORITY_APPLICATION - 1);
    1023                 :            : 
    1024                 :          0 :   self->selected_age = (guint) -1;
    1025                 :            : 
    1026                 :          0 :   self->cancellable = g_cancellable_new ();
    1027                 :            : 
    1028                 :          0 :   self->action_group = g_simple_action_group_new ();
    1029                 :          0 :   g_action_map_add_action_entries (G_ACTION_MAP (self->action_group),
    1030                 :            :                                    actions,
    1031                 :            :                                    G_N_ELEMENTS (actions),
    1032                 :            :                                    self);
    1033                 :            : 
    1034                 :          0 :   gtk_widget_insert_action_group (GTK_WIDGET (self),
    1035                 :            :                                   "permissions",
    1036                 :          0 :                                   G_ACTION_GROUP (self->action_group));
    1037                 :            : 
    1038                 :          0 :   gtk_popover_menu_set_menu_model (self->oars_popover, G_MENU_MODEL (self->age_menu));
    1039                 :          0 : }
    1040                 :            : 
    1041                 :            : /**
    1042                 :            :  * mct_user_controls_get_user:
    1043                 :            :  * @self: an #MctUserControls
    1044                 :            :  *
    1045                 :            :  * Get the value of #MctUserControls:user.
    1046                 :            :  *
    1047                 :            :  * Returns: (transfer none) (nullable): the user the controls are configured for,
    1048                 :            :  *    or %NULL if unknown
    1049                 :            :  * Since: 0.5.0
    1050                 :            :  */
    1051                 :            : ActUser *
    1052                 :          0 : mct_user_controls_get_user (MctUserControls *self)
    1053                 :            : {
    1054                 :          0 :   g_return_val_if_fail (MCT_IS_USER_CONTROLS (self), NULL);
    1055                 :            : 
    1056                 :          0 :   return self->user;
    1057                 :            : }
    1058                 :            : 
    1059                 :            : static void
    1060                 :          0 : user_changed_cb (ActUser  *user,
    1061                 :            :                  gpointer  user_data)
    1062                 :            : {
    1063                 :          0 :   MctUserControls *self = MCT_USER_CONTROLS (user_data);
    1064                 :            : 
    1065                 :          0 :   mct_user_controls_set_user_account_type (self, act_user_get_account_type (user));
    1066                 :          0 :   mct_user_controls_set_user_locale (self, get_user_locale (user));
    1067                 :          0 :   mct_user_controls_set_user_display_name (self, get_user_display_name (user));
    1068                 :          0 : }
    1069                 :            : 
    1070                 :            : /**
    1071                 :            :  * mct_user_controls_set_user:
    1072                 :            :  * @self: an #MctUserControls
    1073                 :            :  * @user: (nullable) (transfer none): the user to configure the controls for,
    1074                 :            :  *    or %NULL if unknown
    1075                 :            :  *
    1076                 :            :  * Set the value of #MctUserControls:user.
    1077                 :            :  *
    1078                 :            :  * Since: 0.5.0
    1079                 :            :  */
    1080                 :            : void
    1081                 :          0 : mct_user_controls_set_user (MctUserControls *self,
    1082                 :            :                             ActUser         *user)
    1083                 :            : {
    1084         [ #  # ]:          0 :   g_autoptr(ActUser) old_user = NULL;
    1085                 :            : 
    1086                 :          0 :   g_return_if_fail (MCT_IS_USER_CONTROLS (self));
    1087                 :          0 :   g_return_if_fail (user == NULL || ACT_IS_USER (user));
    1088                 :            : 
    1089                 :            :   /* If we have pending unsaved changes from the previous user, force them to be
    1090                 :            :    * saved first. */
    1091                 :          0 :   flush_update_blocklisted_apps (self);
    1092                 :            : 
    1093         [ #  # ]:          0 :   old_user = (self->user != NULL) ? g_object_ref (self->user) : NULL;
    1094                 :            : 
    1095         [ #  # ]:          0 :   if (g_set_object (&self->user, user))
    1096                 :            :     {
    1097                 :          0 :       g_object_freeze_notify (G_OBJECT (self));
    1098                 :            : 
    1099         [ #  # ]:          0 :       if (old_user != NULL)
    1100                 :          0 :         g_signal_handler_disconnect (old_user, self->user_changed_id);
    1101                 :            : 
    1102                 :            :       /* Update the starting widget state from the user. */
    1103         [ #  # ]:          0 :       if (user != NULL)
    1104                 :            :         {
    1105                 :          0 :           self->user_changed_id = g_signal_connect (user, "changed",
    1106                 :            :                                                     (GCallback) user_changed_cb, self);
    1107                 :          0 :           user_changed_cb (user, self);
    1108                 :            :         }
    1109                 :            : 
    1110                 :          0 :       update_app_filter_from_user (self);
    1111                 :          0 :       setup_parental_control_settings (self);
    1112                 :            : 
    1113                 :          0 :       g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_USER]);
    1114                 :          0 :       g_object_thaw_notify (G_OBJECT (self));
    1115                 :            :     }
    1116                 :            : }
    1117                 :            : 
    1118                 :            : static void
    1119                 :          0 : on_permission_allowed_cb (GObject    *obj,
    1120                 :            :                           GParamSpec *pspec,
    1121                 :            :                           gpointer    user_data)
    1122                 :            : {
    1123                 :          0 :   MctUserControls *self = MCT_USER_CONTROLS (user_data);
    1124                 :            : 
    1125                 :          0 :   update_app_filter_from_user (self);
    1126                 :          0 :   setup_parental_control_settings (self);
    1127                 :          0 : }
    1128                 :            : 
    1129                 :            : /**
    1130                 :            :  * mct_user_controls_get_permission:
    1131                 :            :  * @self: an #MctUserControls
    1132                 :            :  *
    1133                 :            :  * Get the value of #MctUserControls:permission.
    1134                 :            :  *
    1135                 :            :  * Returns: (transfer none) (nullable): a #GPermission indicating whether the
    1136                 :            :  *    current user has permission to view or change parental controls, or %NULL
    1137                 :            :  *    if permission is not allowed or is unknown
    1138                 :            :  * Since: 0.5.0
    1139                 :            :  */
    1140                 :            : GPermission *
    1141                 :          0 : mct_user_controls_get_permission (MctUserControls *self)
    1142                 :            : {
    1143                 :          0 :   g_return_val_if_fail (MCT_IS_USER_CONTROLS (self), NULL);
    1144                 :            : 
    1145                 :          0 :   return self->permission;
    1146                 :            : }
    1147                 :            : 
    1148                 :            : /**
    1149                 :            :  * mct_user_controls_set_permission:
    1150                 :            :  * @self: an #MctUserControls
    1151                 :            :  * @permission: (nullable) (transfer none): the #GPermission indicating whether
    1152                 :            :  *    the current user has permission to view or change parental controls, or
    1153                 :            :  *    %NULL if permission is not allowed or is unknown
    1154                 :            :  *
    1155                 :            :  * Set the value of #MctUserControls:permission.
    1156                 :            :  *
    1157                 :            :  * Since: 0.5.0
    1158                 :            :  */
    1159                 :            : void
    1160                 :          0 : mct_user_controls_set_permission (MctUserControls *self,
    1161                 :            :                                   GPermission     *permission)
    1162                 :            : {
    1163                 :          0 :   g_return_if_fail (MCT_IS_USER_CONTROLS (self));
    1164                 :          0 :   g_return_if_fail (permission == NULL || G_IS_PERMISSION (permission));
    1165                 :            : 
    1166         [ #  # ]:          0 :   if (self->permission == permission)
    1167                 :          0 :     return;
    1168                 :            : 
    1169   [ #  #  #  # ]:          0 :   if (self->permission != NULL && self->permission_allowed_id != 0)
    1170                 :            :     {
    1171                 :          0 :       g_signal_handler_disconnect (self->permission, self->permission_allowed_id);
    1172                 :          0 :       self->permission_allowed_id = 0;
    1173                 :            :     }
    1174                 :            : 
    1175         [ #  # ]:          0 :   g_clear_object (&self->permission);
    1176                 :            : 
    1177         [ #  # ]:          0 :   if (permission != NULL)
    1178                 :            :     {
    1179                 :          0 :       self->permission = g_object_ref (permission);
    1180                 :          0 :       self->permission_allowed_id = g_signal_connect (self->permission,
    1181                 :            :                                                       "notify::allowed",
    1182                 :            :                                                       (GCallback) on_permission_allowed_cb,
    1183                 :            :                                                       self);
    1184                 :            :     }
    1185                 :            : 
    1186                 :            :   /* Handle changes. */
    1187                 :          0 :   update_app_filter_from_user (self);
    1188                 :          0 :   setup_parental_control_settings (self);
    1189                 :            : 
    1190                 :          0 :   g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PERMISSION]);
    1191                 :            : }
    1192                 :            : 
    1193                 :            : /**
    1194                 :            :  * mct_user_controls_get_app_filter:
    1195                 :            :  * @self: an #MctUserControls
    1196                 :            :  *
    1197                 :            :  * Get the value of #MctUserControls:app-filter. If the app filter is unknown
    1198                 :            :  * or could not be retrieved from #MctUserControls:user, this will be %NULL.
    1199                 :            :  *
    1200                 :            :  * Returns: (transfer none) (nullable): the initial app filter used to
    1201                 :            :  *    populate the user controls, or %NULL if unknown
    1202                 :            :  * Since: 0.5.0
    1203                 :            :  */
    1204                 :            : MctAppFilter *
    1205                 :          0 : mct_user_controls_get_app_filter (MctUserControls *self)
    1206                 :            : {
    1207                 :          0 :   g_return_val_if_fail (MCT_IS_USER_CONTROLS (self), NULL);
    1208                 :            : 
    1209                 :          0 :   return self->filter;
    1210                 :            : }
    1211                 :            : 
    1212                 :            : /**
    1213                 :            :  * mct_user_controls_set_app_filter:
    1214                 :            :  * @self: an #MctUserControls
    1215                 :            :  * @app_filter: (nullable) (transfer none): the app filter to configure the user
    1216                 :            :  *    controls from, or %NULL if unknown
    1217                 :            :  *
    1218                 :            :  * Set the value of #MctUserControls:app-filter.
    1219                 :            :  *
    1220                 :            :  * This will overwrite any user changes to the controls, so they should be saved
    1221                 :            :  * first using mct_user_controls_build_app_filter() if desired. They will be
    1222                 :            :  * saved automatically if #MctUserControls:user is set.
    1223                 :            :  *
    1224                 :            :  * Since: 0.5.0
    1225                 :            :  */
    1226                 :            : void
    1227                 :          0 : mct_user_controls_set_app_filter (MctUserControls *self,
    1228                 :            :                                   MctAppFilter    *app_filter)
    1229                 :            : {
    1230                 :          0 :   g_return_if_fail (MCT_IS_USER_CONTROLS (self));
    1231                 :            : 
    1232                 :            :   /* If we have pending unsaved changes from the previous configuration, force
    1233                 :            :    * them to be saved first. */
    1234                 :          0 :   flush_update_blocklisted_apps (self);
    1235                 :            : 
    1236         [ #  # ]:          0 :   if (self->filter == app_filter)
    1237                 :          0 :     return;
    1238                 :            : 
    1239         [ #  # ]:          0 :   g_clear_pointer (&self->filter, mct_app_filter_unref);
    1240         [ #  # ]:          0 :   g_clear_pointer (&self->last_saved_filter, mct_app_filter_unref);
    1241         [ #  # ]:          0 :   if (app_filter != NULL)
    1242                 :            :     {
    1243                 :          0 :       self->filter = mct_app_filter_ref (app_filter);
    1244                 :          0 :       self->last_saved_filter = mct_app_filter_ref (app_filter);
    1245                 :            :     }
    1246                 :            : 
    1247                 :          0 :   g_debug ("Set new app filter from caller");
    1248                 :          0 :   setup_parental_control_settings (self);
    1249                 :            : 
    1250                 :          0 :   g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_APP_FILTER]);
    1251                 :            : }
    1252                 :            : 
    1253                 :            : /**
    1254                 :            :  * mct_user_controls_get_user_account_type:
    1255                 :            :  * @self: an #MctUserControls
    1256                 :            :  *
    1257                 :            :  * Get the value of #MctUserControls:user-account-type.
    1258                 :            :  *
    1259                 :            :  * Returns: the account type of the user the controls are configured for
    1260                 :            :  * Since: 0.5.0
    1261                 :            :  */
    1262                 :            : ActUserAccountType
    1263                 :          0 : mct_user_controls_get_user_account_type (MctUserControls *self)
    1264                 :            : {
    1265                 :          0 :   g_return_val_if_fail (MCT_IS_USER_CONTROLS (self), ACT_USER_ACCOUNT_TYPE_STANDARD);
    1266                 :            : 
    1267                 :          0 :   return self->user_account_type;
    1268                 :            : }
    1269                 :            : 
    1270                 :            : /**
    1271                 :            :  * mct_user_controls_set_user_account_type:
    1272                 :            :  * @self: an #MctUserControls
    1273                 :            :  * @user_account_type: the account type of the user to configure the controls for
    1274                 :            :  *
    1275                 :            :  * Set the value of #MctUserControls:user-account-type.
    1276                 :            :  *
    1277                 :            :  * Since: 0.5.0
    1278                 :            :  */
    1279                 :            : void
    1280                 :          0 : mct_user_controls_set_user_account_type (MctUserControls    *self,
    1281                 :            :                                          ActUserAccountType  user_account_type)
    1282                 :            : {
    1283                 :          0 :   g_return_if_fail (MCT_IS_USER_CONTROLS (self));
    1284                 :            : 
    1285                 :            :   /* If we have pending unsaved changes from the previous user, force them to be
    1286                 :            :    * saved first. */
    1287                 :          0 :   flush_update_blocklisted_apps (self);
    1288                 :            : 
    1289         [ #  # ]:          0 :   if (self->user_account_type == user_account_type)
    1290                 :          0 :     return;
    1291                 :            : 
    1292                 :          0 :   self->user_account_type = user_account_type;
    1293                 :            : 
    1294                 :          0 :   setup_parental_control_settings (self);
    1295                 :            : 
    1296                 :          0 :   g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_USER_ACCOUNT_TYPE]);
    1297                 :            : }
    1298                 :            : 
    1299                 :            : /**
    1300                 :            :  * mct_user_controls_get_user_locale:
    1301                 :            :  * @self: an #MctUserControls
    1302                 :            :  *
    1303                 :            :  * Get the value of #MctUserControls:user-locale.
    1304                 :            :  *
    1305                 :            :  * Returns: (transfer none) (nullable): the locale of the user the controls
    1306                 :            :  *    are configured for, or %NULL if unknown
    1307                 :            :  * Since: 0.5.0
    1308                 :            :  */
    1309                 :            : const gchar *
    1310                 :          0 : mct_user_controls_get_user_locale (MctUserControls *self)
    1311                 :            : {
    1312                 :          0 :   g_return_val_if_fail (MCT_IS_USER_CONTROLS (self), NULL);
    1313                 :            : 
    1314                 :          0 :   return self->user_locale;
    1315                 :            : }
    1316                 :            : 
    1317                 :            : /**
    1318                 :            :  * mct_user_controls_set_user_locale:
    1319                 :            :  * @self: an #MctUserControls
    1320                 :            :  * @user_locale: (nullable) (transfer none): the locale of the user
    1321                 :            :  *    to configure the controls for, or %NULL if unknown
    1322                 :            :  *
    1323                 :            :  * Set the value of #MctUserControls:user-locale.
    1324                 :            :  *
    1325                 :            :  * Since: 0.5.0
    1326                 :            :  */
    1327                 :            : void
    1328                 :          0 : mct_user_controls_set_user_locale (MctUserControls *self,
    1329                 :            :                                    const gchar     *user_locale)
    1330                 :            : {
    1331                 :          0 :   g_return_if_fail (MCT_IS_USER_CONTROLS (self));
    1332                 :          0 :   g_return_if_fail (user_locale == NULL ||
    1333                 :            :                     (*user_locale != '\0' &&
    1334                 :            :                      g_utf8_validate (user_locale, -1, NULL)));
    1335                 :            : 
    1336                 :            :   /* If we have pending unsaved changes from the previous user, force them to be
    1337                 :            :    * saved first. */
    1338                 :          0 :   flush_update_blocklisted_apps (self);
    1339                 :            : 
    1340         [ #  # ]:          0 :   if (g_strcmp0 (self->user_locale, user_locale) == 0)
    1341                 :          0 :     return;
    1342                 :            : 
    1343         [ #  # ]:          0 :   g_clear_pointer (&self->user_locale, g_free);
    1344                 :          0 :   self->user_locale = g_strdup (user_locale);
    1345                 :            : 
    1346                 :          0 :   setup_parental_control_settings (self);
    1347                 :            : 
    1348                 :          0 :   g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_USER_LOCALE]);
    1349                 :            : }
    1350                 :            : 
    1351                 :            : /**
    1352                 :            :  * mct_user_controls_get_user_display_name:
    1353                 :            :  * @self: an #MctUserControls
    1354                 :            :  *
    1355                 :            :  * Get the value of #MctUserControls:user-display-name.
    1356                 :            :  *
    1357                 :            :  * Returns: (transfer none) (nullable): the display name of the user the controls
    1358                 :            :  *    are configured for, or %NULL if unknown
    1359                 :            :  * Since: 0.5.0
    1360                 :            :  */
    1361                 :            : const gchar *
    1362                 :          0 : mct_user_controls_get_user_display_name (MctUserControls *self)
    1363                 :            : {
    1364                 :          0 :   g_return_val_if_fail (MCT_IS_USER_CONTROLS (self), NULL);
    1365                 :            : 
    1366                 :          0 :   return self->user_display_name;
    1367                 :            : }
    1368                 :            : 
    1369                 :            : /**
    1370                 :            :  * mct_user_controls_set_user_display_name:
    1371                 :            :  * @self: an #MctUserControls
    1372                 :            :  * @user_display_name: (nullable) (transfer none): the display name of the user
    1373                 :            :  *    to configure the controls for, or %NULL if unknown
    1374                 :            :  *
    1375                 :            :  * Set the value of #MctUserControls:user-display-name.
    1376                 :            :  *
    1377                 :            :  * Since: 0.5.0
    1378                 :            :  */
    1379                 :            : void
    1380                 :          0 : mct_user_controls_set_user_display_name (MctUserControls *self,
    1381                 :            :                                          const gchar     *user_display_name)
    1382                 :            : {
    1383                 :          0 :   g_return_if_fail (MCT_IS_USER_CONTROLS (self));
    1384                 :          0 :   g_return_if_fail (user_display_name == NULL ||
    1385                 :            :                     (*user_display_name != '\0' &&
    1386                 :            :                      g_utf8_validate (user_display_name, -1, NULL)));
    1387                 :            : 
    1388                 :            :   /* If we have pending unsaved changes from the previous user, force them to be
    1389                 :            :    * saved first. */
    1390                 :          0 :   flush_update_blocklisted_apps (self);
    1391                 :            : 
    1392         [ #  # ]:          0 :   if (g_strcmp0 (self->user_display_name, user_display_name) == 0)
    1393                 :          0 :     return;
    1394                 :            : 
    1395         [ #  # ]:          0 :   g_clear_pointer (&self->user_display_name, g_free);
    1396                 :          0 :   self->user_display_name = g_strdup (user_display_name);
    1397                 :            : 
    1398                 :          0 :   setup_parental_control_settings (self);
    1399                 :            : 
    1400                 :          0 :   g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_USER_DISPLAY_NAME]);
    1401                 :            : }
    1402                 :            : 
    1403                 :            : /**
    1404                 :            :  * mct_user_controls_set_description:
    1405                 :            :  * @self: an #MctUserControls
    1406                 :            :  * @description: (nullable) (transfer none): the description shown
    1407                 :            :  *    above the controls, or %NULL if none.
    1408                 :            :  *
    1409                 :            :  * Set the value of #MctUserControls:description.
    1410                 :            :  *
    1411                 :            :  * Since: 0.11.0
    1412                 :            :  */
    1413                 :            : void
    1414                 :          0 : mct_user_controls_set_description (MctUserControls *self,
    1415                 :            :                                    const gchar     *description)
    1416                 :            : {
    1417                 :          0 :   g_return_if_fail (MCT_IS_USER_CONTROLS (self));
    1418                 :          0 :   g_return_if_fail (description != NULL);
    1419                 :            : 
    1420                 :            :   /* If we have pending unsaved changes from the previous user, force them to be
    1421                 :            :    * saved first. */
    1422                 :          0 :   flush_update_blocklisted_apps (self);
    1423                 :            : 
    1424         [ #  # ]:          0 :   if (g_strcmp0 (self->description, description) == 0)
    1425                 :          0 :     return;
    1426                 :            : 
    1427         [ #  # ]:          0 :   g_clear_pointer (&self->description, g_free);
    1428                 :          0 :   self->description = g_strdup (description);
    1429                 :            : 
    1430                 :          0 :   setup_parental_control_settings (self);
    1431                 :            : 
    1432                 :          0 :   g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DESCRIPTION]);
    1433                 :            : }
    1434                 :            : 
    1435                 :            : /**
    1436                 :            :  * mct_user_controls_build_app_filter:
    1437                 :            :  * @self: an #MctUserControls
    1438                 :            :  * @builder: an existing #MctAppFilterBuilder to modify
    1439                 :            :  *
    1440                 :            :  * Get the app filter settings currently configured in the user controls, by
    1441                 :            :  * modifying the given @builder. This can be used to save the settings manually.
    1442                 :            :  *
    1443                 :            :  * Since: 0.5.0
    1444                 :            :  */
    1445                 :            : void
    1446                 :          0 : mct_user_controls_build_app_filter (MctUserControls     *self,
    1447                 :            :                                     MctAppFilterBuilder *builder)
    1448                 :            : {
    1449                 :            :   gboolean restrict_web_browsers;
    1450                 :            :   gsize i;
    1451         [ #  # ]:          0 :   g_autofree const gchar **oars_categories = as_content_rating_get_all_rating_ids ();
    1452                 :            : 
    1453                 :          0 :   g_return_if_fail (MCT_IS_USER_CONTROLS (self));
    1454                 :          0 :   g_return_if_fail (builder != NULL);
    1455                 :            : 
    1456                 :          0 :   g_debug ("Building parental controls settings…");
    1457                 :            : 
    1458                 :            :   /* Blocklist */
    1459                 :            : 
    1460                 :          0 :   g_debug ("\t → Blocklisting apps");
    1461                 :            : 
    1462                 :          0 :   mct_restrict_applications_dialog_build_app_filter (self->restrict_applications_dialog, builder);
    1463                 :            : 
    1464                 :            :   /* Maturity level */
    1465                 :            : 
    1466                 :          0 :   g_debug ("\t → Maturity level");
    1467                 :            : 
    1468         [ #  # ]:          0 :   if (self->selected_age == oars_disabled_age)
    1469                 :          0 :     g_debug ("\t\t → Disabled");
    1470                 :            : 
    1471   [ #  #  #  # ]:          0 :   for (i = 0; self->selected_age != oars_disabled_age && oars_categories[i] != NULL; i++)
    1472                 :            :     {
    1473                 :            :       MctAppFilterOarsValue oars_value;
    1474                 :            :       const gchar *oars_category;
    1475                 :            : 
    1476                 :          0 :       oars_category = oars_categories[i];
    1477                 :          0 :       oars_value = (MctAppFilterOarsValue) as_content_rating_attribute_from_csm_age (oars_category, self->selected_age);
    1478                 :            : 
    1479                 :          0 :       g_debug ("\t\t → %s: %s", oars_category, oars_value_to_string (oars_value));
    1480                 :            : 
    1481                 :          0 :       mct_app_filter_builder_set_oars_value (builder, oars_category, oars_value);
    1482                 :            :     }
    1483                 :            : 
    1484                 :            :   /* Web browsers */
    1485                 :          0 :   restrict_web_browsers = gtk_switch_get_active (self->restrict_web_browsers_switch);
    1486                 :            : 
    1487         [ #  # ]:          0 :   g_debug ("\t → %s web browsers", restrict_web_browsers ? "Restricting" : "Allowing");
    1488                 :            : 
    1489         [ #  # ]:          0 :   if (restrict_web_browsers)
    1490                 :          0 :     mct_app_filter_builder_blocklist_content_type (builder, WEB_BROWSERS_CONTENT_TYPE);
    1491                 :            : 
    1492                 :            :   /* App installation */
    1493         [ #  # ]:          0 :   if (self->user_account_type != ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR)
    1494                 :            :     {
    1495                 :            :       gboolean restrict_software_installation;
    1496                 :            : 
    1497                 :          0 :       restrict_software_installation = gtk_switch_get_active (self->restrict_software_installation_switch);
    1498                 :            : 
    1499         [ #  # ]:          0 :       g_debug ("\t → %s system installation", restrict_software_installation ? "Restricting" : "Allowing");
    1500         [ #  # ]:          0 :       g_debug ("\t → %s user installation", restrict_software_installation ? "Restricting" : "Allowing");
    1501                 :            : 
    1502                 :          0 :       mct_app_filter_builder_set_allow_user_installation (builder, !restrict_software_installation);
    1503                 :          0 :       mct_app_filter_builder_set_allow_system_installation (builder, !restrict_software_installation);
    1504                 :            :     }
    1505                 :            : }

Generated by: LCOV version 1.16