aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/struct
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/struct')
-rw-r--r--src/ui/struct/CacheObject.cpp45
-rw-r--r--src/ui/struct/CacheObject.h52
-rw-r--r--src/ui/struct/SettingsObject.cpp91
-rw-r--r--src/ui/struct/SettingsObject.h37
-rw-r--r--src/ui/struct/SoftwareVersion.cpp101
-rw-r--r--src/ui/struct/SoftwareVersion.h88
-rw-r--r--src/ui/struct/settings/AppearanceSO.h77
-rw-r--r--src/ui/struct/settings/KeyServerSO.h79
-rw-r--r--src/ui/struct/settings/WindowStateSO.h65
9 files changed, 355 insertions, 280 deletions
diff --git a/src/ui/struct/CacheObject.cpp b/src/ui/struct/CacheObject.cpp
new file mode 100644
index 00000000..bd3b9818
--- /dev/null
+++ b/src/ui/struct/CacheObject.cpp
@@ -0,0 +1,45 @@
+/**
+ * Copyright (C) 2021 Saturneric <[email protected]>
+ *
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgFrontend is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
+ *
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#include "CacheObject.h"
+
+#include "core/function/CacheManager.h"
+
+namespace GpgFrontend::UI {
+
+CacheObject::CacheObject(QString cache_name)
+ : cache_name_(std::move(cache_name)) {
+ this->QJsonDocument::operator=(
+ CacheManager::GetInstance().LoadDurableCache(cache_name_));
+}
+
+CacheObject::~CacheObject() {
+ CacheManager::GetInstance().SaveDurableCache(cache_name_, *this);
+}
+
+} // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/struct/CacheObject.h b/src/ui/struct/CacheObject.h
new file mode 100644
index 00000000..ae8aa056
--- /dev/null
+++ b/src/ui/struct/CacheObject.h
@@ -0,0 +1,52 @@
+/**
+ * Copyright (C) 2021 Saturneric <[email protected]>
+ *
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgFrontend is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
+ *
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#pragma once
+
+namespace GpgFrontend::UI {
+
+class CacheObject : public QJsonDocument {
+ public:
+ /**
+ * @brief Construct a new Cache Object object
+ *
+ * @param cache_name
+ */
+ explicit CacheObject(QString cache_name);
+
+ /**
+ * @brief Destroy the Cache Object object
+ *
+ */
+ ~CacheObject();
+
+ private:
+ QString cache_name_; ///<
+};
+
+} // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/struct/SettingsObject.cpp b/src/ui/struct/SettingsObject.cpp
index d5230089..cc5e85bf 100644
--- a/src/ui/struct/SettingsObject.cpp
+++ b/src/ui/struct/SettingsObject.cpp
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2021 Saturneric
+ * Copyright (C) 2021 Saturneric <[email protected]>
*
* This file is part of GpgFrontend.
*
@@ -20,7 +20,7 @@
* the gpg4usb project, which is under GPL-3.0-or-later.
*
* All the source code of GpgFrontend was modified and released by
- * Saturneric<[email protected]> starting on May 12, 2021.
+ * Saturneric <[email protected]> starting on May 12, 2021.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
@@ -28,77 +28,42 @@
#include "SettingsObject.h"
-nlohmann::json& GpgFrontend::UI::SettingsObject::Check(
- const std::string& key, const nlohmann::json& default_value) {
- // check if the self null
- if (this->nlohmann::json::is_null()) {
- SPDLOG_DEBUG("settings object is null, creating new one");
- this->nlohmann::json::operator=(nlohmann::json::object());
- }
-
- try {
- if (!this->nlohmann::json::contains(key) ||
- this->nlohmann::json::at(key).is_null() ||
- this->nlohmann::json::at(key).type_name() !=
- default_value.type_name()) {
- SPDLOG_DEBUG("added missing key: {}", key);
- if (default_value.is_null()) {
- SPDLOG_WARN("default value is null, using empty object");
- this->nlohmann::json::operator[](key) = nlohmann::json::object();
- } else {
- this->nlohmann::json::operator[](key) = default_value;
- }
- }
- return this->nlohmann::json::at(key);
- } catch (nlohmann::json::exception& e) {
- SPDLOG_ERROR(e.what());
- throw e;
- }
-}
-
-GpgFrontend::UI::SettingsObject GpgFrontend::UI::SettingsObject::Check(
- const std::string& key) {
- // check if the self null
- if (this->nlohmann::json::is_null()) {
- SPDLOG_DEBUG("settings object is null, creating new one");
- this->nlohmann::json::operator=(nlohmann::json::object());
- }
+#include "core/function/DataObjectOperator.h"
- if (!nlohmann::json::contains(key) ||
- this->nlohmann::json::at(key).is_null() ||
- this->nlohmann::json::at(key).type() != nlohmann::json::value_t::object) {
- SPDLOG_DEBUG("added missing key: {}", key);
- this->nlohmann::json::operator[](key) = nlohmann::json::object();
- }
- return SettingsObject{nlohmann::json::operator[](key), false};
-}
+namespace GpgFrontend::UI {
-GpgFrontend::UI::SettingsObject::SettingsObject(std::string settings_name)
+SettingsObject::SettingsObject(QString settings_name)
: settings_name_(std::move(settings_name)) {
try {
- SPDLOG_DEBUG("loading settings from: {}", this->settings_name_);
- auto _json_optional =
- GpgFrontend::DataObjectOperator::GetInstance().GetDataObject(
- settings_name_);
+ GF_UI_LOG_DEBUG("loading settings from: {}", this->settings_name_);
+ auto json_optional =
+ DataObjectOperator::GetInstance().GetDataObject(settings_name_);
- if (_json_optional.has_value()) {
- SPDLOG_DEBUG("settings object: {} loaded.", settings_name_);
- nlohmann::json::operator=(_json_optional.value());
+ if (json_optional.has_value() && json_optional->isObject()) {
+ GF_UI_LOG_DEBUG("settings object: {} loaded.", settings_name_);
+ QJsonObject::operator=(json_optional.value().object());
} else {
- SPDLOG_DEBUG("settings object: {} not found.", settings_name_);
- nlohmann::json::operator=({});
+ GF_UI_LOG_DEBUG("settings object: {} not found.", settings_name_);
+ QJsonObject::operator=({});
}
} catch (std::exception& e) {
- SPDLOG_ERROR(e.what());
+ GF_UI_LOG_ERROR("load setting object error: {}", e.what());
}
}
-GpgFrontend::UI::SettingsObject::SettingsObject(nlohmann::json _sub_json, bool)
- : nlohmann::json(std::move(_sub_json)), settings_name_({}) {}
+SettingsObject::SettingsObject(QJsonObject sub_json)
+ : QJsonObject(std::move(sub_json)) {}
-GpgFrontend::UI::SettingsObject::~SettingsObject() {
- if (!settings_name_.empty())
- GpgFrontend::DataObjectOperator::GetInstance().SaveDataObj(settings_name_,
- *this);
-} \ No newline at end of file
+SettingsObject::~SettingsObject() {
+ if (!settings_name_.isEmpty()) {
+ DataObjectOperator::GetInstance().SaveDataObj(settings_name_,
+ QJsonDocument(*this));
+ }
+}
+
+void SettingsObject::Store(const QJsonObject& json) {
+ auto* parent = (static_cast<QJsonObject*>(this));
+ *parent = json;
+}
+} // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/struct/SettingsObject.h b/src/ui/struct/SettingsObject.h
index d1e85be5..a9e5819f 100644
--- a/src/ui/struct/SettingsObject.h
+++ b/src/ui/struct/SettingsObject.h
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2021 Saturneric
+ * Copyright (C) 2021 Saturneric <[email protected]>
*
* This file is part of GpgFrontend.
*
@@ -20,41 +20,36 @@
* the gpg4usb project, which is under GPL-3.0-or-later.
*
* All the source code of GpgFrontend was modified and released by
- * Saturneric<[email protected]> starting on May 12, 2021.
+ * Saturneric <[email protected]> starting on May 12, 2021.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
-#ifndef GPGFRONTEND_SETTINGSOBJECT_H
-#define GPGFRONTEND_SETTINGSOBJECT_H
-
-#include <utility>
-
-#include "core/function/DataObjectOperator.h"
+#pragma once
namespace GpgFrontend::UI {
/**
* @brief The SettingsObject class
- * This class is used to store settings for the application securely.
+ * This class is used to store data for the application securely.
*
*/
-class SettingsObject : public nlohmann::json {
+class SettingsObject : public QJsonObject {
public:
/**
* @brief Construct a new Settings Object object
*
* @param settings_name The name of the settings object
*/
- explicit SettingsObject(std::string settings_name);
+ explicit SettingsObject(QString settings_name);
/**
* @brief Construct a new Settings Object object
*
* @param _sub_json
*/
- explicit SettingsObject(nlohmann::json _sub_json, bool);
+ explicit SettingsObject(QJsonObject sub_json);
/**
* @brief Destroy the Settings Object object
@@ -65,24 +60,10 @@ class SettingsObject : public nlohmann::json {
/**
* @brief
*
- * @param key
- * @param default_value
- * @return nlohmann::json&
- */
- nlohmann::json& Check(const std::string& key,
- const nlohmann::json& default_value);
-
- /**
- * @brief
- *
- * @param key
- * @return SettingsObject
*/
- SettingsObject Check(const std::string& key);
+ void Store(const QJsonObject&);
private:
- std::string settings_name_; ///<
+ QString settings_name_; ///<
};
} // namespace GpgFrontend::UI
-
-#endif // GPGFRONTEND_SETTINGSOBJECT_H
diff --git a/src/ui/struct/SoftwareVersion.cpp b/src/ui/struct/SoftwareVersion.cpp
deleted file mode 100644
index 6a60cb02..00000000
--- a/src/ui/struct/SoftwareVersion.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * Copyright (C) 2021 Saturneric
- *
- * This file is part of GpgFrontend.
- *
- * GpgFrontend is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GpgFrontend is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
- *
- * The initial version of the source code is inherited from
- * the gpg4usb project, which is under GPL-3.0-or-later.
- *
- * All the source code of GpgFrontend was modified and released by
- * Saturneric<[email protected]> starting on May 12, 2021.
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#include "SoftwareVersion.h"
-
-int GpgFrontend::UI::SoftwareVersion::version_compare(const std::string& a,
- const std::string& b) {
- auto temp_a = a, temp_b = b;
-
- if (!temp_a.empty() && temp_a.front() == 'v') {
- temp_a = temp_a.erase(0, 1);
- SPDLOG_DEBUG("real version a: {}", temp_a);
- }
-
- if (!temp_b.empty() && temp_b.front() == 'v') {
- temp_b.erase(0, 1);
- SPDLOG_DEBUG("real version b: {}", temp_b);
- }
-
- // First, split the string.
- std::vector<std::string> va, vb;
- boost::split(va, temp_a, boost::is_any_of("."));
- boost::split(vb, temp_b, boost::is_any_of("."));
-
- // Compare the numbers step by step, but only as deep as the version
- // with the least elements allows.
- const int depth =
- std::min(static_cast<int>(va.size()), static_cast<int>(vb.size()));
- int ia = 0, ib = 0;
- for (int i = 0; i < depth; ++i) {
- try {
- ia = boost::lexical_cast<int>(va[i]);
- ib = boost::lexical_cast<int>(vb[i]);
- } catch (boost::bad_lexical_cast& ignored) {
- break;
- }
- if (ia != ib) break;
- }
-
- // Return the required number.
- if (ia > ib)
- return 1;
- else if (ia < ib)
- return -1;
- else {
- // In case of equal versions, assumes that the version
- // with the most elements is the highest version.
- if (va.size() > vb.size())
- return 1;
- else if (va.size() < vb.size())
- return -1;
- }
-
- // Everything is equal, return 0.
- return 0;
-}
-
-bool GpgFrontend::UI::SoftwareVersion::NeedUpgrade() const {
- SPDLOG_DEBUG("compair version current {} latest {}, result {}",
- current_version, latest_version,
- version_compare(current_version, latest_version));
-
- SPDLOG_DEBUG("load done: {}, pre-release: {}, draft: {}", load_info_done,
- latest_prerelease, latest_draft);
- return load_info_done && !latest_prerelease && !latest_draft &&
- version_compare(current_version, latest_version) < 0;
-}
-
-bool GpgFrontend::UI::SoftwareVersion::VersionWithDrawn() const {
- return load_info_done && !current_version_found && current_prerelease &&
- !current_draft;
-}
-
-bool GpgFrontend::UI::SoftwareVersion::CurrentVersionReleased() const {
- return load_info_done && current_version_found;
-} \ No newline at end of file
diff --git a/src/ui/struct/SoftwareVersion.h b/src/ui/struct/SoftwareVersion.h
deleted file mode 100644
index 9d861ef1..00000000
--- a/src/ui/struct/SoftwareVersion.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/**
- * Copyright (C) 2021 Saturneric
- *
- * This file is part of GpgFrontend.
- *
- * GpgFrontend is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GpgFrontend is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
- *
- * The initial version of the source code is inherited from
- * the gpg4usb project, which is under GPL-3.0-or-later.
- *
- * All the source code of GpgFrontend was modified and released by
- * Saturneric<[email protected]> starting on May 12, 2021.
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifndef GPGFRONTEND_SOFTWAREVERSION_H
-#define GPGFRONTEND_SOFTWAREVERSION_H
-
-#include <boost/date_time.hpp>
-
-namespace GpgFrontend::UI {
-/**
- * @brief
- *
- */
-struct SoftwareVersion {
- std::string latest_version; ///<
- std::string current_version; ///<
- bool latest_prerelease = false; ///<
- bool latest_draft = false; ///<
- bool current_prerelease = false; ///<
- bool current_draft = false; ///<
- bool load_info_done = false; ///<
- bool current_version_found = false; ///<
- std::string publish_date; ///<
- std::string release_note; ///<
-
- /**
- * @brief
- *
- * @return true
- * @return false
- */
- [[nodiscard]] bool InfoValid() const { return load_info_done; }
-
- /**
- * @brief
- *
- * @return true
- * @return false
- */
- [[nodiscard]] bool NeedUpgrade() const;
-
- /**
- * @brief
- *
- * @return true
- * @return false
- */
- [[nodiscard]] bool VersionWithDrawn() const;
-
- /**
- * @brief
- *
- * @return true
- * @return false
- */
- [[nodiscard]] bool CurrentVersionReleased() const;
-
- private:
- static int version_compare(const std::string& a, const std::string& b);
-};
-} // namespace GpgFrontend::UI
-
-#endif // GPGFRONTEND_SOFTWAREVERSION_H
diff --git a/src/ui/struct/settings/AppearanceSO.h b/src/ui/struct/settings/AppearanceSO.h
new file mode 100644
index 00000000..25262f22
--- /dev/null
+++ b/src/ui/struct/settings/AppearanceSO.h
@@ -0,0 +1,77 @@
+/**
+ * Copyright (C) 2021 Saturneric <[email protected]>
+ *
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgFrontend is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
+ *
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#pragma once
+
+namespace GpgFrontend::UI {
+
+struct AppearanceSO {
+ int text_editor_font_size = 12;
+ int info_board_font_size = 12;
+ int tool_bar_icon_width = 24;
+ int tool_bar_icon_height = 24;
+ Qt::ToolButtonStyle tool_bar_button_style = Qt::ToolButtonTextUnderIcon;
+
+ bool save_window_state;
+
+ explicit AppearanceSO(const QJsonObject& j) {
+ if (const auto v = j["text_editor_font_size"]; v.isDouble()) {
+ text_editor_font_size = v.toInt();
+ }
+ if (const auto v = j["info_board_font_size"]; v.isDouble()) {
+ info_board_font_size = v.toInt();
+ }
+ if (const auto v = j["tool_bar_icon_width"]; v.isDouble()) {
+ tool_bar_icon_width = v.toInt();
+ }
+ if (const auto v = j["tool_bar_icon_height"]; v.isDouble()) {
+ tool_bar_icon_height = v.toInt();
+ }
+ if (const auto v = j["tool_bar_button_style"]; v.isDouble()) {
+ tool_bar_button_style = static_cast<Qt::ToolButtonStyle>(v.toInt());
+ }
+
+ if (const auto v = j["save_window_state"]; v.isBool()) {
+ save_window_state = v.toBool();
+ }
+ }
+
+ [[nodiscard]] auto ToJson() const -> QJsonObject {
+ QJsonObject j;
+ j["text_editor_font_size"] = text_editor_font_size;
+ j["info_board_font_size"] = info_board_font_size;
+ j["tool_bar_icon_width"] = tool_bar_icon_width;
+ j["tool_bar_icon_height"] = tool_bar_icon_height;
+ j["tool_bar_button_style"] = tool_bar_button_style;
+
+ j["save_window_state"] = save_window_state;
+ return j;
+ }
+};
+
+} // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/struct/settings/KeyServerSO.h b/src/ui/struct/settings/KeyServerSO.h
new file mode 100644
index 00000000..3c9320d2
--- /dev/null
+++ b/src/ui/struct/settings/KeyServerSO.h
@@ -0,0 +1,79 @@
+/**
+ * Copyright (C) 2021 Saturneric <[email protected]>
+ *
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgFrontend is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
+ *
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#pragma once
+
+namespace GpgFrontend::UI {
+
+struct KeyServerSO {
+ int default_server = 0;
+ QStringList server_list;
+
+ KeyServerSO() = default;
+
+ explicit KeyServerSO(const QJsonObject& j) {
+ if (const auto v = j["default_server"]; v.isDouble()) {
+ default_server = v.toInt();
+ }
+
+ if (const auto v = j["server_list"]; v.isArray()) {
+ const QJsonArray j_array = v.toArray();
+ server_list.reserve(j_array.size());
+ for (const auto& server : j_array) {
+ server_list.append(server.toString());
+ }
+ }
+
+ if (server_list.empty()) ResetDefaultServerList();
+ }
+
+ auto ToJson() -> QJsonObject {
+ QJsonObject j;
+ j["default_server"] = default_server;
+ auto j_array = QJsonArray();
+
+ for (const auto& s : server_list) {
+ j_array.push_back(s);
+ }
+ j["server_list"] = j_array;
+ return j;
+ }
+
+ auto GetTargetServer() -> QString {
+ if (server_list.empty()) this->ResetDefaultServerList();
+ if (default_server >= server_list.size()) default_server = 0;
+ return server_list[default_server];
+ }
+
+ void ResetDefaultServerList() {
+ server_list << "https://keyserver.ubuntu.com"
+ << "https://keys.openpgp.org";
+ }
+};
+
+} // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/struct/settings/WindowStateSO.h b/src/ui/struct/settings/WindowStateSO.h
new file mode 100644
index 00000000..3fa56f3c
--- /dev/null
+++ b/src/ui/struct/settings/WindowStateSO.h
@@ -0,0 +1,65 @@
+/**
+ * Copyright (C) 2021 Saturneric <[email protected]>
+ *
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgFrontend is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
+ *
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#pragma once
+
+namespace GpgFrontend::UI {
+
+struct WindowStateSO {
+ bool window_save = false;
+ QString window_state_data;
+ int x = 100;
+ int y = 100;
+ int width = 400;
+ int height = 200;
+
+ WindowStateSO() = default;
+
+ explicit WindowStateSO(const QJsonObject &j) {
+ if (const auto v = j["window_save"]; v.isBool()) window_save = v.toBool();
+ if (const auto v = j["window_state_data"]; v.isString()) {
+ window_state_data = v.toString();
+ }
+ if (const auto v = j["x"]; v.isDouble()) x = v.toInt();
+ if (const auto v = j["y"]; v.isDouble()) y = v.toInt();
+ if (const auto v = j["width"]; v.isDouble()) width = v.toInt();
+ if (const auto v = j["height"]; v.isDouble()) height = v.toInt();
+ }
+
+ [[nodiscard]] auto Json() const -> QJsonObject {
+ QJsonObject j;
+ j["window_save"] = window_save;
+ j["window_state_data"] = window_state_data;
+ j["x"] = x;
+ j["y"] = y;
+ j["width"] = width;
+ j["height"] = height;
+ return j;
+ }
+};
+} // namespace GpgFrontend::UI \ No newline at end of file