1 /*
2  * This file is a part of QComicBook.
3  *
4  * Copyright (C) 2005-2006 Pawel Stolowski <pawel.stolowski@wp.pl>
5  *
6  * QComicBook is free software; you can redestribute it and/or modify it
7  * under terms of GNU General Public License by Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY. See GPL for more details.
11  */
12 
13 #include "History.h"
14 
15 using namespace Utility;
16 
History(const QStringList & l,int max)17 History::History(const QStringList &l, int max): size(max)
18 {
19 	hlist = l;
20 }
21 
History(int max)22 History::History(int max)
23 {
24 	size = max;
25 }
26 
~History()27 History::~History()
28 {
29 }
30 
append(const QString & txt)31 void History::append(const QString &txt)
32 {
33 	const int i = hlist.indexOf(txt);
34 
35 	//
36 	// text not found on the list - append it
37 	if (i < 0)
38 	{
39 		hlist.push_front(txt);
40 		//
41 		// remove last text item if history reached its max size
42 		if (hlist.count() > size)
43 			hlist.pop_back();
44 	}
45 	else //put the item to the front
46 	{
47 		hlist.removeAt(i);
48 		hlist.push_front(txt);
49 	}
50 }
51 
remove(const QString & txt)52 void History::remove(const QString &txt)
53 {
54 	const int i = hlist.indexOf(txt);
55 	if (i >= 0)
56 		hlist.removeAt(i);
57 }
58 
set(const QStringList & l)59 void History::set(const QStringList &l)
60 {
61 	hlist = l;
62 }
63 
first()64 QString History::first()
65 {
66 	return hlist.first();
67 }
68 
getAll() const69 QStringList History::getAll() const
70 {
71 	return hlist;
72 }
73 
74