LCOV - code coverage report
Current view: top level - src/libvalent/ui - valent-device-gadget.c (source / functions) Coverage Total Hit
Test: Code Coverage Lines: 87.9 % 33 29
Test Date: 2024-04-23 06:02:46 Functions: 100.0 % 7 7
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 62.5 % 8 5

             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-gadget"
       5                 :             : 
       6                 :             : #include "config.h"
       7                 :             : 
       8                 :             : #include <gtk/gtk.h>
       9                 :             : #include <libvalent-core.h>
      10                 :             : #include <libvalent-device.h>
      11                 :             : 
      12                 :             : #include "valent-device-gadget.h"
      13                 :             : 
      14                 :             : 
      15                 :             : /**
      16                 :             :  * ValentDeviceGadget:
      17                 :             :  *
      18                 :             :  * An abstract base class for device plugin gadgets.
      19                 :             :  *
      20                 :             :  * `ValentDeviceGadget` is an base class for [class@Valent.DevicePlugin]
      21                 :             :  * implementations that want to provide a small widget to display or control a
      22                 :             :  * simple state (e.g. battery level).
      23                 :             :  *
      24                 :             :  * Since: 1.0
      25                 :             :  */
      26                 :             : 
      27                 :             : typedef struct
      28                 :             : {
      29                 :             :   GtkWidget     parent_instance;
      30                 :             : 
      31                 :             :   ValentDevice *device;
      32                 :             : } ValentDeviceGadgetPrivate;
      33                 :             : 
      34   [ +  +  +  - ]:         351 : G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ValentDeviceGadget, valent_device_gadget, GTK_TYPE_WIDGET)
      35                 :             : 
      36                 :             : 
      37                 :             : enum {
      38                 :             :   PROP_0,
      39                 :             :   PROP_DEVICE,
      40                 :             :   N_PROPERTIES
      41                 :             : };
      42                 :             : 
      43                 :             : static GParamSpec *properties[N_PROPERTIES] = { NULL, };
      44                 :             : 
      45                 :             : 
      46                 :             : /*
      47                 :             :  * GObject
      48                 :             :  */
      49                 :             : static void
      50                 :           5 : valent_device_gadget_get_property (GObject    *object,
      51                 :             :                                    guint       prop_id,
      52                 :             :                                    GValue     *value,
      53                 :             :                                    GParamSpec *pspec)
      54                 :             : {
      55                 :           5 :   ValentDeviceGadget *self = VALENT_DEVICE_GADGET (object);
      56                 :           5 :   ValentDeviceGadgetPrivate *priv = valent_device_gadget_get_instance_private (self);
      57                 :             : 
      58         [ +  - ]:           5 :   switch (prop_id)
      59                 :             :     {
      60                 :           5 :     case PROP_DEVICE:
      61                 :           5 :       g_value_set_object (value, priv->device);
      62                 :           5 :       break;
      63                 :             : 
      64                 :           0 :     default:
      65                 :           0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      66                 :             :     }
      67                 :           5 : }
      68                 :             : 
      69                 :             : static void
      70                 :           7 : valent_device_gadget_set_property (GObject      *object,
      71                 :             :                                    guint         prop_id,
      72                 :             :                                    const GValue *value,
      73                 :             :                                    GParamSpec   *pspec)
      74                 :             : {
      75                 :           7 :   ValentDeviceGadget *self = VALENT_DEVICE_GADGET (object);
      76                 :           7 :   ValentDeviceGadgetPrivate *priv = valent_device_gadget_get_instance_private (self);
      77                 :             : 
      78         [ +  - ]:           7 :   switch (prop_id)
      79                 :             :     {
      80                 :           7 :     case PROP_DEVICE:
      81                 :           7 :       priv->device = g_value_get_object (value);
      82                 :           7 :       break;
      83                 :             : 
      84                 :           0 :     default:
      85                 :           0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      86                 :             :     }
      87                 :           7 : }
      88                 :             : 
      89                 :             : static void
      90                 :          66 : valent_device_gadget_class_init (ValentDeviceGadgetClass *klass)
      91                 :             : {
      92                 :          66 :   GObjectClass *object_class = G_OBJECT_CLASS (klass);
      93                 :          66 :   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
      94                 :             : 
      95                 :          66 :   object_class->get_property = valent_device_gadget_get_property;
      96                 :          66 :   object_class->set_property = valent_device_gadget_set_property;
      97                 :             : 
      98                 :             :   /**
      99                 :             :    * ValentDeviceGadget:device:
     100                 :             :    *
     101                 :             :    * The [class@Valent.Device] this gadget is for.
     102                 :             :    *
     103                 :             :    * Since: 1.0
     104                 :             :    */
     105                 :         132 :   properties [PROP_DEVICE] =
     106                 :          66 :     g_param_spec_object ("device", NULL, NULL,
     107                 :             :                          VALENT_TYPE_DEVICE,
     108                 :             :                          (G_PARAM_READWRITE |
     109                 :             :                           G_PARAM_CONSTRUCT_ONLY |
     110                 :             :                           G_PARAM_EXPLICIT_NOTIFY |
     111                 :             :                           G_PARAM_STATIC_STRINGS));
     112                 :             : 
     113                 :          66 :   g_object_class_install_properties (object_class, N_PROPERTIES, properties);
     114                 :             : 
     115                 :          66 :   gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
     116                 :          66 : }
     117                 :             : 
     118                 :             : static void
     119                 :           7 : valent_device_gadget_init (ValentDeviceGadget *self)
     120                 :             : {
     121                 :           7 : }
     122                 :             : 
        

Generated by: LCOV version 2.0-1