From 64e4d531b36380d74f7aa363df0bb64b32f3fb8c Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Fri, 25 Mar 2011 18:25:56 +0100 Subject: [PATCH] sync process now runs, but no synchronization between sync processes --- src/mirall/folder.cpp | 2 +- src/mirall/folder.h | 2 +- src/mirall/folderwatcher.h | 6 +++++ src/mirall/unisonfolder.cpp | 49 ++++++++++++++++++++++++++++++++++--- src/mirall/unisonfolder.h | 12 +++++++-- 5 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp index 06f46016a..0d711c0e9 100644 --- a/src/mirall/folder.cpp +++ b/src/mirall/folder.cpp @@ -43,7 +43,7 @@ QString Folder::path() const void Folder::slotChanged(const QStringList &pathList) { qDebug() << "Changed >> " << pathList; - + startSync(pathList); } void Folder::slotOpenFolder() diff --git a/src/mirall/folder.h b/src/mirall/folder.h index 841a72a28..fe8507813 100644 --- a/src/mirall/folder.h +++ b/src/mirall/folder.h @@ -30,7 +30,7 @@ public: * starts a sync operation * requests are serialized */ - virtual void startSync() = 0; + virtual void startSync(const QStringList &pathList) = 0; virtual bool isSyncing() const = 0; diff --git a/src/mirall/folderwatcher.h b/src/mirall/folderwatcher.h index c04f85fe3..35b75d5f0 100644 --- a/src/mirall/folderwatcher.h +++ b/src/mirall/folderwatcher.h @@ -15,6 +15,12 @@ namespace Mirall { /** * Watches a folder and sub folders for changes + * + * Will notify changed files relative to the root() + * directory. + * + * If too many changes happen in a short time interval, + * it will accumulate and be fired together later. */ class FolderWatcher : public QObject { diff --git a/src/mirall/unisonfolder.cpp b/src/mirall/unisonfolder.cpp index 409c68464..c1fa88e86 100644 --- a/src/mirall/unisonfolder.cpp +++ b/src/mirall/unisonfolder.cpp @@ -1,6 +1,7 @@ +#include #include -#include #include +#include #include "mirall/unisonfolder.h" namespace Mirall { @@ -10,6 +11,17 @@ UnisonFolder::UnisonFolder(const QString &path, const QString &secondPath, QObje _unison(new QProcess(this)), _secondPath(secondPath) { + QObject::connect(_unison, SIGNAL(readyReadStandardOutput()), + SLOT(slotReadyReadStandardOutput())); + + QObject::connect(_unison, SIGNAL(readyReadStandardError()), + SLOT(slotReadyReadStandardError())); + + QObject::connect(_unison, SIGNAL(stateChanged(QProcess::ProcessState)), + SLOT(slotStateChanged(QProcess::ProcessState))); + + QObject::connect(_unison, SIGNAL(error(QProcess::ProcessError)), + SLOT(slotError(QProcess::ProcessError))); } UnisonFolder::~UnisonFolder() @@ -26,7 +38,7 @@ QString UnisonFolder::secondPath() const return _secondPath; } -void UnisonFolder::startSync() +void UnisonFolder::startSync(const QStringList &pathList) { QMutexLocker locker(&_syncMutex); @@ -35,16 +47,45 @@ void UnisonFolder::startSync() args << "-ui" << "text"; args << "-auto" << "-batch"; args << "-confirmbigdel"; - //args << "-path"; + + // may be we should use a QDir in the API itself? + QDir root(path()); + foreach(QString changedPath, pathList) { + args << "-path" << root.relativeFilePath(changedPath); + } + args << path(); args << secondPath(); + emit syncStarted(); + _unison->start(program, args); - emit syncStarted(); emit syncFinished(); } +void UnisonFolder::slotReadyReadStandardOutput() +{ + qDebug() << _unison->readAllStandardOutput();; + +} + +void UnisonFolder::slotReadyReadStandardError() +{ + qDebug() << _unison->readAllStandardError();; + +} + +void UnisonFolder::slotStateChanged(QProcess::ProcessState state) +{ + qDebug() << "changed: " << state; +} + +void UnisonFolder::slotError(QProcess::ProcessError error) +{ + qDebug() << "error: " << error; +} + } // ns #include "unisonfolder.moc" diff --git a/src/mirall/unisonfolder.h b/src/mirall/unisonfolder.h index 6bd07234e..cdcf0b4cc 100644 --- a/src/mirall/unisonfolder.h +++ b/src/mirall/unisonfolder.h @@ -2,6 +2,9 @@ #define MIRALL_UNISONFOLDER_H #include +#include +#include + #include "mirall/folder.h" class QProcess; @@ -10,16 +13,21 @@ namespace Mirall { class UnisonFolder : public Folder { + Q_OBJECT public: UnisonFolder(const QString &path, const QString &secondPath, QObject *parent = 0L); virtual ~UnisonFolder(); QString secondPath() const; - virtual void startSync(); + virtual void startSync(const QStringList &pathList); virtual bool isSyncing() const; - +protected slots: + void slotReadyReadStandardOutput(); + void slotReadyReadStandardError(); + void slotStateChanged(QProcess::ProcessState); + void slotError(QProcess::ProcessError); private: QMutex _syncMutex; QProcess *_unison;