Commit 2fbd2d3d authored by Igor Kushnir's avatar Igor Kushnir
Browse files

Man Pages: open unsupported links externally

External opening offers a much better experience than the current silent
ignoring of the user's navigation attempt.

I have tried the following code in place of
QDesktopServices::openUrl(url)):
    auto* const job = new KIO::OpenUrlJob{url};
    job->setUiDelegate(new KIO::JobUiDelegate(
                KJobUiDelegate::AutoHandlingEnabled,
                ICore::self()->uiController()->activeMainWindow()));
    // job->setStartupId(KStartupInfo::startupId());
    job->start();
The KIO::OpenUrlJob() code probably handles errors better, but it is
more verbose and requires including 4 headers. Errors are uncommon in
this case, so I decided to go with the simpler alternative.
parent 4eafe7c5
Pipeline #193368 passed with stage
in 24 minutes and 36 seconds
add_definitions(-DTRANSLATION_DOMAIN=\"kdevmanpage\")
declare_qt_logging_category(kdevmanpage_LOG_SRCS
TYPE PLUGIN
IDENTIFIER MANPAGE
CATEGORY_BASENAME "manpage"
)
set(kdevmanpage_SRCS
manpagedocumentation.cpp
manpageplugin.cpp
manpagemodel.cpp
manpagedocumentationwidget.cpp
${kdevmanpage_LOG_SRCS}
)
kdevplatform_add_plugin(kdevmanpage SOURCES ${kdevmanpage_SRCS})
......
......@@ -9,11 +9,17 @@
#include "manpagemodel.h"
#include "manpageplugin.h"
#include "manpagedocumentation.h"
#include "debug.h"
#include "../openwith/iopenwith.h"
#include <interfaces/icore.h>
#include <interfaces/idocumentationcontroller.h>
#include <QDesktopServices>
#include <QStringListModel>
#include <QTimer>
#include <limits>
namespace {
......@@ -172,14 +178,31 @@ void ManPageModel::showItem(const QModelIndex& idx)
void ManPageModel::showItemFromUrl(const QUrl& url)
{
qCDebug(MANPAGE) << "showing" << url.toDisplayString(QUrl::PreferLocalFile);
auto doc = ManPageDocumentation::s_provider->documentation(url);
IDocumentationController* const controller = ICore::self()->documentationController();
if (!doc) {
doc = controller->documentation(url);
if (!doc) {
// Ignore the unsupported link and stay on the current documentation page
// instead of displaying a blank page. Even if this is an external link we can
// Open the unsupported link externally and stay on the current
// documentation page. Even if this is an external link we can
// download the contents of, our support for website navigation is very poor.
if (url.isLocalFile()) {
// This is usually a system header file => open it in the internal editor.
// HACK: the timer delay works around an inexplicable bug that temporarily
// scales current Documentation view's QWebEnginePage as if its zoomFactor
// equals 1 when the call to IOpenWith::openFiles() ends up opening a
// document in DocumentController.
QTimer::singleShot(100, [url] { IOpenWith::openFiles({url}); });
} else {
// This is usually a website or mailto link. IOpenWith::openFiles()
// tends to open it in the internal editor, which is not nice. Let us
// bypass IOpenWith and open the link in the user's preferred application.
if (!QDesktopServices::openUrl(url)) {
qCWarning(MANPAGE) << "couldn't open URL" << url;
}
}
return;
}
}
......
......@@ -4,12 +4,15 @@ remove_definitions(
-DQT_NO_CAST_FROM_BYTEARRAY
)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
set(test_manpagemodel_SRCS
test_manpagemodel.cpp
../manpagedocumentation.cpp
../manpagedocumentationwidget.cpp
../manpagemodel.cpp
../manpageplugin.cpp
${kdevmanpage_LOG_SRCS}
)
if(Qt5_VERSION VERSION_LESS "5.11.0")
......
Supports Markdown
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