Commit 344bdbd4 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Constify

parent 9dbac498
......@@ -106,7 +106,8 @@ void LogViewWidget::setColumns(const LogViewColumns &columns)
// Add new actions
int columnIndex = 0;
foreach (const LogViewColumn &column, columns.columns()) {
const auto columnsLst = columns.columns();
for (const LogViewColumn &column : columnsLst) {
auto *action = new QAction(this);
action->setText(column.columnName());
// helloAction->setIcon(QIcon::fromTheme( QLatin1String( "media-playback-start" )));
......@@ -289,7 +290,7 @@ int LogViewWidget::notHiddenItemCount()
int count = 0;
QTreeWidgetItemIterator it(this, QTreeWidgetItemIterator::NotHidden);
while (*it != nullptr) {
while (*it) {
count++;
++it;
}
......
......@@ -33,14 +33,14 @@
class ProcessOutputLogFileReaderPrivate : public LogFileReaderPrivate
{
public:
long previousLinesCount;
long mPreviousLinesCount;
QTimer processUpdater;
QTimer mProcessUpdater;
QProcess *process = nullptr;
QProcess *mProcess = nullptr;
QString buffer;
QStringList availableStandardOutput;
QString mBuffer;
QStringList mAvailableStandardOutput;
};
ProcessOutputLogFileReader::ProcessOutputLogFileReader(const LogFile &logFile)
......@@ -65,12 +65,12 @@ void ProcessOutputLogFileReader::init()
Q_D(ProcessOutputLogFileReader);
// Init current file position
d->previousLinesCount = 0;
d->availableStandardOutput.clear();
d->process = nullptr;
d->mPreviousLinesCount = 0;
d->mAvailableStandardOutput.clear();
d->mProcess = nullptr;
d->processUpdater.setInterval(PROCESS_OUTPUT_UPDATER_INTERVAL);
connect(&(d->processUpdater), &QTimer::timeout, this, &ProcessOutputLogFileReader::startProcess);
d->mProcessUpdater.setInterval(PROCESS_OUTPUT_UPDATER_INTERVAL);
connect(&(d->mProcessUpdater), &QTimer::timeout, this, &ProcessOutputLogFileReader::startProcess);
logDebug() << "Using process name " << d->logFile.url().toLocalFile();
}
......@@ -83,16 +83,16 @@ void ProcessOutputLogFileReader::watchFile(bool enable)
logDebug() << "Monitoring process : " << d->logFile.url().toLocalFile();
// Reinit current file position
d->previousLinesCount = 0;
d->mPreviousLinesCount = 0;
// Launch the timer
d->processUpdater.start();
d->mProcessUpdater.start();
// Launch immediately the process updater
startProcess();
} else {
// Stop regularly start process
d->processUpdater.stop();
d->mProcessUpdater.stop();
}
}
......@@ -110,14 +110,14 @@ void ProcessOutputLogFileReader::startProcess()
logDebug() << "Starting process...";
d->process = new QProcess();
connect(d->process, &QProcess::readyReadStandardOutput, this, &ProcessOutputLogFileReader::logFileModified);
connect(d->process, SIGNAL(finished(int,QProcess::ExitStatus)), this,
d->mProcess = new QProcess();
connect(d->mProcess, &QProcess::readyReadStandardOutput, this, &ProcessOutputLogFileReader::logFileModified);
connect(d->mProcess, SIGNAL(finished(int,QProcess::ExitStatus)), this,
SLOT(emitProcessOutput(int,QProcess::ExitStatus)));
d->process->start(d->logFile.url().toLocalFile(), QStringList(), QIODevice::ReadOnly | QIODevice::Text);
d->mProcess->start(d->logFile.url().toLocalFile(), QStringList(), QIODevice::ReadOnly | QIODevice::Text);
d->process->waitForStarted();
d->mProcess->waitForStarted();
logDebug() << "Process started";
}
......@@ -129,15 +129,15 @@ void ProcessOutputLogFileReader::closeProcess()
Q_D(ProcessOutputLogFileReader);
// Get the size file for the next calculation
d->previousLinesCount = d->availableStandardOutput.count();
logDebug() << "New lines count : " << d->previousLinesCount << " (" << d->logFile.url().toLocalFile() << ")";
d->mPreviousLinesCount = d->mAvailableStandardOutput.count();
logDebug() << "New lines count : " << d->mPreviousLinesCount << " (" << d->logFile.url().toLocalFile() << ")";
d->availableStandardOutput.clear();
d->mAvailableStandardOutput.clear();
if (d->process) {
d->process->close();
delete d->process;
d->process = nullptr;
if (d->mProcess) {
d->mProcess->close();
delete d->mProcess;
d->mProcess = nullptr;
}
logDebug() << "Process closed";
......@@ -150,8 +150,8 @@ void ProcessOutputLogFileReader::emitProcessOutput(int /*exitCode*/, QProcess::E
// First commit last lines of the buffer to the line list
emptyBuffer();
logDebug() << "Process terminated" << d->previousLinesCount << "previously /"
<< d->availableStandardOutput.count() << "currently";
logDebug() << "Process terminated" << d->mPreviousLinesCount << "previously /"
<< d->mAvailableStandardOutput.count() << "currently";
if (exitStatus == QProcess::CrashExit) {
QString message(i18n("The process '%1' crashed.", d->logFile.url().toLocalFile()));
......@@ -160,21 +160,21 @@ void ProcessOutputLogFileReader::emitProcessOutput(int /*exitCode*/, QProcess::E
}
// If there is no new lines
if (d->previousLinesCount == d->availableStandardOutput.count()) {
if (d->mPreviousLinesCount == d->mAvailableStandardOutput.count()) {
/*
//Q_EMIT an empty log lines list
Q_EMIT contentChanged(this, false, QStringList());
*/
}
// If there are new lines in the file, insert only them or this is the first time we read this file
else if (d->previousLinesCount != 0 && d->previousLinesCount <= d->availableStandardOutput.count()) {
logDebug() << "Reading from line " << d->previousLinesCount << " (" << d->logFile.url().toLocalFile() << ")";
else if (d->mPreviousLinesCount != 0 && d->mPreviousLinesCount <= d->mAvailableStandardOutput.count()) {
logDebug() << "Reading from line " << d->mPreviousLinesCount << " (" << d->logFile.url().toLocalFile() << ")";
QStringList newOutputs;
int index = d->previousLinesCount - 1;
while (index < d->availableStandardOutput.count()) {
newOutputs.append(d->availableStandardOutput.at(index));
int index = d->mPreviousLinesCount - 1;
while (index < d->mAvailableStandardOutput.count()) {
newOutputs.append(d->mAvailableStandardOutput.at(index));
++index;
}
......@@ -187,7 +187,7 @@ void ProcessOutputLogFileReader::emitProcessOutput(int /*exitCode*/, QProcess::E
else {
logDebug() << "New process or process already read. Reading entire content";
Q_EMIT contentChanged(this, Analyzer::FullRead, d->availableStandardOutput);
Q_EMIT contentChanged(this, Analyzer::FullRead, d->mAvailableStandardOutput);
}
closeProcess();
......@@ -200,24 +200,24 @@ void ProcessOutputLogFileReader::logFileModified()
logDebug() << "Content available on process output...";
// New added lines
QByteArray bytesOutput = d->process->readAllStandardOutput();
d->buffer.append(QLatin1String(bytesOutput));
QByteArray bytesOutput = d->mProcess->readAllStandardOutput();
d->mBuffer.append(QLatin1String(bytesOutput));
// Parse buffer
int endLinePos = d->buffer.indexOf(QLatin1String("\n"));
int endLinePos = d->mBuffer.indexOf(QLatin1String("\n"));
forever {
if (endLinePos == -1) {
break;
}
// Add the new found lines and
d->availableStandardOutput.append(d->buffer.left(endLinePos));
d->buffer.remove(0, endLinePos + 1);
d->mAvailableStandardOutput.append(d->mBuffer.left(endLinePos));
d->mBuffer.remove(0, endLinePos + 1);
endLinePos = d->buffer.indexOf(QLatin1String("\n"));
endLinePos = d->mBuffer.indexOf(QLatin1String("\n"));
}
logDebug() << "Received a total of" << d->availableStandardOutput.count() << "new lines";
logDebug() << "Received a total of" << d->mAvailableStandardOutput.count() << "new lines";
}
/**
......@@ -228,9 +228,9 @@ void ProcessOutputLogFileReader::emptyBuffer()
{
Q_D(ProcessOutputLogFileReader);
if (d->buffer.isEmpty() == false) {
if (d->mBuffer.isEmpty() == false) {
logWarning() << "Buffer was not empty !!";
d->availableStandardOutput.append(d->buffer);
d->buffer.clear();
d->mAvailableStandardOutput.append(d->mBuffer);
d->mBuffer.clear();
}
}
......@@ -47,8 +47,7 @@ SimpleAction::~SimpleAction()
QList<QAction *> SimpleAction::innerActions()
{
QList<QAction *> actions;
actions.append(mAction);
const QList<QAction *> actions {mAction};
return actions;
}
......
......@@ -163,7 +163,7 @@ QSize View::sizeHint() const
void View::dropEvent(QDropEvent *event)
{
QList<QUrl> urls = event->mimeData()->urls();
const QList<QUrl> urls = event->mimeData()->urls();
// If URLs have been dropped
if (!urls.isEmpty()) {
......
......@@ -55,17 +55,17 @@ LogLine *AcpidAnalyzer::parseMessage(const QString &logLine, const LogFile &orig
date = QDate::currentDate();
time = QTime::currentTime();
} else {
QString strDate = line.mid(dateBegin + 1, dateEnd - dateBegin - 1);
const QString strDate = line.mid(dateBegin + 1, dateEnd - dateBegin - 1);
QString month = strDate.mid(4, 3);
const QString month = strDate.mid(4, 3);
QString day = strDate.mid(8, 2);
const QString day = strDate.mid(8, 2);
QString hour = strDate.mid(11, 2);
QString min = strDate.mid(14, 2);
QString sec = strDate.mid(17, 2);
const QString hour = strDate.mid(11, 2);
const QString min = strDate.mid(14, 2);
const QString sec = strDate.mid(17, 2);
QString year = strDate.mid(20, 4);
const QString year = strDate.mid(20, 4);
date = QDate(year.toInt(), ParsingHelper::instance()->parseSyslogMonth(month), day.toInt());
time = QTime(hour.toInt(), min.toInt(), sec.toInt());
......
......@@ -25,8 +25,7 @@ AcpidConfiguration::AcpidConfiguration()
{
mConfiguration->setCurrentGroup(QStringLiteral("AcpidLogMode"));
QStringList defaultAcpidPaths;
defaultAcpidPaths << QStringLiteral("/var/log/acpid");
const QStringList defaultAcpidPaths {QStringLiteral("/var/log/acpid")};
mConfiguration->addItemStringList(QStringLiteral("LogFilesPaths"), mAcpidPaths, defaultAcpidPaths,
QStringLiteral("LogFilesPaths"));
}
......
......@@ -60,7 +60,7 @@ void AcpidConfigurationWidget::defaultConfig()
bool AcpidConfigurationWidget::isValid() const
{
if (mFileList->isEmpty() == false) {
if (!mFileList->isEmpty()) {
return true;
}
......
......@@ -72,17 +72,17 @@ LogLine *ApacheAnalyzer::parseMessage(const QString &logLine, const LogFile &ori
QString type;
QString message;
QString strDate = line.mid(dateBegin + 1, dateEnd - dateBegin - 1);
const QString strDate = line.mid(dateBegin + 1, dateEnd - dateBegin - 1);
QString month = strDate.mid(4, 3);
const QString month = strDate.mid(4, 3);
QString day = strDate.mid(8, 2);
const QString day = strDate.mid(8, 2);
QString hour = strDate.mid(11, 2);
QString min = strDate.mid(14, 2);
QString sec = strDate.mid(17, 2);
const QString hour = strDate.mid(11, 2);
const QString min = strDate.mid(14, 2);
const QString sec = strDate.mid(17, 2);
QString year = strDate.mid(20, 4);
const QString year = strDate.mid(20, 4);
date = QDate(year.toInt(), ParsingHelper::instance()->parseSyslogMonth(month), day.toInt());
time = QTime(hour.toInt(), min.toInt(), sec.toInt());
......
......@@ -25,13 +25,11 @@ ApacheConfiguration::ApacheConfiguration()
{
mConfiguration->setCurrentGroup(QStringLiteral("ApacheLogMode"));
QStringList defaultApachePaths;
defaultApachePaths << QStringLiteral("/var/log/apache2/error.log");
const QStringList defaultApachePaths {QStringLiteral("/var/log/apache2/error.log")};
mConfiguration->addItemStringList(QStringLiteral("ApacheLogFilesPaths"), mApachePaths,
defaultApachePaths, QStringLiteral("ApacheLogFilesPaths"));
QStringList defaultApacheAccessPaths;
defaultApacheAccessPaths << QStringLiteral("/var/log/apache2/access.log");
const QStringList defaultApacheAccessPaths {QStringLiteral("/var/log/apache2/access.log")};
mConfiguration->addItemStringList(QStringLiteral("ApacheAccessLogFilesPaths"), mApacheAccessPaths,
defaultApacheAccessPaths,
QStringLiteral("ApacheAccessLogFilesPaths"));
......
......@@ -71,7 +71,7 @@ void ApacheConfigurationWidget::readConfig()
bool ApacheConfigurationWidget::isValid() const
{
if (mApacheFileList->isOneOfCategoryEmpty() == true) {
if (mApacheFileList->isOneOfCategoryEmpty()) {
logDebug() << "Apache configuration not valid";
return false;
}
......
......@@ -52,8 +52,8 @@ LogModeAction *ApacheLogModeFactory::createLogModeAction() const
LogMode *apacheLogMode = Globals::instance().findLogMode(QStringLiteral(APACHE_LOG_MODE_ID));
LogMode *apacheAccessLogMode = Globals::instance().findLogMode(QStringLiteral(APACHE_ACCESS_LOG_MODE_ID));
bool apacheLogsExist = apacheLogMode->filesExist();
bool apacheAccessLogsExist = apacheAccessLogMode->filesExist();
const bool apacheLogsExist = apacheLogMode->filesExist();
const bool apacheAccessLogsExist = apacheAccessLogMode->filesExist();
if (!apacheLogsExist && !apacheAccessLogsExist) {
return nullptr;
......
......@@ -30,7 +30,7 @@ LogLine *AuthenticationAnalyzer::parseMessage(const QString &logLine, const LogF
{
LogLine *syslogLine = SyslogAnalyzer::parseMessage(logLine, originalLogFile);
QString message = syslogLine->logItems().at(syslogLine->logItems().count() - 1);
const QString message = syslogLine->logItems().at(syslogLine->logItems().count() - 1);
if (hasErrorKeywords(message)) {
syslogLine->setLogLevel(Globals::instance().errorLogLevel());
......
......@@ -25,17 +25,15 @@ AuthenticationConfiguration::AuthenticationConfiguration()
{
mConfiguration->setCurrentGroup(QStringLiteral("AuthenticationLogMode"));
QString defaultAuthenticationPath(QStringLiteral("/var/log/auth.log"));
const QString defaultAuthenticationPath{QStringLiteral("/var/log/auth.log")};
mConfiguration->addItemString(QStringLiteral("LogFilePath"), mAuthenticationPath,
defaultAuthenticationPath, QStringLiteral("LogFilePath"));
QStringList defaultWarningKeywords;
defaultWarningKeywords.append(QStringLiteral("failed"));
const QStringList defaultWarningKeywords {QStringLiteral("failed")};
mConfiguration->addItemStringList(QStringLiteral("WarningKeywords"), mWarningKeywords,
defaultWarningKeywords, QStringLiteral("WarningKeywords"));
QStringList defaultErrorKeywords;
defaultErrorKeywords.append(QStringLiteral("error"));
const QStringList defaultErrorKeywords{QStringLiteral("error")};
mConfiguration->addItemStringList(QStringLiteral("ErrorKeywords"), mErrorKeywords,
defaultErrorKeywords, QStringLiteral("ErrorKeywords"));
}
......
......@@ -80,8 +80,8 @@ void AuthenticationConfigurationWidget::readConfig()
.findLogMode(QStringLiteral(AUTHENTICATION_LOG_MODE_ID))
->logModeConfiguration<AuthenticationConfiguration *>();
QString path = authenticationConfiguration->authenticationPath();
QFileInfo fileInfo(path);
const QString path = authenticationConfiguration->authenticationPath();
const QFileInfo fileInfo(path);
mWarningBox->setVisible(!fileInfo.exists());
mAuthenticationUrlRequester->setUrl(QUrl::fromLocalFile(path));
......
......@@ -64,7 +64,6 @@ QList<LogFile> AuthenticationLogMode::createLogFiles()
{
auto *configuration = logModeConfiguration<AuthenticationConfiguration *>();
QList<LogFile> logFiles;
logFiles.append(configuration->findGenericLogFile(configuration->authenticationPath()));
const QList<LogFile> logFiles {configuration->findGenericLogFile(configuration->authenticationPath())};
return logFiles;
}
......@@ -135,7 +135,7 @@ void FileList::modifyItem(QListWidgetItem *item)
const QStringList paths = mFileListHelper.findPaths(urls);
// We only take the first path
if (paths.count() >= 1) {
if (!paths.isEmpty()) {
item->setText(paths.at(0));
}
......
......@@ -29,13 +29,6 @@
#include "globals.h"
#include "ksystemlogConfig.h"
class GenericLogModeConfigurationPrivate
{
public:
};
GenericLogModeConfiguration::GenericLogModeConfiguration(const QString &configurationGroup, const QStringList &defaultLogFilesPaths, const QList<int> &defaultLogFilesLevels)
{
logDebug() << "Using Configuration Group : " << configurationGroup;
......@@ -87,8 +80,8 @@ QList<LogFile> GenericLogModeConfiguration::findGenericLogFiles() const
QListIterator<int> itInt(mLogFilesLevels);
while (itString.hasNext()) {
int intValue = itInt.next();
QString stringValue = itString.next();
const int intValue = itInt.next();
const QString stringValue = itString.next();
if (intValue >= 0 && intValue < static_cast<int>(Globals::instance().logLevels().count())) {
level = Globals::instance().logLevels().at(intValue);
......
......@@ -144,7 +144,7 @@ void MultipleFileList::updateButtons()
bool MultipleFileList::isFileListsEmpty() const
{
for (int i = 0; i < fileList->topLevelItemCount(); ++i) {
for (int i = 0, total = fileList->topLevelItemCount(); i < total; ++i) {
if (categoryCount(i) != 0) {
logDebug() << "Is not empty";
return false;
......@@ -157,7 +157,7 @@ bool MultipleFileList::isFileListsEmpty() const
bool MultipleFileList::isOneOfCategoryEmpty() const
{
for (int i = 0; i < fileList->topLevelItemCount(); ++i) {
for (int i = 0, total = fileList->topLevelItemCount(); i < total; ++i) {
if (categoryCount(i) == 0) {
logDebug() << "A category is empty";
return true;
......@@ -177,7 +177,7 @@ int MultipleFileList::categoryCount(int index) const
}
int count = 0;
for (int i = 0; i < item->childCount(); ++i) {
for (int i = 0, total = item->childCount(); i < total; ++i) {
QTreeWidgetItem *childItem = item->child(i);
if (isEmptyItem(childItem) == false) {
count++;
......@@ -220,7 +220,7 @@ void MultipleFileList::addItem(int category)
logDebug() << "Adding item" << category;
// Open a standard Filedialog
QList<QUrl> urls = mFileListHelper.openUrls();
const QList<QUrl> urls = mFileListHelper.openUrls();
QTreeWidgetItem *categoryItem = fileList->topLevelItem(category);
......@@ -253,7 +253,7 @@ QTreeWidgetItem *MultipleFileList::findCategoryOfChild(QTreeWidgetItem *childIte
{
logDebug() << "Finding Category of" << childItem->text(0);
for (int i = 0; i < fileList->topLevelItemCount(); ++i) {
for (int i = 0, total = fileList->topLevelItemCount(); i < total; ++i) {
QTreeWidgetItem *item = fileList->topLevelItem(i);
if (item->indexOfChild(childItem) != -1) {
......@@ -377,7 +377,7 @@ void MultipleFileList::updateEmptyItems()
logDebug() << "Adding empty items...";
for (int i = 0; i < fileList->topLevelItemCount(); ++i) {
for (int i = 0, total = fileList->topLevelItemCount(); i < total; ++i) {
QTreeWidgetItem *categoryItem = fileList->topLevelItem(i);
// If it's a category item and it's empty
......@@ -457,7 +457,7 @@ QStringList MultipleFileList::paths(int category)
QTreeWidgetItemIterator it(fileList, QTreeWidgetItemIterator::All);
QStringList paths;
while (*it != nullptr) {
while (*it) {
QTreeWidgetItem *item = *it;
if (categoryItem->indexOfChild(item) != -1) {
......
......@@ -55,7 +55,7 @@ LogLine *CronAnalyzer::parseMessage(const QString &logLine, const LogFile &origi
int leftBracket = message.indexOf(QLatin1Char('('));
int rightBracket = message.indexOf(QLatin1Char(')'));
QString user = message.mid(leftBracket + 1, rightBracket - leftBracket - 1);
const QString user = message.mid(leftBracket + 1, rightBracket - leftBracket - 1);
list.append(user);
......
......@@ -25,12 +25,11 @@ CronConfiguration::CronConfiguration()
{
mConfiguration->setCurrentGroup(QStringLiteral("CronLogMode"));
QStringList defaultCronPaths;
defaultCronPaths << QStringLiteral("/var/log/syslog");
const QStringList defaultCronPaths{QStringLiteral("/var/log/syslog")};
mConfiguration->addItemStringList(QStringLiteral("LogFilesPaths"), mCronPaths, defaultCronPaths,
QStringLiteral("LogFilesPaths"));
QString defaultProcessFilter(QStringLiteral("/usr/sbin/cron"));
const QString defaultProcessFilter(QStringLiteral("/usr/sbin/cron"));
mConfiguration->addItemString(QStringLiteral("ProcessFilter"), mProcessFilter, defaultProcessFilter,
QStringLiteral("ProcessFilter"));
}
......
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