From 3bbe700f969471ce18ba6b41f006485f0957f43e Mon Sep 17 00:00:00 2001 From: reionwong Date: Wed, 30 Jun 2021 17:16:38 +0800 Subject: [PATCH] Support open file manager --- CMakeLists.txt | 2 ++ src/main.cpp | 3 +++ src/processhelper.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ src/processhelper.h | 37 +++++++++++++++++++++++++++++++++++++ src/qml/Terminal.qml | 2 +- 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/processhelper.cpp create mode 100644 src/processhelper.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 970d283..56dc8a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,8 @@ endif() set(SRCS src/main.cpp + src/processhelper.h + src/processhelper.cpp ) set(RESOURCES diff --git a/src/main.cpp b/src/main.cpp index 2ba367f..c3c1071 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,6 +24,8 @@ #include #include +#include "processhelper.h" + int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); @@ -44,6 +46,7 @@ int main(int argc, char *argv[]) } } + engine.rootContext()->setContextProperty("Process", new ProcessHelper); engine.addImportPath(QStringLiteral("qrc:/")); engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml"))); diff --git a/src/processhelper.cpp b/src/processhelper.cpp new file mode 100644 index 0000000..2e9b9ed --- /dev/null +++ b/src/processhelper.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: Reion Wong + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "processhelper.h" +#include + +ProcessHelper *SELF = nullptr; + +ProcessHelper *ProcessHelper::self() +{ + if (!SELF) + SELF = new ProcessHelper; + + return SELF; +} + +ProcessHelper::ProcessHelper(QObject *parent) + : QObject(parent) +{ + +} + +bool ProcessHelper::startDetached(const QString &program, const QStringList &arguments) +{ + return QProcess::startDetached(program, arguments); +} diff --git a/src/processhelper.h b/src/processhelper.h new file mode 100644 index 0000000..d20bb8d --- /dev/null +++ b/src/processhelper.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: Reion Wong + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef PROCESSHELPER_H +#define PROCESSHELPER_H + +#include + +class ProcessHelper : public QObject +{ + Q_OBJECT + +public: + static ProcessHelper *self(); + explicit ProcessHelper(QObject *parent = nullptr); + + Q_INVOKABLE bool startDetached(const QString &program, const QStringList &arguments); + +}; + +#endif // PROCESSHELPER_H diff --git a/src/qml/Terminal.qml b/src/qml/Terminal.qml index 45f69f4..fd25067 100644 --- a/src/qml/Terminal.qml +++ b/src/qml/Terminal.qml @@ -174,7 +174,7 @@ Page { MenuItem { text: qsTr("Open File Manager") - onTriggered: {} + onTriggered: Process.startDetached("gio", ["open", _session.currentDir]) } }