2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2021 the Claws Mail team and Hiroyuki Yamamoto
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/>.
22 #include "claws-features.h"
26 #include <glib/gi18n.h>
30 #include "mainwindow.h"
31 #include "statusbar.h"
39 static GList
*statusbar_list
= NULL
;
40 static gulong statusbar_puts_all_hook_id
= HOOK_NONE
;
42 GtkWidget
*statusbar_create(void)
49 statusbar
= gtk_statusbar_new();
51 gtk_widget_set_margin_top(GTK_WIDGET(statusbar
), 0);
52 gtk_widget_set_margin_bottom(GTK_WIDGET(statusbar
), 0);
53 statusbar_list
= g_list_append(statusbar_list
, statusbar
);
54 gtk_container_set_border_width(GTK_CONTAINER(statusbar
), 1);
55 child
= gtk_statusbar_get_message_area(GTK_STATUSBAR(statusbar
));
56 gtk_widget_set_margin_top(GTK_WIDGET(child
), 0);
57 gtk_widget_set_margin_bottom(GTK_WIDGET(child
), 0);
58 gtk_widget_set_margin_start(GTK_WIDGET(child
), 0);
59 gtk_widget_set_margin_end(GTK_WIDGET(child
), 0);
60 parent
= gtk_widget_get_parent(child
);
61 gtk_container_remove(GTK_CONTAINER(parent
), g_object_ref(child
));
62 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 0);
63 gtk_container_add(GTK_CONTAINER(parent
), hbox
);
64 gtk_widget_show(hbox
);
65 gtk_box_pack_start(GTK_BOX(hbox
), child
, TRUE
, TRUE
, 0);
66 g_object_unref(child
);
71 void statusbar_puts(GtkStatusbar
*statusbar
, const gchar
*str
)
79 buf
= trim_string(tmp
, 76);
82 cid
= gtk_statusbar_get_context_id(statusbar
, "Standard Output");
83 gtk_statusbar_pop(statusbar
, cid
);
84 gtk_statusbar_push(statusbar
, cid
, buf
);
89 void statusbar_puts_all(const gchar
*str
)
93 for (cur
= statusbar_list
; cur
!= NULL
; cur
= cur
->next
)
94 statusbar_puts(GTK_STATUSBAR(cur
->data
), str
);
97 void statusbar_print(GtkStatusbar
*statusbar
, const gchar
*format
, ...)
102 va_start(args
, format
);
103 g_vsnprintf(buf
, sizeof(buf
), format
, args
);
106 statusbar_puts(statusbar
, buf
);
109 void statusbar_print_all(const gchar
*format
, ...)
115 va_start(args
, format
);
116 g_vsnprintf(buf
, sizeof(buf
), format
, args
);
119 for (cur
= statusbar_list
; cur
!= NULL
; cur
= cur
->next
)
120 statusbar_puts(GTK_STATUSBAR(cur
->data
), buf
);
123 void statusbar_pop_all(void)
128 for (cur
= statusbar_list
; cur
!= NULL
; cur
= cur
->next
) {
129 cid
= gtk_statusbar_get_context_id(GTK_STATUSBAR(cur
->data
),
131 gtk_statusbar_pop(GTK_STATUSBAR(cur
->data
), cid
);
135 static gboolean
statusbar_puts_all_hook (gpointer source
, gpointer data
)
137 LogText
*logtext
= (LogText
*) source
;
139 cm_return_val_if_fail(logtext
!= NULL
, TRUE
);
140 cm_return_val_if_fail(logtext
->text
!= NULL
, TRUE
);
143 if (logtext
->type
== LOG_NORMAL
) {
144 statusbar_puts_all(logtext
->text
+ LOG_TIME_LEN
);
145 } else if (logtext
->type
== LOG_MSG
) {
146 statusbar_puts_all(logtext
->text
);
152 void statusbar_verbosity_set(gboolean verbose
)
154 if (verbose
&& (statusbar_puts_all_hook_id
== HOOK_NONE
)) {
155 statusbar_puts_all_hook_id
=
156 hooks_register_hook(LOG_APPEND_TEXT_HOOKLIST
, statusbar_puts_all_hook
, NULL
);
157 } else if (!verbose
&& (statusbar_puts_all_hook_id
!= HOOK_NONE
)) {
158 hooks_unregister_hook(LOG_APPEND_TEXT_HOOKLIST
, statusbar_puts_all_hook_id
);
159 statusbar_puts_all_hook_id
= HOOK_NONE
;
164 void statusbar_progress_all (gint done
, gint total
, gint step
)
166 GtkProgressBar
*progressbar
= GTK_PROGRESS_BAR(
167 mainwindow_get_mainwindow()->progressbar
);
170 if (total
&& done
% step
== 0) {
172 /* use a more compact format */
173 const gchar
*format
= "%d/%d";
175 const gchar
*format
= "%d / %d";
177 g_snprintf(buf
, sizeof(buf
), format
, done
, total
);
178 gtk_progress_bar_set_show_text(progressbar
, TRUE
);
179 gtk_progress_bar_set_text(progressbar
, buf
);
180 gtk_progress_bar_set_fraction(progressbar
,
181 (gfloat
)done
/ (gfloat
)total
);
182 if (!gtk_widget_get_visible(GTK_WIDGET(progressbar
)))
183 gtk_widget_show(GTK_WIDGET(progressbar
));
184 } else if (total
== 0) {
185 gtk_progress_bar_set_text(progressbar
, "");
186 gtk_progress_bar_set_fraction(progressbar
, 0.0);
187 gtk_widget_hide(GTK_WIDGET(progressbar
));