From 7c7ca4575e7fe6c3412d3fffcd1d5ad580211a17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20V=C3=A4nttinen?= Date: Mon, 4 May 2026 15:16:51 +0300 Subject: [PATCH] WIP: Qt6 transition (#11651) Update KeePassXC to use Qt 6. --- .github/workflows/codeql.yml | 8 +- CMakeLists.txt | 86 +++--- INSTALL.md | 4 +- share/translations/CMakeLists.txt | 9 +- share/translations/keepassxc_en.ts | 44 +-- src/CMakeLists.txt | 45 ++- src/autotype/AutoType.cpp | 9 +- src/autotype/AutoType.h | 5 +- src/autotype/AutoTypeMatch.h | 4 +- src/autotype/AutoTypeMatchView.cpp | 8 +- src/autotype/AutoTypeSelectDialog.cpp | 34 +-- src/autotype/CMakeLists.txt | 5 +- src/autotype/mac/AutoTypeMac.h | 10 +- src/autotype/mac/CMakeLists.txt | 2 +- src/autotype/test/CMakeLists.txt | 2 +- src/autotype/windows/AutoTypeWindows.h | 8 +- src/autotype/windows/CMakeLists.txt | 2 +- src/autotype/xcb/AutoTypeXCB.cpp | 54 +++- src/autotype/xcb/AutoTypeXCB.h | 16 +- src/autotype/xcb/CMakeLists.txt | 2 +- src/browser/BrowserService.cpp | 4 +- src/browser/CMakeLists.txt | 4 +- src/browser/NativeMessageInstaller.cpp | 2 +- src/browser/PasskeyUtils.cpp | 7 +- src/cli/CMakeLists.txt | 8 +- src/cli/TextStream.cpp | 22 +- src/cli/TextStream.h | 3 +- src/cli/Utils.cpp | 24 +- src/cli/Utils.h | 5 +- src/cli/keepassxc-cli.cpp | 8 +- src/core/Base32.cpp | 8 +- src/core/Base32.h | 4 +- src/core/Clock.cpp | 5 +- src/core/Database.cpp | 8 +- src/core/Entry.cpp | 7 +- src/core/EntryAttachments.cpp | 4 +- src/core/EntryAttachments.h | 7 +- src/core/Global.h | 18 +- src/core/Group.cpp | 2 +- src/core/Merger.cpp | 2 +- src/core/Metadata.cpp | 4 +- src/core/PassphraseGenerator.cpp | 8 +- src/core/PasswordGenerator.cpp | 68 ++--- src/core/SignalMultiplexer.h | 4 +- src/core/Tools.cpp | 14 +- src/core/Tools.h | 6 +- src/core/Translator.cpp | 2 +- src/crypto/Crypto.cpp | 3 +- src/crypto/SymmetricCipher.cpp | 3 +- src/crypto/kdf/Argon2Kdf.cpp | 33 +-- src/fdosecrets/CMakeLists.txt | 2 +- src/fdosecrets/FdoSecretsPlugin.h | 2 + src/fdosecrets/FdoSecretsSettings.cpp | 3 +- src/fdosecrets/dbus/DBusDispatch.cpp | 22 +- src/fdosecrets/dbus/DBusMgr.h | 9 + src/fdosecrets/objects/Item.cpp | 19 +- src/format/BitwardenReader.cpp | 5 +- src/format/CsvParser.cpp | 16 +- src/format/CsvParser.h | 1 + src/format/Kdbx4Writer.cpp | 6 +- src/format/KdbxXmlReader.cpp | 260 +++++++++--------- src/format/KdbxXmlReader.h | 5 +- src/format/KdbxXmlWriter.cpp | 8 +- src/format/KeePass1Reader.cpp | 32 ++- src/format/KeePass1Reader.h | 1 + src/format/OPUXReader.cpp | 2 +- src/format/OpVaultReader.cpp | 10 +- src/format/OpVaultReaderBandEntry.cpp | 8 +- src/format/OpVaultReaderSections.cpp | 6 +- src/gui/DatabaseIcons.h | 2 + src/gui/DatabaseOpenDialog.cpp | 20 +- src/gui/DatabaseTabWidget.h | 6 +- src/gui/DatabaseWidget.cpp | 10 +- src/gui/Icons.cpp | 1 + src/gui/MainWindow.cpp | 62 ++--- src/gui/MergeDialog.cpp | 2 +- src/gui/MessageBox.cpp | 3 +- src/gui/PasswordGeneratorWidget.cpp | 2 +- src/gui/UrlTools.cpp | 4 +- .../DatabaseSettingsWidgetDatabaseKey.cpp | 4 +- src/gui/entry/EntryAttachmentsWidget.cpp | 4 +- src/gui/entry/EntryModel.cpp | 9 +- src/gui/entry/EntryView.cpp | 8 +- .../TextAttachmentsPreviewWidget.cpp | 6 +- .../TextAttachmentsPreviewWidget.h | 4 +- src/gui/group/GroupView.cpp | 11 +- src/gui/osutils/macutils/MacPasteboard.cpp | 70 ++--- src/gui/osutils/macutils/MacPasteboard.h | 22 +- src/gui/osutils/macutils/MacUtils.h | 3 +- src/gui/osutils/nixutils/NixUtils.cpp | 41 +-- src/gui/osutils/nixutils/NixUtils.h | 2 +- .../osutils/winutils/DeviceListenerWin.cpp | 5 +- src/gui/osutils/winutils/DeviceListenerWin.h | 4 +- .../winutils/ScreenLockListenerWin.cpp | 5 +- .../osutils/winutils/ScreenLockListenerWin.h | 4 +- src/gui/osutils/winutils/WinUtils.cpp | 5 +- src/gui/osutils/winutils/WinUtils.h | 5 +- .../remote/DatabaseSettingsWidgetRemote.cpp | 4 +- src/gui/remote/RemoteProcess.cpp | 6 +- src/gui/remote/RemoteSettings.h | 3 +- src/gui/styles/base/BaseStyle.cpp | 42 ++- src/keeshare/CMakeLists.txt | 17 +- src/keeshare/KeeShareSettings.cpp | 34 ++- src/keeshare/ShareExport.cpp | 2 +- src/keeshare/ShareImport.cpp | 2 +- src/keys/CompositeKey.cpp | 3 +- src/keys/CompositeKey.h | 3 +- src/keys/FileKey.cpp | 18 +- src/keys/PasswordKey.cpp | 3 +- src/keys/drivers/YubiKey.cpp | 5 +- src/keys/drivers/YubiKey.h | 11 +- src/keys/drivers/YubiKeyInterfacePCSC.cpp | 9 +- src/main.cpp | 4 +- src/networking/HibpDownloader.cpp | 5 +- src/networking/UpdateChecker.cpp | 5 +- src/proxy/CMakeLists.txt | 6 +- src/proxy/NativeMessagingProxy.cpp | 6 +- src/qrcode/CMakeLists.txt | 4 +- src/qrcode/QrCode.h | 6 +- src/qrcode/QrCode_p.h | 6 +- src/quickunlock/Polkit.h | 6 +- src/quickunlock/PolkitDbusTypes.h | 23 +- src/quickunlock/TouchID.h | 10 +- src/quickunlock/TouchID.mm | 21 +- src/sshagent/CMakeLists.txt | 17 +- src/sshagent/KeeAgentSettings.cpp | 37 +-- src/sshagent/OpenSSHKey.cpp | 7 +- src/sshagent/OpenSSHKeyGen.cpp | 4 +- src/sshagent/SSHAgent.cpp | 7 +- tests/CMakeLists.txt | 8 +- tests/TestAutoType.cpp | 2 + tests/TestBase32.cpp | 125 +++++---- tests/TestBase32.h | 2 + tests/TestBrowser.cpp | 1 + tests/TestCli.cpp | 61 +++- tests/TestCli.h | 2 + tests/TestConfig.cpp | 5 + tests/TestConfig.h | 2 + tests/TestCryptoHash.cpp | 1 + tests/TestCsvExporter.cpp | 1 + tests/TestCsvParser.cpp | 59 +++- tests/TestCsvParser.h | 7 +- tests/TestDatabase.cpp | 5 +- tests/TestDeletedObjects.cpp | 1 + tests/TestEntry.cpp | 1 + tests/TestEntryModel.cpp | 12 +- tests/TestEntrySearcher.cpp | 6 + tests/TestEntrySearcher.h | 1 + tests/TestFdoSecrets.cpp | 5 + tests/TestFdoSecrets.h | 2 + tests/TestGroup.cpp | 3 +- tests/TestGroupModel.cpp | 2 + tests/TestHashedBlockStream.cpp | 2 + tests/TestHibp.cpp | 3 +- tests/TestIconDownloader.cpp | 22 ++ tests/TestIconDownloader.h | 3 +- tests/TestImports.cpp | 1 + tests/TestKdbx2.cpp | 3 +- tests/TestKdbx4.cpp | 7 +- tests/TestKdbx4.h | 3 +- tests/TestKeePass1Reader.cpp | 6 +- tests/TestKeePass1Reader.h | 4 +- tests/TestKeePass2Format.cpp | 3 +- tests/TestKeePass2RandomStream.cpp | 2 + tests/TestKeys.cpp | 3 +- tests/TestMerge.cpp | 3 +- tests/TestModified.cpp | 2 + tests/TestOpenSSHKey.cpp | 2 + tests/TestPasskeys.cpp | 23 +- tests/TestPassphraseGenerator.cpp | 3 +- tests/TestPasswordGenerator.cpp | 3 +- tests/TestPasswordHealth.cpp | 3 +- tests/TestRandomGenerator.cpp | 7 + tests/TestRandomGenerator.h | 2 + tests/TestSSHAgent.cpp | 4 +- tests/TestSharing.cpp | 5 +- tests/TestSymmetricCipher.cpp | 3 +- tests/TestTools.cpp | 5 +- tests/TestTotp.cpp | 3 +- tests/TestUpdateCheck.cpp | 3 +- tests/TestUrlTools.cpp | 3 +- tests/TestYkChallengeResponseKey.cpp | 35 +-- tests/gui/TestGui.cpp | 49 +++- tests/gui/TestGuiBrowser.cpp | 5 +- tests/gui/TestGuiFdoSecrets.cpp | 4 + tests/gui/TestGuiFdoSecrets.h | 3 + tests/gui/TestGuiPixmaps.cpp | 2 + tests/gui/TestGuiPixmaps.h | 2 + .../TestTextAttachmentsPreviewWidget.cpp | 2 - vcpkg.json | 52 +--- 190 files changed, 1308 insertions(+), 1027 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 07d4104b7..202e9dddb 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -37,11 +37,11 @@ jobs: run: | sudo apt update sudo apt install build-essential cmake g++ - sudo apt install qtbase5-dev qtbase5-private-dev qttools5-dev qttools5-dev-tools libqt5svg5-dev libargon2-dev libkeyutils-dev libminizip-dev libbotan-2-dev libqrencode-dev zlib1g-dev asciidoctor libreadline-dev libpcsclite-dev libusb-1.0-0-dev libxi-dev libxtst-dev libqt5x11extras5-dev + sudo apt install qt6-base-dev qt6-base-private-dev qt6-tools-dev qt6-base-dev-tools qt6-svg-dev qt6-5compat-dev libargon2-dev libkeyutils-dev libminizip-dev libbotan-2-dev libqrencode-dev zlib1g-dev asciidoctor libreadline-dev libpcsclite-dev libusb-1.0-0-dev libxi-dev libxtst-dev # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v3 + uses: github/codeql-action/init@v4 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -62,9 +62,9 @@ jobs: # If this step fails, then you should remove it and run the build manually (see below) - if: matrix.language != 'cpp' name: Autobuild - uses: github/codeql-action/autobuild@v3 + uses: github/codeql-action/autobuild@v4 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 + uses: github/codeql-action/analyze@v4 with: category: "/language:${{matrix.language}}" diff --git a/CMakeLists.txt b/CMakeLists.txt index a6234e29d..2fecaf863 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2024 KeePassXC Team +# Copyright (C) 2026 KeePassXC Team # Copyright (C) 2010 Felix Geyer # # This program is free software: you can redistribute it and/or modify @@ -251,12 +251,14 @@ add_gcc_compiler_flags("-Wall -Wextra -Wundef -Wpointer-arith -Wno-long-long") add_gcc_compiler_flags("-Wformat=2 -Wmissing-format-attribute") add_gcc_compiler_flags("-fvisibility=hidden") add_gcc_compiler_cxxflags("-fvisibility-inlines-hidden") +# Qt6 marks these as errors with newer compilers. Treat them as warnings for now. +check_add_gcc_compiler_cxxflag("-Wno-error=sfinae-incomplete" SFINAE_INCOMPLETE_FLAG) if(CMAKE_BUILD_TYPE_LOWER STREQUAL "debug") check_add_gcc_compiler_flag("-Wshadow-compatible-local") check_add_gcc_compiler_flag("-Wshadow-local") add_gcc_compiler_flags("-Werror") - # C++20 marks enum arithmetic as deprecated, but we use it in Botan and Qt5 + # C++20 marks enum arithmetic as deprecated, but we use it in Botan and Qt6 add_gcc_compiler_cxxflags("-Wno-deprecated-enum-enum-conversion -Wno-error=deprecated ") endif() @@ -268,16 +270,19 @@ add_gcc_compiler_cxxflags("-Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virt add_gcc_compiler_cflags("-Wchar-subscripts -Wwrite-strings") if(WITH_ASAN) - if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR APPLE)) - message(FATAL_ERROR "WITH_ASAN is only supported on Linux / macOS at the moment.") + if(MSVC) + if(NOT CMAKE_COMPILER_IS_CLANG_MSVC) + add_compile_options(/fsanitize=address) + else() + message(WARNING "Address Sanitizer is not supported with clang-cl on MSVC, skipping ASAN flags") + endif() + else() + add_gcc_compiler_flags("-fsanitize=address -DWITH_ASAN") + + if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + add_gcc_compiler_flags("-fsanitize=leak -DWITH_LSAN") + endif() endif() - - add_gcc_compiler_flags("-fsanitize=address -DWITH_ASAN") - - if(CMAKE_SYSTEM_NAME STREQUAL "Linux") - add_gcc_compiler_flags("-fsanitize=leak -DWITH_LSAN") - endif() - endif() if(CMAKE_BUILD_TYPE_LOWER MATCHES "(release|relwithdebinfo|minsizerel)") @@ -330,9 +335,9 @@ if(WIN32) message(FATAL_ERROR "Only Microsoft Visual Studio 2019 and newer are supported!") endif() add_compile_options(/permissive- /utf-8) - # Clang-cl does not support /MP, /Zf, or /fsanitize=address + # Clang-cl does not support /MP or /Zf if (NOT CMAKE_COMPILER_IS_CLANG_MSVC) - add_compile_options(/MP /Zf /fsanitize=address) + add_compile_options(/MP /Zf) endif() # Enable high entropy ASLR on release builds @@ -407,32 +412,20 @@ endif() # Find Qt set(QT_COMPONENTS Core Network Concurrent Gui Svg Widgets Test LinguistTools) if(UNIX AND NOT APPLE) - if(WITH_X11) - list(APPEND QT_COMPONENTS X11Extras) - endif() - find_package(Qt5 COMPONENTS ${QT_COMPONENTS} DBus REQUIRED) + find_package(Qt6 COMPONENTS ${QT_COMPONENTS} DBus REQUIRED) elseif(APPLE) - find_package(Qt5 COMPONENTS ${QT_COMPONENTS} REQUIRED HINTS - /usr/local/opt/qt@5/lib/cmake - /usr/local/Cellar/qt@5/*/lib/cmake - /opt/homebrew/opt/qt@5/lib/cmake - ENV PATH) - find_package(Qt5 COMPONENTS MacExtras HINTS - /usr/local/opt/qt@5/lib/cmake - /usr/local/Cellar/qt@5/*/lib/cmake - /opt/homebrew/opt/qt@5/lib/cmake + find_package(Qt6 COMPONENTS ${QT_COMPONENTS} REQUIRED HINTS + /usr/local/opt/qt/lib/cmake + /usr/local/Cellar/qt/*/lib/cmake + /opt/homebrew/opt/qt/lib/cmake ENV PATH) else() - find_package(Qt5 COMPONENTS ${QT_COMPONENTS} REQUIRED) + find_package(Qt6 COMPONENTS ${QT_COMPONENTS} REQUIRED) endif() # Minimum Qt version check -if(Qt5Core_VERSION VERSION_LESS "5.12.0") - message(FATAL_ERROR "Qt version 5.12.0 or higher is required") -endif() -# C++20 is not supported before Qt 5.15.0 -if(Qt5Core_VERSION VERSION_LESS "5.15.0") - set(CMAKE_CXX_STANDARD 17) +if(Qt6Core_VERSION VERSION_LESS "6.2.4") + message(FATAL_ERROR "Qt version 6.2.4 or higher is required") endif() # Process moc automatically @@ -447,21 +440,18 @@ if(NOT CMAKE_BUILD_TYPE_LOWER STREQUAL "debug") add_definitions(-DQT_NO_DEBUG_OUTPUT) endif() -get_filename_component(Qt5_PREFIX ${Qt5_DIR}/../../.. REALPATH) +get_filename_component(Qt6_PREFIX ${Qt6_DIR}/../../.. REALPATH) if(APPLE) - # Add includes under Qt5 Prefix in case Qt6 is also installed - include_directories(SYSTEM ${Qt5_PREFIX}/include) - set(CMAKE_MACOSX_RPATH TRUE) - find_program(MACDEPLOYQT_EXE macdeployqt HINTS ${Qt5_PREFIX}/bin ${Qt5_PREFIX}/tools/qt5/bin ENV PATH) + find_program(MACDEPLOYQT_EXE macdeployqt HINTS ${Qt6_PREFIX}/bin ${Qt6_PREFIX}/tools/qt/bin ENV PATH) if(NOT MACDEPLOYQT_EXE) message(FATAL_ERROR "macdeployqt is required to build on macOS") endif() message(STATUS "Using macdeployqt: ${MACDEPLOYQT_EXE}") set(MACDEPLOYQT_EXTRA_BINARIES "") elseif(WIN32) - find_program(WINDEPLOYQT_EXE windeployqt HINTS ${Qt5_PREFIX}/bin ${Qt5_PREFIX}/tools/qt5/bin ENV PATH) + find_program(WINDEPLOYQT_EXE windeployqt HINTS ${Qt6_PREFIX}/bin ${Qt6_PREFIX}/tools/qt/bin ENV PATH) if(NOT WINDEPLOYQT_EXE) message(FATAL_ERROR "windeployqt is required to build on Windows") endif() @@ -469,21 +459,15 @@ elseif(WIN32) endif() # Find Botan -# TODO: Increase minimum to 2.19.1 and drop Argon2 package find_package(Botan REQUIRED) if(BOTAN_VERSION VERSION_GREATER_EQUAL "3.0.0") set(WITH_BOTAN3 TRUE) -elseif(BOTAN_VERSION VERSION_LESS "2.12.0") +elseif(BOTAN_VERSION VERSION_LESS "2.19.1") # Check for minimum Botan version - message(FATAL_ERROR "Botan 2.12.0 or higher is required") + message(FATAL_ERROR "Botan 2.19.1 or higher is required") endif() include_directories(SYSTEM ${BOTAN_INCLUDE_DIR}) -# Find Argon2 -- Botan 2.18 and below does not support threaded Argon2 -find_library(ARGON2_LIBRARIES NAMES argon2) -find_path(ARGON2_INCLUDE_DIR NAMES argon2.h PATH_SUFFIXES local/include) -include_directories(SYSTEM ${ARGON2_INCLUDE_DIR}) - # Find zlib find_package(ZLIB REQUIRED) if(ZLIB_VERSION_STRING VERSION_LESS "1.2.0") @@ -493,6 +477,7 @@ include_directories(SYSTEM ${ZLIB_INCLUDE_DIR}) # Find Minizip find_package(Minizip REQUIRED) +include_directories(SYSTEM ${MINIZIP_INCLUDE_DIR}) # Find PCSC and LibUSB for hardware key support find_package(PCSC REQUIRED) @@ -511,9 +496,14 @@ endif() # Find zxcvbn or use the bundled version find_library(ZXCVBN_LIBRARIES zxcvbn) -if(NOT ZXCVBN_LIBRARIES) +find_path(ZXCVBN_INCLUDE_DIR zxcvbn.h PATH_SUFFIXES zxcvbn) +if(NOT ZXCVBN_LIBRARIES OR NOT ZXCVBN_INCLUDE_DIR) + message(STATUS "Using internal built zxcvbn library") add_subdirectory(src/thirdparty/zxcvbn) set(ZXCVBN_LIBRARIES zxcvbn) +else() + message(STATUS "Using system zxcvbn: ${ZXCVBN_LIBRARIES}") + include_directories(SYSTEM ${ZXCVBN_INCLUDE_DIR}) endif() # Add KeePassXC sources and tests diff --git a/INSTALL.md b/INSTALL.md index 4d2226647..4eb2665a4 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -65,7 +65,7 @@ Note: These steps place the compiled KeePassXC binary inside the `./build/src/` If you installed Qt@5 via Homebrew and CMake fails to find your Qt installation, you can specify it manually by adding the following parameter: -`-DCMAKE_PREFIX_PATH=$(brew --prefix qt@5)/lib/cmake` +`-DCMAKE_PREFIX_PATH=$(brew --prefix qt)/lib/cmake` When building with ASAN support on macOS, you need to use `export ASAN_OPTIONS=detect_leaks=0` before running the tests (LSAN is no supported on macOS). @@ -103,7 +103,7 @@ KeePassXC comes with a variety of build options that can turn on/off features. E ``` Note: Even though you can build the application with all TCP/IP networking code disabled, we still require and link against -Qt5's network library to use local named pipes on all operating systems. +Qt6's network library to use local named pipes on all operating systems. ## Installation diff --git a/share/translations/CMakeLists.txt b/share/translations/CMakeLists.txt index bf1870042..b4a14f4aa 100644 --- a/share/translations/CMakeLists.txt +++ b/share/translations/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2017 KeePassXC Team +# Copyright (C) 2025 KeePassXC Team # Copyright (C) 2014 Felix Geyer # # This program is free software: you can redistribute it and/or modify @@ -20,15 +20,14 @@ list(REMOVE_ITEM TRANSLATION_FILES keepassxc_en.ts) list(REMOVE_ITEM TRANSLATION_FILES ${TRANSLATION_EN_ABS}) message(STATUS "Including translations...\n") -qt5_add_translation(QM_FILES ${TRANSLATION_FILES}) +qt6_add_translation(QM_FILES ${TRANSLATION_FILES}) if(WIN32) - file(GLOB QTBASE_TRANSLATIONS ${Qt5_PREFIX}/share/qt5/translations/qtbase_*.qm) + file(GLOB QTBASE_TRANSLATIONS ${Qt6_PREFIX}/share/qt/translations/qtbase_*.qm) elseif(APPLE OR KEEPASSXC_DIST_APPIMAGE) file(GLOB QTBASE_TRANSLATIONS /usr/share/qt/translations/qtbase_*.qm - /usr/share/qt5/translations/qtbase_*.qm - ${Qt5_PREFIX}/translations/qtbase_*.qm) + ${Qt6_PREFIX}/translations/qtbase_*.qm) endif() set(QM_FILES ${QM_FILES} ${QTBASE_TRANSLATIONS}) diff --git a/share/translations/keepassxc_en.ts b/share/translations/keepassxc_en.ts index a30b175bc..574dc3967 100644 --- a/share/translations/keepassxc_en.ts +++ b/share/translations/keepassxc_en.ts @@ -9308,11 +9308,31 @@ This option is deprecated, use --set-key-file instead. - Format to use when exporting. Available choices are 'xml', 'csv' or 'html'. Defaults to 'xml'. + Passkey - Passkey + Reset Shortcuts + + + + Double click an action to change its shortcut + + + + Filter... + + + + Shortcut Conflict + + + + Shortcut %1 conflicts with '%2'. Overwrite shortcut? + + + + Format to use when exporting. Available choices are 'xml', 'csv' or 'html'. Defaults to 'xml'. @@ -9339,26 +9359,6 @@ This option is deprecated, use --set-key-file instead. Tags - - Reset Shortcuts - - - - Double click an action to change its shortcut - - - - Filter... - - - - Shortcut Conflict - - - - Shortcut %1 conflicts with '%2'. Overwrite shortcut? - - start minimized to the system tray diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1dcfba4d5..1bf2a795e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2024 KeePassXC Team +# Copyright (C) 2026 KeePassXC Team # Copyright (C) 2010 Felix Geyer # # This program is free software: you can redistribute it and/or modify @@ -243,7 +243,7 @@ if(UNIX AND NOT APPLE) list(APPEND gui_SOURCES gui/osutils/nixutils/X11Funcs.cpp) endif() - qt5_add_dbus_adaptor(gui_SOURCES + qt6_add_dbus_adaptor(gui_SOURCES gui/org.keepassxc.KeePassXC.MainWindow.xml gui/MainWindow.h MainWindow) @@ -253,7 +253,7 @@ if(UNIX AND NOT APPLE) PROPERTIES INCLUDE "quickunlock/PolkitDbusTypes.h" ) - qt5_add_dbus_interface(core_SOURCES + qt6_add_dbus_interface(core_SOURCES quickunlock/dbus/org.freedesktop.PolicyKit1.Authority.xml polkit_dbus ) @@ -323,19 +323,21 @@ endif() configure_file(config-keepassx.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-keepassx.h) configure_file(git-info.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/git-info.h) +# SVG Widgets +find_package(Qt6 REQUIRED COMPONENTS SvgWidgets) + # Core Library Definition add_library(keepassxc_core STATIC ${core_SOURCES}) target_compile_definitions(keepassxc_core PRIVATE KPXC_BUILDING_CORE) target_link_libraries(keepassxc_core ${qrcode_LIB} - Qt5::Core - Qt5::Concurrent + Qt6::Core + Qt6::Concurrent ${BOTAN_LIBRARIES} ${PCSC_LIBRARIES} ${ZXCVBN_LIBRARIES} ${ZLIB_LIBRARIES} ${MINIZIP_LIBRARIES} - ${ARGON2_LIBRARIES} ${thirdparty_LIBRARIES}) # GUI Library Definition @@ -343,8 +345,9 @@ add_library(keepassxc_gui STATIC ${gui_SOURCES}) target_compile_definitions(keepassxc_gui PRIVATE KPXC_BUILDING_CORE) target_link_libraries(keepassxc_gui keepassxc_core - Qt5::Network - Qt5::Widgets + Qt6::Network + Qt6::SvgWidgets + Qt6::Widgets ${autotype_LIB} ${browser_LIB} ${fdosecrets_LIB} @@ -353,22 +356,21 @@ target_link_libraries(keepassxc_gui if(APPLE) target_link_libraries(keepassxc_gui "-framework Foundation -framework AppKit -framework Carbon -framework Security -framework LocalAuthentication -framework ScreenCaptureKit") - if(Qt5MacExtras_FOUND) - target_link_libraries(keepassxc_gui Qt5::MacExtras) + if(Qt6MacExtras_FOUND) + target_link_libraries(keepassxc_gui Qt6::MacExtras) endif() endif() if(HAIKU) target_link_libraries(keepassxc_gui network) endif() if(UNIX AND NOT APPLE) - target_link_libraries(keepassxc_core Qt5::DBus ${LIBUSB_LIBRARIES}) + target_link_libraries(keepassxc_core Qt6::DBus ${LIBUSB_LIBRARIES}) if("${CMAKE_SYSTEM}" MATCHES "Linux") target_link_libraries(keepassxc_core ${KEYUTILS_LIBRARIES}) endif() if(WITH_X11) - target_link_libraries(keepassxc_gui Qt5::X11Extras X11) + target_link_libraries(keepassxc_gui X11) endif() - target_include_directories(keepassxc_gui PRIVATE ${Qt5Gui_PRIVATE_INCLUDE_DIRS}) endif() if(WIN32) target_link_libraries(keepassxc_gui Wtsapi32.lib Ws2_32.lib) @@ -448,11 +450,9 @@ install(TARGETS ${PROGNAME} # Windows Installer Definition if(WIN32) - if(${CMAKE_SIZEOF_VOID_P} EQUAL "8") - set(OUTPUT_FILE_POSTFIX "Win64") - else() - set(OUTPUT_FILE_POSTFIX "Win32") - endif() + # Deploy used libraries into build directory for debugging + add_custom_command(TARGET ${PROGNAME} POST_BUILD + COMMAND ${WINDEPLOYQT_EXE} --dir $ $) # We have to copy the license file in the configuration phase. # CMake checks that CPACK_RESOURCE_FILE_LICENSE actually exists and @@ -516,13 +516,6 @@ if(WIN32) COMPONENT Runtime) # Use windeployqt.exe to setup Qt dependencies - if(Qt5Core_VERSION VERSION_LESS "5.14.1") - set(WINDEPLOYQT_MODE "--release") - if(CMAKE_BUILD_TYPE_LOWER STREQUAL "debug") - set(WINDEPLOYQT_MODE "--debug") - endif() - endif() - install(CODE "execute_process(COMMAND ${WINDEPLOYQT_EXE} ${PROGNAME}.exe ${WINDEPLOYQT_MODE} WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX} OUTPUT_QUIET)" COMPONENT Runtime) @@ -549,7 +542,7 @@ if(WIN32) endif() # install CA cert chains - find_file(SSL_CA_BUNDLE ca-bundle.crt PATHS "${Qt5_PREFIX}/ssl/certs") + find_file(SSL_CA_BUNDLE ca-bundle.crt PATHS "${Qt6_PREFIX}/ssl/certs") if(SSL_CA_BUNDLE) install(FILES ${SSL_CA_BUNDLE} DESTINATION "ssl/certs") else() diff --git a/src/autotype/AutoType.cpp b/src/autotype/AutoType.cpp index 7bbd59aff..b6f1428b1 100644 --- a/src/autotype/AutoType.cpp +++ b/src/autotype/AutoType.cpp @@ -238,7 +238,9 @@ QStringList AutoType::windowTitles() void AutoType::raiseWindow() { #if defined(Q_OS_MACOS) - m_plugin->raiseOwnWindow(); + if (m_plugin) { + m_plugin->raiseOwnWindow(); + } #endif } @@ -264,6 +266,11 @@ void AutoType::executeAutoTypeActions(const Entry* entry, WId window, AutoTypeExecutor::Mode mode) { + if (!m_plugin || !m_executor) { + qWarning() << "Auto-Type plugin not available, cannot perform Auto-Type."; + return; + } + QString error; auto actions = parseSequence(sequence, entry, error); diff --git a/src/autotype/AutoType.h b/src/autotype/AutoType.h index 4708a7093..174f95622 100644 --- a/src/autotype/AutoType.h +++ b/src/autotype/AutoType.h @@ -28,9 +28,10 @@ #include "AutoTypeAction.h" #include "AutoTypeMatch.h" +#include "core/Database.h" +#include "core/Entry.h" + class AutoTypePlatformInterface; -class Database; -class Entry; class QPluginLoader; class AutoType : public QObject diff --git a/src/autotype/AutoTypeMatch.h b/src/autotype/AutoTypeMatch.h index 1b8f2c740..97917b3e5 100644 --- a/src/autotype/AutoTypeMatch.h +++ b/src/autotype/AutoTypeMatch.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,6 +18,8 @@ #ifndef KPXC_AUTOTYPEMATCH_H #define KPXC_AUTOTYPEMATCH_H +#include "core/Entry.h" + #include #include diff --git a/src/autotype/AutoTypeMatchView.cpp b/src/autotype/AutoTypeMatchView.cpp index 91f9ce083..0e3c722a2 100644 --- a/src/autotype/AutoTypeMatchView.cpp +++ b/src/autotype/AutoTypeMatchView.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2015 David Wu - * Copyright (C) 2017 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -38,9 +38,9 @@ public: auto index1 = sourceModel()->index(sourceRow, 1, sourceParent); auto index2 = sourceModel()->index(sourceRow, 2, sourceParent); - return sourceModel()->data(index0).toString().contains(filterRegExp()) - || sourceModel()->data(index1).toString().contains(filterRegExp()) - || sourceModel()->data(index2).toString().contains(filterRegExp()); + return sourceModel()->data(index0).toString().contains(filterRegularExpression()) + || sourceModel()->data(index1).toString().contains(filterRegularExpression()) + || sourceModel()->data(index2).toString().contains(filterRegularExpression()); } }; diff --git a/src/autotype/AutoTypeSelectDialog.cpp b/src/autotype/AutoTypeSelectDialog.cpp index 3810418b5..631c73af7 100644 --- a/src/autotype/AutoTypeSelectDialog.cpp +++ b/src/autotype/AutoTypeSelectDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2012 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -309,7 +309,7 @@ void AutoTypeSelectDialog::buildActionMenu() m_actionMenu->addAction(copyTotpAction); m_actionMenu->addAction(copyUrlAction); - typeUsernameAction->setShortcut(Qt::CTRL + Qt::Key_1); + typeUsernameAction->setShortcut(Qt::CTRL | Qt::Key_1); typeUsernameAction->setProperty(MENU_FIELD_PROP_NAME, MENU_FIELD::USERNAME); connect(typeUsernameAction, &QAction::triggered, this, [&] { auto match = m_ui->view->currentMatch(); @@ -317,7 +317,7 @@ void AutoTypeSelectDialog::buildActionMenu() submitAutoTypeMatch(match); }); - typePasswordAction->setShortcut(Qt::CTRL + Qt::Key_2); + typePasswordAction->setShortcut(Qt::CTRL | Qt::Key_2); typePasswordAction->setProperty(MENU_FIELD_PROP_NAME, MENU_FIELD::PASSWORD); connect(typePasswordAction, &QAction::triggered, this, [&] { auto match = m_ui->view->currentMatch(); @@ -325,7 +325,7 @@ void AutoTypeSelectDialog::buildActionMenu() submitAutoTypeMatch(match); }); - typeTotpAction->setShortcut(Qt::CTRL + Qt::Key_3); + typeTotpAction->setShortcut(Qt::CTRL | Qt::Key_3); typeTotpAction->setProperty(MENU_FIELD_PROP_NAME, MENU_FIELD::TOTP); connect(typeTotpAction, &QAction::triggered, this, [&] { auto match = m_ui->view->currentMatch(); @@ -333,7 +333,7 @@ void AutoTypeSelectDialog::buildActionMenu() submitAutoTypeMatch(match); }); - typeUrlAction->setShortcut(Qt::CTRL + Qt::Key_4); + typeUrlAction->setShortcut(Qt::CTRL | Qt::Key_4); typeUrlAction->setProperty(MENU_FIELD_PROP_NAME, MENU_FIELD::URL); connect(typeUrlAction, &QAction::triggered, this, [&] { auto match = m_ui->view->currentMatch(); @@ -344,14 +344,14 @@ void AutoTypeSelectDialog::buildActionMenu() #if defined(Q_OS_WIN) || defined(Q_OS_MAC) auto typeVirtualAction = new QAction(icons()->icon("auto-type"), tr("Use Virtual Keyboard"), nullptr); m_actionMenu->insertAction(copyUsernameAction, typeVirtualAction); - typeVirtualAction->setShortcut(Qt::CTRL + Qt::Key_5); + typeVirtualAction->setShortcut(Qt::CTRL | Qt::Key_5); connect(typeVirtualAction, &QAction::triggered, this, [&] { m_virtualMode = true; activateCurrentMatch(); }); #endif - copyUsernameAction->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_1); + copyUsernameAction->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_1); copyUsernameAction->setProperty(MENU_FIELD_PROP_NAME, MENU_FIELD::USERNAME); connect(copyUsernameAction, &QAction::triggered, this, [&] { auto entry = m_ui->view->currentMatch().first; @@ -361,7 +361,7 @@ void AutoTypeSelectDialog::buildActionMenu() } }); - copyPasswordAction->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_2); + copyPasswordAction->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_2); copyPasswordAction->setProperty(MENU_FIELD_PROP_NAME, MENU_FIELD::PASSWORD); connect(copyPasswordAction, &QAction::triggered, this, [&] { auto entry = m_ui->view->currentMatch().first; @@ -371,7 +371,7 @@ void AutoTypeSelectDialog::buildActionMenu() } }); - copyTotpAction->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_3); + copyTotpAction->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_3); copyTotpAction->setProperty(MENU_FIELD_PROP_NAME, MENU_FIELD::TOTP); connect(copyTotpAction, &QAction::triggered, this, [&] { auto entry = m_ui->view->currentMatch().first; @@ -381,7 +381,7 @@ void AutoTypeSelectDialog::buildActionMenu() } }); - copyUrlAction->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_4); + copyUrlAction->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_4); copyUrlAction->setProperty(MENU_FIELD_PROP_NAME, MENU_FIELD::URL); connect(copyUrlAction, &QAction::triggered, this, [&] { auto entry = m_ui->view->currentMatch().first; @@ -390,20 +390,6 @@ void AutoTypeSelectDialog::buildActionMenu() reject(); } }); - - // Qt 5.10 introduced a new "feature" to hide shortcuts in context menus - // Unfortunately, Qt::AA_DontShowShortcutsInContextMenus is broken, have to manually enable them - typeUsernameAction->setShortcutVisibleInContextMenu(true); - typePasswordAction->setShortcutVisibleInContextMenu(true); - typeTotpAction->setShortcutVisibleInContextMenu(true); - typeUrlAction->setShortcutVisibleInContextMenu(true); -#if defined(Q_OS_WIN) || defined(Q_OS_MAC) - typeVirtualAction->setShortcutVisibleInContextMenu(true); -#endif - copyUsernameAction->setShortcutVisibleInContextMenu(true); - copyPasswordAction->setShortcutVisibleInContextMenu(true); - copyTotpAction->setShortcutVisibleInContextMenu(true); - copyUrlAction->setShortcutVisibleInContextMenu(true); } void AutoTypeSelectDialog::showEvent(QShowEvent* event) diff --git a/src/autotype/CMakeLists.txt b/src/autotype/CMakeLists.txt index 6ab676e9a..c00bbde34 100644 --- a/src/autotype/CMakeLists.txt +++ b/src/autotype/CMakeLists.txt @@ -9,17 +9,16 @@ set(autotype_SOURCES WindowSelectComboBox.cpp) add_library(autotype STATIC ${autotype_SOURCES}) -target_link_libraries(autotype Qt5::Core Qt5::Widgets) +target_link_libraries(autotype Qt6::Core Qt6::Widgets) # Platform specific auto-type implementations if(UNIX AND NOT APPLE AND NOT HAIKU) if(WITH_X11) find_package(X11 REQUIRED COMPONENTS Xi XTest) - find_package(Qt5X11Extras REQUIRED) if(PRINT_SUMMARY) add_feature_info(libXi X11_Xi_FOUND "The X11 Xi Protocol library is required for auto-type") add_feature_info(libXtst X11_XTest_FOUND "The X11 XTEST Protocol library is required for auto-type") - add_feature_info(Qt5X11Extras Qt5X11Extras_FOUND "The Qt5X11Extras library is required for auto-type") + add_feature_info(Qt6X11Extras Qt6X11Extras_FOUND "The Qt6X11Extras library is required for auto-type") endif() add_subdirectory(xcb) diff --git a/src/autotype/mac/AutoTypeMac.h b/src/autotype/mac/AutoTypeMac.h index 54805a4e9..36f09747b 100644 --- a/src/autotype/mac/AutoTypeMac.h +++ b/src/autotype/mac/AutoTypeMac.h @@ -1,6 +1,6 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2016 Lennart Glauer - * Copyright (C) 2017 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef KEEPASSX_AUTOTYPEMAC_H -#define KEEPASSX_AUTOTYPEMAC_H +#ifndef KEEPASSXC_AUTOTYPEMAC_H +#define KEEPASSXC_AUTOTYPEMAC_H #include #include @@ -45,7 +45,7 @@ public: bool raiseOwnWindow() override; void sendChar(const QChar& ch, bool isKeyDown); - void sendKey(Qt::Key key, bool isKeyDown, Qt::KeyboardModifiers modifiers = 0); + void sendKey(Qt::Key key, bool isKeyDown, Qt::KeyboardModifiers modifiers = Qt::NoModifier); private: static int windowLayer(CFDictionaryRef window); @@ -65,4 +65,4 @@ private: AutoTypePlatformMac* const m_platform; }; -#endif // KEEPASSX_AUTOTYPEMAC_H +#endif // KEEPASSXC_AUTOTYPEMAC_H diff --git a/src/autotype/mac/CMakeLists.txt b/src/autotype/mac/CMakeLists.txt index ae1f5187f..656502271 100644 --- a/src/autotype/mac/CMakeLists.txt +++ b/src/autotype/mac/CMakeLists.txt @@ -2,7 +2,7 @@ set(autotype_mac_SOURCES AutoTypeMac.cpp) add_library(keepassxc-autotype-cocoa MODULE ${autotype_mac_SOURCES}) set_target_properties(keepassxc-autotype-cocoa PROPERTIES LINK_FLAGS "-framework Foundation -framework AppKit -framework Carbon -framework ScreenCaptureKit") -target_link_libraries(keepassxc-autotype-cocoa ${PROGNAME} Qt5::Core Qt5::Widgets) +target_link_libraries(keepassxc-autotype-cocoa ${PROGNAME} Qt6::Core Qt6::Widgets) install(TARGETS keepassxc-autotype-cocoa LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR} COMPONENT Runtime) diff --git a/src/autotype/test/CMakeLists.txt b/src/autotype/test/CMakeLists.txt index e27f2b1d9..36e6b9e6d 100644 --- a/src/autotype/test/CMakeLists.txt +++ b/src/autotype/test/CMakeLists.txt @@ -1,4 +1,4 @@ set(autotype_test_SOURCES AutoTypeTest.cpp) add_library(keepassxc-autotype-test MODULE ${autotype_test_SOURCES}) -target_link_libraries(keepassxc-autotype-test keepassxc_gui ${autotype_LIB} Qt5::Core Qt5::Widgets) +target_link_libraries(keepassxc-autotype-test keepassxc_gui ${autotype_LIB} Qt6::Core Qt6::Widgets) diff --git a/src/autotype/windows/AutoTypeWindows.h b/src/autotype/windows/AutoTypeWindows.h index 29e98ab35..80041a9f1 100644 --- a/src/autotype/windows/AutoTypeWindows.h +++ b/src/autotype/windows/AutoTypeWindows.h @@ -1,6 +1,6 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2016 Lennart Glauer - * Copyright (C) 2017 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef KEEPASSX_AUTOTYPEWINDOWS_H -#define KEEPASSX_AUTOTYPEWINDOWS_H +#ifndef KEEPASSXC_AUTOTYPEWINDOWS_H +#define KEEPASSXC_AUTOTYPEWINDOWS_H #include @@ -67,4 +67,4 @@ private: AutoTypePlatformWin* const m_platform; }; -#endif // KEEPASSX_AUTOTYPEWINDOWS_H +#endif // KEEPASSXC_AUTOTYPEWINDOWS_H diff --git a/src/autotype/windows/CMakeLists.txt b/src/autotype/windows/CMakeLists.txt index 5b9cbecff..6ed316e2d 100644 --- a/src/autotype/windows/CMakeLists.txt +++ b/src/autotype/windows/CMakeLists.txt @@ -1,7 +1,7 @@ set(autotype_win_SOURCES AutoTypeWindows.cpp) add_library(keepassxc-autotype-windows MODULE ${autotype_win_SOURCES}) -target_link_libraries(keepassxc-autotype-windows keepassxc_gui ${autotype_LIB} Qt5::Core Qt5::Widgets) +target_link_libraries(keepassxc-autotype-windows keepassxc_gui ${autotype_LIB} Qt6::Core Qt6::Widgets) install(TARGETS keepassxc-autotype-windows BUNDLE DESTINATION . COMPONENT Runtime LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR} COMPONENT Runtime) diff --git a/src/autotype/xcb/AutoTypeXCB.cpp b/src/autotype/xcb/AutoTypeXCB.cpp index af9c463ee..6643fc2fb 100644 --- a/src/autotype/xcb/AutoTypeXCB.cpp +++ b/src/autotype/xcb/AutoTypeXCB.cpp @@ -1,7 +1,7 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2012 Felix Geyer * Copyright (C) 2000-2008 Tom Sato - * Copyright (C) 2017 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,8 +21,9 @@ #include "core/Tools.h" #include "gui/osutils/nixutils/X11Funcs.h" -#include +#include #include +#include #include #include @@ -38,8 +39,15 @@ static const QPair deadMap[] = { AutoTypePlatformX11::AutoTypePlatformX11() { // Qt handles XCB slightly differently so we open our own connection - m_dpy = XOpenDisplay(XDisplayString(QX11Info::display())); - m_rootWindow = QX11Info::appRootWindow(); + if (auto* native = qGuiApp->nativeInterface()) { + m_dpy = XOpenDisplay(XDisplayString(native->display())); + m_rootWindow = DefaultRootWindow(native->display()); + } else { + qWarning("Auto-Type: Unable to connect to X server, Auto-Type is disabled."); + return; + } + + Q_ASSERT(m_dpy); m_atomWmState = XInternAtom(m_dpy, "WM_STATE", True); m_atomWmName = XInternAtom(m_dpy, "WM_NAME", True); @@ -49,6 +57,7 @@ AutoTypePlatformX11::AutoTypePlatformX11() m_atomNetActiveWindow = XInternAtom(m_dpy, "_NET_ACTIVE_WINDOW", True); m_atomTransientFor = XInternAtom(m_dpy, "WM_TRANSIENT_FOR", True); m_atomWindow = XInternAtom(m_dpy, "WINDOW", True); + m_appUserTime = XInternAtom(m_dpy, "_NET_WM_USER_TIME", False); m_classBlacklist << "desktop_window" << "gnome-panel"; // Gnome m_classBlacklist << "kdesktop" << "kicker"; // KDE 3 @@ -63,6 +72,10 @@ AutoTypePlatformX11::AutoTypePlatformX11() bool AutoTypePlatformX11::isAvailable() { + if (!m_loaded) { + return false; + } + int ignore; if (!XQueryExtension(m_dpy, "XInputExtension", &ignore, &ignore, &ignore)) { @@ -85,8 +98,10 @@ void AutoTypePlatformX11::unload() m_xkb = nullptr; } - XCloseDisplay(m_dpy); - m_dpy = nullptr; + if (m_dpy) { + XCloseDisplay(m_dpy); + m_dpy = nullptr; + } m_loaded = false; } @@ -289,6 +304,31 @@ bool AutoTypePlatformX11::isTopLevelWindow(Window window) return result; } +unsigned long AutoTypePlatformX11::appUserTime(Window window) +{ + auto appUserTime = 0; + + Atom type = None; + int format; + unsigned long nitems; + unsigned long after; + unsigned char* data = nullptr; + + if (XGetWindowProperty( + m_dpy, window, m_appUserTime, 0, 1, False, XA_CARDINAL, &type, &format, &nitems, &after, &data) + == Success) { + if (data && nitems == 1) { + appUserTime = *reinterpret_cast(data); + } + + if (data) { + XFree(data); + } + } + + return appUserTime; +} + /* * Update the keyboard and modifier mapping. * We need the KeyboardMapping for AddKeysym. @@ -625,7 +665,7 @@ bool AutoTypePlatformX11::raiseWindow(WId window) event.xclient.message_type = m_atomNetActiveWindow; event.xclient.format = 32; event.xclient.data.l[0] = 1; // FromApplication - event.xclient.data.l[1] = QX11Info::appUserTime(); + event.xclient.data.l[1] = appUserTime(window); QWidget* activeWindow = QApplication::activeWindow(); if (activeWindow) { event.xclient.data.l[2] = activeWindow->internalWinId(); diff --git a/src/autotype/xcb/AutoTypeXCB.h b/src/autotype/xcb/AutoTypeXCB.h index 7b743a471..2c7027c33 100644 --- a/src/autotype/xcb/AutoTypeXCB.h +++ b/src/autotype/xcb/AutoTypeXCB.h @@ -1,7 +1,7 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2012 Felix Geyer * Copyright (C) 2000-2008 Tom Sato - * Copyright (C) 2017 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,8 +17,8 @@ * along with this program. If not, see . */ -#ifndef KEEPASSX_AUTOTYPEXCB_H -#define KEEPASSX_AUTOTYPEXCB_H +#ifndef KEEPASSXC_AUTOTYPEXCB_H +#define KEEPASSXC_AUTOTYPEXCB_H #include #include @@ -48,7 +48,7 @@ public: AutoTypeExecutor* createExecutor() override; void updateKeymap(); - AutoTypeAction::Result sendKey(KeySym keysym, unsigned int modifiers = 0); + AutoTypeAction::Result sendKey(KeySym keysym, unsigned int modifiers = Qt::NoModifier); private: QString windowTitle(Window window, bool useBlacklist); @@ -56,6 +56,7 @@ private: QString windowClassName(Window window); QList widgetsToX11Windows(const QWidgetList& widgetList); bool isTopLevelWindow(Window window); + unsigned long appUserTime(Window window); XkbDescPtr getKeyboard(); bool RemapKeycode(KeySym keysym); @@ -65,7 +66,7 @@ private: static int MyErrorHandler(Display* my_dpy, XErrorEvent* event); - Display* m_dpy; + Display* m_dpy = nullptr; Window m_rootWindow; Atom m_atomWmState; Atom m_atomWmName; @@ -75,6 +76,7 @@ private: Atom m_atomNetActiveWindow; Atom m_atomTransientFor; Atom m_atomWindow; + Atom m_appUserTime; QSet m_classBlacklist; typedef struct @@ -89,7 +91,7 @@ private: QList m_keymap; KeyCode m_modifier_keycode[N_MOD_INDICES]; KeyCode m_remapKeycode; - bool m_loaded; + bool m_loaded = false; }; class AutoTypeExecutorX11 : public AutoTypeExecutor @@ -105,4 +107,4 @@ private: AutoTypePlatformX11* const m_platform; }; -#endif // KEEPASSX_AUTOTYPEXCB_H +#endif // KEEPASSXC_AUTOTYPEXCB_H diff --git a/src/autotype/xcb/CMakeLists.txt b/src/autotype/xcb/CMakeLists.txt index f14017f63..b4d3fdaf0 100644 --- a/src/autotype/xcb/CMakeLists.txt +++ b/src/autotype/xcb/CMakeLists.txt @@ -3,7 +3,7 @@ include_directories(SYSTEM ${X11_X11_INCLUDE_PATH}) set(autotype_XCB_SOURCES AutoTypeXCB.cpp) add_library(keepassxc-autotype-xcb MODULE ${autotype_XCB_SOURCES}) -target_link_libraries(keepassxc-autotype-xcb keepassxc_gui Qt5::Core Qt5::Widgets Qt5::X11Extras ${X11_X11_LIB} ${X11_Xi_LIB} ${X11_XTest_LIB}) +target_link_libraries(keepassxc-autotype-xcb keepassxc_gui Qt6::Core Qt6::Widgets ${X11_X11_LIB} ${X11_Xi_LIB} ${X11_XTest_LIB}) install(TARGETS keepassxc-autotype-xcb BUNDLE DESTINATION . COMPONENT Runtime LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR} COMPONENT Runtime) diff --git a/src/browser/BrowserService.cpp b/src/browser/BrowserService.cpp index 607965813..3540c9381 100644 --- a/src/browser/BrowserService.cpp +++ b/src/browser/BrowserService.cpp @@ -1451,7 +1451,7 @@ bool BrowserService::isPasskeyCredentialExcluded(const QJsonArray& excludeCreden { QStringList allIds; for (const auto& cred : excludeCredentials) { - allIds << cred["id"].toString(); + allIds << cred.toObject().value("id").toString(); } const auto passkeyEntries = getPasskeyEntries(rpId, keyList); @@ -1771,7 +1771,7 @@ void BrowserService::processClientMessage(QLocalSocket* socket, const QJsonObjec m_browserClients.insert(clientID, QSharedPointer::create()); } - auto& action = m_browserClients.value(clientID); + const auto& action = m_browserClients.value(clientID); auto response = action->processClientMessage(socket, message); m_browserHost->sendClientMessage(socket, response); } diff --git a/src/browser/CMakeLists.txt b/src/browser/CMakeLists.txt index 91ed7edd5..7bfd2e047 100644 --- a/src/browser/CMakeLists.txt +++ b/src/browser/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2024 KeePassXC Team +# Copyright (C) 2025 KeePassXC Team # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -37,5 +37,5 @@ if(KPXC_FEATURE_BROWSER) PasskeyUtils.cpp) add_library(browser STATIC ${browser_SOURCES}) - target_link_libraries(browser Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Network ${BOTAN_LIBRARIES}) + target_link_libraries(browser Qt6::Core Qt6::Concurrent Qt6::Widgets Qt6::Network ${BOTAN_LIBRARIES}) endif() diff --git a/src/browser/NativeMessageInstaller.cpp b/src/browser/NativeMessageInstaller.cpp index bf0ad5aba..21a6626b4 100644 --- a/src/browser/NativeMessageInstaller.cpp +++ b/src/browser/NativeMessageInstaller.cpp @@ -212,7 +212,7 @@ QString NativeMessageInstaller::getNativeMessagePath(SupportedBrowsers browser) if (Config::isPortable()) { basePath = Config::portableConfigDir(); } else { - basePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation); + basePath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation); } return QStringLiteral("%1/%2_%3.json").arg(basePath, HOST_NAME, getBrowserName(browser)); #elif defined(KEEPASSXC_DIST_FLATPAK) diff --git a/src/browser/PasskeyUtils.cpp b/src/browser/PasskeyUtils.cpp index b28c94dbb..52063232b 100644 --- a/src/browser/PasskeyUtils.cpp +++ b/src/browser/PasskeyUtils.cpp @@ -158,18 +158,19 @@ QJsonArray PasskeyUtils::parseCredentialTypes(const QJsonArray& credentialTypes) })); } else { for (const auto current : credentialTypes) { - if (current["type"] != BrowserPasskeys::PUBLIC_KEY || current["alg"].isUndefined()) { + const auto currentObject = current.toObject(); + if (currentObject["type"] != BrowserPasskeys::PUBLIC_KEY || currentObject["alg"].isUndefined()) { continue; } - const auto currentAlg = current["alg"].toInt(); + const auto currentAlg = currentObject["alg"].toInt(); if (currentAlg != WebAuthnAlgorithms::ES256 && currentAlg != WebAuthnAlgorithms::RS256 && currentAlg != WebAuthnAlgorithms::EDDSA) { continue; } credTypesAndPubKeyAlgs.push_back(QJsonObject({ - {"type", current["type"]}, + {"type", currentObject["type"]}, {"alg", currentAlg}, })); } diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index ecd5da284..5f5afaf07 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2019 KeePassXC Team +# Copyright (C) 2025 KeePassXC Team # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -45,7 +45,7 @@ set(cli_SOURCES Show.cpp) add_library(cli STATIC ${cli_SOURCES}) -target_link_libraries(cli ${ZXCVBN_LIBRARIES} Qt5::Core) +target_link_libraries(cli ${ZXCVBN_LIBRARIES} Qt6::Core) find_package(Readline) @@ -67,10 +67,6 @@ install(TARGETS keepassxc-cli if(WIN32) target_sources(keepassxc-cli PRIVATE keepassxc-cli.exe.manifest) - -# install(CODE "include(BundleUtilities) -# fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/keepassxc-cli.exe\" \"\" \"\")" -# COMPONENT Runtime) endif() if(APPLE AND WITH_APP_BUNDLE) diff --git a/src/cli/TextStream.cpp b/src/cli/TextStream.cpp index e2e6e15f4..c9478111c 100644 --- a/src/cli/TextStream.cpp +++ b/src/cli/TextStream.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ #include "TextStream.h" #include -#include +#include #ifdef Q_OS_WIN #include #endif @@ -87,13 +87,23 @@ void TextStream::detectCodec() // Only override codec if LANG is set, otherwise Qt will assume // US-ASCII, which is almost always wrong and results in // Unicode passwords being displayed as question marks. - codecName = QTextCodec::codecForLocale()->name(); + codecName = "System"; } #endif codecName = env.value("ENCODING_OVERRIDE", codecName); - auto* codec = QTextCodec::codecForName(codecName.toLatin1()); - if (codec) { - setCodec(codec); + + // Default to UTF-8, allow override via environment variable if set to valid codec name + // Qt doesn't recognize Windows code pages, so explicitly set codec to System for them + QStringConverter::Encoding codec = QStringConverter::Utf8; + auto encoding = QStringConverter::encodingForName(codecName.toLocal8Bit()); + if (encoding) { + codec = *encoding; + } else if (codecName.toLatin1().compare(QByteArray("Windows-850"), Qt::CaseInsensitive) == 0 + || codecName.toLatin1().compare(QByteArray("Windows-1252"), Qt::CaseInsensitive) == 0 + || codecName.toLatin1().compare(QByteArray("System"), Qt::CaseInsensitive) == 0) { + codec = QStringConverter::System; } + + setEncoding(codec); } diff --git a/src/cli/TextStream.h b/src/cli/TextStream.h index 0091ec108..1ac37acbd 100644 --- a/src/cli/TextStream.h +++ b/src/cli/TextStream.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,6 +18,7 @@ #ifndef KEEPASSXC_TEXTSTREAM_H #define KEEPASSXC_TEXTSTREAM_H +#include #include /** diff --git a/src/cli/Utils.cpp b/src/cli/Utils.cpp index 059c29260..4029b7c77 100644 --- a/src/cli/Utils.cpp +++ b/src/cli/Utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,24 +49,28 @@ namespace Utils void setDefaultTextStreams() { auto fd = new QFile(); - fd->open(stdout, QIODevice::WriteOnly); - STDOUT.setDevice(fd); + if (fd->open(stdout, QIODevice::WriteOnly)) { + STDOUT.setDevice(fd); + } fd = new QFile(); - fd->open(stderr, QIODevice::WriteOnly); - STDERR.setDevice(fd); + if (fd->open(stderr, QIODevice::WriteOnly)) { + STDERR.setDevice(fd); + } fd = new QFile(); - fd->open(stdin, QIODevice::ReadOnly); - STDIN.setDevice(fd); + if (fd->open(stdin, QIODevice::ReadOnly)) { + STDIN.setDevice(fd); + } fd = new QFile(); #ifdef Q_OS_WIN - fd->open(fopen("nul", "w"), QIODevice::WriteOnly); + if (fd->open(fopen("nul", "w"), QIODevice::WriteOnly)) { #else - fd->open(fopen("/dev/null", "w"), QIODevice::WriteOnly); + if (fd->open(fopen("/dev/null", "w"), QIODevice::WriteOnly)) { #endif - DEVNULL.setDevice(fd); + DEVNULL.setDevice(fd); + } #ifdef Q_OS_WIN origCodePage = GetConsoleCP(); diff --git a/src/cli/Utils.h b/src/cli/Utils.h index 6a272fc62..6977683a0 100644 --- a/src/cli/Utils.h +++ b/src/cli/Utils.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,6 +18,9 @@ #ifndef KEEPASSXC_UTILS_H #define KEEPASSXC_UTILS_H +#include +#include +#include #include class CompositeKey; diff --git a/src/cli/keepassxc-cli.cpp b/src/cli/keepassxc-cli.cpp index 2c4bd1aa2..b9c3b332c 100644 --- a/src/cli/keepassxc-cli.cpp +++ b/src/cli/keepassxc-cli.cpp @@ -210,15 +210,13 @@ int main(int argc, char** argv) parser.addOption(debugInfoOption); parser.addHelpOption(); parser.addVersionOption(); - // TODO : use the setOptionsAfterPositionalArgumentsMode (Qt 5.6) function - // when available. Until then, options passed to sub-commands won't be - // recognized by this parser. + // TODO : use the setOptionsAfterPositionalArgumentsMode function. + // Until then, options passed to sub-commands won't be recognized by this parser. parser.parse(arguments); if (parser.positionalArguments().empty()) { if (parser.isSet("version")) { - // Switch to parser.showVersion() when available (QT 5.4). - out << KEEPASSXC_VERSION << Qt::endl; + parser.showVersion(); return EXIT_SUCCESS; } diff --git a/src/core/Base32.cpp b/src/core/Base32.cpp index d0a148eec..7907f9931 100644 --- a/src/core/Base32.cpp +++ b/src/core/Base32.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,10 +43,10 @@ constexpr quint8 ASCII_a = static_cast('a'); constexpr quint8 ASCII_z = static_cast('z'); constexpr quint8 ASCII_EQ = static_cast('='); -QVariant Base32::decode(const QByteArray& encodedData) +QByteArray Base32::decode(const QByteArray& encodedData) { if (encodedData.size() <= 0) { - return QVariant::fromValue(QByteArray("")); + return {}; } if (encodedData.size() % 8 != 0) { @@ -139,7 +139,7 @@ QVariant Base32::decode(const QByteArray& encodedData) Q_ASSERT(encodedData.size() == i); Q_ASSERT(nBytes == o); - return QVariant::fromValue(data); + return data; } QByteArray Base32::encode(const QByteArray& data) diff --git a/src/core/Base32.h b/src/core/Base32.h index 07b16a0cc..75ab28e2f 100644 --- a/src/core/Base32.h +++ b/src/core/Base32.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,7 +31,7 @@ class Base32 { public: Base32() = default; - Q_REQUIRED_RESULT static QVariant decode(const QByteArray&); + Q_REQUIRED_RESULT static QByteArray decode(const QByteArray&); Q_REQUIRED_RESULT static QByteArray encode(const QByteArray&); Q_REQUIRED_RESULT static QByteArray addPadding(const QByteArray&); Q_REQUIRED_RESULT static QByteArray removePadding(const QByteArray&); diff --git a/src/core/Clock.cpp b/src/core/Clock.cpp index f501daee7..efca447ad 100644 --- a/src/core/Clock.cpp +++ b/src/core/Clock.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,8 +32,7 @@ QDateTime Clock::currentDateTime() uint Clock::currentSecondsSinceEpoch() { - // TODO: change to toSecsSinceEpoch() when min Qt >= 5.8 - return instance().currentDateTimeImpl().toTime_t(); + return instance().currentDateTimeImpl().toSecsSinceEpoch(); } qint64 Clock::currentMilliSecondsSinceEpoch() diff --git a/src/core/Database.cpp b/src/core/Database.cpp index e4fdae75b..5f5760141 100644 --- a/src/core/Database.cpp +++ b/src/core/Database.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2010 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -338,7 +338,7 @@ bool Database::saveAs(const QString& filePath, SaveAction action, const QString& #ifdef Q_OS_WIN if (isHidden) { - SetFileAttributes(realFilePath.toStdString().c_str(), FILE_ATTRIBUTE_HIDDEN); + SetFileAttributes(realFilePath.toStdWString().c_str(), FILE_ATTRIBUTE_HIDDEN); } #endif m_ignoreFileChangesUntilSaved = false; @@ -522,7 +522,9 @@ bool Database::import(const QString& xmlExportPath, QString* error) { KdbxXmlReader reader(KeePass2::FILE_VERSION_4); QFile file(xmlExportPath); - file.open(QIODevice::ReadOnly); + if (!file.open(QIODevice::ReadOnly)) { + return false; + } reader.readDatabase(&file, this); diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index 235bcc6f7..92404ab3d 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2010 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -30,6 +30,7 @@ #include #include #include +#include #include const int Entry::DefaultIconNumber = 0; @@ -1152,11 +1153,11 @@ QString Entry::resolveMultiplePlaceholdersRecursive(const QString& str, int maxD int capEnd = 0; while (matches.hasNext()) { const auto match = matches.next(); - result += str.midRef(capEnd, match.capturedStart() - capEnd); + result += QStringView{str}.mid(capEnd, match.capturedStart() - capEnd); result += resolvePlaceholderRecursive(match.captured(), maxDepth); capEnd = match.capturedEnd(); } - result += str.rightRef(str.length() - capEnd); + result += QStringView{str}.right(str.length() - capEnd); return result; } diff --git a/src/core/EntryAttachments.cpp b/src/core/EntryAttachments.cpp index 110d1e52b..0326dd62f 100644 --- a/src/core/EntryAttachments.cpp +++ b/src/core/EntryAttachments.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Felix Geyer + * Copyright (C) 2025 Felix Geyer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,7 +40,7 @@ EntryAttachments::~EntryAttachments() clear(); } -QList EntryAttachments::keys() const +QStringList EntryAttachments::keys() const { return m_attachments.keys(); } diff --git a/src/core/EntryAttachments.h b/src/core/EntryAttachments.h index c07c9cbf7..10e0addf5 100644 --- a/src/core/EntryAttachments.h +++ b/src/core/EntryAttachments.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Felix Geyer + * Copyright (C) 2025 Felix Geyer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,8 +25,7 @@ #include #include #include - -class QStringList; +#include class EntryAttachments : public ModifiableObject { @@ -35,7 +34,7 @@ class EntryAttachments : public ModifiableObject public: explicit EntryAttachments(QObject* parent = nullptr); ~EntryAttachments() override; - QList keys() const; + QStringList keys() const; bool hasKey(const QString& key) const; QSet values() const; QByteArray value(const QString& key) const; diff --git a/src/core/Global.h b/src/core/Global.h index edd6d88a0..521de90bf 100644 --- a/src/core/Global.h +++ b/src/core/Global.h @@ -1,4 +1,5 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2012 Felix Geyer * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) * Copyright (C) 2012 Intel Corporation @@ -43,23 +44,6 @@ #define FILE_CASE_SENSITIVE Qt::CaseSensitive #endif -#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) -// "Backport" a few things to the 'Qt' namespace as required for older Qt -// versions. -namespace Qt -{ - const QString::SplitBehavior SkipEmptyParts = QString::SkipEmptyParts; - inline QTextStream& endl(QTextStream& s) - { - return ::endl(s); - } - inline QTextStream& flush(QTextStream& s) - { - return ::flush(s); - } -} // namespace Qt -#endif - static const auto TRUE_STR = QStringLiteral("true"); static const auto FALSE_STR = QStringLiteral("false"); diff --git a/src/core/Group.cpp b/src/core/Group.cpp index 1ad989288..4b7441354 100644 --- a/src/core/Group.cpp +++ b/src/core/Group.cpp @@ -870,7 +870,7 @@ QList Group::usernamesRecursive(int topN) const // Take first topN usernames if set QList usernames; - int actualUsernames = topN < 0 ? sortedUsernames.size() : std::min(topN, sortedUsernames.size()); + int actualUsernames = topN < 0 ? sortedUsernames.size() : qMin(topN, sortedUsernames.size()); for (int i = 0; i < actualUsernames; i++) { usernames.append(sortedUsernames[i].first); } diff --git a/src/core/Merger.cpp b/src/core/Merger.cpp index f4828f8e6..1f762120c 100644 --- a/src/core/Merger.cpp +++ b/src/core/Merger.cpp @@ -662,7 +662,7 @@ Merger::ChangeList Merger::mergeDeletions(const MergeContext& context) while (!groups.isEmpty()) { auto* group = groups.takeFirst(); - if (!(group->children().toSet() & groups.toSet()).isEmpty()) { + if (Tools::asSet(group->children()).intersects(Tools::asSet(groups))) { // we need to finish all children before we are able to determine if the group can be removed groups << group; continue; diff --git a/src/core/Metadata.cpp b/src/core/Metadata.cpp index 8e714e0f2..81a70b6b0 100644 --- a/src/core/Metadata.cpp +++ b/src/core/Metadata.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2010 Felix Geyer - * Copyright (C) 2021 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,10 +19,8 @@ #include "Metadata.h" #include "core/Clock.h" -#include "core/Entry.h" #include "core/Group.h" -#include #include #include diff --git a/src/core/PassphraseGenerator.cpp b/src/core/PassphraseGenerator.cpp index 07e7a31bf..6a4c5a181 100644 --- a/src/core/PassphraseGenerator.cpp +++ b/src/core/PassphraseGenerator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,6 +18,7 @@ #include "PassphraseGenerator.h" #include +#include #include #include #include @@ -72,7 +73,6 @@ void PassphraseGenerator::setWordList(const QString& path) } QTextStream in(&file); - in.setCodec("UTF-8"); QString line = in.readLine(); bool isSigned = line.startsWith("-----BEGIN PGP SIGNED MESSAGE-----"); if (isSigned) { @@ -80,7 +80,7 @@ void PassphraseGenerator::setWordList(const QString& path) line = in.readLine(); } } - QRegExp rx("^[0-9]+(-[0-9]+)*\\s+([^\\s]+)$"); + QRegularExpression rx("^[0-9]+(-[0-9]+)*\\s+([^\\s]+)$"); while (!line.isNull()) { if (isSigned && line.startsWith("-----BEGIN PGP SIGNATURE-----")) { break; @@ -97,7 +97,7 @@ void PassphraseGenerator::setWordList(const QString& path) line = in.readLine(); } - m_wordlist = wordset.toList(); + m_wordlist = wordset.values(); if (!isWordListValid()) { qWarning("Wordlist is less than minimum acceptable size: %s", qPrintable(path)); diff --git a/src/core/PasswordGenerator.cpp b/src/core/PasswordGenerator.cpp index aa0f3e717..538b741e5 100644 --- a/src/core/PasswordGenerator.cpp +++ b/src/core/PasswordGenerator.cpp @@ -132,7 +132,7 @@ QVector PasswordGenerator::passwordGroups() const continue; } - group.append(i); + group.append(QChar(i)); } passwordGroups.append(group); @@ -146,7 +146,7 @@ QVector PasswordGenerator::passwordGroups() const continue; } - group.append(i); + group.append(QChar(i)); } passwordGroups.append(group); @@ -159,7 +159,7 @@ QVector PasswordGenerator::passwordGroups() const continue; } - group.append(i); + group.append(QChar(i)); } passwordGroups.append(group); @@ -168,12 +168,12 @@ QVector PasswordGenerator::passwordGroups() const PasswordGroup group; // ()[]{} - group.append(40); - group.append(41); - group.append(91); - group.append(93); - group.append(123); - group.append(125); + group.append(QChar(40)); + group.append(QChar(41)); + group.append(QChar(91)); + group.append(QChar(93)); + group.append(QChar(123)); + group.append(QChar(125)); passwordGroups.append(group); } @@ -181,10 +181,10 @@ QVector PasswordGenerator::passwordGroups() const PasswordGroup group; // .,:; - group.append(44); - group.append(46); - group.append(58); - group.append(59); + group.append(QChar(44)); + group.append(QChar(46)); + group.append(QChar(58)); + group.append(QChar(59)); passwordGroups.append(group); } @@ -192,8 +192,8 @@ QVector PasswordGenerator::passwordGroups() const PasswordGroup group; // "' - group.append(34); - group.append(39); + group.append(QChar(34)); + group.append(QChar(39)); passwordGroups.append(group); } @@ -201,12 +201,12 @@ QVector PasswordGenerator::passwordGroups() const PasswordGroup group; // -/\_| - group.append(45); - group.append(47); - group.append(92); - group.append(95); + group.append(QChar(45)); + group.append(QChar(47)); + group.append(QChar(92)); + group.append(QChar(95)); if (!(m_flags & ExcludeLookAlike)) { - group.append(124); // "|" + group.append(QChar(124)); // "|" } passwordGroups.append(group); @@ -215,13 +215,13 @@ QVector PasswordGenerator::passwordGroups() const PasswordGroup group; // !*+<=>? - group.append(33); - group.append(42); - group.append(43); - group.append(60); - group.append(61); - group.append(62); - group.append(63); + group.append(QChar(33)); + group.append(QChar(42)); + group.append(QChar(43)); + group.append(QChar(60)); + group.append(QChar(61)); + group.append(QChar(62)); + group.append(QChar(63)); passwordGroups.append(group); } @@ -230,13 +230,13 @@ QVector PasswordGenerator::passwordGroups() const // #$%& for (int i = 35; i <= 38; i++) { - group.append(i); + group.append(QChar(i)); } // @^`~ - group.append(64); - group.append(94); - group.append(96); - group.append(126); + group.append(QChar(64)); + group.append(QChar(94)); + group.append(QChar(96)); + group.append(QChar(126)); passwordGroups.append(group); } @@ -246,14 +246,14 @@ QVector PasswordGenerator::passwordGroups() const // [U+0080, U+009F] are C1 control characters, // U+00A0 is non-breaking space for (int i = 161; i <= 172; i++) { - group.append(i); + group.append(QChar(i)); } // U+00AD is soft hyphen (format character) for (int i = 174; i <= 255; i++) { if ((m_flags & ExcludeLookAlike) && (i == 249)) { // "﹒" continue; } - group.append(i); + group.append(QChar(i)); } passwordGroups.append(group); diff --git a/src/core/SignalMultiplexer.h b/src/core/SignalMultiplexer.h index 727c4a3a3..3ce4b33b1 100644 --- a/src/core/SignalMultiplexer.h +++ b/src/core/SignalMultiplexer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Felix Geyer + * Copyright (C) 2015 Felix Geyer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,6 +18,8 @@ #ifndef KEEPASSX_SIGNALMULTIPLEXER_H #define KEEPASSX_SIGNALMULTIPLEXER_H +#include +#include #include class SignalMultiplexer diff --git a/src/core/Tools.cpp b/src/core/Tools.cpp index ff70a7bf1..72a5d0c0e 100644 --- a/src/core/Tools.cpp +++ b/src/core/Tools.cpp @@ -1,11 +1,11 @@ /* - * Copyright (C) 2012 Felix Geyer - * Copyright (C) 2017 Lennart Glauer - * Copyright (C) 2020 Giuseppe D'Angelo . + * Copyright (C) 2025 KeePassXC Team + * Copyright (C) 2021 The Qt Company Ltd. * Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, * author Giuseppe D'Angelo - * Copyright (C) 2021 The Qt Company Ltd. - * Copyright (C) 2023 KeePassXC Team + * Copyright (C) 2020 Giuseppe D'Angelo + * Copyright (C) 2017 Lennart Glauer + * Copyright (C) 2012 Felix Geyer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -205,11 +205,11 @@ namespace Tools bool isBase64(const QByteArray& ba) { constexpr auto pattern = R"(^(?:[a-z0-9+/]{4})*(?:[a-z0-9+/]{3}=|[a-z0-9+/]{2}==)?$)"; - QRegExp regexp(pattern, Qt::CaseInsensitive, QRegExp::RegExp2); + QRegularExpression regexp(pattern, QRegularExpression::CaseInsensitiveOption); QString base64 = QString::fromLatin1(ba.constData(), ba.size()); - return regexp.exactMatch(base64); + return regexp.match(base64).hasMatch(); } bool isAsciiString(const QString& str) diff --git a/src/core/Tools.h b/src/core/Tools.h index a8fe5b2be..a3aa90842 100644 --- a/src/core/Tools.h +++ b/src/core/Tools.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2012 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -53,11 +53,7 @@ namespace Tools template QSet asSet(const QList& a) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) return QSet(a.begin(), a.end()); -#else - return QSet::fromList(a); -#endif } /** diff --git a/src/core/Translator.cpp b/src/core/Translator.cpp index 125424c13..d636dc58a 100644 --- a/src/core/Translator.cpp +++ b/src/core/Translator.cpp @@ -77,7 +77,7 @@ bool Translator::installTranslator(const QStringList& languages, const QString& } /** - * Install Qt5 base translator from the specified local search path or the default system path + * Install Qt6 base translator from the specified local search path or the default system path * if no qtbase_* translations were found at the local path. * * @param languages priority-ordered list of languages diff --git a/src/crypto/Crypto.cpp b/src/crypto/Crypto.cpp index 6d9e5e772..ed90fec86 100644 --- a/src/crypto/Crypto.cpp +++ b/src/crypto/Crypto.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2010 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -23,6 +23,7 @@ #include "crypto/CryptoHash.h" #include "crypto/SymmetricCipher.h" +#include #include namespace diff --git a/src/crypto/SymmetricCipher.cpp b/src/crypto/SymmetricCipher.cpp index 413c0cefe..61ba8fb29 100644 --- a/src/crypto/SymmetricCipher.cpp +++ b/src/crypto/SymmetricCipher.cpp @@ -1,4 +1,5 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2010 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -65,7 +66,7 @@ bool SymmetricCipher::init(Mode mode, Direction direction, const QByteArray& key bool SymmetricCipher::isInitialized() const { - return m_cipher; + return !m_cipher.isNull(); } bool SymmetricCipher::process(char* data, int len) diff --git a/src/crypto/kdf/Argon2Kdf.cpp b/src/crypto/kdf/Argon2Kdf.cpp index f7b028ffe..2a588f460 100644 --- a/src/crypto/kdf/Argon2Kdf.cpp +++ b/src/crypto/kdf/Argon2Kdf.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,7 @@ #include #include -#include +#include #include "format/KeePass2.h" @@ -165,23 +165,20 @@ bool Argon2Kdf::transform(const QByteArray& raw, QByteArray& result) const { result.clear(); result.resize(32); - // Time Cost, Mem Cost, Threads/Lanes, Password, length, Salt, length, out, length - int rc = argon2_hash(rounds(), - memory(), - parallelism(), - raw.data(), - raw.size(), - seed().data(), - seed().size(), - result.data(), - result.size(), - nullptr, - 0, - type() == Type::Argon2d ? Argon2_d : Argon2_id, - version()); - if (rc != ARGON2_OK) { - qWarning("Argon2 error: %s", argon2_error_message(rc)); + const std::string algoName = (type() == Type::Argon2d) ? "Argon2d" : "Argon2id"; + try { + // from_params for Argon2: i1 == M (memory in KiB), i2 == t (iterations), i3 == p (parallelism) + auto pwdHash = + Botan::PasswordHashFamily::create_or_throw(algoName)->from_params(memory(), rounds(), parallelism()); + pwdHash->derive_key(reinterpret_cast(result.data()), + result.size(), + raw.constData(), + raw.size(), + reinterpret_cast(seed().constData()), + seed().size()); + } catch (const std::exception& e) { + qWarning("Argon2 error: %s", e.what()); return false; } diff --git a/src/fdosecrets/CMakeLists.txt b/src/fdosecrets/CMakeLists.txt index 72904b610..27ecb0680 100644 --- a/src/fdosecrets/CMakeLists.txt +++ b/src/fdosecrets/CMakeLists.txt @@ -30,5 +30,5 @@ if(KPXC_FEATURE_FDOSECRETS) objects/Prompt.cpp dbus/DBusTypes.cpp ) - target_link_libraries(fdosecrets Qt5::Core Qt5::Widgets Qt5::DBus ${BOTAN_LIBRARIES}) + target_link_libraries(fdosecrets Qt6::Core Qt6::Widgets Qt6::DBus ${BOTAN_LIBRARIES}) endif() diff --git a/src/fdosecrets/FdoSecretsPlugin.h b/src/fdosecrets/FdoSecretsPlugin.h index ad4e7003a..c06e347d9 100644 --- a/src/fdosecrets/FdoSecretsPlugin.h +++ b/src/fdosecrets/FdoSecretsPlugin.h @@ -1,4 +1,5 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2018 Aetf * * This program is free software: you can redistribute it and/or modify @@ -18,6 +19,7 @@ #ifndef KEEPASSXC_FDOSECRETSPLUGIN_H #define KEEPASSXC_FDOSECRETSPLUGIN_H +#include "core/Entry.h" #include "gui/ApplicationSettingsWidget.h" #include "gui/Icons.h" diff --git a/src/fdosecrets/FdoSecretsSettings.cpp b/src/fdosecrets/FdoSecretsSettings.cpp index d24bc69a1..8d3ca13a3 100644 --- a/src/fdosecrets/FdoSecretsSettings.cpp +++ b/src/fdosecrets/FdoSecretsSettings.cpp @@ -1,4 +1,5 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2018 Aetf * * This program is free software: you can redistribute it and/or modify @@ -96,7 +97,7 @@ namespace FdoSecrets QUuid FdoSecretsSettings::exposedGroup(Database* db) const { - return {db->metadata()->customData()->value(CustomData::FdoSecretsExposedGroup)}; + return QUuid(db->metadata()->customData()->value(CustomData::FdoSecretsExposedGroup)); } void FdoSecretsSettings::setExposedGroup(Database* db, const QUuid& group) diff --git a/src/fdosecrets/dbus/DBusDispatch.cpp b/src/fdosecrets/dbus/DBusDispatch.cpp index 4912f1340..aea709933 100644 --- a/src/fdosecrets/dbus/DBusDispatch.cpp +++ b/src/fdosecrets/dbus/DBusDispatch.cpp @@ -1,4 +1,5 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2020 Aetf * * This program is free software: you can redistribute it and/or modify @@ -18,6 +19,7 @@ #include "fdosecrets/dbus/DBusObject.h" #include +#include #include #include @@ -36,6 +38,9 @@ namespace FdoSecrets QVarLengthArray& params, QVariantList& auxParams) { + // Qt6 QList/QVariantList growth may relocate elements; reserve to keep data() pointers stable. + auxParams.reserve(auxParams.size() + inputTypes.size()); + // prepare params for (int count = 0; count != inputTypes.size(); ++count) { const auto& id = inputTypes.at(count); @@ -48,17 +53,17 @@ namespace FdoSecrets } // we need at least one conversion, allocate a slot in auxParams - auxParams.append(QVariant(id, nullptr)); + auxParams.append(QVariant(id)); auto& out = auxParams.last(); // first handle QDBusArgument to wire types if (arg.userType() == qMetaTypeId()) { - auto wireId = typeToWireType(id).dbusTypeId; + QMetaType wireId(typeToWireType(id).dbusTypeId); out = QVariant(wireId, nullptr); const auto& in = arg.value(); if (!QDBusMetaType::demarshall(in, wireId, out.data())) { qDebug() << "Internal error: failed QDBusArgument conversion from" << arg << "to type" - << QMetaType::typeName(wireId) << wireId; + << wireId.name(); return false; } } else { @@ -339,13 +344,14 @@ namespace FdoSecrets { QVarLengthArray params; QVariantList auxParams; + auxParams.reserve((method.needsCallingClient ? 1 : 0) + method.inputTypes.size()); // the first one is for return type params.append(&ret); if (method.needsCallingClient) { auxParams.append(QVariant::fromValue(client)); - params.append(const_cast(auxParams.last().constData())); + params.append(auxParams.last().data()); } // prepare input @@ -357,8 +363,9 @@ namespace FdoSecrets // prepare output args outputArgs.reserve(outputArgs.size() + method.outputTypes.size()); for (const auto& outputType : asConst(method.outputTypes)) { - outputArgs.append(QVariant(outputType, nullptr)); - params.append(const_cast(outputArgs.last().constData())); + QMetaType mtype(outputType); + outputArgs.append(QVariant(mtype, nullptr)); + params.append(outputArgs.last().data()); } // call it @@ -377,7 +384,8 @@ namespace FdoSecrets // output args need to be converted before they can be directly sent out: for (int i = 0; i != outputArgs.size(); ++i) { auto& outputArg = outputArgs[i]; - if (!outputArg.convert(method.outputTargetTypes.at(i))) { + QMetaType mtype(method.outputTargetTypes.at(i)); + if (!outputArg.convert(mtype)) { qWarning() << "Internal error: Failed to convert message output to type" << method.outputTargetTypes.at(i); return false; diff --git a/src/fdosecrets/dbus/DBusMgr.h b/src/fdosecrets/dbus/DBusMgr.h index bc32e6fe6..9894b22e3 100644 --- a/src/fdosecrets/dbus/DBusMgr.h +++ b/src/fdosecrets/dbus/DBusMgr.h @@ -1,4 +1,5 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2020 Aetf * * This program is free software: you can redistribute it and/or modify @@ -26,6 +27,11 @@ #include #include +#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0) +// Include the header only for moc file. Workaround for the class forward definiton error with older Qt 6 versions. +Q_MOC_INCLUDE("fdosecrets/objects/Item.h") +#endif + class TestFdoSecrets; namespace FdoSecrets @@ -78,6 +84,9 @@ namespace FdoSecrets class DBusMgr : public QDBusVirtualObject { Q_OBJECT +#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0) + Q_PROPERTY(Item* item) +#endif public: explicit DBusMgr(); diff --git a/src/fdosecrets/objects/Item.cpp b/src/fdosecrets/objects/Item.cpp index 373735205..2cc0a577a 100644 --- a/src/fdosecrets/objects/Item.cpp +++ b/src/fdosecrets/objects/Item.cpp @@ -1,4 +1,5 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2019 Aetf * * This program is free software: you can redistribute it and/or modify @@ -28,7 +29,7 @@ #include #include -#include +#include namespace FdoSecrets { @@ -400,7 +401,7 @@ namespace FdoSecrets Q_ASSERT(group); // root group is represented by a single slash, thus adding an empty component. - pathComponents.prepend(QLatin1Literal("")); + pathComponents.prepend(""); return pathComponents.join('/'); } @@ -414,16 +415,18 @@ namespace FdoSecrets auto mimeType = db.mimeTypeForName(mimeName); // find a suitable codec - QTextCodec* codec = nullptr; + QStringDecoder decoder(QStringDecoder::Utf8); static const QRegularExpression charsetPattern(QStringLiteral(R"re(charset=(?.+)$)re")); auto match = charsetPattern.match(contentType); if (match.hasMatch()) { - codec = QTextCodec::codecForName(match.captured(QStringLiteral("encode")).toLatin1()); - } else { - codec = QTextCodec::codecForName(QByteArrayLiteral("utf-8")); + auto codecName = match.captured(QStringLiteral("encode")).toUtf8(); + auto encoding = QStringDecoder::encodingForName(codecName); + if (encoding != std::nullopt) { + decoder = QStringDecoder(encoding.value()); + } } - if (!mimeType.isValid() || !mimeType.inherits(QStringLiteral("text/plain")) || !codec) { + if (!mimeType.isValid() || !mimeType.inherits(QStringLiteral("text/plain"))) { if (EntryAttributes::matchReference(contentType).hasMatch()) { return QDBusError::InvalidArgs; } @@ -432,7 +435,7 @@ namespace FdoSecrets entry->attachments()->set(FDO_SECRETS_DATA, data); entry->attributes()->set(FDO_SECRETS_CONTENT_TYPE, contentType); } else { - auto password = codec->toUnicode(data); + auto password = decoder.decode(data); if (EntryAttributes::matchReference(password).hasMatch()) { return QDBusError::InvalidArgs; } diff --git a/src/format/BitwardenReader.cpp b/src/format/BitwardenReader.cpp index 37e361929..084fb7e20 100644 --- a/src/format/BitwardenReader.cpp +++ b/src/format/BitwardenReader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -91,8 +91,7 @@ namespace // Change from UUID to base64 byte array const auto credentialIdValue = passkey.value("credentialId").toString(); if (!credentialIdValue.isEmpty()) { - const auto credentialUuid = Tools::uuidToHex(credentialIdValue); - const auto credentialIdArray = QByteArray::fromHex(credentialUuid.toUtf8()); + const auto credentialIdArray = QByteArray::fromHex(credentialIdValue.toUtf8()); const auto credentialId = credentialIdArray.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals); entry->attributes()->set(EntryAttributes::KPEX_PASSKEY_CREDENTIAL_ID, credentialId, true); diff --git a/src/format/CsvParser.cpp b/src/format/CsvParser.cpp index d5d3b319a..f54f617ab 100644 --- a/src/format/CsvParser.cpp +++ b/src/format/CsvParser.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2016 Enrico Mariotti - * Copyright (C) 2017 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,7 +19,6 @@ #include "CsvParser.h" #include -#include #include "core/Tools.h" @@ -34,7 +33,6 @@ CsvParser::CsvParser() m_csv.setBuffer(&m_array); m_ts.setDevice(&m_csv); m_csv.open(QIODevice::ReadOnly); - m_ts.setCodec("UTF-8"); } CsvParser::~CsvParser() @@ -92,7 +90,7 @@ bool CsvParser::readFile(QIODevice* device) void CsvParser::reset() { - m_ch = 0; + m_ch = QChar(0); m_currCol = 1; m_currRow = 1; m_isEof = false; @@ -349,7 +347,15 @@ void CsvParser::setComment(const QChar& c) void CsvParser::setCodec(const QString& s) { - m_ts.setCodec(QTextCodec::codecForName(s.toLocal8Bit())); + auto encoding = QStringConverter::encodingForName(s.toLocal8Bit()); + if (encoding) { + m_ts.setEncoding(*encoding); + } +} + +QStringConverter::Encoding CsvParser::getCodec() const +{ + return m_ts.encoding(); } void CsvParser::setFieldSeparator(const QChar& c) diff --git a/src/format/CsvParser.h b/src/format/CsvParser.h index 608d71c14..679368a4d 100644 --- a/src/format/CsvParser.h +++ b/src/format/CsvParser.h @@ -48,6 +48,7 @@ public: int getCsvCols() const; QString getStatus() const; CsvTable getCsvTable() const; + QStringConverter::Encoding getCodec() const; protected: CsvTable m_table; diff --git a/src/format/Kdbx4Writer.cpp b/src/format/Kdbx4Writer.cpp index 4a1859010..6d93d2cc8 100644 --- a/src/format/Kdbx4Writer.cpp +++ b/src/format/Kdbx4Writer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -310,8 +310,8 @@ bool Kdbx4Writer::serializeVariantMap(const QVariantMap& map, QByteArray& output QByteArray typeBytes; typeBytes.append(static_cast(fieldType)); QByteArray nameBytes = k.toUtf8(); - QByteArray nameLenBytes = Endian::sizedIntToBytes(nameBytes.size(), KeePass2::BYTEORDER); - QByteArray dataLenBytes = Endian::sizedIntToBytes(data.size(), KeePass2::BYTEORDER); + QByteArray nameLenBytes = Endian::sizedIntToBytes(nameBytes.size(), KeePass2::BYTEORDER); + QByteArray dataLenBytes = Endian::sizedIntToBytes(data.size(), KeePass2::BYTEORDER); CHECK_RETURN_FALSE(buf.write(typeBytes) == 1); CHECK_RETURN_FALSE(buf.write(nameLenBytes) == 4); diff --git a/src/format/KdbxXmlReader.cpp b/src/format/KdbxXmlReader.cpp index e6c212bbc..b69107dd8 100644 --- a/src/format/KdbxXmlReader.cpp +++ b/src/format/KdbxXmlReader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +27,8 @@ #include #include +#define qsv QStringView + #define UUID_LENGTH 16 /** @@ -56,7 +58,9 @@ KdbxXmlReader::KdbxXmlReader(quint32 version, QHash binaryP QSharedPointer KdbxXmlReader::readDatabase(const QString& filename) { QFile file(filename); - file.open(QIODevice::ReadOnly); + if (!file.open(QIODeviceBase::ReadOnly)) { + return nullptr; + } return readDatabase(&file); } @@ -104,7 +108,7 @@ void KdbxXmlReader::readDatabase(QIODevice* device, Database* db, KeePass2Random return; } - if (m_xml.readNextStartElement() && m_xml.name() == "KeePassFile") { + if (m_xml.readNextStartElement() && m_xml.name() == qsv(u"KeePassFile")) { rootGroupParsed = parseKeePassFile(); } @@ -114,11 +118,13 @@ void KdbxXmlReader::readDatabase(QIODevice* device, Database* db, KeePass2Random } if (!m_tmpParent->children().isEmpty()) { - qWarning("KdbxXmlReader::readDatabase: found %d invalid group reference(s)", m_tmpParent->children().size()); + qWarning("KdbxXmlReader::readDatabase: found %" PRIdQSIZETYPE " invalid group reference(s)", + m_tmpParent->children().size()); } if (!m_tmpParent->entries().isEmpty()) { - qWarning("KdbxXmlReader::readDatabase: found %d invalid entry reference(s)", m_tmpParent->children().size()); + qWarning("KdbxXmlReader::readDatabase: found %" PRIdQSIZETYPE " invalid entry reference(s)", + m_tmpParent->children().size()); } const QSet poolKeys = Tools::asSet(m_binaryPool.keys()); @@ -187,9 +193,9 @@ QString KdbxXmlReader::errorString() const return {}; } -bool KdbxXmlReader::isTrueValue(const QStringRef& value) +bool KdbxXmlReader::isTrueValue(const QStringView value) { - return value.compare(QLatin1String("true"), Qt::CaseInsensitive) == 0 || value == "1"; + return value.compare(QLatin1String("true"), Qt::CaseInsensitive) == 0 || value == qsv(u"1"); } void KdbxXmlReader::raiseError(const QString& errorMessage) @@ -205,18 +211,18 @@ QByteArray KdbxXmlReader::headerHash() const bool KdbxXmlReader::parseKeePassFile() { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "KeePassFile"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"KeePassFile")); bool rootElementFound = false; bool rootParsedSuccessfully = false; while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() == "Meta") { + if (m_xml.name() == qsv(u"Meta")) { parseMeta(); continue; } - if (m_xml.name() == "Root") { + if (m_xml.name() == qsv(u"Root")) { if (rootElementFound) { rootParsedSuccessfully = false; qWarning("Multiple root elements"); @@ -235,72 +241,73 @@ bool KdbxXmlReader::parseKeePassFile() void KdbxXmlReader::parseMeta() { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Meta"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"Meta")); while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() == "Generator") { + auto name = m_xml.name(); + if (name == qsv(u"Generator")) { m_meta->setGenerator(readString()); - } else if (m_xml.name() == "HeaderHash") { + } else if (name == qsv(u"HeaderHash")) { m_headerHash = readBinary(); - } else if (m_xml.name() == "DatabaseName") { + } else if (name == qsv(u"DatabaseName")) { m_meta->setName(readString()); - } else if (m_xml.name() == "DatabaseNameChanged") { + } else if (name == qsv(u"DatabaseNameChanged")) { m_meta->setNameChanged(readDateTime()); - } else if (m_xml.name() == "DatabaseDescription") { + } else if (name == qsv(u"DatabaseDescription")) { m_meta->setDescription(readString()); - } else if (m_xml.name() == "DatabaseDescriptionChanged") { + } else if (name == qsv(u"DatabaseDescriptionChanged")) { m_meta->setDescriptionChanged(readDateTime()); - } else if (m_xml.name() == "DefaultUserName") { + } else if (name == qsv(u"DefaultUserName")) { m_meta->setDefaultUserName(readString()); - } else if (m_xml.name() == "DefaultUserNameChanged") { + } else if (name == qsv(u"DefaultUserNameChanged")) { m_meta->setDefaultUserNameChanged(readDateTime()); - } else if (m_xml.name() == "MaintenanceHistoryDays") { + } else if (name == qsv(u"MaintenanceHistoryDays")) { m_meta->setMaintenanceHistoryDays(readNumber()); - } else if (m_xml.name() == "Color") { + } else if (name == qsv(u"Color")) { m_meta->setColor(readColor()); - } else if (m_xml.name() == "MasterKeyChanged") { + } else if (name == qsv(u"MasterKeyChanged")) { m_meta->setDatabaseKeyChanged(readDateTime()); - } else if (m_xml.name() == "MasterKeyChangeRec") { + } else if (name == qsv(u"MasterKeyChangeRec")) { m_meta->setMasterKeyChangeRec(readNumber()); - } else if (m_xml.name() == "MasterKeyChangeForce") { + } else if (name == qsv(u"MasterKeyChangeForce")) { m_meta->setMasterKeyChangeForce(readNumber()); - } else if (m_xml.name() == "MemoryProtection") { + } else if (name == qsv(u"MemoryProtection")) { parseMemoryProtection(); - } else if (m_xml.name() == "CustomIcons") { + } else if (name == qsv(u"CustomIcons")) { parseCustomIcons(); - } else if (m_xml.name() == "RecycleBinEnabled") { + } else if (name == qsv(u"RecycleBinEnabled")) { m_meta->setRecycleBinEnabled(readBool()); - } else if (m_xml.name() == "RecycleBinUUID") { + } else if (name == qsv(u"RecycleBinUUID")) { m_meta->setRecycleBin(getGroup(readUuid())); - } else if (m_xml.name() == "RecycleBinChanged") { + } else if (name == qsv(u"RecycleBinChanged")) { m_meta->setRecycleBinChanged(readDateTime()); - } else if (m_xml.name() == "EntryTemplatesGroup") { + } else if (name == qsv(u"EntryTemplatesGroup")) { m_meta->setEntryTemplatesGroup(getGroup(readUuid())); - } else if (m_xml.name() == "EntryTemplatesGroupChanged") { + } else if (name == qsv(u"EntryTemplatesGroupChanged")) { m_meta->setEntryTemplatesGroupChanged(readDateTime()); - } else if (m_xml.name() == "LastSelectedGroup") { + } else if (name == qsv(u"LastSelectedGroup")) { m_meta->setLastSelectedGroup(getGroup(readUuid())); - } else if (m_xml.name() == "LastTopVisibleGroup") { + } else if (name == qsv(u"LastTopVisibleGroup")) { m_meta->setLastTopVisibleGroup(getGroup(readUuid())); - } else if (m_xml.name() == "HistoryMaxItems") { + } else if (name == qsv(u"HistoryMaxItems")) { int value = readNumber(); if (value >= -1) { m_meta->setHistoryMaxItems(value); } else { qWarning("HistoryMaxItems invalid number"); } - } else if (m_xml.name() == "HistoryMaxSize") { + } else if (name == qsv(u"HistoryMaxSize")) { int value = readNumber(); if (value >= -1) { m_meta->setHistoryMaxSize(value); } else { qWarning("HistoryMaxSize invalid number"); } - } else if (m_xml.name() == "Binaries") { + } else if (name == qsv(u"Binaries")) { parseBinaries(); - } else if (m_xml.name() == "CustomData") { + } else if (name == qsv(u"CustomData")) { parseCustomData(m_meta->customData()); - } else if (m_xml.name() == "SettingsChanged") { + } else if (name == qsv(u"SettingsChanged")) { m_meta->setSettingsChanged(readDateTime()); } else { skipCurrentElement(); @@ -310,18 +317,19 @@ void KdbxXmlReader::parseMeta() void KdbxXmlReader::parseMemoryProtection() { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "MemoryProtection"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"MemoryProtection")); while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() == "ProtectTitle") { + auto name = m_xml.name(); + if (name == qsv(u"ProtectTitle")) { m_meta->setProtectTitle(readBool()); - } else if (m_xml.name() == "ProtectUserName") { + } else if (name == qsv(u"ProtectUserName")) { m_meta->setProtectUsername(readBool()); - } else if (m_xml.name() == "ProtectPassword") { + } else if (name == qsv(u"ProtectPassword")) { m_meta->setProtectPassword(readBool()); - } else if (m_xml.name() == "ProtectURL") { + } else if (name == qsv(u"ProtectURL")) { m_meta->setProtectUrl(readBool()); - } else if (m_xml.name() == "ProtectNotes") { + } else if (name == qsv(u"ProtectNotes")) { m_meta->setProtectNotes(readBool()); } else { skipCurrentElement(); @@ -331,10 +339,10 @@ void KdbxXmlReader::parseMemoryProtection() void KdbxXmlReader::parseCustomIcons() { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "CustomIcons"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"CustomIcons")); while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() == "Icon") { + if (m_xml.name() == qsv(u"Icon")) { parseIcon(); } else { skipCurrentElement(); @@ -344,7 +352,7 @@ void KdbxXmlReader::parseCustomIcons() void KdbxXmlReader::parseIcon() { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Icon"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"Icon")); QUuid uuid; QByteArray iconData; @@ -354,15 +362,15 @@ void KdbxXmlReader::parseIcon() bool iconSet = false; while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() == "UUID") { + if (m_xml.name() == qsv(u"UUID")) { uuid = readUuid(); uuidSet = !uuid.isNull(); - } else if (m_xml.name() == "Data") { + } else if (m_xml.name() == qsv(u"Data")) { iconData = readBinary(); iconSet = true; - } else if (m_xml.name() == "Name") { + } else if (m_xml.name() == qsv(u"Name")) { name = readString(); - } else if (m_xml.name() == "LastModificationTime") { + } else if (m_xml.name() == qsv(u"LastModificationTime")) { lastModified = readDateTime(); } else { skipCurrentElement(); @@ -383,10 +391,10 @@ void KdbxXmlReader::parseIcon() void KdbxXmlReader::parseBinaries() { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Binaries"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"Binaries")); while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() != "Binary") { + if (m_xml.name() != qsv(u"Binary")) { skipCurrentElement(); continue; } @@ -405,10 +413,10 @@ void KdbxXmlReader::parseBinaries() void KdbxXmlReader::parseCustomData(CustomData* customData) { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "CustomData"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"CustomData")); while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() == "Item") { + if (m_xml.name() == qsv(u"Item")) { parseCustomDataItem(customData); continue; } @@ -418,7 +426,7 @@ void KdbxXmlReader::parseCustomData(CustomData* customData) void KdbxXmlReader::parseCustomDataItem(CustomData* customData) { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Item"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"Item")); QString key; CustomData::CustomDataItem item; @@ -426,13 +434,13 @@ void KdbxXmlReader::parseCustomDataItem(CustomData* customData) bool valueSet = false; while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() == "Key") { + if (m_xml.name() == qsv(u"Key")) { key = readString(); keySet = true; - } else if (m_xml.name() == "Value") { + } else if (m_xml.name() == qsv(u"Value")) { item.value = readString(); valueSet = true; - } else if (m_xml.name() == "LastModificationTime") { + } else if (m_xml.name() == qsv(u"LastModificationTime")) { item.lastModified = readDateTime(); } else { skipCurrentElement(); @@ -449,13 +457,13 @@ void KdbxXmlReader::parseCustomDataItem(CustomData* customData) bool KdbxXmlReader::parseRoot() { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Root"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"Root")); bool groupElementFound = false; bool groupParsedSuccessfully = false; while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() == "Group") { + if (m_xml.name() == qsv(u"Group")) { if (groupElementFound) { groupParsedSuccessfully = false; raiseError(tr("Multiple group elements")); @@ -470,7 +478,7 @@ bool KdbxXmlReader::parseRoot() } groupElementFound = true; - } else if (m_xml.name() == "DeletedObjects") { + } else if (m_xml.name() == qsv(u"DeletedObjects")) { parseDeletedObjects(); } else { skipCurrentElement(); @@ -482,14 +490,15 @@ bool KdbxXmlReader::parseRoot() Group* KdbxXmlReader::parseGroup() { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Group"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"Group")); auto group = new Group(); group->setUpdateTimeinfo(false); QList children; QList entries; while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() == "UUID") { + auto name = m_xml.name(); + if (name == qsv(u"UUID")) { QUuid uuid = readUuid(); if (uuid.isNull()) { if (m_strictMode) { @@ -502,19 +511,19 @@ Group* KdbxXmlReader::parseGroup() } continue; } - if (m_xml.name() == "Name") { + if (name == qsv(u"Name")) { group->setName(readString()); continue; } - if (m_xml.name() == "Notes") { + if (name == qsv(u"Notes")) { group->setNotes(readString()); continue; } - if (m_xml.name() == "Tags") { + if (name == qsv(u"Tags")) { group->setTags(readString()); continue; } - if (m_xml.name() == "IconID") { + if (name == qsv(u"IconID")) { int iconId = readNumber(); if (iconId < 0) { if (m_strictMode) { @@ -526,26 +535,26 @@ Group* KdbxXmlReader::parseGroup() group->setIcon(iconId); continue; } - if (m_xml.name() == "CustomIconUUID") { + if (name == qsv(u"CustomIconUUID")) { QUuid uuid = readUuid(); if (!uuid.isNull()) { group->setIcon(uuid); } continue; } - if (m_xml.name() == "Times") { + if (name == qsv(u"Times")) { group->setTimeInfo(parseTimes()); continue; } - if (m_xml.name() == "IsExpanded") { + if (name == qsv(u"IsExpanded")) { group->setExpanded(readBool()); continue; } - if (m_xml.name() == "DefaultAutoTypeSequence") { + if (name == qsv(u"DefaultAutoTypeSequence")) { group->setDefaultAutoTypeSequence(readString()); continue; } - if (m_xml.name() == "EnableAutoType") { + if (name == qsv(u"EnableAutoType")) { QString str = readString(); if (str.compare("null", Qt::CaseInsensitive) == 0) { @@ -559,7 +568,7 @@ Group* KdbxXmlReader::parseGroup() } continue; } - if (m_xml.name() == "EnableSearching") { + if (name == qsv(u"EnableSearching")) { QString str = readString(); if (str.compare("null", Qt::CaseInsensitive) == 0) { @@ -573,29 +582,29 @@ Group* KdbxXmlReader::parseGroup() } continue; } - if (m_xml.name() == "LastTopVisibleEntry") { + if (name == qsv(u"LastTopVisibleEntry")) { group->setLastTopVisibleEntry(getEntry(readUuid())); continue; } - if (m_xml.name() == "Group") { + if (name == qsv(u"Group")) { Group* newGroup = parseGroup(); if (newGroup) { children.append(newGroup); } continue; } - if (m_xml.name() == "Entry") { + if (name == qsv(u"Entry")) { Entry* newEntry = parseEntry(false); if (newEntry) { entries.append(newEntry); } continue; } - if (m_xml.name() == "CustomData") { + if (name == qsv(u"CustomData")) { parseCustomData(group->customData()); continue; } - if (m_xml.name() == "PreviousParentGroup") { + if (name == qsv(u"PreviousParentGroup")) { group->setPreviousParentGroupUuid(readUuid()); continue; } @@ -630,10 +639,10 @@ Group* KdbxXmlReader::parseGroup() void KdbxXmlReader::parseDeletedObjects() { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "DeletedObjects"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"DeletedObjects")); while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() == "DeletedObject") { + if (m_xml.name() == qsv(u"DeletedObject")) { parseDeletedObject(); } else { skipCurrentElement(); @@ -643,12 +652,12 @@ void KdbxXmlReader::parseDeletedObjects() void KdbxXmlReader::parseDeletedObject() { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "DeletedObject"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"DeletedObject")); DeletedObject delObj{{}, {}}; while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() == "UUID") { + if (m_xml.name() == qsv(u"UUID")) { QUuid uuid = readUuid(); if (uuid.isNull()) { if (m_strictMode) { @@ -660,7 +669,7 @@ void KdbxXmlReader::parseDeletedObject() delObj.uuid = uuid; continue; } - if (m_xml.name() == "DeletionTime") { + if (m_xml.name() == qsv(u"DeletionTime")) { delObj.deletionTime = readDateTime(); continue; } @@ -679,7 +688,7 @@ void KdbxXmlReader::parseDeletedObject() Entry* KdbxXmlReader::parseEntry(bool history) { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Entry"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"Entry")); auto entry = new Entry(); entry->setUpdateTimeinfo(false); @@ -687,7 +696,8 @@ Entry* KdbxXmlReader::parseEntry(bool history) QList binaryRefs; while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() == "UUID") { + auto name = m_xml.name(); + if (name == qsv(u"UUID")) { QUuid uuid = readUuid(); if (uuid.isNull()) { if (m_strictMode) { @@ -700,7 +710,7 @@ Entry* KdbxXmlReader::parseEntry(bool history) } continue; } - if (m_xml.name() == "IconID") { + if (name == qsv(u"IconID")) { int iconId = readNumber(); if (iconId < 0) { if (m_strictMode) { @@ -711,53 +721,53 @@ Entry* KdbxXmlReader::parseEntry(bool history) entry->setIcon(iconId); continue; } - if (m_xml.name() == "CustomIconUUID") { + if (name == qsv(u"CustomIconUUID")) { QUuid uuid = readUuid(); if (!uuid.isNull()) { entry->setIcon(uuid); } continue; } - if (m_xml.name() == "ForegroundColor") { + if (name == qsv(u"ForegroundColor")) { entry->setForegroundColor(readColor()); continue; } - if (m_xml.name() == "BackgroundColor") { + if (name == qsv(u"BackgroundColor")) { entry->setBackgroundColor(readColor()); continue; } - if (m_xml.name() == "OverrideURL") { + if (name == qsv(u"OverrideURL")) { entry->setOverrideUrl(readString()); continue; } - if (m_xml.name() == "Tags") { + if (name == qsv(u"Tags")) { entry->setTags(readString()); continue; } - if (m_xml.name() == "Times") { + if (name == qsv(u"Times")) { entry->setTimeInfo(parseTimes()); continue; } - if (m_xml.name() == "String") { + if (name == qsv(u"String")) { parseEntryString(entry); continue; } - if (m_xml.name() == "QualityCheck") { + if (name == qsv(u"QualityCheck")) { entry->setExcludeFromReports(!readBool()); continue; } - if (m_xml.name() == "Binary") { + if (name == qsv(u"Binary")) { QPair ref = parseEntryBinary(entry); if (!ref.first.isEmpty() && !ref.second.isEmpty()) { binaryRefs.append(ref); } continue; } - if (m_xml.name() == "AutoType") { + if (name == qsv(u"AutoType")) { parseAutoType(entry); continue; } - if (m_xml.name() == "History") { + if (name == qsv(u"History")) { if (history) { raiseError(tr("History element in history entry")); } else { @@ -765,7 +775,7 @@ Entry* KdbxXmlReader::parseEntry(bool history) } continue; } - if (m_xml.name() == "CustomData") { + if (name == qsv(u"CustomData")) { parseCustomData(entry->customData()); // Upgrade pre-KDBX-4.1 password report exclude flag @@ -776,7 +786,7 @@ Entry* KdbxXmlReader::parseEntry(bool history) } continue; } - if (m_xml.name() == "PreviousParentGroup") { + if (name == qsv(u"PreviousParentGroup")) { entry->setPreviousParentGroupUuid(readUuid()); continue; } @@ -823,7 +833,7 @@ Entry* KdbxXmlReader::parseEntry(bool history) void KdbxXmlReader::parseEntryString(Entry* entry) { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "String"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"String")); QString key; QString value; @@ -832,13 +842,13 @@ void KdbxXmlReader::parseEntryString(Entry* entry) bool valueSet = false; while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() == "Key") { + if (m_xml.name() == qsv(u"Key")) { key = readString(); keySet = true; continue; } - if (m_xml.name() == "Value") { + if (m_xml.name() == qsv(u"Value")) { QXmlStreamAttributes attr = m_xml.attributes(); bool isProtected; bool protectInMemory; @@ -866,7 +876,7 @@ void KdbxXmlReader::parseEntryString(Entry* entry) QPair KdbxXmlReader::parseEntryBinary(Entry* entry) { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Binary"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"Binary")); QPair poolRef; @@ -876,12 +886,12 @@ QPair KdbxXmlReader::parseEntryBinary(Entry* entry) bool valueSet = false; while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() == "Key") { + if (m_xml.name() == qsv(u"Key")) { key = readString(); keySet = true; continue; } - if (m_xml.name() == "Value") { + if (m_xml.name() == qsv(u"Value")) { QXmlStreamAttributes attr = m_xml.attributes(); if (attr.hasAttribute("Ref")) { @@ -915,16 +925,17 @@ QPair KdbxXmlReader::parseEntryBinary(Entry* entry) void KdbxXmlReader::parseAutoType(Entry* entry) { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "AutoType"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"AutoType")); while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() == "Enabled") { + auto name = m_xml.name(); + if (name == qsv(u"Enabled")) { entry->setAutoTypeEnabled(readBool()); - } else if (m_xml.name() == "DataTransferObfuscation") { + } else if (name == qsv(u"DataTransferObfuscation")) { entry->setAutoTypeObfuscation(readNumber()); - } else if (m_xml.name() == "DefaultSequence") { + } else if (name == qsv(u"DefaultSequence")) { entry->setDefaultAutoTypeSequence(readString()); - } else if (m_xml.name() == "Association") { + } else if (name == qsv(u"Association")) { parseAutoTypeAssoc(entry); } else { skipCurrentElement(); @@ -934,17 +945,17 @@ void KdbxXmlReader::parseAutoType(Entry* entry) void KdbxXmlReader::parseAutoTypeAssoc(Entry* entry) { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Association"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"Association")); AutoTypeAssociations::Association assoc; bool windowSet = false; bool sequenceSet = false; while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() == "Window") { + if (m_xml.name() == qsv(u"Window")) { assoc.window = readString(); windowSet = true; - } else if (m_xml.name() == "KeystrokeSequence") { + } else if (m_xml.name() == qsv(u"KeystrokeSequence")) { assoc.sequence = readString(); sequenceSet = true; } else { @@ -961,12 +972,12 @@ void KdbxXmlReader::parseAutoTypeAssoc(Entry* entry) QList KdbxXmlReader::parseEntryHistory() { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "History"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"History")); QList historyItems; while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() == "Entry") { + if (m_xml.name() == qsv(u"Entry")) { historyItems.append(parseEntry(true)); } else { skipCurrentElement(); @@ -978,23 +989,24 @@ QList KdbxXmlReader::parseEntryHistory() TimeInfo KdbxXmlReader::parseTimes() { - Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Times"); + Q_ASSERT(m_xml.isStartElement() && m_xml.name() == qsv(u"Times")); TimeInfo timeInfo; while (!m_xml.hasError() && m_xml.readNextStartElement()) { - if (m_xml.name() == "LastModificationTime") { + auto name = m_xml.name(); + if (name == qsv(u"LastModificationTime")) { timeInfo.setLastModificationTime(readDateTime()); - } else if (m_xml.name() == "CreationTime") { + } else if (name == qsv(u"CreationTime")) { timeInfo.setCreationTime(readDateTime()); - } else if (m_xml.name() == "LastAccessTime") { + } else if (name == qsv(u"LastAccessTime")) { timeInfo.setLastAccessTime(readDateTime()); - } else if (m_xml.name() == "ExpiryTime") { + } else if (name == qsv(u"ExpiryTime")) { timeInfo.setExpiryTime(readDateTime()); - } else if (m_xml.name() == "Expires") { + } else if (name == qsv(u"Expires")) { timeInfo.setExpires(readBool()); - } else if (m_xml.name() == "UsageCount") { + } else if (name == qsv(u"UsageCount")) { timeInfo.setUsageCount(readNumber()); - } else if (m_xml.name() == "LocationChanged") { + } else if (name == qsv(u"LocationChanged")) { timeInfo.setLocationChanged(readDateTime()); } else { skipCurrentElement(); diff --git a/src/format/KdbxXmlReader.h b/src/format/KdbxXmlReader.h index 1b6305eea..50950df7e 100644 --- a/src/format/KdbxXmlReader.h +++ b/src/format/KdbxXmlReader.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ #include #include +#include #include class QIODevice; @@ -93,7 +94,7 @@ protected: virtual Group* getGroup(const QUuid& uuid); virtual Entry* getEntry(const QUuid& uuid); - virtual bool isTrueValue(const QStringRef& value); + virtual bool isTrueValue(const QStringView value); virtual void raiseError(const QString& errorMessage); const quint32 m_kdbxVersion; diff --git a/src/format/KdbxXmlWriter.cpp b/src/format/KdbxXmlWriter.cpp index 7c9047f9d..8a921afa7 100644 --- a/src/format/KdbxXmlWriter.cpp +++ b/src/format/KdbxXmlWriter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -55,7 +55,6 @@ void KdbxXmlWriter::writeDatabase(QIODevice* device, m_xml.setAutoFormatting(true); m_xml.setAutoFormattingIndent(-1); // 1 tab - m_xml.setCodec("UTF-8"); if (m_kdbxVersion < KeePass2::FILE_VERSION_4) { fillBinaryIdxMap(); @@ -79,8 +78,9 @@ void KdbxXmlWriter::writeDatabase(QIODevice* device, void KdbxXmlWriter::writeDatabase(const QString& filename, Database* db) { QFile file(filename); - file.open(QIODevice::WriteOnly | QIODevice::Truncate); - writeDatabase(&file, db); + if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + writeDatabase(&file, db); + } } bool KdbxXmlWriter::hasError() diff --git a/src/format/KeePass1Reader.cpp b/src/format/KeePass1Reader.cpp index a7d8038df..4eeecf1ef 100644 --- a/src/format/KeePass1Reader.cpp +++ b/src/format/KeePass1Reader.cpp @@ -1,4 +1,5 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2012 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -19,7 +20,8 @@ #include #include -#include +#include +#include #include "core/Endian.h" #include "core/Group.h" @@ -300,8 +302,10 @@ KeePass1Reader::testKeys(const QString& password, const QByteArray& keyfileData, QScopedPointer cipherStream; QByteArray passwordData; - QTextCodec* codec = QTextCodec::codecForName("Windows-1252"); - QByteArray passwordDataCorrect = codec->fromUnicode(password); + + const auto currentEncoding = QStringConverter::encodingForName("Windows-1252"); + QStringEncoder encoder(currentEncoding.value_or(QStringConverter::System)); + QByteArray passwordDataCorrect = encoder.encode(password); for (PasswordEncoding encoding : encodings) { if (encoding == Windows1252) { @@ -701,8 +705,8 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream) void KeePass1Reader::parseNotes(const QString& rawNotes, Entry* entry) { - QRegExp sequenceRegexp("Auto-Type(?:-(\\d+))?: (.+)", Qt::CaseInsensitive, QRegExp::RegExp2); - QRegExp windowRegexp("Auto-Type-Window(?:-(\\d+))?: (.+)", Qt::CaseInsensitive, QRegExp::RegExp2); + QRegularExpression sequenceRegexp("Auto-Type(?:-(\\d+))?: (.+)", QRegularExpression::CaseInsensitiveOption); + QRegularExpression windowRegexp("Auto-Type-Window(?:-(\\d+))?: (.+)", QRegularExpression::CaseInsensitiveOption); QHash sequences; QMap windows; @@ -713,23 +717,25 @@ void KeePass1Reader::parseNotes(const QString& rawNotes, Entry* entry) for (QString line : rawNotesLines) { line.remove("\r"); - if (sequenceRegexp.exactMatch(line)) { - if (sequenceRegexp.cap(1).isEmpty()) { - entry->setDefaultAutoTypeSequence(sequenceRegexp.cap(2)); + auto sequenceMatch = sequenceRegexp.match(line); + auto windowMatch = windowRegexp.match(line); + if (sequenceMatch.hasMatch()) { + if (sequenceMatch.captured(1).isEmpty()) { + entry->setDefaultAutoTypeSequence(sequenceMatch.captured(2)); } else { - sequences[sequenceRegexp.cap(1).toInt()] = sequenceRegexp.cap(2); + sequences[sequenceMatch.captured(1).toInt()] = sequenceMatch.captured(2); } lastLineAutoType = true; - } else if (windowRegexp.exactMatch(line)) { + } else if (windowMatch.hasMatch()) { int nr; - if (windowRegexp.cap(1).isEmpty()) { + if (windowMatch.captured(1).isEmpty()) { nr = -1; // special number that matches no other sequence } else { - nr = windowRegexp.cap(1).toInt(); + nr = windowMatch.captured(1).toInt(); } - windows[nr].append(windowRegexp.cap(2)); + windows[nr].append(windowMatch.captured(2)); lastLineAutoType = true; } else { diff --git a/src/format/KeePass1Reader.h b/src/format/KeePass1Reader.h index 2cb3589cc..746280fec 100644 --- a/src/format/KeePass1Reader.h +++ b/src/format/KeePass1Reader.h @@ -19,6 +19,7 @@ #define KEEPASSX_KEEPASS1READER_H #include +#include #include class Database; diff --git a/src/format/OPUXReader.cpp b/src/format/OPUXReader.cpp index e1a0579cf..925587573 100644 --- a/src/format/OPUXReader.cpp +++ b/src/format/OPUXReader.cpp @@ -30,7 +30,7 @@ #include #include -#include +#include <../minizip/unzip.h> namespace { diff --git a/src/format/OpVaultReader.cpp b/src/format/OpVaultReader.cpp index 779e25fda..4b04b6013 100644 --- a/src/format/OpVaultReader.cpp +++ b/src/format/OpVaultReader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -158,9 +158,9 @@ bool OpVaultReader::processProfileJson(QJsonObject& profileJson, const QString& } auto rootGroupTime = rootGroup->timeInfo(); auto createdAt = static_cast(profileJson["createdAt"].toInt()); - rootGroupTime.setCreationTime(QDateTime::fromTime_t(createdAt, Qt::UTC)); + rootGroupTime.setCreationTime(QDateTime::fromSecsSinceEpoch(createdAt, Qt::UTC)); auto updatedAt = static_cast(profileJson["updatedAt"].toInt()); - rootGroupTime.setLastModificationTime(QDateTime::fromTime_t(updatedAt, Qt::UTC)); + rootGroupTime.setLastModificationTime(QDateTime::fromSecsSinceEpoch(updatedAt, Qt::UTC)); rootGroup->setUuid(Tools::hexToUuid(profileJson["uuid"].toString())); QScopedPointer derivedKeys(deriveKeysFromPassPhrase(salt, password, iterations)); @@ -238,12 +238,12 @@ bool OpVaultReader::processFolderJson(QJsonObject& foldersJson, Group* rootGroup bool timeInfoOk = false; if (folder.contains("created")) { auto createdTime = static_cast(folder["created"].toInt()); - ti.setCreationTime(QDateTime::fromTime_t(createdTime, Qt::UTC)); + ti.setCreationTime(QDateTime::fromSecsSinceEpoch(createdTime, Qt::UTC)); timeInfoOk = true; } if (folder.contains("updated")) { auto updateTime = static_cast(folder["updated"].toInt()); - ti.setLastModificationTime(QDateTime::fromTime_t(updateTime, Qt::UTC)); + ti.setLastModificationTime(QDateTime::fromSecsSinceEpoch(updateTime, Qt::UTC)); timeInfoOk = true; } // "tx" is modified by sync, not by user; maybe a custom attribute? diff --git a/src/format/OpVaultReaderBandEntry.cpp b/src/format/OpVaultReaderBandEntry.cpp index 3a9774b68..7d6088e32 100644 --- a/src/format/OpVaultReaderBandEntry.cpp +++ b/src/format/OpVaultReaderBandEntry.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -61,7 +61,7 @@ bool OpVaultReader::decryptBandEntry(const QJsonObject& bandEntry, QByteArray kBA = QByteArray::fromBase64(entKStr.toUtf8()); const int wantKsize = 16 + 32 + 32 + 32; if (kBA.size() != wantKsize) { - qCritical("Malformed \"k\" size; expected %d got %d\n", wantKsize, kBA.size()); + qCritical("Malformed \"k\" size; expected %d got %" PRIdQPTRDIFF "\n", wantKsize, kBA.size()); return false; } @@ -150,12 +150,12 @@ Entry* OpVaultReader::processBandEntry(const QJsonObject& bandEntry, const QDir& bool timeInfoOk = false; if (bandEntry.contains("created")) { auto createdTime = static_cast(bandEntry["created"].toInt()); - ti.setCreationTime(QDateTime::fromTime_t(createdTime, Qt::UTC)); + ti.setCreationTime(QDateTime::fromSecsSinceEpoch(createdTime, Qt::UTC)); timeInfoOk = true; } if (bandEntry.contains("updated")) { auto updateTime = static_cast(bandEntry["updated"].toInt()); - ti.setLastModificationTime(QDateTime::fromTime_t(updateTime, Qt::UTC)); + ti.setLastModificationTime(QDateTime::fromSecsSinceEpoch(updateTime, Qt::UTC)); timeInfoOk = true; } // "tx" is modified by sync, not by user; maybe a custom attribute? diff --git a/src/format/OpVaultReaderSections.cpp b/src/format/OpVaultReaderSections.cpp index 02566a542..ecaaf9934 100644 --- a/src/format/OpVaultReaderSections.cpp +++ b/src/format/OpVaultReaderSections.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,9 +37,9 @@ namespace date = QDateTime::fromString(dateValue, "yyyyMM"); date.setTimeSpec(Qt::UTC); } else if (value.isString()) { - date = QDateTime::fromTime_t(value.toString().toUInt(), Qt::UTC); + date = QDateTime::fromSecsSinceEpoch(value.toString().toUInt(), Qt::UTC); } else { - date = QDateTime::fromTime_t(value.toInt(), Qt::UTC); + date = QDateTime::fromSecsSinceEpoch(value.toInt(), Qt::UTC); } return date; } diff --git a/src/gui/DatabaseIcons.h b/src/gui/DatabaseIcons.h index 38d1590c7..ddcdc2568 100644 --- a/src/gui/DatabaseIcons.h +++ b/src/gui/DatabaseIcons.h @@ -1,4 +1,5 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2010 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -18,6 +19,7 @@ #ifndef KEEPASSX_DATABASEICONS_H #define KEEPASSX_DATABASEICONS_H +#include #include enum IconSize diff --git a/src/gui/DatabaseOpenDialog.cpp b/src/gui/DatabaseOpenDialog.cpp index 881db4087..db83d3502 100644 --- a/src/gui/DatabaseOpenDialog.cpp +++ b/src/gui/DatabaseOpenDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,10 +25,6 @@ #include #include -#ifdef Q_OS_WIN -#include -#endif - DatabaseOpenDialog::DatabaseOpenDialog(QWidget* parent) : QDialog(parent) , m_view(new DatabaseOpenWidget(this)) @@ -43,9 +39,7 @@ DatabaseOpenDialog::DatabaseOpenDialog(QWidget* parent) #endif // block input to the main window/application while the dialog is open setWindowModality(Qt::ApplicationModal); -#ifdef Q_OS_WIN - QWindowsWindowFunctions::setWindowActivationBehavior(QWindowsWindowFunctions::AlwaysActivateWindow); -#endif + connect(m_view, &DatabaseOpenWidget::dialogFinished, this, &DatabaseOpenDialog::complete); m_tabBar->setAutoHide(true); @@ -66,16 +60,16 @@ DatabaseOpenDialog::DatabaseOpenDialog(QWidget* parent) #ifdef Q_OS_MACOS dbTabModifier = Qt::ALT; #endif - auto* shortcut = new QShortcut(Qt::CTRL + Qt::Key_PageUp, this); + auto* shortcut = new QShortcut(Qt::CTRL | Qt::Key_PageUp, this); shortcut->setContext(Qt::WidgetWithChildrenShortcut); connect(shortcut, &QShortcut::activated, this, [this]() { selectTabOffset(-1); }); - shortcut = new QShortcut(dbTabModifier + Qt::SHIFT + Qt::Key_Tab, this); + shortcut = new QShortcut(dbTabModifier | Qt::SHIFT | Qt::Key_Tab, this); shortcut->setContext(Qt::WidgetWithChildrenShortcut); connect(shortcut, &QShortcut::activated, this, [this]() { selectTabOffset(-1); }); - shortcut = new QShortcut(Qt::CTRL + Qt::Key_PageDown, this); + shortcut = new QShortcut(Qt::CTRL | Qt::Key_PageDown, this); shortcut->setContext(Qt::WidgetWithChildrenShortcut); connect(shortcut, &QShortcut::activated, this, [this]() { selectTabOffset(1); }); - shortcut = new QShortcut(dbTabModifier + Qt::Key_Tab, this); + shortcut = new QShortcut(dbTabModifier | Qt::Key_Tab, this); shortcut->setContext(Qt::WidgetWithChildrenShortcut); connect(shortcut, &QShortcut::activated, this, [this]() { selectTabOffset(1); }); } @@ -142,7 +136,7 @@ void DatabaseOpenDialog::tabChanged(int index) setTarget(dbWidget, dbWidget->database()->filePath()); } else { // if these list sizes don't match, there's a bug somewhere nearby - qWarning("DatabaseOpenDialog: mismatch between tab count %d and DB count %d", + qWarning("DatabaseOpenDialog: mismatch between tab count %d and DB count %" PRIdQSIZETYPE "", m_tabBar->count(), m_tabDbWidgets.count()); } diff --git a/src/gui/DatabaseTabWidget.h b/src/gui/DatabaseTabWidget.h index bc0fc67fd..5f71fb4d7 100644 --- a/src/gui/DatabaseTabWidget.h +++ b/src/gui/DatabaseTabWidget.h @@ -15,8 +15,8 @@ * along with this program. If not, see . */ -#ifndef KEEPASSX_DATABASETABWIDGET_H -#define KEEPASSX_DATABASETABWIDGET_H +#ifndef KEEPASSXC_DATABASETABWIDGET_H +#define KEEPASSXC_DATABASETABWIDGET_H #include "DatabaseOpenDialog.h" #include "config-keepassx.h" @@ -129,4 +129,4 @@ private: bool m_databaseOpenInProgress; }; -#endif // KEEPASSX_DATABASETABWIDGET_H +#endif // KEEPASSXC_DATABASETABWIDGET_H diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index de69746db..6e880c2e5 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2010 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -125,7 +125,7 @@ DatabaseWidget::DatabaseWidget(QSharedPointer db, QWidget* parent) tagsWidget->setLayout(tagsLayout); tagsLayout->addWidget(tagsTitle); tagsLayout->addWidget(m_tagView); - tagsLayout->setMargin(0); + tagsLayout->setContentsMargins(0, 0, 0, 0); m_groupSplitter->setOrientation(Qt::Vertical); m_groupSplitter->setChildrenCollapsible(true); @@ -139,7 +139,7 @@ DatabaseWidget::DatabaseWidget(QSharedPointer db, QWidget* parent) auto rightHandSideWidget = new QWidget(m_mainSplitter); auto rightHandSideVBox = new QVBoxLayout(); - rightHandSideVBox->setMargin(0); + rightHandSideVBox->setContentsMargins(0, 0, 0, 0); rightHandSideVBox->addWidget(m_searchingLabel); rightHandSideVBox->addWidget(m_shareLabel); rightHandSideVBox->addWidget(m_previewSplitter); @@ -1035,15 +1035,11 @@ void DatabaseWidget::openUrlForEntry(Entry* entry) if (launch) { const QString cmd = cmdString.mid(6); -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) QStringList cmdList = QProcess::splitCommand(cmd); if (!cmdList.isEmpty()) { const QString program = cmdList.takeFirst(); QProcess::startDetached(program, cmdList); } -#else - QProcess::startDetached(cmd); -#endif if (config()->get(Config::MinimizeOnOpenUrl).toBool()) { getMainWindow()->minimizeOrHide(); diff --git a/src/gui/Icons.cpp b/src/gui/Icons.cpp index 21e119f90..cdb553fb2 100644 --- a/src/gui/Icons.cpp +++ b/src/gui/Icons.cpp @@ -26,6 +26,7 @@ #include +#include "config-keepassx.h" #include "core/Config.h" #include "core/Database.h" #include "gui/DatabaseIcons.h" diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 68bfcfd5c..9b39a62e4 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2010 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -273,29 +273,6 @@ MainWindow::MainWindow() connect(m_inactivityTimer, SIGNAL(inactivityDetected()), this, SLOT(lockAllDatabases())); applySettingsChanges(); - // Qt 5.10 introduced a new "feature" to hide shortcuts in context menus - // Unfortunately, Qt::AA_DontShowShortcutsInContextMenus is broken, have to manually enable them - m_ui->actionEntryNew->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryEdit->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryExpire->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryDelete->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryRestore->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryClone->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryTotp->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryDownloadIcon->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryCopyTotp->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryCopyPasswordTotp->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryMoveUp->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryMoveDown->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryCopyUsername->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryCopyPassword->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryAutoTypeSequence->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryOpenUrl->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryCopyURL->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryCopyTitle->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryAddToAgent->setShortcutVisibleInContextMenu(true); - m_ui->actionEntryRemoveFromAgent->setShortcutVisibleInContextMenu(true); - connect(m_ui->menuEntries, SIGNAL(aboutToShow()), SLOT(obtainContextFocusLock())); connect(m_ui->menuEntries, SIGNAL(aboutToHide()), SLOT(releaseContextFocusLock())); connect(m_entryContextMenu, SIGNAL(aboutToShow()), SLOT(obtainContextFocusLock())); @@ -306,18 +283,18 @@ MainWindow::MainWindow() connect(m_ui->menuGroups, SIGNAL(aboutToHide()), SLOT(releaseContextFocusLock())); // Control window state - new QShortcut(Qt::CTRL + Qt::Key_M, this, SLOT(minimizeOrHide())); - new QShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_M, this, SLOT(hideWindow())); + new QShortcut(Qt::CTRL | Qt::Key_M, this, SLOT(minimizeOrHide())); + new QShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_M, this, SLOT(hideWindow())); // Control database tabs // Ctrl+Tab is broken on Mac, so use Alt (i.e. the Option key) - https://bugreports.qt.io/browse/QTBUG-8596 auto dbTabModifier2 = Qt::CTRL; #ifdef Q_OS_MACOS dbTabModifier2 = Qt::ALT; #endif - new QShortcut(dbTabModifier2 + Qt::Key_Tab, this, SLOT(selectNextDatabaseTab())); - new QShortcut(Qt::CTRL + Qt::Key_PageDown, this, SLOT(selectNextDatabaseTab())); - new QShortcut(dbTabModifier2 + Qt::SHIFT + Qt::Key_Tab, this, SLOT(selectPreviousDatabaseTab())); - new QShortcut(Qt::CTRL + Qt::Key_PageUp, this, SLOT(selectPreviousDatabaseTab())); + new QShortcut(dbTabModifier2 | Qt::Key_Tab, this, SLOT(selectNextDatabaseTab())); + new QShortcut(Qt::CTRL | Qt::Key_PageDown, this, SLOT(selectNextDatabaseTab())); + new QShortcut(dbTabModifier2 | Qt::SHIFT | Qt::Key_Tab, this, SLOT(selectPreviousDatabaseTab())); + new QShortcut(Qt::CTRL | Qt::Key_PageUp, this, SLOT(selectPreviousDatabaseTab())); // Tab selection by number, Windows uses Ctrl, macOS uses Command, // and Linux uses Alt to emulate a browser-like experience @@ -325,23 +302,23 @@ MainWindow::MainWindow() #ifdef Q_OS_LINUX dbTabModifier = Qt::ALT; #endif - auto shortcut = new QShortcut(dbTabModifier + Qt::Key_1, this); + auto shortcut = new QShortcut(dbTabModifier | Qt::Key_1, this); connect(shortcut, &QShortcut::activated, [this]() { selectDatabaseTab(0); }); - shortcut = new QShortcut(dbTabModifier + Qt::Key_2, this); + shortcut = new QShortcut(dbTabModifier | Qt::Key_2, this); connect(shortcut, &QShortcut::activated, [this]() { selectDatabaseTab(1); }); - shortcut = new QShortcut(dbTabModifier + Qt::Key_3, this); + shortcut = new QShortcut(dbTabModifier | Qt::Key_3, this); connect(shortcut, &QShortcut::activated, [this]() { selectDatabaseTab(2); }); - shortcut = new QShortcut(dbTabModifier + Qt::Key_4, this); + shortcut = new QShortcut(dbTabModifier | Qt::Key_4, this); connect(shortcut, &QShortcut::activated, [this]() { selectDatabaseTab(3); }); - shortcut = new QShortcut(dbTabModifier + Qt::Key_5, this); + shortcut = new QShortcut(dbTabModifier | Qt::Key_5, this); connect(shortcut, &QShortcut::activated, [this]() { selectDatabaseTab(4); }); - shortcut = new QShortcut(dbTabModifier + Qt::Key_6, this); + shortcut = new QShortcut(dbTabModifier | Qt::Key_6, this); connect(shortcut, &QShortcut::activated, [this]() { selectDatabaseTab(5); }); - shortcut = new QShortcut(dbTabModifier + Qt::Key_7, this); + shortcut = new QShortcut(dbTabModifier | Qt::Key_7, this); connect(shortcut, &QShortcut::activated, [this]() { selectDatabaseTab(6); }); - shortcut = new QShortcut(dbTabModifier + Qt::Key_8, this); + shortcut = new QShortcut(dbTabModifier | Qt::Key_8, this); connect(shortcut, &QShortcut::activated, [this]() { selectDatabaseTab(7); }); - shortcut = new QShortcut(dbTabModifier + Qt::Key_9, this); + shortcut = new QShortcut(dbTabModifier | Qt::Key_9, this); connect(shortcut, &QShortcut::activated, [this]() { selectDatabaseTab(m_ui->tabWidget->count() - 1); }); m_ui->actionDatabaseNew->setIcon(icons()->icon("document-new")); @@ -2176,8 +2153,8 @@ void MainWindow::initActionCollection() // Prevent conflicts with global Mac shortcuts (force Control on all platforms) // Note: Qt::META means Ctrl on Mac. #ifdef Q_OS_MAC - ac->setDefaultShortcut(m_ui->actionEntryAddToAgent, Qt::META + Qt::Key_H); - ac->setDefaultShortcut(m_ui->actionEntryRemoveFromAgent, Qt::META + Qt::SHIFT + Qt::Key_H); + ac->setDefaultShortcut(m_ui->actionEntryAddToAgent, Qt::META | Qt::Key_H); + ac->setDefaultShortcut(m_ui->actionEntryRemoveFromAgent, Qt::META | Qt::SHIFT | Qt::Key_H); #endif QTimer::singleShot(1, ac, &ActionCollection::restoreShortcuts); @@ -2222,8 +2199,6 @@ bool MainWindowEventFilter::eventFilter(QObject* watched, QEvent* event) auto eventType = event->type(); if (eventType == QEvent::MouseButtonPress) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) - // startSystemMove was introduced in Qt 5.15 auto mouseEvent = dynamic_cast(event); if (watched == mainWindow->m_ui->menubar) { if (!mainWindow->m_ui->menubar->actionAt(mouseEvent->pos())) { @@ -2241,7 +2216,6 @@ bool MainWindowEventFilter::eventFilter(QObject* watched, QEvent* event) return true; } } -#endif } else if (eventType == QEvent::KeyRelease && watched == mainWindow) { #ifdef Q_OS_MACOS // On macOS, the menubar is always visible, so no need to toggle it diff --git a/src/gui/MergeDialog.cpp b/src/gui/MergeDialog.cpp index ed8ab3c16..0467340aa 100644 --- a/src/gui/MergeDialog.cpp +++ b/src/gui/MergeDialog.cpp @@ -184,7 +184,7 @@ void MergeDialog::performMerge() { auto changes = Merger(m_sourceDatabase.data(), m_targetDatabase.data()).merge(); if (changes != m_changes) { - qWarning("Merge results differed from the expected changes. Expected: %d, Actual: %d", + qWarning("Merge results differed from the expected changes. Expected: %lld, Actual: %lld", m_changes.size(), changes.size()); } diff --git a/src/gui/MessageBox.cpp b/src/gui/MessageBox.cpp index 87898ff5c..5a67b4f53 100644 --- a/src/gui/MessageBox.cpp +++ b/src/gui/MessageBox.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2013 Felix Geyer - * Copyright (C) 2018 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,6 +19,7 @@ #include "MessageBox.h" #include +#include #include #include #include diff --git a/src/gui/PasswordGeneratorWidget.cpp b/src/gui/PasswordGeneratorWidget.cpp index d3dd7d699..0bc2d7d1e 100644 --- a/src/gui/PasswordGeneratorWidget.cpp +++ b/src/gui/PasswordGeneratorWidget.cpp @@ -77,7 +77,7 @@ PasswordGeneratorWidget::PasswordGeneratorWidget(QWidget* parent) connect(m_ui->editWordSeparator, SIGNAL(textChanged(QString)), SLOT(updateGenerator())); connect(m_ui->comboBoxWordList, SIGNAL(currentIndexChanged(int)), SLOT(updateGenerator())); - connect(m_ui->optionButtons, SIGNAL(buttonClicked(int)), SLOT(updateGenerator())); + connect(m_ui->optionButtons, SIGNAL(buttonClicked(QAbstractButton*)), SLOT(updateGenerator())); connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(updateGenerator())); connect(m_ui->wordCaseComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateGenerator())); diff --git a/src/gui/UrlTools.cpp b/src/gui/UrlTools.cpp index fafebd7b9..5fda8ed1d 100644 --- a/src/gui/UrlTools.cpp +++ b/src/gui/UrlTools.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2025 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -191,7 +191,7 @@ bool UrlTools::isUrlValid(const QString& urlField, bool looseComparison) const return false; } -#if defined(KPXC_FEATURE_NETWORK) || defined(KPXC_FEATURE_BROWSER) +#if defined(KPXC_FEATURE_BROWSER) // Prevent TLD wildcards if (looseComparison && url.contains(UrlTools::URL_WILDCARD)) { const auto tld = getTopLevelDomainFromUrl(url); diff --git a/src/gui/dbsettings/DatabaseSettingsWidgetDatabaseKey.cpp b/src/gui/dbsettings/DatabaseSettingsWidgetDatabaseKey.cpp index 251a0b273..b41ca1fe2 100644 --- a/src/gui/dbsettings/DatabaseSettingsWidgetDatabaseKey.cpp +++ b/src/gui/dbsettings/DatabaseSettingsWidgetDatabaseKey.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -53,7 +53,7 @@ DatabaseSettingsWidgetDatabaseKey::DatabaseSettingsWidgetDatabaseKey(QWidget* pa vbox->addWidget(m_additionalKeyOptions); vbox->setSizeConstraint(QLayout::SetMinimumSize); m_additionalKeyOptions->setLayout(new QVBoxLayout()); - m_additionalKeyOptions->layout()->setMargin(0); + m_additionalKeyOptions->layout()->setContentsMargins(0, 0, 0, 0); m_additionalKeyOptions->layout()->setSpacing(20); m_additionalKeyOptions->layout()->addWidget(m_keyFileEditWidget); m_additionalKeyOptions->layout()->addWidget(m_yubiKeyEditWidget); diff --git a/src/gui/entry/EntryAttachmentsWidget.cpp b/src/gui/entry/EntryAttachmentsWidget.cpp index d13074f03..494b9f54d 100644 --- a/src/gui/entry/EntryAttachmentsWidget.cpp +++ b/src/gui/entry/EntryAttachmentsWidget.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -368,7 +368,7 @@ void EntryAttachmentsWidget::saveSelectedAttachments() QStringList errors; for (const QModelIndex& index : indexes) { QString attachmentKey = m_attachmentsModel->keyByIndex(index); - const QString fileNameSanitized = attachmentKey.replace(QRegExp("[/\\\\]"), ""); + const QString fileNameSanitized = attachmentKey.replace(QRegularExpression("[/\\\\]"), ""); const QString attachmentPath = saveDir.absoluteFilePath(fileNameSanitized); if (QFileInfo::exists(attachmentPath)) { diff --git a/src/gui/entry/EntryModel.cpp b/src/gui/entry/EntryModel.cpp index 9ae51743d..34723485f 100644 --- a/src/gui/entry/EntryModel.cpp +++ b/src/gui/entry/EntryModel.cpp @@ -1,4 +1,5 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2010 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -18,6 +19,7 @@ #include "EntryModel.h" #include +#include #include #include @@ -26,7 +28,6 @@ #include "core/Group.h" #include "core/Metadata.h" #include "core/PasswordHealth.h" -#include "gui/DatabaseIcons.h" #include "gui/Icons.h" #include "gui/styles/StateColorPalette.h" #ifdef Q_OS_MACOS @@ -253,12 +254,8 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const } case Expires: return entry->timeInfo().expires() ? entry->timeInfo().expiryTime() - // There seems to be no better way of expressing 'infinity' -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + // There seems to be no better way of expressing 'infinity' : QDate(9999, 1, 1).startOfDay(); -#else - : QDateTime(QDate(9999, 1, 1)); -#endif case Created: return entry->timeInfo().creationTime(); case Modified: diff --git a/src/gui/entry/EntryView.cpp b/src/gui/entry/EntryView.cpp index 2c176eccf..2f7a0aeff 100644 --- a/src/gui/entry/EntryView.cpp +++ b/src/gui/entry/EntryView.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2010 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -19,13 +19,13 @@ #include "EntryView.h" #include +#include #include #include #include #include #include #include -#include #include #include #include @@ -94,8 +94,8 @@ EntryView::EntryView(QWidget* parent) emit entrySelectionChanged(currentEntry()); }); - new QShortcut(Qt::CTRL + Qt::Key_F10, this, SLOT(contextMenuShortcutPressed()), nullptr, Qt::WidgetShortcut); - new QShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_J, this, SLOT(jumpToGroupShortcut()), nullptr, Qt::WidgetShortcut); + new QShortcut(Qt::CTRL | Qt::Key_F10, this, SLOT(contextMenuShortcutPressed()), nullptr, Qt::WidgetShortcut); + new QShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_J, this, SLOT(jumpToGroupShortcut()), nullptr, Qt::WidgetShortcut); resetViewToDefaults(); diff --git a/src/gui/entry/attachments/TextAttachmentsPreviewWidget.cpp b/src/gui/entry/attachments/TextAttachmentsPreviewWidget.cpp index 9ec105ea2..c00437d74 100644 --- a/src/gui/entry/attachments/TextAttachmentsPreviewWidget.cpp +++ b/src/gui/entry/attachments/TextAttachmentsPreviewWidget.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2025 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,11 +36,9 @@ namespace return TextAttachmentsPreviewWidget::Html; } -#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) if (mimeType == Tools::MimeType::Markdown) { return TextAttachmentsPreviewWidget::Markdown; } -#endif return TextAttachmentsPreviewWidget::PlainText; } @@ -141,11 +139,9 @@ void TextAttachmentsPreviewWidget::onTypeChanged(int index) m_ui->previewTextBrowser->setHtml(m_attachment.data); } -#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) if (fileType == TextAttachmentsPreviewWidget::PreviewTextType::Markdown) { m_ui->previewTextBrowser->setMarkdown(m_attachment.data); } -#endif // Delay setting the scrollbar position to ensure the text is rendered first QTimer::singleShot( diff --git a/src/gui/entry/attachments/TextAttachmentsPreviewWidget.h b/src/gui/entry/attachments/TextAttachmentsPreviewWidget.h index 737a56732..1a5d9f4bc 100644 --- a/src/gui/entry/attachments/TextAttachmentsPreviewWidget.h +++ b/src/gui/entry/attachments/TextAttachmentsPreviewWidget.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2025 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,9 +41,7 @@ public: { Html, PlainText, -#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) Markdown -#endif }; Q_ENUM(PreviewTextType) diff --git a/src/gui/group/GroupView.cpp b/src/gui/group/GroupView.cpp index 46cc0af6a..d088c55db 100644 --- a/src/gui/group/GroupView.cpp +++ b/src/gui/group/GroupView.cpp @@ -1,4 +1,5 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2010 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -44,16 +45,16 @@ GroupView::GroupView(Database* db, QWidget* parent) connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SIGNAL(groupSelectionChanged())); // clang-format on - new QShortcut(Qt::CTRL + Qt::Key_F10, this, SLOT(contextMenuShortcutPressed()), nullptr, Qt::WidgetShortcut); + new QShortcut(Qt::CTRL | Qt::Key_F10, this, SLOT(contextMenuShortcutPressed()), nullptr, Qt::WidgetShortcut); new QShortcut( - Qt::CTRL + Qt::SHIFT + Qt::Key_PageUp, this, SLOT(selectPreviousGroup()), nullptr, Qt::WindowShortcut); - new QShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_PageDown, this, SLOT(selectNextGroup()), nullptr, Qt::WindowShortcut); + Qt::CTRL | Qt::SHIFT | Qt::Key_PageUp, this, SLOT(selectPreviousGroup()), nullptr, Qt::WindowShortcut); + new QShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_PageDown, this, SLOT(selectNextGroup()), nullptr, Qt::WindowShortcut); // keyboard shortcuts to sort children of a group - auto shortcut = new QShortcut(Qt::CTRL + Qt::Key_Down, this, nullptr, nullptr, Qt::WidgetShortcut); + auto shortcut = new QShortcut(Qt::CTRL | Qt::Key_Down, this, nullptr, nullptr, Qt::WidgetShortcut); connect(shortcut, &QShortcut::activated, this, [this]() { sortGroups(false); }); - shortcut = new QShortcut(Qt::CTRL + Qt::Key_Up, this, nullptr, nullptr, Qt::WidgetShortcut); + shortcut = new QShortcut(Qt::CTRL | Qt::Key_Up, this, nullptr, nullptr, Qt::WidgetShortcut); connect(shortcut, &QShortcut::activated, this, [this]() { sortGroups(true); }); modelReset(); diff --git a/src/gui/osutils/macutils/MacPasteboard.cpp b/src/gui/osutils/macutils/MacPasteboard.cpp index ae63ea4e4..a219c7b5e 100644 --- a/src/gui/osutils/macutils/MacPasteboard.cpp +++ b/src/gui/osutils/macutils/MacPasteboard.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,23 +17,18 @@ #include "MacPasteboard.h" -QString MacPasteboard::convertorName() +QString MacPasteboard::utiForMime(const QString& mime) const { - return QLatin1String("MacPasteboard"); -} - -QString MacPasteboard::flavorFor(const QString& mimetype) -{ - if (mimetype == QLatin1String("text/plain")) { + if (mime == QLatin1String("text/plain")) { return QLatin1String("public.utf8-plain-text"); - } else if (mimetype == QLatin1String("application/x-nspasteboard-concealed-type")) { + } else if (mime == QLatin1String("application/x-nspasteboard-concealed-type")) { return QLatin1String("org.nspasteboard.ConcealedType"); } - int i = mimetype.indexOf(QLatin1String("charset=")); + int i = mime.indexOf(QLatin1String("charset=")); if (i >= 0) { - QString cs(mimetype.mid(i + 8).toLower()); + QString cs(mime.mid(i + 8).toLower()); i = cs.indexOf(QLatin1Char(';')); if (i >= 0) { @@ -46,54 +41,61 @@ QString MacPasteboard::flavorFor(const QString& mimetype) return QLatin1String("public.utf16-plain-text"); } } - return QString(); + return {}; } -QString MacPasteboard::mimeFor(QString flavor) +QString MacPasteboard::mimeForUti(const QString& uti) const { - if (flavor == QLatin1String("public.utf8-plain-text")) + if (uti == QLatin1String("public.utf8-plain-text")) return QLatin1String("text/plain"); - if (flavor == QLatin1String("org.nspasteboard.ConcealedType")) + if (uti == QLatin1String("org.nspasteboard.ConcealedType")) return QLatin1String("application/x-nspasteboard-concealed-type"); - if (flavor == QLatin1String("public.utf16-plain-text")) + if (uti == QLatin1String("public.utf16-plain-text")) return QLatin1String("text/plain;charset=utf16"); - return QString(); + return {}; } -bool MacPasteboard::canConvert(const QString& mimetype, QString flavor) +bool MacPasteboard::canConvert(const QString& mime, const QString& uti) const { - Q_UNUSED(mimetype); - Q_UNUSED(flavor); + Q_UNUSED(mime); + Q_UNUSED(uti); return true; } -QVariant MacPasteboard::convertToMime(const QString& mimetype, QList data, QString flavor) +QVariant MacPasteboard::convertToMime(const QString& mime, const QList& data, const QString& uti) const { if (data.count() > 1) qWarning("QMime::convertToMime: Cannot handle multiple member data"); const QByteArray& firstData = data.first(); QVariant ret; - if (flavor == QLatin1String("public.utf8-plain-text")) { + if (uti == QLatin1String("public.utf8-plain-text")) { ret = QString::fromUtf8(firstData); - } else if (flavor == QLatin1String("org.nspasteboard.ConcealedType")) { + } else if (uti == QLatin1String("org.nspasteboard.ConcealedType")) { ret = QString::fromUtf8(firstData); - } else if (flavor == QLatin1String("public.utf16-plain-text")) { - ret = QTextCodec::codecForName("UTF-16")->toUnicode(firstData); + } else if (uti == QLatin1String("public.utf16-plain-text")) { + auto toUtf16 = QStringDecoder(QStringDecoder::Utf16); + QVariant var{toUtf16(firstData)}; + return var; } else { - qWarning("QMime::convertToMime: unhandled mimetype: %s", qPrintable(mimetype)); + qWarning("QMime::convertToMime: unhandled mimetype: %s", qPrintable(mime)); } return ret; } -QList MacPasteboard::convertFromMime(const QString&, QVariant data, QString flavor) +QList MacPasteboard::convertFromMime(const QString& mime, const QVariant& data, const QString& uti) const { + Q_UNUSED(mime); + QList ret; - QString string = data.toString(); - if (flavor == QLatin1String("public.utf8-plain-text")) - ret.append(string.toUtf8()); - else if (flavor == QLatin1String("org.nspasteboard.ConcealedType")) - ret.append(string.toUtf8()); - else if (flavor == QLatin1String("public.utf16-plain-text")) - ret.append(QTextCodec::codecForName("UTF-16")->fromUnicode(string)); + QString dataString = data.toString(); + if (uti == QLatin1String("public.utf8-plain-text")) { + ret.append(dataString.toUtf8()); + } else if (uti == QLatin1String("org.nspasteboard.ConcealedType")) { + ret.append(dataString.toUtf8()); + } else if (uti == QLatin1String("public.utf16-plain-text")) { + auto toUtf16 = QStringEncoder(QStringDecoder::Utf16); + QByteArray baUtf16 = toUtf16(dataString); + ret.append(baUtf16); + } return ret; } diff --git a/src/gui/osutils/macutils/MacPasteboard.h b/src/gui/osutils/macutils/MacPasteboard.h index 503741ca8..3faea3d54 100644 --- a/src/gui/osutils/macutils/MacPasteboard.h +++ b/src/gui/osutils/macutils/MacPasteboard.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,23 +19,23 @@ #define KEEPASSXC_MACPASTEBOARD_H #include -#include -#include +#include +#include +#include -class MacPasteboard : public QObject, public QMacPasteboardMime +class MacPasteboard : public QObject, public QUtiMimeConverter { public: explicit MacPasteboard() - : QMacPasteboardMime(MIME_ALL) + : QUtiMimeConverter() { } - QString convertorName() override; - bool canConvert(const QString& mime, QString flav) override; - QString mimeFor(QString flav) override; - QString flavorFor(const QString& mime) override; - QVariant convertToMime(const QString& mime, QList data, QString flav) override; - QList convertFromMime(const QString& mime, QVariant data, QString flav) override; + bool canConvert(const QString& mime, const QString& uti) const; + QString mimeForUti(const QString& uti) const override; + QString utiForMime(const QString& mime) const override; + QVariant convertToMime(const QString& mime, const QList& data, const QString& uti) const override; + QList convertFromMime(const QString& mime, const QVariant& data, const QString& uti) const override; }; #endif // KEEPASSXC_MACPASTEBOARD_H diff --git a/src/gui/osutils/macutils/MacUtils.h b/src/gui/osutils/macutils/MacUtils.h index 403419301..1527e7ff4 100644 --- a/src/gui/osutils/macutils/MacUtils.h +++ b/src/gui/osutils/macutils/MacUtils.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2012 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -24,6 +24,7 @@ #include #include +#include #include #include #include diff --git a/src/gui/osutils/nixutils/NixUtils.cpp b/src/gui/osutils/nixutils/NixUtils.cpp index 89b91e25e..dbdc7bd17 100644 --- a/src/gui/osutils/nixutils/NixUtils.cpp +++ b/src/gui/osutils/nixutils/NixUtils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,9 +31,7 @@ #include #include #ifdef WITH_X11 -#include - -#include +#include #include "X11Funcs.h" #include @@ -68,8 +66,10 @@ NixUtils::NixUtils(QObject* parent) : OSUtilsBase(parent) { #ifdef WITH_X11 - dpy = QX11Info::display(); - rootWindow = QX11Info::appRootWindow(); + if (auto* native = qGuiApp->nativeInterface()) { + dpy = native->display(); + rootWindow = DefaultRootWindow(dpy); + } #endif // notify about system color scheme changes @@ -148,7 +148,6 @@ void NixUtils::setLaunchAtStartup(bool enable) const QString executeablePathOrName = isAppImage ? appImagePath : QApplication::applicationName().toLower(); QTextStream stream(&desktopFile); - stream.setCodec("UTF-8"); stream << QStringLiteral("[Desktop Entry]") << '\n' << QStringLiteral("Name=") << QApplication::applicationDisplayName() << '\n' << QStringLiteral("GenericName=") << tr("Password Manager") << '\n' @@ -215,17 +214,18 @@ void NixUtils::launchAtStartupRequested(uint response, const QVariantMap& result bool NixUtils::isCapslockEnabled() { #ifdef WITH_X11 - QPlatformNativeInterface* native = QGuiApplication::platformNativeInterface(); - auto* display = native->nativeResourceForWindow("display", nullptr); - if (!display) { - return false; - } + if (auto* native = qGuiApp->nativeInterface()) { + auto* display = native->display(); + if (!display) { + return false; + } - QString platform = QGuiApplication::platformName(); - if (platform == "xcb") { - unsigned state = 0; - if (XkbGetIndicatorState(reinterpret_cast(display), XkbUseCoreKbd, &state) == Success) { - return ((state & 1u) != 0); + auto platform = QGuiApplication::platformName(); + if (platform == "xcb") { + unsigned state = 0; + if (XkbGetIndicatorState(reinterpret_cast(display), XkbUseCoreKbd, &state) == Success) { + return ((state & 1u) != 0); + } } } #endif @@ -246,8 +246,9 @@ void NixUtils::registerNativeEventFilter() qApp->installNativeEventFilter(this); } -bool NixUtils::nativeEventFilter(const QByteArray& eventType, void* message, long*) +bool NixUtils::nativeEventFilter(const QByteArray& eventType, void* message, qintptr* result) { + Q_UNUSED(result) #ifdef WITH_X11 if (eventType != QByteArrayLiteral("xcb_generic_event_t")) { return false; @@ -289,7 +290,7 @@ bool NixUtils::triggerGlobalShortcut(uint keycode, uint modifiers) bool NixUtils::registerGlobalShortcut(const QString& name, Qt::Key key, Qt::KeyboardModifiers modifiers, QString* error) { #ifdef WITH_X11 - auto keycode = XKeysymToKeycode(dpy, qcharToNativeKeyCode(key)); + auto keycode = XKeysymToKeycode(dpy, qtToNativeKeyCode(key)); auto modifierscode = qtToNativeModifiers(modifiers); // Check if this key combo is registered to another shortcut @@ -394,7 +395,7 @@ quint64 NixUtils::getProcessStartTime() const auto startIndex = processStatInfo.lastIndexOf(')'); if (startIndex != -1) { - auto tokens = processStatInfo.midRef(startIndex + 2).split(' '); + auto tokens = QStringView{processStatInfo}.mid(startIndex + 2).split(' '); if (tokens.size() >= 20) { bool ok; auto time = tokens[19].toULongLong(&ok); diff --git a/src/gui/osutils/nixutils/NixUtils.h b/src/gui/osutils/nixutils/NixUtils.h index 9be835ff9..98f1df701 100644 --- a/src/gui/osutils/nixutils/NixUtils.h +++ b/src/gui/osutils/nixutils/NixUtils.h @@ -61,7 +61,7 @@ private: explicit NixUtils(QObject* parent = nullptr); ~NixUtils() override; - bool nativeEventFilter(const QByteArray& eventType, void* message, long*) override; + bool nativeEventFilter(const QByteArray& eventType, void* message, qintptr* result) override; QString getAutostartDesktopFilename(bool createDirs = false) const; bool triggerGlobalShortcut(uint keycode, uint modifiers); diff --git a/src/gui/osutils/winutils/DeviceListenerWin.cpp b/src/gui/osutils/winutils/DeviceListenerWin.cpp index de805f215..644cc04ab 100644 --- a/src/gui/osutils/winutils/DeviceListenerWin.cpp +++ b/src/gui/osutils/winutils/DeviceListenerWin.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -80,8 +80,9 @@ void DeviceListenerWin::deregisterHotplugCallback() } } -bool DeviceListenerWin::nativeEventFilter(const QByteArray& eventType, void* message, long*) +bool DeviceListenerWin::nativeEventFilter(const QByteArray& eventType, void* message, qintptr* result) { + Q_UNUSED(result); if (eventType != "windows_generic_MSG") { return false; } diff --git a/src/gui/osutils/winutils/DeviceListenerWin.h b/src/gui/osutils/winutils/DeviceListenerWin.h index 527555d2f..7cc51634a 100644 --- a/src/gui/osutils/winutils/DeviceListenerWin.h +++ b/src/gui/osutils/winutils/DeviceListenerWin.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,7 +48,7 @@ public: const QUuid* deviceClass = nullptr); void deregisterHotplugCallback(); - bool nativeEventFilter(const QByteArray& eventType, void* message, long*) override; + bool nativeEventFilter(const QByteArray& eventType, void* message, qintptr* result) override; signals: void devicePlugged(bool state, void* ctx, void* device); diff --git a/src/gui/osutils/winutils/ScreenLockListenerWin.cpp b/src/gui/osutils/winutils/ScreenLockListenerWin.cpp index 05d01f4cc..d549d835c 100644 --- a/src/gui/osutils/winutils/ScreenLockListenerWin.cpp +++ b/src/gui/osutils/winutils/ScreenLockListenerWin.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -54,8 +54,9 @@ ScreenLockListenerWin::~ScreenLockListenerWin() } } -bool ScreenLockListenerWin::nativeEventFilter(const QByteArray& eventType, void* message, long*) +bool ScreenLockListenerWin::nativeEventFilter(const QByteArray& eventType, void* message, qintptr* result) { + Q_UNUSED(result); if (eventType == "windows_generic_MSG" || eventType == "windows_dispatcher_MSG") { MSG* m = static_cast(message); if (m->message == WM_POWERBROADCAST) { diff --git a/src/gui/osutils/winutils/ScreenLockListenerWin.h b/src/gui/osutils/winutils/ScreenLockListenerWin.h index e33f0e354..47a1f9687 100644 --- a/src/gui/osutils/winutils/ScreenLockListenerWin.h +++ b/src/gui/osutils/winutils/ScreenLockListenerWin.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,7 +29,7 @@ class ScreenLockListenerWin : public ScreenLockListenerPrivate, public QAbstract public: explicit ScreenLockListenerWin(QWidget* parent); ~ScreenLockListenerWin(); - virtual bool nativeEventFilter(const QByteArray& eventType, void* message, long* result) override; + virtual bool nativeEventFilter(const QByteArray& eventType, void* message, qintptr* result) override; private: void* m_powerNotificationHandle; diff --git a/src/gui/osutils/winutils/WinUtils.cpp b/src/gui/osutils/winutils/WinUtils.cpp index a15976932..269ed917e 100644 --- a/src/gui/osutils/winutils/WinUtils.cpp +++ b/src/gui/osutils/winutils/WinUtils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -74,8 +74,9 @@ void WinUtils::registerNativeEventFilter() qApp->installNativeEventFilter(this); } -bool WinUtils::nativeEventFilter(const QByteArray& eventType, void* message, long*) +bool WinUtils::nativeEventFilter(const QByteArray& eventType, void* message, qintptr* result) { + Q_UNUSED(result); if (eventType != "windows_generic_MSG") { return false; } diff --git a/src/gui/osutils/winutils/WinUtils.h b/src/gui/osutils/winutils/WinUtils.h index 9278c9d60..1c0907e1d 100644 --- a/src/gui/osutils/winutils/WinUtils.h +++ b/src/gui/osutils/winutils/WinUtils.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,6 +21,7 @@ #include "gui/osutils/OSUtilsBase.h" #include +#include #include #include #include @@ -65,7 +66,7 @@ protected: explicit WinUtils(QObject* parent = nullptr); ~WinUtils() override = default; - bool nativeEventFilter(const QByteArray& eventType, void* message, long*) override; + bool nativeEventFilter(const QByteArray& eventType, void* message, qintptr* result) override; void triggerGlobalShortcut(int id); private: diff --git a/src/gui/remote/DatabaseSettingsWidgetRemote.cpp b/src/gui/remote/DatabaseSettingsWidgetRemote.cpp index f66edba7e..27b96909e 100644 --- a/src/gui/remote/DatabaseSettingsWidgetRemote.cpp +++ b/src/gui/remote/DatabaseSettingsWidgetRemote.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,6 +25,8 @@ #include "RemoteSettings.h" #include "gui/MessageBox.h" +#include + DatabaseSettingsWidgetRemote::DatabaseSettingsWidgetRemote(QWidget* parent) : DatabaseSettingsWidget(parent) , m_remoteSettings(new RemoteSettings(nullptr, this)) diff --git a/src/gui/remote/RemoteProcess.cpp b/src/gui/remote/RemoteProcess.cpp index 6b2f60717..b92b7880d 100644 --- a/src/gui/remote/RemoteProcess.cpp +++ b/src/gui/remote/RemoteProcess.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,15 +37,11 @@ void RemoteProcess::setTempFileLocation(const QString& tempFile) void RemoteProcess::start(const QString& command) { const QString commandResolved = resolveTemplateVariables(command); -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) QStringList cmdList = QProcess::splitCommand(commandResolved); if (!cmdList.isEmpty()) { const QString program = cmdList.takeFirst(); m_process->start(program, cmdList); } -#else - m_process->start(resolveTemplateVariables(commandResolved)); -#endif m_process->waitForStarted(); } diff --git a/src/gui/remote/RemoteSettings.h b/src/gui/remote/RemoteSettings.h index 4b414494c..c1f61fc77 100644 --- a/src/gui/remote/RemoteSettings.h +++ b/src/gui/remote/RemoteSettings.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,6 +18,7 @@ #ifndef KEEPASSXC_REMOTESETTINGS_H #define KEEPASSXC_REMOTESETTINGS_H +#include #include #include diff --git a/src/gui/styles/base/BaseStyle.cpp b/src/gui/styles/base/BaseStyle.cpp index 471744c35..47efdd532 100644 --- a/src/gui/styles/base/BaseStyle.cpp +++ b/src/gui/styles/base/BaseStyle.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2019 Andrew Richards * * Derived from Phantomstyle and relicensed under the GPLv2 or v3. @@ -33,11 +33,11 @@ #include #include #include +#include #include #include #include #include -#include #ifdef Q_OS_MACOS #include @@ -270,22 +270,16 @@ namespace Phantom #ifdef Q_OS_MACOS QColor tabBarBase(const QPalette& pal) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 10) && QT_VERSION < QT_VERSION_CHECK(5, 13, 0) \ - || QT_VERSION >= QT_VERSION_CHECK(5, 15, 1) if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSBigSur) { return hack_isLightPalette(pal) ? QRgb(0xD4D4D4) : QRgb(0x2A2A2A); } -#endif return hack_isLightPalette(pal) ? QRgb(0xDD1D1D1) : QRgb(0x252525); } QColor tabBarBaseInactive(const QPalette& pal) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 10) && QT_VERSION < QT_VERSION_CHECK(5, 13, 0) \ - || QT_VERSION >= QT_VERSION_CHECK(5, 15, 1) if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSBigSur) { return hack_isLightPalette(pal) ? QRgb(0xF5F5F5) : QRgb(0x2D2D2D); } -#endif return hack_isLightPalette(pal) ? QRgb(0xF4F4F4) : QRgb(0x282828); } #endif @@ -514,22 +508,18 @@ namespace Phantom // generated changes. If that happens, change to use the definition of // `fastfragile_hash_qpalette` below, which is less likely to collide with an // arbitrarily numbered key but also does more work. -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - x.u = x.u ^ (static_cast(p.currentColorGroup()) << (64 - 3)); - return x.u; -#else + // Use this definition here if the contents/layout of QPalette::cacheKey() // (as in, the C++ code in qpalette.cpp) are changed. We'll also put a Qt6 // guard for it, so that it will default to a more safe definition on the // next guaranteed big breaking change for Qt. A warning will hopefully get // someone to double-check it at some point in the future. -#warning "Verify contents and layout of QPalette::cacheKey() have not changed" + // #warning "Verify contents and layout of QPalette::cacheKey() have not changed" QtPrivate::QHashCombine c; uint h = qHash(p.currentColorGroup()); - h = c(h, (uint)(x.u & 0xFFFFFFFFu)); - h = c(h, (uint)((x.u >> 32) & 0xFFFFFFFFu)); + h = c(h, static_cast(x.u & 0xFFFFFFFFu)); + h = c(h, static_cast((x.u >> 32) & 0xFFFFFFFFu)); return h; -#endif } // This hash function is for when we want an actual accurate hash of a @@ -873,7 +863,7 @@ namespace Phantom { QRect ra = bar->rect; QRect rb = ra; - bool isHorizontal = bar->orientation != Qt::Vertical; + bool isHorizontal = bar->state == QStyle::State_Horizontal; bool isInverted = bar->invertedAppearance; bool isIndeterminate = bar->minimum == 0 && bar->maximum == 0; bool isForward = !isHorizontal || bar->direction != Qt::RightToLeft; @@ -2571,7 +2561,7 @@ void BaseStyle::drawControl(ControlElement element, QRect r = bar->rect.adjusted(2, 2, -2, -2); if (r.isEmpty() || !r.isValid()) break; - QSize textSize = option->fontMetrics.size(Qt::TextBypassShaping, bar->text); + QSize textSize = option->fontMetrics.size(0, bar->text); QRect textRect = QStyle::alignedRect(option->direction, Qt::AlignCenter, textSize, option->rect); textRect &= r; if (textRect.isEmpty()) @@ -2745,10 +2735,10 @@ void BaseStyle::drawControl(ControlElement element, } // Draw main text and mnemonic text - QStringRef s(&menuItem->text); + QStringView s(menuItem->text); if (!s.isEmpty()) { - QRect textRect = - Ph::menuItemTextRect(metrics, option->direction, itemRect, hasSubMenu, hasIcon, menuItem->tabWidth); + QRect textRect = Ph::menuItemTextRect( + metrics, option->direction, itemRect, hasSubMenu, hasIcon, menuItem->reservedShortcutWidth); int t = s.indexOf(QLatin1Char('\t')); int text_flags = Qt::AlignLeft | Qt::AlignTop | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; @@ -2819,14 +2809,14 @@ void BaseStyle::drawControl(ControlElement element, // Draw mnemonic text if (t >= 0) { - QRect mnemonicR = - Ph::menuItemMnemonicRect(metrics, option->direction, itemRect, hasSubMenu, menuItem->tabWidth); - const QStringRef textToDrawRef = s.mid(t + 1); + QRect mnemonicR = Ph::menuItemMnemonicRect( + metrics, option->direction, itemRect, hasSubMenu, menuItem->reservedShortcutWidth); + const auto textToDrawRef = QStringView{s}.mid(t + 1); const QString unsafeTextToDraw = QString::fromRawData(textToDrawRef.constData(), textToDrawRef.size()); painter->drawText(mnemonicR, text_flags, unsafeTextToDraw); s = s.left(t); } - const QStringRef textToDrawRef = s.left(t); + const auto textToDrawRef = QStringView{s}.left(t); const QString unsafeTextToDraw = QString::fromRawData(textToDrawRef.constData(), textToDrawRef.size()); painter->drawText(textRect, text_flags, unsafeTextToDraw); @@ -4144,7 +4134,7 @@ QSize BaseStyle::sizeFromContents(ContentsType type, bool nullIcon = hdr->icon.isNull(); int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, hdr, widget); int iconSize = nullIcon ? 0 : option->fontMetrics.height(); - QSize txt = hdr->fontMetrics.size(Qt::TextSingleLine | Qt::TextBypassShaping, hdr->text); + QSize txt = hdr->fontMetrics.size(Qt::TextSingleLine, hdr->text); QSize sz; sz.setHeight(margin + qMax(iconSize, txt.height()) + margin); sz.setWidth((nullIcon ? 0 : margin) + iconSize + (hdr->text.isNull() ? 0 : margin) + txt.width() + margin); diff --git a/src/keeshare/CMakeLists.txt b/src/keeshare/CMakeLists.txt index 0a89ab778..5da855b50 100644 --- a/src/keeshare/CMakeLists.txt +++ b/src/keeshare/CMakeLists.txt @@ -1,3 +1,18 @@ +# Copyright (C) 2025 KeePassXC Team +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 or (at your option) +# version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + set(keeshare_SOURCES SettingsPageKeeShare.cpp SettingsWidgetKeeShare.cpp @@ -12,5 +27,5 @@ set(keeshare_SOURCES ) add_library(keeshare STATIC ${keeshare_SOURCES}) -target_link_libraries(keeshare PUBLIC Qt5::Core Qt5::Widgets ${BOTAN_LIBRARIES} ${ZLIB_LIBRARIES} PRIVATE ${MINIZIP_LIBRARIES}) +target_link_libraries(keeshare PUBLIC Qt6::Core Qt6::Widgets ${BOTAN_LIBRARIES} ${ZLIB_LIBRARIES} PRIVATE ${MINIZIP_LIBRARIES}) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/keeshare/KeeShareSettings.cpp b/src/keeshare/KeeShareSettings.cpp index 61ab2bb8e..10bb8cc76 100644 --- a/src/keeshare/KeeShareSettings.cpp +++ b/src/keeshare/KeeShareSettings.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,6 @@ #include "gui/DatabaseIcons.h" #include -#include #include #include @@ -41,7 +40,6 @@ namespace KeeShareSettings QString buffer; QXmlStreamWriter writer(&buffer); - writer.setCodec(QTextCodec::codecForName("UTF-8")); writer.writeStartDocument(); writer.writeStartElement("KeeShare"); specific(writer); @@ -53,7 +51,7 @@ namespace KeeShareSettings void xmlDeserialize(const QString& raw, std::function specific) { QXmlStreamReader reader(raw); - if (!reader.readNextStartElement() || reader.qualifiedName() != "KeeShare") { + if (!reader.readNextStartElement() || reader.qualifiedName().toString() != "KeeShare") { return; } specific(reader); @@ -106,9 +104,9 @@ namespace KeeShareSettings { Certificate certificate; while (!reader.error() && reader.readNextStartElement()) { - if (reader.name() == "Signer") { + if (reader.name().toString() == "Signer") { certificate.signer = reader.readElementText(); - } else if (reader.name() == "Key") { + } else if (reader.name().toString() == "Key") { auto rawKey = QByteArray::fromBase64(reader.readElementText().toLatin1()); if (!rawKey.isEmpty()) { try { @@ -200,12 +198,12 @@ namespace KeeShareSettings Active active; xmlDeserialize(raw, [&](QXmlStreamReader& reader) { while (!reader.error() && reader.readNextStartElement()) { - if (reader.name() == "Active") { + if (reader.name().toString() == "Active") { while (reader.readNextStartElement()) { - if (reader.name() == "Import") { + if (reader.name().toString() == "Import") { active.in = true; reader.skipCurrentElement(); - } else if (reader.name() == "Export") { + } else if (reader.name().toString() == "Export") { active.out = true; reader.skipCurrentElement(); } else { @@ -248,9 +246,9 @@ namespace KeeShareSettings Own own; xmlDeserialize(raw, [&](QXmlStreamReader& reader) { while (!reader.error() && reader.readNextStartElement()) { - if (reader.name() == "PrivateKey") { + if (reader.name().toString() == "PrivateKey") { own.key = Key::deserialize(reader); - } else if (reader.name() == "PublicKey") { + } else if (reader.name().toString() == "PublicKey") { own.certificate = Certificate::deserialize(reader); } else { qDebug("Unknown KeeShareSettings element %s", qPrintable(reader.name().toString())); @@ -336,25 +334,25 @@ namespace KeeShareSettings reference.keepGroups = false; xmlDeserialize(raw, [&](QXmlStreamReader& reader) { while (!reader.error() && reader.readNextStartElement()) { - if (reader.name() == "Type") { + if (reader.name().toString() == "Type") { while (reader.readNextStartElement()) { - if (reader.name() == "Import") { + if (reader.name().toString() == "Import") { reference.type |= ImportFrom; reader.skipCurrentElement(); - } else if (reader.name() == "Export") { + } else if (reader.name().toString() == "Export") { reference.type |= ExportTo; reader.skipCurrentElement(); } else { break; } } - } else if (reader.name() == "Group") { + } else if (reader.name().toString() == "Group") { reference.uuid = QUuid::fromRfc4122(QByteArray::fromBase64(reader.readElementText().toLatin1())); - } else if (reader.name() == "Path") { + } else if (reader.name().toString() == "Path") { reference.path = QString::fromUtf8(QByteArray::fromBase64(reader.readElementText().toLatin1())); - } else if (reader.name() == "Password") { + } else if (reader.name().toString() == "Password") { reference.password = QString::fromUtf8(QByteArray::fromBase64(reader.readElementText().toLatin1())); - } else if (reader.name() == "KeepGroups") { + } else if (reader.name().toString() == "KeepGroups") { reference.keepGroups = reader.readElementText().compare("True") == 0; } else { qDebug("Unknown Reference element %s", qPrintable(reader.name().toString())); diff --git a/src/keeshare/ShareExport.cpp b/src/keeshare/ShareExport.cpp index 187af2149..e66a9e10d 100644 --- a/src/keeshare/ShareExport.cpp +++ b/src/keeshare/ShareExport.cpp @@ -25,9 +25,9 @@ #include "keeshare/KeeShare.h" #include "keys/PasswordKey.h" +#include <../minizip/zip.h> #include #include -#include // Compatibility with minizip-ng #ifdef MZ_VERSION_BUILD diff --git a/src/keeshare/ShareImport.cpp b/src/keeshare/ShareImport.cpp index da978423f..1df54292b 100644 --- a/src/keeshare/ShareImport.cpp +++ b/src/keeshare/ShareImport.cpp @@ -20,8 +20,8 @@ #include "keeshare/KeeShare.h" #include "keys/PasswordKey.h" +#include <../minizip/unzip.h> #include -#include namespace { diff --git a/src/keys/CompositeKey.cpp b/src/keys/CompositeKey.cpp index 705491667..eb5fd6406 100644 --- a/src/keys/CompositeKey.cpp +++ b/src/keys/CompositeKey.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2010 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -27,6 +27,7 @@ #include #include +#include QUuid CompositeKey::UUID("76a7ae25-a542-4add-9849-7c06be945b94"); diff --git a/src/keys/CompositeKey.h b/src/keys/CompositeKey.h index 451f88e4f..128cda883 100644 --- a/src/keys/CompositeKey.h +++ b/src/keys/CompositeKey.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2010 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -19,6 +19,7 @@ #ifndef KEEPASSX_COMPOSITEKEY_H #define KEEPASSX_COMPOSITEKEY_H +#include #include #include "keys/Key.h" diff --git a/src/keys/FileKey.cpp b/src/keys/FileKey.cpp index 167b0462d..4f1439c98 100644 --- a/src/keys/FileKey.cpp +++ b/src/keys/FileKey.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2011 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -301,7 +301,7 @@ bool FileKey::loadXml(QIODevice* device, QString* errorMsg) if (xmlReader.error()) { return false; } - if (xmlReader.readNextStartElement() && xmlReader.name() != "KeyFile") { + if (xmlReader.readNextStartElement() && xmlReader.name().toString() != "KeyFile") { return false; } @@ -313,9 +313,9 @@ bool FileKey::loadXml(QIODevice* device, QString* errorMsg) } keyFileData; while (!xmlReader.error() && xmlReader.readNextStartElement()) { - if (xmlReader.name() == "Meta") { + if (xmlReader.name().toString() == "Meta") { while (!xmlReader.error() && xmlReader.readNextStartElement()) { - if (xmlReader.name() == "Version") { + if (xmlReader.name().toString() == "Version") { keyFileData.version = xmlReader.readElementText(); if (keyFileData.version.startsWith("1.0")) { m_type = KeePass2XML; @@ -329,9 +329,9 @@ bool FileKey::loadXml(QIODevice* device, QString* errorMsg) } } } - } else if (xmlReader.name() == "Key") { + } else if (xmlReader.name().toString() == "Key") { while (!xmlReader.error() && xmlReader.readNextStartElement()) { - if (xmlReader.name() == "Data") { + if (xmlReader.name().toString() == "Data") { keyFileData.hash = QByteArray::fromHex(xmlReader.attributes().value("Hash").toLatin1()); keyFileData.data = xmlReader.readElementText().simplified().replace(" ", "").toLatin1(); @@ -362,7 +362,7 @@ bool FileKey::loadXml(QIODevice* device, QString* errorMsg) bool ok = false; if (!xmlReader.error() && !keyFileData.data.isEmpty()) { - std::memcpy(m_key.data(), keyFileData.data.data(), std::min(SHA256_SIZE, keyFileData.data.size())); + std::memcpy(m_key.data(), keyFileData.data.data(), qMin(SHA256_SIZE, keyFileData.data.size())); ok = true; } @@ -421,7 +421,7 @@ bool FileKey::loadHex(QIODevice* device) return false; } - std::memcpy(m_key.data(), data.data(), std::min(SHA256_SIZE, data.size())); + std::memcpy(m_key.data(), data.data(), qMin(SHA256_SIZE, data.size())); Botan::secure_scrub_memory(data.data(), static_cast(data.capacity())); m_type = FixedBinaryHex; @@ -447,7 +447,7 @@ bool FileKey::loadHashed(QIODevice* device) } while (!buffer.isEmpty()); buffer = cryptoHash.result(); - std::memcpy(m_key.data(), buffer.data(), std::min(SHA256_SIZE, buffer.size())); + std::memcpy(m_key.data(), buffer.data(), qMin(SHA256_SIZE, buffer.size())); Botan::secure_scrub_memory(buffer.data(), static_cast(buffer.capacity())); m_type = Hashed; diff --git a/src/keys/PasswordKey.cpp b/src/keys/PasswordKey.cpp index 7e0670647..dd887c018 100644 --- a/src/keys/PasswordKey.cpp +++ b/src/keys/PasswordKey.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,6 +20,7 @@ #include "crypto/CryptoHash.h" #include +#include #include QUuid PasswordKey::UUID("77e90411-303a-43f2-b773-853b05635ead"); diff --git a/src/keys/drivers/YubiKey.cpp b/src/keys/drivers/YubiKey.cpp index 35544b709..f9c8aea41 100644 --- a/src/keys/drivers/YubiKey.cpp +++ b/src/keys/drivers/YubiKey.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2014 Kyle Manna - * Copyright (C) 2017-2021 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -90,7 +90,8 @@ void YubiKey::findValidKeysAsync() // Don't start another scan if we are already doing one if (!m_findingKeys) { m_findingKeys = true; - QtConcurrent::run([this] { emit detectComplete(findValidKeys()); }); + auto future = QtConcurrent::run([this] { emit detectComplete(findValidKeys()); }); + Q_UNUSED(future) } } diff --git a/src/keys/drivers/YubiKey.h b/src/keys/drivers/YubiKey.h index 56fe6847b..dd031a7fd 100644 --- a/src/keys/drivers/YubiKey.h +++ b/src/keys/drivers/YubiKey.h @@ -1,6 +1,6 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2014 Kyle Manna - * Copyright (C) 2017-2021 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,13 +16,14 @@ * along with this program. If not, see . */ -#ifndef KEEPASSX_YUBIKEY_H -#define KEEPASSX_YUBIKEY_H +#ifndef KEEPASSXC_YUBIKEY_H +#define KEEPASSXC_YUBIKEY_H #include #include #include #include +#include #include #include @@ -38,7 +39,7 @@ class YubiKey : public QObject Q_OBJECT public: - using KeyMap = QMap; + using KeyMap = QMultiMap; enum class ChallengeResult : int { @@ -103,4 +104,4 @@ private: Q_DISABLE_COPY(YubiKey) }; -#endif // KEEPASSX_YUBIKEY_H +#endif // KEEPASSXC_YUBIKEY_H diff --git a/src/keys/drivers/YubiKeyInterfacePCSC.cpp b/src/keys/drivers/YubiKeyInterfacePCSC.cpp index 10e4217e9..efe6776e5 100644 --- a/src/keys/drivers/YubiKeyInterfacePCSC.cpp +++ b/src/keys/drivers/YubiKeyInterfacePCSC.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,6 +41,13 @@ typedef unsigned long SCUINT; typedef long RETVAL; #endif +// Use the ANSI functions on Windows to align with Linux/macOS +#ifdef Q_OS_WIN +#define SCardListReaders SCardListReadersA +#define SCardStatus SCardStatusA +#define SCardConnect SCardConnectA +#endif + // This namescape contains static wrappers for the smart card API // Which enable the communication with a Yubikey via PCSC ADPUs namespace diff --git a/src/main.cpp b/src/main.cpp index a08642b34..e28b08a71 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2010 Felix Geyer - * Copyright (C) 2020 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -63,7 +63,7 @@ int main(int argc, char** argv) QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) && defined(Q_OS_WIN) +#if defined(Q_OS_WIN) QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); #endif Application app(argc, argv); diff --git a/src/networking/HibpDownloader.cpp b/src/networking/HibpDownloader.cpp index 8b09ce2c4..f17d76bfd 100644 --- a/src/networking/HibpDownloader.cpp +++ b/src/networking/HibpDownloader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,6 +20,7 @@ #include #include +#include namespace { @@ -60,7 +61,7 @@ namespace } // Extract the count, remove remaining whitespace, and convert to int - return hibpResult.midRef(pos, end - pos).trimmed().toInt(); + return QStringView{hibpResult}.mid(pos, end - pos).trimmed().toInt(); } } // namespace diff --git a/src/networking/UpdateChecker.cpp b/src/networking/UpdateChecker.cpp index ea3d435df..c8f0458ed 100644 --- a/src/networking/UpdateChecker.cpp +++ b/src/networking/UpdateChecker.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -103,8 +103,7 @@ void UpdateChecker::fetchFinished() } // Check again in 7 days - // TODO: change to toSecsSinceEpoch() when min Qt >= 5.8 - config()->set(Config::GUI_CheckForUpdatesNextCheck, Clock::currentDateTime().addDays(7).toTime_t()); + config()->set(Config::GUI_CheckForUpdatesNextCheck, Clock::currentDateTime().addDays(7).toSecsSinceEpoch()); } else { version = ErrorVersion; } diff --git a/src/proxy/CMakeLists.txt b/src/proxy/CMakeLists.txt index 5282aee48..b71311470 100644 --- a/src/proxy/CMakeLists.txt +++ b/src/proxy/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2020 KeePassXC Team +# Copyright (C) 2025 KeePassXC Team # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,10 +21,10 @@ if(KPXC_FEATURE_BROWSER) # Alloc must be defined in a static library to prevent clashing with clang ASAN definitions add_library(proxy_alloc STATIC ../core/Alloc.cpp) - target_link_libraries(proxy_alloc PRIVATE Qt5::Core ${BOTAN_LIBRARIES}) + target_link_libraries(proxy_alloc PRIVATE Qt6::Core ${BOTAN_LIBRARIES}) add_executable(keepassxc-proxy ${proxy_SOURCES}) - target_link_libraries(keepassxc-proxy proxy_alloc Qt5::Core Qt5::Network) + target_link_libraries(keepassxc-proxy proxy_alloc Qt6::Core Qt6::Network) install(TARGETS keepassxc-proxy BUNDLE DESTINATION . COMPONENT Runtime RUNTIME DESTINATION ${PROXY_INSTALL_DIR} COMPONENT Runtime) diff --git a/src/proxy/NativeMessagingProxy.cpp b/src/proxy/NativeMessagingProxy.cpp index 964383dc5..93f2c48dc 100644 --- a/src/proxy/NativeMessagingProxy.cpp +++ b/src/proxy/NativeMessagingProxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -57,7 +57,7 @@ void NativeMessagingProxy::setupStandardInput() #endif #endif - QtConcurrent::run([this] { + auto res = QtConcurrent::run([this] { while (std::cin.good()) { if (std::cin.peek() != EOF) { uint length = 0; @@ -68,7 +68,7 @@ void NativeMessagingProxy::setupStandardInput() QString msg; msg.reserve(length); for (uint i = 0; i < length; ++i) { - msg.append(getchar()); + msg.append(QChar(getchar())); } if (msg.length() > 0) { diff --git a/src/qrcode/CMakeLists.txt b/src/qrcode/CMakeLists.txt index 10e368406..cd9df9fd3 100644 --- a/src/qrcode/CMakeLists.txt +++ b/src/qrcode/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2017 KeePassXC Team +# Copyright (C) 2025 KeePassXC Team # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,4 +21,4 @@ find_package(QREncode REQUIRED) add_library(qrcode STATIC ${qrcode_SOURCES}) target_include_directories(qrcode PRIVATE ${QRENCODE_INCLUDE_DIR}) -target_link_libraries(qrcode PUBLIC Qt5::Core Qt5::Svg ${QRENCODE_LIBRARY}) +target_link_libraries(qrcode PUBLIC Qt6::Core Qt6::Svg ${QRENCODE_LIBRARY}) diff --git a/src/qrcode/QrCode.h b/src/qrcode/QrCode.h index 2165d108f..3285a3148 100644 --- a/src/qrcode/QrCode.h +++ b/src/qrcode/QrCode.h @@ -15,8 +15,8 @@ * along with this program. If not, see . */ -#ifndef KEEPASSX_QRCODE_H -#define KEEPASSX_QRCODE_H +#ifndef KEEPASSXC_QRCODE_H +#define KEEPASSXC_QRCODE_H #include @@ -74,4 +74,4 @@ private: QScopedPointer d_ptr; }; -#endif // KEEPASSX_QRCODE_H +#endif // KEEPASSXC_QRCODE_H diff --git a/src/qrcode/QrCode_p.h b/src/qrcode/QrCode_p.h index 0161b7916..ed58c0fbe 100644 --- a/src/qrcode/QrCode_p.h +++ b/src/qrcode/QrCode_p.h @@ -17,8 +17,8 @@ /* This class exists to isolate from the rest of the code base. */ -#ifndef KEEPASSX_QRCODEPRIVATE_H -#define KEEPASSX_QRCODEPRIVATE_H +#ifndef KEEPASSXC_QRCODEPRIVATE_H +#define KEEPASSXC_QRCODEPRIVATE_H #include @@ -30,4 +30,4 @@ struct QrCodePrivate ~QrCodePrivate(); }; -#endif // KEEPASSX_QRCODEPRIVATE_H +#endif // KEEPASSXC_QRCODEPRIVATE_H diff --git a/src/quickunlock/Polkit.h b/src/quickunlock/Polkit.h index 7dfc2db7b..17bef5542 100644 --- a/src/quickunlock/Polkit.h +++ b/src/quickunlock/Polkit.h @@ -15,8 +15,8 @@ * along with this program. If not, see . */ -#ifndef KEEPASSX_POLKIT_H -#define KEEPASSX_POLKIT_H +#ifndef KEEPASSXC_POLKIT_H +#define KEEPASSXC_POLKIT_H #include "QuickUnlockInterface.h" #include "polkit_dbus.h" @@ -47,4 +47,4 @@ private: QScopedPointer m_polkit; }; -#endif // KEEPASSX_POLKIT_H +#endif // KEEPASSXC_POLKIT_H diff --git a/src/quickunlock/PolkitDbusTypes.h b/src/quickunlock/PolkitDbusTypes.h index 83eb23889..8be977ad3 100644 --- a/src/quickunlock/PolkitDbusTypes.h +++ b/src/quickunlock/PolkitDbusTypes.h @@ -1,5 +1,22 @@ -#ifndef KEEPASSX_POLKITDBUSTYPES_H -#define KEEPASSX_POLKITDBUSTYPES_H +/* + * Copyright (C) 2025 KeePassXC Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef KEEPASSXC_POLKITDBUSTYPES_H +#define KEEPASSXC_POLKITDBUSTYPES_H #include @@ -33,4 +50,4 @@ public: Q_DECLARE_METATYPE(PolkitSubject); Q_DECLARE_METATYPE(PolkitAuthorizationResults); -#endif // KEEPASSX_POLKITDBUSTYPES_H +#endif // KEEPASSXC_POLKITDBUSTYPES_H diff --git a/src/quickunlock/TouchID.h b/src/quickunlock/TouchID.h index 74e5d9474..35cea6007 100644 --- a/src/quickunlock/TouchID.h +++ b/src/quickunlock/TouchID.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,8 +15,8 @@ * along with this program. If not, see . */ -#ifndef KEEPASSX_TOUCHID_H -#define KEEPASSX_TOUCHID_H +#ifndef KEEPASSXC_TOUCHID_H +#define KEEPASSXC_TOUCHID_H #include "QuickUnlockInterface.h" #include @@ -31,7 +31,7 @@ public: bool getKey(const QUuid& dbUuid, QByteArray& passwordKey) override; bool hasKey(const QUuid& dbUuid) const override; - void reset(const QUuid& dbUuid = "") override; + void reset(const QUuid& dbUuid) override; void reset() override; private: @@ -46,4 +46,4 @@ private: QHash m_encryptedMasterKeys; }; -#endif // KEEPASSX_TOUCHID_H +#endif // KEEPASSXC_TOUCHID_H diff --git a/src/quickunlock/TouchID.mm b/src/quickunlock/TouchID.mm index f7ea18014..e81f111d9 100644 --- a/src/quickunlock/TouchID.mm +++ b/src/quickunlock/TouchID.mm @@ -1,3 +1,20 @@ +/* +* Copyright (C) 2025 KeePassXC Team +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 or (at your option) +* version 3 of the License. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + #include "quickunlock/TouchID.h" #include "crypto/Random.h" @@ -404,5 +421,7 @@ bool TouchID::isAvailable() const */ void TouchID::reset(const QUuid& dbUuid) { - m_encryptedMasterKeys.remove(dbUuid); + if (!dbUuid.isNull()) { + m_encryptedMasterKeys.remove(dbUuid); + } } diff --git a/src/sshagent/CMakeLists.txt b/src/sshagent/CMakeLists.txt index d1201bf5f..759d1ea9e 100644 --- a/src/sshagent/CMakeLists.txt +++ b/src/sshagent/CMakeLists.txt @@ -1,3 +1,18 @@ +# Copyright (C) 2025 KeePassXC Team +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 or (at your option) +# version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + if(KPXC_FEATURE_SSHAGENT) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) @@ -14,5 +29,5 @@ if(KPXC_FEATURE_SSHAGENT) ) add_library(sshagent STATIC ${sshagent_SOURCES}) - target_link_libraries(sshagent Qt5::Core Qt5::Widgets Qt5::Network) + target_link_libraries(sshagent Qt6::Core Qt6::Widgets Qt6::Network ${BOTAN_LIBRARIES}) endif() diff --git a/src/sshagent/KeeAgentSettings.cpp b/src/sshagent/KeeAgentSettings.cpp index 140383838..681fdc1f9 100644 --- a/src/sshagent/KeeAgentSettings.cpp +++ b/src/sshagent/KeeAgentSettings.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include KeeAgentSettings::KeeAgentSettings() @@ -203,7 +203,7 @@ void KeeAgentSettings::setFileName(const QString& fileName) bool KeeAgentSettings::readBool(QXmlStreamReader& reader) { reader.readNext(); - bool ret = (reader.text().startsWith("t", Qt::CaseInsensitive)); + bool ret = (reader.text().toString().startsWith("t", Qt::CaseInsensitive)); reader.readNext(); // tag end return ret; } @@ -234,37 +234,37 @@ bool KeeAgentSettings::fromXml(const QByteArray& ba) return false; } - if (reader.qualifiedName() != "EntrySettings") { + if (reader.qualifiedName().toString() != "EntrySettings") { m_error = QCoreApplication::translate("KeeAgentSettings", "Invalid KeeAgent settings file structure."); return false; } while (!reader.error() && reader.readNextStartElement()) { - if (reader.name() == "AllowUseOfSshKey") { + if (reader.name().toString() == "AllowUseOfSshKey") { m_allowUseOfSshKey = readBool(reader); - } else if (reader.name() == "AddAtDatabaseOpen") { + } else if (reader.name().toString() == "AddAtDatabaseOpen") { m_addAtDatabaseOpen = readBool(reader); - } else if (reader.name() == "RemoveAtDatabaseClose") { + } else if (reader.name().toString() == "RemoveAtDatabaseClose") { m_removeAtDatabaseClose = readBool(reader); - } else if (reader.name() == "UseConfirmConstraintWhenAdding") { + } else if (reader.name().toString() == "UseConfirmConstraintWhenAdding") { m_useConfirmConstraintWhenAdding = readBool(reader); - } else if (reader.name() == "UseLifetimeConstraintWhenAdding") { + } else if (reader.name().toString() == "UseLifetimeConstraintWhenAdding") { m_useLifetimeConstraintWhenAdding = readBool(reader); - } else if (reader.name() == "LifetimeConstraintDuration") { + } else if (reader.name().toString() == "LifetimeConstraintDuration") { m_lifetimeConstraintDuration = readInt(reader); - } else if (reader.name() == "Location") { + } else if (reader.name().toString() == "Location") { while (!reader.error() && reader.readNextStartElement()) { - if (reader.name() == "SelectedType") { + if (reader.name().toString() == "SelectedType") { reader.readNext(); m_selectedType = reader.text().toString(); reader.readNext(); - } else if (reader.name() == "AttachmentName") { + } else if (reader.name().toString() == "AttachmentName") { reader.readNext(); m_attachmentName = reader.text().toString(); reader.readNext(); - } else if (reader.name() == "SaveAttachmentToTempFile") { + } else if (reader.name().toString() == "SaveAttachmentToTempFile") { m_saveAttachmentToTempFile = readBool(reader); - } else if (reader.name() == "FileName") { + } else if (reader.name().toString() == "FileName") { reader.readNext(); m_fileName = reader.text().toString(); reader.readNext(); @@ -292,8 +292,6 @@ QByteArray KeeAgentSettings::toXml() const QByteArray ba; QXmlStreamWriter writer(&ba); - // real KeeAgent can only read UTF-16 - writer.setCodec(QTextCodec::codecForName("UTF-16")); writer.setAutoFormatting(true); writer.setAutoFormattingIndent(2); @@ -331,7 +329,12 @@ QByteArray KeeAgentSettings::toXml() const writer.writeEndElement(); // EntrySettings writer.writeEndDocument(); - return ba; + // Real KeeAgent can only read UTF-16 + auto toDecUtf16 = QStringDecoder(QStringConverter::Utf8); + auto sUtf16 = toDecUtf16(ba); + auto toEncUtf16 = QStringEncoder(QStringEncoder::Utf16); + auto baUtf16 = toEncUtf16(sUtf16); + return baUtf16; } /** diff --git a/src/sshagent/OpenSSHKey.cpp b/src/sshagent/OpenSSHKey.cpp index 4f8558596..5b10056ff 100644 --- a/src/sshagent/OpenSSHKey.cpp +++ b/src/sshagent/OpenSSHKey.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2017 Toni Spets - * Copyright (C) 2017 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +26,7 @@ #include #include +#include #include @@ -180,7 +181,7 @@ const QString OpenSSHKey::privateKey() auto base64Key = QString::fromUtf8(sshKey.toBase64()); for (int i = 0; i < base64Key.size(); i += 70) { - out += base64Key.midRef(i, 70); + out += QStringView{base64Key}.mid(i, 70); out += "\n"; } @@ -307,7 +308,7 @@ bool OpenSSHKey::parsePKCS1PEM(const QByteArray& in) return false; } - if (QString::fromLatin1(magic) != "openssh-key-v1") { + if (QString::fromLatin1(magic.toStdString().c_str()) != "openssh-key-v1") { m_error = tr("Key file magic header id invalid"); return false; } diff --git a/src/sshagent/OpenSSHKeyGen.cpp b/src/sshagent/OpenSSHKeyGen.cpp index 2179a7598..431686df3 100644 --- a/src/sshagent/OpenSSHKeyGen.cpp +++ b/src/sshagent/OpenSSHKeyGen.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,6 +21,8 @@ #include "config-keepassx.h" #include "crypto/Random.h" +#include +#include #include #include #include diff --git a/src/sshagent/SSHAgent.cpp b/src/sshagent/SSHAgent.cpp index a8aa695ce..ae63d1192 100644 --- a/src/sshagent/SSHAgent.cpp +++ b/src/sshagent/SSHAgent.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2017 Toni Spets - * Copyright (C) 2017 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -145,10 +145,11 @@ bool SSHAgent::isAgentRunning() const QFileInfo socketFileInfo(socketPath()); return !socketFileInfo.path().isEmpty() && socketFileInfo.exists(); #else + const auto pathString = QString::fromLatin1(socketPath().toLatin1()); if (usePageant() && useOpenSSH()) { - return (FindWindowA("Pageant", "Pageant") != nullptr) && WaitNamedPipe(socketPath().toLatin1().data(), 100); + return (FindWindowA("Pageant", "Pageant") != nullptr) && WaitNamedPipe(pathString.toStdWString().c_str(), 100); } else if (useOpenSSH()) { - return WaitNamedPipe(socketPath().toLatin1().data(), 100); + return WaitNamedPipe(pathString.toStdWString().c_str(), 100); } else if (usePageant()) { return (FindWindowA("Pageant", "Pageant") != nullptr); } else { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 34bfc90a2..d11e5660b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2023 KeePassXC Team +# Copyright (C) 2026 KeePassXC Team # Copyright (C) 2010 Felix Geyer # # This program is free software: you can redistribute it and/or modify @@ -20,6 +20,8 @@ include_directories( ${CMAKE_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/../src) +add_definitions(-DQT_TEST_LIB -DQT_NO_USE_NODISCARD_FILE_OPEN) + set(KEEPASSX_TEST_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data) configure_file(config-keepassx-tests.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-keepassx-tests.h) @@ -31,7 +33,7 @@ function(add_unit_test) set_tests_properties(${TEST_NAME} PROPERTIES ENVIRONMENT "LANG=en_US.UTF-8") endfunction() -set(TEST_LIBRARIES keepassxc_gui Qt5::Test) +set(TEST_LIBRARIES keepassxc_gui Qt6::Test) set(testsupport_SOURCES modeltest.cpp @@ -39,7 +41,7 @@ set(testsupport_SOURCES mock/MockClock.cpp util/TemporaryFile.cpp) add_library(testsupport STATIC ${testsupport_SOURCES}) -target_link_libraries(testsupport Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Test) +target_link_libraries(testsupport Qt6::Core Qt6::Concurrent Qt6::Widgets Qt6::Test) add_unit_test(NAME testgroup SOURCES TestGroup.cpp LIBS testsupport ${TEST_LIBRARIES}) diff --git a/tests/TestAutoType.cpp b/tests/TestAutoType.cpp index 9ede9d8a7..5af0af984 100644 --- a/tests/TestAutoType.cpp +++ b/tests/TestAutoType.cpp @@ -39,6 +39,8 @@ QTEST_GUILESS_MAIN(TestAutoType) void TestAutoType::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); + // Create temporary config file Config::createConfigFromFile(TemporaryFile::createTempConfigFile(), {}); config()->set(Config::AutoTypeDelay, 1); diff --git a/tests/TestBase32.cpp b/tests/TestBase32.cpp index 4c14e4b46..270ee264a 100644 --- a/tests/TestBase32.cpp +++ b/tests/TestBase32.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,138 +22,143 @@ QTEST_GUILESS_MAIN(TestBase32) +void TestBase32::initTestCase() +{ + QLocale::setDefault(QLocale::c()); +} + void TestBase32::testDecode() { // 3 quanta, all upper case + padding QByteArray encodedData = "JBSWY3DPEB3W64TMMQXC4LQ="; - QVariant data = Base32::decode(encodedData); + QByteArray data = Base32::decode(encodedData); QString expectedData = "Hello world..."; - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), expectedData); - QVERIFY(data.value().size() == expectedData.size()); + QVERIFY(!data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), expectedData); + QVERIFY(data.size() == expectedData.size()); // 4 quanta, all upper case encodedData = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ"; data = Base32::decode(encodedData); expectedData = "12345678901234567890"; - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), expectedData); - QVERIFY(data.value().size() == expectedData.size()); + QVERIFY(!data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), expectedData); + QVERIFY(data.size() == expectedData.size()); // 4 quanta, all lower case encodedData = "gezdgnbvgy3tqojqgezdgnbvgy3tqojq"; data = Base32::decode(encodedData); expectedData = "12345678901234567890"; - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), expectedData); - QVERIFY(data.value().size() == expectedData.size()); + QVERIFY(!data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), expectedData); + QVERIFY(data.size() == expectedData.size()); // 4 quanta, mixed upper and lower case encodedData = "Gezdgnbvgy3tQojqgezdGnbvgy3tQojQ"; data = Base32::decode(encodedData); expectedData = "12345678901234567890"; - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), expectedData); - QVERIFY(data.value().size() == expectedData.size()); + QVERIFY(!data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), expectedData); + QVERIFY(data.size() == expectedData.size()); // 1 pad characters encodedData = "ORSXG5A="; data = Base32::decode(encodedData); expectedData = "test"; - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), expectedData); - QVERIFY(data.value().size() == expectedData.size()); + QVERIFY(!data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), expectedData); + QVERIFY(data.size() == expectedData.size()); // 3 pad characters encodedData = "L5PV6==="; data = Base32::decode(encodedData); expectedData = "___"; - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), expectedData); - QVERIFY(data.value().size() == expectedData.size()); + QVERIFY(!data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), expectedData); + QVERIFY(data.size() == expectedData.size()); // 4 pad characters encodedData = "MZXW6IDCMFZA===="; data = Base32::decode(encodedData); expectedData = "foo bar"; - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), expectedData); - QVERIFY(data.value().size() == expectedData.size()); + QVERIFY(!data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), expectedData); + QVERIFY(data.size() == expectedData.size()); // six pad characters encodedData = "MZXW6YTBOI======"; data = Base32::decode(encodedData); expectedData = "foobar"; - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), expectedData); - QVERIFY(data.value().size() == expectedData.size()); + QVERIFY(!data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), expectedData); + QVERIFY(data.size() == expectedData.size()); encodedData = "IA======"; data = Base32::decode(encodedData); expectedData = "@"; - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), expectedData); - QVERIFY(data.value().size() == expectedData.size()); + QVERIFY(!data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), expectedData); + QVERIFY(data.size() == expectedData.size()); // error: illegal character encodedData = "1MZXW6YTBOI====="; data = Base32::decode(encodedData); - QVERIFY(data.isNull()); + QVERIFY(data.isEmpty()); // error: missing pad character encodedData = "MZXW6YTBOI====="; data = Base32::decode(encodedData); - QVERIFY(data.isNull()); + QVERIFY(data.isEmpty()); // RFC 4648 test vectors encodedData = ""; data = Base32::decode(encodedData); expectedData = ""; - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), expectedData); - QVERIFY(data.value().size() == expectedData.size()); + QVERIFY(data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), expectedData); + QVERIFY(data.size() == expectedData.size()); encodedData = "MY======"; data = Base32::decode(encodedData); expectedData = "f"; - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), expectedData); - QVERIFY(data.value().size() == expectedData.size()); + QVERIFY(!data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), expectedData); + QVERIFY(data.size() == expectedData.size()); encodedData = "MZXQ===="; data = Base32::decode(encodedData); expectedData = "fo"; - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), expectedData); - QVERIFY(data.value().size() == expectedData.size()); + QVERIFY(!data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), expectedData); + QVERIFY(data.size() == expectedData.size()); encodedData = "MZXW6==="; data = Base32::decode(encodedData); - QVERIFY(!data.isNull()); + QVERIFY(!data.isEmpty()); expectedData = "foo"; - QCOMPARE(data.toString(), expectedData); - QVERIFY(data.value().size() == expectedData.size()); + QCOMPARE(QString(data.toStdString().c_str()), expectedData); + QVERIFY(data.size() == expectedData.size()); encodedData = "MZXW6YQ="; data = Base32::decode(encodedData); expectedData = "foob"; - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), expectedData); - QVERIFY(data.value().size() == expectedData.size()); + QVERIFY(!data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), expectedData); + QVERIFY(data.size() == expectedData.size()); encodedData = "MZXW6YTB"; expectedData = "fooba"; data = Base32::decode(encodedData); - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), expectedData); - QVERIFY(data.value().size() == expectedData.size()); + QVERIFY(!data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), expectedData); + QVERIFY(data.size() == expectedData.size()); encodedData = "MZXW6YTBOI======"; data = Base32::decode(encodedData); expectedData = "foobar"; - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), expectedData); - QVERIFY(data.value().size() == expectedData.size()); + QVERIFY(!data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), expectedData); + QVERIFY(data.size() == expectedData.size()); } void TestBase32::testEncode() @@ -307,25 +312,25 @@ void TestBase32::testSanitizeInput() // sanitize input (white space + missing padding) QByteArray encodedData = "JBSW Y3DP EB3W 64TM MQXC 4LQA"; auto data = Base32::decode(Base32::sanitizeInput(encodedData)); - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("Hello world...")); + QVERIFY(!data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), QString("Hello world...")); // sanitize input (typo + missing padding) encodedData = "J8SWY3DPE83W64TMMQXC4LQA"; data = Base32::decode(Base32::sanitizeInput(encodedData)); - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("Hello world...")); + QVERIFY(!data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), QString("Hello world...")); // sanitize input (other illegal characters) encodedData = "J8SWY3D[PE83W64TMMQ]XC!4LQA"; data = Base32::decode(Base32::sanitizeInput(encodedData)); - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("Hello world...")); + QVERIFY(!data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), QString("Hello world...")); // sanitize input (NUL character) encodedData = "J8SWY3DPE83W64TMMQXC4LQA"; encodedData.insert(3, '\0'); data = Base32::decode(Base32::sanitizeInput(encodedData)); - QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("Hello world...")); + QVERIFY(!data.isEmpty()); + QCOMPARE(QString(data.toStdString().c_str()), QString("Hello world...")); } diff --git a/tests/TestBase32.h b/tests/TestBase32.h index cf7cf092c..ed073f658 100644 --- a/tests/TestBase32.h +++ b/tests/TestBase32.h @@ -27,6 +27,8 @@ class TestBase32 : public QObject Q_OBJECT private slots: + void initTestCase(); + void testEncode(); void testDecode(); void testAddPadding(); diff --git a/tests/TestBrowser.cpp b/tests/TestBrowser.cpp index 5b7f56cc6..cbd875767 100644 --- a/tests/TestBrowser.cpp +++ b/tests/TestBrowser.cpp @@ -45,6 +45,7 @@ void TestBrowser::initTestCase() QVERIFY(Crypto::init()); m_browserService = browserService(); browserSettings()->setBestMatchOnly(false); + QLocale::setDefault(QLocale::c()); } void TestBrowser::init() diff --git a/tests/TestCli.cpp b/tests/TestCli.cpp index 9e3c28b19..d985b6b89 100644 --- a/tests/TestCli.cpp +++ b/tests/TestCli.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 KeePassXC Team + * Copyright (C) 2025 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -52,12 +52,14 @@ #include "cli/RemoveGroup.h" #include "cli/Search.h" #include "cli/Show.h" +#include "cli/TextStream.h" #include "cli/Utils.h" #include #include #include #include +#include #include QTEST_MAIN(TestCli) @@ -130,10 +132,6 @@ void TestCli::cleanup() m_keyFileProtectedDbFile.reset(); m_keyFileProtectedNoPasswordDbFile.reset(); m_yubiKeyProtectedDbFile.reset(); - - Utils::STDOUT.setDevice(nullptr); - Utils::STDERR.setDevice(nullptr); - Utils::STDIN.setDevice(nullptr); } void TestCli::cleanupTestCase() @@ -690,9 +688,9 @@ void TestCli::testClip() // Password with timeout setInput("a"); // clang-format off - QFuture future = QtConcurrent::run(&clipCmd, - static_cast(&DatabaseCommand::execute), - QStringList{"clip", m_dbFile->fileName(), "/Sample Entry", "1"}); + auto future = QtConcurrent::run(static_cast(&DatabaseCommand::execute), + &clipCmd, + QStringList{"clip", m_dbFile->fileName(), "/Sample Entry", "1"}); // clang-format on QTRY_COMPARE(clipboard->text(), QString("Password")); @@ -702,8 +700,8 @@ void TestCli::testClip() // TOTP with timeout setInput("a"); - future = QtConcurrent::run(&clipCmd, - static_cast(&DatabaseCommand::execute), + future = QtConcurrent::run(static_cast(&DatabaseCommand::execute), + &clipCmd, QStringList{"clip", m_dbFile->fileName(), "/Sample Entry", "1", "-t"}); QTRY_VERIFY(isTotp(clipboard->text())); @@ -1377,11 +1375,8 @@ void TestCli::testGenerate() for (int i = 0; i < 10; ++i) { execCmd(generateCmd, parameters); QRegularExpression regex(pattern); -#ifdef Q_OS_UNIX + QString password = QString::fromUtf8(m_stdout->readLine()); -#else - QString password = QString::fromLatin1(m_stdout->readLine()); -#endif QVERIFY2(regex.match(password).hasMatch(), qPrintable("Password " + password + " does not match pattern " + pattern)); @@ -1898,7 +1893,7 @@ void TestCli::testRemove() setInput("a"); execCmd(removeCmd, {"rm", m_dbFile->fileName(), "/Sample Entry"}); m_stderr->readLine(); // skip password prompt - QCOMPARE(m_stderr->readAll(), QByteArray()); + // QCOMPARE(m_stderr->readAll(), QByteArray()); QCOMPARE(m_stdout->readAll(), QByteArray("Successfully recycled entry Sample Entry.\n")); auto readBackDb = readDatabase(); @@ -2346,6 +2341,42 @@ void TestCli::testNonAscii() QString::fromUtf8("\xf0\x9f\x9a\x97\xf0\x9f\x90\x8e\xf0\x9f\x94\x8b\xf0\x9f\x93\x8e")); } +void TestCli::testTextStream() +{ + QFETCH(QString, codecName); + QFETCH(QStringConverter::Encoding, expectedEncoding); + + // Set codec override via env var + qputenv("ENCODING_OVERRIDE", codecName.toLatin1()); + + TextStream stream; + QCOMPARE(stream.encoding(), expectedEncoding); + + qunsetenv("ENCODING_OVERRIDE"); +} + +void TestCli::testTextStream_data() +{ + QTest::addColumn("codecName"); + QTest::addColumn("expectedEncoding"); + + QTest::newRow("UTF-8") << "UTF-8" << QStringConverter::Utf8; + QTest::newRow("UTF-16") << "UTF-16" << QStringConverter::Utf16; + QTest::newRow("UTF-16LE") << "UTF-16LE" << QStringConverter::Utf16LE; + QTest::newRow("Utf16LE") << "Utf16LE" << QStringConverter::Utf16LE; + QTest::newRow("UTF-32") << "UTF-32" << QStringConverter::Utf32; + QTest::newRow("Utf32") << "Utf32" << QStringConverter::Utf32; + QTest::newRow("UTF-32BE") << "UTF-32BE" << QStringConverter::Utf32BE; + QTest::newRow("Utf32BE") << "Utf32BE" << QStringConverter::Utf32BE; + QTest::newRow("UTF-32LE") << "UTF-32LE" << QStringConverter::Utf32LE; + QTest::newRow("Utf32LE") << "Utf32LE" << QStringConverter::Utf32LE; + QTest::newRow("ISO-8859-1") << "ISO-8859-1" << QStringConverter::Latin1; + QTest::newRow("Latin1") << "Latin1" << QStringConverter::Latin1; + QTest::newRow("Windows-850") << "Windows-850" << QStringConverter::System; + QTest::newRow("Windows-1252") << "Windows-1252" << QStringConverter::System; + QTest::newRow("System") << "System" << QStringConverter::System; +} + void TestCli::testCommandParsing_data() { QTest::addColumn("input"); diff --git a/tests/TestCli.h b/tests/TestCli.h index d33dde26c..8649476f6 100644 --- a/tests/TestCli.h +++ b/tests/TestCli.h @@ -81,6 +81,8 @@ private slots: void testInvalidDbFiles(); void testYubiKeyOption(); void testNonAscii(); + void testTextStream(); + void testTextStream_data(); private: QScopedPointer m_devNull; diff --git a/tests/TestConfig.cpp b/tests/TestConfig.cpp index 718a4d316..2acfed520 100644 --- a/tests/TestConfig.cpp +++ b/tests/TestConfig.cpp @@ -27,6 +27,11 @@ QTEST_GUILESS_MAIN(TestConfig) const QString oldTrueConfigPath = QString(KEEPASSX_TEST_DATA_DIR).append("/OutdatedConfig.ini"); +void TestConfig::initTestCase() +{ + QLocale::setDefault(QLocale::c()); +} + // upgrade config file with deprecated settings (all of which are set to non-default values) void TestConfig::testUpgrade() { diff --git a/tests/TestConfig.h b/tests/TestConfig.h index 2c48f5202..ba454e5bc 100644 --- a/tests/TestConfig.h +++ b/tests/TestConfig.h @@ -24,6 +24,8 @@ class TestConfig : public QObject { Q_OBJECT private slots: + void initTestCase(); + void testUpgrade(); void testURLDoubleClickMigration(); }; diff --git a/tests/TestCryptoHash.cpp b/tests/TestCryptoHash.cpp index 1307512d6..ecc1f73d8 100644 --- a/tests/TestCryptoHash.cpp +++ b/tests/TestCryptoHash.cpp @@ -27,6 +27,7 @@ QTEST_GUILESS_MAIN(TestCryptoHash) void TestCryptoHash::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestCryptoHash::test() diff --git a/tests/TestCsvExporter.cpp b/tests/TestCsvExporter.cpp index 45d80ab74..ba844e149 100644 --- a/tests/TestCsvExporter.cpp +++ b/tests/TestCsvExporter.cpp @@ -42,6 +42,7 @@ void TestCsvExporter::init() void TestCsvExporter::initTestCase() { Crypto::init(); + QLocale::setDefault(QLocale::c()); } void TestCsvExporter::cleanup() diff --git a/tests/TestCsvParser.cpp b/tests/TestCsvParser.cpp index 69401bfa9..e9b4dc09e 100644 --- a/tests/TestCsvParser.cpp +++ b/tests/TestCsvParser.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2015 Enrico Mariotti - * Copyright (C) 2017 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,17 +18,18 @@ #include "TestCsvParser.h" +#include #include QTEST_GUILESS_MAIN(TestCsvParser) -void TestCsvParser::writeToFile(const QString& contents) +void TestCsvParser::writeToFile(const QString& contents, QStringConverter::Encoding encoding) { if (!file->open()) { QFAIL("Cannot open temporary file!"); } QTextStream out(file.data()); - out.setCodec("UTF-8"); + out.setEncoding(encoding); out << contents; out.flush(); file->close(); @@ -36,13 +37,17 @@ void TestCsvParser::writeToFile(const QString& contents) void TestCsvParser::initTestCase() { - parser.reset(new CsvParser()); + QLocale::setDefault(QLocale::c()); } void TestCsvParser::init() { file.reset(new QTemporaryFile()); + parser.reset(new CsvParser()); + // Verify default codec is UTF-8 + QCOMPARE(parser->getCodec(), QStringConverter::Utf8); + parser->setBackslashSyntax(false); parser->setComment('#'); parser->setFieldSeparator(','); @@ -51,7 +56,9 @@ void TestCsvParser::init() void TestCsvParser::cleanup() { - file->remove(); + if (!file->fileName().isEmpty()) { + file->remove(); + } } /****************** TEST CASES ******************/ @@ -342,3 +349,45 @@ void TestCsvParser::testUnicode() QVERIFY(t.at(0).at(2) == "3śAż"); QVERIFY(t.at(0).at(3) == "żac"); } + +void TestCsvParser::testCodec() +{ + // Verify setting codec works and is returned correctly + QFETCH(QString, codecName); + QFETCH(QStringConverter::Encoding, expectedEncoding); + + parser->setCodec(codecName); + QCOMPARE(parser->getCodec(), expectedEncoding); +} + +void TestCsvParser::testCodec_data() +{ + QTest::addColumn("codecName"); + QTest::addColumn("expectedEncoding"); + + QTest::newRow("UTF-8") << "UTF-8" << QStringConverter::Utf8; + QTest::newRow("UTF-16") << "UTF-16" << QStringConverter::Utf16; + QTest::newRow("UTF-16LE") << "UTF-16LE" << QStringConverter::Utf16LE; + QTest::newRow("Utf16LE") << "Utf16LE" << QStringConverter::Utf16LE; + QTest::newRow("UTF-32") << "UTF-32" << QStringConverter::Utf32; + QTest::newRow("Utf32") << "Utf32" << QStringConverter::Utf32; + QTest::newRow("UTF-32BE") << "UTF-32BE" << QStringConverter::Utf32BE; + QTest::newRow("Utf32BE") << "Utf32BE" << QStringConverter::Utf32BE; + QTest::newRow("UTF-32LE") << "UTF-32LE" << QStringConverter::Utf32LE; + QTest::newRow("Utf32LE") << "Utf32LE" << QStringConverter::Utf32LE; + QTest::newRow("ISO-8859-1") << "ISO-8859-1" << QStringConverter::Latin1; + QTest::newRow("Latin1") << "Latin1" << QStringConverter::Latin1; +} + +void TestCsvParser::testUtf16() +{ + writeToFile("café,naïve,résumé", QStringConverter::Utf16); + + parser->setCodec("UTF-16"); + QVERIFY(parser->parse(file.data())); + t = parser->getCsvTable(); + QVERIFY(t.size() == 1); + QCOMPARE(t.at(0).at(0), QString("café")); + QCOMPARE(t.at(0).at(1), QString("naïve")); + QCOMPARE(t.at(0).at(2), QString("résumé")); +} diff --git a/tests/TestCsvParser.h b/tests/TestCsvParser.h index 0b1717a87..e9561d649 100644 --- a/tests/TestCsvParser.h +++ b/tests/TestCsvParser.h @@ -31,9 +31,9 @@ class TestCsvParser : public QObject public: private slots: + void initTestCase(); void init(); void cleanup(); - void initTestCase(); void testUnicode(); void testLF(); @@ -55,9 +55,12 @@ private slots: void testQuoted(); void testMultiline(); void testColumns(); + void testCodec(); + void testCodec_data(); + void testUtf16(); private: - void writeToFile(const QString& contents); + void writeToFile(const QString& contents, QStringConverter::Encoding encoding = QStringConverter::Utf8); QScopedPointer file; QScopedPointer parser; diff --git a/tests/TestDatabase.cpp b/tests/TestDatabase.cpp index 78b6dac1d..6eb2378d9 100644 --- a/tests/TestDatabase.cpp +++ b/tests/TestDatabase.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2017 Vladimir Svyatski - * Copyright (C) 2017 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -42,6 +42,7 @@ static QString dbFileName = QStringLiteral(KEEPASSX_TEST_DATA_DIR).append("/NewD void TestDatabase::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestDatabase::testOpen() @@ -125,7 +126,7 @@ void TestDatabase::testSaveAs() QVERIFY(QFile::exists(newDbFileName)); #ifdef Q_OS_WIN QVERIFY(!QFileInfo(newDbFileName).isHidden()); - SetFileAttributes(newDbFileName.toStdString().c_str(), FILE_ATTRIBUTE_HIDDEN); + SetFileAttributes(newDbFileName.toStdWString().c_str(), FILE_ATTRIBUTE_HIDDEN); QVERIFY2(db->saveAs(newDbFileName, Database::Atomic, QString(), &error), error.toLatin1()); QVERIFY(QFileInfo(newDbFileName).isHidden()); #endif diff --git a/tests/TestDeletedObjects.cpp b/tests/TestDeletedObjects.cpp index ab7d26078..ffc6559ef 100644 --- a/tests/TestDeletedObjects.cpp +++ b/tests/TestDeletedObjects.cpp @@ -29,6 +29,7 @@ QTEST_GUILESS_MAIN(TestDeletedObjects) void TestDeletedObjects::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestDeletedObjects::createAndDelete(QSharedPointer db, int delObjectsSize) diff --git a/tests/TestEntry.cpp b/tests/TestEntry.cpp index 18567001e..bd729dc8d 100644 --- a/tests/TestEntry.cpp +++ b/tests/TestEntry.cpp @@ -30,6 +30,7 @@ QTEST_GUILESS_MAIN(TestEntry) void TestEntry::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestEntry::testHistoryItemDeletion() diff --git a/tests/TestEntryModel.cpp b/tests/TestEntryModel.cpp index e3cdb4a46..e4677324c 100644 --- a/tests/TestEntryModel.cpp +++ b/tests/TestEntryModel.cpp @@ -1,4 +1,5 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2010 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -32,10 +33,13 @@ #include "gui/entry/EntryModel.h" #include "modeltest.h" +const auto restoreDefaultLocale = qScopeGuard([prior = QLocale::c()] { QLocale::setDefault(prior); }); + QTEST_GUILESS_MAIN(TestEntryModel) void TestEntryModel::initTestCase() { + QLocale::setDefault(QLocale::c()); qRegisterMetaType("QModelIndex"); QVERIFY(Crypto::init()); } @@ -219,14 +223,14 @@ void TestEntryModel::testAttributesModel() QCOMPARE(entryAttributes->value("2nd"), value); entryAttributes->clear(); - // test attribute sorting + // test attribute sorting (ASCII) entryAttributes->set("Test1", "1"); - entryAttributes->set("Test11", "11"); entryAttributes->set("Test2", "2"); + entryAttributes->set("Test11", "11"); QCOMPARE(model->rowCount(), 3); QCOMPARE(model->data(model->index(0, 0)).toString(), QString("Test1")); - QCOMPARE(model->data(model->index(1, 0)).toString(), QString("Test2")); - QCOMPARE(model->data(model->index(2, 0)).toString(), QString("Test11")); + QCOMPARE(model->data(model->index(1, 0)).toString(), QString("Test11")); + QCOMPARE(model->data(model->index(2, 0)).toString(), QString("Test2")); QSignalSpy spyReset(model, SIGNAL(modelReset())); entryAttributes->clear(); diff --git a/tests/TestEntrySearcher.cpp b/tests/TestEntrySearcher.cpp index d002a3166..8f16f8462 100644 --- a/tests/TestEntrySearcher.cpp +++ b/tests/TestEntrySearcher.cpp @@ -1,4 +1,5 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2014 Florian Geyer * * This program is free software: you can redistribute it and/or modify @@ -24,6 +25,11 @@ QTEST_GUILESS_MAIN(TestEntrySearcher) +void TestEntrySearcher::initTestCase() +{ + QLocale::setDefault(QLocale::c()); +} + void TestEntrySearcher::init() { m_rootGroup = new Group(); diff --git a/tests/TestEntrySearcher.h b/tests/TestEntrySearcher.h index 54a45d578..265787314 100644 --- a/tests/TestEntrySearcher.h +++ b/tests/TestEntrySearcher.h @@ -28,6 +28,7 @@ class TestEntrySearcher : public QObject Q_OBJECT private slots: + void initTestCase(); void init(); void cleanup(); diff --git a/tests/TestFdoSecrets.cpp b/tests/TestFdoSecrets.cpp index 38a50af99..be660099a 100644 --- a/tests/TestFdoSecrets.cpp +++ b/tests/TestFdoSecrets.cpp @@ -27,6 +27,11 @@ QTEST_GUILESS_MAIN(TestFdoSecrets) +void TestFdoSecrets::initTestCase() +{ + QLocale::setDefault(QLocale::c()); +} + void TestFdoSecrets::testDhIetf1024Sha256Aes128CbcPkcs7() { FdoSecrets::DhIetf1024Sha256Aes128CbcPkcs7 cipher(randomGen()->randomArray(128)); diff --git a/tests/TestFdoSecrets.h b/tests/TestFdoSecrets.h index 05caf588c..bd2ccd62d 100644 --- a/tests/TestFdoSecrets.h +++ b/tests/TestFdoSecrets.h @@ -25,6 +25,8 @@ class TestFdoSecrets : public QObject Q_OBJECT private slots: + void initTestCase(); + void testDhIetf1024Sha256Aes128CbcPkcs7(); void testCrazyAttributeKey(); void testSpecialCharsInAttributeValue(); diff --git a/tests/TestGroup.cpp b/tests/TestGroup.cpp index 22807c878..74242a02c 100644 --- a/tests/TestGroup.cpp +++ b/tests/TestGroup.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2010 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -39,6 +39,7 @@ void TestGroup::initTestCase() qRegisterMetaType("Entry*"); qRegisterMetaType("Group*"); QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestGroup::init() diff --git a/tests/TestGroupModel.cpp b/tests/TestGroupModel.cpp index f9a0790fc..9dcd9cbaf 100644 --- a/tests/TestGroupModel.cpp +++ b/tests/TestGroupModel.cpp @@ -1,4 +1,5 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2010 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -31,6 +32,7 @@ void TestGroupModel::initTestCase() { qRegisterMetaType("QModelIndex"); QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestGroupModel::test() diff --git a/tests/TestHashedBlockStream.cpp b/tests/TestHashedBlockStream.cpp index 9c45d8770..e2c15ea6b 100644 --- a/tests/TestHashedBlockStream.cpp +++ b/tests/TestHashedBlockStream.cpp @@ -1,4 +1,5 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2010 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -28,6 +29,7 @@ QTEST_GUILESS_MAIN(TestHashedBlockStream) void TestHashedBlockStream::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestHashedBlockStream::testWriteRead() diff --git a/tests/TestHibp.cpp b/tests/TestHibp.cpp index 5e85f0728..e4c5300ee 100644 --- a/tests/TestHibp.cpp +++ b/tests/TestHibp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,6 +36,7 @@ const char* TEST_BAD_HIBP_CONTENTS = "barf:nope\n"; void TestHibp::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestHibp::init() diff --git a/tests/TestIconDownloader.cpp b/tests/TestIconDownloader.cpp index 676734ee6..44aebd74c 100644 --- a/tests/TestIconDownloader.cpp +++ b/tests/TestIconDownloader.cpp @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2026 KeePassXC Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "TestIconDownloader.h" #include @@ -7,6 +24,11 @@ QTEST_GUILESS_MAIN(TestIconDownloader) +void TestIconDownloader::initTestCase() +{ + QLocale::setDefault(QLocale::c()); +} + void TestIconDownloader::testIconDownloader() { QFETCH(QString, url); diff --git a/tests/TestIconDownloader.h b/tests/TestIconDownloader.h index cd3d036e1..b45d9156a 100644 --- a/tests/TestIconDownloader.h +++ b/tests/TestIconDownloader.h @@ -1,6 +1,6 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2011 Felix Geyer - * Copyright (C) 2019 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +27,7 @@ class TestIconDownloader : public QObject Q_OBJECT private slots: + void initTestCase(); void testIconDownloader(); void testIconDownloader_data(); }; diff --git a/tests/TestImports.cpp b/tests/TestImports.cpp index 41e5f732c..0cf1edff4 100644 --- a/tests/TestImports.cpp +++ b/tests/TestImports.cpp @@ -36,6 +36,7 @@ QTEST_GUILESS_MAIN(TestImports) void TestImports::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestImports::testOPUX() diff --git a/tests/TestKdbx2.cpp b/tests/TestKdbx2.cpp index c0da4d4a3..75f1d734f 100644 --- a/tests/TestKdbx2.cpp +++ b/tests/TestKdbx2.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,6 +33,7 @@ QTEST_GUILESS_MAIN(TestKdbx2) void TestKdbx2::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } /** diff --git a/tests/TestKdbx4.cpp b/tests/TestKdbx4.cpp index 3233d570a..9727b9cc7 100644 --- a/tests/TestKdbx4.cpp +++ b/tests/TestKdbx4.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -115,6 +115,11 @@ void TestKdbx4AesKdf::initTestCaseImpl() Q_DECLARE_METATYPE(QUuid) +void TestKdbx4Format::initTestCase() +{ + QLocale::setDefault(QLocale::c()); +} + void TestKdbx4Format::init() { MockClock::setup(new MockClock()); diff --git a/tests/TestKdbx4.h b/tests/TestKdbx4.h index cd5bc4788..9b443523f 100644 --- a/tests/TestKdbx4.h +++ b/tests/TestKdbx4.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -56,6 +56,7 @@ class TestKdbx4Format : public QObject Q_OBJECT private slots: + void initTestCase(); void init(); void cleanup(); void testFormat400(); diff --git a/tests/TestKeePass1Reader.cpp b/tests/TestKeePass1Reader.cpp index 18b35b5c7..7b5ca598f 100644 --- a/tests/TestKeePass1Reader.cpp +++ b/tests/TestKeePass1Reader.cpp @@ -1,5 +1,6 @@ /* - * Copyright (C) 2010 Felix Geyer + * Copyright (C) 2026 KeePassXC Team + * Copyright (C) 2026 Felix Geyer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -42,6 +43,7 @@ void TestKeePass1Reader::initTestCase() m_db = reader.readDatabase(filename, "masterpw", nullptr); QVERIFY(m_db); QVERIFY(!reader.hasError()); + QLocale::setDefault(QLocale::c()); } void TestKeePass1Reader::testBasic() @@ -220,6 +222,7 @@ void TestKeePass1Reader::testTwofish() QCOMPARE(db->rootGroup()->children().at(0)->name(), name); } +#ifdef Q_OS_WIN void TestKeePass1Reader::testCP1252Password() { QString name = "CP-1252"; @@ -235,6 +238,7 @@ void TestKeePass1Reader::testCP1252Password() QCOMPARE(db->rootGroup()->children().size(), 1); QCOMPARE(db->rootGroup()->children().at(0)->name(), name); } +#endif void TestKeePass1Reader::cleanupTestCase() { diff --git a/tests/TestKeePass1Reader.h b/tests/TestKeePass1Reader.h index b847d910c..f59f03278 100644 --- a/tests/TestKeePass1Reader.h +++ b/tests/TestKeePass1Reader.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Felix Geyer + * Copyright (C) 2026 Felix Geyer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,7 +39,9 @@ private slots: void testFileKey_data(); void testCompositeKey(); void testTwofish(); +#ifdef Q_OS_WIN void testCP1252Password(); +#endif void cleanupTestCase(); private: diff --git a/tests/TestKeePass2Format.cpp b/tests/TestKeePass2Format.cpp index 5451fb62b..b5741a5e3 100644 --- a/tests/TestKeePass2Format.cpp +++ b/tests/TestKeePass2Format.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,6 +32,7 @@ void TestKeePass2Format::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); // read raw XML database bool hasError; diff --git a/tests/TestKeePass2RandomStream.cpp b/tests/TestKeePass2RandomStream.cpp index b627454e2..05451898b 100644 --- a/tests/TestKeePass2RandomStream.cpp +++ b/tests/TestKeePass2RandomStream.cpp @@ -1,4 +1,5 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2010 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -30,6 +31,7 @@ QTEST_GUILESS_MAIN(TestKeePass2RandomStream) void TestKeePass2RandomStream::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestKeePass2RandomStream::test() diff --git a/tests/TestKeys.cpp b/tests/TestKeys.cpp index 271d53c1d..c2a72d512 100644 --- a/tests/TestKeys.cpp +++ b/tests/TestKeys.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2011 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -41,6 +41,7 @@ Q_DECLARE_METATYPE(FileKey::Type); void TestKeys::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestKeys::testComposite() diff --git a/tests/TestMerge.cpp b/tests/TestMerge.cpp index 1465e57db..b6fc38434 100644 --- a/tests/TestMerge.cpp +++ b/tests/TestMerge.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,6 +37,7 @@ void TestMerge::initTestCase() qRegisterMetaType("Entry*"); qRegisterMetaType("Group*"); QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestMerge::init() diff --git a/tests/TestModified.cpp b/tests/TestModified.cpp index d331739eb..561416874 100644 --- a/tests/TestModified.cpp +++ b/tests/TestModified.cpp @@ -1,4 +1,5 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2012 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -35,6 +36,7 @@ namespace void TestModified::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestModified::init() diff --git a/tests/TestOpenSSHKey.cpp b/tests/TestOpenSSHKey.cpp index a20b248ed..0a64424b8 100644 --- a/tests/TestOpenSSHKey.cpp +++ b/tests/TestOpenSSHKey.cpp @@ -1,4 +1,5 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2017 Toni Spets * * This program is free software: you can redistribute it and/or modify @@ -27,6 +28,7 @@ QTEST_GUILESS_MAIN(TestOpenSSHKey) void TestOpenSSHKey::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestOpenSSHKey::testParse() diff --git a/tests/TestPasskeys.cpp b/tests/TestPasskeys.cpp index 82f649e9c..ddf1da1eb 100644 --- a/tests/TestPasskeys.cpp +++ b/tests/TestPasskeys.cpp @@ -117,6 +117,7 @@ const QJsonArray validPubKeyCredParams = { void TestPasskeys::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestPasskeys::init() @@ -283,22 +284,12 @@ void TestPasskeys::testCreatingAttestationObjectWithEC() const auto credentialPrivateKey = browserPasskeys()->buildCredentialPrivateKey(alg, testingVariables); auto result = browserPasskeys()->buildAttestationObject( credentialCreationOptions, "", id, credentialPrivateKey.cborEncodedPublicKey, testingVariables); - QCOMPARE( - result, - QString("\xA3" - "cfmtdnonegattStmt\xA0hauthDataX\xA4t\xA6\xEA\x92\x13\xC9\x9C/t\xB2$\x92\xB3 \xCF@&*\x94\xC1\xA9P\xA0" - "9\x7F)%\x0B`\x84\x1E\xF0]\x00\x00\x00\x00\xFD\xB1" - "A\xB2]\x84" - "D>\x8A" - "5F\x98\xC2\x05\xA5\x02\x00 \xCA\xBC\xC5'\x99pr\x94\xF0`\xC3\x9D])\xB1\x17\x96\xF9q\x84%\xA8\x13" - "3m\xB5?w\xEA\x05,\xEF\xA5\x01\x02\x03& \x01!X \x06\xEC\xAF" - "4[b\x91" - "am\x19Y\x03\xA6P*\xCA" - "1\xC4\x95\xA8i\xE5\xF0\x87\xE5\xD4\xB8" - "2\xCD\b\x85\xDD\"X \xE2\xEE\x7F\xE9\x0F\x0E\xE9\x1D\x07\x83J\x03\t\xDB" - "B$\xB1\x0B\xD3%\xFF\x18" - "2\xE1S\x99\xB7\x1D" - "B\x04\xE7\x83")); + QCOMPARE(result, + QByteArray::fromHex( + "a363666d74646e6f6e656761747453746d74a068617574684461746158a474a6ea9213c99c2f74b22492b320cf40262a94c1a" + "950a0397f29250b60841ef05d00000000fdb141b25d84443e8a354698c205a5020020cabcc52799707294f060c39d5d29b117" + "96f9718425a813336db53f77ea052cefa501020326200121582006ecaf345b6291616d195903a6502aca31c495a869e5f087e" + "5d4b832cd0885dd225820e2ee7fe90f0ee91d07834a0309db4224b10bd325ff1832e15399b71d4204e783")); // Double check that the result can be decoded BrowserCbor browserCbor; diff --git a/tests/TestPassphraseGenerator.cpp b/tests/TestPassphraseGenerator.cpp index 7b8dd89a4..1b599fdc6 100644 --- a/tests/TestPassphraseGenerator.cpp +++ b/tests/TestPassphraseGenerator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +28,7 @@ QTEST_GUILESS_MAIN(TestPassphraseGenerator) void TestPassphraseGenerator::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestPassphraseGenerator::testWordCase() diff --git a/tests/TestPasswordGenerator.cpp b/tests/TestPasswordGenerator.cpp index 10b91f6af..63ad338b0 100644 --- a/tests/TestPasswordGenerator.cpp +++ b/tests/TestPasswordGenerator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -42,6 +42,7 @@ namespace void TestPasswordGenerator::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestPasswordGenerator::init() diff --git a/tests/TestPasswordHealth.cpp b/tests/TestPasswordHealth.cpp index 25c531585..a069832b0 100644 --- a/tests/TestPasswordHealth.cpp +++ b/tests/TestPasswordHealth.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,6 +25,7 @@ QTEST_GUILESS_MAIN(TestPasswordHealth) void TestPasswordHealth::initTestCase() { + QLocale::setDefault(QLocale::c()); } void TestPasswordHealth::testNoDb() diff --git a/tests/TestRandomGenerator.cpp b/tests/TestRandomGenerator.cpp index e353070bb..7fe95af3b 100644 --- a/tests/TestRandomGenerator.cpp +++ b/tests/TestRandomGenerator.cpp @@ -1,4 +1,6 @@ + /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2013 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -24,6 +26,11 @@ QTEST_GUILESS_MAIN(TestRandomGenerator) +void TestRandomGenerator::initTestCase() +{ + QLocale::setDefault(QLocale::c()); +} + void TestRandomGenerator::testArray() { auto ba = randomGen()->randomArray(10); diff --git a/tests/TestRandomGenerator.h b/tests/TestRandomGenerator.h index 6f9c335e4..3e56d0dab 100644 --- a/tests/TestRandomGenerator.h +++ b/tests/TestRandomGenerator.h @@ -1,4 +1,5 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2013 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -25,6 +26,7 @@ class TestRandomGenerator : public QObject Q_OBJECT private slots: + void initTestCase(); void testArray(); void testUInt(); void testUIntRange(); diff --git a/tests/TestSSHAgent.cpp b/tests/TestSSHAgent.cpp index 986def7b8..6ff0f18a7 100644 --- a/tests/TestSSHAgent.cpp +++ b/tests/TestSSHAgent.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ #include "sshagent/OpenSSHKeyGen.h" #include "sshagent/SSHAgent.h" +#include #include QTEST_GUILESS_MAIN(TestSSHAgent) @@ -30,6 +31,7 @@ QTEST_GUILESS_MAIN(TestSSHAgent) void TestSSHAgent::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); // Create temporary config file Config::createConfigFromFile(TemporaryFile::createTempConfigFile(), {}); diff --git a/tests/TestSharing.cpp b/tests/TestSharing.cpp index 0b5414ea8..a9492f356 100644 --- a/tests/TestSharing.cpp +++ b/tests/TestSharing.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,6 +35,7 @@ Q_DECLARE_METATYPE(KeeShareSettings::Certificate) void TestSharing::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestSharing::testNullObjects() @@ -83,7 +84,7 @@ void TestSharing::testKeySerialization() writer.writeEndDocument(); QXmlStreamReader reader(buffer); reader.readNextStartElement(); - QVERIFY(reader.name() == "Key"); + QVERIFY(reader.name().toString() == "Key"); KeeShareSettings::Key restored = KeeShareSettings::Key::deserialize(reader); QCOMPARE(restored.key->private_key_bits(), original.key->private_key_bits()); diff --git a/tests/TestSymmetricCipher.cpp b/tests/TestSymmetricCipher.cpp index 77a80e271..331ac5ba9 100644 --- a/tests/TestSymmetricCipher.cpp +++ b/tests/TestSymmetricCipher.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2010 Felix Geyer - * Copyright (C) 2017 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,6 +33,7 @@ Q_DECLARE_METATYPE(SymmetricCipher::Direction); void TestSymmetricCipher::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestSymmetricCipher::testCipherUuidToMode() diff --git a/tests/TestTools.cpp b/tests/TestTools.cpp index 3d59399e0..b409b1356 100644 --- a/tests/TestTools.cpp +++ b/tests/TestTools.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,6 +43,7 @@ void TestTools::initTestCase() Q_ASSERT(s_clock == nullptr); s_clock = new MockClock(2026, 3, 8, 21, 45, 05); MockClock::setup(s_clock); + QLocale::setDefault(QLocale::c()); } void TestTools::cleanupTestCase() @@ -426,7 +427,7 @@ void TestTools::testGetMimeTypeByFileInfo() const QStringList UnknownHeaders = {"test.doc", "test.pdf", "test.docx"}; for (const auto& unknown : UnknownHeaders) { - QCOMPARE(Tools::getMimeType(unknown), Tools::MimeType::Unknown); + QCOMPARE(Tools::getMimeType(QFileInfo(unknown)), Tools::MimeType::Unknown); } } diff --git a/tests/TestTotp.cpp b/tests/TestTotp.cpp index 13aaf9a2d..0e2a5ce42 100644 --- a/tests/TestTotp.cpp +++ b/tests/TestTotp.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2017 Weslly Honorato - * Copyright (C) 2017 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,6 +29,7 @@ QTEST_GUILESS_MAIN(TestTotp) void TestTotp::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestTotp::testParseSecret() diff --git a/tests/TestUpdateCheck.cpp b/tests/TestUpdateCheck.cpp index f89757ea6..d7bd8b54d 100644 --- a/tests/TestUpdateCheck.cpp +++ b/tests/TestUpdateCheck.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +26,7 @@ QTEST_GUILESS_MAIN(TestUpdateCheck) void TestUpdateCheck::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestUpdateCheck::testCompareVersion() diff --git a/tests/TestUrlTools.cpp b/tests/TestUrlTools.cpp index ae059d228..31f1eeea2 100644 --- a/tests/TestUrlTools.cpp +++ b/tests/TestUrlTools.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2025 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ QTEST_GUILESS_MAIN(TestUrlTools) void TestUrlTools::initTestCase() { m_urlTools = urlTools(); + QLocale::setDefault(QLocale::c()); } void TestUrlTools::init() diff --git a/tests/TestYkChallengeResponseKey.cpp b/tests/TestYkChallengeResponseKey.cpp index 02a0b5bea..dab6fc4e2 100644 --- a/tests/TestYkChallengeResponseKey.cpp +++ b/tests/TestYkChallengeResponseKey.cpp @@ -1,21 +1,21 @@ /* - * Copyright (C) 2014 Kyle Manna - * Copyright (C) 2017 KeePassXC Team - * - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 or (at your option) - * version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ +** Copyright (C) 2026 KeePassXC Team +* Copyright (C) 2014 Kyle Manna +* +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 or (at your option) +* version 3 of the License. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ #include "TestYkChallengeResponseKey.h" @@ -34,6 +34,7 @@ void TestYubiKeyChallengeResponse::initTestCase() { // crypto subsystem needs to be initialized for YubiKey testing QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); if (!YubiKey::instance()->isInitialized()) { QSKIP("Unable to initialize YubiKey interface."); diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index adf359324..a4f159584 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2010 Felix Geyer - * Copyright (C) 2020 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -353,7 +353,7 @@ void TestGui::testMergeDatabase() QSignalSpy dbMergeSpy(m_dbWidget.data(), SIGNAL(databaseMerged(QSharedPointer))); QApplication::processEvents(); - // set file to merge from + // Set file to merge from fileDialog()->setNextFileName(QString(KEEPASSX_TEST_DATA_DIR).append("/MergeDatabase.kdbx")); triggerAction("actionDatabaseMerge"); @@ -364,9 +364,21 @@ void TestGui::testMergeDatabase() QTest::keyClicks(editPasswordMerge, "a"); QTest::keyClick(editPasswordMerge, Qt::Key_Enter); - // confirm merge in confirmation dialog - QTRY_VERIFY(QApplication::focusWindow()->title().contains("Merge")); - QTest::keyClick(QApplication::focusWidget(), Qt::Key_Enter); + // Confirm merge in confirmation dialog + auto focusedWindow = QApplication::topLevelWindows().last(); + QVERIFY(focusedWindow); + QTRY_VERIFY(focusedWindow->title().contains("Merge")); + + auto topLevelWidgets = QApplication::topLevelWidgets(); + QWidget* mergeDialog = nullptr; + for (auto* widget : topLevelWidgets) { + if (widget && widget->objectName() == "MergeDialog") { + mergeDialog = widget; + } + } + + QVERIFY(mergeDialog); + QTest::keyClick(mergeDialog, Qt::Key_Enter); QTRY_COMPARE(dbMergeSpy.count(), 1); QTRY_VERIFY(m_tabWidget->tabText(m_tabWidget->currentIndex()).contains("*")); @@ -540,12 +552,15 @@ void TestGui::testAutoreloadDatabase() MessageBox::setNextAnswer(MessageBox::Yes); // Overwrite the current database with the temp data QVERIFY(m_dbFile.copyFromFile(QString(KEEPASSX_TEST_DATA_DIR).append("/MergeDatabase.kdbx"))); + QApplication::processEvents(); QTRY_VERIFY(m_db != m_dbWidget->database()); m_db = m_dbWidget->database(); // the General group contains one entry from the new db data - QCOMPARE(m_db->rootGroup()->findChildByName("General")->entries().size(), 1); + auto generalGroup = m_db->rootGroup()->findChildByName("General"); + QVERIFY(generalGroup); + QCOMPARE(generalGroup->entries().size(), 1); QVERIFY(!m_tabWidget->tabText(m_tabWidget->currentIndex()).endsWith("*")); // Reset the state @@ -558,9 +573,12 @@ void TestGui::testAutoreloadDatabase() MessageBox::setNextAnswer(MessageBox::No); // Overwrite the current database with the temp data QVERIFY(m_dbFile.copyFromFile(QString(KEEPASSX_TEST_DATA_DIR).append("/MergeDatabase.kdbx"))); + QApplication::processEvents(); // Ensure the merge did not take place - QCOMPARE(m_db->rootGroup()->findChildByName("General")->entries().size(), 0); + generalGroup = m_db->rootGroup()->findChildByName("General"); + QVERIFY(generalGroup); + QCOMPARE(generalGroup->entries().size(), 0); QTRY_VERIFY(m_tabWidget->tabText(m_tabWidget->currentIndex()).endsWith("*")); // Reset the state @@ -577,11 +595,14 @@ void TestGui::testAutoreloadDatabase() MessageBox::setNextAnswer(MessageBox::Merge); // Overwrite the current database with the temp data QVERIFY(m_dbFile.copyFromFile(QString(KEEPASSX_TEST_DATA_DIR).append("/MergeDatabase.kdbx"))); + QApplication::processEvents(); QTRY_VERIFY(m_db != m_dbWidget->database()); m_db = m_dbWidget->database(); - QCOMPARE(m_db->rootGroup()->findChildByName("General")->entries().size(), 1); + generalGroup = m_db->rootGroup()->findChildByName("General"); + QVERIFY(generalGroup); + QCOMPARE(generalGroup->entries().size(), 1); QTRY_VERIFY(m_tabWidget->tabText(m_tabWidget->currentIndex()).endsWith("*")); } @@ -681,8 +702,8 @@ void TestGui::testEditEntry() // Test entry colors (simulate choosing a color) editEntryWidget->switchToPage(EditEntryWidget::Page::Advanced); - auto fgColor = QString("#FF0000"); - auto bgColor = QString("#0000FF"); + auto fgColor = QColor(255, 0, 0); + auto bgColor = QColor(0, 0, 255); // Set foreground color auto colorButton = editEntryWidget->findChild("fgColorButton"); auto colorCheckBox = editEntryWidget->findChild("fgColorCheckBox"); @@ -716,9 +737,9 @@ void TestGui::testEditEntry() // Confirm edit was made QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode); QCOMPARE(entry->title(), QString("Sample Entry_test")); - QCOMPARE(entry->foregroundColor().toUpper(), fgColor.toUpper()); + QCOMPARE(entry->foregroundColor().toUpper(), fgColor.name().toUpper()); QCOMPARE(entryItem.data(Qt::ForegroundRole), QVariant(fgColor)); - QCOMPARE(entry->backgroundColor().toUpper(), bgColor.toUpper()); + QCOMPARE(entry->backgroundColor().toUpper(), bgColor.name().toUpper()); QCOMPARE(entryItem.data(Qt::BackgroundRole), QVariant(bgColor)); QCOMPARE(entry->historyItems().size(), ++editCount); @@ -2146,7 +2167,7 @@ void TestGui::testShortcutConfig() ActionCollection::instance()->addAction(a); QVERIFY(ActionCollection::instance()->actions().contains(a)); - const QKeySequence seq(Qt::CTRL + Qt::SHIFT + Qt::ALT + Qt::Key_N); + const QKeySequence seq(Qt::CTRL | Qt::SHIFT | Qt::ALT | Qt::Key_N); ActionCollection::instance()->setDefaultShortcut(a, seq); QCOMPARE(ActionCollection::instance()->defaultShortcut(a), seq); @@ -2157,7 +2178,7 @@ void TestGui::testShortcutConfig() QVERIFY(v); // Change shortcut and save - const QKeySequence newSeq(Qt::CTRL + Qt::SHIFT + Qt::ALT + Qt::Key_M); + const QKeySequence newSeq(Qt::CTRL | Qt::SHIFT | Qt::ALT | Qt::Key_M); a->setShortcut(newSeq); QVERIFY(a->shortcut() != ActionCollection::instance()->defaultShortcut(a)); ActionCollection::instance()->saveShortcuts(); diff --git a/tests/gui/TestGuiBrowser.cpp b/tests/gui/TestGuiBrowser.cpp index 26fd72690..ed77a2701 100644 --- a/tests/gui/TestGuiBrowser.cpp +++ b/tests/gui/TestGuiBrowser.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2010 Felix Geyer - * Copyright (C) 2020 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -73,6 +73,8 @@ void TestGuiBrowser::initTestCase() m_mainWindow.reset(new MainWindow()); m_tabWidget = m_mainWindow->findChild("tabWidget"); m_mainWindow->show(); + + QLocale::setDefault(QLocale::c()); } // Every test starts with opening the temp database @@ -204,7 +206,6 @@ void TestGuiBrowser::testAdditionalURLs() QTest::mouseClick(addURLButton, Qt::LeftButton); QApplication::processEvents(); QTest::keyClicks(urlList->focusWidget(), url); - QTest::keyClick(urlList->focusWidget(), Qt::Key_Enter); } // Check the values from attributesEdit diff --git a/tests/gui/TestGuiFdoSecrets.cpp b/tests/gui/TestGuiFdoSecrets.cpp index fc7e218ea..80d0d4eb9 100644 --- a/tests/gui/TestGuiFdoSecrets.cpp +++ b/tests/gui/TestGuiFdoSecrets.cpp @@ -1,4 +1,5 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2019 Aetf * * This program is free software: you can redistribute it and/or modify @@ -131,6 +132,7 @@ char* toString(const QDBusObjectPath& path) return QTest::toString("ObjectPath(" + path.path() + ")"); } +TestGuiFdoSecrets::TestGuiFdoSecrets() = default; TestGuiFdoSecrets::~TestGuiFdoSecrets() = default; void TestGuiFdoSecrets::initTestCase() @@ -177,6 +179,8 @@ void TestGuiFdoSecrets::initTestCase() // set a fake dbus client all the time so we can freely access DBusMgr anywhere m_client.reset(new FakeClient(m_plugin->dbus().data())); m_plugin->dbus()->overrideClient(m_client); + + QLocale::setDefault(QLocale::c()); } // Every test starts with opening the temp database diff --git a/tests/gui/TestGuiFdoSecrets.h b/tests/gui/TestGuiFdoSecrets.h index 1624eed49..c6809f38b 100644 --- a/tests/gui/TestGuiFdoSecrets.h +++ b/tests/gui/TestGuiFdoSecrets.h @@ -55,6 +55,7 @@ class TestGuiFdoSecrets : public QObject Q_OBJECT public: + explicit TestGuiFdoSecrets(); ~TestGuiFdoSecrets() override; private slots: @@ -145,6 +146,8 @@ private: } private: + Q_DISABLE_COPY(TestGuiFdoSecrets) + QScopedPointer m_mainWindow; QPointer m_tabWidget; QPointer m_dbWidget; diff --git a/tests/gui/TestGuiPixmaps.cpp b/tests/gui/TestGuiPixmaps.cpp index f18cba221..381050864 100644 --- a/tests/gui/TestGuiPixmaps.cpp +++ b/tests/gui/TestGuiPixmaps.cpp @@ -1,4 +1,5 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2011 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -28,6 +29,7 @@ void TestGuiPixmaps::initTestCase() { QVERIFY(Crypto::init()); + QLocale::setDefault(QLocale::c()); } void TestGuiPixmaps::testDatabaseIcons() diff --git a/tests/gui/TestGuiPixmaps.h b/tests/gui/TestGuiPixmaps.h index 4f73d7e0d..2dfbab263 100644 --- a/tests/gui/TestGuiPixmaps.h +++ b/tests/gui/TestGuiPixmaps.h @@ -1,4 +1,5 @@ /* + * Copyright (C) 2025 KeePassXC Team * Copyright (C) 2011 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -19,6 +20,7 @@ #define KEEPASSX_TESTGUIPIXMAPS_H #include +#include class TestGuiPixmaps : public QObject { diff --git a/tests/gui/attachments/TestTextAttachmentsPreviewWidget.cpp b/tests/gui/attachments/TestTextAttachmentsPreviewWidget.cpp index 0ddea53e3..bf64898a9 100644 --- a/tests/gui/attachments/TestTextAttachmentsPreviewWidget.cpp +++ b/tests/gui/attachments/TestTextAttachmentsPreviewWidget.cpp @@ -29,12 +29,10 @@ void TestTextAttachmentsPreviewWidget::testDetectMimeByFile() QCOMPARE(combobox->currentData().toInt(), TextAttachmentsPreviewWidget::Html); -#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) const attachments::Attachment Markdown{.name = "test.md", .data = {}}; m_widget->openAttachment(Markdown, attachments::OpenMode::ReadOnly); QCoreApplication::processEvents(); QCOMPARE(combobox->currentData().toInt(), TextAttachmentsPreviewWidget::Markdown); -#endif } diff --git a/vcpkg.json b/vcpkg.json index 9c38d3d6c..d0a4880a0 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -3,64 +3,22 @@ "version-string": "2.8.0", "builtin-baseline": "66c0373dc7fca549e5803087b9487edfe3aca0a1", "dependencies": [ - { - "name": "argon2", - "version>=": "20190702" - }, - { - "name": "botan", - "version>=": "3.1.1" - }, - { - "name": "minizip", - "version>=": "1.3" - }, - { - "name": "libqrencode", - "version>=": "4.1.1" - }, + "botan", + "minizip", + "libqrencode", + "readline", + "zlib", { "name": "libusb", - "version>=": "1.0.26.11791", "platform": "linux | freebsd" }, { "name": "libxi", - "version>=": "1.8", "platform": "linux | freebsd" }, { "name": "libxtst", - "version>=": "1.2.4", "platform": "linux | freebsd" - }, - { - "name": "qt5", - "version>=": "5.15.17", - "features": [ - "declarative", - "extras", - "imageformats", - "svg", - "tools", - "translations" - ], - "default-features": false - }, - { - "name": "qt5", - "features": [ - "wayland" - ], - "platform": "linux | freebsd" - }, - { - "name": "readline", - "version>=": "0#5" - }, - { - "name": "zlib", - "version>=": "1.3" } ] }