1 /*
2 SPDX-FileCopyrightText: 2007 Nicolas Ternisien <nicolas.ternisien@gmail.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include "xorgAnalyzer.h"
8 #include <KLocalizedString>
9
XorgAnalyzer(LogMode * logMode)10 XorgAnalyzer::XorgAnalyzer(LogMode *logMode)
11 : FileAnalyzer(logMode)
12 , mCurrentDateTime(QDateTime::currentDateTime())
13 {
14 initializeTypeName();
15 }
16
~XorgAnalyzer()17 XorgAnalyzer::~XorgAnalyzer()
18 {
19 }
20
initColumns()21 LogViewColumns XorgAnalyzer::initColumns()
22 {
23 LogViewColumns columns;
24
25 columns.addColumn(LogViewColumn(i18n("Line"), false, false));
26 columns.addColumn(LogViewColumn(i18n("Type"), false, false));
27 columns.addColumn(LogViewColumn(i18n("Message"), false, false));
28
29 columns.setGroupByDay(false);
30 columns.setGroupByHour(false);
31
32 return columns;
33 }
34
createLogFileReader(const LogFile & logFile)35 LogFileReader *XorgAnalyzer::createLogFileReader(const LogFile &logFile)
36 {
37 return new LocalLogFileReader(logFile);
38 }
39
logFileSortMode()40 Analyzer::LogFileSortMode XorgAnalyzer::logFileSortMode()
41 {
42 return Analyzer::AscendingSortedLogFile;
43 }
44
parseMessage(const QString & logLine,const LogFile & originalFile)45 LogLine *XorgAnalyzer::parseMessage(const QString &logLine, const LogFile &originalFile)
46 {
47 QString string(logLine);
48
49 const QString type = string.left(4);
50
51 LogLevel *logLineType = findTypeName(type);
52
53 // If the type is not empty, the log message has a type, so we can delete it
54 if (logLineType) {
55 string.remove(0, 5);
56 } else {
57 logLineType = Globals::instance().informationLogLevel();
58 }
59
60 QStringList list;
61 list.append(logLineType->name());
62 list.append(string);
63
64 return new LogLine(mLogLineInternalIdGenerator++, mCurrentDateTime, list, originalFile.url().toLocalFile(), logLineType, mLogMode);
65 }
66
initializeTypeName()67 void XorgAnalyzer::initializeTypeName()
68 {
69 mXorgLevels[QStringLiteral("(--)")] = new LogLevel(1001, i18n("Probed"), QStringLiteral(PROBED_LOG_LEVEL_ICON), QColor(246, 206, 30), this);
70
71 mXorgLevels[QStringLiteral("(**)")] = new LogLevel(1002, i18n("From config file"), QStringLiteral(CONFIG_FILE_LOG_LEVEL_ICON), QColor(161, 133, 240), this);
72
73 mXorgLevels[QStringLiteral("(==)")] =
74 new LogLevel(1003, i18n("Default setting"), QStringLiteral(DEFAULT_SETTING_LOG_LEVEL_ICON), QColor(169, 189, 165), this);
75
76 mXorgLevels[QStringLiteral("(++)")] =
77 new LogLevel(1004, i18n("From command Line"), QStringLiteral(COMMAND_LINE_LOG_LEVEL_ICON), QColor(179, 181, 214), this);
78
79 mXorgLevels[QStringLiteral("(!!)")] = Globals::instance().noticeLogLevel();
80 mXorgLevels[QStringLiteral("(II)")] = Globals::instance().informationLogLevel();
81 mXorgLevels[QStringLiteral("(WW)")] = Globals::instance().warningLogLevel();
82 mXorgLevels[QStringLiteral("(EE)")] = Globals::instance().errorLogLevel();
83
84 mXorgLevels[QStringLiteral("(NI)")] =
85 new LogLevel(1005, i18n("Not implemented"), QStringLiteral(NOT_IMPLEMENTED_LOG_LEVEL_ICON), QColor(136, 146, 240), this);
86
87 mXorgLevels[QStringLiteral("(\?\?)")] = Globals::instance().noLogLevel();
88 }
89
findTypeName(const QString & type)90 LogLevel *XorgAnalyzer::findTypeName(const QString &type)
91 {
92 QMap<QString, LogLevel *>::iterator it;
93
94 it = mXorgLevels.find(type);
95 if (it != mXorgLevels.end()) {
96 return *it;
97 } else {
98 return nullptr;
99 }
100 }
101