Skip to content

Commit 5967d01

Browse files
Merge pull request #49 from Reim-developer/dev
Implement theme preload via TOML configuration with Rust backend FFI
2 parents 179c378 + ac1d9e5 commit 5967d01

22 files changed

Lines changed: 483 additions & 310 deletions

.clang-format

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
---
12
Language: Cpp
23
BasedOnStyle: Google
34
IndentWidth: 4
4-
ColumnLimit: 80
5+
ColumnLimit: 80
6+
UseTab: Always
7+
TabWidth: 4
8+
IndentPPDirectives: BeforeHash
9+
PPIndentWidth: 4

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22
"rust-analyzer.linkedProjects": [
33
"src/back_end/Cargo.toml"
44
],
5-
"rust-analyzer.check.command": "clippy"
5+
"rust-analyzer.check.command": "clippy",
6+
"files.associations": {
7+
".clang-format": "yaml",
8+
".clang-tidy": "yaml"
9+
}
610
}

src/ffi/namespace/include/config.hxx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,29 @@
44

55
namespace Lazyboard::ffi {
66

7-
inline char* config_dir() {
8-
char* result = raw_config_dir();
7+
inline char *config_dir() {
8+
char *result = raw_config_dir();
99

10-
return result;
10+
return result;
1111
}
12+
1213
inline WriteConfigStatus write_default_config() {
13-
auto result = raw_write_default_config();
14+
auto result = raw_write_default_config();
15+
16+
return result;
17+
}
18+
19+
inline RawReadAppConfigStatus exists_config(const char *path,
20+
RawAppConfig *config_out) {
21+
auto result = raw_exists_config(path, config_out);
1422

15-
return result;
23+
return result;
1624
}
25+
26+
inline void free_cstr_app_config(RawAppConfig *config_out) {
27+
raw_free_cstr_app_config(config_out);
28+
}
29+
1730
} // namespace Lazyboard::ffi
1831

19-
#endif // CONFIG_HXX
32+
#endif // CONFIG_HXX

src/ffi/namespace/include/utils.hxx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
#include "../../raw/utils.hxx"
44

55
namespace Lazyboard::ffi {
6-
inline OpenBrowserStatus open_browser(const char* url) {
7-
auto result = raw_open_browser(url);
6+
inline OpenBrowserStatus open_browser(const char *url) {
7+
auto result = raw_open_browser(url);
88

9-
return result;
9+
return result;
1010
}
1111

12-
inline CreateFileSystemStatus new_folder(const char* path) {
13-
auto result = raw_new_folder(path);
12+
inline CreateFileSystemStatus new_folder(const char *path) {
13+
auto result = raw_new_folder(path);
1414

15-
return result;
15+
return result;
1616
}
1717

18-
inline bool is_exists_path(char* path) {
19-
auto result = raw_is_path_exists(path);
18+
inline bool is_exists_path(char *path) {
19+
auto result = raw_is_path_exists(path);
2020

21-
return result;
21+
return result;
2222
}
2323

24-
inline void free_c_str(char* c_str) { raw_free_c_str(c_str); }
24+
inline void free_c_str(char *c_str) { raw_free_c_str(c_str); }
2525
} // namespace Lazyboard::ffi
2626

27-
#endif // UTILS_HXX
27+
#endif // UTILS_HXX

src/ffi/raw/config.hxx

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,48 @@ extern "C" {
77

88
#include <cstdint>
99

10+
/* From module `utils::fs_utils` in Rust backend */
1011
enum WriteConfigStatus : uint8_t {
11-
OK,
12-
TOML_TO_STRING_FAILED,
13-
CREATE_DIR_FAILED,
14-
CREATE_FILE_FAILED,
15-
WRITE_FILE_FAILED,
16-
GET_DATA_LOCAL_FAILED,
12+
OK,
13+
TOML_TO_STRING_FAILED,
14+
CREATE_DIR_FAILED,
15+
CREATE_FILE_FAILED,
16+
WRITE_FILE_FAILED,
17+
GET_DATA_LOCAL_FAILED,
1718
};
1819

19-
char* raw_config_dir();
20-
WriteConfigStatus raw_write_default_config();
20+
char *raw_config_dir();
21+
auto raw_write_default_config() -> WriteConfigStatus;
22+
/* End module */
23+
24+
/* From module `raw_config` in Rust backend */
25+
enum RawReadAppConfigStatus : uint8_t {
26+
READ_OK,
27+
READ_FILE_FAILED,
28+
UTF_8_ERROR,
29+
PARSE_TOML_FAILED,
30+
CONVERT_TO_MUT_FAILED,
31+
};
32+
33+
typedef struct {
34+
bool hide_when_closed;
35+
bool notification;
36+
} RawAppSettings;
37+
38+
typedef struct {
39+
char *background_color;
40+
char *foreground_color;
41+
} RawAppGuiSettings;
42+
43+
typedef struct {
44+
RawAppSettings raw_app_settings;
45+
RawAppGuiSettings raw_app_gui_settings;
46+
} RawAppConfig;
47+
48+
RawReadAppConfigStatus raw_exists_config(const char *path,
49+
RawAppConfig *config_out);
50+
void raw_free_cstr_app_config(RawAppConfig *config);
51+
/* End module */
2152

2253
#ifdef __cplusplus
2354
}

src/ffi/raw/utils.hxx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ extern "C" {
99
using std::uint8_t;
1010

1111
enum class OpenBrowserStatus : uint8_t {
12-
OK,
13-
WRAP_RAW_C_FAILED,
14-
URL_IS_EMPTY,
15-
OPEN_BROWSER_FAILED,
12+
OK,
13+
WRAP_RAW_C_FAILED,
14+
URL_IS_EMPTY,
15+
OPEN_BROWSER_FAILED,
1616
};
1717

1818
enum class CreateFileSystemStatus : uint8_t {
19-
OK,
20-
WRAP_RAW_C_FAILED,
21-
FAILED,
19+
OK,
20+
WRAP_RAW_C_FAILED,
21+
FAILED,
2222
};
2323

24-
OpenBrowserStatus raw_open_browser(const char* url);
25-
CreateFileSystemStatus raw_new_folder(const char* path);
26-
bool raw_is_path_exists(const char* path);
27-
void raw_free_c_str(char* c_str);
24+
OpenBrowserStatus raw_open_browser(const char *url);
25+
CreateFileSystemStatus raw_new_folder(const char *path);
26+
bool raw_is_path_exists(const char *path);
27+
void raw_free_c_str(char *c_str);
2828

2929
#ifdef __cplusplus
3030
}
3131
#endif
32-
#endif // UTILS_RAW_HXX
32+
#endif // UTILS_RAW_HXX

src/front_end/about_widget.cxx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ using Self = AboutWidget;
1717
AboutWidget::AboutWidget() { show_about = make_unique<QPushButton>(); }
1818

1919
void Self::setup_event() {
20-
const auto function = [this]() {
21-
if (!about_window) {
22-
about_window = make_unique<AboutWindow>();
23-
}
20+
const auto function = [this]() {
21+
if (!about_window) {
22+
about_window = make_unique<AboutWindow>();
23+
}
2424

25-
about_window->show_window();
26-
};
25+
about_window->show_window();
26+
};
2727

28-
QObject::connect(show_about.get(), &QPushButton::clicked, function);
28+
QObject::connect(show_about.get(), &QPushButton::clicked, function);
2929
}
3030

31-
void Self::setup_widget(QGridLayout* grid_layout) {
32-
show_about->setText("About");
33-
this->setup_event();
34-
grid_layout->addWidget(show_about.get(), 1, 1);
31+
void Self::setup_widget(QGridLayout *grid_layout) {
32+
show_about->setText("About");
33+
this->setup_event();
34+
grid_layout->addWidget(show_about.get(), 1, 1);
3535
}

src/front_end/about_window.cxx

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,72 +16,72 @@ using std::make_unique;
1616
using Self = AboutWindow;
1717

1818
AboutWindow::AboutWindow() {
19-
about_window = make_unique<QDialog>();
20-
grid_layout = make_unique<QGridLayout>();
21-
github_button = make_unique<QPushButton>();
22-
github_issue_button = make_unique<QPushButton>();
23-
github_pull_button = make_unique<QPushButton>();
19+
about_window = make_unique<QDialog>();
20+
grid_layout = make_unique<QGridLayout>();
21+
github_button = make_unique<QPushButton>();
22+
github_issue_button = make_unique<QPushButton>();
23+
github_pull_button = make_unique<QPushButton>();
2424
}
2525

2626
void Self::is_open_browser_ok(OpenBrowserStatus status) {
27-
switch (status) {
28-
case OpenBrowserStatus::OK:
29-
break;
30-
31-
case OpenBrowserStatus::OPEN_BROWSER_FAILED:
32-
QMessageBox::critical(about_window.get(), "Error",
33-
"Could not open your browser");
34-
break;
35-
36-
case OpenBrowserStatus::WRAP_RAW_C_FAILED:
37-
QMessageBox::critical(about_window.get(), "Error",
38-
"Could not wrap C raw to safety string");
39-
40-
break;
41-
case OpenBrowserStatus::URL_IS_EMPTY:
42-
QMessageBox::critical(about_window.get(), "Error", "Url is empty");
43-
break;
44-
}
27+
switch (status) {
28+
case OpenBrowserStatus::OK:
29+
break;
30+
31+
case OpenBrowserStatus::OPEN_BROWSER_FAILED:
32+
QMessageBox::critical(about_window.get(), "Error",
33+
"Could not open your browser");
34+
break;
35+
36+
case OpenBrowserStatus::WRAP_RAW_C_FAILED:
37+
QMessageBox::critical(about_window.get(), "Error",
38+
"Could not wrap C raw to safety string");
39+
40+
break;
41+
case OpenBrowserStatus::URL_IS_EMPTY:
42+
QMessageBox::critical(about_window.get(), "Error", "Url is empty");
43+
break;
44+
}
4545
}
4646

47-
void Self::open_browser_when_clicked(QPushButton* button, const char* url) {
48-
const auto open_browser = [this, url] {
49-
auto status = Lazyboard::ffi::open_browser(url);
50-
is_open_browser_ok(status);
51-
};
47+
void Self::open_browser_when_clicked(QPushButton *button, const char *url) {
48+
const auto open_browser = [this, url] {
49+
auto status = Lazyboard::ffi::open_browser(url);
50+
is_open_browser_ok(status);
51+
};
5252

53-
QObject::connect(button, &QPushButton::clicked, open_browser);
53+
QObject::connect(button, &QPushButton::clicked, open_browser);
5454
}
5555

5656
void Self::setup_buttons() {
57-
github_button->setText("GitHub | Source Code");
58-
github_button->setToolTip("Get Lazyboard source code");
57+
github_button->setText("GitHub | Source Code");
58+
github_button->setToolTip("Get Lazyboard source code");
5959

60-
github_issue_button->setText("Issue | Bug Report");
61-
github_issue_button->setToolTip("Report issue/bug");
60+
github_issue_button->setText("Issue | Bug Report");
61+
github_issue_button->setToolTip("Report issue/bug");
6262

63-
github_pull_button->setText("Pull Request | Contribute");
64-
github_pull_button->setToolTip("Contribute");
63+
github_pull_button->setText("Pull Request | Contribute");
64+
github_pull_button->setToolTip("Contribute");
6565

66-
this->open_browser_when_clicked(github_button.get(), GITHUB_URL);
67-
this->open_browser_when_clicked(github_issue_button.get(),
68-
GITHUB_ISSUE_URL);
69-
this->open_browser_when_clicked(github_pull_button.get(), GITHUB_PULL_URL);
66+
this->open_browser_when_clicked(github_button.get(), GITHUB_URL);
67+
this->open_browser_when_clicked(github_issue_button.get(),
68+
GITHUB_ISSUE_URL);
69+
this->open_browser_when_clicked(github_pull_button.get(), GITHUB_PULL_URL);
7070

71-
grid_layout->addWidget(github_button.get(), 0, 0);
72-
grid_layout->addWidget(github_issue_button.get(), 0, 1);
73-
grid_layout->addWidget(github_pull_button.get(), 1, 0);
71+
grid_layout->addWidget(github_button.get(), 0, 0);
72+
grid_layout->addWidget(github_issue_button.get(), 0, 1);
73+
grid_layout->addWidget(github_pull_button.get(), 1, 0);
7474
}
7575

7676
void Self::setup_front_end() {
77-
about_window->setLayout(this->grid_layout.get());
78-
this->setup_buttons();
77+
about_window->setLayout(this->grid_layout.get());
78+
this->setup_buttons();
7979
}
8080

8181
void Self::show_window() {
82-
about_window->setMinimumSize(MIN_WIDTH, MIN_HEIGHT);
83-
about_window->setWindowTitle("Lazyboard About");
82+
about_window->setMinimumSize(MIN_WIDTH, MIN_HEIGHT);
83+
about_window->setWindowTitle("Lazyboard About");
8484

85-
this->setup_front_end();
86-
about_window->exec();
85+
this->setup_front_end();
86+
about_window->exec();
8787
}

src/front_end/include/about_widget.hxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ using std::unique_ptr;
1313
namespace Lazyboard::front_end {
1414
class AboutWidget {
1515
public:
16-
AboutWidget();
16+
AboutWidget();
1717

1818
private:
19-
unique_ptr<QPushButton> show_about;
20-
unique_ptr<AboutWindow> about_window;
19+
unique_ptr<QPushButton> show_about;
20+
unique_ptr<AboutWindow> about_window;
2121

2222
private:
23-
void setup_event();
23+
void setup_event();
2424

2525
public:
26-
void setup_widget(QGridLayout* layout);
26+
void setup_widget(QGridLayout *layout);
2727
};
2828

2929
} // namespace Lazyboard::front_end
3030

31-
#endif // ABOUT_WIDGET_HXX
31+
#endif // ABOUT_WIDGET_HXX

0 commit comments

Comments
 (0)