sync process now runs, but no synchronization between sync processes

This commit is contained in:
Duncan Mac-Vicar P 2011-03-25 18:25:56 +01:00
parent f31ddde36d
commit 64e4d531b3
5 changed files with 63 additions and 8 deletions

View file

@ -43,7 +43,7 @@ QString Folder::path() const
void Folder::slotChanged(const QStringList &pathList)
{
qDebug() << "Changed >> " << pathList;
startSync(pathList);
}
void Folder::slotOpenFolder()

View file

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

View file

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

View file

@ -1,6 +1,7 @@
#include <QDebug>
#include <QMutexLocker>
#include <QProcess>
#include <QStringList>
#include <QDir>
#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"

View file

@ -2,6 +2,9 @@
#define MIRALL_UNISONFOLDER_H
#include <QMutex>
#include <QProcess>
#include <QStringList>
#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;