Add simple (and ugly) strip mode icon
[qcomicbook-oblomov] / src / history.cpp
1 /*
2  * This file is a part of QComicBook.
3  *
4  * Copyright (C) 2005-2006 Pawel Stolowski <yogin@linux.bydg.org>
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
17 History::History(const QStringList &l, int max): size(max)
18 {
19         hlist = l;
20 }
21
22 History::History(int max)
23 {
24         size = max;
25 }
26
27 History::~History()
28 {
29 }
30
31 void History::append(const QString &txt)
32 {
33         QStringList::iterator it = hlist.find(txt);
34         //
35         // text not found on the list - append it
36         if (it == hlist.end())
37         {
38                 hlist.push_front(txt);
39                 //
40                 // remove last text item if history reached its max size
41                 if (hlist.count() > size)
42                         hlist.pop_back();
43         }
44         else //put the item to the front
45         {
46                 hlist.remove(it);
47                 hlist.push_front(txt);
48         }
49 }
50
51 void History::remove(const QString &txt)
52 {
53         hlist.remove(txt);
54 }
55
56 void History::set(const QStringList &l)
57 {
58         hlist = l;
59 }
60
61 QString History::first()
62 {
63         return hlist.first(); 
64 }
65
66 QStringList History::getAll() const
67 {
68         return hlist;
69 }
70