Commit e60894f8 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Port away from foreach

Test Plan: builds, energy saving kcm opens fine

Reviewers: #plasma, apol

Reviewed By: apol

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D24242
parent d4558f9e
......@@ -69,6 +69,7 @@ include_directories (
)
add_definitions(-DQT_NO_KEYWORDS)
add_definitions(-DQT_NO_FOREACH)
if (EXISTS "${CMAKE_SOURCE_DIR}/.git")
add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000)
endif()
......
......@@ -93,7 +93,7 @@ QList< QPair< QString, QWidget* > > HandleButtonEventsConfig::buildUi()
QList<QComboBox *> boxes;
boxes << m_lidCloseCombo << m_powerButtonCombo;
Q_FOREACH (QComboBox *box, boxes) {
for (QComboBox *box : qAsConst(boxes)) {
box->addItem(QIcon::fromTheme("dialog-cancel"), i18n("Do nothing"), (uint)SuspendSession::None);
if (PowerManagement::instance()->canSuspend()) {
box->addItem(QIcon::fromTheme("system-suspend"), i18nc("Suspend to RAM", "Sleep"), (uint)SuspendSession::ToRamMode);
......
......@@ -69,13 +69,13 @@ void BacklightHelper::initUsingBacklightType()
backlightDir.setFilter(QDir::AllDirs | QDir::NoDot | QDir::NoDotDot | QDir::NoDotAndDotDot | QDir::Readable);
backlightDir.setSorting(QDir::Name | QDir::Reversed);// Reverse is needed to priorize acpi_video1 over 0
QStringList interfaces = backlightDir.entryList();
const QStringList interfaces = backlightDir.entryList();
QFile file;
QByteArray buffer;
QStringList firmware, platform, raw, leds;
Q_FOREACH(const QString & interface, interfaces) {
for (const QString & interface : interfaces) {
file.setFileName(BACKLIGHT_SYSFS_PATH + interface + "/type");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
continue;
......
......@@ -350,7 +350,7 @@ void PowerDevilUPowerBackend::initWithBrightness(bool screenBrightnessAvailable)
}
// battery
Q_FOREACH(OrgFreedesktopUPowerDeviceInterface * upowerDevice, m_devices) {
for (const OrgFreedesktopUPowerDeviceInterface * upowerDevice : qAsConst(m_devices)) {
if (upowerDevice->type() == 2 && upowerDevice->powerSupply()) {
QString udi = upowerDevice->path();
setCapacityForBattery(udi, qRound(upowerDevice->capacity())); // acknowledge capacity
......@@ -547,8 +547,8 @@ void PowerDevilUPowerBackend::enumerateDevices()
m_lidIsClosed = m_upowerInterface->lidIsClosed();
m_onBattery = m_upowerInterface->onBattery();
QList<QDBusObjectPath> deviceList = m_upowerInterface->EnumerateDevices();
Q_FOREACH (const QDBusObjectPath & device, deviceList) {
const QList<QDBusObjectPath> deviceList = m_upowerInterface->EnumerateDevices();
for (const QDBusObjectPath & device : deviceList) {
addDevice(device.path());
}
......@@ -625,7 +625,7 @@ void PowerDevilUPowerBackend::updateDeviceProps()
qreal energyFullTotal = 0.0;
uint stateTotal = 0;
Q_FOREACH(OrgFreedesktopUPowerDeviceInterface * upowerDevice, m_devices) {
for (const OrgFreedesktopUPowerDeviceInterface * upowerDevice : qAsConst(m_devices)) {
const uint type = upowerDevice->type();
if (( type == 2 || type == 3) && upowerDevice->powerSupply()) {
const uint state = upowerDevice->state();
......
......@@ -62,7 +62,7 @@ void ClientPrivate::setWatchedSubsystems(const QStringList &subsystemList)
}
// apply our filters; an empty list means listen to everything
Q_FOREACH (const QString& subsysDevtype, subsystemList) {
for (const QString& subsysDevtype : subsystemList) {
int ix = subsysDevtype.indexOf(u'/');
if (ix > 0) {
......
......@@ -92,9 +92,9 @@ void ActionPool::clearCache()
void ActionPool::init(PowerDevil::Core *parent)
{
// Load all the actions
KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("PowerDevil/Action"),
const KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("PowerDevil/Action"),
QStringLiteral("[X-KDE-PowerDevil-Action-IsBundled] == FALSE"));
Q_FOREACH (KService::Ptr offer, offers) {
for (const KService::Ptr offer : offers) {
QString actionId = offer->property(QStringLiteral("X-KDE-PowerDevil-Action-ID"), QVariant::String).toString();
qCDebug(POWERDEVIL) << "Got a valid offer for " << actionId;
......@@ -149,9 +149,9 @@ void ActionPool::init(PowerDevil::Core *parent)
// Register DBus objects
{
KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("PowerDevil/Action"),
const KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("PowerDevil/Action"),
QStringLiteral("[X-KDE-PowerDevil-Action-RegistersDBusInterface] == TRUE"));
Q_FOREACH (KService::Ptr offer, offers) {
for (const KService::Ptr offer : offers) {
QString actionId = offer->property(QStringLiteral("X-KDE-PowerDevil-Action-ID"), QVariant::String).toString();
if (m_actionPool.contains(actionId)) {
......@@ -190,7 +190,7 @@ Action* ActionPool::loadAction(const QString& actionId, const KConfigGroup& grou
void ActionPool::unloadAllActiveActions()
{
Q_FOREACH (const QString &action, m_activeActions) {
for (const QString &action : qAsConst(m_activeActions)) {
m_actionPool[action]->onProfileUnload();
m_actionPool[action]->unloadAction();
}
......
......@@ -101,7 +101,7 @@ void PowerDevilApp::init()
}
QFileInfo backendFileInfo;
Q_FOREACH (const QFileInfo &f, fileInfos) {
for (const QFileInfo &f : qAsConst(fileInfos)) {
if (f.baseName().toLower() == QLatin1String("powerdevilupowerbackend")) {
backendFileInfo = f;
break;
......
......@@ -129,7 +129,8 @@ void Core::onBackendReady()
this, SLOT(onDeviceRemoved(QString)));
// Force the addition of already existent batteries
Q_FOREACH (const Device &device, Device::listFromType(DeviceInterface::Battery, QString())) {
const auto devices = Device::listFromType(DeviceInterface::Battery, QString());
for (const Device &device : devices) {
onDeviceAdded(device.udi());
}
}
......@@ -350,7 +351,8 @@ void Core::loadProfile(bool force)
}
// Cool, now let's load the needed actions
Q_FOREACH (const QString &actionName, config.groupList()) {
const auto groupList = config.groupList();
for (const QString &actionName : groupList) {
Action *action = ActionPool::instance()->loadAction(actionName, config.group(actionName), this);
if (action) {
action->onProfileLoad();
......@@ -797,9 +799,9 @@ void Core::registerActionTimeout(Action* action, int timeout)
void Core::unregisterActionTimeouts(Action* action)
{
// Clear all timeouts from the action
QList< int > timeoutsToClean = m_registeredActionTimeouts[action];
const QList< int > timeoutsToClean = m_registeredActionTimeouts[action];
Q_FOREACH (int id, timeoutsToClean) {
for (int id : timeoutsToClean) {
KIdleTime::instance()->removeIdleTimeout(id);
}
......
......@@ -654,8 +654,8 @@ bool PolicyAgent::HasInhibition(/*PolicyAgent::RequiredPolicies*/ uint types)
void PolicyAgent::releaseAllInhibitions()
{
QList< uint > allCookies = m_cookieToAppName.keys();
Q_FOREACH (uint cookie, allCookies) {
const QList< uint > allCookies = m_cookieToAppName.keys();
for (uint cookie : allCookies) {
ReleaseInhibition(cookie);
}
}
......
......@@ -46,7 +46,8 @@ void ProfileGenerator::generateProfiles(bool toRam, bool toDisk)
KSharedConfigPtr profilesConfig = KSharedConfig::openConfig("powermanagementprofilesrc", KConfig::SimpleConfig);
// And clear it
Q_FOREACH (const QString &group, profilesConfig->groupList()) {
const QStringList groupList = profilesConfig->groupList();
for (const QString &group : groupList) {
// Don't delete activity-specific settings
if (group != "Activities") {
profilesConfig->deleteGroup(group);
......
......@@ -111,7 +111,7 @@ ActivityPage::~ActivityPage()
void ActivityPage::load()
{
Q_FOREACH (ActivityWidget *widget, m_activityWidgets) {
for (ActivityWidget *widget : qAsConst(m_activityWidgets)) {
widget->load();
}
......@@ -120,7 +120,7 @@ void ActivityPage::load()
void ActivityPage::save()
{
Q_FOREACH (ActivityWidget *widget, m_activityWidgets) {
for (ActivityWidget *widget : qAsConst(m_activityWidgets)) {
widget->save();
}
......@@ -185,7 +185,8 @@ void ActivityPage::populateTabs()
}
int index = 0;
Q_FOREACH (const QString &activity, m_activityConsumer->activities()) {
const QStringList activities = m_activityConsumer->activities();
for (const QString &activity : activities) {
KActivities::Info *info = new KActivities::Info(activity, this);
const QString icon = info->icon();
const QString name = info->name();
......
......@@ -109,7 +109,8 @@ void ActivityWidget::load()
m_ui->actLikeComboBox->addItem(QIcon::fromTheme("battery-low"), i18n("PC running on low battery"), "LowBattery");
bool hasBattery = false;
Q_FOREACH (const Solid::Device &device, Solid::Device::listFromType(Solid::DeviceInterface::Battery, QString())) {
const auto batteries = Solid::Device::listFromType(Solid::DeviceInterface::Battery, QString());
for (const Solid::Device &device : batteries) {
const Solid::Battery *b = qobject_cast<const Solid::Battery*> (device.asDeviceInterface(Solid::DeviceInterface::Battery));
if (b->type() == Solid::Battery::PrimaryBattery || b->type() == Solid::Battery::UpsBattery) {
hasBattery = false;
......@@ -120,7 +121,8 @@ void ActivityWidget::load()
m_ui->actLikeRadio->setVisible(hasBattery);
m_ui->actLikeComboBox->setVisible(hasBattery);
Q_FOREACH (const QString &activity, m_activityConsumer->activities()) {
const QStringList activities = m_activityConsumer->activities();
for (const QString &activity : activities) {
if (activity == m_activity) {
continue;
}
......
......@@ -48,9 +48,9 @@ ActionEditWidget::ActionEditWidget(const QString &configName, QWidget *parent)
QMap< int, QList<QPair<QString, QWidget*> > > widgets;
// Load all the services
KService::List offers = KServiceTypeTrader::self()->query("PowerDevil/Action", "(Type == 'Service')");
const KService::List offers = KServiceTypeTrader::self()->query("PowerDevil/Action", "(Type == 'Service')");
Q_FOREACH (const KService::Ptr &offer, offers) {
for (const KService::Ptr &offer : offers) {
// Does it have a runtime requirement?
if (offer->property("X-KDE-PowerDevil-Action-HasRuntimeRequirement", QVariant::Bool).toBool()) {
qCDebug(POWERDEVIL) << offer->name() << " has a runtime requirement";
......
......@@ -93,7 +93,8 @@ void GeneralPage::fillUi()
bool hasPowerSupplyBattery = false;
bool hasPeripheralBattery = false;
Q_FOREACH (const Solid::Device &device, Solid::Device::listFromType(Solid::DeviceInterface::Battery, QString())) {
const auto devices = Solid::Device::listFromType(Solid::DeviceInterface::Battery, QString());
for (const Solid::Device &device : devices) {
const Solid::Battery *b = qobject_cast<const Solid::Battery*> (device.asDeviceInterface(Solid::DeviceInterface::Battery));
if (b->isPowerSupply()) {
hasPowerSupplyBattery = true;
......
......@@ -115,7 +115,8 @@ EditPage::EditPage(QWidget *parent, const QVariantList &args)
connect(watcher, SIGNAL(serviceUnregistered(QString)), this, SLOT(onServiceUnregistered(QString)));
bool hasBattery = false;
Q_FOREACH(const Solid::Device &device, Solid::Device::listFromType(Solid::DeviceInterface::Battery, QString())) {
const auto batteries = Solid::Device::listFromType(Solid::DeviceInterface::Battery, QString());
for(const Solid::Device &device : batteries) {
const Solid::Battery *b = qobject_cast<const Solid::Battery*> (device.asDeviceInterface(Solid::DeviceInterface::Battery));
if (b->isPowerSupply() && (b->type() == Solid::Battery::PrimaryBattery || b->type() == Solid::Battery::UpsBattery)) {
hasBattery = true;
......
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