Skip to content

Commit

Permalink
Require Qt >= 5.12
Browse files Browse the repository at this point in the history
Bump the minimum required Qt version up to 5.12, as per
keepassxreboot#10859 (comment).
Previously, the minimum version was 5.2.0 based on the CMakeLists.txt
check, though it's unclear if such old versions would actually work.

With this, we are able to remove a whole bunch of #ifdef'd code.
  • Loading branch information
c4rlo authored and pull[bot] committed Jun 23, 2024
1 parent 845edbb commit e2a0520
Show file tree
Hide file tree
Showing 20 changed files with 7 additions and 156 deletions.
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -512,14 +512,8 @@ 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")
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)
message(FATAL_ERROR "Qt version 5.12.0 or higher is required")
endif()

get_filename_component(Qt5_PREFIX ${Qt5_DIR}/../../.. REALPATH)
Expand Down
5 changes: 0 additions & 5 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5701,11 +5701,6 @@ This version is not meant for production use.</source>
Expect some bugs and minor issues, this version is meant for testing purposes.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>WARNING: Your Qt version may cause KeePassXC to crash with an On-Screen Keyboard.
We recommend you use the AppImage available on our downloads page.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No Tags</source>
<translation type="unfinished"></translation>
Expand Down
12 changes: 1 addition & 11 deletions src/autotype/AutoTypeSelectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@

#include <QCloseEvent>
#include <QMenu>
#include <QShortcut>
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
#include <QScreen>
#else
#include <QDesktopWidget>
#endif
#include <QShortcut>

#include "core/Config.h"
#include "core/Database.h"
Expand Down Expand Up @@ -334,15 +330,13 @@ void AutoTypeSelectDialog::buildActionMenu()
});
#endif

#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
// 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);
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
typeVirtualAction->setShortcutVisibleInContextMenu(true);
#endif
#endif

copyUsernameAction->setProperty(MENU_FIELD_PROP_NAME, MENU_FIELD::USERNAME);
Expand Down Expand Up @@ -377,16 +371,12 @@ void AutoTypeSelectDialog::showEvent(QShowEvent* event)
{
QDialog::showEvent(event);

#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
auto screen = QApplication::screenAt(QCursor::pos());
if (!screen) {
// screenAt can return a nullptr, default to the primary screen
screen = QApplication::primaryScreen();
}
QRect screenGeometry = screen->availableGeometry();
#else
QRect screenGeometry = QApplication::desktop()->availableGeometry(QCursor::pos());
#endif

// Resize to last used size
QSize size = config()->get(Config::GUI_AutoTypeSelectDialogSize).toSize();
Expand Down
10 changes: 1 addition & 9 deletions src/autotype/PickcharsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@
#include "gui/Icons.h"

#include <QPushButton>
#include <QShortcut>
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
#include <QScreen>
#else
#include <QDesktopWidget>
#endif
#include <QShortcut>

PickcharsDialog::PickcharsDialog(const QString& string, QWidget* parent)
: QDialog(parent)
Expand Down Expand Up @@ -157,15 +153,11 @@ void PickcharsDialog::showEvent(QShowEvent* event)
QDialog::showEvent(event);

// Center on active screen
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
auto screen = QApplication::screenAt(QCursor::pos());
if (!screen) {
// screenAt can return a nullptr, default to the primary screen
screen = QApplication::primaryScreen();
}
QRect screenGeometry = screen->availableGeometry();
#else
QRect screenGeometry = QApplication::desktop()->availableGeometry(QCursor::pos());
#endif
move(screenGeometry.center().x() - (size().width() / 2), screenGeometry.center().y() - (size().height() / 2));
}
3 changes: 1 addition & 2 deletions src/core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {

// Messages
{Config::Messages_NoLegacyKeyFileWarning, {QS("Messages/NoLegacyKeyFileWarning"), Roaming, false}},
{Config::Messages_Qt55CompatibilityWarning, {QS("Messages/Qt55CompatibilityWarning"), Local, false}},
{Config::Messages_HidePreReleaseWarning, {QS("Messages/HidePreReleaseWarning"), Local, {}}}};

