1 /* Eye of Gnome - Statusbar
2  *
3  * Copyright (C) 2000-2006 The Free Software Foundation
4  *
5  * Author: Federico Mena-Quintero <federico@gnome.org>
6  *	   Jens Finke <jens@gnome.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21  */
22 
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 
27 #include "eog-statusbar.h"
28 
29 #include <string.h>
30 #include <glib/gi18n.h>
31 #include <gtk/gtk.h>
32 
33 struct _EogStatusbarPrivate
34 {
35 	GtkWidget *progressbar;
36 	GtkWidget *img_num_label;
37 };
38 
G_DEFINE_TYPE_WITH_PRIVATE(EogStatusbar,eog_statusbar,GTK_TYPE_STATUSBAR)39 G_DEFINE_TYPE_WITH_PRIVATE (EogStatusbar, eog_statusbar, GTK_TYPE_STATUSBAR)
40 
41 static void
42 eog_statusbar_class_init (EogStatusbarClass *klass)
43 {
44     /* empty */
45 }
46 
47 static void
eog_statusbar_init(EogStatusbar * statusbar)48 eog_statusbar_init (EogStatusbar *statusbar)
49 {
50 	EogStatusbarPrivate *priv;
51 	GtkWidget *vbox;
52 
53 	g_object_set (statusbar, "margin", 0, NULL);
54 
55 	statusbar->priv = eog_statusbar_get_instance_private (statusbar);
56 	priv = statusbar->priv;
57 
58 	priv->img_num_label = gtk_label_new (NULL);
59 	gtk_widget_show (priv->img_num_label);
60 
61 	gtk_box_pack_end (GTK_BOX (statusbar),
62 			  priv->img_num_label,
63 			  FALSE,
64 			  TRUE,
65 			  6);
66 
67 	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
68 
69 	gtk_box_pack_end (GTK_BOX (statusbar),
70 			  vbox,
71 			  FALSE,
72 			  FALSE,
73 			  6);
74 
75 	statusbar->priv->progressbar = gtk_progress_bar_new ();
76 
77 	gtk_box_pack_end (GTK_BOX (vbox),
78 			  priv->progressbar,
79 			  TRUE,
80 			  FALSE,
81 			  0);
82 
83 	gtk_widget_show (vbox);
84 
85 	gtk_widget_hide (statusbar->priv->progressbar);
86 
87 }
88 
89 GtkWidget *
eog_statusbar_new(void)90 eog_statusbar_new (void)
91 {
92 	return GTK_WIDGET (g_object_new (EOG_TYPE_STATUSBAR, NULL));
93 }
94 
95 void
eog_statusbar_set_image_number(EogStatusbar * statusbar,gint num,gint tot)96 eog_statusbar_set_image_number (EogStatusbar *statusbar,
97                                 gint          num,
98 				gint          tot)
99 {
100 	gchar *msg;
101 
102 	g_return_if_fail (EOG_IS_STATUSBAR (statusbar));
103 
104 	/* Hide number display if values don't make sense */
105 	if (G_UNLIKELY (num <= 0 || tot <= 0))
106 		return;
107 
108 	/* Translators: This string is displayed in the statusbar.
109 	 * The first token is the image number, the second is total image
110 	 * count.
111 	 *
112 	 * Translate to "%Id" if you want to use localized digits, or
113 	 * translate to "%d" otherwise.
114 	 *
115 	 * Note that translating this doesn't guarantee that you get localized
116 	 * digits. That needs support from your system and locale definition
117 	 * too.*/
118 	msg = g_strdup_printf (_("%d / %d"), num, tot);
119 
120 	gtk_label_set_text (GTK_LABEL (statusbar->priv->img_num_label), msg);
121 
122       	g_free (msg);
123 }
124 
125 void
eog_statusbar_set_progress(EogStatusbar * statusbar,gdouble progress)126 eog_statusbar_set_progress (EogStatusbar *statusbar,
127 			    gdouble       progress)
128 {
129 	g_return_if_fail (EOG_IS_STATUSBAR (statusbar));
130 
131 	gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (statusbar->priv->progressbar),
132 				       progress);
133 
134 	if (progress > 0 && progress < 1) {
135 		gtk_widget_show (statusbar->priv->progressbar);
136 		gtk_widget_hide (statusbar->priv->img_num_label);
137 	} else {
138 		gtk_widget_hide (statusbar->priv->progressbar);
139 		gtk_widget_show (statusbar->priv->img_num_label);
140 	}
141 }
142