2017-02-20 18:37:11 +01:00
|
|
|
#ifndef SYNCTHINGFILEITEMACTION_H
|
|
|
|
#define SYNCTHINGFILEITEMACTION_H
|
|
|
|
|
|
|
|
#include "../connector/syncthingconnection.h"
|
|
|
|
|
|
|
|
#include <KAbstractFileItemActionPlugin>
|
2017-03-11 19:57:49 +01:00
|
|
|
#include <KFileItemListProperties>
|
|
|
|
|
2018-11-27 17:59:17 +01:00
|
|
|
#include <QAction>
|
|
|
|
#include <QWidget>
|
2017-04-08 14:27:15 +02:00
|
|
|
#include <QWidgetAction>
|
2017-02-20 18:37:11 +01:00
|
|
|
|
2018-11-27 17:59:17 +01:00
|
|
|
QT_FORWARD_DECLARE_CLASS(QLabel)
|
2017-02-20 18:37:11 +01:00
|
|
|
|
|
|
|
class KFileItemListProperties;
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
class SyncthingMenuAction : public QAction {
|
2017-03-11 19:57:49 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-11-27 17:59:17 +01:00
|
|
|
explicit SyncthingMenuAction(const KFileItemListProperties &properties = KFileItemListProperties(),
|
|
|
|
const QList<QAction *> &actions = QList<QAction *>(), QWidget *parentWidget = nullptr);
|
2017-03-11 19:57:49 +01:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void updateStatus(Data::SyncthingStatus status);
|
|
|
|
|
|
|
|
private:
|
|
|
|
KFileItemListProperties m_properties;
|
|
|
|
};
|
|
|
|
|
2018-11-27 17:59:17 +01:00
|
|
|
class SyncthingInfoAction;
|
|
|
|
|
|
|
|
class SyncthingInfoWidget : public QWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit SyncthingInfoWidget(const SyncthingInfoAction *action, QWidget *parent = nullptr);
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void updateFromSender();
|
|
|
|
void updateFromAction(const SyncthingInfoAction *action);
|
|
|
|
|
|
|
|
private:
|
|
|
|
QLabel *const m_textLabel;
|
|
|
|
QLabel *const m_iconLabel;
|
|
|
|
};
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
class SyncthingInfoAction : public QWidgetAction {
|
2017-04-08 14:27:15 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-11-27 17:59:17 +01:00
|
|
|
explicit SyncthingInfoAction(QObject *parent = nullptr);
|
2017-04-08 14:27:15 +02:00
|
|
|
|
|
|
|
protected:
|
2018-10-10 21:26:46 +02:00
|
|
|
QWidget *createWidget(QWidget *parent) override;
|
2017-04-08 14:27:15 +02:00
|
|
|
};
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
class SyncthingDirActions : public QObject {
|
2017-03-13 00:40:48 +01:00
|
|
|
Q_OBJECT
|
2017-05-01 03:34:43 +02:00
|
|
|
friend QList<QAction *> &operator<<(QList<QAction *> &, SyncthingDirActions &);
|
2017-03-13 00:40:48 +01:00
|
|
|
|
|
|
|
public:
|
2018-11-27 17:59:17 +01:00
|
|
|
explicit SyncthingDirActions(const Data::SyncthingDir &dir, QObject *parent = nullptr);
|
2017-03-13 00:40:48 +01:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void updateStatus(const std::vector<Data::SyncthingDir> &dirs);
|
|
|
|
bool updateStatus(const Data::SyncthingDir &dir);
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString m_dirId;
|
|
|
|
QAction m_infoAction;
|
2017-04-08 14:27:15 +02:00
|
|
|
SyncthingInfoAction m_statusAction;
|
2017-08-30 00:36:49 +02:00
|
|
|
SyncthingInfoAction m_globalStatusAction;
|
|
|
|
SyncthingInfoAction m_localStatusAction;
|
2017-04-08 14:27:15 +02:00
|
|
|
SyncthingInfoAction m_lastScanAction;
|
|
|
|
SyncthingInfoAction m_rescanIntervalAction;
|
2017-08-30 00:36:49 +02:00
|
|
|
SyncthingInfoAction m_errorsAction;
|
2017-03-13 00:40:48 +01:00
|
|
|
};
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
QList<QAction *> &operator<<(QList<QAction *> &actions, SyncthingDirActions &dirActions);
|
2017-03-13 00:40:48 +01:00
|
|
|
|
2018-11-27 17:59:17 +01:00
|
|
|
class SyncthingFileItemActionStaticData : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QString configPath READ configPath)
|
|
|
|
Q_PROPERTY(QString currentError READ currentError WRITE setCurrentError NOTIFY currentErrorChanged RESET clearCurrentError)
|
|
|
|
Q_PROPERTY(bool hasError READ hasError NOTIFY hasErrorChanged)
|
|
|
|
Q_PROPERTY(bool initialized READ isInitialized)
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit SyncthingFileItemActionStaticData();
|
|
|
|
~SyncthingFileItemActionStaticData();
|
|
|
|
Data::SyncthingConnection &connection();
|
|
|
|
const Data::SyncthingConnection &connection() const;
|
|
|
|
const QString &configPath() const;
|
|
|
|
const QString ¤tError() const;
|
|
|
|
bool hasError() const;
|
|
|
|
bool isInitialized() const;
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void initialize();
|
|
|
|
bool applySyncthingConfiguration(const QString &syncthingConfigFilePath);
|
|
|
|
void logConnectionStatus();
|
|
|
|
void logConnectionError(const QString &errorMessage, Data::SyncthingErrorCategory errorCategory);
|
|
|
|
void rescanDir(const QString &dirId, const QString &relpath = QString());
|
|
|
|
static void showAboutDialog();
|
|
|
|
void selectSyncthingConfig();
|
|
|
|
void setCurrentError(const QString ¤tError);
|
|
|
|
void clearCurrentError();
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void currentErrorChanged(const QString &error);
|
|
|
|
void hasErrorChanged(bool hasError);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Data::SyncthingConnection m_connection;
|
|
|
|
QString m_configFilePath;
|
|
|
|
QString m_currentError;
|
|
|
|
bool m_initialized;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline Data::SyncthingConnection &SyncthingFileItemActionStaticData::connection()
|
|
|
|
{
|
|
|
|
return m_connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const Data::SyncthingConnection &SyncthingFileItemActionStaticData::connection() const
|
|
|
|
{
|
|
|
|
return m_connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const QString &SyncthingFileItemActionStaticData::configPath() const
|
|
|
|
{
|
|
|
|
return m_configFilePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const QString &SyncthingFileItemActionStaticData::currentError() const
|
|
|
|
{
|
|
|
|
return m_currentError;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool SyncthingFileItemActionStaticData::hasError() const
|
|
|
|
{
|
|
|
|
return !currentError().isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool SyncthingFileItemActionStaticData::isInitialized() const
|
|
|
|
{
|
|
|
|
return m_initialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SyncthingFileItemActionStaticData::clearCurrentError()
|
|
|
|
{
|
|
|
|
m_currentError.clear();
|
|
|
|
}
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
class SyncthingFileItemAction : public KAbstractFileItemActionPlugin {
|
2017-02-20 18:37:11 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-05-01 03:34:43 +02:00
|
|
|
SyncthingFileItemAction(QObject *parent, const QVariantList &args);
|
2017-02-20 18:37:11 +01:00
|
|
|
QList<QAction *> actions(const KFileItemListProperties &fileItemInfo, QWidget *parentWidget) override;
|
2017-03-11 19:57:49 +01:00
|
|
|
static QList<QAction *> createActions(const KFileItemListProperties &fileItemInfo, QWidget *parentWidget);
|
2018-11-27 17:59:17 +01:00
|
|
|
static SyncthingFileItemActionStaticData &staticData();
|
2017-02-20 18:37:11 +01:00
|
|
|
|
|
|
|
private:
|
2018-11-27 17:59:17 +01:00
|
|
|
static SyncthingFileItemActionStaticData s_data;
|
2017-02-20 18:37:11 +01:00
|
|
|
};
|
|
|
|
|
2018-11-27 17:59:17 +01:00
|
|
|
inline SyncthingFileItemActionStaticData &SyncthingFileItemAction::staticData()
|
|
|
|
{
|
|
|
|
return s_data;
|
|
|
|
}
|
|
|
|
|
2017-02-20 18:37:11 +01:00
|
|
|
#endif // SYNCTHINGFILEITEMACTION_H
|