prevent multiple broadcasts of the same notification
This commit is contained in:
parent
cec2801784
commit
e246656cb1
|
@ -41,7 +41,6 @@ NotificationData::NotificationData(const Snore::Application &application, const
|
||||||
m_text(text),
|
m_text(text),
|
||||||
m_icon(icon),
|
m_icon(icon),
|
||||||
m_priority(priority),
|
m_priority(priority),
|
||||||
m_closeReason(Notification::NONE),
|
|
||||||
m_hints(m_application.constHints())
|
m_hints(m_application.constHints())
|
||||||
{
|
{
|
||||||
notificationCount++;
|
notificationCount++;
|
||||||
|
@ -58,7 +57,6 @@ Snore::NotificationData::NotificationData(const Notification &old, const QString
|
||||||
m_text(text),
|
m_text(text),
|
||||||
m_icon(icon),
|
m_icon(icon),
|
||||||
m_priority(priority),
|
m_priority(priority),
|
||||||
m_closeReason(Notification::NONE),
|
|
||||||
m_hints(m_application.constHints()),
|
m_hints(m_application.constHints()),
|
||||||
m_toReplace(old)
|
m_toReplace(old)
|
||||||
{
|
{
|
||||||
|
@ -105,3 +103,13 @@ QString NotificationData::resolveMarkup(const QString &string, Utils::MARKUP_FLA
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NotificationData::setBroadcasted()
|
||||||
|
{
|
||||||
|
m_isBroadcasted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NotificationData::isBroadcasted() const
|
||||||
|
{
|
||||||
|
return m_isBroadcasted;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,10 @@ public:
|
||||||
|
|
||||||
QString resolveMarkup(const QString &string, Utils::MARKUP_FLAGS flags);
|
QString resolveMarkup(const QString &string, Utils::MARKUP_FLAGS flags);
|
||||||
|
|
||||||
|
void setBroadcasted();
|
||||||
|
|
||||||
|
bool isBroadcasted() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(NotificationData)
|
Q_DISABLE_COPY(NotificationData)
|
||||||
|
|
||||||
|
@ -62,13 +66,14 @@ private:
|
||||||
QString m_text;
|
QString m_text;
|
||||||
Icon m_icon;
|
Icon m_icon;
|
||||||
Notification::Prioritys m_priority;
|
Notification::Prioritys m_priority;
|
||||||
Notification::CloseReasons m_closeReason;
|
Notification::CloseReasons m_closeReason = Notification::NONE;
|
||||||
Action m_actionInvoked;
|
Action m_actionInvoked;
|
||||||
QHash<int, Action> m_actions;
|
QHash<int, Action> m_actions;
|
||||||
Hint m_hints;
|
Hint m_hints;
|
||||||
Notification m_toReplace;
|
Notification m_toReplace;
|
||||||
QScopedPointer<QTimer> m_timeoutTimer;
|
QScopedPointer<QTimer> m_timeoutTimer;
|
||||||
QSet<const QObject *> m_activeIn;
|
QSet<const QObject *> m_activeIn;
|
||||||
|
bool m_isBroadcasted = false;
|
||||||
|
|
||||||
static uint notificationCount;
|
static uint notificationCount;
|
||||||
static uint m_idCount;
|
static uint m_idCount;
|
||||||
|
|
|
@ -113,12 +113,18 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types)
|
||||||
void SnoreCore::broadcastNotification(Notification notification)
|
void SnoreCore::broadcastNotification(Notification notification)
|
||||||
{
|
{
|
||||||
Q_D(SnoreCore);
|
Q_D(SnoreCore);
|
||||||
|
Q_ASSERT_X(!notification.data()->isBroadcasted(), Q_FUNC_INFO, "Notification was already broadcasted.");
|
||||||
|
if (notification.data()->isBroadcasted()) {
|
||||||
|
snoreDebug(SNORE_WARNING) << "Notification" << notification << "was already broadcasted.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
snoreDebug(SNORE_DEBUG) << "Broadcasting" << notification << "timeout:" << notification.timeout();
|
snoreDebug(SNORE_DEBUG) << "Broadcasting" << notification << "timeout:" << notification.timeout();
|
||||||
if (d->m_notificationBackend != nullptr) {
|
if (d->m_notificationBackend != nullptr) {
|
||||||
if (notification.isUpdate() && !d->m_notificationBackend->canUpdateNotification()) {
|
if (notification.isUpdate() && !d->m_notificationBackend->canUpdateNotification()) {
|
||||||
requestCloseNotification(notification.old(), Notification::REPLACED);
|
requestCloseNotification(notification.old(), Notification::REPLACED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
notification.data()->setBroadcasted();
|
||||||
emit d->notify(notification);
|
emit d->notify(notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue