[112] | 1 | /* smplayer, GUI front-end for mplayer.
|
---|
[188] | 2 | Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
[112] | 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 |
|
---|
[170] | 53 | void Recents::addItem(QString s, QString title) {
|
---|
| 54 | s += "|title]=" + title;
|
---|
| 55 | addItem(s);
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[112] | 58 | QString Recents::item(int n) {
|
---|
[170] | 59 | QString res;
|
---|
| 60 |
|
---|
| 61 | QStringList s = l[n].split("|title]=");
|
---|
| 62 | if (s.count() > 0) res = s[0];
|
---|
| 63 |
|
---|
| 64 | return res;
|
---|
[112] | 65 | }
|
---|
| 66 |
|
---|
[170] | 67 | QString 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 |
|
---|
[112] | 76 | void 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 |
|
---|
| 84 | void 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 |
|
---|
| 97 | QStringList Recents::toStringList() {
|
---|
| 98 | return l;
|
---|
| 99 | }
|
---|
| 100 |
|
---|