LCOV - code coverage report
Current view: top level - src/plugins/findmyphone - valent-findmyphone-plugin.c (source / functions) Coverage Total Hit
Test: Code Coverage Lines: 75.0 % 56 42
Test Date: 2024-07-14 03:00:40 Functions: 80.0 % 10 8
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 42.3 % 26 11

             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-findmyphone-plugin"
       5                 :             : 
       6                 :             : #include "config.h"
       7                 :             : 
       8                 :             : #include <glib/gi18n.h>
       9                 :             : #include <gio/gio.h>
      10                 :             : #include <json-glib/json-glib.h>
      11                 :             : #include <valent.h>
      12                 :             : 
      13                 :             : #include "valent-findmyphone-plugin.h"
      14                 :             : #include "valent-findmyphone-ringer.h"
      15                 :             : 
      16                 :             : 
      17                 :             : struct _ValentFindmyphonePlugin
      18                 :             : {
      19                 :             :   ValentDevicePlugin       parent_instance;
      20                 :             : 
      21                 :             :   ValentFindmyphoneRinger *ringer;
      22                 :             : };
      23                 :             : 
      24   [ +  +  +  - ]:          13 : G_DEFINE_FINAL_TYPE (ValentFindmyphonePlugin, valent_findmyphone_plugin, VALENT_TYPE_DEVICE_PLUGIN)
      25                 :             : 
      26                 :             : 
      27                 :             : static void
      28                 :           0 : valent_findmyphone_plugin_handle_findmyphone_request (ValentFindmyphonePlugin *self)
      29                 :             : {
      30         [ #  # ]:           0 :   g_assert (VALENT_IS_FINDMYPHONE_PLUGIN (self));
      31                 :             : 
      32                 :           0 :   valent_findmyphone_ringer_toggle (self->ringer, self);
      33                 :           0 : }
      34                 :             : 
      35                 :             : /*
      36                 :             :  * GActions
      37                 :             :  */
      38                 :             : static void
      39                 :           1 : ring_action (GSimpleAction *action,
      40                 :             :              GVariant      *parameter,
      41                 :             :              gpointer       user_data)
      42                 :             : {
      43                 :           1 :   ValentFindmyphonePlugin *self = VALENT_FINDMYPHONE_PLUGIN (user_data);
      44                 :           2 :   g_autoptr (JsonNode) packet = NULL;
      45                 :             : 
      46         [ +  - ]:           1 :   g_assert (VALENT_IS_FINDMYPHONE_PLUGIN (self));
      47                 :             : 
      48                 :           1 :   packet = valent_packet_new ("kdeconnect.findmyphone.request");
      49         [ +  - ]:           1 :   valent_device_plugin_queue_packet (VALENT_DEVICE_PLUGIN (self), packet);
      50                 :           1 : }
      51                 :             : 
      52                 :             : static const GActionEntry actions[] = {
      53                 :             :     {"ring", ring_action, NULL, NULL, NULL}
      54                 :             : };
      55                 :             : 
      56                 :             : /*
      57                 :             :  * ValentDevicePlugin
      58                 :             :  */
      59                 :             : static void
      60                 :           9 : valent_findmyphone_plugin_update_state (ValentDevicePlugin *plugin,
      61                 :             :                                         ValentDeviceState   state)
      62                 :             : {
      63                 :           9 :   ValentFindmyphonePlugin *self = VALENT_FINDMYPHONE_PLUGIN (plugin);
      64                 :           9 :   gboolean available;
      65                 :             : 
      66         [ +  - ]:           9 :   g_assert (VALENT_IS_FINDMYPHONE_PLUGIN (self));
      67                 :             : 
      68                 :           9 :   available = (state & VALENT_DEVICE_STATE_CONNECTED) != 0 &&
      69                 :             :               (state & VALENT_DEVICE_STATE_PAIRED) != 0;
      70                 :             : 
      71                 :             :   /* Stop any ringing */
      72   [ +  +  -  + ]:           9 :   if (!available && valent_findmyphone_ringer_is_owner (self->ringer, self))
      73                 :           0 :     valent_findmyphone_ringer_hide (self->ringer);
      74                 :             : 
      75                 :           9 :   valent_extension_toggle_actions (VALENT_EXTENSION (plugin), available);
      76                 :           9 : }
      77                 :             : 
      78                 :             : static void
      79                 :           0 : valent_findmyphone_plugin_handle_packet (ValentDevicePlugin *plugin,
      80                 :             :                                          const char         *type,
      81                 :             :                                          JsonNode           *packet)
      82                 :             : {
      83                 :           0 :   ValentFindmyphonePlugin *self = VALENT_FINDMYPHONE_PLUGIN (plugin);
      84                 :             : 
      85         [ #  # ]:           0 :   g_assert (VALENT_IS_FINDMYPHONE_PLUGIN (self));
      86         [ #  # ]:           0 :   g_assert (type != NULL);
      87         [ #  # ]:           0 :   g_assert (VALENT_IS_PACKET (packet));
      88                 :             : 
      89         [ #  # ]:           0 :   if (g_str_equal (type, "kdeconnect.findmyphone.request"))
      90                 :           0 :     valent_findmyphone_plugin_handle_findmyphone_request (self);
      91                 :             :   else
      92                 :           0 :     g_assert_not_reached ();
      93                 :           0 : }
      94                 :             : 
      95                 :             : /*
      96                 :             :  * ValentObject
      97                 :             :  */
      98                 :             : static void
      99                 :           8 : valent_findmyphone_plugin_destroy (ValentObject *object)
     100                 :             : {
     101                 :           8 :   ValentFindmyphonePlugin *self = VALENT_FINDMYPHONE_PLUGIN (object);
     102                 :           8 :   ValentDevicePlugin *plugin = VALENT_DEVICE_PLUGIN (object);
     103                 :             : 
     104         [ +  + ]:           8 :   g_clear_pointer (&self->ringer, valent_findmyphone_ringer_release);
     105                 :           8 :   valent_device_plugin_set_menu_item (plugin, "device.findmyphone.ring", NULL);
     106                 :             : 
     107                 :           8 :   VALENT_OBJECT_CLASS (valent_findmyphone_plugin_parent_class)->destroy (object);
     108                 :           8 : }
     109                 :             : 
     110                 :             : /*
     111                 :             :  * GObject
     112                 :             :  */
     113                 :             : static void
     114                 :           4 : valent_findmyphone_plugin_constructed (GObject *object)
     115                 :             : {
     116                 :           4 :   ValentDevicePlugin *plugin = VALENT_DEVICE_PLUGIN (object);
     117                 :           4 :   ValentFindmyphonePlugin *self = VALENT_FINDMYPHONE_PLUGIN (object);
     118                 :             : 
     119                 :           4 :   g_action_map_add_action_entries (G_ACTION_MAP (plugin),
     120                 :             :                                    actions,
     121                 :             :                                    G_N_ELEMENTS (actions),
     122                 :             :                                    plugin);
     123                 :           4 :   valent_device_plugin_set_menu_action (plugin,
     124                 :             :                                         "device.findmyphone.ring",
     125                 :           4 :                                         _("Ring"),
     126                 :             :                                         "phonelink-ring-symbolic");
     127                 :           4 :   self->ringer = valent_findmyphone_ringer_acquire ();
     128                 :             : 
     129                 :           4 :   G_OBJECT_CLASS (valent_findmyphone_plugin_parent_class)->constructed (object);
     130                 :           4 : }
     131                 :             : 
     132                 :             : static void
     133                 :           1 : valent_findmyphone_plugin_class_init (ValentFindmyphonePluginClass *klass)
     134                 :             : {
     135                 :           1 :   GObjectClass *object_class = G_OBJECT_CLASS (klass);
     136                 :           1 :   ValentObjectClass *vobject_class = VALENT_OBJECT_CLASS (klass);
     137                 :           1 :   ValentDevicePluginClass *plugin_class = VALENT_DEVICE_PLUGIN_CLASS (klass);
     138                 :             : 
     139                 :           1 :   object_class->constructed = valent_findmyphone_plugin_constructed;
     140                 :             : 
     141                 :           1 :   vobject_class->destroy = valent_findmyphone_plugin_destroy;
     142                 :             : 
     143                 :           1 :   plugin_class->handle_packet = valent_findmyphone_plugin_handle_packet;
     144                 :           1 :   plugin_class->update_state = valent_findmyphone_plugin_update_state;
     145                 :             : }
     146                 :             : 
     147                 :             : static void
     148                 :           4 : valent_findmyphone_plugin_init (ValentFindmyphonePlugin *self)
     149                 :             : {
     150                 :           4 : }
     151                 :             : 
        

Generated by: LCOV version 2.0-1