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;
64 
70  template <typename T>
71  T LookupSettings(std::string path, T default_value) noexcept {
72  T value = default_value;
73  try {
74  value = static_cast<T>(GetUISettings().lookup(path));
75  } catch (...) {
76  SPDLOG_WARN("setting not found: {}", path);
77  }
78  return value;
79  }
80 
86  [[nodiscard]] std::filesystem::path GetAppDir() const { return app_path_; }
87 
88  [[nodiscard]] std::filesystem::path GetAppDataPath() const {
89  return app_data_path_;
90  }
91 
97  [[nodiscard]] std::filesystem::path GetLogDir() const {
98  return app_log_path_;
99  }
100 
106  [[nodiscard]] std::filesystem::path GetStandaloneDatabaseDir() const {
107  auto db_path = app_configure_path_ / "db";
108  if (!std::filesystem::exists(db_path)) {
109  std::filesystem::create_directory(db_path);
110  }
111  return db_path;
112  }
113 
114  [[nodiscard]] std::filesystem::path GetAppConfigPath() const {
115  return app_configure_path_;
116  }
117 
123  [[nodiscard]] std::filesystem::path GetStandaloneGpgBinDir() const {
124  return app_resource_path_ / "gpg1.4" / "gpg";
125  }
126 
132  [[nodiscard]] std::filesystem::path GetLocaleDir() const {
133  return app_locale_path_;
134  }
135 
141  [[nodiscard]] std::filesystem::path GetResourceDir() const {
142  return app_resource_path_;
143  }
144 
150  [[nodiscard]] std::filesystem::path GetCertsDir() const {
151  return app_resource_path_ / "certs";
152  }
153 
158  void SyncSettings() noexcept;
159 
160  private:
161  std::filesystem::path app_path_ = QCoreApplication::applicationDirPath()
162  .toStdString();
163  std::filesystem::path app_data_path_ =
164  QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
165  .toStdString();
166  std::filesystem::path app_log_path_ =
167  app_data_path_ / "logs";
168  std::filesystem::path app_data_objs_path_ =
169  app_data_path_ / "objs";
170 
171 #ifdef LINUX_INSTALL_BUILD
172  std::filesystem::path app_resource_path_ =
173  std::filesystem::path(APP_LOCALSTATE_PATH) /
174  "gpgfrontend";
175 #else
176  std::filesystem::path app_resource_path_ =
177  RESOURCE_DIR_BOOST_PATH(app_path_);
178 #endif
179 
180 #ifdef LINUX_INSTALL_BUILD
181  std::filesystem::path app_locale_path_ =
182  std::string(APP_LOCALE_PATH);
183 #else
184  std::filesystem::path app_locale_path_ =
185  app_resource_path_ / "locales";
186 #endif
187 
188  std::filesystem::path app_configure_path_ =
189  QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)
190  .toStdString();
191  std::filesystem::path ui_config_dir_path_ =
192  app_configure_path_ / "conf";
193  std::filesystem::path ui_config_path_ =
194  ui_config_dir_path_ / "main.cfg";
195 
196  libconfig::Config ui_cfg_;
197 
202  void init_app_secure_key();
203 };
204 } // namespace GpgFrontend
205 
206 #endif // GPGFRONTEND_GLOBALSETTINGSTATION_H
Definition: GlobalSettingStation.h:43
std::filesystem::path GetLocaleDir() const
Get the Locale Dir object.
Definition: GlobalSettingStation.h:132
libconfig::Config ui_cfg_
UI Configure File.
Definition: GlobalSettingStation.h:196
std::filesystem::path GetCertsDir() const
Get the Certs Dir object.
Definition: GlobalSettingStation.h:150
std::filesystem::path GetLogDir() const
Get the Log Dir object.
Definition: GlobalSettingStation.h:97
std::filesystem::path GetStandaloneGpgBinDir() const
Get the Standalone Gpg Bin Dir object.
Definition: GlobalSettingStation.h:123
std::filesystem::path GetAppDir() const
Get the App Dir object.
Definition: GlobalSettingStation.h:86
std::filesystem::path GetStandaloneDatabaseDir() const
Get the Standalone Database Dir object.
Definition: GlobalSettingStation.h:106
~GlobalSettingStation() noexcept override
Destroy the Global Setting Station object.
std::filesystem::path GetResourceDir() const
Get the Resource Dir object.
Definition: GlobalSettingStation.h:141
Definition: GpgFunctionObject.h:150
static int GetDefaultChannel()
Get the Default Channel object.
Definition: GpgFunctionObject.h:251
Definition: CoreCommonUtil.cpp:31