ActivityWidget: use a QHash for _widgetsToRemove

The problem with QSet is that the QDateTime was part of
the hash, but that does not make sens as it should be unique
per widget and not per <date, widget>

Instead make it a QHash so there is only one entry per widget.
This commit is contained in:
Olivier Goffart 2016-04-11 15:27:29 +02:00
parent 976f4dfabe
commit c48b5c4f61
2 changed files with 19 additions and 16 deletions

View file

@ -442,32 +442,35 @@ void ActivityWidget::scheduleWidgetToRemove(NotificationWidget *widget, int mill
if( !widget ) {
return;
}
// in fife seconds from now, remove the widget.
QDateTime removeTime = QDateTime::currentDateTime().addMSecs(milliseconds);
QPair<QDateTime, NotificationWidget*> removeInfo = qMakePair(removeTime, widget);
if( !_widgetsToRemove.contains(removeInfo) ) {
_widgetsToRemove.insert( removeInfo );
if( !_removeTimer.isActive() ) {
_removeTimer.start();
}
// in five seconds from now, remove the widget.
QDateTime removeTime = QDateTime::currentDateTimeUtc().addMSecs(milliseconds);
QDateTime &it = _widgetsToRemove[widget];
if (!it.isValid() || it > removeTime) {
it = removeTime;
}
if( !_removeTimer.isActive() ) {
_removeTimer.start();
}
}
// Called every second to see if widgets need to be removed.
void ActivityWidget::slotCheckToCleanWidgets()
{
// loop over all widgets in the to-remove queue
foreach( auto toRemove, _widgetsToRemove ) {
QDateTime t = toRemove.first;
NotificationWidget *widget = toRemove.second;
auto currentTime = QDateTime::currentDateTimeUtc();
auto it = _widgetsToRemove.begin();
while (it != _widgetsToRemove.end()) {
// loop over all widgets in the to-remove queue
QDateTime t = it.value();
NotificationWidget *widget = it.key();
if( QDateTime::currentDateTime() > t ) {
if( currentTime > t ) {
// found one to remove!
Activity::Identifier id = widget->activity().ident();
_widgetForNotifId.remove(id);
widget->deleteLater();
_widgetsToRemove.remove(toRemove);
it = _widgetsToRemove.erase(it);
} else {
++it;
}
}

View file

@ -96,7 +96,7 @@ private:
QSet<int> _guiLoggedNotifications;
ActivityList _blacklistedNotifications;
QSet< QPair<QDateTime, NotificationWidget*> > _widgetsToRemove;
QHash<NotificationWidget*, QDateTime> _widgetsToRemove;
QTimer _removeTimer;
// number of currently running notification requests. If non zero,