GCC Code Coverage Report


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

Line Branch Exec Source
1 /* cc-info-row.c
2 *
3 * Copyright 2018 Matthias Clasen <matthias.clasen@gmail.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: GPL-3.0-or-later
19 */
20
21 #include <config.h>
22 #include <glib/gi18n.h>
23
24 #include "cc-info-row.h"
25 #include "cc-applications-resources.h"
26
27 struct _CcInfoRow
28 {
29 AdwActionRow parent;
30
31 GtkWidget *info;
32 GtkWidget *expander;
33
34 gboolean expanded;
35 gboolean link;
36 };
37
38 G_DEFINE_TYPE (CcInfoRow, cc_info_row, ADW_TYPE_ACTION_ROW)
39
40 enum
41 {
42 PROP_0,
43 PROP_INFO,
44 PROP_HAS_EXPANDER,
45 PROP_IS_LINK,
46 PROP_EXPANDED
47 };
48
49 static void
50 cc_info_row_get_property (GObject *object,
51 guint prop_id,
52 GValue *value,
53 GParamSpec *pspec)
54 {
55 CcInfoRow *row = CC_INFO_ROW (object);
56
57 switch (prop_id)
58 {
59 case PROP_INFO:
60 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (row->info)));
61 break;
62 case PROP_HAS_EXPANDER:
63 g_value_set_boolean (value, gtk_widget_get_visible (row->expander));
64 break;
65 case PROP_IS_LINK:
66 g_value_set_boolean (value, row->link);
67 break;
68 case PROP_EXPANDED:
69 g_value_set_boolean (value, cc_info_row_get_expanded (row));
70 break;
71 default:
72 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
73 break;
74 }
75 }
76
77 static void
78 update_expander (CcInfoRow *row)
79 {
80 if (row->link)
81 gtk_image_set_from_icon_name (GTK_IMAGE (row->expander), "go-next-symbolic");
82 else if (row->expanded)
83 gtk_image_set_from_icon_name (GTK_IMAGE (row->expander), "pan-down-symbolic");
84 else
85 gtk_image_set_from_icon_name (GTK_IMAGE (row->expander), "pan-end-symbolic");
86 }
87
88 static void
89 cc_info_row_set_property (GObject *object,
90 guint prop_id,
91 const GValue *value,
92 GParamSpec *pspec)
93 {
94 CcInfoRow *row = CC_INFO_ROW (object);
95
96 switch (prop_id)
97 {
98 case PROP_INFO:
99 gtk_label_set_label (GTK_LABEL (row->info), g_value_get_string (value));
100 break;
101
102 case PROP_HAS_EXPANDER:
103 gtk_widget_set_visible (row->expander, g_value_get_boolean (value));
104 gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), g_value_get_boolean (value));
105 break;
106
107 case PROP_IS_LINK:
108 row->link = g_value_get_boolean (value);
109 update_expander (row);
110 break;
111
112 case PROP_EXPANDED:
113 cc_info_row_set_expanded (row, g_value_get_boolean (value));
114 break;
115
116 default:
117 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
118 break;
119 }
120 }
121
122 static void
123 cc_info_row_class_init (CcInfoRowClass *klass)
124 {
125 GObjectClass *object_class = G_OBJECT_CLASS (klass);
126 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
127
128 object_class->get_property = cc_info_row_get_property;
129 object_class->set_property = cc_info_row_set_property;
130
131 gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/applications/cc-info-row.ui");
132
133 g_object_class_install_property (object_class,
134 PROP_INFO,
135 g_param_spec_string ("info", "info", "info",
136 NULL, G_PARAM_READWRITE));
137
138 g_object_class_install_property (object_class,
139 PROP_HAS_EXPANDER,
140 g_param_spec_boolean ("has-expander", "has-expander", "has-expander",
141 FALSE, G_PARAM_READWRITE));
142
143 g_object_class_install_property (object_class,
144 PROP_EXPANDED,
145 g_param_spec_boolean ("expanded", "expanded", "expanded",
146 FALSE, G_PARAM_READWRITE));
147
148 g_object_class_install_property (object_class,
149 PROP_IS_LINK,
150 g_param_spec_boolean ("is-link", "is-link", "is-link",
151 FALSE, G_PARAM_READWRITE));
152
153 gtk_widget_class_bind_template_child (widget_class, CcInfoRow, info);
154 gtk_widget_class_bind_template_child (widget_class, CcInfoRow, expander);
155 }
156
157 static void
158 cc_info_row_init (CcInfoRow *self)
159 {
160 gtk_widget_init_template (GTK_WIDGET (self));
161 }
162
163 CcInfoRow *
164 cc_info_row_new (void)
165 {
166 return CC_INFO_ROW (g_object_new (CC_TYPE_INFO_ROW, NULL));
167 }
168
169 gboolean
170 cc_info_row_get_expanded (CcInfoRow *row)
171 {
172 return row->expanded;
173 }
174
175 void
176 cc_info_row_set_expanded (CcInfoRow *row,
177 gboolean expanded)
178 {
179 if (row->expanded == expanded)
180 return;
181
182 row->expanded = expanded;
183 update_expander (row);
184
185 g_object_notify (G_OBJECT (row), "expanded");
186 }
187
188