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

Port foreach/forever

parent ef5e1f65
......@@ -63,11 +63,7 @@ void FileAnalyzer::deleteLogFiles()
watchLogFiles(false);
// Remove the watching on the monitored files
foreach (LogFileReader *logFileReader, mLogFileReaders) {
logDebug() << "Remove file : " << logFileReader->logFile().url().toLocalFile();
delete logFileReader;
}
qDeleteAll(mLogFileReaders);
mLogFileReaders.clear();
}
......
......@@ -84,24 +84,16 @@ Globals::Globals()
Globals::~Globals()
{
foreach (LogModeAction *logModeAction, d->mLogModeActions) {
delete logModeAction;
}
qDeleteAll(d->mLogModeActions);
d->mLogModeActions.clear();
foreach (LogMode *logMode, d->mLogModes) {
delete logMode;
}
qDeleteAll(d->mLogModes);
d->mLogModes.clear();
foreach (LogLevel *logLevel, d->mLogLevels) {
delete logLevel;
}
qDeleteAll(d->mLogLevels);
d->mLogLevels.clear();
foreach (LogModeFactory *factory, d->mFactories) {
delete factory;
}
qDeleteAll(d->mFactories);
d->mFactories.clear();
delete d;
......@@ -262,13 +254,11 @@ LogMode *Globals::findLogMode(const QString &logModeName)
void Globals::recreateLogModeActions()
{
// Delete existing log mode actions.
foreach (LogModeAction *logModeAction, d->mLogModeActions) {
delete logModeAction;
}
qDeleteAll(d->mLogModeActions);
d->mLogModeActions.clear();
// Create new log mode action for each log mode.
foreach (LogModeFactory *factory, d->mFactories) {
for (LogModeFactory *factory : qAsConst(d->mFactories)) {
LogModeAction *logModeAction = factory->createLogModeAction();
if (logModeAction) {
d->mLogModeActions.append(logModeAction);
......
......@@ -118,7 +118,7 @@ void KioLogFileReader::dataReceived(KIO::Job *job, const QByteArray &data)
void KioLogFileReader::emitCompleteLines()
{
int endLinePos = mBuffer.indexOf(QLatin1String("\n"));
forever {
while (1) {
if (endLinePos == -1) {
break;
}
......
......@@ -74,7 +74,8 @@ bool LogViewModel::isEmpty() const
void LogViewModel::removeRecentStatusOfLogLines()
{
// The older lines are no longer recent
foreach (LogViewWidgetItem *item, mLogViewWidget->items()) {
const auto items = mLogViewWidget->items();
for (LogViewWidgetItem *item : items) {
item->logLine()->setRecent(false);
}
}
......@@ -194,7 +195,8 @@ void LogViewModel::removeOldestLogLine()
mOldestItem = nullptr;
// Find the next oldest item
foreach (LogViewWidgetItem *item, mLogViewWidget->items()) {
const auto items{mLogViewWidget->items()};
for (LogViewWidgetItem *item : items) {
if (!mOldestItem) {
mOldestItem = item;
continue;
......
......@@ -203,7 +203,7 @@ void ProcessOutputLogFileReader::logFileModified()
// Parse buffer
int endLinePos = d->mBuffer.indexOf(QLatin1String("\n"));
forever {
while (1) {
if (endLinePos == -1) {
break;
}
......
......@@ -260,7 +260,8 @@ void MainWindow::updateReloading()
mTabs->changeReloadingTab(currentView, !enabled);
// Enables/Disables all Log Mode menus (useful for multiple actions menus)
foreach (LogModeAction *logModeAction, Globals::instance().logModeActions()) {
const auto logModeActions{Globals::instance().logModeActions()};
for (LogModeAction *logModeAction : logModeActions) {
logModeAction->actionMenu()->setEnabled(enabled);
}
}
......@@ -300,7 +301,8 @@ void MainWindow::toggleItemTooltip(bool enabled)
{
KSystemLogConfig::setTooltipEnabled(enabled);
foreach (LogManager *manager, mTabs->logManagers()) {
const auto logManagers{mTabs->logManagers()};
for (LogManager *manager : logManagers) {
manager->usedView()->logViewWidget()->toggleToolTip(enabled);
}
}
......@@ -364,7 +366,8 @@ void MainWindow::changeResumePauseAction(bool paused)
}
// Be sure that the button will always have a good size
foreach (QWidget *widget, mResumePauseAction->associatedWidgets()) {
const auto associatedWidgets{mResumePauseAction->associatedWidgets()};
for (QWidget *widget : associatedWidgets) {
if (widget->sizeHint().width() > widget->size().width()) {
widget->setMinimumSize(widget->sizeHint());
}
......@@ -487,7 +490,8 @@ void MainWindow::toggleFilterBar()
{
logDebug() << "Toggling filter bar..." << mFilterBarAction->isChecked();
foreach (LogManager *manager, mTabs->logManagers()) {
const auto logManagers{mTabs->logManagers()};
for (LogManager *manager : logManagers) {
manager->usedView()->toggleLogViewFilter(mFilterBarAction->isChecked());
}
......@@ -727,7 +731,8 @@ void MainWindow::selectLogModeAction(bool)
logDebug() << "Selected action" << selectedModeId;
LogMode *currentMode = nullptr;
foreach (LogMode *logMode, Globals::instance().logModes()) {
const auto logModes{Globals::instance().logModes()};
for (LogMode *logMode : logModes) {
if (logMode->id() == selectedModeId) {
currentMode = logMode;
break;
......@@ -763,7 +768,8 @@ void MainWindow::setupLogModeMenu()
auto servicesAction = new KActionMenu(QIcon::fromTheme(QStringLiteral("preferences-system-session-services")), i18n("Services"), this);
auto othersAction = new KActionMenu(QIcon::fromTheme(QStringLiteral("preferences-other")), i18n("Others"), this);
foreach (LogModeAction *logModeAction, Globals::instance().logModeActions()) {
const auto logModeActions{Globals::instance().logModeActions()};
for (LogModeAction *logModeAction : logModeActions) {
if (logModeAction->category() == LogModeAction::RootCategory) {
menuLogModeActions.append(logModeAction->actionMenu());
} else if (logModeAction->category() == LogModeAction::ServicesCategory) {
......@@ -791,8 +797,10 @@ void MainWindow::setupLogModeMenu()
void MainWindow::setupLogActions()
{
// Sets up log mode actions.
foreach (LogModeAction *logModeAction, Globals::instance().logModeActions()) {
foreach (QAction *action, logModeAction->innerActions()) {
const auto logModeActions{Globals::instance().logModeActions()};
for (LogModeAction *logModeAction : logModeActions) {
const auto innerActions{logModeAction->innerActions()};
for (QAction *action : innerActions) {
ActionData actionData = action->data().value<ActionData>();
if (actionData.addToActionCollection) {
logDebug() << "Adding action" << actionData.id;
......
......@@ -85,11 +85,7 @@ void AuditAnalyzer::deleteLogFiles()
watchLogFiles(false);
// Remove the watching on the monitored files
foreach (LogFileReader *logFileReader, mLogFileReaders) {
logDebug() << "Remove file : " << logFileReader->logFile().url().path();
delete logFileReader;
}
qDeleteAll(mLogFileReaders);
mLogFileReaders.clear();
}
......
......@@ -117,7 +117,8 @@ void LogLevelFileList::changeItemType()
LogLevelSelectionDialog logLevelSelectionDialog(this);
QListWidget *logLevels = logLevelSelectionDialog.logLevels();
foreach (LogLevel *level, Globals::instance().logLevels()) {
const auto logLevelsItems{Globals::instance().logLevels()};
for (LogLevel *level : logLevelsItems) {
logLevels->addItem(new QListWidgetItem(level->icon(), level->name()));
}
......
......@@ -344,8 +344,8 @@ void MultipleFileList::removeAllItems()
while (*it) {
QTreeWidgetItem *item = *it;
QList<QTreeWidgetItem *> children = item->takeChildren();
foreach (QTreeWidgetItem *childItem, children) {
const QList<QTreeWidgetItem *> children = item->takeChildren();
for (QTreeWidgetItem *childItem : children) {
delete childItem;
}
......
......@@ -232,7 +232,7 @@ QList<JournaldLocalAnalyzer::JournalEntry> JournaldLocalAnalyzer::readJournal(co
if (prepareJournalReading(journal, filters)) {
// Iterate over filtered entries.
forever {
while (1) {
JournalEntry entry;
res = sd_journal_next(journal);
if (res < 0) {
......
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