From 9f7365cbb65b0c46306657facbee3d39dabf318a Mon Sep 17 00:00:00 2001 From: Slendi Date: Tue, 14 Oct 2025 20:35:03 +0300 Subject: [PATCH] Begin work on icons Signed-off-by: Slendi --- src/IconRegistry.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++ src/IconRegistry.hpp | 23 +++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/IconRegistry.cpp create mode 100644 src/IconRegistry.hpp diff --git a/src/IconRegistry.cpp b/src/IconRegistry.cpp new file mode 100644 index 0000000..a184461 --- /dev/null +++ b/src/IconRegistry.cpp @@ -0,0 +1,60 @@ +#include "IconRegistry.hpp" + +#include +#include +#include +#include + +IconTheme::IconTheme(std::filesystem::path const &themes_directory_path) +{ + for (auto const &dir : + std::filesystem::directory_iterator(themes_directory_path)) { + if (!dir.is_directory()) + continue; + + auto const index_path = dir.path() / "index.theme"; + if (std::filesystem::is_regular_file(index_path)) + continue; + } +} + +IconRegistry::IconRegistry() +{ + std::vector theme_directory_paths; + + { + auto const *env { getenv("HOME") }; + if (env && *env) { + theme_directory_paths.push_back( + std::filesystem::path(env) / ".icons"); + } + } + + { + auto const *env { getenv("XDG_DATA_DIRS") }; + if (env && *env) { + theme_directory_paths.push_back( + std::filesystem::path(env) / "icons"); + } + } + + { + std::filesystem::path const path { "/usr/share/pixmaps" }; + if (std::filesystem::exists(path)) + theme_directory_paths.push_back(path); + } + + for (auto const &path : std::move(theme_directory_paths) + | std::views::filter([](std::filesystem::path &path) { + return std::filesystem::is_directory(path); + })) { + try { + m_themes.push_back({ path }); + } catch (...) { + } + } + + if (m_themes.empty()) { + throw std::runtime_error("Could not find any icon themes."); + } +} diff --git a/src/IconRegistry.hpp b/src/IconRegistry.hpp new file mode 100644 index 0000000..d57be76 --- /dev/null +++ b/src/IconRegistry.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include +#include +#include + +struct Icon { }; + +struct IconTheme { + IconTheme(std::filesystem::path const &themes_directory_path); + ~IconTheme() = default; + +private: + std::unordered_map m_cached_icons; +}; + +struct IconRegistry { + IconRegistry(); + ~IconRegistry() = default; + +private: + std::vector m_themes; +};