2
* $Id: statusbar_gui.c,v 1.9 2004/01/14 20:52:33 rmanfredi Exp $
4
* Copyright (c) 2001-2003, Raphael Manfredi, Richard Eckart
6
* GUI stuff used by share.c
8
*----------------------------------------------------------------------
9
* This file is part of gtk-gnutella.
11
* gtk-gnutella is free software; you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation; either version 2 of the License, or
14
* (at your option) any later version.
16
* gtk-gnutella is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
21
* You should have received a copy of the GNU General Public License
22
* along with gtk-gnutella; if not, write to the Free Software
24
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
*----------------------------------------------------------------------
29
#include "statusbar_gui.h"
30
#include "override.h" /* Must be the last header included */
32
RCSID("$Id: statusbar_gui.c,v 1.9 2004/01/14 20:52:33 rmanfredi Exp $");
35
* Timeout entry for statusbar messages.
37
typedef struct statusbar_timeout {
38
statusbar_msgid_t id; /* message id of the message */
39
time_t timeout; /* time after which the message should be removed */
40
} statusbar_timeout_t;
43
* statusbar context ids
45
guint scid_bottom = (guint) -1;
46
guint scid_hostsfile = (guint) -1;
47
guint scid_search_autoselected = (guint) -1;
48
guint scid_queue_freezed = (guint) -1;
49
guint scid_info = (guint) -1;
50
guint scid_ip_changed = (guint) -1;
51
guint scid_warn = (guint) -1;
54
* List with timeout entries for statusbar messages
56
static GSList *sl_statusbar_timeouts = NULL;
61
static gchar *statbar_botstr = NULL;
62
static gchar *statbar_botstr_new = NULL;
64
static void statusbar_gui_free_timeout(struct statusbar_timeout * t);
65
static void statusbar_gui_free_timeout_list(void);
66
static void statusbar_gui_add_timeout(statusbar_msgid_t, guint timeout);
68
void statusbar_gui_init(void)
70
GtkStatusbar *statusbar;
72
statusbar = GTK_STATUSBAR
73
(lookup_widget(main_window, "statusbar"));
77
gtk_statusbar_get_context_id(statusbar, "default");
79
gtk_statusbar_get_context_id(statusbar, "reading hosts file");
80
scid_search_autoselected =
81
gtk_statusbar_get_context_id(statusbar, "autoselected search items");
83
gtk_statusbar_get_context_id(statusbar, "queue freezed");
86
gtk_statusbar_get_context_id(statusbar, "information");
89
gtk_statusbar_get_context_id(statusbar, "ip changed");
92
gtk_statusbar_get_context_id(statusbar, "warning");
95
* This message lies at the bottom of the statusbar, and is never removed,
96
* but to be replaced by an updated message.
98
* The current string held at the bottom is stored in `statbar_botstr'.
99
* If a new string is pending replacement in `statbar_botstr_new', then
100
* it will replace the current one when the last timeout for pushed
101
* messages expires, at which time we'll know the bottom message is shown.
105
statbar_botstr = g_strdup(GTA_WEBSITE);
106
statusbar_gui_push(SB_MESSAGE, scid_bottom, 0, statbar_botstr);
109
void statusbar_gui_shutdown(void)
111
statusbar_gui_free_timeout_list();
113
if (statbar_botstr_new)
114
g_free(statbar_botstr_new);
116
g_free(statbar_botstr);
120
void statusbar_gui_set_default(const char *format, ...)
122
static gchar buf[1024];
125
va_start(args, format);
127
if (statbar_botstr_new != NULL)
128
g_free(statbar_botstr_new);
130
if (format != NULL) {
131
gm_vsnprintf(buf, sizeof(buf), format, args);
132
statbar_botstr_new = g_strdup(buf);
134
statbar_botstr_new = g_strdup(GTA_WEBSITE);
141
* statusbar_gui_message:
143
* Put a message on the statusbar. The message will by displayed for
144
* a number of seconds given by timeout. If timeout is 0 the message
145
* will not be automatically removed.
147
* Returns: message id of the added message
149
statusbar_msgid_t statusbar_gui_push
150
(sb_types_t type, guint scid, guint timeout, const gchar *format , ...)
152
static gchar buf[1024];
154
statusbar_msgid_t id = {0, 0};
155
GtkStatusbar *statusbar;
157
va_start(args, format);
159
if (format != NULL) {
162
gm_vsnprintf(buf, sizeof(buf), format, args);
165
gm_vsnprintf(buf, sizeof(buf), format, args);
173
statusbar = GTK_STATUSBAR
174
(lookup_widget(main_window, "statusbar"));
177
id.msgid = gtk_statusbar_push(GTK_STATUSBAR(statusbar), scid, buf);
180
statusbar_gui_add_timeout(id, timeout);
187
static void statusbar_gui_pop(guint scid)
189
GtkStatusbar *statusbar;
191
statusbar = GTK_STATUSBAR
192
(lookup_widget(main_window, "statusbar"));
194
gtk_statusbar_pop(GTK_STATUSBAR(statusbar), scid);
197
void statusbar_gui_remove(statusbar_msgid_t id)
199
GtkStatusbar *statusbar;
201
statusbar = GTK_STATUSBAR
202
(lookup_widget(main_window, "statusbar"));
204
gtk_statusbar_remove(GTK_STATUSBAR(statusbar), id.scid, id.msgid);
208
* statusbar_gui_add_timeout:
210
* Add a statusbar message id to the timeout list, so it will be removed
211
* automatically after a number of seconds.
213
static void statusbar_gui_add_timeout(statusbar_msgid_t id, guint timeout)
215
struct statusbar_timeout * t = NULL;
217
t = g_malloc0(sizeof(struct statusbar_timeout));
220
t->timeout = time((time_t *) NULL) + timeout;
222
sl_statusbar_timeouts = g_slist_prepend(sl_statusbar_timeouts, t);
226
* statusbar_gui_free_timeout:
228
* Remove the timeout from the timeout list and free allocated memory.
230
static void statusbar_gui_free_timeout(struct statusbar_timeout * t)
234
statusbar_gui_remove(t->id);
236
sl_statusbar_timeouts = g_slist_remove(sl_statusbar_timeouts, t);
242
* statusbar_gui_clear_timeouts
244
* Check whether statusbar items have expired and remove them from the
247
void statusbar_gui_clear_timeouts(time_t now)
249
GSList *to_remove = NULL;
252
for (l = sl_statusbar_timeouts; l; l = l->next) {
253
struct statusbar_timeout *t = (struct statusbar_timeout *) l->data;
255
if (now > t->timeout)
256
to_remove = g_slist_prepend(to_remove, t);
259
for (l = to_remove; l; l = l->next)
260
statusbar_gui_free_timeout((struct statusbar_timeout *) l->data);
262
g_slist_free(to_remove);
265
* When there are no more timeouts left, and there's a pending
266
* new statusbar string to display, pop the old one and add the new.
270
if (sl_statusbar_timeouts == NULL && statbar_botstr_new) {
271
statusbar_gui_pop(scid_bottom);
272
g_free(statbar_botstr);
273
statbar_botstr = statbar_botstr_new;
274
statbar_botstr_new = NULL;
275
statusbar_gui_push(SB_MESSAGE, scid_bottom, 0, statbar_botstr);
280
* statusbar_gui_free_timeout_list:
282
* Clear the whole timeout list and free allocated memory.
284
static void statusbar_gui_free_timeout_list(void)
288
for (l = sl_statusbar_timeouts; l; l = sl_statusbar_timeouts) {
289
struct statusbar_timeout *t = (struct statusbar_timeout *) l->data;
291
statusbar_gui_free_timeout(t);