Plasma-workspace

defaultservice.cpp
1// SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
2// SPDX-FileCopyrightText: 2023 Harald Sitter <sitter@kde.org>
3
4#include "defaultservice.h"
5
6#include <KApplicationTrader>
7#include <KConfigGroup>
8#include <KSharedConfig>
9
10KService::Ptr DefaultService::browser()
11{
12 // NOTE this function could be lifted into a framework or refactored into only following scheme-handler
13 KService::Ptr preferredService = KApplicationTrader::preferredService(QStringLiteral("x-scheme-handler/http"));
14 if (preferredService) {
15 return preferredService;
16 }
17
18 KService::Ptr htmlApp = KApplicationTrader::preferredService(QStringLiteral("text/html"));
19 if (htmlApp) {
20 return htmlApp;
21 }
22
23 return KService::serviceByStorageId(legacyBrowserExec());
24}
25
26QString DefaultService::legacyBrowserExec()
27{
28 KConfigGroup config(KSharedConfig::openConfig(), QStringLiteral("General"));
29 QString browserApp = config.readPathEntry("BrowserApplication", QString());
30 if (!browserApp.isEmpty()) {
31 if (browserApp.startsWith(QLatin1Char('!'))) {
32 browserApp.remove(0, 1);
33 }
34 return browserApp;
35 }
36
37 return {};
38}
static Ptr serviceByStorageId(const QString &_storageId)
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
KSERVICE_EXPORT KService::Ptr preferredService(const QString &mimeType)
bool isEmpty() const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Apr 27 2024 22:12:02 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.