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 @@
#include <KMimeTypeTrader>
#include <QPushButton>
#include <KRun>
#include <KIO/ApplicationLauncherJob>
#include <QTemporaryFile>
#include <QMimeDatabase>
#include <KFileItemActions>
......@@ -714,24 +715,21 @@ void AttachmentControllerBase::openWith(const KService::Ptr &offer)
i18n("Unable to open attachment"));
return;
}
QList<QUrl> lst;
QUrl url = QUrl::fromLocalFile(tempFile->fileName());
lst.append(url);
tempFile->setPermissions(QFile::ReadUser);
bool result = false;
if (offer) {
result = KRun::runService(*offer, lst, d->wParent, false);
} else {
result = KRun::displayOpenWithDialog(lst, d->wParent, false);
}
if (!result) {
// If offer is null, this will show the "open with" dialog
KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(offer);
job->setUrls({url});
job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, d->wParent));
job->start();
connect(job, &KJob::result, this, [tempFile, job]() {
if (job->error()) {
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).
tempFile->setParent(this); // Manages lifetime.
}
}
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