Statistics
| Revision:

root / src / statusbar.c @ 2661

History | View | Annotate | Download (2.7 kB)

1 1 hiro
/*
2 1 hiro
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 947 hiro
 * Copyright (C) 1999-2006 Hiroyuki Yamamoto
4 1 hiro
 *
5 1 hiro
 * This program is free software; you can redistribute it and/or modify
6 1 hiro
 * it under the terms of the GNU General Public License as published by
7 1 hiro
 * the Free Software Foundation; either version 2 of the License, or
8 1 hiro
 * (at your option) any later version.
9 1 hiro
 *
10 1 hiro
 * This program is distributed in the hope that it will be useful,
11 1 hiro
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 1 hiro
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 1 hiro
 * GNU General Public License for more details.
14 1 hiro
 *
15 1 hiro
 * You should have received a copy of the GNU General Public License
16 1 hiro
 * along with this program; if not, write to the Free Software
17 1 hiro
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 1 hiro
 */
19 1 hiro
20 1 hiro
#ifdef HAVE_CONFIG_H
21 1 hiro
#  include "config.h"
22 1 hiro
#endif
23 1 hiro
24 1 hiro
#include <glib.h>
25 92 hiro
#include <glib/gi18n.h>
26 1 hiro
#include <gtk/gtkstatusbar.h>
27 1 hiro
#include <stdarg.h>
28 1 hiro
29 1 hiro
#include "statusbar.h"
30 1 hiro
#include "gtkutils.h"
31 1 hiro
#include "utils.h"
32 1 hiro
33 1 hiro
#define BUFFSIZE 1024
34 1 hiro
35 1 hiro
static GList *statusbar_list = NULL;
36 1 hiro
37 1 hiro
GtkWidget *statusbar_create(void)
38 1 hiro
{
39 1 hiro
        GtkWidget *statusbar;
40 1 hiro
41 1 hiro
        statusbar = gtk_statusbar_new();
42 11 hiro
        gtk_widget_set_size_request(statusbar, 1, -1);
43 1 hiro
        statusbar_list = g_list_append(statusbar_list, statusbar);
44 1 hiro
45 524 hiro
        set_log_show_status_func(statusbar_puts_all);
46 524 hiro
47 1 hiro
        return statusbar;
48 1 hiro
}
49 1 hiro
50 1 hiro
void statusbar_puts(GtkStatusbar *statusbar, const gchar *str)
51 1 hiro
{
52 1 hiro
        gint cid;
53 1 hiro
        gchar *buf;
54 1 hiro
55 947 hiro
        buf = g_strdup(str);
56 947 hiro
        strretchomp(buf);
57 1 hiro
58 1 hiro
        cid = gtk_statusbar_get_context_id(statusbar, "Standard Output");
59 1 hiro
        gtk_statusbar_pop(statusbar, cid);
60 1 hiro
        gtk_statusbar_push(statusbar, cid, buf);
61 227 hiro
        gtkut_widget_draw_now(GTK_WIDGET(statusbar));
62 1 hiro
63 1 hiro
        g_free(buf);
64 1 hiro
}
65 1 hiro
66 1 hiro
void statusbar_puts_all(const gchar *str)
67 1 hiro
{
68 1 hiro
        GList *cur;
69 1 hiro
70 2259 hiro
        gdk_threads_enter();
71 1 hiro
        for (cur = statusbar_list; cur != NULL; cur = cur->next)
72 1 hiro
                statusbar_puts(GTK_STATUSBAR(cur->data), str);
73 2259 hiro
        gdk_threads_leave();
74 1 hiro
}
75 1 hiro
76 1 hiro
void statusbar_print(GtkStatusbar *statusbar, const gchar *format, ...)
77 1 hiro
{
78 1 hiro
        va_list args;
79 1 hiro
        gchar buf[BUFFSIZE];
80 1 hiro
81 1 hiro
        va_start(args, format);
82 1 hiro
        g_vsnprintf(buf, sizeof(buf), format, args);
83 1 hiro
        va_end(args);
84 1 hiro
85 1 hiro
        statusbar_puts(statusbar, buf);
86 1 hiro
}
87 1 hiro
88 1 hiro
void statusbar_print_all(const gchar *format, ...)
89 1 hiro
{
90 1 hiro
        va_list args;
91 1 hiro
        gchar buf[BUFFSIZE];
92 1 hiro
        GList *cur;
93 1 hiro
94 1 hiro
        va_start(args, format);
95 1 hiro
        g_vsnprintf(buf, sizeof(buf), format, args);
96 1 hiro
        va_end(args);
97 1 hiro
98 1 hiro
        for (cur = statusbar_list; cur != NULL; cur = cur->next)
99 1 hiro
                statusbar_puts(GTK_STATUSBAR(cur->data), buf);
100 1 hiro
}
101 1 hiro
102 1 hiro
void statusbar_pop_all(void)
103 1 hiro
{
104 1 hiro
        GList *cur;
105 1 hiro
        gint cid;
106 1 hiro
107 1 hiro
        for (cur = statusbar_list; cur != NULL; cur = cur->next) {
108 1 hiro
                cid = gtk_statusbar_get_context_id(GTK_STATUSBAR(cur->data),
109 1 hiro
                                                   "Standard Output");
110 1 hiro
                gtk_statusbar_pop(GTK_STATUSBAR(cur->data), cid);
111 1 hiro
        }
112 1 hiro
}