2016-10-04 23:55:20 +02:00
# ifndef DATA_SYNCTHINGDEV_H
# define DATA_SYNCTHINGDEV_H
2020-03-02 15:38:38 +01:00
# include "./qstringhash.h"
2020-03-01 22:04:30 +01:00
# include "./syncthingcompletion.h"
2016-10-04 23:55:20 +02:00
# include <c++utilities/chrono/datetime.h>
2017-05-01 03:34:43 +02:00
# include <QMetaType>
2016-10-04 23:55:20 +02:00
# include <QString>
# include <QStringList>
2020-04-27 23:08:41 +02:00
# include <cstdlib>
# include <unordered_map>
# include <vector>
2016-10-04 23:55:20 +02:00
namespace Data {
2019-09-27 16:48:58 +02:00
/// \brief The SyncthingDevStatus enum represents a Syncthing device status.
/// \remarks The device status is not directly provided by Syncthing and instead deduced by this library from
/// other information and events.
2020-12-31 02:30:05 +01:00
enum class SyncthingDevStatus {
Unknown , /**< device status is unknown */
Disconnected , /**< device is disconnected */
OwnDevice , /**< device is the own device; the own device will always have this status assigned */
Idle , /**< device is connected and all shared directories are up-to-date on its end */
Synchronizing , /**< device is connected but not all shared directories are up-to-date on its end */
OutOfSync , /**< device is connected but not all shared directories are up-to-date on its end due to an error (never set so far; seems not possible to determine) */
Rejected , /**< device is rejected */
} ;
2016-10-04 23:55:20 +02:00
2017-02-20 18:00:42 +01:00
QString statusString ( SyncthingDevStatus status ) ;
2017-05-01 03:34:43 +02:00
struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingDev {
2020-03-01 22:04:30 +01:00
explicit SyncthingDev ( const QString & id = QString ( ) , const QString & name = QString ( ) ) ;
2017-02-20 21:00:18 +01:00
QString statusString ( ) const ;
2017-05-30 15:06:34 +02:00
bool isConnected ( ) const ;
2020-03-01 22:04:30 +01:00
void setConnectedStateAccordingToCompletion ( ) ;
2018-03-29 00:38:21 +02:00
const QString displayName ( ) const ;
2017-02-20 21:00:18 +01:00
2016-10-04 23:55:20 +02:00
QString id ;
QString name ;
QStringList addresses ;
QString compression ;
QString certName ;
2018-11-02 23:37:35 +01:00
SyncthingDevStatus status = SyncthingDevStatus : : Unknown ;
2019-03-13 19:12:23 +01:00
std : : uint64_t totalIncomingTraffic = 0 ;
std : : uint64_t totalOutgoingTraffic = 0 ;
2016-10-04 23:55:20 +02:00
QString connectionAddress ;
QString connectionType ;
QString clientVersion ;
2019-06-10 22:48:26 +02:00
CppUtilities : : DateTime lastSeen ;
2020-03-01 22:04:30 +01:00
std : : unordered_map < QString , SyncthingCompletion > completionByDir ;
SyncthingCompletion overallCompletion ;
bool introducer = false ;
bool paused = false ;
2016-10-04 23:55:20 +02:00
} ;
2017-05-01 03:34:43 +02:00
inline SyncthingDev : : SyncthingDev ( const QString & id , const QString & name )
: id ( id )
, name ( name )
{
}
2016-11-01 17:06:31 +01:00
2017-05-30 15:06:34 +02:00
inline bool SyncthingDev : : isConnected ( ) const
{
switch ( status ) {
case SyncthingDevStatus : : Unknown :
case SyncthingDevStatus : : Disconnected :
case SyncthingDevStatus : : OwnDevice :
2020-03-01 22:04:30 +01:00
case SyncthingDevStatus : : Rejected :
2017-05-30 15:06:34 +02:00
return false ;
default :
return true ;
}
}
2020-03-01 22:04:30 +01:00
inline void SyncthingDev : : setConnectedStateAccordingToCompletion ( )
{
status = overallCompletion . needed . isNull ( ) ? SyncthingDevStatus : : Idle : SyncthingDevStatus : : Synchronizing ;
}
2018-03-29 00:38:21 +02:00
inline const QString SyncthingDev : : displayName ( ) const
{
return name . isEmpty ( ) ? id : name ;
}
2016-10-04 23:55:20 +02:00
} // namespace Data
2017-04-23 13:48:55 +02:00
Q_DECLARE_METATYPE ( Data : : SyncthingDev )
2016-10-04 23:55:20 +02:00
# endif // DATA_SYNCTHINGDEV_H