1
by mental
moving trunk for module inkscape |
1 |
/*
|
2246
by mental
update short descriptions of MessageStack and MessageContext a little bit |
2 |
* MessageStack - manages stack of active status messages
|
1
by mental
moving trunk for module inkscape |
3 |
*
|
4 |
* Authors:
|
|
5 |
* MenTaLguY <mental@rydia.net>
|
|
6 |
*
|
|
7 |
* Copyright (C) 2004 MenTaLguY
|
|
8 |
*
|
|
9 |
* Released under GNU GPL, read the file 'COPYING' for more information
|
|
10 |
*/
|
|
11 |
||
4588
by keescook
first set of updates to headers for clean gcc 4.3 builds |
12 |
#include <string.h> |
10762
by Alex Valavanis
Switch to top-level glib headers. Thanks to DimStar for patch |
13 |
#include <glib.h> |
4629
by bryce
Applying fixes for gcc 4.3 build issues (closes LP: #169115) |
14 |
#include <cstring> |
15 |
#include <string> |
|
1
by mental
moving trunk for module inkscape |
16 |
#include "message-stack.h" |
17 |
||
18 |
namespace Inkscape { |
|
19 |
||
20 |
MessageStack::MessageStack() |
|
21 |
: _messages(NULL), _next_id(1) |
|
22 |
{
|
|
23 |
}
|
|
24 |
||
25 |
MessageStack::~MessageStack() |
|
26 |
{
|
|
27 |
while (_messages) { |
|
28 |
_messages = _discard(_messages); |
|
29 |
}
|
|
30 |
}
|
|
31 |
||
32 |
MessageId MessageStack::push(MessageType type, gchar const *message) { |
|
33 |
return _push(type, 0, message); |
|
34 |
}
|
|
35 |
||
36 |
MessageId MessageStack::pushF(MessageType type, gchar const *format, ...) |
|
37 |
{
|
|
38 |
va_list args; |
|
39 |
va_start(args, format); |
|
40 |
MessageId id=pushVF(type, format, args); |
|
41 |
va_end(args); |
|
42 |
return id; |
|
43 |
}
|
|
44 |
||
45 |
MessageId MessageStack::pushVF(MessageType type, gchar const *format, va_list args) |
|
46 |
{
|
|
47 |
MessageId id; |
|
48 |
gchar *message=g_strdup_vprintf(format, args); |
|
49 |
id = push(type, message); |
|
50 |
g_free(message); |
|
51 |
return id; |
|
52 |
}
|
|
53 |
||
54 |
void MessageStack::cancel(MessageId id) { |
|
55 |
Message **ref; |
|
56 |
for ( ref = &_messages ; *ref ; ref = &(*ref)->next ) { |
|
57 |
if ( (*ref)->id == id ) { |
|
58 |
*ref = _discard(*ref); |
|
59 |
_emitChanged(); |
|
60 |
break; |
|
61 |
}
|
|
62 |
}
|
|
63 |
}
|
|
64 |
||
10507
by Jon A. Cruz
Cleaning up trace methods to aid fixing color inversion. |
65 |
MessageId MessageStack::flash(MessageType type, Glib::ustring const &message) |
66 |
{
|
|
67 |
MessageId id = flash( type, message.c_str() ); |
|
68 |
return id; |
|
69 |
}
|
|
70 |
||
1
by mental
moving trunk for module inkscape |
71 |
MessageId MessageStack::flash(MessageType type, gchar const *message) { |
72 |
switch (type) { |
|
73 |
case INFORMATION_MESSAGE: // stay rather long so as to seem permanent, but eventually disappear |
|
74 |
return _push(type, 6000 + 80*strlen(message), message); |
|
75 |
break; |
|
76 |
case ERROR_MESSAGE: // pretty important stuff, but temporary |
|
77 |
return _push(type, 4000 + 60*strlen(message), message); |
|
78 |
break; |
|
79 |
case WARNING_MESSAGE: // a bit less important than error |
|
80 |
return _push(type, 2000 + 40*strlen(message), message); |
|
81 |
break; |
|
2232
by buliabyak
add new message type for urgent immediate statusbar display |
82 |
case IMMEDIATE_MESSAGE: // same length as normal, higher priority |
83 |
return _push(type, 1000 + 20*strlen(message), message); |
|
84 |
break; |
|
1
by mental
moving trunk for module inkscape |
85 |
case NORMAL_MESSAGE: // something ephemeral |
86 |
default: |
|
87 |
return _push(type, 1000 + 20*strlen(message), message); |
|
88 |
break; |
|
89 |
}
|
|
90 |
}
|
|
91 |
||
92 |
MessageId MessageStack::flashF(MessageType type, gchar const *format, ...) { |
|
93 |
va_list args; |
|
94 |
va_start(args, format); |
|
95 |
MessageId id = flashVF(type, format, args); |
|
96 |
va_end(args); |
|
97 |
return id; |
|
98 |
}
|
|
99 |
||
100 |
MessageId MessageStack::flashVF(MessageType type, gchar const *format, va_list args) |
|
101 |
{
|
|
102 |
gchar *message=g_strdup_vprintf(format, args); |
|
103 |
MessageId id = flash(type, message); |
|
104 |
g_free(message); |
|
105 |
return id; |
|
106 |
}
|
|
107 |
||
108 |
MessageId MessageStack::_push(MessageType type, guint lifetime, gchar const *message) |
|
109 |
{
|
|
110 |
Message *m=new Message; |
|
111 |
MessageId id=_next_id++; |
|
112 |
||
113 |
m->stack = this; |
|
114 |
m->id = id; |
|
115 |
m->type = type; |
|
116 |
m->message = g_strdup(message); |
|
117 |
||
118 |
if (lifetime) { |
|
149
by rwst
bulk trailing spaces removal. consistency through MD5 of binary |
119 |
m->timeout_id = g_timeout_add(lifetime, &MessageStack::_timeout, m); |
1
by mental
moving trunk for module inkscape |
120 |
} else { |
121 |
m->timeout_id = 0; |
|
122 |
}
|
|
149
by rwst
bulk trailing spaces removal. consistency through MD5 of binary |
123 |
|
1
by mental
moving trunk for module inkscape |
124 |
m->next = _messages; |
125 |
_messages = m; |
|
126 |
||
127 |
_emitChanged(); |
|
128 |
||
129 |
return id; |
|
130 |
}
|
|
131 |
||
132 |
MessageStack::Message *MessageStack::_discard(MessageStack::Message *m) |
|
133 |
{
|
|
134 |
Message *next=m->next; |
|
135 |
if (m->timeout_id) { |
|
136 |
g_source_remove(m->timeout_id); |
|
137 |
m->timeout_id = 0; |
|
138 |
}
|
|
139 |
g_free(m->message); |
|
140 |
m->message = NULL; |
|
141 |
m->stack = NULL; |
|
142 |
delete m; |
|
143 |
return next; |
|
144 |
}
|
|
145 |
||
146 |
void MessageStack::_emitChanged() { |
|
147 |
if (_messages) { |
|
148 |
_changed_signal.emit(_messages->type, _messages->message); |
|
149 |
} else { |
|
150 |
_changed_signal.emit(NORMAL_MESSAGE, NULL); |
|
151 |
}
|
|
152 |
}
|
|
1636
by kidproto
I peeled back my changes because of some deep error. |
153 |
|
1
by mental
moving trunk for module inkscape |
154 |
gboolean MessageStack::_timeout(gpointer data) { |
155 |
Message *m=reinterpret_cast<Message *>(data); |
|
156 |
m->timeout_id = 0; |
|
157 |
m->stack->cancel(m->id); |
|
158 |
return FALSE; |
|
159 |
}
|
|
160 |
||
161 |
}
|
|
162 |
||
163 |
/*
|
|
164 |
Local Variables:
|
|
165 |
mode:c++
|
|
166 |
c-file-style:"stroustrup"
|
|
167 |
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
|
|
168 |
indent-tabs-mode:nil
|
|
169 |
fill-column:99
|
|
170 |
End:
|
|
171 |
*/
|
|
9900
by Chris Morgan
Super duper mega (fun!) commit: replaced encoding=utf-8 with fileencoding=utf-8 in all 1074 Vim modelines. |
172 |
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
|