Skip to content

Commit

Permalink
Fix all Qt 5.15 deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
c4rlo authored and varjolintu committed Dec 2, 2023
1 parent cc0530b commit 74792c2
Show file tree
Hide file tree
Showing 73 changed files with 377 additions and 255 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +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")
if(Qt5Core_VERSION VERSION_LESS "5.9.5")
message(FATAL_ERROR "Qt version 5.9.5 or higher is required")
endif()

# CBOR for Passkeys requires Qt 5.12
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ 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 Qt5::Core Qt5::Network Qt5::Widgets)

add_library(keepassx_core STATIC ${keepassx_SOURCES})

Expand Down
3 changes: 2 additions & 1 deletion src/autotype/AutoType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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 @@ -457,7 +458,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/ShortcutWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
ShortcutWidget::ShortcutWidget(QWidget* parent)
: QLineEdit(parent)
, m_key(static_cast<Qt::Key>(0))
, m_modifiers(nullptr)
, m_modifiers(Qt::NoModifier)
, m_locked(false)
{
setReadOnly(true);
Expand Down Expand Up @@ -61,7 +61,7 @@ void ShortcutWidget::setShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers)
void ShortcutWidget::resetShortcut()
{
m_key = static_cast<Qt::Key>(0);
m_modifiers = nullptr;
m_modifiers = Qt::NoModifier;
m_locked = false;
autoType()->unregisterGlobalShortcut();
}
Expand Down
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
4 changes: 2 additions & 2 deletions src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@

#include <QCheckBox>
#include <QCryptographicHash>
#include <QHostAddress>
#include <QInputDialog>
#include <QJsonArray>
#include <QJsonObject>
#include <QListWidget>
#include <QLocalSocket>
#include <QLocale>
#include <QProgressDialog>
#include <QUrl>

Expand Down Expand Up @@ -594,7 +594,7 @@ QString BrowserService::storeKey(const QString& key)
hideWindow();
db->metadata()->customData()->set(CustomData::BrowserKeyPrefix + id, key);
db->metadata()->customData()->set(QString("%1_%2").arg(CustomData::Created, id),
Clock::currentDateTime().toString(Qt::SystemLocaleShortDate));
QLocale::system().toString(Clock::currentDateTime(), QLocale::ShortFormat));
return id;
}

Expand Down
11 changes: 6 additions & 5 deletions src/cli/Add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "Generate.h"
#include "Utils.h"
#include "core/Global.h"
#include "core/Group.h"
#include "core/PasswordGenerator.h"

Expand Down Expand Up @@ -78,7 +79,7 @@ int Add::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<Q

// Cannot use those 2 options at the same time!
if (parser->isSet(Add::GenerateOption) && parser->isSet(Add::PasswordPromptOption)) {
err << QObject::tr("Cannot generate a password and prompt at the same time.") << endl;
err << QObject::tr("Cannot generate a password and prompt at the same time.") << Qt::endl;
return EXIT_FAILURE;
}

Expand All @@ -94,7 +95,7 @@ int Add::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<Q

Entry* entry = database->rootGroup()->addEntryWithPath(entryPath);
if (!entry) {
err << QObject::tr("Could not create entry with path %1.").arg(entryPath) << endl;
err << QObject::tr("Could not create entry with path %1.").arg(entryPath) << Qt::endl;
return EXIT_FAILURE;
}

Expand All @@ -112,7 +113,7 @@ int Add::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<Q

if (parser->isSet(Add::PasswordPromptOption)) {
if (!parser->isSet(Command::QuietOption)) {
out << QObject::tr("Enter password for new entry: ") << flush;
out << QObject::tr("Enter password for new entry: ") << Qt::flush;
}
QString password = Utils::getPassword(parser->isSet(Command::QuietOption));
entry->setPassword(password);
Expand All @@ -123,12 +124,12 @@ int Add::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<Q

QString errorMessage;
if (!database->save(Database::Atomic, {}, &errorMessage)) {
err << QObject::tr("Writing the database failed %1.").arg(errorMessage) << endl;
err << QObject::tr("Writing the database failed %1.").arg(errorMessage) << Qt::endl;
return EXIT_FAILURE;
}

if (!parser->isSet(Command::QuietOption)) {
out << QObject::tr("Successfully added entry %1.").arg(entry->title()) << endl;
out << QObject::tr("Successfully added entry %1.").arg(entry->title()) << Qt::endl;
}
return EXIT_SUCCESS;
}
9 changes: 5 additions & 4 deletions src/cli/AddGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "AddGroup.h"

#include "Utils.h"
#include "core/Global.h"
#include "core/Group.h"

