Skip to content

Commit 8719f1f

Browse files
feat: migrate early ini to early json
1 parent 840f3d5 commit 8719f1f

9 files changed

Lines changed: 114 additions & 88 deletions

File tree

cmake/generate_desktop_settings.cmake

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# ============================================================
44
# This module generates:
55
# 1. desktop_settings.h - compile-time header with default paths
6-
# 2. settings/early.ini - pre-configured settings for overlay
6+
# 2. settings/early.json - pre-configured settings for overlay
77
#
88
# Output directories:
99
# ${CMAKE_BINARY_DIR}/autogen/desktop_settings/ (header)
10-
# ${CMAKE_BINARY_DIR}/bin/settings/ (early.ini)
10+
# ${CMAKE_BINARY_DIR}/bin/settings/ (early.json)
1111
#
1212
# Cross-compilation:
1313
# Set -DCFDESKTOP_DEFAULT_ROOT=<path> to override the default
@@ -42,7 +42,9 @@ function(cf_generate_desktop_settings)
4242
else()
4343
# Native build: use host environment variables
4444
if(WIN32)
45-
set(CFDESKTOP_DEFAULT_ROOT "$ENV{USERPROFILE}/cfdesktop/")
45+
# Normalize to forward slashes to avoid Qt6 QSettings treating
46+
# backslashes as escape sequences in the INI file
47+
file(TO_CMAKE_PATH "$ENV{USERPROFILE}/cfdesktop/" CFDESKTOP_DEFAULT_ROOT)
4648
else()
4749
set(CFDESKTOP_DEFAULT_ROOT "$ENV{HOME}/desktop")
4850
endif()
@@ -67,23 +69,23 @@ function(cf_generate_desktop_settings)
6769
log_info("DesktopSettings" "Desktop root default: ${CFDESKTOP_DEFAULT_ROOT}")
6870

6971
# ----------------------------------------------------------
70-
# 2. Generate settings/early.ini (pre-configured for overlay)
72+
# 2. Generate settings/early.json (pre-configured for overlay)
7173
# ----------------------------------------------------------
72-
set(EARLY_INI_OUTPUT_DIR ${CMAKE_BINARY_DIR}/bin/settings)
73-
file(MAKE_DIRECTORY ${EARLY_INI_OUTPUT_DIR})
74+
set(EARLY_JSON_OUTPUT_DIR ${CMAKE_BINARY_DIR}/bin/settings)
75+
file(MAKE_DIRECTORY ${EARLY_JSON_OUTPUT_DIR})
7476

7577
# Only generate if not already present (preserve developer customizations)
76-
set(EARLY_INI_PATH ${EARLY_INI_OUTPUT_DIR}/early.ini)
78+
set(EARLY_JSON_PATH ${EARLY_JSON_OUTPUT_DIR}/early.json)
7779

78-
if(NOT EXISTS "${EARLY_INI_PATH}" OR CFDESKTOP_OVERLAY_FORCE)
80+
if(NOT EXISTS "${EARLY_JSON_PATH}" OR CFDESKTOP_OVERLAY_FORCE)
7981
configure_file(
80-
${CMAKE_SOURCE_DIR}/cmake/meta_info/early_settings.template.ini.in
81-
${EARLY_INI_PATH}
82+
${CMAKE_SOURCE_DIR}/cmake/meta_info/early_settings.template.json.in
83+
${EARLY_JSON_PATH}
8284
@ONLY
8385
)
84-
log_info("DesktopSettings" "Generated settings/early.ini in: ${EARLY_INI_OUTPUT_DIR}")
86+
log_info("DesktopSettings" "Generated settings/early.json in: ${EARLY_JSON_OUTPUT_DIR}")
8587
else()
86-
log_info("DesktopSettings" "settings/early.ini already exists, skipping generation")
88+
log_info("DesktopSettings" "settings/early.json already exists, skipping generation")
8789
endif()
8890

8991
# ----------------------------------------------------------

cmake/meta_info/desktop_settings.template.h.in

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212

