Commit 92bbefff authored by David Faure's avatar David Faure Committed by Laurent Montel
Browse files

Port AttachmentControllerBase::openWith to ApplicationLauncherJob

Tested with kmail composer, RMB on attachment, OpenWith submenu
(selecting an app, and selecting "Open With" to get the dialog)
parent 91466ff8
Pipeline #23666 passed with stage
in 84 minutes and 1 second
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#include <KMimeTypeTrader> #include <KMimeTypeTrader>
#include <QPushButton> #include <QPushButton>
#include <KRun> #include <KRun>
#include <KIO/ApplicationLauncherJob>
#include <QTemporaryFile> #include <QTemporaryFile>
#include <QMimeDatabase> #include <QMimeDatabase>
#include <KFileItemActions> #include <KFileItemActions>
...@@ -714,24 +715,21 @@ void AttachmentControllerBase::openWith(const KService::Ptr &offer) ...@@ -714,24 +715,21 @@ void AttachmentControllerBase::openWith(const KService::Ptr &offer)
i18n("Unable to open attachment")); i18n("Unable to open attachment"));
return; return;
} }
QList<QUrl> lst;
QUrl url = QUrl::fromLocalFile(tempFile->fileName()); QUrl url = QUrl::fromLocalFile(tempFile->fileName());
lst.append(url);
tempFile->setPermissions(QFile::ReadUser); tempFile->setPermissions(QFile::ReadUser);
bool result = false; // If offer is null, this will show the "open with" dialog
if (offer) { KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(offer);
result = KRun::runService(*offer, lst, d->wParent, false); job->setUrls({url});
} else { job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, d->wParent));
result = KRun::displayOpenWithDialog(lst, d->wParent, false); job->start();
} connect(job, &KJob::result, this, [tempFile, job]() {
if (!result) { if (job->error()) {
delete tempFile; delete tempFile;
tempFile = nullptr; }
} else { });
// The file was opened. Delete it only when the composer is closed // Delete the file only when the composer is closed
// (and this object is destroyed). // (and this object is destroyed).
tempFile->setParent(this); // Manages lifetime. tempFile->setParent(this); // Manages lifetime.
}
} }
void AttachmentControllerBase::openAttachment(const AttachmentPart::Ptr &part) void AttachmentControllerBase::openAttachment(const AttachmentPart::Ptr &part)
......
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