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 ...@@ -8,7 +8,7 @@ set (RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE
project(ark VERSION ${RELEASE_SERVICE_VERSION}) project(ark VERSION ${RELEASE_SERVICE_VERSION})
set(QT_MIN_VERSION 5.12.0) 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) find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
......
...@@ -33,9 +33,10 @@ ...@@ -33,9 +33,10 @@
#include "queries.h" #include "queries.h"
#include <KIO/JobTracker> #include <KIO/JobTracker>
#include <KIO/JobUiDelegate>
#include <KIO/OpenUrlJob>
#include <KLocalizedString> #include <KLocalizedString>
#include <KMessageBox> #include <KMessageBox>
#include <KRun>
#include <KWidgetJobTracker> #include <KWidgetJobTracker>
#include <QDir> #include <QDir>
...@@ -171,9 +172,11 @@ void BatchExtract::slotResult(KJob *job) ...@@ -171,9 +172,11 @@ void BatchExtract::slotResult(KJob *job)
if (!hasSubjobs()) { if (!hasSubjobs()) {
if (openDestinationAfterExtraction()) { if (openDestinationAfterExtraction()) {
QUrl destination(destinationFolder()); const QString path = QDir::cleanPath(destinationFolder());
destination.setPath(QDir::cleanPath(destination.path())); const QUrl destination(QUrl::fromLocalFile(path));
KRun::runUrl(destination, QStringLiteral("inode/directory"), nullptr, KRun::RunExecutables, QString(), QByteArray()); 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"; qCDebug(ARK) << "Finished, emitting the result";
......
...@@ -48,13 +48,15 @@ ...@@ -48,13 +48,15 @@
#include <KActionCollection> #include <KActionCollection>
#include <KConfigGroup> #include <KConfigGroup>
#include <KGuiItem> #include <KGuiItem>
#include <KIO/ApplicationLauncherJob>
#include <KIO/Job> #include <KIO/Job>
#include <KIO/JobUiDelegate>
#include <KIO/OpenUrlJob>
#include <KJobWidgets> #include <KJobWidgets>
#include <KIO/StatJob> #include <KIO/StatJob>
#include <KMessageBox> #include <KMessageBox>
#include <KParts/OpenUrlArguments> #include <KParts/OpenUrlArguments>
#include <KPluginFactory> #include <KPluginFactory>
#include <KRun>
#include <KStandardGuiItem> #include <KStandardGuiItem>
#include <KToggleAction> #include <KToggleAction>
#include <KLocalizedString> #include <KLocalizedString>
...@@ -1029,13 +1031,18 @@ void Part::slotOpenExtractedEntry(KJob *job) ...@@ -1029,13 +1031,18 @@ void Part::slotOpenExtractedEntry(KJob *job)
QFile::setPermissions(fullName, QFileDevice::ReadOwner | QFileDevice::ReadGroup | QFileDevice::ReadOther); QFile::setPermissions(fullName, QFileDevice::ReadOwner | QFileDevice::ReadGroup | QFileDevice::ReadOther);
} }
const QUrl url = QUrl::fromUserInput(fullName, QString(), QUrl::AssumeLocalFile);
if (qobject_cast<OpenWithJob*>(job)) { if (qobject_cast<OpenWithJob*>(job)) {
const QList<QUrl> urls = {QUrl::fromUserInput(fullName, QString(), QUrl::AssumeLocalFile)}; // Constructing an ApplicationLauncherJob without an argument will
KRun::displayOpenWithDialog(urls, widget()); // trigger the openWith dialog
KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob();
job->setUrls({url});
job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, widget()));
job->start();
} else { } else {
KRun::runUrl(QUrl::fromUserInput(fullName, QString(), QUrl::AssumeLocalFile), KIO::OpenUrlJob *job = new KIO::OpenUrlJob(url);
QMimeDatabase().mimeTypeForFile(fullName).name(), job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, widget()));
widget(), KRun::RunFlags()); job->start();
} }
} else if (job->error() != KJob::KilledJobError) { } else if (job->error() != KJob::KilledJobError) {
KMessageBox::error(widget(), job->errorString()); KMessageBox::error(widget(), job->errorString());
...@@ -1261,7 +1268,9 @@ void Part::slotExtractionDone(KJob* job) ...@@ -1261,7 +1268,9 @@ void Part::slotExtractionDone(KJob* job)
QUrl destinationDirectory = QUrl::fromLocalFile(extractJob->destinationDirectory()).adjusted(QUrl::NormalizePathSegments); QUrl destinationDirectory = QUrl::fromLocalFile(extractJob->destinationDirectory()).adjusted(QUrl::NormalizePathSegments);
qCDebug(ARK) << "Shall open URL" << destinationDirectory; 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()) { 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