From 38eb689b69750ee3d2218db226cc09b9b801feb6 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 6 Apr 2024 19:30:43 +0200 Subject: [PATCH] Allow showing remote file browser from Plasmoid --- plasmoid/lib/syncthingapplet.cpp | 18 ++++++++++++++++++ plasmoid/lib/syncthingapplet.h | 5 +++++ .../package6/contents/ui/DirectoriesPage.qml | 11 ++++++++++- plasmoid/package6/contents/ui/TopLevelView.qml | 10 +++++++--- plasmoid/scripts/settestenv.sh | 2 +- 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/plasmoid/lib/syncthingapplet.cpp b/plasmoid/lib/syncthingapplet.cpp index 6deb953..7862fb4 100644 --- a/plasmoid/lib/syncthingapplet.cpp +++ b/plasmoid/lib/syncthingapplet.cpp @@ -363,6 +363,11 @@ QString SyncthingApplet::substituteTilde(const QString &path) const return Data::substituteTilde(path, m_connection.tilde(), m_connection.pathSeparator()); } +bool SyncthingApplet::areWipFeaturesEnabled() const +{ + return Settings::values().enableWipFeatures; +} + void SyncthingApplet::showSettingsDlg() { if (!m_settingsDlg) { @@ -517,6 +522,19 @@ void SyncthingApplet::showDirectoryErrors(const QString &dirId) dlg->show(); } +void SyncthingApplet::browseRemoteFiles(const QString &dirId) +{ + auto row = 0; + auto *const dir = m_connection.findDirInfo(dirId, row); + if (!dir) { + return; + } + auto *const dlg = QtGui::browseRemoteFilesDialog(m_connection, *dir); + dlg->resize(600, 500); + centerWidget(dlg); + dlg->show(); +} + void SyncthingApplet::copyToClipboard(const QString &text) { QGuiApplication::clipboard()->setText(text); diff --git a/plasmoid/lib/syncthingapplet.h b/plasmoid/lib/syncthingapplet.h index 06bf0a2..39abdf2 100644 --- a/plasmoid/lib/syncthingapplet.h +++ b/plasmoid/lib/syncthingapplet.h @@ -86,6 +86,7 @@ class SyncthingApplet : public Plasma::Applet { Q_PROPERTY(bool passive READ isPassive NOTIFY passiveChanged) Q_PROPERTY(QList passiveStates READ passiveStates WRITE setPassiveStates) Q_PROPERTY(QString faUrl READ faUrl NOTIFY faUrlChanged) + Q_PROPERTY(bool wipFeaturesEnabled READ areWipFeaturesEnabled NOTIFY wipFeaturesEnabledChanged) public: SyncthingApplet(QObject *parent, const QVariantList &data); @@ -132,6 +133,7 @@ public: Q_INVOKABLE QIcon loadForkAwesomeIcon(const QString &name, int size = 32) const; Q_INVOKABLE QString formatFileSize(quint64 fileSizeInByte) const; Q_INVOKABLE QString substituteTilde(const QString &path) const; + bool areWipFeaturesEnabled() const; public Q_SLOTS: void init() override; @@ -146,6 +148,7 @@ public Q_SLOTS: void dismissNotifications(); void showInternalErrorsDialog(); void showDirectoryErrors(const QString &dirId); + void browseRemoteFiles(const QString &dirId); void copyToClipboard(const QString &text); void updateStatusIconAndTooltip(); void saveSettings(); @@ -177,6 +180,8 @@ Q_SIGNALS: void notificationsAvailableChanged(bool notificationsAvailable); void passiveChanged(bool passive); void faUrlChanged(const QString &faUrl); + /// \remarks Never emitted, just to silence "... depends on non-NOTIFYable ..." + void wipFeaturesEnabledChanged(); private Q_SLOTS: void handleSettingsChanged(); diff --git a/plasmoid/package6/contents/ui/DirectoriesPage.qml b/plasmoid/package6/contents/ui/DirectoriesPage.qml index 8ec4d5d..6ab7f65 100644 --- a/plasmoid/package6/contents/ui/DirectoriesPage.qml +++ b/plasmoid/package6/contents/ui/DirectoriesPage.qml @@ -38,6 +38,7 @@ ColumnLayout { delegate: TopLevelItem { id: item width: directoryView.effectiveWidth() + readonly property string dirId_: dirId readonly property string dirName: name readonly property string dirPath: path property alias errorsButton: errorsButton @@ -141,7 +142,7 @@ ColumnLayout { function init(item) { // use value for properties depending on paused state from buttons - rescanItem.enabled = item.rescanButton.enabled + rescanItem.enabled = browseRemoteFilesItem.enabled = item.rescanButton.enabled resumePauseItem.text = item.resumePauseButton.tooltip resumePauseItem.icon = item.resumePauseButton.icon } @@ -180,6 +181,14 @@ ColumnLayout { onClicked: directoryView.clickCurrentItemButton( "openButton") } + PlasmaExtras.MenuItem { + id: browseRemoteFilesItem + text: qsTr("Browse remote files") + icon: "document-open-remote" + onClicked: directoryView.triggerNativeActionWithCurrentItemData( + "browseRemoteFiles", "dirId_") + visible: plasmoid.wipFeaturesEnabled + } } } } diff --git a/plasmoid/package6/contents/ui/TopLevelView.qml b/plasmoid/package6/contents/ui/TopLevelView.qml index b0a70ec..a41c6ae 100644 --- a/plasmoid/package6/contents/ui/TopLevelView.qml +++ b/plasmoid/package6/contents/ui/TopLevelView.qml @@ -42,16 +42,20 @@ ListView { } } - function copyCurrentItemData(fieldName) { + function triggerNativeActionWithCurrentItemData(actionName, fieldName) { if (!currentItem) { return } - var data = currentItem[fieldName] + const data = currentItem[fieldName] if (data) { - plasmoid.copyToClipboard(data) + plasmoid[actionName](data) } } + function copyCurrentItemData(fieldName) { + this.triggerNativeActionWithCurrentItemData("copyToClipboard", fieldName) + } + function showContextMenu(item, x, y) { if (typeof contextMenu === "undefined") { return diff --git a/plasmoid/scripts/settestenv.sh b/plasmoid/scripts/settestenv.sh index b11e0b6..7795a1a 100755 --- a/plasmoid/scripts/settestenv.sh +++ b/plasmoid/scripts/settestenv.sh @@ -17,8 +17,8 @@ if ! [[ $QT_PLUGIN_PATH ]]; then elif [ -f "$PWD"/plasmoid/lib/plasma/applets/*syncthingplasmoid*.so ]; then export QT_PLUGIN_PATH=$PWD/plasmoid/lib fi - echo "QT_PLUGIN_PATH used for Plasmoid testing: $QT_PLUGIN_PATH" fi +echo "QT_PLUGIN_PATH used for Plasmoid testing: $QT_PLUGIN_PATH" # set TEST_FILE_PATH so files for the mocked configuration can be found export TEST_FILE_PATH=$(dirname "${BASH_SOURCE[0]}")/../testfiles