LCOV - code coverage report
Current view: top level - gcr - gcr-certificate-section.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 53 70 75.7 %
Date: 2022-09-04 10:20:22 Functions: 13 14 92.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 14 27 51.9 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright 2021 Collabora Ltd.
       3                 :            :  * Copyright Corentin Noël <corentin.noel@collabora.com>
       4                 :            :  * SPDX-License-Identifier: LGPL-2.1-or-later
       5                 :            :  */
       6                 :            : 
       7                 :            : #include "gcr-certificate-field.h"
       8                 :            : #include "gcr-certificate-section.h"
       9                 :            : #include "gcr-enum-types.h"
      10                 :            : 
      11                 :            : struct _GcrCertificateSection {
      12                 :            :         GObject parent_instance;
      13                 :            : 
      14                 :            :         char *label;
      15                 :            :         GcrCertificateSectionFlags flags;
      16                 :            :         GListStore *fields;
      17                 :            : };
      18                 :            : 
      19   [ +  +  +  -  :        145 : G_DEFINE_FINAL_TYPE (GcrCertificateSection, gcr_certificate_section, G_TYPE_OBJECT)
                   +  + ]
      20                 :            : 
      21                 :            : enum {
      22                 :            :         PROP_LABEL = 1,
      23                 :            :         PROP_FIELDS,
      24                 :            :         PROP_FLAGS,
      25                 :            :         N_PROPERTIES
      26                 :            : };
      27                 :            : 
      28                 :            : static GParamSpec *obj_properties [N_PROPERTIES];
      29                 :            : 
      30                 :            : 
      31                 :            : /**
      32                 :            :  * _gcr_certificate_section_new:
      33                 :            :  * @label: the user-displayable label of the section
      34                 :            :  * @important: whether this section should be visible by default
      35                 :            :  *
      36                 :            :  * Create a new certificate section usable in user interfaces.
      37                 :            :  *
      38                 :            :  * Returns: (transfer full): a new #GcrCertificateSection
      39                 :            :  */
      40                 :            : GcrCertificateSection *
      41                 :         16 : _gcr_certificate_section_new (const char *label,
      42                 :            :                               gboolean    important)
      43                 :            : {
      44                 :         16 :         return g_object_new (GCR_TYPE_CERTIFICATE_SECTION,
      45                 :            :                              "label", label,
      46                 :            :                              "flags", important ? GCR_CERTIFICATE_SECTION_IMPORTANT : GCR_CERTIFICATE_SECTION_NONE,
      47                 :            :                              NULL);
      48                 :            : }
      49                 :            : 
      50                 :            : static void
      51                 :         16 : gcr_certificate_section_finalize (GObject *object)
      52                 :            : {
      53                 :         16 :         GcrCertificateSection *self = (GcrCertificateSection *)object;
      54         [ +  - ]:         16 :         g_clear_pointer (&self->label, g_free);
      55                 :            : 
      56                 :         16 :         G_OBJECT_CLASS (gcr_certificate_section_parent_class)->finalize (object);
      57                 :         16 : }
      58                 :            : 
      59                 :            : static void
      60                 :         16 : gcr_certificate_section_dispose (GObject *object)
      61                 :            : {
      62                 :         16 :         GcrCertificateSection *self = (GcrCertificateSection *)object;
      63         [ +  - ]:         16 :         g_clear_object (&self->fields);
      64                 :            : 
      65                 :         16 :         G_OBJECT_CLASS (gcr_certificate_section_parent_class)->dispose (object);
      66                 :         16 : }
      67                 :            : 
      68                 :            : static void
      69                 :          0 : gcr_certificate_section_get_property (GObject    *object,
      70                 :            :                                       guint       prop_id,
      71                 :            :                                       GValue     *value,
      72                 :            :                                       GParamSpec *pspec)
      73                 :            : {
      74                 :          0 :         GcrCertificateSection *self = GCR_CERTIFICATE_SECTION (object);
      75                 :            : 
      76   [ #  #  #  # ]:          0 :         switch (prop_id) {
      77                 :          0 :         case PROP_LABEL:
      78                 :          0 :                 g_value_set_string (value, self->label);
      79                 :          0 :                 break;
      80                 :          0 :         case PROP_FIELDS:
      81                 :          0 :                 g_value_set_object (value, &self->fields);
      82                 :          0 :                 break;
      83                 :          0 :         case PROP_FLAGS:
      84                 :          0 :                 g_value_set_flags (value, self->flags);
      85                 :          0 :                 break;
      86                 :          0 :         default:
      87                 :          0 :                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      88                 :            :         }
      89                 :          0 : }
      90                 :            : 
      91                 :            : static void
      92                 :         32 : gcr_certificate_section_set_property (GObject      *object,
      93                 :            :                                       guint         prop_id,
      94                 :            :                                       const GValue *value,
      95                 :            :                                       GParamSpec   *pspec)
      96                 :            : {
      97                 :         32 :         GcrCertificateSection *self = GCR_CERTIFICATE_SECTION (object);
      98                 :            : 
      99      [ +  +  - ]:         32 :         switch (prop_id) {
     100                 :         16 :         case PROP_LABEL:
     101                 :         16 :                 self->label = g_value_dup_string (value);
     102                 :         16 :                 break;
     103                 :         16 :         case PROP_FLAGS:
     104                 :         16 :                 self->flags = g_value_get_flags (value);
     105                 :         16 :                 break;
     106                 :          0 :         default:
     107                 :          0 :                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     108                 :            :         }
     109                 :         32 : }
     110                 :            : 
     111                 :            : static void
     112                 :          1 : gcr_certificate_section_class_init (GcrCertificateSectionClass *klass)
     113                 :            : {
     114                 :          1 :         GObjectClass *object_class = G_OBJECT_CLASS (klass);
     115                 :            : 
     116                 :          1 :         object_class->finalize = gcr_certificate_section_finalize;
     117                 :          1 :         object_class->dispose = gcr_certificate_section_dispose;
     118                 :          1 :         object_class->get_property = gcr_certificate_section_get_property;
     119                 :          1 :         object_class->set_property = gcr_certificate_section_set_property;
     120                 :            : 
     121                 :          1 :         obj_properties[PROP_LABEL] =
     122                 :          1 :                 g_param_spec_string ("label",
     123                 :            :                                      "Label",
     124                 :            :                                      "Display name of the field.",
     125                 :            :                                      NULL,
     126                 :            :                                      G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
     127                 :            : 
     128                 :          1 :         obj_properties[PROP_FIELDS] =
     129                 :          1 :                 g_param_spec_object ("fields",
     130                 :            :                                      "Fields",
     131                 :            :                                      "The list of fields.",
     132                 :            :                                      G_TYPE_LIST_MODEL,
     133                 :            :                                      G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
     134                 :            : 
     135                 :          1 :         obj_properties[PROP_FLAGS] =
     136                 :          1 :                 g_param_spec_flags ("flags",
     137                 :            :                                     "Flags",
     138                 :            :                                     "Flags defined for the section.",
     139                 :            :                                     GCR_TYPE_CERTIFICATE_SECTION_FLAGS,
     140                 :            :                                     GCR_CERTIFICATE_SECTION_NONE,
     141                 :            :                                     G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
     142                 :            : 
     143                 :          1 :         g_object_class_install_properties (object_class,
     144                 :            :                                            N_PROPERTIES,
     145                 :            :                                            obj_properties);
     146                 :          1 : }
     147                 :            : 
     148                 :            : static void
     149                 :         16 : gcr_certificate_section_init (GcrCertificateSection *self)
     150                 :            : {
     151                 :         16 :         self->fields = g_list_store_new (GCR_TYPE_CERTIFICATE_FIELD);
     152                 :         16 : }
     153                 :            : 
     154                 :            : /**
     155                 :            :  * gcr_certificate_section_get_label:
     156                 :            :  * @self: the #GcrCertificateSection
     157                 :            :  *
     158                 :            :  * Get the displayable label of the section.
     159                 :            :  *
     160                 :            :  * Returns: the displayable label of the section
     161                 :            :  */
     162                 :            : const char *
     163                 :         16 : gcr_certificate_section_get_label (GcrCertificateSection *self)
     164                 :            : {
     165         [ -  + ]:         16 :         g_return_val_if_fail (self != NULL, NULL);
     166                 :            : 
     167                 :         16 :         return self->label;
     168                 :            : }
     169                 :            : 
     170                 :            : /**
     171                 :            :  * gcr_certificate_section_get_flags:
     172                 :            :  * @self: the #GcrCertificateSection
     173                 :            :  *
     174                 :            :  * Get the flags.
     175                 :            :  *
     176                 :            :  * Returns: the `GcrCertificateSectionFlags`
     177                 :            :  */
     178                 :            : GcrCertificateSectionFlags
     179                 :         16 : gcr_certificate_section_get_flags (GcrCertificateSection *self)
     180                 :            : {
     181         [ -  + ]:         16 :         g_return_val_if_fail (self != NULL, FALSE);
     182                 :            : 
     183                 :         16 :         return self->flags;
     184                 :            : }
     185                 :            : 
     186                 :            : /**
     187                 :            :  * gcr_certificate_section_get_fields:
     188                 :            :  * @self: the #GcrCertificateSection
     189                 :            :  *
     190                 :            :  * Get the list of all the fields in this section.
     191                 :            :  *
     192                 :            :  * Returns: (transfer none): a #GListModel of #GcrCertificateField
     193                 :            :  */
     194                 :            : GListModel *
     195                 :         16 : gcr_certificate_section_get_fields (GcrCertificateSection *self)
     196                 :            : {
     197         [ -  + ]:         16 :         g_return_val_if_fail (self != NULL, NULL);
     198                 :            : 
     199                 :         16 :         return G_LIST_MODEL (self->fields);
     200                 :            : }
     201                 :            : 
     202                 :            : void
     203                 :         47 : _gcr_certificate_section_append_field (GcrCertificateSection *section,
     204                 :            :                                        GcrCertificateField   *field)
     205                 :            : {
     206         [ -  + ]:         47 :         g_return_if_fail (GCR_IS_CERTIFICATE_SECTION (section));
     207         [ -  + ]:         47 :         g_return_if_fail (GCR_IS_CERTIFICATE_FIELD (field));
     208                 :            : 
     209                 :         47 :         g_list_store_append (section->fields, field);
     210                 :            : }
     211                 :            : 

Generated by: LCOV version 1.14