This repository was archived by the owner on Mar 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdefaults.h
143 lines (120 loc) · 4.44 KB
/
defaults.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
#ifndef QTDATASYNC_DEFAULTS_H
#define QTDATASYNC_DEFAULTS_H
#include <QtCore/qglobal.h>
#include <QtCore/qobject.h>
#include <QtCore/qdir.h>
#include <QtCore/qsettings.h>
#include <QtCore/qloggingcategory.h>
#include <QtCore/qdebug.h>
#include <QtRemoteObjects/qremoteobjectnode.h>
#include "QtDataSync/qtdatasync_global.h"
#include "QtDataSync/exception.h"
#include "QtDataSync/setup.h"
class QSqlDatabase;
class QJsonSerializer;
namespace QtDataSync {
class Logger;
class Defaults;
class EmitterAdapter;
class DatabaseRefPrivate;
//! A wrapper around QSqlDatabase to manage the connections
class Q_DATASYNC_EXPORT DatabaseRef
{
Q_DISABLE_COPY(DatabaseRef)
public:
//! Default constructor. Constructs an invalid database reference
DatabaseRef();
~DatabaseRef();
//! @private
DatabaseRef(DatabaseRefPrivate *d);
//! Move constructor
DatabaseRef(DatabaseRef &&other) noexcept;
//! Move assignment operator
DatabaseRef &operator=(DatabaseRef &&other) noexcept;
//! Returns true if this reference points to a valid database
bool isValid() const;
//! Returns the database that is managed by this reference
QSqlDatabase database() const;
//! Implicit cast operator to the managed database
operator QSqlDatabase() const;
//! Arrow operator to access the database
QSqlDatabase *operator->() const;
//! Drops the reference to the database early
void drop();
private:
QScopedPointer<DatabaseRefPrivate> d;
};
class DefaultsPrivate;
//! A helper class to get defaults per datasync instance (threadsafe)
class Q_DATASYNC_EXPORT Defaults
{
Q_GADGET
friend class DefaultsPrivate;
public:
//! The keys of special properties set on the defaults
enum PropertyKey {
CacheSize, //!< @copybrief Setup::cacheSize
PersistDeleted, //!< @copybrief Setup::persistDeletedVersion
ConflictPolicy, //!< @copybrief Setup::syncPolicy
SslConfiguration, //!< @copybrief Setup::sslConfiguration
RemoteConfiguration, //!< @copybrief Setup::remoteConfiguration
KeyStoreProvider, //!< @copybrief Setup::keyStoreProvider
SignScheme, //!< @copybrief Setup::signatureScheme
SignKeyParam, //!< @copybrief Setup::signatureKeyParam
CryptScheme, //!< @copybrief Setup::encryptionScheme
CryptKeyParam, //!< @copybrief Setup::encryptionKeyParam
SymScheme, //!< @copybrief Setup::cipherScheme
SymKeyParam, //!< @copybrief Setup::cipherKeySize
EventLoggingMode //!< @copybrief Setup::eventLoggingMode
};
Q_ENUM(PropertyKey)
//! Default constructor. Constructs an invalid defaults object
Defaults();
//! @private
Defaults(const QSharedPointer<DefaultsPrivate> &d);
//! Copy constructor
Defaults(const Defaults &other);
//! Move constructor
Defaults(Defaults &&other) noexcept;
//! Copy assignment operator
Defaults &operator=(const Defaults &other);
//! Move assignment operator
Defaults &operator=(Defaults &&other) noexcept;
~Defaults();
//! Checks if the current defaults are valid. Default constructed defaults are invalid
bool isValid() const;
//! Drops the reference to the defaults early
void drop();
//! Create a new logger instance
Logger *createLogger(const QByteArray &subCategory, QObject *parent = nullptr) const;
//! Returns the name of the current setup
QString setupName() const;
//! Returns the storage directory
QDir storageDir() const;
//! Returns the url to use for the remote object connection
QUrl remoteAddress() const;
//! Returns the remote object node for the current thread to connect to the engine
QRemoteObjectNode *remoteNode() const;
//! Returns a new instance of QSettings for this setup
QSettings *createSettings(QObject *parent = nullptr, const QString &group = {}) const;
//! Returns the serializer of the current setup
const QJsonSerializer *serializer() const;
//! Returns the conflict resolver of the current setup
const ConflictResolver *conflictResolver() const;
//! Returns the extra property defined by the given key
QVariant property(PropertyKey key) const;
//! Returns the standard key parameter for the given signature scheme
static QVariant defaultParam(Setup::SignatureScheme scheme);
//! Returns the standard key parameter for the given encryption scheme
static QVariant defaultParam(Setup::EncryptionScheme scheme);
//! Aquire a reference to the standard sqlite database
DatabaseRef aquireDatabase(QObject *object) const;
//! @private
EmitterAdapter *createEmitter(QObject *parent = nullptr) const;
//! @private
QVariant cacheHandle() const;
private:
QSharedPointer<DefaultsPrivate> d;
};
}
#endif // QTDATASYNC_DEFAULTS_H