diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,8 +14,11 @@ include(KDEInstallDirs) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(KDECMakeSettings) + +find_package(KF5I18n ${KF5_DEP_VERSION} REQUIRED) + set(REQUIRED_QT_VERSION 5.12.0) -find_package(Qt5Gui ${REQUIRED_QT_VERSION} REQUIRED NO_MODULE) +find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Widgets) if (NOT APPLE AND NOT WIN32) find_package(X11 MODULE) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,7 +30,8 @@ target_include_directories(KF5GuiAddons PUBLIC "$") target_include_directories(KF5GuiAddons INTERFACE "$" ) target_compile_definitions(KF5GuiAddons INTERFACE "$") -target_link_libraries(KF5GuiAddons PUBLIC Qt5::Gui) +target_link_libraries(KF5GuiAddons PUBLIC Qt5::Widgets) +target_link_libraries(KF5GuiAddons PUBLIC KF5::I18n) set(WITH_XCB) if (NOT APPLE AND X11_FOUND AND X11_Xkb_FOUND AND XCB_XCB_FOUND) diff --git a/src/util/urlhandler.cpp b/src/util/urlhandler.cpp --- a/src/util/urlhandler.cpp +++ b/src/util/urlhandler.cpp @@ -11,6 +11,9 @@ #include #include #include +#include + +#include class UrlHandler : public QObject { @@ -21,34 +24,39 @@ public Q_SLOTS: void openHelp(const QUrl &url) { + const QString appName = QCoreApplication::applicationName(); + QUrl u(url); if (u.path() == QLatin1Char('/')) { - u.setPath(QCoreApplication::applicationName()); + u.setPath(appName); } const QString helpcenter = QStandardPaths::findExecutable(QStringLiteral("khelpcenter")); - if (helpcenter.isEmpty()) { - //if khelpcenter is not installed and it's a KDE application, use docs.kde.org - if (QCoreApplication::organizationDomain() == QLatin1String("kde.org")) { - if (QCoreApplication::applicationName() == QLatin1String("systemsettings") - && url.path().startsWith(QLatin1String("/kcontrol"))) { - // special case for kcm modules - // e.g. "help:/kcontrol/fonts/index.html" >>> "&application=kcontorl/fonts" - const QUrl httpUrl(QStringLiteral("https://docs.kde.org/index.php?branch=stable5&language=") - + QLocale().name() + QLatin1String("&application=") - + url.path().remove(0, 1).remove(QLatin1String("/index.html"))); - QDesktopServices::openUrl(httpUrl); - } else { - const QUrl httpUrl(QLatin1String("https://docs.kde.org/index.php?branch=stable5&language=")+QLocale().name()+QLatin1String("&application=") + - QCoreApplication::applicationName() + QStringLiteral("&path=") + url.path()); - QDesktopServices::openUrl(httpUrl); - } - } else { - QDesktopServices::openUrl(u); - } - } else { + if (!helpcenter.isEmpty()) { // use khelpcenter if it is available QProcess::startDetached(helpcenter, QStringList(u.toString())); + return; } + + //if khelpcenter is not available and it's a KDE application, use docs.kde.org + if (QCoreApplication::organizationDomain() == QLatin1String("kde.org")) { + QString path = url.path(); + QString docPath; + if (appName == QLatin1String("systemsettings") && path.startsWith(QLatin1String("/kcontrol"))) { + // special case for kcm modules + // e.g. "help:/kcontrol/fonts/index.html" >>> "&application=kcontorl/fonts" + docPath = path.remove(0, 1).remove(QLatin1String("/index.html")); + } else { //e.g. "help:/okular", "help:/systemsettings" + docPath = appName + QStringLiteral("&path=") + path; + } + const QUrl httpUrl(QLatin1String("https://docs.kde.org/index.php?branch=stable5&language=") + + QLocale().name() + QLatin1String("&application=") + docPath); + QDesktopServices::openUrl(httpUrl); + return; + } + + // not a KDE application + // TODO: use qCWarning() when we have loggin categories set up + qDebug() << "Could not find a suitable handler for " << u.toString(); } };