Allow showing remote file browser from Plasmoid

This commit is contained in:
Martchus 2024-04-06 19:30:43 +02:00
parent bc6db82b6b
commit 38eb689b69
5 changed files with 41 additions and 5 deletions

View File

@ -363,6 +363,11 @@ QString SyncthingApplet::substituteTilde(const QString &path) const
return Data::substituteTilde(path, m_connection.tilde(), m_connection.pathSeparator()); return Data::substituteTilde(path, m_connection.tilde(), m_connection.pathSeparator());
} }
bool SyncthingApplet::areWipFeaturesEnabled() const
{
return Settings::values().enableWipFeatures;
}
void SyncthingApplet::showSettingsDlg() void SyncthingApplet::showSettingsDlg()
{ {
if (!m_settingsDlg) { if (!m_settingsDlg) {
@ -517,6 +522,19 @@ void SyncthingApplet::showDirectoryErrors(const QString &dirId)
dlg->show(); 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) void SyncthingApplet::copyToClipboard(const QString &text)
{ {
QGuiApplication::clipboard()->setText(text); QGuiApplication::clipboard()->setText(text);

View File

@ -86,6 +86,7 @@ class SyncthingApplet : public Plasma::Applet {
Q_PROPERTY(bool passive READ isPassive NOTIFY passiveChanged) Q_PROPERTY(bool passive READ isPassive NOTIFY passiveChanged)
Q_PROPERTY(QList<QtUtilities::ChecklistItem> passiveStates READ passiveStates WRITE setPassiveStates) Q_PROPERTY(QList<QtUtilities::ChecklistItem> passiveStates READ passiveStates WRITE setPassiveStates)
Q_PROPERTY(QString faUrl READ faUrl NOTIFY faUrlChanged) Q_PROPERTY(QString faUrl READ faUrl NOTIFY faUrlChanged)
Q_PROPERTY(bool wipFeaturesEnabled READ areWipFeaturesEnabled NOTIFY wipFeaturesEnabledChanged)
public: public:
SyncthingApplet(QObject *parent, const QVariantList &data); SyncthingApplet(QObject *parent, const QVariantList &data);
@ -132,6 +133,7 @@ public:
Q_INVOKABLE QIcon loadForkAwesomeIcon(const QString &name, int size = 32) const; Q_INVOKABLE QIcon loadForkAwesomeIcon(const QString &name, int size = 32) const;
Q_INVOKABLE QString formatFileSize(quint64 fileSizeInByte) const; Q_INVOKABLE QString formatFileSize(quint64 fileSizeInByte) const;
Q_INVOKABLE QString substituteTilde(const QString &path) const; Q_INVOKABLE QString substituteTilde(const QString &path) const;
bool areWipFeaturesEnabled() const;
public Q_SLOTS: public Q_SLOTS:
void init() override; void init() override;
@ -146,6 +148,7 @@ public Q_SLOTS:
void dismissNotifications(); void dismissNotifications();
void showInternalErrorsDialog(); void showInternalErrorsDialog();
void showDirectoryErrors(const QString &dirId); void showDirectoryErrors(const QString &dirId);
void browseRemoteFiles(const QString &dirId);
void copyToClipboard(const QString &text); void copyToClipboard(const QString &text);
void updateStatusIconAndTooltip(); void updateStatusIconAndTooltip();
void saveSettings(); void saveSettings();
@ -177,6 +180,8 @@ Q_SIGNALS:
void notificationsAvailableChanged(bool notificationsAvailable); void notificationsAvailableChanged(bool notificationsAvailable);
void passiveChanged(bool passive); void passiveChanged(bool passive);
void faUrlChanged(const QString &faUrl); void faUrlChanged(const QString &faUrl);
/// \remarks Never emitted, just to silence "... depends on non-NOTIFYable ..."
void wipFeaturesEnabledChanged();
private Q_SLOTS: private Q_SLOTS:
void handleSettingsChanged(); void handleSettingsChanged();

View File

@ -38,6 +38,7 @@ ColumnLayout {
delegate: TopLevelItem { delegate: TopLevelItem {
id: item id: item
width: directoryView.effectiveWidth() width: directoryView.effectiveWidth()
readonly property string dirId_: dirId
readonly property string dirName: name readonly property string dirName: name
readonly property string dirPath: path readonly property string dirPath: path
property alias errorsButton: errorsButton property alias errorsButton: errorsButton
@ -141,7 +142,7 @@ ColumnLayout {
function init(item) { function init(item) {
// use value for properties depending on paused state from buttons // 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.text = item.resumePauseButton.tooltip
resumePauseItem.icon = item.resumePauseButton.icon resumePauseItem.icon = item.resumePauseButton.icon
} }
@ -180,6 +181,14 @@ ColumnLayout {
onClicked: directoryView.clickCurrentItemButton( onClicked: directoryView.clickCurrentItemButton(
"openButton") "openButton")
} }
PlasmaExtras.MenuItem {
id: browseRemoteFilesItem
text: qsTr("Browse remote files")
icon: "document-open-remote"
onClicked: directoryView.triggerNativeActionWithCurrentItemData(
"browseRemoteFiles", "dirId_")
visible: plasmoid.wipFeaturesEnabled
}
} }
} }
} }

View File

@ -42,16 +42,20 @@ ListView {
} }
} }
function copyCurrentItemData(fieldName) { function triggerNativeActionWithCurrentItemData(actionName, fieldName) {
if (!currentItem) { if (!currentItem) {
return return
} }
var data = currentItem[fieldName] const data = currentItem[fieldName]
if (data) { if (data) {
plasmoid.copyToClipboard(data) plasmoid[actionName](data)
} }
} }
function copyCurrentItemData(fieldName) {
this.triggerNativeActionWithCurrentItemData("copyToClipboard", fieldName)
}
function showContextMenu(item, x, y) { function showContextMenu(item, x, y) {
if (typeof contextMenu === "undefined") { if (typeof contextMenu === "undefined") {
return return

View File

@ -17,8 +17,8 @@ if ! [[ $QT_PLUGIN_PATH ]]; then
elif [ -f "$PWD"/plasmoid/lib/plasma/applets/*syncthingplasmoid*.so ]; then elif [ -f "$PWD"/plasmoid/lib/plasma/applets/*syncthingplasmoid*.so ]; then
export QT_PLUGIN_PATH=$PWD/plasmoid/lib export QT_PLUGIN_PATH=$PWD/plasmoid/lib
fi fi
echo "QT_PLUGIN_PATH used for Plasmoid testing: $QT_PLUGIN_PATH"
fi 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 # set TEST_FILE_PATH so files for the mocked configuration can be found
export TEST_FILE_PATH=$(dirname "${BASH_SOURCE[0]}")/../testfiles export TEST_FILE_PATH=$(dirname "${BASH_SOURCE[0]}")/../testfiles