Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-progress-message-area.c
Go to the documentation of this file.
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 
26 
27 #define EV_PROGRESS_MESSAGE_AREA_GET_PRIVATE(obj) \
28  (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EV_TYPE_PROGRESS_MESSAGE_AREA, EvProgressMessageAreaPrivate))
29 
31  GtkWidget *label;
32  GtkWidget *progress_bar;
33 };
34 
35 enum {
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
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,
62  g_param_spec_string ("status",
63  "Status",
64  "The status text of the progress area",
65  NULL,
66  G_PARAM_READWRITE |
67  G_PARAM_STATIC_STRINGS));
68  g_object_class_install_property (gobject_class,
70  g_param_spec_double ("fraction",
71  "Fraction",
72  "The fraction of total work that has been completed",
73  0.0, 1.0, 0.0,
74  G_PARAM_READWRITE |
75  G_PARAM_STATIC_STRINGS));
76 
77  g_type_class_add_private (gobject_class, sizeof (EvProgressMessageAreaPrivate));
78 }
79 
80 static void
82 {
83  GtkWidget *contents;
84  GtkWidget *vbox;
85 
87 
89 
90  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
91 
92  area->priv->label = gtk_label_new (NULL);
93  gtk_label_set_use_markup (GTK_LABEL (area->priv->label), TRUE);
94  gtk_label_set_ellipsize (GTK_LABEL (area->priv->label),
95  PANGO_ELLIPSIZE_END);
96  gtk_misc_set_alignment (GTK_MISC (area->priv->label), 0.0, 0.5);
97  gtk_box_pack_start (GTK_BOX (vbox), area->priv->label, TRUE, TRUE, 0);
98  gtk_widget_show (area->priv->label);
99 
100  area->priv->progress_bar = gtk_progress_bar_new ();
101  gtk_widget_set_size_request (area->priv->progress_bar, -1, 15);
102  gtk_box_pack_start (GTK_BOX (vbox), area->priv->progress_bar, TRUE, FALSE, 0);
103  gtk_widget_show (area->priv->progress_bar);
104 
105  gtk_box_pack_start (GTK_BOX (contents), vbox, TRUE, TRUE, 0);
106  gtk_widget_show (vbox);
107 }
108 
109 static void
111  guint prop_id,
112  const GValue *value,
113  GParamSpec *pspec)
114 {
116 
117  switch (prop_id) {
118  case PROP_STATUS:
119  ev_progress_message_area_set_status (area, g_value_get_string (value));
120  break;
121  case PROP_FRACTION:
122  ev_progress_message_area_set_fraction (area, g_value_get_double (value));
123  break;
124  default:
125  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
126  }
127 }
128 
129 static void
131  guint prop_id,
132  GValue *value,
133  GParamSpec *pspec)
134 {
136 
137  switch (prop_id) {
138  case PROP_STATUS:
139  g_value_set_string (value, gtk_label_get_label (GTK_LABEL (area->priv->label)));
140  break;
141  case PROP_FRACTION: {
142  gdouble fraction;
143 
144  fraction = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (area->priv->progress_bar));
145  g_value_set_double (value, fraction);
146  }
147  break;
148  default:
149  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
150  }
151 }
152 
153 GtkWidget *
154 ev_progress_message_area_new (const gchar *stock_id,
155  const gchar *text,
156  const gchar *first_button_text,
157  ...)
158 {
159  GtkWidget *widget;
160 
161  widget = g_object_new (EV_TYPE_PROGRESS_MESSAGE_AREA,
162  "message-type", GTK_MESSAGE_OTHER,
163  "text", text,
164  NULL);
165  if (first_button_text) {
166  va_list args;
167 
168  va_start (args, first_button_text);
170  first_button_text,
171  args);
172  va_end (args);
173  }
174 
176 
177  return widget;
178 }
179 
180 void
182  const gchar *str)
183 {
184  g_return_if_fail (EV_IS_PROGRESS_MESSAGE_AREA (area));
185 
186  gtk_label_set_text (GTK_LABEL (area->priv->label), str);
187 
188  g_object_notify (G_OBJECT (area), "status");
189 }
190 
191 void
193  gdouble fraction)
194 {
195  g_return_if_fail (EV_IS_PROGRESS_MESSAGE_AREA (area));
196 
197  gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (area->priv->progress_bar),
198  fraction);
199  g_object_notify (G_OBJECT (area), "fraction");
200 }