Restore correct formatting

Many lines were not conformant with the project's formatting rules.
This patch should fix all formatting and whitespace issues in the code
base.
A clang-format directive was put around the connect() calls containing
SIGNALs and SLOTs whose signatures would be denormalized because of the
formatting rules.
This commit is contained in:
Gianluca Recchia 2018-11-01 04:27:38 +01:00 committed by Jonathan White
parent f9625189cb
commit fc930bae69
No known key found for this signature in database
GPG key ID: 440FC65F2E0C6E01
186 changed files with 2437 additions and 2122 deletions

View file

@ -51,7 +51,8 @@ int Add::execute(const QStringList& arguments)
parser.addOption(Command::QuietOption);
parser.addOption(Command::KeyFileOption);
QCommandLineOption username(QStringList() << "u" << "username",
QCommandLineOption username(QStringList() << "u"
<< "username",
QObject::tr("Username for the entry."),
QObject::tr("username"));
parser.addOption(username);
@ -59,15 +60,18 @@ int Add::execute(const QStringList& arguments)
QCommandLineOption url(QStringList() << "url", QObject::tr("URL for the entry."), QObject::tr("URL"));
parser.addOption(url);
QCommandLineOption prompt(QStringList() << "p" << "password-prompt",
QCommandLineOption prompt(QStringList() << "p"
<< "password-prompt",
QObject::tr("Prompt for the entry's password."));
parser.addOption(prompt);
QCommandLineOption generate(QStringList() << "g" << "generate",
QCommandLineOption generate(QStringList() << "g"
<< "generate",
QObject::tr("Generate a password for the entry."));
parser.addOption(generate);
QCommandLineOption length(QStringList() << "l" << "password-length",
QCommandLineOption length(QStringList() << "l"
<< "password-length",
QObject::tr("Length for the generated password."),
QObject::tr("length"));
parser.addOption(length);

View file

@ -50,12 +50,13 @@ int Clip::execute(const QStringList& arguments)
parser.addOption(Command::QuietOption);
parser.addOption(Command::KeyFileOption);
QCommandLineOption totp(QStringList() << "t" << "totp",
QCommandLineOption totp(QStringList() << "t"
<< "totp",
QObject::tr("Copy the current TOTP to the clipboard."));
parser.addOption(totp);
parser.addPositionalArgument("entry", QObject::tr("Path of the entry to clip.", "clip = copy to clipboard"));
parser.addPositionalArgument("timeout",
QObject::tr("Timeout in seconds before clearing the clipboard."), "[timeout]");
parser.addPositionalArgument(
"timeout", QObject::tr("Timeout in seconds before clearing the clipboard."), "[timeout]");
parser.addHelpOption();
parser.process(arguments);

View file

@ -43,11 +43,13 @@ int Diceware::execute(const QStringList& arguments)
QCommandLineParser parser;
parser.setApplicationDescription(description);
QCommandLineOption words(QStringList() << "W" << "words",
QCommandLineOption words(QStringList() << "W"
<< "words",
QObject::tr("Word count for the diceware passphrase."),
QObject::tr("count", "CLI parameter"));
parser.addOption(words);
QCommandLineOption wordlistFile(QStringList() << "w" << "word-list",
QCommandLineOption wordlistFile(QStringList() << "w"
<< "word-list",
QObject::tr("Wordlist for the diceware generator.\n[Default: EFF English]"),
QObject::tr("path"));
parser.addOption(wordlistFile);

View file

@ -51,7 +51,8 @@ int Edit::execute(const QStringList& arguments)
parser.addOption(Command::QuietOption);
parser.addOption(Command::KeyFileOption);
QCommandLineOption username(QStringList() << "u" << "username",
QCommandLineOption username(QStringList() << "u"
<< "username",
QObject::tr("Username for the entry."),
QObject::tr("username"));
parser.addOption(username);
@ -59,20 +60,24 @@ int Edit::execute(const QStringList& arguments)
QCommandLineOption url(QStringList() << "url", QObject::tr("URL for the entry."), QObject::tr("URL"));
parser.addOption(url);
QCommandLineOption title(QStringList() << "t" << "title",
QCommandLineOption title(QStringList() << "t"
<< "title",
QObject::tr("Title for the entry."),
QObject::tr("title"));
parser.addOption(title);
QCommandLineOption prompt(QStringList() << "p" << "password-prompt",
QCommandLineOption prompt(QStringList() << "p"
<< "password-prompt",
QObject::tr("Prompt for the entry's password."));
parser.addOption(prompt);
QCommandLineOption generate(QStringList() << "g" << "generate",
QCommandLineOption generate(QStringList() << "g"
<< "generate",
QObject::tr("Generate a password for the entry."));
parser.addOption(generate);
QCommandLineOption length(QStringList() << "l" << "password-length",
QCommandLineOption length(QStringList() << "l"
<< "password-length",
QObject::tr("Length for the generated password."),
QObject::tr("length"));
parser.addOption(length);
@ -111,8 +116,7 @@ int Edit::execute(const QStringList& arguments)
}
if (parser.value("username").isEmpty() && parser.value("url").isEmpty() && parser.value("title").isEmpty()
&& !parser.isSet(prompt)
&& !parser.isSet(generate)) {
&& !parser.isSet(prompt) && !parser.isSet(generate)) {
err << QObject::tr("Not changing any field for entry %1.").arg(entryPath) << endl;
return EXIT_FAILURE;
}

View file

@ -51,9 +51,11 @@ static void estimate(const char* pwd, bool advanced)
int len = static_cast<int>(strlen(pwd));
if (!advanced) {
e = ZxcvbnMatch(pwd, nullptr, nullptr);
// 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;
// clang-format on
} else {
int ChkLen = 0;
ZxcMatch_t *info, *p;
@ -63,10 +65,12 @@ static void estimate(const char* pwd, bool advanced)
m += p->Entrpy;
}
m = e - m;
// clang-format off
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;
// clang-format on
p = info;
ChkLen = 0;
while (p) {
@ -132,9 +136,10 @@ static void estimate(const char* pwd, bool advanced)
break;
}
ChkLen += p->Length;
// clang-format off
out << QObject::tr("Length %1").arg(p->Length) << '\t'
<< QObject::tr("Entropy %1 (%2)").arg(p->Entrpy, 6, 'f', 3).arg(p->Entrpy * 0.301029996, 0, 'f', 2) << '\t';
// clang-format on
for (n = 0; n < p->Length; ++n, ++pwd) {
out << *pwd;
}
@ -143,7 +148,8 @@ static void estimate(const char* pwd, bool advanced)
}
ZxcvbnFreeInfo(info);
if (ChkLen != len) {
out << QObject::tr("*** Password length (%1) != sum of length of parts (%2) ***").arg(len).arg(ChkLen) << endl;
out << QObject::tr("*** Password length (%1) != sum of length of parts (%2) ***").arg(len).arg(ChkLen)
<< endl;
}
}
}
@ -156,7 +162,8 @@ int Estimate::execute(const QStringList& arguments)
QCommandLineParser parser;
parser.setApplicationDescription(description);
parser.addPositionalArgument("password", QObject::tr("Password for which to estimate the entropy."), "[password]");
QCommandLineOption advancedOption(QStringList() << "a" << "advanced",
QCommandLineOption advancedOption(QStringList() << "a"
<< "advanced",
QObject::tr("Perform advanced analysis on the password."));
parser.addOption(advancedOption);
parser.addHelpOption();

View file

@ -84,7 +84,8 @@ int Extract::execute(const QStringList& arguments)
if (fileKey->type() != FileKey::Hashed) {
err << QObject::tr("WARNING: You are using a legacy key file format which may become\n"
"unsupported in the future.\n\n"
"Please consider generating a new key file.") << endl;
"Please consider generating a new key file.")
<< endl;
}
// LCOV_EXCL_STOP

View file

@ -43,26 +43,33 @@ int Generate::execute(const QStringList& arguments)
QCommandLineParser parser;
parser.setApplicationDescription(description);
QCommandLineOption len(QStringList() << "L" << "length",
QCommandLineOption len(QStringList() << "L"
<< "length",
QObject::tr("Length of the generated password"),
QObject::tr("length"));
parser.addOption(len);
QCommandLineOption lower(QStringList() << "l" << "lower",
QCommandLineOption lower(QStringList() << "l"
<< "lower",
QObject::tr("Use lowercase characters"));
parser.addOption(lower);
QCommandLineOption upper(QStringList() << "u" << "upper",
QCommandLineOption upper(QStringList() << "u"
<< "upper",
QObject::tr("Use uppercase characters"));
parser.addOption(upper);
QCommandLineOption numeric(QStringList() << "n" << "numeric",
QCommandLineOption numeric(QStringList() << "n"
<< "numeric",
QObject::tr("Use numbers."));
parser.addOption(numeric);
QCommandLineOption special(QStringList() << "s" << "special",
QCommandLineOption special(QStringList() << "s"
<< "special",
QObject::tr("Use special characters"));
parser.addOption(special);
QCommandLineOption extended(QStringList() << "e" << "extended",
QCommandLineOption extended(QStringList() << "e"
<< "extended",
QObject::tr("Use extended ASCII"));
parser.addOption(extended);
QCommandLineOption exclude(QStringList() << "x" << "exclude",
QCommandLineOption exclude(QStringList() << "x"
<< "exclude",
QObject::tr("Exclude character set"),
QObject::tr("chars"));
parser.addOption(exclude);

View file

@ -49,7 +49,8 @@ int List::execute(const QStringList& arguments)
parser.addOption(Command::QuietOption);
parser.addOption(Command::KeyFileOption);
QCommandLineOption recursiveOption(QStringList() << "R" << "recursive",
QCommandLineOption recursiveOption(QStringList() << "R"
<< "recursive",
QObject::tr("Recursively list the elements of the group."));
parser.addOption(recursiveOption);
parser.addHelpOption();

View file

@ -47,12 +47,14 @@ int Merge::execute(const QStringList& arguments)
parser.addPositionalArgument("database2", QObject::tr("Path of the database to merge from."));
parser.addOption(Command::QuietOption);
QCommandLineOption samePasswordOption(QStringList() << "s" << "same-credentials",
QCommandLineOption samePasswordOption(QStringList() << "s"
<< "same-credentials",
QObject::tr("Use the same credentials for both database files."));
parser.addOption(samePasswordOption);
parser.addOption(Command::KeyFileOption);
QCommandLineOption keyFileFromOption(QStringList() << "f" << "key-file-from",
QCommandLineOption keyFileFromOption(QStringList() << "f"
<< "key-file-from",
QObject::tr("Key file of the database to merge from."),
QObject::tr("path"));
parser.addOption(keyFileFromOption);

View file

@ -48,11 +48,13 @@ int Show::execute(const QStringList& arguments)
parser.addPositionalArgument("database", QObject::tr("Path of the database."));
parser.addOption(Command::QuietOption);
parser.addOption(Command::KeyFileOption);
QCommandLineOption totp(QStringList() << "t" << "totp",
QCommandLineOption totp(QStringList() << "t"
<< "totp",
QObject::tr("Show the entry's current TOTP."));
parser.addOption(totp);
QCommandLineOption attributes(
QStringList() << "a" << "attributes",
QStringList() << "a"
<< "attributes",
QObject::tr(
"Names of the attributes to show. "
"This option can be specified more than once, with each attribute shown one-per-line in the given order. "

View file

@ -28,20 +28,20 @@
namespace Utils
{
/**
* STDOUT file handle for the CLI.
*/
FILE* STDOUT = stdout;
/**
* STDOUT file handle for the CLI.
*/
FILE* STDOUT = stdout;
/**
* STDERR file handle for the CLI.
*/
FILE* STDERR = stderr;
/**
* STDERR file handle for the CLI.
*/
FILE* STDERR = stderr;
/**
* STDIN file handle for the CLI.
*/
FILE* STDIN = stdin;
/**
* STDIN file handle for the CLI.
*/
FILE* STDIN = stdin;
/**
* DEVNULL file handle for the CLI.
@ -56,48 +56,47 @@ FILE* DEVNULL = fopen("/dev/null", "w");
void setStdinEcho(bool enable = true)
{
#ifdef Q_OS_WIN
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(hIn, &mode);
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(hIn, &mode);
if (enable) {
mode |= ENABLE_ECHO_INPUT;
} else {
mode &= ~ENABLE_ECHO_INPUT;
}
SetConsoleMode(hIn, mode);
if (enable) {
mode |= ENABLE_ECHO_INPUT;
} else {
mode &= ~ENABLE_ECHO_INPUT;
}
SetConsoleMode(hIn, mode);
#else
struct termios t;
tcgetattr(STDIN_FILENO, &t);
struct termios t;
tcgetattr(STDIN_FILENO, &t);
if (enable) {
t.c_lflag |= ECHO;
} else {
t.c_lflag &= ~ECHO;
if (enable) {
t.c_lflag |= ECHO;
} else {
t.c_lflag &= ~ECHO;
}
tcsetattr(STDIN_FILENO, TCSANOW, &t);
#endif
}
tcsetattr(STDIN_FILENO, TCSANOW, &t);
#endif
}
namespace Test
{
QStringList nextPasswords = {};
namespace Test
{
QStringList nextPasswords = {};
/**
* Set the next password returned by \link getPassword() instead of reading it from STDIN.
* Multiple calls to this method will fill a queue of passwords.
* This function is intended for testing purposes.
*
* @param password password to return next
*/
void setNextPassword(const QString& password)
{
nextPasswords.append(password);
}
} // namespace Test
/**
* Set the next password returned by \link getPassword() instead of reading it from STDIN.
* Multiple calls to this method will fill a queue of passwords.
* This function is intended for testing purposes.
*
* @param password password to return next
*/
void setNextPassword(const QString& password)
{
nextPasswords.append(password);
}
} // namespace Test
/**
* Read a user password from STDIN or return a password previously
@ -109,74 +108,74 @@ QString getPassword(FILE* outputDescriptor)
{
TextStream out(outputDescriptor, QIODevice::WriteOnly);
// return preset password if one is set
if (!Test::nextPasswords.isEmpty()) {
auto password = Test::nextPasswords.takeFirst();
// simulate user entering newline
// return preset password if one is set
if (!Test::nextPasswords.isEmpty()) {
auto password = Test::nextPasswords.takeFirst();
// simulate user entering newline
out << endl;
return password;
}
TextStream in(STDIN, QIODevice::ReadOnly);
setStdinEcho(false);
QString line = in.readLine();
setStdinEcho(true);
out << endl;
return password;
return line;
}
TextStream in(STDIN, QIODevice::ReadOnly);
/**
* A valid and running event loop is needed to use the global QClipboard,
* so we need to use this from the CLI.
*/
int clipText(const QString& text)
{
TextStream err(Utils::STDERR);
setStdinEcho(false);
QString line = in.readLine();
setStdinEcho(true);
out << endl;
return line;
}
/**
* A valid and running event loop is needed to use the global QClipboard,
* so we need to use this from the CLI.
*/
int clipText(const QString& text)
{
TextStream err(Utils::STDERR);
QString programName = "";
QStringList arguments;
QString programName = "";
QStringList arguments;
#ifdef Q_OS_UNIX
programName = "xclip";
arguments << "-i"
<< "-selection"
<< "clipboard";
programName = "xclip";
arguments << "-i"
<< "-selection"
<< "clipboard";
#endif
#ifdef Q_OS_MACOS
programName = "pbcopy";
programName = "pbcopy";
#endif
#ifdef Q_OS_WIN
programName = "clip";
programName = "clip";
#endif
if (programName.isEmpty()) {
err << QObject::tr("No program defined for clipboard manipulation");
err.flush();
return EXIT_FAILURE;
if (programName.isEmpty()) {
err << QObject::tr("No program defined for clipboard manipulation");
err.flush();
return EXIT_FAILURE;
}
auto* clipProcess = new QProcess(nullptr);
clipProcess->start(programName, arguments);
clipProcess->waitForStarted();
if (clipProcess->state() != QProcess::Running) {
err << QObject::tr("Unable to start program %1").arg(programName);
err.flush();
return EXIT_FAILURE;
}
if (clipProcess->write(text.toLatin1()) == -1) {
qDebug("Unable to write to process : %s", qPrintable(clipProcess->errorString()));
}
clipProcess->waitForBytesWritten();
clipProcess->closeWriteChannel();
clipProcess->waitForFinished();
return clipProcess->exitCode();
}
auto* clipProcess = new QProcess(nullptr);
clipProcess->start(programName, arguments);
clipProcess->waitForStarted();
if (clipProcess->state() != QProcess::Running) {
err << QObject::tr("Unable to start program %1").arg(programName);
err.flush();
return EXIT_FAILURE;
}
if (clipProcess->write(text.toLatin1()) == -1) {
qDebug("Unable to write to process : %s", qPrintable(clipProcess->errorString()));
}
clipProcess->waitForBytesWritten();
clipProcess->closeWriteChannel();
clipProcess->waitForFinished();
return clipProcess->exitCode();
}
} // namespace Utils
} // namespace Utils

View file

@ -18,24 +18,24 @@
#ifndef KEEPASSXC_UTILS_H
#define KEEPASSXC_UTILS_H
#include <QtCore/qglobal.h>
#include "cli/TextStream.h"
#include <QtCore/qglobal.h>
namespace Utils
{
extern FILE* STDOUT;
extern FILE* STDERR;
extern FILE* STDIN;
extern FILE* DEVNULL;
extern FILE* STDOUT;
extern FILE* STDERR;
extern FILE* STDIN;
extern FILE* DEVNULL;
void setStdinEcho(bool enable);
QString getPassword(FILE* outputDescriptor = STDOUT);
int clipText(const QString& text);
void setStdinEcho(bool enable);
QString getPassword(FILE* outputDescriptor = STDOUT);
int clipText(const QString& text);
namespace Test
{
void setNextPassword(const QString& password);
}
};
namespace Test
{
void setNextPassword(const QString& password);
}
}; // namespace Utils
#endif // KEEPASSXC_UTILS_H