File indexing completed on 2024-04-21 03:55:55

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2021 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only
0006 */
0007 
0008 #include <KIO/JobUiDelegateFactory>
0009 #include <KTerminalLauncherJob>
0010 
0011 #include <KService>
0012 
0013 #include <QApplication>
0014 #include <QDebug>
0015 #include <QProcessEnvironment>
0016 #include <QStandardPaths>
0017 
0018 int main(int argc, char *argv[])
0019 {
0020     QApplication app(argc, argv);
0021 
0022     QString command;
0023     if (argc > 1) {
0024         command = QString::fromLocal8Bit(argv[1]);
0025     }
0026 
0027     auto *job = new KTerminalLauncherJob(command);
0028     QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
0029     env.insert(QStringLiteral("MYVAR"), QStringLiteral("myvalue")); // for interactive testing that it was set
0030     job->setProcessEnvironment(env);
0031     job->setWorkingDirectory(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)); // for testing
0032     job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, nullptr));
0033     job->start();
0034 
0035     QObject::connect(job, &KJob::result, &app, [&]() {
0036         if (job->error()) {
0037             qWarning() << job->errorString();
0038             app.exit(1);
0039         } else {
0040             qDebug() << "Successfully started";
0041             app.exit(0);
0042         }
0043     });
0044 
0045     return app.exec();
0046 }