nextcloud-desktop/src/mirall/csyncthread.h

129 lines
3.5 KiB
C
Raw Normal View History

/*
* 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.
*/
2013-02-13 20:13:25 +04:00
#ifndef CSYNCTHREAD_H
#define CSYNCTHREAD_H
2012-03-01 19:11:56 +04:00
#include <stdint.h>
#include <QMutex>
#include <QThread>
#include <QString>
2013-05-16 15:54:22 +04:00
#include <qelapsedtimer.h>
#include <QNetworkProxy>
#include <QNetworkCookie>
2012-04-14 14:16:30 +04:00
#include <csync.h>
2013-01-15 23:41:52 +04:00
#include "mirall/syncfileitem.h"
2013-05-16 15:54:22 +04:00
#include "progressdatabase.h"
#include "mirall/progressdispatcher.h"
2013-01-15 23:41:52 +04:00
class QProcess;
2013-08-21 17:29:04 +04:00
Q_DECLARE_METATYPE(CSYNC_STATUS)
namespace Mirall {
2013-05-16 15:54:22 +04:00
class OwncloudPropagator;
2013-09-24 17:56:03 +04:00
void csyncLogCatcher(int /*verbosity*/,
const char */*function*/,
const char *buffer,
void */*userdata*/);
2013-05-16 15:54:22 +04:00
class CSyncThread : public QObject
{
Q_OBJECT
// Keep the actions that have been performed, in order to update the db
struct Action {
QByteArray etag;
csync_instructions_e instruction;
};
QHash<QByteArray, Action> _performedActions;
public:
CSyncThread(CSYNC *, const QString &localPath, const QString &remotePath);
~CSyncThread();
static QString csyncErrorToString( CSYNC_STATUS);
Q_INVOKABLE void startSync();
signals:
void csyncError( const QString& );
void csyncWarning( const QString& );
void csyncUnavailable();
2013-01-15 23:41:52 +04:00
void treeWalkResult(const SyncFileItemVector&);
void transmissionProgress( const Progress::Info& progress );
void csyncStateDbFile( const QString& );
void wipeDb();
void finished();
void started();
void aboutToRemoveAllFiles(SyncFileItem::Direction direction, bool *cancel);
2013-05-16 15:54:22 +04:00
private slots:
2013-08-21 17:29:04 +04:00
void transferCompleted(const SyncFileItem& item, CSYNC_STATUS error);
2013-05-16 15:54:22 +04:00
void startNextTransfer();
2013-08-14 21:59:16 +04:00
void slotProgress(Progress::Kind kind, const QString& file, quint64, quint64);
2013-05-16 15:54:22 +04:00
private:
void handleSyncError(CSYNC *ctx, const char *state);
2013-01-15 23:41:52 +04:00
static int treewalkLocal( TREE_WALK_FILE*, void *);
static int treewalkRemote( TREE_WALK_FILE*, void *);
int treewalkFile( TREE_WALK_FILE*, bool );
2013-05-04 17:32:11 +04:00
int treewalkFinalize( TREE_WALK_FILE* );
2013-01-15 23:41:52 +04:00
Progress::Kind csyncToProgressKind( enum csync_notify_type_e kind );
2013-01-15 23:41:52 +04:00
static int walkFinalize(TREE_WALK_FILE*, void* );
static QMutex _mutex;
static QMutex _syncMutex;
2013-01-15 23:41:52 +04:00
SyncFileItemVector _syncedItems;
2013-05-16 15:54:22 +04:00
int _iterator; // index in _syncedItems for the next item to process.
ProgressDatabase _progressDataBase;
2013-01-15 23:41:52 +04:00
CSYNC *_csync_ctx;
bool _needsUpdate;
QString _localPath;
QString _remotePath;
2013-05-16 15:54:22 +04:00
QScopedPointer <OwncloudPropagator> _propagator;
QElapsedTimer _syncTime;
QString _lastDeleted; // if the last item was a path and it has been deleted
// maps the origin and the target of the folders that have been renamed
QHash<QString, QString> _renamedFolders;
QString adjustRenamedPath(const QString &original);
bool _hasFiles; // true if there is at least one file that is not ignored or removed
2013-08-14 21:59:16 +04:00
Progress::Info _progressInfo;
int _downloadLimit;
int _uploadLimit;
2013-07-30 16:53:42 +04:00
friend struct CSyncRunScopeHelper;
};
}
#endif // CSYNCTHREAD_H