diff --git a/client/Application.cpp b/client/Application.cpp index 0a8adec45..5e898c2dc 100644 --- a/client/Application.cpp +++ b/client/Application.cpp @@ -25,6 +25,7 @@ #include "QSigner.h" #include "QSmartCard.h" #include "DigiDoc.h" +#include "Settings.h" #include "Styles.h" #ifdef Q_OS_MAC #include "MacMenuBar.h" @@ -52,7 +53,6 @@ class MacMenuBar {}; #include #include #include -#include #include #include #include @@ -90,8 +90,7 @@ class DigidocConf final: public digidoc::XmlConfCurrent public: DigidocConf() { - debug = s.value(QStringLiteral("LibdigidocppDebug"), false).toBool(); - s.remove(QStringLiteral("LibdigidocppDebug")); + Settings::LIBDIGIDOCPP_DEBUG = false; #ifdef CONFIG_URL reload(); @@ -121,73 +120,74 @@ class DigidocConf final: public digidoc::XmlConfCurrent std::string proxyHost() const final { return proxyConf(&QNetworkProxy::hostName, - QStringLiteral("ProxyHost"), [this] { return digidoc::XmlConfCurrent::proxyHost(); }); + Settings::PROXY_HOST, [this] { return digidoc::XmlConfCurrent::proxyHost(); }); } std::string proxyPort() const final { return proxyConf([](const QNetworkProxy &systemProxy) { return QString::number(systemProxy.port()); }, - QStringLiteral("ProxyPort"), [this] { return digidoc::XmlConfCurrent::proxyPort(); }); + Settings::PROXY_PORT, [this] { return digidoc::XmlConfCurrent::proxyPort(); }); } std::string proxyUser() const final { return proxyConf(&QNetworkProxy::user, - QStringLiteral("ProxyUser"), [this] { return digidoc::XmlConfCurrent::proxyUser(); }); + Settings::PROXY_USER, [this] { return digidoc::XmlConfCurrent::proxyUser(); }); } std::string proxyPass() const final { return proxyConf(&QNetworkProxy::password, - QStringLiteral("ProxyPass"), [this] { return digidoc::XmlConfCurrent::proxyPass(); }); + Settings::PROXY_PASS, [this] { return digidoc::XmlConfCurrent::proxyPass(); }); } #ifdef Q_OS_MAC bool proxyTunnelSSL() const final - { return s.value(QStringLiteral("ProxyTunnelSSL"), digidoc::XmlConfCurrent::proxyTunnelSSL()).toBool(); } + { return Settings::PROXY_TUNNEL_SSL.value(digidoc::XmlConfCurrent::proxyTunnelSSL()); } bool PKCS12Disable() const final - { return s.value(QStringLiteral("PKCS12Disable"), digidoc::XmlConfCurrent::PKCS12Disable()).toBool(); } + { return Settings::PKCS12_DISABLE.value(digidoc::XmlConfCurrent::PKCS12Disable()); } std::string TSLCache() const final { return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation).toStdString(); } bool TSLOnlineDigest() const final - { return s.value(QStringLiteral("TSLOnlineDigest"), digidoc::XmlConfCurrent::TSLOnlineDigest()).toBool(); } + { return Settings::TSL_ONLINE_DIGEST.value(digidoc::XmlConfCurrent::TSLOnlineDigest()); } void setProxyHost( const std::string &host ) final - { SettingsDialog::setValueEx(QStringLiteral("ProxyHost"), fromStdString(host)); } + { Settings::PROXY_HOST = host; } void setProxyPort( const std::string &port ) final - { SettingsDialog::setValueEx(QStringLiteral("ProxyPort"), fromStdString(port)); } + { Settings::PROXY_PORT = port; } void setProxyUser( const std::string &user ) final - { SettingsDialog::setValueEx(QStringLiteral("ProxyUser"), fromStdString(user)); } + { Settings::PROXY_USER = user; } void setProxyPass( const std::string &pass ) final - { SettingsDialog::setValueEx(QStringLiteral("ProxyPass"), fromStdString(pass)); } + { Settings::PROXY_PASS = pass; } void setProxyTunnelSSL( bool enable ) final - { SettingsDialog::setValueEx(QStringLiteral("ProxyTunnelSSL"), enable, digidoc::XmlConfCurrent::proxyTunnelSSL()); } + { Settings::PROXY_TUNNEL_SSL.setValue(enable, digidoc::XmlConfCurrent::proxyTunnelSSL()); } void setPKCS12Cert( const std::string & /*cert*/) final {} void setPKCS12Pass( const std::string & /*pass*/) final {} void setPKCS12Disable( bool disable ) final - { SettingsDialog::setValueEx(QStringLiteral("PKCS12Disable"), disable, digidoc::XmlConfCurrent::PKCS12Disable()); } + { Settings::PKCS12_DISABLE.setValue(disable, digidoc::XmlConfCurrent::PKCS12Disable()); } void setTSLOnlineDigest( bool enable ) final - { SettingsDialog::setValueEx(QStringLiteral("TSLOnlineDigest"), enable, digidoc::XmlConfCurrent::TSLOnlineDigest()); } + { Settings::TSL_ONLINE_DIGEST.setValue(enable, digidoc::XmlConfCurrent::TSLOnlineDigest()); } #endif std::vector TSCerts() const final { std::vector list = toCerts(QLatin1String("CERT-BUNDLE")); - if(digidoc::X509Cert cert = toCert(fromBase64(s.value(QStringLiteral("TSA-CERT"))))) + if(digidoc::X509Cert cert = toCert(fromBase64(QVariant(Settings::TSA_CERT)))) list.push_back(cert); return list; } std::string TSUrl() const final { - if(s.value(QStringLiteral("TSA-URL-CUSTOM"), s.contains(QStringLiteral("TSA-URL"))).toBool()) - return valueUserScope(QStringLiteral("TSA-URL"), digidoc::XmlConfCurrent::TSUrl()); - return valueSystemScope(QStringLiteral("TSA-URL"), digidoc::XmlConfCurrent::TSUrl()); + if(Settings::TSA_URL_CUSTOM) + return valueUserScope(Settings::TSA_URL, digidoc::XmlConfCurrent::TSUrl()); + return valueSystemScope(Settings::TSA_URL.KEY, digidoc::XmlConfCurrent::TSUrl()); } void setTSUrl(const std::string &url) final - { SettingsDialog::setValueEx(QStringLiteral("TSA-URL"), fromStdString(url)); } + { Settings::TSA_URL = url; } - std::string TSLUrl() const final { return valueSystemScope(QStringLiteral("TSL-URL"), digidoc::XmlConfCurrent::TSLUrl()); } + std::string TSLUrl() const final + { return valueSystemScope(QLatin1String("TSL-URL"), digidoc::XmlConfCurrent::TSLUrl()); } std::vector TSLCerts() const final { std::vector tslcerts = toCerts(QLatin1String("TSL-CERTS")); @@ -196,10 +196,8 @@ class DigidocConf final: public digidoc::XmlConfCurrent digidoc::X509Cert verifyServiceCert() const final { - QByteArray cert = fromBase64(obj.value(QStringLiteral("SIVA-CERT"))); - if(cert.isEmpty()) - return digidoc::XmlConfCurrent::verifyServiceCert(); - return toCert(cert); + QByteArray cert = fromBase64(obj.value(Settings::SIVA_CERT.KEY)); + return cert.isEmpty() ? digidoc::XmlConfCurrent::verifyServiceCert() : toCert(cert); } std::vector verifyServiceCerts() const final { @@ -210,12 +208,12 @@ class DigidocConf final: public digidoc::XmlConfCurrent } std::string verifyServiceUri() const final { - if(s.value(QStringLiteral("SIVA-URL-CUSTOM"), s.contains(QStringLiteral("SIVA-URL"))).toBool()) - return valueUserScope(QStringLiteral("SIVA-URL"), digidoc::XmlConfCurrent::verifyServiceUri()); - return valueSystemScope(QStringLiteral("SIVA-URL"), digidoc::XmlConfCurrent::verifyServiceUri()); + if(Settings::SIVA_URL_CUSTOM) + return valueUserScope(Settings::SIVA_URL, digidoc::XmlConfCurrent::verifyServiceUri()); + return valueSystemScope(Settings::SIVA_URL.KEY, digidoc::XmlConfCurrent::verifyServiceUri()); } void setVerifyServiceUri(const std::string &url) final - { SettingsDialog::setValueEx(QStringLiteral("SIVA-URL"), QString::fromStdString(url), QString()); } + { Settings::SIVA_URL = url; } std::string ocsp(const std::string &issuer) const final { @@ -225,7 +223,7 @@ class DigidocConf final: public digidoc::XmlConfCurrent if(issuer == i.key().toStdString()) return i.value().toString().toStdString(); } - return obj.value(QStringLiteral("OCSP-URL")).toString(fromStdString(digidoc::XmlConfCurrent::ocsp(issuer))).toStdString(); + return valueSystemScope(QLatin1String("OCSP-URL"), digidoc::XmlConfCurrent::ocsp(issuer)); } bool TSLAllowExpired() const final @@ -249,8 +247,8 @@ class DigidocConf final: public digidoc::XmlConfCurrent void reload() { obj = qApp->conf()->object(); - if(s.value(QStringLiteral("TSA-URL")) == obj.value(QStringLiteral("TSA-URL"))) - s.remove(QStringLiteral("TSA-URL")); // Cleanup user conf if it is default url + if(Settings::TSA_URL == obj.value(Settings::TSA_URL.KEY).toString()) + Settings::TSA_URL.clear(); // Cleanup user conf if it is default url QList list; for(const auto &cert: obj.value(QStringLiteral("CERT-BUNDLE")).toArray()) list.append(QSslCertificate(fromBase64(cert), QSsl::Der)); @@ -260,23 +258,25 @@ class DigidocConf final: public digidoc::XmlConfCurrent } #endif - std::string valueSystemScope(const QString &key, const std::string &defaultValue) const + template + std::string valueSystemScope(const T &key, std::string &&defaultValue) const { - return obj.value(key).toString(fromStdString(defaultValue)).toStdString(); + return obj.contains(key) ? obj.value(key).toString().toStdString() : std::forward(defaultValue); } - std::string valueUserScope(const QString &key, const std::string &defaultValue) const + template + std::string valueUserScope(const Option &option, std::string &&defaultValue) const { - return s.value(key, obj.value(key).toString(fromStdString(defaultValue))).toString().toStdString(); + return option.isSet() ? option : valueSystemScope(option.KEY, std::forward(defaultValue)); } - template - std::string proxyConf(System &&system, const QString &key, Config &&config) const + template + std::string proxyConf(System &&system, const Option &option, Config &&config) const { - switch(s.value(QStringLiteral("ProxyConfig")).toUInt()) + switch(Settings::PROXY_CONFIG) { - case 0: return {}; - case 1: return std::invoke(system, [] { + case Settings::ProxyNone: return {}; + case Settings::ProxySystem: return std::invoke(system, [] { for(const QNetworkProxy &proxy: QNetworkProxyFactory::systemProxyForQuery()) { if(proxy.type() == QNetworkProxy::HttpProxy) @@ -284,7 +284,7 @@ class DigidocConf final: public digidoc::XmlConfCurrent } return QNetworkProxy{}; }()).toStdString(); - default: return s.contains(key) ? s.value(key).toString().toStdString() : config(); + default: return option.isSet() ? option : config(); } } @@ -310,9 +310,7 @@ class DigidocConf final: public digidoc::XmlConfCurrent return certs; } - static constexpr auto fromStdString = &QString::fromStdString; - QSettings s; - bool debug = false; + bool debug = Settings::LIBDIGIDOCPP_DEBUG; public: QJsonObject obj; }; @@ -389,7 +387,7 @@ Application::Application( int &argc, char **argv ) connect(d->newClientAction, &QAction::triggered, this, [&]{ showClient({}, false, false, true); }); // This is needed to release application from memory (Windows) - setQuitOnLastWindowClosed( true ); + setQuitOnLastWindowClosed( true ); d->lastWindowTimer.setSingleShot(true); connect(&d->lastWindowTimer, &QTimer::timeout, this, []{ if(topLevelWindows().isEmpty()) quit(); }); connect(this, &Application::lastWindowClosed, this, [&]{ d->lastWindowTimer.start(10s); }); @@ -452,7 +450,7 @@ Application::Application( int &argc, char **argv ) QTimer::singleShot(0, this, [this] { QWidget *parent = mainWindow(); #ifdef Q_OS_MAC - if(QSettings().value(QStringLiteral("plugins")).isNull()) + if(!Settings::PLUGINS.isSet()) { auto *dlg = new WarningDialog(tr( "In order to authenticate and sign in e-services with an ID-card you need to install the web browser components."), parent); @@ -465,15 +463,15 @@ Application::Application( int &argc, char **argv ) { case QMessageBox::Open: QDesktopServices::openUrl(tr("https://www.id.ee/en/article/install-id-software/")); break; case QMessageBox::Ignore: break; - default: QSettings().setValue(QStringLiteral("plugins"), "ignore"); + default: Settings::PLUGINS = QStringLiteral("ignore"); } }); dlg->open(); } #endif - if(QSettings().value(QStringLiteral("showIntro"), true).toBool()) + if(Settings::SHOW_INTRO) { - QSettings().setValue(QStringLiteral("showIntro"), false); + Settings::SHOW_INTRO = false; auto *dlg = new FirstRun(parent); connect(dlg, &FirstRun::langChanged, this, [this](const QString& lang) { loadTranslation( lang ); }); dlg->open(); @@ -611,6 +609,19 @@ Configuration* Application::conf() return d->conf; } +template +QJsonValue Application::confValue(const T &key) +{ +#ifdef CONFIG_URL + return qApp->conf()->object().value(key); +#else + return {}; +#endif +} + +template QJsonValue Application::confValue(const QString &key); +template QJsonValue Application::confValue(const QLatin1String &key); + QVariant Application::confValue( ConfParameter parameter, const QVariant &value ) { auto *i = static_cast(digidoc::Conf::instance()); @@ -680,7 +691,7 @@ void Application::loadTranslation( const QString &lang ) { if( d->lang == lang ) return; - QSettings().setValue(QStringLiteral("Language"), d->lang = lang); + Settings::LANGUAGE = d->lang = lang; if(lang == QLatin1String("en")) QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedKingdom)); else if(lang == QLatin1String("ru")) QLocale::setDefault(QLocale( QLocale::Russian, QLocale::RussianFederation)); @@ -830,14 +841,14 @@ void Application::migrateSettings() #endif newSettings.remove(QStringLiteral("Client/Type")); - if(newSettings.value(QStringLiteral("SettingsMigrated"), false).toBool()) + if(Settings::SETTINGS_MIGRATED) return; #ifdef Q_OS_WIN QSettings reg(QStringLiteral("HKEY_CURRENT_USER\\Software"), QSettings::NativeFormat); if(!reg.childGroups().contains(QStringLiteral("Estonian ID Card"))) { - newSettings.setValue(QStringLiteral("SettingsMigrated"), true); + Settings::SETTINGS_MIGRATED = true; return; } @@ -854,34 +865,34 @@ void Application::migrateSettings() #endif static const QVector> orgOldNewKeys { - {"showIntro", "showIntro"}, + {"showIntro", Settings::SHOW_INTRO.KEY}, {"PKCS12Disable","PKCS12Disable"}, - {"Client/MobileCode","MobileCode"}, - {"Client/MobileNumber","MobileNumber"}, - {"ProxyHost","ProxyHost"}, - {"ProxyPass","ProxyPass"}, - {"ProxyPort","ProxyPort"}, - {"ProxyUser","ProxyUser"}, + {"Client/MobileCode", Settings::MOBILEID_CODE.KEY}, + {"Client/MobileNumber", Settings::MOBILEID_NUMBER.KEY}, + {"ProxyHost", Settings::PROXY_HOST.KEY}, + {"ProxyPass", Settings::PROXY_PASS.KEY}, + {"ProxyPort", Settings::PROXY_PORT.KEY}, + {"ProxyUser", Settings::PROXY_USER.KEY}, {"Client/City","City"}, {"Client/Country","Country"}, {"Client/Zip","Zip"}, {"Client/Role","Role"}, {"Client/State","State"}, {"Client/Resolution","Resolution"}, - {"Main/language","Language"}, - {"Client/DefaultDir","DefaultDir"}, + {"Main/language", Settings::LANGUAGE.KEY}, + {"Client/DefaultDir", Settings::DEFAULT_DIR.KEY}, {"ProxyTunnelSSL","ProxyTunnelSSL"} }; static const QVector> appOldNewKeys { {"TSLOnlineDigest", "TSLOnlineDigest"}, - {"Client/proxyConfig", "ProxyConfig"}, - {"lastPath", "lastPath"}, + {"Client/proxyConfig", Settings::PROXY_CONFIG.KEY}, + {"lastPath", Settings::LAST_PATH.KEY}, {"LastCheck", "LastCheck"}, - {"Client/RoleAddressInfo", "RoleAddressInfo"}, - {"Client/ShowPrintSummary", "ShowPrintSummary"}, - {"TSA-URL", "TSA-URL"}, - {"MobileSettings", "MobileSettings"}, + {"Client/RoleAddressInfo", Settings::SHOW_ROLE_ADDRESS_INFO.KEY}, + {"Client/ShowPrintSummary", Settings::SHOW_PRINT_SUMMARY.KEY}, + {"TSA-URL", Settings::TSA_URL.KEY}, + {"MobileSettings", Settings::MOBILEID_REMEMBER.KEY}, }; for(const QPair &keypairs: orgOldNewKeys) { @@ -917,13 +928,12 @@ void Application::migrateSettings() newSettings.setValue(key, oldAppSettings.value(key)); } - newSettings.setValue(QStringLiteral("SettingsMigrated"), true); + Settings::SETTINGS_MIGRATED = true; #ifndef Q_OS_MAC - QString key = "proxyConfig"; - if(!newSettings.contains("showIntro") && !newSettings.contains("ProxyConfig") && dd3Settings.contains(key)) + if(!Settings::SHOW_INTRO && !Settings::PROXY_CONFIG.isSet() && dd3Settings.contains(Settings::PROXY_CONFIG.KEY)) { - newSettings.setValue("ProxyConfig", dd3Settings.value(key)); + Settings::PROXY_CONFIG = dd3Settings.value(Settings::PROXY_CONFIG.KEY); SettingsDialog::loadProxy(digidoc::Conf::instance()); } diff --git a/client/Application.h b/client/Application.h index 00eea9f30..32594414a 100644 --- a/client/Application.h +++ b/client/Application.h @@ -70,6 +70,8 @@ class Application final: public Common void waitForTSL( const QString &file ); static void addRecent( const QString &file ); + template + static QJsonValue confValue(const T &key); static QVariant confValue(ConfParameter parameter, const QVariant &value = {}); static void clearConfValue( ConfParameter parameter ); static void initDiagnosticConf(); diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 5344d3e1c..5932bfae7 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -13,7 +13,7 @@ configure_file( translations/tr.qrc tr.qrc COPYONLY ) qt_add_translation(SOURCES translations/en.ts translations/et.ts translations/ru.ts) add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE - ${PROJECT_NAME}.rc + ${PROJECT_NAME}.rc ${SOURCES} images/images.qrc fonts/fonts.qrc @@ -41,6 +41,7 @@ add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE sslConnect.cpp Styles.cpp PrintSheet.cpp + Settings.cpp SslCertificate.cpp TokenData.cpp dialogs/AccessCert.cpp @@ -137,21 +138,21 @@ endif() if(${QT_VERSION_MAJOR} STREQUAL "6") find_package(Qt6 COMPONENTS Core5Compat SvgWidgets REQUIRED) - target_link_libraries(${PROJECT_NAME} Qt6::Core5Compat Qt6::SvgWidgets) + target_link_libraries(${PROJECT_NAME} Qt6::Core5Compat Qt6::SvgWidgets) elseif(WIN32) find_package(Qt5 COMPONENTS WinExtras) - target_compile_definitions(${PROJECT_NAME} PRIVATE QT_WIN_EXTRAS) - target_link_libraries(${PROJECT_NAME} Qt5::WinExtras) + target_compile_definitions(${PROJECT_NAME} PRIVATE QT_WIN_EXTRAS) + target_link_libraries(${PROJECT_NAME} Qt5::WinExtras) endif() set_target_properties(${PROJECT_NAME} PROPERTIES AUTOUIC ON AUTORCC ON MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/mac/Info.plist.cmake - MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME} - MACOSX_BUNDLE_GUI_IDENTIFIER "ee.ria.${PROJECT_NAME}" + MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME} + MACOSX_BUNDLE_GUI_IDENTIFIER "ee.ria.${PROJECT_NAME}" ) -target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR} ${LIBDIGIDOCPP_INCLUDE_DIR} ) +target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR} ${LIBDIGIDOCPP_INCLUDE_DIR}) target_compile_definitions(${PROJECT_NAME} PRIVATE MOBILEID_URL="${MOBILEID_URL}" SMARTID_URL="${SMARTID_URL}" @@ -168,58 +169,58 @@ if( APPLE ) set_source_files_properties( ${_file} PROPERTIES MACOSX_PACKAGE_LOCATION ${_file_dir}) endforeach(_file) - target_sources(${PROJECT_NAME} PRIVATE ${RESOURCE_FILES} Application_mac.mm MacMenuBar.cpp dialogs/CertificateDetails_mac.mm Diagnostics_unix.cpp) + target_sources(${PROJECT_NAME} PRIVATE ${RESOURCE_FILES} Application_mac.mm MacMenuBar.cpp dialogs/CertificateDetails_mac.mm Diagnostics_unix.cpp) set_source_files_properties( Application_mac.mm dialogs/CertificateDetails_mac.mm PROPERTIES COMPILE_FLAGS "-fobjc-arc" ) set_source_files_properties( LdapSearch.cpp PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations" ) - target_link_libraries(${PROJECT_NAME} "-framework Security" "-framework Quartz" "-framework Cocoa" "-fobjc-arc") - add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND cp -a ${PKCS11_MODULE} $ - COMMAND mkdir -p $/Library/QuickLook - COMMAND cp -a $ $/Library/QuickLook + target_link_libraries(${PROJECT_NAME} "-framework Security" "-framework Quartz" "-framework Cocoa" "-fobjc-arc") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND cp -a ${PKCS11_MODULE} $ + COMMAND mkdir -p $/Library/QuickLook + COMMAND cp -a $ $/Library/QuickLook ) - add_custom_target(macdeployqt DEPENDS ${PROJECT_NAME} - COMMAND ${qtCore_install_prefix}/macdeployqt $ - COMMAND rm -rf $/PlugIns/bearer - COMMAND cp -a /Library/Frameworks/digidocpp.framework $/Frameworks - COMMAND rm $/Frameworks/digidocpp.framework/Resources/digidoc-tool - COMMAND find $/Frameworks -name Headers | xargs rm -rf - COMMAND install_name_tool -delete_rpath /Library/Frameworks $ + add_custom_target(macdeployqt DEPENDS ${PROJECT_NAME} + COMMAND ${qtCore_install_prefix}/macdeployqt $ + COMMAND rm -rf $/PlugIns/bearer + COMMAND cp -a /Library/Frameworks/digidocpp.framework $/Frameworks + COMMAND rm $/Frameworks/digidocpp.framework/Resources/digidoc-tool + COMMAND find $/Frameworks -name Headers | xargs rm -rf + COMMAND install_name_tool -delete_rpath /Library/Frameworks $ COMMAND ln -sf digidocpp.framework/Libraries/libcrypto.dylib - $/Frameworks/libcrypto.1.1.dylib + $/Frameworks/libcrypto.1.1.dylib COMMAND ln -sf digidocpp.framework/Libraries/libssl.dylib - $/Frameworks/libssl.1.1.dylib + $/Frameworks/libssl.1.1.dylib ) - add_custom_target(codesign DEPENDS ${PROJECT_NAME} + add_custom_target(codesign DEPENDS ${PROJECT_NAME} COMMAND codesign -f -s \"$$SIGNCERT\" - $/*.* - $/Frameworks/digidocpp.framework/Libraries/* - $/Frameworks/*.framework - $/PlugIns/*/* - $/Library/QuickLook/DigiDocQL.qlgenerator + $/*.* + $/Frameworks/digidocpp.framework/Libraries/* + $/Frameworks/*.framework + $/PlugIns/*/* + $/Library/QuickLook/DigiDocQL.qlgenerator COMMAND if echo \"$$SIGNCERT\" | grep -q "Developer ID" \; then - codesign -f -s \"$$SIGNCERT\" $ --entitlements ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.eToken.entitlements\; + codesign -f -s \"$$SIGNCERT\" $ --entitlements ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.eToken.entitlements\; else - codesign -f -s \"$$SIGNCERT\" $ --entitlements ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.entitlements\; + codesign -f -s \"$$SIGNCERT\" $ --entitlements ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.entitlements\; fi ) - add_custom_target(productbuild DEPENDS ${PROJECT_NAME} - COMMAND productbuild --component $ /Applications + add_custom_target(productbuild DEPENDS ${PROJECT_NAME} + COMMAND productbuild --component $ /Applications --sign \"$$INSTCERT\" ${CMAKE_BINARY_DIR}/qdigidoc4-store_${VERSION}$ENV{VER_SUFFIX}.pkg ) - add_custom_target(zip DEPENDS ${PROJECT_NAME} - COMMAND zip --symlinks -r -D ${CMAKE_BINARY_DIR}/qdigidoc4_${VERSION}$ENV{VER_SUFFIX}.zip ${PROJECT_NAME}.app + add_custom_target(zip DEPENDS ${PROJECT_NAME} + COMMAND zip --symlinks -r -D ${CMAKE_BINARY_DIR}/qdigidoc4_${VERSION}$ENV{VER_SUFFIX}.zip ${PROJECT_NAME}.app ) - add_custom_target(zipdebug DEPENDS ${PROJECT_NAME} - COMMAND dsymutil -o ${PROJECT_NAME}.dSYM $ - COMMAND zip -r ${CMAKE_BINARY_DIR}/qdigidoc4-dbg_${VERSION}$ENV{VER_SUFFIX}.zip ${PROJECT_NAME}.dSYM + add_custom_target(zipdebug DEPENDS ${PROJECT_NAME} + COMMAND dsymutil -o ${PROJECT_NAME}.dSYM $ + COMMAND zip -r ${CMAKE_BINARY_DIR}/qdigidoc4-dbg_${VERSION}$ENV{VER_SUFFIX}.zip ${PROJECT_NAME}.dSYM ) elseif(WIN32) - target_sources(${PROJECT_NAME} PRIVATE QCNG.cpp CertStore.cpp Diagnostics_win.cpp) - target_compile_options(${PROJECT_NAME} PRIVATE "/guard:cf") - target_link_options(${PROJECT_NAME} PRIVATE "/guard:cf" $<$:/INTEGRITYCHECK>) - target_link_libraries(${PROJECT_NAME} NCrypt Crypt32 Cryptui) + target_sources(${PROJECT_NAME} PRIVATE QCNG.cpp CertStore.cpp Diagnostics_win.cpp) + target_compile_options(${PROJECT_NAME} PRIVATE "/guard:cf") + target_link_options(${PROJECT_NAME} PRIVATE "/guard:cf" $<$:/INTEGRITYCHECK>) + target_link_libraries(${PROJECT_NAME} NCrypt Crypt32 Cryptui) get_filename_component(LIBS_PATH ${LIBDIGIDOCPP_LIBRARIES} DIRECTORY) if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(PLATFORM x64) @@ -230,7 +231,7 @@ elseif(WIN32) endif() set(MSI_FILE "Digidoc4_Client-${VERSION}$ENV{VER_SUFFIX}.${PLATFORM}") list(APPEND CANDLE_CMD "$ENV{WIX}bin\\candle.exe" -nologo -arch ${PLATFORM} -dMSI_VERSION=${VERSION} -dPlatform=${PLATFORM} - -dlibs_path="${LIBS_PATH}" -dclient_path=$ -dico_path=${CMAKE_CURRENT_SOURCE_DIR}/images/digidoc.ico + -dlibs_path="${LIBS_PATH}" -dclient_path=$ -dico_path=${CMAKE_CURRENT_SOURCE_DIR}/images/digidoc.ico -dqtconf=${CMAKE_SOURCE_DIR}/qt.conf -dschemasLocation=${LIBS_PATH}/schema SchemasFragment.wxs -dqt_ver_major=${QT_VERSION_MAJOR} -dqt_suffix=$<$:d> ${CMAKE_SOURCE_DIR}/qdigidoc4.wxs ${CMAKE_SOURCE_DIR}/cmake/modules/WelcomeDlg2.wxs ${CMAKE_SOURCE_DIR}/cmake/modules/WixUI_Minimal2.wxs) @@ -238,7 +239,7 @@ elseif(WIN32) qdigidoc4.wixobj SchemasFragment.wixobj WelcomeDlg2.wixobj WixUI_Minimal2.wixobj -dWixUIDialogBmp=${CMAKE_SOURCE_DIR}/cmake/modules/dlgbmp.bmp -dWixUIBannerBmp=${CMAKE_SOURCE_DIR}/cmake/modules/banner.bmp) - add_custom_target(msi DEPENDS ${PROJECT_NAME} + add_custom_target(msi DEPENDS ${PROJECT_NAME} COMMAND "$ENV{WIX}bin\\heat.exe" dir ${LIBS_PATH}/schema -nologo -cg Schemas -gg -scom -sreg -sfrag -srd -dr SchemaFolder -var var.schemasLocation -out SchemasFragment.wxs COMMAND ${CANDLE_CMD} COMMAND ${LIGHT_CMD} -loc ${CMAKE_SOURCE_DIR}/qdigidoc4.en-US.wxl -cultures:en-US -o "${MSI_FILE}.en-US.msi" @@ -252,8 +253,8 @@ elseif(WIN32) if(SIGNCERT) list(APPEND SIGNCMD signtool.exe sign /a /v /s MY /n "${SIGNCERT}" /fd SHA256 /du http://installer.id.ee /tr http://sha256timestamp.ws.symantec.com/sha256/timestamp /td SHA256) - add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${SIGNCMD} "$<$:/ph;/ac;${CROSSSIGNCERT}>" $ + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${SIGNCMD} "$<$:/ph;/ac;${CROSSSIGNCERT}>" $ COMMAND_EXPAND_LISTS ) add_custom_command(TARGET msi POST_BUILD @@ -262,12 +263,12 @@ elseif(WIN32) ) endif() configure_file(${CMAKE_SOURCE_DIR}/AppxManifest.xml.cmake ${CMAKE_BINARY_DIR}/AppxManifest.xml) - add_custom_target(appx DEPENDS ${PROJECT_NAME} + add_custom_target(appx DEPENDS ${PROJECT_NAME} COMMAND ${CMAKE_COMMAND} -E remove ${MSI_FILE}.appx COMMAND ${CMAKE_COMMAND} -E remove_directory appx COMMAND ${CMAKE_COMMAND} -E make_directory appx COMMAND ${CMAKE_COMMAND} -E copy AppxManifest.xml appx - COMMAND ${CMAKE_COMMAND} -E copy $ appx + COMMAND ${CMAKE_COMMAND} -E copy $ appx COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/qt.conf appx COMMAND ${CMAKE_COMMAND} -E copy ${LIBS_PATH}/798.p12 appx COMMAND ${CMAKE_COMMAND} -E copy ${LIBS_PATH}/libcrypto-1_1${OPENSSL_SUFFIX}.dll appx @@ -293,10 +294,10 @@ elseif(WIN32) ) else() find_package( Threads REQUIRED ) - target_sources(${PROJECT_NAME} PRIVATE Diagnostics_unix.cpp) - target_link_libraries(${PROJECT_NAME} Threads::Threads ) + target_sources(${PROJECT_NAME} PRIVATE Diagnostics_unix.cpp) + target_link_libraries(${PROJECT_NAME} Threads::Threads ) configure_file( qdigidoc4.1.cmake qdigidoc4.1 ) - install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) + install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/qdigidoc4.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 ) install( FILES qdigidoc4.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications ) install( FILES qdigidoc4.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/mime/packages ) diff --git a/client/CryptoDoc.cpp b/client/CryptoDoc.cpp index ac6dde463..69798c741 100644 --- a/client/CryptoDoc.cpp +++ b/client/CryptoDoc.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include #include diff --git a/client/Diagnostics.cpp b/client/Diagnostics.cpp index ec8bfb27d..45e42eec4 100644 --- a/client/Diagnostics.cpp +++ b/client/Diagnostics.cpp @@ -22,9 +22,8 @@ #include "QPCSC.h" #ifdef CONFIG_URL -#include "Configuration.h" +#include "Settings.h" #include -#include #endif #include @@ -38,21 +37,14 @@ void Diagnostics::generalInfo(QTextStream &s) << "" << "URLs:" << "" #ifdef CONFIG_URL << "
CONFIG_URL: " << CONFIG_URL - << "
SID-PROXY-URL: " << qApp->conf()->object().value(QStringLiteral("SID-PROXY-URL")).toString(QStringLiteral(SMARTID_URL)) - << "
SIDV2-PROXY-URL: " << qApp->conf()->object().value(QStringLiteral("SIDV2-PROXY-URL")).toString(QStringLiteral(SMARTID_URL)) - << "
SID-SK-URL: " << qApp->conf()->object().value(QStringLiteral("SID-SK-URL")).toString(QStringLiteral(SMARTID_URL)) - << "
SIDV2-SK-URL: " << qApp->conf()->object().value(QStringLiteral("SIDV2-SK-URL")).toString(QStringLiteral(SMARTID_URL)) - << "
MID-PROXY-URL: " << qApp->conf()->object().value(QStringLiteral("MID-PROXY-URL")).toString(QStringLiteral(MOBILEID_URL)) - << "
MID-SK-URL: " << qApp->conf()->object().value(QStringLiteral("MID-SK-URL")).toString(QStringLiteral(MOBILEID_URL)) - << "
RPUUID: " << (QSettings().value(QStringLiteral("MIDUUID-CUSTOM"), QSettings().contains(QStringLiteral("MIDUUID"))).toBool() ? tr("is set manually") : tr("is set by default")) -#else -#ifdef MOBILEID_URL - << "
MOBILEID_URL: " << MOBILEID_URL -#endif -#ifdef SMARTID_URL - << "
SMARTID_URL: " << SMARTID_URL -#endif #endif + << "
SID-PROXY-URL: " << qApp->confValue(QLatin1String("SID-PROXY-URL")).toString(QStringLiteral(SMARTID_URL)) + << "
SIDV2-PROXY-URL: " << qApp->confValue(QLatin1String("SIDV2-PROXY-URL")).toString(QStringLiteral(SMARTID_URL)) + << "
SID-SK-URL: " << qApp->confValue(QLatin1String("SID-SK-URL")).toString(QStringLiteral(SMARTID_URL)) + << "
SIDV2-SK-URL: " << qApp->confValue(QLatin1String("SIDV2-SK-URL")).toString(QStringLiteral(SMARTID_URL)) + << "
MID-PROXY-URL: " << Settings::MID_PROXY_URL + << "
MID-SK-URL: " << Settings::MID_SK_URL + << "
RPUUID: " << (Settings::MID_UUID_CUSTOM ? tr("is set manually") : tr("is set by default")) << "
TSL_URL: " << qApp->confValue(Application::TSLUrl).toString() << "
TSA_URL: " << qApp->confValue(Application::TSAUrl).toString() << "
SIVA_URL: " << qApp->confValue(Application::SiVaUrl).toString() @@ -72,7 +64,7 @@ void Diagnostics::generalInfo(QTextStream &s) #ifdef CONFIG_URL s << "" << tr("Central Configuration") << ":"; - QJsonObject metainf = qApp->conf()->object().value(QStringLiteral("META-INF")).toObject(); + QJsonObject metainf = qApp->confValue(QLatin1String("META-INF")).toObject(); for(QJsonObject::const_iterator i = metainf.constBegin(), end = metainf.constEnd(); i != end; ++i) { if(i.value().type() == QJsonValue::Double) diff --git a/client/DocumentModel.cpp b/client/DocumentModel.cpp index d82f72867..bb5115d6d 100644 --- a/client/DocumentModel.cpp +++ b/client/DocumentModel.cpp @@ -23,9 +23,6 @@ #include "dialogs/FileDialog.h" #include "dialogs/WarningDialog.h" -#include - -#include #include #include #include @@ -47,19 +44,13 @@ QStringList DocumentModel::tempFiles() const { QFileInfo f(save(i, FileDialog::tempPath(data(i)))); if(f.exists()) - copied << f.absoluteFilePath(); + copied.append(f.absoluteFilePath()); } - return copied; } bool DocumentModel::verifyFile(const QString &f) { - QJsonObject obj; -#ifdef CONFIG_URL - obj = qApp->conf()->object(); -#endif - static const QJsonArray defaultArray { QStringLiteral("ddoc"), QStringLiteral("bdoc") ,QStringLiteral("edoc"), QStringLiteral("adoc"), QStringLiteral("asice"), QStringLiteral("cdoc"), QStringLiteral("asics"), QStringLiteral("txt"), QStringLiteral("doc"), QStringLiteral("docx"), QStringLiteral("odt"), QStringLiteral("ods"), QStringLiteral("tex"), QStringLiteral("wks"), QStringLiteral("wps"), @@ -67,12 +58,12 @@ bool DocumentModel::verifyFile(const QString &f) QStringLiteral("pps"), QStringLiteral("ppt"), QStringLiteral("pptx"), QStringLiteral("png"), QStringLiteral("jpg"), QStringLiteral("jpeg"), QStringLiteral("bmp"), QStringLiteral("ai"), QStringLiteral("gif"), QStringLiteral("ico"), QStringLiteral("ps"), QStringLiteral("psd"), QStringLiteral("tif"), QStringLiteral("tiff"), QStringLiteral("csv")}; - QJsonArray allowedExts = obj.value(QLatin1String("ALLOWED-EXTENSIONS")).toArray(defaultArray); - + QJsonArray allowedExts = qApp->confValue(QLatin1String("ALLOWED-EXTENSIONS")).toArray(defaultArray); if(!allowedExts.contains(QJsonValue(QFileInfo(f).suffix().toLower()))){ - WarningDialog dlg(tr("A file with this extension cannot be opened in the DigiDoc4 Client. Download the file to view it."), qApp->activeWindow()); - dlg.setCancelText(tr("OK")); - dlg.exec(); + auto *dlg = new WarningDialog(tr("A file with this extension cannot be opened in the DigiDoc4 Client. Download the file to view it."), qApp->activeWindow()); + dlg->setAttribute(Qt::WA_DeleteOnClose); + dlg->setCancelText(tr("OK")); + dlg->open(); return false; } diff --git a/client/DocumentModel.h b/client/DocumentModel.h index f84545dcf..ec1459cff 100644 --- a/client/DocumentModel.h +++ b/client/DocumentModel.h @@ -43,5 +43,5 @@ class DocumentModel: public QObject void removed(int row); protected: - bool verifyFile(const QString &f); + static bool verifyFile(const QString &f); }; diff --git a/client/MainWindow.cpp b/client/MainWindow.cpp index 7b712e262..5d42eafc0 100644 --- a/client/MainWindow.cpp +++ b/client/MainWindow.cpp @@ -28,6 +28,7 @@ #include "PrintSheet.h" #include "QPCSC.h" #include "QSigner.h" +#include "Settings.h" #include "Styles.h" #include "sslConnect.h" #include "TokenData.h" @@ -49,7 +50,6 @@ #include "widgets/WarningList.h" #include -#include #include #include #include @@ -375,8 +375,7 @@ void MainWindow::navigateToPage( Pages page, const QStringList &files, bool crea std::unique_ptr signatureContainer(new DigiDoc(this)); if(create) { - QString defaultDir = QSettings().value(QStringLiteral("DefaultDir")).toString(); - QString filename = FileDialog::createNewFileName(files[0], QStringLiteral(".asice"), tr("signature container"), defaultDir, this); + QString filename = FileDialog::createNewFileName(files[0], true, this); if(!filename.isNull()) { signatureContainer->create(filename); @@ -406,8 +405,7 @@ void MainWindow::navigateToPage( Pages page, const QStringList &files, bool crea if(create) { - QString defaultDir = QSettings().value(QStringLiteral("DefaultDir")).toString(); - QString filename = FileDialog::createNewFileName(files[0], QStringLiteral(".cdoc"), tr("crypto container"), defaultDir, this); + QString filename = FileDialog::createNewFileName(files[0], false, this); if(!filename.isNull()) { cryptoContainer->clear(filename); @@ -510,8 +508,7 @@ void MainWindow::convertToBDoc() void MainWindow::convertToCDoc() { - QString defaultDir = QSettings().value(QStringLiteral("Client/DefaultDir")).toString(); - QString filename = FileDialog::createNewFileName(digiDoc->fileName(), QStringLiteral(".cdoc"), tr("crypto container"), defaultDir, this); + QString filename = FileDialog::createNewFileName(digiDoc->fileName(), false, this); if(filename.isNull()) return; @@ -818,11 +815,11 @@ QString MainWindow::selectFile( const QString &title, const QString &filename, b QString active; if( fixedExt ) { - if(ext == QLatin1String("bdoc")) exts << bdoc; - if(ext == QLatin1String("cdoc")) exts << cdoc; - if(ext == QLatin1String("asice") || ext == QLatin1String("sce")) exts << asic; - if(ext == QLatin1String("edoc")) exts << edoc; - if(ext == QLatin1String("adoc")) exts << adoc; + if(ext == QLatin1String("bdoc")) exts.append(bdoc); + if(ext == QLatin1String("cdoc")) exts.append(cdoc); + if(ext == QLatin1String("asice") || ext == QLatin1String("sce")) exts.append(asic); + if(ext == QLatin1String("edoc")) exts.append(edoc); + if(ext == QLatin1String("adoc")) exts.append(adoc); } else { @@ -1094,8 +1091,7 @@ void MainWindow::warningClicked(const QString &link) bool MainWindow::wrap(const QString& wrappedFile, bool enclose) { - QString defaultDir = QSettings().value(QStringLiteral("DefaultDir")).toString(); - QString filename = FileDialog::createNewFileName(wrappedFile, QStringLiteral(".asice"), tr("signature container"), defaultDir, this); + QString filename = FileDialog::createNewFileName(wrappedFile, true, this); if(filename.isNull()) return false; diff --git a/client/Settings.cpp b/client/Settings.cpp new file mode 100644 index 000000000..12ffab6e1 --- /dev/null +++ b/client/Settings.cpp @@ -0,0 +1,91 @@ +/* + * QDigiDoc4 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "Settings.h" + +#include "Application.h" + +#include + +template +using Option = Settings::Option; + +const Option Settings::MID_UUID { QStringLiteral("MIDUUID") }; +const Option Settings::MID_NAME { QStringLiteral("MIDNAME"), QStringLiteral("RIA DigiDoc") }; +const Option Settings::MID_PROXY_URL { QStringLiteral("MID-PROXY-URL"), [] { + return qApp->confValue(QLatin1String("MID-PROXY-URL")).toString(QStringLiteral(MOBILEID_URL)); +}}; +const Option Settings::MID_SK_URL { QStringLiteral("MID-SK-URL"), [] { + return qApp->confValue(QLatin1String("MID-SK-URL")).toString(QStringLiteral(MOBILEID_URL)); +}}; +const Option Settings::MID_UUID_CUSTOM + { QStringLiteral("MIDUUID-CUSTOM"), [] { return Settings::MID_UUID.isSet(); } }; +const Option Settings::MOBILEID_REMEMBER { QStringLiteral("MobileSettings"), true }; +const Option Settings::MOBILEID_CODE { QStringLiteral("MobileCode") }; +const Option Settings::MOBILEID_NUMBER { QStringLiteral("MobileNumber") }; +const Option Settings::MOBILEID_ORDER { QStringLiteral("MIDOrder"), true }; + +const Option Settings::SID_UUID { QStringLiteral("SIDUUID") }; +const Option Settings::SID_NAME { QStringLiteral("SIDNAME"), QStringLiteral("RIA DigiDoc") }; +const Option Settings::SID_PROXY_URL { QStringLiteral("SID-PROXY-URL"), []{ + return qApp->confValue(QLatin1String("SIDV2-PROXY-URL")).toString(qApp->confValue(QLatin1String("SID-PROXY-URL")).toString(QStringLiteral(SMARTID_URL))); +}}; +const Option Settings::SID_SK_URL { QStringLiteral("SID-SK-URL"), []{ + return qApp->confValue(QLatin1String("SIDV2-SK-URL")).toString(qApp->confValue(QLatin1String("SID-SK-URL")).toString(QStringLiteral(SMARTID_URL))); +}}; +const Option Settings::SID_UUID_CUSTOM + { QStringLiteral("SIDUUID-CUSTOM"), [] { return Settings::SID_UUID.isSet(); } }; +const Option Settings::SMARTID_REMEMBER { QStringLiteral("SmartIDSettings"), true }; +const Option Settings::SMARTID_CODE { QStringLiteral("SmartID") }; +const Option Settings::SMARTID_COUNTRY { QStringLiteral("SmartIDCountry"), QStringLiteral("EE") }; +const QStringList Settings::SMARTID_COUNTRY_LIST = { + QStringLiteral("EE"), + QStringLiteral("LT"), + QStringLiteral("LV"), +}; + +const Option Settings::SIVA_CERT { QStringLiteral("SIVA-CERT") }; +const Option Settings::SIVA_URL { QStringLiteral("SIVA-URL") }; +const Option Settings::SIVA_URL_CUSTOM + { QStringLiteral("SIVA-URL-CUSTOM"), [] { return Settings::SIVA_URL.isSet(); } }; +const Option Settings::TSA_CERT { QStringLiteral("TSA-CERT") }; +const Option Settings::TSA_URL { QStringLiteral("TSA-URL") }; +const Option Settings::TSA_URL_CUSTOM + { QStringLiteral("TSA-URL-CUSTOM"), [] { return Settings::TSA_URL.isSet(); } }; + +const Option Settings::DEFAULT_DIR { QStringLiteral("DefaultDir") }; +const Option Settings::LANGUAGE { QStringLiteral("Language") }; +const Option Settings::LAST_PATH { QStringLiteral("lastPath") }; +const Option Settings::LIBDIGIDOCPP_DEBUG { QStringLiteral("LibdigidocppDebug"), false }; +const Option Settings::SETTINGS_MIGRATED { QStringLiteral("SettingsMigrated"), false }; +const Option Settings::SHOW_INTRO { QStringLiteral("showIntro"), true }; +const Option Settings::SHOW_PRINT_SUMMARY { QStringLiteral("ShowPrintSummary"), false }; +const Option Settings::SHOW_ROLE_ADDRESS_INFO { QStringLiteral("RoleAddressInfo"), false }; + +const Option Settings::PROXY_CONFIG { QStringLiteral("ProxyConfig"), Settings::ProxyNone }; +const Option Settings::PROXY_HOST { QStringLiteral("ProxyHost") }; +const Option Settings::PROXY_PORT { QStringLiteral("ProxyPort") }; +const Option Settings::PROXY_USER { QStringLiteral("ProxyUser") }; +const Option Settings::PROXY_PASS { QStringLiteral("ProxyPass") }; +#ifdef Q_OS_MAC +const Option Settings::PROXY_TUNNEL_SSL { QStringLiteral("ProxyTunnelSSL"), false }; +const Option Settings::PKCS12_DISABLE { QStringLiteral("PKCS12Disable"), false }; +const Option Settings::PLUGINS { QStringLiteral("plugins") }; +const Option Settings::TSL_ONLINE_DIGEST { QStringLiteral("TSLOnlineDigest"), true }; +#endif diff --git a/client/Settings.h b/client/Settings.h new file mode 100644 index 000000000..4b485ef69 --- /dev/null +++ b/client/Settings.h @@ -0,0 +1,131 @@ +/* + * QDigiDoc4 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#pragma once + +#include + +template +using if_QString = std::enable_if_t, bool>; + +struct Settings +{ + template + struct Option + { + operator QVariant() const { + return QSettings().value(KEY, defaultValue()); + } + operator T() const { + return operator QVariant().template value(); + } + template > + operator std::string() const { + return operator T().toStdString(); + } + void operator =(const QVariant &value) const { + setValue(value, defaultValue()); + } + void operator =(const T &value) const { + operator =(QVariant(value)); + } + template > + void operator =(const std::string &value) const { + operator =(QString::fromStdString(value)); + } + void clear() const { + QSettings().remove(KEY); + } + bool isSet() const { + return QSettings().contains(KEY); + } + T value(const QVariant &def) const { + return QSettings().value(KEY, def).template value(); + } + void setValue(const QVariant &value, const QVariant &def = {}) const { + if(bool valueIsNullOrEmpty = value.type() == QVariant::String ? value.toString().isEmpty() : value.isNull(); + value == def || (def.isNull() && valueIsNullOrEmpty)) + clear(); + else + QSettings().setValue(KEY, value); + } + T defaultValue() const { + if constexpr (std::is_invocable_v) + return DEFAULT(); + else + return DEFAULT; + } + const QString KEY; + const D DEFAULT {}; + }; + + static const Option MID_UUID; + static const Option MID_NAME; + static const Option MID_PROXY_URL; + static const Option MID_SK_URL; + static const Option MID_UUID_CUSTOM; + static const Option MOBILEID_REMEMBER; + static const Option MOBILEID_CODE; + static const Option MOBILEID_NUMBER; + static const Option MOBILEID_ORDER; + + static const Option SID_UUID; + static const Option SID_NAME; + static const Option SID_PROXY_URL; + static const Option SID_SK_URL; + static const Option SID_UUID_CUSTOM; + static const Option SMARTID_REMEMBER; + static const Option SMARTID_CODE; + static const Option SMARTID_COUNTRY; + static const QStringList SMARTID_COUNTRY_LIST; + + static const Option SIVA_CERT; + static const Option SIVA_URL; + static const Option SIVA_URL_CUSTOM; + static const Option TSA_CERT; + static const Option TSA_URL; + static const Option TSA_URL_CUSTOM; + + static const Option DEFAULT_DIR; + static const Option LANGUAGE; + static const Option LAST_PATH; + static const Option LIBDIGIDOCPP_DEBUG; + static const Option SETTINGS_MIGRATED; + static const Option SHOW_INTRO; + static const Option SHOW_PRINT_SUMMARY; + static const Option SHOW_ROLE_ADDRESS_INFO; + + enum ProxyConfig { + ProxyNone, + ProxySystem, + ProxyManual, + }; + static const Option PROXY_CONFIG; + static const Option PROXY_HOST; + static const Option PROXY_PORT; + static const Option PROXY_USER; + static const Option PROXY_PASS; +#ifdef Q_OS_MAC + static const Option PROXY_TUNNEL_SSL; + static const Option PKCS12_DISABLE; + static const Option PLUGINS; + static const Option TSL_ONLINE_DIGEST; +#endif +}; +Q_DECLARE_METATYPE(Settings::ProxyConfig) diff --git a/client/dialogs/AddRecipients.cpp b/client/dialogs/AddRecipients.cpp index e7b0a3c5f..3e56ad92c 100644 --- a/client/dialogs/AddRecipients.cpp +++ b/client/dialogs/AddRecipients.cpp @@ -169,12 +169,12 @@ void AddRecipients::addRecipientFromFile() } if( cert.isNull() ) { - WarningDialog::show( this, tr("Failed to read certificate")); + WarningDialog::show(this, tr("Failed to read certificate")); } else if( !SslCertificate( cert ).keyUsage().contains( SslCertificate::KeyEncipherment ) && !SslCertificate( cert ).keyUsage().contains( SslCertificate::KeyAgreement ) ) { - WarningDialog::show( this, tr("This certificate cannot be used for encryption")); + WarningDialog::show(this, tr("This certificate cannot be used for encryption")); } else if(AddressItem *item = addRecipientToLeftPane(cert)) { @@ -278,12 +278,7 @@ void AddRecipients::addSelectedCerts(const QList& selectedCertD QString AddRecipients::defaultUrl(QLatin1String key, const QString &defaultValue) { -#ifdef CONFIG_URL - return qApp->conf()->object().value(key).toString(defaultValue); -#else - Q_UNUSED(key) - return defaultValue; -#endif + return qApp->confValue(key).toString(defaultValue); } void AddRecipients::enableRecipientFromCard() diff --git a/client/dialogs/FileDialog.cpp b/client/dialogs/FileDialog.cpp index 61a8be9f3..6d474a344 100644 --- a/client/dialogs/FileDialog.cpp +++ b/client/dialogs/FileDialog.cpp @@ -20,13 +20,13 @@ #include "FileDialog.h" #include "Application.h" +#include "Settings.h" #include "dialogs/WarningDialog.h" #include #include #include #include -#include #include #include @@ -40,7 +40,7 @@ class CPtr { T *d; public: - CPtr(T *p = nullptr): d(p) {} + explicit CPtr(T *p = {}): d(p) {} ~CPtr() { if(d) d->Release(); } inline T* operator->() const { return d; } inline operator T*() const { return d; } @@ -50,8 +50,12 @@ class CPtr #include -QString FileDialog::createNewFileName(const QString &file, const QString &extension, const QString &type, const QString &defaultDir, QWidget *parent) +QString FileDialog::createNewFileName(const QString &file, bool signature, QWidget *parent) { + const QString extension = signature ? QStringLiteral(".asice") : QStringLiteral(".cdoc"); + const QString type = signature ? tr("signature container") : tr("crypto container"); + QString capitalized = type[0].toUpper() + type.mid(1); + const QString defaultDir = Settings::DEFAULT_DIR; const QFileInfo f(normalized(file)); QString dir = defaultDir.isEmpty() ? f.absolutePath() : defaultDir; QString fileName = QDir::toNativeSeparators(dir + QDir::separator() + f.completeBaseName() + extension); @@ -61,8 +65,7 @@ QString FileDialog::createNewFileName(const QString &file, const QString &extens if(!QFile::exists(fileName)) return fileName; #endif - QString capitalized = type[0].toUpper() + type.mid(1); - fileName = FileDialog::getSaveFileName(parent, Application::tr("Create %1").arg(type), fileName, + fileName = FileDialog::getSaveFileName(parent, tr("Create %1").arg(type), fileName, QStringLiteral("%1 (*%2)").arg(capitalized, extension)); if(!fileName.isEmpty()) QFile::remove(fileName); @@ -164,13 +167,13 @@ void FileDialog::setFileZone(const QString &path, int zone) QString FileDialog::getDir( const QString &dir ) { #ifdef Q_OS_OSX - Q_UNUSED(dir); + Q_UNUSED(dir) QString path = QSettings().value(QStringLiteral("NSNavLastRootDirectory")).toString(); path.replace('~', QDir::homePath()); return path; #else - return !dir.isEmpty() ? dir : QSettings().value("lastPath", - QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)).toString(); + return !dir.isEmpty() ? dir : Settings::LAST_PATH.value( + QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); #endif } @@ -302,9 +305,9 @@ QString FileDialog::result( const QString &str ) { #ifndef Q_OS_OSX if(!str.isEmpty()) - QSettings().setValue("lastPath", QFileInfo(str).absolutePath()); + Settings::LAST_PATH = QFileInfo(str).absolutePath(); #else - QSettings().remove(QStringLiteral("lastPath")); + Settings::LAST_PATH.clear(); #endif return str; } @@ -313,7 +316,7 @@ QStringList FileDialog::result( const QStringList &list ) { QStringList l; for( const QString &str: list ) - l << result( str ); + l.append(result(str)); return l; } diff --git a/client/dialogs/FileDialog.h b/client/dialogs/FileDialog.h index 1a86aba5d..f6da2a86b 100644 --- a/client/dialogs/FileDialog.h +++ b/client/dialogs/FileDialog.h @@ -33,8 +33,7 @@ class FileDialog : public QFileDialog using QFileDialog::QFileDialog; - static QString createNewFileName(const QString &file, const QString &extension, - const QString &type, const QString &defaultDir, QWidget *parent); + static QString createNewFileName(const QString &file, bool signature, QWidget *parent); static FileType detect(const QString &filename); static bool fileIsWritable( const QString &filename ); static QString fileSize( quint64 bytes ); diff --git a/client/dialogs/MobileDialog.cpp b/client/dialogs/MobileDialog.cpp index e9c39d99b..9665bf096 100644 --- a/client/dialogs/MobileDialog.cpp +++ b/client/dialogs/MobileDialog.cpp @@ -21,19 +21,15 @@ #include "ui_MobileDialog.h" #include "IKValidator.h" +#include "Settings.h" #include "Styles.h" -#include "dialogs/SettingsDialog.h" #include "effects/Overlay.h" -#include - -#define COUNTRY_CODE_EST QStringLiteral("372") -#define COUNTRY_CODE_LTU QStringLiteral("370") - MobileDialog::MobileDialog(QWidget *parent) : QDialog(parent), ui(new Ui::MobileDialog) { + static const QStringList countryCodes {QStringLiteral("372"), QStringLiteral("370")}; new Overlay(this, parent); ui->setupUi(this); setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); @@ -57,18 +53,18 @@ MobileDialog::MobileDialog(QWidget *parent) : // Mobile ui->idCode->setValidator(new NumberValidator(ui->idCode)); - ui->idCode->setText(QSettings().value(QStringLiteral("MobileCode")).toString()); + ui->idCode->setText(Settings::MOBILEID_CODE); ui->idCode->setAttribute(Qt::WA_MacShowFocusRect, false); ui->phoneNo->setValidator(new NumberValidator(ui->phoneNo)); - ui->phoneNo->setText(QSettings().value(QStringLiteral("MobileNumber"), COUNTRY_CODE_EST).toString()); + ui->phoneNo->setText(Settings::MOBILEID_NUMBER.value(countryCodes[0])); ui->phoneNo->setAttribute(Qt::WA_MacShowFocusRect, false); - ui->cbRemember->setChecked(QSettings().value(QStringLiteral("MobileSettings"), true).toBool()); + ui->cbRemember->setChecked(Settings::MOBILEID_REMEMBER); ui->cbRemember->setAttribute(Qt::WA_MacShowFocusRect, false); auto saveSettings = [this] { bool checked = ui->cbRemember->isChecked(); - SettingsDialog::setValueEx(QStringLiteral("MobileSettings"), checked, true); - SettingsDialog::setValueEx(QStringLiteral("MobileCode"), checked ? ui->idCode->text() : QString()); - SettingsDialog::setValueEx(QStringLiteral("MobileNumber"), checked ? ui->phoneNo->text() : QString()); + Settings::MOBILEID_REMEMBER = checked; + Settings::MOBILEID_CODE = checked ? ui->idCode->text() : QString(); + Settings::MOBILEID_NUMBER = checked ? ui->phoneNo->text() : QString(); }; connect(ui->idCode, &QLineEdit::returnPressed, ui->sign, &QPushButton::click); connect(ui->idCode, &QLineEdit::textEdited, this, saveSettings); @@ -76,7 +72,6 @@ MobileDialog::MobileDialog(QWidget *parent) : connect(ui->phoneNo, &QLineEdit::textEdited, this, saveSettings); connect(ui->cbRemember, &QCheckBox::clicked, this, saveSettings); connect(ui->sign, &QPushButton::clicked, this, [this] { - static const QStringList countryCodes {COUNTRY_CODE_EST, COUNTRY_CODE_LTU}; if(!IKValidator::isValid(idCode())) { ui->idCode->setStyleSheet(QStringLiteral("border-color: #c53e3e")); diff --git a/client/dialogs/MobileProgress.cpp b/client/dialogs/MobileProgress.cpp index bb83e3ed3..283317431 100644 --- a/client/dialogs/MobileProgress.cpp +++ b/client/dialogs/MobileProgress.cpp @@ -21,12 +21,12 @@ #include "ui_MobileProgress.h" #include "Application.h" +#include "Settings.h" #include "Styles.h" #include "Utils.h" #include "dialogs/WarningDialog.h" #include -#include #include @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include @@ -54,28 +53,21 @@ class MobileProgress::Private final: public QDialog, public Ui::MobileProgress { Q_OBJECT public: - QString URL() { return !UUID.isNull() && useCustomUUID ? SKURL : PROXYURL; } using QDialog::QDialog; void reject() final { l.exit(QDialog::Rejected); } - QTimeLine *statusTimer = nullptr; - QNetworkAccessManager *manager = nullptr; + QTimeLine *statusTimer {}; + QNetworkAccessManager *manager {}; QNetworkRequest req; QString ssid, cell, sessionID; std::vector signature; X509Cert cert; QEventLoop l; -#ifdef CONFIG_URL - QString PROXYURL = qApp->conf()->object().value(QStringLiteral("MID-PROXY-URL")).toString(QStringLiteral(MOBILEID_URL)); - QString SKURL = qApp->conf()->object().value(QStringLiteral("MID-SK-URL")).toString(QStringLiteral(MOBILEID_URL)); -#else - QString PROXYURL = QSettings().value(QStringLiteral("MID-PROXY-URL"), QStringLiteral(MOBILEID_URL)).toString(); - QString SKURL = QSettings().value(QStringLiteral("MID-SK-URL"), QStringLiteral(MOBILEID_URL)).toString(); -#endif - QString NAME = QSettings().value(QStringLiteral("MIDNAME"), QStringLiteral("RIA DigiDoc")).toString(); - bool useCustomUUID = QSettings().value(QStringLiteral("MIDUUID-CUSTOM"), QSettings().contains(QStringLiteral("MIDUUID"))).toBool(); - QString UUID = useCustomUUID ? QSettings().value(QStringLiteral("MIDUUID")).toString() : QString(); + bool useCustomUUID = Settings::MID_UUID_CUSTOM; + QString NAME = Settings::MID_NAME; + QString UUID = useCustomUUID ? Settings::MID_UUID : QString(); + QString URL = !UUID.isNull() && useCustomUUID ? Settings::MID_SK_URL : Settings::MID_PROXY_URL; #ifdef QT_WIN_EXTRAS - QWinTaskbarButton *taskbar = nullptr; + QWinTaskbarButton *taskbar {}; #endif }; @@ -127,7 +119,7 @@ background-color: #007aff; QList trusted; #ifdef CONFIG_URL ssl.setCaCertificates({}); - for(const QJsonValue cert: qApp->conf()->object().value(QStringLiteral("CERT-BUNDLE")).toArray()) + for(const auto cert: qApp->confValue(QLatin1String("CERT-BUNDLE")).toArray()) trusted << QSslCertificate(QByteArray::fromBase64(cert.toString().toLatin1()), QSsl::Der); #endif d->req.setSslConfiguration(ssl); @@ -162,7 +154,7 @@ background-color: #007aff; qCWarning(MIDLog) << err; stop(); d->hide(); - WarningDialog *dlg = WarningDialog::show(d->parentWidget(), err, details); + auto *dlg = WarningDialog::show(d->parentWidget(), err, details); QObject::connect(dlg, &WarningDialog::finished, &d->l, &QEventLoop::exit); }; @@ -263,7 +255,7 @@ background-color: #007aff; returnError(tr("Service result:") + endResult); return; } - d->req.setUrl(QUrl(QStringLiteral("%1/signature/session/%2?timeoutMs=10000").arg(d->URL(), d->sessionID))); + d->req.setUrl(QUrl(QStringLiteral("%1/signature/session/%2?timeoutMs=10000").arg(d->URL, d->sessionID))); qCDebug(MIDLog).noquote() << d->req.url(); d->manager->get(d->req); }); @@ -283,7 +275,7 @@ bool MobileProgress::init(const QString &ssid, const QString &cell) { if(!d->UUID.isEmpty() && QUuid(d->UUID).isNull()) { - WarningDialog(tr("Failed to send request. Check your %1 service access settings.").arg(tr("mobile-ID")), {}, d->parentWidget()).exec(); + WarningDialog::show(d->parentWidget(), tr("Failed to send request. Check your %1 service access settings.").arg(tr("mobile-ID"))); return false; } d->ssid = ssid; @@ -297,7 +289,7 @@ bool MobileProgress::init(const QString &ssid, const QString &cell) {"nationalIdentityNumber", d->ssid}, {"phoneNumber", d->cell}, })).toJson(); - d->req.setUrl(QUrl(QStringLiteral("%1/certificate").arg(d->URL()))); + d->req.setUrl(QUrl(QStringLiteral("%1/certificate").arg(d->URL))); qCDebug(MIDLog).noquote() << d->req.url() << data; d->manager->post(d->req, data); return d->l.exec() == QDialog::Accepted; @@ -339,7 +331,7 @@ std::vector MobileProgress::sign(const std::string &method, const })).toJson(); // Workaround MID proxy issues data = QString::fromUtf8(data).arg(escapeUnicode(tr("Sign document"))).toUtf8(); - d->req.setUrl(QUrl(QStringLiteral("%1/signature").arg(d->URL()))); + d->req.setUrl(QUrl(QStringLiteral("%1/signature").arg(d->URL))); qCDebug(MIDLog).noquote() << d->req.url() << data; d->manager->post(d->req, data); d->statusTimer->start(); diff --git a/client/dialogs/RoleAddressDialog.cpp b/client/dialogs/RoleAddressDialog.cpp index 0edc1ba43..22ef7afc1 100644 --- a/client/dialogs/RoleAddressDialog.cpp +++ b/client/dialogs/RoleAddressDialog.cpp @@ -20,21 +20,15 @@ #include "RoleAddressDialog.h" #include "ui_RoleAddressDialog.h" +#include "Settings.h" #include "Styles.h" -#include "dialogs/SettingsDialog.h" #include "effects/Overlay.h" -#include - #include -#include +#include #include -class RoleAddressDialog::Private: public Ui::RoleAddressDialog -{ -public: - QSettings s; -}; +class RoleAddressDialog::Private: public Ui::RoleAddressDialog {}; RoleAddressDialog::RoleAddressDialog(QWidget *parent) : QDialog(parent) @@ -68,21 +62,22 @@ RoleAddressDialog::RoleAddressDialog(QWidget *parent) for(QLineEdit *line: findChildren()) { - QCompleter *completer = new QCompleter(d->s.value(line->objectName()).toStringList(), line); + Settings::Option s{line->objectName()}; + QCompleter *completer = new QCompleter(s, line); completer->setMaxVisibleItems(10); completer->setCompletionMode(QCompleter::PopupCompletion); completer->setCaseSensitivity(Qt::CaseInsensitive); - line->setText(d->s.value(line->objectName()).toStringList().value(0)); + line->setText(QStringList(s).value(0)); line->setFont(regularFont); line->setCompleter(completer); connect(line, &QLineEdit::editingFinished, this, [=] { - QStringList list = d->s.value(line->objectName()).toStringList(); + QStringList list = s; list.removeAll(line->text()); list.insert(0, line->text()); if(list.size() > 10) list.removeLast(); - d->s.setValue(line->objectName(), QString()); // Uses on Windows MULTI_STRING registry - SettingsDialog::setValueEx(line->objectName(), list); + s.clear(); // Uses on Windows MULTI_STRING registry + s = list; }); completer->popup()->setStyleSheet("background-color:#FFFFFF; color: #000000;"); } @@ -95,7 +90,7 @@ RoleAddressDialog::~RoleAddressDialog() int RoleAddressDialog::get(QString &city, QString &country, QString &state, QString &zip, QString &role) { - if(!QSettings().value(QStringLiteral("RoleAddressInfo"), false).toBool()) + if(!Settings::SHOW_ROLE_ADDRESS_INFO) return QDialog::Accepted; new Overlay(this, parentWidget()); int result = QDialog::exec(); diff --git a/client/dialogs/SettingsDialog.cpp b/client/dialogs/SettingsDialog.cpp index 1453f880c..676beb54c 100644 --- a/client/dialogs/SettingsDialog.cpp +++ b/client/dialogs/SettingsDialog.cpp @@ -30,6 +30,7 @@ #include "Diagnostics.h" #include "FileDialog.h" #include "QSigner.h" +#include "Settings.h" #include "Styles.h" #include "SslCertificate.h" #include "TokenData.h" @@ -45,7 +46,6 @@ #include #include -#include #include #include #include @@ -340,8 +340,6 @@ void SettingsDialog::retranslate(const QString& lang) void SettingsDialog::initFunctionality() { - QSettings s; - // pageGeneral selectLanguage(); connect(ui->langGroup, qOverload(&QButtonGroup::buttonClicked), this, @@ -351,14 +349,14 @@ void SettingsDialog::initFunctionality() connect(ui->chkGeneralTslRefresh, &QCheckBox::toggled, [](bool checked) { qApp->setConfValue(Application::TSLOnlineDigest, checked); }); - ui->chkShowPrintSummary->setChecked(s.value(QStringLiteral("ShowPrintSummary"), false).toBool()); + ui->chkShowPrintSummary->setChecked(Settings::SHOW_PRINT_SUMMARY); connect(ui->chkShowPrintSummary, &QCheckBox::toggled, this, &SettingsDialog::togglePrinting); connect(ui->chkShowPrintSummary, &QCheckBox::toggled, this, [](bool checked) { - setValueEx(QStringLiteral("ShowPrintSummary"), checked, false); + Settings::SHOW_PRINT_SUMMARY = checked; }); - ui->chkRoleAddressInfo->setChecked(s.value(QStringLiteral("RoleAddressInfo"), false).toBool()); + ui->chkRoleAddressInfo->setChecked(Settings::SHOW_ROLE_ADDRESS_INFO); connect(ui->chkRoleAddressInfo, &QCheckBox::toggled, this, [](bool checked) { - setValueEx(QStringLiteral("RoleAddressInfo"), checked, false); + Settings::SHOW_ROLE_ADDRESS_INFO = checked; }); #ifdef Q_OS_MAC @@ -369,12 +367,11 @@ void SettingsDialog::initFunctionality() ui->rdGeneralSpecifyDirectory->hide(); #else connect(ui->btGeneralChooseDirectory, &QPushButton::clicked, this, [=]{ - QString dir = FileDialog::getExistingDirectory(this, tr("Select folder"), - QSettings().value(QStringLiteral("DefaultDir")).toString()); + QString dir = FileDialog::getExistingDirectory(this, tr("Select folder"), Settings::DEFAULT_DIR); if(!dir.isEmpty()) { ui->rdGeneralSpecifyDirectory->setChecked(true); - setValueEx(QStringLiteral("DefaultDir"), dir); + Settings::DEFAULT_DIR = dir; ui->txtGeneralDirectory->setText(dir); } }); @@ -384,11 +381,11 @@ void SettingsDialog::initFunctionality() if(!enable) ui->txtGeneralDirectory->clear(); }); - ui->txtGeneralDirectory->setText(s.value(QStringLiteral("DefaultDir")).toString()); + ui->txtGeneralDirectory->setText(Settings::DEFAULT_DIR); if(ui->txtGeneralDirectory->text().isEmpty()) ui->rdGeneralSameDirectory->setChecked(true); connect(ui->txtGeneralDirectory, &QLineEdit::textChanged, this, [](const QString &text) { - setValueEx(QStringLiteral("DefaultDir"), text); + Settings::DEFAULT_DIR = text; }); #endif @@ -398,14 +395,14 @@ void SettingsDialog::initFunctionality() connect( ui->rdProxyNone, &QRadioButton::toggled, this, &SettingsDialog::setProxyEnabled ); connect( ui->rdProxySystem, &QRadioButton::toggled, this, &SettingsDialog::setProxyEnabled ); connect( ui->rdProxyManual, &QRadioButton::toggled, this, &SettingsDialog::setProxyEnabled ); - switch(s.value(QStringLiteral("ProxyConfig"), 0).toInt()) + switch(Settings::PROXY_CONFIG) { - case 1: ui->rdProxySystem->setChecked(true); break; - case 2: ui->rdProxyManual->setChecked(true); break; + case Settings::ProxySystem: ui->rdProxySystem->setChecked(true); break; + case Settings::ProxyManual: ui->rdProxyManual->setChecked(true); break; default: ui->rdProxyNone->setChecked(true); break; } - ui->chkProxyEnableForSSL->setDisabled((s.value(QStringLiteral("ProxyConfig"), 0).toInt() != 2)); + ui->chkProxyEnableForSSL->setDisabled(Settings::PROXY_CONFIG != Settings::ProxyManual); updateProxy(); // pageServices - Access Cert @@ -426,20 +423,18 @@ void SettingsDialog::initFunctionality() connect(ui->rdTimeStampCustom, &QRadioButton::toggled, ui->txtTimeStamp, [this](bool checked) { ui->txtTimeStamp->setEnabled(checked); ui->wgtTSACert->setVisible(checked); - setValueEx(QStringLiteral("TSA-URL-CUSTOM"), checked, QSettings().contains(QStringLiteral("TSA-URL"))); + Settings::TSA_URL_CUSTOM = checked; }); - ui->rdTimeStampCustom->setChecked(s.value(QStringLiteral("TSA-URL-CUSTOM"), s.contains(QStringLiteral("TSA-URL"))).toBool()); + ui->rdTimeStampCustom->setChecked(Settings::TSA_URL_CUSTOM); ui->wgtTSACert->setVisible(ui->rdTimeStampCustom->isChecked()); -#ifdef CONFIG_URL - ui->txtTimeStamp->setPlaceholderText(qApp->conf()->object().value(QStringLiteral("TSA-URL")).toString()); -#endif - QString TSA_URL = s.value(QStringLiteral("TSA-URL"), qApp->confValue(Application::TSAUrl)).toString(); + ui->txtTimeStamp->setPlaceholderText(qApp->confValue(Settings::TSA_URL.KEY).toString()); + QString TSA_URL = Settings::TSA_URL.value(qApp->confValue(Application::TSAUrl)); ui->txtTimeStamp->setText(ui->txtTimeStamp->placeholderText() == TSA_URL ? QString() : TSA_URL); connect(ui->txtTimeStamp, &QLineEdit::textChanged, this, [this](const QString &url) { qApp->setConfValue(Application::TSAUrl, url); if(url.isEmpty()) { - QSettings().remove(QStringLiteral("TSA-CERT")); + Settings::TSA_CERT.clear(); updateTSACert(QSslCertificate()); } }); @@ -451,22 +446,22 @@ void SettingsDialog::initFunctionality() QStringLiteral("%1 (*.crt *.cer *.pem)").arg(tr("Time-Stamping service SSL certificate"))); if(cert.isNull()) return; - QSettings().setValue(QStringLiteral("TSA-CERT"), cert.toDer().toBase64()); + Settings::TSA_CERT = cert.toDer().toBase64(); updateTSACert(cert); }); - updateTSACert(QSslCertificate(QByteArray::fromBase64(s.value(QStringLiteral("TSA-CERT")).toByteArray()), QSsl::Der)); + updateTSACert(QSslCertificate(QByteArray::fromBase64(Settings::TSA_CERT), QSsl::Der)); // pageServices - MID connect(ui->rdMIDUUIDCustom, &QRadioButton::toggled, ui->txtMIDUUID, [=](bool checked) { ui->txtMIDUUID->setEnabled(checked); - setValueEx(QStringLiteral("MIDUUID-CUSTOM"), checked, QSettings().contains(QStringLiteral("MIDUUID"))); - setValueEx(QStringLiteral("SIDUUID-CUSTOM"), checked, QSettings().contains(QStringLiteral("SIDUUID"))); + Settings::MID_UUID_CUSTOM = checked; + Settings::SID_UUID_CUSTOM = checked; }); - ui->rdMIDUUIDCustom->setChecked(s.value(QStringLiteral("MIDUUID-CUSTOM"), s.contains(QStringLiteral("MIDUUID"))).toBool()); - ui->txtMIDUUID->setText(s.value(QStringLiteral("MIDUUID")).toString()); + ui->rdMIDUUIDCustom->setChecked(Settings::MID_UUID_CUSTOM); + ui->txtMIDUUID->setText(Settings::MID_UUID); connect(ui->txtMIDUUID, &QLineEdit::textChanged, this, [](const QString &text) { - setValueEx(QStringLiteral("MIDUUID"), text); - setValueEx(QStringLiteral("SIDUUID"), text); + Settings::MID_UUID = text; + Settings::SID_UUID = text; }); connect(ui->helpMID, &QToolButton::clicked, this, []{ QDesktopServices::openUrl(tr("https://www.id.ee/en/article/for-organisations-that-sign-large-quantities-of-documents-using-digidoc4-client/")); @@ -476,20 +471,18 @@ void SettingsDialog::initFunctionality() connect(ui->rdSiVaCustom, &QRadioButton::toggled, ui->txtSiVa, [this](bool checked) { ui->txtSiVa->setEnabled(checked); ui->wgtSiVaCert->setVisible(checked); - setValueEx(QStringLiteral("SIVA-URL-CUSTOM"), checked, QSettings().contains(QStringLiteral("SIVA-URL"))); + Settings::SIVA_URL_CUSTOM = checked; }); - ui->rdSiVaCustom->setChecked(s.value(QStringLiteral("SIVA-URL-CUSTOM"), s.contains(QStringLiteral("SIVA-URL"))).toBool()); + ui->rdSiVaCustom->setChecked(Settings::SIVA_URL_CUSTOM); ui->wgtSiVaCert->setVisible(ui->rdSiVaCustom->isChecked()); -#ifdef CONFIG_URL - ui->txtSiVa->setPlaceholderText(qApp->conf()->object().value(QStringLiteral("SIVA-URL")).toString()); -#endif - QString SIVA_URL = s.value(QStringLiteral("SIVA-URL"), qApp->confValue(Application::SiVaUrl)).toString(); + ui->txtSiVa->setPlaceholderText(qApp->confValue(Settings::SIVA_URL.KEY).toString()); + QString SIVA_URL = Settings::SIVA_URL.value(qApp->confValue(Application::SiVaUrl)); ui->txtSiVa->setText(ui->txtSiVa->placeholderText() == SIVA_URL ? QString() : SIVA_URL); connect(ui->txtSiVa, &QLineEdit::textChanged, this, [this](const QString &url) { qApp->setConfValue(Application::SiVaUrl, url); if(url.isEmpty()) { - QSettings().remove(QStringLiteral("SIVA-CERT")); + Settings::SIVA_CERT.clear(); updateSiVaCert(QSslCertificate()); } }); @@ -501,15 +494,15 @@ void SettingsDialog::initFunctionality() QStringLiteral("%1 (*.crt *.cer *.pem)").arg(tr("Digital Signature Validation Service SiVa SSL certificate"))); if(cert.isNull()) return; - QSettings().setValue(QStringLiteral("SIVA-CERT"), cert.toDer().toBase64()); + Settings::SIVA_CERT = cert.toDer().toBase64(); updateSiVaCert(cert); }); - updateSiVaCert(QSslCertificate(QByteArray::fromBase64(s.value(QStringLiteral("SIVA-CERT")).toByteArray()), QSsl::Der)); + updateSiVaCert(QSslCertificate(QByteArray::fromBase64(Settings::SIVA_CERT), QSsl::Der)); // pageDiagnostics - ui->chkLibdigidocppDebug->setChecked(s.value(QStringLiteral("LibdigidocppDebug"), false).toBool()); + ui->chkLibdigidocppDebug->setChecked(Settings::LIBDIGIDOCPP_DEBUG); connect(ui->chkLibdigidocppDebug, &QCheckBox::toggled, this, [this](bool checked) { - setValueEx(QStringLiteral("LibdigidocppDebug"), checked, false); + Settings::LIBDIGIDOCPP_DEBUG = checked; if(!checked) { QFile::remove(qdigidoc4log); @@ -613,11 +606,11 @@ void SettingsDialog::updateVersion() void SettingsDialog::saveProxy() { if(ui->rdProxyNone->isChecked()) - setValueEx(QStringLiteral("ProxyConfig"), 0, 0); + Settings::PROXY_CONFIG = Settings::ProxyNone; else if(ui->rdProxySystem->isChecked()) - setValueEx(QStringLiteral("ProxyConfig"), 1, 0); + Settings::PROXY_CONFIG = Settings::ProxySystem; else if(ui->rdProxyManual->isChecked()) - setValueEx(QStringLiteral("ProxyConfig"), 2, 0); + Settings::PROXY_CONFIG = Settings::ProxyManual; Application::setConfValue( Application::ProxyHost, ui->txtProxyHost->text() ); Application::setConfValue( Application::ProxyPort, ui->txtProxyPort->text() ); Application::setConfValue( Application::ProxyUser, ui->txtProxyUsername->text() ); @@ -627,24 +620,15 @@ void SettingsDialog::saveProxy() updateProxy(); } -void SettingsDialog::setValueEx(const QString &key, const QVariant &value, const QVariant &def) -{ - bool valueIsNull = value.type() == QVariant::String ? value.toString().isEmpty() : value.isNull(); - if(value == def || (def.isNull() && valueIsNull)) - QSettings().remove(key); - else - QSettings().setValue(key, value); -} - void SettingsDialog::loadProxy( const digidoc::Conf *conf ) { - switch(QSettings().value(QStringLiteral("ProxyConfig"), 0).toUInt()) + switch(Settings::PROXY_CONFIG) { - case 0: + case Settings::ProxyNone: QNetworkProxyFactory::setUseSystemConfiguration(false); QNetworkProxy::setApplicationProxy({}); break; - case 1: + case Settings::ProxySystem: QNetworkProxyFactory::setUseSystemConfiguration(true); break; default: diff --git a/client/dialogs/SettingsDialog.h b/client/dialogs/SettingsDialog.h index 0649a60f3..d84131f1c 100644 --- a/client/dialogs/SettingsDialog.h +++ b/client/dialogs/SettingsDialog.h @@ -57,7 +57,6 @@ class SettingsDialog final: public QDialog void showPage(int page); static QString certInfo(const SslCertificate &c); static void loadProxy( const digidoc::Conf *conf ); - static void setValueEx(const QString &key, const QVariant &value, const QVariant &def = {}); signals: void langChanged(const QString& lang); diff --git a/client/dialogs/SmartIDDialog.cpp b/client/dialogs/SmartIDDialog.cpp index 7f93714e1..9b155f280 100644 --- a/client/dialogs/SmartIDDialog.cpp +++ b/client/dialogs/SmartIDDialog.cpp @@ -21,17 +21,15 @@ #include "ui_SmartIDDialog.h" #include "IKValidator.h" +#include "Settings.h" #include "Styles.h" -#include "dialogs/SettingsDialog.h" #include "effects/Overlay.h" -#include - SmartIDDialog::SmartIDDialog(QWidget *parent) : QDialog(parent) , ui(new Ui::SmartIDDialog) { - static QString EE = QStringLiteral("EE"); + static const QString &EE = Settings::SMARTID_COUNTRY_LIST[0]; new Overlay(this, parent); ui->setupUi(this); @@ -56,20 +54,18 @@ SmartIDDialog::SmartIDDialog(QWidget *parent) ui->sign->setFont(condensed); ui->cancel->setFont(condensed); - QSettings s; QValidator *ik = new NumberValidator(ui->idCode); ui->idCode->setValidator(ik); - ui->idCode->setText(s.value(QStringLiteral("SmartID")).toString()); - ui->idCountry->setItemData(0, "EE"); - ui->idCountry->setItemData(1, "LT"); - ui->idCountry->setItemData(2, "LV"); - ui->idCountry->setCurrentIndex(ui->idCountry->findData(s.value(QStringLiteral("SmartIDCountry"), QStringLiteral("EE")).toString())); - ui->cbRemember->setChecked(s.value(QStringLiteral("SmartIDSettings"), true).toBool()); + ui->idCode->setText(Settings::SMARTID_CODE); + for(int i = 0, count = Settings::SMARTID_COUNTRY_LIST.size(); i < count; ++i) + ui->idCountry->setItemData(i, Settings::SMARTID_COUNTRY_LIST[i]); + ui->idCountry->setCurrentIndex(ui->idCountry->findData(Settings::SMARTID_COUNTRY)); + ui->cbRemember->setChecked(Settings::SMARTID_REMEMBER); auto saveSettings = [this]{ bool checked = ui->cbRemember->isChecked(); - SettingsDialog::setValueEx(QStringLiteral("SmartIDSettings"), checked, true); - SettingsDialog::setValueEx(QStringLiteral("SmartID"), checked ? idCode() : QString()); - SettingsDialog::setValueEx(QStringLiteral("SmartIDCountry"), checked ? country() : EE, EE); + Settings::SMARTID_REMEMBER = checked; + Settings::SMARTID_CODE = checked ? idCode() : QString(); + Settings::SMARTID_COUNTRY = checked ? country() : EE; }; connect(ui->idCode, &QLineEdit::returnPressed, ui->sign, &QPushButton::click); connect(ui->idCode, &QLineEdit::textEdited, this, saveSettings); diff --git a/client/dialogs/SmartIDProgress.cpp b/client/dialogs/SmartIDProgress.cpp index e94a175e2..2f516e7cd 100644 --- a/client/dialogs/SmartIDProgress.cpp +++ b/client/dialogs/SmartIDProgress.cpp @@ -21,12 +21,12 @@ #include "ui_MobileProgress.h" #include "Application.h" +#include "Settings.h" #include "Styles.h" #include "Utils.h" #include "dialogs/WarningDialog.h" #include -#include #include @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -55,7 +54,6 @@ class SmartIDProgress::Private final: public QDialog, public Ui::MobileProgress { Q_OBJECT public: - QString URL() { return !UUID.isNull() && useCustomUUID ? SKURL : PROXYURL; } using QDialog::QDialog; void reject() final { l.exit(QDialog::Rejected); } void setVisible(bool visible) final { @@ -63,26 +61,19 @@ class SmartIDProgress::Private final: public QDialog, public Ui::MobileProgress QDialog::setVisible(visible); if(!visible && hider) hider.reset(); } - QTimeLine *statusTimer = nullptr; - QNetworkAccessManager *manager = nullptr; + QTimeLine *statusTimer {}; + QNetworkAccessManager *manager {}; QNetworkRequest req; QString documentNumber, sessionID, fileName; X509Cert cert; std::vector signature; QEventLoop l; -#ifdef CONFIG_URL - QJsonObject config = qApp->conf()->object(); - QString PROXYURL = config.value(QLatin1String("SIDV2-PROXY-URL")).toString(config.value(QLatin1String("SID-PROXY-URL")).toString(QStringLiteral(SMARTID_URL))); - QString SKURL = config.value(QLatin1String("SIDV2-SK-URL")).toString(config.value(QLatin1String("SID-SK-URL")).toString(QStringLiteral(SMARTID_URL))); -#else - QString PROXYURL = QSettings().value(QStringLiteral("SID-PROXY-URL"), QStringLiteral(SMARTID_URL)).toString(); - QString SKURL = QSettings().value(QStringLiteral("SID-SK-URL"), QStringLiteral(SMARTID_URL)).toString(); -#endif - QString NAME = QSettings().value(QStringLiteral("SIDNAME"), QStringLiteral("RIA DigiDoc")).toString(); - bool useCustomUUID = QSettings().value(QStringLiteral("SIDUUID-CUSTOM"), QSettings().contains(QStringLiteral("SIDUUID"))).toBool(); - QString UUID = useCustomUUID ? QSettings().value(QStringLiteral("SIDUUID")).toString() : QString(); + bool useCustomUUID = Settings::SID_UUID_CUSTOM; + QString UUID = useCustomUUID ? Settings::SID_UUID : QString(); + QString NAME = Settings::SID_NAME; + QString URL = !UUID.isNull() && useCustomUUID ? Settings::SID_SK_URL : Settings::SID_PROXY_URL; #ifdef QT_WIN_EXTRAS - QWinTaskbarButton *taskbar = nullptr; + QWinTaskbarButton *taskbar {}; #endif std::unique_ptr hider; }; @@ -137,8 +128,8 @@ background-color: #007aff; QList trusted; #ifdef CONFIG_URL ssl.setCaCertificates({}); - for(const QJsonValue c: d->config.value(QLatin1String("CERT-BUNDLE")).toArray()) - trusted << QSslCertificate(QByteArray::fromBase64(c.toString().toLatin1()), QSsl::Der); + for(const QJsonValue c: qApp->confValue(QLatin1String("CERT-BUNDLE")).toArray()) + trusted.append(QSslCertificate(QByteArray::fromBase64(c.toString().toLatin1()), QSsl::Der)); #endif d->req.setSslConfiguration(ssl); d->req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); @@ -171,7 +162,7 @@ background-color: #007aff; auto returnError = [=](const QString &err, const QString &details = {}) { qCWarning(SIDLog) << err; d->hide(); - WarningDialog *dlg = WarningDialog::show(d->parentWidget(), err, details); + auto *dlg = WarningDialog::show(d->parentWidget(), err, details); QObject::connect(dlg, &WarningDialog::finished, &d->l, &QEventLoop::exit); }; @@ -274,7 +265,7 @@ background-color: #007aff; } else { d->show(); } - d->req.setUrl(QUrl(QStringLiteral("%1/session/%2?timeoutMs=10000").arg(d->URL(), d->sessionID))); + d->req.setUrl(QUrl(QStringLiteral("%1/session/%2?timeoutMs=10000").arg(d->URL, d->sessionID))); qCDebug(SIDLog).noquote() << d->req.url(); d->manager->get(d->req); }); @@ -294,7 +285,7 @@ bool SmartIDProgress::init(const QString &country, const QString &idCode, const { if(!d->UUID.isEmpty() && QUuid(d->UUID).isNull()) { - WarningDialog(tr("Failed to send request. Check your %1 service access settings.").arg(tr("Smart-ID")), {}, d->parentWidget()).exec(); + WarningDialog::show(d->parentWidget(), tr("Failed to send request. Check your %1 service access settings.").arg(tr("Smart-ID"))); return false; } QFileInfo info(fileName); @@ -311,9 +302,9 @@ bool SmartIDProgress::init(const QString &country, const QString &idCode, const {"nonce", QUuid::createUuid().toString().remove('-').mid(1, 30)} }).toJson(); if (d->req.url().path().contains(QLatin1String("v1"), Qt::CaseInsensitive)) { - d->req.setUrl(QUrl(QStringLiteral("%1/certificatechoice/pno/%2/%3").arg(d->URL(), country, idCode))); + d->req.setUrl(QUrl(QStringLiteral("%1/certificatechoice/pno/%2/%3").arg(d->URL, country, idCode))); } else { - d->req.setUrl(QUrl(QStringLiteral("%1/certificatechoice/etsi/PNO%2-%3").arg(d->URL(), country, idCode))); + d->req.setUrl(QUrl(QStringLiteral("%1/certificatechoice/etsi/PNO%2-%3").arg(d->URL, country, idCode))); } qCDebug(SIDLog).noquote() << d->req.url() << data; d->manager->post(d->req, data); @@ -366,7 +357,7 @@ std::vector SmartIDProgress::sign(const std::string &method, cons } // Workaround SID proxy issues QByteArray data = QString::fromUtf8(QJsonDocument(req).toJson()).arg(escapeUnicode(escape)).toUtf8(); - d->req.setUrl(QUrl(QStringLiteral("%1/signature/document/%2").arg(d->URL(), d->documentNumber))); + d->req.setUrl(QUrl(QStringLiteral("%1/signature/document/%2").arg(d->URL, d->documentNumber))); qCDebug(SIDLog).noquote() << d->req.url() << data; d->manager->post(d->req, data); d->statusTimer->start(); diff --git a/client/sslConnect.cpp b/client/sslConnect.cpp index eceabb03d..81b65e077 100644 --- a/client/sslConnect.cpp +++ b/client/sslConnect.cpp @@ -25,9 +25,6 @@ #include "TokenData.h" #include "dialogs/WaitDialog.h" -#include - -#include #include #include #include @@ -47,8 +44,8 @@ SSLConnect::SSLConnect(QObject *parent) { #ifdef CONFIG_URL d->ssl.setCaCertificates({}); - for(const QJsonValue c: qApp->conf()->object().value(QStringLiteral("CERT-BUNDLE")).toArray()) - d->trusted << QSslCertificate(QByteArray::fromBase64(c.toString().toLatin1()), QSsl::Der); + for(const auto c: qApp->confValue(QLatin1String("CERT-BUNDLE")).toArray()) + d->trusted.append(QSslCertificate(QByteArray::fromBase64(c.toString().toLatin1()), QSsl::Der)); #endif } @@ -81,15 +78,11 @@ void SSLConnect::fetch() d->ssl.setPrivateKey(key); d->ssl.setLocalCertificate(cert); - QJsonObject obj; -#ifdef CONFIG_URL - obj = qApp->conf()->object(); -#endif QNetworkRequest req; req.setSslConfiguration(d->ssl); req.setRawHeader("User-Agent", QString(QStringLiteral("%1/%2 (%3)")) .arg(qApp->applicationName(), qApp->applicationVersion(), Common::applicationOs()).toUtf8()); - req.setUrl(obj.value(QLatin1String("PICTURE-URL")).toString(QStringLiteral("https://sisene.www.eesti.ee/idportaal/portaal.idpilt"))); + req.setUrl(qApp->confValue(QLatin1String("PICTURE-URL")).toString(QStringLiteral("https://sisene.www.eesti.ee/idportaal/portaal.idpilt"))); QNetworkAccessManager *nam = new QNetworkAccessManager(this); connect(nam, &QNetworkAccessManager::sslErrors, this, [=](QNetworkReply *reply, const QList &errors){ diff --git a/client/translations/en.ts b/client/translations/en.ts index baa45b538..7f519757c 100644 --- a/client/translations/en.ts +++ b/client/translations/en.ts @@ -209,10 +209,6 @@ Loading TSL lists Loading TSL lists - - Create %1 - Create %1 - Added file(s) exceeds the maximum size limit of the container(120MB). Added file(s) exceeds the maximum size limit of the container (~120MB). @@ -924,6 +920,18 @@ Choose Choose + + signature container + signature container + + + crypto container + crypto container + + + Create %1 + Create %1 + FileItem @@ -1490,14 +1498,6 @@ ID-CARD Open file for encryption or decryption ... OR LOAD FILE FROM DISK - - signature container - signature container - - - crypto container - crypto container - Decryption succeeded! Decryption succeeded! @@ -2791,7 +2791,7 @@ Additional licenses and components Select Time-Stamping server certificate - + Select Time-Stamping server certificate Time-Stamping service SSL certificate diff --git a/client/translations/et.ts b/client/translations/et.ts index d159f4f54..85b7c0d2e 100644 --- a/client/translations/et.ts +++ b/client/translations/et.ts @@ -209,10 +209,6 @@ Loading TSL lists Laadin TSL-nimekirja - - Create %1 - Loo %1 - Added file(s) exceeds the maximum size limit of the container(120MB). Lisatud fail(id) ületab turvaümbriku maksimaalset suurust (~120MB). @@ -924,6 +920,18 @@ Choose Vali + + signature container + allkirjaümbrik + + + crypto container + krüptoümbrik + + + Create %1 + Loo %1 + FileItem @@ -1490,14 +1498,6 @@ ID-KAARDIGA Open file for encryption or decryption ... VÕI VALI FAIL KETTALT - - signature container - allkirja ümbrik - - - crypto container - krüpto ümbrik - Decryption succeeded! Dekrüpteerimine õnnestus! diff --git a/client/translations/ru.ts b/client/translations/ru.ts index c1834edd5..516c92574 100644 --- a/client/translations/ru.ts +++ b/client/translations/ru.ts @@ -209,10 +209,6 @@ Loading TSL lists Загружаем список TSL - - Create %1 - Создайте %1 - Added file(s) exceeds the maximum size limit of the container(120MB). Вложенные файл(ы) превышают размер контейнера безопасности (~120 МБ). @@ -926,6 +922,18 @@ Choose Выбрать + + signature container + контейнер подписи + + + crypto container + криптоконтейнер + + + Create %1 + Создайте %1 + FileItem @@ -1492,14 +1500,6 @@ ID-КАРТОЙ Open file for encryption or decryption ... ИЛИ ЗАГРУЗИТЕ ФАЙЛ С ДИСКА - - signature container - контейнер подписи - - - crypto container - криптоконтейнер - Decryption succeeded! Расшифровывание прошло успешно! diff --git a/client/widgets/ContainerPage.cpp b/client/widgets/ContainerPage.cpp index 1a3f14db5..20e006c2b 100644 --- a/client/widgets/ContainerPage.cpp +++ b/client/widgets/ContainerPage.cpp @@ -22,6 +22,7 @@ #include "CryptoDoc.h" #include "DigiDoc.h" +#include "Settings.h" #include "Styles.h" #include "SslCertificate.h" #include "dialogs/AddRecipients.h" @@ -38,8 +39,6 @@ #include #include -#include - using namespace ria::qdigidoc4; ContainerPage::ContainerPage(QWidget *parent) @@ -63,7 +62,7 @@ ContainerPage::ContainerPage(QWidget *parent) ui->summary->init( LabelButton::BoxedDeepCerulean, tr("PRINT SUMMARY"), Actions::ContainerSummary ); ui->save->init( LabelButton::BoxedDeepCerulean, tr("SAVE WITHOUT SIGNING"), Actions::ContainerSave ); - mobileCode = QSettings().value(QStringLiteral("MobileCode")).toString(); + mobileCode = Settings::MOBILEID_CODE; connect(this, &ContainerPage::moved,this, &ContainerPage::setHeader); connect(ui->changeLocation, &LabelButton::clicked, this, &ContainerPage::forward); @@ -82,7 +81,7 @@ ContainerPage::ContainerPage(QWidget *parent) connect(ui->containerFile, &QLabel::linkActivated, this, [this](const QString &link) { emit action(Actions::ContainerNavigate, link); }); - ui->summary->setVisible(QSettings().value(QStringLiteral("ShowPrintSummary"), false).toBool()); + ui->summary->setVisible(Settings::SHOW_PRINT_SUMMARY); } ContainerPage::~ContainerPage() @@ -126,7 +125,7 @@ bool ContainerPage::checkAction(int code, const QString& selectedCard, const QSt if(ui->rightPane->hasItem( [selectedCard, selectedMobile, code](Item* const item) -> bool { - auto signatureItem = qobject_cast(item); + auto *signatureItem = qobject_cast(item); return signatureItem && signatureItem->isSelfSigned(selectedCard, (code == SignatureMobile) ? selectedMobile: QString()); } )) @@ -179,15 +178,13 @@ void ContainerPage::forward(int code) { case SignatureMobile: { - MobileDialog dlg(this); - QString newCode = QSettings().value(QStringLiteral("MobileCode")).toString(); - if(dlg.exec() == QDialog::Accepted) + if(MobileDialog dlg(this); dlg.exec() == QDialog::Accepted) { if(checkAction(SignatureMobile, dlg.idCode(), dlg.phoneNo())) emit action(SignatureMobile, dlg.idCode(), dlg.phoneNo()); } - if (newCode != mobileCode) + if(QString newCode = Settings::MOBILEID_CODE; newCode != mobileCode) { mobileCode = newCode; cardChanged(cardInReader); @@ -196,15 +193,13 @@ void ContainerPage::forward(int code) } case SignatureSmartID: { - SmartIDDialog dlg(this); - QString newCode = QSettings().value(QStringLiteral("SmartID")).toString(); - if(dlg.exec() == QDialog::Accepted) + if(SmartIDDialog dlg(this); dlg.exec() == QDialog::Accepted) { if(checkAction(SignatureMobile, dlg.idCode(), {})) emit action(SignatureSmartID, dlg.country(), dlg.idCode()); } - if (newCode != mobileCode) + if(QString newCode = Settings::SMARTID_CODE; newCode != mobileCode) { mobileCode = newCode; cardChanged(cardInReader); @@ -266,7 +261,7 @@ void ContainerPage::showMainAction(const QList &actions) { if(!mainAction) { - mainAction.reset(new MainAction(this)); + mainAction = std::make_unique(this); connect(mainAction.get(), &MainAction::action, this, &ContainerPage::forward); } mainAction->showActions(actions); @@ -327,7 +322,7 @@ void ContainerPage::transition(DigiDoc* container) for(const DigiDocSignature &c: container->timestamps()) { - SignatureItem *item = new SignatureItem(c, container->state(), ui->rightPane); + auto *item = new SignatureItem(c, container->state(), ui->rightPane); if(c.isInvalid()) addError(item); ui->rightPane->addHeaderWidget(item); @@ -336,7 +331,7 @@ void ContainerPage::transition(DigiDoc* container) for(const DigiDocSignature &c: container->signatures()) { - SignatureItem *item = new SignatureItem(c, container->state(), ui->rightPane); + auto *item = new SignatureItem(c, container->state(), ui->rightPane); if(c.isInvalid()) addError(item); ui->rightPane->addWidget(item); @@ -391,7 +386,7 @@ void ContainerPage::updatePanes(ContainerState state) { ui->leftPane->stateChange(state); ui->rightPane->stateChange(state); - bool showPrintSummary = QSettings().value(QStringLiteral("ShowPrintSummary"), false).toBool(); + bool showPrintSummary = Settings::SHOW_PRINT_SUMMARY; auto setButtonsVisible = [](const QVector &buttons, bool visible) { for(QWidget *button: buttons) button->setVisible(visible); }; diff --git a/client/widgets/MainAction.cpp b/client/widgets/MainAction.cpp index 56677d3a7..9a3fe55d4 100644 --- a/client/widgets/MainAction.cpp +++ b/client/widgets/MainAction.cpp @@ -19,10 +19,9 @@ #include "MainAction.h" #include "ui_MainAction.h" +#include "Settings.h" #include "Styles.h" -#include "dialogs/SettingsDialog.h" -#include #include #include #include @@ -49,9 +48,9 @@ MainAction::MainAction(QWidget *parent) connect(ui->mainAction, &QPushButton::clicked, this, [&]{ if (ui->actions.value(0) == Actions::SignatureMobile) - SettingsDialog::setValueEx("MIDOrder", true, true); + Settings::MOBILEID_ORDER = true; if (ui->actions.value(0) == Actions::SignatureSmartID) - SettingsDialog::setValueEx("MIDOrder", false, true); + Settings::MOBILEID_ORDER = false; }); connect(ui->mainAction, &QPushButton::clicked, this, [&]{ emit action(ui->actions.value(0)); }); connect(ui->mainAction, &QPushButton::clicked, this, &MainAction::hideDropdown); @@ -103,7 +102,7 @@ bool MainAction::eventFilter(QObject *watched, QEvent *event) case QEvent::Paint: if(watched == ui->otherCards) { - QToolButton *button = qobject_cast(watched); + auto *button = qobject_cast(watched); QPainter painter(button); painter.setRenderHint(QPainter::Antialiasing); if(ui->otherCards->property("pressed").toBool()) @@ -128,7 +127,7 @@ bool MainAction::eventFilter(QObject *watched, QEvent *event) } -QString MainAction::label(Actions action) const +QString MainAction::label(Actions action) { switch(action) { @@ -154,7 +153,7 @@ void MainAction::showActions(const QList &actions) std::all_of(order.cbegin(), order.cend(), [] (Actions action) { return action == SignatureMobile || action == SignatureSmartID; }) && - !QSettings().value("MIDOrder", true).toBool()) + !Settings::MOBILEID_ORDER) { std::reverse(order.begin(), order.end()); } @@ -170,7 +169,7 @@ void MainAction::showDropdown() { for(QList::const_iterator i = ui->actions.cbegin() + 1; i != ui->actions.cend(); ++i) { - QPushButton *other = new QPushButton(label(*i), parentWidget()); + auto *other = new QPushButton(label(*i), parentWidget()); other->setAccessibleName(label(*i).toLower()); other->setCursor(ui->mainAction->cursor()); other->setFont(ui->mainAction->font()); @@ -180,9 +179,9 @@ void MainAction::showDropdown() other->setStyleSheet(ui->mainAction->styleSheet() + QStringLiteral("\nborder-top-left-radius: 2px; border-top-right-radius: 2px;")); if (*i == Actions::SignatureMobile) - connect(other, &QPushButton::clicked, this, []{ SettingsDialog::setValueEx("MIDOrder", true, true); }); + connect(other, &QPushButton::clicked, this, []{ Settings::MOBILEID_ORDER = true; }); if (*i == Actions::SignatureSmartID) - connect(other, &QPushButton::clicked, this, []{ SettingsDialog::setValueEx("MIDOrder", false, true); }); + connect(other, &QPushButton::clicked, this, []{ Settings::MOBILEID_ORDER = false; }); connect(other, &QPushButton::clicked, this, &MainAction::hideDropdown); connect(other, &QPushButton::clicked, this, [=]{ emit this->action(*i); }); ui->list.push_back(other); diff --git a/client/widgets/MainAction.h b/client/widgets/MainAction.h index 80349614c..263d95ff0 100644 --- a/client/widgets/MainAction.h +++ b/client/widgets/MainAction.h @@ -41,10 +41,11 @@ class MainAction final : public QWidget private: void changeEvent(QEvent* event) override; bool eventFilter(QObject *watched, QEvent *event) override; - QString label(ria::qdigidoc4::Actions action) const; void showDropdown(); void update(); + static QString label(ria::qdigidoc4::Actions action); + class Private; Private *ui; };