2016-12-27 21:25:07 +01:00
|
|
|
#ifndef SYNCHRONIZER_H
|
|
|
|
#define SYNCHRONIZER_H
|
|
|
|
|
|
|
|
#include <stable.h>
|
|
|
|
#include "webapi.h"
|
|
|
|
#include "database.h"
|
2017-01-03 19:42:01 +01:00
|
|
|
#include "models/change.h"
|
2016-12-27 21:25:07 +01:00
|
|
|
|
|
|
|
namespace jop {
|
|
|
|
|
|
|
|
class Synchronizer : public QObject {
|
|
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-01-11 11:14:57 +01:00
|
|
|
enum SynchronizationState { Idle, UploadingChanges, DownloadingChanges, Aborting, Frozen };
|
2017-01-05 18:59:01 +01:00
|
|
|
|
2017-03-01 21:01:03 +00:00
|
|
|
Synchronizer();
|
2016-12-27 21:25:07 +01:00
|
|
|
void start();
|
2017-01-05 18:59:01 +01:00
|
|
|
void setSessionId(const QString& v);
|
2017-01-11 11:14:57 +01:00
|
|
|
void abort();
|
|
|
|
void freeze();
|
|
|
|
void unfreeze();
|
|
|
|
WebApi& api();
|
2016-12-27 21:25:07 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2017-01-03 19:42:01 +01:00
|
|
|
QUrlQuery valuesToUrlQuery(const QHash<QString, BaseModel::Value> &values) const;
|
2017-01-05 18:59:01 +01:00
|
|
|
WebApi api_;
|
|
|
|
SynchronizationState state_;
|
|
|
|
int uploadsRemaining_;
|
2017-01-09 12:13:58 +01:00
|
|
|
void checkNextState();
|
|
|
|
void switchState(SynchronizationState state);
|
2016-12-27 21:25:07 +01:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
|
|
|
void api_requestDone(const QJsonObject& response, const QString& tag);
|
|
|
|
|
2017-03-01 21:01:03 +00:00
|
|
|
signals:
|
|
|
|
|
|
|
|
void started();
|
|
|
|
void finished();
|
|
|
|
|
2016-12-27 21:25:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SYNCHRONIZER_H
|