-
Notifications
You must be signed in to change notification settings - Fork 2
/
SyncManager.h
175 lines (143 loc) · 6.04 KB
/
SyncManager.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
===============================================================================
Copyright (C) 2022-2024 Ilya Lyakhovets
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 3 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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
===============================================================================
*/
#ifndef SYNCMANAGER_H
#define SYNCMANAGER_H
#include <QList>
#include <QSet>
#include <QMap>
#include <QQueue>
#include <QTimer>
#include <QDateTime>
#include "SyncFile.h"
#include "SyncFolder.h"
#include "SyncProfile.h"
#define DATA_FILENAME "Data.dat"
#define SYNC_MIN_DELAY 1000
#define NOTIFICATION_COOLDOWN 300000
#define MOVED_FILES_MIN_SIZE 0
/*
===========================================================
SyncManager
===========================================================
*/
class SyncManager : public QObject
{
Q_OBJECT
public:
enum SyncingMode
{
Automatic,
Manual
};
enum DeletionMode
{
MoveToTrash,
Versioning,
DeletePermanently
};
SyncManager();
~SyncManager();
void addToQueue(int profileNumber = -1);
void sync();
void updateTimer();
void updateStatus();
void updateNextSyncingTime();
void saveData() const;
void restoreData();
inline void setSyncingMode(SyncingMode mode) { m_syncingMode = mode; }
inline void setDeletionMode(DeletionMode mode) { m_deletionMode = mode; }
inline SyncingMode syncingMode() const { return m_syncingMode; }
inline DeletionMode deletionMode() const { return m_deletionMode; }
inline const QQueue<int> &queue() const { return m_queue; }
inline const QList<SyncProfile> &profiles() const { return m_profiles; }
inline QList<SyncProfile> &profiles() { return m_profiles; }
inline QTimer &syncTimer() { return m_syncTimer; }
inline void shouldQuit() { m_shouldQuit = true; }
inline void setSyncTimeMultiplier(int multiplier) { m_syncTimeMultiplier = multiplier; }
inline void setPaused(bool paused) { m_paused = paused; }
inline void setSyncHidden(bool hidden) { m_syncHidden = hidden; }
inline void enableNotifications(bool enable) { m_notifications = enable; }
inline void enableRememberFiles(bool enable) { m_rememberFiles = enable; }
inline void enableDetectMovedFiles(bool enable) { m_detectMovedFiles = enable; }
inline int filesToSync() const { return m_filesToSync; }
inline int syncTimeMultiplier() const { return m_syncTimeMultiplier; }
inline int syncEvery() const { return m_syncEvery; }
inline int existingProfiles() const { return m_existingProfiles; }
inline int movedFileMinSize() const { return m_movedFileMinSize; }
inline bool isCaseSensitiveSystem() const { return m_caseSensitiveSystem; }
inline bool isQuitting() const { return m_shouldQuit; }
inline bool isThereIssue() const { return m_issue; }
inline bool isThereWarning() const { return m_warning; }
inline bool isBusy() const { return m_busy; }
inline bool isPaused() const { return m_paused; }
inline bool isSyncing() const { return m_syncing; }
inline bool isSyncHidden() const { return m_syncHidden; }
inline bool notificationsEnabled() const { return m_notifications; }
inline bool rememberFilesEnabled() const { return m_rememberFiles; }
inline bool detectMovedFilesEnabled() const { return m_detectMovedFiles; }
inline const QString &versionFolder() const { return m_versionFolder; }
inline const QString &versionPattern() const { return m_versionPattern; }
Q_SIGNALS:
void warning(const QString &title, const QString &message);
void profileSynced(SyncProfile *profile);
private:
bool syncProfile(SyncProfile &profile);
int getListOfFiles(SyncFolder &folder, const QList<QByteArray> &excludeList);
void checkForRenamedFolders(SyncProfile &profile);
void checkForMovedFiles(SyncProfile &profile);
void checkForAddedFiles(SyncProfile &profile);
void checkForRemovedFiles(SyncProfile &profile);
void checkForChanges(SyncProfile &profile);
bool removeFile(SyncFolder &folder, const QString &path, const QString &fullPath, const QString &versioningPath, SyncFile::Type type);
void renameFolders(SyncFolder &folder);
void moveFiles(SyncFolder &folder);
void createParentFolders(SyncFolder &folder, QByteArray path);
void removeFolders(SyncFolder &folder, const QString &versioningPath);
void removeFiles(SyncFolder &folder, const QString &versioningPath);
void createFolders(SyncFolder &folder, const QString &versioningPath);
void copyFiles(SyncFolder &folder, const QString &versioningPath);
void syncFiles(SyncProfile &profile);
SyncingMode m_syncingMode;
DeletionMode m_deletionMode;
QQueue<int> m_queue;
QList<SyncProfile> m_profiles;
QTimer m_syncTimer;
int m_filesToSync = 0;
int m_syncTimeMultiplier = 1;
int m_syncEvery = 0;
int m_existingProfiles = 0;
int m_movedFileMinSize = 0;
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
bool m_caseSensitiveSystem = false;
#else
bool m_caseSensitiveSystem = true;
#endif
bool m_shouldQuit = false;
bool m_issue = true;
bool m_warning = false;
bool m_busy = false;
bool m_paused = false;
bool m_syncing = false;
bool m_syncHidden = false;
bool m_notifications = true;
bool m_rememberFiles = false;
bool m_detectMovedFiles = false;
QMap<QString, QTimer *> m_notificationList;
QSet<hash64_t> m_usedDevices;
QString m_versionFolder;
QString m_versionPattern;
};
#endif // SYNCMANAGER_H