Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Qt6 transition #10267

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 19 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2018 KeePassXC Team <team@keepassxc.org>
# Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
# Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
#
# This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -205,6 +205,9 @@ if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14.0")
check_pie_supported()
endif()

# Find Qt5 compatibility library
find_package(Qt6 REQUIRED COMPONENTS Core5Compat)

# Find Botan early since the version affects subsequent compiler options
find_package(Botan REQUIRED)
if(BOTAN_VERSION VERSION_GREATER_EQUAL "3.0.0")
Expand Down Expand Up @@ -496,37 +499,22 @@ if(UNIX AND NOT APPLE)
if(WITH_XC_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)
endif()

if(Qt5Core_VERSION VERSION_LESS "5.2.0")
message(FATAL_ERROR "Qt version 5.2.0 or higher is required")
find_package(Qt6 COMPONENTS ${QT_COMPONENTS} REQUIRED)
endif()

# CBOR for Passkeys requires Qt 5.12
if(Qt5Core_VERSION VERSION_LESS "5.12.0")
message(STATUS "Qt version 5.12.0 or higher is required for Passkeys support")
set(WITH_XC_BROWSER_PASSKEYS OFF)
if(Qt6Core_VERSION VERSION_LESS "6.6.0")
message(FATAL_ERROR "Qt version 6.6.0 or higher is required")
endif()

get_filename_component(Qt5_PREFIX ${Qt5_DIR}/../../.. REALPATH)
if(APPLE)
# Add includes under Qt5 Prefix in case Qt6 is also installed
include_directories(SYSTEM ${Qt5_PREFIX}/include)
endif()
get_filename_component(Qt6_PREFIX ${Qt6_DIR}/../../.. REALPATH)

# Process moc automatically
set(CMAKE_AUTOMOC ON)
Expand All @@ -537,18 +525,18 @@ set(CMAKE_AUTORCC ON)

if(APPLE)
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 macdeployqt6 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")
message(FATAL_ERROR "macdeployqt6 is required to build on macOS")
endif()
message(STATUS "Using macdeployqt: ${MACDEPLOYQT_EXE}")
message(STATUS "Using macdeployqt6: ${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 windeployqt6 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")
message(FATAL_ERROR "windeployqt6 is required to build on Windows")
endif()
message(STATUS "Using windeployqt: ${WINDEPLOYQT_EXE}")
message(STATUS "Using windeployq6t: ${WINDEPLOYQT_EXE}")
endif()

# Debian sets the build type to None for package builds.
Expand Down
14 changes: 7 additions & 7 deletions release-tool
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,10 @@ checkXcodeSetup() {
fi
}

