1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2011 Ricardo Villalba <rvm@escomposlinux.org>
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 of the License, or
|
---|
7 | (at your option) any later version.
|
---|
8 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "recents.h"
|
---|
20 |
|
---|
21 | Recents::Recents()
|
---|
22 | {
|
---|
23 | l.clear();
|
---|
24 | max_items = 10;
|
---|
25 | }
|
---|
26 |
|
---|
27 | Recents::~Recents() {
|
---|
28 | }
|
---|
29 |
|
---|
30 | void Recents::clear() {
|
---|
31 | l.clear();
|
---|
32 | }
|
---|
33 |
|
---|
34 | int Recents::count() {
|
---|
35 | return l.count();
|
---|
36 | }
|
---|
37 |
|
---|
38 | void Recents::setMaxItems(int n_items) {
|
---|
39 | max_items = n_items;
|
---|
40 | fromStringList(l);
|
---|
41 | }
|
---|
42 |
|
---|
43 | void Recents::addItem(QString s) {
|
---|
44 | qDebug("Recents::addItem: '%s'", s.toUtf8().data());
|
---|
45 |
|
---|
46 | int pos = l.indexOf(s);
|
---|
47 | if (pos != -1) l.removeAt(pos);
|
---|
48 | l.prepend(s);
|
---|
49 |
|
---|
50 | if (l.count() > max_items) l.removeLast();
|
---|
51 | }
|
---|
52 |
|
---|
53 | QString Recents::item(int n) {
|
---|
54 | return l[n];
|
---|
55 | }
|
---|
56 |
|
---|
57 | void Recents::list() {
|
---|
58 | qDebug("Recents::list");
|
---|
59 |
|
---|
60 | for (int n=0; n < l.count(); n++) {
|
---|
61 | qDebug(" * item %d: '%s'", n, l[n].toUtf8().constData() );
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | void Recents::fromStringList(QStringList list) {
|
---|
66 | l.clear();
|
---|
67 |
|
---|
68 | int max = list.count();
|
---|
69 | if (max_items < max) max = max_items;
|
---|
70 |
|
---|
71 | //qDebug("max_items: %d, count: %d max: %d", max_items, l.count(), max);
|
---|
72 |
|
---|
73 | for (int n = 0; n < max; n++) {
|
---|
74 | l.append( list[n] );
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | QStringList Recents::toStringList() {
|
---|
79 | return l;
|
---|
80 | }
|
---|
81 |
|
---|