[Pkg-owncloud-commits] [owncloud-client] 182/470: Notifications: Refresh the notifications based on a config value.

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 b9663456d8d4aa85e808f65c64fa6ac3def77d6f
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Fri Mar 18 16:23:21 2016 +0100

    Notifications: Refresh the notifications based on a config value.
    
    Pulls a timer that polls for new notifications regularly. Add
    Config file method for the interval value.
---
 src/gui/activitywidget.cpp | 46 +++++++++++++++++++++++++++++++++++++++++-----
 src/gui/activitywidget.h   |  9 +++++++--
 src/gui/settingsdialog.cpp |  4 +++-
 src/libsync/configfile.cpp | 17 +++++++++++++++++
 src/libsync/configfile.h   |  3 +++
 5 files changed, 71 insertions(+), 8 deletions(-)

diff --git a/src/gui/activitywidget.cpp b/src/gui/activitywidget.cpp
index a009bd7..18418d0 100644
--- a/src/gui/activitywidget.cpp
+++ b/src/gui/activitywidget.cpp
@@ -18,7 +18,6 @@
 
 #include "activitylistmodel.h"
 #include "activitywidget.h"
-#include "configfile.h"
 #include "syncresult.h"
 #include "logger.h"
 #include "utility.h"
@@ -44,6 +43,10 @@
 
 #include <climits>
 
+// time span in milliseconds which has to be between two
+// refreshes of the notifications
+#define NOTIFICATION_REQUEST_FREE_PERIOD 15000
+
 namespace OCC {
 
 
@@ -98,10 +101,13 @@ ActivityWidget::~ActivityWidget()
     delete _ui;
 }
 
-void ActivityWidget::slotRefresh(AccountState *ptr)
+void ActivityWidget::slotRefreshActivities(AccountState *ptr)
 {
     _model->slotRefreshActivity(ptr);
+}
 
