2017-11-26 03:17:30 +01:00
|
|
|
#ifndef DATA_SYNCTHINGNOTIFIER_H
|
|
|
|
#define DATA_SYNCTHINGNOTIFIER_H
|
|
|
|
|
|
|
|
#include "./global.h"
|
|
|
|
|
2020-12-31 02:17:25 +01:00
|
|
|
#include <c++utilities/misc/flagenumclass.h>
|
|
|
|
|
2017-11-26 03:17:30 +01:00
|
|
|
#include <QObject>
|
2019-07-12 20:24:19 +02:00
|
|
|
#include <QProcess>
|
2017-11-26 03:17:30 +01:00
|
|
|
|
2020-10-23 17:04:15 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
#include "./syncthingdev.h"
|
2020-11-03 18:28:31 +01:00
|
|
|
#include "./syncthingprocess.h"
|
|
|
|
#include "./syncthingservice.h"
|
2020-10-23 17:04:15 +02:00
|
|
|
#endif
|
|
|
|
|
2019-06-10 22:48:26 +02:00
|
|
|
namespace CppUtilities {
|
2018-01-28 18:07:39 +01:00
|
|
|
class DateTime;
|
|
|
|
}
|
|
|
|
|
2017-11-26 03:17:30 +01:00
|
|
|
namespace Data {
|
|
|
|
|
|
|
|
enum class SyncthingStatus;
|
|
|
|
class SyncthingConnection;
|
|
|
|
class SyncthingService;
|
2018-04-02 20:26:00 +02:00
|
|
|
class SyncthingProcess;
|
2017-11-26 03:17:30 +01:00
|
|
|
struct SyncthingDir;
|
2018-01-27 23:27:50 +01:00
|
|
|
struct SyncthingDev;
|
2017-11-26 03:17:30 +01:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief The SyncthingHighLevelNotification enum specifies the high-level notifications provided by the SyncthingNotifier class.
|
|
|
|
* \remarks The enum is supposed to be used as flag-enum.
|
|
|
|
*/
|
|
|
|
enum class SyncthingHighLevelNotification {
|
2020-12-31 02:17:25 +01:00
|
|
|
None = 0,
|
|
|
|
ConnectedDisconnected = (1 << 0),
|
|
|
|
LocalSyncComplete = (1 << 1),
|
|
|
|
RemoteSyncComplete = (1 << 2),
|
|
|
|
NewDevice = (1 << 3),
|
|
|
|
NewDir = (1 << 4),
|
|
|
|
SyncthingProcessError = (1 << 5),
|
2017-11-26 03:17:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingNotifier : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(SyncthingHighLevelNotification enabledNotifications READ enabledNotifications WRITE setEnabledNotifications)
|
2018-04-02 20:26:00 +02:00
|
|
|
Q_PROPERTY(bool ignoreInavailabilityAfterStart READ ignoreInavailabilityAfterStart WRITE setIgnoreInavailabilityAfterStart)
|
2018-05-15 22:27:54 +02:00
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
|
|
|
Q_PROPERTY(const SyncthingService *service READ service WRITE setService)
|
|
|
|
#endif
|
|
|
|
Q_PROPERTY(const SyncthingProcess *process READ process WRITE setProcess)
|
2017-11-26 03:17:30 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
SyncthingNotifier(const SyncthingConnection &connection, QObject *parent = nullptr);
|
|
|
|
|
2018-12-24 17:19:11 +01:00
|
|
|
const SyncthingConnection &connection() const;
|
2017-11-26 03:17:30 +01:00
|
|
|
SyncthingHighLevelNotification enabledNotifications() const;
|
2018-04-02 20:26:00 +02:00
|
|
|
unsigned int ignoreInavailabilityAfterStart() const;
|
2018-05-15 22:27:54 +02:00
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
|
|
|
const SyncthingService *service() const;
|
|
|
|
#endif
|
|
|
|
const SyncthingProcess *process() const;
|
2017-11-26 03:17:30 +01:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void setEnabledNotifications(SyncthingHighLevelNotification enabledNotifications);
|
2018-04-02 20:26:00 +02:00
|
|
|
void setIgnoreInavailabilityAfterStart(unsigned int seconds);
|
2018-05-15 22:27:54 +02:00
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
|
|
|
void setService(const SyncthingService *service);
|
|
|
|
#endif
|
|
|
|
void setProcess(const SyncthingProcess *process);
|
2017-11-26 03:17:30 +01:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
2018-01-27 23:27:50 +01:00
|
|
|
///! \brief Emitted when the connection status changes. Also provides the previous status.
|
2017-11-26 03:17:30 +01:00
|
|
|
void statusChanged(SyncthingStatus previousStatus, SyncthingStatus newStatus);
|
|
|
|
///! \brief Emitted when the connection to Syncthing has been established.
|
|
|
|
void connected();
|
|
|
|
///! \brief Emitted when the connection to Syncthing has been interrupted.
|
|
|
|
void disconnected();
|
2018-05-01 22:23:54 +02:00
|
|
|
///! \brief Emitted when one or more directories have completed synchronization.
|
|
|
|
///! \remarks Both, local and remote devices, are taken into account.
|
2018-01-27 23:27:50 +01:00
|
|
|
void syncComplete(const QString &message);
|
2018-05-01 22:23:54 +02:00
|
|
|
///! \brief Emitted when a new device talks to us.
|
|
|
|
void newDevice(const QString &devId, const QString &message);
|
|
|
|
///! \brief Emitted when a new directory is shared with us.
|
|
|
|
void newDir(const QString &devId, const QString &dirId, const QString &message);
|
2019-07-12 20:24:19 +02:00
|
|
|
///! \brief Emitted when the Syncthing process fails to start or crashes.
|
|
|
|
void syncthingProcessError(const QString &message, const QString &additionalInfo);
|
2017-11-26 03:17:30 +01:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void handleStatusChangedEvent(SyncthingStatus newStatus);
|
2019-06-10 22:48:26 +02:00
|
|
|
void handleNewDevEvent(CppUtilities::DateTime when, const QString &devId, const QString &address);
|
|
|
|
void handleNewDirEvent(CppUtilities::DateTime when, const QString &devId, const SyncthingDev *dev, const QString &dirId, const QString &dirLabel);
|
2019-07-12 20:24:19 +02:00
|
|
|
void handleSyncthingProcessError(QProcess::ProcessError syncthingProcessError);
|
2017-11-26 03:17:30 +01:00
|
|
|
|
|
|
|
private:
|
2018-04-02 20:26:00 +02:00
|
|
|
bool isDisconnectRelevant() const;
|
2017-11-26 03:17:30 +01:00
|
|
|
void emitConnectedAndDisconnected(SyncthingStatus newStatus);
|
2019-06-10 22:48:26 +02:00
|
|
|
void emitSyncComplete(CppUtilities::DateTime when, const SyncthingDir &dir, int index, const SyncthingDev *remoteDev);
|
2017-11-26 03:17:30 +01:00
|
|
|
|
|
|
|
const SyncthingConnection &m_connection;
|
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
2018-05-15 22:27:54 +02:00
|
|
|
const SyncthingService *m_service;
|
2017-11-26 03:17:30 +01:00
|
|
|
#endif
|
2018-05-15 22:27:54 +02:00
|
|
|
const SyncthingProcess *m_process;
|
2017-11-26 03:17:30 +01:00
|
|
|
SyncthingHighLevelNotification m_enabledNotifications;
|
|
|
|
SyncthingStatus m_previousStatus;
|
2018-04-02 20:26:00 +02:00
|
|
|
unsigned int m_ignoreInavailabilityAfterStart;
|
2017-11-26 03:17:30 +01:00
|
|
|
bool m_initialized;
|
|
|
|
};
|
|
|
|
|
2018-12-24 17:19:11 +01:00
|
|
|
/*!
|
|
|
|
* \brief Returns the associated connection.
|
|
|
|
*/
|
|
|
|
inline const SyncthingConnection &SyncthingNotifier::connection() const
|
|
|
|
{
|
|
|
|
return m_connection;
|
|
|
|
}
|
|
|
|
|
2017-11-26 03:17:30 +01:00
|
|
|
/*!
|
|
|
|
* \brief Returns which notifications are enabled (by default none).
|
|
|
|
*/
|
|
|
|
inline SyncthingHighLevelNotification SyncthingNotifier::enabledNotifications() const
|
|
|
|
{
|
|
|
|
return m_enabledNotifications;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets which notifications are enabled.
|
|
|
|
*/
|
|
|
|
inline void SyncthingNotifier::setEnabledNotifications(SyncthingHighLevelNotification enabledNotifications)
|
|
|
|
{
|
|
|
|
m_enabledNotifications = enabledNotifications;
|
|
|
|
}
|
|
|
|
|
2018-04-02 20:26:00 +02:00
|
|
|
/*!
|
2021-07-03 19:29:49 +02:00
|
|
|
* \brief Returns the number of seconds after startup or standby-wakeup to suppress disconnect notifications.
|
2018-04-02 20:26:00 +02:00
|
|
|
*/
|
|
|
|
inline unsigned int SyncthingNotifier::ignoreInavailabilityAfterStart() const
|
|
|
|
{
|
|
|
|
return m_ignoreInavailabilityAfterStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Prevents disconnect notifications in the first \a seconds after startup or standby-wakeup.
|
|
|
|
*/
|
|
|
|
inline void SyncthingNotifier::setIgnoreInavailabilityAfterStart(unsigned int seconds)
|
|
|
|
{
|
|
|
|
m_ignoreInavailabilityAfterStart = seconds;
|
|
|
|
}
|
|
|
|
|
2018-05-15 22:27:54 +02:00
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
|
|
|
/*!
|
|
|
|
* \brief Returns the SyncthingService to be taken into account. Might be nullptr.
|
|
|
|
*/
|
|
|
|
inline const SyncthingService *SyncthingNotifier::service() const
|
|
|
|
{
|
|
|
|
return m_service;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets the SyncthingService to be taken into account. Might be nullptr.
|
|
|
|
*/
|
|
|
|
inline void SyncthingNotifier::setService(const SyncthingService *service)
|
|
|
|
{
|
|
|
|
m_service = service;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the SyncthingProcess to be taken into account. Might be nullptr.
|
|
|
|
*/
|
|
|
|
inline const SyncthingProcess *SyncthingNotifier::process() const
|
|
|
|
{
|
|
|
|
return m_process;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets the SyncthingProcess to be taken into account. Might be nullptr.
|
|
|
|
*/
|
|
|
|
inline void SyncthingNotifier::setProcess(const SyncthingProcess *process)
|
|
|
|
{
|
|
|
|
m_process = process;
|
|
|
|
}
|
|
|
|
|
2017-11-26 03:17:30 +01:00
|
|
|
} // namespace Data
|
|
|
|
|
2020-12-31 02:17:25 +01:00
|
|
|
CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(Data, Data::SyncthingHighLevelNotification)
|
|
|
|
|
2017-11-26 03:17:30 +01:00
|
|
|
#endif // DATA_SYNCTHINGNOTIFIER_H
|