2013-05-03 21:11:00 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Olivier Goffart <ogoffart@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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OWNCLOUDPROPAGATOR_H
|
|
|
|
#define OWNCLOUDPROPAGATOR_H
|
|
|
|
|
2013-05-05 13:41:31 +04:00
|
|
|
#include <neon/ne_request.h>
|
2013-05-15 17:22:20 +04:00
|
|
|
#include <QHash>
|
2013-05-16 15:54:22 +04:00
|
|
|
#include <QObject>
|
2013-08-14 21:59:16 +04:00
|
|
|
#include <qelapsedtimer.h>
|
2013-05-05 13:41:31 +04:00
|
|
|
|
2013-05-03 21:11:00 +04:00
|
|
|
#include "syncfileitem.h"
|
2013-08-14 21:59:16 +04:00
|
|
|
#include "progressdispatcher.h"
|
2013-05-03 21:11:00 +04:00
|
|
|
|
2013-10-16 18:47:24 +04:00
|
|
|
struct hbf_transfer_s;
|
2013-05-03 21:11:00 +04:00
|
|
|
struct ne_session_s;
|
|
|
|
struct ne_decompress_s;
|
|
|
|
|
|
|
|
namespace Mirall {
|
|
|
|
|
2013-10-16 13:59:54 +04:00
|
|
|
class SyncJournalDb;
|
2013-10-28 13:47:10 +04:00
|
|
|
class OwncloudPropagator;
|
2013-05-06 18:59:11 +04:00
|
|
|
|
2013-10-28 13:47:10 +04:00
|
|
|
class PropagatorJob : public QObject {
|
2013-05-16 15:54:22 +04:00
|
|
|
Q_OBJECT
|
2013-10-28 13:47:10 +04:00
|
|
|
protected:
|
|
|
|
OwncloudPropagator *_propagator;
|
|
|
|
public:
|
|
|
|
explicit PropagatorJob(OwncloudPropagator* propagator) : _propagator(propagator) {}
|
2014-01-07 18:42:21 +04:00
|
|
|
|
2013-10-28 13:47:10 +04:00
|
|
|
public slots:
|
|
|
|
virtual void start() = 0;
|
|
|
|
signals:
|
|
|
|
void finished(SyncFileItem::Status);
|
|
|
|
void completed(const SyncFileItem &);
|
2013-11-25 19:16:33 +04:00
|
|
|
void progress(Progress::Kind, const SyncFileItem& item, quint64 bytes, quint64 total);
|
2013-10-28 13:47:10 +04:00
|
|
|
};
|
2013-05-16 15:54:22 +04:00
|
|
|
|
2013-10-28 13:47:10 +04:00
|
|
|
/*
|
|
|
|
* Propagate a directory, and all its sub entries.
|
|
|
|
*/
|
|
|
|
class PropagateDirectory : public PropagatorJob {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
// e.g: create the directory
|
|
|
|
QScopedPointer<PropagatorJob>_firstJob;
|
2013-05-03 21:11:00 +04:00
|
|
|
|
2013-10-28 13:47:10 +04:00
|
|
|
// all the sub files or sub directories.
|
|
|
|
//TODO: in the future, all sub job can be run in parallel
|
|
|
|
QVector<PropagatorJob *> _subJobs;
|
2013-05-16 16:50:36 +04:00
|
|
|
|
2013-11-14 16:47:43 +04:00
|
|
|
SyncFileItem _item;
|
|
|
|
|
2013-10-28 13:47:10 +04:00
|
|
|
int _current; // index of the current running job
|
2013-11-28 13:00:12 +04:00
|
|
|
SyncFileItem::Status _hasError; // NoStatus, or NormalError / SoftError if there was an error
|
2013-05-03 21:11:00 +04:00
|
|
|
|
|
|
|
|
2013-10-28 13:47:10 +04:00
|
|
|
explicit PropagateDirectory(OwncloudPropagator *propagator, const SyncFileItem &item = SyncFileItem())
|
|
|
|
: PropagatorJob(propagator)
|
2013-11-28 13:00:12 +04:00
|
|
|
, _firstJob(0), _item(item), _current(-1), _hasError(SyncFileItem::NoStatus) { }
|
2013-10-28 13:47:10 +04:00
|
|
|
|
|
|
|
virtual ~PropagateDirectory() {
|
|
|
|
qDeleteAll(_subJobs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void append(PropagatorJob *subJob) {
|
|
|
|
_subJobs.append(subJob);
|
|
|
|
}
|
|
|
|
|
2013-11-15 20:42:27 +04:00
|
|
|
virtual void start();
|
|
|
|
|
2013-05-04 17:32:11 +04:00
|
|
|
|
2013-10-28 13:47:10 +04:00
|
|
|
private slots:
|
|
|
|
void startJob(PropagatorJob *next) {
|
|
|
|
connect(next, SIGNAL(finished(SyncFileItem::Status)), this, SLOT(proceedNext(SyncFileItem::Status)), Qt::QueuedConnection);
|
|
|
|
connect(next, SIGNAL(completed(SyncFileItem)), this, SIGNAL(completed(SyncFileItem)));
|
2013-11-25 19:16:33 +04:00
|
|
|
connect(next, SIGNAL(progress(Progress::Kind,SyncFileItem,quint64,quint64)), this, SIGNAL(progress(Progress::Kind,SyncFileItem,quint64,quint64)));
|
2013-10-28 13:47:10 +04:00
|
|
|
next->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void proceedNext(SyncFileItem::Status status);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Abstract class to propagate a single item
|
|
|
|
*/
|
|
|
|
class PropagateItemJob : public PropagatorJob {
|
|
|
|
Q_OBJECT
|
|
|
|
protected:
|
2013-11-20 17:02:19 +04:00
|
|
|
void done(SyncFileItem::Status status, const QString &errorString = QString());
|
2013-10-28 13:47:10 +04:00
|
|
|
|
|
|
|
void updateMTimeAndETag(const char *uri, time_t);
|
2013-10-25 15:29:20 +04:00
|
|
|
|
2013-10-04 17:13:36 +04:00
|
|
|
/* fetch the error code and string from the session
|
2013-10-28 13:47:10 +04:00
|
|
|
in case of error, calls done with the error and returns true.
|
|
|
|
|
|
|
|
If the HTTP error code is ignoreHTTPError, the error is ignored
|
2013-10-04 17:13:36 +04:00
|
|
|
*/
|
2013-10-28 13:47:10 +04:00
|
|
|
bool updateErrorFromSession(int neon_code = 0, ne_request *req = 0, int ignoreHTTPError = 0);
|
2013-05-03 21:11:00 +04:00
|
|
|
|
2013-10-28 13:47:10 +04:00
|
|
|
/*
|
|
|
|
* to be called by the progress callback and will wait the amount of time needed.
|
|
|
|
*/
|
|
|
|
void limitBandwidth(qint64 progress, qint64 limit);
|
|
|
|
|
2013-11-20 17:02:19 +04:00
|
|
|
QElapsedTimer _lastTime;
|
|
|
|
qint64 _lastProgress;
|
2013-11-20 17:02:02 +04:00
|
|
|
int _httpStatusCode;
|
2013-11-20 17:02:19 +04:00
|
|
|
SyncFileItem _item;
|
2013-10-28 13:47:10 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
PropagateItemJob(OwncloudPropagator* propagator, const SyncFileItem &item)
|
2013-11-20 17:02:02 +04:00
|
|
|
: PropagatorJob(propagator), _lastProgress(0), _httpStatusCode(0), _item(item) {}
|
2013-10-28 13:47:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Dummy job that just mark it as completed and ignored.
|
|
|
|
class PropagateIgnoreJob : public PropagateItemJob {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
PropagateIgnoreJob(OwncloudPropagator* propagator,const SyncFileItem& item)
|
|
|
|
: PropagateItemJob(propagator, item) {}
|
|
|
|
void start() {
|
|
|
|
done(SyncFileItem::FileIgnored);
|
|
|
|
}
|
|
|
|
};
|
2013-08-14 21:59:16 +04:00
|
|
|
|
2013-10-04 17:13:36 +04:00
|
|
|
|
2013-10-28 13:47:10 +04:00
|
|
|
class OwncloudPropagator : public QObject {
|
|
|
|
Q_OBJECT
|
2013-08-14 21:59:16 +04:00
|
|
|
|
2013-10-28 13:47:10 +04:00
|
|
|
PropagateItemJob *createJob(const SyncFileItem& item);
|
|
|
|
QScopedPointer<PropagateDirectory> _rootJob;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ne_session_s *_session;
|
|
|
|
QString _localDir; // absolute path to the local directory. ends with '/'
|
|
|
|
QString _remoteDir; // path to the root of the remote. ends with '/'
|
|
|
|
SyncJournalDb *_journal;
|
2013-10-16 18:47:24 +04:00
|
|
|
|
2013-05-03 21:11:00 +04:00
|
|
|
public:
|
2013-08-14 16:59:32 +04:00
|
|
|
OwncloudPropagator(ne_session_s *session, const QString &localDir, const QString &remoteDir,
|
2013-10-16 13:59:54 +04:00
|
|
|
SyncJournalDb *progressDb, QAtomicInt *abortRequested)
|
2013-08-14 16:59:32 +04:00
|
|
|
: _session(session)
|
2013-05-03 21:11:00 +04:00
|
|
|
, _localDir(localDir)
|
2013-08-14 16:59:32 +04:00
|
|
|
, _remoteDir(remoteDir)
|
2013-10-16 13:59:54 +04:00
|
|
|
, _journal(progressDb)
|
2013-10-02 21:41:17 +04:00
|
|
|
, _abortRequested(abortRequested)
|
2013-05-08 15:30:30 +04:00
|
|
|
{
|
2013-08-14 16:59:32 +04:00
|
|
|
if (!localDir.endsWith(QChar('/'))) _localDir+='/';
|
|
|
|
if (!remoteDir.endsWith(QChar('/'))) _remoteDir+='/';
|
2013-05-03 21:11:00 +04:00
|
|
|
}
|
2013-10-28 13:47:10 +04:00
|
|
|
|
|
|
|
void start(const SyncFileItemVector &_syncedItems);
|
2013-05-16 15:54:22 +04:00
|
|
|
|
2013-08-14 21:59:16 +04:00
|
|
|
int _downloadLimit;
|
|
|
|
int _uploadLimit;
|
|
|
|
|
2013-10-02 21:41:17 +04:00
|
|
|
QAtomicInt *_abortRequested; // boolean set by the main thread to abort.
|
|
|
|
|
2014-01-07 18:42:21 +04:00
|
|
|
void overallTransmissionSizeChanged( qint64 change );
|
|
|
|
|
2013-05-16 15:54:22 +04:00
|
|
|
signals:
|
2013-10-04 17:13:36 +04:00
|
|
|
void completed(const SyncFileItem &);
|
2013-11-25 19:16:33 +04:00
|
|
|
void progress(Progress::Kind kind, const SyncFileItem&, quint64 bytes, quint64 total);
|
2014-01-07 18:42:21 +04:00
|
|
|
void progressChanged(qint64 change);
|
2013-10-28 13:47:10 +04:00
|
|
|
void finished();
|
2013-11-25 01:26:50 +04:00
|
|
|
|
2013-05-03 21:11:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|