Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
WallpaperCandidates.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3#pragma once
4
5#include <QFileInfo>
6#include <QList>
7#include <QObject>
8#include <QString>
9#include <QStringList>
10#include <QVariantList>
11#include <QtQmlIntegration/qqmlintegration.h>
12
13namespace PhosphorShellPicker {
14
17{
19 QString path;
21 QString name;
23 QString source;
24
25 bool operator==(const Candidate& other) const = default;
26};
27
47class WallpaperCandidates : public QObject
48{
49 Q_OBJECT
50 QML_ELEMENT
51
53 Q_PROPERTY(QStringList directories READ directories WRITE setDirectories NOTIFY directoriesChanged)
55 Q_PROPERTY(QString currentPath READ currentPath WRITE setCurrentPath NOTIFY currentPathChanged)
57 Q_PROPERTY(QVariantList candidates READ candidates NOTIFY candidatesChanged)
58 Q_PROPERTY(int count READ count NOTIFY candidatesChanged)
59
60public:
61 explicit WallpaperCandidates(QObject* parent = nullptr);
63
64 [[nodiscard]] QStringList directories() const;
65 void setDirectories(const QStringList& directories);
66
67 [[nodiscard]] QString currentPath() const;
68 void setCurrentPath(const QString& path);
69
70 [[nodiscard]] QVariantList candidates() const;
71 [[nodiscard]] int count() const;
72
75 [[nodiscard]] static QStringList defaultDirectories();
76
79 [[nodiscard]] static QList<Candidate> scanDirectory(const QString& directory);
80
84 [[nodiscard]] static QString packageImage(const QString& packageDir);
85
87 [[nodiscard]] static QString packageName(const QString& packageDir);
88
90 [[nodiscard]] static bool isImageFile(const QString& fileName);
91
95 [[nodiscard]] static bool isUsableImage(const QFileInfo& entry);
96
101 static constexpr int MaxCandidatesPerDirectory = 2000;
102
105 Q_INVOKABLE void rescan();
106
107Q_SIGNALS:
111
112private:
113 QStringList m_directories;
114 QString m_currentPath;
115 QList<Candidate> m_candidates;
116 // Lazily built view of m_candidates for QML; see candidates().
117 mutable QVariantList m_candidatesCache;
118 mutable bool m_candidatesCacheValid = false;
119};
120
121} // namespace PhosphorShellPicker
static bool isUsableImage(const QFileInfo &entry)
Whether a scanned entry is a REGULAR file the picker can offer.
static bool isImageFile(const QString &fileName)
Whether a file name carries a raster image suffix the picker offers.
static QStringList defaultDirectories()
The user's wallpaper directory followed by the system ones, every existing wallpapers directory on th...
WallpaperCandidates(QObject *parent=nullptr)
Directories to scan, in order. Defaults to defaultDirectories().
static QList< Candidate > scanDirectory(const QString &directory)
Scan one directory: its image files and its Plasma packages, sorted by name within each shape (files ...
static QString packageName(const QString &packageDir)
A package's display name from its metadata, or the directory name.
void setDirectories(const QStringList &directories)
static QString packageImage(const QString &packageDir)
The image a Plasma wallpaper package offers: the largest under contents/images/ by the WxH in its nam...
void rescan()
Re-run the scan against directories and currentPath.
void setCurrentPath(const QString &path)
static constexpr int MaxCandidatesPerDirectory
Most candidates taken from any one directory.
Definition WallpaperCandidates.h:101
Definition AppearanceLibrary.h:13
One wallpaper the picker can offer.
Definition WallpaperCandidates.h:17
QString path
Absolute path of the image file.
Definition WallpaperCandidates.h:19
QString source
Where it came from: "current", "file" or "package".
Definition WallpaperCandidates.h:23
QString name
Display name: the file's base name, or a Plasma package's name.
Definition WallpaperCandidates.h:21
bool operator==(const Candidate &other) const =default