summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVyacheslav Matyushin <[email protected]>2015-11-08 03:02:51 +0300
committerVyacheslav Matyushin <[email protected]>2015-11-08 03:02:51 +0300
commitdd18837aed841490a3a90815fea840ad79b6079b (patch)
treeb881c4052291f4969d1ec568c763235a95fe3937
parent450faf22d8eec07e2fa58f639905477f91f473b4 (diff)
Various fixes suggested by static analyzer.
-rw-r--r--src/lib/fileAnalyzer.cpp30
-rw-r--r--src/lib/kioLogFileReader.cpp2
-rw-r--r--src/lib/localLogFileReader.cpp29
-rw-r--r--src/lib/logMode.cpp6
-rw-r--r--src/lib/logViewColumns.cpp10
-rw-r--r--src/lib/logViewColumns.h1
-rw-r--r--src/lib/logViewExport.cpp37
-rw-r--r--src/lib/logViewWidget.cpp2
-rw-r--r--src/modes/base/genericConfiguration.cpp2
-rw-r--r--src/modes/base/genericConfiguration.h2
-rw-r--r--src/modes/base/logLevelFileList.cpp8
-rw-r--r--src/modes/base/multipleFileList.cpp4
-rw-r--r--src/modes/cups/cupsAccessAnalyzer.h2
-rw-r--r--src/modes/cups/cupsPageAnalyzer.h2
-rw-r--r--src/modes/cups/cupsPdfAnalyzer.h2
-rw-r--r--src/modes/journald/journaldConfiguration.cpp4
-rw-r--r--src/modes/journald/journaldLocalAnalyzer.cpp7
17 files changed, 66 insertions, 84 deletions
diff --git a/src/lib/fileAnalyzer.cpp b/src/lib/fileAnalyzer.cpp
index 1dd1196..2e2a4ef 100644
--- a/src/lib/fileAnalyzer.cpp
+++ b/src/lib/fileAnalyzer.cpp
@@ -81,31 +81,29 @@ void FileAnalyzer::setLogFiles(const QList<LogFile> &logFiles)
LogFileReader *logFileReader = createLogFileReader(logFile);
logFileReaders.append(logFileReader);
- connect(logFileReader, &LogFileReader::contentChanged,
- this, &FileAnalyzer::logFileChanged);
+ connect(logFileReader, &LogFileReader::contentChanged, this, &FileAnalyzer::logFileChanged);
connect(logFileReader, &LogFileReader::statusBarChanged, this, &Analyzer::statusBarChanged);
- connect(logFileReader, &LogFileReader::errorOccured, this,
- &Analyzer::errorOccured);
+ connect(logFileReader, &LogFileReader::errorOccured, this, &Analyzer::errorOccured);
}
}
void FileAnalyzer::logFileChanged(LogFileReader *logFileReader, ReadingMode readingMode,
- const QStringList &content)
+ const QStringList &content)
{
+ QString filePath = logFileReader->logFile().url().path();
if (readingMode == Analyzer::FullRead)
- logDebug() << "File " << logFileReader->logFile().url().path() << " has been modified on full read.";
+ logDebug() << "File " << filePath << " has been modified on full read.";
else
- logDebug() << "File " << logFileReader->logFile().url().path()
- << " has been modified on partial read";
+ logDebug() << "File " << filePath << " has been modified on partial read";
if (parsingPaused == true) {
logDebug() << "Pause enabled. Nothing read.";
return;
}
- logDebug() << "Locking file modifications of " << logFileReader->logFile().url().path();
+ logDebug() << "Locking file modifications of " << filePath;
insertionLocking.lock();
- logDebug() << "Unlocking file modifications of " << logFileReader->logFile().url().path();
+ logDebug() << "Unlocking file modifications of " << filePath;
QTime benchmark;
benchmark.start();
@@ -117,9 +115,9 @@ void FileAnalyzer::logFileChanged(LogFileReader *logFileReader, ReadingMode read
if (readingMode == Analyzer::UpdatingRead) {
insertedLogLineCount = insertLines(content, logFileReader->logFile(), Analyzer::UpdatingRead);
} else {
- logDebug() << "Reading file " << logFileReader->logFile().url().path();
+ logDebug() << "Reading file " << filePath;
- emit statusBarChanged(i18n("Opening '%1'...", logFileReader->logFile().url().path()));
+ emit statusBarChanged(i18n("Opening '%1'...", filePath));
// Inform that we are now reading the "index" file
emit readFileStarted(*logMode, logFileReader->logFile(),
@@ -128,8 +126,7 @@ void FileAnalyzer::logFileChanged(LogFileReader *logFileReader, ReadingMode read
insertedLogLineCount = insertLines(content, logFileReader->logFile(), Analyzer::FullRead);
- emit statusBarChanged(
- i18n("Log file '%1' loaded successfully.", logFileReader->logFile().url().path()));
+ emit statusBarChanged(i18n("Log file '%1' loaded successfully.", filePath));
}
logViewModel->endingMultipleInsertions(readingMode, insertedLogLineCount);
@@ -141,14 +138,15 @@ void FileAnalyzer::logFileChanged(LogFileReader *logFileReader, ReadingMode read
emit logUpdated(insertedLogLineCount);
// Inform MainWindow status bar
- emit statusBarChanged(i18n("Log file '%1' has changed.", logFileReader->logFile().url().path()));
+ emit statusBarChanged(i18n("Log file '%1' has changed.", filePath));
logDebug() << "Updating log files in " << benchmark.elapsed() << " ms";
insertionLocking.unlock();
}
-int FileAnalyzer::insertLines(const QStringList &bufferedLines, const LogFile &logFile, ReadingMode readingMode)
+int FileAnalyzer::insertLines(const QStringList &bufferedLines, const LogFile &logFile,
+ ReadingMode readingMode)
{
logDebug() << "Inserting lines...";
diff --git a/src/lib/kioLogFileReader.cpp b/src/lib/kioLogFileReader.cpp
index c9d4443..7bb37e9 100644
--- a/src/lib/kioLogFileReader.cpp
+++ b/src/lib/kioLogFileReader.cpp
@@ -38,6 +38,8 @@ class KioLogFileReaderPrivate
public:
KioLogFileReaderPrivate(const LogFile &file)
: logFile(file)
+ , fileJob(nullptr)
+ , fileWatch(nullptr)
{
}
diff --git a/src/lib/localLogFileReader.cpp b/src/lib/localLogFileReader.cpp
index 6b364bf..107fc54 100644
--- a/src/lib/localLogFileReader.cpp
+++ b/src/lib/localLogFileReader.cpp
@@ -85,12 +85,13 @@ void LocalLogFileReader::init()
void LocalLogFileReader::watchFile(bool enable)
{
Q_D(LocalLogFileReader);
+ QString filePath = d->logFile.url().path();
if (enable == true) {
- logDebug() << "Monitoring file : " << d->logFile.url().path();
+ logDebug() << "Monitoring file : " << filePath;
- if (d->watch->contains(d->logFile.url().path()) == false) {
- d->watch->addFile(d->logFile.url().path());
+ if (d->watch->contains(filePath) == false) {
+ d->watch->addFile(filePath);
}
// Reinit current file position
@@ -99,13 +100,14 @@ void LocalLogFileReader::watchFile(bool enable)
// If we enable the watching, then we first try to see if new lines have appeared
logFileModified();
} else {
- d->watch->removeFile(d->logFile.url().path());
+ d->watch->removeFile(filePath);
}
}
QIODevice *LocalLogFileReader::open()
{
Q_D(LocalLogFileReader);
+ QString filePath = d->logFile.url().path();
if (d->logFile.url().isValid() == false) {
QString message(i18n("This file is not valid. Please adjust it in the settings of KSystemLog."));
@@ -114,16 +116,16 @@ QIODevice *LocalLogFileReader::open()
}
QMimeDatabase db;
- QString mimeType = db.mimeTypeForFile(d->logFile.url().path(), QMimeDatabase::MatchContent).name();
+ QString mimeType = db.mimeTypeForFile(filePath, QMimeDatabase::MatchContent).name();
- logDebug() << d->logFile.url().path() << " : " << mimeType;
+ logDebug() << filePath << " : " << mimeType;
QIODevice *inputDevice;
// Try to see if this file exists
- QFile *file = new QFile(d->logFile.url().path());
+ QFile *file = new QFile(filePath);
// If the file does not exist
if (!file->exists()) {
- QString message(i18n("The file '%1' does not exist.", d->logFile.url().path()));
+ QString message(i18n("The file '%1' does not exist.", filePath));
emit errorOccured(i18n("File Does Not Exist"), message);
emit statusBarChanged(message);
delete file;
@@ -140,13 +142,11 @@ QIODevice *LocalLogFileReader::open()
else {
logDebug() << "Using KFilterDev input device";
- // inputDevice = KFilterDev::deviceForFile(d->logFile.url().path(), mimeType);
- inputDevice = new KCompressionDevice(d->logFile.url().path(),
- KFilterDev::compressionTypeForMimeType(mimeType));
+ // inputDevice = KFilterDev::deviceForFile(filePath, mimeType);
+ inputDevice = new KCompressionDevice(filePath, KFilterDev::compressionTypeForMimeType(mimeType));
if (inputDevice == NULL) {
- QString message(
- i18n("Unable to uncompress the '%2' format of '%1'.", d->logFile.url().path(), mimeType));
+ QString message(i18n("Unable to uncompress the '%2' format of '%1'.", filePath, mimeType));
emit errorOccured(i18n("Unable to Uncompress File"), message);
emit statusBarChanged(message);
return NULL;
@@ -154,8 +154,7 @@ QIODevice *LocalLogFileReader::open()
}
if (!inputDevice->open(QIODevice::ReadOnly)) {
- QString message(
- i18n("You do not have sufficient permissions to read '%1'.", d->logFile.url().path()));
+ QString message(i18n("You do not have sufficient permissions to read '%1'.", filePath));
emit errorOccured(i18n("Insufficient Permissions"), message);
emit statusBarChanged(message);
delete inputDevice;
diff --git a/src/lib/logMode.cpp b/src/lib/logMode.cpp
index ec8e873..c97fa39 100644
--- a/src/lib/logMode.cpp
+++ b/src/lib/logMode.cpp
@@ -40,11 +40,9 @@ LogMode::LogMode(const QString &id, const QString &name, const QString &iconName
LogMode::~LogMode()
{
- if (d->action)
- delete d->action;
+ delete d->action;
- if (d->itemBuilder)
- delete d->itemBuilder;
+ delete d->itemBuilder;
delete d;
}
diff --git a/src/lib/logViewColumns.cpp b/src/lib/logViewColumns.cpp
index 8a9b67a..f0d7516 100644
--- a/src/lib/logViewColumns.cpp
+++ b/src/lib/logViewColumns.cpp
@@ -48,6 +48,16 @@ LogViewColumns::LogViewColumns()
d->groupByLogFile = true;
}
+LogViewColumns::LogViewColumns(const LogViewColumns &columns)
+ : d(new LogViewColumnsPrivate())
+{
+ d->columns = columns.columns();
+ d->groupByLogLevel = columns.isGroupByLogLevel();
+ d->groupByDay = columns.isGroupByDay();
+ d->groupByHour = columns.isGroupByHour();
+ d->groupByLogFile = columns.isGroupByLogFile();
+}
+
LogViewColumns::~LogViewColumns()
{
delete d;
diff --git a/src/lib/logViewColumns.h b/src/lib/logViewColumns.h
index aa75353..d4c0c62 100644
--- a/src/lib/logViewColumns.h
+++ b/src/lib/logViewColumns.h
@@ -32,6 +32,7 @@ class LogViewColumns
{
public:
LogViewColumns();
+ LogViewColumns(const LogViewColumns &columns);
~LogViewColumns();
diff --git a/src/lib/logViewExport.cpp b/src/lib/logViewExport.cpp
index 380712f..cdde02c 100644
--- a/src/lib/logViewExport.cpp
+++ b/src/lib/logViewExport.cpp
@@ -1,4 +1,4 @@
-/***************************************************************************
+/***************************************************************************
* KSystemLog, a system log viewer tool *
* Copyright (C) 2007 by Nicolas Ternisien *
@@ -127,10 +127,11 @@ void LogViewExport::printSelection()
QPen originalPen(painter.pen());
- int dpiy = painter.device()->logicalDpiY();
+ QPaintDevice *painterDevice = painter.device();
+ int dpiy = painterDevice->logicalDpiY();
int margin = (int)((2 / 2.54) * dpiy); // 2 cm margins
- QRect printView(margin, margin, painter.device()->width() - 2 * margin,
- painter.device()->height() - 2 * margin);
+ QRect printView(margin, margin, painterDevice->width() - 2 * margin,
+ painterDevice->height() - 2 * margin);
int page = 1;
@@ -140,36 +141,13 @@ void LogViewExport::printSelection()
QTreeWidgetItemIterator it(logViewWidget, QTreeWidgetItemIterator::Selected);
while (*it != NULL) {
LogViewWidgetItem *item = static_cast<LogViewWidgetItem *>(*it);
-
- /*
- if(qtItem==NULL)
- {
- painter.setPen(originalPen);
- printPageNumber(painter, printView, movement, page);
- break;
- }*/
-
QString body = item->logLine()->exportToText();
- // body+= "\n";
-
- /* QPrinter Port: comment out as dialog page is not currently being used, so not ported
- QString strUseColor = printer.option("kde-ksystemlog-print_"+ item->logLine()->logLevel()->name());
- int use = strUseColor.toInt();
- if (use) {
- QPen pen(originalPen);
- pen.setColor(item->logLine()->logLevel()->color());
- painter.setPen(pen);
- } else {*/
painter.setPen(originalPen);
- //}
-
painter.drawText(printView, Qt::AlignLeft | Qt::TextWordWrap, body);
-
int fontHeight = painter.fontMetrics().height();
int lines = painter.fontMetrics().width(body) / printView.width() + 1;
int moveBy = (fontHeight + 2) * lines;
painter.translate(0, moveBy);
-
movement = movement + moveBy;
if (movement + margin >= printView.height()) {
painter.setPen(originalPen);
@@ -178,7 +156,6 @@ void LogViewExport::printSelection()
page++;
movement = 0;
}
-
++it;
++i;
}
@@ -213,7 +190,7 @@ void LogViewExport::copyToClipboard()
text.append(item->logLine()->exportToText());
text.append(QLatin1Char('\n'));
- it++;
+ ++it;
nbCopied++;
}
@@ -264,7 +241,7 @@ void LogViewExport::fileSave()
stream << item->logLine()->exportToText() << '\n';
// Retrieve the next item
- it++;
+ ++it;
nbCopied++;
}
diff --git a/src/lib/logViewWidget.cpp b/src/lib/logViewWidget.cpp
index 593b9dd..c59d10c 100644
--- a/src/lib/logViewWidget.cpp
+++ b/src/lib/logViewWidget.cpp
@@ -245,7 +245,7 @@ LogViewWidgetItem *LogViewWidget::lastSelectedItem()
while (*it) {
item = (*it);
- it++;
+ ++it;
}
// Returns the last selected item or NULL is there is no item selected
diff --git a/src/modes/base/genericConfiguration.cpp b/src/modes/base/genericConfiguration.cpp
index 8046e5b..3c494e1 100644
--- a/src/modes/base/genericConfiguration.cpp
+++ b/src/modes/base/genericConfiguration.cpp
@@ -40,7 +40,7 @@ public:
GenericLogModeConfiguration::GenericLogModeConfiguration(const QString &configurationGroup,
const QStringList &defaultLogFilesPaths,
- const QList<int> defaultLogFilesLevels)
+ const QList<int> &defaultLogFilesLevels)
: d(new GenericLogModeConfigurationPrivate())
{
logDebug() << "Using Configuration Group : " << configurationGroup;
diff --git a/src/modes/base/genericConfiguration.h b/src/modes/base/genericConfiguration.h
index 20143af..be0f34a 100644
--- a/src/modes/base/genericConfiguration.h
+++ b/src/modes/base/genericConfiguration.h
@@ -37,7 +37,7 @@ class GenericLogModeConfiguration : public LogModeConfiguration
public:
GenericLogModeConfiguration(const QString &configurationGroup, const QStringList &defaultLogFilesPaths,
- const QList<int> defaultLogFilesLevels);
+ const QList<int> &defaultLogFilesLevels);
virtual ~GenericLogModeConfiguration();
QStringList logFilesPaths() const;
diff --git a/src/modes/base/logLevelFileList.cpp b/src/modes/base/logLevelFileList.cpp
index b2e1f5e..c457a1f 100644
--- a/src/modes/base/logLevelFileList.cpp
+++ b/src/modes/base/logLevelFileList.cpp
@@ -117,19 +117,19 @@ void LogLevelFileList::changeItemType()
logDebug() << "Changing item type...";
LogLevelSelectionDialog logLevelSelectionDialog(this);
+ QListWidget *logLevels = logLevelSelectionDialog.logLevels();
foreach (LogLevel *level, Globals::instance().logLevels()) {
- logLevelSelectionDialog.logLevels()->addItem(
- new QListWidgetItem(QIcon(level->pixmap()), level->name()));
+ logLevels->addItem(new QListWidgetItem(QIcon(level->pixmap()), level->name()));
}
int choice = logLevelSelectionDialog.exec();
if (choice == QDialog::Accepted) {
- QList<QListWidgetItem *> selectedLogLevels = logLevelSelectionDialog.logLevels()->selectedItems();
+ QList<QListWidgetItem *> selectedLogLevels = logLevels->selectedItems();
if (selectedLogLevels.isEmpty() == false) {
QListWidgetItem *logLevel = selectedLogLevels.at(0);
- int selectedLogLevel = logLevelSelectionDialog.logLevels()->row(logLevel);
+ int selectedLogLevel = logLevels->row(logLevel);
QList<QListWidgetItem *> selectedItems = fileList->selectedItems();
foreach (QListWidgetItem *item, selectedItems) {
diff --git a/src/modes/base/multipleFileList.cpp b/src/modes/base/multipleFileList.cpp
index 227075d..ffaa9b4 100644
--- a/src/modes/base/multipleFileList.cpp
+++ b/src/modes/base/multipleFileList.cpp
@@ -354,7 +354,7 @@ void MultipleFileList::removeAllItems()
delete childItem;
}
- it++;
+ ++it;
}
updateEmptyItems();
@@ -462,7 +462,7 @@ QStringList MultipleFileList::paths(int category)
paths.append(item->text(0));
}
- it++;
+ ++it;
}
return paths;
diff --git a/src/modes/cups/cupsAccessAnalyzer.h b/src/modes/cups/cupsAccessAnalyzer.h
index 428bb9f..5334241 100644
--- a/src/modes/cups/cupsAccessAnalyzer.h
+++ b/src/modes/cups/cupsAccessAnalyzer.h
@@ -85,8 +85,6 @@ protected:
*/
LogLine *parseMessage(const QString &logLine, const LogFile &originalLogFile)
{
- QString line(logLine);
-
int firstPosition = cupsAccessRegex.indexIn(logLine);
if (firstPosition == -1) {
logDebug() << "Unable to parse line " << logLine;
diff --git a/src/modes/cups/cupsPageAnalyzer.h b/src/modes/cups/cupsPageAnalyzer.h
index 4ae7c24..6133531 100644
--- a/src/modes/cups/cupsPageAnalyzer.h
+++ b/src/modes/cups/cupsPageAnalyzer.h
@@ -76,8 +76,6 @@ protected:
*/
LogLine *parseMessage(const QString &logLine, const LogFile &originalLogFile)
{
- QString line(logLine);
-
int firstPosition = cupsPageRegex.indexIn(logLine);
if (firstPosition == -1) {
logDebug() << "Unable to parse line " << logLine;
diff --git a/src/modes/cups/cupsPdfAnalyzer.h b/src/modes/cups/cupsPdfAnalyzer.h
index 95261c6..0d20b29 100644
--- a/src/modes/cups/cupsPdfAnalyzer.h
+++ b/src/modes/cups/cupsPdfAnalyzer.h
@@ -76,8 +76,6 @@ protected:
*/
LogLine *parseMessage(const QString &logLine, const LogFile &originalLogFile)
{
- QString line(logLine);
-
int firstPosition = cupsPdfRegex.indexIn(logLine);
if (firstPosition == -1) {
logDebug() << "Unable to parse line " << logLine;
diff --git a/src/modes/journald/journaldConfiguration.cpp b/src/modes/journald/journaldConfiguration.cpp
index 07e8dbb..a9ca460 100644
--- a/src/modes/journald/journaldConfiguration.cpp
+++ b/src/modes/journald/journaldConfiguration.cpp
@@ -24,6 +24,10 @@
JournaldConfiguration::JournaldConfiguration()
{
+ m_displayCurrentBootOnly = true;
+ m_displayCurrentUserProcesses = true;
+ m_displaySystemServices = true;
+
configuration->setCurrentGroup(QLatin1String("JournaldLogMode"));
configuration->addItemBool(QLatin1String("CurrentBootOnly"), m_displayCurrentBootOnly, true);
configuration->addItemBool(QLatin1String("CurrentUserProcesses"), m_displayCurrentUserProcesses, true);
diff --git a/src/modes/journald/journaldLocalAnalyzer.cpp b/src/modes/journald/journaldLocalAnalyzer.cpp
index f26d597..9b5c5cb 100644
--- a/src/modes/journald/journaldLocalAnalyzer.cpp
+++ b/src/modes/journald/journaldLocalAnalyzer.cpp
@@ -45,7 +45,7 @@ JournaldLocalAnalyzer::JournaldLocalAnalyzer(LogMode *logMode, QString filter)
m_journalFlags |= SD_JOURNAL_SYSTEM;
sd_journal_open(&m_journal, m_journalFlags);
- int fd = sd_journal_get_fd(m_journal);
+ qintptr fd = sd_journal_get_fd(m_journal);
m_journalNotifier = new QSocketNotifier(fd, QSocketNotifier::Read);
m_journalNotifier->setEnabled(false);
connect(m_journalNotifier, &QSocketNotifier::activated, this,
@@ -236,9 +236,8 @@ QList<JournaldLocalAnalyzer::JournalEntry> JournaldLocalAnalyzer::readJournal(co
entryList.append(entry);
}
- if (m_cursor)
- free(m_cursor);
- res = sd_journal_get_cursor(journal, &m_cursor);
+ free(m_cursor);
+ sd_journal_get_cursor(journal, &m_cursor);
}
sd_journal_close(journal);