Krita Source Code Documentation
Loading...
Searching...
No Matches
KHelpClient Namespace Reference

Functions

KRITAWIDGETUTILS_EXPORT void invokeHelp (const QString &anchor=QString(), const QString &appname=QString())
 

Function Documentation

◆ invokeHelp()

void KHelpClient::invokeHelp ( const QString & anchor = QString(),
const QString & appname = QString() )

Invokes the KHelpCenter HTML help viewer from docbook sources.

The HTML file will be found using the X-DocPath entry in the application's desktop file. It can be either a relative path, or a website URL.

Parameters
anchorThis has to be a defined anchor in your docbook sources or website. If empty the main index is loaded.
appnameThis allows you to specify the .desktop file to get the help path from. If empty the QCoreApplication::applicationName() is used.
Since
5.0

Definition at line 18 of file khelpclient.cpp.

19{
20 QString appname;
21 if (_appname.isEmpty()) {
22 appname = QCoreApplication::instance()->applicationName();
23 } else {
24 appname = _appname;
25 }
26
27 // Look for the .desktop file of the application
28
29 // was:
30 //KService::Ptr service(KService::serviceByDesktopName(appname));
31 //if (service)
32 // docPath = service->docPath();
33 // but we don't want to depend on KService here.
34
35 QString docPath;
36 const QStringList desktopDirs = QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation);
37 Q_FOREACH (const QString &dir, desktopDirs) {
38 QDirIterator it(dir, QStringList() << appname + QLatin1String(".desktop"), QDir::NoFilter, QDirIterator::Subdirectories);
39 while (it.hasNext()) {
40 const QString desktopPath(it.next());
41 KDesktopFile desktopFile(desktopPath);
42 docPath = desktopFile.readDocPath();
43
44 // TODO: why explicit break in a loop?
45 break;
46 }
47 }
48
49 // docPath could be a path or a full URL, I think.
50
51 QUrl url;
52 if (!docPath.isEmpty()) {
53 url = QUrl(QLatin1String("help:/")).resolved(QUrl(docPath));
54 } else {
55 url = QUrl(QString::fromLatin1("help:/%1/index.html").arg(appname));
56 }
57
58 if (!anchor.isEmpty()) {
59 QUrlQuery query(url);
60 query.addQueryItem(QString::fromLatin1("anchor"), anchor);
61 url.setQuery(query);
62 }
63
64 // launch khelpcenter, or a browser for URIs not handled by khelpcenter
65 QDesktopServices::openUrl(url);
66}
QList< QString > QStringList