mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 09:30:13 +03:00
moved CsyncThread class to its own file
This commit is contained in:
parent
486bb0f5ef
commit
0c46382b6b
5 changed files with 142 additions and 84 deletions
|
@ -57,6 +57,8 @@ if(CSYNC_FOUND)
|
|||
set(mirall_SRCS
|
||||
${mirall_SRCS}
|
||||
mirall/csyncfolder.cpp
|
||||
mirall/owncloudfolder.cpp
|
||||
mirall/csyncthread.cpp
|
||||
)
|
||||
include_directories(${CSYNC_INCLUDE_DIR})
|
||||
endif(CSYNC_FOUND)
|
||||
|
|
|
@ -20,65 +20,11 @@
|
|||
#include <QTextStream>
|
||||
|
||||
#include "csync.h"
|
||||
|
||||
#include "mirall/csyncthread.h"
|
||||
#include "mirall/csyncfolder.h"
|
||||
|
||||
namespace Mirall {
|
||||
|
||||
CSyncThread::CSyncThread(const QString &source, const QString &target)
|
||||
: _source(source)
|
||||
, _target(target)
|
||||
, _error(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CSyncThread::~CSyncThread()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CSyncThread::error() const
|
||||
{
|
||||
return _error != 0;
|
||||
}
|
||||
|
||||
QMutex CSyncThread::_mutex;
|
||||
|
||||
void CSyncThread::run()
|
||||
{
|
||||
QMutexLocker locker(&_mutex);
|
||||
|
||||
CSYNC *csync;
|
||||
|
||||
_error = csync_create(&csync,
|
||||
_source.toLocal8Bit().data(),
|
||||
_target.toLocal8Bit().data());
|
||||
if (error())
|
||||
return;
|
||||
|
||||
#if LIBCSYNC_VERSION_INT >= CSYNC_VERSION_INT(0, 45, 0)
|
||||
csync_enable_conflictcopys(csync);
|
||||
#endif
|
||||
|
||||
_error = csync_init(csync);
|
||||
|
||||
if (error())
|
||||
goto cleanup;
|
||||
|
||||
_error = csync_update(csync);
|
||||
if (error())
|
||||
goto cleanup;
|
||||
|
||||
_error = csync_reconcile(csync);
|
||||
if (error())
|
||||
goto cleanup;
|
||||
|
||||
_error = csync_propagate(csync);
|
||||
cleanup:
|
||||
csync_destroy(csync);
|
||||
}
|
||||
|
||||
CSyncFolder::CSyncFolder(const QString &alias,
|
||||
const QString &path,
|
||||
const QString &secondPath,
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#ifndef CSYNCFOLDER_H
|
||||
#define CSYNCFOLDER_H
|
||||
|
||||
/*
|
||||
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
|
||||
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -12,47 +16,23 @@
|
|||
* for more details.
|
||||
*/
|
||||
|
||||
#ifndef MIRALL_CSYNCFOLDER_H
|
||||
#define MIRALL_CSYNCFOLDER_H
|
||||
|
||||
#include <QMutex>
|
||||
#include <QMutex>
|
||||
#include <QThread>
|
||||
#include <QStringList>
|
||||
#include <QString>
|
||||
|
||||
#include "mirall/csyncthread.h"
|
||||
#include "mirall/folder.h"
|
||||
|
||||
class QProcess;
|
||||
|
||||
namespace Mirall {
|
||||
|
||||
class CSyncThread : public QThread
|
||||
{
|
||||
public:
|
||||
CSyncThread(const QString &source, const QString &target);
|
||||
~CSyncThread();
|
||||
|
||||
virtual void run();
|
||||
|
||||
/**
|
||||
* true if last operation ended with error
|
||||
*/
|
||||
bool error() const;
|
||||
|
||||
private:
|
||||
static QMutex _mutex;
|
||||
QString _source;
|
||||
QString _target;
|
||||
int _error;
|
||||
};
|
||||
|
||||
class CSyncFolder : public Folder
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CSyncFolder(const QString &alias,
|
||||
const QString &path,
|
||||
const QString &secondPath, QObject *parent = 0L);
|
||||
CSyncFolder(const QString &alias,
|
||||
const QString &path,
|
||||
const QString &secondPath, QObject *parent = 0L);
|
||||
virtual ~CSyncFolder();
|
||||
QString secondPath() const;
|
||||
virtual void startSync(const QStringList &pathList);
|
||||
|
|
82
src/mirall/csyncthread.cpp
Normal file
82
src/mirall/csyncthread.cpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
|
||||
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QMutexLocker>
|
||||
#include <QThread>
|
||||
#include <QStringList>
|
||||
#include <QTextStream>
|
||||
|
||||
#include <csync.h>
|
||||
#include "mirall/csyncthread.h"
|
||||
|
||||
namespace Mirall {
|
||||
|
||||
CSyncThread::CSyncThread(const QString &source, const QString &target)
|
||||
: _source(source)
|
||||
, _target(target)
|
||||
, _error(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CSyncThread::~CSyncThread()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CSyncThread::error() const
|
||||
{
|
||||
return _error != 0;
|
||||
}
|
||||
|
||||
QMutex CSyncThread::_mutex;
|
||||
|
||||
void CSyncThread::run()
|
||||
{
|
||||
QMutexLocker locker(&_mutex);
|
||||
|
||||
CSYNC *csync;
|
||||
|
||||
_error = csync_create(&csync,
|
||||
_source.toLocal8Bit().data(),
|
||||
_target.toLocal8Bit().data());
|
||||
if (error())
|
||||
return;
|
||||
|
||||
#if LIBCSYNC_VERSION_INT >= CSYNC_VERSION_INT(0, 45, 0)
|
||||
csync_enable_conflictcopys(csync);
|
||||
#endif
|
||||
|
||||
_error = csync_init(csync);
|
||||
|
||||
if (error())
|
||||
goto cleanup;
|
||||
|
||||
_error = csync_update(csync);
|
||||
if (error())
|
||||
goto cleanup;
|
||||
|
||||
_error = csync_reconcile(csync);
|
||||
if (error())
|
||||
goto cleanup;
|
||||
|
||||
_error = csync_propagate(csync);
|
||||
cleanup:
|
||||
csync_destroy(csync);
|
||||
}
|
||||
|
||||
}
|
48
src/mirall/csyncthread.h
Normal file
48
src/mirall/csyncthread.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
#ifndef CSYNCTHREAD_H
|
||||
#define CSYNCTHREAD_H
|
||||
|
||||
/*
|
||||
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
|
||||
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <QMutex>
|
||||
#include <QThread>
|
||||
#include <QString>
|
||||
|
||||
class QProcess;
|
||||
|
||||
namespace Mirall {
|
||||
|
||||
class CSyncThread : public QThread
|
||||
{
|
||||
public:
|
||||
CSyncThread(const QString &source, const QString &target);
|
||||
~CSyncThread();
|
||||
|
||||
virtual void run();
|
||||
|
||||
/**
|
||||
* true if last operation ended with error
|
||||
*/
|
||||
bool error() const;
|
||||
|
||||
private:
|
||||
static QMutex _mutex;
|
||||
QString _source;
|
||||
QString _target;
|
||||
int _error;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CSYNCTHREAD_H
|
Loading…
Reference in a new issue