1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
* vi:set noexpandtab tabstop=8 shiftwidth=8:
*
* Copyright (C) 2016 Rafał Lużyński <digitalfreak@lingonborough.com>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include "config.h"
#include "gs-info-bar.h"
struct _GsInfoBar
{
GtkInfoBar parent_instance;
GtkWidget *label_title;
GtkWidget *label_body;
GtkWidget *label_warning;
};
G_DEFINE_TYPE (GsInfoBar, gs_info_bar, GTK_TYPE_INFO_BAR)
enum {
PROP_0,
PROP_TITLE,
PROP_BODY,
PROP_WARNING
};
static void
gs_info_bar_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GsInfoBar *infobar = GS_INFO_BAR (object);
switch (prop_id) {
case PROP_TITLE:
g_value_set_string (value, gs_info_bar_get_title (infobar));
break;
case PROP_BODY:
g_value_set_string (value, gs_info_bar_get_body (infobar));
break;
case PROP_WARNING:
g_value_set_string (value, gs_info_bar_get_warning (infobar));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gs_info_bar_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GsInfoBar *infobar = GS_INFO_BAR (object);
switch (prop_id) {
case PROP_TITLE:
gs_info_bar_set_title (infobar, g_value_get_string (value));
break;
case PROP_BODY:
gs_info_bar_set_body (infobar, g_value_get_string (value));
break;
case PROP_WARNING:
gs_info_bar_set_warning (infobar, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gs_info_bar_init (GsInfoBar *infobar)
{
gtk_widget_set_has_window (GTK_WIDGET (infobar), FALSE);
gtk_widget_init_template (GTK_WIDGET (infobar));
}
static void
gs_info_bar_class_init (GsInfoBarClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->get_property = gs_info_bar_get_property;
object_class->set_property = gs_info_bar_set_property;
g_object_class_install_property (object_class, PROP_TITLE,
g_param_spec_string ("title",
"Title Text",
"The title (header) text of the info bar",
"",
G_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_BODY,
g_param_spec_string ("body",
"Body Text",
"The body (main) text of the info bar",
NULL,
G_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_WARNING,
g_param_spec_string ("warning",
"Warning Text",
"The warning text of the info bar, below the body text",
NULL,
G_PARAM_READWRITE));
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-info-bar.ui");
gtk_widget_class_bind_template_child (widget_class,
GsInfoBar, label_title);
gtk_widget_class_bind_template_child (widget_class,
GsInfoBar, label_body);
gtk_widget_class_bind_template_child (widget_class,
GsInfoBar, label_warning);
}
GtkWidget *
gs_info_bar_new (void)
{
GsInfoBar *infobar;
infobar = g_object_new (GS_TYPE_INFO_BAR, NULL);
return GTK_WIDGET (infobar);
}
static const gchar *
retrieve_from_label (GtkWidget *label)
{
if (!gtk_widget_get_visible (label))
return NULL;
else
return gtk_label_get_label (GTK_LABEL (label));
}
static void
update_label (GtkWidget *label, const gchar *text)
{
gtk_label_set_label (GTK_LABEL (label), text);
gtk_widget_set_visible (label,
text != NULL && *text != '\0');
}
const gchar *
gs_info_bar_get_title (GsInfoBar *bar)
{
g_return_val_if_fail (GS_IS_INFO_BAR (bar), NULL);
return retrieve_from_label (bar->label_title);
}
void
gs_info_bar_set_title (GsInfoBar *bar, const gchar *text)
{
g_return_if_fail (GS_IS_INFO_BAR (bar));
update_label (bar->label_title, text);
}
const gchar *
gs_info_bar_get_body (GsInfoBar *bar)
{
g_return_val_if_fail (GS_IS_INFO_BAR (bar), NULL);
return retrieve_from_label (bar->label_body);
}
void
gs_info_bar_set_body (GsInfoBar *bar, const gchar *text)
{
g_return_if_fail (GS_IS_INFO_BAR (bar));
update_label (bar->label_body, text);
}
const gchar *
gs_info_bar_get_warning (GsInfoBar *bar)
{
g_return_val_if_fail (GS_IS_INFO_BAR (bar), NULL);
return retrieve_from_label (bar->label_warning);
}
void
gs_info_bar_set_warning (GsInfoBar *bar, const gchar *text)
{
g_return_if_fail (GS_IS_INFO_BAR (bar));
update_label (bar->label_warning, text);
}
|