LCOV - code coverage report
Current view: top level - src/libvalent/messages - valent-message-attachment.c (source / functions) Coverage Total Hit
Test: Code Coverage Lines: 20.3 % 59 12
Test Date: 2024-10-18 21:32:59 Functions: 33.3 % 12 4
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 8.8 % 34 3

             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-message-attachment"
       5                 :             : 
       6                 :             : #include "config.h"
       7                 :             : 
       8                 :             : #include <gio/gio.h>
       9                 :             : #include <libvalent-core.h>
      10                 :             : 
      11                 :             : #include "valent-message-attachment.h"
      12                 :             : 
      13                 :             : 
      14                 :             : struct _ValentMessageAttachment
      15                 :             : {
      16                 :             :   ValentObject  parent_instance;
      17                 :             : 
      18                 :             :   GFile        *file;
      19                 :             :   GIcon        *preview;
      20                 :             : };
      21                 :             : 
      22   [ +  +  +  - ]:         134 : G_DEFINE_FINAL_TYPE (ValentMessageAttachment, valent_message_attachment, VALENT_TYPE_OBJECT)
      23                 :             : 
      24                 :             : typedef enum {
      25                 :             :   PROP_FILE = 1,
      26                 :             :   PROP_PREVIEW,
      27                 :             : } ValentMessageAttachmentProperty;
      28                 :             : 
      29                 :             : static GParamSpec *properties[PROP_PREVIEW + 1] = { NULL, };
      30                 :             : 
      31                 :             : 
      32                 :             : /*
      33                 :             :  * GObject
      34                 :             :  */
      35                 :             : static void
      36                 :           0 : valent_message_attachment_finalize (GObject *object)
      37                 :             : {
      38                 :           0 :   ValentMessageAttachment *self = VALENT_MESSAGE_ATTACHMENT (object);
      39                 :             : 
      40         [ #  # ]:           0 :   g_clear_object (&self->file);
      41         [ #  # ]:           0 :   g_clear_object (&self->preview);
      42                 :             : 
      43                 :           0 :   G_OBJECT_CLASS (valent_message_attachment_parent_class)->finalize (object);
      44                 :           0 : }
      45                 :             : 
      46                 :             : static void
      47                 :           0 : valent_message_attachment_get_property (GObject    *object,
      48                 :             :                                         guint       prop_id,
      49                 :             :                                         GValue     *value,
      50                 :             :                                         GParamSpec *pspec)
      51                 :             : {
      52                 :           0 :   ValentMessageAttachment *self = VALENT_MESSAGE_ATTACHMENT (object);
      53                 :             : 
      54      [ #  #  # ]:           0 :   switch ((ValentMessageAttachmentProperty)prop_id)
      55                 :             :     {
      56                 :           0 :     case PROP_FILE:
      57                 :           0 :       g_value_set_object (value, self->file);
      58                 :           0 :       break;
      59                 :             : 
      60                 :           0 :     case PROP_PREVIEW:
      61                 :           0 :       g_value_set_object (value, self->preview);
      62                 :           0 :       break;
      63                 :             : 
      64                 :           0 :     default:
      65                 :           0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      66                 :             :     }
      67                 :           0 : }
      68                 :             : 
      69                 :             : static void
      70                 :           0 : valent_message_attachment_set_property (GObject      *object,
      71                 :             :                                         guint         prop_id,
      72                 :             :                                         const GValue *value,
      73                 :             :                                         GParamSpec   *pspec)
      74                 :             : {
      75                 :           0 :   ValentMessageAttachment *self = VALENT_MESSAGE_ATTACHMENT (object);
      76                 :             : 
      77      [ #  #  # ]:           0 :   switch ((ValentMessageAttachmentProperty)prop_id)
      78                 :             :     {
      79                 :           0 :     case PROP_FILE:
      80                 :           0 :       valent_message_attachment_set_file (self, g_value_get_object (value));
      81                 :           0 :       break;
      82                 :             : 
      83                 :           0 :     case PROP_PREVIEW:
      84                 :           0 :       valent_message_attachment_set_preview (self, g_value_get_object (value));
      85                 :           0 :       break;
      86                 :             : 
      87                 :           0 :     default:
      88                 :           0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      89                 :             :     }
      90                 :           0 : }
      91                 :             : 
      92                 :             : static void
      93                 :           1 : valent_message_attachment_class_init (ValentMessageAttachmentClass *klass)
      94                 :             : {
      95                 :           1 :   GObjectClass *object_class = G_OBJECT_CLASS (klass);
      96                 :             : 
      97                 :           1 :   object_class->finalize = valent_message_attachment_finalize;
      98                 :           1 :   object_class->get_property = valent_message_attachment_get_property;
      99                 :           1 :   object_class->set_property = valent_message_attachment_set_property;
     100                 :             : 
     101                 :             :   /**
     102                 :             :    * ValentMessageAttachment:file: (getter get_file) (setter set_file)
     103                 :             :    *
     104                 :             :    * A file for the attachment.
     105                 :             :  *
     106                 :             :  * Since: 1.0
     107                 :             :    */
     108                 :           2 :   properties [PROP_FILE] =
     109                 :           1 :     g_param_spec_object ("file", NULL, NULL,
     110                 :             :                          G_TYPE_FILE,
     111                 :             :                          (G_PARAM_READWRITE |
     112                 :             :                           G_PARAM_EXPLICIT_NOTIFY |
     113                 :             :                           G_PARAM_STATIC_STRINGS));
     114                 :             : 
     115                 :             :   /**
     116                 :             :    * ValentMessageAttachment:preview: (getter get_preview) (setter set_preview)
     117                 :             :    *
     118                 :             :    * A thumbnail preview of the attachment.
     119                 :             :  *
     120                 :             :  * Since: 1.0
     121                 :             :    */
     122                 :           2 :   properties [PROP_PREVIEW] =
     123                 :           1 :     g_param_spec_object ("preview", NULL, NULL,
     124                 :             :                          G_TYPE_ICON,
     125                 :             :                          (G_PARAM_READWRITE |
     126                 :             :                           G_PARAM_EXPLICIT_NOTIFY |
     127                 :             :                           G_PARAM_STATIC_STRINGS));
     128                 :             : 
     129                 :           1 :   g_object_class_install_properties (object_class, G_N_ELEMENTS (properties), properties);
     130                 :           1 : }
     131                 :             : 
     132                 :             : static void
     133                 :           0 : valent_message_attachment_init (ValentMessageAttachment *self)
     134                 :             : {
     135                 :           0 : }
     136                 :             : 
     137                 :             : /**
     138                 :             :  * valent_message_attachment_get_file: (get-property file)
     139                 :             :  * @attachment: a `ValentMessageAttachment`
     140                 :             :  *
     141                 :             :  * Get the file for @attachment.
     142                 :             :  *
     143                 :             :  * Returns: (transfer none) (nullable): the attachment file
     144                 :             :  *
     145                 :             :  * Since: 1.0
     146                 :             :  */
     147                 :             : GFile *
     148                 :           0 : valent_message_attachment_get_file (ValentMessageAttachment *attachment)
     149                 :             : {
     150         [ #  # ]:           0 :   g_return_val_if_fail (VALENT_IS_MESSAGE_ATTACHMENT (attachment), NULL);
     151                 :             : 
     152                 :           0 :   return attachment->file;
     153                 :             : }
     154                 :             : 
     155                 :             : /**
     156                 :             :  * valent_message_attachment_set_file: (set-property file)
     157                 :             :  * @attachment: a `ValentMessageAttachment`
     158                 :             :  * @file: (nullable): the attachment file
     159                 :             :  *
     160                 :             :  * Set the file for @attachment to @file.
     161                 :             :  *
     162                 :             :  * Since: 1.0
     163                 :             :  */
     164                 :             : void
     165                 :           0 : valent_message_attachment_set_file (ValentMessageAttachment *attachment,
     166                 :             :                                     GFile                   *file)
     167                 :             : {
     168         [ #  # ]:           0 :   g_return_if_fail (VALENT_IS_MESSAGE_ATTACHMENT (attachment));
     169   [ #  #  #  #  :           0 :   g_return_if_fail (file == NULL || G_IS_FILE (file));
             #  #  #  # ]
     170                 :             : 
     171         [ #  # ]:           0 :   if (g_set_object (&attachment->file, file))
     172                 :           0 :     g_object_notify_by_pspec (G_OBJECT (attachment), properties[PROP_FILE]);
     173                 :             : }
     174                 :             : 
     175                 :             : /**
     176                 :             :  * valent_message_attachment_get_preview: (get-property preview)
     177                 :             :  * @attachment: a `ValentMessageAttachment`
     178                 :             :  *
     179                 :             :  * Get the thumbnail preview of @attachment.
     180                 :             :  *
     181                 :             :  * Returns: (transfer none) (nullable): a thumbnail preview
     182                 :             :  *
     183                 :             :  * Since: 1.0
     184                 :             :  */
     185                 :             : GIcon *
     186                 :           0 : valent_message_attachment_get_preview (ValentMessageAttachment *attachment)
     187                 :             : {
     188         [ #  # ]:           0 :   g_return_val_if_fail (VALENT_IS_MESSAGE_ATTACHMENT (attachment), NULL);
     189                 :             : 
     190                 :           0 :   return attachment->preview;
     191                 :             : }
     192                 :             : 
     193                 :             : /**
     194                 :             :  * valent_message_attachment_set_preview: (set-property preview)
     195                 :             :  * @attachment: a `ValentMessageAttachment`
     196                 :             :  * @preview: (nullable): the attachment preview
     197                 :             :  *
     198                 :             :  * Set the preview for @attachment to @preview.
     199                 :             :  *
     200                 :             :  * Since: 1.0
     201                 :             :  */
     202                 :             : void
     203                 :           0 : valent_message_attachment_set_preview (ValentMessageAttachment *attachment,
     204                 :             :                                        GIcon                   *preview)
     205                 :             : {
     206         [ #  # ]:           0 :   g_return_if_fail (VALENT_IS_MESSAGE_ATTACHMENT (attachment));
     207                 :             : 
     208         [ #  # ]:           0 :   if (g_set_object (&attachment->preview, preview))
     209                 :           0 :     g_object_notify_by_pspec (G_OBJECT (attachment), properties[PROP_PREVIEW]);
     210                 :             : }
     211                 :             : 
        

Generated by: LCOV version 2.0-1