GCC Code Coverage Report


Directory: ./
File: panels/common/cc-list-row-info-button.c
Date: 2024-05-04 07:58:27
Exec Total Coverage
Lines: 0 50 0.0%
Functions: 0 9 0.0%
Branches: 0 19 0.0%

Line Branch Exec Source
1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* cc-list-row.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 * Author(s):
20 * Felipe Borges <felipeborges@gnome.org>
21 *
22 * SPDX-License-Identifier: GPL-3.0-or-later
23 */
24
25 #undef G_LOG_DOMAIN
26 #define G_LOG_DOMAIN "cc-list-row-info-button"
27
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31
32 #include "cc-common-resources.h"
33 #include "cc-list-row-info-button.h"
34
35 struct _CcListRowInfoButton
36 {
37 GtkWidget parent_instance;
38
39 GtkWidget *button;
40 GtkLabel *label;
41 };
42
43 G_DEFINE_TYPE (CcListRowInfoButton, cc_list_row_info_button, GTK_TYPE_WIDGET)
44
45
46 enum {
47 PROP_0,
48 PROP_TEXT,
49 N_PROPS
50 };
51
52 static GParamSpec *properties[N_PROPS];
53
54 static void
55 cc_list_row_info_button_get_property (GObject *object,
56 guint prop_id,
57 GValue *value,
58 GParamSpec *pspec)
59 {
60 CcListRowInfoButton *self = (CcListRowInfoButton *)object;
61
62 switch (prop_id)
63 {
64 case PROP_TEXT:
65 g_value_set_string (value, gtk_label_get_label (self->label));
66 break;
67
68 default:
69 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
70 }
71 }
72
73 static void
74 cc_list_row_info_button_set_property (GObject *object,
75 guint prop_id,
76 const GValue *value,
77 GParamSpec *pspec)
78 {
79 CcListRowInfoButton *self = (CcListRowInfoButton *)object;
80
81 switch (prop_id)
82 {
83 case PROP_TEXT:
84 gtk_label_set_label (self->label, g_value_get_string (value));
85 break;
86
87 default:
88 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
89 }
90 }
91
92 static void
93 cc_list_row_info_button_dispose (GObject *object)
94 {
95 CcListRowInfoButton *self = CC_LIST_ROW_INFO_BUTTON (object);
96
97 g_clear_pointer (&self->button, gtk_widget_unparent);
98
99 G_OBJECT_CLASS (cc_list_row_info_button_parent_class)->dispose (object);
100 }
101
102 static void
103 cc_list_row_info_button_class_init (CcListRowInfoButtonClass *klass)
104 {
105 GObjectClass *object_class = G_OBJECT_CLASS (klass);
106 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
107
108 object_class->dispose = cc_list_row_info_button_dispose;
109 object_class->get_property = cc_list_row_info_button_get_property;
110 object_class->set_property = cc_list_row_info_button_set_property;
111
112 properties[PROP_TEXT] =
113 g_param_spec_string ("text",
114 "Text",
115 "Set text for the popover label",
116 NULL,
117 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
118
119 g_object_class_install_properties (object_class, N_PROPS, properties);
120
121 gtk_widget_class_set_template_from_resource (widget_class,
122 "/org/gnome/control-center/"
123 "common/cc-list-row-info-button.ui");
124
125 gtk_widget_class_bind_template_child (widget_class, CcListRowInfoButton, button);
126 gtk_widget_class_bind_template_child (widget_class, CcListRowInfoButton, label);
127
128 gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
129 }
130
131 static void
132 cc_list_row_info_button_init (CcListRowInfoButton *self)
133 {
134 g_resources_register (cc_common_get_resource ());
135
136 gtk_widget_init_template (GTK_WIDGET (self));
137 }
138
139 void
140 cc_list_row_info_button_set_text (CcListRowInfoButton *self,
141 const gchar *text)
142 {
143 g_return_if_fail (CC_IS_LIST_ROW_INFO_BUTTON (self));
144
145 if (!text)
146 text = "";
147
148 if (g_str_equal (text, gtk_label_get_label (self->label)))
149 return;
150
151 gtk_label_set_text (self->label, text);
152 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TEXT]);
153 }
154