2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include <glib/gi18n.h>
26 #include <gtk/gtkstatusbar.h>
27 #include <gtk/gtkprogressbar.h>
30 #include "mainwindow.h"
31 #include "statusbar.h"
38 #include <hildon-widgets/hildon-banner.h>
44 static GList *statusbar_list = NULL;
45 gint statusbar_puts_all_hook_id = -1;
47 GtkWidget *statusbar_create(void)
51 statusbar = gtk_statusbar_new();
52 gtk_widget_set_size_request(statusbar, 1, -1);
53 statusbar_list = g_list_append(statusbar_list, statusbar);
54 gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(statusbar),
56 gtk_container_set_border_width(GTK_CONTAINER(statusbar), 1);
58 gtk_widget_ref(GTK_STATUSBAR(statusbar)->label);
59 gtk_container_remove(GTK_CONTAINER(GTK_STATUSBAR(statusbar)->frame),
60 GTK_STATUSBAR(statusbar)->label);
61 gtk_widget_hide(GTK_STATUSBAR(statusbar)->frame);
62 gtk_box_pack_start (GTK_BOX(statusbar), GTK_STATUSBAR(statusbar)->label,
64 gtk_widget_unref(GTK_STATUSBAR(statusbar)->label);
65 gtk_container_remove(GTK_CONTAINER(statusbar),
66 GTK_STATUSBAR(statusbar)->frame);
67 GTK_STATUSBAR(statusbar)->frame = gtk_frame_new(NULL);
72 void statusbar_puts(GtkStatusbar *statusbar, const gchar *str)
80 buf = trim_string(tmp, 76);
83 cid = gtk_statusbar_get_context_id(statusbar, "Standard Output");
84 gtk_statusbar_pop(statusbar, cid);
85 gtk_statusbar_push(statusbar, cid, buf);
86 gtkut_widget_draw_now(GTK_WIDGET(statusbar));
91 void statusbar_puts_all(const gchar *str)
95 for (cur = statusbar_list; cur != NULL; cur = cur->next)
96 statusbar_puts(GTK_STATUSBAR(cur->data), str);
99 void statusbar_print(GtkStatusbar *statusbar, const gchar *format, ...)
104 va_start(args, format);
105 g_vsnprintf(buf, sizeof(buf), format, args);
108 statusbar_puts(statusbar, buf);
112 static GSList *banner_texts = NULL;
113 static GtkWidget *banner = NULL;
114 void statuswindow_print_all(const gchar *format, ...)
120 va_start(args, format);
121 g_vsnprintf(buf, sizeof(buf), format, args);
124 for (cur = statusbar_list; cur != NULL; cur = cur->next)
125 statusbar_puts(GTK_STATUSBAR(cur->data), buf);
126 if (mainwindow_get_mainwindow()) {
127 if (banner != NULL) {
128 gchar *last_text = (gchar *)banner_texts->data;
129 if (!strcmp2(last_text, buf))
133 if (banner == NULL) {
134 banner = hildon_banner_show_animation(
135 mainwindow_get_mainwindow()->window,
138 g_object_ref(banner);
139 banner_texts = g_slist_prepend(banner_texts, g_strdup(buf));
141 hildon_banner_set_text(HILDON_BANNER(banner), buf);
142 banner_texts = g_slist_prepend(banner_texts, g_strdup(buf));
147 void statuswindow_pop_all(void)
152 for (cur = statusbar_list; cur != NULL; cur = cur->next) {
153 cid = gtk_statusbar_get_context_id(GTK_STATUSBAR(cur->data),
155 gtk_statusbar_pop(GTK_STATUSBAR(cur->data), cid);
157 if (banner && banner_texts) {
158 gchar *old_text = (gchar *)banner_texts->data;
159 gchar *prev_text = NULL;
160 banner_texts = g_slist_remove(banner_texts, old_text);
163 prev_text = (gchar *)banner_texts->data;
164 hildon_banner_set_text(HILDON_BANNER(banner), prev_text);
166 gtk_widget_destroy(banner);
167 g_object_unref(banner);
174 void statusbar_print_all(const gchar *format, ...)
180 va_start(args, format);
181 g_vsnprintf(buf, sizeof(buf), format, args);
184 for (cur = statusbar_list; cur != NULL; cur = cur->next)
185 statusbar_puts(GTK_STATUSBAR(cur->data), buf);
188 void statusbar_pop_all(void)
193 for (cur = statusbar_list; cur != NULL; cur = cur->next) {
194 cid = gtk_statusbar_get_context_id(GTK_STATUSBAR(cur->data),
196 gtk_statusbar_pop(GTK_STATUSBAR(cur->data), cid);
200 static gboolean statusbar_puts_all_hook (gpointer source, gpointer data)
202 LogText *logtext = (LogText *) source;
204 g_return_val_if_fail(logtext != NULL, TRUE);
205 g_return_val_if_fail(logtext->text != NULL, TRUE);
208 if (logtext->type == LOG_NORMAL) {
209 statusbar_puts_all(logtext->text + LOG_TIME_LEN);
210 } else if (logtext->type == LOG_MSG) {
211 statusbar_puts_all(logtext->text);
217 void statusbar_verbosity_set(gboolean verbose)
219 if (verbose && (statusbar_puts_all_hook_id == -1)) {
220 statusbar_puts_all_hook_id =
221 hooks_register_hook(LOG_APPEND_TEXT_HOOKLIST, statusbar_puts_all_hook, NULL);
222 } else if (!verbose && (statusbar_puts_all_hook_id != -1)) {
223 hooks_unregister_hook(LOG_APPEND_TEXT_HOOKLIST, statusbar_puts_all_hook_id);
224 statusbar_puts_all_hook_id = -1;
229 void statusbar_progress_all (gint done, gint total, gint step)
232 if (total && done % step == 0) {
233 g_snprintf(buf, sizeof(buf), "%d / %d", done, total);
234 gtk_progress_bar_set_text
235 (GTK_PROGRESS_BAR(mainwindow_get_mainwindow()->progressbar), buf);
236 gtk_progress_bar_set_fraction
237 (GTK_PROGRESS_BAR(mainwindow_get_mainwindow()->progressbar),
238 (total == 0) ? 0 : (gfloat)done / (gfloat)total);
239 } else if (total == 0) {
240 gtk_progress_bar_set_text
241 (GTK_PROGRESS_BAR(mainwindow_get_mainwindow()->progressbar), "");
242 gtk_progress_bar_set_fraction
243 (GTK_PROGRESS_BAR(mainwindow_get_mainwindow()->progressbar), 0.0);