Commit a11a8b06 authored by Volker Krause's avatar Volker Krause
Browse files

Add a command line option for importing temporary files

Due to being a unique application, we cannot just receive temporary content
(e.g. from Qrca) via stdin, nor can the calling application properly manage
the lifetime of a temporary file for that, as the called process can return
before an already running instance was able to process to data.

Instead we now have an explicit option to tell the consuming instance to
clean up the files it is being passed once those have been imported.
parent 6d444ee6
...@@ -177,15 +177,19 @@ void registerApplicationSingletons() ...@@ -177,15 +177,19 @@ void registerApplicationSingletons()
#undef REGISTER_SINGLETON_INSTANCE #undef REGISTER_SINGLETON_INSTANCE
void handlePositionalArguments(ApplicationController *appController, const QStringList &args) void handlePositionalArguments(ApplicationController *appController, const QStringList &args, bool isTemporary)
{ {
for (const auto &file : args) { for (const auto &file : args) {
const auto localUrl = QUrl::fromLocalFile(file); const auto localUrl = QUrl::fromLocalFile(file);
if (QFile::exists(localUrl.toLocalFile())) if (QFile::exists(localUrl.toLocalFile())) {
appController->importFromUrl(localUrl); appController->importFromUrl(localUrl);
else if (isTemporary) {
QFile::remove(localUrl.toLocalFile());
}
} else {
appController->importFromUrl(QUrl::fromUserInput(file)); appController->importFromUrl(QUrl::fromUserInput(file));
} }
}
} }
#ifdef Q_OS_ANDROID #ifdef Q_OS_ANDROID
...@@ -220,6 +224,8 @@ int main(int argc, char **argv) ...@@ -220,6 +224,8 @@ int main(int argc, char **argv)
KAboutData::setApplicationData(aboutData); KAboutData::setApplicationData(aboutData);
QCommandLineParser parser; QCommandLineParser parser;
QCommandLineOption isTemporaryOpt(QStringLiteral("delete-after-use"), QStringLiteral("Input file is a temporary file that needs to be deleted after importing."));
parser.addOption(isTemporaryOpt);
aboutData.setupCommandLine(&parser); aboutData.setupCommandLine(&parser);
parser.addPositionalArgument(QStringLiteral("file"), i18n("PkPass or JSON-LD file to import.")); parser.addPositionalArgument(QStringLiteral("file"), i18n("PkPass or JSON-LD file to import."));
parser.process(app); parser.process(app);
...@@ -307,12 +313,12 @@ int main(int argc, char **argv) ...@@ -307,12 +313,12 @@ int main(int argc, char **argv)
appController.setLiveDataManager(&liveDataMgr); appController.setLiveDataManager(&liveDataMgr);
appController.setTripGroupManager(&tripGroupMgr); appController.setTripGroupManager(&tripGroupMgr);
#ifndef Q_OS_ANDROID #ifndef Q_OS_ANDROID
QObject::connect(&service, &KDBusService::activateRequested, [&parser, &appController](const QStringList &args, const QString &workingDir) { QObject::connect(&service, &KDBusService::activateRequested, [&](const QStringList &args, const QString &workingDir) {
qCDebug(Log) << "remote activation" << args << workingDir; qCDebug(Log) << "remote activation" << args << workingDir;
if (!args.isEmpty()) { if (!args.isEmpty()) {
QDir::setCurrent(workingDir); QDir::setCurrent(workingDir);
parser.parse(args); parser.parse(args);
handlePositionalArguments(&appController, parser.positionalArguments()); handlePositionalArguments(&appController, parser.positionalArguments(), parser.isSet(isTemporaryOpt));
} }
if (!QGuiApplication::allWindows().isEmpty()) { if (!QGuiApplication::allWindows().isEmpty()) {
QGuiApplication::allWindows().at(0)->requestActivate(); QGuiApplication::allWindows().at(0)->requestActivate();
...@@ -332,7 +338,7 @@ int main(int argc, char **argv) ...@@ -332,7 +338,7 @@ int main(int argc, char **argv)
engine.rootContext()->setContextObject(l10nContext); engine.rootContext()->setContextObject(l10nContext);
engine.load(QStringLiteral("qrc:/main.qml")); engine.load(QStringLiteral("qrc:/main.qml"));
handlePositionalArguments(&appController, parser.positionalArguments()); handlePositionalArguments(&appController, parser.positionalArguments(), parser.isSet(isTemporaryOpt));
#ifdef Q_OS_ANDROID #ifdef Q_OS_ANDROID
using namespace KAndroidExtras; using namespace KAndroidExtras;
appController.importFromIntent(Activity::getIntent()); appController.importFromIntent(Activity::getIntent());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment