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 <openssl/x509.h>
33 
34 #include <boost/filesystem/operations.hpp>
35 #include <boost/filesystem/path.hpp>
36 
37 #include "GpgFrontendBuildInstallInfo.h"
38 #include "core/GpgFrontendCore.h"
39 #include "core/GpgFunctionObject.h"
40 
41 namespace GpgFrontend {
42 
47 class GPGFRONTEND_CORE_EXPORT GlobalSettingStation
48  : public SingletonFunctionObject<GlobalSettingStation> {
49  public:
54  explicit GlobalSettingStation(
55  int channel = SingletonFunctionObject::GetDefaultChannel()) noexcept;
56 
61  ~GlobalSettingStation() noexcept override;
62 
68  libconfig::Setting &GetUISettings() noexcept { return ui_cfg_.getRoot(); }
69 
75  [[nodiscard]] std::filesystem::path GetAppDir() const { return app_path_; }
76 
77  [[nodiscard]] std::filesystem::path GetAppDataPath() const {
78  return app_data_path_;
79  }
80 
86  [[nodiscard]] std::filesystem::path GetLogDir() const {
87  return app_log_path_;
88  }
89 
95  [[nodiscard]] std::filesystem::path GetStandaloneDatabaseDir() const {
96  auto db_path = app_configure_path_ / "db";
97  if (!std::filesystem::exists(db_path)) {
98  std::filesystem::create_directory(db_path);
99  }
100  return db_path;
101  }
102 
103  [[nodiscard]] std::filesystem::path GetAppConfigPath() const {
104  return app_configure_path_;
105  }
106 
112  [[nodiscard]] std::filesystem::path GetStandaloneGpgBinDir() const {
113  return app_resource_path_ / "gpg1.4" / "gpg";
114  }
115 
121  [[nodiscard]] std::filesystem::path GetLocaleDir() const {
122  return app_locale_path_;
123  }
124 
130  [[nodiscard]] std::filesystem::path GetResourceDir() const {
131  return app_resource_path_;
132  }
133 
139  [[nodiscard]] std::filesystem::path GetCertsDir() const {
140  return app_resource_path_ / "certs";
141  }
142 
147  void SyncSettings() noexcept;
148 
149  private:
150  std::filesystem::path app_path_ =
151  qApp->applicationDirPath().toStdString();
152  std::filesystem::path app_data_path_ =
153  QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
154  .toStdString();
155  std::filesystem::path app_log_path_ =
156  app_data_path_ / "logs";
157  std::filesystem::path app_data_objs_path_ =
158  app_data_path_ / "objs";
159 
160 #ifdef LINUX_INSTALL_BUILD
161  std::filesystem::path app_resource_path_ =
162  std::filesystem::path(APP_LOCALSTATE_PATH) /
163  "gpgfrontend";
164 #else
165  std::filesystem::path app_resource_path_ =
166  RESOURCE_DIR_BOOST_PATH(app_path_);
167 #endif
168 
169 #ifdef LINUX_INSTALL_BUILD
170  std::filesystem::path app_locale_path_ =
171  std::string(APP_LOCALE_PATH);
172 #else
173  std::filesystem::path app_locale_path_ =
174  app_resource_path_ / "locales";
175 #endif
176 
177  std::filesystem::path app_configure_path_ =
178  QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)
179  .toStdString();
180  std::filesystem::path ui_config_dir_path_ =
181  app_configure_path_ /
182  "UserInterface";
183  std::filesystem::path ui_config_path_ =
184  ui_config_dir_path_ / "ui.cfg";
185 
186  libconfig::Config ui_cfg_;
187 
192  void init_app_secure_key();
193 };
194 } // namespace GpgFrontend
195 
196 #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:155
GpgFrontend::GlobalSettingStation::GetUISettings
libconfig::Setting & GetUISettings() noexcept
Definition: GlobalSettingStation.h:68
GpgFrontend::GlobalSettingStation::ui_config_path_
std::filesystem::path ui_config_path_
UI Configure File Location.
Definition: GlobalSettingStation.h:183
GpgFrontend::GlobalSettingStation::GetCertsDir
std::filesystem::path GetCertsDir() const
Get the Certs Dir object.
Definition: GlobalSettingStation.h:139
GpgFrontend::GlobalSettingStation::GetLocaleDir
std::filesystem::path GetLocaleDir() const
Get the Locale Dir object.
Definition: GlobalSettingStation.h:121
GpgFrontend::GlobalSettingStation::GetResourceDir
std::filesystem::path GetResourceDir() const
Get the Resource Dir object.
Definition: GlobalSettingStation.h:130
GpgFrontend::GlobalSettingStation::GetStandaloneDatabaseDir
std::filesystem::path GetStandaloneDatabaseDir() const
Get the Standalone Database Dir object.
Definition: GlobalSettingStation.h:95
GpgFrontend::GlobalSettingStation::app_data_path_
std::filesystem::path app_data_path_
Program Data Location.
Definition: GlobalSettingStation.h:152
GpgFrontend::GlobalSettingStation::ui_config_dir_path_
std::filesystem::path ui_config_dir_path_
Configure File Directory Location.
Definition: GlobalSettingStation.h:180
GpgFrontend::GlobalSettingStation::app_path_
std::filesystem::path app_path_
Program Location.
Definition: GlobalSettingStation.h:150
GpgFrontend::GlobalSettingStation::app_locale_path_
std::filesystem::path app_locale_path_
Program Data Location.
Definition: GlobalSettingStation.h:173
GpgFrontend::GlobalSettingStation
Definition: GlobalSettingStation.h:47
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:127
GpgFrontend::GlobalSettingStation::app_configure_path_
std::filesystem::path app_configure_path_
Program Configure Location.
Definition: GlobalSettingStation.h:177
GpgFrontend::GlobalSettingStation::GetStandaloneGpgBinDir
std::filesystem::path GetStandaloneGpgBinDir() const
Get the Standalone Gpg Bin Dir object.
Definition: GlobalSettingStation.h:112
GpgFrontend::GlobalSettingStation::GetLogDir
std::filesystem::path GetLogDir() const
Get the Log Dir object.
Definition: GlobalSettingStation.h:86
GpgFrontend::GlobalSettingStation::ui_cfg_
libconfig::Config ui_cfg_
UI Configure File.
Definition: GlobalSettingStation.h:186
GpgFrontend::GlobalSettingStation::GetAppDir
std::filesystem::path GetAppDir() const
Get the App Dir object.
Definition: GlobalSettingStation.h:75