Commit f3362c1a authored by Volker Krause's avatar Volker Krause

Clean up duplicated local file import code

parent 1ff6a227
......@@ -215,13 +215,13 @@ void ApplicationController::navigateTo(const QGeoPositionInfo &from, const QVari
}
#endif
#ifdef Q_OS_ANDROID
static bool isPkPassFile(const QUrl &url)
{
// ### is this enough, or do we need to check the file magic?
return url.fileName().endsWith(QLatin1String(".pkpass"));
}
#ifdef Q_OS_ANDROID
void ApplicationController::importFromIntent(const QAndroidJniObject &intent)
{
if (!intent.isValid()) {
......@@ -245,12 +245,7 @@ void ApplicationController::importFromIntent(const QAndroidJniObject &intent)
}
} else if (scheme.toString() == QLatin1String("file")) {
const auto uriStr = uri.callObjectMethod("toString", "()Ljava/lang/String;");
const auto url = QUrl(uriStr.toString());
if (isPkPassFile(url)) {
m_pkPassMgr->importPass(url);
} else {
m_resMgr->importReservation(url);
}
importLocalFile(QUrl(uriStr.toString()));
} else {
const auto uriStr = uri.callObjectMethod("toString", "()Ljava/lang/String;");
qCWarning(Log) << "Unknown intent URI:" << uriStr.toString();
......@@ -275,3 +270,12 @@ void ApplicationController::importFile()
QtAndroid::startActivity(intent, 0, &m_activityResultReceiver);
#endif
}
void ApplicationController::importLocalFile(const QUrl &url)
{
if (isPkPassFile(url)) {
m_pkPassMgr->importPass(url);
} else {
m_resMgr->importReservation(url);
}
}
......@@ -48,6 +48,7 @@ public:
#ifdef Q_OS_ANDROID
void importFromIntent(const QAndroidJniObject &intent);
#endif
void importLocalFile(const QUrl &url);
private:
ReservationManager *m_resMgr = nullptr;
......
......@@ -114,16 +114,13 @@ int main(int argc, char **argv)
appController.setReservationManager(&resMgr);
appController.setPkPassManager(&passMgr);
#ifndef Q_OS_ANDROID
QObject::connect(&service, &KDBusService::activateRequested, [&parser, &passMgr, &resMgr](const QStringList &args, const QString &workingDir) {
QObject::connect(&service, &KDBusService::activateRequested, [&parser, &appController](const QStringList &args, const QString &workingDir) {
qCDebug(Log) << "remote activation" << args << workingDir;
if (!args.isEmpty()) {
QDir::setCurrent(workingDir);
parser.parse(args);
for (const auto &file : parser.positionalArguments()) {
if (file.endsWith(QLatin1String(".pkpass")))
passMgr.importPass(QUrl::fromLocalFile(file));
else
resMgr.importReservation(QUrl::fromLocalFile(file));
appController.importLocalFile(QUrl::fromLocalFile(file));
}
}
if (!QGuiApplication::allWindows().isEmpty()) {
......@@ -168,10 +165,7 @@ int main(int argc, char **argv)
engine.load(QStringLiteral(":/main.qml"));
for (const auto &file : parser.positionalArguments()) {
if (file.endsWith(QLatin1String(".pkpass")))
passMgr.importPass(QUrl::fromLocalFile(file));
else
resMgr.importReservation(QUrl::fromLocalFile(file));
appController.importLocalFile(QUrl::fromLocalFile(file));
}
handleViewIntent(&appController);
......
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