Skip to content

Commit

Permalink
Create Settings class (open-eid#1152)
Browse files Browse the repository at this point in the history
IB-7607

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored Feb 13, 2023
1 parent a35d33c commit 9dba973
Show file tree
Hide file tree
Showing 27 changed files with 565 additions and 415 deletions.
158 changes: 84 additions & 74 deletions client/Application.cpp

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions client/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class Application final: public Common
void waitForTSL( const QString &file );

static void addRecent( const QString &file );
template<class T>
static QJsonValue confValue(const T &key);
static QVariant confValue(ConfParameter parameter, const QVariant &value = {});
static void clearConfValue( ConfParameter parameter );
static void initDiagnosticConf();
Expand Down
101 changes: 51 additions & 50 deletions client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand All @@ -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} $<TARGET_FILE_DIR:${PROJECT_NAME}>
COMMAND mkdir -p $<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Library/QuickLook
COMMAND cp -a $<TARGET_BUNDLE_DIR:DigiDocQL> $<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/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} $<TARGET_FILE_DIR:${PROJECT_NAME}>
COMMAND mkdir -p $<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Library/QuickLook
COMMAND cp -a $<TARGET_BUNDLE_DIR:DigiDocQL> $<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Library/QuickLook
)
add_custom_target(macdeployqt DEPENDS ${PROJECT_NAME}
COMMAND ${qtCore_install_prefix}/macdeployqt $<TARGET_BUNDLE_DIR:${PROJECT_NAME}>
COMMAND rm -rf $<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/PlugIns/bearer
COMMAND cp -a /Library/Frameworks/digidocpp.framework $<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks
COMMAND rm $<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks/digidocpp.framework/Resources/digidoc-tool
COMMAND find $<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks -name Headers | xargs rm -rf
COMMAND install_name_tool -delete_rpath /Library/Frameworks $<TARGET_FILE:${PROJECT_NAME}>
add_custom_target(macdeployqt DEPENDS ${PROJECT_NAME}
COMMAND ${qtCore_install_prefix}/macdeployqt $<TARGET_BUNDLE_DIR:${PROJECT_NAME}>
COMMAND rm -rf $<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/PlugIns/bearer
COMMAND cp -a /Library/Frameworks/digidocpp.framework $<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks
COMMAND rm $<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks/digidocpp.framework/Resources/digidoc-tool
COMMAND find $<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks -name Headers | xargs rm -rf
COMMAND install_name_tool -delete_rpath /Library/Frameworks $<TARGET_FILE:${PROJECT_NAME}>
COMMAND ln -sf digidocpp.framework/Libraries/libcrypto.dylib
$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks/libcrypto.1.1.dylib
$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks/libcrypto.1.1.dylib
COMMAND ln -sf digidocpp.framework/Libraries/libssl.dylib
$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks/libssl.1.1.dylib
$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks/libssl.1.1.dylib
)

add_custom_target(codesign DEPENDS ${PROJECT_NAME}
add_custom_target(codesign DEPENDS ${PROJECT_NAME}
COMMAND codesign -f -s \"$$SIGNCERT\"
$<TARGET_FILE_DIR:${PROJECT_NAME}>/*.*
$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks/digidocpp.framework/Libraries/*
$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks/*.framework
$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/PlugIns/*/*
$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Library/QuickLook/DigiDocQL.qlgenerator
$<TARGET_FILE_DIR:${PROJECT_NAME}>/*.*
$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks/digidocpp.framework/Libraries/*
$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks/*.framework
$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/PlugIns/*/*
$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Library/QuickLook/DigiDocQL.qlgenerator
COMMAND if echo \"$$SIGNCERT\" | grep -q "Developer ID" \; then
codesign -f -s \"$$SIGNCERT\" $<TARGET_BUNDLE_DIR:${PROJECT_NAME}> --entitlements ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.eToken.entitlements\;
codesign -f -s \"$$SIGNCERT\" $<TARGET_BUNDLE_DIR:${PROJECT_NAME}> --entitlements ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.eToken.entitlements\;
else
codesign -f -s \"$$SIGNCERT\" $<TARGET_BUNDLE_DIR:${PROJECT_NAME}> --entitlements ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.entitlements\;
codesign -f -s \"$$SIGNCERT\" $<TARGET_BUNDLE_DIR:${PROJECT_NAME}> --entitlements ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.entitlements\;
fi
)

add_custom_target(productbuild DEPENDS ${PROJECT_NAME}
COMMAND productbuild --component $<TARGET_BUNDLE_DIR:${PROJECT_NAME}> /Applications
add_custom_target(productbuild DEPENDS ${PROJECT_NAME}
COMMAND productbuild --component $<TARGET_BUNDLE_DIR:${PROJECT_NAME}> /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 $<TARGET_FILE:${PROJECT_NAME}>
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 $<TARGET_FILE:${PROJECT_NAME}>
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" $<$<BOOL:${CROSSSIGNCERT}>:/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" $<$<BOOL:${CROSSSIGNCERT}>:/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)
Expand All @@ -230,15 +231,15 @@ 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=$<TARGET_FILE:${PROJECT_NAME}> -dico_path=${CMAKE_CURRENT_SOURCE_DIR}/images/digidoc.ico
-dlibs_path="${LIBS_PATH}" -dclient_path=$<TARGET_FILE:${PROJECT_NAME}> -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=$<$<CONFIG:Debug>:d> ${CMAKE_SOURCE_DIR}/qdigidoc4.wxs
${CMAKE_SOURCE_DIR}/cmake/modules/WelcomeDlg2.wxs ${CMAKE_SOURCE_DIR}/cmake/modules/WixUI_Minimal2.wxs)
list(APPEND LIGHT_CMD "$ENV{WIX}bin\\light.exe" -nologo -ext WixUIExtension
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"
Expand All @@ -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} "$<$<BOOL:${CROSSSIGNCERT}>:/ph;/ac;${CROSSSIGNCERT}>" $<TARGET_FILE:${PROJECT_NAME}>
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${SIGNCMD} "$<$<BOOL:${CROSSSIGNCERT}>:/ph;/ac;${CROSSSIGNCERT}>" $<TARGET_FILE:${PROJECT_NAME}>
COMMAND_EXPAND_LISTS
)
add_custom_command(TARGET msi POST_BUILD
Expand All @@ -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 $<TARGET_FILE:${PROJECT_NAME}> appx
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PROJECT_NAME}> 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
Expand All @@ -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 )
Expand Down
1 change: 0 additions & 1 deletion client/CryptoDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include <QtCore/QUrl>
#include <QtCore/QXmlStreamReader>
#include <QtCore/QXmlStreamWriter>
#include <QtCore/QSettings>
#include <QtGui/QDesktopServices>
#include <QtNetwork/QSslKey>

