Commit 961cdf0e authored by Ahmad Samir's avatar Ahmad Samir Committed by Ingo Klöcker
Browse files

Port Q_FOREACH to range-for

parent 07b183c2
......@@ -146,16 +146,15 @@ void CertifyCertificateCommand::doStart()
return;
}
std::vector<Key> secKeys;
Q_FOREACH (const Key &secKey, KeyCache::instance()->secretKeys()) {
// Only include usable keys.
if (secKey.canCertify() && secKey.protocol() == OpenPGP && !secKey.isRevoked() &&
!secKey.isExpired() && !secKey.isInvalid()) {
secKeys.push_back(secKey);
}
}
if (secKeys.empty()) {
auto findAnyGoodKey = []() {
const std::vector<Key> secKeys = KeyCache::instance()->secretKeys();
return std::any_of(secKeys.cbegin(), secKeys.cend(), [](const Key &secKey) {
return secKey.canCertify() && secKey.protocol() == OpenPGP && !secKey.isRevoked()
&& !secKey.isExpired() && !secKey.isInvalid();
});
};
if (!findAnyGoodKey()) {
auto sel = KMessageBox::questionYesNo(d->parentWidgetOrView(),
xi18nc("@info", "To certify other certificates, you first need to create an OpenPGP certificate for yourself.") +
QStringLiteral("<br><br>") +
......@@ -174,28 +173,25 @@ void CertifyCertificateCommand::doStart()
d->finished();
return;
}
Q_FOREACH (const Key &secKey, KeyCache::instance()->secretKeys()) {
// Check again for secret keys
if (secKey.canCertify() && secKey.protocol() == OpenPGP && !secKey.isRevoked() &&
!secKey.isExpired() && !secKey.isInvalid()) {
secKeys.push_back(secKey);
}
}
if (secKeys.empty()) {
// Check again for secret keys
if (!findAnyGoodKey()) {
qCDebug(KLEOPATRA_LOG) << "Sec Keys still empty after keygen.";
Q_EMIT(canceled());
d->finished();
return;
}
}
const Key &key = keys.front();
for (const UserID &uid : std::as_const(d->uids))
if (qstricmp(uid.parent().primaryFingerprint(), key.primaryFingerprint()) != 0) {
qCWarning(KLEOPATRA_LOG) << "User ID <-> Key mismatch!";
d->finished();
return;
}
const char *primary = keys.front().primaryFingerprint();
const bool anyMismatch = std::any_of(d->uids.cbegin(), d->uids.cend(), [primary](const UserID &uid) {
return qstricmp(uid.parent().primaryFingerprint(), primary) != 0;
});
if (anyMismatch) {
qCWarning(KLEOPATRA_LOG) << "User ID <-> Key mismatch!";
d->finished();
return;
}
d->ensureDialogCreated();
Q_ASSERT(d->dialog);
......
......@@ -157,7 +157,7 @@ void NewResultPage::addTaskCollection(const std::shared_ptr<TaskCollection> &col
connect(coll.get(), SIGNAL(started(std::shared_ptr<Kleo::Crypto::Task>)),
this, SLOT(started(std::shared_ptr<Kleo::Crypto::Task>)));
Q_FOREACH (const std::shared_ptr<Task> &i, coll->tasks()) { // create labels for all tags in collection
for (const std::shared_ptr<Task> &i : coll->tasks()) { // create labels for all tags in collection
Q_ASSERT(i);
QLabel *l = d->labelForTag(i->tag());
Q_ASSERT(l); (void)l;
......
......@@ -621,7 +621,8 @@ void ResolveRecipientsPage::setRecipients(const std::vector<Mailbox> &recipients
std::vector<Key> ResolveRecipientsPage::resolvedCertificates() const
{
std::vector<Key> certs;
Q_FOREACH (const QString &i, d->m_listWidget->identifiers()) {
const QStringList identifiers = d->m_listWidget->identifiers();
for (const QString &i : identifiers) {
const GpgME::Key cert = d->m_listWidget->selectedCertificate(i);
if (!cert.isNull()) {
certs.push_back(cert);
......
......@@ -154,7 +154,7 @@ void ResultPage::setTaskCollection(const std::shared_ptr<TaskCollection> &coll)
connect(d->m_tasks.get(), SIGNAL(started(std::shared_ptr<Kleo::Crypto::Task>)),
this, SLOT(started(std::shared_ptr<Kleo::Crypto::Task>)));
Q_FOREACH (const std::shared_ptr<Task> &i, d->m_tasks->tasks()) { // create labels for all tags in collection
for (const std::shared_ptr<Task> &i : d->m_tasks->tasks()) { // create labels for all tags in collection
Q_ASSERT(i && d->labelForTag(i->tag()));
Q_UNUSED(i)
}
......
......@@ -105,12 +105,12 @@ bool ReadOnlyProtocolSelectionWidget::isProtocolChecked(Protocol protocol) const
std::set<Protocol> ReadOnlyProtocolSelectionWidget::checkedProtocols() const
{
std::set<Protocol> res;
Q_FOREACH (const Protocol i, supportedProtocols()) //krazy:exclude=foreach
for (const Protocol i : supportedProtocols()) {
if (isProtocolChecked(i)) {
res.insert(i);
}
}
return res;
}
SigningProtocolSelectionWidget::SigningProtocolSelectionWidget(QWidget *parent, Qt::WindowFlags f)
......@@ -122,7 +122,7 @@ SigningProtocolSelectionWidget::SigningProtocolSelectionWidget(QWidget *parent,
auto const layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
Q_FOREACH (const Protocol i, supportedProtocols()) { //krazy:exclude=foreach
for (const Protocol i : supportedProtocols()) {
auto const b = new QCheckBox;
b->setText(formatLabel(i, Key()));
m_buttons[i] = b;
......@@ -360,10 +360,11 @@ bool SignerResolvePage::Private::protocolSelected(Protocol p) const
void SignerResolvePage::Private::setCertificates(const QMap<GpgME::Protocol, GpgME::Key> &certs)
{
certificates = certs;
Q_FOREACH (const Protocol i, certs.keys()) { //krazy:exclude=foreach
const Key key = certs.value(i);
readOnlyProtocolSelectionWidget->setCertificate(i, key);
signingProtocolSelectionWidget->setCertificate(i, key);
for (auto it = certs.cbegin(), endIt = certs.cend(); it != endIt; ++it) {
const Protocol proto = it.key();
const Key &key = it.value();
readOnlyProtocolSelectionWidget->setCertificate(proto, key);
signingProtocolSelectionWidget->setCertificate(proto, key);
}
updateUi();
}
......@@ -538,7 +539,7 @@ void SignerResolvePage::setPresetProtocol(Protocol protocol)
void SignerResolvePage::setPresetProtocols(const std::vector<Protocol> &protocols)
{
d->presetProtocols = protocols;
Q_FOREACH (const Protocol i, supportedProtocols()) { //krazy:exclude=foreach
for (const Protocol i : supportedProtocols()) {
const bool checked = std::find(protocols.begin(), protocols.end(), i) != protocols.end();
d->signingProtocolSelectionWidget->setProtocolChecked(i, checked);
d->readOnlyProtocolSelectionWidget->setProtocolChecked(i, checked);
......@@ -626,10 +627,11 @@ void SignerResolvePage::setSigningUserMutable(bool ismutable)
std::set<Protocol> SignerResolvePage::selectedProtocolsWithoutSigningCertificate() const
{
std::set<Protocol> res;
Q_FOREACH (const Protocol i, selectedProtocols()) //krazy:exclude=foreach
for (const Protocol i : selectedProtocols()) {
if (signingCertificates(i).empty()) {
res.insert(i);
}
}
return res;
}
......
......@@ -240,7 +240,7 @@ void SignEMailController::Private::schedule()
if (!cms && !openpgp) {
kleo_assert(runnable.empty());
QPointer<QObject> Q = q;
Q_FOREACH (const std::shared_ptr<SignEMailTask> t, completed) {
for (const std::shared_ptr<SignEMailTask> &t : completed) {
Q_EMIT q->reportMicAlg(t->micAlg());
if (!Q) {
return;
......
......@@ -514,7 +514,7 @@ void SignEncryptFilesController::Private::slotWizardOperationPrepared()
const bool ascii = prefs.addASCIIArmor();
std::vector<Key> pgpRecipients, cmsRecipients, pgpSigners, cmsSigners;
Q_FOREACH (const Key &k, recipients) {
for (const Key &k : recipients) {
if (k.protocol() == GpgME::OpenPGP) {
pgpRecipients.push_back(k);
} else {
......@@ -522,7 +522,7 @@ void SignEncryptFilesController::Private::slotWizardOperationPrepared()
}
}
Q_FOREACH (const Key &k, signers) {
for (const Key &k : signers) {
if (k.protocol() == GpgME::OpenPGP) {
pgpSigners.push_back(k);
} else {
......@@ -547,7 +547,7 @@ void SignEncryptFilesController::Private::slotWizardOperationPrepared()
wizard->encryptSymmetric());
} else {
Q_FOREACH (const QString &file, files) {
for (const QString &file : std::as_const(files)) {
const std::vector< std::shared_ptr<SignEncryptTask> > created =
createSignEncryptTasksForFileInfo(QFileInfo(file), ascii,
pgpRecipients,
......@@ -561,7 +561,7 @@ void SignEncryptFilesController::Private::slotWizardOperationPrepared()
}
const std::shared_ptr<OverwritePolicy> overwritePolicy(new OverwritePolicy(wizard));
Q_FOREACH (const std::shared_ptr<SignEncryptTask> &i, tasks) {
for (const std::shared_ptr<SignEncryptTask> &i : tasks) {
i->setOverwritePolicy(overwritePolicy);
}
......
......@@ -325,10 +325,12 @@ void LookupCertificatesDialog::accept()
void LookupCertificatesDialog::Private::enableDisableWidgets()
{
// enable/disable everything except 'close', based on passive:
Q_FOREACH (QObject *const o, q->children())
const QList<QObject *> list = q->children();
for (QObject *const o : list) {
if (QWidget *const w = qobject_cast<QWidget *>(o)) {
w->setDisabled(passive && w != ui.closePB() && w != ui.buttonBox);
}
}
if (passive) {
return;
......
......@@ -439,7 +439,8 @@ QString KleopatraApplication::newInstance(const QCommandLineParser &parser,
errors << i18n("Cannot read \"%1\"", fileName);
}
}
Q_FOREACH (Command *cmd, Command::commandsForFiles(files)) {
const QVector<Command *> allCmds = Command::commandsForFiles(files);
for (Command *cmd : allCmds) {
if (parentId) {
cmd->setParentWId(parentId);
} else {
......
......@@ -668,23 +668,26 @@ void Command::Private::run()
}
}
Q_FOREACH (const QString &filePath, in.filePaths)
for (const QString &filePath : std::as_const(in.filePaths)) {
if ((err = send_file(ctx, filePath))) {
out.errorString = i18n("Failed to send file path %1: %2", filePath, to_error_string(err));
goto leave;
}
}
Q_FOREACH (const QString &sender, in.senders)
for (const QString &sender : std::as_const(in.senders)) {
if ((err = send_sender(ctx, sender, in.areSendersInformative))) {
out.errorString = i18n("Failed to send sender %1: %2", sender, to_error_string(err));
goto leave;
}
}
Q_FOREACH (const QString &recipient, in.recipients)
for (const QString &recipient : std::as_const(in.recipients)) {
if ((err = send_recipient(ctx, recipient, in.areRecipientsInformative))) {
out.errorString = i18n("Failed to send recipient %1: %2", recipient, to_error_string(err));
goto leave;
}
}
#if 0
setup I / O;
......
......@@ -91,10 +91,12 @@ int DecryptVerifyCommandEMailBase::doStart()
d->controller.reset(new DecryptVerifyEMailController(shared_from_this()));
const QString st = sessionTitle();
if (!st.isEmpty())
Q_FOREACH (const std::shared_ptr<Input> &i, inputs()) {
if (!st.isEmpty()) {
const std::vector<std::shared_ptr<Input>> allInputs = inputs();
for (const std::shared_ptr<Input> &i : allInputs) {
i->setLabel(st);
}
}
d->controller->setSessionId(sessionId());
d->controller->setOperation(operation());
......
......@@ -166,10 +166,12 @@ void EncryptCommand::Private::slotRecipientsResolved()
try {
const QString sessionTitle = q->sessionTitle();
if (!sessionTitle.isEmpty())
Q_FOREACH (const std::shared_ptr<Input> &i, q->inputs()) {
if (!sessionTitle.isEmpty()) {
const std::vector<std::shared_ptr<Input>> allInputs = q->inputs();
for (const std::shared_ptr<Input> &i : allInputs) {
i->setLabel(sessionTitle);
}
}
cont->startEncryption(q->inputs(), q->outputs());
......
......@@ -162,10 +162,12 @@ void SignCommand::Private::slotSignersResolved()
try {
const QString sessionTitle = q->sessionTitle();
if (!sessionTitle.isEmpty())
Q_FOREACH (const std::shared_ptr<Input> &i, q->inputs()) {
if (!sessionTitle.isEmpty()) {
const std::vector<std::shared_ptr<Input>> allInputs = q->inputs();
for (const std::shared_ptr<Input> &i : allInputs) {
i->setLabel(sessionTitle);
}
}
cont->setDetachedSignature(q->hasOption("detached"));
cont->startSigning(q->inputs(), q->outputs());
......
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