mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 23:28:14 +03:00
refactor the notification timer in a new method
some debug messages cleanup
This commit is contained in:
parent
6b8589f4dc
commit
15579232f7
5 changed files with 75 additions and 25 deletions
|
@ -24,6 +24,12 @@ Folder::Folder(const QString &path, QObject *parent)
|
|||
_watcher = new Mirall::FolderWatcher(path, this);
|
||||
QObject::connect(_watcher, SIGNAL(folderChanged(const QStringList &)),
|
||||
SLOT(slotChanged(const QStringList &)));
|
||||
|
||||
QObject::connect(this, SIGNAL(syncStarted()),
|
||||
SLOT(slotSyncStarted()));
|
||||
QObject::connect(this, SIGNAL(syncFinished()),
|
||||
SLOT(slotSyncFinished()));
|
||||
|
||||
}
|
||||
|
||||
QAction * Folder::openAction() const
|
||||
|
@ -42,7 +48,6 @@ QString Folder::path() const
|
|||
|
||||
void Folder::slotChanged(const QStringList &pathList)
|
||||
{
|
||||
qDebug() << "Changed >> " << pathList;
|
||||
startSync(pathList);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,10 +30,11 @@ FolderWatcher::FolderWatcher(const QString &root, QObject *parent)
|
|||
_eventInterval(DEFAULT_EVENT_INTERVAL_SEC),
|
||||
_root(root),
|
||||
_processTimer(new QTimer(this)),
|
||||
_lastEventTime(QTime::currentTime())
|
||||
_lastEventTime(QTime::currentTime()),
|
||||
_lastMask(0)
|
||||
{
|
||||
_processTimer->setSingleShot(true);
|
||||
QObject::connect(_processTimer, SIGNAL(timeout()), this, SLOT(slotProcessPaths()));
|
||||
QObject::connect(_processTimer, SIGNAL(timeout()), this, SLOT(slotProcessTimerTimeout()));
|
||||
|
||||
_inotify = new INotify(standard_event_mask);
|
||||
slotAddFolderRecursive(root);
|
||||
|
@ -58,14 +59,13 @@ bool FolderWatcher::eventsEnabled() const
|
|||
|
||||
void FolderWatcher::setEventsEnabled(bool enabled)
|
||||
{
|
||||
qDebug() << " * event notification " << (enabled ? "enabled" : "disabled");
|
||||
_eventsEnabled = enabled;
|
||||
if (_eventsEnabled) {
|
||||
// schedule a queue cleanup for accumulated events
|
||||
if ( _pendingPaths.empty() )
|
||||
return;
|
||||
|
||||
if (!_processTimer->isActive())
|
||||
_processTimer->start(eventInterval() * 1000);
|
||||
setProcessTimer();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -110,13 +110,25 @@ void FolderWatcher::slotAddFolderRecursive(const QString &path)
|
|||
|
||||
void FolderWatcher::slotINotifyEvent(int mask, int cookie, const QString &path)
|
||||
{
|
||||
int lastMask = _lastMask;
|
||||
QString lastPath = _lastPath;
|
||||
|
||||
_lastMask = mask;
|
||||
_lastPath = path;
|
||||
|
||||
// cancel close write events that come after create
|
||||
//if (lastMask == IN_CREATE && mask == IN_CLOSE_WRITE
|
||||
// && lastPath == path ) {
|
||||
// return;
|
||||
//}
|
||||
|
||||
if (IN_IGNORED & mask) {
|
||||
qDebug() << "IGNORE event";
|
||||
//qDebug() << "IGNORE event";
|
||||
return;
|
||||
}
|
||||
|
||||
if (IN_Q_OVERFLOW & mask)
|
||||
qDebug() << "OVERFLOW";
|
||||
//qDebug() << "OVERFLOW";
|
||||
|
||||
if (mask & IN_CREATE) {
|
||||
qDebug() << cookie << " CREATE: " << path;
|
||||
|
@ -125,26 +137,39 @@ void FolderWatcher::slotINotifyEvent(int mask, int cookie, const QString &path)
|
|||
}
|
||||
}
|
||||
else if (mask & IN_DELETE) {
|
||||
qDebug() << cookie << " DELETE: " << path;
|
||||
//qDebug() << cookie << " DELETE: " << path;
|
||||
if (_inotify->directories().contains(path));
|
||||
qDebug() << "`-> removing " << path;
|
||||
_inotify->removePath(path);
|
||||
}
|
||||
else if (mask & IN_CLOSE_WRITE) {
|
||||
qDebug() << cookie << " WRITABLE CLOSED: " << path;
|
||||
//qDebug() << cookie << " WRITABLE CLOSED: " << path;
|
||||
}
|
||||
else if (mask & IN_MOVE) {
|
||||
qDebug() << cookie << " MOVE: " << path;
|
||||
//qDebug() << cookie << " MOVE: " << path;
|
||||
}
|
||||
else {
|
||||
qDebug() << cookie << " OTHER " << mask << " :" << path;
|
||||
//qDebug() << cookie << " OTHER " << mask << " :" << path;
|
||||
}
|
||||
|
||||
_pendingPaths.append(path);
|
||||
|
||||
slotProcessPaths();
|
||||
}
|
||||
|
||||
void FolderWatcher::slotProcessTimerTimeout()
|
||||
{
|
||||
qDebug() << "* Scheduled processing of event queue";
|
||||
slotProcessPaths();
|
||||
}
|
||||
|
||||
void FolderWatcher::setProcessTimer()
|
||||
{
|
||||
if (!_processTimer->isActive()) {
|
||||
qDebug() << "* Pending events will be processed in" << eventInterval() << "seconds. (" << _pendingPaths.size() << "events until now )";
|
||||
_processTimer->start(eventInterval() * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
void FolderWatcher::slotProcessPaths()
|
||||
{
|
||||
QTime eventTime = QTime::currentTime();
|
||||
|
@ -153,23 +178,25 @@ void FolderWatcher::slotProcessPaths()
|
|||
return;
|
||||
|
||||
if (_lastEventTime.secsTo(eventTime) < eventInterval()) {
|
||||
qDebug() << "Last event happened less than " << eventInterval() << " seconds ago...";
|
||||
//qDebug() << "`-> Last event happened less than " << eventInterval() << " seconds ago...";
|
||||
// schedule a forced queue cleanup later
|
||||
if (!_processTimer->isActive())
|
||||
_processTimer->start(eventInterval() * 1000);
|
||||
setProcessTimer();
|
||||
return;
|
||||
}
|
||||
|
||||
// if the events will be processed because changed files and not
|
||||
// because a forced update, stop any timer.
|
||||
if (_processTimer->isActive())
|
||||
_processTimer->stop();
|
||||
|
||||
_lastEventTime = eventTime;
|
||||
QStringList notifyPaths(_pendingPaths);
|
||||
_pendingPaths.clear();
|
||||
|
||||
qDebug() << " * Notify " << notifyPaths.size() << " changed items";
|
||||
emit folderChanged(notifyPaths);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#include "folderwatcher.moc"
|
||||
|
|
|
@ -73,9 +73,14 @@ signals:
|
|||
*/
|
||||
void folderChanged(const QStringList &pathList);
|
||||
|
||||
protected:
|
||||
void setProcessTimer();
|
||||
|
||||
protected slots:
|
||||
void slotINotifyEvent(int mask, int cookie, const QString &path);
|
||||
void slotAddFolderRecursive(const QString &path);
|
||||
// called when the manually process timer triggers
|
||||
void slotProcessTimerTimeout();
|
||||
void slotProcessPaths();
|
||||
private:
|
||||
bool _eventsEnabled;
|
||||
|
@ -86,6 +91,10 @@ private:
|
|||
QStringList _pendingPaths;
|
||||
QTimer *_processTimer;
|
||||
QTime _lastEventTime;
|
||||
|
||||
// to cancel events that belong to the same action
|
||||
int _lastMask;
|
||||
QString _lastPath;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,9 @@ UnisonFolder::UnisonFolder(const QString &path, const QString &secondPath, QObje
|
|||
QObject::connect(_unison, SIGNAL(error(QProcess::ProcessError)),
|
||||
SLOT(slotError(QProcess::ProcessError)));
|
||||
|
||||
QObject::connect(_unison, SIGNAL(started()),
|
||||
SLOT(slotStarted()));
|
||||
|
||||
QObject::connect(_unison, SIGNAL(finished(int, QProcess::ExitStatus)),
|
||||
SLOT(slotFinished(int, QProcess::ExitStatus)));
|
||||
}
|
||||
|
@ -65,31 +68,36 @@ void UnisonFolder::startSync(const QStringList &pathList)
|
|||
_unison->start(program, args);
|
||||
}
|
||||
|
||||
void UnisonFolder::slotStarted()
|
||||
{
|
||||
qDebug() << " * Unison process started ( PID " << _unison->pid() << ")";
|
||||
//qDebug() << _unison->readAllStandardOutput();;
|
||||
}
|
||||
|
||||
void UnisonFolder::slotFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||
{
|
||||
qDebug() << " * Unison process finished with status" << exitCode;
|
||||
emit syncFinished();
|
||||
}
|
||||
|
||||
void UnisonFolder::slotReadyReadStandardOutput()
|
||||
{
|
||||
qDebug() << _unison->readAllStandardOutput();;
|
||||
|
||||
//qDebug() << _unison->readAllStandardOutput();;
|
||||
}
|
||||
|
||||
void UnisonFolder::slotReadyReadStandardError()
|
||||
{
|
||||
qDebug() << _unison->readAllStandardError();;
|
||||
|
||||
//qDebug() << _unison->readAllStandardError();;
|
||||
}
|
||||
|
||||
void UnisonFolder::slotStateChanged(QProcess::ProcessState state)
|
||||
{
|
||||
qDebug() << "changed: " << state;
|
||||
//qDebug() << "changed: " << state;
|
||||
}
|
||||
|
||||
void UnisonFolder::slotError(QProcess::ProcessError error)
|
||||
{
|
||||
qDebug() << "error: " << error;
|
||||
//qDebug() << "error: " << error;
|
||||
}
|
||||
|
||||
} // ns
|
||||
|
|
|
@ -29,6 +29,7 @@ protected slots:
|
|||
void slotReadyReadStandardError();
|
||||
void slotStateChanged(QProcess::ProcessState);
|
||||
void slotFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||
void slotStarted();
|
||||
void slotError(QProcess::ProcessError);
|
||||
private:
|
||||
QMutex _syncMutex;
|
||||
|
|
Loading…
Reference in a new issue