Unverified Commit 1032e97b authored by Rolf Eike Beer's avatar Rolf Eike Beer
Browse files

fix many code quality warnings from CI

parent fb798790
Pipeline #118496 failed with stage
in 4 minutes and 14 seconds
......@@ -144,10 +144,8 @@ KGpgKeyNode::readChildren()
{
KgpgInterface::readSignatures(this);
m_signs = 0;
for (const KGpgNode *n : qAsConst(children))
if (n->getType() == ITYPE_SIGN)
m_signs++;
m_signs = std::count_if(children.cbegin(), children.cend(),
[](const KGpgNode *n) { return n->getType() == ITYPE_SIGN; });
}
QString
......
......@@ -64,8 +64,8 @@ KgpgKeySub::KgpgKeySub(const QString &id, const uint size, const KgpgKeyTrust tr
}
KgpgKeySub::KgpgKeySub(const KgpgKeySub &other)
: d(other.d)
{
d = other.d;
}
void KgpgKeySub::setExpiration(const QDateTime &date)
......@@ -195,8 +195,8 @@ KgpgKey::KgpgKey(const QString &id, const uint size, const KgpgKeyTrust trust, c
}
KgpgKey::KgpgKey(const KgpgKey &other)
: d(other.d)
{
d = other.d;
}
void KgpgKey::setSecret(const bool secret)
......@@ -363,9 +363,10 @@ KgpgKeyAlgo KgpgKey::algorithm() const
KgpgKeyAlgo KgpgKey::encryptionAlgorithm() const
{
// Get the first encryption subkey
for (const KgpgKeySub &k : qAsConst(*d->gpgsublist))
if (k.type() & SKT_ENCRYPTION)
return k.algorithm();
auto it = std::find_if(d->gpgsublist->cbegin(), d->gpgsublist->cend(),
[](const KgpgKeySub &k) { return k.type() & SKT_ENCRYPTION; });
if (it != d->gpgsublist->cend())
return it->algorithm();
return ALGO_UNKNOWN;
}
......
......@@ -656,22 +656,19 @@ void KgpgEditor::slotPreVerifyFile()
void KgpgEditor::slotVerifyFile(const QUrl &url)
{
if (!url.isEmpty())
{
QString sigfile;
if (!url.fileName().endsWith(QLatin1String(".sig")))
{
sigfile = url.path() + QLatin1String( ".sig" );
QFile fsig(sigfile);
if (!fsig.exists())
{
sigfile = url.path() + QLatin1String( ".asc" );
QFile fsig(sigfile);
// if no .asc or .sig signature file included, assume the file is internally signed
if (!fsig.exists())
sigfile.clear();
}
}
if (url.isEmpty())
return;
QString sigfile;
if (!url.fileName().endsWith(QLatin1String(".sig"))) {
sigfile = url.path() + QLatin1String( ".sig" );
if (!QFile::exists(sigfile)) {
sigfile = url.path() + QLatin1String( ".asc" );
// if no .asc or .sig signature file included, assume the file is internally signed
if (!QFile::exists(sigfile))
sigfile.clear();
}
}
QList<QUrl> chkfiles;
if (sigfile.isEmpty())
......@@ -682,7 +679,6 @@ void KgpgEditor::slotVerifyFile(const QUrl &url)
KGpgVerify *verify = new KGpgVerify(this, chkfiles);
connect(verify, &KGpgVerify::done, m_editor, &KgpgTextEdit::slotVerifyDone);
verify->start();
}
}
void KgpgEditor::slotCheckMd5()
......
......@@ -2416,21 +2416,14 @@ void KeysManager::confirmdeletekey()
slotDelUid();
return;
} else if ((pt & ITYPE_GROUP) && !(pt & ~ITYPE_GPAIR)) {
bool invalidDelete = false;
for (const KGpgNode *nd : ndlist)
if (nd->getType() == ITYPE_GROUP) {
invalidDelete = true;
break;
}
bool invalidDelete = std::any_of(ndlist.cbegin(), ndlist.cend(),
[](const KGpgNode *nd) { return nd->getType() == ITYPE_GROUP; });
// only allow removing group members if they belong to the same group
if (!invalidDelete) {
const KGpgNode * const group = ndlist.front()->getParentKeyNode();
for (const KGpgNode *nd : ndlist)
if (nd->getParentKeyNode() != group) {
invalidDelete = true;
break;
}
invalidDelete = std::any_of(ndlist.cbegin(), ndlist.cend(),
[group] (const KGpgNode *nd) { return nd->getParentKeyNode() != group; });
}
if (!invalidDelete) {
......
......@@ -240,18 +240,15 @@ void KGpgExternalActions::verifyFile(QUrl url)
// try to find detached signature.
if (!url.fileName().endsWith(QLatin1String(".sig"))) {
sigfile = url.path() + QLatin1String( ".sig" );
QFile fsig(sigfile);
if (!fsig.exists()) {
if (!QFile::exists(sigfile)) {
sigfile = url.path() + QLatin1String( ".asc" );
QFile fsig(sigfile);
// if no .asc or .sig signature file included, assume the file is internally signed
if (!fsig.exists())
if (!QFile::exists(sigfile))
sigfile.clear();
}
} else {
sigfile = url.path();
sigfile.chop(4);
url = QUrl(sigfile);
}
KGpgVerify *kgpv = new KGpgVerify(parent(), QList<QUrl>({QUrl(sigfile)}));
......
......@@ -53,10 +53,10 @@ void KgpgInterface::setGpgSetting(const QString &name, const QString &value, con
const QString temp = name + QLatin1Char(' ');
QString texttowrite;
bool found = false;
QTextStream t(&qfile);
QTextStream tin(&qfile);
while (!t.atEnd()) {
QString result = t.readLine();
while (!tin.atEnd()) {
QString result = tin.readLine();
if (result.simplified().startsWith(temp)) {
if (!value.isEmpty())
result = temp + QLatin1Char( ' ' ) + value;
......@@ -73,8 +73,8 @@ void KgpgInterface::setGpgSetting(const QString &name, const QString &value, con
texttowrite += QLatin1Char( '\n' ) + temp + QLatin1Char( ' ' ) + value;
if (qfile.open(QIODevice::WriteOnly)) {
QTextStream t(&qfile);
t << texttowrite;
QTextStream tout(&qfile);
tout << texttowrite;
qfile.close();
}
}
......@@ -101,10 +101,10 @@ void KgpgInterface::setGpgBoolSetting(const QString &name, const bool enable, co
if (qfile.exists() && qfile.open(QIODevice::ReadOnly)) {
QString texttowrite;
bool found = false;
QTextStream t(&qfile);
QTextStream tin(&qfile);
while (!t.atEnd()) {
QString result(t.readLine());
while (!tin.atEnd()) {
QString result(tin.readLine());
if (result.simplified().startsWith(name)) {
if (enable)
......@@ -123,8 +123,8 @@ void KgpgInterface::setGpgBoolSetting(const QString &name, const bool enable, co
texttowrite += name;
if (qfile.open(QIODevice::WriteOnly)) {
QTextStream t(&qfile);
t << texttowrite;
QTextStream tout(&qfile);
tout << texttowrite;
qfile.close();
}
}
......
......@@ -14,6 +14,7 @@
class KGpgTextInterfacePrivate
{
Q_DISABLE_COPY(KGpgTextInterfacePrivate)
public:
KGpgTextInterfacePrivate(QObject *parent, const QString &keyID, const QStringList &options);
......
......@@ -36,9 +36,6 @@ public:
protected:
bool nextLine(const QString &line) override;
bool passphraseReceived() override;
private:
int m_fixargs;
};
#endif // KGPGPRIMARYUID_H
......@@ -91,7 +91,7 @@ private:
QList<QUrl> m_inpfiles;
QString m_text;
QStringList m_messages;
bool m_closeInput; ///< if input channel of GnuPG should be closed after m_text is written
bool m_closeInput = false; ///< if input channel of GnuPG should be closed after m_text is written
void cleanUrls();
......
......@@ -333,9 +333,9 @@ KGpgTransaction::waitForFinished(const int msecs)
int ret = TS_OK;
if (d->m_inputTransaction != nullptr) {
int ret = d->m_inputTransaction->waitForFinished(msecs);
if ((ret != TS_OK) && (msecs != -1))
return ret;
int iret = d->m_inputTransaction->waitForFinished(msecs);
if ((iret != TS_OK) && (msecs != -1))
return iret;
}
bool b = d->m_process->waitForFinished(msecs);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment