-
Notifications
You must be signed in to change notification settings - Fork 3
/
syncservice.h
132 lines (108 loc) · 2.59 KB
/
syncservice.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef SYNCSERVICE_H
#define SYNCSERVICE_H
#include <QObject>
#include <QSettings>
/**
* @brief Abstract class for synchronization service
*/
class SyncService : public QObject
{
Q_OBJECT
Q_PROPERTY(QString filePath READ getFilePath NOTIFY filePathChanged)
Q_PROPERTY(SyncState state READ getState NOTIFY stateChanged)
public:
/**
* @brief State of the file synchronization
*/
enum SyncState
{
UpToDate,
Updated,
Offline,
NotFound,
OutOfSync,
Failed
};
Q_ENUM(SyncState)
/**
* @brief Direction to synchronize
*/
enum SyncDirection
{
Download,
Upload
};
Q_ENUM(SyncDirection)
public:
/**
* @brief Abstract class for synchronization service
* @param settings Settings
*/
SyncService(QSettings *settings);
virtual ~SyncService();
/**
* @brief Gets the path to the local file
* @return Path
*/
QString getFilePath() const;
/**
* @brief Gets the state of the file synchronization
* @return State
*/
SyncState getState() const;
/**
* @brief Synchronizes the file
* @param direction Direction to synchronize
* @note See getState() for details about the synchronization state
* @return True on success
*/
virtual bool synchronize(SyncDirection direction) = 0;
/**
* @brief Clears the whole cache
* @note All local files will be deleted
*/
Q_INVOKABLE void clearCache();
signals:
/**
* @brief Signal to emit a messsage
* @param type Type
* @param txt Message
*/
void message(int type, const QString& txt);
/**
* @brief Signal when the file path changed
* @param filePath File path
*/
void filePathChanged(QString filePath);
/**
* @brief Signal when the state changed
* @param state State
*/
void stateChanged(SyncService::SyncState state);
protected:
/**
* @brief Sets the path to the local file
* @param filePath File path
*/
void setFilePath(const QString &filePath);
/**
* @brief Sets the state
* @param state State
*/
void setState(SyncState state);
/**
* @brief clearCachedSettings
*/
virtual void clearCachedSettings();
/**
* @brief Gets a path to store a file in the cache
* @param filePath File
* @return File path in the cache
*/
static QString cacheFilePath(const QString filePath);
QSettings* _settings;
private:
QString _filePath;
SyncState _state;
};
#endif // SYNCSERVICE_H