Allow always to change config
This commit is contained in:
parent
10747bfdf9
commit
1d5b90a693
|
@ -60,6 +60,7 @@ class LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingNotifier : public QObject {
|
|||
public:
|
||||
SyncthingNotifier(const SyncthingConnection &connection, QObject *parent = nullptr);
|
||||
|
||||
const SyncthingConnection &connection() const;
|
||||
SyncthingHighLevelNotification enabledNotifications() const;
|
||||
unsigned int ignoreInavailabilityAfterStart() const;
|
||||
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
||||
|
@ -112,6 +113,14 @@ private:
|
|||
bool m_initialized;
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Returns the associated connection.
|
||||
*/
|
||||
inline const SyncthingConnection &SyncthingNotifier::connection() const
|
||||
{
|
||||
return m_connection;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns which notifications are enabled (by default none).
|
||||
*/
|
||||
|
|
|
@ -47,18 +47,11 @@ SyncthingFileItemAction::SyncthingFileItemAction(QObject *parent, const QVariant
|
|||
|
||||
QList<QAction *> SyncthingFileItemAction::actions(const KFileItemListProperties &fileItemInfo, QWidget *parentWidget)
|
||||
{
|
||||
// handle case when not connected yet
|
||||
if (!s_data.connection().isConnected()) {
|
||||
s_data.connection().connect();
|
||||
auto *menuAction = new SyncthingMenuAction(fileItemInfo, QList<QAction *>(), parentWidget);
|
||||
connect(&s_data.connection(), &SyncthingConnection::statusChanged, menuAction, &SyncthingMenuAction::updateStatus);
|
||||
return QList<QAction *>() << menuAction;
|
||||
}
|
||||
|
||||
const QList<QAction *> actions = createActions(fileItemInfo, parentWidget);
|
||||
|
||||
// don't show anything if no relevant actions could be determined
|
||||
if (actions.isEmpty()) {
|
||||
return actions;
|
||||
if (s_data.connection().isConnected() && actions.isEmpty()) {
|
||||
return QList<QAction *>();
|
||||
}
|
||||
|
||||
return QList<QAction *>({ new SyncthingMenuAction(fileItemInfo, actions, parentWidget) });
|
||||
|
|
|
@ -13,37 +13,62 @@ using namespace Data;
|
|||
SyncthingMenuAction::SyncthingMenuAction(const KFileItemListProperties &properties, const QList<QAction *> &actions, QWidget *parentWidget)
|
||||
: QAction(parentWidget)
|
||||
, m_properties(properties)
|
||||
, m_notifier(SyncthingFileItemAction::staticData().connection())
|
||||
{
|
||||
if (!actions.isEmpty()) {
|
||||
auto *menu = new QMenu(parentWidget);
|
||||
menu->addActions(actions);
|
||||
setMenu(menu);
|
||||
}
|
||||
updateStatus(SyncthingFileItemAction::staticData().connection().status());
|
||||
// init according to current state
|
||||
createMenu(actions);
|
||||
updateActionStatus();
|
||||
|
||||
// setup handling future state change
|
||||
m_notifier.setEnabledNotifications(SyncthingHighLevelNotification::ConnectedDisconnected);
|
||||
connect(&m_notifier, &SyncthingNotifier::connected, this, &SyncthingMenuAction::handleConnectedChanged);
|
||||
connect(&m_notifier, &SyncthingNotifier::disconnected, this, &SyncthingMenuAction::handleConnectedChanged);
|
||||
}
|
||||
|
||||
void SyncthingMenuAction::updateStatus(SyncthingStatus status)
|
||||
void SyncthingMenuAction::handleConnectedChanged()
|
||||
{
|
||||
if (status != SyncthingStatus::Disconnected && status != SyncthingStatus::Reconnecting && status != SyncthingStatus::BeingDestroyed) {
|
||||
// update the current menu
|
||||
if (QMenu *const menu = this->menu()) {
|
||||
setMenu(nullptr);
|
||||
delete menu;
|
||||
}
|
||||
createMenu(SyncthingFileItemAction::createActions(m_properties, parentWidget()));
|
||||
|
||||
// update status of action itself
|
||||
updateActionStatus();
|
||||
}
|
||||
|
||||
void SyncthingMenuAction::updateActionStatus()
|
||||
{
|
||||
auto &data = SyncthingFileItemAction::staticData();
|
||||
auto &connection = data.connection();
|
||||
|
||||
// handle case when already connected
|
||||
if (connection.isConnected()) {
|
||||
setText(tr("Syncthing"));
|
||||
setIcon(statusIcons().scanninig);
|
||||
if (!menu()) {
|
||||
const QList<QAction *> actions = SyncthingFileItemAction::createActions(m_properties, parentWidget());
|
||||
if (!actions.isEmpty()) {
|
||||
auto *menu = new QMenu(parentWidget());
|
||||
menu->addActions(actions);
|
||||
setMenu(menu);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (status != SyncthingStatus::Reconnecting) {
|
||||
SyncthingFileItemAction::staticData().connection().connect();
|
||||
}
|
||||
setText(tr("Syncthing - connecting"));
|
||||
setIcon(statusIcons().disconnected);
|
||||
if (QMenu *menu = this->menu()) {
|
||||
setMenu(nullptr);
|
||||
delete menu;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// attempt to connect if not reconnecting anyways and there's no configuration issue
|
||||
if (connection.status() != SyncthingStatus::Reconnecting && !data.hasError()) {
|
||||
connection.connect();
|
||||
}
|
||||
|
||||
if (connection.hasPendingRequests()) {
|
||||
setText(tr("Syncthing - connecting"));
|
||||
} else {
|
||||
setText(tr("Syncthing - not connected"));
|
||||
}
|
||||
setIcon(statusIcons().disconnected);
|
||||
}
|
||||
|
||||
void SyncthingMenuAction::createMenu(const QList<QAction *> &actions)
|
||||
{
|
||||
if (actions.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
auto *const menu = new QMenu(parentWidget());
|
||||
menu->addActions(actions);
|
||||
setMenu(menu);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef SYNCTHINGMENUACTION_H
|
||||
#define SYNCTHINGMENUACTION_H
|
||||
|
||||
#include "../connector/syncthingnotifier.h"
|
||||
|
||||
#include <KFileItemListProperties>
|
||||
|
||||
#include <QAction>
|
||||
|
@ -19,11 +21,15 @@ public:
|
|||
explicit SyncthingMenuAction(const KFileItemListProperties &properties = KFileItemListProperties(),
|
||||
const QList<QAction *> &actions = QList<QAction *>(), QWidget *parentWidget = nullptr);
|
||||
|
||||
public Q_SLOTS:
|
||||
void updateStatus(Data::SyncthingStatus status);
|
||||
private Q_SLOTS:
|
||||
void handleConnectedChanged();
|
||||
void updateActionStatus();
|
||||
|
||||
private:
|
||||
void createMenu(const QList<QAction *> &actions);
|
||||
|
||||
KFileItemListProperties m_properties;
|
||||
Data::SyncthingNotifier m_notifier;
|
||||
};
|
||||
|
||||
#endif // SYNCTHINGMENUACTION_H
|
||||
|
|
Loading…
Reference in New Issue