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"
|
|
|
|
|
|
|
|
#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>
|
|
|
|
|
|
|
|
#include <Plasma/Applet>
|
|
|
|
|
2017-09-18 20:29:36 +02:00
|
|
|
#include <QSize>
|
|
|
|
|
2017-08-29 23:58:49 +02:00
|
|
|
namespace Dialogs {
|
|
|
|
class SettingsDialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
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)
|
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)
|
|
|
|
Q_PROPERTY(QString outgoingTraffic READ outgoingTraffic NOTIFY trafficChanged)
|
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)
|
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;
|
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;
|
|
|
|
QString outgoingTraffic() 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;
|
2017-08-29 23:58:49 +02:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void init() Q_DECL_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();
|
|
|
|
void showDirectoryErrors(unsigned int directoryIndex) const;
|
2017-10-01 17:49:48 +02:00
|
|
|
void copyToClipboard(const QString &text);
|
2017-10-16 19:40:44 +02:00
|
|
|
void updateStatusIconAndTooltip();
|
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 ..."
|
|
|
|
void serviceChanged();
|
|
|
|
void localChanged();
|
2017-08-29 23:58:49 +02:00
|
|
|
void connectionStatusChanged();
|
|
|
|
void trafficChanged();
|
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);
|
2017-08-29 23:58:49 +02:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
2017-09-09 21:40:00 +02:00
|
|
|
void handleSettingsChanged();
|
|
|
|
void handleConnectionStatusChanged(Data::SyncthingStatus status);
|
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);
|
|
|
|
void handleErrorsCleared();
|
2017-08-29 23:58:49 +02:00
|
|
|
void handleAboutDialogDeleted();
|
|
|
|
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
|
|
|
|
void handleWebViewDeleted();
|
|
|
|
#endif
|
2017-09-08 16:59:53 +02:00
|
|
|
void handleNewNotification(ChronoUtilities::DateTime when, const QString &msg);
|
|
|
|
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
|
2017-08-29 23:58:49 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
Dialogs::AboutDialog *m_aboutDlg;
|
|
|
|
Data::SyncthingConnection m_connection;
|
2018-01-27 23:27:50 +01:00
|
|
|
Data::SyncthingNotifier m_notifier;
|
2017-08-29 23:58:49 +02:00
|
|
|
QtGui::StatusInfo m_statusInfo;
|
|
|
|
Data::SyncthingDirectoryModel m_dirModel;
|
|
|
|
Data::SyncthingDeviceModel m_devModel;
|
|
|
|
Data::SyncthingDownloadModel m_downloadModel;
|
2017-09-08 16:59:53 +02:00
|
|
|
Dialogs::SettingsDialog *m_settingsDlg;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-09-08 16:59:53 +02:00
|
|
|
inline Data::SyncthingService *SyncthingApplet::service() const
|
|
|
|
{
|
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
|
|
|
return &Data::syncthingService();
|
|
|
|
#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);
|
|
|
|
}
|
|
|
|
}
|
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
|