5 #include "statusmessage.h"
7 #include <Cutelyst/Application>
8 #include <Cutelyst/Plugins/Session/session.h>
10 #include <QRandomGenerator>
11 #include <QtCore/QDateTime>
12 #include <QtCore/QLoggingCategory>
16 Q_LOGGING_CATEGORY(C_STATUSMESSAGE,
"cutelyst.plugins.statusmessage", QtWarningMsg)
27 QString sessionPrefix = QStringLiteral(
"status_msg");
28 QString tokenParam = QStringLiteral(
"mid");
29 QString statusMsgStashKey = QStringLiteral(
"status_msg");
30 QString errorMsgStashKey = QStringLiteral(
"error_msg");
33 void StatusMessagePrivate::_q_postFork(
Application *app)
55 return d->sessionPrefix;
79 return d->statusMsgStashKey;
91 return d->errorMsgStashKey;
102 if (Q_UNLIKELY(!m_instance)) {
103 qCCritical(C_STATUSMESSAGE,
"StatusMessage plugin not registered");
114 const QString statusKey = priv->sessionPrefix + u
"status" + token;
116 if (!statusValue.
isNull()) {
117 deleteKeys.
append(statusKey);
118 c->
setStash(priv->statusMsgStashKey, statusValue);
121 const QString errorKey = priv->sessionPrefix + u
"error" + token;
123 if (!errorValue.
isNull()) {
124 deleteKeys.
append(errorKey);
125 c->
setStash(priv->errorMsgStashKey, errorValue);
142 if (Q_UNLIKELY(!m_instance)) {
143 qCCritical(C_STATUSMESSAGE,
"StatusMessage plugin not registered");
147 token = createToken();
155 if (Q_UNLIKELY(!m_instance)) {
156 qCCritical(C_STATUSMESSAGE,
"StatusMessage plugin not registered");
161 const QString token = createToken();
163 map.
insert(priv->tokenParam, token);
170 if (Q_UNLIKELY(!m_instance)) {
171 qCCritical(C_STATUSMESSAGE,
"StatusMessage plugin not registered");
175 token = createToken();
183 if (Q_UNLIKELY(!m_instance)) {
184 qCCritical(C_STATUSMESSAGE,
"StatusMessage plugin not registered");
189 const QString token = createToken();
191 map.
insert(priv->tokenParam, token);
201 #include "moc_statusmessage.cpp"
The Cutelyst application.
void postForked(Cutelyst::Application *app)
void setStash(const QString &key, const QVariant &value)
Base class for Cutelyst Plugins.
QString queryParam(const QString &key, const QString &defaultValue={}) const
static QVariant value(Context *c, const QString &key, const QVariant &defaultValue=QVariant())
static void setValue(Context *c, const QString &key, const QVariant &value)
static void deleteValues(Context *c, const QStringList &keys)
Manage status messages over multiple requests stored in the Session.
static QString error(Context *c, const QString &msg)
static void load(Context *c)
QString errorMgStashKey() const noexcept
void setTokenParam(const QString &tokenParam)
QString statusMsgStashKey() const noexcept
virtual bool setup(Application *app) override
static QString status(Context *c, const QString &msg)
static ParamsMultiMap statusQuery(Context *c, const QString &msg, ParamsMultiMap query={})
void setErrorMgStashKey(const QString &errorMgStashKey)
QString sessionPrefix() const noexcept
void setStatusMsgStashKey(const QString &statusMsgStashKey)
QString tokenParam() const noexcept
void setSessionPrefix(const QString &sessionPrefix)
virtual ~StatusMessage() override
static ParamsMultiMap errorQuery(Context *c, const QString &msg, ParamsMultiMap query={})
The Cutelyst namespace holds all public Cutelyst API.
void append(QList::parameter_type value)
bool isEmpty() const const
QMultiMap::iterator insert(QMultiMap::const_iterator pos, const Key &key, const T &value)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QRandomGenerator * global()
bool isEmpty() const const
QString number(double n, char format, int precision)
QString rightJustified(qsizetype width, QChar fill, bool truncate) const const
bool isNull() const const