diff options
Diffstat (limited to 'src')
33 files changed, 348 insertions, 195 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 47cd8a50..d5a713b1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -107,7 +107,6 @@ 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) if (MULTI_LANG_SUPPORT) make_directory(${RESOURCE_OUTPUT_DIRECTORY}/locales) file(COPY ${CMAKE_SOURCE_DIR}/resource/locale/out/ DESTINATION ${RESOURCE_OUTPUT_DIRECTORY}/locales FOLLOW_SYMLINK_CHAIN) @@ -174,11 +173,11 @@ if (APPLICATION_BUILD) 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/ + COMMAND /bin/mkdir -p ./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 + COMMAND /bin/mkdir -p ./gpgfrontend/usr/lib WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMENT "Complement to build the required architecture") else () @@ -205,22 +204,25 @@ if (APPLICATION_BUILD) 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) - set(QT_DEPENDENCY_LIBS Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core) + IF (MINGW) message(STATUS "Link Application Static Library For MINGW") + find_library(libconfig NAMES libconfig++.a) + find_library(libintl NAMES libintl.a) + find_library(libiconv NAMES libiconv.a) + target_link_libraries(${AppName} ${GPGFRONTEND_LIBS} ${QT_DEPENDENCY_LIBS} - crypto ssl) + ${libintl} ${libiconv} ${libconfig} crypto ssl) elseif (APPLE) message(STATUS "Link Application Static Library For macOS") target_link_libraries(${AppName} ${GPGFRONTEND_LIBS} ${QT_DEPENDENCY_LIBS} - crypto ssl) + crypto ssl intl) else () message(STATUS "Link Application Static Library For UNIX ") target_link_libraries(${AppName} diff --git a/src/GpgFrontend.h.in b/src/GpgFrontend.h.in index 1814ddbc..622c2b07 100644 --- a/src/GpgFrontend.h.in +++ b/src/GpgFrontend.h.in @@ -26,12 +26,23 @@ #define GPGFRONTEND_H_IN // i18n +#ifdef WINDOWS +#include <winsock2.h> +#include <windows.h> +#endif + #include <libintl.h> #define _(String) gettext (String) #define gettext_noop(String) String #define N_(String) gettext_noop (String) +#ifdef WINDOWS +#include <clocale> +#undef vsnprintf +#endif + // logging +#define ELPP_DEFAULT_LOGGING_FLAGS 8192 #include <easyloggingpp/easylogging++.h> #define PROJECT_NAME "@CMAKE_PROJECT_NAME@" diff --git a/src/gpg/CMakeLists.txt b/src/gpg/CMakeLists.txt index 36a81591..886f8fdc 100644 --- a/src/gpg/CMakeLists.txt +++ b/src/gpg/CMakeLists.txt @@ -23,11 +23,16 @@ if (MINGW) target_link_libraries(gpg_core ${THIRD_PARTY_LIBS} ${BOOST_LIBS} gpgme gpg-error assuan wsock32) + target_compile_features(gpg_core PUBLIC cxx_std_17) elseif (APPLE) + find_library(libgpgme NAMES libgpgme.a) + find_library(libgpg-error NAMES libgpg-error.a) + find_library(libassuan NAMES libassuan.a) message(STATUS "Link GPG Static Library For macOS") target_link_libraries(gpg_core ${THIRD_PARTY_LIBS} ${BOOST_LIBS} - libgpgme.a libgpg-error.a libassuan.a dl) + ${libgpgme} ${libgpg-error} ${libassuan} + dl) else () message(STATUS "Link GPG Static Library For Unix") target_link_libraries(gpg_core ${THIRD_PARTY_LIBS} diff --git a/src/gpg/GpgConstants.cpp b/src/gpg/GpgConstants.cpp index aa56fe10..5688287e 100644 --- a/src/gpg/GpgConstants.cpp +++ b/src/gpg/GpgConstants.cpp @@ -27,7 +27,7 @@ #include <gpg-error.h> #include <boost/algorithm/string/predicate.hpp> -#include <filesystem> +#include <boost/filesystem.hpp> const char* GpgFrontend::GpgConstants::PGP_CRYPT_BEGIN = "-----BEGIN PGP MESSAGE-----"; @@ -78,9 +78,9 @@ gpgme_error_t GpgFrontend::check_gpg_error(gpgme_error_t err, std::string GpgFrontend::beautify_fingerprint( GpgFrontend::BypeArrayConstRef fingerprint) { auto _fingerprint = fingerprint; - uint len = fingerprint.size(); + unsigned len = fingerprint.size(); if ((len > 0) && (len % 4 == 0)) - for (uint n = 0; 4 * (n + 1) < len; ++n) + for (unsigned n = 0; 4 * (n + 1) < len; ++n) _fingerprint.insert(static_cast<int>(5u * n + 4u), " "); return fingerprint; } @@ -108,7 +108,7 @@ static inline std::string trim(std::string& s) { } std::string GpgFrontend::read_all_data_in_file(const std::string& path) { - using namespace std::filesystem; + using namespace boost::filesystem; class path file_info(path.c_str()); if (!exists(file_info) || !is_regular_file(path)) @@ -126,7 +126,7 @@ std::string GpgFrontend::read_all_data_in_file(const std::string& path) { bool GpgFrontend::write_buffer_to_file(const std::string& path, const std::string& out_buffer) { - std::ofstream out_file(std::filesystem::path(path), std::ios::out); + std::ofstream out_file(boost::filesystem::path(path).string(), std::ios::out); if (!out_file.good()) return false; out_file.write(out_buffer.c_str(), out_buffer.size()); out_file.close(); @@ -135,7 +135,7 @@ bool GpgFrontend::write_buffer_to_file(const std::string& path, std::string GpgFrontend::get_file_extension(const std::string& path) { // Create a Path object from given string - std::filesystem::path path_obj(path); + boost::filesystem::path path_obj(path); // Check if file name in the path object has extension if (path_obj.has_extension()) { // Fetch the extension from path object and return @@ -147,11 +147,11 @@ std::string GpgFrontend::get_file_extension(const std::string& path) { std::string GpgFrontend::get_only_file_name_with_path(const std::string& path) { // Create a Path object from given string - std::filesystem::path path_obj(path); + boost::filesystem::path path_obj(path); // Check if file name in the path object has extension if (path_obj.has_filename()) { // Fetch the extension from path object and return - return path_obj.parent_path() / path_obj.stem(); + return (path_obj.parent_path() / path_obj.stem()).string(); } // In case of no extension return empty string throw std::runtime_error("invalid file path"); diff --git a/src/gpg/GpgConstants.h b/src/gpg/GpgConstants.h index 4804924a..1cd0f64d 100644 --- a/src/gpg/GpgConstants.h +++ b/src/gpg/GpgConstants.h @@ -25,19 +25,16 @@ #ifndef GPG_CONSTANTS_H #define GPG_CONSTANTS_H -#define ELPP_DEFAULT_LOGGING_FLAGS 8192 -#include <easyloggingpp/easylogging++.h> +#include "GpgFrontend.h" + #include <gpg-error.h> #include <gpgme.h> #include <cassert> #include <functional> -#include <libconfig.h++> #include <memory> #include <string> -#include "GpgFrontend.h" - const int RESTART_CODE = 1000; namespace GpgFrontend { diff --git a/src/gpg/GpgContext.h b/src/gpg/GpgContext.h index 7df90060..4a9b6fc0 100644 --- a/src/gpg/GpgContext.h +++ b/src/gpg/GpgContext.h @@ -25,6 +25,8 @@ #ifndef __SGPGMEPP_CONTEXT_H__ #define __SGPGMEPP_CONTEXT_H__ +#include "GpgConstants.h" + #include "GpgFunctionObject.h" #include "GpgInfo.h" #include "GpgModel.h" @@ -36,7 +38,7 @@ namespace GpgFrontend { */ class GpgContext : public SingletonFunctionObject<GpgContext> { public: - GpgContext(bool independent_database = false, + explicit GpgContext(bool independent_database = false, std::string path = std::string(), int channel = 0); ~GpgContext() override = default; diff --git a/src/gpg/GpgModel.h b/src/gpg/GpgModel.h index a9351e50..3e07427c 100644 --- a/src/gpg/GpgModel.h +++ b/src/gpg/GpgModel.h @@ -25,6 +25,8 @@ #ifndef GPGFRONTEND_ZH_CN_TS_GPGMODEL_H #define GPGFRONTEND_ZH_CN_TS_GPGMODEL_H +#include "GpgConstants.h" + #include <list> #include <utility> diff --git a/src/gpg/function/GpgCommandExecutor.cpp b/src/gpg/function/GpgCommandExecutor.cpp index a494d4a8..9b99b400 100644 --- a/src/gpg/function/GpgCommandExecutor.cpp +++ b/src/gpg/function/GpgCommandExecutor.cpp @@ -22,8 +22,11 @@ * */ #include "gpg/function/GpgCommandExecutor.h" - +#ifndef WINDOWS #include <boost/asio.hpp> +#endif + +#ifndef WINDOWS using boost::process::async_pipe; @@ -52,3 +55,5 @@ void GpgFrontend::GpgCommandExecutor::Execute( child_process.wait(); child_process.exit_code(); } + +#endif diff --git a/src/gpg/function/GpgCommandExecutor.h b/src/gpg/function/GpgCommandExecutor.h index a6eaaf4a..f28caca8 100644 --- a/src/gpg/function/GpgCommandExecutor.h +++ b/src/gpg/function/GpgCommandExecutor.h @@ -25,7 +25,9 @@ #ifndef GPGFRONTEND_ZH_CN_TS_GPGCOMMANDEXECUTOR_H #define GPGFRONTEND_ZH_CN_TS_GPGCOMMANDEXECUTOR_H +#ifndef WINDOWS #include <boost/process.hpp> +#endif #include "gpg/GpgContext.h" #include "gpg/GpgFunctionObject.h" @@ -33,10 +35,13 @@ namespace GpgFrontend { class GpgCommandExecutor : public SingletonFunctionObject<GpgCommandExecutor> { public: + +#ifndef WINDOWS void Execute(StringArgsRef arguments, const std::function<void(boost::process::async_pipe &in, boost::process::async_pipe &out)> &interact_func); +#endif private: GpgContext &ctx = GpgContext::GetInstance(); diff --git a/src/gpg/function/GpgKeyOpera.cpp b/src/gpg/function/GpgKeyOpera.cpp index a7371904..c60f9157 100644 --- a/src/gpg/function/GpgKeyOpera.cpp +++ b/src/gpg/function/GpgKeyOpera.cpp @@ -24,7 +24,7 @@ #include "gpg/function/GpgKeyOpera.h" -#include <boost/asio/read_until.hpp> +#include <boost/asio.hpp> #include <boost/date_time/posix_time/conversion.hpp> #include <boost/process/async_pipe.hpp> #include <memory> @@ -99,38 +99,45 @@ void GpgFrontend::GpgKeyOpera::GenerateRevokeCert( using boost::asio::async_write; using boost::process::async_pipe; +#ifndef WINDOWS GpgCommandExecutor::GetInstance().Execute( args, [](async_pipe& in, async_pipe& out) -> void { - boost::asio::streambuf buff; - boost::asio::read_until(in, buff, '\n'); - - std::istream is(&buff); - - while (!is.eof()) { - std::string line; - is >> line; - LOG(INFO) << "line" << line; - boost::algorithm::trim(line); - if (line == std::string("[GNUPG:] GET_BOOL gen_revoke.okay")) { - - } else if (line == - std::string( - "[GNUPG:] GET_LINE ask_revocation_reason.code")) { - - } else if (line == - std::string( - "[GNUPG:] GET_LINE ask_revocation_reason.text")) { - - } else if (line == - std::string("[GNUPG:] GET_BOOL openfile.overwrite.okay")) { - - } else if (line == - std::string( - "[GNUPG:] GET_BOOL ask_revocation_reason.okay")) { - - } - } + // boost::asio::streambuf buff; + // boost::asio::read_until(in, buff, '\n'); + // + // std::istream is(&buff); + // + // while (!is.eof()) { + // std::string line; + // is >> line; + // LOG(INFO) << "line" << line; + // boost::algorithm::trim(line); + // if (line == std::string("[GNUPG:] GET_BOOL + // gen_revoke.okay")) { + // + // } else if (line == + // std::string( + // "[GNUPG:] GET_LINE + // ask_revocation_reason.code")) { + // + // } else if (line == + // std::string( + // "[GNUPG:] GET_LINE + // ask_revocation_reason.text")) { + // + // } else if (line == + // std::string("[GNUPG:] GET_BOOL + // openfile.overwrite.okay")) { + // + // } else if (line == + // std::string( + // "[GNUPG:] GET_BOOL + // ask_revocation_reason.okay")) { + // + // } + // } }); +#endif } /** diff --git a/src/gpg/result_analyse/VerifyResultAnalyse.cpp b/src/gpg/result_analyse/VerifyResultAnalyse.cpp index 849c2051..55e50f38 100644 --- a/src/gpg/result_analyse/VerifyResultAnalyse.cpp +++ b/src/gpg/result_analyse/VerifyResultAnalyse.cpp @@ -113,7 +113,7 @@ void GpgFrontend::VerifyResultAnalyse::do_analyse() { case GPG_ERR_NO_PUBKEY: stream << _("A signature could NOT be verified due to a Missing Key") << std::endl; - setStatus(-1); + setStatus(-2); break; case GPG_ERR_CERT_REVOKED: stream << _("A signature is valid but the key used to verify the " @@ -184,3 +184,10 @@ bool GpgFrontend::VerifyResultAnalyse::print_signer(std::stringstream &stream, stream << std::endl; return keyFound; } + +gpgme_signature_t GpgFrontend::VerifyResultAnalyse::GetSignatures() { + if (result) + return result->signatures; + else + return nullptr; +} diff --git a/src/gpg/result_analyse/VerifyResultAnalyse.h b/src/gpg/result_analyse/VerifyResultAnalyse.h index c3364025..51ce17ac 100644 --- a/src/gpg/result_analyse/VerifyResultAnalyse.h +++ b/src/gpg/result_analyse/VerifyResultAnalyse.h @@ -34,6 +34,8 @@ class VerifyResultAnalyse : public ResultAnalyse { public: explicit VerifyResultAnalyse(GpgError error, GpgVerifyResult result); + gpgme_signature_t GetSignatures(); + private: void do_analyse(); diff --git a/src/main.cpp b/src/main.cpp index e3506064..82cfe9c1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -74,8 +74,6 @@ int main(int argc, char* argv[]) { */ int return_from_event_loop_code; - LOG(INFO) << _("Resource Directory") << RESOURCE_DIR(app_path); - do { QApplication::setQuitOnLastWindowClosed(true); @@ -135,25 +133,41 @@ void init_locale() { settings.lookup("general").getType() != libconfig::Setting::TypeGroup) settings.add("general", libconfig::Setting::TypeGroup); + // set system default at first auto& general = settings["general"]; if (!general.exists("lang")) - general.add("lang", libconfig::Setting::TypeString) = - QLocale::system().name().toStdString(); + general.add("lang", libconfig::Setting::TypeString) = ""; GpgFrontend::UI::GlobalSettingStation::GetInstance().Sync(); + auto* locale_name = setlocale(LC_ALL, nullptr); + LOG(INFO) << "current system locale" << locale_name; + + // read from settings file std::string lang; if (!general.lookupValue("lang", lang)) { LOG(ERROR) << _("Could not read properly from configure file"); }; LOG(INFO) << "lang" << lang; + LOG(INFO) << "PROJECT_NAME" << PROJECT_NAME; + LOG(INFO) << "locales path" + << GpgFrontend::UI::GlobalSettingStation::GetInstance() + .GetLocaleDir() + .c_str(); + if (!lang.empty()) lang += ".UTF8"; // GNU gettext settings - setlocale(LC_ALL, lang.c_str()); + locale_name = setlocale(LC_ALL, lang.c_str()); + if (locale_name == nullptr) { + LOG(WARNING) << "set locale name failed"; + } else { + LOG(INFO) << "locale name now" << locale_name; + } + bindtextdomain(PROJECT_NAME, GpgFrontend::UI::GlobalSettingStation::GetInstance() .GetLocaleDir() - .c_str()); + .string().c_str()); textdomain(PROJECT_NAME); } diff --git a/src/smtp/smtpexports.h b/src/smtp/smtpexports.h index 9ca12bae..4bad0da0 100644 --- a/src/smtp/smtpexports.h +++ b/src/smtp/smtpexports.h @@ -1,10 +1,10 @@ -#ifndef SMTPEXPORTS_H
-#define SMTPEXPORTS_H
-
-#ifdef SMTP_BUILD
-#define SMTP_EXPORT
-#else
-#define SMTP_EXPORT
-#endif
-
-#endif // SMTPEXPORTS_H
+#ifndef SMTPEXPORTS_H +#define SMTPEXPORTS_H + +#ifdef SMTP_BUILD +#define SMTP_EXPORT +#else +#define SMTP_EXPORT +#endif + +#endif // SMTPEXPORTS_H diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index acd0e42f..b80da2ec 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -16,4 +16,6 @@ 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 + Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core) + +target_compile_features(gpgfrontend-ui PUBLIC cxx_std_17)
\ No newline at end of file diff --git a/src/ui/GpgFrontendUI.h b/src/ui/GpgFrontendUI.h index c5d80d01..01f82822 100644 --- a/src/ui/GpgFrontendUI.h +++ b/src/ui/GpgFrontendUI.h @@ -25,13 +25,17 @@ #ifndef GPGFRONTEND_GPGFRONTENDUI_H #define GPGFRONTEND_GPGFRONTENDUI_H -#include <GpgFrontend.h> +#include "GpgFrontend.h" #include <QtCore> #include <QtNetwork> #include <QtPrintSupport> #include <QtWidgets> +#undef LIBCONFIGXX_STATIC +#define LIBCONFIGXX_STATIC +#include <libconfig.h++> + /** * Resources File(s) Path Vars */ diff --git a/src/ui/KeyServerImportDialog.cpp b/src/ui/KeyServerImportDialog.cpp index c7d9cd37..17db7d65 100644 --- a/src/ui/KeyServerImportDialog.cpp +++ b/src/ui/KeyServerImportDialog.cpp @@ -195,6 +195,8 @@ void KeyServerImportDialog::createKeysTable() { } void KeyServerImportDialog::setMessage(const QString& text, bool error) { + if (mAutomatic) return; + message->setText(text); if (error) { icon->setPixmap( @@ -429,7 +431,8 @@ void KeyServerImportDialog::slotImport(const QStringList& keyIds, auto manager = new QNetworkAccessManager(this); QNetworkReply* reply = manager->get(QNetworkRequest(req_url)); - connect(reply, SIGNAL(finished()), this, SLOT(slotImportFinished())); + connect(reply, &QNetworkReply::finished, this, + [&, keyId]() { this->slotImportFinished(keyId); }); LOG(INFO) << "loading start"; setLoading(true); while (reply->isRunning()) QApplication::processEvents(); @@ -438,7 +441,7 @@ void KeyServerImportDialog::slotImport(const QStringList& keyIds, } } -void KeyServerImportDialog::slotImportFinished() { +void KeyServerImportDialog::slotImportFinished(QString keyid) { LOG(INFO) << _("Called"); auto* reply = qobject_cast<QNetworkReply*>(sender()); @@ -448,18 +451,39 @@ void KeyServerImportDialog::slotImportFinished() { auto error = reply->error(); if (error != QNetworkReply::NoError) { LOG(ERROR) << "Error From Reply" << reply->errorString().toStdString(); - switch (error) { - case QNetworkReply::ContentNotFoundError: - setMessage(_("Key Not Found"), true); - break; - case QNetworkReply::TimeoutError: - setMessage(_("Timeout"), true); - break; - case QNetworkReply::HostNotFoundError: - setMessage(_("Key Server Not Found"), true); - break; - default: - setMessage(_("Connection Error"), true); + if (!mAutomatic) { + switch (error) { + case QNetworkReply::ContentNotFoundError: + setMessage(_("Key Not Found"), true); + break; + case QNetworkReply::TimeoutError: + setMessage(_("Timeout"), true); + break; + case QNetworkReply::HostNotFoundError: + setMessage(_("Key Server Not Found"), true); + break; + default: + setMessage(_("Connection Error"), true); + } + } else { + switch (error) { + case QNetworkReply::ContentNotFoundError: + QMessageBox::critical( + nullptr, _("Public key Not Found"), + QString(_("Public key fingerprint %1 not found in the Keyserver")) + .arg(keyid)); + break; + case QNetworkReply::TimeoutError: + QMessageBox::critical(nullptr, _("Timeout"), "Connection timeout"); + break; + case QNetworkReply::HostNotFoundError: + QMessageBox::critical(nullptr, _("Host Not Found"), + "cannot resolve the default Keyserver"); + break; + default: + QMessageBox::critical(nullptr, _("Connection Error"), + _("General Connection Error")); + } } if (mAutomatic) { setWindowFlags(Qt::Window | Qt::WindowTitleHint | diff --git a/src/ui/KeyServerImportDialog.h b/src/ui/KeyServerImportDialog.h index d7f3364d..67571f2f 100644 --- a/src/ui/KeyServerImportDialog.h +++ b/src/ui/KeyServerImportDialog.h @@ -53,7 +53,7 @@ class KeyServerImportDialog : public QDialog { void slotSearchFinished(); - void slotImportFinished(); + void slotImportFinished(QString keyid); void slotSearch(); diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index 31271ef1..6b0977fd 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -26,7 +26,7 @@ #include "ui/UserInterfaceUtils.h" #ifdef RELEASE -#include "ui/help/VersionCheckThread.h" +#include "ui/function/VersionCheckThread.h" #endif #include "ui/settings/GlobalSettingStation.h" diff --git a/src/ui/Wizard.cpp b/src/ui/Wizard.cpp index 67af385b..de0107c4 100644 --- a/src/ui/Wizard.cpp +++ b/src/ui/Wizard.cpp @@ -99,7 +99,9 @@ IntroPage::IntroPage(QWidget* parent) : QWizardPage(parent) { topLabel->setWordWrap(true); // QComboBox for language selection - auto* langLabel = new QLabel(_("Choose a Language")); + auto* langLabel = + new QLabel(_("If it supports the language currently being used in your " + "system, GpgFrontend will automatically set it.")); langLabel->setWordWrap(true); languages = SettingsDialog::listLanguages(); @@ -110,56 +112,64 @@ IntroPage::IntroPage(QWidget* parent) : QWizardPage(parent) { } // selected entry from config - auto lang = "en_US"; - auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); - try { - lang = settings.lookup("general.lang"); - } catch (...) { - LOG(INFO) << "Read for general.lang failed"; - } - - QString langKey = lang; - QString langValue = languages.value(langKey); - if (!langKey.isEmpty()) { - langSelectBox->setCurrentIndex(langSelectBox->findText(langValue)); - } - - connect(langSelectBox, SIGNAL(currentIndexChanged(QString)), this, - SLOT(slotLangChange(QString))); + // auto lang = ""; + // auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); + // try { + // lang = settings.lookup("general.lang"); + // } catch (...) { + // LOG(INFO) << "Read for general.lang failed"; + // } + // + // QString langKey = lang; + // QString langValue = languages.value(langKey); + // LOG(INFO) << "lang key" << langKey.toStdString() << "lang value" + // << langValue.toStdString(); + // langSelectBox->setCurrentIndex(langSelectBox->findText(langValue)); + + // connect(langSelectBox, SIGNAL(currentIndexChanged(QString)), this, + // SLOT(slotLangChange(QString))); // set layout and add widgets auto* layout = new QVBoxLayout; layout->addWidget(topLabel); + layout->addStretch(); layout->addWidget(langLabel); - layout->addWidget(langSelectBox); + // layout->addWidget(langSelectBox); + setLayout(layout); } -void IntroPage::slotLangChange(const QString& lang) { - auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); - - if (!settings.exists("general") || - settings.lookup("general").getType() != libconfig::Setting::TypeGroup) - settings.add("general", libconfig::Setting::TypeGroup); - - auto& general = settings["general"]; - if (!general.exists("lang")) - general.add("lang", libconfig::Setting::TypeString) = - languages.key(lang).toStdString(); - - if (!settings.exists("wizard") || - settings.lookup("wizard").getType() != libconfig::Setting::TypeGroup) - settings.add("wizard", libconfig::Setting::TypeGroup); - - auto& wizard = settings["wizard"]; - if (!wizard.exists("next_page")) - wizard.add("next_page", libconfig::Setting::TypeInt) = - this->wizard()->currentId(); - - GlobalSettingStation::GetInstance().Sync(); - - qApp->exit(RESTART_CODE); -} +// void IntroPage::slotLangChange(const QString& lang) { +// auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); +// +// if (!settings.exists("general") || +// settings.lookup("general").getType() != libconfig::Setting::TypeGroup) +// settings.add("general", libconfig::Setting::TypeGroup); +// +// auto& general = settings["general"]; +// if (!general.exists("lang")) +// general.add("lang", libconfig::Setting::TypeString) = +// languages.key(lang).toStdString(); +// else { +// general["lang"] = languages.key(lang).toStdString(); +// } +// +// if (!settings.exists("wizard") || +// settings.lookup("wizard").getType() != libconfig::Setting::TypeGroup) +// settings.add("wizard", libconfig::Setting::TypeGroup); +// +// auto& wizard = settings["wizard"]; +// if (!wizard.exists("next_page")) +// wizard.add("next_page", libconfig::Setting::TypeInt) = +// this->wizard()->currentId(); +// else { +// wizard["next_page"] = this->wizard()->currentId(); +// } +// +// GlobalSettingStation::GetInstance().Sync(); +// +// qApp->exit(RESTART_CODE); +// } int IntroPage::nextId() const { return Wizard::Page_Choose; } diff --git a/src/ui/Wizard.h b/src/ui/Wizard.h index 5a66fb6e..8d7395db 100644 --- a/src/ui/Wizard.h +++ b/src/ui/Wizard.h @@ -64,7 +64,7 @@ class IntroPage : public QWizardPage { private: private slots: - void slotLangChange(const QString& lang); + // void slotLangChange(const QString& lang); }; class ChoosePage : public QWizardPage { diff --git a/src/ui/function/FileReadThread.cpp b/src/ui/function/FileReadThread.cpp index 34ade8e2..a5a861ea 100644 --- a/src/ui/function/FileReadThread.cpp +++ b/src/ui/function/FileReadThread.cpp @@ -32,15 +32,15 @@ namespace GpgFrontend::UI { FileReadThread::FileReadThread(std::string path) : path(std::move(path)) {} void FileReadThread::run() { - LOG(INFO) << "read_thread Started"; + LOG(INFO) << "Started"; boost::filesystem::path read_file_path(this->path); if (is_regular_file(read_file_path)) { - LOG(INFO) << "read_thread Read Open"; + LOG(INFO) << "Read Open"; - auto fp = fopen(read_file_path.c_str(), "r"); + auto fp = fopen(read_file_path.string().c_str(), "r"); size_t read_size; LOG(INFO) << "Thread Start Reading"; - + char buffer[8192]; while ((read_size = fread(buffer, sizeof(char), sizeof buffer, fp)) > 0) { // Check isInterruptionRequested @@ -53,6 +53,11 @@ void FileReadThread::run() { std::string buffer_str(buffer, read_size); emit sendReadBlock(QString::fromStdString(buffer_str)); +#ifdef RELEASE + QThread::msleep(16); +#else + QThread::msleep(24); +#endif } fclose(fp); emit readDone(); diff --git a/src/ui/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/keypair_details/KeyPairSubkeyTab.cpp index 7b239bf1..4458be50 100644 --- a/src/ui/keypair_details/KeyPairSubkeyTab.cpp +++ b/src/ui/keypair_details/KeyPairSubkeyTab.cpp @@ -185,7 +185,7 @@ void KeyPairSubkeyTab::slotRefreshSubkeyList() { if (!row) { for (auto i = 0; i < subkeyList->columnCount(); i++) { - subkeyList->item(row, i)->setTextColor(QColor(65, 105, 255)); + subkeyList->item(row, i)->setForeground(QColor(65, 105, 255)); } } diff --git a/src/ui/keypair_details/KeyPairUIDTab.cpp b/src/ui/keypair_details/KeyPairUIDTab.cpp index 7358c20a..0ca7eb2c 100644 --- a/src/ui/keypair_details/KeyPairUIDTab.cpp +++ b/src/ui/keypair_details/KeyPairUIDTab.cpp @@ -177,7 +177,7 @@ void KeyPairUIDTab::slotRefreshUIDList() { if (!row) { for (auto i = 0; i < uidList->columnCount(); i++) { - uidList->item(row, i)->setTextColor(QColor(65, 105, 255)); + uidList->item(row, i)->setForeground(QColor(65, 105, 255)); } } diff --git a/src/ui/main_window/MainWindowFileSlotFunction.cpp b/src/ui/main_window/MainWindowFileSlotFunction.cpp index b0f7c535..0b4f7837 100644 --- a/src/ui/main_window/MainWindowFileSlotFunction.cpp +++ b/src/ui/main_window/MainWindowFileSlotFunction.cpp @@ -278,11 +278,37 @@ void MainWindow::slotFileVerify() { resultAnalyse.analyse(); process_result_analyse(edit, infoBoard, resultAnalyse); - // if (resultAnalyse->getStatus() >= 0) { + if (resultAnalyse.getStatus() == -2) { + QMessageBox::StandardButton reply; + reply = QMessageBox::question( + this, _("Public key not found locally"), + _("There is no target public key content in local for GpgFrontend to " + "gather enough information about this Signature. Do you want to " + "import the public key from Keyserver now?"), + QMessageBox::Yes | QMessageBox::No); + if (reply == QMessageBox::Yes) { + qDebug() << "Yes was clicked"; + auto dialog = KeyServerImportDialog(true, this); + auto key_ids = std::make_unique<KeyIdArgsList>(); + auto* signature = resultAnalyse.GetSignatures(); + while (signature != nullptr) { + LOG(INFO) << "signature fpr" << signature->fpr; + key_ids->push_back(signature->fpr); + signature = signature->next; + } + dialog.slotImport(key_ids); + dialog.show(); + + } else { + qDebug() << "Yes was *not* clicked"; + } + } + + // if (resultAnalyse.getStatus() >= 0) { // infoBoard->resetOptionActionsMenu(); // infoBoard->addOptionalAction( - // "Show Verify Details", [this, error, result]() { - // VerifyDetailsDialog(this, mCtx, mKeyList, error, result); + // "Show Verify Details", [this, error, &result]() { + // VerifyDetailsDialog(this, mKeyList, error, result); // }); // } diff --git a/src/ui/settings/GlobalSettingStation.cpp b/src/ui/settings/GlobalSettingStation.cpp index 8946d267..e88de93b 100644 --- a/src/ui/settings/GlobalSettingStation.cpp +++ b/src/ui/settings/GlobalSettingStation.cpp @@ -38,7 +38,7 @@ GpgFrontend::UI::GlobalSettingStation::GetInstance() { void GpgFrontend::UI::GlobalSettingStation::Sync() noexcept { using namespace libconfig; try { - ui_cfg.writeFile(ui_config_path.c_str()); + ui_cfg.writeFile(ui_config_path.string().c_str()); LOG(INFO) << _("Updated ui configuration successfully written to") << ui_config_path; @@ -70,7 +70,7 @@ GpgFrontend::UI::GlobalSettingStation::GlobalSettingStation() noexcept { if (!exists(ui_config_path)) { try { - this->ui_cfg.writeFile(ui_config_path.c_str()); + this->ui_cfg.writeFile(ui_config_path.string().c_str()); LOG(INFO) << _("UserInterface configuration successfully written to") << ui_config_path; @@ -81,7 +81,7 @@ GpgFrontend::UI::GlobalSettingStation::GlobalSettingStation() noexcept { } } else { try { - this->ui_cfg.readFile(ui_config_path.c_str()); + this->ui_cfg.readFile(ui_config_path.string().c_str()); LOG(INFO) << _("UserInterface configuration successfully read from") << ui_config_path; } catch (const FileIOException& fioex) { diff --git a/src/ui/settings/GlobalSettingStation.h b/src/ui/settings/GlobalSettingStation.h index 22713626..ef2c6a9a 100644 --- a/src/ui/settings/GlobalSettingStation.h +++ b/src/ui/settings/GlobalSettingStation.h @@ -27,7 +27,6 @@ #include <boost/filesystem/operations.hpp> #include <boost/filesystem/path.hpp> -#include <libconfig.h++> #include "ui/GpgFrontendUI.h" diff --git a/src/ui/settings/SettingsDialog.cpp b/src/ui/settings/SettingsDialog.cpp index 7fac5348..fcef70c7 100644 --- a/src/ui/settings/SettingsDialog.cpp +++ b/src/ui/settings/SettingsDialog.cpp @@ -131,7 +131,7 @@ QHash<QString, QString> SettingsDialog::listLanguages() { auto locale_path = GlobalSettingStation::GetInstance().GetLocaleDir(); - auto locale_dir = QDir(locale_path.c_str()); + auto locale_dir = QDir(QString::fromStdString(locale_path.string()) ); QStringList file_names = locale_dir.entryList(QStringList("*")); for (int i = 0; i < file_names.size(); ++i) { diff --git a/src/ui/settings/SettingsGeneral.cpp b/src/ui/settings/SettingsGeneral.cpp index c0db08a5..e6ee5499 100644 --- a/src/ui/settings/SettingsGeneral.cpp +++ b/src/ui/settings/SettingsGeneral.cpp @@ -206,7 +206,9 @@ void GeneralTab::setSettings() { QString lang_value = lang.value(lang_key.c_str()); LOG(INFO) << "lang settings current" << lang_value.toStdString(); if (!lang.empty()) { - langSelectBox->setCurrentIndex(langSelectBox->findText(lang_key.c_str())); + langSelectBox->setCurrentIndex(langSelectBox->findText(lang_value)); + } else { + langSelectBox->setCurrentIndex(0); } } catch (...) { LOG(ERROR) << _("Setting Operation Error") << _("lang"); @@ -275,26 +277,26 @@ void GeneralTab::applySettings() { #ifdef MULTI_LANG_SUPPORT if (!general.exists("lang")) general.add("lang", libconfig::Setting::TypeBoolean) = - langSelectBox->currentText().toStdString(); + lang.key(langSelectBox->currentText()).toStdString(); else { - general["lang"] = langSelectBox->currentText().toStdString(); + general["lang"] = lang.key(langSelectBox->currentText()).toStdString(); #endif + } #ifdef SERVER_SUPPORT - settings.setValue( - "general/ownKeyId", - QString::fromStdString(keyIdsList[ownKeySelectBox->currentIndex()])); + settings.setValue( + "general/ownKeyId", + QString::fromStdString(keyIdsList[ownKeySelectBox->currentIndex()])); - settings.setValue("general/serviceToken", - QString::fromStdString(serviceToken)); + settings.setValue("general/serviceToken", + QString::fromStdString(serviceToken)); #endif - if (!general.exists("confirm_import_keys")) - general.add("confirm_import_keys", libconfig::Setting::TypeBoolean) = - importConfirmationCheckBox->isChecked(); - else { - general["confirm_import_keys"] = importConfirmationCheckBox->isChecked(); - } + if (!general.exists("confirm_import_keys")) + general.add("confirm_import_keys", libconfig::Setting::TypeBoolean) = + importConfirmationCheckBox->isChecked(); + else { + general["confirm_import_keys"] = importConfirmationCheckBox->isChecked(); } } diff --git a/src/ui/widgets/EditorPage.cpp b/src/ui/widgets/EditorPage.cpp index eeedfaf5..94c98036 100644 --- a/src/ui/widgets/EditorPage.cpp +++ b/src/ui/widgets/EditorPage.cpp @@ -107,9 +107,11 @@ void EditorPage::slotFormatGpgHeader() { cursor.setCharFormat(signFormat); } -void EditorPage::readFile() { +void EditorPage::ReadFile() { LOG(INFO) << "Called"; + readDone = false; + auto text_page = this->getTextPage(); text_page->setReadOnly(true); auto thread = new FileReadThread(this->fullFilePath.toStdString()); @@ -126,19 +128,27 @@ void EditorPage::readFile() { connect(thread, &FileReadThread::finished, this, [=]() { LOG(INFO) << "Thread finished"; thread->deleteLater(); + readDone = true; + readThread = nullptr; }); - connect(this, &FileReadThread::destroyed, [=]() { + connect(this, &EditorPage::destroyed, [=]() { LOG(INFO) << "RequestInterruption for readThread"; thread->requestInterruption(); - thread->deleteLater(); + readThread = nullptr; }); - + this->readThread = thread; thread->start(); } void EditorPage::slotInsertText(const QString& text) { this->getTextPage()->insertPlainText(text); } +void EditorPage::PrepareToDestroy() { + if (readThread) { + readThread->requestInterruption(); + readThread = nullptr; + } +} } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/EditorPage.h b/src/ui/widgets/EditorPage.h index 1a19134c..a0a05dab 100644 --- a/src/ui/widgets/EditorPage.h +++ b/src/ui/widgets/EditorPage.h @@ -84,13 +84,19 @@ class EditorPage : public QWidget { */ void closeNoteByClass(const char* className); - void readFile(); + void ReadFile(); + + [[nodiscard]] bool ReadDone() const { return this->readDone; } + + void PrepareToDestroy(); private: QTextEdit* textPage; /** The textedit of the tab */ QVBoxLayout* mainLayout; /** The layout for the tab */ QString fullFilePath; /** The path to the file handled in the tab */ bool signMarked{}; /** true, if the signed header is marked, false if not */ + bool readDone = false; + QThread* readThread = nullptr; private slots: diff --git a/src/ui/widgets/FilePage.cpp b/src/ui/widgets/FilePage.cpp index bb026804..2c8df5e4 100644 --- a/src/ui/widgets/FilePage.cpp +++ b/src/ui/widgets/FilePage.cpp @@ -31,10 +31,8 @@ namespace GpgFrontend::UI { FilePage::FilePage(QWidget* parent) : QWidget(parent) { - qDebug() << "First Parent" << parent; firstParent = parent; - - qDebug() << "New File Page"; + LOG(INFO) << "New File Page"; dirModel = new QFileSystemModel(); dirModel->setRootPath(QDir::currentPath()); @@ -43,8 +41,9 @@ FilePage::FilePage(QWidget* parent) : QWidget(parent) { dirTreeView->setModel(dirModel); dirTreeView->setAnimated(true); dirTreeView->setIndentation(20); - dirTreeView->setRootIndex(dirModel->index(QDir::currentPath())); dirTreeView->setContextMenuPolicy(Qt::CustomContextMenu); + dirTreeView->setColumnWidth(0, 320); + dirTreeView->setRootIndex(dirModel->index(QDir::currentPath())); mPath = boost::filesystem::path(dirModel->rootPath().toStdString()); createPopupMenu(); @@ -63,7 +62,7 @@ FilePage::FilePage(QWidget* parent) : QWidget(parent) { upLevelButton->setIconSize(upPixmap.rect().size()); upLevelButton->setStyleSheet(buttonStyle); - refreshButton = new QPushButton("Refresh"); + refreshButton = new QPushButton(_("Refresh")); connect(refreshButton, SIGNAL(clicked(bool)), this, SLOT(slotGoPath())); goPathButton = new QPushButton(); @@ -107,7 +106,8 @@ FilePage::FilePage(QWidget* parent) : QWidget(parent) { connect(dirTreeView, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onCustomContextMenu(const QPoint&))); - emit pathChanged(mPath.c_str()); + // refresh + slotGoPath(); } void FilePage::fileTreeViewItemClicked(const QModelIndex& index) { @@ -124,31 +124,33 @@ void FilePage::slotUpLevel() { if (mPath.has_parent_path()) { mPath = mPath.parent_path(); - auto fileInfo = QFileInfo(mPath.c_str()); + auto fileInfo = QFileInfo(QString::fromStdString(mPath.string())); if (fileInfo.isDir() && fileInfo.isReadable() && fileInfo.isExecutable()) { - pathEdit->setText(mPath.c_str()); + pathEdit->setText(QString::fromStdString(mPath.string())); slotGoPath(); } LOG(INFO) << "Current Root mPath" << mPath; - emit pathChanged(mPath.c_str()); + emit pathChanged(QString::fromStdString(mPath.string())); } } void FilePage::fileTreeViewItemDoubleClicked(const QModelIndex& index) { mPath = boost::filesystem::path( dirModel->fileInfo(index).absoluteFilePath().toStdString()); - auto fileInfo = QFileInfo(mPath.c_str()); + auto fileInfo = QFileInfo(QString::fromStdString(mPath.string())); auto targetModelIndex = dirTreeView->model()->index(index.row(), 0, index.parent()); if (fileInfo.isDir() && fileInfo.isReadable() && fileInfo.isExecutable()) { dirTreeView->setRootIndex(targetModelIndex); - pathEdit->setText(mPath.c_str()); + pathEdit->setText(QString::fromStdString(mPath.string())); } + for (int i = 1; i < dirModel->columnCount(); ++i) + dirTreeView->resizeColumnToContents(i); LOG(INFO) << "Index mPath" << mPath; - emit pathChanged(mPath.c_str()); + emit pathChanged(QString::fromStdString(mPath.string())); } -QString FilePage::getSelected() const { return selectedPath.c_str(); } +QString FilePage::getSelected() const { return QString::fromStdString(selectedPath.string()); } void FilePage::slotGoPath() { qDebug() << "getSelected" << pathEdit->text(); @@ -157,11 +159,13 @@ void FilePage::slotGoPath() { mPath = boost::filesystem::path(fileInfo.filePath().toStdString()); LOG(INFO) << "Set Path" << mPath; dirTreeView->setRootIndex(dirModel->index(fileInfo.filePath())); + for (int i = 1; i < dirModel->columnCount(); ++i) + dirTreeView->resizeColumnToContents(i); } else { QMessageBox::critical(this, "Error", "The path is unprivileged or unreachable."); } - emit pathChanged(mPath.c_str()); + emit pathChanged(QString::fromStdString(mPath.string())); } void FilePage::createPopupMenu() { @@ -195,7 +199,7 @@ void FilePage::onCustomContextMenu(const QPoint& point) { dirModel->fileInfo(index).absoluteFilePath().toStdString()); LOG(INFO) << "FilePage::onCustomContextMenu Right Click" << selectedPath; if (index.isValid()) { - QFileInfo info(selectedPath.c_str()); + QFileInfo info(QString::fromStdString(selectedPath.string())); encryptItemAct->setEnabled( info.isFile() && (info.suffix() != "gpg" && info.suffix() != "sig")); decryptItemAct->setEnabled(info.isFile() && info.suffix() == "gpg"); @@ -209,7 +213,7 @@ void FilePage::onCustomContextMenu(const QPoint& point) { } void FilePage::slotOpenItem() { - QFileInfo info(selectedPath.c_str()); + QFileInfo info(QString::fromStdString(selectedPath.string())); if (info.isDir()) { LOG(INFO) << "FilePage::slotOpenItem getSelected" << pathEdit->text().toStdString(); diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp index 528a4c88..8d4ea4a0 100644 --- a/src/ui/widgets/TextEdit.cpp +++ b/src/ui/widgets/TextEdit.cpp @@ -83,7 +83,7 @@ void TextEdit::slotOpenFile(QString& path) { tabWidget->setCurrentIndex(tabWidget->count() - 1); QApplication::restoreOverrideCursor(); page->getTextPage()->setFocus(); - page->readFile(); + page->ReadFile(); } else { QMessageBox::warning(this, _("Warning"), (boost::format(_("Cannot read file %1%:\n%2%.")) % @@ -250,7 +250,7 @@ bool TextEdit::maybeSaveCurrentTab(bool askToSave) { } QTextDocument* document = page->getTextPage()->document(); - if (document->isModified()) { + if (page->ReadDone() && document->isModified()) { QMessageBox::StandardButton result = QMessageBox::Cancel; // write title of tab to docname and remove the leading * @@ -284,6 +284,9 @@ bool TextEdit::maybeSaveCurrentTab(bool askToSave) { return false; } } + + // destroy + page->PrepareToDestroy(); return true; } @@ -326,20 +329,16 @@ bool TextEdit::maybeSaveAnyTab() { return false; } } else { - bool allsaved = true; + bool all_saved = true; QList<int> tabIdsToSave = dialog->getTabIdsToSave(); - foreach (int tabId, tabIdsToSave) { + for (const auto& tabId : tabIdsToSave) { tabWidget->setCurrentIndex(tabId); if (!maybeSaveCurrentTab(false)) { - allsaved = false; + all_saved = false; } } - if (allsaved) { - return true; - } else { - return false; - } + return all_saved; } } // code should never reach this statement @@ -489,11 +488,14 @@ QHash<int, QString> TextEdit::unsavedDocuments() const { for (int i = 0; i < tabWidget->count(); i++) { auto* ep = qobject_cast<EditorPage*>(tabWidget->widget(i)); - if (ep != nullptr && ep->getTextPage()->document()->isModified()) { - QString docname = tabWidget->tabText(i); + if (ep != nullptr && ep->ReadDone() && + ep->getTextPage()->document()->isModified()) { + QString doc_name = tabWidget->tabText(i); + LOG(INFO) << "unsaved" << doc_name.toStdString(); + // remove * before name of modified doc - docname.remove(0, 2); - unsavedDocs.insert(i, docname); + doc_name.remove(0, 2); + unsavedDocs.insert(i, doc_name); } } return unsavedDocs; |