+void ActivityWidget::slotRefreshNotifications(AccountState *ptr)
+{
     // start a server notification handler if no notification requests
     // are running
     if( _notificationRequestsRunning == 0 ) {
@@ -428,10 +434,19 @@ ActivitySettings::ActivitySettings(QWidget *parent)
     _progressIndicator = new QProgressIndicator(this);
     _tab->setCornerWidget(_progressIndicator);
 
+    connect(&_notificationCheckTimer, SIGNAL(timeout()),
+            this, SLOT(slotRegularNotificationCheck()));
+
     // connect a model signal to stop the animation.
     connect(_activityWidget, SIGNAL(rowsInserted()), _progressIndicator, SLOT(stopAnimation()));
 }
 
+void ActivitySettings::setNotificationRefreshInterval( quint64 interval )
+{
+    qDebug() << "Starting Notification refresh timer with " << interval/1000 << " sec interval";
+    _notificationCheckTimer.start(interval);
+}
+
 void ActivitySettings::setActivityTabHidden(bool hidden)
 {
     if( hidden && _activityTabId > -1 ) {
@@ -477,9 +492,30 @@ void ActivitySettings::slotRemoveAccount( AccountState *ptr )
 
 void ActivitySettings::slotRefresh( AccountState* ptr )
 {
-    if( ptr && ptr->isConnected() && isVisible()) {
-        _progressIndicator->startAnimation();
-        _activityWidget->slotRefresh(ptr);
+    // Fetch Activities only if visible and if last check is longer than 15 secs ago
+    if( _timeSinceLastCheck.isValid() && _timeSinceLastCheck.elapsed() < NOTIFICATION_REQUEST_FREE_PERIOD ) {
+        qDebug() << Q_FUNC_INFO << "do not check as last check is only secs ago: " << _timeSinceLastCheck.elapsed() / 1000;
+        return;
+    }
+    if( ptr && ptr->isConnected() ) {
+        if( isVisible() ) {
+            _progressIndicator->startAnimation();
+            _activityWidget->slotRefreshActivities( ptr);
+        }
+        _activityWidget->slotRefreshNotifications(ptr);
+        if( !_timeSinceLastCheck.isValid() ) {
+            _timeSinceLastCheck.start();
+        } else {
+            _timeSinceLastCheck.restart();
+        }
+    }
+}
+
+void ActivitySettings::slotRegularNotificationCheck()
+{
+    AccountManager *am = AccountManager::instance();
+    foreach (AccountStatePtr a, am->accounts()) {
+        slotRefresh(a.data());
     }
 }
 
diff --git a/src/gui/activitywidget.h b/src/gui/activitywidget.h
index 6a07b34..acbab0d 100644
--- a/src/gui/activitywidget.h
+++ b/src/gui/activitywidget.h
@@ -62,7 +62,8 @@ public:
 
 public slots:
     void slotOpenFile(QModelIndex indx);
-    void slotRefresh(AccountState* ptr);
+    void slotRefreshActivities(AccountState* ptr);
+    void slotRefreshNotifications(AccountState *ptr);
     void slotRemoveAccount( AccountState *ptr );
     void slotAccountActivityStatus(AccountState *ast, int statusCode);
 
@@ -121,9 +122,12 @@ public slots:
     void slotRefresh( AccountState* ptr );
     void slotRemoveAccount( AccountState *ptr );
 
+    void setNotificationRefreshInterval( quint64 interval );
+
 private slots:
     void slotCopyToClipboard();
     void setActivityTabHidden(bool hidden);
+    void slotRegularNotificationCheck();
 
 signals:
     void guiLog(const QString&, const QString&);
@@ -137,7 +141,8 @@ private:
     ActivityWidget *_activityWidget;
     ProtocolWidget *_protocolWidget;
     QProgressIndicator *_progressIndicator;
-
+    QTimer         _notificationCheckTimer;
+    QElapsedTimer  _timeSinceLastCheck;
 };
 
 }
diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp
index abe9c92..3aa8df0 100644
--- a/src/gui/settingsdialog.cpp
+++ b/src/gui/settingsdialog.cpp
@@ -61,6 +61,8 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
     QDialog(parent)
     , _ui(new Ui::SettingsDialog), _gui(gui)
 {
+    ConfigFile cfg;
+
     setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
     _ui->setupUi(this);
     _toolBar = new QToolBar;
@@ -89,6 +91,7 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
     _ui->stack->addWidget(_activitySettings);
     connect( _activitySettings, SIGNAL(guiLog(QString,QString)), _gui,
              SLOT(slotShowOptionalTrayMessage(QString,QString)) );
+    _activitySettings->setNotificationRefreshInterval( cfg.notificationRefreshInterval());
 
     QAction *generalAction = createColorAwareAction(QLatin1String(":/client/resources/settings.png"), tr("General"));
     _actionGroup->addAction(generalAction);
@@ -128,7 +131,6 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
 
     customizeStyle();
 
-    ConfigFile cfg;
     cfg.restoreGeometry(this);
 }
 
diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp
index 32d2475..6b11c6d 100644
--- a/src/libsync/configfile.cpp
+++ b/src/libsync/configfile.cpp
@@ -42,6 +42,7 @@ namespace OCC {
 //static const char caCertsKeyC[] = "CaCertificates"; only used from account.cpp
 static const char remotePollIntervalC[] = "remotePollInterval";
 static const char forceSyncIntervalC[] = "forceSyncInterval";
+static const char notificationRefreshIntervalC[] = "notificationRefreshInterval";
 static const char monoIconsC[] = "monoIcons";
 static const char promptDeleteC[] = "promptDeleteAllFiles";
 static const char crashReporterC[] = "crashReporter";
@@ -390,6 +391,22 @@ quint64 ConfigFile::forceSyncInterval(const QString& connection) const
     return interval;
 }
 
+quint64 ConfigFile::notificationRefreshInterval(const QString& connection) const
+{
+    QString con( connection );
+    if( connection.isEmpty() ) con = defaultConnection();
+    QSettings settings(configFile(), QSettings::IniFormat);
+    settings.beginGroup( con );
+
+    quint64 defaultInterval = 5 * 60 * 1000ull; // 5 minutes
+    quint64 interval = settings.value( QLatin1String(notificationRefreshIntervalC), defaultInterval ).toULongLong();
+    if( interval < 60*1000ull) {
+        qDebug() << "notification refresh interval smaller than one minute, setting to one minute";
+        interval = 60*1000ull;
+    }
+    return interval;
+}
+
 int ConfigFile::updateCheckInterval( const QString& connection ) const
 {
     QString con( connection );
diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h
index 3d000f5..d45a969 100644
--- a/src/libsync/configfile.h
+++ b/src/libsync/configfile.h
@@ -63,6 +63,9 @@ public:
     /* Set poll interval. Value in milliseconds has to be larger than 5000 */
     void setRemotePollInterval(int interval, const QString& connection = QString() );
 
+    /* Interval to check for new notifications */
+    quint64 notificationRefreshInterval(const QString& connection = QString()) const;
+
     /* Force sync interval, in milliseconds */
     quint64 forceSyncInterval(const QString &connection = QString()) const;
 

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