Line |
Branch |
Exec |
Source |
1 |
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- |
2 |
|
|
* |
3 |
|
|
* Copyright (C) 2023 Cyber Phantom <inam123451@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 2 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 |
|
|
*/ |
19 |
|
|
|
20 |
|
|
#include "cc-info-entry.h" |
21 |
|
|
|
22 |
|
|
struct _CcInfoEntry |
23 |
|
|
{ |
24 |
|
|
GtkBox parent; |
25 |
|
|
|
26 |
|
|
GtkLabel *prop; |
27 |
|
|
GtkLabel *value; |
28 |
|
|
}; |
29 |
|
|
|
30 |
|
✗ |
G_DEFINE_TYPE (CcInfoEntry, cc_info_entry, GTK_TYPE_BOX) |
31 |
|
|
|
32 |
|
|
enum { |
33 |
|
|
PROP_0, |
34 |
|
|
PROP_LABEL, |
35 |
|
|
PROP_VALUE, |
36 |
|
|
N_PROPS |
37 |
|
|
}; |
38 |
|
|
|
39 |
|
|
static GParamSpec *properties[N_PROPS]; |
40 |
|
|
|
41 |
|
|
static void |
42 |
|
✗ |
cc_info_entry_get_property (GObject *object, |
43 |
|
|
guint prop_id, |
44 |
|
|
GValue *value, |
45 |
|
|
GParamSpec *pspec) |
46 |
|
|
{ |
47 |
|
✗ |
CcInfoEntry *self = (CcInfoEntry *)object; |
48 |
|
|
|
49 |
|
✗ |
switch (prop_id) |
50 |
|
|
{ |
51 |
|
✗ |
case PROP_LABEL: |
52 |
|
✗ |
g_value_set_string (value, gtk_label_get_label (self->prop)); |
53 |
|
✗ |
break; |
54 |
|
|
|
55 |
|
✗ |
case PROP_VALUE: |
56 |
|
✗ |
g_value_set_string (value, gtk_label_get_label (self->value)); |
57 |
|
✗ |
break; |
58 |
|
|
|
59 |
|
✗ |
default: |
60 |
|
✗ |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
61 |
|
|
} |
62 |
|
✗ |
} |
63 |
|
|
|
64 |
|
|
static void |
65 |
|
✗ |
cc_info_entry_set_property (GObject *object, |
66 |
|
|
guint prop_id, |
67 |
|
|
const GValue *value, |
68 |
|
|
GParamSpec *pspec) |
69 |
|
|
{ |
70 |
|
✗ |
CcInfoEntry *self = (CcInfoEntry *)object; |
71 |
|
|
|
72 |
|
✗ |
switch (prop_id) |
73 |
|
|
{ |
74 |
|
✗ |
case PROP_LABEL: |
75 |
|
✗ |
gtk_label_set_label (self->prop, g_value_get_string (value)); |
76 |
|
✗ |
break; |
77 |
|
|
|
78 |
|
✗ |
case PROP_VALUE: |
79 |
|
✗ |
gtk_label_set_label (self->value, g_value_get_string (value)); |
80 |
|
✗ |
break; |
81 |
|
|
|
82 |
|
✗ |
default: |
83 |
|
✗ |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
84 |
|
|
} |
85 |
|
✗ |
} |
86 |
|
|
|
87 |
|
|
static void |
88 |
|
✗ |
cc_info_entry_class_init (CcInfoEntryClass *klass) |
89 |
|
|
{ |
90 |
|
✗ |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
91 |
|
✗ |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
92 |
|
|
|
93 |
|
✗ |
object_class->get_property = cc_info_entry_get_property; |
94 |
|
✗ |
object_class->set_property = cc_info_entry_set_property; |
95 |
|
|
|
96 |
|
✗ |
properties[PROP_LABEL] = |
97 |
|
✗ |
g_param_spec_string ("label", |
98 |
|
|
"Label", |
99 |
|
|
"Set the Label of the Info Entry", |
100 |
|
|
NULL, |
101 |
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
102 |
|
|
|
103 |
|
✗ |
properties[PROP_VALUE] = |
104 |
|
✗ |
g_param_spec_string ("value", |
105 |
|
|
"Value", |
106 |
|
|
"Set the Value of the Info Entry", |
107 |
|
|
NULL, |
108 |
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
109 |
|
|
|
110 |
|
✗ |
g_object_class_install_properties (object_class, N_PROPS, properties); |
111 |
|
|
|
112 |
|
✗ |
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/system/about/cc-info-entry.ui"); |
113 |
|
|
|
114 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcInfoEntry, prop); |
115 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcInfoEntry, value); |
116 |
|
✗ |
} |
117 |
|
|
|
118 |
|
|
static void |
119 |
|
✗ |
cc_info_entry_init (CcInfoEntry *self) |
120 |
|
|
{ |
121 |
|
✗ |
gtk_widget_init_template (GTK_WIDGET (self)); |
122 |
|
✗ |
} |
123 |
|
|
|
124 |
|
|
void |
125 |
|
✗ |
cc_info_entry_set_value (CcInfoEntry *self, |
126 |
|
|
const gchar *value) |
127 |
|
|
{ |
128 |
|
✗ |
g_return_if_fail (CC_IS_INFO_ENTRY (self)); |
129 |
|
|
|
130 |
|
✗ |
if (!value) |
131 |
|
✗ |
value = ""; |
132 |
|
|
|
133 |
|
✗ |
if (g_str_equal (gtk_label_get_label (self->value), value)) |
134 |
|
✗ |
return; |
135 |
|
|
|
136 |
|
✗ |
gtk_label_set_label (self->value, value); |
137 |
|
✗ |
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_VALUE]); |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
GtkWidget * |
141 |
|
✗ |
cc_info_entry_new (const gchar *label, |
142 |
|
|
const gchar *value) |
143 |
|
|
{ |
144 |
|
✗ |
if (label == NULL) |
145 |
|
✗ |
label = ""; |
146 |
|
|
|
147 |
|
✗ |
if (value == NULL) |
148 |
|
✗ |
value = ""; |
149 |
|
|
|
150 |
|
✗ |
return g_object_new (CC_TYPE_INFO_ENTRY, |
151 |
|
|
"label", label, |
152 |
|
|
"value", value, |
153 |
|
|
NULL); |
154 |
|
|
} |
155 |
|
|
|