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

unisonfolder.cpp « mirall « src - github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 828a1ce8a0d79cbf341a9f9ea6b8cf4b2e9a50d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <QDebug>
#include <QDir>
#include <QMutexLocker>
#include <QStringList>
#include <QTextStream>

#include "mirall/unisonfolder.h"

namespace Mirall {

UnisonFolder::UnisonFolder(const QString &path, const QString &secondPath, QObject *parent)
    : Folder(path, parent),
      _unison(new QProcess(this)),
      _secondPath(secondPath),
      _syncCount(0)
{
    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)));

    QObject::connect(_unison, SIGNAL(started()),
                     SLOT(slotStarted()));

    QObject::connect(_unison, SIGNAL(finished(int, QProcess::ExitStatus)),
                     SLOT(slotFinished(int, QProcess::ExitStatus)));
}

UnisonFolder::~UnisonFolder()
{
}

bool UnisonFolder::isBusy() const
{
    return (_unison->state() != QProcess::NotRunning);
}

QString UnisonFolder::secondPath() const
{
    return _secondPath;
}

void UnisonFolder::startSync(const QStringList &pathList)
{
    QMutexLocker locker(&_syncMutex);

    emit syncStarted();

    QString program = "unison";
    QStringList args;
    args << "-ui" << "text";
    args << "-auto" << "-batch";

    args << "-confirmbigdel=false";

    // 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);
        }
    }

    args  << path();
    args  << secondPath();

    qDebug() << "    * Unison: will use" << pathList.size() << "path arguments";
    _unison->start(program, args);
}

void UnisonFolder::slotStarted()
{
    qDebug() << "    * Unison process started ( PID " << _unison->pid() << ")";
    _syncCount++;

    //qDebug() << _unison->readAllStandardOutput();;
}

void UnisonFolder::slotFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
    qDebug() << "    * Unison process finished with status" << exitCode;

    //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();

    emit syncFinished();
}

void UnisonFolder::slotReadyReadStandardOutput()
{
    QTextStream stream(&_lastOutput);
    stream << _unison->readAllStandardOutput();;
}

void UnisonFolder::slotReadyReadStandardError()
{
    QTextStream stream(&_lastOutput);
    stream << _unison->readAllStandardError();;
}

void UnisonFolder::slotStateChanged(QProcess::ProcessState state)
{
    //qDebug() << "changed: " << state;
}

void UnisonFolder::slotError(QProcess::ProcessError error)
{
    //qDebug() << "error: " << error;
}

} // ns

#include "unisonfolder.moc"