2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws 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 2 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, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include <glib/gi18n.h>
26 #include <gtk/gtkstatusbar.h>
27 #include <gtk/gtkprogressbar.h>
30 #include "mainwindow.h"
31 #include "statusbar.h"
39 static GList *statusbar_list = NULL;
40 gint statusbar_puts_all_hook_id = -1;
42 GtkWidget *statusbar_create(void)
46 statusbar = gtk_statusbar_new();
47 gtk_widget_set_size_request(statusbar, 1, -1);
48 statusbar_list = g_list_append(statusbar_list, statusbar);
49 gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(statusbar),
55 void statusbar_puts(GtkStatusbar *statusbar, const gchar *str)
63 buf = trim_string(tmp, 76);
66 cid = gtk_statusbar_get_context_id(statusbar, "Standard Output");
67 gtk_statusbar_pop(statusbar, cid);
68 gtk_statusbar_push(statusbar, cid, buf);
69 gtkut_widget_draw_now(GTK_WIDGET(statusbar));
74 void statusbar_puts_all(const gchar *str)
78 for (cur = statusbar_list; cur != NULL; cur = cur->next)
79 statusbar_puts(GTK_STATUSBAR(cur->data), str);
82 void statusbar_print(GtkStatusbar *statusbar, const gchar *format, ...)
87 va_start(args, format);
88 g_vsnprintf(buf, sizeof(buf), format, args);
91 statusbar_puts(statusbar, buf);
94 void statusbar_print_all(const gchar *format, ...)
100 va_start(args, format);
101 g_vsnprintf(buf, sizeof(buf), format, args);
104 for (cur = statusbar_list; cur != NULL; cur = cur->next)
105 statusbar_puts(GTK_STATUSBAR(cur->data), buf);
108 void statusbar_pop_all(void)
113 for (cur = statusbar_list; cur != NULL; cur = cur->next) {
114 cid = gtk_statusbar_get_context_id(GTK_STATUSBAR(cur->data),
116 gtk_statusbar_pop(GTK_STATUSBAR(cur->data), cid);
120 gboolean statusbar_puts_all_hook (gpointer source, gpointer data)
122 LogText *logtext = (LogText *) source;
124 g_return_val_if_fail(logtext != NULL, TRUE);
125 g_return_val_if_fail(logtext->text != NULL, TRUE);
128 if (logtext->type == LOG_NORMAL) {
129 statusbar_puts_all(logtext->text + LOG_TIME_LEN);
130 } else if (logtext->type == LOG_MSG) {
131 statusbar_puts_all(logtext->text);
137 void statusbar_verbosity_set(gboolean verbose)
139 if (verbose && (statusbar_puts_all_hook_id == -1)) {
140 statusbar_puts_all_hook_id =
141 hooks_register_hook(LOG_APPEND_TEXT_HOOKLIST, statusbar_puts_all_hook, NULL);
142 } else if (!verbose && (statusbar_puts_all_hook_id != -1)) {
143 hooks_unregister_hook(LOG_APPEND_TEXT_HOOKLIST, statusbar_puts_all_hook_id);
144 statusbar_puts_all_hook_id = -1;
149 void statusbar_progress_all (gint done, gint total, gint step)
152 g_snprintf(buf, sizeof(buf), "%d / %d", done, total);
153 if (total && done % step == 0) {
154 gtk_progress_bar_set_text
155 (GTK_PROGRESS_BAR(mainwindow_get_mainwindow()->progressbar), buf);
156 gtk_progress_bar_set_fraction
157 (GTK_PROGRESS_BAR(mainwindow_get_mainwindow()->progressbar),
158 (gfloat)done / (gfloat)total);
159 } else if (total == 0) {
160 gtk_progress_bar_set_text
161 (GTK_PROGRESS_BAR(mainwindow_get_mainwindow()->progressbar), "");
162 gtk_progress_bar_set_fraction
163 (GTK_PROGRESS_BAR(mainwindow_get_mainwindow()->progressbar), 0.0);