GCC Code Coverage Report


Directory: ./
File: panels/system/users/cc-entry-feedback.c
Date: 2024-05-04 07:58:27
Exec Total Coverage
Lines: 0 73 0.0%
Functions: 0 10 0.0%
Branches: 0 27 0.0%

Line Branch Exec Source
1 /*
2 * cc-entry-feedback.c
3 *
4 * Copyright 2023 Red Hat 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 3 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 * SPDX-License-Identifier: GPL-3.0-or-later
20 *
21 * Author(s):
22 * Felipe Borges <felipeborges@gnome.org>
23 * Ondrej Holy <oholy@redhat.com>
24 */
25
26 #undef G_LOG_DOMAIN
27 #define G_LOG_DOMAIN "cc-entry-feedback"
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include "cc-entry-feedback.h"
34
35 struct _CcEntryFeedback
36 {
37 GtkBox parent_instance;
38
39 GtkImage *image;
40 GtkLabel *label;
41
42 gchar *default_icon_name;
43 gchar *default_text;
44 };
45
46 G_DEFINE_TYPE (CcEntryFeedback, cc_entry_feedback, GTK_TYPE_BOX)
47
48 enum
49 {
50 PROP_0,
51 PROP_ICON_NAME,
52 PROP_TEXT,
53 PROP_DEFAULT_ICON_NAME,
54 PROP_DEFAULT_TEXT,
55 };
56
57 static void
58 cc_entry_feedback_get_property (GObject *object,
59 guint prop_id,
60 GValue *value,
61 GParamSpec *pspec)
62 {
63 CcEntryFeedback *self = CC_ENTRY_FEEDBACK (object);
64
65 switch (prop_id)
66 {
67 case PROP_ICON_NAME:
68 g_value_set_string (value, gtk_image_get_icon_name (self->image));
69 break;
70 case PROP_TEXT:
71 g_value_set_string (value, gtk_label_get_label (self->label));
72 break;
73 case PROP_DEFAULT_ICON_NAME:
74 g_value_set_string (value, self->default_icon_name);
75 break;
76 case PROP_DEFAULT_TEXT:
77 g_value_set_string (value, self->default_text);
78 break;
79 default:
80 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
81 }
82 }
83
84 static void
85 set_icon (CcEntryFeedback *self,
86 const gchar *icon_name)
87 {
88 const gchar *class;
89
90 class = gtk_image_get_icon_name (self->image);
91 if (class != NULL)
92 gtk_widget_remove_css_class (GTK_WIDGET (self->image), class);
93
94 gtk_image_set_from_icon_name (self->image, icon_name);
95 gtk_widget_add_css_class (GTK_WIDGET (self->image), icon_name);
96 }
97
98 static void
99 cc_entry_feedback_set_property (GObject *object,
100 guint prop_id,
101 const GValue *value,
102 GParamSpec *pspec)
103 {
104 CcEntryFeedback *self = CC_ENTRY_FEEDBACK (object);
105
106 switch (prop_id)
107 {
108 case PROP_ICON_NAME:
109 set_icon (self, g_value_get_string (value));
110 break;
111 case PROP_TEXT:
112 gtk_label_set_label (self->label, g_value_get_string (value));
113 break;
114 case PROP_DEFAULT_ICON_NAME:
115 g_free (self->default_icon_name);
116 self->default_icon_name = g_strdup (g_value_get_string (value));
117 if (gtk_image_get_icon_name (self->image) == NULL)
118 set_icon (self, self->default_icon_name);
119 break;
120 case PROP_DEFAULT_TEXT:
121 g_free (self->default_text);
122 self->default_text = g_strdup (g_value_get_string (value));
123 if (g_str_equal (gtk_label_get_label (self->label), ""))
124 gtk_label_set_label (self->label, self->default_text);
125 break;
126 default:
127 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
128 }
129 }
130
131 static void
132 cc_entry_feedback_init (CcEntryFeedback *self)
133 {
134 gtk_widget_init_template (GTK_WIDGET (self));
135 }
136
137 static void
138 cc_entry_feedback_class_init (CcEntryFeedbackClass * klass)
139 {
140 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
141 GObjectClass *object_class = G_OBJECT_CLASS (klass);
142
143 object_class->get_property = cc_entry_feedback_get_property;
144 object_class->set_property = cc_entry_feedback_set_property;
145
146 gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/system/users/cc-entry-feedback.ui");
147
148 gtk_widget_class_bind_template_child (widget_class, CcEntryFeedback, image);
149 gtk_widget_class_bind_template_child (widget_class, CcEntryFeedback, label);
150
151 g_object_class_install_property (object_class,
152 PROP_ICON_NAME,
153 g_param_spec_string ("icon-name",
154 "Icon name",
155 "The icon theme name for the icon to be shown",
156 NULL,
157 G_PARAM_READWRITE));
158 g_object_class_install_property (object_class,
159 PROP_TEXT,
160 g_param_spec_string ("text",
161 "Text",
162 "The text to be displayed.",
163 NULL,
164 G_PARAM_READWRITE));
165 g_object_class_install_property (object_class,
166 PROP_DEFAULT_ICON_NAME,
167 g_param_spec_string ("default-icon-name",
168 "Default icon name",
169 "The icon theme name for the icon to be shown by default.",
170 NULL,
171 G_PARAM_READWRITE));
172 g_object_class_install_property (object_class,
173 PROP_DEFAULT_TEXT,
174 g_param_spec_string ("default-text",
175 "Default text",
176 "The text to be displayed by default.",
177 NULL,
178 G_PARAM_READWRITE));
179 }
180
181 void
182 cc_entry_feedback_reset (CcEntryFeedback *self)
183 {
184 g_return_if_fail (CC_IS_ENTRY_FEEDBACK (self));
185
186 cc_entry_feedback_update (self, self->default_icon_name, self->default_text);
187 }
188
189 void
190 cc_entry_feedback_update (CcEntryFeedback *self,
191 const gchar *icon_name,
192 const gchar *text)
193 {
194 g_return_if_fail (CC_IS_ENTRY_FEEDBACK (self));
195
196 set_icon (self, icon_name);
197 gtk_label_set_label (self->label, text);
198 }
199