LCOV - code coverage report
Current view: top level - src/plugins/share - valent-share-target.c (source / functions) Coverage Total Hit
Test: Code Coverage Lines: 45.0 % 60 27
Test Date: 2024-04-23 06:02:46 Functions: 60.0 % 10 6
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 15.0 % 40 6

             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-share-target"
       5                 :             : 
       6                 :             : #include <gio/gio.h>
       7                 :             : #include <gtk/gtk.h>
       8                 :             : #include <valent.h>
       9                 :             : 
      10                 :             : #include "valent-share-dialog.h"
      11                 :             : #include "valent-share-target.h"
      12                 :             : 
      13                 :             : 
      14                 :             : struct _ValentShareTarget
      15                 :             : {
      16                 :             :   ValentApplicationPlugin  parent_instance;
      17                 :             : 
      18                 :             :   GPtrArray               *windows;
      19                 :             : };
      20                 :             : 
      21   [ +  +  +  - ]:          18 : G_DEFINE_FINAL_TYPE (ValentShareTarget, valent_share_target, VALENT_TYPE_APPLICATION_PLUGIN)
      22                 :             : 
      23                 :             : 
      24                 :             : static void
      25                 :           0 : on_destroy (GtkWindow         *window,
      26                 :             :             ValentShareTarget *self)
      27                 :             : {
      28                 :           0 :   unsigned int index;
      29                 :             : 
      30   [ #  #  #  #  :           0 :   g_assert (GTK_IS_WINDOW (window));
             #  #  #  # ]
      31         [ #  # ]:           0 :   g_assert (VALENT_IS_SHARE_TARGET (self));
      32                 :             : 
      33                 :             :   /* The signal was emitted because we're disposing or being disabled */
      34         [ #  # ]:           0 :   if (self->windows == NULL)
      35                 :           0 :     return;
      36                 :             : 
      37         [ #  # ]:           0 :   if (g_ptr_array_find (self->windows, window, &index))
      38                 :           0 :     g_ptr_array_steal_index (self->windows, index);
      39                 :             : }
      40                 :             : 
      41                 :             : static void
      42                 :           0 : valent_share_target_present (ValentShareTarget *self,
      43                 :             :                              GListModel        *files)
      44                 :             : {
      45                 :           0 :   GtkWindow *window = NULL;
      46                 :             : 
      47         [ #  # ]:           0 :   g_assert (VALENT_IS_SHARE_TARGET (self));
      48   [ #  #  #  # ]:           0 :   g_assert (files == NULL || G_IS_LIST_MODEL (files));
      49                 :             : 
      50                 :           0 :   window = g_object_new (VALENT_TYPE_SHARE_DIALOG,
      51                 :             :                          "files", files,
      52                 :             :                          NULL);
      53                 :           0 :   g_signal_connect_object (G_OBJECT (window),
      54                 :             :                            "destroy",
      55                 :             :                            G_CALLBACK (on_destroy),
      56                 :             :                            self,
      57                 :             :                            G_CONNECT_DEFAULT);
      58                 :           0 :   g_ptr_array_add (self->windows, window);
      59                 :             : 
      60                 :           0 :   gtk_window_present (window);
      61                 :           0 : }
      62                 :             : 
      63                 :             : /*
      64                 :             :  * GActions
      65                 :             :  */
      66                 :             : static inline void
      67                 :           0 : share_dialog_action (GSimpleAction *action,
      68                 :             :                      GVariant      *parameters,
      69                 :             :                      gpointer       user_data)
      70                 :             : {
      71                 :           0 :   ValentShareTarget *self = VALENT_SHARE_TARGET (user_data);
      72                 :             : 
      73         [ #  # ]:           0 :   g_assert (VALENT_IS_SHARE_TARGET (self));
      74                 :             : 
      75                 :           0 :   valent_share_target_present (self, NULL);
      76                 :           0 : }
      77                 :             : 
      78                 :             : static const GActionEntry app_actions[] = {
      79                 :             :   { "share-dialog", share_dialog_action, NULL, NULL, NULL },
      80                 :             : };
      81                 :             : 
      82                 :             : /*
      83                 :             :  * ValentApplicationPlugin
      84                 :             :  */
      85                 :             : static gboolean
      86                 :           0 : valent_share_target_open (ValentApplicationPlugin  *plugin,
      87                 :             :                           GFile                   **files,
      88                 :             :                           int                       n_files,
      89                 :             :                           const char               *hint)
      90                 :             : {
      91                 :           0 :   ValentShareTarget *self = VALENT_SHARE_TARGET (plugin);
      92                 :           0 :   g_autoptr (GListStore) files_list = NULL;
      93                 :             : 
      94         [ #  # ]:           0 :   g_assert (VALENT_IS_SHARE_TARGET (plugin));
      95         [ #  # ]:           0 :   g_assert (files != NULL);
      96         [ #  # ]:           0 :   g_assert (n_files > 0);
      97         [ #  # ]:           0 :   g_assert (hint != NULL);
      98                 :             : 
      99                 :           0 :   files_list = g_list_store_new (G_TYPE_FILE);
     100                 :           0 :   g_list_store_splice (files_list, 0, 0, (gpointer *)files, n_files);
     101                 :           0 :   valent_share_target_present (self, G_LIST_MODEL (files_list));
     102                 :             : 
     103         [ #  # ]:           0 :   return TRUE;
     104                 :             : }
     105                 :             : 
     106                 :             : /*
     107                 :             :  * ValentObject
     108                 :             :  */
     109                 :             : static void
     110                 :           1 : valent_share_target_destroy (ValentObject *object)
     111                 :             : {
     112                 :           1 :   ValentShareTarget *self = VALENT_SHARE_TARGET (object);
     113                 :           1 :   GApplication *application = NULL;
     114                 :             : 
     115                 :           1 :   application = valent_extension_get_object (VALENT_EXTENSION (self));
     116                 :             : 
     117         [ +  + ]:           2 :   for (size_t i = 0; i < G_N_ELEMENTS (app_actions); i++)
     118                 :           1 :     g_action_map_remove_action (G_ACTION_MAP (application), app_actions[i].name);
     119                 :             : 
     120         [ +  - ]:           1 :   g_clear_pointer (&self->windows, g_ptr_array_unref);
     121                 :             : 
     122                 :           1 :   VALENT_OBJECT_CLASS (valent_share_target_parent_class)->destroy (object);
     123                 :           1 : }
     124                 :             : 
     125                 :             : /*
     126                 :             :  * GObject
     127                 :             :  */
     128                 :             : static void
     129                 :           1 : valent_share_target_constructed (GObject *object)
     130                 :             : {
     131                 :           1 :   ValentShareTarget *self = VALENT_SHARE_TARGET (object);
     132                 :           1 :   GApplication *application = NULL;
     133                 :             : 
     134                 :           1 :   G_OBJECT_CLASS (valent_share_target_parent_class)->constructed (object);
     135                 :             : 
     136                 :           1 :   application = valent_extension_get_object (VALENT_EXTENSION (self));
     137                 :           1 :   g_action_map_add_action_entries (G_ACTION_MAP (application),
     138                 :             :                                    app_actions,
     139                 :             :                                    G_N_ELEMENTS (app_actions),
     140                 :             :                                    self);
     141                 :           1 : }
     142                 :             : 
     143                 :             : static void
     144                 :           6 : valent_share_target_class_init (ValentShareTargetClass *klass)
     145                 :             : {
     146                 :           6 :   GObjectClass *object_class = G_OBJECT_CLASS (klass);
     147                 :           6 :   ValentObjectClass *vobject_class = VALENT_OBJECT_CLASS (klass);
     148                 :           6 :   ValentApplicationPluginClass *plugin_class = VALENT_APPLICATION_PLUGIN_CLASS (klass);
     149                 :             : 
     150                 :           6 :   object_class->constructed = valent_share_target_constructed;
     151                 :             : 
     152                 :           6 :   vobject_class->destroy = valent_share_target_destroy;
     153                 :             : 
     154                 :           6 :   plugin_class->open = valent_share_target_open;
     155                 :             : }
     156                 :             : 
     157                 :             : static void
     158                 :           1 : valent_share_target_init (ValentShareTarget *self)
     159                 :             : {
     160                 :           1 :   self->windows = g_ptr_array_new_with_free_func ((GDestroyNotify)gtk_window_destroy);
     161                 :           1 : }
     162                 :             : 
        

Generated by: LCOV version 2.0-1