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.
This commit is contained in:
Klaas Freitag 2016-03-18 16:23:21 +01:00
parent 7f22a07312
commit b9663456d8
5 changed files with 71 additions and 8 deletions

View file

@ -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());
}
}

View file

@ -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;
};
}

View file

@ -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);
}

View file

@ -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 );

View file

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