LCOV - code coverage report
Current view: top level - gio - gnotificationbackend.c (source / functions) Coverage Total Hit
Test: unnamed Lines: 71.0 % 62 44
Test Date: 2026-11-10 05:12:13 Functions: 91.7 % 12 11
Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * Copyright © 2013 Lars Uebernickel
       3                 :             :  *
       4                 :             :  * SPDX-License-Identifier: LGPL-2.1-or-later
       5                 :             :  *
       6                 :             :  * This library is free software; you can redistribute it and/or
       7                 :             :  * modify it under the terms of the GNU Lesser General Public
       8                 :             :  * License as published by the Free Software Foundation; either
       9                 :             :  * version 2.1 of the License, or (at your option) any later version.
      10                 :             :  *
      11                 :             :  * This library is distributed in the hope that it will be useful,
      12                 :             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14                 :             :  * Lesser General Public License for more details.
      15                 :             :  *
      16                 :             :  * You should have received a copy of the GNU Lesser General
      17                 :             :  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
      18                 :             :  *
      19                 :             :  * Authors: Lars Uebernickel <lars@uebernic.de>
      20                 :             :  */
      21                 :             : 
      22                 :             : #include "gnotificationbackend.h"
      23                 :             : 
      24                 :             : #include "gnotification.h"
      25                 :             : #include "gapplication.h"
      26                 :             : #include "gactiongroup.h"
      27                 :             : #include "giomodule-priv.h"
      28                 :             : 
      29                 :         986 : G_DEFINE_TYPE (GNotificationBackend, g_notification_backend, G_TYPE_OBJECT)
      30                 :             : 
      31                 :             : typedef enum
      32                 :             : {
      33                 :             :   PROP_APPLICATION = 1,
      34                 :             : } GNotificationBackendProperty;
      35                 :             : 
      36                 :             : static GParamSpec *props[PROP_APPLICATION + 1];
      37                 :             : 
      38                 :             : /**
      39                 :             :  * g_notification_backend_dup_application:
      40                 :             :  *
      41                 :             :  * Returns: (transfer full) (nullable):
      42                 :             :  *  The application object this notification backend handles notifications for.
      43                 :             :  */
      44                 :             : GApplication *
      45                 :          17 : g_notification_backend_dup_application (GNotificationBackend *self)
      46                 :             : {
      47                 :          17 :   g_return_val_if_fail (G_IS_NOTIFICATION_BACKEND (self), NULL);
      48                 :             : 
      49                 :          17 :   return (GApplication *) g_weak_ref_get (&self->application);
      50                 :           0 : }
      51                 :             : 
      52                 :             : static void
      53                 :           0 : g_notification_backend_get_property (GObject *obj,
      54                 :             :                                      guint prop_id,
      55                 :             :                                      GValue *value,
      56                 :             :                                      GParamSpec *pspec)
      57                 :             : {
      58                 :           0 :   GNotificationBackend *self = G_NOTIFICATION_BACKEND (obj);
      59                 :             : 
      60                 :           0 :   switch ((GNotificationBackendProperty) prop_id)
      61                 :             :     {
      62                 :           0 :     case PROP_APPLICATION:
      63                 :             :       {
      64                 :           0 :         g_value_take_object (value, g_notification_backend_dup_application (self));
      65                 :           0 :         break;
      66                 :             :       }
      67                 :           0 :     default:
      68                 :           0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
      69                 :           0 :     }
      70                 :           0 : }
      71                 :             : 
      72                 :             : static void
      73                 :           5 : g_notification_backend_set_property (GObject *obj,
      74                 :             :                                      guint prop_id,
      75                 :             :                                      const GValue *value,
      76                 :             :                                      GParamSpec *pspec)
      77                 :             : {
      78                 :           5 :   GNotificationBackend *self = G_NOTIFICATION_BACKEND (obj);
      79                 :             : 
      80                 :           5 :   switch ((GNotificationBackendProperty) prop_id)
      81                 :             :     {
      82                 :           5 :     case PROP_APPLICATION:
      83                 :             :       {
      84                 :           5 :         g_weak_ref_init (&self->application, g_value_get_object (value));
      85                 :           5 :         break;
      86                 :             :       }
      87                 :           0 :     default:
      88                 :           0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
      89                 :           0 :     }
      90                 :           5 : }
      91                 :             : 
      92                 :             : static void
      93                 :           5 : g_notification_backend_dispose (GObject *obj)
      94                 :             : {
      95                 :           5 :   GNotificationBackend *backend = G_NOTIFICATION_BACKEND (obj);
      96                 :             : 
      97                 :           5 :   g_weak_ref_clear (&backend->application);
      98                 :           5 :   g_clear_object (&backend->dbus_connection);
      99                 :             : 
     100                 :           5 :   G_OBJECT_CLASS (g_notification_backend_parent_class)->dispose (obj);
     101                 :           5 : }
     102                 :             : 
     103                 :             : static void
     104                 :           2 : g_notification_backend_class_init (GNotificationBackendClass *class)
     105                 :             : {
     106                 :           2 :   GObjectClass *object_class = G_OBJECT_CLASS (class);
     107                 :             : 
     108                 :           2 :   object_class->dispose = g_notification_backend_dispose;
     109                 :           2 :   object_class->get_property = g_notification_backend_get_property;
     110                 :           2 :   object_class->set_property = g_notification_backend_set_property;
     111                 :             : 
     112                 :             :   /**
     113                 :             :    * GNotificationBackend:application:
     114                 :             :    *
     115                 :             :    * The application object this notification backend handles
     116                 :             :    * notifications for.
     117                 :             :    *
     118                 :             :    * Since: 2.90
     119                 :             :    */
     120                 :           2 :   props[PROP_APPLICATION] =
     121                 :           2 :     g_param_spec_object ("application", NULL, NULL,
     122                 :           0 :                          G_TYPE_APPLICATION,
     123                 :             :                          G_PARAM_STATIC_STRINGS |
     124                 :             :                          G_PARAM_READWRITE |
     125                 :             :                          G_PARAM_CONSTRUCT_ONLY);
     126                 :             : 
     127                 :           2 :   g_object_class_install_properties (object_class, G_N_ELEMENTS (props), props);
     128                 :           2 : }
     129                 :             : 
     130                 :             : static void
     131                 :           5 : g_notification_backend_init (GNotificationBackend *backend)
     132                 :             : {
     133                 :           5 : }
     134                 :             : 
     135                 :             : GNotificationBackend *
     136                 :           3 : g_notification_backend_new_default (GApplication *application)
     137                 :             : {
     138                 :             :   GType backend_type;
     139                 :             :   GNotificationBackend *backend;
     140                 :             : 
     141                 :           3 :   g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
     142                 :             : 
     143                 :           3 :   backend_type = _g_io_module_get_default_type (G_NOTIFICATION_BACKEND_EXTENSION_POINT_NAME,
     144                 :             :                                                 "GNOTIFICATION_BACKEND",
     145                 :             :                                                 G_STRUCT_OFFSET (GNotificationBackendClass, is_supported));
     146                 :             : 
     147                 :           3 :   backend = g_object_new (backend_type, "application", application, NULL);
     148                 :             : 
     149                 :           3 :   backend->dbus_connection = g_application_get_dbus_connection (application);
     150                 :           3 :   if (backend->dbus_connection)
     151                 :           3 :     g_object_ref (backend->dbus_connection);
     152                 :             : 
     153                 :           3 :   return backend;
     154                 :           0 : }
     155                 :             : 
     156                 :             : void
     157                 :           5 : g_notification_backend_send_notification (GNotificationBackend *backend,
     158                 :             :                                           const gchar          *id,
     159                 :             :                                           GNotification        *notification)
     160                 :             : {
     161                 :           5 :   g_return_if_fail (G_IS_NOTIFICATION_BACKEND (backend));
     162                 :           5 :   g_return_if_fail (G_IS_NOTIFICATION (notification));
     163                 :             : 
     164                 :           5 :   G_NOTIFICATION_BACKEND_GET_CLASS (backend)->send_notification (backend, id, notification);
     165                 :           0 : }
     166                 :             : 
     167                 :             : void
     168                 :           3 : g_notification_backend_withdraw_notification (GNotificationBackend *backend,
     169                 :             :                                               const gchar          *id)
     170                 :             : {
     171                 :           3 :   g_return_if_fail (G_IS_NOTIFICATION_BACKEND (backend));
     172                 :           3 :   g_return_if_fail (id != NULL);
     173                 :             : 
     174                 :           3 :   G_NOTIFICATION_BACKEND_GET_CLASS (backend)->withdraw_notification (backend, id);
     175                 :           0 : }
        

Generated by: LCOV version 2.0-1