Expand Down
26 changes: 9 additions & 17 deletions client/Diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
#include "QPCSC.h"

#ifdef CONFIG_URL
#include "Configuration.h"
#include "Settings.h"
#include <QtCore/QJsonObject>
#include <QtCore/QSettings>
#endif

#include <QtCore/QDir>
Expand All @@ -38,21 +37,14 @@ void Diagnostics::generalInfo(QTextStream &s)
<< "<b>" << "URLs:" << "</b>"
#ifdef CONFIG_URL
<< "<br />CONFIG_URL: " << CONFIG_URL
<< "<br />SID-PROXY-URL: " << qApp->conf()->object().value(QStringLiteral("SID-PROXY-URL")).toString(QStringLiteral(SMARTID_URL))
<< "<br />SIDV2-PROXY-URL: " << qApp->conf()->object().value(QStringLiteral("SIDV2-PROXY-URL")).toString(QStringLiteral(SMARTID_URL))
<< "<br />SID-SK-URL: " << qApp->conf()->object().value(QStringLiteral("SID-SK-URL")).toString(QStringLiteral(SMARTID_URL))
<< "<br />SIDV2-SK-URL: " << qApp->conf()->object().value(QStringLiteral("SIDV2-SK-URL")).toString(QStringLiteral(SMARTID_URL))
<< "<br />MID-PROXY-URL: " << qApp->conf()->object().value(QStringLiteral("MID-PROXY-URL")).toString(QStringLiteral(MOBILEID_URL))
<< "<br />MID-SK-URL: " << qApp->conf()->object().value(QStringLiteral("MID-SK-URL")).toString(QStringLiteral(MOBILEID_URL))
<< "<br />RPUUID: " << (QSettings().value(QStringLiteral("MIDUUID-CUSTOM"), QSettings().contains(QStringLiteral("MIDUUID"))).toBool() ? tr("is set manually") : tr("is set by default"))
#else
#ifdef MOBILEID_URL
<< "<br />MOBILEID_URL: " << MOBILEID_URL
#endif
#ifdef SMARTID_URL
<< "<br />SMARTID_URL: " << SMARTID_URL
#endif
#endif
<< "<br />SID-PROXY-URL: " << qApp->confValue(QLatin1String("SID-PROXY-URL")).toString(QStringLiteral(SMARTID_URL))
<< "<br />SIDV2-PROXY-URL: " << qApp->confValue(QLatin1String("SIDV2-PROXY-URL")).toString(QStringLiteral(SMARTID_URL))
<< "<br />SID-SK-URL: " << qApp->confValue(QLatin1String("SID-SK-URL")).toString(QStringLiteral(SMARTID_URL))
<< "<br />SIDV2-SK-URL: " << qApp->confValue(QLatin1String("SIDV2-SK-URL")).toString(QStringLiteral(SMARTID_URL))
<< "<br />MID-PROXY-URL: " << Settings::MID_PROXY_URL
<< "<br />MID-SK-URL: " << Settings::MID_SK_URL
<< "<br />RPUUID: " << (Settings::MID_UUID_CUSTOM ? tr("is set manually") : tr("is set by default"))
<< "<br />TSL_URL: " << qApp->confValue(Application::TSLUrl).toString()
<< "<br />TSA_URL: " << qApp->confValue(Application::TSAUrl).toString()
<< "<br />SIVA_URL: " << qApp->confValue(Application::SiVaUrl).toString()
Expand All @@ -72,7 +64,7 @@ void Diagnostics::generalInfo(QTextStream &s)

#ifdef CONFIG_URL
s << "<b>" << tr("Central Configuration") << ":</b>";
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)
Expand Down
21 changes: 6 additions & 15 deletions client/DocumentModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
#include "dialogs/FileDialog.h"
#include "dialogs/WarningDialog.h"

#include <common/Configuration.h>

#include <QtCore/QJsonObject>
#include <QtCore/QJsonArray>
#include <QtCore/QFileInfo>
#include <QtCore/QProcessEnvironment>
Expand All @@ -47,32 +44,26 @@ 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"),
QStringLiteral("wpd"), QStringLiteral("rtf"), QStringLiteral("xlr"), QStringLiteral("xls"), QStringLiteral("xlsx"), QStringLiteral("pdf"), QStringLiteral("key"), QStringLiteral("odp"),
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;
}

Expand Down
2 changes: 1 addition & 1 deletion client/DocumentModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ class DocumentModel: public QObject
void removed(int row);

protected:
bool verifyFile(const QString &f);
static bool verifyFile(const QString &f);
};
Loading

0 comments on commit 9dba973

Please sign in to comment.