1313
namespace cf::desktop::early_stage {
1414
/// @brief Default relative path to the early settings configuration file.
15-
static constexpr const char* EARLY_SETTINGS = "settings/early.ini";
15+
static constexpr const char* EARLY_SETTINGS = "settings/early.json";
1616

17-
/// @brief Template content for generating the early settings INI file.
18-
static constexpr const char* EARLY_SETTINGS_TEMPLATE = R"([logger]
19-
# Dirent Should be relatives at CFDesktop Itself
20-
dirent="logger/"
21-
22-
[desktop]
23-
# Desktop Root Places, that place will be the place where desktop
24-
# Scan and, maybe created the subdirectories
25-
root="@CFDESKTOP_DEFAULT_ROOT@"
17+
/// @brief Template content for generating the early settings JSON file.
18+
static constexpr const char* EARLY_SETTINGS_TEMPLATE = R"({
19+
"logger": {
20+
"dirent": "logger/"
21+
},
22+
"desktop": {
23+
"root": "@CFDESKTOP_DEFAULT_ROOT@"
24+
}
25+
}
2626
)";
2727
} // namespace cf::desktop::early_stage

cmake/meta_info/early_settings.template.ini.in

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"logger": {
3+
"dirent": "logger/"
4+
},
5+
"desktop": {
6+
"root": "@CFDESKTOP_DEFAULT_ROOT@"
7+
}
8+
}
Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,46 @@
11
#include "settings/early_settings.h"
22
#include "file_op.h"
33
#include "log/log_helper.h"
4-
#include <memory>
4+
#include <QFile>
5+
#include <QJsonDocument>
6+
#include <QJsonObject>
57

