Commit cd0712f6 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Port some foreach

parent ad31002c
Pipeline #48172 failed with stage
in 11 minutes and 50 seconds
......@@ -83,7 +83,8 @@ QStringList ExportOpenPGPCertsToServerCommand::arguments() const
result << QStringLiteral("--keyserver") << QStringLiteral("keys.gnupg.net");
}
result << QStringLiteral("--send-keys");
Q_FOREACH (const Key &key, d->keys()) {
const auto keys = d->keys();
for (const Key &key : keys) {
result << QLatin1String(key.primaryFingerprint());
}
return result;
......
......@@ -506,8 +506,9 @@ void ImportCertificatesCommand::Private::handleExternalCMSImports()
// For external CMS Imports we have to manually do a keylist
// with validation to get the intermediate and root ca imported
// automatically if trusted-certs and extra-certs are used.
Q_FOREACH (const ImportResult &result, results) {
Q_FOREACH (const Import &import, result.imports()) {
for (const ImportResult &result : qAsConst(results)) {
const auto imports = result.imports();
for (const Import &import : imports) {
if (!import.fingerprint()) {
continue;
}
......
......@@ -142,7 +142,7 @@ void AutoDecryptVerifyFilesController::Private::exec()
m_runnableTasks.swap(tasks);
std::shared_ptr<TaskCollection> coll(new TaskCollection);
Q_FOREACH (const std::shared_ptr<Task> &i, m_runnableTasks) {
for (const std::shared_ptr<Task> &i : qAsConst(m_runnableTasks)) {
q->connectTask(i);
}
coll->setTasks(m_runnableTasks);
......
......@@ -167,10 +167,12 @@ static QList<QRegExp> get_patterns(const std::vector< std::shared_ptr<ChecksumDe
{
QList<QRegExp> result;
for (const std::shared_ptr<ChecksumDefinition> &cd : checksumDefinitions)
if (cd)
Q_FOREACH (const QString &pattern, cd->patterns()) {
if (cd) {
const auto patterns = cd->patterns();
for (const QString &pattern : patterns) {
result.push_back(QRegExp(pattern, fs_cs));
}
}
return result;
}
......@@ -445,7 +447,8 @@ static std::shared_ptr<ChecksumDefinition> filename2definition(const QString &fi
{
for (const std::shared_ptr<ChecksumDefinition> &cd : checksumDefinitions) {
if (cd) {
Q_FOREACH (const QString &pattern, cd->patterns()) {
const auto patterns = cd->patterns();
for (const QString &pattern : patterns) {
if (QRegExp(pattern, fs_cs).exactMatch(fileName)) {
return cd;
}
......@@ -683,7 +686,7 @@ void CreateChecksumsController::Private::run()
const quint64 factor = total / std::numeric_limits<int>::max() + 1;
quint64 done = 0;
Q_FOREACH (const Dir &dir, dirs) {
for (const Dir &dir : dirs) {
Q_EMIT progress(done / factor, total / factor,
i18n("Checksumming (%2) in %1", dir.checksumDefinition->label(), dir.dir.path()));
bool fatal = false;
......
......@@ -171,7 +171,7 @@ void DecryptVerifyEMailController::Private::schedule()
}
if (!m_runningTask) {
kleo_assert(m_runnableTasks.empty());
Q_FOREACH (const std::shared_ptr<const DecryptVerifyResult> &i, m_results) {
for (const std::shared_ptr<const DecryptVerifyResult> &i : qAsConst(m_results)) {
Q_EMIT q->verificationResult(i->verificationResult());
}
// if there is a popup, wait for either the client cancel or the user closing the popup.
......
......@@ -195,7 +195,7 @@ void EncryptEMailController::start()
coll->setTasks(tmp);
d->ensureWizardCreated();
d->wizard->setTaskCollection(coll);
Q_FOREACH (const std::shared_ptr<Task> &t, tmp) {
for (const std::shared_ptr<Task> &t : qAsConst(tmp)) {
connectTask(t);
}
d->schedule();
......
......@@ -124,7 +124,7 @@ void ResolveRecipientsPage::ListWidget::setProtocol(GpgME::Protocol prot)
return;
}
m_protocol = prot;
Q_FOREACH (ItemWidget *i, widgets) {
for (ItemWidget *i : qAsConst(widgets)) {
i->setProtocol(prot);
}
}
......@@ -291,7 +291,7 @@ void ResolveRecipientsPage::ItemWidget::resetCertificates()
}
m_certCombo->clear();
Q_FOREACH (const Key &i, certs) {
for (const Key &i : qAsConst(certs)) {
addCertificateToComboBox(i);
}
if (!m_selectedCertificates[m_protocol].isNull()) {
......@@ -550,7 +550,7 @@ void ResolveRecipientsPage::Private::addRecipient()
const std::vector<Key> keys = dlg->selectedCertificates();
int i = 0;
Q_FOREACH (const Key &key, keys) {
for (const Key &key : keys) {
const QStringList existing = m_listWidget->identifiers();
QString rec = i18n("Recipient");
while (existing.contains(rec)) {
......@@ -603,7 +603,7 @@ void ResolveRecipientsPage::setRecipients(const std::vector<Mailbox> &recipients
uint cmsCount = 0;
uint pgpCount = 0;
uint senders = 0;
Q_FOREACH (const Mailbox &mb, encryptToSelfRecipients) {
for (const Mailbox &mb : encryptToSelfRecipients) {
const QString id = QLatin1String("sender-") + QString::number(++senders);
d->m_listWidget->addEntry(id, i18n("Sender"), mb);
const std::vector<Key> pgp = makeSuggestions(d->m_recipientPreferences, mb, OpenPGP);
......@@ -612,7 +612,7 @@ void ResolveRecipientsPage::setRecipients(const std::vector<Mailbox> &recipients
cmsCount += !cms.empty();
d->m_listWidget->setCertificates(id, pgp, cms);
}
Q_FOREACH (const Mailbox &i, recipients) {
for (const Mailbox &i : recipients) {
//TODO:
const QString address = i.prettyAddress();
d->addRecipient(i);
......
......@@ -155,13 +155,13 @@ private:
bool first;
first = true;
Q_FOREACH (const CertificateSelectionLine &line, ui.signers) {
for (const CertificateSelectionLine &line : qAsConst(ui.signers)) {
line.showHide(proto, first, showAll, sign);
}
ui.selectSigningCertificatesGB.setVisible(sign && (showAll || !first));
first = true;
Q_FOREACH (const CertificateSelectionLine &line, ui.recipients) {
for (const CertificateSelectionLine &line : qAsConst(ui.recipients)) {
line.showHide(proto, first, showAll, encrypt);
}
ui.selectEncryptionCertificatesGB.setVisible(encrypt && (showAll || !first));
......
......@@ -255,7 +255,8 @@ public:
void setOutputNames(const QMap<int, QString> &names) {
Q_ASSERT(mOutNames.isEmpty());
mOutNames = names;
Q_FOREACH (int i, mOutNames.keys()) {
const auto keys = mOutNames.keys();
for (int i : keys) {
mRequester[i] = createRequester(i, mOutLayout);
}
updateFileWidgets();
......
......@@ -135,7 +135,7 @@ SignEncryptWidget::SignEncryptWidget(QWidget *parent, bool sigEncExclusive)
mEncOtherChk->setChecked(true);
connect(mEncOtherChk, &QCheckBox::toggled, this,
[this](bool toggled) {
Q_FOREACH (CertificateLineEdit *edit, mRecpWidgets) {
for (CertificateLineEdit *edit : qAsConst(mRecpWidgets)) {
edit->setEnabled(toggled);
}
updateOp();
......@@ -301,7 +301,7 @@ void SignEncryptWidget::addUnknownRecipient(const char *keyID)
void SignEncryptWidget::recipientsChanged()
{
bool oneEmpty = false;
Q_FOREACH (const CertificateLineEdit *w, mRecpWidgets) {
for (const CertificateLineEdit *w : qAsConst(mRecpWidgets)) {
if (w->key().isNull()) {
oneEmpty = true;
break;
......@@ -332,7 +332,7 @@ Key SignEncryptWidget::selfKey() const
QVector <Key> SignEncryptWidget::recipients() const
{
QVector<Key> ret;
Q_FOREACH (const CertificateLineEdit *w, mRecpWidgets) {
for (const CertificateLineEdit *w : qAsConst(mRecpWidgets)) {
if (!w->isEnabled()) {
// If one is disabled, all are disabled.
break;
......@@ -401,7 +401,7 @@ void SignEncryptWidget::recpRemovalRequested(CertificateLineEdit *w)
return;
}
int emptyEdits = 0;
Q_FOREACH (const CertificateLineEdit *edit, mRecpWidgets) {
for (const CertificateLineEdit *edit : qAsConst(mRecpWidgets)) {
if (edit->isEmpty()) {
emptyEdits++;
}
......@@ -491,7 +491,7 @@ void SignEncryptWidget::setProtocol(GpgME::Protocol proto)
mSigSelect->setKeyFilter(std::shared_ptr<KeyFilter>(new SignCertificateFilter(proto)));
mSelfSelect->setKeyFilter(std::shared_ptr<KeyFilter>(new EncryptSelfCertificateFilter(proto)));
const auto encFilter = std::shared_ptr<KeyFilter>(new EncryptCertificateFilter(proto));
Q_FOREACH (CertificateLineEdit *edit, mRecpWidgets) {
for (CertificateLineEdit *edit : qAsConst(mRecpWidgets)) {
edit->setKeyFilter(encFilter);
}
......
......@@ -470,7 +470,7 @@ void NewSignEncryptEMailController::Private::startEncryption()
// ### use a new result dialog
dialog->setTaskCollection(coll);
#endif
Q_FOREACH (const std::shared_ptr<Task> &t, tmp) {
for (const std::shared_ptr<Task> &t : qAsConst(tmp)) {
q->connectTask(t);
}
schedule();
......@@ -521,7 +521,7 @@ void NewSignEncryptEMailController::Private::startSigning()
// ### use a new result dialog
dialog->setTaskCollection(coll);
#endif
Q_FOREACH (const std::shared_ptr<Task> &t, tmp) {
for (const std::shared_ptr<Task> &t : qAsConst(tmp)) {
q->connectTask(t);
}
schedule();
......
......@@ -214,7 +214,7 @@ void SignEMailController::start()
coll->setTasks(tmp);
d->ensureWizardCreated();
d->wizard->setTaskCollection(coll);
Q_FOREACH (const std::shared_ptr<Task> &t, tmp) {
for (const std::shared_ptr<Task> &t : qAsConst(tmp)) {
connectTask(t);
}
......
......@@ -85,10 +85,12 @@ static QList<QRegExp> get_patterns(const std::vector< std::shared_ptr<ChecksumDe
{
QList<QRegExp> result;
for (const std::shared_ptr<ChecksumDefinition> &cd : checksumDefinitions)
if (cd)
Q_FOREACH (const QString &pattern, cd->patterns()) {
if (cd) {
const auto patterns = cd->patterns();
for (const QString &pattern : patterns) {
result.push_back(QRegExp(pattern, fs_cs));
}
}
return result;
}
......@@ -326,11 +328,13 @@ static std::shared_ptr<ChecksumDefinition> filename2definition(const QString &fi
const std::vector< std::shared_ptr<ChecksumDefinition> > &checksumDefinitions)
{
for (const std::shared_ptr<ChecksumDefinition> &cd : checksumDefinitions)
if (cd)
Q_FOREACH (const QString &pattern, cd->patterns())
if (cd) {
const auto patterns = cd->patterns();
for (const QString &pattern : patterns)
if (QRegExp(pattern, fs_cs).exactMatch(fileName)) {
return cd;
}
}
return std::shared_ptr<ChecksumDefinition>();
}
......
......@@ -255,7 +255,8 @@ QString KleopatraApplication::newInstance(const QCommandLineParser &parser,
// Query and Search treat positional arguments differently, see below.
if (!queryMode) {
Q_FOREACH (const QString &file, parser.positionalArguments()) {
const auto positionalArguments = parser.positionalArguments();
for (const QString &file : positionalArguments) {
// We do not check that file exists here. Better handle
// these errors in the UI.
if (QFileInfo(file).isAbsolute()) {
......@@ -379,7 +380,7 @@ QString KleopatraApplication::newInstance(const QCommandLineParser &parser,
openOrRaiseMainWindow();
}
} else {
Q_FOREACH (const QString& fileName, files) {
for (const QString& fileName : qAsConst(files)) {
QFileInfo fi(fileName);
if (!fi.isReadable()) {
errors << i18n("Cannot read \"%1\"", fileName);
......
......@@ -1426,7 +1426,7 @@ void EnterDetailsPage::updateForm()
QMap<int, Line> lines;
Q_FOREACH (const QString &rawKey, attrOrder) {
for (const QString &rawKey : qAsConst(attrOrder)) {
const QString key = rawKey.trimmed().toUpper();
const QString attr = attributeFromKey(key);
if (attr.isEmpty()) {
......
......@@ -774,7 +774,7 @@ private Q_SLOTS:
std::list<Transaction> ft;
KDAB_SYNCHRONIZED(m_mutex)
ft.splice(ft.begin(), m_finishedTransactions);
Q_FOREACH (const Transaction &t, ft)
for (const Transaction &t : qAsConst(ft))
if (t.receiver && t.slot && *t.slot) {
QMetaObject::invokeMethod(t.receiver, t.slot, Qt::DirectConnection, Q_ARG(GpgME::Error, err));
}
......
......@@ -106,8 +106,8 @@ protected:
});
}
foreach (QAction *action, mColumnActions) {
int column = action->data().toInt();
for (QAction *action : qAsConst(mColumnActions)) {
const int column = action->data().toInt();
action->setChecked(!isColumnHidden(column));
}
......
......@@ -274,7 +274,7 @@ int main(int argc, char *argv[])
}
}
Q_FOREACH (const char *opt, options) {
for (const char *opt : qAsConst(options)) {
std::string line = "OPTION ";
line += opt;
if (const gpg_error_t err = assuan_transact(ctx, line.c_str(), nullptr, nullptr, nullptr, nullptr, nullptr, nullptr)) {
......
Markdown is supported
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