2001-04-19 14:21:46 +02:00
|
|
|
/*
|
|
|
|
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
|
2013-06-11 16:59:51 +02:00
|
|
|
* Copyright (C) 1999-2013 Hiroyuki Yamamoto and the Claws Mail team
|
2001-04-19 14:21:46 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-11 18:38:12 +02:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-04-19 14:21:46 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-07-11 18:38:12 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2001-04-19 14:21:46 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
2012-07-07 09:09:39 +02:00
|
|
|
#include "claws-features.h"
|
2001-04-19 14:21:46 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <glib.h>
|
2005-02-10 13:06:07 +01:00
|
|
|
#include <glib/gi18n.h>
|
2008-09-09 18:40:59 +02:00
|
|
|
#include <gtk/gtk.h>
|
2001-04-19 14:21:46 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2005-07-10 06:09:06 +02:00
|
|
|
#include "mainwindow.h"
|
2001-04-19 14:21:46 +02:00
|
|
|
#include "statusbar.h"
|
|
|
|
#include "gtkutils.h"
|
|
|
|
#include "utils.h"
|
2002-12-08 12:37:28 +01:00
|
|
|
#include "log.h"
|
|
|
|
#include "hooks.h"
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
#define BUFFSIZE 1024
|
|
|
|
|
|
|
|
static GList *statusbar_list = NULL;
|
2002-12-11 00:03:59 +01:00
|
|
|
gint statusbar_puts_all_hook_id = -1;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
GtkWidget *statusbar_create(void)
|
|
|
|
{
|
|
|
|
GtkWidget *statusbar;
|
2009-12-19 18:02:11 +01:00
|
|
|
GtkWidget *child;
|
|
|
|
GtkWidget *parent;
|
|
|
|
GtkWidget *hbox;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
statusbar = gtk_statusbar_new();
|
2005-02-01 09:58:33 +01:00
|
|
|
gtk_widget_set_size_request(statusbar, 1, -1);
|
2001-04-19 14:21:46 +02:00
|
|
|
statusbar_list = g_list_append(statusbar_list, statusbar);
|
2011-10-07 11:40:16 +02:00
|
|
|
#if !GTK_CHECK_VERSION(3, 0, 0)
|
2004-07-19 17:03:13 +02:00
|
|
|
gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(statusbar),
|
2011-10-07 11:40:16 +02:00
|
|
|
FALSE);
|
|
|
|
#endif
|
2006-08-31 19:27:03 +02:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(statusbar), 1);
|
2009-12-19 18:02:11 +01:00
|
|
|
child = gtk_statusbar_get_message_area(GTK_STATUSBAR(statusbar));
|
|
|
|
parent = gtk_widget_get_parent(child);
|
|
|
|
gtk_container_remove(GTK_CONTAINER(parent), g_object_ref(child));
|
|
|
|
hbox = gtk_hbox_new(FALSE, 0);
|
|
|
|
gtk_container_add(GTK_CONTAINER(parent), hbox);
|
|
|
|
gtk_widget_show(hbox);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), child, TRUE, TRUE, 0);
|
|
|
|
g_object_unref(child);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
return statusbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
void statusbar_puts(GtkStatusbar *statusbar, const gchar *str)
|
|
|
|
{
|
|
|
|
gint cid;
|
|
|
|
gchar *buf;
|
2005-02-01 09:58:33 +01:00
|
|
|
gchar *tmp;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2005-02-01 09:58:33 +01:00
|
|
|
tmp = g_strdup(str);
|
|
|
|
strretchomp(tmp);
|
|
|
|
buf = trim_string(tmp, 76);
|
|
|
|
g_free(tmp);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
cid = gtk_statusbar_get_context_id(statusbar, "Standard Output");
|
|
|
|
gtk_statusbar_pop(statusbar, cid);
|
|
|
|
gtk_statusbar_push(statusbar, cid, buf);
|
2005-04-21 08:49:55 +02:00
|
|
|
gtkut_widget_draw_now(GTK_WIDGET(statusbar));
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
g_free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void statusbar_puts_all(const gchar *str)
|
|
|
|
{
|
|
|
|
GList *cur;
|
|
|
|
|
|
|
|
for (cur = statusbar_list; cur != NULL; cur = cur->next)
|
|
|
|
statusbar_puts(GTK_STATUSBAR(cur->data), str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void statusbar_print(GtkStatusbar *statusbar, const gchar *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
gchar buf[BUFFSIZE];
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
g_vsnprintf(buf, sizeof(buf), format, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
statusbar_puts(statusbar, buf);
|
|
|
|
}
|
|
|
|
|
2007-09-16 08:30:16 +02:00
|
|
|
void statusbar_print_all(const gchar *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
gchar buf[BUFFSIZE];
|
|
|
|
GList *cur;
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
g_vsnprintf(buf, sizeof(buf), format, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
for (cur = statusbar_list; cur != NULL; cur = cur->next)
|
|
|
|
statusbar_puts(GTK_STATUSBAR(cur->data), buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void statusbar_pop_all(void)
|
|
|
|
{
|
|
|
|
GList *cur;
|
|
|
|
gint cid;
|
|
|
|
|
|
|
|
for (cur = statusbar_list; cur != NULL; cur = cur->next) {
|
|
|
|
cid = gtk_statusbar_get_context_id(GTK_STATUSBAR(cur->data),
|
|
|
|
"Standard Output");
|
|
|
|
gtk_statusbar_pop(GTK_STATUSBAR(cur->data), cid);
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
2002-12-11 00:03:59 +01:00
|
|
|
|
2007-01-20 20:54:05 +01:00
|
|
|
static gboolean statusbar_puts_all_hook (gpointer source, gpointer data)
|
2002-12-11 00:03:59 +01:00
|
|
|
{
|
|
|
|
LogText *logtext = (LogText *) source;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(logtext != NULL, TRUE);
|
|
|
|
cm_return_val_if_fail(logtext->text != NULL, TRUE);
|
2002-12-11 00:03:59 +01:00
|
|
|
|
|
|
|
statusbar_pop_all();
|
|
|
|
if (logtext->type == LOG_NORMAL) {
|
|
|
|
statusbar_puts_all(logtext->text + LOG_TIME_LEN);
|
|
|
|
} else if (logtext->type == LOG_MSG) {
|
|
|
|
statusbar_puts_all(logtext->text);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void statusbar_verbosity_set(gboolean verbose)
|
|
|
|
{
|
|
|
|
if (verbose && (statusbar_puts_all_hook_id == -1)) {
|
|
|
|
statusbar_puts_all_hook_id =
|
|
|
|
hooks_register_hook(LOG_APPEND_TEXT_HOOKLIST, statusbar_puts_all_hook, NULL);
|
|
|
|
} else if (!verbose && (statusbar_puts_all_hook_id != -1)) {
|
|
|
|
hooks_unregister_hook(LOG_APPEND_TEXT_HOOKLIST, statusbar_puts_all_hook_id);
|
|
|
|
statusbar_puts_all_hook_id = -1;
|
|
|
|
statusbar_pop_all();
|
|
|
|
}
|
|
|
|
}
|
2005-07-10 06:09:06 +02:00
|
|
|
|
|
|
|
void statusbar_progress_all (gint done, gint total, gint step)
|
|
|
|
{
|
2010-08-23 20:24:07 +02:00
|
|
|
GtkProgressBar *progressbar = GTK_PROGRESS_BAR(
|
|
|
|
mainwindow_get_mainwindow()->progressbar);
|
2005-07-10 06:09:06 +02:00
|
|
|
gchar buf[32];
|
2010-08-23 20:24:07 +02:00
|
|
|
|
2006-12-27 00:03:31 +01:00
|
|
|
if (total && done % step == 0) {
|
2010-11-02 16:36:38 +01:00
|
|
|
#ifdef GENERIC_UMPC
|
|
|
|
/* use a more compact format */
|
|
|
|
const gchar *format = "%d/%d";
|
|
|
|
#else
|
|
|
|
const gchar *format = "%d / %d";
|
|
|
|
#endif
|
|
|
|
g_snprintf(buf, sizeof(buf), format, done, total);
|
2010-08-23 20:24:07 +02:00
|
|
|
gtk_progress_bar_set_text(progressbar, buf);
|
|
|
|
gtk_progress_bar_set_fraction(progressbar,
|
2014-06-10 11:36:16 +02:00
|
|
|
(gfloat)done / (gfloat)total);
|
2011-10-22 19:09:05 +02:00
|
|
|
if (!gtk_widget_get_visible(GTK_WIDGET(progressbar)))
|
2010-08-23 20:24:07 +02:00
|
|
|
gtk_widget_show(GTK_WIDGET(progressbar));
|
2005-07-10 06:09:06 +02:00
|
|
|
} else if (total == 0) {
|
2010-08-23 20:24:07 +02:00
|
|
|
gtk_progress_bar_set_text(progressbar, "");
|
|
|
|
gtk_progress_bar_set_fraction(progressbar, 0.0);
|
|
|
|
gtk_widget_hide(GTK_WIDGET(progressbar));
|
2005-07-10 06:09:06 +02:00
|
|
|
}
|
|
|
|
}
|