Commit c4c765a9 authored by Ahmad Samir's avatar Ahmad Samir Committed by David Faure

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.
parent 071f1a26
......@@ -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)
......
......@@ -33,9 +33,10 @@
#include "queries.h"
#include <KIO/JobTracker>
#include <KIO/JobUiDelegate>
#include <KIO/OpenUrlJob>
#include <KLocalizedString>
#include <KMessageBox>
#include <KRun>
#include <KWidgetJobTracker>
#include <QDir>
......@@ -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";
......
......@@ -48,13 +48,15 @@
#include <KActionCollection>
#include <KConfigGroup>
#include <KGuiItem>
#include <KIO/ApplicationLauncherJob>
#include <KIO/Job>
#include <KIO/JobUiDelegate>
#include <KIO/OpenUrlJob>
#include <KJobWidgets>
#include <KIO/StatJob>
#include <KMessageBox>
#include <KParts/OpenUrlArguments>
#include <KPluginFactory>
#include <KRun>
#include <KStandardGuiItem>
#include <KToggleAction>
#include <KLocalizedString>
......@@ -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<OpenWithJob*>(job)) {
const QList<QUrl> 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()) {
......
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