From c4c765a90bd475303bcaf8d468ae0835aceda340 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Fri, 21 Aug 2020 22:06:38 +0000 Subject: [PATCH] Port KRun to OpenUrlJob and ApplicationLauncherJob In BatchExtract, use QUrl::fromLocalFile to construct a url with the file:// scheme, so that the destination dir can be opened after the extraction is finished. Bump minimum KF version to 5.71 as that's where OpenUrlJob was introduced. --- CMakeLists.txt | 2 +- app/batchextract.cpp | 11 +++++++---- part/part.cpp | 23 ++++++++++++++++------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dfa6dcf5..3fbdc927 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ set (RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE project(ark VERSION ${RELEASE_SERVICE_VERSION}) set(QT_MIN_VERSION 5.12.0) -set(KF5_MIN_VERSION 5.70.0) +set(KF5_MIN_VERSION 5.71.0) find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) diff --git a/app/batchextract.cpp b/app/batchextract.cpp index 8a110f1e..09591d6a 100644 --- a/app/batchextract.cpp +++ b/app/batchextract.cpp @@ -33,9 +33,10 @@ #include "queries.h" #include +#include +#include #include #include -#include #include #include @@ -171,9 +172,11 @@ void BatchExtract::slotResult(KJob *job) if (!hasSubjobs()) { if (openDestinationAfterExtraction()) { - QUrl destination(destinationFolder()); - destination.setPath(QDir::cleanPath(destination.path())); - KRun::runUrl(destination, QStringLiteral("inode/directory"), nullptr, KRun::RunExecutables, QString(), QByteArray()); + const QString path = QDir::cleanPath(destinationFolder()); + const QUrl destination(QUrl::fromLocalFile(path)); + KIO::OpenUrlJob *job = new KIO::OpenUrlJob(destination, QStringLiteral("inode/directory")); + job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, nullptr)); + job->start(); } qCDebug(ARK) << "Finished, emitting the result"; diff --git a/part/part.cpp b/part/part.cpp index c8a935e7..731176b5 100644 --- a/part/part.cpp +++ b/part/part.cpp @@ -48,13 +48,15 @@ #include #include #include +#include #include +#include +#include #include #include #include #include #include -#include #include #include #include @@ -1029,13 +1031,18 @@ void Part::slotOpenExtractedEntry(KJob *job) QFile::setPermissions(fullName, QFileDevice::ReadOwner | QFileDevice::ReadGroup | QFileDevice::ReadOther); } + const QUrl url = QUrl::fromUserInput(fullName, QString(), QUrl::AssumeLocalFile); if (qobject_cast(job)) { - const QList urls = {QUrl::fromUserInput(fullName, QString(), QUrl::AssumeLocalFile)}; - KRun::displayOpenWithDialog(urls, widget()); + // Constructing an ApplicationLauncherJob without an argument will + // trigger the openWith dialog + KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(); + job->setUrls({url}); + job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, widget())); + job->start(); } else { - KRun::runUrl(QUrl::fromUserInput(fullName, QString(), QUrl::AssumeLocalFile), - QMimeDatabase().mimeTypeForFile(fullName).name(), - widget(), KRun::RunFlags()); + KIO::OpenUrlJob *job = new KIO::OpenUrlJob(url); + job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, widget())); + job->start(); } } else if (job->error() != KJob::KilledJobError) { KMessageBox::error(widget(), job->errorString()); @@ -1261,7 +1268,9 @@ void Part::slotExtractionDone(KJob* job) QUrl destinationDirectory = QUrl::fromLocalFile(extractJob->destinationDirectory()).adjusted(QUrl::NormalizePathSegments); qCDebug(ARK) << "Shall open URL" << destinationDirectory; - KRun::runUrl(destinationDirectory, QStringLiteral("inode/directory"), widget(), KRun::RunExecutables, QString(), QByteArray()); + KIO::OpenUrlJob *job = new KIO::OpenUrlJob(destinationDirectory, QStringLiteral("inode/directory")); + job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, widget())); + job->start(); } if (ArkSettings::closeAfterExtraction()) { -- GitLab