Ability to sort cur.playlist by long tap on it
[someplayer] / src / track.cpp
1 /*
2  * SomePlayer - An alternate music player for Maemo 5
3  * Copyright (C) 2010 Nikolay (somebody) Tischenko <niktischenko@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
19
20 #include "track.h"
21 #include "tagresolver.h"
22 #include <QFileInfo>
23
24 using namespace SomePlayer::DataObjects;
25
26 Track::Track() : QObject() {
27 }
28
29 Track::Track(TrackMetadata metadata, QString source) : QObject() {
30         _metadata = metadata;
31         if (_metadata.title() == _UNKNOWN_TRACK_) {
32                 QFileInfo info(source);
33                 _metadata.setTitle(info.baseName());
34         }
35         _source = source;
36         _count = 0;
37 }
38
39 Track::Track(const Track &track) : QObject() {
40         this->_metadata = track.metadata();
41         this->_source = track.source();
42         this->_count = track._count;
43 }
44
45 /// deprecated
46 Track::Track(QString source) :QObject() {
47         _resolver = new TagResolver(this);
48         connect(_resolver, SIGNAL(decoded(Track)), this, SLOT(decoded(Track)));
49         QStringList foo;
50         foo << source;
51         _resolver->decode(foo);
52         _count = 0;
53 }
54
55 TrackMetadata Track::metadata() const {
56         return _metadata;
57 }
58
59 void Track::setMetadata(TrackMetadata meta) {
60         _metadata = meta;
61 }
62
63 QString Track::source() const {
64         return _source;
65 }
66
67 void Track::setSource(QString source) {
68         _source = source;
69 }
70
71 int Track::count() const{
72         return _count;
73 }
74
75 void Track::setCount(int count) {
76         _count = count;
77 }
78
79 void Track::decoded(Track track) {
80         _source = track.source();
81         _metadata = track.metadata();
82         delete _resolver;
83 }
84
85 Track &Track::operator =(const Track &track) {
86         _source = track.source();
87         _metadata = track.metadata();
88         _count = track._count;
89         return *this;
90 }
91
92 Track::~Track() {}
93
94 bool Track::operator ==(const Track &track) const {
95         return _source == track._source;
96 }
97
98 bool Track::operator >= (const Track &track) const {
99         return (metadata().title().compare(track.metadata().title()) >= 0);
100 }
101
102 bool Track::operator < (const Track &track) const {
103         return (metadata().title().compare(track.metadata().title()) < 0);
104 }