Skip to content

Commit

Permalink
Fix all Qt 5.15 deprecation warnings (keepassxreboot#7783)
Browse files Browse the repository at this point in the history
* Deprecated qSort() -> std::sort()
* Replace QDateTime::toString(Qt::DefaultLocaleShortDate) with Clock::toString()
* Replace QDateTime::toString(Qt::SystemLocaleShortDate) with QLocale::system().toString(..., QLocale::ShortFormat)
* Use QDateTime::startOfDay() instead of QDate(QDateTime) 
  Note: QDateTime::startOfDay() is only available in Qt 5.14, we need to guard it
* Replace QString::SkipEmptyParts with Qt::SkipEmptyParts
  Note: Its designated replacement, Qt::SplitBehavior, was only added in Qt 5.14.
* Don't call deprecated QFlags(nullptr) constructor
* QSet::{toList->values}
* Replace QList::toSet, QSet::fromList with Tools::asSet()
* QHash::insertMulti -> QMultiHash::insert
* QProcess::startDetached: non-deprecated overload
* QProcess::{pid->processId}
* QPainter::{HighQuality->}Antialiasing
* QPalette::{background->window}()
* Use Qt::{Background,Foreground}Role
* endl -> Qt::endl, flush -> Qt::flush
* Make YubiKey::s_interfaceMutex non-recursive
* OpenSSHKeyGenDialog: use non-deprecated QComboBox::sizeAdjustPolicy setting
  • Loading branch information
c4rlo authored and pull[bot] committed Jun 23, 2024
1 parent c832b08 commit 6b8b906
Show file tree
Hide file tree
Showing 67 changed files with 341 additions and 240 deletions.
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 @@ -460,7 +461,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
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
3 changes: 2 additions & 1 deletion src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <QJsonObject>
#include <QListWidget>
#include <QLocalSocket>
#include <QLocale>
#include <QProgressDialog>
#include <QUrl>

Expand Down Expand Up @@ -601,7 +602,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 6b8b906

Please sign in to comment.