[Pkg-owncloud-commits] [owncloud-client] 173/470: Notifications: Remove "done" notification widgets after fife seconds.

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu May 12 16:25:00 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 328d254f7f93c3ac5a555bd1a8a822b1b6a3ee0e
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Fri Mar 18 11:25:14 2016 +0100

    Notifications: Remove "done" notification widgets after fife seconds.
---
 src/gui/activitywidget.cpp     | 27 +++++++++++++++++++++++++++
 src/gui/activitywidget.h       |  1 +
 src/gui/notificationwidget.cpp | 12 ++++++++++++
 src/gui/notificationwidget.h   |  5 +++++
 4 files changed, 45 insertions(+)

diff --git a/src/gui/activitywidget.cpp b/src/gui/activitywidget.cpp
index a8be244..a009bd7 100644
--- a/src/gui/activitywidget.cpp
+++ b/src/gui/activitywidget.cpp
@@ -38,6 +38,7 @@
 #include "notificationconfirmjob.h"
 #include "servernotificationhandler.h"
 #include "theme.h"
+#include "ocsjob.h"
 
 #include "ui_activitywidget.h"
 
@@ -359,8 +360,34 @@ void ActivityWidget::slotNotifyServerFinished( const QString& reply, int replyCo
     endNotificationRequest(job->widget(), replyCode);
     // FIXME: remove the  widget after a couple of seconds
     qDebug() << Q_FUNC_INFO << "Server Notification reply code"<< replyCode << reply;
+
+    // if the notification was successful start a timer that triggers
+    // removal of the done widgets in a few seconds
+    // Add 200 millisecs to the predefined value to make sure that the timer in
+    // widget's method readyToClose() has elapsed.
+    if( replyCode == OCS_SUCCESS_STATUS_CODE ) {
+        QTimer::singleShot(NOTIFICATION_WIDGET_CLOSE_AFTER_MILLISECS+200, this, SLOT(slotCleanWidgetList()));
+    }
+}
+
+void ActivityWidget::slotCleanWidgetList()
+{
+    foreach( int id, _widgetForNotifId.keys() ) {
+        Q_ASSERT(_widgetForNotifId[id]);
+        if( _widgetForNotifId[id]->readyToClose() ) {
+            auto *widget = _widgetForNotifId[id];
+            _widgetForNotifId.remove(id);
+            delete widget;
+        }
+    }
+
+    if( _widgetForNotifId.isEmpty() ) {
+        _ui->_notifyLabel->setHidden(true);
+        _ui->_notifyScroll->setHidden(true);
+    }
 }
 
+
 /* ==================================================================== */
 
 ActivitySettings::ActivitySettings(QWidget *parent)
diff --git a/src/gui/activitywidget.h b/src/gui/activitywidget.h
index 01c5914..6a07b34 100644
--- a/src/gui/activitywidget.h
+++ b/src/gui/activitywidget.h
@@ -79,6 +79,7 @@ private slots:
     void slotNotifyNetworkError( QNetworkReply* );
     void slotNotifyServerFinished( const QString& reply, int replyCode );
     void endNotificationRequest(NotificationWidget *widget , int replyCode);
+    void slotCleanWidgetList();
 
 private:
     void showLabels();
diff --git a/src/gui/notificationwidget.cpp b/src/gui/notificationwidget.cpp
index afba083..de28c7c 100644
--- a/src/gui/notificationwidget.cpp
+++ b/src/gui/notificationwidget.cpp
@@ -112,10 +112,22 @@ void NotificationWidget::slotNotificationRequestFinished(int statusCode)
 
         //* The second parameter is a time, such as 'selected at 09:58pm'
         doneText = tr("'%1' selected at %2").arg(_actionLabel).arg(timeStr);
+
+        // start a timer, so that activity widget can remove this widget after a
+        // certain time. It needs to be done by ActivityWidget because it also
+        // needs to hide the scrollview if no widget is left any more.
+        // method readyToClose() checks for the timer value to see if it is expired
+        _closeTimer.start();
     }
     _ui._timeLabel->setText( doneText );
 
     _progressIndi->stopAnimation();
+
+}
+
+bool NotificationWidget::readyToClose()
+{
+    return _closeTimer.isValid() && _closeTimer.elapsed() > NOTIFICATION_WIDGET_CLOSE_AFTER_MILLISECS;
 }
 
 }
diff --git a/src/gui/notificationwidget.h b/src/gui/notificationwidget.h
index fceb2d9..8c14339 100644
--- a/src/gui/notificationwidget.h
+++ b/src/gui/notificationwidget.h
@@ -20,6 +20,8 @@
 
 #include "ui_notificationwidget.h"
 
+#define NOTIFICATION_WIDGET_CLOSE_AFTER_MILLISECS 4800
+
 class QProgressIndicator;
 
 namespace OCC {
@@ -30,6 +32,8 @@ class NotificationWidget : public QWidget
 public:
     explicit NotificationWidget(QWidget *parent = 0);
 
+    bool readyToClose();
+
 signals:
     void sendNotificationRequest( const QString&, const QString& link, const QString& verb);
 
@@ -47,6 +51,7 @@ private:
     QString _accountName;
     QProgressIndicator *_progressIndi;
     QString _actionLabel;
+    QElapsedTimer _closeTimer;
 };
 
 }

-- 
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