diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 56d7b6ab8..7e45814d9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) diff --git a/src/mirall/csyncfolder.cpp b/src/mirall/csyncfolder.cpp index 4024c6ac6..3b65163b3 100644 --- a/src/mirall/csyncfolder.cpp +++ b/src/mirall/csyncfolder.cpp @@ -20,65 +20,11 @@ #include #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, diff --git a/src/mirall/csyncfolder.h b/src/mirall/csyncfolder.h index d1b318116..f4aa88bda 100644 --- a/src/mirall/csyncfolder.h +++ b/src/mirall/csyncfolder.h @@ -1,5 +1,9 @@ +#ifndef CSYNCFOLDER_H +#define CSYNCFOLDER_H + /* * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag * * 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 #include #include -#include +#include +#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); diff --git a/src/mirall/csyncthread.cpp b/src/mirall/csyncthread.cpp new file mode 100644 index 000000000..27c3b41bd --- /dev/null +++ b/src/mirall/csyncthread.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * + * 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 +#include +#include +#include +#include +#include + +#include +#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); +} + +} diff --git a/src/mirall/csyncthread.h b/src/mirall/csyncthread.h new file mode 100644 index 000000000..ffdc1ef70 --- /dev/null +++ b/src/mirall/csyncthread.h @@ -0,0 +1,48 @@ +#ifndef CSYNCTHREAD_H +#define CSYNCTHREAD_H + +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * + * 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 +#include +#include + +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