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:
|
public:
|
||||||
SyncthingNotifier(const SyncthingConnection &connection, QObject *parent = nullptr);
|
SyncthingNotifier(const SyncthingConnection &connection, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
const SyncthingConnection &connection() const;
|
||||||
SyncthingHighLevelNotification enabledNotifications() const;
|
SyncthingHighLevelNotification enabledNotifications() const;
|
||||||
unsigned int ignoreInavailabilityAfterStart() const;
|
unsigned int ignoreInavailabilityAfterStart() const;
|
||||||
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
||||||
|
@ -112,6 +113,14 @@ private:
|
||||||
bool m_initialized;
|
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).
|
* \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)
|
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);
|
const QList<QAction *> actions = createActions(fileItemInfo, parentWidget);
|
||||||
|
|
||||||
// don't show anything if no relevant actions could be determined
|
// don't show anything if no relevant actions could be determined
|
||||||
if (actions.isEmpty()) {
|
if (s_data.connection().isConnected() && actions.isEmpty()) {
|
||||||
return actions;
|
return QList<QAction *>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return QList<QAction *>({ new SyncthingMenuAction(fileItemInfo, actions, parentWidget) });
|
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)
|
SyncthingMenuAction::SyncthingMenuAction(const KFileItemListProperties &properties, const QList<QAction *> &actions, QWidget *parentWidget)
|
||||||
: QAction(parentWidget)
|
: QAction(parentWidget)
|
||||||
, m_properties(properties)
|
, m_properties(properties)
|
||||||
|
, m_notifier(SyncthingFileItemAction::staticData().connection())
|
||||||
{
|
{
|
||||||
if (!actions.isEmpty()) {
|
// init according to current state
|
||||||
auto *menu = new QMenu(parentWidget);
|
createMenu(actions);
|
||||||
menu->addActions(actions);
|
updateActionStatus();
|
||||||
setMenu(menu);
|
|
||||||
}
|
// setup handling future state change
|
||||||
updateStatus(SyncthingFileItemAction::staticData().connection().status());
|
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"));
|
setText(tr("Syncthing"));
|
||||||
setIcon(statusIcons().scanninig);
|
setIcon(statusIcons().scanninig);
|
||||||
if (!menu()) {
|
return;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
#ifndef SYNCTHINGMENUACTION_H
|
||||||
#define SYNCTHINGMENUACTION_H
|
#define SYNCTHINGMENUACTION_H
|
||||||
|
|
||||||
|
#include "../connector/syncthingnotifier.h"
|
||||||
|
|
||||||
#include <KFileItemListProperties>
|
#include <KFileItemListProperties>
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
@ -19,11 +21,15 @@ public:
|
||||||
explicit SyncthingMenuAction(const KFileItemListProperties &properties = KFileItemListProperties(),
|
explicit SyncthingMenuAction(const KFileItemListProperties &properties = KFileItemListProperties(),
|
||||||
const QList<QAction *> &actions = QList<QAction *>(), QWidget *parentWidget = nullptr);
|
const QList<QAction *> &actions = QList<QAction *>(), QWidget *parentWidget = nullptr);
|
||||||
|
|
||||||
public Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void updateStatus(Data::SyncthingStatus status);
|
void handleConnectedChanged();
|
||||||
|
void updateActionStatus();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void createMenu(const QList<QAction *> &actions);
|
||||||
|
|
||||||
KFileItemListProperties m_properties;
|
KFileItemListProperties m_properties;
|
||||||
|
Data::SyncthingNotifier m_notifier;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SYNCTHINGMENUACTION_H
|
#endif // SYNCTHINGMENUACTION_H
|
||||||
|
|
Loading…
Reference in New Issue