Code

Store cached icons to disk between runs, and invalidate/purge as needed.
[inkscape.git] / src / message-context.cpp
1 /*
2  * MessageContext - context for posting status messages
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  */
12 #include <glib/gstrfuncs.h>
13 #include "message-context.h"
14 #include "message-stack.h"
16 namespace Inkscape {
18 MessageContext::MessageContext(MessageStack *stack)
19 : _stack(stack), _message_id(0), _flash_message_id(0)
20 {
21     GC::anchor(_stack);
22 }
24 MessageContext::~MessageContext() {
25     clear();
26     GC::release(_stack);
27     _stack = NULL;
28 }
30 void MessageContext::set(MessageType type, gchar const *message) {
31     if (_message_id) {
32         _stack->cancel(_message_id);
33     }
34     _message_id = _stack->push(type, message);
35 }
37 void MessageContext::setF(MessageType type, gchar const *format, ...)
38 {
39     va_list args;
40     va_start(args, format);
41     setVF(type, format, args);
42     va_end(args);
43 }
45 void MessageContext::setVF(MessageType type, gchar const *format, va_list args)
46 {
47     gchar *message=g_strdup_vprintf(format, args);
48     set(type, message);
49     g_free(message);
50 }
52 void MessageContext::flash(MessageType type, gchar const *message) {
53     if (_flash_message_id) {
54         _stack->cancel(_flash_message_id);
55     }
56     _flash_message_id = _stack->flash(type, message);
57 }
59 void MessageContext::flashF(MessageType type, gchar const *format, ...) {
60     va_list args;
61     va_start(args, format);
62     flashVF(type, format, args);
63     va_end(args);
64 }
66 void MessageContext::flashVF(MessageType type, gchar const *format, va_list args) {
67     gchar *message=g_strdup_vprintf(format, args);
68     flash(type, message);
69     g_free(message);
70 }
72 void MessageContext::clear() {
73     if (_message_id) {
74         _stack->cancel(_message_id);
75         _message_id = 0;
76     }
77     if (_flash_message_id) {
78         _stack->cancel(_flash_message_id);
79         _flash_message_id = 0;
80     }
81 }
83 }
85 /*
86   Local Variables:
87   mode:c++
88   c-file-style:"stroustrup"
89   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
90   indent-tabs-mode:nil
91   fill-column:99
92   End:
93 */
94 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :