GpgFrontend Project
A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.
GlobalSettingStation.h
1 
29 #ifndef GPGFRONTEND_GLOBALSETTINGSTATION_H
30 #define GPGFRONTEND_GLOBALSETTINGSTATION_H
31 
32 #include "GpgFrontendBuildInstallInfo.h"
33 #include "core/GpgFrontendCore.h"
34 #include "core/GpgFunctionObject.h"
35 
36 namespace GpgFrontend {
37 
42 class GPGFRONTEND_CORE_EXPORT GlobalSettingStation
43  : public SingletonFunctionObject<GlobalSettingStation> {
44  public:
49  explicit GlobalSettingStation(
50  int channel = SingletonFunctionObject::GetDefaultChannel()) noexcept;
51 
56  ~GlobalSettingStation() noexcept override;
57 
63  libconfig::Setting &GetUISettings() noexcept { return ui_cfg_.getRoot(); }
64 
70  [[nodiscard]] std::filesystem::path GetAppDir() const { return app_path_; }
71 
72  [[nodiscard]] std::filesystem::path GetAppDataPath() const {
73  return app_data_path_;
74  }
75 
81  [[nodiscard]] std::filesystem::path GetLogDir() const {
82  return app_log_path_;
83  }
84 
90  [[nodiscard]] std::filesystem::path GetStandaloneDatabaseDir() const {
91  auto db_path = app_configure_path_ / "db";
92  if (!std::filesystem::exists(db_path)) {
93  std::filesystem::create_directory(db_path);
94  }
95  return db_path;
96  }
97 
98  [[nodiscard]] std::filesystem::path GetAppConfigPath() const {
99  return app_configure_path_;
100  }
101 
107  [[nodiscard]] std::filesystem::path GetStandaloneGpgBinDir() const {
108  return app_resource_path_ / "gpg1.4" / "gpg";
109  }
110 
116  [[nodiscard]] std::filesystem::path GetLocaleDir() const {
117  return app_locale_path_;
118  }
119 
125  [[nodiscard]] std::filesystem::path GetResourceDir() const {
126  return app_resource_path_;
127  }
128 
134  [[nodiscard]] std::filesystem::path GetCertsDir() const {
135  return app_resource_path_ / "certs";
136  }
137 
142  void SyncSettings() noexcept;
143 
144  private:
145  std::filesystem::path app_path_ =
146  QCoreApplication::applicationDirPath().toStdString();
147  std::filesystem::path app_data_path_ =
148  QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
149  .toStdString();
150  std::filesystem::path app_log_path_ =
151  app_data_path_ / "logs";
152  std::filesystem::path app_data_objs_path_ =
153  app_data_path_ / "objs";
154 
155 #ifdef LINUX_INSTALL_BUILD
156  std::filesystem::path app_resource_path_ =
157  std::filesystem::path(APP_LOCALSTATE_PATH) /
158  "gpgfrontend";
159 #else
160  std::filesystem::path app_resource_path_ =
161  RESOURCE_DIR_BOOST_PATH(app_path_);
162 #endif
163 
164 #ifdef LINUX_INSTALL_BUILD
165  std::filesystem::path app_locale_path_ =
166  std::string(APP_LOCALE_PATH);
167 #else
168  std::filesystem::path app_locale_path_ =
169  app_resource_path_ / "locales";
170 #endif
171 
172  std::filesystem::path app_configure_path_ =
173  QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)
174  .toStdString();
175  std::filesystem::path ui_config_dir_path_ =
176  app_configure_path_ /
177  "UserInterface";
178  std::filesystem::path ui_config_path_ =
179  ui_config_dir_path_ / "ui.cfg";
180 
181  libconfig::Config ui_cfg_;
182 
187  void init_app_secure_key();
188 };
189 } // namespace GpgFrontend
190 
191 #endif // GPGFRONTEND_GLOBALSETTINGSTATION_H
GpgFrontend::SingletonFunctionObject< GlobalSettingStation >
GpgFrontend::GlobalSettingStation::SyncSettings
void SyncSettings() noexcept
sync the settings to the file
Definition: GlobalSettingStation.cpp:33
GpgFrontend
Definition: CoreCommonUtil.cpp:29
GpgFrontend::GlobalSettingStation::app_log_path_
std::filesystem::path app_log_path_
Program Data Location.
Definition: GlobalSettingStation.h:150
GpgFrontend::GlobalSettingStation::GetUISettings
libconfig::Setting & GetUISettings() noexcept
Definition: GlobalSettingStation.h:63
GpgFrontend::GlobalSettingStation::ui_config_path_
std::filesystem::path ui_config_path_
UI Configure File Location.
Definition: GlobalSettingStation.h:178
GpgFrontend::GlobalSettingStation::GetCertsDir
std::filesystem::path GetCertsDir() const
Get the Certs Dir object.
Definition: GlobalSettingStation.h:134
GpgFrontend::GlobalSettingStation::GetLocaleDir
std::filesystem::path GetLocaleDir() const
Get the Locale Dir object.
Definition: GlobalSettingStation.h:116
GpgFrontend::GlobalSettingStation::GetResourceDir
std::filesystem::path GetResourceDir() const
Get the Resource Dir object.
Definition: GlobalSettingStation.h:125
GpgFrontend::GlobalSettingStation::GetStandaloneDatabaseDir
std::filesystem::path GetStandaloneDatabaseDir() const
Get the Standalone Database Dir object.
Definition: GlobalSettingStation.h:90
GpgFrontend::GlobalSettingStation::app_data_path_
std::filesystem::path app_data_path_
Program Data Location.
Definition: GlobalSettingStation.h:147
GpgFrontend::GlobalSettingStation::ui_config_dir_path_
std::filesystem::path ui_config_dir_path_
Configure File Directory Location.
Definition: GlobalSettingStation.h:175
GpgFrontend::GlobalSettingStation::app_path_
std::filesystem::path app_path_
Program Location.
Definition: GlobalSettingStation.h:145
GpgFrontend::GlobalSettingStation::app_locale_path_
std::filesystem::path app_locale_path_
Program Data Location.
Definition: GlobalSettingStation.h:168
GpgFrontend::GlobalSettingStation
Definition: GlobalSettingStation.h:42
GpgFrontend::GlobalSettingStation::~GlobalSettingStation
~GlobalSettingStation() noexcept override
Destroy the Global Setting Station object.
GpgFrontend::GlobalSettingStation::GlobalSettingStation
GlobalSettingStation(int channel=SingletonFunctionObject::GetDefaultChannel()) noexcept
Construct a new Global Setting Station object.
Definition: GlobalSettingStation.cpp:46
GpgFrontend::SingletonFunctionObject::GetDefaultChannel
static int GetDefaultChannel()
Get the Default Channel object.
Definition: GpgFunctionObject.h:232
GpgFrontend::GlobalSettingStation::app_configure_path_
std::filesystem::path app_configure_path_
Program Configure Location.
Definition: GlobalSettingStation.h:172
GpgFrontend::GlobalSettingStation::GetStandaloneGpgBinDir
std::filesystem::path GetStandaloneGpgBinDir() const
Get the Standalone Gpg Bin Dir object.
Definition: GlobalSettingStation.h:107
GpgFrontend::GlobalSettingStation::GetLogDir
std::filesystem::path GetLogDir() const
Get the Log Dir object.
Definition: GlobalSettingStation.h:81
GpgFrontend::GlobalSettingStation::ui_cfg_
libconfig::Config ui_cfg_
UI Configure File.
Definition: GlobalSettingStation.h:181
GpgFrontend::GlobalSettingStation::GetAppDir
std::filesystem::path GetAppDir() const
Get the App Dir object.
Definition: GlobalSettingStation.h:70