// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL #include "IconThemeSelector.h" #include #include #include namespace koutnet { IconThemeSelector::IconThemeSelector(KOutNetSettings *settings, QObject *parent) : QObject(parent) , m_settings(settings) , m_baseTheme(QIcon::themeName()) { } QString IconThemeSelector::theme() const { return m_settings->iconTheme(); } void IconThemeSelector::setTheme(const QString &theme) { if (m_settings->iconTheme() == theme) return; const bool wasCustomised = customised(); m_settings->setIconTheme(theme); apply(); Q_EMIT themeChanged(); if (wasCustomised != customised()) Q_EMIT customisedChanged(); } bool IconThemeSelector::customised() const { return !m_settings->iconTheme().isEmpty(); } QStringList IconThemeSelector::availableThemes() const { if (m_themesCached) return m_themes; QStringList themes; const QStringList paths = QIcon::themeSearchPaths(); for (const QString &path : paths) { const QDir directory(path); const QStringList entries = directory.entryList(QDir::Dirs | QDir::NoDotAndDotDot); for (const QString &entry : entries) { // A directory is a theme only if it says so: the marker is the file // Qt reads the theme's own name and inheritance out of. if (QFileInfo::exists(directory.filePath(entry) + QStringLiteral("/index.theme"))) themes << entry; } } themes.removeDuplicates(); themes.sort(Qt::CaseInsensitive); m_themes = themes; m_themesCached = true; return m_themes; } void IconThemeSelector::resetToSystem() { const bool wasCustomised = customised(); m_settings->setIconTheme(QString()); apply(); Q_EMIT themeChanged(); if (wasCustomised) Q_EMIT customisedChanged(); } void IconThemeSelector::apply() const { const QString theme = m_settings->iconTheme(); QIcon::setThemeName(theme.isEmpty() ? m_baseTheme : theme); } } // namespace koutnet