2011-04-06 13:48:02 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
2011-03-25 20:25:56 +03:00
|
|
|
#include <QDebug>
|
2011-04-04 20:41:14 +04:00
|
|
|
#include <QDir>
|
2011-03-21 02:58:53 +03:00
|
|
|
#include <QMutexLocker>
|
|
|
|
#include <QStringList>
|
2011-04-04 20:41:14 +04:00
|
|
|
#include <QTextStream>
|
|
|
|
|
2011-03-21 02:58:53 +03:00
|
|
|
#include "mirall/unisonfolder.h"
|
|
|
|
|
|
|
|
namespace Mirall {
|
|
|
|
|
2011-04-06 11:52:02 +04:00
|
|
|
UnisonFolder::UnisonFolder(const QString &alias,
|
|
|
|
const QString &path,
|
|
|
|
const QString &secondPath,
|
|
|
|
QObject *parent)
|
|
|
|
: Folder(alias, path, parent),
|
2011-03-21 02:58:53 +03:00
|
|
|
_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-04-04 20:41:14 +04:00
|
|
|
args << "-confirmbigdel=false";
|
2011-03-31 10:19:04 +04:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
2011-04-04 20:41:14 +04:00
|
|
|
qDebug() << " * Unison: will use" << pathList.size() << "path arguments";
|
2011-03-21 02:58:53 +03:00
|
|
|
_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-04-04 20:41:14 +04:00
|
|
|
|
|
|
|
//if (exitCode != 0) {
|
|
|
|
qDebug() << _lastOutput;
|
|
|
|
//}
|
|
|
|
|
|
|
|
// parse a summary from here:
|
|
|
|
//[BGN] Copying zw.png from //piscola//space/store/folder1 to /space/mirall/folder1
|
|
|
|
//[BGN] Deleting gn.png from /space/mirall/folder1
|
|
|
|
//[END] Deleting gn.png
|
|
|
|
|
|
|
|
// from stderr:
|
|
|
|
//Reconciling changes
|
|
|
|
// <---- new file Package.h
|
|
|
|
|
|
|
|
_lastOutput.clear();
|
|
|
|
|
2011-04-08 13:36:53 +04:00
|
|
|
emit syncFinished((exitCode != 0) ?
|
|
|
|
SyncResult(SyncResult::Error)
|
|
|
|
: SyncResult(SyncResult::Success));
|
2011-03-21 02:58:53 +03:00
|
|
|
}
|
|
|
|
|
2011-03-25 20:25:56 +03:00
|
|
|
void UnisonFolder::slotReadyReadStandardOutput()
|
|
|
|
{
|
2011-04-04 20:41:14 +04:00
|
|
|
QTextStream stream(&_lastOutput);
|
|
|
|
stream << _unison->readAllStandardOutput();;
|
2011-03-25 20:25:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void UnisonFolder::slotReadyReadStandardError()
|
|
|
|
{
|
2011-04-04 20:41:14 +04:00
|
|
|
QTextStream stream(&_lastOutput);
|
|
|
|
stream << _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"
|