#include <QCommandLineParser>
Expand Down Expand Up @@ -45,13 +46,13 @@ int AddGroup::executeWithDatabase(QSharedPointer<Database> database, QSharedPoin

Group* group = database->rootGroup()->findGroupByPath(groupPath);
if (group) {
err << QObject::tr("Group %1 already exists!").arg(groupPath) << endl;
err << QObject::tr("Group %1 already exists!").arg(groupPath) << Qt::endl;
return EXIT_FAILURE;
}

Group* parentGroup = database->rootGroup()->findGroupByPath(parentGroupPath);
if (!parentGroup) {
err << QObject::tr("Group %1 not found.").arg(parentGroupPath) << endl;
err << QObject::tr("Group %1 not found.").arg(parentGroupPath) << Qt::endl;
return EXIT_FAILURE;
}

Expand All @@ -62,12 +63,12 @@ int AddGroup::executeWithDatabase(QSharedPointer<Database> database, QSharedPoin

QString errorMessage;
if (!database->save(Database::Atomic, {}, &errorMessage)) {
err << QObject::tr("Writing the database failed %1.").arg(errorMessage) << endl;
err << QObject::tr("Writing the database failed %1.").arg(errorMessage) << Qt::endl;
return EXIT_FAILURE;
}

if (!parser->isSet(Command::QuietOption)) {
out << QObject::tr("Successfully added group %1.").arg(groupName) << endl;
out << QObject::tr("Successfully added group %1.").arg(groupName) << Qt::endl;
}
return EXIT_SUCCESS;
}
17 changes: 10 additions & 7 deletions src/cli/Analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "Analyze.h"

#include "Utils.h"
#include "core/Global.h"
#include "core/Group.h"
#include "core/HibpOffline.h"

Expand Down Expand Up @@ -60,23 +61,24 @@ int Analyze::executeWithDatabase(QSharedPointer<Database> database, QSharedPoint

auto okon = parser->value(Analyze::OkonOption);
if (!okon.isEmpty()) {
out << QObject::tr("Evaluating database entries using okon…") << endl;
out << QObject::tr("Evaluating database entries using okon…") << Qt::endl;

if (!HibpOffline::okonReport(database, okon, hibpDatabase, findings, &error)) {
err << error << endl;
err << error << Qt::endl;
return EXIT_FAILURE;
}
} else {
QFile hibpFile(hibpDatabase);
if (!hibpFile.open(QFile::ReadOnly)) {
err << QObject::tr("Failed to open HIBP file %1: %2").arg(hibpDatabase).arg(hibpFile.errorString()) << endl;
err << QObject::tr("Failed to open HIBP file %1: %2").arg(hibpDatabase).arg(hibpFile.errorString())
<< Qt::endl;
return EXIT_FAILURE;
}

out << QObject::tr("Evaluating database entries against HIBP file, this will take a while…") << endl;
out << QObject::tr("Evaluating database entries against HIBP file, this will take a while…") << Qt::endl;

if (!HibpOffline::report(database, hibpFile, findings, &error)) {
err << error << endl;
err << error << Qt::endl;
return EXIT_FAILURE;
}
}
Expand All @@ -91,9 +93,10 @@ int Analyze::executeWithDatabase(QSharedPointer<Database> database, QSharedPoint
}

if (count > 0) {
out << QObject::tr("Password for '%1' has been leaked %2 time(s)!", "", count).arg(path).arg(count) << endl;
out << QObject::tr("Password for '%1' has been leaked %2 time(s)!", "", count).arg(path).arg(count)
<< Qt::endl;
} else {
out << QObject::tr("Password for '%1' has been leaked!").arg(path) << endl;
out << QObject::tr("Password for '%1' has been leaked!").arg(path) << Qt::endl;
}
}

Expand Down
13 changes: 7 additions & 6 deletions src/cli/AttachmentExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "AttachmentExport.h"

#include "Utils.h"
#include "core/Global.h"
#include "core/Group.h"

#include <QCommandLineParser>
Expand Down Expand Up @@ -49,40 +50,40 @@ int AttachmentExport::executeWithDatabase(QSharedPointer<Database> database, QSh

auto entry = database->rootGroup()->findEntryByPath(entryPath);
if (!entry) {
err << QObject::tr("Could not find entry with path %1.").arg(entryPath) << endl;
err << QObject::tr("Could not find entry with path %1.").arg(entryPath) << Qt::endl;
return EXIT_FAILURE;
}

auto attachmentName = args.at(2);

auto attachments = entry->attachments();
if (!attachments->hasKey(attachmentName)) {
err << QObject::tr("Could not find attachment with name %1.").arg(attachmentName) << endl;
err << QObject::tr("Could not find attachment with name %1.").arg(attachmentName) << Qt::endl;
return EXIT_FAILURE;
}

if (parser->isSet(AttachmentExport::StdoutOption)) {
// Output to STDOUT even in quiet mode
Utils::STDOUT << attachments->value(attachmentName) << flush;
Utils::STDOUT << attachments->value(attachmentName) << Qt::flush;
return EXIT_SUCCESS;
}

if (args.size() < 4) {
err << QObject::tr("No export target given. Please use '--stdout' or specify an 'export-file'.") << endl;
err << QObject::tr("No export target given. Please use '--stdout' or specify an 'export-file'.") << Qt::endl;
return EXIT_FAILURE;
}

auto exportFileName = args.at(3);
QFile exportFile(exportFileName);
if (!exportFile.open(QIODevice::WriteOnly)) {
err << QObject::tr("Could not open output file %1.").arg(exportFileName) << endl;
err << QObject::tr("Could not open output file %1.").arg(exportFileName) << Qt::endl;
return EXIT_FAILURE;
}
exportFile.write(attachments->value(attachmentName));

out << QObject::tr("Successfully exported attachment %1 of entry %2 to %3.")
.arg(attachmentName, entryPath, exportFileName)
<< endl;
<< Qt::endl;

return EXIT_SUCCESS;
}
11 changes: 6 additions & 5 deletions src/cli/AttachmentImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "AttachmentImport.h"

#include "Utils.h"
#include "core/Global.h"
#include "core/Group.h"

#include <QCommandLineParser>
Expand Down Expand Up @@ -50,23 +51,23 @@ int AttachmentImport::executeWithDatabase(QSharedPointer<Database> database, QSh

auto entry = database->rootGroup()->findEntryByPath(entryPath);
if (!entry) {
err << QObject::tr("Could not find entry with path %1.").arg(entryPath) << endl;
err << QObject::tr("Could not find entry with path %1.").arg(entryPath) << Qt::endl;
return EXIT_FAILURE;
}

auto attachmentName = args.at(2);

auto attachments = entry->attachments();
if (attachments->hasKey(attachmentName) && !parser->isSet(AttachmentImport::ForceOption)) {
err << QObject::tr("Attachment %1 already exists for entry %2.").arg(attachmentName, entryPath) << endl;
err << QObject::tr("Attachment %1 already exists for entry %2.").arg(attachmentName, entryPath) << Qt::endl;
return EXIT_FAILURE;
}

auto importFileName = args.at(3);

QFile importFile(importFileName);
if (!importFile.open(QIODevice::ReadOnly)) {
err << QObject::tr("Could not open attachment file %1.").arg(importFileName) << endl;
err << QObject::tr("Could not open attachment file %1.").arg(importFileName) << Qt::endl;
return EXIT_FAILURE;
}

Expand All @@ -76,12 +77,12 @@ int AttachmentImport::executeWithDatabase(QSharedPointer<Database> database, QSh

QString errorMessage;
if (!database->save(Database::Atomic, {}, &errorMessage)) {
err << QObject::tr("Writing the database failed %1.").arg(errorMessage) << endl;
err << QObject::tr("Writing the database failed %1.").arg(errorMessage) << Qt::endl;
return EXIT_FAILURE;
}

out << QObject::tr("Successfully imported attachment %1 as %2 to entry %3.")
.arg(importFileName, attachmentName, entryPath)
<< endl;
<< Qt::endl;
return EXIT_SUCCESS;
}
9 changes: 5 additions & 4 deletions src/cli/AttachmentRemove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "AttachmentRemove.h"

#include "Utils.h"
#include "core/Global.h"
#include "core/Group.h"

#include <QCommandLineParser>
Expand All @@ -41,15 +42,15 @@ int AttachmentRemove::executeWithDatabase(QSharedPointer<Database> database, QSh

auto entry = database->rootGroup()->findEntryByPath(entryPath);
if (!entry) {
err << QObject::tr("Could not find entry with path %1.").arg(entryPath) << endl;
err << QObject::tr("Could not find entry with path %1.").arg(entryPath) << Qt::endl;
return EXIT_FAILURE;
}

auto attachmentName = args.at(2);

auto attachments = entry->attachments();
if (!attachments->hasKey(attachmentName)) {
err << QObject::tr("Could not find attachment with name %1.").arg(attachmentName) << endl;
err << QObject::tr("Could not find attachment with name %1.").arg(attachmentName) << Qt::endl;
return EXIT_FAILURE;
}

Expand All @@ -59,10 +60,10 @@ int AttachmentRemove::executeWithDatabase(QSharedPointer<Database> database, QSh

QString errorMessage;
if (!database->save(Database::Atomic, {}, &errorMessage)) {
err << QObject::tr("Writing the database failed %1.").arg(errorMessage) << endl;
err << QObject::tr("Writing the database failed %1.").arg(errorMessage) << Qt::endl;
return EXIT_FAILURE;
}

out << QObject::tr("Successfully removed attachment %1 from entry %2.").arg(attachmentName, entryPath) << endl;
out << QObject::tr("Successfully removed attachment %1 from entry %2.").arg(attachmentName, entryPath) << Qt::endl;
return EXIT_SUCCESS;
}
Loading

0 comments on commit 74792c2

Please sign in to comment.