QtDataSync
4.2.0
A simple offline-first synchronisation framework, to synchronize data of Qt applications between devices
|
Manages devices that belong to the users account. More...
#include <accountmanager.h>
Public Slots | |
void | listDevices () |
Sends a request to the server to list all devices that belong to the current account. More... | |
void | removeDevice (const QUuid &deviceInfo) |
Remove the device with the given id from the current account. More... | |
void | removeDevice (const QtDataSync::DeviceInfo &deviceInfo) |
Remove the given device from the current account. More... | |
void | resetAccount (bool keepData=true) |
Removes this device from the current account and then creates a new one. More... | |
void | changeRemote (const RemoteConfig &config, bool keepData=true) |
Resets the account and connects to the new remote to create a new one. More... | |
void | updateExchangeKey () |
Generate a new secret exchange key used to encrypt data. More... | |
void | setDeviceName (const QString &deviceName) |
WRITE accessor for AccountManager::deviceName. | |
void | resetDeviceName () |
RESET accessor for AccountManager::deviceName. | |
Signals | |
void | accountDevices (const QList< QtDataSync::DeviceInfo > &devices, QPrivateSignal) |
Is emitted when the accounts devices have been sent by the server. More... | |
void | loginRequested (QtDataSync::LoginRequest request, QPrivateSignal) |
Is emitted when another device requests permission to be added to the current account. More... | |
void | importAccepted (QPrivateSignal) |
Is emitted when the partner accept the account import. More... | |
void | accountAccessGranted (const QUuid &deviceId, QPrivateSignal) |
Is emitted when a device has been granted access to the current account. More... | |
QT_DATASYNC_REVISION_2 void | setupNameChanged (const QString &setupName, QPrivateSignal) |
NOTIFY accessor for AccountManager::setupName. | |
void | deviceNameChanged (const QString &deviceName, QPrivateSignal) |
NOTIFY accessor for AccountManager::deviceName. | |
void | deviceFingerprintChanged (const QByteArray &deviceFingerprint, QPrivateSignal) |
NOTIFY accessor for AccountManager::deviceFingerprint. | |
void | lastErrorChanged (const QString &lastError, QPrivateSignal) |
NOTIFY accessor for AccountManager::lastError. | |
Public Member Functions | |
AccountManager (QObject *parent=nullptr) | |
Default constructor, uses the default setup. More... | |
AccountManager (const QString &setupName, QObject *parent=nullptr) | |
Constructor with an explicit setup. More... | |
AccountManager (QRemoteObjectNode *node, QObject *parent=nullptr) | |
Constructor with a remote object node to connect to. More... | |
Q_INVOKABLE QRemoteObjectReplica * | replica () const |
The internal replica used to connect to the engine. More... | |
void | exportAccount (bool includeServer, const std::function< void(QJsonObject)> &completedFn, const std::function< void(QString)> &errorFn={}) |
Export the current account data as untrusted export. More... | |
void | exportAccount (bool includeServer, const std::function< void(QByteArray)> &completedFn, const std::function< void(QString)> &errorFn={}) |
Export the current account data as untrusted export. More... | |
void | exportAccountTrusted (bool includeServer, const QString &password, const std::function< void(QJsonObject)> &completedFn, const std::function< void(QString)> &errorFn={}) |
Export the current account data as trusted export. More... | |
void | exportAccountTrusted (bool includeServer, const QString &password, const std::function< void(QByteArray)> &completedFn, const std::function< void(QString)> &errorFn={}) |
Export the current account data as trusted export. More... | |
void | importAccount (const QJsonObject &importData, const std::function< void(bool, QString)> &completedFn, bool keepData=false) |
Import an account from the given untrusted export data. More... | |
void | importAccount (const QByteArray &importData, const std::function< void(bool, QString)> &completedFn, bool keepData=false) |
Import an account from the given untrusted export data. More... | |
void | importAccountTrusted (const QJsonObject &importData, const QString &password, const std::function< void(bool, QString)> &completedFn, bool keepData=false) |
Import an account from the given trusted export data. More... | |
void | importAccountTrusted (const QByteArray &importData, const QString &password, const std::function< void(bool, QString)> &completedFn, bool keepData=false) |
Import an account from the given trusted export data. More... | |
QString | setupName () const |
READ accessor for AccountManager::setupName. | |
QString | deviceName () const |
READ accessor for AccountManager::deviceName. | |
QByteArray | deviceFingerprint () const |
READ accessor for AccountManager::deviceFingerprint. | |
QString | lastError () const |
READ accessor for AccountManager::lastError. | |
Public Member Functions inherited from QObject | |
virtual const QMetaObject * | metaObject () const const |
virtual void * | qt_metacast (const char *) |
virtual int | qt_metacall (QMetaObject::Call, int, void **) |
QObject (QObject *parent) | |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
QString | objectName () const const |
void | setObjectName (const QString &name) |
bool | isWidgetType () const const |
bool | isWindowType () const const |
bool | signalsBlocked () const const |
bool | blockSignals (bool block) |
QThread * | thread () const const |
void | moveToThread (QThread *targetThread) |
int | startTimer (int interval, Qt::TimerType timerType) |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType) |
void | killTimer (int id) |
T | findChild (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegExp ®Exp, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
const QObjectList & | children () const const |
void | setParent (QObject *parent) |
void | installEventFilter (QObject *filterObj) |
void | removeEventFilter (QObject *obj) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const |
bool | disconnect (const char *signal, const QObject *receiver, const char *method) const const |
bool | disconnect (const QObject *receiver, const char *method) const const |
void | dumpObjectTree () |
void | dumpObjectInfo () |
void | dumpObjectTree () const const |
void | dumpObjectInfo () const const |
bool | setProperty (const char *name, const QVariant &value) |
QVariant | property (const char *name) const const |
QList< QByteArray > | dynamicPropertyNames () const const |
void | destroyed (QObject *obj) |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () const const |
bool | inherits (const char *className) const const |
void | deleteLater () |
Static Public Member Functions | |
static bool | isTrustedImport (const QJsonObject &importData) |
Checks if the given data is trusted or not. More... | |
static bool | isTrustedImport (const QByteArray &importData) |
Checks if the given data is trusted or not. More... | |
Static Public Member Functions inherited from QObject | |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
QString | trUtf8 (const char *sourceText, const char *disambiguation, int n) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, Functor functor) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
bool | disconnect (const QMetaObject::Connection &connection) |
bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
Properties | |
QString | setupName |
Holds the name of the setup this manager operates on. More... | |
QString | deviceName |
The display name of the device. More... | |
QByteArray | deviceFingerprint |
The fingerprint of the devices cryptographic keys. More... | |
QString | lastError |
The last internal error that occured. More... | |
Properties inherited from QObject | |
objectName | |
Additional Inherited Members | |
Protected Member Functions inherited from QObject | |
QObject * | sender () const const |
int | senderSignalIndex () const const |
int | receivers (const char *signal) const const |
bool | isSignalConnected (const QMetaMethod &signal) const const |
virtual void | timerEvent (QTimerEvent *event) |
virtual void | childEvent (QChildEvent *event) |
virtual void | customEvent (QEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
Manages devices that belong to the users account.
It can be used to list the devices that belong to the current account, remove device from the account and to export and import account data in order to add a new device to an existing account
The manager connects to the engine via a QRemoteObjectNode. Internally the class holds a replica of a source that is part of the datasync engine which is created by the setup. Typically, this node is managed by the setup too, but you can specify your own node in the constructor. In order to increase security and performance a special remote object connection is used that utilizes events to deliver messages within the same process only. See Threaded remote objects for details.
Definition at line 119 of file accountmanager.h.
|
explicit |
Default constructor, uses the default setup.
parent | The parent object |
SetupDoesNotExistException | Thrown if the default setup was not created yet |
|
explicit |
Constructor with an explicit setup.
setupName | The name of the setup to connect to |
parent | The parent object |
SetupDoesNotExistException | Thrown if the given setup was not created yet |
|
explicit |
Constructor with a remote object node to connect to.
node | The remote object node used to connect to the source objects |
parent | The parent object |
|
signal |
Is emitted when a device has been granted access to the current account.
deviceId | The device id of the device that has been granted access |
This is a private signal. It can be connect to as usual, but can only be emitted by the class it belongs to
Gets emitted when this device accepted the import of another device and sent it the secret keys. Gets only emitted for exports done by this device, not by other devices.
|
signal |
Is emitted when the accounts devices have been sent by the server.
devices | The devices that currently belong to the current account |
This is a private signal. It can be connect to as usual, but can only be emitted by the class it belongs to
The list does not contain this device, it only shows the other devices that belong to the same account as this one. Gets emitted as reply to listDevices(). In case removeDevice() gets called after listDevices() and the device removed was emitted via this signal, the new list without that device gets emittet as well.
|
slot |
Resets the account and connects to the new remote to create a new one.
config | The remote config to be used to connect to the new remote |
keepData | Specify whether the stored data should be preserved |
Disconnects you from the current remote, and then tries to connect to the new remote defined by the new config. This operation implicitly performs an account reset. See resetAccount() for more details.
QtDataSync::AccountManager::exportAccount | ( | bool | includeServer, |
const std::function< void(QJsonObject)> & | completedFn, | ||
const std::function< void(QString)> & | errorFn = {} |
||
) |
Export the current account data as untrusted export.
includeServer | Specify whether the server address and configuration should be included into the export data |
completedFn | A function that is called with the exported data as parameter |
errorFn | A function that is called if the export fails. |
Semantics of the completedFn
:
Semantics of the errorFn
:
The function initiates an asynchronous export of the user data. When is is finished, one of the two result functions is called on the AccountManagers thread. They are only called as long as the manager still exists.
The export is untrusted, which means a device that uses that data to add itself to the account will trigger the loginRequested() signal and must explicitly be accepted.
The includeServer
parameter can be set to true to include the servers address and configuration. This is needed in cases where the server data is not hard coded into the application (for example when the load balancer is used).
void QtDataSync::AccountManager::exportAccount | ( | bool | includeServer, |
const std::function< void(QByteArray)> & | completedFn, | ||
const std::function< void(QString)> & | errorFn = {} |
||
) |
Export the current account data as untrusted export.
includeServer | Specify whether the server address and configuration should be included into the export data |
completedFn | A function that is called with the exported data as parameter |
errorFn | A function that is called if the export fails. |
Semantics of the completedFn
:
Semantics of the errorFn
:
The function initiates an asynchronous export of the user data. When is is finished, one of the two result functions is called on the AccountManagers thread. They are only called as long as the manager still exists.
The export is untrusted, which means a device that uses that data to add itself to the account will trigger the loginRequested() signal and must explicitly be accepted.
The includeServer
parameter can be set to true to include the servers address and configuration. This is needed in cases where the server data is not hard coded into the application (for example when the load balancer is used).
QtDataSync::AccountManager::exportAccountTrusted | ( | bool | includeServer, |
const QString & | password, | ||
const std::function< void(QJsonObject)> & | completedFn, | ||
const std::function< void(QString)> & | errorFn = {} |
||
) |
Export the current account data as trusted export.
includeServer | Specify whether the server address and configuration should be included into the export data |
password | The password used to encrypt the exported data with |
completedFn | A function that is called with the exported data as parameter |
errorFn | A function that is called if the export fails. |
Semantics of the completedFn
:
Semantics of the errorFn
:
The function initiates an asynchronous export of the user data. When is is finished, one of the two result functions is called on the AccountManagers thread. They are only called as long as the manager still exists.
The export is trusted, which means that is encrypted with the given password and can only be import by someone who knows the password. Since the password serves as token of trust, no additional confirmation is needed. As soon as the partner requests to be added and can confirm he knows the shared password, the device is added to the account.
The includeServer
parameter can be set to true to include the servers address and configuration. This is needed in cases where the server data is not hard coded into the application (for example when the load balancer is used).
void QtDataSync::AccountManager::exportAccountTrusted | ( | bool | includeServer, |
const QString & | password, | ||
const std::function< void(QByteArray)> & | completedFn, | ||
const std::function< void(QString)> & | errorFn = {} |
||
) |
Export the current account data as trusted export.
includeServer | Specify whether the server address and configuration should be included into the export data |
password | The password used to encrypt the exported data with |
completedFn | A function that is called with the exported data as parameter |
errorFn | A function that is called if the export fails. |
Semantics of the completedFn
:
Semantics of the errorFn
:
The function initiates an asynchronous export of the user data. When is is finished, one of the two result functions is called on the AccountManagers thread. They are only called as long as the manager still exists.
The export is trusted, which means that is encrypted with the given password and can only be import by someone who knows the password. Since the password serves as token of trust, no additional confirmation is needed. As soon as the partner requests to be added and can confirm he knows the shared password, the device is added to the account.
The includeServer
parameter can be set to true to include the servers address and configuration. This is needed in cases where the server data is not hard coded into the application (for example when the load balancer is used).
|
signal |
Is emitted when the partner accept the account import.
This is a private signal. It can be connect to as usual, but can only be emitted by the class it belongs to
Gets emitted when an import completly succeeded, i.e. as soon as the device that export the data accept this device and shared the secret keys with it.
QtDataSync::AccountManager::importAccount | ( | const QJsonObject & | importData, |
const std::function< void(bool, QString)> & | completedFn, | ||
bool | keepData = false |
||
) |
Import an account from the given untrusted export data.
importData | The account data to be imported |
completedFn | A function that is called once the import has been finished |
keepData | Specify whether the stored data should be preserved |
Semantics of the completedFn
:
true
if the import was successful, false
if notThe function initiates an asynchronous import of the user data. When is is finished, the result functions is called on the AccountManagers thread. It is only called as long as the manager still exists.
The import is untrusted, which means that the device that created the export must explicitly accept this device to be added to the account.
If keepData
is false (the default), all local data is deleted before the import. This way only the data that already belongs to the account is imported. If true, the local data is kept and will be synchronized to the account as soon as access was granted.
void QtDataSync::AccountManager::importAccount | ( | const QByteArray & | importData, |
const std::function< void(bool, QString)> & | completedFn, | ||
bool | keepData = false |
||
) |
Import an account from the given untrusted export data.
importData | The account data to be imported |
completedFn | A function that is called once the import has been finished |
keepData | Specify whether the stored data should be preserved |
Semantics of the completedFn
:
true
if the import was successful, false
if notThe function initiates an asynchronous import of the user data. When is is finished, the result functions is called on the AccountManagers thread. It is only called as long as the manager still exists.
The import is untrusted, which means that the device that created the export must explicitly accept this device to be added to the account.
If keepData
is false (the default), all local data is deleted before the import. This way only the data that already belongs to the account is imported. If true, the local data is kept and will be synchronized to the account as soon as access was granted.
QtDataSync::AccountManager::importAccountTrusted | ( | const QJsonObject & | importData, |
const QString & | password, | ||
const std::function< void(bool, QString)> & | completedFn, | ||
bool | keepData = false |
||
) |
Import an account from the given trusted export data.
importData | The account data to be imported |
password | The password used to decrypt the imported data with. Must be the same as used for the export |
completedFn | A function that is called once the import has been finished |
keepData | Specify whether the stored data should be preserved |
Semantics of the completedFn
:
true
if the import was successful, false
if notThe function initiates an asynchronous import of the user data. When is is finished, the result functions is called on the AccountManagers thread. It is only called as long as the manager still exists.
The import is trusted, which means that as long as the password is correct and the export data still valid, the import will be accepted. Event though no confirmation is needed, the device that exported the data must still be connected.
If keepData
is false (the default), all local data is deleted before the import. This way only the data that already belongs to the account is imported. If true, the local data is kept and will be synchronized to the account as soon as access was granted.
void QtDataSync::AccountManager::importAccountTrusted | ( | const QByteArray & | importData, |
const QString & | password, | ||
const std::function< void(bool, QString)> & | completedFn, | ||
bool | keepData = false |
||
) |
Import an account from the given trusted export data.
importData | The account data to be imported |
password | The password used to decrypt the imported data with. Must be the same as used for the export |
completedFn | A function that is called once the import has been finished |
keepData | Specify whether the stored data should be preserved |
Semantics of the completedFn
:
true
if the import was successful, false
if notThe function initiates an asynchronous import of the user data. When is is finished, the result functions is called on the AccountManagers thread. It is only called as long as the manager still exists.
The import is trusted, which means that as long as the password is correct and the export data still valid, the import will be accepted. Event though no confirmation is needed, the device that exported the data must still be connected.
If keepData
is false (the default), all local data is deleted before the import. This way only the data that already belongs to the account is imported. If true, the local data is kept and will be synchronized to the account as soon as access was granted.
|
static |
Checks if the given data is trusted or not.
importData | The import data to be scanned for the trusted flag |
true
if the data is trusted, false
if notNo validity checks are performed. If the data is not valid, simply false
is returned
|
static |
Checks if the given data is trusted or not.
importData | The import data to be scanned for the trusted flag |
true
if the data is trusted, false
if notNo validity checks are performed. If the data is not valid, simply false
is returned
|
slot |
Sends a request to the server to list all devices that belong to the current account.
The request is processed asynchronously. As soon as the server replied, the accountDevices() signal is emitted with all the device that currently belong to the account except the current device that sent the request. This method will do nothing if the remote is not connected.
|
signal |
Is emitted when another device requests permission to be added to the current account.
request | The login request to be handeled |
This is a private signal. It can be connect to as usual, but can only be emitted by the class it belongs to
Gets emitted when a device imports untrusted account data that was exported from this device. Use the passed login request object to get more details about the device and to react to it.
|
slot |
Remove the device with the given id from the current account.
deviceInfo | The id of the device to be removed |
The device is deleted from the account and disconnected from the server if it was connected. This method cannot be used to remove the current device. Use resetAccount() instead. listDevices() was called before this method and the device was part of the account at that time, accountDevices() will be emitted again, now without the removed device. This method will do nothing if the remote is not connected.
|
inlineslot |
Remove the given device from the current account.
deviceInfo | The id of the device to be removed |
The device is deleted from the account and disconnected from the server if it was connected. This method cannot be used to remove the current device. Use resetAccount() instead. listDevices() was called before this method and the device was part of the account at that time, accountDevices() will be emitted again, now without the removed device. This method will do nothing if the remote is not connected.
Definition at line 181 of file accountmanager.h.
QtDataSync::AccountManager::replica | ( | ) | const |
The internal replica used to connect to the engine.
Returns a reference to the internally used replica which connects to the engine. The replica is only valid as long as the AccountManager exists. You can use the replica reference to get information about it's state etc.
|
slot |
Removes this device from the current account and then creates a new one.
keepData | Specify whether the stored data should be preserved |
If connected to the remote, this device is removed from the current account. If the device was the last device in the account, the account gets deleted as well. If the remote is not connected that step is not performed, and other devices will still see this one as part of their account.
Internally, all private encryption and signing keys are permanently deleted and new ones are created. The engine will reconnect to the server and register a completly new account with new ids.
If keepData
is false, all local data is deleted. This is basically a full reset. If it is true (the default) then all data is kept.
|
slot |
Generate a new secret exchange key used to encrypt data.
Generates a new exchange key and sends it to all devices of the current account. This key is used to verify that a device belongs to your account and to encrypt data between the devices. Thi method will do nothing if the remote is not connected.
|
read |
The fingerprint of the devices cryptographic keys.
Default: Derived from the public keys
The fingerprint is generated as Sha3 with a length of 256bit by hashing the public keys and schemes used. It should not be used to identify a device, but can be used to verify that the keys belong to a device.
Accessors | |
---|---|
READ | deviceFingerprint() |
NOTIFY | deviceFingerprintChanged() |
Definition at line 128 of file accountmanager.h.
|
readwrite |
The display name of the device.
Default: QSysInfo::machineHostName()
This name will be displayed on other devices as name for this device, in combination with the fingerprint.
Accessors | |
---|---|
READ | deviceName() |
WRITE | setDeviceName() |
RESET | resetDeviceName() |
NOTIFY | deviceNameChanged() |
Definition at line 126 of file accountmanager.h.
|
read |
The last internal error that occured.
Default: empty
The last error that happend internally. The returned string is a localized string ment to be displayed to a user. There is no need to log such an error, as interally the error has already been logged with even more details. Use this property to inform the user something went wrong.
Accessors | |
---|---|
READ | lastError() |
NOTIFY | lastErrorChanged() |
Definition at line 130 of file accountmanager.h.
|
read |
Holds the name of the setup this manager operates on.
Default: QtDataSync::DefaultSetup
The setup name is the name that was passed to the Setup::create method to create the datasync instance this manager is refering to.
Accessors | |
---|---|
READ | setupName() |
NOTIFY | setupNameChanged() |
REVISION | 2 |
Definition at line 124 of file accountmanager.h.