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 "tracks.h"
|
---|
20 | #include <QRegExp>
|
---|
21 |
|
---|
22 | Tracks::Tracks() {
|
---|
23 | clear();
|
---|
24 | }
|
---|
25 |
|
---|
26 | Tracks::~Tracks() {
|
---|
27 | }
|
---|
28 |
|
---|
29 | void Tracks::clear() {
|
---|
30 | tm.clear();
|
---|
31 | }
|
---|
32 |
|
---|
33 | void Tracks::addLang(int ID, QString lang) {
|
---|
34 | tm[ID].setLang(lang);
|
---|
35 | tm[ID].setID(ID);
|
---|
36 | }
|
---|
37 |
|
---|
38 | void Tracks::addName(int ID, QString name) {
|
---|
39 | tm[ID].setName(name);
|
---|
40 | tm[ID].setID(ID);
|
---|
41 | }
|
---|
42 |
|
---|
43 | void Tracks::addID(int ID) {
|
---|
44 | tm[ID].setID(ID);
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 | int Tracks::numItems() {
|
---|
49 | return tm.count();
|
---|
50 | }
|
---|
51 |
|
---|
52 | bool Tracks::existsItemAt(int n) {
|
---|
53 | return ((n > 0) && (n < numItems()));
|
---|
54 | }
|
---|
55 |
|
---|
56 | TrackData Tracks::itemAt(int n) {
|
---|
57 | return tm.values()[n];
|
---|
58 | }
|
---|
59 |
|
---|
60 | TrackData Tracks::item(int ID) {
|
---|
61 | return tm[ID];
|
---|
62 | }
|
---|
63 |
|
---|
64 | int Tracks::find(int ID) {
|
---|
65 | for (int n=0; n < numItems(); n++) {
|
---|
66 | if (itemAt(n).ID() == ID) return n;
|
---|
67 | }
|
---|
68 | return -1;
|
---|
69 | }
|
---|
70 |
|
---|
71 | int Tracks::findLang(QString expr) {
|
---|
72 | qDebug( "Tracks::findLang: '%s'", expr.toUtf8().data());
|
---|
73 | QRegExp rx( expr );
|
---|
74 |
|
---|
75 | int res_id = -1;
|
---|
76 |
|
---|
77 | for (int n=0; n < numItems(); n++) {
|
---|
78 | qDebug("Tracks::findLang: lang #%d '%s'", n, itemAt(n).lang().toUtf8().data());
|
---|
79 | if (rx.indexIn( itemAt(n).lang() ) > -1) {
|
---|
80 | qDebug("Tracks::findLang: found preferred lang!");
|
---|
81 | res_id = itemAt(n).ID();
|
---|
82 | break;
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 | return res_id;
|
---|
87 | }
|
---|
88 |
|
---|
89 | void Tracks::list() {
|
---|
90 | QMapIterator<int, TrackData> i(tm);
|
---|
91 | while (i.hasNext()) {
|
---|
92 | i.next();
|
---|
93 | TrackData d = i.value();
|
---|
94 | qDebug("Tracks::list: item %d: ID: %d lang: '%s' name: '%s'",
|
---|
95 | i.key(), d.ID(), d.lang().toUtf8().constData(), d.name().toUtf8().constData() );
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|