Statistics
| Revision:

root / src / statusbar.c @ 1

History | View | Annotate | Download (2.84 KB)

1
/*
2
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3
 * Copyright (C) 1999,2000 Hiroyuki Yamamoto
4
 *
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 2 of the License, or
8
 * (at your option) any later version.
9
 *
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.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
 */
19

    
20
#ifdef HAVE_CONFIG_H
21
#  include "config.h"
22
#endif
23

    
24
#include <glib.h>
25
#include <gtk/gtkstatusbar.h>
26
#include <stdarg.h>
27

    
28
#include "intl.h"
29
#include "statusbar.h"
30
#include "gtkutils.h"
31
#include "utils.h"
32

    
33
#define BUFFSIZE 1024
34

    
35
static GList *statusbar_list = NULL;
36

    
37
GtkWidget *statusbar_create(void)
38
{
39
        GtkWidget *statusbar;
40

    
41
        statusbar = gtk_statusbar_new();
42
        gtk_widget_set_usize(statusbar, 1, -1);
43
        statusbar_list = g_list_append(statusbar_list, statusbar);
44

    
45
        return statusbar;
46
}
47

    
48
void statusbar_puts(GtkStatusbar *statusbar, const gchar *str)
49
{
50
        gint cid;
51
        gchar *buf;
52

    
53
        buf = g_strdup(str);
54
        strretchomp(buf);
55
        if (strlen(buf) > 76) {
56
                wchar_t *wbuf;
57

    
58
                wbuf = strdup_mbstowcs(buf);
59

    
60
                if (wcslen(wbuf) > 60) {
61
                        gchar *tmp;
62

    
63
                        g_free(buf);
64
                        wbuf[60] = (wchar_t)0;
65
                        tmp = strdup_wcstombs(wbuf);
66
                        buf = g_strconcat(tmp, "...", NULL);
67
                        g_free(tmp);
68
                }
69

    
70
                g_free(wbuf);
71
        }
72

    
73
        cid = gtk_statusbar_get_context_id(statusbar, "Standard Output");
74
        gtk_statusbar_pop(statusbar, cid);
75
        gtk_statusbar_push(statusbar, cid, buf);
76
        gtkut_widget_wait_for_draw(GTK_WIDGET(statusbar)->parent);
77

    
78
        g_free(buf);
79
}
80

    
81
void statusbar_puts_all(const gchar *str)
82
{
83
        GList *cur;
84

    
85
        for (cur = statusbar_list; cur != NULL; cur = cur->next)
86
                statusbar_puts(GTK_STATUSBAR(cur->data), str);
87
}
88

    
89
void statusbar_print(GtkStatusbar *statusbar, const gchar *format, ...)
90
{
91
        va_list args;
92
        gchar buf[BUFFSIZE];
93

    
94
        va_start(args, format);
95
        g_vsnprintf(buf, sizeof(buf), format, args);
96
        va_end(args);
97

    
98
        statusbar_puts(statusbar, buf);
99
}
100

    
101
void statusbar_print_all(const gchar *format, ...)
102
{
103
        va_list args;
104
        gchar buf[BUFFSIZE];
105
        GList *cur;
106

    
107
        va_start(args, format);
108
        g_vsnprintf(buf, sizeof(buf), format, args);
109
        va_end(args);
110

    
111
        for (cur = statusbar_list; cur != NULL; cur = cur->next)
112
                statusbar_puts(GTK_STATUSBAR(cur->data), buf);
113
}
114

    
115
void statusbar_pop_all(void)
116
{
117
        GList *cur;
118
        gint cid;
119

    
120
        for (cur = statusbar_list; cur != NULL; cur = cur->next) {
121
                cid = gtk_statusbar_get_context_id(GTK_STATUSBAR(cur->data),
122
                                                   "Standard Output");
123
                gtk_statusbar_pop(GTK_STATUSBAR(cur->data), cid);
124
        }
125
}