Replace remaining instances of Q_FOREACH with C++11 range-based for loops
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "core/Database.h"
|
||||
#include "core/Entry.h"
|
||||
#include "core/Global.h"
|
||||
#include "core/Group.h"
|
||||
#include "core/EntrySearcher.h"
|
||||
#include "core/Metadata.h"
|
||||
@@ -189,8 +190,9 @@ bool Service::removeFirstDomain(QString & hostname)
|
||||
QList<Entry*> Service::searchEntries(Database* db, const QString& hostname)
|
||||
{
|
||||
QList<Entry*> entries;
|
||||
if (Group* rootGroup = db->rootGroup())
|
||||
Q_FOREACH (Entry* entry, EntrySearcher().search(hostname, rootGroup, Qt::CaseInsensitive)) {
|
||||
if (Group* rootGroup = db->rootGroup()) {
|
||||
const auto results = EntrySearcher().search(hostname, rootGroup, Qt::CaseInsensitive);
|
||||
for (Entry* entry: results) {
|
||||
QString title = entry->title();
|
||||
QString url = entry->url();
|
||||
|
||||
@@ -201,6 +203,7 @@ QList<Entry*> Service::searchEntries(Database* db, const QString& hostname)
|
||||
|| (matchUrlScheme(url) && hostname.endsWith(QUrl(url).host())) )
|
||||
entries.append(entry);
|
||||
}
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
@@ -223,8 +226,9 @@ QList<Entry*> Service::searchEntries(const QString& text)
|
||||
QString hostname = QUrl(text).host();
|
||||
QList<Entry*> entries;
|
||||
do {
|
||||
Q_FOREACH (Database* db, databases)
|
||||
for (Database* db: asConst(databases)) {
|
||||
entries << searchEntries(db, hostname);
|
||||
}
|
||||
} while(entries.isEmpty() && removeFirstDomain(hostname));
|
||||
|
||||
return entries;
|
||||
@@ -249,9 +253,12 @@ KeepassHttpProtocol::Entry Service::prepareEntry(const Entry* entry)
|
||||
KeepassHttpProtocol::Entry res(entry->resolvePlaceholder(entry->title()), entry->resolvePlaceholder(entry->username()), entry->resolvePlaceholder(entry->password()), entry->uuid().toHex());
|
||||
if (HttpSettings::supportKphFields()) {
|
||||
const EntryAttributes * attr = entry->attributes();
|
||||
Q_FOREACH (const QString& key, attr->keys())
|
||||
if (key.startsWith(QLatin1String("KPH: ")))
|
||||
const auto keys = attr->keys();
|
||||
for (const QString& key: keys) {
|
||||
if (key.startsWith(QLatin1String("KPH: "))) {
|
||||
res.addStringField(key, attr->value(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -318,7 +325,8 @@ QList<KeepassHttpProtocol::Entry> Service::findMatchingEntries(const QString& /*
|
||||
//Check entries for authorization
|
||||
QList<Entry*> pwEntriesToConfirm;
|
||||
QList<Entry*> pwEntries;
|
||||
Q_FOREACH (Entry * entry, searchEntries(url)) {
|
||||
const auto entries = searchEntries(url);
|
||||
for (Entry* entry: entries) {
|
||||
switch(checkAccess(entry, host, submitHost, realm)) {
|
||||
case Denied:
|
||||
continue;
|
||||
@@ -352,7 +360,7 @@ QList<KeepassHttpProtocol::Entry> Service::findMatchingEntries(const QString& /*
|
||||
|
||||
int res = dlg.exec();
|
||||
if (dlg.remember()) {
|
||||
Q_FOREACH (Entry * entry, pwEntriesToConfirm) {
|
||||
for (Entry* entry: asConst(pwEntriesToConfirm)) {
|
||||
EntryConfig config;
|
||||
config.load(entry);
|
||||
if (res == QDialog::Accepted) {
|
||||
@@ -383,28 +391,22 @@ QList<KeepassHttpProtocol::Entry> Service::findMatchingEntries(const QString& /*
|
||||
const QString baseSubmitURL = url.toString(QUrl::StripTrailingSlash | QUrl::RemovePath | QUrl::RemoveQuery | QUrl::RemoveFragment);
|
||||
|
||||
//Cache priorities
|
||||
QHash<const Entry *, int> priorities;
|
||||
QHash<const Entry*, int> priorities;
|
||||
priorities.reserve(pwEntries.size());
|
||||
Q_FOREACH (const Entry * entry, pwEntries)
|
||||
for (const Entry* entry: asConst(pwEntries)) {
|
||||
priorities.insert(entry, sortPriority(entry, host, submitUrl, baseSubmitURL));
|
||||
}
|
||||
|
||||
//Sort by priorities
|
||||
std::sort(pwEntries.begin(), pwEntries.end(), SortEntries(priorities, HttpSettings::sortByTitle() ? "Title" : "UserName"));
|
||||
}
|
||||
|
||||
//if (pwEntries.count() > 0)
|
||||
//{
|
||||
// var names = (from e in resp.Entries select e.Name).Distinct<string>();
|
||||
// var n = String.Join("\n ", names.ToArray<string>());
|
||||
// if (HttpSettings::receiveCredentialNotification())
|
||||
// ShowNotification(QString("%0: %1 is receiving credentials for:\n%2").arg(Id).arg(host).arg(n)));
|
||||
//}
|
||||
|
||||
//Fill the list
|
||||
QList<KeepassHttpProtocol::Entry> result;
|
||||
result.reserve(pwEntries.count());
|
||||
Q_FOREACH (Entry * entry, pwEntries)
|
||||
for (Entry* entry: asConst(pwEntries)) {
|
||||
result << prepareEntry(entry);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -416,12 +418,19 @@ int Service::countMatchingEntries(const QString &, const QString &url, const QSt
|
||||
QList<KeepassHttpProtocol::Entry> Service::searchAllEntries(const QString &)
|
||||
{
|
||||
QList<KeepassHttpProtocol::Entry> result;
|
||||
if (DatabaseWidget * dbWidget = m_dbTabWidget->currentDatabaseWidget())
|
||||
if (Database * db = dbWidget->database())
|
||||
if (Group * rootGroup = db->rootGroup())
|
||||
Q_FOREACH (Entry * entry, rootGroup->entriesRecursive())
|
||||
if (!entry->url().isEmpty() || QUrl(entry->title()).isValid())
|
||||
result << KeepassHttpProtocol::Entry(entry->title(), entry->username(), QString(), entry->uuid().toHex());
|
||||
if (DatabaseWidget* dbWidget = m_dbTabWidget->currentDatabaseWidget()) {
|
||||
if (Database* db = dbWidget->database()) {
|
||||
if (Group* rootGroup = db->rootGroup()) {
|
||||
const auto entries = rootGroup->entriesRecursive();
|
||||
for (Entry* entry: entries) {
|
||||
if (!entry->url().isEmpty() || QUrl(entry->title()).isValid()) {
|
||||
result << KeepassHttpProtocol::Entry(entry->title(), entry->username(),
|
||||
QString(), entry->uuid().toHex());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -430,11 +439,15 @@ Group * Service::findCreateAddEntryGroup()
|
||||
if (DatabaseWidget * dbWidget = m_dbTabWidget->currentDatabaseWidget())
|
||||
if (Database * db = dbWidget->database())
|
||||
if (Group * rootGroup = db->rootGroup()) {
|
||||
const QString groupName = QLatin1String(KEEPASSHTTP_GROUP_NAME);//TODO: setting to decide where new keys are created
|
||||
//TODO: setting to decide where new keys are created
|
||||
const QString groupName = QLatin1String(KEEPASSHTTP_GROUP_NAME);
|
||||
|
||||
Q_FOREACH (const Group * g, rootGroup->groupsRecursive(true))
|
||||
if (g->name() == groupName)
|
||||
const auto groups = rootGroup->groupsRecursive(true);
|
||||
for (const Group * g: groups) {
|
||||
if (g->name() == groupName) {
|
||||
return db->resolveGroup(g->uuid());
|
||||
}
|
||||
}
|
||||
|
||||
Group * group;
|
||||
group = new Group();
|
||||
@@ -507,14 +520,18 @@ void Service::removeSharedEncryptionKeys()
|
||||
QMessageBox::Ok);
|
||||
} else if (Entry* entry = getConfigEntry()) {
|
||||
QStringList keysToRemove;
|
||||
Q_FOREACH (const QString& key, entry->attributes()->keys())
|
||||
if (key.startsWith(ASSOCIATE_KEY_PREFIX))
|
||||
const auto keys = entry->attributes()->keys();
|
||||
for (const QString& key: keys) {
|
||||
if (key.startsWith(ASSOCIATE_KEY_PREFIX)) {
|
||||
keysToRemove << key;
|
||||
}
|
||||
}
|
||||
|
||||
if(keysToRemove.count()) {
|
||||
entry->beginUpdate();
|
||||
Q_FOREACH (const QString& key, keysToRemove)
|
||||
for (const QString& key: asConst(keysToRemove)) {
|
||||
entry->attributes()->remove(key);
|
||||
}
|
||||
entry->endUpdate();
|
||||
|
||||
const int count = keysToRemove.count();
|
||||
@@ -548,7 +565,7 @@ void Service::removeStoredPermissions()
|
||||
progress.setWindowModality(Qt::WindowModal);
|
||||
|
||||
uint counter = 0;
|
||||
Q_FOREACH (Entry* entry, entries) {
|
||||
for (Entry* entry: asConst(entries)) {
|
||||
if (progress.wasCanceled())
|
||||
return;
|
||||
if (entry->attributes()->contains(KEEPASSHTTP_NAME)) {
|
||||
|
||||
Reference in New Issue
Block a user