mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 23:28:14 +03:00
move polling system to Folder where it belongs
This commit is contained in:
parent
e721acd7e8
commit
9055cdc60d
4 changed files with 71 additions and 45 deletions
|
@ -3,17 +3,22 @@
|
|||
#include <QDesktopServices>
|
||||
#include <QIcon>
|
||||
#include <QMutexLocker>
|
||||
#include <QTimer>
|
||||
#include <QUrl>
|
||||
|
||||
#include "mirall/constants.h"
|
||||
#include "mirall/folder.h"
|
||||
#include "mirall/folderwatcher.h"
|
||||
|
||||
#define DEFAULT_POLL_INTERVAL_SEC 30
|
||||
|
||||
namespace Mirall {
|
||||
|
||||
Folder::Folder(const QString &path, QObject *parent)
|
||||
: QObject(parent),
|
||||
_path(path)
|
||||
_path(path),
|
||||
_pollTimer(new QTimer(this)),
|
||||
_pollInterval(DEFAULT_POLL_INTERVAL_SEC)
|
||||
{
|
||||
_openAction = new QAction(QIcon(FOLDER_ICON), path, this);
|
||||
_openAction->setIconVisibleInMenu(true);
|
||||
|
@ -21,6 +26,11 @@ Folder::Folder(const QString &path, QObject *parent)
|
|||
|
||||
QObject::connect(_openAction, SIGNAL(triggered(bool)), SLOT(slotOpenFolder()));
|
||||
|
||||
_pollTimer->setSingleShot(false);
|
||||
_pollTimer->setInterval(pollInterval() * 1000);
|
||||
QObject::connect(_pollTimer, SIGNAL(timeout()), this, SLOT(slotPollTimerTimeout()));
|
||||
_pollTimer->start();
|
||||
|
||||
_watcher = new Mirall::FolderWatcher(path, this);
|
||||
QObject::connect(_watcher, SIGNAL(folderChanged(const QStringList &)),
|
||||
SLOT(slotChanged(const QStringList &)));
|
||||
|
@ -46,6 +56,23 @@ QString Folder::path() const
|
|||
return _path;
|
||||
}
|
||||
|
||||
int Folder::pollInterval() const
|
||||
{
|
||||
return _pollInterval;
|
||||
}
|
||||
|
||||
void Folder::setPollInterval(int seconds)
|
||||
{
|
||||
_pollInterval = seconds;
|
||||
}
|
||||
|
||||
void Folder::slotPollTimerTimeout()
|
||||
{
|
||||
qDebug() << "* Polling remote for changes. Ignoring all pending events until now";
|
||||
_watcher->clearPendingEvents();
|
||||
startSync(QStringList());
|
||||
}
|
||||
|
||||
void Folder::slotChanged(const QStringList &pathList)
|
||||
{
|
||||
startSync(pathList);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <QStringList>
|
||||
|
||||
class QAction;
|
||||
class QTimer;
|
||||
|
||||
namespace Mirall {
|
||||
|
||||
|
@ -27,8 +28,13 @@ public:
|
|||
QAction *openAction() const;
|
||||
|
||||
/**
|
||||
* starts a sync operation
|
||||
* requests are serialized
|
||||
* Starts a sync operation
|
||||
*
|
||||
* If the list of changed files is known, it is passed.
|
||||
*
|
||||
* If the list of changed files is empty, the folder
|
||||
* implementation should figure it by itself of
|
||||
* perform a full scan of changes
|
||||
*/
|
||||
virtual void startSync(const QStringList &pathList) = 0;
|
||||
|
||||
|
@ -38,6 +44,19 @@ public:
|
|||
*/
|
||||
virtual bool isBusy() const = 0;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* The minimum amounts of seconds to wait before
|
||||
* doing a full sync to see if the remote changed
|
||||
*/
|
||||
int pollInterval() const;
|
||||
|
||||
/**
|
||||
* Sets minimum amounts of seconds that will separate
|
||||
* poll intervals
|
||||
*/
|
||||
void setPollInterval(int seconds);
|
||||
|
||||
signals:
|
||||
|
||||
void syncStarted();
|
||||
|
@ -45,11 +64,19 @@ signals:
|
|||
|
||||
protected:
|
||||
FolderWatcher *_watcher;
|
||||
|
||||
private:
|
||||
|
||||
QString _path;
|
||||
QAction *_openAction;
|
||||
// poll timer for remote syncs
|
||||
QTimer *_pollTimer;
|
||||
int _pollInterval;
|
||||
|
||||
protected slots:
|
||||
|
||||
void slotPollTimerTimeout();
|
||||
|
||||
/* called when the watcher detect a list of changed
|
||||
paths */
|
||||
void slotChanged(const QStringList &pathList);
|
||||
|
|
|
@ -20,7 +20,6 @@ static const uint32_t standard_event_mask =
|
|||
/* minimum amount of seconds between two
|
||||
events to consider it a new event */
|
||||
#define DEFAULT_EVENT_INTERVAL_SEC 5
|
||||
#define DEFAULT_POLL_INTERVAL_SEC 30
|
||||
|
||||
namespace Mirall {
|
||||
|
||||
|
@ -28,10 +27,8 @@ FolderWatcher::FolderWatcher(const QString &root, QObject *parent)
|
|||
: QObject(parent),
|
||||
_eventsEnabled(true),
|
||||
_eventInterval(DEFAULT_EVENT_INTERVAL_SEC),
|
||||
_pollInterval(DEFAULT_POLL_INTERVAL_SEC),
|
||||
_root(root),
|
||||
_processTimer(new QTimer(this)),
|
||||
_pollTimer(new QTimer(this)),
|
||||
_lastMask(0)
|
||||
{
|
||||
// this is not the best place for this
|
||||
|
@ -40,11 +37,6 @@ FolderWatcher::FolderWatcher(const QString &root, QObject *parent)
|
|||
_processTimer->setSingleShot(true);
|
||||
QObject::connect(_processTimer, SIGNAL(timeout()), this, SLOT(slotProcessTimerTimeout()));
|
||||
|
||||
_pollTimer->setSingleShot(false);
|
||||
_pollTimer->setInterval(pollInterval() * 1000);
|
||||
QObject::connect(_pollTimer, SIGNAL(timeout()), this, SLOT(slotPollTimerTimeout()));
|
||||
_pollTimer->start();
|
||||
|
||||
_inotify = new INotify(standard_event_mask);
|
||||
slotAddFolderRecursive(root);
|
||||
QObject::connect(_inotify, SIGNAL(notifyEvent(int, int, const QString &)),
|
||||
|
@ -92,6 +84,13 @@ void FolderWatcher::setEventsEnabled(bool enabled)
|
|||
}
|
||||
}
|
||||
|
||||
void FolderWatcher::clearPendingEvents()
|
||||
{
|
||||
if (_processTimer->isActive())
|
||||
_processTimer->stop();
|
||||
_pendingPaths.clear();
|
||||
}
|
||||
|
||||
int FolderWatcher::eventInterval() const
|
||||
{
|
||||
return _eventInterval;
|
||||
|
@ -102,16 +101,6 @@ void FolderWatcher::setEventInterval(int seconds)
|
|||
_eventInterval = seconds;
|
||||
}
|
||||
|
||||
int FolderWatcher::pollInterval() const
|
||||
{
|
||||
return _pollInterval;
|
||||
}
|
||||
|
||||
void FolderWatcher::setPollInterval(int seconds)
|
||||
{
|
||||
_pollInterval = seconds;
|
||||
}
|
||||
|
||||
QStringList FolderWatcher::folders() const
|
||||
{
|
||||
return _inotify->directories();
|
||||
|
@ -213,15 +202,10 @@ void FolderWatcher::slotINotifyEvent(int mask, int cookie, const QString &path)
|
|||
void FolderWatcher::slotProcessTimerTimeout()
|
||||
{
|
||||
qDebug() << "* Scheduled processing of event queue";
|
||||
if (!_pendingPaths.empty())
|
||||
slotProcessPaths();
|
||||
}
|
||||
|
||||
void FolderWatcher::slotPollTimerTimeout()
|
||||
{
|
||||
qDebug() << "* Polling remote for changes";
|
||||
emit folderChanged(QStringList());
|
||||
}
|
||||
|
||||
void FolderWatcher::setProcessTimer()
|
||||
{
|
||||
if (!_processTimer->isActive()) {
|
||||
|
|
|
@ -64,6 +64,11 @@ public:
|
|||
*/
|
||||
void setEventsEnabled(bool enabled);
|
||||
|
||||
/**
|
||||
* Clear all pending events
|
||||
*/
|
||||
void clearPendingEvents();
|
||||
|
||||
/**
|
||||
* The minimum amounts of seconds that will separate
|
||||
* folderChanged() intervals
|
||||
|
@ -76,19 +81,6 @@ public:
|
|||
*/
|
||||
void setEventInterval(int seconds);
|
||||
|
||||
/**
|
||||
* The minimum amounts of seconds to wait before
|
||||
* doing a full sync to see if the remote changed
|
||||
*/
|
||||
int pollInterval() const;
|
||||
|
||||
/**
|
||||
* Sets minimum amounts of seconds that will separate
|
||||
* poll intervals
|
||||
*/
|
||||
void setPollInterval(int seconds);
|
||||
|
||||
|
||||
signals:
|
||||
/**
|
||||
* Emitted when one of the paths is changed
|
||||
|
@ -103,13 +95,11 @@ protected slots:
|
|||
void slotAddFolderRecursive(const QString &path);
|
||||
// called when the manually process timer triggers
|
||||
void slotProcessTimerTimeout();
|
||||
void slotPollTimerTimeout();
|
||||
void slotProcessPaths();
|
||||
|
||||
private:
|
||||
bool _eventsEnabled;
|
||||
int _eventInterval;
|
||||
int _pollInterval;
|
||||
|
||||
INotify *_inotify;
|
||||
QString _root;
|
||||
|
@ -117,8 +107,6 @@ private:
|
|||
QStringList _pendingPaths;
|
||||
|
||||
QTimer *_processTimer;
|
||||
// poll timer for remote syncs
|
||||
QTimer *_pollTimer;
|
||||
|
||||
QTime _lastEventTime;
|
||||
|
||||
|
|
Loading…
Reference in a new issue