Krita Source Code Documentation
Loading...
Searching...
No Matches
khelpclient.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 * SPDX-FileCopyrightText: 2012 David Faure <faure@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6
7#include "khelpclient.h"
8
9#include "kdesktopfile.h"
10
11#include <QCoreApplication>
12#include <QUrl>
13#include <QDirIterator>
14#include <QUrlQuery>
15#include <QStandardPaths>
16#include <QDesktopServices>
17
18void KHelpClient::invokeHelp(const QString &anchor, const QString &_appname)
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}
67
QList< QString > QStringList
KRITAWIDGETUTILS_EXPORT void invokeHelp(const QString &anchor=QString(), const QString &appname=QString())