Improve some sieve-related translations
[claws.git] / src / statusbar.c
blob3179896e3ecb1bd7fd20326a3ef35e7bdc90ec95
1 /*
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/>.
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #include "claws-features.h"
23 #endif
25 #include <glib.h>
26 #include <glib/gi18n.h>
27 #include <gtk/gtk.h>
28 #include <stdarg.h>
30 #include "mainwindow.h"
31 #include "statusbar.h"
32 #include "gtkutils.h"
33 #include "utils.h"
34 #include "log.h"
35 #include "hooks.h"
37 #define BUFFSIZE 1024
39 static GList *statusbar_list = NULL;
40 static gulong statusbar_puts_all_hook_id = HOOK_NONE;
42 GtkWidget *statusbar_create(void)
44 GtkWidget *statusbar;
45 GtkWidget *child;
46 GtkWidget *parent;
47 GtkWidget *hbox;
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);
68 return statusbar;
71 void statusbar_puts(GtkStatusbar *statusbar, const gchar *str)
73 gint cid;
74 gchar *buf;
75 gchar *tmp;
77 tmp = g_strdup(str);
78 strretchomp(tmp);
79 buf = trim_string(tmp, 76);
80 g_free(tmp);
82 cid = gtk_statusbar_get_context_id(statusbar, "Standard Output");
83 gtk_statusbar_pop(statusbar, cid);
84 gtk_statusbar_push(statusbar, cid, buf);
86 g_free(buf);
89 void statusbar_puts_all(const gchar *str)
91 GList *cur;
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, ...)
99 va_list args;
100 gchar buf[BUFFSIZE];
102 va_start(args, format);
103 g_vsnprintf(buf, sizeof(buf), format, args);
104 va_end(args);
106 statusbar_puts(statusbar, buf);
109 void statusbar_print_all(const gchar *format, ...)
111 va_list args;
112 gchar buf[BUFFSIZE];
113 GList *cur;
115 va_start(args, format);
116 g_vsnprintf(buf, sizeof(buf), format, args);
117 va_end(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)
125 GList *cur;
126 gint cid;
128 for (cur = statusbar_list; cur != NULL; cur = cur->next) {
129 cid = gtk_statusbar_get_context_id(GTK_STATUSBAR(cur->data),
130 "Standard Output");
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);
142 statusbar_pop_all();
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);
149 return FALSE;
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;
160 statusbar_pop_all();
164 void statusbar_progress_all (gint done, gint total, gint step)
166 GtkProgressBar *progressbar = GTK_PROGRESS_BAR(
167 mainwindow_get_mainwindow()->progressbar);
168 gchar buf[32];
170 if (total && done % step == 0) {
171 #ifdef GENERIC_UMPC
172 /* use a more compact format */
173 const gchar *format = "%d/%d";
174 #else
175 const gchar *format = "%d / %d";
176 #endif
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));