2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2022 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/>.
21 #include "claws-features.h"
25 #include <glib/gi18n.h>
29 #include "mainwindow.h"
30 #include "statusbar.h"
38 static GList
*statusbar_list
= NULL
;
39 static gulong statusbar_puts_all_hook_id
= HOOK_NONE
;
41 GtkWidget
*statusbar_create(void)
48 statusbar
= gtk_statusbar_new();
50 gtk_widget_set_margin_top(GTK_WIDGET(statusbar
), 0);
51 gtk_widget_set_margin_bottom(GTK_WIDGET(statusbar
), 0);
52 statusbar_list
= g_list_append(statusbar_list
, statusbar
);
53 gtk_container_set_border_width(GTK_CONTAINER(statusbar
), 1);
54 child
= gtk_statusbar_get_message_area(GTK_STATUSBAR(statusbar
));
55 gtk_widget_set_margin_top(GTK_WIDGET(child
), 0);
56 gtk_widget_set_margin_bottom(GTK_WIDGET(child
), 0);
57 gtk_widget_set_margin_start(GTK_WIDGET(child
), 0);
58 gtk_widget_set_margin_end(GTK_WIDGET(child
), 0);
59 parent
= gtk_widget_get_parent(child
);
60 gtk_container_remove(GTK_CONTAINER(parent
), g_object_ref(child
));
61 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 0);
62 gtk_container_add(GTK_CONTAINER(parent
), hbox
);
63 gtk_widget_show(hbox
);
64 gtk_box_pack_start(GTK_BOX(hbox
), child
, TRUE
, TRUE
, 0);
65 g_object_unref(child
);
70 void statusbar_puts(GtkStatusbar
*statusbar
, const gchar
*str
)
78 buf
= trim_string(tmp
, 76);
81 cid
= gtk_statusbar_get_context_id(statusbar
, "Standard Output");
82 gtk_statusbar_pop(statusbar
, cid
);
83 gtk_statusbar_push(statusbar
, cid
, buf
);
88 void statusbar_puts_all(const gchar
*str
)
92 for (cur
= statusbar_list
; cur
!= NULL
; cur
= cur
->next
)
93 statusbar_puts(GTK_STATUSBAR(cur
->data
), str
);
96 void statusbar_print_all(const gchar
*format
, ...)
102 va_start(args
, format
);
103 g_vsnprintf(buf
, sizeof(buf
), format
, args
);
106 for (cur
= statusbar_list
; cur
!= NULL
; cur
= cur
->next
)
107 statusbar_puts(GTK_STATUSBAR(cur
->data
), buf
);
110 void statusbar_pop_all(void)
115 for (cur
= statusbar_list
; cur
!= NULL
; cur
= cur
->next
) {
116 cid
= gtk_statusbar_get_context_id(GTK_STATUSBAR(cur
->data
),
118 gtk_statusbar_pop(GTK_STATUSBAR(cur
->data
), cid
);
122 static gboolean
statusbar_puts_all_hook (gpointer source
, gpointer data
)
124 LogText
*logtext
= (LogText
*) source
;
126 cm_return_val_if_fail(logtext
!= NULL
, TRUE
);
127 cm_return_val_if_fail(logtext
->text
!= NULL
, TRUE
);
130 if (logtext
->type
== LOG_NORMAL
) {
131 statusbar_puts_all(logtext
->text
+ LOG_TIME_LEN
);
132 } else if (logtext
->type
== LOG_MSG
) {
133 statusbar_puts_all(logtext
->text
);
139 void statusbar_verbosity_set(gboolean verbose
)
141 if (verbose
&& (statusbar_puts_all_hook_id
== HOOK_NONE
)) {
142 statusbar_puts_all_hook_id
=
143 hooks_register_hook(LOG_APPEND_TEXT_HOOKLIST
, statusbar_puts_all_hook
, NULL
);
144 } else if (!verbose
&& (statusbar_puts_all_hook_id
!= HOOK_NONE
)) {
145 hooks_unregister_hook(LOG_APPEND_TEXT_HOOKLIST
, statusbar_puts_all_hook_id
);
146 statusbar_puts_all_hook_id
= HOOK_NONE
;
151 void statusbar_progress_all (gint done
, gint total
, gint step
)
153 GtkProgressBar
*progressbar
= GTK_PROGRESS_BAR(
154 mainwindow_get_mainwindow()->progressbar
);
157 if (total
&& done
% step
== 0) {
159 /* use a more compact format */
160 const gchar
*format
= "%d/%d";
162 const gchar
*format
= "%d / %d";
164 g_snprintf(buf
, sizeof(buf
), format
, done
, total
);
165 gtk_progress_bar_set_show_text(progressbar
, TRUE
);
166 gtk_progress_bar_set_text(progressbar
, buf
);
167 gtk_progress_bar_set_fraction(progressbar
,
168 (gfloat
)done
/ (gfloat
)total
);
169 if (!gtk_widget_get_visible(GTK_WIDGET(progressbar
)))
170 gtk_widget_show(GTK_WIDGET(progressbar
));
171 } else if (total
== 0) {
172 gtk_progress_bar_set_text(progressbar
, "");
173 gtk_progress_bar_set_fraction(progressbar
, 0.0);
174 gtk_widget_hide(GTK_WIDGET(progressbar
));