@@ -20,6 +20,7 @@ using std::cout;
2020#endif
2121
2222#include " ../front_end_utils/include/error_types.hxx"
23+ #include " ../front_end_utils/include/utils.hxx"
2324
2425using Lazyboard::front_end::MainWindowPreload;
2526using Self = MainWindowPreload;
@@ -28,74 +29,67 @@ using std::make_unique;
2829using std::string;
2930using std::stringstream;
3031using namespace Lazyboard ::ffi;
31- using Lazyboard::front_end_utils::error_types_map;
32+ using Lazyboard::front_end_utils::error_dialog_show;
33+ using Lazyboard::front_end_utils::ErrorTypes;
3234
3335void Self::on_gen_default_cfg_error (WriteConfigStatus status,
3436 QMainWindow *main_window) {
3537 switch (status) {
38+ using E = ErrorTypes;
39+
3640 case WriteConfigStatus::OK:
3741 break ;
3842
3943 case WriteConfigStatus::CREATE_DIR_FAILED:
40- QMessageBox::critical (main_window, " Error" ,
41- " Could not create config directory" );
44+ error_dialog_show (main_window, E::CREATE_DIR_FAILED);
4245
4346 break ;
4447
4548 case WriteConfigStatus::GET_CONFIG_DIR_FAILED:
46- QMessageBox::critical (main_window, " Error" ,
47- " Could not get application local data" );
49+ error_dialog_show (main_window, E::GET_CONFIG_DIR_FAILED);
4850 break ;
4951
5052 case WriteConfigStatus::CREATE_FILE_FAILED:
51- QMessageBox::critical (main_window, " Error" ,
52- " Could not create configuration file" );
53+ error_dialog_show (main_window, E::CREATE_FILE_FAILED);
5354 break ;
5455
5556 case WriteConfigStatus::WRITE_FILE_FAILED:
56- QMessageBox::critical (main_window, " Error" ,
57- " Could not write configuration" );
57+ error_dialog_show (main_window, E::WRITE_FILE_FAILED);
5858 break ;
5959
6060 case WriteConfigStatus::TOML_TO_STRING_FAILED:
61- QMessageBox::critical (main_window, " Error" ,
62- " Could not convert TOML data to string" );
61+ error_dialog_show (main_window, E::TOML_TO_STRING_FAILED);
6362 break ;
6463 }
6564}
6665
6766void Self::on_read_exists_cfg_error (RawReadAppConfigStatus status,
6867 QMainWindow *main_window) {
6968 using Status = RawReadAppConfigStatus;
69+ using E = ErrorTypes;
7070
7171 switch (status) {
7272 case Status::READ_OK:
7373 break ;
7474
7575 case Status::CONVERT_TO_MUT_FAILED:
76- QMessageBox::critical (main_window, " Error" ,
77- " Could not convert to *mut c_char" );
76+ error_dialog_show (main_window, E::CONVERT_TO_MUT_FAILED);
7877 break ;
7978
8079 case Status::PARSE_TOML_FAILED:
81- QMessageBox::critical (main_window, " Error" ,
82- " Parse TOML configuration failed" );
80+ error_dialog_show (main_window, E::PARSE_TOML_FAILED);
8381 break ;
8482
8583 case Status::READ_FILE_FAILED:
86- QMessageBox::critical (main_window, " Error" ,
87- " Could not read configuration file" );
84+ error_dialog_show (main_window, E::READ_FILE_FAILED);
8885 break ;
8986
9087 case Status::UTF_8_ERROR:
91- QMessageBox::critical (main_window, " Error" ,
92- " UTF-8 error in configuration file" );
88+ error_dialog_show (main_window, E::UTF_8_ERROR);
9389 break ;
9490
9591 case Status::CONVERT_TO_C_STR_FAILED:
96- QMessageBox::critical (
97- main_window, " Error" ,
98- " Could not convert value configuration to C string" );
92+ error_dialog_show (main_window, E::CONVERT_TO_C_STR_FAILED);
9993 break ;
10094 }
10195}
@@ -122,9 +116,8 @@ void Self::create_default_config(QMainWindow *main_window) {
122116
123117 // clang-format off
124118 #if defined(LAZY_DEBUG)
125- cout << " [DEBUG] " << " Config path not found, generate at: " << config_path
126- << " \n " ;
127- #endif
119+ cout << " [DEBUG] " << " Config path not found, generate at: " << config_path << " \n " ;
120+ #endif
128121
129122 return ;
130123 }
@@ -137,8 +130,8 @@ void Self::create_default_config(QMainWindow *main_window) {
137130void Self::read_if_exists_config (QMainWindow *main_window) {
138131 raw_app_config = make_unique<RawAppConfig>();
139132 theme_manager = make_unique<ThemeManager>();
140- auto config_path = this ->application_config ();
141133
134+ auto config_path = this ->application_config ();
142135 auto status = exists_config (config_path.data (), raw_app_config.get ());
143136 this ->on_read_exists_cfg_error (status, main_window);
144137
0 commit comments