~ubuntu-branches/ubuntu/wily/smplayer/wily

« back to all changes in this revision

Viewing changes to src/recents.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Maia Kozheva
  • Date: 2009-03-31 23:05:43 UTC
  • mto: (1.1.9 upstream) (3.1.2 squeeze)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20090331230543-nsklbxenl2hf2n6h
ImportĀ upstreamĀ versionĀ 0.6.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
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>
3
3
 
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
17
17
*/
18
18
 
19
19
#include "recents.h"
20
 
#include "global.h"
21
 
#include <QSettings>
22
 
 
23
 
using namespace Global;
24
 
 
25
 
Recents::Recents(QObject* parent) : QObject(parent) 
 
20
 
 
21
Recents::Recents()
26
22
{
27
23
        l.clear();
28
24
        max_items = 10;
29
 
        load();
30
25
}
31
26
 
32
27
Recents::~Recents() {
33
 
        save();
34
28
}
35
29
 
36
30
void Recents::clear() {
37
31
        l.clear();
38
32
}
39
33
 
40
 
void Recents::add(QString s) {
41
 
        qDebug("Recents::add: '%s'", s.toUtf8().data());
42
 
 
43
 
        /*
44
 
        QStringList::iterator it = l.find(s);
45
 
        if (it != l.end()) l.erase(it);
46
 
        l.prepend(s);
47
 
 
48
 
        if (l.count() > max_items) l.erase(l.fromLast());
49
 
        */
 
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());
50
45
 
51
46
        int pos = l.indexOf(s);
52
47
        if (pos != -1) l.removeAt(pos);
53
48
        l.prepend(s);
54
49
 
55
50
        if (l.count() > max_items) l.removeLast();
56
 
 
57
 
        //qDebug(" * current list:");
58
 
        //list();
59
 
}
60
 
 
61
 
int Recents::count() {
62
 
        return l.count();
63
51
}
64
52
 
65
53
QString Recents::item(int n) {
69
57
void Recents::list() {
70
58
        qDebug("Recents::list");
71
59
 
72
 
        for (int n=0; n < count(); n++) {
73
 
                qDebug(" * item %d: '%s'", n, item(n).toUtf8().data() );
74
 
        }
75
 
}
76
 
 
77
 
void Recents::save() {
78
 
        qDebug("Recents::save");
79
 
 
80
 
        QSettings * set = settings;
81
 
 
82
 
        /*
83
 
        set->beginGroup( "recent_files");
84
 
 
85
 
        set->writeEntry( "items", count() );
86
 
        for (int n=0; n < count(); n++) {
87
 
                set->writeEntry("entry_" + QString::number(n), item(n) );
88
 
        }
89
 
        */
90
 
 
91
 
        set->beginGroup( "recent_files");
92
 
        set->setValue( "files", l );
93
 
 
94
 
        set->endGroup();
95
 
}
96
 
 
97
 
void Recents::load() {
98
 
        qDebug("Recents::load");
99
 
 
 
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) {
100
66
        l.clear();
101
67
 
102
 
        QSettings * set = settings;
103
 
 
104
 
        /*
105
 
        set->beginGroup( "recent_files");
106
 
 
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;
 
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] );
111
75
        }
112
 
        */
113
 
 
114
 
        set->beginGroup( "recent_files");
115
 
        l = set->value( "files" ).toStringList();
116
 
 
117
 
        set->endGroup();
118
 
}
119
 
 
120
 
#include "moc_recents.cpp"
 
76
}
 
77
 
 
78
QStringList Recents::toStringList() {
 
79
        return l;
 
80
}
 
81