diff options
author | Saturneric <[email protected]> | 2021-11-28 04:35:01 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2021-11-28 04:35:01 +0000 |
commit | b5b3ba7b1dc52a8dbae2a3a6970b44ede827f060 (patch) | |
tree | 7dffd4f4e6684d078616d88999590b95e8a56410 /src | |
parent | UI Framework Modified. (diff) | |
download | GpgFrontend-b5b3ba7b1dc52a8dbae2a3a6970b44ede827f060.tar.gz GpgFrontend-b5b3ba7b1dc52a8dbae2a3a6970b44ede827f060.zip |
Can be compiled with minimal UI support.
Diffstat (limited to 'src')
43 files changed, 1038 insertions, 770 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6477039d..13e48933 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,29 +1,29 @@ -if(GPG_CORE) +if (GPG_CORE) message(STATUS "Build Gpg Core") add_subdirectory(gpg) -endif() +endif () -if(UI_CORE) +if (UI_CORE) message(STATUS "Build UI Core") add_subdirectory(ui) -endif() +endif () -if(SMTP_SUPPORT) +if (SMTP_SUPPORT) message(STATUS "Build SMTP Support") add_subdirectory(smtp) -endif() +endif () -if(SERVER_SUPPORT) +if (SERVER_SUPPORT) message(STATUS "Build Server Support") add_subdirectory(server) -endif() +endif () -if(ADVANCE_SUPPORT) +if (ADVANCE_SUPPORT) message(STATUS "Build Advance Support") add_subdirectory(advance) -endif() +endif () -if(APPLICATION_BUILD) +if (APPLICATION_BUILD) aux_source_directory(. BASE_SOURCE) set(APP_ICON_RESOURCE_WINDOWS "${CMAKE_SOURCE_DIR}/gpgfrontend.rc") set_property(SOURCE gpgfrontend.rc APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/gpgfrontend.ico) @@ -31,30 +31,30 @@ if(APPLICATION_BUILD) # Set Binary Output Path set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release) message(STATUS "CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") -endif() +endif () -if(APPLICATION_BUILD) +if (APPLICATION_BUILD) # Set Resource Output Path - if(${CMAKE_BUILD_TYPE} STREQUAL "Release") - if(APPLE) + if (${CMAKE_BUILD_TYPE} STREQUAL "Release") + if (APPLE) set(RESOURCE_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Resources) - elseif(LINUX) + elseif (LINUX) file(COPY ${CMAKE_SOURCE_DIR}/resource/gpgfrontend DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) set(RESOURCE_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gpgfrontend/usr/share) - else() + else () set(RESOURCE_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) - endif() - else() + endif () + else () set(RESOURCE_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) - endif() + endif () message(STATUS "RESOURCE_OUTPUT_DIRECTORY ${RESOURCE_OUTPUT_DIRECTORY}") -endif() +endif () # Get ALL SOURCE FILES file(GLOB_RECURSE ALL_SOURCE_FILES RELACTIVE ${CMAKE_SOURCE_DIR}/src/*.cpp) -if(MULTI_LANG_SUPPORT) +if (MULTI_LANG_SUPPORT) # Set Translation Files set(QT_TS_FILES gpgfrontend_en_us.ts gpgfrontend_zh_cn.ts @@ -66,36 +66,36 @@ if(MULTI_LANG_SUPPORT) QT5_create_translation(QON_QM_FILES ${CMAKE_SOURCE_DIR} ${QT_TS_FILES}) message(STATUS "QON_QM_FILES ${QON_QM_FILES}") add_custom_target(translations DEPENDS ${QON_QM_FILES}) -endif() +endif () -if(BASIC_ENV_CONFIG) +if (BASIC_ENV_CONFIG) # Set Build Information configure_file(${CMAKE_SOURCE_DIR}/src/GpgFrontend.h.in ${CMAKE_SOURCE_DIR}/src/GpgFrontend.h @ONLY) configure_file(${CMAKE_SOURCE_DIR}/src/GpgFrontendBuildInfo.h.in ${CMAKE_SOURCE_DIR}/src/GpgFrontendBuildInfo.h @ONLY) -endif() +endif () -if(APPLICATION_BUILD) +if (APPLICATION_BUILD) # Copy Resource Files file(COPY ${CMAKE_SOURCE_DIR}/resource/css DESTINATION ${RESOURCE_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) file(COPY ${CMAKE_SOURCE_DIR}/resource/icons DESTINATION ${RESOURCE_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) file(COPY ${CMAKE_SOURCE_DIR}/resource/conf DESTINATION ${RESOURCE_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) -endif() +endif () -if(APPLICATION_BUILD) - if(${CMAKE_BUILD_TYPE} STREQUAL "Release") - if(APPLE) +if (APPLICATION_BUILD) + if (${CMAKE_BUILD_TYPE} STREQUAL "Release") + if (APPLE) file(COPY ${CMAKE_SOURCE_DIR}/gpgfrontend.icns DESTINATION ${RESOURCE_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) # Refresh App Bundle file(REMOVE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${AppName}.app) - elseif(LINUX) + elseif (LINUX) file(REMOVE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gpgfrontend/usr/bin/${AppName}) - endif() - endif() -endif() + endif () + endif () +endif () -if(APPLICATION_BUILD) +if (APPLICATION_BUILD) # Copy Utils Files - if(MINGW) + if (MINGW) message(STATUS "Copying Dependent DLL For Windows Runtime Env") file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/lib/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/gpgme/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) @@ -105,59 +105,72 @@ if(APPLICATION_BUILD) file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/printsupport DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/platforms DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) file(COPY ${CMAKE_SOURCE_DIR}/resource/utils/openssl/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN) - endif() -endif() + endif () +endif () -if(APPLICATION_BUILD) +if (APPLICATION_BUILD) set(RESOURCE_FILES ${CMAKE_SOURCE_DIR}/gpgfrontend.qrc ${APP_ICON_RESOURCE_WINDOWS} ${QON_QM_FILES}) add_custom_target(resources ALL DEPENDS ${RESOURCE_FILES}) - if(MULTI_LANG_SUPPORT) + if (MULTI_LANG_SUPPORT) add_dependencies(resources translations) - endif() -endif() + endif () +endif () -if(APPLICATION_BUILD) - if(${CMAKE_BUILD_TYPE} STREQUAL "Release") - if(MINGW) +if (APPLICATION_BUILD) + if (${CMAKE_BUILD_TYPE} STREQUAL "Release") + if (MINGW) add_executable(${AppName} WIN32 ${BASE_SOURCE} ${RESOURCE_FILES} ${QT5_MOCS}) - elseif(APPLE) + elseif (APPLE) add_executable(${AppName} MACOSX_BUNDLE ${ICON_RESOURCE} ${BASE_SOURCE} ${RESOURCE_FILES} ${QT5_MOCS}) set_target_properties(${AppName} PROPERTIES - BUNDLE True - MACOSX_BUNDLE_GUI_IDENTIFIER pub.gpgfrontend.gpgfrontend - MACOSX_BUNDLE_BUNDLE_NAME ${AppName} - MACOSX_BUNDLE_LONG_VERSION_STRING ${BUILD_VERSION} - MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION} - MACOSX_BUNDLE_BUNDLE_VERSION ${BUILD_VERSION} - MACOSX_BUNDLE_ICON_FILE "gpgfrontend.icns") + BUNDLE True + MACOSX_BUNDLE_GUI_IDENTIFIER pub.gpgfrontend.gpgfrontend + MACOSX_BUNDLE_BUNDLE_NAME ${AppName} + MACOSX_BUNDLE_LONG_VERSION_STRING ${BUILD_VERSION} + MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION} + MACOSX_BUNDLE_BUNDLE_VERSION ${BUILD_VERSION} + MACOSX_BUNDLE_ICON_FILE "gpgfrontend.icns") add_custom_command(TARGET ${AppName} POST_BUILD - COMMAND /bin/rm -rf ./${AppName}.app/Contents/Resources - WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - COMMENT "Deleting Resources in App Bundle") + COMMAND /bin/rm -rf ./${AppName}.app/Contents/Resources + WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + COMMENT "Deleting Resources in App Bundle") add_custom_command(TARGET ${AppName} POST_BUILD - COMMAND /bin/mv -n ./Resources ./${AppName}.app/Contents/ - WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - COMMENT "Copying Resources into App Bundle Resource") - elseif(LINUX) + COMMAND /bin/mv -n ./Resources ./${AppName}.app/Contents/ + WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + COMMENT "Copying Resources into App Bundle Resource") + elseif (LINUX) add_executable(${AppName} ${BASE_SOURCE} ${RESOURCE_FILES} ${QT5_MOCS}) add_custom_command(TARGET ${AppName} POST_BUILD - COMMAND /bin/mkdir ./gpgfrontend/usr/bin && /bin/mv -f ./${AppName} ./gpgfrontend/usr/bin/ - WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - COMMENT "Copying Binary into App Image") + COMMAND /bin/mkdir ./gpgfrontend/usr/bin && /bin/mv -f ./${AppName} ./gpgfrontend/usr/bin/ + WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + COMMENT "Copying Binary into App Image") add_custom_command(TARGET ${AppName} POST_BUILD COMMAND /bin/mkdir ./gpgfrontend/usr/lib WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMENT "Complement to build the required architecture") - else() + else () add_executable(${AppName} ${BASE_SOURCE} ${RESOURCE_FILES} ${QT5_MOCS}) - endif() - else() + endif () + else () add_executable(${AppName} ${BASE_SOURCE} ${RESOURCE_FILES} ${QT5_MOCS}) - endif() -endif() + endif () +endif () + +if (APPLICATION_BUILD) + + if (ADVANCE_SUPPORT) + set(GPGFRONTEND_BEFORE_UI_LIBS ${GPGFRONTEND_BEFORE_UI_LIBS} advance) + endif () + if (ADVANCE_SUPPORT) + set(GPGFRONTEND_BEFORE_UI_LIBS ${GPGFRONTEND_BEFORE_UI_LIBS} server) + endif () + if (SMTP_SUPPORT) + set(GPGFRONTEND_AFTER_UI_LIBS ${GPGFRONTEND_AFTER_UI_LIBS} server) + endif () + + + set(GPGFRONTEND_LIBS ${GPGFRONTEND_AFTER_UI_LIBS} gpgfrontend-ui ${GPGFRONTEND_BEFORE_UI_LIBS} gpg_core easy_logging_pp) -if(APPLICATION_BUILD) - set(GPGFRONTEND_LIBS smtp gpgfrontend-ui advance server gpg_core) set(QT_DEPENDENCY_LIBS Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core) IF (MINGW) message(STATUS "Link Application Static Library For MINGW") @@ -165,18 +178,18 @@ if(APPLICATION_BUILD) ${GPGFRONTEND_LIBS} ${QT_DEPENDENCY_LIBS} crypto ssl) - elseif(APPLE) + elseif (APPLE) message(STATUS "Link Application Static Library For macOS") target_link_libraries(${AppName} ${GPGFRONTEND_LIBS} ${QT_DEPENDENCY_LIBS} crypto ssl) - else() + else () message(STATUS "Link Application Static Library For UNIX") target_link_libraries(${AppName} ${GPGFRONTEND_LIBS} ${QT_DEPENDENCY_LIBS} crypto ssl pthread) - endif() -endif() + endif () +endif () diff --git a/src/gpg/model/GpgKey.h b/src/gpg/model/GpgKey.h index 1aa307e6..ecebf3b2 100644 --- a/src/gpg/model/GpgKey.h +++ b/src/gpg/model/GpgKey.h @@ -74,7 +74,9 @@ class GpgKey { } [[nodiscard]] boost::gregorian::date last_update() const { - return boost::posix_time::from_time_t(_key_ref->last_update).date(); + return boost::posix_time::from_time_t( + static_cast<time_t>(_key_ref->last_update)) + .date(); } [[nodiscard]] boost::gregorian::date expires() const { diff --git a/src/main.cpp b/src/main.cpp index 1222adf3..f44d7ad3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,6 +25,9 @@ #include "GpgFrontendBuildInfo.h" #include "ui/MainWindow.h" +// Easy Logging Cpp +INITIALIZE_EASYLOGGINGPP + int main(int argc, char* argv[]) { Q_INIT_RESOURCE(gpgfrontend); @@ -77,12 +80,10 @@ int main(int argc, char* argv[]) { } qDebug() << "Language set" << lang; translator.load(RESOURCE_DIR(appPath) + "/ts/" + "gpgfrontend_" + lang); - qDebug() << "Translator" << translator.filePath(); QApplication::installTranslator(&translator); // set qt translations translator2.load(RESOURCE_DIR(appPath) + "/ts/qt_" + lang); - qDebug() << "Translator2" << translator2.filePath(); QApplication::installTranslator(&translator2); QApplication::setQuitOnLastWindowClosed(true); @@ -108,7 +109,7 @@ int main(int argc, char* argv[]) { gpgme_set_locale(nullptr, LC_MESSAGES, setlocale(LC_MESSAGES, nullptr)); #endif - MainWindow window; + GpgFrontend::UI::MainWindow window; return_from_event_loop_code = QApplication::exec(); } while (return_from_event_loop_code == RESTART_CODE); diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index ecf998d6..6e9ef497 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -6,7 +6,13 @@ aux_source_directory(./main_window UI_SOURCE) aux_source_directory(./help UI_SOURCE) aux_source_directory(./settings UI_SOURCE) -add_library(gpgfrontend-ui STATIC ${UI_SOURCE} GpgFrontendUI.h) +if (SMTP_SUPPORT) + message(STATUS "Build SMTP Support") + aux_source_directory(./smtp UI_SOURCE) +endif () + + +add_library(gpgfrontend-ui STATIC ${UI_SOURCE}) target_link_libraries(gpgfrontend-ui Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core)
\ No newline at end of file diff --git a/src/ui/KeyMgmt.cpp b/src/ui/KeyMgmt.cpp index 6d15a1eb..6a070188 100755 --- a/src/ui/KeyMgmt.cpp +++ b/src/ui/KeyMgmt.cpp @@ -218,9 +218,9 @@ void KeyMgmt::createToolBars() { keyToolBar->addAction(exportKeyToClipboardAct); } -void KeyMgmt::slotImportKeys(ByteArrayPtr in_buffer) { - GpgImportInformation result = - GpgKeyImportExportor::GetInstance().ImportKey(std::move(in_buffer)); +void KeyMgmt::slotImportKeys(const std::string& in_buffer) { + GpgImportInformation result = GpgKeyImportExportor::GetInstance().ImportKey( + std::make_unique<ByteArray>(in_buffer)); new KeyImportDetailDialog(result, false, this); } @@ -230,8 +230,7 @@ void KeyMgmt::slotImportKeyFromFile() { tr("Key Files") + " (*.asc *.txt);;" + tr("Keyring files") + " (*.gpg);;All Files (*)"); if (!file_name.isNull()) { - slotImportKeys(std::make_unique<ByteArray>( - read_all_data_in_file(file_name.toStdString()))); + slotImportKeys(read_all_data_in_file(file_name.toStdString())); } } @@ -242,8 +241,7 @@ void KeyMgmt::slotImportKeyFromKeyServer() { void KeyMgmt::slotImportKeyFromClipboard() { QClipboard* cb = QApplication::clipboard(); - slotImportKeys(std::make_unique<ByteArray>( - cb->text(QClipboard::Clipboard).toUtf8().toStdString())); + slotImportKeys(cb->text(QClipboard::Clipboard).toUtf8().toStdString()); } void KeyMgmt::slotDeleteSelectedKeys() { diff --git a/src/ui/KeyMgmt.h b/src/ui/KeyMgmt.h index deddb4f7..a0a4bb72 100755 --- a/src/ui/KeyMgmt.h +++ b/src/ui/KeyMgmt.h @@ -57,7 +57,7 @@ class KeyMgmt : public QMainWindow { void slotImportKeyFromKeyServer(); - void slotImportKeys(GpgFrontend::ByteArrayPtr in_buffer); + void slotImportKeys(const std::string& in_buffer); void slotExportKeyToFile(); diff --git a/src/ui/KeyServerImportDialog.cpp b/src/ui/KeyServerImportDialog.cpp index dae8f723..c4d2bdac 100644 --- a/src/ui/KeyServerImportDialog.cpp +++ b/src/ui/KeyServerImportDialog.cpp @@ -30,15 +30,14 @@ namespace GpgFrontend::UI { -KeyServerImportDialog::KeyServerImportDialog(KeyList* keyList, - bool automatic, +KeyServerImportDialog::KeyServerImportDialog(KeyList* keyList, bool automatic, QWidget* parent) : QDialog(parent), + mAutomatic(automatic), appPath(qApp->applicationDirPath()), settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", QSettings::IniFormat), - mKeyList(keyList), - mAutomatic(automatic) { + mKeyList(keyList) { if (automatic) { setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); } @@ -79,8 +78,7 @@ KeyServerImportDialog::KeyServerImportDialog(KeyList* keyList, // Layout for import and close button auto* buttonsLayout = new QHBoxLayout; buttonsLayout->addStretch(); - if (!automatic) - buttonsLayout->addWidget(importButton); + if (!automatic) buttonsLayout->addWidget(importButton); buttonsLayout->addWidget(closeButton); auto* mainLayout = new QGridLayout; @@ -353,10 +351,14 @@ void KeyServerImportDialog::slotImport() { } } -void KeyServerImportDialog::slotImport(const QStringList& keyIds) { +void KeyServerImportDialog::slotImport(const KeyIdArgsListPtr& keys) { QString keyserver = settings.value("keyserver/defaultKeyServer").toString(); qDebug() << "Select Key Server" << keyserver; - slotImport(keyIds, QUrl(keyserver)); + auto key_ids = QStringList(); + for (const auto& key_id : *keys) { + key_ids.append(QString::fromStdString(key_id)); + } + slotImport(key_ids, QUrl(keyserver)); } void KeyServerImportDialog::slotImportKey(const KeyIdArgsListPtr& keys) { diff --git a/src/ui/KeyServerImportDialog.h b/src/ui/KeyServerImportDialog.h index 615a77c6..061329b4 100644 --- a/src/ui/KeyServerImportDialog.h +++ b/src/ui/KeyServerImportDialog.h @@ -22,8 +22,8 @@ * */ -#ifndef __KEYSERVERIMPORTDIALOG_H__ -#define __KEYSERVERIMPORTDIALOG_H__ +#ifndef __KEY_SERVER_IMPORT_DIALOG_H__ +#define __KEY_SERVER_IMPORT_DIALOG_H__ #include "KeyImportDetailDialog.h" #include "gpg/GpgContext.h" @@ -40,7 +40,7 @@ class KeyServerImportDialog : public QDialog { KeyServerImportDialog(QWidget* parent); - void slotImport(const QStringList& keyIds); + void slotImport(const KeyIdArgsListPtr& keys); void slotImport(const QStringList& keyIds, const QUrl& keyserverUrl); @@ -91,4 +91,4 @@ class KeyServerImportDialog : public QDialog { } // namespace GpgFrontend::UI -#endif // __KEYSERVERIMPORTDIALOG_H__ +#endif // __KEY_SERVER_IMPORT_DIALOG_H__ diff --git a/src/ui/KeyUploadDialog.cpp b/src/ui/KeyUploadDialog.cpp index 06b1d074..da905e8e 100644 --- a/src/ui/KeyUploadDialog.cpp +++ b/src/ui/KeyUploadDialog.cpp @@ -57,10 +57,11 @@ KeyUploadDialog::KeyUploadDialog(const KeyIdArgsListPtr& keys_ids, void KeyUploadDialog::slotUpload() { auto out_data = std::make_unique<ByteArray>(); GpgKeyImportExportor::GetInstance().ExportKeys(*mKeys, out_data); - uploadKeyToServer(std::move(out_data)); + uploadKeyToServer(*out_data); } -void KeyUploadDialog::uploadKeyToServer(ByteArrayPtr keys_data) { +void KeyUploadDialog::uploadKeyToServer( + const GpgFrontend::ByteArray& keys_data) { // set default keyserver QString keyserver = settings.value("keyserver/defaultKeyServer").toString(); @@ -70,7 +71,7 @@ void KeyUploadDialog::uploadKeyToServer(ByteArrayPtr keys_data) { // Building Post Data QByteArray postData; - auto& data = *keys_data; + auto data = std::string(keys_data); boost::algorithm::replace_all(data, "\n", "%0A"); boost::algorithm::replace_all(data, "\r", "%0D"); @@ -79,8 +80,8 @@ void KeyUploadDialog::uploadKeyToServer(ByteArrayPtr keys_data) { boost::algorithm::replace_all(data, "/", "%2F"); boost::algorithm::replace_all(data, ":", "%3A"); boost::algorithm::replace_all(data, "+", "%2B"); - boost::algorithm::replace_all(data, '=', "%3D"); - boost::algorithm::replace_all(data, ' ', '+'); + boost::algorithm::replace_all(data, "=", "%3D"); + boost::algorithm::replace_all(data, " ", "+"); QNetworkRequest request(reqUrl); request.setHeader(QNetworkRequest::ContentTypeHeader, diff --git a/src/ui/KeyUploadDialog.h b/src/ui/KeyUploadDialog.h index b57440d4..bf7533cb 100644 --- a/src/ui/KeyUploadDialog.h +++ b/src/ui/KeyUploadDialog.h @@ -41,7 +41,7 @@ class KeyUploadDialog : public QDialog { private slots: - void uploadKeyToServer(GpgFrontend::ByteArrayPtr keys_data); + void uploadKeyToServer(const GpgFrontend::ByteArray& keys_data); void slotUploadFinished(); diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index 33478b8a..497463aa 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -126,6 +126,9 @@ MainWindow::MainWindow() } } edit->curTextPage()->setFocus(); + + waitingDialog->close(); + this->setMinimumSize(1200, 700); this->setWindowTitle(qApp->applicationName()); this->show(); @@ -210,7 +213,7 @@ void MainWindow::saveSettings() { auto keyIds = mKeyList->getChecked(); if (!keyIds->empty()) { QStringList key_ids_str_list; - for (const auto& key_id : keyIds) + for (const auto& key_id : *keyIds) key_ids_str_list << QString::fromStdString(key_id); settings.setValue("keys/savedCheckedKeyList", key_ids_str_list); } else { diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index 333ee971..f6de47d8 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -26,22 +26,21 @@ #define __GPGWIN_H__ #include "gpg/GpgConstants.h" +#include "gpg/result_analyse/DecryptResultAnalyse.h" +#include "gpg/result_analyse/EncryptResultAnalyse.h" +#include "gpg/result_analyse/SignResultAnalyse.h" #include "ui/FileEncryptionDialog.h" #include "ui/FindWidget.h" #include "ui/GpgFrontendUI.h" #include "ui/KeyMgmt.h" #include "ui/KeyUploadDialog.h" -#include "ui/SettingsDialog.h" #include "ui/WaitingDialog.h" #include "ui/Wizard.h" #include "ui/help/AboutDialog.h" +#include "ui/settings/SettingsDialog.h" #include "ui/widgets/InfoBoardWidget.h" #include "ui/widgets/TextEdit.h" -#include "gpg/result_analyse/DecryptResultAnalyse.h" -#include "gpg/result_analyse/EncryptResultAnalyse.h" -#include "gpg/result_analyse/SignResultAnalyse.h" - namespace GpgFrontend::UI { /** * @brief @@ -318,6 +317,8 @@ class MainWindow : public QMainWindow { */ void saveSettings(); +#ifdef ADVANCE_SUPPORT + /** * @details Get full crypto text */ @@ -328,6 +329,8 @@ class MainWindow : public QMainWindow { */ void shortenCryptText(); +#endif + /** * @brief return true, if restart is needed */ diff --git a/src/ui/SettingsDialog.h b/src/ui/SettingsDialog.h deleted file mode 100755 index d205f8fe..00000000 --- a/src/ui/SettingsDialog.h +++ /dev/null @@ -1,255 +0,0 @@ -/** - * 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. - * - * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. - * - * The initial version of the source code is inherited from gpg4usb-team. - * Their source code version also complies with GNU General Public License. - * - * The source code version of this software was modified and released - * by Saturneric<[email protected]> starting on May 12, 2021. - * - */ - -#ifndef __SETTINGSDIALOG_H__ -#define __SETTINGSDIALOG_H__ - -#include "ui/GpgFrontendUI.h" -#include "ui/widgets/KeyList.h" - -namespace GpgFrontend::UI { - -class GeneralTab : public QWidget { - Q_OBJECT - - public: - explicit GeneralTab(QWidget* parent = nullptr); - - void setSettings(); - - void applySettings(); - - private: - QString appPath; - QSettings settings; - - QComboBox* serverSelectBox; - QCheckBox* saveCheckedKeysCheckBox; - QCheckBox* importConfirmationCheckBox; - QComboBox* langSelectBox; - QComboBox* ownKeySelectBox; - QPushButton* getServiceTokenButton; - QLabel* serviceTokenLabel; - QHash<QString, QString> lang; - - std::unordered_map<std::string, std::string> keyIds; - std::vector<std::string> keyIdsList; - std::string serviceToken; - KeyList* mKeyList; - - private slots: - - void slotOwnKeyIdChanged(); - - void slotLanguageChanged(); - - void slotGetServiceToken(); - - signals: - - void signalRestartNeeded(bool needed); -}; - -class SendMailTab : public QWidget { - Q_OBJECT - - public: - explicit SendMailTab(QWidget* parent = nullptr); - - void setSettings(); - - void applySettings(); - - private slots: - - void slotCheckConnection(); - - void slotCheckBoxSetEnableDisable(int state); - - private: - QString appPath; - QSettings settings; - - QCheckBox* enableCheckBox; - - QLineEdit* smtpAddress; - QLineEdit* username; - QLineEdit* password; - QSpinBox* portSpin; - QComboBox* connectionTypeComboBox; - QLineEdit* defaultSender; - - QPushButton* checkConnectionButton; - - signals: - - void signalRestartNeeded(bool needed); -}; - -class AppearanceTab : public QWidget { - Q_OBJECT - - public: - // void setSettings(); - explicit AppearanceTab(QWidget* parent = nullptr); - - void setSettings(); - - void applySettings(); - - private: - QString appPath; - QSettings settings; - - QButtonGroup* iconStyleGroup; - QRadioButton* iconSizeSmall; - QRadioButton* iconSizeMedium; - QRadioButton* iconSizeLarge; - QButtonGroup* iconSizeGroup; - QRadioButton* iconTextButton; - QRadioButton* iconIconsButton; - QRadioButton* iconAllButton; - QSpinBox* infoBoardFontSizeSpin; - QCheckBox* windowSizeCheckBox; - - signals: - - void signalRestartNeeded(bool needed); -}; - -class KeyserverTab : public QWidget { - Q_OBJECT - - public: - explicit KeyserverTab(QWidget* parent = nullptr); - - void setSettings(); - - void applySettings(); - - private: - QString appPath; - QSettings settings; - QComboBox* comboBox; - QLineEdit* newKeyServerEdit; - QTableWidget* keyServerTable; - QStringList keyServerStrList; - - private slots: - - void addKeyServer(); - - void refreshTable(); - - signals: - - void signalRestartNeeded(bool needed); -}; - -class AdvancedTab : public QWidget { - Q_OBJECT - - public: - explicit AdvancedTab(QWidget* parent = nullptr); - - void setSettings(); - - void applySettings(); - - private: - QString appPath; - QSettings settings; - - QCheckBox* steganoCheckBox; - QCheckBox* autoPubkeyExchangeCheckBox; - - signals: - - void signalRestartNeeded(bool needed); -}; - -class GpgPathsTab : public QWidget { - Q_OBJECT - public: - explicit GpgPathsTab(QWidget* parent = nullptr); - - void applySettings(); - - private: - static QString getRelativePath(const QString& dir1, const QString& dir2); - - QString appPath; - QSettings settings; - - QString defKeydbPath; /** The default keydb path used by gpg4usb */ - QString accKeydbPath; /** The currently used keydb path */ - QLabel* keydbLabel; - - void setSettings(); - - private slots: - - QString chooseKeydbDir(); - - void setKeydbPathToDefault(); -}; - -class SettingsDialog : public QDialog { - Q_OBJECT - - public: - explicit SettingsDialog(QWidget* parent = nullptr); - - GeneralTab* generalTab; - SendMailTab* sendMailTab; - AppearanceTab* appearanceTab; - KeyserverTab* keyserverTab; - AdvancedTab* advancedTab; - GpgPathsTab* gpgPathsTab; - - static QHash<QString, QString> listLanguages(); - - public slots: - - void slotAccept(); - - signals: - - void signalRestartNeeded(bool needed); - - private: - QTabWidget* tabWidget; - QDialogButtonBox* buttonBox; - bool restartNeeded{}; - - bool getRestartNeeded() const; - - private slots: - - void slotSetRestartNeeded(bool needed); -}; - -} // namespace GpgFrontend::UI - -#endif // __SETTINGSDIALOG_H__ diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp new file mode 100644 index 00000000..8a6021c0 --- /dev/null +++ b/src/ui/UserInterfaceUtils.cpp @@ -0,0 +1,80 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#include "UserInterfaceUtils.h" + +#include "gpg/result_analyse/ResultAnalyse.h" +#include "ui/WaitingDialog.h" +#include "ui/widgets/InfoBoardWidget.h" +#include "ui/widgets/TextEdit.h" + +namespace GpgFrontend::UI { +void refresh_info_board(InfoBoardWidget* info_board, int status, + const std::string& report_text) { + if (status < 0) + info_board->slotRefresh(QString::fromStdString(report_text), + INFO_ERROR_CRITICAL); + else if (status > 0) + info_board->slotRefresh(QString::fromStdString(report_text), INFO_ERROR_OK); + else + info_board->slotRefresh(QString::fromStdString(report_text), + INFO_ERROR_WARN); +} + +void process_result_analyse(TextEdit* edit, InfoBoardWidget* info_board, + const ResultAnalyse& result_analyse) { + info_board->associateTabWidget(edit->tabWidget); + info_board->associateFileTreeView(edit->curFilePage()); + refresh_info_board(info_board, result_analyse.getStatus(), + result_analyse.getResultReport()); +} + +void process_result_analyse(TextEdit* edit, InfoBoardWidget* info_board, + const ResultAnalyse& result_analyse_a, + const ResultAnalyse& result_analyse_b) { + info_board->associateTabWidget(edit->tabWidget); + info_board->associateFileTreeView(edit->curFilePage()); + + refresh_info_board( + info_board, + std::min(result_analyse_a.getStatus(), result_analyse_a.getStatus()), + result_analyse_a.getResultReport() + result_analyse_a.getResultReport()); +} + +void process_operation(QWidget* parent, const std::string& waiting_title, + const std::function<void()>& func) { + auto thread = QThread::create(func); + QApplication::connect(thread, SIGNAL(finished()), thread, + SLOT(deleteLater())); + thread->start(); + + auto* dialog = + new WaitingDialog(QString::fromStdString(waiting_title), parent); + while (thread->isRunning()) { + QApplication::processEvents(); + } + dialog->close(); +} + +} // namespace GpgFrontend::UI
\ No newline at end of file diff --git a/src/ui/UserInterfaceUtils.h b/src/ui/UserInterfaceUtils.h new file mode 100644 index 00000000..979cebe6 --- /dev/null +++ b/src/ui/UserInterfaceUtils.h @@ -0,0 +1,54 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef GPGFRONTEND_USER_INTERFACE_UTILS_H +#define GPGFRONTEND_USER_INTERFACE_UTILS_H + +#include "ui/GpgFrontendUI.h" + +namespace GpgFrontend { +class ResultAnalyse; +} + +namespace GpgFrontend::UI { + +class InfoBoardWidget; +class TextEdit; + +void refresh_info_board(InfoBoardWidget* info_board, int status, + const std::string& report_text); + +void process_result_analyse(TextEdit* edit, InfoBoardWidget* info_board, + const ResultAnalyse& result_analyse); + +void process_result_analyse(TextEdit* edit, InfoBoardWidget* info_board, + const ResultAnalyse& result_analyse_a, + const ResultAnalyse& result_analyse_b); + +void process_operation(QWidget* parent, const std::string& waiting_title, + const std::function<void()>& func); + +} // namespace GpgFrontend::UI + +#endif // GPGFRONTEND_USER_INTERFACE_UTILS_H diff --git a/src/ui/WaitingDialog.h b/src/ui/WaitingDialog.h index a81ab9ce..342360fd 100644 --- a/src/ui/WaitingDialog.h +++ b/src/ui/WaitingDialog.h @@ -22,6 +22,9 @@ * */ +#ifndef __UI_WAITING_DIALOG_H__ +#define __UI_WAITING_DIALOG_H__ + #include "ui/GpgFrontendUI.h" namespace GpgFrontend::UI { @@ -39,3 +42,5 @@ class WaitingDialog : public QDialog { }; } // namespace GpgFrontend::UI + +#endif // __UI_WAITING_DIALOG_H__ diff --git a/src/ui/Wizard.h b/src/ui/Wizard.h index cb6cd13e..41b1a745 100644 --- a/src/ui/Wizard.h +++ b/src/ui/Wizard.h @@ -25,11 +25,11 @@ #ifndef WIZARD_H #define WIZARD_H -#include "SettingsDialog.h" #include "gpg/GpgConstants.h" #include "ui/GpgFrontendUI.h" #include "ui/KeyMgmt.h" #include "ui/keygen/KeygenDialog.h" +#include "ui/settings/SettingsDialog.h" namespace GpgFrontend::UI { diff --git a/src/ui/keypair_details/KeyPairDetailTab.cpp b/src/ui/keypair_details/KeyPairDetailTab.cpp index fe95a10e..65b38b84 100644 --- a/src/ui/keypair_details/KeyPairDetailTab.cpp +++ b/src/ui/keypair_details/KeyPairDetailTab.cpp @@ -264,7 +264,7 @@ void KeyPairDetailTab::slotCopyFingerprint() { } void KeyPairDetailTab::slotModifyEditDatetime() { - auto dialog = new KeySetExpireDateDialog(mKey, this); + auto dialog = new KeySetExpireDateDialog(mKey.id(), this); dialog->show(); } diff --git a/src/ui/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/keypair_details/KeyPairSubkeyTab.cpp index 84d9f558..a56885d1 100644 --- a/src/ui/keypair_details/KeyPairSubkeyTab.cpp +++ b/src/ui/keypair_details/KeyPairSubkeyTab.cpp @@ -28,8 +28,7 @@ namespace GpgFrontend::UI { KeyPairSubkeyTab::KeyPairSubkeyTab(const std::string& key_id, QWidget* parent) - : mKey(std::move(GpgKeyGetter::GetInstance().GetKey(key_id))), - QWidget(parent) { + : QWidget(parent), mKey(GpgKeyGetter::GetInstance().GetKey(key_id)) { createSubkeyList(); createSubkeyOperaMenu(); @@ -179,7 +178,7 @@ void KeyPairSubkeyTab::slotRefreshSubkeyList() { } void KeyPairSubkeyTab::slotAddSubkey() { - auto dialog = new SubkeyGenerateDialog(mKey, this); + auto dialog = new SubkeyGenerateDialog(mKey.id(), this); dialog->show(); } @@ -252,12 +251,9 @@ void KeyPairSubkeyTab::createSubkeyOperaMenu() { } void KeyPairSubkeyTab::slotEditSubkey() { - qDebug() << "Slot Edit Subkry"; - auto subkey_id = std::make_unique<std::string>(getSelectedSubkey().id()); - if (*subkey_id == buffered_subkeys[0].id()) { - subkey_id = nullptr; - } - auto dialog = new KeySetExpireDateDialog(mKey, subkey_id, this); + qDebug() << "Slot Edit Subkey"; + auto dialog = + new KeySetExpireDateDialog(mKey.id(), getSelectedSubkey().id(), this); dialog->show(); } diff --git a/src/ui/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/keypair_details/KeySetExpireDateDialog.cpp index 788adf44..7d681a6e 100644 --- a/src/ui/keypair_details/KeySetExpireDateDialog.cpp +++ b/src/ui/keypair_details/KeySetExpireDateDialog.cpp @@ -24,6 +24,8 @@ #include "ui/keypair_details/KeySetExpireDateDialog.h" +#include <utility> + #include "gpg/function/GpgKeyGetter.h" #include "gpg/function/GpgKeyOpera.h" @@ -36,11 +38,11 @@ KeySetExpireDateDialog::KeySetExpireDateDialog(const KeyId& key_id, } KeySetExpireDateDialog::KeySetExpireDateDialog(const KeyId& key_id, - const std::string& subkey_id, + std::string subkey_id, QWidget* parent) : QDialog(parent), mKey(GpgKeyGetter::GetInstance().GetKey(key_id)), - mSubkey(subkey_id) { + mSubkey(std::move(subkey_id)) { init(); } diff --git a/src/ui/keypair_details/KeySetExpireDateDialog.h b/src/ui/keypair_details/KeySetExpireDateDialog.h index d7c19eaa..09153956 100644 --- a/src/ui/keypair_details/KeySetExpireDateDialog.h +++ b/src/ui/keypair_details/KeySetExpireDateDialog.h @@ -39,11 +39,10 @@ class KeySetExpireDateDialog : public QDialog { QWidget* parent = nullptr); explicit KeySetExpireDateDialog(const KeyId& key_id, - const std::string& subkey_id, + std::string subkey_id, QWidget* parent = nullptr); private: - void init(); const GpgKey mKey; diff --git a/src/ui/main_window/MainWindowFileSlotFunction.cpp b/src/ui/main_window/MainWindowFileSlotFunction.cpp index 2719b103..933579b0 100644 --- a/src/ui/main_window/MainWindowFileSlotFunction.cpp +++ b/src/ui/main_window/MainWindowFileSlotFunction.cpp @@ -23,14 +23,12 @@ */ #include "MainWindow.h" - #include "gpg/function/GpgFileOpera.h" #include "gpg/function/GpgKeyGetter.h" namespace GpgFrontend::UI { -void refresh_info_board(InfoBoardWidget* info_board, - int status, +void refresh_info_board(InfoBoardWidget* info_board, int status, const std::string& report_text) { if (status < 0) info_board->slotRefresh(QString::fromStdString(report_text), @@ -42,8 +40,7 @@ void refresh_info_board(InfoBoardWidget* info_board, INFO_ERROR_WARN); } -void process_result_analyse(TextEdit* edit, - InfoBoardWidget* info_board, +void process_result_analyse(TextEdit* edit, InfoBoardWidget* info_board, const ResultAnalyse& result_analyse) { info_board->associateTabWidget(edit->tabWidget); info_board->associateFileTreeView(edit->curFilePage()); @@ -51,8 +48,7 @@ void process_result_analyse(TextEdit* edit, result_analyse.getResultReport()); } -void process_result_analyse(TextEdit* edit, - InfoBoardWidget* info_board, +void process_result_analyse(TextEdit* edit, InfoBoardWidget* info_board, const ResultAnalyse& result_analyse_a, const ResultAnalyse& result_analyse_b) { info_board->associateTabWidget(edit->tabWidget); @@ -85,9 +81,8 @@ bool file_pre_check(QWidget* parent, const QString& path) { return true; } -void process_operation(QWidget* parent, - std::string waiting_title, - std::function<void()> func) { +void process_operation(QWidget* parent, const std::string& waiting_title, + const std::function<void()>& func) { GpgEncrResult result = nullptr; gpgme_error_t error; @@ -109,8 +104,7 @@ void MainWindow::slotFileEncrypt() { auto fileTreeView = edit->slotCurPageFileTreeView(); auto path = fileTreeView->getSelected(); - if (!file_pre_check(this, path)) - return; + if (!file_pre_check(this, path)) return; if (QFile::exists(path + ".asc")) { auto ret = QMessageBox::warning( @@ -118,8 +112,7 @@ void MainWindow::slotFileEncrypt() { tr("The target file already exists, do you need to overwrite it?"), QMessageBox::Ok | QMessageBox::Cancel); - if (ret == QMessageBox::Cancel) - return; + if (ret == QMessageBox::Cancel) return; } auto key_ids = mKeyList->getChecked(); @@ -169,8 +162,7 @@ void MainWindow::slotFileDecrypt() { auto fileTreeView = edit->slotCurPageFileTreeView(); auto path = fileTreeView->getSelected(); - if (!file_pre_check(this, path)) - return; + if (!file_pre_check(this, path)) return; QString outFileName, fileExtension = QFileInfo(path).suffix(); @@ -187,8 +179,7 @@ void MainWindow::slotFileDecrypt() { tr("The target file already exists, do you need to overwrite it?"), QMessageBox::Ok | QMessageBox::Cancel); - if (ret == QMessageBox::Cancel) - return; + if (ret == QMessageBox::Cancel) return; } GpgDecrResult result = nullptr; @@ -220,8 +211,7 @@ void MainWindow::slotFileSign() { auto fileTreeView = edit->slotCurPageFileTreeView(); auto path = fileTreeView->getSelected(); - if (!file_pre_check(this, path)) - return; + if (!file_pre_check(this, path)) return; if (QFile::exists(path + ".sig")) { auto ret = QMessageBox::warning( @@ -229,8 +219,7 @@ void MainWindow::slotFileSign() { tr("The target file already exists, do you need to overwrite it?"), QMessageBox::Ok | QMessageBox::Cancel); - if (ret == QMessageBox::Cancel) - return; + if (ret == QMessageBox::Cancel) return; } auto key_ids = mKeyList->getChecked(); @@ -359,8 +348,7 @@ void MainWindow::slotFileEncryptSign() { auto fileTreeView = edit->slotCurPageFileTreeView(); auto path = fileTreeView->getSelected(); - if (!file_pre_check(this, path)) - return; + if (!file_pre_check(this, path)) return; if (QFile::exists(path + ".gpg")) { auto ret = QMessageBox::warning( @@ -368,8 +356,7 @@ void MainWindow::slotFileEncryptSign() { tr("The target file already exists, do you need to overwrite it?"), QMessageBox::Ok | QMessageBox::Cancel); - if (ret == QMessageBox::Cancel) - return; + if (ret == QMessageBox::Cancel) return; } auto key_ids = mKeyList->getChecked(); @@ -396,10 +383,8 @@ void MainWindow::slotFileEncryptSign() { return; } - if (key_can_sign) - can_sign = true; - if (key_can_encr) - can_encr = true; + if (key_can_sign) can_sign = true; + if (key_can_encr) can_encr = true; } if (!can_encr) { @@ -450,8 +435,7 @@ void MainWindow::slotFileDecryptVerify() { auto fileTreeView = edit->slotCurPageFileTreeView(); auto path = fileTreeView->getSelected(); - if (!file_pre_check(this, path)) - return; + if (!file_pre_check(this, path)) return; QString outFileName, fileExtension = QFileInfo(path).suffix(); diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index 0dcbd506..9107e4d7 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -31,7 +31,14 @@ #include "server/api/PubkeyUploader.h" #endif -#include "ui/SendMailDialog.h" +#ifdef SMTP_SUPPORT +#include "ui/smtp/SendMailDialog.h" +#endif + +#include "gpg/function/BasicOperator.h" +#include "gpg/function/GpgKeyGetter.h" +#include "gpg/function/GpgKeyImportExportor.h" +#include "ui/UserInterfaceUtils.h" #include "ui/widgets/SignersPicker.h" namespace GpgFrontend::UI { @@ -39,156 +46,140 @@ namespace GpgFrontend::UI { * Encrypt Entry(Text & File) */ void MainWindow::slotEncrypt() { - if (edit->tabCount() == 0) - return; + if (edit->tabCount() == 0) return; if (edit->slotCurPageTextEdit() != nullptr) { - auto keys = mKeyList->getChecked(keys); + auto key_ids = mKeyList->getChecked(); - if (keys.count() == 0) { + if (key_ids->empty()) { QMessageBox::critical(nullptr, tr("No Key Selected"), tr("No Key Selected")); return; } - for (const auto& key : keys) { - if (!GpgFrontend::GpgContext::checkIfKeyCanEncr(key)) { + auto key_getter = GpgFrontend::GpgKeyGetter::GetInstance(); + auto keys = GpgKeyGetter::GetInstance().GetKeys(key_ids); + for (const auto& key : *keys) { + if (!key.CanEncrActual()) { QMessageBox::information( nullptr, tr("Invalid Operation"), tr("The selected key contains a key that does not actually have a " "encrypt usage.<br/>") + tr("<br/>For example the Following Key: <br/>") + - key.uids.first().uid); + QString::fromStdString(key.uids()->front().uid())); return; } } - auto tmp = QByteArray(); - - gpgme_encrypt_result_t result = nullptr; - - gpgme_error_t error; - - auto thread = QThread::create([&]() { - error = mCtx->encrypt(keys, edit->curTextPage()->toPlainText().toUtf8(), - &tmp, &result); + auto tmp = std::make_unique<ByteArray>(); + + GpgEncrResult result = nullptr; + GpgError error; + bool if_error = false; + process_operation(this, tr("Encrypting").toStdString(), [&]() { + try { + auto buffer = edit->curTextPage()->toPlainText().toUtf8().toStdString(); + error = GpgFrontend::BasicOperator::GetInstance().Encrypt( + std::move(*keys), buffer, tmp, result); + } catch (const std::runtime_error& e) { + if_error = true; + } }); - connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); - thread->start(); - - auto* dialog = new WaitingDialog(tr("Encrypting"), this); - - while (thread->isRunning()) - QApplication::processEvents(); - - dialog->close(); - auto resultAnalyse = new EncryptResultAnalyse(error, result); - auto& reportText = resultAnalyse->getResultReport(); - - auto tmp2 = QString(tmp); - edit->slotFillTextEditWithText(tmp2); - infoBoard->associateTextEdit(edit->curTextPage()); - - // check result analyse status - if (resultAnalyse->getStatus() < 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); - else if (resultAnalyse->getStatus() > 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_OK); - else - infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); + if (!if_error) { + edit->slotFillTextEditWithText(QString::fromStdString(*tmp)); + auto resultAnalyse = EncryptResultAnalyse(error, std::move(result)); + resultAnalyse.analyse(); + process_result_analyse(edit, infoBoard, resultAnalyse); + +#ifdef SMTP_SUPPORT + // set optional actions + if (resultAnalyse.getStatus() >= 0) { + infoBoard->resetOptionActionsMenu(); + infoBoard->addOptionalAction("Send Mail", [this]() { + if (settings.value("sendMail/enable", false).toBool()) + new SendMailDialog(edit->curTextPage()->toPlainText(), this); + else { + QMessageBox::warning(nullptr, tr("Function Disabled"), + tr("Please go to the settings interface to " + "enable and configure this function.")); + } + }); + } +#endif - // set optional actions - if (resultAnalyse->getStatus() >= 0) { - infoBoard->resetOptionActionsMenu(); - infoBoard->addOptionalAction("Send Mail", [this]() { - if (settings.value("sendMail/enable", false).toBool()) - new SendMailDialog(edit->curTextPage()->toPlainText(), this); - else { - QMessageBox::warning(nullptr, tr("Function Disabled"), - tr("Please go to the settings interface to " - "enable and configure this function.")); - } - }); + } else { + QMessageBox::critical(this, tr("Error"), + tr("An error occurred during operation.")); + return; } - delete resultAnalyse; } else if (edit->slotCurPageFileTreeView() != nullptr) { this->slotFileEncrypt(); } } void MainWindow::slotSign() { - if (edit->tabCount() == 0) - return; + if (edit->tabCount() == 0) return; if (edit->slotCurPageTextEdit() != nullptr) { - QVector<GpgKey> keys; - - mKeyList->getPrivateCheckedKeys(keys); + auto key_ids = mKeyList->getPrivateChecked(); - if (keys.isEmpty()) { + if (key_ids->empty()) { QMessageBox::critical(this, tr("No Key Selected"), tr("No Key Selected")); return; } - for (const auto& key : keys) { - if (!GpgFrontend::GpgContext::checkIfKeyCanSign(key)) { + auto keys = GpgKeyGetter::GetInstance().GetKeys(key_ids); + for (const auto& key : *keys) { + if (!key.CanSignActual()) { QMessageBox::information( this, tr("Invalid Operation"), tr("The selected key contains a key that does not actually have a " "signature usage.<br/>") + tr("<br/>For example the Following Key: <br/>") + - key.uids.first().uid); + QString::fromStdString(key.uids()->front().uid())); return; } } - auto tmp = QByteArray(); - - gpgme_sign_result_t result = nullptr; + auto tmp = std::make_unique<ByteArray>(); + GpgSignResult result = nullptr; gpgme_error_t error; - auto thread = QThread::create([&]() { - error = mCtx->sign(keys, edit->curTextPage()->toPlainText().toUtf8(), - &tmp, GPGME_SIG_MODE_CLEAR, &result); + bool if_error = false; + + process_operation(this, tr("Signing").toStdString(), [&]() { + try { + auto buffer = edit->curTextPage()->toPlainText().toUtf8().toStdString(); + error = GpgFrontend::BasicOperator::GetInstance().Sign( + std::move(*keys), buffer, tmp, GPGME_SIG_MODE_CLEAR, result); + } catch (const std::runtime_error& e) { + if_error = true; + } }); - connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); - thread->start(); - auto* dialog = new WaitingDialog(tr("Signing"), this); - while (thread->isRunning()) { - QApplication::processEvents(); + if (!if_error) { + auto resultAnalyse = SignResultAnalyse(error, std::move(result)); + resultAnalyse.analyse(); + process_result_analyse(edit, infoBoard, resultAnalyse); + edit->slotFillTextEditWithText(QString::fromStdString(*tmp)); + } else { + QMessageBox::critical(this, tr("Error"), + tr("An error occurred during operation.")); + return; } - dialog->close(); - - infoBoard->associateTextEdit(edit->curTextPage()); - edit->slotFillTextEditWithText(QString::fromUtf8(tmp)); - - auto resultAnalyse = new SignResultAnalyse(mCtx, error, result); - - auto& reportText = resultAnalyse->getResultReport(); - if (resultAnalyse->getStatus() < 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); - else if (resultAnalyse->getStatus() > 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_OK); - else - infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); - - delete resultAnalyse; } else if (edit->slotCurPageFileTreeView() != nullptr) { this->slotFileSign(); } } void MainWindow::slotDecrypt() { - if (edit->tabCount() == 0) - return; + if (edit->tabCount() == 0) return; if (edit->slotCurPageTextEdit() != nullptr) { - auto decrypted = QByteArray(); + auto decrypted = std::make_unique<ByteArray>(); QByteArray text = edit->curTextPage()->toPlainText().toUtf8(); - GpgFrontend::GpgContext::preventNoDataErr(&text); if (text.trimmed().startsWith( GpgConstants::GPG_FRONTEND_SHORT_CRYPTO_HEAD)) { @@ -198,39 +189,31 @@ void MainWindow::slotDecrypt() { return; } - gpgme_decrypt_result_t result = nullptr; - + GpgDecrResult result = nullptr; gpgme_error_t error; - auto thread = QThread::create([&]() { - // try decrypt, if fail do nothing, especially don't replace text - error = mCtx->decrypt(text, &decrypted, &result); + bool if_error = false; + process_operation(this, tr("Decrypting").toStdString(), [&]() { + try { + auto buffer = text.toStdString(); + error = GpgFrontend::BasicOperator::GetInstance().Decrypt( + buffer, decrypted, result); + } catch (const std::runtime_error& e) { + if_error = true; + } }); - connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); - thread->start(); - - auto* dialog = new WaitingDialog(tr("Decrypting"), this); - while (thread->isRunning()) { - QApplication::processEvents(); - } - - dialog->close(); - - infoBoard->associateTextEdit(edit->curTextPage()); - if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) - edit->slotFillTextEditWithText(QString::fromUtf8(decrypted)); + if (!if_error) { + auto resultAnalyse = DecryptResultAnalyse(error, std::move(result)); + resultAnalyse.analyse(); + process_result_analyse(edit, infoBoard, resultAnalyse); - auto resultAnalyse = new DecryptResultAnalyse(mCtx, error, result); - - auto& reportText = resultAnalyse->getResultReport(); - if (resultAnalyse->getStatus() < 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); - else if (resultAnalyse->getStatus() > 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_OK); - else - infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); - - delete resultAnalyse; + if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) + edit->slotFillTextEditWithText(QString::fromStdString(*decrypted)); + } else { + QMessageBox::critical(this, tr("Error"), + tr("An error occurred during operation.")); + return; + } } else if (edit->slotCurPageFileTreeView() != nullptr) { this->slotFileDecrypt(); } @@ -249,153 +232,137 @@ void MainWindow::slotFind() { } void MainWindow::slotVerify() { - if (edit->tabCount() == 0) - return; + if (edit->tabCount() == 0) return; if (edit->slotCurPageTextEdit() != nullptr) { QByteArray text = edit->curTextPage()->toPlainText().toUtf8(); - GpgFrontend::GpgContext::preventNoDataErr(&text); - - gpgme_verify_result_t result; + // TODO(Saturneric) PreventNoDataErr + + auto sig_buffer = std::make_unique<ByteArray>(nullptr); + + GpgVerifyResult result = nullptr; + GpgError error; + bool if_error = false; + process_operation(this, tr("Verifying").toStdString(), [&]() { + try { + auto buffer = text.toStdString(); + error = GpgFrontend::BasicOperator::GetInstance().Verify( + buffer, sig_buffer, result); + } catch (const std::runtime_error& e) { + if_error = true; + } + }); - gpgme_error_t error; - auto thread = QThread::create( - [&]() { error = mCtx->verify(&text, nullptr, &result); }); - connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); - thread->start(); - - auto* dialog = new WaitingDialog(tr("Verifying"), this); - while (thread->isRunning()) - QApplication::processEvents(); - dialog->close(); - - auto resultAnalyse = new VerifyResultAnalyse(mCtx, error, result); - infoBoard->associateTextEdit(edit->curTextPage()); - - auto& reportText = resultAnalyse->getResultReport(); - if (resultAnalyse->getStatus() < 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); - else if (resultAnalyse->getStatus() > 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_OK); - else - infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); - - if (resultAnalyse->getStatus() >= 0) { - infoBoard->resetOptionActionsMenu(); - infoBoard->addOptionalAction( - "Show Verify Details", [this, error, result]() { - VerifyDetailsDialog(this, mCtx, mKeyList, error, result); - }); + if (!if_error) { + auto resultAnalyse = VerifyResultAnalyse(error, std::move(result)); + resultAnalyse.analyse(); + process_result_analyse(edit, infoBoard, resultAnalyse); + + // if (resultAnalyse->getStatus() >= 0) { + // infoBoard->resetOptionActionsMenu(); + // infoBoard->addOptionalAction( + // "Show Verify Details", [this, error, result]() { + // VerifyDetailsDialog(this, mCtx, mKeyList, error, result); + // }); + // } + + } else { + QMessageBox::critical(this, tr("Error"), + tr("An error occurred during operation.")); + return; } - delete resultAnalyse; } else if (edit->slotCurPageFileTreeView() != nullptr) { this->slotFileVerify(); } } void MainWindow::slotEncryptSign() { - if (edit->tabCount() == 0) - return; + if (edit->tabCount() == 0) return; if (edit->slotCurPageTextEdit() != nullptr) { - QVector<GpgKey> keys; - mKeyList->getCheckedKeys(keys); + auto key_ids = mKeyList->getChecked(); - if (keys.empty()) { + if (key_ids->empty()) { QMessageBox::critical(nullptr, tr("No Key Selected"), tr("No Key Selected")); return; } - for (const auto& key : keys) { - bool key_can_encr = GpgFrontend::GpgContext::checkIfKeyCanEncr(key); + auto keys = GpgKeyGetter::GetInstance().GetKeys(key_ids); + + for (const auto& key : *keys) { + bool key_can_encrypt = key.CanEncrActual(); - if (!key_can_encr) { + if (!key_can_encrypt) { QMessageBox::critical( nullptr, tr("Invalid KeyPair"), tr("The selected keypair cannot be used for encryption.<br/>") + tr("<br/>For example the Following Key: <br/>") + - key.uids.first().uid); + QString::fromStdString(key.uids()->front().uid())); return; } } QVector<GpgKey> signerKeys; - auto signersPicker = new SignersPicker(mCtx, this); + auto signersPicker = new SignersPicker(this); QEventLoop loop; connect(signersPicker, SIGNAL(finished(int)), &loop, SLOT(quit())); loop.exec(); - signersPicker->getCheckedSigners(signerKeys); + auto signer_key_ids = signersPicker->getCheckedSigners(); + auto signer_keys = GpgKeyGetter::GetInstance().GetKeys(key_ids); - for (const auto& key : keys) { - qDebug() << "Keys " << key.email; + for (const auto& key : *keys) { + qDebug() << "Keys " << QString::fromStdString(key.email()); } - for (const auto& signer : signerKeys) { - qDebug() << "Signers " << signer.email; + for (const auto& signer : *signer_keys) { + qDebug() << "Signers " << QString::fromStdString(signer.email()); } - auto tmp = QByteArray(); - gpgme_encrypt_result_t encr_result = nullptr; - gpgme_sign_result_t sign_result = nullptr; - - gpgme_error_t error; - auto thread = QThread::create([&]() { - error = mCtx->encryptSign(keys, signerKeys, - edit->curTextPage()->toPlainText().toUtf8(), - &tmp, &encr_result, &sign_result); + GpgEncrResult encr_result = nullptr; + GpgSignResult sign_result = nullptr; + GpgError error; + bool if_error = false; + + auto tmp = std::make_unique<ByteArray>(); + process_operation(this, tr("Encrypting and Signing").toStdString(), [&]() { + try { + auto buffer = edit->curTextPage()->toPlainText().toUtf8().toStdString(); + error = GpgFrontend::BasicOperator::GetInstance().EncryptSign( + std::move(*keys), std::move(*signer_keys), buffer, tmp, encr_result, + sign_result); + } catch (const std::runtime_error& e) { + if_error = true; + } }); - connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); - thread->start(); - - auto* dialog = new WaitingDialog(tr("Encrypting and Signing"), this); - while (thread->isRunning()) { - QApplication::processEvents(); - } - if (settings.value("advanced/autoPubkeyExchange").toBool()) { - PubkeyUploader pubkeyUploader(mCtx, signerKeys); - pubkeyUploader.start(); - if (!pubkeyUploader.result()) { - QMessageBox::warning(nullptr, tr("Automatic Key Exchange Warning"), - tr("Part of the automatic key exchange failed, " - "which may be related to your key.") + - tr("If possible, try to use the RSA algorithm " - "compatible with the server for signing.")); + if (!if_error) { +#ifdef ADVANCE_SUPPORT + if (settings.value("advanced/autoPubkeyExchange").toBool()) { + PubkeyUploader pubkeyUploader(mCtx, signerKeys); + pubkeyUploader.start(); + if (!pubkeyUploader.result()) { + QMessageBox::warning( + nullptr, tr("Automatic Key Exchange Warning"), + tr("Part of the automatic key exchange failed, " + "which may be related to your key.") + + tr("If possible, try to use the RSA algorithm " + "compatible with the server for signing.")); + } } - } - - dialog->close(); - - if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) { - auto tmp2 = QString(tmp); - edit->slotFillTextEditWithText(tmp2); - } - - qDebug() << "Start Analyse Result"; - - auto resultAnalyseEncr = new EncryptResultAnalyse(error, encr_result); - auto resultAnalyseSign = new SignResultAnalyse(mCtx, error, sign_result); - int status = std::min(resultAnalyseEncr->getStatus(), - resultAnalyseSign->getStatus()); - auto reportText = resultAnalyseEncr->getResultReport() + - resultAnalyseSign->getResultReport(); - - infoBoard->associateTextEdit(edit->curTextPage()); - - if (status < 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); - else if (status > 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_OK); - else - infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); +#endif - qDebug() << "End Analyse Result"; + auto encrypt_res = EncryptResultAnalyse(error, std::move(encr_result)); + auto sign_res = SignResultAnalyse(error, std::move(sign_result)); + encrypt_res.analyse(); + sign_res.analyse(); + process_result_analyse(edit, infoBoard, encrypt_res, sign_res); + edit->slotFillTextEditWithText(QString::fromStdString(*tmp)); - if (status >= 0) { +#ifdef SMTP_SUPPORT infoBoard->resetOptionActionsMenu(); infoBoard->addOptionalAction("Send Mail", [this]() { if (settings.value("sendMail/enable", false).toBool()) @@ -406,6 +373,9 @@ void MainWindow::slotEncryptSign() { "enable and configure this function.")); } }); +#endif + +#ifdef ADVANCE_SUPPORT infoBoard->addOptionalAction("Shorten Ciphertext", [this]() { if (settings.value("general/serviceToken").toString().isEmpty()) QMessageBox::warning(nullptr, tr("Service Token Empty"), @@ -415,23 +385,25 @@ void MainWindow::slotEncryptSign() { shortenCryptText(); } }); - } +#endif - delete resultAnalyseEncr; - delete resultAnalyseSign; + } else { + QMessageBox::critical(this, tr("Error"), + tr("An error occurred during operation.")); + return; + } } else if (edit->slotCurPageFileTreeView() != nullptr) { this->slotFileEncryptSign(); } } void MainWindow::slotDecryptVerify() { - if (edit->tabCount() == 0) - return; + if (edit->tabCount() == 0) return; if (edit->slotCurPageTextEdit() != nullptr) { - auto decrypted = QByteArray(); QString plainText = edit->curTextPage()->toPlainText(); +#ifdef ADVANCE_SUPPORT if (plainText.trimmed().startsWith( GpgConstants::GPG_FRONTEND_SHORT_CRYPTO_HEAD)) { auto cryptoText = getCryptText(plainText); @@ -439,73 +411,64 @@ void MainWindow::slotDecryptVerify() { plainText = cryptoText; } } +#endif QByteArray text = plainText.toUtf8(); - GpgFrontend::GpgContext::preventNoDataErr(&text); - - gpgme_decrypt_result_t d_result = nullptr; - gpgme_verify_result_t v_result = nullptr; - - auto* dialog = new WaitingDialog(tr("Decrypting and Verifying"), this); + GpgDecrResult d_result = nullptr; + GpgVerifyResult v_result = nullptr; + gpgme_error_t error; + bool if_error = false; +#ifdef ADVANCE_SUPPORT // Automatically import public keys that are not stored locally if (settings.value("advanced/autoPubkeyExchange").toBool()) { gpgme_verify_result_t tmp_v_result = nullptr; auto thread = QThread::create( [&]() { mCtx->verify(&text, nullptr, &tmp_v_result); }); thread->start(); - while (thread->isRunning()) - QApplication::processEvents(); + while (thread->isRunning()) QApplication::processEvents(); auto* checker = new UnknownSignersChecker(mCtx, tmp_v_result); checker->start(); checker->deleteLater(); } - - gpgme_error_t error; - auto thread = QThread::create([&]() { - error = mCtx->decryptVerify(text, &decrypted, &d_result, &v_result); - }); - connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); - thread->start(); - - while (thread->isRunning()) - QApplication::processEvents(); - - dialog->close(); - - qDebug() << "Start Analyse Result"; - - infoBoard->associateTextEdit(edit->curTextPage()); - - if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) - edit->slotFillTextEditWithText(QString::fromUtf8(decrypted)); - - auto resultAnalyseDecrypt = new DecryptResultAnalyse(mCtx, error, d_result); - auto resultAnalyseVerify = new VerifyResultAnalyse(mCtx, error, v_result); - - int status = std::min(resultAnalyseDecrypt->getStatus(), - resultAnalyseVerify->getStatus()); - auto& reportText = resultAnalyseDecrypt->getResultReport() + - resultAnalyseVerify->getResultReport(); - if (status < 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); - else if (status > 0) - infoBoard->slotRefresh(reportText, INFO_ERROR_OK); - else - infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); - - if (resultAnalyseVerify->getStatus() >= 0) { - infoBoard->resetOptionActionsMenu(); - infoBoard->addOptionalAction( - "Show Verify Details", [this, error, v_result]() { - VerifyDetailsDialog(this, mCtx, mKeyList, error, v_result); - }); +#endif + auto decrypted = std::make_unique<ByteArray>(); + process_operation(this, tr("Decrypting and Verifying").toStdString(), + [&]() { + try { + auto buffer = text.toStdString(); + error = BasicOperator::GetInstance().DecryptVerify( + buffer, decrypted, d_result, v_result); + } catch (const std::runtime_error& e) { + if_error = true; + } + }); + + if (!if_error) { + infoBoard->associateFileTreeView(edit->curFilePage()); + + auto decrypt_res = DecryptResultAnalyse(error, std::move(d_result)); + auto verify_res = VerifyResultAnalyse(error, std::move(v_result)); + decrypt_res.analyse(); + verify_res.analyse(); + process_result_analyse(edit, infoBoard, decrypt_res, verify_res); + + edit->slotFillTextEditWithText(QString::fromStdString(*decrypted)); + + // if (verify_res.getStatus() >= 0) { + // infoBoard->resetOptionActionsMenu(); + // infoBoard->addOptionalAction( + // "Show Verify Details", [this, error, v_result]() { + // VerifyDetailsDialog(this, mCtx, mKeyList, error, + // v_result); + // }); + // } + } else { + QMessageBox::critical(this, tr("Error"), + tr("An error occurred during operation.")); + return; } - delete resultAnalyseDecrypt; - delete resultAnalyseVerify; - - qDebug() << "End Analyse Result"; } else if (edit->slotCurPageFileTreeView() != nullptr) { this->slotFileDecryptVerify(); @@ -520,58 +483,55 @@ void MainWindow::slotAppendSelectedKeys() { return; } - auto* keyArray = new QByteArray(); - mCtx->exportKeys(mKeyList->getSelected(), keyArray); - edit->curTextPage()->append(*keyArray); + auto exported = std::make_unique<ByteArray>(); + auto key_ids = mKeyList->getSelected(); + + GpgKeyImportExportor::GetInstance().ExportKeys(key_ids, exported); + edit->curTextPage()->append(QString::fromStdString(*exported)); } void MainWindow::slotCopyMailAddressToClipboard() { - if (mKeyList->getSelected()->isEmpty()) { - return; - } - auto key = mCtx->getKeyRefById(mKeyList->getSelected()->first()); - if (!key.good) { + auto key_ids = mKeyList->getSelected(); + if (key_ids->empty()) return; + + auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front()); + if (!key.good()) { QMessageBox::critical(nullptr, tr("Error"), tr("Key Not Found.")); return; } QClipboard* cb = QApplication::clipboard(); - QString mail = key.email; - cb->setText(mail); + cb->setText(QString::fromStdString(key.email())); } void MainWindow::slotShowKeyDetails() { - if (mKeyList->getSelected()->isEmpty()) { - return; - } - auto key = mCtx->getKeyRefById(mKeyList->getSelected()->first()); - if (key.good) { - new KeyDetailsDialog(mCtx, key, this); + auto key_ids = mKeyList->getSelected(); + if (key_ids->empty()) return; + + auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front()); + if (key.good()) { + new KeyDetailsDialog(key, this); } else { QMessageBox::critical(nullptr, tr("Error"), tr("Key Not Found.")); } } void MainWindow::refreshKeysFromKeyserver() { - if (mKeyList->getSelected()->isEmpty()) { - return; - } + auto key_ids = mKeyList->getSelected(); + if (key_ids->empty()) return; - auto* dialog = new KeyServerImportDialog(mCtx, mKeyList, true, this); + auto* dialog = new KeyServerImportDialog(mKeyList, true, this); dialog->show(); - dialog->slotImport(*mKeyList->getSelected()); + dialog->slotImport(key_ids); } void MainWindow::uploadKeyToServer() { - QVector<GpgKey> keys; - keys.append(mKeyList->getSelectedKey()); - auto* dialog = new KeyUploadDialog(mCtx, keys, this); + auto key_ids = mKeyList->getSelected(); + auto* dialog = new KeyUploadDialog(key_ids, this); dialog->show(); dialog->slotUpload(); } -void MainWindow::slotOpenFile(QString& path) { - edit->slotOpenFile(path); -} +void MainWindow::slotOpenFile(QString& path) { edit->slotOpenFile(path); } void MainWindow::slotVersionUpgrade(const QString& currentVersion, const QString& latestVersion) { diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp index 982c9efb..baade2b4 100644 --- a/src/ui/main_window/MainWindowSlotUI.cpp +++ b/src/ui/main_window/MainWindowSlotUI.cpp @@ -71,8 +71,7 @@ void MainWindow::slotCheckAttachmentFolder() { void MainWindow::slotImportKeyFromEdit() { if (edit->tabCount() == 0 || edit->slotCurPageTextEdit() == nullptr) return; - keyMgmt->slotImportKeys(std::make_unique<ByteArray>( - edit->curTextPage()->toPlainText().toStdString())); + keyMgmt->slotImportKeys(edit->curTextPage()->toPlainText().toStdString()); } void MainWindow::slotOpenKeyManagement() { diff --git a/src/ui/settings/SettingsAdvanced.cpp b/src/ui/settings/SettingsAdvanced.cpp index 90e588e9..048cbe2d 100644 --- a/src/ui/settings/SettingsAdvanced.cpp +++ b/src/ui/settings/SettingsAdvanced.cpp @@ -22,7 +22,7 @@ * */ -#include "ui/SettingsDialog.h" +#include "SettingsAdvanced.h" namespace GpgFrontend::UI { diff --git a/src/ui/settings/SettingsAdvanced.h b/src/ui/settings/SettingsAdvanced.h new file mode 100644 index 00000000..197fa22d --- /dev/null +++ b/src/ui/settings/SettingsAdvanced.h @@ -0,0 +1,54 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef GPGFRONTEND_SETTINGSADVANCED_H +#define GPGFRONTEND_SETTINGSADVANCED_H + +#include "ui/GpgFrontendUI.h" + +namespace GpgFrontend::UI { +class AdvancedTab : public QWidget { + Q_OBJECT + + public: + explicit AdvancedTab(QWidget* parent = nullptr); + + void setSettings(); + + void applySettings(); + + private: + QString appPath; + QSettings settings; + + QCheckBox* steganoCheckBox; + QCheckBox* autoPubkeyExchangeCheckBox; + + signals: + + void signalRestartNeeded(bool needed); +}; +} // namespace GpgFrontend::UI + +#endif // GPGFRONTEND_SETTINGSADVANCED_H diff --git a/src/ui/settings/SettingsAppearance.cpp b/src/ui/settings/SettingsAppearance.cpp index 79bfe5d8..74ad6c2a 100644 --- a/src/ui/settings/SettingsAppearance.cpp +++ b/src/ui/settings/SettingsAppearance.cpp @@ -22,7 +22,7 @@ * */ -#include "ui/SettingsDialog.h" +#include "SettingsAppearance.h" namespace GpgFrontend::UI { @@ -149,8 +149,7 @@ void AppearanceTab::setSettings() { // infoBoardFontSize auto infoBoardFontSize = settings.value("informationBoard/fontSize", 10).toInt(); - if (infoBoardFontSize < 9 || infoBoardFontSize > 18) - infoBoardFontSize = 10; + if (infoBoardFontSize < 9 || infoBoardFontSize > 18) infoBoardFontSize = 10; infoBoardFontSizeSpin->setValue(infoBoardFontSize); } diff --git a/src/ui/settings/SettingsAppearance.h b/src/ui/settings/SettingsAppearance.h new file mode 100644 index 00000000..163f3c93 --- /dev/null +++ b/src/ui/settings/SettingsAppearance.h @@ -0,0 +1,65 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef GPGFRONTEND_SETTINGSAPPEARANCE_H +#define GPGFRONTEND_SETTINGSAPPEARANCE_H + +#include "ui/GpgFrontendUI.h" + +namespace GpgFrontend::UI { + +class AppearanceTab : public QWidget { + Q_OBJECT + + public: + // void setSettings(); + explicit AppearanceTab(QWidget* parent = nullptr); + + void setSettings(); + + void applySettings(); + + private: + QString appPath; + QSettings settings; + + QButtonGroup* iconStyleGroup; + QRadioButton* iconSizeSmall; + QRadioButton* iconSizeMedium; + QRadioButton* iconSizeLarge; + QButtonGroup* iconSizeGroup; + QRadioButton* iconTextButton; + QRadioButton* iconIconsButton; + QRadioButton* iconAllButton; + QSpinBox* infoBoardFontSizeSpin; + QCheckBox* windowSizeCheckBox; + + signals: + + void signalRestartNeeded(bool needed); +}; + +} + +#endif // GPGFRONTEND_SETTINGSAPPEARANCE_H diff --git a/src/ui/settings/SettingsDialog.cpp b/src/ui/settings/SettingsDialog.cpp index 9a423dfd..553ce53e 100644 --- a/src/ui/settings/SettingsDialog.cpp +++ b/src/ui/settings/SettingsDialog.cpp @@ -22,8 +22,16 @@ * */ -#include "ui/SettingsDialog.h" -#include "ui/WaitingDialog.h" +#include "SettingsDialog.h" + +#include "SettingsAdvanced.h" +#include "SettingsAppearance.h" +#include "SettingsGeneral.h" +#include "SettingsKeyServer.h" + +#ifdef SMTP_SUPPORT +#include "SettingsSendMail.h" +#endif namespace GpgFrontend::UI { @@ -31,14 +39,18 @@ SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) { tabWidget = new QTabWidget; generalTab = new GeneralTab(); appearanceTab = new AppearanceTab; +#ifdef SMTP_SUPPORT sendMailTab = new SendMailTab; +#endif keyserverTab = new KeyserverTab; advancedTab = new AdvancedTab; gpgPathsTab = new GpgPathsTab; tabWidget->addTab(generalTab, tr("General")); tabWidget->addTab(appearanceTab, tr("Appearance")); +#ifdef SMTP_SUPPORT tabWidget->addTab(sendMailTab, tr("Send Mail")); +#endif tabWidget->addTab(keyserverTab, tr("Key Server")); // tabWidget->addTab(gpgPathsTab, tr("Gpg paths")); tabWidget->addTab(advancedTab, tr("Advanced")); @@ -64,8 +76,10 @@ SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) { SLOT(slotSetRestartNeeded(bool))); connect(appearanceTab, SIGNAL(signalRestartNeeded(bool)), this, SLOT(slotSetRestartNeeded(bool))); +#ifdef SMTP_SUPPORT connect(sendMailTab, SIGNAL(signalRestartNeeded(bool)), this, SLOT(slotSetRestartNeeded(bool))); +#endif connect(keyserverTab, SIGNAL(signalRestartNeeded(bool)), this, SLOT(slotSetRestartNeeded(bool))); connect(advancedTab, SIGNAL(signalRestartNeeded(bool)), this, @@ -78,9 +92,7 @@ SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) { this->show(); } -bool SettingsDialog::getRestartNeeded() const { - return this->restartNeeded; -} +bool SettingsDialog::getRestartNeeded() const { return this->restartNeeded; } void SettingsDialog::slotSetRestartNeeded(bool needed) { this->restartNeeded = needed; @@ -88,7 +100,9 @@ void SettingsDialog::slotSetRestartNeeded(bool needed) { void SettingsDialog::slotAccept() { generalTab->applySettings(); +#ifdef SMTP_SUPPORT sendMailTab->applySettings(); +#endif appearanceTab->applySettings(); keyserverTab->applySettings(); advancedTab->applySettings(); diff --git a/src/ui/settings/SettingsDialog.h b/src/ui/settings/SettingsDialog.h new file mode 100755 index 00000000..0f89e266 --- /dev/null +++ b/src/ui/settings/SettingsDialog.h @@ -0,0 +1,108 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef __SETTINGSDIALOG_H__ +#define __SETTINGSDIALOG_H__ + +#include "ui/GpgFrontendUI.h" +#include "ui/widgets/KeyList.h" + +namespace GpgFrontend::UI { + +class GeneralTab; + +#ifdef SMTP_SUPPORT +class SendMailTab; +#endif + +class AppearanceTab; +class KeyserverTab; +class AdvancedTab; + +class GpgPathsTab : public QWidget { + Q_OBJECT + public: + explicit GpgPathsTab(QWidget* parent = nullptr); + + void applySettings(); + + private: + static QString getRelativePath(const QString& dir1, const QString& dir2); + + QString appPath; + QSettings settings; + + QString defKeydbPath; /** The default keydb path used by gpg4usb */ + QString accKeydbPath; /** The currently used keydb path */ + QLabel* keydbLabel; + + void setSettings(); + + private slots: + + QString chooseKeydbDir(); + + void setKeydbPathToDefault(); +}; + +class SettingsDialog : public QDialog { + Q_OBJECT + + public: + explicit SettingsDialog(QWidget* parent = nullptr); + + GeneralTab* generalTab; +#ifdef SMTP_SUPPORT + SendMailTab* sendMailTab; +#endif + AppearanceTab* appearanceTab; + KeyserverTab* keyserverTab; + AdvancedTab* advancedTab; + GpgPathsTab* gpgPathsTab; + + static QHash<QString, QString> listLanguages(); + + public slots: + + void slotAccept(); + + signals: + + void signalRestartNeeded(bool needed); + + private: + QTabWidget* tabWidget; + QDialogButtonBox* buttonBox; + bool restartNeeded{}; + + bool getRestartNeeded() const; + + private slots: + + void slotSetRestartNeeded(bool needed); +}; + +} // namespace GpgFrontend::UI + +#endif // __SETTINGSDIALOG_H__ diff --git a/src/ui/settings/SettingsGeneral.cpp b/src/ui/settings/SettingsGeneral.cpp index dab0bb5d..8ecb2213 100644 --- a/src/ui/settings/SettingsGeneral.cpp +++ b/src/ui/settings/SettingsGeneral.cpp @@ -22,15 +22,16 @@ * */ -#include "ui/SettingsDialog.h" - -#include "rapidjson/prettywriter.h" +#include "SettingsGeneral.h" #ifdef SERVER_SUPPORT #include "server/ComUtils.h" #endif + +#include "SettingsDialog.h" #include "gpg/function/GpgKeyGetter.h" -#include "ui/WaitingDialog.h" +#include "rapidjson/prettywriter.h" +#include "ui/widgets/KeyList.h" namespace GpgFrontend::UI { @@ -114,8 +115,7 @@ GeneralTab::GeneralTab(QWidget* parent) for (const auto& keyid : *private_keys) { auto key = GpgKeyGetter::GetInstance().GetKey(keyid); - if (!key.good()) - continue; + if (!key.good()) continue; keyIds.insert({key.id(), key.uids()->front().uid()}); } for (const auto& k : keyIds) { @@ -167,8 +167,7 @@ void GeneralTab::setSettings() { serverList.append("service.gpgfrontend.pub"); serverList.append("localhost"); } - for (const auto& s : serverList) - serverSelectBox->addItem(s); + for (const auto& s : serverList) serverSelectBox->addItem(s); qDebug() << "Current Gpgfrontend Server" << settings.value("general/currentGpgfrontendServer").toString(); @@ -241,9 +240,7 @@ void GeneralTab::applySettings() { importConfirmationCheckBox->isChecked()); } -void GeneralTab::slotLanguageChanged() { - emit signalRestartNeeded(true); -} +void GeneralTab::slotLanguageChanged() { emit signalRestartNeeded(true); } void GeneralTab::slotOwnKeyIdChanged() { // Set ownKeyId to currently selected diff --git a/src/ui/settings/SettingsGeneral.h b/src/ui/settings/SettingsGeneral.h new file mode 100644 index 00000000..ea4061e7 --- /dev/null +++ b/src/ui/settings/SettingsGeneral.h @@ -0,0 +1,73 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef GPGFRONTEND_SETTINGSGENERAL_H +#define GPGFRONTEND_SETTINGSGENERAL_H + +#include "ui/GpgFrontendUI.h" + +namespace GpgFrontend::UI { +class KeyList; + +class GeneralTab : public QWidget { + Q_OBJECT + + public: + explicit GeneralTab(QWidget* parent = nullptr); + + void setSettings(); + + void applySettings(); + + private: + QString appPath; + QSettings settings; + + QComboBox* serverSelectBox; + QCheckBox* saveCheckedKeysCheckBox; + QCheckBox* importConfirmationCheckBox; + QComboBox* langSelectBox; + QComboBox* ownKeySelectBox; + QPushButton* getServiceTokenButton; + QLabel* serviceTokenLabel; + QHash<QString, QString> lang; + + std::unordered_map<std::string, std::string> keyIds; + std::vector<std::string> keyIdsList; + std::string serviceToken; + KeyList* mKeyList; + + private slots: + + void slotOwnKeyIdChanged(); + + void slotLanguageChanged(); + + signals: + + void signalRestartNeeded(bool needed); +}; +} // namespace GpgFrontend::UI + +#endif // GPGFRONTEND_SETTINGSGENERAL_H diff --git a/src/ui/settings/SettingsKeyServer.cpp b/src/ui/settings/SettingsKeyServer.cpp index e11115c1..d232a46e 100644 --- a/src/ui/settings/SettingsKeyServer.cpp +++ b/src/ui/settings/SettingsKeyServer.cpp @@ -22,7 +22,7 @@ * */ -#include "ui/SettingsDialog.h" +#include "SettingsKeyServer.h" namespace GpgFrontend::UI { diff --git a/src/ui/settings/SettingsKeyServer.h b/src/ui/settings/SettingsKeyServer.h new file mode 100644 index 00000000..ce7c5b2e --- /dev/null +++ b/src/ui/settings/SettingsKeyServer.h @@ -0,0 +1,61 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef GPGFRONTEND_SETTINGSKEYSERVER_H +#define GPGFRONTEND_SETTINGSKEYSERVER_H + +#include "ui/GpgFrontendUI.h" + +namespace GpgFrontend::UI { +class KeyserverTab : public QWidget { + Q_OBJECT + + public: + explicit KeyserverTab(QWidget* parent = nullptr); + + void setSettings(); + + void applySettings(); + + private: + QString appPath; + QSettings settings; + QComboBox* comboBox; + QLineEdit* newKeyServerEdit; + QTableWidget* keyServerTable; + QStringList keyServerStrList; + + private slots: + + void addKeyServer(); + + void refreshTable(); + + signals: + + void signalRestartNeeded(bool needed); +}; +} + +#endif // GPGFRONTEND_SETTINGSKEYSERVER_H diff --git a/src/ui/settings/SettingsSendMail.cpp b/src/ui/settings/SettingsSendMail.cpp index 8db3cd0a..9d48b2a0 100644 --- a/src/ui/settings/SettingsSendMail.cpp +++ b/src/ui/settings/SettingsSendMail.cpp @@ -22,10 +22,11 @@ * */ +#include "SettingsSendMail.h" + #ifdef SMTP_SUPPORT #include "smtp/SmtpMime" #endif -#include "ui/SettingsDialog.h" namespace GpgFrontend::UI { @@ -92,8 +93,6 @@ SendMailTab::SendMailTab(QWidget* parent) connect(enableCheckBox, SIGNAL(stateChanged(int)), this, SLOT(slotCheckBoxSetEnableDisable(int))); - connect(checkConnectionButton, SIGNAL(clicked(bool)), this, - SLOT(slotCheckConnection())); this->setLayout(vBox); setSettings(); diff --git a/src/ui/settings/SettingsSendMail.h b/src/ui/settings/SettingsSendMail.h new file mode 100644 index 00000000..ec8f83c9 --- /dev/null +++ b/src/ui/settings/SettingsSendMail.h @@ -0,0 +1,46 @@ +// +// Created by saturneric on 2021/11/28. +// + +#ifndef GPGFRONTEND_SETTINGSSENDMAIL_H +#define GPGFRONTEND_SETTINGSSENDMAIL_H + +#include "ui/GpgFrontendUI.h" + +namespace GpgFrontend::UI { +class SendMailTab : public QWidget { + Q_OBJECT + + public: + explicit SendMailTab(QWidget* parent = nullptr); + + void setSettings(); + + void applySettings(); + + private slots: + + void slotCheckBoxSetEnableDisable(int state); + + private: + QString appPath; + QSettings settings; + + QCheckBox* enableCheckBox; + + QLineEdit* smtpAddress; + QLineEdit* username; + QLineEdit* password; + QSpinBox* portSpin; + QComboBox* connectionTypeComboBox; + QLineEdit* defaultSender; + + QPushButton* checkConnectionButton; + + signals: + + void signalRestartNeeded(bool needed); +}; +} // namespace GpgFrontend::UI + +#endif // GPGFRONTEND_SETTINGSSENDMAIL_H diff --git a/src/ui/SendMailDialog.cpp b/src/ui/smtp/SendMailDialog.cpp index e140ca87..51ece6c9 100644 --- a/src/ui/SendMailDialog.cpp +++ b/src/ui/smtp/SendMailDialog.cpp @@ -22,7 +22,7 @@ * */ -#include "ui/SendMailDialog.h" +#include "SendMailDialog.h" #include <utility> @@ -149,8 +149,7 @@ void SendMailDialog::slotConfirm() { message.setSender(new EmailAddress(senderEdit->text())); for (const auto& reci : rcptStringList) { - if (!reci.isEmpty()) - message.addRecipient(new EmailAddress(reci.trimmed())); + if (!reci.isEmpty()) message.addRecipient(new EmailAddress(reci.trimmed())); } message.setSubject(subjectEdit->text()); diff --git a/src/ui/SendMailDialog.h b/src/ui/smtp/SendMailDialog.h index 6afdfe79..6afdfe79 100644 --- a/src/ui/SendMailDialog.h +++ b/src/ui/smtp/SendMailDialog.h diff --git a/src/ui/widgets/InfoBoardWidget.cpp b/src/ui/widgets/InfoBoardWidget.cpp index a77ed73c..aac80514 100644 --- a/src/ui/widgets/InfoBoardWidget.cpp +++ b/src/ui/widgets/InfoBoardWidget.cpp @@ -86,7 +86,11 @@ InfoBoardWidget::InfoBoardWidget(QWidget* parent, KeyList* keyList) void InfoBoardWidget::slotImportFromKeyserver() { auto* importDialog = new KeyServerImportDialog(mKeyList, false, this); - importDialog->slotImport(*keysNotInList); + auto key_ids = std::make_unique<KeyIdArgsList>(); + for (const auto& key_id : *keysNotInList) { + key_ids->push_back(key_id.toStdString()); + } + importDialog->slotImport(key_ids); } void InfoBoardWidget::setInfoBoard(const QString& text, diff --git a/src/ui/widgets/SignersPicker.cpp b/src/ui/widgets/SignersPicker.cpp index 58dc8dbc..3c720b10 100644 --- a/src/ui/widgets/SignersPicker.cpp +++ b/src/ui/widgets/SignersPicker.cpp @@ -26,18 +26,17 @@ namespace GpgFrontend::UI { -SignersPicker::SignersPicker(GpgFrontend::GpgContext* ctx, QWidget* parent) - : mCtx(ctx), QDialog(parent) { +SignersPicker::SignersPicker(QWidget* parent) : QDialog(parent) { auto confirmButton = new QPushButton(tr("Confirm")); connect(confirmButton, SIGNAL(clicked(bool)), this, SLOT(accept())); /*Setup KeyList*/ mKeyList = new KeyList( - mCtx, KeyListRow::ONLY_SECRET_KEY, + KeyListRow::ONLY_SECRET_KEY, KeyListColumn::NAME | KeyListColumn::EmailAddress | KeyListColumn::Usage); mKeyList->setFilter([](const GpgKey& key) -> bool { - if (!GpgFrontend::GpgContext::checkIfKeyCanSign(key)) + if (!key.CanSignActual()) return false; else return true; @@ -58,8 +57,8 @@ SignersPicker::SignersPicker(GpgFrontend::GpgContext* ctx, QWidget* parent) this->show(); } -void SignersPicker::getCheckedSigners(QVector<GpgKey>& keys) { - mKeyList->getPrivateCheckedKeys(keys); +GpgFrontend::KeyIdArgsListPtr SignersPicker::getCheckedSigners() { + return mKeyList->getPrivateChecked(); } } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/SignersPicker.h b/src/ui/widgets/SignersPicker.h index 17c57e62..278e0142 100644 --- a/src/ui/widgets/SignersPicker.h +++ b/src/ui/widgets/SignersPicker.h @@ -27,7 +27,6 @@ #include "GpgFrontend.h" #include "gpg/GpgContext.h" - #include "ui/widgets/KeyList.h" namespace GpgFrontend::UI { @@ -36,13 +35,11 @@ class SignersPicker : public QDialog { Q_OBJECT public: - explicit SignersPicker(GpgFrontend::GpgContext* ctx, - QWidget* parent = nullptr); + explicit SignersPicker(QWidget* parent = nullptr); - void getCheckedSigners(QVector<GpgKey>& keys); + GpgFrontend::KeyIdArgsListPtr getCheckedSigners(); private: - GpgFrontend::GpgContext* mCtx; KeyList* mKeyList; }; diff --git a/src/ui/widgets/TextEdit.h b/src/ui/widgets/TextEdit.h index 6af70345..91bacf65 100644 --- a/src/ui/widgets/TextEdit.h +++ b/src/ui/widgets/TextEdit.h @@ -84,13 +84,13 @@ class TextEdit : public QWidget { * @details Return pointer to the currently activated text edit tab page. * */ - [[nodiscard]] EditorPage* slotCurPageTextEdit() const; + EditorPage* slotCurPageTextEdit() const; /** * @details Return pointer to the currently activated file treeview tab page. * */ - [[nodiscard]] FilePage* slotCurPageFileTreeView() const; + FilePage* slotCurPageFileTreeView() const; /** * @details Insert a ">" at the begining of every line of current textedit. diff --git a/src/ui/widgets/VerifyKeyDetailBox.cpp b/src/ui/widgets/VerifyKeyDetailBox.cpp index 76af201d..97f792b1 100644 --- a/src/ui/widgets/VerifyKeyDetailBox.cpp +++ b/src/ui/widgets/VerifyKeyDetailBox.cpp @@ -28,8 +28,7 @@ namespace GpgFrontend::UI { -VerifyKeyDetailBox::VerifyKeyDetailBox(QWidget* parent, - KeyList* keyList, +VerifyKeyDetailBox::VerifyKeyDetailBox(QWidget* parent, KeyList* keyList, gpgme_signature_t signature) : QGroupBox(parent), mKeyList(keyList), fpr(signature->fpr) { auto* vbox = new QVBoxLayout(); @@ -150,7 +149,9 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(QWidget* parent, void VerifyKeyDetailBox::slotImportFormKeyserver() { auto* importDialog = new KeyServerImportDialog(mKeyList, false, this); - importDialog->slotImport(QStringList(fpr)); + auto key_ids = std::make_unique<KeyIdArgsList>(); + key_ids->push_back(fpr.toStdString()); + importDialog->slotImport(key_ids); } QString VerifyKeyDetailBox::beautifyFingerprint(QString fingerprint) { @@ -166,8 +167,7 @@ QGridLayout* VerifyKeyDetailBox::createKeyInfoGrid( auto grid = new QGridLayout(); GpgKey key = GpgKeyGetter::GetInstance().GetKey(signature->fpr); - if (!key.good()) - return nullptr; + if (!key.good()) return nullptr; grid->addWidget(new QLabel(tr("Signer Name:")), 0, 0); grid->addWidget(new QLabel(tr("Signer Email:")), 1, 0); grid->addWidget(new QLabel(tr("Key's Fingerprint:")), 2, 0); |