From 66fa79b87ef92b6208b66ee94ac369dfa8393a17 Mon Sep 17 00:00:00 2001 From: reionwong Date: Mon, 19 Jul 2021 15:51:19 +0800 Subject: [PATCH] Improve open file manager --- src/processhelper.cpp | 22 ++++++++++++++++++++++ src/processhelper.h | 2 +- src/qml/ExitPromptDialog.qml | 17 ++++++++--------- src/qml/Terminal.qml | 2 +- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/processhelper.cpp b/src/processhelper.cpp index deac390..de86b9e 100644 --- a/src/processhelper.cpp +++ b/src/processhelper.cpp @@ -19,9 +19,15 @@ #include "processhelper.h" #include +#include +#include #include #include +#include +#include +#include + ProcessHelper *SELF = nullptr; ProcessHelper *ProcessHelper::self() @@ -52,3 +58,19 @@ bool ProcessHelper::openUrl(const QString &url) return QDesktopServices::openUrl(_url); } + +bool ProcessHelper::openFileManager(const QString &url) +{ + QDBusInterface iface(QStringLiteral("org.freedesktop.FileManager1"), + QStringLiteral("/org/freedesktop/FileManager1"), + QStringLiteral("org.freedesktop.FileManager1")); + + if (iface.lastError().isValid()) + return false; + + iface.call("ShowFolders", + QStringList() << QUrl::fromLocalFile(url).toString(), + QString::number(QApplication::applicationPid())); + + return true; +} diff --git a/src/processhelper.h b/src/processhelper.h index c6f93e5..b4e6de1 100644 --- a/src/processhelper.h +++ b/src/processhelper.h @@ -32,7 +32,7 @@ public: Q_INVOKABLE bool startDetached(const QString &program, const QStringList &arguments); Q_INVOKABLE bool openUrl(const QString &url); - + Q_INVOKABLE bool openFileManager(const QString &url); }; #endif // PROCESSHELPER_H diff --git a/src/qml/ExitPromptDialog.qml b/src/qml/ExitPromptDialog.qml index 21521ef..3ece396 100644 --- a/src/qml/ExitPromptDialog.qml +++ b/src/qml/ExitPromptDialog.qml @@ -28,38 +28,37 @@ Dialog { modal: true - width: _mainLayout.implicitWidth + FishUI.Units.largeSpacing * 4 - height: _mainLayout.implicitHeight + FishUI.Units.largeSpacing * 4 + width: _mainLayout.childrenRect.width + FishUI.Units.largeSpacing * 4 + height: _mainLayout.childrenRect.height + FishUI.Units.largeSpacing * 4 x: (parent.width - control.width) / 2 y: (parent.height - control.height) / 2 signal okBtnClicked - Rectangle { - anchors.fill: parent - color: FishUI.Theme.backgroundColor - } - ColumnLayout { id: _mainLayout anchors.fill: parent + anchors.leftMargin: FishUI.Units.largeSpacing + anchors.rightMargin: FishUI.Units.largeSpacing Label { text: qsTr("Process is running, are you sure you want to quit?") Layout.alignment: Qt.AlignHCenter } - DialogButtonBox { - Layout.alignment: Qt.AlignHCenter + RowLayout { + spacing: FishUI.Units.largeSpacing Button { text: qsTr("Cancel") + Layout.fillWidth: true onClicked: control.visible = false } Button { text: qsTr("OK") + Layout.fillWidth: true onClicked: { control.visible = false control.okBtnClicked() diff --git a/src/qml/Terminal.qml b/src/qml/Terminal.qml index bce1e8d..67c3412 100644 --- a/src/qml/Terminal.qml +++ b/src/qml/Terminal.qml @@ -175,7 +175,7 @@ Page { MenuItem { text: qsTr("Open File Manager") - onTriggered: Process.openUrl(_session.currentDir) + onTriggered: Process.openFileManager(_session.currentDir) } }