Plasma-workspace

defaultwallpaper.cpp
1// SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
2// SPDX-FileCopyrightText: 2023 Méven Car <meven@kde.org>
3
4#include "defaultwallpaper.h"
5
6#include <KConfigGroup>
7#include <KPackage/PackageLoader>
8#include <Plasma/Theme>
9
10KPackage::Package DefaultWallpaper::defaultWallpaperPackage()
11{
12 // Try from the look and feel package first, then from the plasma theme
13 KPackage::Package lookAndFeelPackage = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel"));
14 KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), QStringLiteral("KDE"));
15 const QString packageName = cg.readEntry("LookAndFeelPackage", QString());
16 // If empty, it will be the default (currently Breeze)
17 if (!packageName.isEmpty()) {
18 lookAndFeelPackage.setPath(packageName);
19 }
20
21 KConfigGroup lnfDefaultsConfig = KConfigGroup(KSharedConfig::openConfig(lookAndFeelPackage.filePath("defaults")), QStringLiteral("Wallpaper"));
22
23 const QString image = lnfDefaultsConfig.readEntry("Image", "");
24 KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Wallpaper/Images"));
25
26 if (!image.isEmpty()) {
27 package.setPath(
28 QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("wallpapers/%1").arg(image), QStandardPaths::LocateDirectory));
29 }
30
31 if (!package.isValid()) {
32 // Try to get a default from the plasma theme
33 Plasma::Theme theme;
34 QString path = theme.wallpaperPath();
35 int index = path.indexOf(QLatin1String("/contents/images/"));
36 if (index > -1) { // We have file from package -> get path to package
37 path = path.left(index);
38 }
39 package.setPath(path);
40 }
41
42 if (!package.isValid()) {
43 // Use Next
44 package.setPath(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("wallpapers/Next"), QStandardPaths::LocateDirectory));
45 }
46
47 return package;
48}
QString readEntry(const char *key, const char *aDefault=nullptr) const
Package loadPackage(const QString &packageFormat, const QString &packagePath=QString())
static PackageLoader * self()
void setPath(const QString &path)
QString filePath(const QByteArray &key, const QString &filename=QString()) const
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 12:00:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.