Skip to content

Commit

Permalink
endl -> Qt::endl, flush -> Qt::flush
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
c4rlo committed Apr 3, 2022
1 parent 59ef5fe commit e34bf40
Show file tree
Hide file tree
Showing 28 changed files with 161 additions and 153 deletions.
10 changes: 5 additions & 5 deletions src/cli/Add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int Add::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<Q

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

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

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

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

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

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

if (!parser->isSet(Command::QuietOption)) {
out << QObject::tr("Successfully added entry %1.").arg(entry->title()) << endl;
out << QObject::tr("Successfully added entry %1.").arg(entry->title()) << Qt_endl;
}
return EXIT_SUCCESS;
}
8 changes: 4 additions & 4 deletions src/cli/AddGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ int AddGroup::executeWithDatabase(QSharedPointer<Database> database, QSharedPoin

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

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

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

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

if (!parser->isSet(Command::QuietOption)) {
out << QObject::tr("Successfully added group %1.").arg(groupName) << endl;
out << QObject::tr("Successfully added group %1.").arg(groupName) << Qt_endl;
}
return EXIT_SUCCESS;
}
14 changes: 7 additions & 7 deletions src/cli/Analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ int Analyze::executeWithDatabase(QSharedPointer<Database> database, QSharedPoint

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

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

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

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

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

Expand Down
12 changes: 6 additions & 6 deletions src/cli/AttachmentExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,40 +49,40 @@ int AttachmentExport::executeWithDatabase(QSharedPointer<Database> database, QSh

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

auto attachmentName = args.at(2);

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

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

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

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

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

return EXIT_SUCCESS;
}
10 changes: 5 additions & 5 deletions src/cli/AttachmentImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ int AttachmentImport::executeWithDatabase(QSharedPointer<Database> database, QSh

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

auto attachmentName = args.at(2);

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

auto importFileName = args.at(3);

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

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

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

out << QObject::tr("Successfully imported attachment %1 as %2 to entry %3.")
.arg(importFileName, attachmentName, entryPath)
<< endl;
<< Qt_endl;
return EXIT_SUCCESS;
}
8 changes: 4 additions & 4 deletions src/cli/AttachmentRemove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ int AttachmentRemove::executeWithDatabase(QSharedPointer<Database> database, QSh

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

auto attachmentName = args.at(2);

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

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

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

out << QObject::tr("Successfully removed attachment %1 from entry %2.").arg(attachmentName, entryPath) << endl;
out << QObject::tr("Successfully removed attachment %1 from entry %2.").arg(attachmentName, entryPath) << Qt_endl;
return EXIT_SUCCESS;
}
24 changes: 12 additions & 12 deletions src/cli/Clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int Clip::executeWithDatabase(QSharedPointer<Database> 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;
}
}
Expand All @@ -83,27 +83,27 @@ int Clip::executeWithDatabase(QSharedPointer<Database> 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);
}

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;
}

Expand All @@ -112,7 +112,7 @@ int Clip::executeWithDatabase(QSharedPointer<Database> 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;
}

Expand All @@ -123,7 +123,7 @@ int Clip::executeWithDatabase(QSharedPointer<Database> 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;
Expand All @@ -133,7 +133,7 @@ int Clip::executeWithDatabase(QSharedPointer<Database> 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;
}

Expand All @@ -142,7 +142,7 @@ int Clip::executeWithDatabase(QSharedPointer<Database> 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;
Expand All @@ -152,13 +152,13 @@ int Clip::executeWithDatabase(QSharedPointer<Database> 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;
}
Loading

0 comments on commit e34bf40

Please sign in to comment.