GCC Code Coverage Report


Directory: ./
File: panels/wacom/cc-wacom-ekr-page.c
Date: 2024-05-04 07:58:27
Exec Total Coverage
Lines: 0 71 0.0%
Functions: 0 12 0.0%
Branches: 0 19 0.0%

Line Branch Exec Source
1 /*
2 * Copyright © 2022 Red Hat, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Carlos Garnacho <carlosg@gnome.org>
18 */
19
20 #include "config.h"
21
22 #include "cc-wacom-ekr-page.h"
23 #include "cc-wacom-panel.h"
24
25 struct _CcWacomEkrPage
26 {
27 GtkBox parent_instance;
28 GtkWidget *ekr_section;
29 GtkWidget *ekr_icon;
30 GtkWidget *ekr_map_buttons;
31 CcWacomPanel *panel;
32 CcWacomDevice *device;
33 };
34
35 enum {
36 PROP_0,
37 PROP_PANEL,
38 PROP_DEVICE,
39 N_PROPS,
40 };
41
42 static GParamSpec *props[N_PROPS] = { 0, };
43
44 G_DEFINE_TYPE (CcWacomEkrPage, cc_wacom_ekr_page, GTK_TYPE_BOX)
45
46 static void
47 set_osd_visibility_cb (GObject *source_object,
48 GAsyncResult *res,
49 gpointer data)
50 {
51 g_autoptr(GError) error = NULL;
52 g_autoptr(GVariant) result = NULL;
53
54 result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error);
55
56 if (error && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
57 g_warning ("Error invoking pad button mapping OSK: %s\n", error->message);
58 }
59
60 static void
61 set_osd_visibility (CcWacomEkrPage *page)
62 {
63 GDBusProxy *proxy;
64 GsdDevice *gsd_device;
65 const gchar *device_path;
66
67 proxy = cc_wacom_panel_get_gsd_wacom_bus_proxy (page->panel);
68
69 if (proxy == NULL) {
70 g_warning ("Wacom D-Bus interface is not available");
71 return;
72 }
73
74 gsd_device = cc_wacom_device_get_device (page->device);
75 device_path = gsd_device_get_device_file (gsd_device);
76
77 g_dbus_proxy_call (proxy,
78 "Show",
79 g_variant_new ("(ob)", device_path, TRUE),
80 G_DBUS_CALL_FLAGS_NONE,
81 -1,
82 NULL,
83 set_osd_visibility_cb,
84 page);
85 }
86
87 static void
88 on_map_buttons_activated (CcWacomEkrPage *self)
89 {
90 set_osd_visibility (self);
91 }
92
93 static void
94 cc_wacom_ekr_page_get_property (GObject *object,
95 guint prop_id,
96 GValue *value,
97 GParamSpec *pspec)
98 {
99 CcWacomEkrPage *page = CC_WACOM_EKR_PAGE (object);
100
101 switch (prop_id) {
102 case PROP_PANEL:
103 g_value_set_object (value, page->panel);
104 break;
105 case PROP_DEVICE:
106 g_value_set_object (value, page->device);
107 break;
108 default:
109 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
110 break;
111 }
112 }
113
114 static void
115 cc_wacom_ekr_page_set_property (GObject *object,
116 guint prop_id,
117 const GValue *value,
118 GParamSpec *pspec)
119 {
120 CcWacomEkrPage *page = CC_WACOM_EKR_PAGE (object);
121
122 switch (prop_id) {
123 case PROP_PANEL:
124 page->panel = g_value_get_object (value);
125 break;
126 case PROP_DEVICE:
127 page->device = g_value_get_object (value);
128 break;
129 default:
130 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
131 break;
132 }
133 }
134
135 static void
136 cc_wacom_ekr_page_constructed (GObject *object)
137 {
138 CcWacomEkrPage *page = CC_WACOM_EKR_PAGE (object);
139
140 G_OBJECT_CLASS (cc_wacom_ekr_page_parent_class)->constructed (object);
141
142 adw_preferences_group_set_title (ADW_PREFERENCES_GROUP (page->ekr_section),
143 cc_wacom_device_get_name (page->device));
144 }
145
146 static void
147 cc_wacom_ekr_page_class_init (CcWacomEkrPageClass *klass)
148 {
149 GObjectClass *object_class = G_OBJECT_CLASS (klass);
150 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
151
152 object_class->get_property = cc_wacom_ekr_page_get_property;
153 object_class->set_property = cc_wacom_ekr_page_set_property;
154 object_class->constructed = cc_wacom_ekr_page_constructed;
155
156 gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/wacom/cc-wacom-ekr-page.ui");
157
158 gtk_widget_class_bind_template_child (widget_class, CcWacomEkrPage, ekr_section);
159 gtk_widget_class_bind_template_child (widget_class, CcWacomEkrPage, ekr_icon);
160 gtk_widget_class_bind_template_child (widget_class, CcWacomEkrPage, ekr_map_buttons);
161
162 gtk_widget_class_bind_template_callback (widget_class, on_map_buttons_activated);
163
164 props[PROP_PANEL] = g_param_spec_object ("panel",
165 "panel",
166 "panel",
167 CC_TYPE_WACOM_PANEL,
168 G_PARAM_READWRITE |
169 G_PARAM_CONSTRUCT_ONLY);
170
171 props[PROP_DEVICE] = g_param_spec_object ("device",
172 "device",
173 "device",
174 CC_TYPE_WACOM_DEVICE,
175 G_PARAM_READWRITE |
176 G_PARAM_CONSTRUCT_ONLY);
177
178 g_object_class_install_properties (object_class, N_PROPS, props);
179 }
180
181 static void
182 cc_wacom_ekr_page_init (CcWacomEkrPage *page)
183 {
184 gtk_widget_init_template (GTK_WIDGET (page));
185 }
186
187 GtkWidget *
188 cc_wacom_ekr_page_new (CcWacomPanel *panel,
189 CcWacomDevice *ekr)
190 {
191 return g_object_new (CC_TYPE_WACOM_EKR_PAGE,
192 "panel", panel,
193 "device", ekr,
194 NULL);
195 }
196