Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
message-stack.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
6/*
7 * Authors:
8 * MenTaLguY <mental@rydia.net>
9 * Jon A. Cruz <jon@joncruz.org>
10 *
11 * Copyright (C) 2004 MenTaLguY
12 * Copyright (C) 2011 Jon A. Cruz
13 *
14 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
15 */
16
17#ifndef SEEN_INKSCAPE_MESSAGE_STACK_H
18#define SEEN_INKSCAPE_MESSAGE_STACK_H
19
20#include <cstdarg>
21#include <cstddef>
22#include <glib.h> // G_GNUC_PRINTF is the only thing worth having from here
23#include <glibmm/ustring.h>
24#include <sigc++/sigc++.h>
25
26#include "message.h"
27
28namespace Inkscape {
29
48class MessageStack final
49{
50public:
53
54 MessageStack(MessageStack const &) = delete; // no copy
55 void operator=(MessageStack const &) = delete; // no assign
56
64 char const *currentMessage() {
65 return _messages ? _messages->message : nullptr;
66 }
67
71 sigc::connection connectChanged(sigc::slot<void (MessageType, char const *)> slot)
72 {
73 return _changed_signal.connect(slot);
74 }
75
83 MessageId push(MessageType type, char const *message);
84
92 MessageId pushF(MessageType type, char const *format, ...) G_GNUC_PRINTF(3,4);
93
103 MessageId pushVF(MessageType type, char const *format, va_list args);
104
112 void cancel(MessageId id);
113
122 MessageId flash(MessageType type, char const *message);
123
132 MessageId flash(MessageType type, Glib::ustring const &message);
133
134
143 MessageId flashF(MessageType type, char const *format, ...) G_GNUC_PRINTF(3,4);
144
154 MessageId flashVF(MessageType type, char const *format, va_list args);
155
156private:
165
167 MessageId _push(MessageType type, unsigned int lifetime, char const *message);
168
170 void _emitChanged();
171 static int _timeout(void* data);
172
173 sigc::signal<void (MessageType, char const *)> _changed_signal;
176};
177
178}
179
180#endif
181/*
182 Local Variables:
183 mode:c++
184 c-file-style:"stroustrup"
185 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
186 indent-tabs-mode:nil
187 fill-column:99
188 End:
189*/
190// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
A class which holds a stack of displayed messages.
MessageId flash(MessageType type, char const *message)
Temporarily pushes a message onto the stack.
MessageId flashF(MessageType type, char const *format,...) G_GNUC_PRINTF(3
temporarily pushes a message onto the stack using printf-like formatting
Message * _discard(Message *m)
frees a message struct and returns the next such struct in the list
Message * _messages
the stack of messages as a linked list
MessageStack(MessageStack const &)=delete
MessageId _next_id
the next message id to assign
char const * currentMessage()
returns the text of the message currently at the top of the stack
MessageId _push(MessageType type, unsigned int lifetime, char const *message)
pushes a message onto the stack with an optional timeout
void cancel(MessageId id)
removes a message from the stack, given its id
MessageType currentMessageType()
returns the type of message currently at the top of the stack
static int _timeout(void *data)
callback to expire flashed messages
sigc::connection connectChanged(sigc::slot< void(MessageType, char const *)> slot)
connects to the "changed" signal which is emitted whenever the topmost message on the stack changes.
void operator=(MessageStack const &)=delete
MessageId pushF(MessageType type, char const *format,...) G_GNUC_PRINTF(3
pushes a message onto the stack using printf-like formatting
MessageId push(MessageType type, char const *message)
pushes a message onto the stack
MessageId MessageId flashVF(MessageType type, char const *format, va_list args)
temporarily pushes a message onto the stack using printf-like formatting, using a stdarg argument lis...
sigc::signal< void(MessageType, char const *)> _changed_signal
void _emitChanged()
emits the "changed" signal
MessageId MessageId pushVF(MessageType type, char const *format, va_list args)
pushes a message onto the stack using printf-like formatting, using a stdarg argument list
Helper class to stream background task notifications as a series of messages.
std::uint_least32_t MessageId
An integer ID which identifies a displayed message in a particular Inkscape::MessageStack.
Definition message.h:39
MessageType
A hint about the meaning of a message; is it an ordinary message, a message advising the user of some...
Definition message.h:25
@ NORMAL_MESSAGE
Definition message.h:26
int G_GNUC_PRINTF(2, 3) safeprintf(char(&buf)[N]
static const Point data[]