2017-08-29 23:58:49 +02:00
|
|
|
#include "./syncthingapplet.h"
|
2017-09-09 21:40:00 +02:00
|
|
|
#include "./settingsdialog.h"
|
2017-08-29 23:58:49 +02:00
|
|
|
|
2017-09-08 16:59:53 +02:00
|
|
|
#include "../../connector/syncthingservice.h"
|
|
|
|
#include "../../connector/utils.h"
|
|
|
|
|
2018-11-03 21:30:17 +01:00
|
|
|
#include "../../widgets/misc/direrrorsdialog.h"
|
2018-11-03 18:07:45 +01:00
|
|
|
#include "../../widgets/misc/internalerrorsdialog.h"
|
2017-08-29 23:58:49 +02:00
|
|
|
#include "../../widgets/misc/otherdialogs.h"
|
|
|
|
#include "../../widgets/misc/textviewdialog.h"
|
|
|
|
#include "../../widgets/settings/settings.h"
|
|
|
|
#include "../../widgets/settings/settingsdialog.h"
|
|
|
|
#include "../../widgets/webview/webviewdialog.h"
|
|
|
|
|
|
|
|
#include "../../model/syncthingicons.h"
|
|
|
|
|
|
|
|
#include "../../connector/utils.h"
|
|
|
|
|
|
|
|
#include "resources/config.h"
|
2019-03-13 19:12:23 +01:00
|
|
|
#include "resources/qtconfig.h"
|
2017-08-29 23:58:49 +02:00
|
|
|
|
|
|
|
#include <qtutilities/misc/desktoputils.h>
|
|
|
|
#include <qtutilities/misc/dialogutils.h>
|
|
|
|
#include <qtutilities/resources/resources.h>
|
|
|
|
|
2018-03-18 18:24:00 +01:00
|
|
|
#include <c++utilities/application/argumentparser.h>
|
2019-02-27 20:42:41 +01:00
|
|
|
#include <c++utilities/conversion/stringconversion.h>
|
2018-03-18 18:24:00 +01:00
|
|
|
|
2017-09-18 20:29:36 +02:00
|
|
|
#include <KConfigGroup>
|
|
|
|
|
2017-10-01 17:49:48 +02:00
|
|
|
#include <QClipboard>
|
2017-08-29 23:58:49 +02:00
|
|
|
#include <QDesktopServices>
|
2017-10-01 17:49:48 +02:00
|
|
|
#include <QGuiApplication>
|
2017-09-08 16:59:53 +02:00
|
|
|
#include <QNetworkReply>
|
2019-02-23 13:55:46 +01:00
|
|
|
#include <QPalette>
|
2017-08-29 23:58:49 +02:00
|
|
|
#include <QQmlEngine>
|
2017-09-08 16:59:53 +02:00
|
|
|
#include <QStringBuilder>
|
2017-08-29 23:58:49 +02:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Data;
|
|
|
|
using namespace Plasma;
|
|
|
|
using namespace Dialogs;
|
|
|
|
using namespace QtGui;
|
2019-02-27 20:42:41 +01:00
|
|
|
using namespace ConversionUtilities;
|
2017-09-08 16:59:53 +02:00
|
|
|
using namespace ChronoUtilities;
|
2017-08-29 23:58:49 +02:00
|
|
|
|
2017-09-09 21:40:00 +02:00
|
|
|
namespace Plasmoid {
|
|
|
|
|
2017-08-29 23:58:49 +02:00
|
|
|
SyncthingApplet::SyncthingApplet(QObject *parent, const QVariantList &data)
|
|
|
|
: Applet(parent, data)
|
|
|
|
, m_aboutDlg(nullptr)
|
|
|
|
, m_connection()
|
2018-01-27 23:27:50 +01:00
|
|
|
, m_notifier(m_connection)
|
2017-08-29 23:58:49 +02:00
|
|
|
, m_dirModel(m_connection)
|
|
|
|
, m_devModel(m_connection)
|
|
|
|
, m_downloadModel(m_connection)
|
2017-09-08 16:59:53 +02:00
|
|
|
, m_settingsDlg(nullptr)
|
2017-08-29 23:58:49 +02:00
|
|
|
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
|
|
|
|
, m_webViewDlg(nullptr)
|
|
|
|
#endif
|
2017-09-08 16:59:53 +02:00
|
|
|
, m_currentConnectionConfig(-1)
|
2017-09-09 21:40:00 +02:00
|
|
|
, m_initialized(false)
|
2017-08-29 23:58:49 +02:00
|
|
|
{
|
2018-05-15 22:27:54 +02:00
|
|
|
m_notifier.setService(&m_service);
|
2017-08-29 23:58:49 +02:00
|
|
|
qmlRegisterUncreatableMetaObject(Data::staticMetaObject, "martchus.syncthingplasmoid", 0, 6, "Data", QStringLiteral("only enums"));
|
|
|
|
}
|
|
|
|
|
|
|
|
SyncthingApplet::~SyncthingApplet()
|
|
|
|
{
|
2017-09-08 16:59:53 +02:00
|
|
|
delete m_settingsDlg;
|
2017-08-29 23:58:49 +02:00
|
|
|
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
|
|
|
|
delete m_webViewDlg;
|
|
|
|
#endif
|
2018-04-11 23:15:15 +02:00
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
|
|
|
SyncthingService::setMainInstance(nullptr);
|
|
|
|
#endif
|
2017-08-29 23:58:49 +02:00
|
|
|
}
|
|
|
|
|
2017-09-09 21:40:00 +02:00
|
|
|
void SyncthingApplet::init()
|
|
|
|
{
|
|
|
|
LOAD_QT_TRANSLATIONS;
|
|
|
|
|
|
|
|
Applet::init();
|
|
|
|
|
|
|
|
// connect signals and slots
|
2018-01-27 23:27:50 +01:00
|
|
|
connect(&m_notifier, &SyncthingNotifier::statusChanged, this, &SyncthingApplet::handleConnectionStatusChanged);
|
|
|
|
connect(&m_notifier, &SyncthingNotifier::syncComplete, &m_dbusNotifier, &DBusStatusNotifier::showSyncComplete);
|
|
|
|
connect(&m_notifier, &SyncthingNotifier::disconnected, &m_dbusNotifier, &DBusStatusNotifier::showDisconnect);
|
2017-10-05 00:08:46 +02:00
|
|
|
connect(&m_connection, &SyncthingConnection::newDevices, this, &SyncthingApplet::handleDevicesChanged);
|
|
|
|
connect(&m_connection, &SyncthingConnection::devStatusChanged, this, &SyncthingApplet::handleDevicesChanged);
|
2017-09-09 21:40:00 +02:00
|
|
|
connect(&m_connection, &SyncthingConnection::error, this, &SyncthingApplet::handleInternalError);
|
|
|
|
connect(&m_connection, &SyncthingConnection::trafficChanged, this, &SyncthingApplet::trafficChanged);
|
2019-02-17 23:45:53 +01:00
|
|
|
connect(&m_connection, &SyncthingConnection::dirStatisticsChanged, this, &SyncthingApplet::handleDirStatisticsChanged);
|
2017-09-09 21:40:00 +02:00
|
|
|
connect(&m_connection, &SyncthingConnection::newNotification, this, &SyncthingApplet::handleNewNotification);
|
2018-05-01 22:27:03 +02:00
|
|
|
connect(&m_notifier, &SyncthingNotifier::newDevice, &m_dbusNotifier, &DBusStatusNotifier::showNewDev);
|
|
|
|
connect(&m_notifier, &SyncthingNotifier::newDir, &m_dbusNotifier, &DBusStatusNotifier::showNewDir);
|
2017-09-09 21:40:00 +02:00
|
|
|
connect(&m_dbusNotifier, &DBusStatusNotifier::connectRequested, &m_connection,
|
|
|
|
static_cast<void (SyncthingConnection::*)(void)>(&SyncthingConnection::connect));
|
|
|
|
connect(&m_dbusNotifier, &DBusStatusNotifier::dismissNotificationsRequested, this, &SyncthingApplet::dismissNotifications);
|
|
|
|
connect(&m_dbusNotifier, &DBusStatusNotifier::showNotificationsRequested, this, &SyncthingApplet::showNotificationsDialog);
|
|
|
|
connect(&m_dbusNotifier, &DBusStatusNotifier::errorDetailsRequested, this, &SyncthingApplet::showInternalErrorsDialog);
|
2018-05-01 22:27:03 +02:00
|
|
|
connect(&m_dbusNotifier, &DBusStatusNotifier::webUiRequested, this, &SyncthingApplet::showWebUI);
|
2017-09-09 21:40:00 +02:00
|
|
|
|
|
|
|
// restore settings
|
|
|
|
Settings::restore();
|
|
|
|
|
2018-04-12 23:16:51 +02:00
|
|
|
// initialize systemd service support
|
2017-09-09 21:40:00 +02:00
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
2018-04-11 23:15:15 +02:00
|
|
|
SyncthingService::setMainInstance(&m_service);
|
|
|
|
m_service.setUnitName(Settings::values().systemd.syncthingUnit);
|
|
|
|
connect(&m_service, &SyncthingService::systemdAvailableChanged, this, &SyncthingApplet::handleSystemdStatusChanged);
|
2018-04-12 23:16:51 +02:00
|
|
|
connect(&m_service, &SyncthingService::stateChanged, this, &SyncthingApplet::handleSystemdStatusChanged);
|
2018-04-11 23:15:15 +02:00
|
|
|
connect(&m_service, &SyncthingService::errorOccurred, this, &SyncthingApplet::handleSystemdServiceError);
|
2017-09-09 21:40:00 +02:00
|
|
|
#endif
|
|
|
|
|
2018-05-15 22:01:03 +02:00
|
|
|
// load primary connection config
|
|
|
|
m_currentConnectionConfig = config().readEntry<int>("selectedConfig", 0);
|
|
|
|
|
2018-04-12 23:16:51 +02:00
|
|
|
// apply settings and connect according to settings
|
|
|
|
handleSettingsChanged();
|
|
|
|
|
2017-09-09 21:40:00 +02:00
|
|
|
m_initialized = true;
|
|
|
|
}
|
|
|
|
|
2017-08-29 23:58:49 +02:00
|
|
|
QIcon SyncthingApplet::statusIcon() const
|
|
|
|
{
|
|
|
|
return m_statusInfo.statusIcon();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SyncthingApplet::incomingTraffic() const
|
|
|
|
{
|
|
|
|
return trafficString(m_connection.totalIncomingTraffic(), m_connection.totalIncomingRate());
|
|
|
|
}
|
|
|
|
|
2019-02-17 23:45:53 +01:00
|
|
|
bool SyncthingApplet::hasIncomingTraffic() const
|
|
|
|
{
|
|
|
|
return m_connection.totalIncomingRate() > 0.0;
|
|
|
|
}
|
|
|
|
|
2017-08-29 23:58:49 +02:00
|
|
|
QString SyncthingApplet::outgoingTraffic() const
|
|
|
|
{
|
|
|
|
return trafficString(m_connection.totalOutgoingTraffic(), m_connection.totalOutgoingRate());
|
|
|
|
}
|
|
|
|
|
2019-02-17 23:45:53 +01:00
|
|
|
bool SyncthingApplet::hasOutgoingTraffic() const
|
|
|
|
{
|
|
|
|
return m_connection.totalOutgoingRate() > 0.0;
|
|
|
|
}
|
|
|
|
|
2019-02-27 20:42:41 +01:00
|
|
|
SyncthingStatistics SyncthingApplet::globalStatistics() const
|
2019-02-17 23:45:53 +01:00
|
|
|
{
|
2019-02-27 20:42:41 +01:00
|
|
|
return m_overallStats.global;
|
2019-02-17 23:45:53 +01:00
|
|
|
}
|
|
|
|
|
2019-02-27 20:42:41 +01:00
|
|
|
SyncthingStatistics SyncthingApplet::localStatistics() const
|
2019-02-17 23:45:53 +01:00
|
|
|
{
|
2019-02-27 20:42:41 +01:00
|
|
|
return m_overallStats.local;
|
2019-02-17 23:45:53 +01:00
|
|
|
}
|
|
|
|
|
2017-09-08 16:59:53 +02:00
|
|
|
QStringList SyncthingApplet::connectionConfigNames() const
|
|
|
|
{
|
|
|
|
const auto &settings = Settings::values().connection;
|
|
|
|
QStringList names;
|
|
|
|
names.reserve(static_cast<int>(settings.secondary.size() + 1));
|
|
|
|
names << settings.primary.label;
|
|
|
|
for (const auto &setting : settings.secondary) {
|
|
|
|
names << setting.label;
|
|
|
|
}
|
|
|
|
return names;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SyncthingApplet::currentConnectionConfigName() const
|
|
|
|
{
|
|
|
|
const auto &settings = Settings::values().connection;
|
|
|
|
if (m_currentConnectionConfig == 0) {
|
|
|
|
return settings.primary.label;
|
|
|
|
} else if (m_currentConnectionConfig > 0 && static_cast<unsigned>(m_currentConnectionConfig) <= settings.secondary.size()) {
|
|
|
|
return settings.secondary[static_cast<unsigned>(m_currentConnectionConfig) - 1].label;
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2017-09-09 21:40:00 +02:00
|
|
|
Data::SyncthingConnectionSettings *SyncthingApplet::connectionConfig(int index)
|
|
|
|
{
|
|
|
|
auto &connectionSettings = Settings::values().connection;
|
|
|
|
if (index >= 0 && static_cast<unsigned>(index) <= connectionSettings.secondary.size()) {
|
|
|
|
return index == 0 ? &connectionSettings.primary : &connectionSettings.secondary[static_cast<unsigned>(index) - 1];
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SyncthingApplet::setCurrentConnectionConfigIndex(int index)
|
2017-09-08 16:59:53 +02:00
|
|
|
{
|
2018-04-02 20:26:00 +02:00
|
|
|
auto &settings = Settings::values();
|
|
|
|
bool reconnectRequired = false;
|
|
|
|
if (index != m_currentConnectionConfig && index >= 0 && static_cast<unsigned>(index) <= settings.connection.secondary.size()) {
|
|
|
|
auto &selectedConfig = index == 0 ? settings.connection.primary : settings.connection.secondary[static_cast<unsigned>(index) - 1];
|
|
|
|
reconnectRequired = m_connection.applySettings(selectedConfig);
|
2017-09-08 16:59:53 +02:00
|
|
|
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
|
|
|
|
if (m_webViewDlg) {
|
2018-10-28 14:27:25 +01:00
|
|
|
m_webViewDlg->applySettings(selectedConfig, false);
|
2017-09-08 16:59:53 +02:00
|
|
|
}
|
|
|
|
#endif
|
2017-09-18 20:29:36 +02:00
|
|
|
config().writeEntry<int>("selectedConfig", index);
|
2017-09-08 16:59:53 +02:00
|
|
|
emit currentConnectionConfigIndexChanged(m_currentConnectionConfig = index);
|
|
|
|
emit localChanged();
|
|
|
|
}
|
2018-04-02 20:26:00 +02:00
|
|
|
|
|
|
|
// apply systemd settings, reconnect if required and possible
|
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
|
|
|
settings.systemd.apply(m_connection, currentConnectionConfig(), reconnectRequired);
|
|
|
|
#else
|
|
|
|
if (reconnectRequired || !m_connection.isConnected()) {
|
|
|
|
m_connection.reconnect();
|
|
|
|
}
|
|
|
|
#endif
|
2017-09-08 16:59:53 +02:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:26:00 +02:00
|
|
|
bool SyncthingApplet::isStartStopEnabled() const
|
2017-08-29 23:58:49 +02:00
|
|
|
{
|
2017-09-09 21:40:00 +02:00
|
|
|
return Settings::values().systemd.showButton;
|
2017-08-29 23:58:49 +02:00
|
|
|
}
|
|
|
|
|
2017-10-01 21:42:26 +02:00
|
|
|
bool SyncthingApplet::areNotificationsAvailable() const
|
|
|
|
{
|
|
|
|
return !m_notifications.empty();
|
|
|
|
}
|
|
|
|
|
2018-10-10 17:48:48 +02:00
|
|
|
void SyncthingApplet::setPassiveStates(const QList<Models::ChecklistItem> &passiveStates)
|
|
|
|
{
|
|
|
|
m_passiveSelectionModel.setItems(passiveStates);
|
|
|
|
const auto currentState = static_cast<int>(m_connection.status());
|
|
|
|
setPassive(currentState >= 0 && currentState < passiveStates.size() && passiveStates.at(currentState).isChecked());
|
|
|
|
}
|
|
|
|
|
2017-10-16 19:40:44 +02:00
|
|
|
void SyncthingApplet::updateStatusIconAndTooltip()
|
|
|
|
{
|
|
|
|
m_statusInfo.updateConnectionStatus(m_connection);
|
|
|
|
m_statusInfo.updateConnectedDevices(m_connection);
|
|
|
|
emit connectionStatusChanged();
|
|
|
|
}
|
|
|
|
|
2019-02-27 20:42:41 +01:00
|
|
|
QIcon SyncthingApplet::loadFontAwesomeIcon(const QString &name, bool solid) const
|
2019-02-23 13:55:46 +01:00
|
|
|
{
|
2019-02-27 20:42:41 +01:00
|
|
|
return Data::renderSvgImage(Data::loadFontAwesomeIcon(name, QGuiApplication::palette().color(QPalette::Foreground), solid), QSize(32, 32), 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SyncthingApplet::formatFileSize(quint64 fileSizeInByte) const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(dataSizeToString(fileSizeInByte));
|
2019-02-23 13:55:46 +01:00
|
|
|
}
|
|
|
|
|
2017-09-08 16:59:53 +02:00
|
|
|
void SyncthingApplet::showSettingsDlg()
|
2017-08-29 23:58:49 +02:00
|
|
|
{
|
2017-09-08 16:59:53 +02:00
|
|
|
if (!m_settingsDlg) {
|
2018-10-10 17:48:48 +02:00
|
|
|
m_settingsDlg = new SettingsDialog(*this);
|
2017-09-18 20:29:36 +02:00
|
|
|
// ensure settings take effect when applied
|
2017-09-09 21:40:00 +02:00
|
|
|
connect(m_settingsDlg, &Dialogs::SettingsDialog::applied, this, &SyncthingApplet::handleSettingsChanged);
|
2017-09-18 20:29:36 +02:00
|
|
|
// save plasmoid specific settings to disk when applied
|
|
|
|
connect(m_settingsDlg, &Dialogs::SettingsDialog::applied, this, &SyncthingApplet::configChanged);
|
|
|
|
// save global/general settings to disk when applied
|
|
|
|
connect(m_settingsDlg, &Dialogs::SettingsDialog::applied, &Settings::save);
|
2017-08-29 23:58:49 +02:00
|
|
|
}
|
2017-09-08 16:59:53 +02:00
|
|
|
Dialogs::centerWidget(m_settingsDlg);
|
|
|
|
m_settingsDlg->show();
|
|
|
|
m_settingsDlg->activateWindow();
|
2017-08-29 23:58:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SyncthingApplet::showWebUI()
|
|
|
|
{
|
|
|
|
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
|
|
|
|
if (Settings::values().webView.disabled) {
|
|
|
|
#endif
|
|
|
|
QDesktopServices::openUrl(m_connection.syncthingUrl());
|
|
|
|
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
|
|
|
|
} else {
|
|
|
|
if (!m_webViewDlg) {
|
|
|
|
m_webViewDlg = new WebViewDialog;
|
2017-09-09 21:40:00 +02:00
|
|
|
if (const auto *connectionConfig = currentConnectionConfig()) {
|
2018-10-28 14:27:25 +01:00
|
|
|
m_webViewDlg->applySettings(*connectionConfig, true);
|
2017-09-09 21:40:00 +02:00
|
|
|
}
|
2017-08-29 23:58:49 +02:00
|
|
|
connect(m_webViewDlg, &WebViewDialog::destroyed, this, &SyncthingApplet::handleWebViewDeleted);
|
|
|
|
}
|
|
|
|
m_webViewDlg->show();
|
|
|
|
m_webViewDlg->activateWindow();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void SyncthingApplet::showLog()
|
|
|
|
{
|
|
|
|
auto *const dlg = TextViewDialog::forLogEntries(m_connection);
|
|
|
|
dlg->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
centerWidget(dlg);
|
|
|
|
dlg->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SyncthingApplet::showOwnDeviceId()
|
|
|
|
{
|
|
|
|
auto *const dlg = ownDeviceIdDialog(m_connection);
|
|
|
|
dlg->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
centerWidget(dlg);
|
|
|
|
dlg->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SyncthingApplet::showAboutDialog()
|
|
|
|
{
|
|
|
|
if (!m_aboutDlg) {
|
2019-02-17 23:45:53 +01:00
|
|
|
m_aboutDlg = new AboutDialog(nullptr, QStringLiteral(APP_NAME),
|
|
|
|
QStringLiteral("<p>Developed by " APP_AUTHOR "<br>Syncthing icons from <a href=\"https://syncthing.net\">Syncthing project</a><br>Using "
|
|
|
|
"icons from <a href=\"https://fontawesome.com\">Font "
|
|
|
|
"Awesome</a> (see <a href=\"https://fontawesome.com/license\">their license</a>)</p>"),
|
2019-05-05 18:42:19 +02:00
|
|
|
QStringLiteral(APP_VERSION), ApplicationUtilities::applicationInfo.dependencyVersions, QStringLiteral(APP_URL),
|
|
|
|
QStringLiteral(APP_DESCRIPTION), QImage(statusIcons().scanninig.pixmap(128).toImage()));
|
2017-08-29 23:58:49 +02:00
|
|
|
m_aboutDlg->setWindowTitle(tr("About") + QStringLiteral(" - " APP_NAME));
|
2017-09-08 16:59:53 +02:00
|
|
|
m_aboutDlg->setWindowIcon(QIcon::fromTheme(QStringLiteral("syncthingtray")));
|
2017-08-29 23:58:49 +02:00
|
|
|
m_aboutDlg->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
connect(m_aboutDlg, &QObject::destroyed, this, &SyncthingApplet::handleAboutDialogDeleted);
|
|
|
|
}
|
|
|
|
centerWidget(m_aboutDlg);
|
|
|
|
m_aboutDlg->show();
|
|
|
|
m_aboutDlg->activateWindow();
|
|
|
|
}
|
|
|
|
|
2017-09-08 16:59:53 +02:00
|
|
|
void SyncthingApplet::showNotificationsDialog()
|
|
|
|
{
|
|
|
|
auto *const dlg = TextViewDialog::forLogEntries(m_notifications, tr("New notifications"));
|
|
|
|
dlg->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
centerWidget(dlg);
|
|
|
|
dlg->show();
|
|
|
|
dismissNotifications();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SyncthingApplet::dismissNotifications()
|
2017-08-29 23:58:49 +02:00
|
|
|
{
|
2017-09-08 16:59:53 +02:00
|
|
|
m_connection.considerAllNotificationsRead();
|
2017-10-01 21:42:26 +02:00
|
|
|
if (!m_notifications.empty()) {
|
|
|
|
m_notifications.clear();
|
|
|
|
emit notificationsAvailableChanged(false);
|
2017-10-16 19:40:44 +02:00
|
|
|
// update status as well because having or not having notifications is relevant for status text/icon
|
|
|
|
updateStatusIconAndTooltip();
|
2017-10-01 21:42:26 +02:00
|
|
|
}
|
2017-09-08 16:59:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SyncthingApplet::showInternalErrorsDialog()
|
|
|
|
{
|
2018-11-03 18:07:45 +01:00
|
|
|
auto *const errorViewDlg = InternalErrorsDialog::instance();
|
|
|
|
connect(errorViewDlg, &InternalErrorsDialog::errorsCleared, this, &SyncthingApplet::handleErrorsCleared);
|
2017-09-08 16:59:53 +02:00
|
|
|
centerWidget(errorViewDlg);
|
|
|
|
errorViewDlg->show();
|
|
|
|
}
|
|
|
|
|
2018-11-03 21:30:17 +01:00
|
|
|
void SyncthingApplet::showDirectoryErrors(unsigned int directoryIndex)
|
2017-09-08 16:59:53 +02:00
|
|
|
{
|
|
|
|
const auto &dirs = m_connection.dirInfo();
|
2018-11-03 21:30:17 +01:00
|
|
|
if (directoryIndex >= dirs.size()) {
|
|
|
|
return;
|
2017-08-29 23:58:49 +02:00
|
|
|
}
|
2018-11-03 21:30:17 +01:00
|
|
|
|
|
|
|
const auto &dir(dirs[directoryIndex]);
|
|
|
|
m_connection.requestDirPullErrors(dir.id);
|
|
|
|
|
|
|
|
auto *const dlg = new DirectoryErrorsDialog(m_connection, dir);
|
|
|
|
dlg->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
centerWidget(dlg);
|
|
|
|
dlg->show();
|
2017-08-29 23:58:49 +02:00
|
|
|
}
|
|
|
|
|
2017-10-01 17:49:48 +02:00
|
|
|
void SyncthingApplet::copyToClipboard(const QString &text)
|
|
|
|
{
|
|
|
|
QGuiApplication::clipboard()->setText(text);
|
|
|
|
}
|
|
|
|
|
2017-09-18 20:29:36 +02:00
|
|
|
/*!
|
|
|
|
* \brief Ensures settings take effect when applied via the settings dialog.
|
|
|
|
* \remarks Does not save the settings to disk. This is done in Settings::save() and Applet::configChanged().
|
|
|
|
*/
|
2017-09-09 21:40:00 +02:00
|
|
|
void SyncthingApplet::handleSettingsChanged()
|
2017-09-08 16:59:53 +02:00
|
|
|
{
|
2017-09-18 20:29:36 +02:00
|
|
|
const KConfigGroup config(this->config());
|
2018-01-27 23:27:50 +01:00
|
|
|
const auto &settings(Settings::values());
|
|
|
|
|
|
|
|
// apply notifiction settings
|
2018-04-02 20:26:00 +02:00
|
|
|
settings.apply(m_notifier);
|
2017-09-18 20:29:36 +02:00
|
|
|
|
2017-09-11 23:47:46 +02:00
|
|
|
// apply appearance settings
|
2017-09-18 20:29:36 +02:00
|
|
|
setSize(config.readEntry<QSize>("size", QSize(25, 25)));
|
|
|
|
const bool brightColors = config.readEntry<bool>("brightColors", false);
|
|
|
|
m_dirModel.setBrightColors(brightColors);
|
|
|
|
m_devModel.setBrightColors(brightColors);
|
|
|
|
m_downloadModel.setBrightColors(brightColors);
|
2017-09-11 23:47:46 +02:00
|
|
|
|
2018-10-10 17:48:48 +02:00
|
|
|
// restore selected states
|
|
|
|
// note: The settings dialog writes this to the Plasmoid's config like the other settings. However, it
|
|
|
|
// is simpler and more efficient to assign the states directly. Of course this is only possible if
|
|
|
|
// the dialog has already been shown.
|
|
|
|
if (m_settingsDlg) {
|
|
|
|
setPassiveStates(m_settingsDlg->appearanceOptionPage()->passiveStatusSelection()->items());
|
|
|
|
} else {
|
2018-10-10 21:00:13 +02:00
|
|
|
m_passiveSelectionModel.applyVariantList(config.readEntry("passiveStates", QVariantList()));
|
2018-10-10 17:48:48 +02:00
|
|
|
}
|
|
|
|
|
2017-09-11 23:47:46 +02:00
|
|
|
// apply connection config
|
2017-09-08 16:59:53 +02:00
|
|
|
const int currentConfig = m_currentConnectionConfig;
|
|
|
|
m_currentConnectionConfig = -1; // force update
|
|
|
|
setCurrentConnectionConfigIndex(currentConfig);
|
2017-09-11 23:47:46 +02:00
|
|
|
|
2017-09-09 21:40:00 +02:00
|
|
|
emit settingsChanged();
|
2017-09-08 16:59:53 +02:00
|
|
|
}
|
|
|
|
|
2018-10-10 23:37:24 +02:00
|
|
|
void SyncthingApplet::handleConnectionStatusChanged(Data::SyncthingStatus previousStatus, Data::SyncthingStatus newStatus)
|
2017-08-29 23:58:49 +02:00
|
|
|
{
|
2018-10-10 23:37:24 +02:00
|
|
|
Q_UNUSED(previousStatus)
|
2018-01-28 18:08:03 +01:00
|
|
|
if (!m_initialized) {
|
2017-09-09 21:40:00 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-10 17:48:48 +02:00
|
|
|
// update whether passive
|
2018-10-10 23:37:24 +02:00
|
|
|
setPassive(static_cast<int>(newStatus) < passiveStates().size() && passiveStates().at(static_cast<int>(newStatus)).isChecked());
|
2018-10-10 17:48:48 +02:00
|
|
|
|
2017-09-09 21:40:00 +02:00
|
|
|
// update status icon and tooltip text
|
2017-10-05 00:08:46 +02:00
|
|
|
m_statusInfo.updateConnectionStatus(m_connection);
|
|
|
|
m_statusInfo.updateConnectedDevices(m_connection);
|
2017-08-29 23:58:49 +02:00
|
|
|
emit connectionStatusChanged();
|
|
|
|
}
|
|
|
|
|
2017-10-05 00:08:46 +02:00
|
|
|
void SyncthingApplet::handleDevicesChanged()
|
|
|
|
{
|
|
|
|
m_statusInfo.updateConnectedDevices(m_connection);
|
2018-08-04 15:47:19 +02:00
|
|
|
emit connectionStatusChanged();
|
2017-10-05 00:08:46 +02:00
|
|
|
}
|
|
|
|
|
2017-09-08 16:59:53 +02:00
|
|
|
void SyncthingApplet::handleInternalError(
|
|
|
|
const QString &errorMsg, SyncthingErrorCategory category, int networkError, const QNetworkRequest &request, const QByteArray &response)
|
|
|
|
{
|
2018-04-02 20:26:00 +02:00
|
|
|
if (!InternalError::isRelevant(m_connection, category, networkError)) {
|
|
|
|
return;
|
2017-09-08 16:59:53 +02:00
|
|
|
}
|
2018-04-02 20:26:00 +02:00
|
|
|
InternalError error(errorMsg, request.url(), response);
|
|
|
|
m_dbusNotifier.showInternalError(error);
|
2018-11-03 18:07:45 +01:00
|
|
|
InternalErrorsDialog::addError(move(error));
|
2017-09-08 16:59:53 +02:00
|
|
|
}
|
|
|
|
|
2019-02-17 23:45:53 +01:00
|
|
|
void SyncthingApplet::handleDirStatisticsChanged()
|
|
|
|
{
|
|
|
|
m_overallStats = m_connection.computeOverallDirStatistics();
|
|
|
|
emit statisticsChanged();
|
|
|
|
}
|
|
|
|
|
2017-09-08 16:59:53 +02:00
|
|
|
void SyncthingApplet::handleErrorsCleared()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-08-29 23:58:49 +02:00
|
|
|
void SyncthingApplet::handleAboutDialogDeleted()
|
|
|
|
{
|
|
|
|
m_aboutDlg = nullptr;
|
|
|
|
}
|
|
|
|
|
2018-08-24 15:34:36 +02:00
|
|
|
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
|
2017-08-29 23:58:49 +02:00
|
|
|
void SyncthingApplet::handleWebViewDeleted()
|
|
|
|
{
|
|
|
|
m_webViewDlg = nullptr;
|
|
|
|
}
|
2018-08-24 15:34:36 +02:00
|
|
|
#endif
|
2017-08-29 23:58:49 +02:00
|
|
|
|
2017-09-08 16:59:53 +02:00
|
|
|
void SyncthingApplet::handleNewNotification(DateTime when, const QString &msg)
|
|
|
|
{
|
|
|
|
m_notifications.emplace_back(QString::fromLocal8Bit(when.toString(DateTimeOutputFormat::DateAndTime, true).data()), msg);
|
|
|
|
if (Settings::values().notifyOn.syncthingErrors) {
|
|
|
|
m_dbusNotifier.showSyncthingNotification(when, msg);
|
|
|
|
}
|
2017-10-01 21:42:26 +02:00
|
|
|
if (m_notifications.size() == 1) {
|
|
|
|
emit notificationsAvailableChanged(true);
|
2017-10-16 19:40:44 +02:00
|
|
|
// update status as well because having or not having notifications is relevant for status text/icon
|
|
|
|
updateStatusIconAndTooltip();
|
2017-10-01 21:42:26 +02:00
|
|
|
}
|
2017-09-08 16:59:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SyncthingApplet::handleSystemdServiceError(const QString &context, const QString &name, const QString &message)
|
|
|
|
{
|
|
|
|
handleInternalError(tr("D-Bus error - unable to ") % context % QChar('\n') % name % QChar(':') % message, SyncthingErrorCategory::SpecificRequest,
|
|
|
|
QNetworkReply::NoError, QNetworkRequest(), QByteArray());
|
|
|
|
}
|
2018-04-02 20:26:00 +02:00
|
|
|
|
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
|
|
|
void SyncthingApplet::handleSystemdStatusChanged()
|
|
|
|
{
|
|
|
|
Settings::values().systemd.apply(m_connection, currentConnectionConfig());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-09-17 21:48:15 +02:00
|
|
|
} // namespace Plasmoid
|
2017-09-08 16:59:53 +02:00
|
|
|
|
2017-09-09 21:40:00 +02:00
|
|
|
K_EXPORT_PLASMA_APPLET_WITH_JSON(syncthing, Plasmoid::SyncthingApplet, "metadata.json")
|
2017-08-29 23:58:49 +02:00
|
|
|
|
|
|
|
#include "syncthingapplet.moc"
|