Begin work on icons

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-10-14 20:35:03 +03:00
parent 58c5c2c6c4
commit 9f7365cbb6
2 changed files with 83 additions and 0 deletions

60
src/IconRegistry.cpp Normal file
View File

@@ -0,0 +1,60 @@
#include "IconRegistry.hpp"
#include <cstdlib>
#include <filesystem>
#include <ranges>
#include <stdexcept>
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<std::filesystem::path> 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.");
}
}

23
src/IconRegistry.hpp Normal file
View File

@@ -0,0 +1,23 @@
#pragma once
#include <filesystem>
#include <unordered_map>
#include <vector>
struct Icon { };
struct IconTheme {
IconTheme(std::filesystem::path const &themes_directory_path);
~IconTheme() = default;
private:
std::unordered_map<std::string, Icon> m_cached_icons;
};
struct IconRegistry {
IconRegistry();
~IconRegistry() = default;
private:
std::vector<IconTheme> m_themes;
};