Improve open file manager

pull/2/head
reionwong 4 years ago
parent c939ca8934
commit 66fa79b87e

@ -19,9 +19,15 @@
#include "processhelper.h"
#include <QDesktopServices>
#include <QDBusInterface>
#include <QApplication>
#include <QProcess>
#include <QUrl>
#include <QDBusMessage>
#include <QDBusConnection>
#include <QDBusPendingReply>
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;
}

@ -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

@ -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()

@ -175,7 +175,7 @@ Page {
MenuItem {
text: qsTr("Open File Manager")
onTriggered: Process.openUrl(_session.currentDir)
onTriggered: Process.openFileManager(_session.currentDir)
}
}

Loading…
Cancel
Save