1 /* ev-progress-message-area.c
2 * this file is part of evince, a gnome document viewer
4 * Copyright (C) 2008 Carlos Garcia Campos <carlosgc@gnome.org>
6 * Evince is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Evince is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
25 #include "ev-progress-message-area.h"
27 #define EV_PROGRESS_MESSAGE_AREA_GET_PRIVATE(obj) \
28 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EV_TYPE_PROGRESS_MESSAGE_AREA, EvProgressMessageAreaPrivate))
30 struct _EvProgressMessageAreaPrivate {
32 GtkWidget *progress_bar;
41 static void ev_progress_message_area_set_property (GObject *object,
45 static void ev_progress_message_area_get_property (GObject *object,
50 G_DEFINE_TYPE (EvProgressMessageArea, ev_progress_message_area, EV_TYPE_MESSAGE_AREA)
53 ev_progress_message_area_class_init (EvProgressMessageAreaClass *class)
55 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
57 gobject_class->set_property = ev_progress_message_area_set_property;
58 gobject_class->get_property = ev_progress_message_area_get_property;
60 g_object_class_install_property (gobject_class,
62 g_param_spec_string ("status",
64 "The status text of the progress area",
67 g_object_class_install_property (gobject_class,
69 g_param_spec_double ("fraction",
71 "The fraction of total work that has been completed",
75 g_type_class_add_private (gobject_class, sizeof (EvProgressMessageAreaPrivate));
79 ev_progress_message_area_init (EvProgressMessageArea *area)
84 area->priv = EV_PROGRESS_MESSAGE_AREA_GET_PRIVATE (area);
86 contents = _ev_message_area_get_main_box (EV_MESSAGE_AREA (area));
88 vbox = gtk_vbox_new (FALSE, 6);
90 area->priv->label = gtk_label_new (NULL);
91 gtk_label_set_use_markup (GTK_LABEL (area->priv->label), TRUE);
92 gtk_label_set_ellipsize (GTK_LABEL (area->priv->label),
94 gtk_misc_set_alignment (GTK_MISC (area->priv->label), 0.0, 0.5);
95 gtk_box_pack_start (GTK_BOX (vbox), area->priv->label, TRUE, TRUE, 0);
96 gtk_widget_show (area->priv->label);
98 area->priv->progress_bar = gtk_progress_bar_new ();
99 gtk_widget_set_size_request (area->priv->progress_bar, -1, 15);
100 gtk_box_pack_start (GTK_BOX (vbox), area->priv->progress_bar, TRUE, FALSE, 0);
101 gtk_widget_show (area->priv->progress_bar);
103 gtk_box_pack_start (GTK_BOX (contents), vbox, TRUE, TRUE, 0);
104 gtk_widget_show (vbox);
108 ev_progress_message_area_set_property (GObject *object,
113 EvProgressMessageArea *area = EV_PROGRESS_MESSAGE_AREA (object);
117 ev_progress_message_area_set_status (area, g_value_get_string (value));
120 ev_progress_message_area_set_fraction (area, g_value_get_double (value));
123 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
128 ev_progress_message_area_get_property (GObject *object,
133 EvProgressMessageArea *area = EV_PROGRESS_MESSAGE_AREA (object);
137 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (area->priv->label)));
139 case PROP_FRACTION: {
142 fraction = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (area->priv->progress_bar));
143 g_value_set_double (value, fraction);
147 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
152 ev_progress_message_area_new (const gchar *stock_id,
154 const gchar *first_button_text,
159 widget = g_object_new (EV_TYPE_PROGRESS_MESSAGE_AREA,
160 "message-type", GTK_MESSAGE_OTHER,
163 if (first_button_text) {
166 va_start (args, first_button_text);
167 _ev_message_area_add_buttons_valist (EV_MESSAGE_AREA (widget),
173 ev_message_area_set_image_from_stock (EV_MESSAGE_AREA (widget), stock_id);
179 ev_progress_message_area_set_status (EvProgressMessageArea *area,
182 g_return_if_fail (EV_IS_PROGRESS_MESSAGE_AREA (area));
184 gtk_label_set_text (GTK_LABEL (area->priv->label), str);
186 g_object_notify (G_OBJECT (area), "status");
190 ev_progress_message_area_set_fraction (EvProgressMessageArea *area,
193 g_return_if_fail (EV_IS_PROGRESS_MESSAGE_AREA (area));
195 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (area->priv->progress_bar),
197 g_object_notify (G_OBJECT (area), "fraction");