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
200
201
202
|
/* ev-progress-message-area.c
* this file is part of atril, a mate document viewer
*
* Copyright (C) 2008 Carlos Garcia Campos <carlosgc@gnome.org>
*
* Atril is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Atril is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <gtk/gtk.h>
#include "ev-progress-message-area.h"
#if GTK_CHECK_VERSION (3, 0, 0)
#define gtk_vbox_new(X,Y) gtk_box_new(GTK_ORIENTATION_VERTICAL,Y)
#endif
#define EV_PROGRESS_MESSAGE_AREA_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), EV_TYPE_PROGRESS_MESSAGE_AREA, EvProgressMessageAreaPrivate))
struct _EvProgressMessageAreaPrivate {
GtkWidget *label;
GtkWidget *progress_bar;
};
enum {
PROP_0,
PROP_STATUS,
PROP_FRACTION
};
static void ev_progress_message_area_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void ev_progress_message_area_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
G_DEFINE_TYPE (EvProgressMessageArea, ev_progress_message_area, EV_TYPE_MESSAGE_AREA)
static void
ev_progress_message_area_class_init (EvProgressMessageAreaClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
gobject_class->set_property = ev_progress_message_area_set_property;
gobject_class->get_property = ev_progress_message_area_get_property;
g_object_class_install_property (gobject_class,
PROP_STATUS,
g_param_spec_string ("status",
"Status",
"The status text of the progress area",
NULL,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_FRACTION,
g_param_spec_double ("fraction",
"Fraction",
"The fraction of total work that has been completed",
0.0, 1.0, 0.0,
G_PARAM_READWRITE));
g_type_class_add_private (gobject_class, sizeof (EvProgressMessageAreaPrivate));
}
static void
ev_progress_message_area_init (EvProgressMessageArea *area)
{
GtkWidget *contents;
GtkWidget *vbox;
area->priv = EV_PROGRESS_MESSAGE_AREA_GET_PRIVATE (area);
contents = _ev_message_area_get_main_box (EV_MESSAGE_AREA (area));
vbox = gtk_vbox_new (FALSE, 6);
area->priv->label = gtk_label_new (NULL);
gtk_label_set_use_markup (GTK_LABEL (area->priv->label), TRUE);
gtk_label_set_ellipsize (GTK_LABEL (area->priv->label),
PANGO_ELLIPSIZE_END);
gtk_misc_set_alignment (GTK_MISC (area->priv->label), 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (vbox), area->priv->label, TRUE, TRUE, 0);
gtk_widget_show (area->priv->label);
area->priv->progress_bar = gtk_progress_bar_new ();
gtk_widget_set_size_request (area->priv->progress_bar, -1, 15);
gtk_box_pack_start (GTK_BOX (vbox), area->priv->progress_bar, TRUE, FALSE, 0);
gtk_widget_show (area->priv->progress_bar);
gtk_box_pack_start (GTK_BOX (contents), vbox, TRUE, TRUE, 0);
gtk_widget_show (vbox);
}
static void
ev_progress_message_area_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
EvProgressMessageArea *area = EV_PROGRESS_MESSAGE_AREA (object);
switch (prop_id) {
case PROP_STATUS:
ev_progress_message_area_set_status (area, g_value_get_string (value));
break;
case PROP_FRACTION:
ev_progress_message_area_set_fraction (area, g_value_get_double (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
ev_progress_message_area_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
EvProgressMessageArea *area = EV_PROGRESS_MESSAGE_AREA (object);
switch (prop_id) {
case PROP_STATUS:
g_value_set_string (value, gtk_label_get_label (GTK_LABEL (area->priv->label)));
break;
case PROP_FRACTION: {
gdouble fraction;
fraction = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (area->priv->progress_bar));
g_value_set_double (value, fraction);
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
GtkWidget *
ev_progress_message_area_new (const gchar *stock_id,
const gchar *text,
const gchar *first_button_text,
...)
{
GtkWidget *widget;
widget = g_object_new (EV_TYPE_PROGRESS_MESSAGE_AREA,
"message-type", GTK_MESSAGE_OTHER,
"text", text,
NULL);
if (first_button_text) {
va_list args;
va_start (args, first_button_text);
_ev_message_area_add_buttons_valist (EV_MESSAGE_AREA (widget),
first_button_text,
args);
va_end (args);
}
ev_message_area_set_image_from_stock (EV_MESSAGE_AREA (widget), stock_id);
return widget;
}
void
ev_progress_message_area_set_status (EvProgressMessageArea *area,
const gchar *str)
{
g_return_if_fail (EV_IS_PROGRESS_MESSAGE_AREA (area));
gtk_label_set_text (GTK_LABEL (area->priv->label), str);
g_object_notify (G_OBJECT (area), "status");
}
void
ev_progress_message_area_set_fraction (EvProgressMessageArea *area,
gdouble fraction)
{
g_return_if_fail (EV_IS_PROGRESS_MESSAGE_AREA (area));
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (area->priv->progress_bar),
fraction);
g_object_notify (G_OBJECT (area), "fraction");
}
|