chore: structured src/gui, run clang-format

This commit is contained in:
2025-12-18 13:23:50 +03:00
parent 613c2c80f5
commit 7641846600
55 changed files with 1647 additions and 1399 deletions

View File

@@ -1,6 +1,6 @@
#include "config.hpp"
#include "core/utils.hpp"
#include "core/error.hpp"
#include "core/utils.hpp"
#include <core/palette/color.hpp>
#include <filesystem>
@@ -25,11 +25,12 @@ Result<void> config::initialize(std::unique_ptr<clrsync::core::io::file> file)
m_file = std::move(file);
if (!m_file)
return Err<void>(error_code::config_missing, "Config file is missing");
auto parse_result = m_file->parse();
if (!parse_result)
return Err<void>(error_code::config_invalid, parse_result.error().message, parse_result.error().context);
return Err<void>(error_code::config_invalid, parse_result.error().message,
parse_result.error().context);
return Ok();
}
@@ -68,10 +69,10 @@ void config::copy_file(const std::filesystem::path &src, const std::filesystem::
std::ifstream in(src, std::ios::binary);
std::ofstream out(dst, std::ios::binary);
if (!in || !out)
return;
out << in.rdbuf();
}
@@ -79,7 +80,7 @@ void config::copy_dir(const std::filesystem::path &src, const std::filesystem::p
{
if (!std::filesystem::exists(src))
return;
for (auto const &entry : std::filesystem::recursive_directory_iterator(src))
{
auto rel = std::filesystem::relative(entry.path(), src);
@@ -166,7 +167,7 @@ Result<void> config::set_default_theme(const std::string &theme)
{
if (!m_file)
return Err<void>(error_code::config_missing, "Configuration not initialized");
m_file->set_value("general", "default_theme", theme);
return m_file->save_file();
}
@@ -175,7 +176,7 @@ Result<void> config::set_palettes_path(const std::string &path)
{
if (!m_file)
return Err<void>(error_code::config_missing, "Configuration not initialized");
m_file->set_value("general", "palettes_path", path);
return m_file->save_file();
}
@@ -184,7 +185,7 @@ Result<void> config::set_font(const std::string &font)
{
if (!m_file)
return Err<void>(error_code::config_missing, "Configuration not initialized");
m_file->set_value("general", "font", font);
return m_file->save_file();
}
@@ -192,17 +193,17 @@ Result<void> config::set_font_size(int font_size)
{
if (!m_file)
return Err<void>(error_code::config_missing, "Configuration not initialized");
m_file->set_value("general", "font_size", font_size);
return m_file->save_file();
}
Result<void> config::update_template(const std::string &key,
const clrsync::core::theme_template &theme_template)
const clrsync::core::theme_template &theme_template)
{
if (!m_file)
return Err<void>(error_code::config_missing, "Configuration not initialized");
m_themes[key] = theme_template;
m_file->set_value("templates." + key, "input_path", theme_template.template_path());
m_file->set_value("templates." + key, "output_path", theme_template.output_path());
@@ -215,25 +216,29 @@ Result<void> config::remove_template(const std::string &key)
{
if (!m_file)
return Err<void>(error_code::config_missing, "Configuration not initialized");
auto it = m_themes.find(key);
if (it == m_themes.end())
return Err<void>(error_code::template_not_found, "Template not found", key);
std::filesystem::path template_file = it->second.template_path();
if (std::filesystem::exists(template_file))
{
try {
try
{
std::filesystem::remove(template_file);
} catch (const std::exception& e) {
return Err<void>(error_code::file_write_failed, "Failed to delete template file", e.what());
}
catch (const std::exception &e)
{
return Err<void>(error_code::file_write_failed, "Failed to delete template file",
e.what());
}
}
m_themes.erase(it);
m_file->remove_section("templates." + key);
return m_file->save_file();
}
@@ -264,14 +269,16 @@ const std::unordered_map<std::string, clrsync::core::theme_template> config::tem
return m_themes;
}
Result<const clrsync::core::theme_template*> config::template_by_name(const std::string &name) const
Result<const clrsync::core::theme_template *> config::template_by_name(
const std::string &name) const
{
auto it = m_themes.find(name);
if (it != m_themes.end())
{
return Ok(&it->second);
}
return Err<const clrsync::core::theme_template*>(error_code::template_not_found, "Template not found", name);
return Err<const clrsync::core::theme_template *>(error_code::template_not_found,
"Template not found", name);
}
} // namespace clrsync::core

View File

@@ -1,9 +1,9 @@
#ifndef CLRSYNC_CORE_CONFIG_HPP
#define CLRSYNC_CORE_CONFIG_HPP
#include <core/error.hpp>
#include <core/io/file.hpp>
#include <core/theme/theme_template.hpp>
#include <core/error.hpp>
#include <filesystem>
#include <memory>
#include <string>
@@ -22,17 +22,16 @@ class config
const std::string &palettes_path();
const std::string default_theme() const;
const std::unordered_map<std::string, clrsync::core::theme_template> templates();
Result<const clrsync::core::theme_template*> template_by_name(const std::string &name) const;
Result<const clrsync::core::theme_template *> template_by_name(const std::string &name) const;
std::filesystem::path get_user_config_dir();
Result<void> set_default_theme(const std::string &theme);
Result<void> set_palettes_path(const std::string &path);
Result<void> set_font(const std::string &font);
Result<void> set_font_size(int font_size);
Result<void> update_template(const std::string &key,
const clrsync::core::theme_template &theme_template);
const clrsync::core::theme_template &theme_template);
Result<void> remove_template(const std::string &key);
static std::filesystem::path get_data_dir();
@@ -44,8 +43,8 @@ class config
std::string m_palettes_dir{};
std::unique_ptr<io::file> m_file;
std::unordered_map<std::string, theme_template> m_themes{};
static void copy_file(const std::filesystem::path& src, const std::filesystem::path& dst);
static void copy_dir(const std::filesystem::path& src, const std::filesystem::path& dst);
static void copy_file(const std::filesystem::path &src, const std::filesystem::path &dst);
static void copy_dir(const std::filesystem::path &src, const std::filesystem::path &dst);
void copy_default_configs();
};
} // namespace clrsync::core