2017-08-29 23:58:49 +02:00
|
|
|
#ifndef SYNCTHINGAPPLET_H
|
|
|
|
#define SYNCTHINGAPPLET_H
|
|
|
|
|
2017-09-08 16:59:53 +02:00
|
|
|
#include "../../widgets/misc/dbusstatusnotifier.h"
|
2017-08-29 23:58:49 +02:00
|
|
|
#include "../../widgets/misc/statusinfo.h"
|
2018-01-27 23:33:52 +01:00
|
|
|
#include "../../widgets/webview/webviewdefs.h"
|
2017-08-29 23:58:49 +02:00
|
|
|
|
|
|
|
#include "../../model/syncthingdevicemodel.h"
|
|
|
|
#include "../../model/syncthingdirectorymodel.h"
|
|
|
|
#include "../../model/syncthingdownloadmodel.h"
|
2018-10-10 17:48:48 +02:00
|
|
|
#include "../../model/syncthingstatusselectionmodel.h"
|
2017-08-29 23:58:49 +02:00
|
|
|
|
|
|
|
#include "../../connector/syncthingconnection.h"
|
2018-01-27 23:27:50 +01:00
|
|
|
#include "../../connector/syncthingnotifier.h"
|
2017-09-08 16:59:53 +02:00
|
|
|
#include "../../connector/syncthingservice.h"
|
2017-08-29 23:58:49 +02:00
|
|
|
|
|
|
|
#include <qtutilities/aboutdialog/aboutdialog.h>
|
2018-10-10 17:48:48 +02:00
|
|
|
#include <qtutilities/models/checklistmodel.h>
|
2017-08-29 23:58:49 +02:00
|
|
|
|
|
|
|
#include <Plasma/Applet>
|
|
|
|
|
2017-09-18 20:29:36 +02:00
|
|
|
#include <QSize>
|
|
|
|
|
2017-08-29 23:58:49 +02:00
|
|
|
namespace Data {
|
|
|
|
class SyncthingConnection;
|
2017-09-09 21:40:00 +02:00
|
|
|
struct SyncthingConnectionSettings;
|
2017-08-29 23:58:49 +02:00
|
|
|
class SyncthingDirectoryModel;
|
|
|
|
class SyncthingDeviceModel;
|
|
|
|
class SyncthingDownloadModel;
|
2017-09-08 16:59:53 +02:00
|
|
|
class SyncthingService;
|
|
|
|
enum class SyncthingErrorCategory;
|
2017-09-17 21:48:15 +02:00
|
|
|
} // namespace Data
|
2017-08-29 23:58:49 +02:00
|
|
|
|
|
|
|
namespace QtGui {
|
|
|
|
class WebViewDialog;
|
|
|
|
}
|
|
|
|
|
2017-09-09 21:40:00 +02:00
|
|
|
namespace Plasmoid {
|
|
|
|
|
2018-10-10 17:48:48 +02:00
|
|
|
class SettingsDialog;
|
|
|
|
|
2017-08-29 23:58:49 +02:00
|
|
|
class SyncthingApplet : public Plasma::Applet {
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(Data::SyncthingConnection *connection READ connection NOTIFY connectionChanged)
|
|
|
|
Q_PROPERTY(Data::SyncthingDirectoryModel *dirModel READ dirModel NOTIFY dirModelChanged)
|
|
|
|
Q_PROPERTY(Data::SyncthingDeviceModel *devModel READ devModel NOTIFY devModelChanged)
|
|
|
|
Q_PROPERTY(Data::SyncthingDownloadModel *downloadModel READ downloadModel NOTIFY downloadModelChanged)
|
2018-10-10 17:48:48 +02:00
|
|
|
Q_PROPERTY(Data::SyncthingStatusSelectionModel *passiveSelectionModel READ passiveSelectionModel NOTIFY passiveSelectionModelChanged)
|
2017-09-08 16:59:53 +02:00
|
|
|
Q_PROPERTY(Data::SyncthingService *service READ service NOTIFY serviceChanged)
|
|
|
|
Q_PROPERTY(bool local READ isLocal NOTIFY localChanged)
|
2017-08-29 23:58:49 +02:00
|
|
|
Q_PROPERTY(QString statusText READ statusText NOTIFY connectionStatusChanged)
|
|
|
|
Q_PROPERTY(QString additionalStatusText READ additionalStatusText NOTIFY connectionStatusChanged)
|
|
|
|
Q_PROPERTY(QIcon statusIcon READ statusIcon NOTIFY connectionStatusChanged)
|
|
|
|
Q_PROPERTY(QString incomingTraffic READ incomingTraffic NOTIFY trafficChanged)
|
2019-02-17 23:45:53 +01:00
|
|
|
Q_PROPERTY(bool hasIncomingTraffic READ hasIncomingTraffic NOTIFY trafficChanged)
|
2017-08-29 23:58:49 +02:00
|
|
|
Q_PROPERTY(QString outgoingTraffic READ outgoingTraffic NOTIFY trafficChanged)
|
2019-02-17 23:45:53 +01:00
|
|
|
Q_PROPERTY(bool hasOutgoingTraffic READ hasOutgoingTraffic NOTIFY trafficChanged)
|
2019-02-27 20:42:41 +01:00
|
|
|
Q_PROPERTY(Data::SyncthingStatistics globalStatistics READ globalStatistics NOTIFY statisticsChanged)
|
|
|
|
Q_PROPERTY(Data::SyncthingStatistics localStatistics READ localStatistics NOTIFY statisticsChanged)
|
2017-09-09 21:40:00 +02:00
|
|
|
Q_PROPERTY(QStringList connectionConfigNames READ connectionConfigNames NOTIFY settingsChanged)
|
2017-09-08 16:59:53 +02:00
|
|
|
Q_PROPERTY(QString currentConnectionConfigName READ currentConnectionConfigName NOTIFY currentConnectionConfigIndexChanged)
|
|
|
|
Q_PROPERTY(int currentConnectionConfigIndex READ currentConnectionConfigIndex WRITE setCurrentConnectionConfigIndex NOTIFY
|
|
|
|
currentConnectionConfigIndexChanged)
|
2018-04-02 20:26:00 +02:00
|
|
|
Q_PROPERTY(bool startStopEnabled READ isStartStopEnabled NOTIFY settingsChanged)
|
2017-09-18 20:29:36 +02:00
|
|
|
Q_PROPERTY(QSize size READ size WRITE setSize NOTIFY sizeChanged)
|
2017-10-01 21:42:26 +02:00
|
|
|
Q_PROPERTY(bool notificationsAvailable READ areNotificationsAvailable NOTIFY notificationsAvailableChanged)
|
2018-10-10 17:48:48 +02:00
|
|
|
Q_PROPERTY(bool passive READ isPassive NOTIFY passiveChanged)
|
2019-06-10 22:48:26 +02:00
|
|
|
Q_PROPERTY(QList<QtUtilities::ChecklistItem> passiveStates READ passiveStates WRITE setPassiveStates)
|
2017-08-29 23:58:49 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
SyncthingApplet(QObject *parent, const QVariantList &data);
|
|
|
|
~SyncthingApplet() override;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Data::SyncthingConnection *connection() const;
|
|
|
|
Data::SyncthingDirectoryModel *dirModel() const;
|
|
|
|
Data::SyncthingDeviceModel *devModel() const;
|
|
|
|
Data::SyncthingDownloadModel *downloadModel() const;
|
2018-10-10 17:48:48 +02:00
|
|
|
Data::SyncthingStatusSelectionModel *passiveSelectionModel() const;
|
2017-09-08 16:59:53 +02:00
|
|
|
Data::SyncthingService *service() const;
|
|
|
|
bool isLocal() const;
|
2017-08-29 23:58:49 +02:00
|
|
|
QString statusText() const;
|
|
|
|
QString additionalStatusText() const;
|
|
|
|
QIcon statusIcon() const;
|
|
|
|
QString incomingTraffic() const;
|
2019-02-17 23:45:53 +01:00
|
|
|
bool hasIncomingTraffic() const;
|
2017-08-29 23:58:49 +02:00
|
|
|
QString outgoingTraffic() const;
|
2019-02-17 23:45:53 +01:00
|
|
|
bool hasOutgoingTraffic() const;
|
2019-02-27 20:42:41 +01:00
|
|
|
Data::SyncthingStatistics globalStatistics() const;
|
|
|
|
Data::SyncthingStatistics localStatistics() const;
|
2017-09-08 16:59:53 +02:00
|
|
|
QStringList connectionConfigNames() const;
|
|
|
|
QString currentConnectionConfigName() const;
|
|
|
|
int currentConnectionConfigIndex() const;
|
2017-09-09 21:40:00 +02:00
|
|
|
Data::SyncthingConnectionSettings *currentConnectionConfig();
|
|
|
|
Data::SyncthingConnectionSettings *connectionConfig(int index);
|
2017-09-08 16:59:53 +02:00
|
|
|
void setCurrentConnectionConfigIndex(int index);
|
2018-04-02 20:26:00 +02:00
|
|
|
bool isStartStopEnabled() const;
|
2017-09-18 20:29:36 +02:00
|
|
|
QSize size() const;
|
|
|
|
void setSize(const QSize &size);
|
2017-10-01 21:42:26 +02:00
|
|
|
bool areNotificationsAvailable() const;
|
2018-10-10 17:48:48 +02:00
|
|
|
bool isPassive() const;
|
2019-06-10 22:48:26 +02:00
|
|
|
const QList<QtUtilities::ChecklistItem> &passiveStates() const;
|
|
|
|
void setPassiveStates(const QList<QtUtilities::ChecklistItem> &passiveStates);
|
2017-08-29 23:58:49 +02:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
2018-10-10 21:26:46 +02:00
|
|
|
void init() override;
|
2017-09-08 16:59:53 +02:00
|
|
|
void showSettingsDlg();
|
2017-08-29 23:58:49 +02:00
|
|
|
void showWebUI();
|
|
|
|
void showLog();
|
|
|
|
void showOwnDeviceId();
|
|
|
|
void showAboutDialog();
|
2017-09-08 16:59:53 +02:00
|
|
|
void showNotificationsDialog();
|
|
|
|
void dismissNotifications();
|
|
|
|
void showInternalErrorsDialog();
|
2018-11-03 21:30:17 +01:00
|
|
|
void showDirectoryErrors(unsigned int directoryIndex);
|
2017-10-01 17:49:48 +02:00
|
|
|
void copyToClipboard(const QString &text);
|
2017-10-16 19:40:44 +02:00
|
|
|
void updateStatusIconAndTooltip();
|
2019-02-27 20:42:41 +01:00
|
|
|
QIcon loadFontAwesomeIcon(const QString &name, bool solid = true) const;
|
|
|
|
QString formatFileSize(quint64 fileSizeInByte) const;
|
2017-08-29 23:58:49 +02:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
/// \remarks Never emitted, just to silence "... depends on non-NOTIFYable ..."
|
|
|
|
void connectionChanged();
|
|
|
|
/// \remarks Never emitted, just to silence "... depends on non-NOTIFYable ..."
|
|
|
|
void dirModelChanged();
|
|
|
|
/// \remarks Never emitted, just to silence "... depends on non-NOTIFYable ..."
|
|
|
|
void devModelChanged();
|
|
|
|
/// \remarks Never emitted, just to silence "... depends on non-NOTIFYable ..."
|
|
|
|
void downloadModelChanged();
|
2017-09-08 16:59:53 +02:00
|
|
|
/// \remarks Never emitted, just to silence "... depends on non-NOTIFYable ..."
|
2018-10-10 17:48:48 +02:00
|
|
|
void passiveSelectionModelChanged();
|
|
|
|
/// \remarks Never emitted, just to silence "... depends on non-NOTIFYable ..."
|
2017-09-08 16:59:53 +02:00
|
|
|
void serviceChanged();
|
|
|
|
void localChanged();
|
2017-08-29 23:58:49 +02:00
|
|
|
void connectionStatusChanged();
|
|
|
|
void trafficChanged();
|
2019-02-17 23:45:53 +01:00
|
|
|
void statisticsChanged();
|
2017-09-09 21:40:00 +02:00
|
|
|
void settingsChanged();
|
2017-09-08 16:59:53 +02:00
|
|
|
void currentConnectionConfigIndexChanged(int index);
|
2017-09-18 20:29:36 +02:00
|
|
|
void sizeChanged(const QSize &size);
|
2017-10-01 21:42:26 +02:00
|
|
|
void notificationsAvailableChanged(bool notificationsAvailable);
|
2018-10-10 17:48:48 +02:00
|
|
|
void passiveChanged(bool passive);
|
2017-08-29 23:58:49 +02:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
2017-09-09 21:40:00 +02:00
|
|
|
void handleSettingsChanged();
|
2018-10-10 23:37:24 +02:00
|
|
|
void handleConnectionStatusChanged(Data::SyncthingStatus previousStatus, Data::SyncthingStatus newStatus);
|
2017-10-05 00:08:46 +02:00
|
|
|
void handleDevicesChanged();
|
2017-09-08 16:59:53 +02:00
|
|
|
void handleInternalError(
|
|
|
|
const QString &errorMsg, Data::SyncthingErrorCategory category, int networkError, const QNetworkRequest &request, const QByteArray &response);
|
2019-02-17 23:45:53 +01:00
|
|
|
void handleDirStatisticsChanged();
|
2017-09-08 16:59:53 +02:00
|
|
|
void handleErrorsCleared();
|
2017-08-29 23:58:49 +02:00
|
|
|
void handleAboutDialogDeleted();
|
|
|
|
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
|
|
|
|
void handleWebViewDeleted();
|
|
|
|
#endif
|
2019-06-10 22:48:26 +02:00
|
|
|
void handleNewNotification(CppUtilities::DateTime when, const QString &msg);
|
2017-09-08 16:59:53 +02:00
|
|
|
void handleSystemdServiceError(const QString &context, const QString &name, const QString &message);
|
2018-04-02 20:26:00 +02:00
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
|
|
|
void handleSystemdStatusChanged();
|
|
|
|
#endif
|
2018-10-10 17:48:48 +02:00
|
|
|
void setPassive(bool passive);
|
2017-08-29 23:58:49 +02:00
|
|
|
|
|
|
|
private:
|
2019-06-10 22:48:26 +02:00
|
|
|
QtUtilities::AboutDialog *m_aboutDlg;
|
2017-08-29 23:58:49 +02:00
|
|
|
Data::SyncthingConnection m_connection;
|
2019-02-17 23:45:53 +01:00
|
|
|
Data::SyncthingOverallDirStatistics m_overallStats;
|
2018-01-27 23:27:50 +01:00
|
|
|
Data::SyncthingNotifier m_notifier;
|
2018-04-11 23:15:15 +02:00
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
|
|
|
Data::SyncthingService m_service;
|
|
|
|
#endif
|
2017-08-29 23:58:49 +02:00
|
|
|
QtGui::StatusInfo m_statusInfo;
|
|
|
|
Data::SyncthingDirectoryModel m_dirModel;
|
|
|
|
Data::SyncthingDeviceModel m_devModel;
|
|
|
|
Data::SyncthingDownloadModel m_downloadModel;
|
2018-10-10 17:48:48 +02:00
|
|
|
Data::SyncthingStatusSelectionModel m_passiveSelectionModel;
|
|
|
|
SettingsDialog *m_settingsDlg;
|
2017-09-08 16:59:53 +02:00
|
|
|
QtGui::DBusStatusNotifier m_dbusNotifier;
|
|
|
|
std::vector<Data::SyncthingLogEntry> m_notifications;
|
2017-08-29 23:58:49 +02:00
|
|
|
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
|
|
|
|
QtGui::WebViewDialog *m_webViewDlg;
|
|
|
|
#endif
|
2017-09-08 16:59:53 +02:00
|
|
|
int m_currentConnectionConfig;
|
2017-09-09 21:40:00 +02:00
|
|
|
bool m_initialized;
|
2017-09-18 20:29:36 +02:00
|
|
|
QSize m_size;
|
2017-08-29 23:58:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
inline Data::SyncthingConnection *SyncthingApplet::connection() const
|
|
|
|
{
|
|
|
|
return const_cast<Data::SyncthingConnection *>(&m_connection);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Data::SyncthingDirectoryModel *SyncthingApplet::dirModel() const
|
|
|
|
{
|
|
|
|
return const_cast<Data::SyncthingDirectoryModel *>(&m_dirModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Data::SyncthingDeviceModel *SyncthingApplet::devModel() const
|
|
|
|
{
|
|
|
|
return const_cast<Data::SyncthingDeviceModel *>(&m_devModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Data::SyncthingDownloadModel *SyncthingApplet::downloadModel() const
|
|
|
|
{
|
|
|
|
return const_cast<Data::SyncthingDownloadModel *>(&m_downloadModel);
|
|
|
|
}
|
|
|
|
|
2018-10-10 17:48:48 +02:00
|
|
|
inline Data::SyncthingStatusSelectionModel *SyncthingApplet::passiveSelectionModel() const
|
|
|
|
{
|
|
|
|
return const_cast<Data::SyncthingStatusSelectionModel *>(&m_passiveSelectionModel);
|
|
|
|
}
|
|
|
|
|
2017-09-08 16:59:53 +02:00
|
|
|
inline Data::SyncthingService *SyncthingApplet::service() const
|
|
|
|
{
|
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
2018-04-11 23:15:15 +02:00
|
|
|
return const_cast<Data::SyncthingService *>(&m_service);
|
2017-09-08 16:59:53 +02:00
|
|
|
#else
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-09-09 21:40:00 +02:00
|
|
|
inline QString SyncthingApplet::statusText() const
|
|
|
|
{
|
|
|
|
return m_statusInfo.statusText();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline QString SyncthingApplet::additionalStatusText() const
|
|
|
|
{
|
|
|
|
return m_statusInfo.additionalStatusText();
|
|
|
|
}
|
|
|
|
|
2017-09-08 16:59:53 +02:00
|
|
|
inline bool SyncthingApplet::isLocal() const
|
|
|
|
{
|
|
|
|
return m_connection.isLocal();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int SyncthingApplet::currentConnectionConfigIndex() const
|
|
|
|
{
|
|
|
|
return m_currentConnectionConfig;
|
|
|
|
}
|
|
|
|
|
2017-09-09 21:40:00 +02:00
|
|
|
inline Data::SyncthingConnectionSettings *SyncthingApplet::currentConnectionConfig()
|
|
|
|
{
|
|
|
|
return connectionConfig(m_currentConnectionConfig);
|
|
|
|
}
|
2017-09-18 20:29:36 +02:00
|
|
|
|
|
|
|
inline QSize SyncthingApplet::size() const
|
|
|
|
{
|
|
|
|
return m_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SyncthingApplet::setSize(const QSize &size)
|
|
|
|
{
|
|
|
|
if (size != m_size) {
|
|
|
|
emit sizeChanged(m_size = size);
|
|
|
|
}
|
|
|
|
}
|
2018-10-10 17:48:48 +02:00
|
|
|
|
|
|
|
inline bool SyncthingApplet::isPassive() const
|
|
|
|
{
|
|
|
|
return status() == Plasma::Types::PassiveStatus;
|
|
|
|
}
|
|
|
|
|
2019-06-10 22:48:26 +02:00
|
|
|
inline const QList<QtUtilities::ChecklistItem> &SyncthingApplet::passiveStates() const
|
2018-10-10 17:48:48 +02:00
|
|
|
{
|
|
|
|
return m_passiveSelectionModel.items();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SyncthingApplet::setPassive(bool passive)
|
|
|
|
{
|
|
|
|
if (passive != isPassive()) {
|
|
|
|
setStatus(passive ? Plasma::Types::PassiveStatus : Plasma::Types::ActiveStatus);
|
|
|
|
emit passiveChanged(passive);
|
|
|
|
}
|
|
|
|
}
|
2017-09-17 21:48:15 +02:00
|
|
|
} // namespace Plasmoid
|
2017-09-09 21:40:00 +02:00
|
|
|
|
2017-08-29 23:58:49 +02:00
|
|
|
#endif // SYNCTHINGAPPLET_H
|