-
Notifications
You must be signed in to change notification settings - Fork 1
/
synctask.h
83 lines (67 loc) · 2.19 KB
/
synctask.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
#ifndef SYNCTASK_H
#define SYNCTASK_H
#include <QDateTime>
#include <QDir>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QStandardPaths>
#include <QString>
#include "qcontainerfwd.h"
#include "cosclient.h"
//声明友元类
class SyncCore;
class SyncTaskDatabaseManager;
class User;
class SyncTask
{
private:
//A local path to a dir
int id;
QDir localPath;
QString remotePath;
int syncStatus; //1 for upload/download,2 for only upload,3 for only download. -1 for paused
//lastSyncTime, use Qt::currentDateTime() to get the current time
QDateTime lastSyncTime=QDateTime::fromString("2000-01-01 00:00:00","yyyy-MM-dd hh:mm:ss");
public:
SyncTask(QString localPath, QString remotePath, int syncStatus, int id=-1);
SyncTask(const SyncTask &task){
localPath = task.localPath;
remotePath = task.remotePath;
syncStatus = task.syncStatus;
lastSyncTime = task.lastSyncTime;
id = task.id;
}
COSClient* cosclient;
QString getLocalPath() const { return localPath.absolutePath(); }
QString getRemotePath() const { return remotePath; }
int getId() const { return id; }
int getSyncStatus() const { return syncStatus; }
void setSyncStatus(int status) { syncStatus = status; }
void setId(int _id) { id = _id; }
QDateTime getLastSyncTime() const { return lastSyncTime; }
void setLastSyncTime(QDateTime time) { lastSyncTime = time; }
friend class SyncTaskDatabaseManager;
friend class SyncCore;
};
class SyncTaskDatabaseManager
{
public:
SyncTaskDatabaseManager(User* u);
int addTask(const SyncTask &task);
bool deleteTask(int id);
bool updateTask(const SyncTask &task);
bool deleteATask(const SyncTask &task);
bool queryTask(const SyncTask &task);
void updateTaskStatus(int id, int status);
void updateTaskTime(int id, QDateTime time);
void updateTaskRemotePath(int id, QString remotePath);
void updateTaskLocalPath(int id, QString localPath);
SyncTask getTaskById(int id);
QList<SyncTask> getTasks();
~SyncTaskDatabaseManager() { db.close(); }
private:
void initializeDatabase(QString name);
QSqlDatabase db;
};
#endif // SYNCTASK_H