GCC Code Coverage Report


Directory: ./
File: panels/common/cc-illustrated-row.c
Date: 2024-05-04 07:58:27
Exec Total Coverage
Lines: 0 65 0.0%
Functions: 0 11 0.0%
Branches: 0 23 0.0%

Line Branch Exec Source
1 /* cc-illustrated-row.c
2 *
3 * Copyright 2018 Purism SPC
4 * 2021 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
5 * 2023 Red Hat, Inc
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * SPDX-License-Identifier: GPL-3.0-or-later
21 */
22
23 #include "cc-illustrated-row.h"
24
25 struct _CcIllustratedRow
26 {
27 CcVerticalRow parent;
28
29 GtkBox *picture_box;
30 GtkPicture *picture;
31 gchar *resource_path;
32
33 GtkMediaStream *media_stream;
34 };
35
36 G_DEFINE_FINAL_TYPE (CcIllustratedRow, cc_illustrated_row, CC_TYPE_VERTICAL_ROW);
37
38 enum
39 {
40 PROP_0,
41 PROP_RESOURCE,
42 N_PROPS,
43 };
44
45 static GParamSpec *props[N_PROPS] = { NULL, };
46
47 static void
48 on_picture_leave_cb (CcIllustratedRow *self)
49 {
50 GtkMediaStream *stream = GTK_MEDIA_STREAM (gtk_picture_get_paintable (self->picture));
51
52 gtk_media_stream_set_loop (stream, FALSE);
53 gtk_media_stream_pause (stream);
54 }
55
56 static void
57 on_picture_hover_cb (CcIllustratedRow *self)
58 {
59 GtkMediaStream *stream = GTK_MEDIA_STREAM (gtk_picture_get_paintable (self->picture));
60
61 gtk_media_stream_set_loop (stream, TRUE);
62 gtk_media_stream_play (stream);
63 }
64
65 static void
66 cc_illustrated_row_get_property (GObject *object,
67 guint prop_id,
68 GValue *value,
69 GParamSpec *pspec)
70 {
71 CcIllustratedRow *self = CC_ILLUSTRATED_ROW (object);
72
73 switch (prop_id)
74 {
75 case PROP_RESOURCE:
76 g_value_set_string (value, self->resource_path);
77 break;
78 default:
79 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
80 }
81 }
82
83 static void
84 cc_illustrated_row_set_property (GObject *object,
85 guint prop_id,
86 const GValue *value,
87 GParamSpec *pspec)
88 {
89 CcIllustratedRow *self = CC_ILLUSTRATED_ROW (object);
90
91 switch (prop_id)
92 {
93 case PROP_RESOURCE:
94 cc_illustrated_row_set_resource (self, g_value_get_string (value));
95 break;
96 default:
97 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
98 }
99 }
100
101 static void
102 cc_illustrated_row_finalize (GObject *object)
103 {
104 CcIllustratedRow *self = CC_ILLUSTRATED_ROW (object);
105
106 g_clear_pointer (&self->resource_path, g_free);
107 G_OBJECT_CLASS (cc_illustrated_row_parent_class)->finalize (object);
108 }
109
110 static void
111 cc_illustrated_row_class_init (CcIllustratedRowClass *klass)
112 {
113 GObjectClass *object_class = G_OBJECT_CLASS (klass);
114 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
115
116 object_class->get_property = cc_illustrated_row_get_property;
117 object_class->set_property = cc_illustrated_row_set_property;
118 object_class->finalize = cc_illustrated_row_finalize;
119
120 props[PROP_RESOURCE] =
121 g_param_spec_string ("resource",
122 "Resource",
123 "Resource",
124 "",
125 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
126
127 g_object_class_install_properties (object_class, N_PROPS, props);
128
129 gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/common/cc-illustrated-row.ui");
130
131 gtk_widget_class_bind_template_child (widget_class, CcIllustratedRow, picture);
132 gtk_widget_class_bind_template_child (widget_class, CcIllustratedRow, picture_box);
133
134 gtk_widget_class_bind_template_callback (widget_class, on_picture_hover_cb);
135 gtk_widget_class_bind_template_callback (widget_class, on_picture_leave_cb);
136 }
137
138 static void
139 cc_illustrated_row_init (CcIllustratedRow *self)
140 {
141 gtk_widget_init_template (GTK_WIDGET (self));
142 gtk_widget_set_name (GTK_WIDGET (self), "illustrated-row");
143 gtk_widget_add_css_class (GTK_WIDGET (self), "illustrated-row");
144 }
145
146 void
147 cc_illustrated_row_set_resource (CcIllustratedRow *self,
148 const gchar *resource_path)
149 {
150 g_return_if_fail (CC_IS_ILLUSTRATED_ROW (self));
151
152 if (self->media_stream != NULL)
153 g_clear_object (&self->media_stream);
154
155 g_set_str (&self->resource_path, resource_path);
156 self->media_stream = gtk_media_file_new_for_resource (self->resource_path);
157
158 gtk_picture_set_paintable (self->picture, GDK_PAINTABLE (self->media_stream));
159 gtk_widget_set_visible (GTK_WIDGET (self->picture_box),
160 self->resource_path != NULL &&
161 g_strcmp0 (self->resource_path, "") != 0);
162
163 g_object_notify_by_pspec (G_OBJECT (self), props[PROP_RESOURCE]);
164 }
165