[Pkg-owncloud-commits] [owncloud-client] 301/470: ActivityWidget: use a QHash for _widgetsToRemove

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu May 12 16:25:16 UTC 2016


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit c48b5c4f61bacb90662aa7e63c8c25fbfd67c542
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Mon Apr 11 15:27:29 2016 +0200

    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.
---
 src/gui/activitywidget.cpp | 35 +++++++++++++++++++----------------
 src/gui/activitywidget.h   |  2 +-
 2 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/src/gui/activitywidget.cpp b/src/gui/activitywidget.cpp
index c61abb7..0fe8f39 100644
--- a/src/gui/activitywidget.cpp
+++ b/src/gui/activitywidget.cpp
@@ -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;
-
-        if( QDateTime::currentDateTime() > t ) {
+    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( 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;
         }
     }
 
diff --git a/src/gui/activitywidget.h b/src/gui/activitywidget.h
index be1fc5c..f705573 100644
--- a/src/gui/activitywidget.h
+++ b/src/gui/activitywidget.h
@@ -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,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list