Commit fe562da6 authored by Ahmad Samir's avatar Ahmad Samir

Port KRun to new KIO classes

Let JobUiDelegate handle the error messages.

Keep the code building with older KF versions.
parent 4f5bbd82
......@@ -16,14 +16,21 @@
#include <ktexteditor/document.h>
#include <ktexteditor/editor.h>
#include <kio_version.h>
#if KIO_VERSION < QT_VERSION_CHECK(5, 71, 0)
#include <KOpenWithDialog>
#include <KRun>
#else
#include <KIO/ApplicationLauncherJob>
#include <KIO/JobUiDelegate>
#endif
#include <KApplicationTrader>
#include <KIO/CopyJob>
#include <KIO/DeleteJob>
#include <KIO/OpenFileManagerWindowJob>
#include <KLocalizedString>
#include <KMessageBox>
#include <KOpenWithDialog>
#include <KRun>
#include <KStandardAction>
#include <QApplication>
......@@ -283,15 +290,14 @@ void KateFileTree::slotFixOpenWithMenu()
void KateFileTree::slotOpenWithMenuAction(QAction *a)
{
QList<QUrl> list;
KTextEditor::Document *doc = model()->data(m_indexContextMenu, KateFileTreeModel::DocumentRole).value<KTextEditor::Document *>();
if (!doc) {
return;
}
list.append(doc->url());
const QList<QUrl> list({doc->url()});
#if KIO_VERSION < QT_VERSION_CHECK(5, 71, 0)
const QString openWith = a->data().toString();
if (openWith.isEmpty()) {
// display "open with" dialog
......@@ -308,6 +314,14 @@ void KateFileTree::slotOpenWithMenuAction(QAction *a)
} else {
KMessageBox::error(this, i18n("Application '%1' not found.", openWith), i18n("Application not found"));
}
#else
KService::Ptr app = KService::serviceByDesktopPath(a->data().toString());
// If app is null, ApplicationLauncherJob will invoke the open-with dialog
auto *job = new KIO::ApplicationLauncherJob(app);
job->setUrls(list);
job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
job->start();
#endif
}
Q_DECLARE_METATYPE(QList<KTextEditor::Document *>)
......
......@@ -7,13 +7,20 @@
#include "kateprojecttreeviewcontextmenu.h"
#include <kio_version.h>
#if KIO_VERSION < QT_VERSION_CHECK(5, 71, 0)
#include <KRun>
#else
#include <KIO/ApplicationLauncherJob>
#include <KIO/JobUiDelegate>
#endif
#include <KApplicationTrader>
#include <KIO/OpenFileManagerWindowJob>
#include <KLocalizedString>
#include <KNS3/KMoreTools>
#include <KNS3/KMoreToolsMenuFactory>
#include <KPropertiesDialog>
#include <KRun>
#include <QApplication>
#include <QClipboard>
......@@ -114,6 +121,22 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QPoint
}
}
auto handleOpenWith = [parent](QAction *action, const QString &filename) {
#if KIO_VERSION < QT_VERSION_CHECK(5, 71, 0)
const QString openWith = action->data().toString();
if (KService::Ptr app = KService::serviceByDesktopPath(openWith)) {
KRun::runService(*app, {QUrl::fromLocalFile(filename)}, parent);
}
#else
KService::Ptr app = KService::serviceByDesktopPath(action->data().toString());
// If app is null, ApplicationLauncherJob will invoke the open-with dialog
auto *job = new KIO::ApplicationLauncherJob(app);
job->setUrls({QUrl::fromLocalFile(filename)});
job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, parent));
job->start();
#endif
};
/**
* run menu and handle the triggered action
*/
......@@ -122,12 +145,7 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QPoint
QApplication::clipboard()->setText(filename);
} else if (action->parentWidget() == openWithMenu) {
// handle "open with"
const QString openWith = action->data().toString();
if (KService::Ptr app = KService::serviceByDesktopPath(openWith)) {
QList<QUrl> list;
list << QUrl::fromLocalFile(filename);
KRun::runService(*app, list, parent);
}
handleOpenWith(action, filename);
} else if (action == openContaingFolderAction) {
KIO::highlightInFileManager({QUrl::fromLocalFile(filename)});
} else if (action == filePropertiesAction) {
......
......@@ -41,7 +41,6 @@
#include <KOpenWithDialog>
#include <KRecentDocument>
#include <KRecentFilesAction>
#include <KRun>
#include <KSharedConfig>
#include <KShortcutsDialog>
#include <KStandardAction>
......@@ -51,6 +50,14 @@
#include <KWindowSystem>
#include <KXMLGUIFactory>
#include <kio_version.h>
#if KIO_VERSION < QT_VERSION_CHECK(5, 71, 0)
#include <KRun>
#else
#include <KIO/ApplicationLauncherJob>
#include <KIO/JobUiDelegate>
#endif
#include <KFileItem>
#include <KIO/Job>
......@@ -900,8 +907,8 @@ void KateMainWindow::mSlotFixOpenWithMenu()
void KateMainWindow::slotOpenWithMenuAction(QAction *a)
{
QList<QUrl> list;
list.append(m_viewManager->activeView()->document()->url());
const QList<QUrl> list({m_viewManager->activeView()->document()->url()});
#if KIO_VERSION < QT_VERSION_CHECK(5, 71, 0)
const QString openWith = a->data().toString();
if (openWith.isEmpty()) {
......@@ -919,6 +926,14 @@ void KateMainWindow::slotOpenWithMenuAction(QAction *a)
} else {
KMessageBox::error(this, i18n("Application '%1' not found.", openWith), i18n("Application not found"));
}
#else
KService::Ptr app = KService::serviceByDesktopPath(a->data().toString());
// If app is null, ApplicationLauncherJob will invoke the open-with dialog
auto *job = new KIO::ApplicationLauncherJob(app);
job->setUrls(list);
job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
job->start();
#endif
}
void KateMainWindow::pluginHelp()
......
......@@ -11,10 +11,17 @@
#include "katedocmanager.h"
#include "katemainwindow.h"
#include <kio_version.h>
#if KIO_VERSION < QT_VERSION_CHECK(5, 71, 0)
#include <KRun>
#else
#include <KIO/JobUiDelegate>
#include <KIO/OpenUrlJob>
#endif
#include <KLocalizedString>
#include <KMessageBox>
#include <KProcess>
#include <KRun>
#include <QHeaderView>
#include <QLabel>
......@@ -311,8 +318,16 @@ void KateMwModOnHdDialog::slotPDone()
delete m_diffFile;
m_diffFile = nullptr;
#if KIO_VERSION < QT_VERSION_CHECK(5, 71, 0)
// KRun::runUrl should delete the file, once the client exits
KRun::runUrl(url, QStringLiteral("text/x-patch"), this, KRun::RunFlags(KRun::DeleteTemporaryFiles));
#else
// OpenUrlJob will delete the temp. file
auto *job = new KIO::OpenUrlJob(url, QStringLiteral("text/x-patch"));
job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
job->setDeleteTemporaryFile(true);
job->start();
#endif
}
void KateMwModOnHdDialog::addDocument(KTextEditor::Document *doc)
......
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