From eaa6b0b5f43738c0386e99eeba26b44250e6136d Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 5 Dec 2015 19:12:26 +0100 Subject: Implement `cd` command to enable changing _MetaTerm_'s working directory Exposing access to the working directory to QML is the first step towards enabling usage analogously to a normal terminal emulator alongside the management of multiple running appications. i.e. executing `cd` should change the global working directory so that consecutive commands work as expected. --- main.cc | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'main.cc') diff --git a/main.cc b/main.cc index 617b43a..a27ab6c 100644 --- a/main.cc +++ b/main.cc @@ -1,12 +1,36 @@ +#include +#include #include #include +class WorkingDirectory : public QObject { + Q_OBJECT + + public: + Q_INVOKABLE bool cd(const QString& path) const { + QDir current(QDir::current()); + + const bool result = current.cd(path); + + QDir::setCurrent(current.absolutePath()); + + return result; + } + + Q_INVOKABLE QString current() const { + return QDir::current().absolutePath(); + } +}; + int main(int argc, char *argv[]) { - QApplication application(argc, argv); + WorkingDirectory directory; + QApplication application(argc, argv); + QQmlApplicationEngine engine(QUrl(QStringLiteral("qrc:/main.qml"))); + application.setOrganizationName("akr"); application.setApplicationName("MetaTerm"); - QQmlApplicationEngine engine(QUrl(QStringLiteral("qrc:/main.qml"))); + engine.rootContext()->setContextProperty("workingDirectory", &directory); QObject::connect( static_cast(&engine), @@ -17,3 +41,5 @@ int main(int argc, char *argv[]) { return application.exec(); } + +#include "main.moc" -- cgit v1.2.3