checkQt5LUpdateExists() {
checkQt6LUpdateExists() {
if cmdExists lupdate && ! $(lupdate -version | grep -q "lupdate version 5\."); then
if ! cmdExists lupdate-qt5; then
exitError "Qt Linguist tool (lupdate-qt5) is not installed! Please install using 'apt install qttools5-dev-tools'"
if ! cmdExists lupdate-qt6; then
exitError "Qt Linguist tool (lupdate-qt6) is not installed! Please install using 'apt install qttools6-dev-tools'"
fi
fi
}
Expand All @@ -379,7 +379,7 @@ performChecks() {
logInfo "Validating toolset and repository..."

checkTransifexCommandExists
checkQt5LUpdateExists
checkQt6LUpdateExists
checkGitRepository
checkReleaseDoesNotExist
checkWorkingTreeClean
Expand Down Expand Up @@ -955,7 +955,7 @@ build() {
export MACOSX_DEPLOYMENT_TARGET

logInfo "Configuring build..."
cmake -G "${CMAKE_GENERATOR}" -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES="$(uname -m)" \
cmake -G "${CMAKE_GENERATOR}" -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" \
-DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" ${CMAKE_OPTIONS} "$SRC_DIR"

logInfo "Compiling and packaging sources..."
Expand Down Expand Up @@ -1404,10 +1404,10 @@ i18n() {
exit 1
fi

checkQt5LUpdateExists
checkQt6LUpdateExists

logInfo "Updating source translation file..."
LUPDATE=lupdate-qt5
LUPDATE=lupdate-qt6
if ! command -v $LUPDATE > /dev/null; then
LUPDATE=lupdate
fi
Expand Down
8 changes: 4 additions & 4 deletions share/translations/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
# Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
# Copyright (C) 2014 Felix Geyer <debfx@fobos.de>
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -20,15 +20,15 @@ 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})

Expand Down
31 changes: 16 additions & 15 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ if(UNIX AND NOT APPLE)
list(APPEND keepassx_SOURCES
gui/osutils/nixutils/X11Funcs.cpp)
endif()
qt5_add_dbus_adaptor(keepassx_SOURCES
qt6_add_dbus_adaptor(keepassx_SOURCES
gui/org.keepassxc.KeePassXC.MainWindow.xml
gui/MainWindow.h
MainWindow)
Expand All @@ -235,7 +235,7 @@ if(UNIX AND NOT APPLE)
PROPERTIES
INCLUDE "quickunlock/PolkitDbusTypes.h"
)
qt5_add_dbus_interface(keepassx_SOURCES
qt6_add_dbus_interface(keepassx_SOURCES
quickunlock/dbus/org.freedesktop.PolicyKit1.Authority.xml
polkit_dbus
)
Expand Down Expand Up @@ -374,20 +374,24 @@ configure_file(config-keepassx.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-keepas
configure_file(git-info.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/git-info.h)

add_library(autotype STATIC ${autotype_SOURCES})
target_link_libraries(autotype Qt5::Core Qt5::Widgets)
target_link_libraries(autotype Qt6::Core Qt6::Network Qt6::Widgets)

add_library(keepassx_core STATIC ${keepassx_SOURCES})

find_package(Qt6 REQUIRED COMPONENTS SvgWidgets)

set_target_properties(keepassx_core PROPERTIES COMPILE_DEFINITIONS KEEPASSX_BUILDING_CORE)
target_link_libraries(keepassx_core
autotype
${keepassxcbrowser_LIB}
${qrcode_LIB}
${fdosecrets_LIB}
Qt5::Core
Qt5::Concurrent
Qt5::Network
Qt5::Widgets
Qt6::Core
Qt6::Core5Compat
Qt6::Concurrent
Qt6::Network
Qt6::SvgWidgets
Qt6::Widgets
${BOTAN_LIBRARIES}
${PCSC_LIBRARIES}
${ZXCVBN_LIBRARIES}
Expand All @@ -407,19 +411,16 @@ endif()

if(APPLE)
target_link_libraries(keepassx_core "-framework Foundation -framework AppKit -framework Carbon -framework Security -framework LocalAuthentication")
if(Qt5MacExtras_FOUND)
target_link_libraries(keepassx_core Qt5::MacExtras)
endif()
endif()
if(HAIKU)
target_link_libraries(keepassx_core network)
endif()
if(UNIX AND NOT APPLE)
target_link_libraries(keepassx_core Qt5::DBus ${LIBUSB_LIBRARIES})
target_link_libraries(keepassx_core Qt6::DBus ${LIBUSB_LIBRARIES})
if(WITH_XC_X11)
target_link_libraries(keepassx_core Qt5::X11Extras X11)
target_link_libraries(keepassx_core Qt6::X11Extras X11)
endif()
include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
include_directories(${Qt6Gui_PRIVATE_INCLUDE_DIRS})
endif()
if(WIN32)
target_link_libraries(keepassx_core Wtsapi32.lib Ws2_32.lib)
Expand Down Expand Up @@ -540,7 +541,7 @@ if(WIN32)
COMPONENT Runtime)

# Use windeployqt.exe to setup Qt dependencies
if(Qt5Core_VERSION VERSION_LESS "5.14.1")
if(Qt6Core_VERSION VERSION_LESS "6.6.0") # TODO: Check this.
set(WINDEPLOYQT_MODE "--release")
if(CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
set(WINDEPLOYQT_MODE "--debug")
Expand Down Expand Up @@ -573,7 +574,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()
Expand Down
3 changes: 2 additions & 1 deletion src/autotype/AutoType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "autotype/AutoTypePlatformPlugin.h"
#include "autotype/AutoTypeSelectDialog.h"
#include "autotype/PickcharsDialog.h"
#include "core/Global.h"
#include "core/Resources.h"
#include "core/Tools.h"
#include "gui/MainWindow.h"
Expand Down Expand Up @@ -458,7 +459,7 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi
if (hideExpired && entry->isExpired()) {
continue;
}
auto sequences = entry->autoTypeSequences(m_windowTitleForGlobal).toSet();
const QSet<QString> sequences = Tools::asSet(entry->autoTypeSequences(m_windowTitleForGlobal));
for (const auto& sequence : sequences) {
matchList << AutoTypeMatch(entry, sequence);
}
Expand Down
4 changes: 2 additions & 2 deletions src/autotype/AutoTypeMatch.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
*
* 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
Expand All @@ -18,10 +18,10 @@
#ifndef KPXC_AUTOTYPEMATCH_H
#define KPXC_AUTOTYPEMATCH_H

#include "core/Entry.h"
#include <QPair>
#include <QPointer>

class Entry;
typedef QPair<QPointer<Entry>, QString> AutoTypeMatch;

#endif // KPXC_AUTOTYPEMATCH_H
8 changes: 4 additions & 4 deletions src/autotype/AutoTypeMatchView.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2015 David Wu <lightvector@gmail.com>
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
*
* 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
Expand Down Expand Up @@ -38,9 +38,9 @@ class CustomSortFilterProxyModel : public QSortFilterProxyModel
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());
}
};

Expand Down
2 changes: 0 additions & 2 deletions src/autotype/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
if(WITH_XC_AUTOTYPE)
if(UNIX AND NOT APPLE AND NOT HAIKU)
find_package(X11 REQUIRED COMPONENTS Xi XTest)
find_package(Qt5X11Extras 5.2 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")
endif()

add_subdirectory(xcb)
Expand Down
8 changes: 4 additions & 4 deletions src/autotype/mac/AutoTypeMac.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2016 Lennart Glauer <mail@lennart-glauer.de>
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
*
* 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
Expand All @@ -23,8 +23,8 @@
#include <QtPlugin>
#include <memory>

#include "autotype/AutoTypePlatformPlugin.h"
#include "autotype/AutoTypeAction.h"
#include "autotype/AutoTypePlatformPlugin.h"

class AutoTypePlatformMac : public QObject, public AutoTypePlatformInterface
{
Expand All @@ -45,7 +45,7 @@ class AutoTypePlatformMac : public QObject, public AutoTypePlatformInterface
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);
Expand All @@ -65,4 +65,4 @@ class AutoTypeExecutorMac : public AutoTypeExecutor
AutoTypePlatformMac* const m_platform;
};

#endif // KEEPASSX_AUTOTYPEMAC_H
#endif // KEEPASSX_AUTOTYPEMAC_H
2 changes: 1 addition & 1 deletion src/autotype/mac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
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)
Expand Down
2 changes: 1 addition & 1 deletion src/autotype/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 keepassx_core ${autotype_LIB} Qt5::Core Qt5::Widgets)
target_link_libraries(keepassxc-autotype-test keepassx_core ${autotype_LIB} Qt6::Core Qt6::Widgets)
9 changes: 5 additions & 4 deletions src/browser/BrowserEntryConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "BrowserEntryConfig.h"

#include "core/Entry.h"
#include "core/Global.h"
#include "core/Tools.h"

#include <QJsonDocument>
Expand All @@ -34,22 +35,22 @@ BrowserEntryConfig::BrowserEntryConfig(QObject* parent)

QStringList BrowserEntryConfig::allowedHosts() const
{
return m_allowedHosts.toList();
return m_allowedHosts.values();
}

void BrowserEntryConfig::setAllowedHosts(const QStringList& allowedHosts)
{
m_allowedHosts = allowedHosts.toSet();
m_allowedHosts = Tools::asSet(allowedHosts);
}

QStringList BrowserEntryConfig::deniedHosts() const
{
return m_deniedHosts.toList();
return m_deniedHosts.values();
}

void BrowserEntryConfig::setDeniedHosts(const QStringList& deniedHosts)
{
m_deniedHosts = deniedHosts.toSet();
m_deniedHosts = Tools::asSet(deniedHosts);
}

bool BrowserEntryConfig::isAllowed(const QString& host) const
Expand Down