LCOV - code coverage report
Current view: top level - malcontent-control - access-page.c (source / functions) Coverage Total Hit
Test: 2 coverage DB files Lines: 0.0 % 68 0
Test Date: 2025-09-15 13:55:46 Functions: 0.0 % 12 0
Branches: 0.0 % 24 0

             Branch data     Line data    Source code
       1                 :             : /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
       2                 :             :  *
       3                 :             :  * Copyright 2025 GNOME Foundation, Inc.
       4                 :             :  *
       5                 :             :  * SPDX-License-Identifier: GPL-2.0-or-later
       6                 :             :  *
       7                 :             :  * This program is free software; you can redistribute it and/or modify
       8                 :             :  * it under the terms of the GNU General Public License as published by
       9                 :             :  * the Free Software Foundation; either version 2 of the License, or
      10                 :             :  * (at your option) any later version.
      11                 :             :  *
      12                 :             :  * This program is distributed in the hope that it will be useful,
      13                 :             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :             :  * GNU General Public License for more details.
      16                 :             :  *
      17                 :             :  * You should have received a copy of the GNU General Public License
      18                 :             :  * along with this program; if not, see <http://www.gnu.org/licenses/>.
      19                 :             :  *
      20                 :             :  * Authors:
      21                 :             :  *  - Ignacy Kuchciński <ignacykuchcinski@gnome.org>
      22                 :             :  */
      23                 :             : 
      24                 :             : #include "config.h"
      25                 :             : 
      26                 :             : #include <glib/gi18n-lib.h>
      27                 :             : #include <libmalcontent-ui/malcontent-ui.h>
      28                 :             : 
      29                 :             : #include "access-page.h"
      30                 :             : 
      31                 :             : /**
      32                 :             :  * MctAccessPage:
      33                 :             :  *
      34                 :             :  * A widget which shows parental controls access and restrictions
      35                 :             :  * for the selected user.
      36                 :             :  *
      37                 :             :  * Since: 0.14.0
      38                 :             :  */
      39                 :             : struct _MctAccessPage
      40                 :             : {
      41                 :             :   AdwNavigationPage parent;
      42                 :             : 
      43                 :             :   AdwWindowTitle *access_window_title;
      44                 :             :   MctUserControls *user_controls;
      45                 :             : 
      46                 :             :   MctUser *user; /* (owned) */
      47                 :             :   unsigned long user_notify_id;
      48                 :             : };
      49                 :             : 
      50   [ #  #  #  #  :           0 : G_DEFINE_TYPE (MctAccessPage, mct_access_page, ADW_TYPE_NAVIGATION_PAGE)
                   #  # ]
      51                 :             : 
      52                 :             : typedef enum
      53                 :             : {
      54                 :             :   PROP_USER = 1,
      55                 :             : } MctAccessPageProperty;
      56                 :             : 
      57                 :             : static GParamSpec *properties[PROP_USER + 1];
      58                 :             : 
      59                 :             : static void
      60                 :           0 : mct_access_page_get_property (GObject    *object,
      61                 :             :                               guint       prop_id,
      62                 :             :                               GValue     *value,
      63                 :             :                               GParamSpec *pspec)
      64                 :             : {
      65                 :           0 :   MctAccessPage *self = MCT_ACCESS_PAGE (object);
      66                 :             : 
      67         [ #  # ]:           0 :   switch ((MctAccessPageProperty) prop_id)
      68                 :             :     {
      69                 :           0 :       case PROP_USER:
      70                 :           0 :         g_value_set_object (value, self->user);
      71                 :           0 :         break;
      72                 :             : 
      73                 :           0 :       default:
      74                 :           0 :         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      75                 :             :     }
      76                 :           0 : }
      77                 :             : 
      78                 :             : static void
      79                 :           0 : mct_access_page_set_property (GObject      *object,
      80                 :             :                               guint         prop_id,
      81                 :             :                               const GValue *value,
      82                 :             :                               GParamSpec   *pspec)
      83                 :             : {
      84                 :           0 :   MctAccessPage *self = MCT_ACCESS_PAGE (object);
      85                 :             : 
      86         [ #  # ]:           0 :   switch ((MctAccessPageProperty) prop_id)
      87                 :             :     {
      88                 :           0 :       case PROP_USER:
      89                 :           0 :         mct_access_page_set_user (self, g_value_dup_object (value), NULL);
      90                 :           0 :         break;
      91                 :             : 
      92                 :           0 :       default:
      93                 :           0 :         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      94                 :             :     }
      95                 :           0 : }
      96                 :             : 
      97                 :             : static void
      98                 :           0 : mct_access_page_dispose (GObject *object)
      99                 :             : {
     100                 :           0 :   MctAccessPage *self = MCT_ACCESS_PAGE (object);
     101                 :             : 
     102         [ #  # ]:           0 :   g_clear_signal_handler (&self->user_notify_id, self->user);
     103         [ #  # ]:           0 :   g_clear_object (&self->user);
     104                 :             : 
     105                 :           0 :   G_OBJECT_CLASS (mct_access_page_parent_class)->dispose (object);
     106                 :           0 : }
     107                 :             : 
     108                 :             : static void
     109                 :           0 : mct_access_page_class_init (MctAccessPageClass *klass)
     110                 :             : {
     111                 :           0 :   GObjectClass *object_class = G_OBJECT_CLASS (klass);
     112                 :           0 :   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
     113                 :             : 
     114                 :           0 :   object_class->get_property = mct_access_page_get_property;
     115                 :           0 :   object_class->set_property = mct_access_page_set_property;
     116                 :           0 :   object_class->dispose = mct_access_page_dispose;
     117                 :             : 
     118                 :             :   /**
     119                 :             :    * MctAccessPage:user: (not nullable)
     120                 :             :    *
     121                 :             :    * The currently selected user account.
     122                 :             :    *
     123                 :             :    * Since 0.14.0
     124                 :             :    */
     125                 :           0 :   properties[PROP_USER] =
     126                 :           0 :       g_param_spec_object ("user", NULL, NULL,
     127                 :             :                            MCT_TYPE_USER,
     128                 :             :                            G_PARAM_READWRITE |
     129                 :             :                            G_PARAM_STATIC_STRINGS |
     130                 :             :                            G_PARAM_EXPLICIT_NOTIFY);
     131                 :             : 
     132                 :           0 :   g_object_class_install_properties (object_class, G_N_ELEMENTS (properties), properties);
     133                 :             : 
     134                 :           0 :   gtk_widget_class_set_template_from_resource (widget_class, "/org/freedesktop/MalcontentControl/ui/access-page.ui");
     135                 :             : 
     136                 :           0 :   gtk_widget_class_bind_template_child (widget_class, MctAccessPage, access_window_title);
     137                 :           0 :   gtk_widget_class_bind_template_child (widget_class, MctAccessPage, user_controls);
     138                 :           0 : }
     139                 :             : 
     140                 :             : static void
     141                 :           0 : mct_access_page_init (MctAccessPage *self)
     142                 :             : {
     143                 :           0 :   gtk_widget_init_template (GTK_WIDGET (self));
     144                 :           0 : }
     145                 :             : 
     146                 :             : /**
     147                 :             :  * mct_access_page_new:
     148                 :             :  *
     149                 :             :  * Create a new #MctAccessPage widget.
     150                 :             :  *
     151                 :             :  * Returns: (transfer full): a new access page
     152                 :             :  * Since: 0.14.0
     153                 :             :  */
     154                 :             : MctAccessPage *
     155                 :           0 : mct_access_page_new (void)
     156                 :             : {
     157                 :           0 :   return g_object_new (MCT_TYPE_ACCESS_PAGE,
     158                 :             :                        NULL);
     159                 :             : }
     160                 :             : 
     161                 :             : /**
     162                 :             :  * mct_access_page_get_user:
     163                 :             :  * @self: an #MctAccessPage
     164                 :             :  * @user: an #MctUser
     165                 :             :  *
     166                 :             :  * Get the currently selected user.
     167                 :             :  *
     168                 :             :  * Returns: (transfer none): the currently selected user
     169                 :             :  * Since: 0.14.0
     170                 :             :  */
     171                 :             : MctUser *
     172                 :           0 : mct_access_page_get_user (MctAccessPage *self)
     173                 :             : {
     174                 :           0 :   g_return_val_if_fail (MCT_IS_ACCESS_PAGE (self), NULL);
     175                 :             : 
     176                 :           0 :   return self->user;
     177                 :             : }
     178                 :             : 
     179                 :             : static void
     180                 :           0 : user_notify_cb (GObject    *object,
     181                 :             :                 GParamSpec *pspec,
     182                 :             :                 void       *user_data)
     183                 :             : {
     184                 :           0 :   MctUser *user = MCT_USER (object);
     185                 :           0 :   MctAccessPage *self = MCT_ACCESS_PAGE (user_data);
     186                 :           0 :   g_autofree gchar *help_label = NULL;
     187                 :             : 
     188                 :           0 :   adw_window_title_set_subtitle (self->access_window_title,
     189                 :             :                                  mct_user_get_display_name (user));
     190                 :             : 
     191                 :             :   /* Translators: Replace the link to commonsensemedia.org with some
     192                 :             :    * localised guidance for parents/carers on how to set restrictions on
     193                 :             :    * their child/caree in a responsible way which is in keeping with the
     194                 :             :    * best practice and culture of the region. If no suitable localised
     195                 :             :    * guidance exists, and if the default commonsensemedia.org link is not
     196                 :             :    * suitable, please file an issue against malcontent so we can discuss
     197                 :             :    * further!
     198                 :             :    * https://gitlab.freedesktop.org/pwithnall/malcontent/-/issues/new
     199                 :             :    */
     200                 :           0 :   help_label = g_strdup_printf (_("It’s recommended that restrictions are "
     201                 :             :                                   "set as part of an ongoing conversation "
     202                 :             :                                   "with %s. <a href='https://www.commonsensemedia.org/privacy-and-internet-safety'>"
     203                 :             :                                   "Read guidance</a> on what to consider."),
     204                 :             :                                 mct_user_get_display_name (user));
     205                 :             : 
     206                 :           0 :   mct_user_controls_set_description (self->user_controls, help_label);
     207                 :           0 : }
     208                 :             : 
     209                 :             : /**
     210                 :             :  * mct_access_page_set_user:
     211                 :             :  * @self: an #MctAccessPage
     212                 :             :  * @user: an #MctUser
     213                 :             :  * @permission: (nullable) (transfer none): the #GPermission indicating whether
     214                 :             :  *    the current user has permission to view or change parental controls, or
     215                 :             :  *    %NULL if permission is not allowed or is unknown
     216                 :             :  *
     217                 :             :  * Set the currently selected user.
     218                 :             :  *
     219                 :             :  * Since: 0.14.0
     220                 :             :  */
     221                 :             : void
     222                 :           0 : mct_access_page_set_user (MctAccessPage *self,
     223                 :             :                           MctUser       *user,
     224                 :             :                           GPermission   *permission)
     225                 :             : {
     226                 :           0 :   g_return_if_fail (MCT_IS_ACCESS_PAGE (self));
     227                 :           0 :   g_return_if_fail (MCT_IS_USER (user));
     228                 :             : 
     229                 :           0 :   g_autoptr(MctUser) old_user = NULL;
     230                 :             : 
     231         [ #  # ]:           0 :   old_user = (self->user != NULL) ? g_object_ref (self->user) : NULL;
     232                 :             : 
     233         [ #  # ]:           0 :   if (g_set_object (&self->user, user))
     234                 :             :     {
     235         [ #  # ]:           0 :       if (old_user != NULL)
     236         [ #  # ]:           0 :         g_clear_signal_handler (&self->user_notify_id, old_user);
     237                 :             : 
     238         [ #  # ]:           0 :       if (user != NULL)
     239                 :             :         {
     240                 :           0 :           self->user_notify_id = g_signal_connect (user,
     241                 :             :                                                    "notify",
     242                 :             :                                                    G_CALLBACK (user_notify_cb),
     243                 :             :                                                    self);
     244                 :           0 :           user_notify_cb (G_OBJECT (user), NULL, self);
     245                 :             :         }
     246                 :             : 
     247                 :           0 :       mct_user_controls_set_permission (self->user_controls, permission);
     248                 :           0 :       mct_user_controls_set_user (self->user_controls, user);
     249                 :             : 
     250                 :           0 :       g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_USER]);
     251                 :             :     }
     252                 :             : }
        

Generated by: LCOV version 2.0-1