1+ #include " include/sqlite_manager.hxx"
2+
3+ #include < qmainwindow.h>
4+
5+ #include < format>
6+ #include < string>
7+
8+ #include " ../ffi/namespace/include/sqlite.hxx"
9+ #include " ../ffi/namespace/include/utils.hxx"
10+ #include " ../front_end_utils/include/utils.hxx"
11+
12+ #if defined(LAZY_DEBUG)
13+ #include < iostream>
14+ using std::cout;
15+ #endif
16+
17+ using Lazyboard::ffi::cache_dir;
18+ using Lazyboard::ffi::free_c_str;
19+ using Lazyboard::ffi::init_clipboard_cache;
20+ using Lazyboard::ffi::new_folder;
21+ using Lazyboard::front_end_db::SQLiteManager;
22+ using Lazyboard::front_end_utils::error_dialog_show;
23+ using Lazyboard::front_end_utils::ErrorTypes;
24+ using Self = SQLiteManager;
25+ using std::format;
26+ using std::string;
27+ using Status = InitDatabaseStatus;
28+
29+ void Self::on_create_clipboard_cache_error (
30+ const InitDataResult& result) noexcept {
31+ using E = ErrorTypes;
32+
33+ switch (result) {
34+ case InitDataResult::OK:
35+ break ;
36+
37+ case InitDataResult::C_STR_CONVERT_FAILED:
38+ error_dialog_show (this ->_main_window , E::CONVERT_TO_C_STR_FAILED);
39+ break ;
40+
41+ case InitDataResult::CREATE_DATABASE_FAILED:
42+ error_dialog_show (this ->_main_window , E::CREATE_DATABASE_ERR);
43+ break ;
44+
45+ case InitDataResult::EXECUTE_SQL_FAILED:
46+ error_dialog_show (this ->_main_window , E::EXECUTE_SQL_ERR);
47+ }
48+ }
49+
50+ void Self::on_create_folder_error (const MkdirResult& result) noexcept {
51+ using E = ErrorTypes;
52+ using Result = MkdirResult;
53+
54+ switch (result) {
55+ case Result::OK:
56+ break ;
57+
58+ case Result::WRAP_RAW_C_FAILED:
59+ error_dialog_show (this ->_main_window , E::WRAP_C_STR_ERR);
60+ break ;
61+
62+ case Result::FAILED:
63+ error_dialog_show (this ->_main_window , E::CREATE_DIR_FAILED);
64+ break ;
65+ }
66+ }
67+
68+ void Self::create_clipboard_cache (QMainWindow* main_window) {
69+ this ->_main_window = main_window;
70+
71+ auto raw_cache_directory = cache_dir ();
72+ string cache_dir_string = format (" {}/Lazyboard" , raw_cache_directory);
73+ auto database_path = format (" {}/clipboard_cache.db" , cache_dir_string);
74+ free_c_str (raw_cache_directory);
75+
76+ const auto create_dir_result = new_folder (cache_dir_string.data ());
77+ on_create_folder_error (create_dir_result);
78+
79+ const auto status = init_clipboard_cache (database_path.data ());
80+ on_create_clipboard_cache_error (status);
81+
82+ // clang-format off
83+ #if defined (LAZY_DEBUG)
84+ cout << " Found cache directory path: " << database_path << " \n " ;
85+ #endif // clang-format on
86+ }
0 commit comments