2012-02-15 12:30:37 +04:00
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
|
2012-02-15 12:30:37 +04:00
|
|
|
#include <QMutex>
|
2014-02-05 23:18:03 +04:00
|
|
|
#include <QThread>
|
2012-02-15 12:30:37 +04:00
|
|
|
#include <QString>
|
2013-05-16 15:54:22 +04:00
|
|
|
#include <qelapsedtimer.h>
|
2012-02-15 12:30:37 +04:00
|
|
|
|
2012-04-14 14:16:30 +04:00
|
|
|
#include <csync.h>
|
2012-03-21 21:03:49 +04:00
|
|
|
|
2013-01-15 23:41:52 +04:00
|
|
|
#include "mirall/syncfileitem.h"
|
2013-07-05 20:46:43 +04:00
|
|
|
#include "mirall/progressdispatcher.h"
|
2014-03-26 21:06:25 +04:00
|
|
|
#include "mirall/utility.h"
|
2013-01-15 23:41:52 +04:00
|
|
|
|
2012-02-15 12:30:37 +04:00
|
|
|
class QProcess;
|
|
|
|
|
|
|
|
namespace Mirall {
|
|
|
|
|
2013-10-03 22:00:58 +04:00
|
|
|
class SyncJournalFileRecord;
|
|
|
|
|
|
|
|
class SyncJournalDb;
|
|
|
|
|
2013-05-16 15:54:22 +04:00
|
|
|
class OwncloudPropagator;
|
|
|
|
|
2014-04-25 01:57:42 +04:00
|
|
|
void OWNCLOUDSYNC_EXPORT csyncLogCatcher(int /*verbosity*/,
|
2013-09-24 17:56:03 +04:00
|
|
|
const char */*function*/,
|
|
|
|
const char *buffer,
|
|
|
|
void */*userdata*/);
|
2013-05-16 15:54:22 +04:00
|
|
|
|
2014-04-25 01:45:20 +04:00
|
|
|
class OWNCLOUDSYNC_EXPORT SyncEngine : public QObject
|
2012-02-15 12:30:37 +04:00
|
|
|
{
|
2012-03-21 21:03:49 +04:00
|
|
|
Q_OBJECT
|
2012-02-15 12:30:37 +04:00
|
|
|
public:
|
2014-03-17 14:34:51 +04:00
|
|
|
SyncEngine(CSYNC *, const QString &localPath, const QString &remoteURL, const QString &remotePath, SyncJournalDb *journal);
|
|
|
|
~SyncEngine();
|
2012-02-15 12:30:37 +04:00
|
|
|
|
2013-08-21 15:19:02 +04:00
|
|
|
static QString csyncErrorToString( CSYNC_STATUS);
|
2012-12-06 22:05:03 +04:00
|
|
|
|
2012-08-26 13:47:45 +04:00
|
|
|
Q_INVOKABLE void startSync();
|
2014-06-07 13:49:41 +04:00
|
|
|
void setNetworkLimits(int upload, int download);
|
2012-08-26 13:47:45 +04:00
|
|
|
|
2013-10-02 21:41:17 +04:00
|
|
|
/* Abort the sync. Called from the main thread */
|
|
|
|
void abort();
|
|
|
|
|
2014-03-28 12:39:32 +04:00
|
|
|
Utility::StopWatch &stopWatch() { return _stopWatch; }
|
2014-03-26 21:06:25 +04:00
|
|
|
|
2012-03-21 21:03:49 +04:00
|
|
|
signals:
|
2012-06-11 12:10:07 +04:00
|
|
|
void csyncError( const QString& );
|
2013-01-16 17:39:43 +04:00
|
|
|
void csyncUnavailable();
|
2014-03-14 17:08:32 +04:00
|
|
|
|
2014-03-27 20:04:31 +04:00
|
|
|
// before actual syncing (after update+reconcile) for each item
|
2014-03-27 18:19:02 +04:00
|
|
|
void syncItemDiscovered(const SyncFileItem&);
|
2014-03-27 20:04:31 +04:00
|
|
|
// after the above signals. with the items that actually need propagating
|
|
|
|
void aboutToPropagate(const SyncFileItemVector&);
|
2014-03-14 17:08:32 +04:00
|
|
|
|
2014-03-21 20:13:02 +04:00
|
|
|
// after each job (successful or not)
|
|
|
|
void jobCompleted(const SyncFileItem&);
|
|
|
|
|
2014-03-14 17:08:32 +04:00
|
|
|
// after sync is done
|
2013-01-15 23:41:52 +04:00
|
|
|
void treeWalkResult(const SyncFileItemVector&);
|
2012-06-11 12:10:07 +04:00
|
|
|
|
2014-03-14 21:43:23 +04:00
|
|
|
void transmissionProgress( const Progress::Info& progress );
|
2013-11-25 19:16:33 +04:00
|
|
|
|
2012-06-11 12:10:07 +04:00
|
|
|
void csyncStateDbFile( const QString& );
|
2012-06-25 16:18:13 +04:00
|
|
|
void wipeDb();
|
2012-03-13 20:37:43 +04:00
|
|
|
|
2012-08-26 13:47:45 +04:00
|
|
|
void finished();
|
|
|
|
void started();
|
|
|
|
|
2013-06-10 17:57:23 +04:00
|
|
|
void aboutToRemoveAllFiles(SyncFileItem::Direction direction, bool *cancel);
|
2013-06-08 17:40:45 +04:00
|
|
|
|
2013-05-16 15:54:22 +04:00
|
|
|
private slots:
|
2014-03-14 16:03:16 +04:00
|
|
|
void slotJobCompleted(const SyncFileItem& item);
|
2013-10-28 13:47:10 +04:00
|
|
|
void slotFinished();
|
2014-03-14 16:03:16 +04:00
|
|
|
void slotProgress(const SyncFileItem& item, quint64 curent);
|
|
|
|
void slotAdjustTotalTransmissionSize(qint64 change);
|
2014-02-05 23:18:03 +04:00
|
|
|
void slotUpdateFinished(int updateResult);
|
2013-05-16 15:54:22 +04:00
|
|
|
|
2012-02-15 12:30:37 +04:00
|
|
|
private:
|
2013-02-15 22:29:27 +04:00
|
|
|
void handleSyncError(CSYNC *ctx, const char *state);
|
2013-07-26 15:44:38 +04:00
|
|
|
|
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-11-20 16:44:01 +04:00
|
|
|
bool checkBlacklisting( SyncFileItem *item );
|
2013-01-15 23:41:52 +04:00
|
|
|
|
2014-05-20 14:28:55 +04:00
|
|
|
// cleanup and emit the finished signal
|
|
|
|
void finalize();
|
|
|
|
|
2014-05-29 13:34:25 +04:00
|
|
|
static bool _syncRunning; //true when one sync is running somewhere (for debugging)
|
2013-01-15 23:41:52 +04:00
|
|
|
SyncFileItemVector _syncedItems;
|
2013-05-03 21:11:00 +04:00
|
|
|
|
2013-04-20 14:15:27 +04:00
|
|
|
CSYNC *_csync_ctx;
|
2013-02-14 19:25:00 +04:00
|
|
|
bool _needsUpdate;
|
2013-05-03 21:11:00 +04:00
|
|
|
QString _localPath;
|
2014-02-17 20:31:03 +04:00
|
|
|
QString _remoteUrl;
|
2013-05-03 21:11:00 +04:00
|
|
|
QString _remotePath;
|
2013-10-03 22:00:58 +04:00
|
|
|
SyncJournalDb *_journal;
|
2013-05-16 15:54:22 +04:00
|
|
|
QScopedPointer <OwncloudPropagator> _propagator;
|
|
|
|
QString _lastDeleted; // if the last item was a path and it has been deleted
|
2013-11-11 14:11:45 +04:00
|
|
|
QHash <QString, QString> _seenFiles;
|
2014-02-05 23:18:03 +04:00
|
|
|
QThread _thread;
|
2013-05-16 15:54:22 +04:00
|
|
|
|
2014-03-14 16:03:16 +04:00
|
|
|
Progress::Info _progressInfo;
|
2013-02-15 22:29:27 +04:00
|
|
|
|
2014-03-26 21:06:25 +04:00
|
|
|
Utility::StopWatch _stopWatch;
|
|
|
|
|
2013-05-15 17:22:20 +04:00
|
|
|
// maps the origin and the target of the folders that have been renamed
|
|
|
|
QHash<QString, QString> _renamedFolders;
|
|
|
|
QString adjustRenamedPath(const QString &original);
|
|
|
|
|
2013-06-08 17:40:45 +04:00
|
|
|
bool _hasFiles; // true if there is at least one file that is not ignored or removed
|
2014-03-14 16:03:16 +04:00
|
|
|
|
2013-08-14 21:59:16 +04:00
|
|
|
int _downloadLimit;
|
|
|
|
int _uploadLimit;
|
2012-02-15 12:30:37 +04:00
|
|
|
};
|
2014-02-05 23:18:03 +04:00
|
|
|
|
|
|
|
|
2014-02-18 16:48:13 +04:00
|
|
|
class UpdateJob : public QObject {
|
2014-02-05 23:18:03 +04:00
|
|
|
Q_OBJECT
|
|
|
|
CSYNC *_csync_ctx;
|
2014-02-18 16:48:13 +04:00
|
|
|
csync_log_callback _log_callback;
|
|
|
|
int _log_level;
|
|
|
|
void* _log_userdata;
|
2014-02-05 23:18:03 +04:00
|
|
|
Q_INVOKABLE void start() {
|
2014-02-18 16:48:13 +04:00
|
|
|
csync_set_log_callback(_log_callback);
|
|
|
|
csync_set_log_level(_log_level);
|
|
|
|
csync_set_log_userdata(_log_userdata);
|
2014-02-05 23:18:03 +04:00
|
|
|
emit finished(csync_update(_csync_ctx));
|
|
|
|
deleteLater();
|
|
|
|
}
|
2014-02-18 16:48:13 +04:00
|
|
|
public:
|
|
|
|
explicit UpdateJob(CSYNC *ctx, QObject* parent = 0)
|
|
|
|
: QObject(parent), _csync_ctx(ctx) {
|
|
|
|
// We need to forward the log property as csync uses thread local
|
|
|
|
// and updates run in another thread
|
|
|
|
_log_callback = csync_get_log_callback();
|
|
|
|
_log_level = csync_get_log_level();
|
|
|
|
_log_userdata = csync_get_log_userdata();
|
|
|
|
}
|
2014-02-05 23:18:03 +04:00
|
|
|
signals:
|
|
|
|
void finished(int result);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-15 12:30:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // CSYNCTHREAD_H
|