From e34bf40965fe6d5f02752e4f339c82dab8e4aacf Mon Sep 17 00:00:00 2001 From: Carlo Teubner Date: Sun, 3 Apr 2022 14:38:04 +0100 Subject: [PATCH] endl -> Qt::endl, flush -> Qt::flush Qt 5.15 deprecates usage of non-'Qt::'-prefixed 'endl' and 'flush' I/O manipulators; but the 'Qt::' versions are only introduced in Qt 5.14. Since we wish to maintain backwards compatibility to Qt 5.9.5, we invoke some preprocessor magic. --- src/cli/Add.cpp | 10 +++---- src/cli/AddGroup.cpp | 8 ++--- src/cli/Analyze.cpp | 14 ++++----- src/cli/AttachmentExport.cpp | 12 ++++---- src/cli/AttachmentImport.cpp | 10 +++---- src/cli/AttachmentRemove.cpp | 8 ++--- src/cli/Clip.cpp | 24 +++++++-------- src/cli/Create.cpp | 22 +++++++------- src/cli/Diceware.cpp | 6 ++-- src/cli/Edit.cpp | 12 ++++---- src/cli/Estimate.cpp | 8 ++--- src/cli/Export.cpp | 4 +-- src/cli/Generate.cpp | 6 ++-- src/cli/Import.cpp | 8 ++--- src/cli/Info.cpp | 42 +++++++++++++-------------- src/cli/List.cpp | 6 ++-- src/cli/Merge.cpp | 8 ++--- src/cli/Move.cpp | 10 +++---- src/cli/Remove.cpp | 8 ++--- src/cli/RemoveGroup.cpp | 10 +++---- src/cli/Search.cpp | 4 +-- src/cli/Show.cpp | 22 +++++++------- src/cli/Utils.cpp | 30 +++++++++---------- src/cli/Utils.h | 2 ++ src/cli/keepassxc-cli.cpp | 8 ++--- src/core/Global.h | 4 +++ src/gui/osutils/nixutils/NixUtils.cpp | 4 ++- src/main.cpp | 4 +-- 28 files changed, 161 insertions(+), 153 deletions(-) diff --git a/src/cli/Add.cpp b/src/cli/Add.cpp index 3bd9241d1e..83ea7e52c8 100644 --- a/src/cli/Add.cpp +++ b/src/cli/Add.cpp @@ -78,7 +78,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 +94,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 +112,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 +123,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 43431e8dc0..b0c129e577 100644 --- a/src/cli/AddGroup.cpp +++ b/src/cli/AddGroup.cpp @@ -47,13 +47,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; } @@ -64,12 +64,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..52b2b95460 100644 --- a/src/cli/Analyze.cpp +++ b/src/cli/Analyze.cpp @@ -60,23 +60,23 @@ 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 +91,9 @@ 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..673ffbb0a5 100644 --- a/src/cli/AttachmentExport.cpp +++ b/src/cli/AttachmentExport.cpp @@ -49,7 +49,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 +57,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..eb24d4f7d2 100644 --- a/src/cli/AttachmentImport.cpp +++ b/src/cli/AttachmentImport.cpp @@ -50,7 +50,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 +58,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 +66,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 +76,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..a0467d0a1c 100644 --- a/src/cli/AttachmentRemove.cpp +++ b/src/cli/AttachmentRemove.cpp @@ -41,7 +41,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 +49,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 +59,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 7c4a9bb1f6..b1bbed2183 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; } @@ -123,7 +123,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; @@ -133,7 +133,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; } @@ -142,7 +142,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; @@ -152,13 +152,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/Create.cpp b/src/cli/Create.cpp index 760bf53682..fb9a07d2c8 100644 --- a/src/cli/Create.cpp +++ b/src/cli/Create.cpp @@ -65,13 +65,13 @@ QSharedPointer Create::initializeDatabaseFromOptions(const QSharedPoin 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 {}; } } @@ -81,7 +81,7 @@ QSharedPointer Create::initializeDatabaseFromOptions(const QSharedPoin if (parser->isSet(Create::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); @@ -91,7 +91,7 @@ QSharedPointer Create::initializeDatabaseFromOptions(const QSharedPoin QSharedPointer fileKey; if (!Utils::loadFileKey(parser->value(Create::SetKeyFileOption), fileKey)) { - err << QObject::tr("Loading the key file failed") << endl; + err << QObject::tr("Loading the key file failed") << Qt_endl; return {}; } @@ -101,7 +101,7 @@ QSharedPointer Create::initializeDatabaseFromOptions(const QSharedPoin } 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 {}; } @@ -112,15 +112,15 @@ QSharedPointer Create::initializeDatabaseFromOptions(const QSharedPoin 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 {}; } } @@ -155,7 +155,7 @@ int Create::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; } @@ -166,10 +166,10 @@ int Create::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/Diceware.cpp b/src/cli/Diceware.cpp index b6a65bd1e7..20a8213162 100644 --- a/src/cli/Diceware.cpp +++ b/src/cli/Diceware.cpp @@ -58,7 +58,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 +72,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..fcb5efee03 100644 --- a/src/cli/Edit.cpp +++ b/src/cli/Edit.cpp @@ -66,7 +66,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 +83,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 +93,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 +116,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 +128,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 094fcf36cd..08001cae64 100644 --- a/src/cli/Estimate.cpp +++ b/src/cli/Estimate.cpp @@ -47,7 +47,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 +62,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 +135,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..63e9b0335a 100644 --- a/src/cli/Export.cpp +++ b/src/cli/Export.cpp @@ -46,7 +46,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 +54,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 a3382710d0..d03fee2357 100644 --- a/src/cli/Generate.cpp +++ b/src/cli/Generate.cpp @@ -92,7 +92,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 QSharedPointer(nullptr); } else { passwordGenerator->setLength(passwordLength.toInt()); @@ -138,7 +138,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 QSharedPointer(nullptr); } @@ -159,7 +159,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 3732f0cf69..cd4efac65d 100644 --- a/src/cli/Import.cpp +++ b/src/cli/Import.cpp @@ -60,7 +60,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; } @@ -71,15 +71,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/Info.cpp b/src/cli/Info.cpp index b44b392e15..4efe4ac609 100644 --- a/src/cli/Info.cpp +++ b/src/cli/Info.cpp @@ -36,39 +36,39 @@ int Info::executeWithDatabase(QSharedPointer database, QSharedPointer< { 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.first == database->cipher()) { - out << QObject::tr("Cipher: ") << cipher.second << endl; + out << QObject::tr("Cipher: ") << cipher.second << 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("Location") << ": " << database->filePath() << Qt_endl; out << QObject::tr("Database created") << ": " - << Tools::toString(database->rootGroup()->timeInfo().creationTime()) << endl; - out << QObject::tr("Last saved") << ": " << Tools::toString(stats.modified) << endl; + << Tools::toString(database->rootGroup()->timeInfo().creationTime()) << Qt_endl; + out << QObject::tr("Last saved") << ": " << Tools::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/List.cpp b/src/cli/List.cpp index 4140c1cd80..a772007c02 100644 --- a/src/cli/List.cpp +++ b/src/cli/List.cpp @@ -52,17 +52,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..ebf096f723 100644 --- a/src/cli/Merge.cpp +++ b/src/cli/Merge.cpp @@ -90,18 +90,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 a9ee78614d..816bc3ba77 100644 --- a/src/cli/Move.cpp +++ b/src/cli/Move.cpp @@ -45,18 +45,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; } @@ -66,10 +66,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..e9485a4ba7 100644 --- a/src/cli/Remove.cpp +++ b/src/cli/Remove.cpp @@ -38,7 +38,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 +54,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 6455af4966..1394d4e63b 100644 --- a/src/cli/RemoveGroup.cpp +++ b/src/cli/RemoveGroup.cpp @@ -44,12 +44,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; } @@ -64,14 +64,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..6f78bab910 100644 --- a/src/cli/Search.cpp +++ b/src/cli/Search.cpp @@ -40,12 +40,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 f4d8097f66..f616a20a83 100644 --- a/src/cli/Show.cpp +++ b/src/cli/Show.cpp @@ -68,12 +68,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; } @@ -89,13 +89,13 @@ int Show::executeWithDatabase(QSharedPointer database, QSharedPointer< 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]; @@ -103,33 +103,33 @@ int Show::executeWithDatabase(QSharedPointer database, QSharedPointer< out << canonicalName << ": "; } if (entry->attributes()->isProtected(canonicalName) && showDefaultAttributes && !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 8eb0a04efd..321ec31a06 100644 --- a/src/cli/Utils.cpp +++ b/src/cli/Utils.cpp @@ -103,22 +103,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); @@ -130,7 +130,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 {}; } @@ -138,7 +138,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 @@ -155,20 +155,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})); @@ -185,7 +185,7 @@ namespace Utils if (db->open(databaseFilename, compositeKey, &error)) { return db; } else { - err << error << endl; + err << error << Qt_endl; return {}; } } @@ -210,7 +210,7 @@ namespace Utils setStdinEcho(false); QString line = in.readLine(); setStdinEcho(true); - out << endl; + out << Qt_endl; return line; #endif // __AFL_COMPILER @@ -240,7 +240,7 @@ namespace Utils if (ans.toLower().startsWith("y")) { passwordKey = QSharedPointer::create(""); } - err << endl; + err << Qt_endl; } else { err << QObject::tr("Repeat password: "); err.flush(); @@ -249,7 +249,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; } } @@ -406,13 +406,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/Utils.h b/src/cli/Utils.h index dedc818f66..8895c96b26 100644 --- a/src/cli/Utils.h +++ b/src/cli/Utils.h @@ -18,6 +18,8 @@ #ifndef KEEPASSXC_UTILS_H #define KEEPASSXC_UTILS_H +#include "core/Global.h" + #include class CompositeKey; diff --git a/src/cli/keepassxc-cli.cpp b/src/cli/keepassxc-cli.cpp index 120c706472..80aaa886d7 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/Global.h b/src/core/Global.h index 4b6598d1b1..ab2b022c8e 100644 --- a/src/core/Global.h +++ b/src/core/Global.h @@ -43,8 +43,12 @@ #endif #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) +#define Qt_endl Qt::endl +#define Qt_flush Qt::flush #define Qt_SkipEmptyParts Qt::SkipEmptyParts #else +#define Qt_endl endl +#define Qt_flush flush #define Qt_SkipEmptyParts QString::SkipEmptyParts #endif diff --git a/src/gui/osutils/nixutils/NixUtils.cpp b/src/gui/osutils/nixutils/NixUtils.cpp index d0fa84f3c7..c69cb919fb 100644 --- a/src/gui/osutils/nixutils/NixUtils.cpp +++ b/src/gui/osutils/nixutils/NixUtils.cpp @@ -17,6 +17,8 @@ #include "NixUtils.h" +#include "core/Global.h" + #include #include #include @@ -148,7 +150,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/main.cpp b/src/main.cpp index 24d891a06d..a454a245e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -100,7 +100,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; } @@ -175,7 +175,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(); }