// clang-format on
Expand Down Expand Up @@ -360,7 +359,7 @@ static const QHash<QString, Config::ConfigKey> deprecationMap = {
{QS("generator/WordList"), Config::PasswordGenerator_WordList},
{QS("generator/WordCase"), Config::PasswordGenerator_WordCase},
{QS("generator/Type"), Config::PasswordGenerator_Type},
{QS("QtErrorMessageShown"), Config::Messages_Qt55CompatibilityWarning},
{QS("QtErrorMessageShown"), Config::Deleted},
{QS("GUI/HidePasswords"), Config::Deleted},
{QS("GUI/DarkTrayIcon"), Config::Deleted},

Expand Down
1 change: 0 additions & 1 deletion src/core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ class Config : public QObject
PasswordGenerator_Type,

Messages_NoLegacyKeyFileWarning,
Messages_Qt55CompatibilityWarning,
Messages_HidePreReleaseWarning,

// Special internal value
Expand Down
6 changes: 0 additions & 6 deletions src/core/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,8 @@ bool Database::performSave(const QString& filePath, SaveAction action, const QSt
backupDatabase(filePath, backupFilePath);
}

#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
QFileInfo info(filePath);
auto createTime = info.exists() ? info.birthTime() : QDateTime::currentDateTime();
#endif

switch (action) {
case Atomic: {
Expand All @@ -332,10 +330,8 @@ bool Database::performSave(const QString& filePath, SaveAction action, const QSt
return false;
}

#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
// Retain original creation time
saveFile.setFileTime(createTime, QFile::FileBirthTime);
#endif

if (saveFile.commit()) {
// successfully saved database file
Expand Down Expand Up @@ -368,10 +364,8 @@ bool Database::performSave(const QString& filePath, SaveAction action, const QSt
// successfully saved the database
tempFile.setAutoRemove(false);
QFile::setPermissions(filePath, perms);
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
// Retain original creation time
tempFile.setFileTime(createTime, QFile::FileBirthTime);
#endif
return true;
} else if (backupFilePath.isEmpty() || !restoreDatabase(filePath, backupFilePath)) {
// Failed to copy new database in place, and
Expand Down
2 changes: 0 additions & 2 deletions src/core/Tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,13 @@ namespace Tools
#endif
debugInfo.append("\n");

#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
debugInfo.append(QObject::tr("Operating system: %1\nCPU architecture: %2\nKernel: %3 %4")
.arg(QSysInfo::prettyProductName(),
QSysInfo::currentCpuArchitecture(),
QSysInfo::kernelType(),
QSysInfo::kernelVersion()));

debugInfo.append("\n\n");
#endif

QString extensions;
#ifdef WITH_XC_AUTOTYPE
Expand Down
14 changes: 0 additions & 14 deletions src/core/Tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,6 @@ namespace Tools
}
}

inline int qtRuntimeVersion()
{
// Cache the result since the Qt version can't change during
// the execution, computing it once will be enough
const static int version = []() {
const auto sq = QString::fromLatin1(qVersion());
return (sq.section(QChar::fromLatin1('.'), 0, 0).toInt() << 16)
+ (sq.section(QChar::fromLatin1('.'), 1, 1).toInt() << 8)
+ (sq.section(QChar::fromLatin1('.'), 2, 2).toInt());
}();

return version;
}

// Checks if all values are found inside the list. Returns a list of values not found.
template <typename T> QList<T> getMissingValuesFromList(const QList<T>& list, const QList<T>& required)
{
Expand Down
8 changes: 0 additions & 8 deletions src/gui/Icons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,11 @@ QIcon Icons::trayIcon(bool unlocked)
#else
i = icon(QString("%1-%2%3").arg(applicationIconName(), iconApperance, suffix), false);
#endif
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
// Set as mask to allow the operating system to recolour the tray icon. This may look weird
// if we failed to detect the status bar background colour correctly, but it is certainly
// better than a barely visible icon and even if we did guess correctly, it allows for better
// integration should the system's preferred colours not be 100% black or white.
i.setIsMask(true);
#endif
return i;
}

Expand All @@ -121,11 +119,7 @@ AdaptiveIconEngine::AdaptiveIconEngine(QIcon baseIcon, QColor overrideColor)
void AdaptiveIconEngine::paint(QPainter* painter, const QRect& rect, QIcon::Mode mode, QIcon::State state)
{
// Temporary image canvas to ensure that the background is transparent and alpha blending works.
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
auto scale = painter->device()->devicePixelRatioF();
#else
auto scale = painter->device()->devicePixelRatio();
#endif
QImage img(rect.size() * scale, QImage::Format_ARGB32_Premultiplied);
img.fill(0);
QPainter p(&img);
Expand Down Expand Up @@ -191,9 +185,7 @@ QIcon Icons::icon(const QString& name, bool recolor, const QColor& overrideColor
icon = QIcon::fromTheme(name);
if (recolor) {
icon = QIcon(new AdaptiveIconEngine(icon, overrideColor));
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
icon.setIsMask(true);
#endif
}

m_iconCache.insert(cacheName, icon);
Expand Down
37 changes: 0 additions & 37 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include "autotype/AutoType.h"
#include "core/InactivityTimer.h"
#include "core/Resources.h"
#include "core/Tools.h"
#include "gui/AboutDialog.h"
#include "gui/ActionCollection.h"
#include "gui/Icons.h"
Expand Down Expand Up @@ -293,7 +292,6 @@ MainWindow::MainWindow()
connect(m_inactivityTimer, SIGNAL(inactivityDetected()), this, SLOT(lockDatabasesAfterInactivity()));
applySettingsChanges();

#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
// 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);
Expand All @@ -315,7 +313,6 @@ MainWindow::MainWindow()
m_ui->actionEntryCopyTitle->setShortcutVisibleInContextMenu(true);
m_ui->actionEntryAddToAgent->setShortcutVisibleInContextMenu(true);
m_ui->actionEntryRemoveFromAgent->setShortcutVisibleInContextMenu(true);
#endif

connect(m_ui->menuEntries, SIGNAL(aboutToShow()), SLOT(obtainContextFocusLock()));
connect(m_ui->menuEntries, SIGNAL(aboutToHide()), SLOT(releaseContextFocusLock()));
Expand Down Expand Up @@ -666,15 +663,6 @@ MainWindow::MainWindow()
MessageWidget::Information,
-1);
}
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) && QT_VERSION < QT_VERSION_CHECK(5, 6, 0))
if (!config()->get(Config::Messages_Qt55CompatibilityWarning).toBool()) {
m_ui->globalMessageWidget->showMessage(
tr("WARNING: Your Qt version may cause KeePassXC to crash with an On-Screen Keyboard.\n"
"We recommend you use the AppImage available on our downloads page."),
MessageWidget::Warning,
-1);
config()->set(Config::Messages_Qt55CompatibilityWarning, true);
}
#endif

connect(qApp, SIGNAL(anotherInstanceStarted()), this, SLOT(bringToFront()));
Expand Down Expand Up @@ -1864,27 +1852,6 @@ void MainWindow::toggleWindow()
hideWindow();
} else {
bringToFront();

#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && !defined(QT_NO_DBUS) && (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
// re-register global D-Bus menu (needed on Ubuntu with Unity)
// see https://github.com/keepassxreboot/keepassxc/issues/271
// and https://bugreports.qt.io/browse/QTBUG-58723
// check for !isVisible(), because isNativeMenuBar() does not work with appmenu-qt5
static const auto isDesktopSessionUnity = qgetenv("XDG_CURRENT_DESKTOP") == "Unity";

if (isDesktopSessionUnity && Tools::qtRuntimeVersion() < QT_VERSION_CHECK(5, 9, 0)
&& !m_ui->menubar->isVisible()) {
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("com.canonical.AppMenu.Registrar"),
QStringLiteral("/com/canonical/AppMenu/Registrar"),
QStringLiteral("com.canonical.AppMenu.Registrar"),
QStringLiteral("RegisterWindow"));
QList<QVariant> args;
args << QVariant::fromValue(static_cast<uint32_t>(winId()))
<< QVariant::fromValue(QDBusObjectPath("/MenuBar/1"));
msg.setArguments(args);
QDBusConnection::sessionBus().send(msg);
}
#endif
}
}

Expand Down Expand Up @@ -2019,11 +1986,7 @@ void MainWindow::displayDesktopNotification(const QString& msg, QString title, i
title = BaseWindowTitle;
}

#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
m_trayIcon->showMessage(title, msg, icons()->applicationIcon(), msTimeoutHint);
#else
m_trayIcon->showMessage(title, msg, QSystemTrayIcon::Information, msTimeoutHint);
#endif
}

void MainWindow::restartApp(const QString& message)
Expand Down
7 changes: 0 additions & 7 deletions src/gui/entry/EntryView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,17 +570,10 @@ void EntryView::startDrag(Qt::DropActions supportedActions)

// Grab the screen pixel ratio where the window resides
// TODO: Use direct call to screen() when moving to Qt 6
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
auto screen = QGuiApplication::screenAt(window()->geometry().center());
if (!screen) {
screen = QGuiApplication::primaryScreen();
}
#else
auto screen = QGuiApplication::primaryScreen();
if (windowHandle()) {
screen = windowHandle()->screen();
}
#endif

auto pixelRatio = screen->devicePixelRatio();

Expand Down
Loading

0 comments on commit e2a0520

Please sign in to comment.