From 74792c2a447d6b363d86c17aa3e1f9db7efed8bd Mon Sep 17 00:00:00 2001 From: Carlo Teubner Date: Sun, 17 Apr 2022 22:28:37 +0100 Subject: [PATCH] Fix all Qt 5.15 deprecation warnings --- CMakeLists.txt | 4 +- src/CMakeLists.txt | 2 +- src/autotype/AutoType.cpp | 3 +- src/autotype/ShortcutWidget.cpp | 4 +- src/browser/BrowserEntryConfig.cpp | 9 ++-- src/browser/BrowserService.cpp | 4 +- src/cli/Add.cpp | 11 +++-- src/cli/AddGroup.cpp | 9 ++-- src/cli/Analyze.cpp | 17 ++++--- src/cli/AttachmentExport.cpp | 13 +++--- src/cli/AttachmentImport.cpp | 11 +++-- src/cli/AttachmentRemove.cpp | 9 ++-- src/cli/Clip.cpp | 24 +++++----- src/cli/DatabaseCreate.cpp | 23 +++++----- src/cli/DatabaseEdit.cpp | 27 +++++------ src/cli/DatabaseInfo.cpp | 46 +++++++++---------- src/cli/Diceware.cpp | 7 +-- src/cli/Edit.cpp | 13 +++--- src/cli/Estimate.cpp | 9 ++-- src/cli/Export.cpp | 5 +- src/cli/Generate.cpp | 7 +-- src/cli/Import.cpp | 10 ++-- src/cli/List.cpp | 7 +-- src/cli/Merge.cpp | 9 ++-- src/cli/Move.cpp | 11 +++-- src/cli/Remove.cpp | 9 ++-- src/cli/RemoveGroup.cpp | 11 +++-- src/cli/Search.cpp | 5 +- src/cli/Show.cpp | 24 +++++----- src/cli/Utils.cpp | 33 ++++++------- src/cli/keepassxc-cli.cpp | 8 ++-- src/core/Clock.cpp | 8 ++++ src/core/Clock.h | 2 + src/core/Database.cpp | 2 +- src/core/Entry.cpp | 10 ++-- src/core/EntryAttachments.cpp | 3 +- src/core/EntryAttributes.cpp | 3 +- src/core/EntrySearcher.cpp | 2 +- src/core/Global.h | 18 ++++++++ src/core/Merger.cpp | 4 +- src/core/PasswordHealth.cpp | 9 ++-- src/core/Tools.cpp | 3 ++ src/core/Tools.h | 11 +++++ src/fdosecrets/objects/Collection.cpp | 2 +- .../widgets/AccessControlDialog.cpp | 4 +- src/format/KdbxXmlReader.cpp | 9 ++-- src/format/KdbxXmlReader.h | 3 +- src/format/OpVaultReaderSections.cpp | 3 +- src/gui/DatabaseWidget.cpp | 19 +++++--- src/gui/EntryPreviewWidget.cpp | 7 ++- src/gui/KMessageWidget.cpp | 4 ++ src/gui/csvImport/CsvImportWidget.cpp | 4 +- src/gui/entry/EditEntryWidget.cpp | 5 +- src/gui/entry/EntryHistoryModel.cpp | 3 +- src/gui/entry/EntryHistoryModel.h | 2 + src/gui/entry/EntryModel.cpp | 20 ++++---- src/gui/entry/EntryModel.h | 1 - src/gui/osutils/nixutils/NixUtils.cpp | 3 +- src/gui/reports/ReportsWidgetHibp.cpp | 6 ++- src/gui/reports/ReportsWidgetStatistics.cpp | 6 +-- src/gui/styles/base/BaseStyle.cpp | 12 ++--- src/keys/drivers/YubiKey.cpp | 1 - src/keys/drivers/YubiKey.h | 15 +++++- src/keys/drivers/YubiKeyInterface.cpp | 1 - src/keys/drivers/YubiKeyInterface.h | 13 +++++- src/main.cpp | 4 +- src/sshagent/OpenSSHKey.cpp | 3 +- src/sshagent/OpenSSHKeyGenDialog.ui | 2 +- tests/TestSSHAgent.cpp | 4 +- tests/gui/TestGui.h | 2 +- tests/gui/TestGuiBrowser.h | 2 +- tests/gui/TestGuiFdoSecrets.cpp | 9 ++-- tests/modeltest.cpp | 4 +- 73 files changed, 377 insertions(+), 255 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 252e61fbd6..3b4b63a0bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 15b6d947ac..82e548c8e1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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}) diff --git a/src/autotype/AutoType.cpp b/src/autotype/AutoType.cpp index c39a132018..d84fdc18f9 100644 --- a/src/autotype/AutoType.cpp +++ b/src/autotype/AutoType.cpp @@ -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" @@ -457,7 +458,7 @@ void AutoType::performGlobalAutoType(const QList>& dbLi if (hideExpired && entry->isExpired()) { continue; } - auto sequences = entry->autoTypeSequences(m_windowTitleForGlobal).toSet(); + const QSet sequences = Tools::asSet(entry->autoTypeSequences(m_windowTitleForGlobal)); for (const auto& sequence : sequences) { matchList << AutoTypeMatch(entry, sequence); } diff --git a/src/autotype/ShortcutWidget.cpp b/src/autotype/ShortcutWidget.cpp index 9728fcc4f8..c927f0b9cb 100644 --- a/src/autotype/ShortcutWidget.cpp +++ b/src/autotype/ShortcutWidget.cpp @@ -25,7 +25,7 @@ ShortcutWidget::ShortcutWidget(QWidget* parent) : QLineEdit(parent) , m_key(static_cast(0)) - , m_modifiers(nullptr) + , m_modifiers(Qt::NoModifier) , m_locked(false) { setReadOnly(true); @@ -61,7 +61,7 @@ void ShortcutWidget::setShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers) void ShortcutWidget::resetShortcut() { m_key = static_cast(0); - m_modifiers = nullptr; + m_modifiers = Qt::NoModifier; m_locked = false; autoType()->unregisterGlobalShortcut(); } diff --git a/src/browser/BrowserEntryConfig.cpp b/src/browser/BrowserEntryConfig.cpp index a5bd3263f1..63d3bd16b1 100644 --- a/src/browser/BrowserEntryConfig.cpp +++ b/src/browser/BrowserEntryConfig.cpp @@ -19,6 +19,7 @@ #include "BrowserEntryConfig.h" #include "core/Entry.h" +#include "core/Global.h" #include "core/Tools.h" #include @@ -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 diff --git a/src/browser/BrowserService.cpp b/src/browser/BrowserService.cpp index 8f663a7c7f..8205a22643 100644 --- a/src/browser/BrowserService.cpp +++ b/src/browser/BrowserService.cpp @@ -39,12 +39,12 @@ #include #include -#include #include #include #include #include #include +#include #include #include @@ -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; } diff --git a/src/cli/Add.cpp b/src/cli/Add.cpp index 3bd9241d1e..c600da660b 100644 --- a/src/cli/Add.cpp +++ b/src/cli/Add.cpp @@ -19,6 +19,7 @@ #include "Generate.h" #include "Utils.h" +#include "core/Global.h" #include "core/Group.h" #include "core/PasswordGenerator.h" @@ -78,7 +79,7 @@ int Add::executeWithDatabase(QSharedPointer database, QSharedPointerisSet(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; } @@ -94,7 +95,7 @@ int Add::executeWithDatabase(QSharedPointer database, QSharedPointerrootGroup()->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; } @@ -112,7 +113,7 @@ int Add::executeWithDatabase(QSharedPointer database, QSharedPointerisSet(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); @@ -123,12 +124,12 @@ int Add::executeWithDatabase(QSharedPointer database, QSharedPointersave(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; } diff --git a/src/cli/AddGroup.cpp b/src/cli/AddGroup.cpp index 762afa80f1..2e4bbeac1f 100644 --- a/src/cli/AddGroup.cpp +++ b/src/cli/AddGroup.cpp @@ -18,6 +18,7 @@ #include "AddGroup.h" #include "Utils.h" +#include "core/Global.h" #include "core/Group.h" #include @@ -45,13 +46,13 @@ int AddGroup::executeWithDatabase(QSharedPointer 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; } @@ -62,12 +63,12 @@ int AddGroup::executeWithDatabase(QSharedPointer 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; } diff --git a/src/cli/Analyze.cpp b/src/cli/Analyze.cpp index 185339dc5a..44704014a5 100644 --- a/src/cli/Analyze.cpp +++ b/src/cli/Analyze.cpp @@ -18,6 +18,7 @@ #include "Analyze.h" #include "Utils.h" +#include "core/Global.h" #include "core/Group.h" #include "core/HibpOffline.h" @@ -60,23 +61,24 @@ int Analyze::executeWithDatabase(QSharedPointer 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; } } @@ -91,9 +93,10 @@ int Analyze::executeWithDatabase(QSharedPointer 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; } } diff --git a/src/cli/AttachmentExport.cpp b/src/cli/AttachmentExport.cpp index 46dc5f4b63..b4c88d902f 100644 --- a/src/cli/AttachmentExport.cpp +++ b/src/cli/AttachmentExport.cpp @@ -18,6 +18,7 @@ #include "AttachmentExport.h" #include "Utils.h" +#include "core/Global.h" #include "core/Group.h" #include @@ -49,7 +50,7 @@ int AttachmentExport::executeWithDatabase(QSharedPointer 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; } @@ -57,32 +58,32 @@ int AttachmentExport::executeWithDatabase(QSharedPointer database, QSh 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; } diff --git a/src/cli/AttachmentImport.cpp b/src/cli/AttachmentImport.cpp index 0700961d7e..6611ef5a49 100644 --- a/src/cli/AttachmentImport.cpp +++ b/src/cli/AttachmentImport.cpp @@ -18,6 +18,7 @@ #include "AttachmentImport.h" #include "Utils.h" +#include "core/Global.h" #include "core/Group.h" #include @@ -50,7 +51,7 @@ int AttachmentImport::executeWithDatabase(QSharedPointer 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; } @@ -58,7 +59,7 @@ int AttachmentImport::executeWithDatabase(QSharedPointer database, QSh 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; } @@ -66,7 +67,7 @@ int AttachmentImport::executeWithDatabase(QSharedPointer database, QSh 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; } @@ -76,12 +77,12 @@ int AttachmentImport::executeWithDatabase(QSharedPointer 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; } diff --git a/src/cli/AttachmentRemove.cpp b/src/cli/AttachmentRemove.cpp index a609a8f22d..c8ce4d46c9 100644 --- a/src/cli/AttachmentRemove.cpp +++ b/src/cli/AttachmentRemove.cpp @@ -18,6 +18,7 @@ #include "AttachmentRemove.h" #include "Utils.h" +#include "core/Global.h" #include "core/Group.h" #include @@ -41,7 +42,7 @@ int AttachmentRemove::executeWithDatabase(QSharedPointer 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; } @@ -49,7 +50,7 @@ int AttachmentRemove::executeWithDatabase(QSharedPointer database, QSh 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; } @@ -59,10 +60,10 @@ int AttachmentRemove::executeWithDatabase(QSharedPointer 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; } diff --git a/src/cli/Clip.cpp b/src/cli/Clip.cpp index 47964b190a..e6c73a10a2 100644 --- a/src/cli/Clip.cpp +++ b/src/cli/Clip.cpp @@ -72,7 +72,7 @@ int Clip::executeWithDatabase(QSharedPointer database, QSharedPointer< bool ok; timeout = args.at(2).toInt(&ok); if (!ok) { - err << QObject::tr("Invalid timeout value %1.").arg(args.at(2)) << endl; + err << QObject::tr("Invalid timeout value %1.").arg(args.at(2)) << Qt::endl; return EXIT_FAILURE; } } @@ -83,14 +83,14 @@ int Clip::executeWithDatabase(QSharedPointer database, QSharedPointer< const auto& searchTerm = args.at(1); const auto results = searcher.search(QString("title:%1").arg(searchTerm), database->rootGroup(), true); if (results.count() > 1) { - err << QObject::tr("Multiple entries matching:") << endl; + err << QObject::tr("Multiple entries matching:") << Qt::endl; for (const Entry* result : results) { - err << result->path().prepend('/') << endl; + err << result->path().prepend('/') << Qt::endl; } return EXIT_FAILURE; } else { entryPath = (results.isEmpty()) ? searchTerm : results[0]->path().prepend('/'); - out << QObject::tr("Using matching entry: %1").arg(entryPath) << endl; + out << QObject::tr("Using matching entry: %1").arg(entryPath) << Qt::endl; } } else { entryPath = args.at(1); @@ -98,12 +98,12 @@ int Clip::executeWithDatabase(QSharedPointer database, QSharedPointer< auto* entry = database->rootGroup()->findEntryByPath(entryPath); if (!entry) { - err << QObject::tr("Entry %1 not found.").arg(entryPath) << endl; + err << QObject::tr("Entry %1 not found.").arg(entryPath) << Qt::endl; return EXIT_FAILURE; } if (parser->isSet(AttributeOption) && parser->isSet(TotpOption)) { - err << QObject::tr("ERROR: Please specify one of --attribute or --totp, not both.") << endl; + err << QObject::tr("ERROR: Please specify one of --attribute or --totp, not both.") << Qt::endl; return EXIT_FAILURE; } @@ -112,7 +112,7 @@ int Clip::executeWithDatabase(QSharedPointer database, QSharedPointer< bool found = false; if (parser->isSet(TotpOption) || selectedAttribute == "totp") { if (!entry->hasTotp()) { - err << QObject::tr("Entry with path %1 has no TOTP set up.").arg(entryPath) << endl; + err << QObject::tr("Entry with path %1 has no TOTP set up.").arg(entryPath) << Qt::endl; return EXIT_FAILURE; } @@ -127,7 +127,7 @@ int Clip::executeWithDatabase(QSharedPointer database, QSharedPointer< if (attrs.size() > 1) { err << QObject::tr("ERROR: attribute %1 is ambiguous, it matches %2.") .arg(selectedAttribute, QLocale().createSeparatedList(attrs)) - << endl; + << Qt::endl; return EXIT_FAILURE; } else if (attrs.size() == 1) { found = true; @@ -137,7 +137,7 @@ int Clip::executeWithDatabase(QSharedPointer database, QSharedPointer< } if (!found) { - out << QObject::tr("Attribute \"%1\" not found.").arg(selectedAttribute) << endl; + out << QObject::tr("Attribute \"%1\" not found.").arg(selectedAttribute) << Qt::endl; return EXIT_FAILURE; } @@ -146,7 +146,7 @@ int Clip::executeWithDatabase(QSharedPointer database, QSharedPointer< return exitCode; } - out << QObject::tr("Entry's \"%1\" attribute copied to the clipboard!").arg(selectedAttribute) << endl; + out << QObject::tr("Entry's \"%1\" attribute copied to the clipboard!").arg(selectedAttribute) << Qt::endl; if (timeout <= 0) { return exitCode; @@ -156,13 +156,13 @@ int Clip::executeWithDatabase(QSharedPointer database, QSharedPointer< while (timeout > 0) { out << '\r' << QString(lastLine.size(), ' ') << '\r'; lastLine = QObject::tr("Clearing the clipboard in %1 second(s)...", "", timeout).arg(timeout); - out << lastLine << flush; + out << lastLine << Qt::flush; Tools::sleep(1000); --timeout; } Utils::clipText(""); out << '\r' << QString(lastLine.size(), ' ') << '\r'; - out << QObject::tr("Clipboard cleared!") << endl; + out << QObject::tr("Clipboard cleared!") << Qt::endl; return EXIT_SUCCESS; } diff --git a/src/cli/DatabaseCreate.cpp b/src/cli/DatabaseCreate.cpp index c2444645b9..841f2afd1e 100644 --- a/src/cli/DatabaseCreate.cpp +++ b/src/cli/DatabaseCreate.cpp @@ -18,6 +18,7 @@ #include "DatabaseCreate.h" #include "Utils.h" +#include "core/Global.h" #include "keys/FileKey.h" #include @@ -70,13 +71,13 @@ QSharedPointer DatabaseCreate::initializeDatabaseFromOptions(const QSh if (decryptionTimeValue.length() != 0) { decryptionTime = decryptionTimeValue.toInt(); if (decryptionTime <= 0) { - err << QObject::tr("Invalid decryption time %1.").arg(decryptionTimeValue) << endl; + err << QObject::tr("Invalid decryption time %1.").arg(decryptionTimeValue) << Qt::endl; return {}; } if (decryptionTime < Kdf::MIN_ENCRYPTION_TIME || decryptionTime > Kdf::MAX_ENCRYPTION_TIME) { err << QObject::tr("Target decryption time must be between %1 and %2.") .arg(QString::number(Kdf::MIN_ENCRYPTION_TIME), QString::number(Kdf::MAX_ENCRYPTION_TIME)) - << endl; + << Qt::endl; return {}; } } @@ -86,7 +87,7 @@ QSharedPointer DatabaseCreate::initializeDatabaseFromOptions(const QSh if (parser->isSet(DatabaseCreate::SetPasswordOption)) { auto passwordKey = Utils::getConfirmedPassword(); if (passwordKey.isNull()) { - err << QObject::tr("Failed to set database password.") << endl; + err << QObject::tr("Failed to set database password.") << Qt::endl; return {}; } key->addKey(passwordKey); @@ -104,7 +105,7 @@ QSharedPointer DatabaseCreate::initializeDatabaseFromOptions(const QSh } if (!Utils::loadFileKey(keyFilePath, fileKey)) { - err << QObject::tr("Loading the key file failed") << endl; + err << QObject::tr("Loading the key file failed") << Qt::endl; return {}; } @@ -114,7 +115,7 @@ QSharedPointer DatabaseCreate::initializeDatabaseFromOptions(const QSh } if (key->isEmpty()) { - err << QObject::tr("No key is set. Aborting database creation.") << endl; + err << QObject::tr("No key is set. Aborting database creation.") << Qt::endl; return {}; } @@ -125,15 +126,15 @@ QSharedPointer DatabaseCreate::initializeDatabaseFromOptions(const QSh auto kdf = db->kdf(); Q_ASSERT(kdf); - out << QObject::tr("Benchmarking key derivation function for %1ms delay.").arg(decryptionTimeValue) << endl; + out << QObject::tr("Benchmarking key derivation function for %1ms delay.").arg(decryptionTimeValue) << Qt::endl; int rounds = kdf->benchmark(decryptionTime); - out << QObject::tr("Setting %1 rounds for key derivation function.").arg(QString::number(rounds)) << endl; + out << QObject::tr("Setting %1 rounds for key derivation function.").arg(QString::number(rounds)) << Qt::endl; kdf->setRounds(rounds); bool ok = db->changeKdf(kdf); if (!ok) { - err << QObject::tr("error while setting database key derivation settings.") << endl; + err << QObject::tr("error while setting database key derivation settings.") << Qt::endl; return {}; } } @@ -168,7 +169,7 @@ int DatabaseCreate::execute(const QStringList& arguments) const QString& databaseFilename = args.at(0); if (QFileInfo::exists(databaseFilename)) { - err << QObject::tr("File %1 already exists.").arg(databaseFilename) << endl; + err << QObject::tr("File %1 already exists.").arg(databaseFilename) << Qt::endl; return EXIT_FAILURE; } @@ -179,10 +180,10 @@ int DatabaseCreate::execute(const QStringList& arguments) QString errorMessage; if (!db->saveAs(databaseFilename, Database::Atomic, {}, &errorMessage)) { - err << QObject::tr("Failed to save the database: %1.").arg(errorMessage) << endl; + err << QObject::tr("Failed to save the database: %1.").arg(errorMessage) << Qt::endl; return EXIT_FAILURE; } - out << QObject::tr("Successfully created new database.") << endl; + out << QObject::tr("Successfully created new database.") << Qt::endl; return EXIT_SUCCESS; } diff --git a/src/cli/DatabaseEdit.cpp b/src/cli/DatabaseEdit.cpp index f5ca4ef2eb..3df4d4b191 100644 --- a/src/cli/DatabaseEdit.cpp +++ b/src/cli/DatabaseEdit.cpp @@ -19,6 +19,7 @@ #include "Utils.h" #include "cli/DatabaseCreate.h" +#include "core/Global.h" #include "keys/ChallengeResponseKey.h" #include "keys/FileKey.h" #include "keys/PasswordKey.h" @@ -53,7 +54,7 @@ int DatabaseEdit::executeWithDatabase(QSharedPointer database, QShared err << QObject::tr("Cannot use %1 and %2 at the same time.") .arg(DatabaseCreate::SetPasswordOption.names().at(0)) .arg(DatabaseEdit::UnsetPasswordOption.names().at(0)) - << endl; + << Qt::endl; return EXIT_FAILURE; } @@ -61,7 +62,7 @@ int DatabaseEdit::executeWithDatabase(QSharedPointer database, QShared err << QObject::tr("Cannot use %1 and %2 at the same time.") .arg(DatabaseCreate::SetKeyFileOption.names().at(0)) .arg(DatabaseEdit::UnsetKeyFileOption.names().at(0)) - << endl; + << Qt::endl; return EXIT_FAILURE; } @@ -76,7 +77,7 @@ int DatabaseEdit::executeWithDatabase(QSharedPointer database, QShared parser->value(DatabaseCreate::SetKeyFileOption), parser->isSet(DatabaseEdit::UnsetKeyFileOption)); if (newDatabaseKey.isNull()) { - err << QObject::tr("Could not change the database key.") << endl; + err << QObject::tr("Could not change the database key.") << Qt::endl; return EXIT_FAILURE; } database->setKey(newDatabaseKey); @@ -84,17 +85,17 @@ int DatabaseEdit::executeWithDatabase(QSharedPointer database, QShared } if (!databaseWasChanged) { - out << QObject::tr("Database was not modified.") << endl; + out << QObject::tr("Database was not modified.") << Qt::endl; return EXIT_SUCCESS; } 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 edited the database.") << endl; + out << QObject::tr("Successfully edited the database.") << Qt::endl; return EXIT_SUCCESS; } @@ -113,19 +114,19 @@ QSharedPointer DatabaseEdit::getNewDatabaseKey(QSharedPointerkey()->getChallengeResponseKey(ChallengeResponseKey::UUID); if (removePassword && currentPasswordKey.isNull()) { - err << QObject::tr("Cannot remove password: The database does not have a password.") << endl; + err << QObject::tr("Cannot remove password: The database does not have a password.") << Qt::endl; return {}; } if (removeKeyFile && currentFileKey.isNull()) { - err << QObject::tr("Cannot remove file key: The database does not have a file key.") << endl; + err << QObject::tr("Cannot remove file key: The database does not have a file key.") << Qt::endl; return {}; } if (updatePassword) { QSharedPointer newPasswordKey = Utils::getConfirmedPassword(); if (newPasswordKey.isNull()) { - err << QObject::tr("Failed to set database password.") << endl; + err << QObject::tr("Failed to set database password.") << Qt::endl; return {}; } newDatabaseKey->addKey(newPasswordKey); @@ -137,7 +138,7 @@ QSharedPointer DatabaseEdit::getNewDatabaseKey(QSharedPointer newFileKey = QSharedPointer::create(); QString errorMessage; if (!Utils::loadFileKey(newFileKeyPath, newFileKey)) { - err << QObject::tr("Loading the new key file failed: %1").arg(errorMessage) << endl; + err << QObject::tr("Loading the new key file failed: %1").arg(errorMessage) << Qt::endl; return {}; } newDatabaseKey->addKey(newFileKey); @@ -150,13 +151,13 @@ QSharedPointer DatabaseEdit::getNewDatabaseKey(QSharedPointer& key : database->key()->keys()) { if (key->uuid() != PasswordKey::UUID && key->uuid() != FileKey::UUID) { - err << QObject::tr("Found unexpected Key type %1").arg(key->uuid().toString()) << endl; + err << QObject::tr("Found unexpected Key type %1").arg(key->uuid().toString()) << Qt::endl; return {}; } } for (const QSharedPointer& key : database->key()->challengeResponseKeys()) { if (key->uuid() != ChallengeResponseKey::UUID) { - err << QObject::tr("Found unexpected Key type %1").arg(key->uuid().toString()) << endl; + err << QObject::tr("Found unexpected Key type %1").arg(key->uuid().toString()) << Qt::endl; return {}; } } @@ -166,7 +167,7 @@ QSharedPointer DatabaseEdit::getNewDatabaseKey(QSharedPointerkeys().isEmpty() && newDatabaseKey->challengeResponseKeys().isEmpty()) { - err << QObject::tr("Cannot remove all the keys from a database.") << endl; + err << QObject::tr("Cannot remove all the keys from a database.") << Qt::endl; return {}; } diff --git a/src/cli/DatabaseInfo.cpp b/src/cli/DatabaseInfo.cpp index f0e5e0f033..c240ace512 100644 --- a/src/cli/DatabaseInfo.cpp +++ b/src/cli/DatabaseInfo.cpp @@ -18,9 +18,9 @@ #include "DatabaseInfo.h" #include "Utils.h" +#include "core/Clock.h" #include "core/DatabaseStats.h" #include "core/Global.h" -#include "core/Group.h" #include "core/Metadata.h" #include @@ -35,39 +35,39 @@ int DatabaseInfo::executeWithDatabase(QSharedPointer database, QShared { auto& out = Utils::STDOUT; - out << QObject::tr("UUID: ") << database->uuid().toString() << endl; - out << QObject::tr("Name: ") << database->metadata()->name() << endl; - out << QObject::tr("Description: ") << database->metadata()->description() << endl; + out << QObject::tr("UUID: ") << database->uuid().toString() << Qt::endl; + out << QObject::tr("Name: ") << database->metadata()->name() << Qt::endl; + out << QObject::tr("Description: ") << database->metadata()->description() << Qt::endl; for (auto& cipher : asConst(KeePass2::CIPHERS)) { if (cipher == database->cipher()) { - out << QObject::tr("Cipher: ") << KeePass2::cipherToString(cipher) << endl; + out << QObject::tr("Cipher: ") << KeePass2::cipherToString(cipher) << Qt::endl; } } - out << QObject::tr("KDF: ") << database->kdf()->toString() << endl; + out << QObject::tr("KDF: ") << database->kdf()->toString() << Qt::endl; if (database->metadata()->recycleBinEnabled()) { - out << QObject::tr("Recycle bin is enabled.") << endl; + out << QObject::tr("Recycle bin is enabled.") << Qt::endl; } else { - out << QObject::tr("Recycle bin is not enabled.") << endl; + out << QObject::tr("Recycle bin is not enabled.") << Qt::endl; } DatabaseStats stats(database); - out << QObject::tr("Location") << ": " << database->filePath() << endl; - out << QObject::tr("Database created") << ": " - << database->rootGroup()->timeInfo().creationTime().toString(Qt::DefaultLocaleShortDate) << endl; - out << QObject::tr("Last saved") << ": " << stats.modified.toString(Qt::DefaultLocaleShortDate) << endl; + out << QObject::tr("Location") << ": " << database->filePath() << Qt::endl; + out << QObject::tr("Database created") << ": " << Clock::toString(database->rootGroup()->timeInfo().creationTime()) + << Qt::endl; + out << QObject::tr("Last saved") << ": " << Clock::toString(stats.modified) << Qt::endl; out << QObject::tr("Unsaved changes") << ": " << (database->isModified() ? QObject::tr("yes") : QObject::tr("no")) - << endl; - out << QObject::tr("Number of groups") << ": " << QString::number(stats.groupCount) << endl; - out << QObject::tr("Number of entries") << ": " << QString::number(stats.entryCount) << endl; - out << QObject::tr("Number of expired entries") << ": " << QString::number(stats.expiredEntries) << endl; - out << QObject::tr("Unique passwords") << ": " << QString::number(stats.uniquePasswords) << endl; - out << QObject::tr("Non-unique passwords") << ": " << QString::number(stats.reusedPasswords) << endl; - out << QObject::tr("Maximum password reuse") << ": " << QString::number(stats.maxPwdReuse()) << endl; - out << QObject::tr("Number of short passwords") << ": " << QString::number(stats.shortPasswords) << endl; - out << QObject::tr("Number of weak passwords") << ": " << QString::number(stats.weakPasswords) << endl; - out << QObject::tr("Entries excluded from reports") << ": " << QString::number(stats.excludedEntries) << endl; + << Qt::endl; + out << QObject::tr("Number of groups") << ": " << QString::number(stats.groupCount) << Qt::endl; + out << QObject::tr("Number of entries") << ": " << QString::number(stats.entryCount) << Qt::endl; + out << QObject::tr("Number of expired entries") << ": " << QString::number(stats.expiredEntries) << Qt::endl; + out << QObject::tr("Unique passwords") << ": " << QString::number(stats.uniquePasswords) << Qt::endl; + out << QObject::tr("Non-unique passwords") << ": " << QString::number(stats.reusedPasswords) << Qt::endl; + out << QObject::tr("Maximum password reuse") << ": " << QString::number(stats.maxPwdReuse()) << Qt::endl; + out << QObject::tr("Number of short passwords") << ": " << QString::number(stats.shortPasswords) << Qt::endl; + out << QObject::tr("Number of weak passwords") << ": " << QString::number(stats.weakPasswords) << Qt::endl; + out << QObject::tr("Entries excluded from reports") << ": " << QString::number(stats.excludedEntries) << Qt::endl; out << QObject::tr("Average password length") << ": " << QObject::tr("%1 characters").arg(stats.averagePwdLength()) - << endl; + << Qt::endl; return EXIT_SUCCESS; } diff --git a/src/cli/Diceware.cpp b/src/cli/Diceware.cpp index b6a65bd1e7..3263aaaa97 100644 --- a/src/cli/Diceware.cpp +++ b/src/cli/Diceware.cpp @@ -18,6 +18,7 @@ #include "Diceware.h" #include "Utils.h" +#include "core/Global.h" #include "core/PassphraseGenerator.h" #include @@ -58,7 +59,7 @@ int Diceware::execute(const QStringList& arguments) if (wordCount.isEmpty()) { dicewareGenerator.setWordCount(PassphraseGenerator::DefaultWordCount); } else if (wordCount.toInt() <= 0) { - err << QObject::tr("Invalid word count %1").arg(wordCount) << endl; + err << QObject::tr("Invalid word count %1").arg(wordCount) << Qt::endl; return EXIT_FAILURE; } else { dicewareGenerator.setWordCount(wordCount.toInt()); @@ -72,12 +73,12 @@ int Diceware::execute(const QStringList& arguments) if (!dicewareGenerator.isValid()) { // We already validated the word count input so if the generator is invalid, it // must be because the word list is too small. - err << QObject::tr("The word list is too small (< 1000 items)") << endl; + err << QObject::tr("The word list is too small (< 1000 items)") << Qt::endl; return EXIT_FAILURE; } QString password = dicewareGenerator.generatePassphrase(); - out << password << endl; + out << password << Qt::endl; return EXIT_SUCCESS; } diff --git a/src/cli/Edit.cpp b/src/cli/Edit.cpp index 1154ce3096..d7dcb6e0fb 100644 --- a/src/cli/Edit.cpp +++ b/src/cli/Edit.cpp @@ -20,6 +20,7 @@ #include "Add.h" #include "Generate.h" #include "Utils.h" +#include "core/Global.h" #include "core/Group.h" #include "core/PasswordGenerator.h" @@ -66,7 +67,7 @@ int Edit::executeWithDatabase(QSharedPointer database, QSharedPointer< // 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; } @@ -83,7 +84,7 @@ int Edit::executeWithDatabase(QSharedPointer database, QSharedPointer< Entry* 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; } @@ -93,7 +94,7 @@ int Edit::executeWithDatabase(QSharedPointer database, QSharedPointer< QString title = parser->value(Edit::TitleOption); bool prompt = parser->isSet(Add::PasswordPromptOption); if (username.isEmpty() && url.isEmpty() && notes.isEmpty() && title.isEmpty() && !prompt && !generate) { - err << QObject::tr("Not changing any field for entry %1.").arg(entryPath) << endl; + err << QObject::tr("Not changing any field for entry %1.").arg(entryPath) << Qt::endl; return EXIT_FAILURE; } @@ -116,7 +117,7 @@ int Edit::executeWithDatabase(QSharedPointer database, QSharedPointer< } if (prompt) { - out << QObject::tr("Enter new password for entry: ") << flush; + out << QObject::tr("Enter new password for entry: ") << Qt::flush; QString password = Utils::getPassword(parser->isSet(Command::QuietOption)); entry->setPassword(password); } else if (generate) { @@ -128,10 +129,10 @@ int Edit::executeWithDatabase(QSharedPointer database, QSharedPointer< 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 edited entry %1.").arg(entry->title()) << endl; + out << QObject::tr("Successfully edited entry %1.").arg(entry->title()) << Qt::endl; return EXIT_SUCCESS; } diff --git a/src/cli/Estimate.cpp b/src/cli/Estimate.cpp index 906e6c16e4..967561f56e 100644 --- a/src/cli/Estimate.cpp +++ b/src/cli/Estimate.cpp @@ -18,6 +18,7 @@ #include "Estimate.h" #include "Utils.h" +#include "core/Global.h" #include "core/PasswordHealth.h" #include @@ -47,7 +48,7 @@ static void estimate(const char* pwd, bool advanced) // clang-format off out << QObject::tr("Length %1").arg(len, 0) << '\t' << QObject::tr("Entropy %1").arg(e, 0, 'f', 3) << '\t' - << QObject::tr("Log10 %1").arg(e * 0.301029996, 0, 'f', 3) << endl; + << QObject::tr("Log10 %1").arg(e * 0.301029996, 0, 'f', 3) << Qt::endl; // clang-format on } else { int pwdLen = 0; @@ -62,7 +63,7 @@ static void estimate(const char* pwd, bool advanced) out << QObject::tr("Length %1").arg(len) << '\t' << QObject::tr("Entropy %1").arg(e, 0, 'f', 3) << '\t' << QObject::tr("Log10 %1").arg(e * 0.301029996, 0, 'f', 3) << "\n " - << QObject::tr("Multi-word extra bits %1").arg(m, 0, 'f', 1) << endl; + << QObject::tr("Multi-word extra bits %1").arg(m, 0, 'f', 1) << Qt::endl; // clang-format on p = info; pwdLen = 0; @@ -135,13 +136,13 @@ static void estimate(const char* pwd, bool advanced) for (n = 0; n < p->Length; ++n, ++pwd) { out << *pwd; } - out << endl; + out << Qt::endl; p = p->Next; } ZxcvbnFreeInfo(info); if (pwdLen != len) { out << QObject::tr("*** Password length (%1) != sum of length of parts (%2) ***").arg(len).arg(pwdLen) - << endl; + << Qt::endl; } } } diff --git a/src/cli/Export.cpp b/src/cli/Export.cpp index 6456fe5b14..31894e9269 100644 --- a/src/cli/Export.cpp +++ b/src/cli/Export.cpp @@ -19,6 +19,7 @@ #include "TextStream.h" #include "Utils.h" +#include "core/Global.h" #include "format/CsvExporter.h" #include @@ -46,7 +47,7 @@ int Export::executeWithDatabase(QSharedPointer database, QSharedPointe QByteArray xmlData; QString errorMessage; if (!database->extract(xmlData, &errorMessage)) { - err << QObject::tr("Unable to export database to XML: %1").arg(errorMessage) << endl; + err << QObject::tr("Unable to export database to XML: %1").arg(errorMessage) << Qt::endl; return EXIT_FAILURE; } out.write(xmlData.constData()); @@ -54,7 +55,7 @@ int Export::executeWithDatabase(QSharedPointer database, QSharedPointe CsvExporter csvExporter; out << csvExporter.exportDatabase(database); } else { - err << QObject::tr("Unsupported format %1").arg(format) << endl; + err << QObject::tr("Unsupported format %1").arg(format) << Qt::endl; return EXIT_FAILURE; } diff --git a/src/cli/Generate.cpp b/src/cli/Generate.cpp index 1f6ceff5d3..fd2920202f 100644 --- a/src/cli/Generate.cpp +++ b/src/cli/Generate.cpp @@ -18,6 +18,7 @@ #include "Generate.h" #include "Utils.h" +#include "core/Global.h" #include "core/PasswordGenerator.h" #include @@ -92,7 +93,7 @@ QSharedPointer Generate::createGenerator(QSharedPointersetLength(PasswordGenerator::DefaultLength); } else if (passwordLength.toInt() <= 0) { - err << QObject::tr("Invalid password length %1").arg(passwordLength) << endl; + err << QObject::tr("Invalid password length %1").arg(passwordLength) << Qt::endl; return {}; } else { passwordGenerator->setLength(passwordLength.toInt()); @@ -138,7 +139,7 @@ QSharedPointer Generate::createGenerator(QSharedPointersetExcludedCharacterSet(parser->value(Generate::ExcludeCharsOption)); if (!passwordGenerator->isValid()) { - err << QObject::tr("Invalid password generator after applying all options") << endl; + err << QObject::tr("Invalid password generator after applying all options") << Qt::endl; return {}; } @@ -159,7 +160,7 @@ int Generate::execute(const QStringList& arguments) auto& out = Utils::STDOUT; QString password = passwordGenerator->generatePassword(); - out << password << endl; + out << password << Qt::endl; return EXIT_SUCCESS; } diff --git a/src/cli/Import.cpp b/src/cli/Import.cpp index a9d7a5a2f4..48f93d88c5 100644 --- a/src/cli/Import.cpp +++ b/src/cli/Import.cpp @@ -20,6 +20,8 @@ #include "DatabaseCreate.h" #include "Utils.h" +#include "core/Global.h" + #include #include @@ -61,7 +63,7 @@ int Import::execute(const QStringList& arguments) const QString& dbPath = args.at(1); if (QFileInfo::exists(dbPath)) { - err << QObject::tr("File %1 already exists.").arg(dbPath) << endl; + err << QObject::tr("File %1 already exists.").arg(dbPath) << Qt::endl; return EXIT_FAILURE; } @@ -72,15 +74,15 @@ int Import::execute(const QStringList& arguments) QString errorMessage; if (!db->import(xmlExportPath, &errorMessage)) { - err << QObject::tr("Unable to import XML database: %1").arg(errorMessage) << endl; + err << QObject::tr("Unable to import XML database: %1").arg(errorMessage) << Qt::endl; return EXIT_FAILURE; } if (!db->saveAs(dbPath, Database::Atomic, {}, &errorMessage)) { - err << QObject::tr("Failed to save the database: %1.").arg(errorMessage) << endl; + err << QObject::tr("Failed to save the database: %1.").arg(errorMessage) << Qt::endl; return EXIT_FAILURE; } - out << QObject::tr("Successfully imported database.") << endl; + out << QObject::tr("Successfully imported database.") << Qt::endl; return EXIT_SUCCESS; } diff --git a/src/cli/List.cpp b/src/cli/List.cpp index 4140c1cd80..fb99350ce5 100644 --- a/src/cli/List.cpp +++ b/src/cli/List.cpp @@ -18,6 +18,7 @@ #include "List.h" #include "Utils.h" +#include "core/Global.h" #include "core/Group.h" #include @@ -52,17 +53,17 @@ int List::executeWithDatabase(QSharedPointer database, QSharedPointer< // No group provided, defaulting to root group. if (args.size() == 1) { - out << database->rootGroup()->print(recursive, flatten) << flush; + out << database->rootGroup()->print(recursive, flatten) << Qt::flush; return EXIT_SUCCESS; } const QString& groupPath = args.at(1); Group* group = database->rootGroup()->findGroupByPath(groupPath); if (!group) { - err << QObject::tr("Cannot find group %1.").arg(groupPath) << endl; + err << QObject::tr("Cannot find group %1.").arg(groupPath) << Qt::endl; return EXIT_FAILURE; } - out << group->print(recursive, flatten) << flush; + out << group->print(recursive, flatten) << Qt::flush; return EXIT_SUCCESS; } diff --git a/src/cli/Merge.cpp b/src/cli/Merge.cpp index 410892c9fc..80bd923418 100644 --- a/src/cli/Merge.cpp +++ b/src/cli/Merge.cpp @@ -18,6 +18,7 @@ #include "Merge.h" #include "Utils.h" +#include "core/Global.h" #include "core/Merger.h" #include @@ -90,18 +91,18 @@ int Merge::executeWithDatabase(QSharedPointer database, QSharedPointer QStringList changeList = merger.merge(); for (auto& mergeChange : changeList) { - out << "\t" << mergeChange << endl; + out << "\t" << mergeChange << Qt::endl; } if (!changeList.isEmpty() && !parser->isSet(Merge::DryRunOption)) { QString errorMessage; if (!database->save(Database::Atomic, {}, &errorMessage)) { - err << QObject::tr("Unable to save database to file : %1").arg(errorMessage) << endl; + err << QObject::tr("Unable to save database to file : %1").arg(errorMessage) << Qt::endl; return EXIT_FAILURE; } - out << QObject::tr("Successfully merged %1 into %2.").arg(fromDatabasePath, toDatabasePath) << endl; + out << QObject::tr("Successfully merged %1 into %2.").arg(fromDatabasePath, toDatabasePath) << Qt::endl; } else { - out << QObject::tr("Database was not modified by merge operation.") << endl; + out << QObject::tr("Database was not modified by merge operation.") << Qt::endl; } return EXIT_SUCCESS; diff --git a/src/cli/Move.cpp b/src/cli/Move.cpp index 8cdf96eb9a..96407c6804 100644 --- a/src/cli/Move.cpp +++ b/src/cli/Move.cpp @@ -18,6 +18,7 @@ #include "Move.h" #include "Utils.h" +#include "core/Global.h" #include "core/Group.h" #include @@ -43,18 +44,18 @@ int Move::executeWithDatabase(QSharedPointer database, QSharedPointer< Entry* 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; } Group* destinationGroup = database->rootGroup()->findGroupByPath(destinationPath); if (!destinationGroup) { - err << QObject::tr("Could not find group with path %1.").arg(destinationPath) << endl; + err << QObject::tr("Could not find group with path %1.").arg(destinationPath) << Qt::endl; return EXIT_FAILURE; } if (destinationGroup == entry->parent()) { - err << QObject::tr("Entry is already in group %1.").arg(destinationPath) << endl; + err << QObject::tr("Entry is already in group %1.").arg(destinationPath) << Qt::endl; return EXIT_FAILURE; } @@ -64,10 +65,10 @@ int Move::executeWithDatabase(QSharedPointer database, QSharedPointer< 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 moved entry %1 to group %2.").arg(entry->title(), destinationPath) << endl; + out << QObject::tr("Successfully moved entry %1 to group %2.").arg(entry->title(), destinationPath) << Qt::endl; return EXIT_SUCCESS; } diff --git a/src/cli/Remove.cpp b/src/cli/Remove.cpp index f383d1636d..2e2132f814 100644 --- a/src/cli/Remove.cpp +++ b/src/cli/Remove.cpp @@ -18,6 +18,7 @@ #include "Remove.h" #include "Utils.h" +#include "core/Global.h" #include "core/Group.h" #include "core/Metadata.h" @@ -38,7 +39,7 @@ int Remove::executeWithDatabase(QSharedPointer database, QSharedPointe auto& entryPath = parser->positionalArguments().at(1); QPointer entry = database->rootGroup()->findEntryByPath(entryPath); if (!entry) { - err << QObject::tr("Entry %1 not found.").arg(entryPath) << endl; + err << QObject::tr("Entry %1 not found.").arg(entryPath) << Qt::endl; return EXIT_FAILURE; } @@ -54,14 +55,14 @@ int Remove::executeWithDatabase(QSharedPointer database, QSharedPointe QString errorMessage; if (!database->save(Database::Atomic, {}, &errorMessage)) { - err << QObject::tr("Unable to save database to file: %1").arg(errorMessage) << endl; + err << QObject::tr("Unable to save database to file: %1").arg(errorMessage) << Qt::endl; return EXIT_FAILURE; } if (recycled) { - out << QObject::tr("Successfully recycled entry %1.").arg(entryTitle) << endl; + out << QObject::tr("Successfully recycled entry %1.").arg(entryTitle) << Qt::endl; } else { - out << QObject::tr("Successfully deleted entry %1.").arg(entryTitle) << endl; + out << QObject::tr("Successfully deleted entry %1.").arg(entryTitle) << Qt::endl; } return EXIT_SUCCESS; diff --git a/src/cli/RemoveGroup.cpp b/src/cli/RemoveGroup.cpp index 15bb01c293..43446a0e70 100644 --- a/src/cli/RemoveGroup.cpp +++ b/src/cli/RemoveGroup.cpp @@ -18,6 +18,7 @@ #include "RemoveGroup.h" #include "Utils.h" +#include "core/Global.h" #include "core/Group.h" #include "core/Metadata.h" @@ -42,12 +43,12 @@ int RemoveGroup::executeWithDatabase(QSharedPointer database, QSharedP // Recursive option means were looking for a group to remove. QPointer group = database->rootGroup()->findGroupByPath(groupPath); if (!group) { - err << QObject::tr("Group %1 not found.").arg(groupPath) << endl; + err << QObject::tr("Group %1 not found.").arg(groupPath) << Qt::endl; return EXIT_FAILURE; } if (group == database->rootGroup()) { - err << QObject::tr("Cannot remove root group from database.") << endl; + err << QObject::tr("Cannot remove root group from database.") << Qt::endl; return EXIT_FAILURE; } @@ -62,14 +63,14 @@ int RemoveGroup::executeWithDatabase(QSharedPointer database, QSharedP QString errorMessage; if (!database->save(Database::Atomic, {}, &errorMessage)) { - err << QObject::tr("Unable to save database to file: %1").arg(errorMessage) << endl; + err << QObject::tr("Unable to save database to file: %1").arg(errorMessage) << Qt::endl; return EXIT_FAILURE; } if (recycled) { - out << QObject::tr("Successfully recycled group %1.").arg(groupPath) << endl; + out << QObject::tr("Successfully recycled group %1.").arg(groupPath) << Qt::endl; } else { - out << QObject::tr("Successfully deleted group %1.").arg(groupPath) << endl; + out << QObject::tr("Successfully deleted group %1.").arg(groupPath) << Qt::endl; } return EXIT_SUCCESS; diff --git a/src/cli/Search.cpp b/src/cli/Search.cpp index 44f1743e3c..fcaeadd6a2 100644 --- a/src/cli/Search.cpp +++ b/src/cli/Search.cpp @@ -21,6 +21,7 @@ #include "Utils.h" #include "core/EntrySearcher.h" +#include "core/Global.h" #include "core/Group.h" Search::Search() @@ -40,12 +41,12 @@ int Search::executeWithDatabase(QSharedPointer database, QSharedPointe EntrySearcher searcher; auto results = searcher.search(args.at(1), database->rootGroup(), true); if (results.isEmpty()) { - err << "No results for that search term." << endl; + err << "No results for that search term." << Qt::endl; return EXIT_FAILURE; } for (const Entry* result : asConst(results)) { - out << result->path().prepend('/') << endl; + out << result->path().prepend('/') << Qt::endl; } return EXIT_SUCCESS; } diff --git a/src/cli/Show.cpp b/src/cli/Show.cpp index c8cb430ed9..6cfe2044a4 100644 --- a/src/cli/Show.cpp +++ b/src/cli/Show.cpp @@ -73,12 +73,12 @@ int Show::executeWithDatabase(QSharedPointer database, QSharedPointer< Entry* 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; } if (showTotp && !entry->hasTotp()) { - err << QObject::tr("Entry with path %1 has no TOTP set up.").arg(entryPath) << endl; + err << QObject::tr("Entry with path %1 has no TOTP set up.").arg(entryPath) << Qt::endl; return EXIT_FAILURE; } @@ -113,20 +113,20 @@ int Show::executeWithDatabase(QSharedPointer database, QSharedPointer< if (!attributesWereSpecified) { out << attributeName << ": "; } - out << Utils::getTopLevelField(entry, attributeName) << endl; + out << Utils::getTopLevelField(entry, attributeName) << Qt::endl; continue; } QStringList attrs = Utils::findAttributes(*entry->attributes(), attributeName); if (attrs.isEmpty()) { encounteredError = true; - err << QObject::tr("ERROR: unknown attribute %1.").arg(attributeName) << endl; + err << QObject::tr("ERROR: unknown attribute %1.").arg(attributeName) << Qt::endl; continue; } else if (attrs.size() > 1) { encounteredError = true; err << QObject::tr("ERROR: attribute %1 is ambiguous, it matches %2.") .arg(attributeName, QLocale().createSeparatedList(attrs)) - << endl; + << Qt::endl; continue; } QString canonicalName = attrs[0]; @@ -134,33 +134,33 @@ int Show::executeWithDatabase(QSharedPointer database, QSharedPointer< out << canonicalName << ": "; } if (entry->attributes()->isProtected(canonicalName) && !attributesWereSpecified && !showProtectedAttributes) { - out << "PROTECTED" << endl; + out << "PROTECTED" << Qt::endl; } else { - out << entry->resolveMultiplePlaceholders(entry->attributes()->value(canonicalName)) << endl; + out << entry->resolveMultiplePlaceholders(entry->attributes()->value(canonicalName)) << Qt::endl; } } if (parser->isSet(Show::AttachmentsOption)) { // Separate attachment output from attributes output via a newline. - out << endl; + out << Qt::endl; EntryAttachments* attachments = entry->attachments(); if (attachments->isEmpty()) { - out << QObject::tr("No attachments present.") << endl; + out << QObject::tr("No attachments present.") << Qt::endl; } else { - out << QObject::tr("Attachments:") << endl; + out << QObject::tr("Attachments:") << Qt::endl; // Iterate over the attachments and output their names and size line-by-line, indented. for (const QString& attachmentName : attachments->keys()) { // TODO: use QLocale::formattedDataSize when >= Qt 5.10 QString attachmentSize = Tools::humanReadableFileSize(attachments->value(attachmentName).size(), 1); - out << " " << attachmentName << " (" << attachmentSize << ")" << endl; + out << " " << attachmentName << " (" << attachmentSize << ")" << Qt::endl; } } } if (showTotp) { - out << entry->totp() << endl; + out << entry->totp() << Qt::endl; } return encounteredError ? EXIT_FAILURE : EXIT_SUCCESS; diff --git a/src/cli/Utils.cpp b/src/cli/Utils.cpp index bca837db8a..853ad17bc5 100644 --- a/src/cli/Utils.cpp +++ b/src/cli/Utils.cpp @@ -20,6 +20,7 @@ #include "core/Database.h" #include "core/Entry.h" #include "core/EntryAttributes.h" +#include "core/Global.h" #include "keys/FileKey.h" #ifdef WITH_XC_YUBIKEY #include "keys/ChallengeResponseKey.h" @@ -111,22 +112,22 @@ namespace Utils QFileInfo dbFileInfo(databaseFilename); if (dbFileInfo.canonicalFilePath().isEmpty()) { - err << QObject::tr("Failed to open database file %1: not found").arg(databaseFilename) << endl; + err << QObject::tr("Failed to open database file %1: not found").arg(databaseFilename) << Qt::endl; return {}; } if (!dbFileInfo.isFile()) { - err << QObject::tr("Failed to open database file %1: not a plain file").arg(databaseFilename) << endl; + err << QObject::tr("Failed to open database file %1: not a plain file").arg(databaseFilename) << Qt::endl; return {}; } if (!dbFileInfo.isReadable()) { - err << QObject::tr("Failed to open database file %1: not readable").arg(databaseFilename) << endl; + err << QObject::tr("Failed to open database file %1: not readable").arg(databaseFilename) << Qt::endl; return {}; } if (isPasswordProtected) { - err << QObject::tr("Enter password to unlock %1: ").arg(databaseFilename) << flush; + err << QObject::tr("Enter password to unlock %1: ").arg(databaseFilename) << Qt::flush; QString line = Utils::getPassword(quiet); auto passwordKey = QSharedPointer::create(); passwordKey->setPassword(line); @@ -138,7 +139,7 @@ namespace Utils QString errorMessage; // LCOV_EXCL_START if (!fileKey->load(keyFilename, &errorMessage)) { - err << QObject::tr("Failed to load key file %1: %2").arg(keyFilename, errorMessage) << endl; + err << QObject::tr("Failed to load key file %1: %2").arg(keyFilename, errorMessage) << Qt::endl; return {}; } @@ -146,7 +147,7 @@ namespace Utils err << QObject::tr("WARNING: You are using an old key file format which KeePassXC may\n" "stop supporting in the future.\n\n" "Please consider generating a new key file.") - << endl; + << Qt::endl; } // LCOV_EXCL_STOP @@ -163,20 +164,20 @@ namespace Utils slot = parts[0].toInt(&ok); if (!ok || (slot != 1 && slot != 2)) { - err << QObject::tr("Invalid YubiKey slot %1").arg(parts[0]) << endl; + err << QObject::tr("Invalid YubiKey slot %1").arg(parts[0]) << Qt::endl; return {}; } if (parts.size() > 1) { serial = parts[1].toUInt(&ok, 10); if (!ok) { - err << QObject::tr("Invalid YubiKey serial %1").arg(parts[1]) << endl; + err << QObject::tr("Invalid YubiKey serial %1").arg(parts[1]) << Qt::endl; return {}; } } QObject::connect(YubiKey::instance(), &YubiKey::userInteractionRequest, [&] { - err << QObject::tr("Please present or touch your YubiKey to continue.") << "\n\n" << flush; + err << QObject::tr("Please present or touch your YubiKey to continue.") << "\n\n" << Qt::flush; }); auto key = QSharedPointer(new ChallengeResponseKey({serial, slot})); @@ -193,7 +194,7 @@ namespace Utils if (db->open(databaseFilename, compositeKey, &error)) { return db; } else { - err << error << endl; + err << error << Qt::endl; return {}; } } @@ -218,7 +219,7 @@ namespace Utils setStdinEcho(false); QString line = in.readLine(); setStdinEcho(true); - out << endl; + out << Qt::endl; return line; #endif // __AFL_COMPILER @@ -248,7 +249,7 @@ namespace Utils if (ans.toLower().startsWith("y")) { passwordKey = QSharedPointer::create(""); } - err << endl; + err << Qt::endl; } else { err << QObject::tr("Repeat password: "); err.flush(); @@ -257,7 +258,7 @@ namespace Utils if (password == repeat) { passwordKey = QSharedPointer::create(password); } else { - err << QObject::tr("Error: Passwords do not match.") << endl; + err << QObject::tr("Error: Passwords do not match.") << Qt::endl; } } @@ -303,7 +304,7 @@ namespace Utils QScopedPointer clipProcess(new QProcess(nullptr)); // Skip empty parts, otherwise the program may clip the empty string - QStringList progArgs = prog.second.split(" ", QString::SkipEmptyParts); + QStringList progArgs = prog.second.split(" ", Qt::SkipEmptyParts); clipProcess->start(prog.first, progArgs); clipProcess->waitForStarted(); @@ -425,13 +426,13 @@ namespace Utils fileKey->create(path, &error); if (!error.isEmpty()) { - err << QObject::tr("Creating KeyFile %1 failed: %2").arg(path, error) << endl; + err << QObject::tr("Creating KeyFile %1 failed: %2").arg(path, error) << Qt::endl; return false; } } if (!fileKey->load(path, &error)) { - err << QObject::tr("Loading KeyFile %1 failed: %2").arg(path, error) << endl; + err << QObject::tr("Loading KeyFile %1 failed: %2").arg(path, error) << Qt::endl; return false; } diff --git a/src/cli/keepassxc-cli.cpp b/src/cli/keepassxc-cli.cpp index 120c706472..84bbc56e30 100644 --- a/src/cli/keepassxc-cli.cpp +++ b/src/cli/keepassxc-cli.cpp @@ -153,7 +153,7 @@ int enterInteractiveMode(const QStringList& arguments) auto cmd = Commands::getCommand(args[0]); if (!cmd) { - err << QObject::tr("Unknown command %1").arg(args[0]) << endl; + err << QObject::tr("Unknown command %1").arg(args[0]) << Qt::endl; continue; } else if (cmd->name == "quit" || cmd->name == "exit") { break; @@ -215,11 +215,11 @@ int main(int argc, char** argv) if (parser.positionalArguments().empty()) { if (parser.isSet("version")) { // Switch to parser.showVersion() when available (QT 5.4). - out << KEEPASSXC_VERSION << endl; + out << KEEPASSXC_VERSION << Qt::endl; return EXIT_SUCCESS; } else if (parser.isSet(debugInfoOption)) { QString debugInfo = Tools::debugInfo().append("\n").append(Crypto::debugInfo()); - out << debugInfo << endl; + out << debugInfo << Qt::endl; return EXIT_SUCCESS; } // showHelp exits the application immediately. @@ -233,7 +233,7 @@ int main(int argc, char** argv) auto command = Commands::getCommand(commandName); if (!command) { - err << QObject::tr("Invalid command %1.").arg(commandName) << endl; + err << QObject::tr("Invalid command %1.").arg(commandName) << Qt::endl; err << parser.helpText(); return EXIT_FAILURE; } diff --git a/src/core/Clock.cpp b/src/core/Clock.cpp index fcab4d2ae3..f501daee73 100644 --- a/src/core/Clock.cpp +++ b/src/core/Clock.cpp @@ -16,6 +16,8 @@ */ #include "Clock.h" +#include + QSharedPointer Clock::m_instance; QDateTime Clock::currentDateTimeUtc() @@ -78,6 +80,12 @@ QDateTime Clock::parse(const QString& text, const QString& format) return QDateTime::fromString(text, format); } +QString Clock::toString(const QDateTime& dateTime) +{ + static QLocale locale; + return locale.toString(dateTime, QLocale::ShortFormat); +} + Clock::~Clock() = default; Clock::Clock() = default; diff --git a/src/core/Clock.h b/src/core/Clock.h index 4d1ee25371..ca2577e919 100644 --- a/src/core/Clock.h +++ b/src/core/Clock.h @@ -41,6 +41,8 @@ class Clock static QDateTime parse(const QString& text, Qt::DateFormat format = Qt::TextDate); static QDateTime parse(const QString& text, const QString& format); + static QString toString(const QDateTime& dateTime); + virtual ~Clock(); protected: diff --git a/src/core/Database.cpp b/src/core/Database.cpp index aa36dad126..3239a47aec 100644 --- a/src/core/Database.cpp +++ b/src/core/Database.cpp @@ -712,7 +712,7 @@ void Database::updateTagList() } } - m_tagList = tagSet.toList(); + m_tagList = tagSet.values(); m_tagList.sort(); emit tagListUpdated(); } diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index 973aa189dc..3efe55c456 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -20,6 +20,7 @@ #include "core/Config.h" #include "core/Database.h" +#include "core/Global.h" #include "core/Group.h" #include "core/Metadata.h" #include "core/PasswordHealth.h" @@ -286,7 +287,7 @@ QString Entry::effectiveAutoTypeSequence() const /** * Retrieve the Auto-Type sequences matches for a given windowTitle - * This returns a list with priority ordering. If you don't want duplicates call .toSet() on it. + * This returns a list with priority ordering. If you don't want duplicates, convert it to a QSet. */ QList Entry::autoTypeSequences(const QString& windowTitle) const { @@ -438,7 +439,7 @@ int Entry::size() const size += this->autoTypeAssociations()->associationsSize(); size += this->attachments()->attachmentsSize(); size += this->customData()->dataSize(); - const QStringList tags = this->tags().split(delimiter, QString::SkipEmptyParts); + const QStringList tags = this->tags().split(delimiter, Qt::SkipEmptyParts); for (const QString& tag : tags) { size += tag.toUtf8().size(); } @@ -665,14 +666,13 @@ void Entry::setOverrideUrl(const QString& url) void Entry::setTags(const QString& tags) { static QRegExp rx("(\\,|\\t|\\;)"); - auto taglist = tags.split(rx, QString::SkipEmptyParts); + auto taglist = tags.split(rx, Qt::SkipEmptyParts); // Trim whitespace before/after tag text for (auto itr = taglist.begin(); itr != taglist.end(); ++itr) { *itr = itr->trimmed(); } // Remove duplicates - auto tagSet = QSet::fromList(taglist); - taglist = tagSet.toList(); + taglist = Tools::asSet(taglist).values(); // Sort alphabetically taglist.sort(); set(m_data.tags, taglist); diff --git a/src/core/EntryAttachments.cpp b/src/core/EntryAttachments.cpp index c611f44137..e5c94b7325 100644 --- a/src/core/EntryAttachments.cpp +++ b/src/core/EntryAttachments.cpp @@ -19,6 +19,7 @@ #include "config-keepassx.h" #include "core/Global.h" +#include "core/Tools.h" #include "crypto/Random.h" #include @@ -50,7 +51,7 @@ bool EntryAttachments::hasKey(const QString& key) const QSet EntryAttachments::values() const { - return asConst(m_attachments).values().toSet(); + return Tools::asSet(m_attachments.values()); } QByteArray EntryAttachments::value(const QString& key) const diff --git a/src/core/EntryAttributes.cpp b/src/core/EntryAttributes.cpp index 49c243ec17..22ffa0385d 100644 --- a/src/core/EntryAttributes.cpp +++ b/src/core/EntryAttributes.cpp @@ -18,6 +18,7 @@ #include "EntryAttributes.h" #include "core/Global.h" +#include "core/Tools.h" #include #include @@ -238,7 +239,7 @@ void EntryAttributes::copyCustomKeysFrom(const EntryAttributes* other) bool EntryAttributes::areCustomKeysDifferent(const EntryAttributes* other) { // check if they are equal ignoring the order of the keys - if (keys().toSet() != other->keys().toSet()) { + if (Tools::asSet(keys()) != Tools::asSet(other->keys())) { return true; } diff --git a/src/core/EntrySearcher.cpp b/src/core/EntrySearcher.cpp index 13369a66d8..085c5bcdb0 100644 --- a/src/core/EntrySearcher.cpp +++ b/src/core/EntrySearcher.cpp @@ -203,7 +203,7 @@ bool EntrySearcher::searchEntryImpl(const Entry* entry) case Field::Is: if (term.word.startsWith("expired", Qt::CaseInsensitive)) { auto days = 0; - auto parts = term.word.split("-", QString::SkipEmptyParts); + auto parts = term.word.split("-", Qt::SkipEmptyParts); if (parts.length() >= 2) { days = parts[1].toInt(); } diff --git a/src/core/Global.h b/src/core/Global.h index e9a4db7397..9630f2f73a 100644 --- a/src/core/Global.h +++ b/src/core/Global.h @@ -21,6 +21,7 @@ #define KEEPASSX_GLOBAL_H #include +#include #if defined(Q_OS_WIN) #if defined(KEEPASSX_BUILDING_CORE) @@ -42,6 +43,23 @@ #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/Merger.cpp b/src/core/Merger.cpp index fd30da7aa4..3b66873205 100644 --- a/src/core/Merger.cpp +++ b/src/core/Merger.cpp @@ -17,7 +17,9 @@ #include "Merger.h" +#include "core/Global.h" #include "core/Metadata.h" +#include "core/Tools.h" Merger::Merger(const Database* sourceDb, Database* targetDb) : m_mode(Group::Default) @@ -568,7 +570,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/PasswordHealth.cpp b/src/core/PasswordHealth.cpp index 3225affb30..3a2e5571df 100644 --- a/src/core/PasswordHealth.cpp +++ b/src/core/PasswordHealth.cpp @@ -17,6 +17,7 @@ #include +#include "Clock.h" #include "Group.h" #include "PasswordHealth.h" #include "zxcvbn.h" @@ -171,8 +172,8 @@ QSharedPointer HealthChecker::evaluate(const Entry* entry) const if (entry->isExpired()) { health->setScore(0); health->addScoreReason(QObject::tr("Password has expired")); - health->addScoreDetails(QObject::tr("Password expiry was %1") - .arg(entry->timeInfo().expiryTime().toString(Qt::DefaultLocaleShortDate))); + health->addScoreDetails( + QObject::tr("Password expiry was %1").arg(Clock::toString(entry->timeInfo().expiryTime()))); } else if (entry->timeInfo().expires()) { const int days = QDateTime::currentDateTime().daysTo(entry->timeInfo().expiryTime()); if (days <= 30) { @@ -186,8 +187,8 @@ QSharedPointer HealthChecker::evaluate(const Entry* entry) const } health->adjustScore((30 - days) * -2); - health->addScoreDetails(QObject::tr("Password expires on %1") - .arg(entry->timeInfo().expiryTime().toString(Qt::DefaultLocaleShortDate))); + health->addScoreDetails( + QObject::tr("Password expires on %1").arg(Clock::toString(entry->timeInfo().expiryTime()))); if (days <= 2) { health->addScoreReason(QObject::tr("Password is about to expire")); } else if (days <= 10) { diff --git a/src/core/Tools.cpp b/src/core/Tools.cpp index cefb0448d9..448e5fba87 100644 --- a/src/core/Tools.cpp +++ b/src/core/Tools.cpp @@ -28,6 +28,7 @@ #include "core/Clock.h" +#include #include #include #include @@ -35,6 +36,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/src/core/Tools.h b/src/core/Tools.h index 85c1b53c09..19c85e078f 100644 --- a/src/core/Tools.h +++ b/src/core/Tools.h @@ -24,9 +24,11 @@ #include #include #include +#include class QIODevice; class QRegularExpression; +class QUrl; namespace Tools { @@ -46,6 +48,15 @@ namespace Tools QProcessEnvironment environment = QProcessEnvironment::systemEnvironment()); QString cleanFilename(QString filename); + 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 + } + /** * Escapes all characters in regex such that they do not receive any special treatment when used * in a regular expression. Essentially, this function escapes any characters not in a-zA-Z0-9. diff --git a/src/fdosecrets/objects/Collection.cpp b/src/fdosecrets/objects/Collection.cpp index 4cc6ca537d..96a1e443ae 100644 --- a/src/fdosecrets/objects/Collection.cpp +++ b/src/fdosecrets/objects/Collection.cpp @@ -644,7 +644,7 @@ namespace FdoSecrets // groupPath can't be empty here, because otherwise it will match m_exposedGroup and was returned above Q_ASSERT(!groupPath.isEmpty()); - auto groups = groupPath.split('/', QString::SkipEmptyParts); + auto groups = groupPath.split('/', Qt::SkipEmptyParts); auto groupName = groups.takeLast(); // create parent group diff --git a/src/fdosecrets/widgets/AccessControlDialog.cpp b/src/fdosecrets/widgets/AccessControlDialog.cpp index 8e3a3e1d83..e8602f01d5 100644 --- a/src/fdosecrets/widgets/AccessControlDialog.cpp +++ b/src/fdosecrets/widgets/AccessControlDialog.cpp @@ -24,6 +24,8 @@ #include "fdosecrets/widgets/RowButtonHelper.h" #include "core/Entry.h" +#include "core/Global.h" +#include "core/Tools.h" #include "gui/Icons.h" #include @@ -206,7 +208,7 @@ QHash AccessControlDialog::decisions() const AccessControlDialog::EntryModel::EntryModel(QList entries, QObject* parent) : QAbstractTableModel(parent) , m_entries(std::move(entries)) - , m_selected(QSet::fromList(m_entries)) + , m_selected(Tools::asSet(m_entries)) { } diff --git a/src/format/KdbxXmlReader.cpp b/src/format/KdbxXmlReader.cpp index eb7fa4158e..4ff47d9659 100644 --- a/src/format/KdbxXmlReader.cpp +++ b/src/format/KdbxXmlReader.cpp @@ -19,6 +19,7 @@ #include "KeePass2RandomStream.h" #include "core/Clock.h" #include "core/Endian.h" +#include "core/Global.h" #include "core/Group.h" #include "core/Tools.h" #include "streams/qtiocompressor.h" @@ -120,8 +121,8 @@ void KdbxXmlReader::readDatabase(QIODevice* device, Database* db, KeePass2Random qWarning("KdbxXmlReader::readDatabase: found %d invalid entry reference(s)", m_tmpParent->children().size()); } - const QSet poolKeys = asConst(m_binaryPool).keys().toSet(); - const QSet entryKeys = asConst(m_binaryMap).keys().toSet(); + const QSet poolKeys = Tools::asSet(m_binaryPool.keys()); + const QSet entryKeys = Tools::asSet(m_binaryMap.keys()); const QSet unmappedKeys = entryKeys - poolKeys; const QSet unusedKeys = poolKeys - entryKeys; @@ -133,7 +134,7 @@ void KdbxXmlReader::readDatabase(QIODevice* device, Database* db, KeePass2Random qWarning("KdbxXmlReader::readDatabase: found unused key \"%s\"", qPrintable(key)); } - QHash>::const_iterator i; + QMultiHash>::const_iterator i; for (i = m_binaryMap.constBegin(); i != m_binaryMap.constEnd(); ++i) { const QPair& target = i.value(); target.first->attachments()->set(target.second, m_binaryPool[i.key()]); @@ -815,7 +816,7 @@ Entry* KdbxXmlReader::parseEntry(bool history) } for (const StringPair& ref : asConst(binaryRefs)) { - m_binaryMap.insertMulti(ref.first, qMakePair(entry, ref.second)); + m_binaryMap.insert(ref.first, qMakePair(entry, ref.second)); } return entry; diff --git a/src/format/KdbxXmlReader.h b/src/format/KdbxXmlReader.h index 44978b083f..1b6305eeaf 100644 --- a/src/format/KdbxXmlReader.h +++ b/src/format/KdbxXmlReader.h @@ -22,6 +22,7 @@ #include "core/Metadata.h" #include +#include #include class QIODevice; @@ -109,7 +110,7 @@ class KdbxXmlReader QHash m_entries; QHash m_binaryPool; - QHash> m_binaryMap; + QMultiHash> m_binaryMap; QByteArray m_headerHash; bool m_error = false; diff --git a/src/format/OpVaultReaderSections.cpp b/src/format/OpVaultReaderSections.cpp index 661b9d6c3e..9a50f36246 100644 --- a/src/format/OpVaultReaderSections.cpp +++ b/src/format/OpVaultReaderSections.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include namespace @@ -120,7 +121,7 @@ void OpVaultReader::fillFromSectionField(Entry* entry, const QString& sectionNam if (kind == "date" || kind == "monthYear") { QDateTime date = resolveDate(kind, field.value("v")); if (date.isValid()) { - entry->attributes()->set(attrName, date.toString(Qt::SystemLocaleShortDate)); + entry->attributes()->set(attrName, QLocale::system().toString(date, QLocale::ShortFormat)); } else { qWarning() << QString("[%1] Invalid date attribute found: %2 = %3").arg(entry->title(), attrName, attrValue); diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index b20f5a240b..3ba14f80c6 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -931,7 +931,16 @@ void DatabaseWidget::openUrlForEntry(Entry* entry) } if (launch) { - QProcess::startDetached(cmdString.mid(6)); + 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(); @@ -2118,7 +2127,7 @@ bool DatabaseWidget::saveAs() + (defaultFileName.isEmpty() ? tr("Passwords").append(".kdbx") : defaultFileName)); } const QString newFilePath = fileDialog()->getSaveFileName( - this, tr("Save database as"), oldFilePath, tr("KeePass 2 Database").append(" (*.kdbx)"), nullptr, nullptr); + this, tr("Save database as"), oldFilePath, tr("KeePass 2 Database").append(" (*.kdbx)")); bool ok = false; if (!newFilePath.isEmpty()) { @@ -2210,10 +2219,8 @@ bool DatabaseWidget::saveBackup() const QString newFilePath = fileDialog()->getSaveFileName(this, tr("Save database backup"), - FileDialog::getLastDir("backup", oldFilePath), - tr("KeePass 2 Database").append(" (*.kdbx)"), - nullptr, - nullptr); + FileDialog::getLastDir("backup"), + tr("KeePass 2 Database").append(" (*.kdbx)")); if (!newFilePath.isEmpty()) { // Ensure we don't recurse back into this function diff --git a/src/gui/EntryPreviewWidget.cpp b/src/gui/EntryPreviewWidget.cpp index 50c94325b8..1618902149 100644 --- a/src/gui/EntryPreviewWidget.cpp +++ b/src/gui/EntryPreviewWidget.cpp @@ -20,6 +20,7 @@ #include "ui_EntryPreviewWidget.h" #include "Application.h" +#include "core/Clock.h" #include "core/Config.h" #include "gui/Clipboard.h" #include "gui/Font.h" @@ -399,8 +400,7 @@ void EntryPreviewWidget::updateEntryGeneralTab() } const TimeInfo entryTime = m_currentEntry->timeInfo(); - const QString expires = - entryTime.expires() ? entryTime.expiryTime().toLocalTime().toString(Qt::DefaultLocaleShortDate) : tr("Never"); + const QString expires = entryTime.expires() ? Clock::toString(entryTime.expiryTime().toLocalTime()) : tr("Never"); m_ui->entryExpirationLabel->setText(expires); m_ui->entryTagsList->tags(m_currentEntry->tagList()); m_ui->entryTagsList->setReadOnly(true); @@ -509,8 +509,7 @@ void EntryPreviewWidget::updateGroupGeneralTab() m_ui->groupAutotypeLabel->setText(autotypeText); const TimeInfo groupTime = m_currentGroup->timeInfo(); - const QString expiresText = - groupTime.expires() ? groupTime.expiryTime().toString(Qt::DefaultLocaleShortDate) : tr("Never"); + const QString expiresText = groupTime.expires() ? Clock::toString(groupTime.expiryTime()) : tr("Never"); m_ui->groupExpirationLabel->setText(expiresText); if (config()->get(Config::Security_HideNotes).toBool()) { diff --git a/src/gui/KMessageWidget.cpp b/src/gui/KMessageWidget.cpp index ff279c3329..6b402f3134 100644 --- a/src/gui/KMessageWidget.cpp +++ b/src/gui/KMessageWidget.cpp @@ -280,7 +280,11 @@ void KMessageWidget::setMessageType(KMessageWidget::MessageType type) auto closeButtonPixmap = d->closeButtonPixmap; QPainter painter; painter.begin(&closeButtonPixmap); +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + painter.setRenderHints(QPainter::Antialiasing); +#else painter.setRenderHints(QPainter::HighQualityAntialiasing); +#endif painter.setCompositionMode(QPainter::CompositionMode_SourceIn); painter.fillRect(QRect(0, 0, 16, 16), fg); painter.end(); diff --git a/src/gui/csvImport/CsvImportWidget.cpp b/src/gui/csvImport/CsvImportWidget.cpp index 6781974f54..7a3b44752d 100644 --- a/src/gui/csvImport/CsvImportWidget.cpp +++ b/src/gui/csvImport/CsvImportWidget.cpp @@ -285,7 +285,7 @@ void CsvImportWidget::setRootGroup() } groupLabel = m_parserModel->data(m_parserModel->index(r, 0)).toString(); // check if group name is either "root", "" (empty) or some other label - groupList = groupLabel.split("/", QString::SkipEmptyParts); + groupList = groupLabel.split("/", Qt::SkipEmptyParts); if (groupList.isEmpty()) { is_empty = true; } else if (not groupList.first().compare("Root", Qt::CaseSensitive)) { @@ -314,7 +314,7 @@ Group* CsvImportWidget::splitGroups(const QString& label) return current; } - QStringList groupList = label.split("/", QString::SkipEmptyParts); + QStringList groupList = label.split("/", Qt::SkipEmptyParts); // avoid the creation of a subgroup with the same name as Root if (m_db->rootGroup()->name() == "Root" && groupList.first() == "Root") { groupList.removeFirst(); diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index 9466d09189..17830afe88 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -1210,7 +1210,10 @@ void EditEntryWidget::updateEntryData(Entry* entry) const entry->setPassword(m_mainUi->passwordEdit->text()); entry->setExpires(m_mainUi->expireCheck->isChecked()); entry->setExpiryTime(m_mainUi->expireDatePicker->dateTime().toUTC()); - entry->setTags(m_mainUi->tagsList->tags().toSet().toList().join(";")); // remove repeated tags + + QStringList uniqueTags(m_mainUi->tagsList->tags()); + uniqueTags.removeDuplicates(); + entry->setTags(uniqueTags.join(";")); entry->setNotes(m_mainUi->notesEdit->toPlainText()); diff --git a/src/gui/entry/EntryHistoryModel.cpp b/src/gui/entry/EntryHistoryModel.cpp index acde63cb52..45ff5d88d9 100644 --- a/src/gui/entry/EntryHistoryModel.cpp +++ b/src/gui/entry/EntryHistoryModel.cpp @@ -26,6 +26,7 @@ EntryHistoryModel::EntryHistoryModel(QObject* parent) : QAbstractTableModel(parent) + , m_systemLocale(QLocale::system()) { } @@ -67,7 +68,7 @@ QVariant EntryHistoryModel::data(const QModelIndex& index, int role) const switch (index.column()) { case 0: if (role == Qt::DisplayRole) { - return lastModified.toString(Qt::SystemLocaleShortDate); + return m_systemLocale.toString(lastModified, QLocale::ShortFormat); } else { return lastModified; } diff --git a/src/gui/entry/EntryHistoryModel.h b/src/gui/entry/EntryHistoryModel.h index 21897ec073..101e4ac936 100644 --- a/src/gui/entry/EntryHistoryModel.h +++ b/src/gui/entry/EntryHistoryModel.h @@ -19,6 +19,7 @@ #define KEEPASSX_ENTRYHISTORYMODEL_H #include +#include class Entry; @@ -45,6 +46,7 @@ class EntryHistoryModel : public QAbstractTableModel private: void calculateHistoryModifications(); + QLocale m_systemLocale; QList m_historyEntries; QList m_deletedHistoryEntries; QStringList m_historyModifications; diff --git a/src/gui/entry/EntryModel.cpp b/src/gui/entry/EntryModel.cpp index 234a08ba7e..f809e2b2a6 100644 --- a/src/gui/entry/EntryModel.cpp +++ b/src/gui/entry/EntryModel.cpp @@ -21,6 +21,7 @@ #include #include +#include "core/Clock.h" #include "core/Entry.h" #include "core/Group.h" #include "core/Metadata.h" @@ -36,7 +37,6 @@ EntryModel::EntryModel(QObject* parent) : QAbstractTableModel(parent) , m_group(nullptr) , HiddenContentDisplay(QString("\u25cf").repeated(6)) - , DateFormat(Qt::DefaultLocaleShortDate) { connect(config(), &Config::changed, this, &EntryModel::onConfigChanged); } @@ -189,18 +189,17 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const return result; case Expires: // Display either date of expiry or 'Never' - result = entry->timeInfo().expires() - ? entry->timeInfo().expiryTime().toLocalTime().toString(EntryModel::DateFormat) - : tr("Never"); + result = entry->timeInfo().expires() ? Clock::toString(entry->timeInfo().expiryTime().toLocalTime()) + : tr("Never"); return result; case Created: - result = entry->timeInfo().creationTime().toLocalTime().toString(EntryModel::DateFormat); + result = Clock::toString(entry->timeInfo().creationTime().toLocalTime()); return result; case Modified: - result = entry->timeInfo().lastModificationTime().toLocalTime().toString(EntryModel::DateFormat); + result = Clock::toString(entry->timeInfo().lastModificationTime().toLocalTime()); return result; case Accessed: - result = entry->timeInfo().lastAccessTime().toLocalTime().toString(EntryModel::DateFormat); + result = Clock::toString(entry->timeInfo().lastAccessTime().toLocalTime()); return result; case Attachments: { // Display comma-separated list of attachments @@ -251,8 +250,13 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const return 0; } case Expires: + return entry->timeInfo().expires() ? entry->timeInfo().expiryTime() // There seems to be no better way of expressing 'infinity' - return entry->timeInfo().expires() ? entry->timeInfo().expiryTime() : QDateTime(QDate(9999, 1, 1)); +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + : 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/EntryModel.h b/src/gui/entry/EntryModel.h index 4ad81f4c48..99f254462c 100644 --- a/src/gui/entry/EntryModel.h +++ b/src/gui/entry/EntryModel.h @@ -94,7 +94,6 @@ private slots: QSet m_allGroups; const QString HiddenContentDisplay; - const Qt::DateFormat DateFormat; }; #endif // KEEPASSX_ENTRYMODEL_H diff --git a/src/gui/osutils/nixutils/NixUtils.cpp b/src/gui/osutils/nixutils/NixUtils.cpp index 194b62058e..4d6a3df29b 100644 --- a/src/gui/osutils/nixutils/NixUtils.cpp +++ b/src/gui/osutils/nixutils/NixUtils.cpp @@ -18,6 +18,7 @@ #include "NixUtils.h" #include "config-keepassx.h" +#include "core/Global.h" #include #include @@ -158,7 +159,7 @@ void NixUtils::setLaunchAtStartup(bool enable) << QStringLiteral("X-GNOME-Autostart-enabled=true") << '\n' << QStringLiteral("X-GNOME-Autostart-Delay=2") << '\n' << QStringLiteral("X-KDE-autostart-after=panel") << '\n' - << QStringLiteral("X-LXQt-Need-Tray=true") << endl; + << QStringLiteral("X-LXQt-Need-Tray=true") << Qt::endl; desktopFile.close(); } else if (isLaunchAtStartupEnabled()) { QFile::remove(getAutostartDesktopFilename()); diff --git a/src/gui/reports/ReportsWidgetHibp.cpp b/src/gui/reports/ReportsWidgetHibp.cpp index d4ae1f4d6d..dccaa4c51c 100644 --- a/src/gui/reports/ReportsWidgetHibp.cpp +++ b/src/gui/reports/ReportsWidgetHibp.cpp @@ -29,6 +29,8 @@ #include #include +#include + namespace { class ReportSortProxyModel : public QSortFilterProxyModel @@ -131,8 +133,8 @@ void ReportsWidgetHibp::makeHibpTable() } } - // Sort descending by the number the password has been exposed - qSort(items.begin(), items.end(), [](QPair& lhs, QPair& rhs) { + // Sort decending by the number the password has been exposed + std::sort(items.begin(), items.end(), [](QPair& lhs, QPair& rhs) { return lhs.second > rhs.second; }); diff --git a/src/gui/reports/ReportsWidgetStatistics.cpp b/src/gui/reports/ReportsWidgetStatistics.cpp index e8068b5640..2f1759cd7f 100644 --- a/src/gui/reports/ReportsWidgetStatistics.cpp +++ b/src/gui/reports/ReportsWidgetStatistics.cpp @@ -19,6 +19,7 @@ #include "ui_ReportsWidgetStatistics.h" #include "core/AsyncTask.h" +#include "core/Clock.h" #include "core/DatabaseStats.h" #include "core/Group.h" #include "core/Metadata.h" @@ -86,9 +87,8 @@ void ReportsWidgetStatistics::calculateStats() addStatsRow(tr("Database name"), m_db->metadata()->name()); addStatsRow(tr("Description"), m_db->metadata()->description()); addStatsRow(tr("Location"), m_db->filePath()); - addStatsRow(tr("Database created"), - m_db->rootGroup()->timeInfo().creationTime().toString(Qt::DefaultLocaleShortDate)); - addStatsRow(tr("Last saved"), stats->modified.toString(Qt::DefaultLocaleShortDate)); + addStatsRow(tr("Database created"), Clock::toString(m_db->rootGroup()->timeInfo().creationTime())); + addStatsRow(tr("Last saved"), Clock::toString(stats->modified)); addStatsRow(tr("Unsaved changes"), m_db->isModified() ? tr("yes") : tr("no"), m_db->isModified(), diff --git a/src/gui/styles/base/BaseStyle.cpp b/src/gui/styles/base/BaseStyle.cpp index 5938d5d045..824468b2db 100644 --- a/src/gui/styles/base/BaseStyle.cpp +++ b/src/gui/styles/base/BaseStyle.cpp @@ -1476,13 +1476,13 @@ void BaseStyle::drawPrimitive(PrimitiveElement elem, } case PE_FrameDockWidget: { painter->save(); - QColor softshadow = option->palette.background().color().darker(120); + QColor softshadow = option->palette.window().color().darker(120); QRect r = option->rect; painter->setPen(softshadow); painter->drawRect(r.adjusted(0, 0, -1, -1)); painter->setPen(QPen(option->palette.light(), 1)); painter->drawLine(QPoint(r.left() + 1, r.top() + 1), QPoint(r.left() + 1, r.bottom() - 1)); - painter->setPen(QPen(option->palette.background().color().darker(120))); + painter->setPen(QPen(option->palette.window().color().darker(120))); painter->drawLine(QPoint(r.left() + 1, r.bottom() - 1), QPoint(r.right() - 2, r.bottom() - 1)); painter->drawLine(QPoint(r.right() - 1, r.top() + 1), QPoint(r.right() - 1, r.bottom() - 1)); painter->restore(); @@ -1734,12 +1734,12 @@ void BaseStyle::drawPrimitive(PrimitiveElement elem, // TODO replace with new code const int margin = 6; const int offset = r.height() / 2; - painter->setPen(QPen(option->palette.background().color().darker(110))); + painter->setPen(QPen(option->palette.window().color().darker(110))); painter->drawLine(r.topLeft().x() + margin, r.topLeft().y() + offset, r.topRight().x() - margin, r.topRight().y() + offset); - painter->setPen(QPen(option->palette.background().color().lighter(110))); + painter->setPen(QPen(option->palette.window().color().lighter(110))); painter->drawLine(r.topLeft().x() + margin, r.topLeft().y() + offset + 1, r.topRight().x() - margin, @@ -3268,13 +3268,13 @@ void BaseStyle::drawComplexControl(ComplexControl control, QColor outline = option->palette.dark().color(); QColor titleBarFrameBorder(active ? highlight.darker(180) : outline.darker(110)); - QColor titleBarHighlight(active ? highlight.lighter(120) : palette.background().color().lighter(120)); + QColor titleBarHighlight(active ? highlight.lighter(120) : palette.window().color().lighter(120)); QColor textColor(active ? 0xffffff : 0xff000000); QColor textAlphaColor(active ? 0xffffff : 0xff000000); { // Fill title - auto titlebarColor = QColor(active ? highlight : palette.background().color()); + auto titlebarColor = QColor(active ? highlight : palette.window().color()); painter->fillRect(option->rect.adjusted(1, 1, -1, 0), titlebarColor); // Frame and rounded corners painter->setPen(titleBarFrameBorder); diff --git a/src/keys/drivers/YubiKey.cpp b/src/keys/drivers/YubiKey.cpp index f735c5dba5..a5603de985 100644 --- a/src/keys/drivers/YubiKey.cpp +++ b/src/keys/drivers/YubiKey.cpp @@ -23,7 +23,6 @@ #include YubiKey::YubiKey() - : m_interfaces_detect_mutex(QMutex::Recursive) { int num_interfaces = 0; diff --git a/src/keys/drivers/YubiKey.h b/src/keys/drivers/YubiKey.h index 312dea8973..30de764a77 100644 --- a/src/keys/drivers/YubiKey.h +++ b/src/keys/drivers/YubiKey.h @@ -20,9 +20,15 @@ #define KEEPASSX_YUBIKEY_H #include -#include #include #include + +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) +#include +#else +#include +#endif + #include typedef QPair YubiKeySlot; @@ -85,7 +91,12 @@ class YubiKey : public QObject QTimer m_interactionTimer; bool m_initialized = false; QString m_error; - QMutex m_interfaces_detect_mutex; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + QRecursiveMutex m_interfaces_detect_mutex; +#else + QMutex m_interfaces_detect_mutex{QMutex::Recursive}; +#endif Q_DISABLE_COPY(YubiKey) }; diff --git a/src/keys/drivers/YubiKeyInterface.cpp b/src/keys/drivers/YubiKeyInterface.cpp index fe7f984b7c..07f3554c32 100644 --- a/src/keys/drivers/YubiKeyInterface.cpp +++ b/src/keys/drivers/YubiKeyInterface.cpp @@ -19,7 +19,6 @@ #include "YubiKeyInterface.h" YubiKeyInterface::YubiKeyInterface() - : m_mutex(QMutex::Recursive) { m_interactionTimer.setSingleShot(true); m_interactionTimer.setInterval(300); diff --git a/src/keys/drivers/YubiKeyInterface.h b/src/keys/drivers/YubiKeyInterface.h index 6a72946169..198c9d440a 100644 --- a/src/keys/drivers/YubiKeyInterface.h +++ b/src/keys/drivers/YubiKeyInterface.h @@ -23,6 +23,12 @@ #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) +#include +#else +#include +#endif + /** * Abstract base class to manage the interfaces to hardware key(s) */ @@ -70,7 +76,12 @@ class YubiKeyInterface : public QObject QMultiMap> m_foundKeys; - QMutex m_mutex; +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + QRecursiveMutex m_mutex; +#else + QMutex m_mutex{QMutex::Recursive}; +#endif + QTimer m_interactionTimer; bool m_initialized = false; QString m_error; diff --git a/src/main.cpp b/src/main.cpp index 0faa2c06ba..a6c22dd713 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -102,7 +102,7 @@ int main(int argc, char** argv) if (parser.isSet(debugInfoOption)) { QTextStream out(stdout, QIODevice::WriteOnly); QString debugInfo = Tools::debugInfo().append("\n").append(Crypto::debugInfo()); - out << debugInfo << endl; + out << debugInfo << Qt::endl; return EXIT_SUCCESS; } @@ -198,7 +198,7 @@ int main(int argc, char** argv) // we always need consume a line of STDIN if --pw-stdin is set to clear out the // buffer for native messaging, even if the specified file does not exist QTextStream out(stdout, QIODevice::WriteOnly); - out << QObject::tr("Database password: ") << flush; + out << QObject::tr("Database password: ") << Qt::flush; password = Utils::getPassword(); } mainWindow.openDatabase(filename, password, parser.value(keyfileOption)); diff --git a/src/sshagent/OpenSSHKey.cpp b/src/sshagent/OpenSSHKey.cpp index cdcc257013..9f6fae7611 100644 --- a/src/sshagent/OpenSSHKey.cpp +++ b/src/sshagent/OpenSSHKey.cpp @@ -20,6 +20,7 @@ #include "ASN1Key.h" #include "BinaryStream.h" +#include "core/Global.h" #include "crypto/Random.h" #include "crypto/SymmetricCipher.h" @@ -226,7 +227,7 @@ void OpenSSHKey::clearPrivate() bool OpenSSHKey::extractPEM(const QByteArray& in, QByteArray& out) { QString pem = QString::fromLatin1(in); - QStringList rows = pem.split(QRegularExpression("(?:\r?\n|\r)"), QString::SkipEmptyParts); + QStringList rows = pem.split(QRegularExpression("(?:\r?\n|\r)"), Qt::SkipEmptyParts); if (rows.length() < 3) { m_error = tr("Invalid key file, expecting an OpenSSH key"); diff --git a/src/sshagent/OpenSSHKeyGenDialog.ui b/src/sshagent/OpenSSHKeyGenDialog.ui index 0ab2c17163..1f9e483dd7 100644 --- a/src/sshagent/OpenSSHKeyGenDialog.ui +++ b/src/sshagent/OpenSSHKeyGenDialog.ui @@ -78,7 +78,7 @@ - QComboBox::AdjustToMinimumContentsLength + QComboBox::AdjustToContents 4 diff --git a/tests/TestSSHAgent.cpp b/tests/TestSSHAgent.cpp index 092cbb411b..5bb198cdb4 100644 --- a/tests/TestSSHAgent.cpp +++ b/tests/TestSSHAgent.cpp @@ -57,7 +57,7 @@ void TestSSHAgent::initTestCase() QSKIP("ssh-agent could not be started"); } - qDebug() << "ssh-agent started as pid" << m_agentProcess.pid(); + qDebug() << "ssh-agent started as pid" << m_agentProcess.processId(); // we need to wait for the agent to open the socket before going into real tests QFileInfo socketFileInfo(m_agentSocketFileName); @@ -288,7 +288,7 @@ void TestSSHAgent::testKeyGenEd25519() void TestSSHAgent::cleanupTestCase() { if (m_agentProcess.state() != QProcess::NotRunning) { - qDebug() << "Killing ssh-agent pid" << m_agentProcess.pid(); + qDebug() << "Killing ssh-agent pid" << m_agentProcess.processId(); m_agentProcess.terminate(); m_agentProcess.waitForFinished(); } diff --git a/tests/gui/TestGui.h b/tests/gui/TestGui.h index c631e5bdc8..60d2c3e09c 100644 --- a/tests/gui/TestGui.h +++ b/tests/gui/TestGui.h @@ -82,7 +82,7 @@ private slots: void clickIndex(const QModelIndex& index, QAbstractItemView* view, Qt::MouseButton button, - Qt::KeyboardModifiers stateKey = 0); + Qt::KeyboardModifiers stateKey = {}); void checkSaveDatabase(); void checkStatusBarText(const QString& textFragment); diff --git a/tests/gui/TestGuiBrowser.h b/tests/gui/TestGuiBrowser.h index d34a97f011..4d88a3a756 100644 --- a/tests/gui/TestGuiBrowser.h +++ b/tests/gui/TestGuiBrowser.h @@ -46,7 +46,7 @@ private slots: void clickIndex(const QModelIndex& index, QAbstractItemView* view, Qt::MouseButton button, - Qt::KeyboardModifiers stateKey = 0); + Qt::KeyboardModifiers stateKey = {}); QScopedPointer m_mainWindow; QPointer m_tabWidget; diff --git a/tests/gui/TestGuiFdoSecrets.cpp b/tests/gui/TestGuiFdoSecrets.cpp index be5f44e4e3..4abf515dbd 100644 --- a/tests/gui/TestGuiFdoSecrets.cpp +++ b/tests/gui/TestGuiFdoSecrets.cpp @@ -26,6 +26,7 @@ #include "config-keepassx-tests.h" +#include "core/Global.h" #include "core/Tools.h" #include "crypto/Crypto.h" #include "gui/Application.h" @@ -1248,7 +1249,7 @@ void TestGuiFdoSecrets::testItemReplace() { DBUS_GET2(unlocked, locked, service->SearchItems({{"application", "fdosecrets-test"}})); QSet expected{QDBusObjectPath(item1->path()), QDBusObjectPath(item2->path())}; - COMPARE(QSet::fromList(unlocked), expected); + COMPARE(Tools::asSet(unlocked), expected); } QSignalSpy spyItemCreated(coll.data(), SIGNAL(ItemCreated(QDBusObjectPath))); @@ -1265,7 +1266,7 @@ void TestGuiFdoSecrets::testItemReplace() // there are still 2 entries DBUS_GET2(unlocked, locked, service->SearchItems({{"application", "fdosecrets-test"}})); QSet expected{QDBusObjectPath(item1->path()), QDBusObjectPath(item2->path())}; - COMPARE(QSet::fromList(unlocked), expected); + COMPARE(Tools::asSet(unlocked), expected); VERIFY(waitForSignal(spyItemCreated, 0)); // there may be multiple changed signals, due to each item attribute is set separately @@ -1291,7 +1292,7 @@ void TestGuiFdoSecrets::testItemReplace() QDBusObjectPath(item2->path()), QDBusObjectPath(item4->path()), }; - COMPARE(QSet::fromList(unlocked), expected); + COMPARE(Tools::asSet(unlocked), expected); VERIFY(waitForSignal(spyItemCreated, 1)); { @@ -1619,7 +1620,7 @@ void TestGuiFdoSecrets::testExposeSubgroup() for (const auto& itemPath : itemPaths) { exposedEntries << m_plugin->dbus()->pathToObject(itemPath)->backend(); } - COMPARE(exposedEntries, QSet::fromList(subgroup->entries())); + COMPARE(exposedEntries, Tools::asSet(subgroup->entries())); } void TestGuiFdoSecrets::testModifyingExposedGroup() diff --git a/tests/modeltest.cpp b/tests/modeltest.cpp index 8f7c95484f..abbe546fa6 100644 --- a/tests/modeltest.cpp +++ b/tests/modeltest.cpp @@ -452,12 +452,12 @@ void ModelTest::data() } // General Purpose roles that should return a QColor - QVariant colorVariant = model->data ( model->index ( 0, 0 ), Qt::BackgroundColorRole ); + QVariant colorVariant = model->data ( model->index ( 0, 0 ), Qt::BackgroundRole ); if ( colorVariant.isValid() ) { QVERIFY( colorVariant.canConvert() ); } - colorVariant = model->data ( model->index ( 0, 0 ), Qt::TextColorRole ); + colorVariant = model->data ( model->index ( 0, 0 ), Qt::ForegroundRole ); if ( colorVariant.isValid() ) { QVERIFY( colorVariant.canConvert() ); }