LCOV - code coverage report
Current view: top level - src/plugins/presenter - valent-presenter-remote.c (source / functions) Coverage Total Hit
Test: Code Coverage Lines: 53.2 % 79 42
Test Date: 2024-04-23 06:02:46 Functions: 81.8 % 11 9
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 16.7 % 30 5

             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-presenter-remote"
       5                 :             : 
       6                 :             : #include "config.h"
       7                 :             : 
       8                 :             : #include <adwaita.h>
       9                 :             : #include <glib/gi18n.h>
      10                 :             : #include <gtk/gtk.h>
      11                 :             : #include <valent.h>
      12                 :             : 
      13                 :             : #include "valent-presenter-remote.h"
      14                 :             : 
      15                 :             : 
      16                 :             : struct _ValentPresenterRemote
      17                 :             : {
      18                 :             :   AdwWindow     parent_instance;
      19                 :             : 
      20                 :             :   ValentDevice *device;
      21                 :             : };
      22                 :             : 
      23   [ +  +  +  - ]:           4 : G_DEFINE_FINAL_TYPE (ValentPresenterRemote, valent_presenter_remote, ADW_TYPE_WINDOW)
      24                 :             : 
      25                 :             : enum {
      26                 :             :   PROP_0,
      27                 :             :   PROP_DEVICE,
      28                 :             :   N_PROPERTIES
      29                 :             : };
      30                 :             : 
      31                 :             : static GParamSpec *properties[N_PROPERTIES] = { NULL, };
      32                 :             : 
      33                 :             : /*
      34                 :             :  * File Filter
      35                 :             :  */
      36                 :             : static const char *mimetypes[] = {
      37                 :             :   "application/vnd.ms-powerpoint",
      38                 :             :   "application/vnd.ms-powerpoint.presentation.macroEnabled.12",
      39                 :             :   "application/vnd.ms-powerpoint.slide.macroEnabled.12",
      40                 :             :   "application/vnd.ms-powerpoint.slideshow.macroEnabled.12",
      41                 :             :   "application/vnd.oasis.opendocument.presentation",
      42                 :             :   "application/vnd.oasis.opendocument.presentation-flat-xml",
      43                 :             :   "application/vnd.openxmlformats-officedocument.presentationml.presentation",
      44                 :             :   "application/vnd.openxmlformats-officedocument.presentationml.slide",
      45                 :             :   "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
      46                 :             :   NULL
      47                 :             : };
      48                 :             : 
      49                 :             : /*
      50                 :             :  * GtkWidget
      51                 :             :  */
      52                 :             : static void
      53                 :           0 : gtk_file_dialog_open_cb (GtkFileDialog         *dialog,
      54                 :             :                          GAsyncResult          *result,
      55                 :             :                          ValentPresenterRemote *self)
      56                 :             : {
      57                 :           0 :   g_autoptr (GFile) file = NULL;
      58                 :           0 :   g_autoptr (GError) error = NULL;
      59                 :           0 :   char *uri = NULL;
      60                 :             : 
      61         [ #  # ]:           0 :   if ((file = gtk_file_dialog_open_finish (dialog, result, &error)) == NULL)
      62                 :             :     {
      63   [ #  #  #  # ]:           0 :       if (!g_error_matches (error, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_CANCELLED) &&
      64                 :           0 :           !g_error_matches (error, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_DISMISSED))
      65                 :           0 :         g_warning ("%s(): %s", G_STRFUNC, error->message);
      66                 :             : 
      67         [ #  # ]:           0 :       return;
      68                 :             :     }
      69                 :             : 
      70                 :           0 :   uri = g_file_get_uri (file);
      71         [ #  # ]:           0 :   g_action_group_activate_action (G_ACTION_GROUP (self->device),
      72                 :             :                                   "share.open",
      73                 :             :                                   g_variant_new_take_string (uri));
      74                 :             : }
      75                 :             : 
      76                 :             : static void
      77                 :           0 : presenter_open_action (GtkWidget  *widget,
      78                 :             :                        const char *action_name,
      79                 :             :                        GVariant   *parameter)
      80                 :             : {
      81                 :           0 :   ValentPresenterRemote *self = VALENT_PRESENTER_REMOTE (widget);
      82                 :           0 :   g_autoptr (GtkFileDialog) dialog = NULL;
      83         [ #  # ]:           0 :   g_autoptr (GListStore) filters = NULL;
      84         [ #  # ]:           0 :   g_autoptr (GtkFileFilter) presentations_filter = NULL;
      85         [ #  # ]:           0 :   g_autoptr (GtkFileFilter) all_filter = NULL;
      86                 :             : 
      87         [ #  # ]:           0 :   g_assert (VALENT_IS_PRESENTER_REMOTE (self));
      88                 :             : 
      89                 :             :   /* Select single files */
      90                 :           0 :   dialog = g_object_new (GTK_TYPE_FILE_DIALOG,
      91                 :             :                          "title",        _("Select Presentation"),
      92                 :             :                          "accept-label", _("Open"),
      93                 :             :                          "modal",        TRUE,
      94                 :             :                          NULL);
      95                 :             : 
      96                 :             :   /* Filter presentation files */
      97                 :           0 :   filters = g_list_store_new (GTK_TYPE_FILE_FILTER);
      98                 :             : 
      99                 :           0 :   presentations_filter = gtk_file_filter_new ();
     100                 :           0 :   gtk_file_filter_set_name (presentations_filter, _("Presentations"));
     101                 :             : 
     102         [ #  # ]:           0 :   for (unsigned int i = 0; mimetypes[i] != NULL; i++)
     103                 :           0 :     gtk_file_filter_add_mime_type (presentations_filter, mimetypes[i]);
     104                 :             : 
     105                 :             :   /* Allow any files */
     106                 :           0 :   all_filter = gtk_file_filter_new ();
     107                 :           0 :   gtk_file_filter_set_name (all_filter, _("All Files"));
     108                 :           0 :   gtk_file_filter_add_pattern (all_filter, "*");
     109                 :             : 
     110                 :           0 :   filters = g_list_store_new (GTK_TYPE_FILE_FILTER);
     111                 :           0 :   g_list_store_append (filters, all_filter);
     112                 :           0 :   g_list_store_append (filters, presentations_filter);
     113                 :           0 :   gtk_file_dialog_set_filters (dialog, G_LIST_MODEL (filters));
     114                 :             : 
     115         [ #  # ]:           0 :   gtk_file_dialog_open (dialog,
     116                 :             :                         GTK_WINDOW (self),
     117                 :             :                         NULL,
     118                 :             :                         (GAsyncReadyCallback)gtk_file_dialog_open_cb,
     119                 :             :                         self);
     120                 :           0 : }
     121                 :             : 
     122                 :             : /*
     123                 :             :  * GObject
     124                 :             :  */
     125                 :             : static void
     126                 :           1 : valent_presenter_remote_constructed (GObject *object)
     127                 :             : {
     128                 :           1 :   ValentPresenterRemote *self = VALENT_PRESENTER_REMOTE (object);
     129                 :             : 
     130                 :           1 :   gtk_widget_insert_action_group (GTK_WIDGET (self),
     131                 :             :                                   "device",
     132                 :           1 :                                   G_ACTION_GROUP (self->device));
     133                 :             : 
     134                 :           1 :   G_OBJECT_CLASS (valent_presenter_remote_parent_class)->constructed (object);
     135                 :           1 : }
     136                 :             : 
     137                 :             : static void
     138                 :           1 : valent_presenter_remote_dispose (GObject *object)
     139                 :             : {
     140                 :           1 :   GtkWidget *widget = GTK_WIDGET (object);
     141                 :             : 
     142                 :           1 :   gtk_widget_dispose_template (widget, VALENT_TYPE_PRESENTER_REMOTE);
     143                 :             : 
     144                 :           1 :   G_OBJECT_CLASS (valent_presenter_remote_parent_class)->dispose (object);
     145                 :           1 : }
     146                 :             : 
     147                 :             : static void
     148                 :           1 : valent_presenter_remote_get_property (GObject    *object,
     149                 :             :                                       guint       prop_id,
     150                 :             :                                       GValue     *value,
     151                 :             :                                       GParamSpec *pspec)
     152                 :             : {
     153                 :           1 :   ValentPresenterRemote *self = VALENT_PRESENTER_REMOTE (object);
     154                 :             : 
     155         [ +  - ]:           1 :   switch (prop_id)
     156                 :             :     {
     157                 :           1 :     case PROP_DEVICE:
     158                 :           1 :       g_value_set_object (value, self->device);
     159                 :           1 :       break;
     160                 :             : 
     161                 :           0 :     default:
     162                 :           0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     163                 :             :     }
     164                 :           1 : }
     165                 :             : 
     166                 :             : static void
     167                 :           1 : valent_presenter_remote_set_property (GObject      *object,
     168                 :             :                                       guint         prop_id,
     169                 :             :                                       const GValue *value,
     170                 :             :                                       GParamSpec   *pspec)
     171                 :             : {
     172                 :           1 :   ValentPresenterRemote *self = VALENT_PRESENTER_REMOTE (object);
     173                 :             : 
     174         [ +  - ]:           1 :   switch (prop_id)
     175                 :             :     {
     176                 :           1 :     case PROP_DEVICE:
     177                 :           1 :       self->device = g_value_get_object (value);
     178                 :           1 :       break;
     179                 :             : 
     180                 :           0 :     default:
     181                 :           0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     182                 :             :     }
     183                 :           1 : }
     184                 :             : 
     185                 :             : static void
     186                 :           1 : valent_presenter_remote_class_init (ValentPresenterRemoteClass *klass)
     187                 :             : {
     188                 :           1 :   GObjectClass *object_class = G_OBJECT_CLASS (klass);
     189                 :           1 :   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
     190                 :             : 
     191                 :           1 :   object_class->constructed = valent_presenter_remote_constructed;
     192                 :           1 :   object_class->dispose = valent_presenter_remote_dispose;
     193                 :           1 :   object_class->get_property = valent_presenter_remote_get_property;
     194                 :           1 :   object_class->set_property = valent_presenter_remote_set_property;
     195                 :             : 
     196                 :           1 :   gtk_widget_class_set_template_from_resource (widget_class, "/plugins/presenter/valent-presenter-remote.ui");
     197                 :             : 
     198                 :           1 :   gtk_widget_class_install_action (widget_class, "remote.open", NULL, presenter_open_action);
     199                 :             : 
     200                 :           2 :   properties [PROP_DEVICE] =
     201                 :           1 :     g_param_spec_object ("device", NULL, NULL,
     202                 :             :                          VALENT_TYPE_DEVICE,
     203                 :             :                          (G_PARAM_READWRITE |
     204                 :             :                           G_PARAM_CONSTRUCT_ONLY |
     205                 :             :                           G_PARAM_EXPLICIT_NOTIFY |
     206                 :             :                           G_PARAM_STATIC_STRINGS));
     207                 :             : 
     208                 :           1 :   g_object_class_install_properties (object_class, N_PROPERTIES, properties);
     209                 :           1 : }
     210                 :             : 
     211                 :             : static void
     212                 :           1 : valent_presenter_remote_init (ValentPresenterRemote *self)
     213                 :             : {
     214                 :           1 :   gtk_widget_init_template (GTK_WIDGET (self));
     215                 :           1 : }
     216                 :             : 
        

Generated by: LCOV version 2.0-1