Commit 6b6ae616 authored by Méven Car's avatar Méven Car
Browse files

Runners: Convert foreach to for

Reviewers: #plasma, davidedmundson, ivan

Reviewed By: #plasma, davidedmundson, ivan

Subscribers: ivan, davidedmundson, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26438
parent 1640e9f4
......@@ -121,7 +121,7 @@ void ActivityRunner::match(Plasma::RunnerContext &context)
}
if (list) {
foreach (const QString &activity, activities) {
for (const QString &activity : qAsConst(activities)) {
if (current == activity) {
continue;
}
......@@ -134,7 +134,7 @@ void ActivityRunner::match(Plasma::RunnerContext &context)
}
}
} else {
foreach (const QString &activity, activities) {
for (const QString &activity : qAsConst(activities)) {
if (current == activity) {
continue;
}
......
......@@ -55,7 +55,7 @@ static QIcon componentIcon(const AppStream::Component &comp)
const auto icons = comp.icons();
if (icons.isEmpty()) {
ret = QIcon::fromTheme(QStringLiteral("package-x-generic"));
} else foreach(const AppStream::Icon &icon, icons) {
} else for(const AppStream::Icon &icon : icons) {
QStringList stock;
switch(icon.kind()) {
case AppStream::Icon::KindLocal:
......
......@@ -82,8 +82,8 @@ void BookmarksRunner::match(Plasma::RunnerContext &context)
bool allBookmarks = term.compare(i18nc("list of all konqueror bookmarks", "bookmarks"),
Qt::CaseInsensitive) == 0;
QList<BookmarkMatch> matches = m_browser->match(term, allBookmarks);
foreach(BookmarkMatch match, matches) {
const QList<BookmarkMatch> matches = m_browser->match(term, allBookmarks);
for(BookmarkMatch match : matches) {
if(!context.isValid())
return;
context.addMatch(match.asQueryMatch(this));
......
......@@ -34,7 +34,7 @@
class ProfileBookmarks {
public:
ProfileBookmarks(Profile &profile) : m_profile(profile) {}
ProfileBookmarks(const Profile &profile) : m_profile(profile) {}
inline QJsonArray bookmarks() { return m_bookmarks; }
inline Profile profile() { return m_profile; }
void tearDown() { m_profile.favicon()->teardown(); clear(); }
......@@ -50,7 +50,8 @@ Chrome::Chrome( FindProfile* findProfile, QObject* parent )
m_watcher(new KDirWatch(this)),
m_dirty(false)
{
foreach(Profile profile, findProfile->find()) {
const auto profiles = findProfile->find();
for(const Profile &profile : profiles) {
m_profileBookmarks << new ProfileBookmarks(profile);
m_watcher->addFile(profile.path());
}
......@@ -59,7 +60,7 @@ Chrome::Chrome( FindProfile* findProfile, QObject* parent )
Chrome::~Chrome()
{
foreach(ProfileBookmarks *profileBookmark, m_profileBookmarks) {
for(ProfileBookmarks *profileBookmark : qAsConst(m_profileBookmarks)) {
delete profileBookmark;
}
}
......@@ -70,7 +71,7 @@ QList<BookmarkMatch> Chrome::match(const QString &term, bool addEveryThing)
prepare();
}
QList<BookmarkMatch> results;
foreach(ProfileBookmarks *profileBookmarks, m_profileBookmarks) {
for(ProfileBookmarks *profileBookmarks : qAsConst(m_profileBookmarks)) {
results << match(term, addEveryThing, profileBookmarks);
}
return results;
......@@ -95,7 +96,7 @@ QList<BookmarkMatch> Chrome::match(const QString &term, bool addEveryThing, Prof
void Chrome::prepare()
{
m_dirty = false;
foreach(ProfileBookmarks *profileBookmarks, m_profileBookmarks) {
for(ProfileBookmarks *profileBookmarks : qAsConst(m_profileBookmarks)) {
Profile profile = profileBookmarks->profile();
profileBookmarks->clear();
QFile bookmarksFile(profile.path());
......@@ -120,7 +121,7 @@ void Chrome::prepare()
void Chrome::teardown()
{
foreach(ProfileBookmarks *profileBookmarks, m_profileBookmarks) {
for(ProfileBookmarks *profileBookmarks : qAsConst(m_profileBookmarks)) {
profileBookmarks->tearDown();
}
}
......
......@@ -58,7 +58,7 @@ QList<Profile> FindChromeProfile::find()
QVariantMap localState = jdoc.object().toVariantMap();
QVariantMap profilesConfig = localState.value(QStringLiteral("profile")).toMap().value(QStringLiteral("info_cache")).toMap();
foreach(const QString &profile, profilesConfig.keys()) {
for(const QString &profile : profilesConfig.keys()) {
const QString profilePath = QStringLiteral("%1/%2").arg(configDirectory, profile);
const QString profileBookmarksPath = QStringLiteral("%1/%2").arg(profilePath, QStringLiteral("Bookmarks"));
profiles << Profile(profileBookmarksPath, FaviconFromBlob::chrome(profilePath, this));
......
......@@ -98,9 +98,9 @@ QList< BookmarkMatch > Firefox::match(const QString& term, bool addEverything)
const QMap<QString, QVariant> bindVariables {
{QStringLiteral(":term"), QStringLiteral("%%%1%%").arg(term)},
};
QList<QVariantMap> results = m_fetchsqlite->query(query, bindVariables);
const QList<QVariantMap> results = m_fetchsqlite->query(query, bindVariables);
QMultiMap<QString, QString> uniqueResults;
foreach(QVariantMap result, results) {
for(const QVariantMap &result : results) {
const QString title = result.value(QStringLiteral("title")).toString();
const QUrl url = result.value(QStringLiteral("url")).toUrl();
if (url.isEmpty() || url.scheme() == QLatin1String("place")) {
......
......@@ -39,7 +39,7 @@ QList<BookmarkMatch> Opera::match( const QString& term, bool addEverything )
QLatin1String descriptionStart("\tDESCRIPTION=");
// search
foreach (const QString & entry, m_operaBookmarkEntries) {
for (const QString & entry : qAsConst(m_operaBookmarkEntries)) {
QStringList entryLines = entry.split(QStringLiteral("\n"));
if (!entryLines.first().startsWith(QLatin1String("#URL"))) {
continue; // skip folder entries
......@@ -50,7 +50,7 @@ QList<BookmarkMatch> Opera::match( const QString& term, bool addEverything )
QString url;
QString description;
foreach (const QString & line, entryLines) {
for (const QString & line : qAsConst(entryLines)) {
if (line.startsWith(nameStart)) {
name = line.mid( QString(nameStart).length() ).simplified();
} else if (line.startsWith(urlStart)) {
......
......@@ -97,8 +97,8 @@ QList<QVariantMap> FetchSqlite::query(const QString &sql, QMap<QString, QVariant
//qDebug() << "query: " << sql;
QSqlQuery query(db);
query.prepare(sql);
foreach(const QString &variableName, bindObjects.keys()) {
query.bindValue(variableName, bindObjects.value(variableName));
for (auto entry = bindObjects.constKeyValueBegin(); entry != bindObjects.constKeyValueEnd(); ++entry) {
query.bindValue((*entry).first, (*entry).second);
//qDebug() << "* Bound " << variableName << " to " << query.boundValue(variableName);
}
......
......@@ -120,7 +120,7 @@ void KillRunner::match(Plasma::RunnerContext &context)
QList<Plasma::QueryMatch> matches;
const QList<KSysGuard::Process *> processlist = m_processes->getAllProcesses();
foreach (const KSysGuard::Process *process, processlist) {
for (const KSysGuard::Process *process : processlist) {
if (!context.isValid()) {
return;
}
......
......@@ -60,7 +60,7 @@ PowerDevilRunner::PowerDevilRunner(QObject *parent, const QVariantList &args)
<< i18nc("Note this is a KRunner keyword", "screen brightness")
<< i18nc("Note this is a KRunner keyword", "dim screen");
foreach (const QString &command, commands) {
for (const QString &command : qAsConst(commands)) {
if (command.length() < m_shortestCommand) {
m_shortestCommand = command.length();
}
......@@ -124,7 +124,7 @@ void PowerDevilRunner::updateStatus()
bool PowerDevilRunner::parseQuery(const QString& query, const QList<QRegExp>& rxList, QString& parameter) const
{
foreach (const QRegExp& rx, rxList) {
for (const QRegExp& rx : rxList) {
if (rx.exactMatch(query)) {
parameter = rx.cap(1).trimmed();
return true;
......
......@@ -78,7 +78,7 @@ void RecentDocuments::match(Plasma::RunnerContext &context)
// avoid duplicates
QSet<QUrl> knownUrls;
foreach (const QString &document, m_recentdocuments) {
for (const QString &document : qAsConst(m_recentdocuments)) {
if (!context.isValid()) {
return;
}
......
......@@ -134,7 +134,7 @@ private:
return relevanceIncrement;
}
QString generateQuery(QVector<QStringRef> &strList)
QString generateQuery(const QVector<QStringRef> &strList)
{
QString keywordTemplate = QStringLiteral("exist Keywords");
QString genericNameTemplate = QStringLiteral("exist GenericName");
......@@ -147,7 +147,7 @@ private:
// * a substring of the Name field
// Note that before asking for the content of e.g. Keywords and GenericName we need to ask if
// they exist to prevent a tree evaluation error if they are not defined.
foreach (QStringRef str, strList)
for (const QStringRef &str : strList)
{
keywordTemplate += QStringLiteral(" and '%1' ~subin Keywords").arg(str.toString());
genericNameTemplate += QStringLiteral(" and '%1' ~~ GenericName").arg(str.toString());
......@@ -190,13 +190,13 @@ private:
// See https://techbase.kde.org/Development/Tutorials/Services/Traders#The_KTrader_Query_Language
// if the following is unclear to you.
query = QStringLiteral("exist Exec and ('%1' =~ Name)").arg(term);
KService::List services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), query);
const KService::List services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), query);
if (services.isEmpty()) {
return;
}
foreach (const KService::Ptr &service, services) {
for (const KService::Ptr &service : services) {
qCDebug(RUNNER_SERVICES) << service->name() << "is an exact match!" << service->storageId() << service->exec();
if (disqualify(service)) {
continue;
......@@ -226,7 +226,7 @@ private:
services += KServiceTypeTrader::self()->query(QStringLiteral("KCModule"), query);
qCDebug(RUNNER_SERVICES) << "got " << services.count() << " services from " << query;
foreach (const KService::Ptr &service, services) {
for (const KService::Ptr &service : qAsConst(services)) {
if (disqualify(service)) {
continue;
}
......@@ -296,9 +296,9 @@ private:
{
//search for applications whose categories contains the query
query = QStringLiteral("exist Exec and (exist Categories and '%1' ~subin Categories)").arg(term);
auto services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), query);
const auto services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), query);
foreach (const KService::Ptr &service, services) {
for (const KService::Ptr &service : services) {
qCDebug(RUNNER_SERVICES) << service->name() << "is an exact match!" << service->storageId() << service->exec();
if (disqualify(service)) {
continue;
......@@ -330,14 +330,14 @@ private:
}
query = QStringLiteral("exist Actions"); // doesn't work
auto services = KServiceTypeTrader::self()->query(QStringLiteral("Application"));//, query);
const auto services = KServiceTypeTrader::self()->query(QStringLiteral("Application"));//, query);
foreach (const KService::Ptr &service, services) {
for (const KService::Ptr &service : services) {
if (service->noDisplay()) {
continue;
}
foreach (const KServiceAction &action, service->actions()) {
for (const KServiceAction &action : service->actions()) {
if (action.text().isEmpty() || action.exec().isEmpty() || hasSeen(action)) {
continue;
}
......
......@@ -171,7 +171,7 @@ void SessionRunner::match(Plasma::RunnerContext &context)
SessList sessions;
dm.localSessions(sessions);
foreach (const SessEnt& session, sessions) {
for (const SessEnt& session : qAsConst(sessions)) {
if (!session.vt || session.self) {
continue;
}
......
......@@ -57,10 +57,10 @@ void WindowedWidgetsRunner::match(Plasma::RunnerContext &context)
return;
}
QList<Plasma::QueryMatch> matches;
QList<Plasma::QueryMatch> matches;
foreach (const KPluginMetaData &md, Plasma::PluginLoader::self()->listAppletMetaData(QString())) {
const auto &listMetadata = Plasma::PluginLoader::self()->listAppletMetaData(QString());
for (const KPluginMetaData &md : listMetadata) {
if (!md.isValid()) {
continue;
}
......
......@@ -75,7 +75,8 @@ void WindowsRunner::gatherInfo()
return;
}
foreach (const WId w, KWindowSystem::windows()) {
const auto windows = KWindowSystem::windows();
for (const WId &w : windows) {
KWindowInfo info(w, NET::WMWindowType | NET::WMDesktop |
NET::WMState | NET::XAWMState |
NET::WMName,
......@@ -180,7 +181,7 @@ void WindowsRunner::match(Plasma::RunnerContext& context)
QString windowClass;
QString windowRole;
int desktop = -1;
foreach (const QString& keyword, keywords) {
for (const QString& keyword : keywords) {
if (keyword.endsWith(QLatin1Char('='))) {
continue;
}
......@@ -215,7 +216,7 @@ void WindowsRunner::match(Plasma::RunnerContext& context)
if (!KWindowSystem::hasWId(w)) {
continue;
}
if (!windowName.isEmpty() && !info.name().contains(windowName, Qt::CaseInsensitive)) {
if (!windowName.isEmpty() && !info.name().startsWith(windowName, Qt::CaseInsensitive)) {
continue;
}
if (!windowClass.isEmpty() && !windowClassCompare.contains(windowClass, Qt::CaseInsensitive)) {
......@@ -296,7 +297,7 @@ void WindowsRunner::match(Plasma::RunnerContext& context)
}
// check for matching desktops by name
foreach (const QString& desktopName, m_desktopNames) {
for (const QString& desktopName : qAsConst(m_desktopNames)) {
int desktop = m_desktopNames.indexOf(desktopName) +1;
if (desktopName.contains(term, Qt::CaseInsensitive)) {
// desktop name matches - offer switch to
......
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