68
namespace cf::desktop::early_settings {
79

8-
EarlySettings::EarlySettings(const QString& early_config_path)
9-
: early_settings(std::make_unique<QSettings>(early_config_path, QSettings::IniFormat)) {}
10+
EarlySettings::~EarlySettings() {}
11+
12+
EarlySettings::EarlySettings(const QString& early_config_path) : filepath_(early_config_path) {
13+
QFile file(early_config_path);
14+
if (!file.open(QIODevice::ReadOnly)) {
15+
valid_ = false;
16+
return;
17+
}
18+
19+
QByteArray data = file.readAll();
20+
file.close();
21+
22+
QJsonParseError parseError;
23+
QJsonDocument doc = QJsonDocument::fromJson(data, &parseError);
24+
25+
if (parseError.error != QJsonParseError::NoError || !doc.isObject()) {
26+
valid_ = false;
27+
return;
28+
}
29+
30+
early_settings_obj_ = std::make_unique<QJsonObject>(doc.object());
31+
valid_ = true;
32+
}
1033

1134
bool EarlySettings::valid() const {
12-
if (!early_settings)
13-
return false;
14-
return early_settings->status() == QSettings::NoError;
35+
return valid_;
1536
}
1637

1738
QString EarlySettings::loadFrom() const {
18-
if (!early_settings)
19-
return "invalid settings";
20-
return early_settings->fileName();
39+
return filepath_;
2140
}
2241

2342
QString EarlySettings::get_boot_logger_path() const {
24-
if (!valid()) {
43+
if (!valid() || !early_settings_obj_) {
2544
return {};
2645
}
2746

@@ -30,7 +49,8 @@ QString EarlySettings::get_boot_logger_path() const {
3049
}
3150

3251
const auto log_file_rev = base::filesystem::concat_filepath(
33-
early_settings->value("logger/dirent", "").value<QString>(), logger_helper::log_filename());
52+
(*early_settings_obj_)["logger"].toObject()["dirent"].toString(),
53+
logger_helper::log_filename());
3454
const auto log_file =
3555
base::filesystem::concat_filepath(base::filesystem::app_runtime_dir(), log_file_rev);
3656

@@ -39,20 +59,20 @@ QString EarlySettings::get_boot_logger_path() const {
3959
}
4060

4161
QString EarlySettings::get_desktop_root() const {
42-
if (!valid()) {
62+
if (!valid() || !early_settings_obj_) {
4363
return {};
4464
}
4565

4666
if (!desktop_root.isEmpty()) {
4767
return desktop_root;
4868
}
4969

50-
desktop_root = early_settings->value("desktop/root", "").value<QString>();
70+
desktop_root = (*early_settings_obj_)["desktop"].toObject()["root"].toString();
5171
return desktop_root;
5272
}
5373

54-
std::unique_ptr<QSettings> EarlySettings::unlock_early_settings() {
55-
return std::move(early_settings);
74+
std::unique_ptr<QJsonObject> EarlySettings::unlock_early_settings() {
75+
return std::move(early_settings_obj_);
5676
}
5777

5878
} // namespace cf::desktop::early_settings

desktop/main/early_session/settings/early_settings.h

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,33 @@
33
* @brief Early settings configuration loader and manager.
44
*
55
* Handles loading and accessing early desktop initialization configuration
6-
* from INI files using Qt's QSettings mechanism.
6+
* from JSON files using Qt's JSON parsing.
77
*
88
* @author CFDesktop Team
99
* @date 2026-03-16
10-
* @version 0.13.1
10+
* @version 0.14.0
1111
* @since 0.13.0
1212
* @ingroup early_session
1313
*/
1414
#pragma once
1515

16-
#include <QSettings>
1716
#include <QString>
1817
#include <memory>
1918

19+
class QJsonObject;
20+
2021
namespace cf::desktop::early_settings {
2122
/**
2223
* @brief Manages early desktop configuration settings.
2324
*
24-
* Loads and provides access to early initialization configuration from an
25-
* INI-format configuration file. Uses Qt's QSettings for parsing.
25+
* Loads and provides access to early initialization configuration from a
26+
* JSON-format configuration file.
2627
*
2728
* @note Not thread-safe unless externally synchronized.
2829
* @ingroup early_session
2930
*
3031
* @code
31-
* EarlySettings settings("settings/early.ini");
32+
* EarlySettings settings("settings/early.json");
3233
* if (settings.valid()) {
3334
* QString logPath = settings.get_boot_logger_path();
3435
* }
@@ -39,52 +40,31 @@ class EarlySettings {
3940
/**
4041
* @brief Constructs EarlySettings and loads from the specified config path.
4142
*
42-
* @param[in] early_config_path Path to the early configuration INI file.
43-
* @throws None
44-
* @note None
45-
* @warning None
46-
* @since 0.13.0
47-
* @ingroup early_session
43+
* @param[in] early_config_path Path to the early configuration JSON file.
4844
*/
4945
EarlySettings(const QString& early_config_path);
5046

51-
~EarlySettings() = default;
47+
~EarlySettings();
5248

5349
/**
5450
* @brief Checks if the settings were loaded successfully.
5551
*
5652
* @return True if settings are valid and loaded without error, false otherwise.
57-
* @throws None
58-
* @note None
59-
* @warning None
60-
* @since 0.13.0
61-
* @ingroup early_session
6253
*/
6354
bool valid() const;
6455

6556
/**
6657
* @brief Gets the file path from which settings were loaded.
6758
*
6859
* @return Absolute path to the configuration file.
69-
* @throws None
70-
* @note None
71-
* @warning None
72-
* @since 0.13.0
73-
* @ingroup early_session
7460
*/
7561
QString loadFrom() const;
7662

7763
/**
7864
* @brief Gets the boot logger directory path from settings.
7965
*
80-
* Reads the logger directory configuration from the early settings file.
81-
*
8266
* @return Path to the boot logger directory.
83-
* @throws None
8467
* @note The result is cached after the first call.
85-
* @warning None
86-
* @since 0.13.0
87-
* @ingroup early_session
8868
*/
8969
QString get_boot_logger_path() const;
9070

@@ -96,20 +76,27 @@ class EarlySettings {
9676
QString get_desktop_root() const;
9777

9878
/**
99-
* @brief Unlock the Early Settings, using in release the sessions
79+
* @brief Unlock the Early Settings, used in releasing the sessions.
10080
*
101-
* @return std::unique_ptr<QSettings>
81+
* @return std::unique_ptr<QJsonObject> containing the early settings data.
82+
* Returns nullptr if settings are invalid.
10283
*/
103-
std::unique_ptr<QSettings> unlock_early_settings();
84+
std::unique_ptr<QJsonObject> unlock_early_settings();
10485

10586
private:
106-
/// @brief Cached path to the log file for the current session. Ownership: owner.
87+
/// @brief Cached path to the log file for the current session.
10788
mutable QString this_session_logfile_path{};
10889

109-
/// @brief Cached Desktop Root; only changes when the desktop path is switched
90+
/// @brief Cached Desktop Root; only changes when the desktop path is switched.
11091
mutable QString desktop_root{};
11192

112-
/// @brief Qt settings object for reading the INI configuration. Ownership: owner.
113-
std::unique_ptr<QSettings> early_settings;
93+
/// @brief Parsed JSON object containing the configuration data. Ownership: owner.
94+
std::unique_ptr<QJsonObject> early_settings_obj_;
95+
96+
/// @brief Whether the JSON file was loaded successfully.
97+
bool valid_ = false;
98+
99+
/// @brief Path to the configuration file.
100+
QString filepath_{};
114101
};
115102
} // namespace cf::desktop::early_settings

desktop/main/init/init_settings.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
#include "init_settings.h"
22
#include "early_handle/early_handle.h"
3+
#include <QJsonObject>
34

45
namespace cf::desktop::init_session {
56

7+
InitInfoHandle::~InitInfoHandle() {
8+
delete early_settings_;
9+
early_settings_ = nullptr;
10+
}
11+
612
void InitInfoHandle::passedEarlyBootInfo(early_stage::EarlyHandle& early_handle) {
713
auto earlies = early_handle.unlockEarlySettings();
8-
early_settings_ = earlies->unlock_early_settings();
14+
early_settings_ = earlies->unlock_early_settings().release();
915
/* Releases the Early settings... */
1016
}
1117

@@ -20,7 +26,10 @@ QWidget* InitInfoHandle::unlockBootWidget() {
2026
}
2127

2228
QString InitInfoHandle::root_position() const {
23-
return early_settings_->value("desktop/root").value<QString>();
29+
if (!early_settings_) {
30+
return {};
31+
}
32+
return (*early_settings_)["desktop"].toObject()["root"].toString();
2433
}
2534

26-
} // namespace cf::desktop::init_session
35+
} // namespace cf::desktop::init_session

desktop/main/init/init_settings.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
*/
1515
#pragma once
1616
#include "base/singleton/simple_singleton.hpp"
17-
#include <QSettings>
17+
#include <QString>
1818
#include <memory>
1919

20+
class QJsonObject;
21+
2022
class QWidget;
2123
namespace cf::desktop::early_stage {
2224
class EarlyHandle;
@@ -41,6 +43,7 @@ namespace cf::desktop::init_session {
4143
*/
4244
class InitInfoHandle : public SimpleSingleton<InitInfoHandle> {
4345
public:
46+
~InitInfoHandle();
4447
/**
4548
* @brief Transfers early boot information from the early stage.
4649
*
@@ -100,8 +103,8 @@ class InitInfoHandle : public SimpleSingleton<InitInfoHandle> {
100103
QWidget* boot_widget_{nullptr};
101104
/// @brief Path to load early settings from. Ownership: owner.
102105
QString load_early_settings_from;
103-
/// @brief Qt settings object for early configuration. Ownership: owner.
104-
std::unique_ptr<QSettings> early_settings_;
106+
/// @brief JSON object containing early configuration. Ownership: owner.
107+
QJsonObject* early_settings_ = nullptr;
105108
};
106109

107110
} // namespace cf::desktop::init_session

0 commit comments

Comments
 (0)