source: smplayer/trunk/src/recents.cpp@ 188

Last change on this file since 188 was 188, checked in by Silvan Scherrer, 8 years ago

SMPlayer: update trunk to version 17.1.0

  • Property svn:eol-style set to LF
File size: 2.1 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
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
21Recents::Recents()
22{
23 l.clear();
24 max_items = 10;
25}
26
27Recents::~Recents() {
28}
29
30void Recents::clear() {
31 l.clear();
32}
33
34int Recents::count() {
35 return l.count();
36}
37
38void Recents::setMaxItems(int n_items) {
39 max_items = n_items;
40 fromStringList(l);
41}
42
43void 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
53void Recents::addItem(QString s, QString title) {
54 s += "|title]=" + title;
55 addItem(s);
56}
57
58QString Recents::item(int n) {
59 QString res;
60
61 QStringList s = l[n].split("|title]=");
62 if (s.count() > 0) res = s[0];
63
64 return res;
65}
66
67QString Recents::title(int n) {
68 QString res;
69
70 QStringList s = l[n].split("|title]=");
71 if (s.count() > 1) res = s[1];
72
73 return res;
74}
75
76void Recents::list() {
77 qDebug("Recents::list");
78
79 for (int n=0; n < l.count(); n++) {
80 qDebug(" * item %d: '%s'", n, l[n].toUtf8().constData() );
81 }
82}
83
84void Recents::fromStringList(QStringList list) {
85 l.clear();
86
87 int max = list.count();
88 if (max_items < max) max = max_items;
89
90 //qDebug("max_items: %d, count: %d max: %d", max_items, l.count(), max);
91
92 for (int n = 0; n < max; n++) {
93 l.append( list[n] );
94 }
95}
96
97QStringList Recents::toStringList() {
98 return l;
99}
100
Note: See TracBrowser for help on using the repository browser.