From 95997d27106daf91336847f50efaaa32279b7fc7 Mon Sep 17 00:00:00 2001 From: saturneric Date: Mon, 16 Oct 2023 17:54:05 +0800 Subject: fix: check and update copyright at files --- src/ui/dialog/GeneralDialog.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/ui/dialog/GeneralDialog.cpp') diff --git a/src/ui/dialog/GeneralDialog.cpp b/src/ui/dialog/GeneralDialog.cpp index d4b6613e..0e71140e 100644 --- a/src/ui/dialog/GeneralDialog.cpp +++ b/src/ui/dialog/GeneralDialog.cpp @@ -1,7 +1,7 @@ -/* - * Copyright (c) 2022. Saturneric +/** + * Copyright (C) 2021 Saturneric * - * This file is part of GpgFrontend. + * 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 @@ -20,9 +20,10 @@ * the gpg4usb project, which is under GPL-3.0-or-later. * * All the source code of GpgFrontend was modified and released by - * Saturneric starting on May 12, 2021. + * Saturneric starting on May 12, 2021. * * SPDX-License-Identifier: GPL-3.0-or-later + * */ #include "GeneralDialog.h" -- cgit v1.2.3 From 124929609eabff19359caad276a10f1026793c0f Mon Sep 17 00:00:00 2001 From: saturneric Date: Wed, 25 Oct 2023 18:26:26 +0800 Subject: fix: solve some code tidy issues --- src/ui/dialog/GeneralDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui/dialog/GeneralDialog.cpp') diff --git a/src/ui/dialog/GeneralDialog.cpp b/src/ui/dialog/GeneralDialog.cpp index 0e71140e..3556c403 100644 --- a/src/ui/dialog/GeneralDialog.cpp +++ b/src/ui/dialog/GeneralDialog.cpp @@ -31,7 +31,7 @@ #include "ui/struct/SettingsObject.h" GpgFrontend::UI::GeneralDialog::GeneralDialog(std::string name, QWidget *parent) - : name_(std::move(name)), QDialog(parent) { + : QDialog(parent), name_(std::move(name)) { slot_restore_settings(); connect(this, &QDialog::finished, this, &GeneralDialog::slot_save_settings); } -- cgit v1.2.3 From 644aa4397b03dbef73f8bfedc13925b51cad836b Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 5 Jan 2024 20:55:15 +0800 Subject: feat: integrate logging api to core --- src/ui/dialog/GeneralDialog.cpp | 56 +++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 27 deletions(-) (limited to 'src/ui/dialog/GeneralDialog.cpp') diff --git a/src/ui/dialog/GeneralDialog.cpp b/src/ui/dialog/GeneralDialog.cpp index 3556c403..d48e878d 100644 --- a/src/ui/dialog/GeneralDialog.cpp +++ b/src/ui/dialog/GeneralDialog.cpp @@ -49,21 +49,22 @@ void GpgFrontend::UI::GeneralDialog::slot_restore_settings() noexcept { if (window_save) { int x = general_windows_state.Check("window_pos").Check("x", 0), y = general_windows_state.Check("window_pos").Check("y", 0); - SPDLOG_DEBUG("stored dialog pos, x: {}, y: {}", x, y); + GF_UI_LOG_DEBUG("stored dialog pos, x: {}, y: {}", x, y); QPoint relative_pos = {x, y}; QPoint pos = parent_rect_.topLeft() + relative_pos; - SPDLOG_DEBUG("relative dialog pos, x: {}, y: {}", relative_pos.x(), - relative_pos.y()); + GF_UI_LOG_DEBUG("relative dialog pos, x: {}, y: {}", relative_pos.x(), + relative_pos.y()); int width = general_windows_state.Check("window_size").Check("width", 0), height = general_windows_state.Check("window_size").Check("height", 0); - SPDLOG_DEBUG("stored dialog size, width: {}, height: {}", width, height); + GF_UI_LOG_DEBUG("stored dialog size, width: {}, height: {}", width, + height); QRect target_rect_ = {pos.x(), pos.y(), width, height}; - SPDLOG_DEBUG("dialog stored target rect, width: {}, height: {}", width, - height); + GF_UI_LOG_DEBUG("dialog stored target rect, width: {}, height: {}", width, + height); // check for valid if (width > 0 && height > 0 && screen_rect_.contains(target_rect_)) { @@ -73,7 +74,7 @@ void GpgFrontend::UI::GeneralDialog::slot_restore_settings() noexcept { } } catch (...) { - SPDLOG_ERROR("error at restoring settings"); + GF_UI_LOG_ERROR("error at restoring settings"); } } @@ -83,14 +84,14 @@ void GpgFrontend::UI::GeneralDialog::slot_save_settings() noexcept { update_rect_cache(); - SPDLOG_DEBUG("dialog pos, x: {}, y: {}", rect_.x(), rect_.y()); - SPDLOG_DEBUG("dialog size, width: {}, height: {}", rect_.width(), - rect_.height()); + GF_UI_LOG_DEBUG("dialog pos, x: {}, y: {}", rect_.x(), rect_.y()); + GF_UI_LOG_DEBUG("dialog size, width: {}, height: {}", rect_.width(), + rect_.height()); // window position relative to parent auto relative_pos = rect_.topLeft() - parent_rect_.topLeft(); - SPDLOG_DEBUG("store dialog pos, x: {}, y: {}", relative_pos.x(), - relative_pos.y()); + GF_UI_LOG_DEBUG("store dialog pos, x: {}, y: {}", relative_pos.x(), + relative_pos.y()); general_windows_state["window_pos"]["x"] = relative_pos.x(); general_windows_state["window_pos"]["y"] = relative_pos.y(); @@ -100,7 +101,7 @@ void GpgFrontend::UI::GeneralDialog::slot_save_settings() noexcept { general_windows_state["window_save"] = true; } catch (...) { - SPDLOG_ERROR(name_, "error"); + GF_UI_LOG_ERROR(name_, "error"); } } @@ -109,8 +110,8 @@ void GpgFrontend::UI::GeneralDialog::setPosCenterOfScreen() { int screen_width = screen_rect_.width(); int screen_height = screen_rect_.height(); - SPDLOG_DEBUG("dialog current screen available geometry", screen_width, - screen_height); + GF_UI_LOG_DEBUG("dialog current screen available geometry", screen_width, + screen_height); // update rect of current dialog rect_ = this->geometry(); @@ -127,14 +128,14 @@ void GpgFrontend::UI::GeneralDialog::movePosition2CenterOfParent() { update_rect_cache(); // log for debug - SPDLOG_DEBUG("parent pos x: {} y: {}", parent_rect_.x(), parent_rect_.y()); - SPDLOG_DEBUG("parent size width: {}, height: {}", parent_rect_.width(), - parent_rect_.height()); - SPDLOG_DEBUG("parent center pos x: {}, y: {}", parent_rect_.center().x(), - parent_rect_.center().y()); - SPDLOG_DEBUG("dialog pos x: {} y: {}", rect_.x(), rect_.y()); - SPDLOG_DEBUG("dialog size width: {} height: {}", rect_.width(), - rect_.height()); + GF_UI_LOG_DEBUG("parent pos x: {} y: {}", parent_rect_.x(), parent_rect_.y()); + GF_UI_LOG_DEBUG("parent size width: {}, height: {}", parent_rect_.width(), + parent_rect_.height()); + GF_UI_LOG_DEBUG("parent center pos x: {}, y: {}", parent_rect_.center().x(), + parent_rect_.center().y()); + GF_UI_LOG_DEBUG("dialog pos x: {} y: {}", rect_.x(), rect_.y()); + GF_UI_LOG_DEBUG("dialog size width: {} height: {}", rect_.width(), + rect_.height()); if (parent_rect_.topLeft() != QPoint{0, 0} && parent_rect_.size() != QSize{0, 0}) { @@ -144,8 +145,9 @@ void GpgFrontend::UI::GeneralDialog::movePosition2CenterOfParent() { QPoint target_position = parent_rect_.center() - QPoint(rect_.width() / 2, rect_.height() / 2); - SPDLOG_DEBUG("update position to parent's center, target pos, x:{}, y: {}", - target_position.x(), target_position.y()); + GF_UI_LOG_DEBUG( + "update position to parent's center, target pos, x:{}, y: {}", + target_position.x(), target_position.y()); this->move(target_position); } else { @@ -199,8 +201,8 @@ bool GpgFrontend::UI::GeneralDialog::isRectRestored() { return rect_restored_; } * */ void GpgFrontend::UI::GeneralDialog::showEvent(QShowEvent *event) { - SPDLOG_DEBUG("General Dialog named {} is about to show, caught show event", - name_); + GF_UI_LOG_DEBUG("General Dialog named {} is about to show, caught show event", + name_); // default position strategy if (!isRectRestored()) movePosition2CenterOfParent(); -- cgit v1.2.3 From bf538056b24a68b8fd235b1c50991ee8eb46a776 Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 12 Jan 2024 14:02:37 +0800 Subject: refactor: use QString instead of std::string and improve threading system --- src/ui/dialog/GeneralDialog.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/ui/dialog/GeneralDialog.cpp') diff --git a/src/ui/dialog/GeneralDialog.cpp b/src/ui/dialog/GeneralDialog.cpp index d48e878d..498e2941 100644 --- a/src/ui/dialog/GeneralDialog.cpp +++ b/src/ui/dialog/GeneralDialog.cpp @@ -30,7 +30,7 @@ #include "ui/struct/SettingsObject.h" -GpgFrontend::UI::GeneralDialog::GeneralDialog(std::string name, QWidget *parent) +GpgFrontend::UI::GeneralDialog::GeneralDialog(QString name, QWidget *parent) : QDialog(parent), name_(std::move(name)) { slot_restore_settings(); connect(this, &QDialog::finished, this, &GeneralDialog::slot_save_settings); @@ -47,8 +47,8 @@ void GpgFrontend::UI::GeneralDialog::slot_restore_settings() noexcept { // Restore window size & location if (window_save) { - int x = general_windows_state.Check("window_pos").Check("x", 0), - y = general_windows_state.Check("window_pos").Check("y", 0); + int x = general_windows_state.Check("window_pos").Check("x", 0); + int y = general_windows_state.Check("window_pos").Check("y", 0); GF_UI_LOG_DEBUG("stored dialog pos, x: {}, y: {}", x, y); QPoint relative_pos = {x, y}; @@ -56,19 +56,19 @@ void GpgFrontend::UI::GeneralDialog::slot_restore_settings() noexcept { GF_UI_LOG_DEBUG("relative dialog pos, x: {}, y: {}", relative_pos.x(), relative_pos.y()); - int width = general_windows_state.Check("window_size").Check("width", 0), - height = - general_windows_state.Check("window_size").Check("height", 0); + int width = general_windows_state.Check("window_size").Check("width", 0); + int height = + general_windows_state.Check("window_size").Check("height", 0); GF_UI_LOG_DEBUG("stored dialog size, width: {}, height: {}", width, height); - QRect target_rect_ = {pos.x(), pos.y(), width, height}; + QRect target_rect = {pos.x(), pos.y(), width, height}; GF_UI_LOG_DEBUG("dialog stored target rect, width: {}, height: {}", width, height); // check for valid - if (width > 0 && height > 0 && screen_rect_.contains(target_rect_)) { - this->setGeometry(target_rect_); + if (width > 0 && height > 0 && screen_rect_.contains(target_rect)) { + this->setGeometry(target_rect); this->rect_restored_ = true; } } @@ -101,7 +101,7 @@ void GpgFrontend::UI::GeneralDialog::slot_save_settings() noexcept { general_windows_state["window_save"] = true; } catch (...) { - GF_UI_LOG_ERROR(name_, "error"); + GF_UI_LOG_ERROR("general dialog: {}, caught exception", name_); } } @@ -194,7 +194,9 @@ void GpgFrontend::UI::GeneralDialog::update_rect_cache() { * @brief * */ -bool GpgFrontend::UI::GeneralDialog::isRectRestored() { return rect_restored_; } +auto GpgFrontend::UI::GeneralDialog::isRectRestored() -> bool { + return rect_restored_; +} /** * @brief @@ -207,5 +209,5 @@ void GpgFrontend::UI::GeneralDialog::showEvent(QShowEvent *event) { // default position strategy if (!isRectRestored()) movePosition2CenterOfParent(); - QWidget::showEvent(event); + QDialog::showEvent(event); } \ No newline at end of file -- cgit v1.2.3 From 6c632d70b391f8b317c68f7db8cfd217f9370995 Mon Sep 17 00:00:00 2001 From: saturneric Date: Mon, 15 Jan 2024 17:22:32 +0800 Subject: feat: use qt json support components in data object and infos gathering module --- src/ui/dialog/GeneralDialog.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'src/ui/dialog/GeneralDialog.cpp') diff --git a/src/ui/dialog/GeneralDialog.cpp b/src/ui/dialog/GeneralDialog.cpp index 498e2941..386573a3 100644 --- a/src/ui/dialog/GeneralDialog.cpp +++ b/src/ui/dialog/GeneralDialog.cpp @@ -29,6 +29,9 @@ #include "GeneralDialog.h" #include "ui/struct/SettingsObject.h" +#include "ui/struct/settings/WindowStateSO.h" + +namespace GpgFrontend { GpgFrontend::UI::GeneralDialog::GeneralDialog(QString name, QWidget *parent) : QDialog(parent), name_(std::move(name)) { @@ -43,12 +46,12 @@ void GpgFrontend::UI::GeneralDialog::slot_restore_settings() noexcept { update_rect_cache(); SettingsObject general_windows_state(name_ + "_dialog_state"); - bool window_save = general_windows_state.Check("window_save", false); + auto window_state = WindowStateSO(general_windows_state); // Restore window size & location - if (window_save) { - int x = general_windows_state.Check("window_pos").Check("x", 0); - int y = general_windows_state.Check("window_pos").Check("y", 0); + if (window_state.window_save) { + int x = window_state.x; + int y = window_state.y; GF_UI_LOG_DEBUG("stored dialog pos, x: {}, y: {}", x, y); QPoint relative_pos = {x, y}; @@ -56,9 +59,8 @@ void GpgFrontend::UI::GeneralDialog::slot_restore_settings() noexcept { GF_UI_LOG_DEBUG("relative dialog pos, x: {}, y: {}", relative_pos.x(), relative_pos.y()); - int width = general_windows_state.Check("window_size").Check("width", 0); - int height = - general_windows_state.Check("window_size").Check("height", 0); + int width = window_state.width; + int height = window_state.height; GF_UI_LOG_DEBUG("stored dialog size, width: {}, height: {}", width, height); @@ -93,12 +95,14 @@ void GpgFrontend::UI::GeneralDialog::slot_save_settings() noexcept { GF_UI_LOG_DEBUG("store dialog pos, x: {}, y: {}", relative_pos.x(), relative_pos.y()); - general_windows_state["window_pos"]["x"] = relative_pos.x(); - general_windows_state["window_pos"]["y"] = relative_pos.y(); + WindowStateSO window_state; + window_state.x = relative_pos.x(); + window_state.y = relative_pos.y(); + window_state.width = rect_.width(); + window_state.height = rect_.height(); + window_state.window_save = true; - general_windows_state["window_size"]["width"] = rect_.width(); - general_windows_state["window_size"]["height"] = rect_.height(); - general_windows_state["window_save"] = true; + general_windows_state.Store(window_state.Json()); } catch (...) { GF_UI_LOG_ERROR("general dialog: {}, caught exception", name_); @@ -210,4 +214,6 @@ void GpgFrontend::UI::GeneralDialog::showEvent(QShowEvent *event) { if (!isRectRestored()) movePosition2CenterOfParent(); QDialog::showEvent(event); -} \ No newline at end of file +} + +} // namespace GpgFrontend \ No newline at end of file -- cgit v1.2.3