1
1
/* smplayer, GUI front-end for mplayer.
2
Copyright (C) 2006-2008 Ricardo Villalba <rvm@escomposlinux.org>
2
Copyright (C) 2006-2009 Ricardo Villalba <rvm@escomposlinux.org>
4
4
This program is free software; you can redistribute it and/or modify
5
5
it under the terms of the GNU General Public License as published by
19
19
#include "recents.h"
23
using namespace Global;
25
Recents::Recents(QObject* parent) : QObject(parent)
32
27
Recents::~Recents() {
36
30
void Recents::clear() {
40
void Recents::add(QString s) {
41
qDebug("Recents::add: '%s'", s.toUtf8().data());
44
QStringList::iterator it = l.find(s);
45
if (it != l.end()) l.erase(it);
48
if (l.count() > max_items) l.erase(l.fromLast());
34
int Recents::count() {
38
void Recents::setMaxItems(int n_items) {
43
void Recents::addItem(QString s) {
44
qDebug("Recents::addItem: '%s'", s.toUtf8().data());
51
46
int pos = l.indexOf(s);
52
47
if (pos != -1) l.removeAt(pos);
55
50
if (l.count() > max_items) l.removeLast();
57
//qDebug(" * current list:");
61
int Recents::count() {
65
53
QString Recents::item(int n) {
69
57
void Recents::list() {
70
58
qDebug("Recents::list");
72
for (int n=0; n < count(); n++) {
73
qDebug(" * item %d: '%s'", n, item(n).toUtf8().data() );
77
void Recents::save() {
78
qDebug("Recents::save");
80
QSettings * set = settings;
83
set->beginGroup( "recent_files");
85
set->writeEntry( "items", count() );
86
for (int n=0; n < count(); n++) {
87
set->writeEntry("entry_" + QString::number(n), item(n) );
91
set->beginGroup( "recent_files");
92
set->setValue( "files", l );
97
void Recents::load() {
98
qDebug("Recents::load");
60
for (int n=0; n < l.count(); n++) {
61
qDebug(" * item %d: '%s'", n, l[n].toUtf8().constData() );
65
void Recents::fromStringList(QStringList list) {
102
QSettings * set = settings;
105
set->beginGroup( "recent_files");
107
int num_entries = set->readNumEntry( "items", 0 );
108
for (int n=0; n < num_entries; n++) {
109
QString s = set->readEntry("entry_" + QString::number(n), "" );
110
if (!s.isEmpty()) l.append( s );
68
int max = list.count();
69
if (max_items < max) max = max_items;
71
//qDebug("max_items: %d, count: %d max: %d", max_items, l.count(), max);
73
for (int n = 0; n < max; n++) {
114
set->beginGroup( "recent_files");
115
l = set->value( "files" ).toStringList();
120
#include "moc_recents.cpp"
78
QStringList Recents::toStringList() {