Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mirall/folder.cpp24
-rw-r--r--src/mirall/folder.h12
-rw-r--r--src/mirall/folderman.cpp5
-rw-r--r--src/mirall/folderwatcher.cpp16
-rw-r--r--src/mirall/folderwatcher.h7
-rw-r--r--src/mirall/inotify.cpp1
-rw-r--r--src/mirall/inotify.h1
-rw-r--r--src/mirall/owncloudfolder.cpp27
-rw-r--r--src/mirall/owncloudfolder.h3
9 files changed, 73 insertions, 23 deletions
diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp
index 71dcc1b7e..7090f1b29 100644
--- a/src/mirall/folder.cpp
+++ b/src/mirall/folder.cpp
@@ -196,17 +196,21 @@ void Folder::slotSyncStarted()
void Folder::slotSyncFinished(const SyncResult &result)
{
- _syncResult = result;
- emit syncStateChange();
+#ifdef USE_WATCHER
+ _watcher->setEventsEnabled(true);
+#endif
- // reenable the poll timer if folder is sync enabled
- if( syncEnabled() ) {
- qDebug() << "* " << alias() << "Poll timer enabled";
- _pollTimer->start();
- } else {
- qDebug() << "* Not enabling poll timer for " << alias();
- _pollTimer->stop();
- }
+ _syncResult = result;
+ emit syncStateChange();
+
+ // reenable the poll timer if folder is sync enabled
+ if( syncEnabled() ) {
+ qDebug() << "* " << alias() << "Poll timer enabled with " << _pollTimer->interval() << "seconds";
+ _pollTimer->start();
+ } else {
+ qDebug() << "* Not enabling poll timer for " << alias();
+ _pollTimer->stop();
+ }
}
void Folder::setBackend( const QString& b )
diff --git a/src/mirall/folder.h b/src/mirall/folder.h
index 62db681d4..d2165d631 100644
--- a/src/mirall/folder.h
+++ b/src/mirall/folder.h
@@ -23,13 +23,25 @@
#include "mirall/syncresult.h"
+
+/*
+ * Flag to enable the folder watcher instead of the local polling to detect
+ * changes in the local path.
+ */
+#define USE_WATCHER 1
+#ifdef Q_WS_WIN
+#define USE_WATCHER 0
+#endif
+
class QAction;
class QTimer;
class QIcon;
namespace Mirall {
+#ifdef USE_WATCHER
class FolderWatcher;
+#endif
class Folder : public QObject
{
diff --git a/src/mirall/folderman.cpp b/src/mirall/folderman.cpp
index 1043e2d44..51884a025 100644
--- a/src/mirall/folderman.cpp
+++ b/src/mirall/folderman.cpp
@@ -25,6 +25,7 @@
#include "mirall/owncloudfolder.h"
#include "mirall/syncresult.h"
#include "mirall/folderman.h"
+#include "mirall/inotify.h"
namespace Mirall {
@@ -37,6 +38,10 @@ FolderMan::FolderMan(QObject *parent) :
storageDir.mkpath("folders");
_folderConfigPath = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/folders";
+#ifdef USE_WATCHER
+ Mirall::INotify::initialize();
+#endif
+
_folderChangeSignalMapper = new QSignalMapper(this);
connect(_folderChangeSignalMapper, SIGNAL(mapped(const QString &)),
this, SIGNAL(folderSyncStateChange(const QString &)));
diff --git a/src/mirall/folderwatcher.cpp b/src/mirall/folderwatcher.cpp
index 07d7d3f1a..c6451947c 100644
--- a/src/mirall/folderwatcher.cpp
+++ b/src/mirall/folderwatcher.cpp
@@ -48,7 +48,8 @@ FolderWatcher::FolderWatcher(const QString &root, QObject *parent)
// this is not the best place for this
addIgnore("/**/.unison*");
addIgnore("*csync_timediff.ctmp*");
-
+ addIgnore(".*.sw?"); // vi swap files
+#ifdef USE_WATCHER
_processTimer->setSingleShot(true);
QObject::connect(_processTimer, SIGNAL(timeout()), this, SLOT(slotProcessTimerTimeout()));
@@ -56,6 +57,7 @@ FolderWatcher::FolderWatcher(const QString &root, QObject *parent)
slotAddFolderRecursive(root);
QObject::connect(_inotify, SIGNAL(notifyEvent(int, int, const QString &)),
SLOT(slotINotifyEvent(int, int, const QString &)));
+#endif
// do a first synchronization to get changes while
// the application was not running
setProcessTimer();
@@ -118,13 +120,16 @@ void FolderWatcher::setEventInterval(int seconds)
QStringList FolderWatcher::folders() const
{
+#ifdef USE_WATCHER
return _inotify->directories();
+#endif
}
void FolderWatcher::slotAddFolderRecursive(const QString &path)
{
int subdirs = 0;
qDebug() << "(+) Watcher:" << path;
+#ifdef USE_WATCHER
_inotify->addPath(path);
QStringList watchedFolders(_inotify->directories());
//qDebug() << "currently watching " << watchedFolders;
@@ -151,6 +156,9 @@ void FolderWatcher::slotAddFolderRecursive(const QString &path)
}
if (subdirs >0)
qDebug() << " `-> and" << subdirs << "subdirectories";
+#else
+ qDebug() << "** Watcher is disabled!";
+#endif
}
void FolderWatcher::slotINotifyEvent(int mask, int cookie, const QString &path)
@@ -161,7 +169,9 @@ void FolderWatcher::slotINotifyEvent(int mask, int cookie, const QString &path)
_lastMask = mask;
_lastPath = path;
- // qDebug() << "** Inotify Event " << mask << " on " << path;
+ if( ! eventsEnabled() ) return;
+
+ qDebug() << "** Inotify Event " << mask << " on " << path;
// cancel close write events that come after create
if (lastMask == IN_CREATE && mask == IN_CLOSE_WRITE
&& lastPath == path ) {
@@ -187,10 +197,12 @@ void FolderWatcher::slotINotifyEvent(int mask, int cookie, const QString &path)
}
else if (mask & IN_DELETE) {
//qDebug() << cookie << " DELETE: " << path;
+#ifdef USE_WATCHER
if (_inotify->directories().contains(path) &&
QFileInfo(path).isDir());
qDebug() << "(-) Watcher:" << path;
_inotify->removePath(path);
+#endif
}
else if (mask & IN_CLOSE_WRITE) {
//qDebug() << cookie << " WRITABLE CLOSED: " << path;
diff --git a/src/mirall/folderwatcher.h b/src/mirall/folderwatcher.h
index a82ca23a7..27aa97997 100644
--- a/src/mirall/folderwatcher.h
+++ b/src/mirall/folderwatcher.h
@@ -22,8 +22,12 @@
#include <QTime>
#include <QHash>
+#include "mirall/folder.h"
+
class QTimer;
+#ifdef USE_WATCHER
class INotify;
+#endif
namespace Mirall {
@@ -112,8 +116,9 @@ protected slots:
private:
bool _eventsEnabled;
int _eventInterval;
-
+#ifdef USE_WATCHER
INotify *_inotify;
+#endif
QString _root;
// paths pending to notified
// QStringList _pendingPaths;
diff --git a/src/mirall/inotify.cpp b/src/mirall/inotify.cpp
index 83eb22d0d..7629d885a 100644
--- a/src/mirall/inotify.cpp
+++ b/src/mirall/inotify.cpp
@@ -27,7 +27,6 @@
#define DEFAULT_READ_BUFFERSIZE 2048
namespace Mirall {
-
// Allocate space for static members of class.
int INotify::s_fd;
INotify::INotifyThread* INotify::s_thread;
diff --git a/src/mirall/inotify.h b/src/mirall/inotify.h
index ceffe77ab..38337e979 100644
--- a/src/mirall/inotify.h
+++ b/src/mirall/inotify.h
@@ -73,7 +73,6 @@ private:
int _mask;
QMap<QString, int> _wds;
};
-
}
#endif
diff --git a/src/mirall/owncloudfolder.cpp b/src/mirall/owncloudfolder.cpp
index 86bcdf1e4..329835f30 100644
--- a/src/mirall/owncloudfolder.cpp
+++ b/src/mirall/owncloudfolder.cpp
@@ -40,18 +40,27 @@ ownCloudFolder::ownCloudFolder(const QString &alias,
, _lastWalkedFiles(-1)
{
- connect( _pollTimer, SIGNAL(timeout()), this, SLOT(slotPollTimerRemoteCheck()));
- qDebug() << "****** connect ownCloud Timer";
+#ifdef USE_WATCHER
+ setPollInterval( 15000 );
+ qDebug() << "****** ownCloud folder using watcher *******";
+#else
+ /* If local polling is used, the polltimer of class Folder has to fire more
+ * often
+ * Set a local poll time of 2000 milliseconds, which results in a 30 seconds
+ * remote poll interval, defined in slotPollTimerRemoteCheck
+ */
- // set a local poll time of 2000 milliseconds, which results in a 30 seconds
- // remote poll interval, defined in slotPollTimerRemoteCheck
+ connect( _pollTimer, SIGNAL(timeout()), this, SLOT(slotPollTimerRemoteCheck()));
setPollInterval( 2000 );
+ qDebug() << "****** ownCloud folder using local poll *******";
+#endif
}
ownCloudFolder::~ownCloudFolder()
{
}
+#ifndef USE_WATCHER
void ownCloudFolder::slotPollTimerRemoteCheck()
{
_localCheckOnly = true;
@@ -62,6 +71,7 @@ void ownCloudFolder::slotPollTimerRemoteCheck()
}
qDebug() << "**** CSyncFolder Poll Timer check: " << _pollTimerCnt << " - " << _localCheckOnly;
}
+#endif
bool ownCloudFolder::isBusy() const
{
@@ -110,6 +120,7 @@ void ownCloudFolder::slotCSyncFinished()
else
qDebug() << " * owncloud csync thread finished successfully";
+#ifndef USE_WATCHER
if( _csync->hasLocalChanges( _lastWalkedFiles ) ) {
qDebug() << "Last walked files: " << _lastWalkedFiles << " against " << _csync->walkedFiles();
qDebug() << "*** Local changes, lets do a full sync!" ;
@@ -121,10 +132,12 @@ void ownCloudFolder::slotCSyncFinished()
qDebug() << " *** Finalize, pollTimerCounter is "<< _pollTimerCnt ;
_lastWalkedFiles = _csync->walkedFiles();
// TODO delete thread
- emit syncFinished(_csync->error() ?
- SyncResult(SyncResult::Error)
- : SyncResult(SyncResult::Success));
}
+#endif
+ emit syncFinished(_csync->error() ?
+ SyncResult(SyncResult::Error)
+ : SyncResult(SyncResult::Success));
+
}
} // ns
diff --git a/src/mirall/owncloudfolder.h b/src/mirall/owncloudfolder.h
index 6b13b3d65..f67647782 100644
--- a/src/mirall/owncloudfolder.h
+++ b/src/mirall/owncloudfolder.h
@@ -45,8 +45,9 @@ public slots:
protected slots:
void slotCSyncStarted();
void slotCSyncFinished();
+#ifndef USE_WATCHER
void slotPollTimerRemoteCheck();
-
+#endif
private:
QString _secondPath;
CSyncThread *_csync;