1 /***************************************************************************
2 * KSystemLog, a system log viewer tool *
3 * Copyright (C) 2007 by Nicolas Ternisien *
4 * nicolas.ternisien@gmail.com *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 ***************************************************************************/
24 #include <QStringList>
28 #include "logModeItemBuilder.h"
29 #include "logViewWidgetItem.h"
33 #include "ksystemlogConfig.h"
35 class LogLinePrivate
{
52 LogViewWidgetItem
* item
;
58 const QDateTime
& dateTime
,
59 const QStringList
& logItems
,
64 d(new LogLinePrivate()) {
66 d
->internalId
= internalId
;
68 d
->logItems
= logItems
;
69 d
->originalFile
= file
;
70 d
->logLevel
= logLevel
;
73 //No linked item when constructs this LogLine
76 //By default in newly created item has the recent state
82 //logLevel is managed by Globals
84 //item is managed by LogMode
85 //itemBuilder is managed by LogMode
91 LogMode
* LogLine::logMode() const {
95 void LogLine::setLogMode(LogMode
* logMode
) {
99 bool LogLine::equals(const LogLine
& other
) const {
100 if (logMode()->id() != other
.logMode()->id())
103 if (time() != other
.time())
106 if (logLevel()->id() != other
.logLevel()->id())
109 if (d
->logItems
!= other
.d
->logItems
)
115 LogLevel
* LogLine::logLevel() const {
119 void LogLine::setLogLevel(LogLevel
* level
) {
123 QDateTime
LogLine::time() const {
127 void LogLine::setLogItems(const QStringList
& logItems
) {
128 d
->logItems
= logItems
;
131 QStringList
LogLine::logItems() const {
135 QString
LogLine::sourceFileName() const {
136 return d
->originalFile
;
139 bool LogLine::isOlderThan(const LogLine
& other
) const {
140 if (d
->time
== other
.time())
141 return d
->internalId
< other
.internalId();
143 return d
->time
< other
.time();
146 bool LogLine::isNewerThan(const LogLine
& other
) const {
147 if (d
->time
== other
.time())
148 return d
->internalId
> other
.internalId();
150 return d
->time
> other
.time();
153 bool LogLine::isSameTime(const LogLine
& other
) const {
154 return d
->time
==other
.time();
157 long LogLine::internalId() const {
158 return d
->internalId
;
161 void LogLine::setRecent(bool recent
) {
165 QFont currentFont
= d
->item
->font(d
->item
->columnCount()-1);
167 //We avoid doing the same process
168 if (d
->recent
!= currentFont
.bold()) {
169 currentFont
.setBold(recent
);
170 d
->item
->setFont(d
->item
->columnCount()-1, currentFont
);
176 QString
LogLine::exportToText() const {
180 if (d
->item
== NULL
) {
181 logError() << "Trying to export text from NULL item" << endl
;
185 for (int i
=0; i
< d
->item
->columnCount(); ++i
) {
187 exporting
.append('\t');
189 exporting
.append(d
->item
->text(i
));
195 QString
LogLine::formattedText() {
196 return d
->logMode
->itemBuilder()->createFormattedText(this);
199 void LogLine::setItem(LogViewWidgetItem
* item
) {
205 void LogLine::initializeItem() {
206 d
->logMode
->itemBuilder()->prepareItem(d
->item
);
208 //Call methods that change the look of the item
209 setRecent(d
->recent
);
211 if (KSystemLogConfig::colorizeLogLines()) {
212 //Last column index = d->logItems.count() = (d->logItems.count() -1) +1 (the date column)
213 d
->item
->setForeground(d
->logItems
.count(), QBrush(d
->logLevel
->color()));
216 d
->item
->toggleToolTip(KSystemLogConfig::tooltipEnabled());