GCC Code Coverage Report


Directory: ./
File: shell/cc-panel.c
Date: 2024-05-04 07:58:27
Exec Total Coverage
Lines: 26 80 32.5%
Functions: 8 13 61.5%
Branches: 8 39 20.5%

Line Branch Exec Source
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
2 *
3 * Copyright (C) 2010 Red Hat, Inc.
4 * Copyright (C) 2010 Intel, Inc
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 *
19 * Authors: William Jon McCann <jmccann@redhat.com>
20 * Thomas Wood <thomas.wood@intel.com>
21 *
22 */
23
24 /**
25 * SECTION:cc-panel
26 * @short_description: An abstract class for Control Center panels
27 *
28 * CcPanel is an abstract class used to implement panels for the shell. A
29 * panel contains a collection of related settings that are displayed within
30 * the shell window.
31 */
32
33 #include "config.h"
34
35 #include "cc-panel.h"
36
37 #include <stdlib.h>
38 #include <stdio.h>
39
40 #include <gtk/gtk.h>
41 #include <gio/gio.h>
42
43 typedef struct
44 {
45 CcShell *shell;
46 GCancellable *cancellable;
47
48 gchar *subpage;
49 } CcPanelPrivate;
50
51
5/7
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 47 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 46 times.
142 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (CcPanel, cc_panel, ADW_TYPE_NAVIGATION_PAGE,
52 G_ADD_PRIVATE (CcPanel))
53
54 enum
55 {
56 PROP_0,
57 PROP_SHELL,
58 PROP_PARAMETERS,
59 PROP_SUBPAGE,
60 N_PROPS
61 };
62
63 static GParamSpec *properties [N_PROPS];
64
65 /* GtkBuildable interface */
66
67 /* GObject overrides */
68
69 static void
70 11 cc_panel_set_property (GObject *object,
71 guint prop_id,
72 const GValue *value,
73 GParamSpec *pspec)
74 {
75 11 CcPanelPrivate *priv = cc_panel_get_instance_private (CC_PANEL (object));
76
77
1/3
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
11 switch (prop_id)
78 {
79 11 case PROP_SHELL:
80 /* construct only property */
81 11 priv->shell = g_value_get_object (value);
82 11 break;
83
84 case PROP_PARAMETERS:
85 {
86 g_autoptr(GVariant) v = NULL;
87 GVariant *parameters;
88 gsize n_parameters;
89
90 parameters = g_value_get_variant (value);
91
92 if (parameters == NULL)
93 return;
94
95 n_parameters = g_variant_n_children (parameters);
96 if (n_parameters == 0)
97 return;
98
99 g_variant_get_child (parameters, 0, "v", &v);
100
101 if (g_variant_is_of_type (v, G_VARIANT_TYPE_STRING))
102 {
103 g_set_str (&priv->subpage, g_variant_get_string (v, NULL));
104 g_object_notify_by_pspec (object, properties[PROP_SUBPAGE]);
105 }
106 else if (!g_variant_is_of_type (v, G_VARIANT_TYPE_DICTIONARY))
107 g_warning ("Wrong type for the first argument GVariant, expected 'a{sv}' but got '%s'",
108 (gchar *)g_variant_get_type (v));
109 else if (g_variant_n_children (v) > 0)
110 g_warning ("Ignoring additional flags");
111
112 if (n_parameters > 1)
113 g_warning ("Ignoring additional parameters");
114
115 break;
116 }
117
118 default:
119 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
120 break;
121 }
122 }
123
124 static void
125 cc_panel_get_property (GObject *object,
126 guint prop_id,
127 GValue *value,
128 GParamSpec *pspec)
129 {
130 CcPanelPrivate *priv = cc_panel_get_instance_private (CC_PANEL (object));
131
132 switch (prop_id)
133 {
134 case PROP_SHELL:
135 g_value_set_object (value, priv->shell);
136 break;
137
138 case PROP_SUBPAGE:
139 g_value_set_string (value, priv->subpage);
140 break;
141
142 default:
143 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
144 break;
145 }
146 }
147
148 static void
149 11 cc_panel_finalize (GObject *object)
150 {
151 11 CcPanelPrivate *priv = cc_panel_get_instance_private (CC_PANEL (object));
152
153 11 g_cancellable_cancel (priv->cancellable);
154
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 g_clear_object (&priv->cancellable);
155
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 g_clear_pointer (&priv->subpage, g_free);
156
157 11 G_OBJECT_CLASS (cc_panel_parent_class)->finalize (object);
158 11 }
159
160 static void
161 1 cc_panel_class_init (CcPanelClass *klass)
162 {
163 1 GObjectClass *object_class = G_OBJECT_CLASS (klass);
164
165 1 object_class->get_property = cc_panel_get_property;
166 1 object_class->set_property = cc_panel_set_property;
167 1 object_class->finalize = cc_panel_finalize;
168
169 1 properties[PROP_SHELL] = g_param_spec_object ("shell",
170 "Shell",
171 "Shell the Panel resides in",
172 CC_TYPE_SHELL,
173 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
174
175 1 properties[PROP_PARAMETERS] = g_param_spec_variant ("parameters",
176 "Structured parameters",
177 "Additional parameters passed externally (ie. command line, D-Bus activation)",
178 G_VARIANT_TYPE ("av"),
179 NULL,
180 G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
181
182 1 properties[PROP_SUBPAGE] = g_param_spec_string ("subpage",
183 "Subpage parameters",
184 "Additional parameter extracted from the parameters property to launch a panel subpage",
185 NULL,
186 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
187
188 1 g_object_class_install_properties (object_class, N_PROPS, properties);
189 1 }
190
191 static void
192 11 cc_panel_init (CcPanel *panel)
193 {
194 11 }
195
196 /**
197 * cc_panel_get_shell:
198 * @panel: A #CcPanel
199 *
200 * Get the shell that the panel resides in
201 *
202 * Returns: a #CcShell
203 */
204 CcShell *
205 cc_panel_get_shell (CcPanel *panel)
206 {
207 CcPanelPrivate *priv;
208
209 g_return_val_if_fail (CC_IS_PANEL (panel), NULL);
210
211 priv = cc_panel_get_instance_private (panel);
212
213 return priv->shell;
214 }
215
216 const gchar*
217 cc_panel_get_help_uri (CcPanel *panel)
218 {
219 CcPanelClass *class = CC_PANEL_GET_CLASS (panel);
220
221 if (class->get_help_uri)
222 return class->get_help_uri (panel);
223
224 return NULL;
225 }
226
227 GCancellable *
228 cc_panel_get_cancellable (CcPanel *panel)
229 {
230 CcPanelPrivate *priv = cc_panel_get_instance_private (panel);
231
232 g_return_val_if_fail (CC_IS_PANEL (panel), NULL);
233
234 if (priv->cancellable == NULL)
235 priv->cancellable = g_cancellable_new ();
236
237 return priv->cancellable;
238 }
239
240 void
241 cc_panel_deactivate (CcPanel *panel)
242 {
243 CcPanelPrivate *priv = cc_panel_get_instance_private (panel);
244
245 g_cancellable_cancel (priv->cancellable);
246 }
247