LCOV - code coverage report
Current view: top level - src/libvalent/ui - valent-ui-manager.c (source / functions) Coverage Total Hit
Test: Code Coverage Lines: 9.7 % 62 6
Test Date: 2024-04-23 06:02:46 Functions: 30.0 % 10 3
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10.7 % 28 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                 :             : #include "config.h"
       5                 :             : 
       6                 :             : #include <gio/gio.h>
       7                 :             : #include <gtk/gtk.h>
       8                 :             : #include <libvalent-core.h>
       9                 :             : #include <libvalent-device.h>
      10                 :             : #include <libvalent-input.h>
      11                 :             : #include <libvalent-media.h>
      12                 :             : 
      13                 :             : #include "valent-input-remote.h"
      14                 :             : #include "valent-media-remote.h"
      15                 :             : #include "valent-ui-manager.h"
      16                 :             : #include "valent-ui-utils.h"
      17                 :             : #include "valent-window.h"
      18                 :             : 
      19                 :             : 
      20                 :             : struct _ValentUIManager
      21                 :             : {
      22                 :             :   ValentApplicationPlugin  parent_instance;
      23                 :             : 
      24                 :             :   GtkWindow               *main_window;
      25                 :             :   GtkWindow               *input_remote;
      26                 :             :   GtkWindow               *media_remote;
      27                 :             : };
      28                 :             : 
      29   [ +  +  +  - ]:         131 : G_DEFINE_FINAL_TYPE (ValentUIManager, valent_ui_manager, VALENT_TYPE_APPLICATION_PLUGIN)
      30                 :             : 
      31                 :             : 
      32                 :             : /*
      33                 :             :  * GActions
      34                 :             :  */
      35                 :             : static void
      36                 :           0 : main_window_action (GSimpleAction *action,
      37                 :             :                     GVariant      *parameter,
      38                 :             :                     gpointer       user_data)
      39                 :             : {
      40                 :           0 :   ValentUIManager *self = VALENT_UI_MANAGER (user_data);
      41                 :             : 
      42         [ #  # ]:           0 :   g_assert (VALENT_IS_UI_MANAGER (self));
      43                 :             : 
      44         [ #  # ]:           0 :   if (self->main_window == NULL)
      45                 :             :     {
      46                 :           0 :       ValentDeviceManager *devices = valent_device_manager_get_default ();
      47                 :           0 :       GApplication *application = valent_extension_get_object (VALENT_EXTENSION (self));
      48                 :             : 
      49                 :           0 :       self->main_window = g_object_new (VALENT_TYPE_WINDOW,
      50                 :             :                                         "default-width",  600,
      51                 :             :                                         "default-height", 480,
      52                 :             :                                         "device-manager", devices,
      53                 :             :                                         NULL);
      54                 :           0 :       g_object_add_weak_pointer (G_OBJECT (self->main_window),
      55                 :           0 :                                  (gpointer)&self->main_window);
      56                 :             : 
      57                 :           0 :       gtk_widget_insert_action_group (GTK_WIDGET (self->main_window),
      58                 :             :                                       "app",
      59                 :             :                                       G_ACTION_GROUP (application));
      60                 :             :     }
      61                 :             : 
      62                 :           0 :   gtk_window_present (self->main_window);
      63                 :           0 :   gtk_widget_activate_action_variant (GTK_WIDGET (self->main_window),
      64                 :             :                                       "win.page",
      65                 :             :                                       parameter);
      66                 :           0 : }
      67                 :             : 
      68                 :             : static void
      69                 :           0 : input_remote_action (GSimpleAction *action,
      70                 :             :                      GVariant      *parameter,
      71                 :             :                      gpointer       user_data)
      72                 :             : {
      73                 :           0 :   ValentUIManager *self = VALENT_UI_MANAGER (user_data);
      74                 :             : 
      75         [ #  # ]:           0 :   g_assert (VALENT_IS_UI_MANAGER (self));
      76                 :             : 
      77         [ #  # ]:           0 :   if (self->input_remote == NULL)
      78                 :             :     {
      79                 :           0 :       self->input_remote = g_object_new (VALENT_TYPE_INPUT_REMOTE,
      80                 :             :                                          "adapters", valent_input_get_default (),
      81                 :             :                                          NULL);
      82                 :           0 :       g_object_add_weak_pointer (G_OBJECT (self->input_remote),
      83                 :           0 :                                  (gpointer)&self->input_remote);
      84                 :             :     }
      85                 :             : 
      86                 :           0 :   gtk_window_present (self->input_remote);
      87                 :           0 : }
      88                 :             : 
      89                 :             : static void
      90                 :           0 : media_remote_action (GSimpleAction *action,
      91                 :             :                      GVariant      *parameter,
      92                 :             :                      gpointer       user_data)
      93                 :             : {
      94                 :           0 :   ValentUIManager *self = VALENT_UI_MANAGER (user_data);
      95                 :             : 
      96         [ #  # ]:           0 :   g_assert (VALENT_IS_UI_MANAGER (self));
      97                 :             : 
      98         [ #  # ]:           0 :   if (self->media_remote == NULL)
      99                 :             :     {
     100                 :           0 :       self->media_remote = g_object_new (VALENT_TYPE_MEDIA_REMOTE,
     101                 :             :                                          "players", valent_media_get_default (),
     102                 :             :                                          NULL);
     103                 :           0 :       g_object_add_weak_pointer (G_OBJECT (self->media_remote),
     104                 :           0 :                                  (gpointer)&self->media_remote);
     105                 :             :     }
     106                 :             : 
     107                 :           0 :   gtk_window_present (self->media_remote);
     108                 :           0 : }
     109                 :             : 
     110                 :             : static const GActionEntry app_actions[] = {
     111                 :             :   { "input-remote", input_remote_action, NULL, NULL, NULL },
     112                 :             :   { "media-remote", media_remote_action, NULL, NULL, NULL },
     113                 :             :   { "window",       main_window_action,  "s",  NULL, NULL },
     114                 :             : };
     115                 :             : 
     116                 :             : 
     117                 :             : /*
     118                 :             :  * ValentApplicationPlugin
     119                 :             :  */
     120                 :             : static gboolean
     121                 :           0 : valent_ui_manager_activate (ValentApplicationPlugin *plugin)
     122                 :             : {
     123                 :           0 :   GApplication *application = NULL;
     124                 :             : 
     125         [ #  # ]:           0 :   g_assert (VALENT_IS_UI_MANAGER (plugin));
     126                 :             : 
     127                 :           0 :   application = valent_extension_get_object (VALENT_EXTENSION (plugin));
     128                 :           0 :   g_action_group_activate_action (G_ACTION_GROUP (application),
     129                 :             :                                   "window",
     130                 :             :                                   g_variant_new_string ("main"));
     131                 :             : 
     132                 :           0 :   return TRUE;
     133                 :             : }
     134                 :             : 
     135                 :             : static void
     136                 :           0 : valent_ui_manager_shutdown (ValentApplicationPlugin *plugin)
     137                 :             : {
     138                 :           0 :   ValentUIManager *self = VALENT_UI_MANAGER (plugin);
     139                 :           0 :   GApplication *application = NULL;
     140                 :             : 
     141         [ #  # ]:           0 :   g_assert (VALENT_IS_UI_MANAGER (plugin));
     142                 :             : 
     143                 :           0 :   application = valent_extension_get_object (VALENT_EXTENSION (plugin));
     144                 :             : 
     145         [ #  # ]:           0 :   for (size_t i = 0; i < G_N_ELEMENTS (app_actions); i++)
     146                 :           0 :     g_action_map_remove_action (G_ACTION_MAP (application), app_actions[i].name);
     147                 :             : 
     148         [ #  # ]:           0 :   g_clear_pointer (&self->media_remote, gtk_window_destroy);
     149         [ #  # ]:           0 :   g_clear_pointer (&self->main_window, gtk_window_destroy);
     150                 :           0 : }
     151                 :             : 
     152                 :             : static void
     153                 :           0 : valent_ui_manager_startup (ValentApplicationPlugin *plugin)
     154                 :             : {
     155                 :           0 :   GApplication *application = NULL;
     156                 :             : 
     157         [ #  # ]:           0 :   g_assert (VALENT_IS_UI_MANAGER (plugin));
     158                 :             : 
     159                 :           0 :   application = valent_extension_get_object (VALENT_EXTENSION (plugin));
     160                 :           0 :   g_action_map_add_action_entries (G_ACTION_MAP (application),
     161                 :             :                                    app_actions,
     162                 :             :                                    G_N_ELEMENTS (app_actions),
     163                 :             :                                    plugin);
     164                 :           0 : }
     165                 :             : 
     166                 :             : 
     167                 :             : /*
     168                 :             :  * GObject
     169                 :             :  */
     170                 :             : static void
     171                 :          29 : valent_ui_manager_class_init (ValentUIManagerClass *klass)
     172                 :             : {
     173                 :          29 :   ValentApplicationPluginClass *plugin_class = VALENT_APPLICATION_PLUGIN_CLASS (klass);
     174                 :             : 
     175                 :          29 :   plugin_class->activate = valent_ui_manager_activate;
     176                 :          29 :   plugin_class->shutdown = valent_ui_manager_shutdown;
     177                 :          29 :   plugin_class->startup = valent_ui_manager_startup;
     178                 :             : }
     179                 :             : 
     180                 :             : static void
     181                 :           0 : valent_ui_manager_init (ValentUIManager *self)
     182                 :             : {
     183                 :           0 :   valent_ui_init ();
     184                 :           0 : }
     185                 :             : 
        

Generated by: LCOV version 2.0-1