Allow hiding Plasma applet in certain states
See https://github.com/Martchus/syncthingtray/issues/23
This commit is contained in:
parent
f0a2d60906
commit
87a10c5b33
|
@ -117,11 +117,11 @@ bool SyncthingConnection::isLocal() const
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Returns the string representation of the current status().
|
* \brief Returns the string representation of the specified \a status.
|
||||||
*/
|
*/
|
||||||
QString SyncthingConnection::statusText() const
|
QString SyncthingConnection::statusText(SyncthingStatus status)
|
||||||
{
|
{
|
||||||
switch (m_status) {
|
switch (status) {
|
||||||
case SyncthingStatus::Disconnected:
|
case SyncthingStatus::Disconnected:
|
||||||
return tr("disconnected");
|
return tr("disconnected");
|
||||||
case SyncthingStatus::Reconnecting:
|
case SyncthingStatus::Reconnecting:
|
||||||
|
|
|
@ -106,6 +106,7 @@ public:
|
||||||
void setCredentials(const QString &user, const QString &password);
|
void setCredentials(const QString &user, const QString &password);
|
||||||
SyncthingStatus status() const;
|
SyncthingStatus status() const;
|
||||||
QString statusText() const;
|
QString statusText() const;
|
||||||
|
static QString statusText(SyncthingStatus status);
|
||||||
bool isConnected() const;
|
bool isConnected() const;
|
||||||
bool hasUnreadNotifications() const;
|
bool hasUnreadNotifications() const;
|
||||||
bool hasOutOfSyncDirs() const;
|
bool hasOutOfSyncDirs() const;
|
||||||
|
@ -379,7 +380,16 @@ inline const QString &SyncthingConnection::password() const
|
||||||
*/
|
*/
|
||||||
inline void SyncthingConnection::setCredentials(const QString &user, const QString &password)
|
inline void SyncthingConnection::setCredentials(const QString &user, const QString &password)
|
||||||
{
|
{
|
||||||
m_user = user, m_password = password;
|
m_user = user;
|
||||||
|
m_password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Returns the string representation of the current status().
|
||||||
|
*/
|
||||||
|
inline QString SyncthingConnection::statusText() const
|
||||||
|
{
|
||||||
|
return statusText(m_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -16,6 +16,7 @@ set(HEADER_FILES
|
||||||
syncthingdirectorymodel.h
|
syncthingdirectorymodel.h
|
||||||
syncthingdevicemodel.h
|
syncthingdevicemodel.h
|
||||||
syncthingdownloadmodel.h
|
syncthingdownloadmodel.h
|
||||||
|
syncthingstatusselectionmodel.h
|
||||||
syncthingicons.h
|
syncthingicons.h
|
||||||
colors.h
|
colors.h
|
||||||
)
|
)
|
||||||
|
@ -24,6 +25,7 @@ set(SRC_FILES
|
||||||
syncthingdirectorymodel.cpp
|
syncthingdirectorymodel.cpp
|
||||||
syncthingdevicemodel.cpp
|
syncthingdevicemodel.cpp
|
||||||
syncthingdownloadmodel.cpp
|
syncthingdownloadmodel.cpp
|
||||||
|
syncthingstatusselectionmodel.cpp
|
||||||
syncthingicons.cpp
|
syncthingicons.cpp
|
||||||
)
|
)
|
||||||
set(RES_FILES
|
set(RES_FILES
|
||||||
|
@ -41,7 +43,7 @@ use_cpp_utilities()
|
||||||
|
|
||||||
# find qtutilities (only CMake modules used)
|
# find qtutilities (only CMake modules used)
|
||||||
find_package(qtutilities 5.0.0 REQUIRED)
|
find_package(qtutilities 5.0.0 REQUIRED)
|
||||||
list(APPEND CMAKE_MODULE_PATH ${QT_UTILITIES_MODULE_DIRS})
|
use_qt_utilities()
|
||||||
|
|
||||||
# find backend libraries
|
# find backend libraries
|
||||||
find_package(syncthingconnector ${META_APP_VERSION} REQUIRED)
|
find_package(syncthingconnector ${META_APP_VERSION} REQUIRED)
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
#include "./syncthingstatusselectionmodel.h"
|
||||||
|
|
||||||
|
#include "../connector/syncthingconnection.h"
|
||||||
|
|
||||||
|
using namespace Models;
|
||||||
|
|
||||||
|
namespace Data {
|
||||||
|
|
||||||
|
inline ChecklistItem itemFor(SyncthingStatus status)
|
||||||
|
{
|
||||||
|
return ChecklistItem(static_cast<int>(status), QString(), Qt::Unchecked);
|
||||||
|
}
|
||||||
|
|
||||||
|
SyncthingStatusSelectionModel::SyncthingStatusSelectionModel(QObject *parent)
|
||||||
|
: ChecklistModel(parent)
|
||||||
|
{
|
||||||
|
setItems({
|
||||||
|
itemFor(SyncthingStatus::Disconnected),
|
||||||
|
itemFor(SyncthingStatus::Reconnecting),
|
||||||
|
itemFor(SyncthingStatus::Idle),
|
||||||
|
itemFor(SyncthingStatus::Scanning),
|
||||||
|
itemFor(SyncthingStatus::Paused),
|
||||||
|
itemFor(SyncthingStatus::Synchronizing),
|
||||||
|
itemFor(SyncthingStatus::OutOfSync),
|
||||||
|
itemFor(SyncthingStatus::BeingDestroyed),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
QString SyncthingStatusSelectionModel::labelForId(const QVariant &id) const
|
||||||
|
{
|
||||||
|
return SyncthingConnection::statusText(static_cast<SyncthingStatus>(id.toInt()));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Data
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef DATA_SYNCTHINGSTATUSSELECTIONMODELL_H
|
||||||
|
#define DATA_SYNCTHINGSTATUSSELECTIONMODELL_H
|
||||||
|
|
||||||
|
#include "./global.h"
|
||||||
|
|
||||||
|
#include <qtutilities/models/checklistmodel.h>
|
||||||
|
|
||||||
|
namespace Data {
|
||||||
|
|
||||||
|
class LIB_SYNCTHING_MODEL_EXPORT SyncthingStatusSelectionModel : public Models::ChecklistModel {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit SyncthingStatusSelectionModel(QObject *parent = nullptr);
|
||||||
|
QString labelForId(const QVariant &id) const override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Data
|
||||||
|
|
||||||
|
#endif // DATA_SYNCTHINGSTATUSSELECTIONMODELL_H
|
|
@ -39,7 +39,7 @@ find_package(c++utilities 4.10.0 REQUIRED)
|
||||||
list(APPEND CMAKE_MODULE_PATH ${CPP_UTILITIES_MODULE_DIRS})
|
list(APPEND CMAKE_MODULE_PATH ${CPP_UTILITIES_MODULE_DIRS})
|
||||||
|
|
||||||
# find qtutilities
|
# find qtutilities
|
||||||
find_package(qtutilities 5.10.0 REQUIRED)
|
find_package(qtutilities 5.12.0 REQUIRED)
|
||||||
use_qt_utilities()
|
use_qt_utilities()
|
||||||
|
|
||||||
# check whether qtutilities supports DBus notifications
|
# check whether qtutilities supports DBus notifications
|
||||||
|
|
|
@ -19,14 +19,14 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="colorsLabel">
|
<widget class="QLabel" name="colorsLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Colors</string>
|
<string>Colors</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QCheckBox" name="brightTextColorsCheckBox">
|
<widget class="QCheckBox" name="brightTextColorsCheckBox">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Bright custom text colors (use for dark color scheme)</string>
|
<string>Bright custom text colors (use for dark color scheme)</string>
|
||||||
|
@ -118,6 +118,23 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QLabel" name="passiveLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>States to enable passive mode</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QListView" name="passiveListView">
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::NoSelection</enum>
|
||||||
|
</property>
|
||||||
|
<property name="layoutMode">
|
||||||
|
<enum>QListView::Batched</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "../../widgets/settings/settingsdialog.h"
|
#include "../../widgets/settings/settingsdialog.h"
|
||||||
|
|
||||||
#include <qtutilities/settingsdialog/optioncategory.h>
|
#include <qtutilities/settingsdialog/optioncategory.h>
|
||||||
|
#include <qtutilities/settingsdialog/optioncategorymodel.h>
|
||||||
#include <qtutilities/settingsdialog/optionpage.h>
|
#include <qtutilities/settingsdialog/optionpage.h>
|
||||||
#include <qtutilities/settingsdialog/settingsdialog.h>
|
#include <qtutilities/settingsdialog/settingsdialog.h>
|
||||||
|
|
||||||
|
@ -86,40 +87,62 @@ AppearanceOptionPage::~AppearanceOptionPage()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AppearanceOptionPage::restoreSelectedStates(SyncthingStatusSelectionModel &statusSelectionModel, const KConfigGroup &config, const char *key)
|
||||||
|
{
|
||||||
|
const auto states = config.readEntry(key, QVariantList());
|
||||||
|
int row = 0;
|
||||||
|
for (auto &item : statusSelectionModel.items()) {
|
||||||
|
statusSelectionModel.setChecked(row++, states.contains(item.id()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool AppearanceOptionPage::apply()
|
bool AppearanceOptionPage::apply()
|
||||||
{
|
{
|
||||||
KConfigGroup config = m_applet->config();
|
KConfigGroup config = m_applet->config();
|
||||||
config.writeEntry<QSize>("size", QSize(ui()->widthSpinBox->value(), ui()->heightSpinBox->value()));
|
config.writeEntry<QSize>("size", QSize(ui()->widthSpinBox->value(), ui()->heightSpinBox->value()));
|
||||||
config.writeEntry<bool>("brightColors", ui()->brightTextColorsCheckBox->isChecked());
|
config.writeEntry<bool>("brightColors", ui()->brightTextColorsCheckBox->isChecked());
|
||||||
|
|
||||||
|
QVariantList passiveStates;
|
||||||
|
passiveStates.reserve(m_passiveStatusSelection.items().size());
|
||||||
|
for (auto &item : m_passiveStatusSelection.items()) {
|
||||||
|
if (item.isChecked()) {
|
||||||
|
passiveStates << item.id();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config.writeEntry("passiveStates", passiveStates);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppearanceOptionPage::reset()
|
void AppearanceOptionPage::reset()
|
||||||
{
|
{
|
||||||
const KConfigGroup config = m_applet->config();
|
const KConfigGroup config = m_applet->config();
|
||||||
const QSize size(config.readEntry<QSize>("size", QSize(25, 25)));
|
const auto size(config.readEntry<>("size", QSize(25, 25)));
|
||||||
ui()->widthSpinBox->setValue(size.width());
|
ui()->widthSpinBox->setValue(size.width());
|
||||||
ui()->heightSpinBox->setValue(size.height());
|
ui()->heightSpinBox->setValue(size.height());
|
||||||
ui()->brightTextColorsCheckBox->setChecked(config.readEntry<bool>("brightColors", false));
|
ui()->brightTextColorsCheckBox->setChecked(config.readEntry<>("brightColors", false));
|
||||||
|
restoreSelectedStates(m_passiveStatusSelection, config, "passiveStates");
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *AppearanceOptionPage::setupWidget()
|
QWidget *AppearanceOptionPage::setupWidget()
|
||||||
{
|
{
|
||||||
auto *const widget = AppearanceOptionPageBase::setupWidget();
|
auto *const widget = AppearanceOptionPageBase::setupWidget();
|
||||||
addPlasmoidSpecificNote(ui()->verticalLayout, widget);
|
addPlasmoidSpecificNote(ui()->verticalLayout, widget);
|
||||||
|
ui()->passiveListView->setModel(&m_passiveStatusSelection);
|
||||||
return widget;
|
return widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
QtGui::SettingsDialog *setupSettingsDialog(SyncthingApplet &applet)
|
SettingsDialog::SettingsDialog(Plasmoid::SyncthingApplet &applet)
|
||||||
{
|
{
|
||||||
// setup categories
|
// setup categories
|
||||||
QList<Dialogs::OptionCategory *> categories;
|
QList<Dialogs::OptionCategory *> categories;
|
||||||
Dialogs::OptionCategory *category;
|
Dialogs::OptionCategory *category;
|
||||||
|
|
||||||
category = new OptionCategory;
|
category = new OptionCategory;
|
||||||
|
m_appearanceOptionPage = new AppearanceOptionPage(applet);
|
||||||
category->setDisplayName(QCoreApplication::translate("Plasmoid::SettingsDialog", "Plasmoid"));
|
category->setDisplayName(QCoreApplication::translate("Plasmoid::SettingsDialog", "Plasmoid"));
|
||||||
category->assignPages(QList<Dialogs::OptionPage *>()
|
category->assignPages(QList<Dialogs::OptionPage *>()
|
||||||
<< new ConnectionOptionPage(applet.connection()) << new NotificationsOptionPage(GuiType::Plasmoid) << new AppearanceOptionPage(applet)
|
<< new ConnectionOptionPage(applet.connection()) << new NotificationsOptionPage(GuiType::Plasmoid) << m_appearanceOptionPage
|
||||||
<< new ShortcutOptionPage(applet));
|
<< new ShortcutOptionPage(applet));
|
||||||
category->setIcon(QIcon::fromTheme(QStringLiteral("plasma")));
|
category->setIcon(QIcon::fromTheme(QStringLiteral("plasma")));
|
||||||
categories << category;
|
categories << category;
|
||||||
|
@ -145,7 +168,7 @@ QtGui::SettingsDialog *setupSettingsDialog(SyncthingApplet &applet)
|
||||||
category->setIcon(
|
category->setIcon(
|
||||||
QIcon::fromTheme(QStringLiteral("preferences-other"), QIcon(QStringLiteral(":/icons/hicolor/scalable/apps/preferences-other.svg"))));
|
QIcon::fromTheme(QStringLiteral("preferences-other"), QIcon(QStringLiteral(":/icons/hicolor/scalable/apps/preferences-other.svg"))));
|
||||||
categories << category;
|
categories << category;
|
||||||
|
categoryModel()->setCategories(categories);
|
||||||
return new ::QtGui::SettingsDialog(categories);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Plasmoid
|
} // namespace Plasmoid
|
||||||
|
|
|
@ -1,14 +1,24 @@
|
||||||
#ifndef SETTINGSDIALOG_H
|
#ifndef SETTINGSDIALOG_H
|
||||||
#define SETTINGSDIALOG_H
|
#define SETTINGSDIALOG_H
|
||||||
|
|
||||||
|
#include "../../model/syncthingstatusselectionmodel.h"
|
||||||
|
|
||||||
|
#include "../../widgets/settings/settingsdialog.h"
|
||||||
|
|
||||||
#include <qtutilities/settingsdialog/optionpage.h>
|
#include <qtutilities/settingsdialog/optionpage.h>
|
||||||
|
|
||||||
|
#include <KConfigGroup>
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QKeySequenceEdit)
|
QT_FORWARD_DECLARE_CLASS(QKeySequenceEdit)
|
||||||
|
|
||||||
namespace QtGui {
|
namespace QtGui {
|
||||||
class SettingsDialog;
|
class SettingsDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Data {
|
||||||
|
class SyncthingStatusSelectionModel;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Plasmoid {
|
namespace Plasmoid {
|
||||||
class SyncthingApplet;
|
class SyncthingApplet;
|
||||||
|
|
||||||
|
@ -25,12 +35,35 @@ END_DECLARE_OPTION_PAGE
|
||||||
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_CTOR(AppearanceOptionPage)
|
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_CTOR(AppearanceOptionPage)
|
||||||
public:
|
public:
|
||||||
AppearanceOptionPage(SyncthingApplet &applet, QWidget *parentWidget = nullptr);
|
AppearanceOptionPage(SyncthingApplet &applet, QWidget *parentWidget = nullptr);
|
||||||
|
Data::SyncthingStatusSelectionModel *passiveStatusSelection();
|
||||||
|
static void restoreSelectedStates(Data::SyncthingStatusSelectionModel &statusSelectionModel, const KConfigGroup &config, const char *key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_SETUP_WIDGETS
|
DECLARE_SETUP_WIDGETS
|
||||||
SyncthingApplet *m_applet;
|
SyncthingApplet *m_applet;
|
||||||
|
Data::SyncthingStatusSelectionModel m_passiveStatusSelection;
|
||||||
END_DECLARE_OPTION_PAGE
|
END_DECLARE_OPTION_PAGE
|
||||||
|
|
||||||
|
inline Data::SyncthingStatusSelectionModel *AppearanceOptionPage::passiveStatusSelection()
|
||||||
|
{
|
||||||
|
return &m_passiveStatusSelection;
|
||||||
|
}
|
||||||
|
|
||||||
|
class SettingsDialog : public QtGui::SettingsDialog {
|
||||||
|
public:
|
||||||
|
SettingsDialog(Plasmoid::SyncthingApplet &applet);
|
||||||
|
|
||||||
|
AppearanceOptionPage *appearanceOptionPage();
|
||||||
|
|
||||||
|
private:
|
||||||
|
AppearanceOptionPage *m_appearanceOptionPage;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline AppearanceOptionPage *SettingsDialog::appearanceOptionPage()
|
||||||
|
{
|
||||||
|
return m_appearanceOptionPage;
|
||||||
|
}
|
||||||
|
|
||||||
QtGui::SettingsDialog *setupSettingsDialog(Plasmoid::SyncthingApplet &applet);
|
QtGui::SettingsDialog *setupSettingsDialog(Plasmoid::SyncthingApplet &applet);
|
||||||
} // namespace Plasmoid
|
} // namespace Plasmoid
|
||||||
|
|
||||||
|
|
|
@ -202,6 +202,13 @@ bool SyncthingApplet::areNotificationsAvailable() const
|
||||||
return !m_notifications.empty();
|
return !m_notifications.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
void SyncthingApplet::updateStatusIconAndTooltip()
|
void SyncthingApplet::updateStatusIconAndTooltip()
|
||||||
{
|
{
|
||||||
m_statusInfo.updateConnectionStatus(m_connection);
|
m_statusInfo.updateConnectionStatus(m_connection);
|
||||||
|
@ -212,7 +219,7 @@ void SyncthingApplet::updateStatusIconAndTooltip()
|
||||||
void SyncthingApplet::showSettingsDlg()
|
void SyncthingApplet::showSettingsDlg()
|
||||||
{
|
{
|
||||||
if (!m_settingsDlg) {
|
if (!m_settingsDlg) {
|
||||||
m_settingsDlg = setupSettingsDialog(*this);
|
m_settingsDlg = new SettingsDialog(*this);
|
||||||
// ensure settings take effect when applied
|
// ensure settings take effect when applied
|
||||||
connect(m_settingsDlg, &Dialogs::SettingsDialog::applied, this, &SyncthingApplet::handleSettingsChanged);
|
connect(m_settingsDlg, &Dialogs::SettingsDialog::applied, this, &SyncthingApplet::handleSettingsChanged);
|
||||||
// save plasmoid specific settings to disk when applied
|
// save plasmoid specific settings to disk when applied
|
||||||
|
@ -341,6 +348,16 @@ void SyncthingApplet::handleSettingsChanged()
|
||||||
m_devModel.setBrightColors(brightColors);
|
m_devModel.setBrightColors(brightColors);
|
||||||
m_downloadModel.setBrightColors(brightColors);
|
m_downloadModel.setBrightColors(brightColors);
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
AppearanceOptionPage::restoreSelectedStates(m_passiveSelectionModel, config, "passiveStates");
|
||||||
|
}
|
||||||
|
|
||||||
// apply connection config
|
// apply connection config
|
||||||
const int currentConfig = m_currentConnectionConfig;
|
const int currentConfig = m_currentConnectionConfig;
|
||||||
m_currentConnectionConfig = -1; // force update
|
m_currentConnectionConfig = -1; // force update
|
||||||
|
@ -351,11 +368,13 @@ void SyncthingApplet::handleSettingsChanged()
|
||||||
|
|
||||||
void SyncthingApplet::handleConnectionStatusChanged(SyncthingStatus status)
|
void SyncthingApplet::handleConnectionStatusChanged(SyncthingStatus status)
|
||||||
{
|
{
|
||||||
VAR_UNUSED(status)
|
|
||||||
if (!m_initialized) {
|
if (!m_initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update whether passive
|
||||||
|
setPassive(static_cast<int>(status) < passiveStates().size() && passiveStates().at(static_cast<int>(status)).isChecked());
|
||||||
|
|
||||||
// update status icon and tooltip text
|
// update status icon and tooltip text
|
||||||
m_statusInfo.updateConnectionStatus(m_connection);
|
m_statusInfo.updateConnectionStatus(m_connection);
|
||||||
m_statusInfo.updateConnectedDevices(m_connection);
|
m_statusInfo.updateConnectedDevices(m_connection);
|
||||||
|
|
|
@ -8,21 +8,19 @@
|
||||||
#include "../../model/syncthingdevicemodel.h"
|
#include "../../model/syncthingdevicemodel.h"
|
||||||
#include "../../model/syncthingdirectorymodel.h"
|
#include "../../model/syncthingdirectorymodel.h"
|
||||||
#include "../../model/syncthingdownloadmodel.h"
|
#include "../../model/syncthingdownloadmodel.h"
|
||||||
|
#include "../../model/syncthingstatusselectionmodel.h"
|
||||||
|
|
||||||
#include "../../connector/syncthingconnection.h"
|
#include "../../connector/syncthingconnection.h"
|
||||||
#include "../../connector/syncthingnotifier.h"
|
#include "../../connector/syncthingnotifier.h"
|
||||||
#include "../../connector/syncthingservice.h"
|
#include "../../connector/syncthingservice.h"
|
||||||
|
|
||||||
#include <qtutilities/aboutdialog/aboutdialog.h>
|
#include <qtutilities/aboutdialog/aboutdialog.h>
|
||||||
|
#include <qtutilities/models/checklistmodel.h>
|
||||||
|
|
||||||
#include <Plasma/Applet>
|
#include <Plasma/Applet>
|
||||||
|
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
|
|
||||||
namespace Dialogs {
|
|
||||||
class SettingsDialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
class SyncthingConnection;
|
class SyncthingConnection;
|
||||||
struct SyncthingConnectionSettings;
|
struct SyncthingConnectionSettings;
|
||||||
|
@ -39,12 +37,15 @@ class WebViewDialog;
|
||||||
|
|
||||||
namespace Plasmoid {
|
namespace Plasmoid {
|
||||||
|
|
||||||
|
class SettingsDialog;
|
||||||
|
|
||||||
class SyncthingApplet : public Plasma::Applet {
|
class SyncthingApplet : public Plasma::Applet {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(Data::SyncthingConnection *connection READ connection NOTIFY connectionChanged)
|
Q_PROPERTY(Data::SyncthingConnection *connection READ connection NOTIFY connectionChanged)
|
||||||
Q_PROPERTY(Data::SyncthingDirectoryModel *dirModel READ dirModel NOTIFY dirModelChanged)
|
Q_PROPERTY(Data::SyncthingDirectoryModel *dirModel READ dirModel NOTIFY dirModelChanged)
|
||||||
Q_PROPERTY(Data::SyncthingDeviceModel *devModel READ devModel NOTIFY devModelChanged)
|
Q_PROPERTY(Data::SyncthingDeviceModel *devModel READ devModel NOTIFY devModelChanged)
|
||||||
Q_PROPERTY(Data::SyncthingDownloadModel *downloadModel READ downloadModel NOTIFY downloadModelChanged)
|
Q_PROPERTY(Data::SyncthingDownloadModel *downloadModel READ downloadModel NOTIFY downloadModelChanged)
|
||||||
|
Q_PROPERTY(Data::SyncthingStatusSelectionModel *passiveSelectionModel READ passiveSelectionModel NOTIFY passiveSelectionModelChanged)
|
||||||
Q_PROPERTY(Data::SyncthingService *service READ service NOTIFY serviceChanged)
|
Q_PROPERTY(Data::SyncthingService *service READ service NOTIFY serviceChanged)
|
||||||
Q_PROPERTY(bool local READ isLocal NOTIFY localChanged)
|
Q_PROPERTY(bool local READ isLocal NOTIFY localChanged)
|
||||||
Q_PROPERTY(QString statusText READ statusText NOTIFY connectionStatusChanged)
|
Q_PROPERTY(QString statusText READ statusText NOTIFY connectionStatusChanged)
|
||||||
|
@ -59,6 +60,8 @@ class SyncthingApplet : public Plasma::Applet {
|
||||||
Q_PROPERTY(bool startStopEnabled READ isStartStopEnabled NOTIFY settingsChanged)
|
Q_PROPERTY(bool startStopEnabled READ isStartStopEnabled NOTIFY settingsChanged)
|
||||||
Q_PROPERTY(QSize size READ size WRITE setSize NOTIFY sizeChanged)
|
Q_PROPERTY(QSize size READ size WRITE setSize NOTIFY sizeChanged)
|
||||||
Q_PROPERTY(bool notificationsAvailable READ areNotificationsAvailable NOTIFY notificationsAvailableChanged)
|
Q_PROPERTY(bool notificationsAvailable READ areNotificationsAvailable NOTIFY notificationsAvailableChanged)
|
||||||
|
Q_PROPERTY(bool passive READ isPassive NOTIFY passiveChanged)
|
||||||
|
Q_PROPERTY(QList<Models::ChecklistItem> passiveStates READ passiveStates WRITE setPassiveStates)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SyncthingApplet(QObject *parent, const QVariantList &data);
|
SyncthingApplet(QObject *parent, const QVariantList &data);
|
||||||
|
@ -69,6 +72,7 @@ public:
|
||||||
Data::SyncthingDirectoryModel *dirModel() const;
|
Data::SyncthingDirectoryModel *dirModel() const;
|
||||||
Data::SyncthingDeviceModel *devModel() const;
|
Data::SyncthingDeviceModel *devModel() const;
|
||||||
Data::SyncthingDownloadModel *downloadModel() const;
|
Data::SyncthingDownloadModel *downloadModel() const;
|
||||||
|
Data::SyncthingStatusSelectionModel *passiveSelectionModel() const;
|
||||||
Data::SyncthingService *service() const;
|
Data::SyncthingService *service() const;
|
||||||
bool isLocal() const;
|
bool isLocal() const;
|
||||||
QString statusText() const;
|
QString statusText() const;
|
||||||
|
@ -86,6 +90,9 @@ public:
|
||||||
QSize size() const;
|
QSize size() const;
|
||||||
void setSize(const QSize &size);
|
void setSize(const QSize &size);
|
||||||
bool areNotificationsAvailable() const;
|
bool areNotificationsAvailable() const;
|
||||||
|
bool isPassive() const;
|
||||||
|
const QList<Models::ChecklistItem> &passiveStates() const;
|
||||||
|
void setPassiveStates(const QList<Models::ChecklistItem> &passiveStates);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void init() Q_DECL_OVERRIDE;
|
void init() Q_DECL_OVERRIDE;
|
||||||
|
@ -111,6 +118,8 @@ Q_SIGNALS:
|
||||||
/// \remarks Never emitted, just to silence "... depends on non-NOTIFYable ..."
|
/// \remarks Never emitted, just to silence "... depends on non-NOTIFYable ..."
|
||||||
void downloadModelChanged();
|
void downloadModelChanged();
|
||||||
/// \remarks Never emitted, just to silence "... depends on non-NOTIFYable ..."
|
/// \remarks Never emitted, just to silence "... depends on non-NOTIFYable ..."
|
||||||
|
void passiveSelectionModelChanged();
|
||||||
|
/// \remarks Never emitted, just to silence "... depends on non-NOTIFYable ..."
|
||||||
void serviceChanged();
|
void serviceChanged();
|
||||||
void localChanged();
|
void localChanged();
|
||||||
void connectionStatusChanged();
|
void connectionStatusChanged();
|
||||||
|
@ -119,6 +128,7 @@ Q_SIGNALS:
|
||||||
void currentConnectionConfigIndexChanged(int index);
|
void currentConnectionConfigIndexChanged(int index);
|
||||||
void sizeChanged(const QSize &size);
|
void sizeChanged(const QSize &size);
|
||||||
void notificationsAvailableChanged(bool notificationsAvailable);
|
void notificationsAvailableChanged(bool notificationsAvailable);
|
||||||
|
void passiveChanged(bool passive);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void handleSettingsChanged();
|
void handleSettingsChanged();
|
||||||
|
@ -136,6 +146,7 @@ private Q_SLOTS:
|
||||||
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
||||||
void handleSystemdStatusChanged();
|
void handleSystemdStatusChanged();
|
||||||
#endif
|
#endif
|
||||||
|
void setPassive(bool passive);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Dialogs::AboutDialog *m_aboutDlg;
|
Dialogs::AboutDialog *m_aboutDlg;
|
||||||
|
@ -148,7 +159,8 @@ private:
|
||||||
Data::SyncthingDirectoryModel m_dirModel;
|
Data::SyncthingDirectoryModel m_dirModel;
|
||||||
Data::SyncthingDeviceModel m_devModel;
|
Data::SyncthingDeviceModel m_devModel;
|
||||||
Data::SyncthingDownloadModel m_downloadModel;
|
Data::SyncthingDownloadModel m_downloadModel;
|
||||||
Dialogs::SettingsDialog *m_settingsDlg;
|
Data::SyncthingStatusSelectionModel m_passiveSelectionModel;
|
||||||
|
SettingsDialog *m_settingsDlg;
|
||||||
QtGui::DBusStatusNotifier m_dbusNotifier;
|
QtGui::DBusStatusNotifier m_dbusNotifier;
|
||||||
std::vector<Data::SyncthingLogEntry> m_notifications;
|
std::vector<Data::SyncthingLogEntry> m_notifications;
|
||||||
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
|
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
|
||||||
|
@ -179,6 +191,11 @@ inline Data::SyncthingDownloadModel *SyncthingApplet::downloadModel() const
|
||||||
return const_cast<Data::SyncthingDownloadModel *>(&m_downloadModel);
|
return const_cast<Data::SyncthingDownloadModel *>(&m_downloadModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Data::SyncthingStatusSelectionModel *SyncthingApplet::passiveSelectionModel() const
|
||||||
|
{
|
||||||
|
return const_cast<Data::SyncthingStatusSelectionModel *>(&m_passiveSelectionModel);
|
||||||
|
}
|
||||||
|
|
||||||
inline Data::SyncthingService *SyncthingApplet::service() const
|
inline Data::SyncthingService *SyncthingApplet::service() const
|
||||||
{
|
{
|
||||||
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
||||||
|
@ -224,6 +241,24 @@ inline void SyncthingApplet::setSize(const QSize &size)
|
||||||
emit sizeChanged(m_size = size);
|
emit sizeChanged(m_size = size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool SyncthingApplet::isPassive() const
|
||||||
|
{
|
||||||
|
return status() == Plasma::Types::PassiveStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const QList<Models::ChecklistItem> &SyncthingApplet::passiveStates() const
|
||||||
|
{
|
||||||
|
return m_passiveSelectionModel.items();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void SyncthingApplet::setPassive(bool passive)
|
||||||
|
{
|
||||||
|
if (passive != isPassive()) {
|
||||||
|
setStatus(passive ? Plasma::Types::PassiveStatus : Plasma::Types::ActiveStatus);
|
||||||
|
emit passiveChanged(passive);
|
||||||
|
}
|
||||||
|
}
|
||||||
} // namespace Plasmoid
|
} // namespace Plasmoid
|
||||||
|
|
||||||
#endif // SYNCTHINGAPPLET_H
|
#endif // SYNCTHINGAPPLET_H
|
||||||
|
|
|
@ -18,6 +18,12 @@ rather than the regular home to separate testing from production.
|
||||||
6. Ignore warning that executable is no debug build, it is sufficiant when
|
6. Ignore warning that executable is no debug build, it is sufficiant when
|
||||||
the plugin is a debug build (see next section for QML debugging)
|
the plugin is a debug build (see next section for QML debugging)
|
||||||
|
|
||||||
|
## Saving/restoring settings
|
||||||
|
|
||||||
|
Be aware that `plasmoidviewer` will revert Plasmoid-specific settings to the defaults on
|
||||||
|
startup. So it is not possible to test restoring/saving settings using it.
|
||||||
|
For this use case, `plasmawindowed` can be used instead.
|
||||||
|
|
||||||
## Enable QML debugging
|
## Enable QML debugging
|
||||||
|
|
||||||
To enable QML debugging, it is required to rebuild `plasmoidviewer` with QML debugging
|
To enable QML debugging, it is required to rebuild `plasmoidviewer` with QML debugging
|
||||||
|
|
|
@ -952,6 +952,12 @@ SettingsDialog::SettingsDialog(const QList<OptionCategory *> &categories, QWidge
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SettingsDialog::SettingsDialog(QWidget *parent)
|
||||||
|
: Dialogs::SettingsDialog(parent)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
SettingsDialog::SettingsDialog(Data::SyncthingConnection *connection, QWidget *parent)
|
SettingsDialog::SettingsDialog(Data::SyncthingConnection *connection, QWidget *parent)
|
||||||
: Dialogs::SettingsDialog(parent)
|
: Dialogs::SettingsDialog(parent)
|
||||||
{
|
{
|
||||||
|
|
|
@ -114,6 +114,7 @@ class SYNCTHINGWIDGETS_EXPORT SettingsDialog : public Dialogs::SettingsDialog {
|
||||||
public:
|
public:
|
||||||
explicit SettingsDialog(Data::SyncthingConnection *connection, QWidget *parent = nullptr);
|
explicit SettingsDialog(Data::SyncthingConnection *connection, QWidget *parent = nullptr);
|
||||||
explicit SettingsDialog(const QList<Dialogs::OptionCategory *> &categories, QWidget *parent = nullptr);
|
explicit SettingsDialog(const QList<Dialogs::OptionCategory *> &categories, QWidget *parent = nullptr);
|
||||||
|
explicit SettingsDialog(QWidget *parent = nullptr);
|
||||||
~SettingsDialog();
|
~SettingsDialog();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue