diff --git a/autotests/openurljobtest.h b/autotests/openurljobtest.h --- a/autotests/openurljobtest.h +++ b/autotests/openurljobtest.h @@ -55,12 +55,14 @@ void ftpUrlWithKIO(); void takeOverAfterMimeTypeFound(); + void runDeskopFileDirectly(); private: void writeApplicationDesktopFile(const QString &filePath); QStringList m_filesToRemove; QTemporaryDir m_tempDir; + QString m_fakeService; }; #endif /* OPENURLJOBTEST_H */ diff --git a/autotests/openurljobtest.cpp b/autotests/openurljobtest.cpp --- a/autotests/openurljobtest.cpp +++ b/autotests/openurljobtest.cpp @@ -79,10 +79,10 @@ QFile::remove(mimeApps); ksycoca_ms_between_checks = 0; // need it to check the ksycoca mtime - QString fakeService = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + QLatin1Char('/') + s_tempServiceName; - writeApplicationDesktopFile(fakeService); - fakeService = QFileInfo(fakeService).canonicalFilePath(); - m_filesToRemove.append(fakeService); + m_fakeService = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + QLatin1Char('/') + s_tempServiceName; + writeApplicationDesktopFile(m_fakeService); + m_fakeService = QFileInfo(m_fakeService).canonicalFilePath(); + m_filesToRemove.append(m_fakeService); // Ensure our service is the preferred one KConfig mimeAppsCfg(mimeApps); @@ -95,7 +95,7 @@ for (const char *mimeType : {"text/plain", "application/x-shellscript"}) { KService::Ptr preferredTextEditor = KApplicationTrader::preferredService(QString::fromLatin1(mimeType)); QVERIFY(preferredTextEditor); - QCOMPARE(preferredTextEditor->entryPath(), fakeService); + QCOMPARE(preferredTextEditor->entryPath(), m_fakeService); } // As used for preferredService @@ -442,6 +442,17 @@ QCOMPARE(foundMime, "image/jpeg"); } +void OpenUrlJobTest::runDeskopFileDirectly() +{ + KIO::OpenUrlJob *job = new KIO::OpenUrlJob(QUrl::fromLocalFile(m_fakeService), this); + job->setRunExecutables(true); + QVERIFY(job->exec()); + + const QString dest = m_tempDir.path() + "/dest"; + QTRY_VERIFY2(QFile::exists(dest), qPrintable(dest)); + QCOMPARE(readFile(dest), QString{}); +} + void OpenUrlJobTest::writeApplicationDesktopFile(const QString &filePath) { KDesktopFile file(filePath); diff --git a/src/gui/openurljob.cpp b/src/gui/openurljob.cpp --- a/src/gui/openurljob.cpp +++ b/src/gui/openurljob.cpp @@ -86,7 +86,11 @@ bool handleExecutables(const QMimeType &mimeType); void runLink(const QString &filePath, const QString &urlStr, const QString &optionalServiceName); void showOpenWithDialog(); - void startService(const KService::Ptr &service); + void startService(const KService::Ptr &service, const QList &urls); + void startService(const KService::Ptr &service) + { + startService(service, {m_url}); + } }; KIO::OpenUrlJob::OpenUrlJob(const QUrl &url, QObject *parent) @@ -308,10 +312,10 @@ }); } -void KIO::OpenUrlJobPrivate::startService(const KService::Ptr &service) +void KIO::OpenUrlJobPrivate::startService(const KService::Ptr &service, const QList &urls) { KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(service, q); - job->setUrls({m_url}); + job->setUrls(urls); job->setRunFlags(m_deleteTemporaryFile ? KIO::ApplicationLauncherJob::DeleteTemporaryFiles : KIO::ApplicationLauncherJob::RunFlags{}); job->setSuggestedFileName(m_suggestedFileName); job->setStartupId(m_startupId); @@ -575,7 +579,7 @@ && !cfgGroup.readEntry("Exec").isEmpty() && m_runExecutables) { KService::Ptr service(new KService(filePath)); - startService(service); + startService(service, {}); return; } else if (cfg.hasLinkType()) { runLink(filePath, cfg.readUrl(), cfg.desktopGroup().readEntry("X-KDE-LastOpenedWith"));