]> www.fi.muni.cz Git - evince.git/blob - shell/ev-progress-message-area.c
[dualscreen] fix crash on ctrl+w and fix control window closing
[evince.git] / shell / ev-progress-message-area.c
1 /* ev-progress-message-area.c
2  *  this file is part of evince, a gnome document viewer
3  *
4  * Copyright (C) 2008 Carlos Garcia Campos <carlosgc@gnome.org>
5  *
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.
10  *
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.
15  *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20
21 #include <config.h>
22
23 #include <gtk/gtk.h>
24
25 #include "ev-progress-message-area.h"
26
27 #define EV_PROGRESS_MESSAGE_AREA_GET_PRIVATE(obj) \
28         (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EV_TYPE_PROGRESS_MESSAGE_AREA, EvProgressMessageAreaPrivate))
29
30 struct _EvProgressMessageAreaPrivate {
31         GtkWidget *label;
32         GtkWidget *progress_bar;
33 };
34
35 enum {
36         PROP_0,
37         PROP_STATUS,
38         PROP_FRACTION
39 };
40
41 static void ev_progress_message_area_set_property (GObject      *object,
42                                                    guint         prop_id,
43                                                    const GValue *value,
44                                                    GParamSpec   *pspec);
45 static void ev_progress_message_area_get_property (GObject      *object,
46                                                    guint         prop_id,
47                                                    GValue       *value,
48                                                    GParamSpec   *pspec);
49
50 G_DEFINE_TYPE (EvProgressMessageArea, ev_progress_message_area, EV_TYPE_MESSAGE_AREA)
51
52 static void
53 ev_progress_message_area_class_init (EvProgressMessageAreaClass *class)
54 {
55         GObjectClass *gobject_class = G_OBJECT_CLASS (class);
56
57         gobject_class->set_property = ev_progress_message_area_set_property;
58         gobject_class->get_property = ev_progress_message_area_get_property;
59
60         g_object_class_install_property (gobject_class,
61                                          PROP_STATUS,
62                                          g_param_spec_string ("status",
63                                                               "Status",
64                                                               "The status text of the progress area",
65                                                               NULL,
66                                                               G_PARAM_READWRITE));
67         g_object_class_install_property (gobject_class,
68                                          PROP_FRACTION,
69                                          g_param_spec_double ("fraction",
70                                                               "Fraction",
71                                                               "The fraction of total work that has been completed",
72                                                               0.0, 1.0, 0.0,
73                                                               G_PARAM_READWRITE));
74
75         g_type_class_add_private (gobject_class, sizeof (EvProgressMessageAreaPrivate));
76 }
77
78 static void
79 ev_progress_message_area_init (EvProgressMessageArea *area)
80 {
81         GtkWidget *contents;
82         GtkWidget *vbox;
83         
84         area->priv = EV_PROGRESS_MESSAGE_AREA_GET_PRIVATE (area);
85
86         contents = _ev_message_area_get_main_box (EV_MESSAGE_AREA (area));
87         
88         vbox = gtk_vbox_new (FALSE, 6);
89         
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),
93                                  PANGO_ELLIPSIZE_END);
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);
97
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);
102
103         gtk_box_pack_start (GTK_BOX (contents), vbox, TRUE, TRUE, 0);
104         gtk_widget_show (vbox);
105 }
106
107 static void
108 ev_progress_message_area_set_property (GObject      *object,
109                                        guint         prop_id,
110                                        const GValue *value,
111                                        GParamSpec   *pspec)
112 {
113         EvProgressMessageArea *area = EV_PROGRESS_MESSAGE_AREA (object);
114
115         switch (prop_id) {
116         case PROP_STATUS:
117                 ev_progress_message_area_set_status (area, g_value_get_string (value));
118                 break;
119         case PROP_FRACTION:
120                 ev_progress_message_area_set_fraction (area, g_value_get_double (value));
121                 break;
122         default:
123                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
124         }
125 }
126
127 static void
128 ev_progress_message_area_get_property (GObject    *object,
129                                        guint       prop_id,
130                                        GValue     *value,
131                                        GParamSpec *pspec)
132 {
133         EvProgressMessageArea *area = EV_PROGRESS_MESSAGE_AREA (object);
134
135         switch (prop_id) {
136         case PROP_STATUS:
137                 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (area->priv->label)));
138                 break;
139         case PROP_FRACTION: {
140                 gdouble fraction;
141
142                 fraction = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (area->priv->progress_bar));
143                 g_value_set_double (value, fraction);
144         }
145                 break;
146         default:
147                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
148         }
149 }
150
151 GtkWidget *
152 ev_progress_message_area_new (const gchar *stock_id,
153                               const gchar *text,
154                               const gchar *first_button_text,
155                               ...)
156 {
157         GtkWidget *widget;
158
159         widget = g_object_new (EV_TYPE_PROGRESS_MESSAGE_AREA,
160                                "message-type", GTK_MESSAGE_OTHER,
161                                "text", text,
162                                NULL);
163         if (first_button_text) {
164                 va_list args;
165
166                 va_start (args, first_button_text);
167                 _ev_message_area_add_buttons_valist (EV_MESSAGE_AREA (widget),
168                                                      first_button_text,
169                                                      args);
170                 va_end (args);
171         }
172
173         ev_message_area_set_image_from_stock (EV_MESSAGE_AREA (widget), stock_id);
174
175         return widget;
176 }
177
178 void
179 ev_progress_message_area_set_status (EvProgressMessageArea *area,
180                                      const gchar           *str)
181 {
182         g_return_if_fail (EV_IS_PROGRESS_MESSAGE_AREA (area));
183
184         gtk_label_set_text (GTK_LABEL (area->priv->label), str);
185
186         g_object_notify (G_OBJECT (area), "status");
187 }
188
189 void
190 ev_progress_message_area_set_fraction (EvProgressMessageArea *area,
191                                        gdouble                fraction)
192 {
193         g_return_if_fail (EV_IS_PROGRESS_MESSAGE_AREA (area));
194         
195         gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (area->priv->progress_bar),
196                                        fraction);
197         g_object_notify (G_OBJECT (area), "fraction");
198 }