KConfigWidgets

khelpclient.cpp
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2012 David Faure <faure@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#include "khelpclient.h"
9
10#include <KDesktopFile>
11
12#include <QCoreApplication>
13#include <QDesktopServices>
14#include <QDirIterator>
15#include <QUrl>
16
17void KHelpClient::invokeHelp(const QString &anchor, const QString &_appname)
18{
19 QString appname;
20 if (_appname.isEmpty()) {
22 } else {
23 appname = _appname;
24 }
25
26 // Look for the .desktop file of the application
27
28 // was:
29 // KService::Ptr service(KService::serviceByDesktopName(appname));
30 // if (service)
31 // docPath = service->docPath();
32 // but we don't want to depend on KService here.
33
34 QString docPath;
36 for (const QString &dir : desktopDirs) {
38 while (it.hasNext()) {
39 const QString desktopPath(it.next());
40 KDesktopFile desktopFile(desktopPath);
41 docPath = desktopFile.readDocPath();
42 break;
43 }
44 }
45
46 // docPath could be a path or a full URL, I think.
47
48 QUrl url;
49 if (!docPath.isEmpty()) {
50 url = QUrl(QStringLiteral("help:/")).resolved(QUrl(docPath));
51 } else {
52 if (!anchor.isEmpty()) {
53 if (anchor.contains(QLatin1Char('#'))) {
54 url = QUrl(QStringLiteral("help:/%1/%2").arg(appname, anchor));
55 } else {
56 url = QUrl(QStringLiteral("help:/%1/%2.html").arg(appname, anchor));
57 }
58 } else {
59 url = QUrl(QStringLiteral("help:/%1/index.html").arg(appname));
60 }
61 }
62
63 // launch khelpcenter, or a browser for URIs not handled by khelpcenter
65}
QString readDocPath() const
void invokeHelp(const QString &anchor=QString(), const QString &appname=QString())
Invokes the KHelpCenter HTML help viewer from docbook sources.
QCoreApplication * instance()
bool openUrl(const QUrl &url)
bool hasNext() const const
QString next()
QStringList standardLocations(StandardLocation type)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QUrl resolved(const QUrl &relative) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:00:18 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.