2011-03-25 20:25:56 +03:00
|
|
|
#include <QDebug>
|
2011-03-21 02:58:53 +03:00
|
|
|
#include <QMutexLocker>
|
|
|
|
#include <QStringList>
|
2011-03-25 20:25:56 +03:00
|
|
|
#include <QDir>
|
2011-03-21 02:58:53 +03:00
|
|
|
#include "mirall/unisonfolder.h"
|
|
|
|
|
|
|
|
namespace Mirall {
|
|
|
|
|
|
|
|
UnisonFolder::UnisonFolder(const QString &path, const QString &secondPath, QObject *parent)
|
|
|
|
: Folder(path, parent),
|
|
|
|
_unison(new QProcess(this)),
|
2011-03-31 10:19:04 +04:00
|
|
|
_secondPath(secondPath),
|
|
|
|
_syncCount(0)
|
2011-03-21 02:58:53 +03:00
|
|
|
{
|
2011-03-25 20:25:56 +03:00
|
|
|
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)));
|
2011-03-27 04:26:41 +04:00
|
|
|
|
2011-03-28 01:29:45 +04:00
|
|
|
QObject::connect(_unison, SIGNAL(started()),
|
|
|
|
SLOT(slotStarted()));
|
|
|
|
|
2011-03-27 04:26:41 +04:00
|
|
|
QObject::connect(_unison, SIGNAL(finished(int, QProcess::ExitStatus)),
|
|
|
|
SLOT(slotFinished(int, QProcess::ExitStatus)));
|
2011-03-21 02:58:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
UnisonFolder::~UnisonFolder()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-27 04:26:41 +04:00
|
|
|
bool UnisonFolder::isBusy() const
|
2011-03-23 01:03:43 +03:00
|
|
|
{
|
2011-03-27 04:26:41 +04:00
|
|
|
return (_unison->state() != QProcess::NotRunning);
|
2011-03-23 01:03:43 +03:00
|
|
|
}
|
|
|
|
|
2011-03-21 02:58:53 +03:00
|
|
|
QString UnisonFolder::secondPath() const
|
|
|
|
{
|
|
|
|
return _secondPath;
|
|
|
|
}
|
|
|
|
|
2011-03-25 20:25:56 +03:00
|
|
|
void UnisonFolder::startSync(const QStringList &pathList)
|
2011-03-21 02:58:53 +03:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&_syncMutex);
|
|
|
|
|
2011-03-27 04:26:41 +04:00
|
|
|
emit syncStarted();
|
|
|
|
|
2011-03-21 02:58:53 +03:00
|
|
|
QString program = "unison";
|
|
|
|
QStringList args;
|
|
|
|
args << "-ui" << "text";
|
|
|
|
args << "-auto" << "-batch";
|
2011-03-25 20:25:56 +03:00
|
|
|
|
2011-03-31 10:19:04 +04:00
|
|
|
//args << "-confirmbigdel";
|
|
|
|
|
|
|
|
// only use -path in after a full synchronization
|
|
|
|
// already happened, which we do only on the first
|
|
|
|
// sync when the program is started
|
|
|
|
if (_syncCount > 0 ) {
|
|
|
|
// may be we should use a QDir in the API itself?
|
|
|
|
QDir root(path());
|
|
|
|
foreach(QString changedPath, pathList) {
|
|
|
|
args << "-path" << root.relativeFilePath(changedPath);
|
|
|
|
}
|
2011-03-25 20:25:56 +03:00
|
|
|
}
|
|
|
|
|
2011-03-21 02:58:53 +03:00
|
|
|
args << path();
|
|
|
|
args << secondPath();
|
|
|
|
|
|
|
|
_unison->start(program, args);
|
2011-03-27 04:26:41 +04:00
|
|
|
}
|
2011-03-21 02:58:53 +03:00
|
|
|
|
2011-03-28 01:29:45 +04:00
|
|
|
void UnisonFolder::slotStarted()
|
|
|
|
{
|
|
|
|
qDebug() << " * Unison process started ( PID " << _unison->pid() << ")";
|
2011-03-31 10:19:04 +04:00
|
|
|
_syncCount++;
|
|
|
|
|
2011-03-28 01:29:45 +04:00
|
|
|
//qDebug() << _unison->readAllStandardOutput();;
|
|
|
|
}
|
|
|
|
|
2011-03-27 04:26:41 +04:00
|
|
|
void UnisonFolder::slotFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
|
|
|
{
|
2011-03-28 01:29:45 +04:00
|
|
|
qDebug() << " * Unison process finished with status" << exitCode;
|
2011-03-21 02:58:53 +03:00
|
|
|
emit syncFinished();
|
|
|
|
}
|
|
|
|
|
2011-03-25 20:25:56 +03:00
|
|
|
void UnisonFolder::slotReadyReadStandardOutput()
|
|
|
|
{
|
2011-04-04 13:36:44 +04:00
|
|
|
qDebug() << _unison->readAllStandardOutput();;
|
2011-03-25 20:25:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void UnisonFolder::slotReadyReadStandardError()
|
|
|
|
{
|
2011-03-28 01:29:45 +04:00
|
|
|
//qDebug() << _unison->readAllStandardError();;
|
2011-03-25 20:25:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void UnisonFolder::slotStateChanged(QProcess::ProcessState state)
|
|
|
|
{
|
2011-03-28 01:29:45 +04:00
|
|
|
//qDebug() << "changed: " << state;
|
2011-03-25 20:25:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void UnisonFolder::slotError(QProcess::ProcessError error)
|
|
|
|
{
|
2011-03-28 01:29:45 +04:00
|
|
|
//qDebug() << "error: " << error;
|
2011-03-25 20:25:56 +03:00
|
|
|
}
|
|
|
|
|
2011-03-21 02:58:53 +03:00
|
|
|
} // ns
|
|
|
|
|
|
|
|
#include "unisonfolder.moc"
|