QtDataSync  4.2.0
A simple offline-first synchronisation framework, to synchronize data of Qt applications between devices
Public Slots | Signals | Public Member Functions | Static Public Attributes | Properties | List of all members
QtDataSync::UserExchangeManager Class Reference

A helper class to exchange the account data between devices on the local network. More...

#include <userexchangemanager.h>

+ Inheritance diagram for QtDataSync::UserExchangeManager:

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...
 
AccountManageraccountManager () 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< UserInfodevices () 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 QMetaObjectmetaObject () 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)
 
QThreadthread () 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)
 
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 &regExp, 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< QByteArraydynamicPropertyNames () const const
 
void destroyed (QObject *obj)
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () 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::UserInfodevices
 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
QObjectsender () 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)
 

Detailed Description

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.

Note
The class makes use of UDP-Broadcasts to discover other devices on the local network. This only works if both devices have an active UserExchangeManager running and if the network they both are connected to supports broadcasts. It does not work across networks.
See also
AccountManager

Definition at line 63 of file userexchangemanager.h.

Constructor & Destructor Documentation

◆ UserExchangeManager() [1/3]

QtDataSync::UserExchangeManager::UserExchangeManager ( QObject parent = nullptr)
explicit

Default constructor, uses the default setup.

Parameters
parentThe parent object
Exceptions
SetupDoesNotExistExceptionThrown if the default setup was not created yet

◆ UserExchangeManager() [2/3]

QtDataSync::UserExchangeManager::UserExchangeManager ( const QString setupName,
QObject parent = nullptr 
)
explicit

Constructor with an explicit setup.

Parameters
setupNameThe name of the setup to connect to
parentThe parent object
Exceptions
SetupDoesNotExistExceptionThrown if the given setup was not created yet

◆ UserExchangeManager() [3/3]

QtDataSync::UserExchangeManager::UserExchangeManager ( AccountManager manager,
QObject parent = nullptr 
)
explicit

Constructor with an account manager to use for account import and export.

Parameters
managerThe account manager to use to import and export account data
parentThe parent object
Attention
The exchange manager does not take ownership of the passed account manager. Thus, the account manager must stay valid as long as the exchange manager exists.

Member Function Documentation

◆ accountManager()

QtDataSync::UserExchangeManager::accountManager ( ) const

The internally used account manager used to export and import data.

Returns
A pointer to the interal account manager object

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.

◆ exchangeError

QtDataSync::UserExchangeManager::exchangeError ( const QString errorString,
QPrivateSignal   
)
signal

Is emitted when an error occured trying to export or import.

Parameters
errorStringA 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.

◆ exportTo()

QtDataSync::UserExchangeManager::exportTo ( const QtDataSync::UserInfo userInfo,
bool  includeServer 
)

Sends the user identity to the given user as untrusted export.

Parameters
userInfoThe user to send the identity to
includeServerSpecify 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.

See also
UserExchangeManager::userDataReceived, UserExchangeManager::importFrom, UserExchangeManager::exportTrustedTo, AccountManager::exportAccount

◆ exportTrustedTo()

QtDataSync::UserExchangeManager::exportTrustedTo ( const QtDataSync::UserInfo userInfo,
bool  includeServer,
const QString password 
)

Sends the user identity to the given user as trusted export.

Parameters
userInfoThe user to send the identity to
includeServerSpecify whether the server address and configuration should be included into the export data
passwordThe 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.

See also
UserExchangeManager::userDataReceived, UserExchangeManager::importTrustedFrom, UserExchangeManager::exportTo, AccountManager::exportAccountTrusted

◆ importFrom()

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.

Parameters
userInfoThe user to that sent the data to import
completedFnA function that is called once the import has been finished
keepDataSpecify 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.

See also
UserExchangeManager::userDataReceived, UserExchangeManager::exportTo, UserExchangeManager::importTrustedFrom, AccountManager::importAccount

◆ importTrustedFrom()

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.

Parameters
userInfoThe user to that sent the data to import
passwordThe password used to decrypt the imported data with. Must be the same as used for the export
completedFnA function that is called once the import has been finished
keepDataSpecify 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.

See also
UserExchangeManager::userDataReceived, UserExchangeManager::exportTrustedTo, UserExchangeManager::importFrom, AccountManager::importAccountTrusted

◆ port()

QtDataSync::UserExchangeManager::port ( ) const

Returns the currently used port.

Returns
The currently used port, if active

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

See also
UserExchangeManager::active, UserExchangeManager::startExchange

◆ startExchange [1/2]

QtDataSync::UserExchangeManager::startExchange ( quint16  port = DataExchangePort)
inlineslot

Start the exchange discovery on the specified port.

Parameters
portThe port to start the exchange on
Returns
true, if successfully started, false if not

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().

See also
UserExchangeManager::active, UserExchangeManager::exchangeError, UserExchangeManager::stopExchange

Definition at line 114 of file userexchangemanager.h.

◆ startExchange [2/2]

QtDataSync::UserExchangeManager::startExchange ( const QHostAddress listenAddress,
quint16  port = DataExchangePort 
)
slot

Start the exchange discovery on the specified address and port.

Parameters
listenAddressThe address to listen on for incoming messages
portThe port to start the exchange on
Returns
true, if successfully started, false if not

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().

See also
UserExchangeManager::active, UserExchangeManager::exchangeError, UserExchangeManager::stopExchange

◆ stopExchange

QtDataSync::UserExchangeManager::stopExchange ( )
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.

See also
UserExchangeManager::active, UserExchangeManager::startExchange

◆ userDataReceived

QtDataSync::UserExchangeManager::userDataReceived ( const QtDataSync::UserInfo userInfo,
bool  trusted,
QPrivateSignal   
)
signal

Is emitted, when a user identity was received from the given user.

Parameters
userInfoThe user that sent his identity to this device
trustedtrue 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.

See also
UserExchangeManager::importFrom, UserExchangeManager::importTrustedFrom, UserExchangeManager::exportTo, UserExchangeManager::exportTrustedTo

Property Documentation

◆ active

QtDataSync::UserExchangeManager::active
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
READisActive()
NOTIFYactiveChanged()
See also
UserExchangeManager::startExchange, UserExchangeManager::stopExchange

Definition at line 70 of file userexchangemanager.h.

◆ devices

QtDataSync::UserExchangeManager::devices
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
READusers()
NOTIFYusersChanged()
See also
UserInfo, UserExchangeManager::active, UserExchangeManager::userDataReceived, UserExchangeManager::exportTo, UserExchangeManager::exportTrustedTo, UserExchangeManager::importFrom, UserExchangeManager::importTrustedFrom

Definition at line 72 of file userexchangemanager.h.

◆ setupName

QtDataSync::UserExchangeManager::setupName
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
READsetupName()
NOTIFYsetupNameChanged()
REVISION2
See also
QtDataSync::DefaultSetup, Setup::create

Definition at line 68 of file userexchangemanager.h.


The documentation for this class was generated from the following files: