QtDataSync
4.2.0
A simple offline-first synchronisation framework, to synchronize data of Qt applications between devices
|
A helper class to exchange the account data between devices on the local network. More...
#include <userexchangemanager.h>
Public Slots | |
bool | startExchange (quint16 port=DataExchangePort) |
Start the exchange discovery on the specified port. More... | |
bool | startExchange (const QHostAddress &listenAddress, quint16 port=DataExchangePort) |
Start the exchange discovery on the specified address and port. More... | |
void | stopExchange () |
Stops the exchange discovery. More... | |
Signals | |
void | userDataReceived (const QtDataSync::UserInfo &userInfo, bool trusted, QPrivateSignal) |
Is emitted, when a user identity was received from the given user. More... | |
void | exchangeError (const QString &errorString, QPrivateSignal) |
Is emitted when an error occured trying to export or import. More... | |
QT_DATASYNC_REVISION_2 void | setupNameChanged (const QString &setupName, QPrivateSignal) |
NOTIFY accessor for UserInfo::setupName. | |
void | activeChanged (bool active, QPrivateSignal) |
NOTIFY accessor for UserInfo::active. | |
void | devicesChanged (QList< QtDataSync::UserInfo > devices, QPrivateSignal) |
NOTIFY accessor for UserInfo::users. | |
Public Member Functions | |
UserExchangeManager (QObject *parent=nullptr) | |
Default constructor, uses the default setup. More... | |
UserExchangeManager (const QString &setupName, QObject *parent=nullptr) | |
Constructor with an explicit setup. More... | |
UserExchangeManager (AccountManager *manager, QObject *parent=nullptr) | |
Constructor with an account manager to use for account import and export. More... | |
AccountManager * | accountManager () const |
The internally used account manager used to export and import data. More... | |
QString | setupName () const |
NOTIFY accessor for UserInfo::setupName. | |
quint16 | port () const |
Returns the currently used port. More... | |
bool | isActive () const |
READ accessor for UserInfo::active. | |
QList< UserInfo > | devices () const |
READ accessor for UserInfo::users. | |
Q_INVOKABLE void | exportTo (const QtDataSync::UserInfo &userInfo, bool includeServer) |
Sends the user identity to the given user as untrusted export. More... | |
Q_INVOKABLE void | exportTrustedTo (const QtDataSync::UserInfo &userInfo, bool includeServer, const QString &password) |
Sends the user identity to the given user as trusted export. More... | |
void | importFrom (const QtDataSync::UserInfo &userInfo, const std::function< void(bool, QString)> &completedFn, bool keepData=false) |
Imports the untrusted user data previously received by the given user. More... | |
void | importTrustedFrom (const QtDataSync::UserInfo &userInfo, const QString &password, const std::function< void(bool, QString)> &completedFn, bool keepData=false) |
Imports the trusted user data previously received by the given user. More... | |
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 Attributes | |
static const quint16 | DataExchangePort |
The default port (13742) for the data exchange. | |
Properties | |
QString | setupName |
Holds the name of the setup this manager operates on. More... | |
bool | active |
Reports whether the instance is currently exchanging or not. More... | |
QList< QtDataSync::UserInfo > | devices |
Holds all currently discovered devices. More... | |
Properties inherited from QObject | |
objectName | |
Additional Inherited Members | |
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) |
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) |
A helper class to exchange the account data between devices on the local network.
This class can be used to exchange the user identity af a setup via the local network. It provides an easy way to transfer the identity between devices, without any need of external transport mediums to get the exported data to another device.
Definition at line 63 of file userexchangemanager.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 an account manager to use for account import and export.
manager | The account manager to use to import and export account data |
parent | The parent object |
QtDataSync::UserExchangeManager::accountManager | ( | ) | const |
The internally used account manager used to export and import data.
Returns a reference to the internally used manager. The manager is only valid as long as the UserExchangeManager exists. You can use the manager reference to get information about it's state etc.
|
signal |
Is emitted when an error occured trying to export or import.
errorString | A localized error string describing what went wrong |
Can be shown to the user to tell him something regarding the import or export (or the general exchange) failed.
QtDataSync::UserExchangeManager::exportTo | ( | const QtDataSync::UserInfo & | userInfo, |
bool | includeServer | ||
) |
Sends the user identity to the given user as untrusted export.
userInfo | The user to send the identity to |
includeServer | Specify whether the server address and configuration should be included into the export data |
The identity of the current user for the setup used on this instance is exported and sent to the address represented by the passed userInfo. The userInfo should be a user discovered by the exchange from UserExchangeManager::devices
Internally, AccountManager::exportAccount is used to perform the actual export. That data is then sent over the network to the partner device. See that documentation for more details.
QtDataSync::UserExchangeManager::exportTrustedTo | ( | const QtDataSync::UserInfo & | userInfo, |
bool | includeServer, | ||
const QString & | password | ||
) |
Sends the user identity to the given user as trusted export.
userInfo | The user to send the identity to |
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 |
The identity of the current user for the setup used on this instance is exported and sent to the address represented by the passed userInfo. The userInfo should be a user discovered by the exchange from UserExchangeManager::devices
Internally, AccountManager::exportAccountTrusted is used to perform the actual export. That data is then sent over the network to the partner device. See that documentation for more details.
QtDataSync::UserExchangeManager::importFrom | ( | const QtDataSync::UserInfo & | userInfo, |
const std::function< void(bool, QString)> & | completedFn, | ||
bool | keepData = false |
||
) |
Imports the untrusted user data previously received by the given user.
userInfo | The user to that sent the data to import |
completedFn | A function that is called once the import has been finished |
keepData | Specify whether the stored data should be preserved |
Use this method to perform the actual import of an identity after receiving it via userDataReceived(). This only works if data has been received from the user that way. Otherwise the operation will fail.
Internally, AccountManager::importAccount is used to perform the actual import. The received data is simply passed to that method. See that documentation for more details.
QtDataSync::UserExchangeManager::importTrustedFrom | ( | const QtDataSync::UserInfo & | userInfo, |
const QString & | password, | ||
const std::function< void(bool, QString)> & | completedFn, | ||
bool | keepData = false |
||
) |
Imports the trusted user data previously received by the given user.
userInfo | The user to that sent the data to import |
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 |
Use this method to perform the actual import of an identity after receiving it via userDataReceived(). This only works if data has been received from the user that way. Otherwise the operation will fail.
Internally, AccountManager::importAccountTrusted is used to perform the actual import. The received data is simply passed to that method. See that documentation for more details.
QtDataSync::UserExchangeManager::port | ( | ) | const |
Returns the currently used port.
The returned port is only valid whne activly exchanging. Can be used to retrieve the choosen port when working with random ports. If not connected, 0 is returned
|
inlineslot |
Start the exchange discovery on the specified port.
port | The port to start the exchange on |
The exchange is run for all addresses, allowing connections from anywhere and broadcasting to anyone in the local network.
If the function fails, the error string describing what went wrong is emitted via exchangeError().
Definition at line 114 of file userexchangemanager.h.
|
slot |
Start the exchange discovery on the specified address and port.
listenAddress | The address to listen on for incoming messages |
port | The port to start the exchange on |
The exchange is run for the given addresses, allowing connections only from addresses matching the given address and broadcasting to anyone in the local network.
If the function fails, the error string describing what went wrong is emitted via exchangeError().
|
slot |
Stops the exchange discovery.
Stops sending and receiving messages, clears all users and pending imports. After stopping, this device disappears from the network and can neither be discovered by other exchanges, nor discover them.
|
signal |
Is emitted, when a user identity was received from the given user.
userInfo | The user that sent his identity to this device |
trusted | true if the received data is a trusted export, false if it is untrusted |
When a user exports his identity to this device via exportTo() or exportTrustedTo(), this signal is emitted. Connect to it to react an proposed identity data. The data is not imported immediatly. You can use the importFrom() and importTrustedFrom() methods to perform the actual import of the data, if you want to accept it. Choose the correct import method based on the trusted
parameter.
|
read |
Reports whether the instance is currently exchanging or not.
Default: false
The UserExchangeManager is considered active when actively searching for other devices, ready to export or import data from and to other devices.
When inactive, the device is disconnected from the network and does not send or receive any data.
Accessors | |
---|---|
READ | isActive() |
NOTIFY | activeChanged() |
Definition at line 70 of file userexchangemanager.h.
|
read |
Holds all currently discovered devices.
Default: Empty
This list contains all devices discovered on the local network (excluding yourself). It only can find devices that have the exchange active on the same port. The list will only contain any users if active.
Accessors | |
---|---|
READ | users() |
NOTIFY | usersChanged() |
Definition at line 72 of file userexchangemanager.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 68 of file userexchangemanager.h.