1
/***************************************************************************
2
* Copyright (C) 2005 by Nicolas Ternisien *
3
* nicolas.ternisien@gmail.com *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
21
#include "logLineList.h"
27
LogLineList::LogLineList() :
34
LogLineList::~LogLineList() {
38
LogLine* LogLineList::getOldestLine() {
39
return(oldestLogLine);
42
void LogLineList::removeOldestLine() {
43
LogLine* line=this->getOldestLine();
51
bool LogLineList::isNewer(LogLine* line) {
52
LogLine* olderLine=this->getOldestLine();
57
return(line->isNewerThan(*olderLine));
61
bool LogLineList::isEmpty() {
62
return(list.isEmpty());
66
LogLine* LogLineList::lastLineInserted() {
67
//Can also returns NULL
71
int LogLineList::getNewLineCount() {
72
return(addedList.count());
75
void LogLineList::insert(LogLine* line) {
76
if (!isNewer(line) || list.count()==0) {
80
addedList.append(line);
84
bool LogLineList::lineAlreadyExists(LogLine* line) {
85
QPtrListIterator<LogLine> it(list);
87
LogLine* other=it.current();
89
if (other->equals(*line))
100
bool LogLineList::remove(LogLine* removedLine) {
101
QPtrListIterator<LogLine> it(list);
103
LogLine* line=it.current();
106
if (this->equals(removedLine, line)) {
107
removedList.append(line);
109
addedList.remove(line);
112
//Now find the new oldest line
126
bool LogLineList::equals(LogLine* l1, LogLine* l2) {
127
return(l1->equals(*l2));
131
int LogLineList::getItemCount() {
132
return(list.count());
135
void LogLineList::clear() {
136
QPtrListIterator<LogLine> it(list);
138
LogLine* line=it.current();
140
removedList.append(line);
152
LogLine* LogLineList::synchronize(View* view) {
153
synchronizeRemovedLines(view);
155
if (firstAdd==false && !addedList.isEmpty()) {
156
synchronizeRecentLines();
161
line=synchronizeAddedLines(view);
163
kdDebug() << "Returning the added line..." << endl;
169
void LogLineList::synchronizeRemovedLines(View* view) {
170
QPtrListIterator<LogLine> it(removedList);
172
LogLine* line=it.current();
174
kdDebug() << "Removing old items from list..." << endl;
176
//We removed the old items
178
if (line->itemExists())
179
line->removeItem(view->getLogList());
181
//TODO Delete the line object
191
LogLine* LogLineList::synchronizeAddedLines(View* view) {
193
kdDebug() << "Adding new items to the list..." << endl;
195
//We add the new items
196
QPtrListIterator<LogLine> it(addedList);
198
LogLine* line=it.current();
201
line->insertItem(view->getLogList());
207
kdDebug() << "Returning latest item..." << endl;
209
//Get the last line of addedList list (can be NULL)
210
line=addedList.last();
214
//Returns line, even if line is NULL (must be tested by the caller class)
218
void LogLineList::synchronizeRecentLines() {
219
kdDebug() << "Recent items become normal..." << endl;
221
//The older lines are no longer recent
222
QPtrListIterator<LogLine> it(recentList);
223
LogLine* line=it.current();
226
//kdDebug() << "before setRecent... " << endl;
227
//kdDebug() << "before setRecent original... : " << line->getOriginalFile() << endl;
228
line->setRecent(false);
229
//kdDebug() << "after setRecent..." << endl;
236
kdDebug() << "New items become recent..." << endl;
238
//The new lines added becomes recent
242
line->setRecent(true);
243
recentList.append(line);
250
void LogLineList::setFirstReadPerformed(bool add) {
254
void LogLineList::updateOldestLine() {
256
QPtrListIterator<LogLine> it(list);
257
if (it.current()==NULL)
260
oldestLogLine=it.current();
262
LogLine* line=it.current();
264
if (line->isOlderThan(*oldestLogLine))