LCOV - code coverage report
Current view: top level - src/plugins/gnome - valent-preferences-page.c (source / functions) Coverage Total Hit
Test: Code Coverage Lines: 80.0 % 60 48
Test Date: 2025-04-18 23:22:27 Functions: 90.0 % 10 9
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 50.0 % 34 17

             Branch data     Line data    Source code
       1                 :             : // SPDX-License-Identifier: GPL-3.0-or-later
       2                 :             : // SPDX-FileCopyrightText: Andy Holmes <andrew.g.r.holmes@gmail.com>
       3                 :             : 
       4                 :             : #define G_LOG_DOMAIN "valent-device-preferences"
       5                 :             : 
       6                 :             : #include "config.h"
       7                 :             : 
       8                 :             : #include <gio/gio.h>
       9                 :             : #include <gtk/gtk.h>
      10                 :             : #include <adwaita.h>
      11                 :             : #include <valent.h>
      12                 :             : 
      13                 :             : #include "valent-preferences-page.h"
      14                 :             : 
      15                 :             : typedef struct
      16                 :             : {
      17                 :             :   ValentContext  *context;
      18                 :             :   GHashTable     *settings;
      19                 :             : } ValentPreferencesPagePrivate;
      20                 :             : 
      21   [ +  +  +  - ]:         204 : G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ValentPreferencesPage, valent_preferences_page, ADW_TYPE_PREFERENCES_PAGE)
      22                 :             : 
      23                 :             : typedef enum {
      24                 :             :   PROP_CONTEXT = 1,
      25                 :             : } ValentPreferencesPageProperty;
      26                 :             : 
      27                 :             : static GParamSpec *properties[PROP_CONTEXT + 1] = { NULL, };
      28                 :             : 
      29                 :             : /*
      30                 :             :  * GObject
      31                 :             :  */
      32                 :             : static void
      33                 :           9 : valent_preferences_page_finalize (GObject *object)
      34                 :             : {
      35                 :           9 :   ValentPreferencesPage *self = VALENT_PREFERENCES_PAGE (object);
      36                 :           9 :   ValentPreferencesPagePrivate *priv = valent_preferences_page_get_instance_private (self);
      37                 :             : 
      38         [ +  - ]:           9 :   g_clear_object (&priv->context);
      39         [ +  - ]:           9 :   g_clear_pointer (&priv->settings, g_hash_table_unref);
      40                 :             : 
      41                 :           9 :   G_OBJECT_CLASS (valent_preferences_page_parent_class)->finalize (object);
      42                 :           9 : }
      43                 :             : 
      44                 :             : static void
      45                 :           0 : valent_preferences_page_get_property (GObject    *object,
      46                 :             :                                       guint       prop_id,
      47                 :             :                                       GValue     *value,
      48                 :             :                                       GParamSpec *pspec)
      49                 :             : {
      50                 :           0 :   ValentPreferencesPage *self = VALENT_PREFERENCES_PAGE (object);
      51                 :           0 :   ValentPreferencesPagePrivate *priv = valent_preferences_page_get_instance_private (self);
      52                 :             : 
      53         [ #  # ]:           0 :   switch ((ValentPreferencesPageProperty)prop_id)
      54                 :             :     {
      55                 :           0 :     case PROP_CONTEXT:
      56                 :           0 :       g_value_set_object (value, priv->context);
      57                 :           0 :       break;
      58                 :             : 
      59                 :           0 :     default:
      60                 :           0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      61                 :             :     }
      62                 :           0 : }
      63                 :             : 
      64                 :             : static void
      65                 :           9 : valent_preferences_page_set_property (GObject      *object,
      66                 :             :                                       guint         prop_id,
      67                 :             :                                       const GValue *value,
      68                 :             :                                       GParamSpec   *pspec)
      69                 :             : {
      70                 :           9 :   ValentPreferencesPage *self = VALENT_PREFERENCES_PAGE (object);
      71                 :           9 :   ValentPreferencesPagePrivate *priv = valent_preferences_page_get_instance_private (self);
      72                 :             : 
      73         [ +  - ]:           9 :   switch ((ValentPreferencesPageProperty)prop_id)
      74                 :             :     {
      75                 :           9 :     case PROP_CONTEXT:
      76                 :           9 :       g_set_object (&priv->context, g_value_get_object (value));
      77                 :           9 :       break;
      78                 :             : 
      79                 :           0 :     default:
      80                 :           0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      81                 :             :     }
      82                 :           9 : }
      83                 :             : 
      84                 :             : static void
      85                 :           2 : valent_preferences_page_class_init (ValentPreferencesPageClass *klass)
      86                 :             : {
      87                 :           2 :   GObjectClass *object_class = G_OBJECT_CLASS (klass);
      88                 :             : 
      89                 :           2 :   object_class->finalize = valent_preferences_page_finalize;
      90                 :           2 :   object_class->get_property = valent_preferences_page_get_property;
      91                 :           2 :   object_class->set_property = valent_preferences_page_set_property;
      92                 :             : 
      93                 :           4 :   properties [PROP_CONTEXT] =
      94                 :           2 :     g_param_spec_object ("context", NULL, NULL,
      95                 :             :                          VALENT_TYPE_CONTEXT,
      96                 :             :                          (G_PARAM_READWRITE |
      97                 :             :                           G_PARAM_STATIC_STRINGS));
      98                 :             : 
      99                 :           2 :   g_object_class_install_properties (object_class, G_N_ELEMENTS (properties), properties);
     100                 :           2 : }
     101                 :             : 
     102                 :             : static void
     103                 :           9 : valent_preferences_page_init (ValentPreferencesPage *self)
     104                 :             : {
     105                 :           9 :   ValentPreferencesPagePrivate *priv = valent_preferences_page_get_instance_private (self);
     106                 :             : 
     107                 :           9 :   priv->settings = g_hash_table_new_full (g_str_hash, g_str_equal,
     108                 :             :                                           g_free, g_object_unref);
     109                 :           9 : }
     110                 :             : 
     111                 :             : ValentContext *
     112                 :           9 : valent_preferences_page_get_context (ValentPreferencesPage *page)
     113                 :             : {
     114                 :           9 :   ValentPreferencesPagePrivate *priv = valent_preferences_page_get_instance_private (page);
     115                 :             : 
     116         [ +  - ]:           9 :   g_return_val_if_fail (VALENT_IS_PREFERENCES_PAGE (page), NULL);
     117                 :             : 
     118                 :           9 :   return priv->context;
     119                 :             : }
     120                 :             : 
     121                 :             : GSettings *
     122                 :          36 : valent_preferences_page_get_settings (ValentPreferencesPage *page,
     123                 :             :                                       const char            *name)
     124                 :             : {
     125                 :          36 :   ValentPreferencesPagePrivate *priv = valent_preferences_page_get_instance_private (page);
     126                 :          36 :   GSettings *settings = NULL;
     127                 :             : 
     128         [ +  - ]:          36 :   g_return_val_if_fail (VALENT_IS_PREFERENCES_PAGE (page), NULL);
     129   [ +  -  -  + ]:          36 :   g_return_val_if_fail (name != NULL && *name != '\0', NULL);
     130                 :             : 
     131                 :          36 :   settings = g_hash_table_lookup (priv->settings, name);
     132         [ +  + ]:          36 :   if (settings == NULL)
     133                 :             :     {
     134                 :          63 :       g_autoptr (ValentContext) plugin_context = NULL;
     135                 :          27 :       PeasEngine *engine = valent_get_plugin_engine ();
     136                 :          27 :       PeasPluginInfo *plugin_info = NULL;
     137                 :             : 
     138                 :          27 :       plugin_context = g_object_new (VALENT_TYPE_CONTEXT,
     139                 :             :                                      "parent", priv->context,
     140                 :             :                                      "domain", "plugin",
     141                 :             :                                      "id",     name,
     142                 :             :                                      NULL);
     143                 :          27 :       plugin_info = peas_engine_get_plugin_info (engine, name);
     144                 :          27 :       settings = valent_context_get_plugin_settings (plugin_context,
     145                 :             :                                                      plugin_info,
     146                 :             :                                                      "X-DevicePluginSettings");
     147   [ -  +  +  - ]:          54 :       g_hash_table_replace (priv->settings, g_strdup (name), settings);
     148                 :             :     }
     149                 :             : 
     150   [ +  -  +  -  :          36 :   g_return_val_if_fail (G_IS_SETTINGS (settings), NULL);
             -  +  -  - ]
     151                 :             : 
     152                 :             :   return settings;
     153                 :             : }
     154                 :             : 
        

Generated by: LCOV version 2.0-1