libnotificationmanager: Expire all notifications when "Do not disturb" is on

After leaving "Do not disturb" mode, a flood of on-screen notifications
ensues, causing the right-hand side of the screen to be full of rapidly
scrolling and disappearing notifications for the next minute.

The user doesn't need to see any notification popup that is suppressed
by DnD mode, because the notification can be viewed from the drawer anyway.

BUG: 440837
FIXED-IN: 5.25
wilder-5.25
Fushan Wen 4 years ago
parent 90d4ccbf71
commit b8b722ba19
No known key found for this signature in database
GPG Key ID: 2E48D1487C91DCAA
  1. 16
      libnotificationmanager/abstractnotificationsmodel.cpp
  2. 1
      libnotificationmanager/abstractnotificationsmodel.h
  3. 1
      libnotificationmanager/abstractnotificationsmodel_p.h
  4. 3
      libnotificationmanager/notificationsmodel.cpp

@ -26,6 +26,7 @@ using namespace NotificationManager;
AbstractNotificationsModel::Private::Private(AbstractNotificationsModel *q)
: q(q)
, inhibited(false)
, lastRead(QDateTime::currentDateTimeUtc())
{
pendingRemovalTimer.setSingleShot(true);
@ -67,10 +68,10 @@ void AbstractNotificationsModel::Private::onNotificationAdded(const Notification
q->endRemoveRows();
}
setupNotificationTimeout(notification);
q->beginInsertRows(QModelIndex(), notifications.count(), notifications.count());
notifications.append(std::move(notification));
// Timeout must be set after the item appends to the vector
setupNotificationTimeout(notification);
q->endInsertRows();
}
@ -159,6 +160,12 @@ void AbstractNotificationsModel::Private::setupNotificationTimeout(const Notific
return;
}
// Don't show the notification popup after switching DND mode off.
if (inhibited) {
q->expire(notification.id());
return;
}
QTimer *timer = notificationTimeouts.value(notification.id());
if (!timer) {
timer = new QTimer();
@ -426,6 +433,11 @@ void AbstractNotificationsModel::stopTimeout(uint notificationId)
delete d->notificationTimeouts.take(notificationId);
}
void AbstractNotificationsModel::setInhibited(bool inhibited)
{
d->inhibited = inhibited;
}
void AbstractNotificationsModel::clear(Notifications::ClearFlags flags)
{
if (d->notifications.isEmpty()) {

@ -44,6 +44,7 @@ public:
void startTimeout(uint notificationId);
void stopTimeout(uint notificationId);
void setInhibited(bool inhibited);
void clear(Notifications::ClearFlags flags);

@ -41,6 +41,7 @@ public:
QVector<uint /*notificationId*/> pendingRemovals;
QTimer pendingRemovalTimer;
bool inhibited; // "Do not disturb" mode
QDateTime lastRead;
};

@ -50,6 +50,9 @@ NotificationsModel::NotificationsModel()
}
});
Server::self().init();
setInhibited(Server::self().inhibited());
connect(&Server::self(), &Server::inhibitedChanged, this, std::bind(&NotificationsModel::setInhibited, this, std::placeholders::_1));
}
void NotificationsModel::expire(uint notificationId)

Loading…
Cancel
Save