Now 'Artist name' and 'ArTist Name' is the same for library
[someplayer] / src / library.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 "library.h"
21
22 using namespace SomePlayer::DataObjects;
23 using namespace SomePlayer::Storage;
24
25 #include "mediascanner.h"
26 #include <QDir>
27
28 Library::Library(QString databasePath, QString playlistsPath) : QObject(0) {
29         _library_storage = new DbStorage(databasePath);
30         _playlist_storage = new FileStorage(playlistsPath);
31         _scanner = new MediaScanner();
32         _resolver = new TagResolver(this);
33         connect(_scanner, SIGNAL(scanFinish(QStringList)), _resolver, SLOT(decode(QStringList)));
34         connect(_resolver, SIGNAL(done()), this, SIGNAL(done()));
35         connect(_resolver, SIGNAL(decoded(Track)), this, SLOT(addTrack(Track)));
36 }
37
38 Library::~Library() {
39         delete _library_storage;
40         delete _playlist_storage;
41 }
42
43 void Library::addDirectory(QString path) {
44         _scanner->init(path);
45         _scanner->start(QThread::LowestPriority);
46 }
47
48 void Library::addFile(QString path) {
49         QStringList files(path);
50         _resolver->decode(files);
51 }
52
53 QList<QString> Library::getArtists() {
54         return _library_storage->getArtists();
55 }
56
57 QList<QString> Library::getAlbumsForArtist(QString artist) {
58         return _library_storage->getAlbumsForArtist(artist);
59 }
60
61 QList<Track> Library::getTracksForAlbum(QString album, QString artist) {
62         return _library_storage->getTracksForAlbum(album, artist);
63 }
64
65
66 // dynamic:
67
68 Playlist Library::getFavorites() {
69         return _library_storage->getFavorites();
70 }
71
72 Playlist Library::getMostPlayed() {
73         return _library_storage->getMostPlayed();
74 }
75
76 Playlist Library::getNeverPlayed() {
77         return _library_storage->getNeverPlayed();
78 }
79
80 Playlist Library::getRecentlyAdded() {
81         return _library_storage->getRecentlyAdded();
82 }
83
84
85 void Library::removeTrack(Track track) {
86         _library_storage->removeTrack(track);
87 }
88
89 void Library::addTrack(Track track) {
90         _library_storage->addTrack(track);
91 }
92
93 void Library::addToFavorites(Track track) {
94         _library_storage->addToFavorites(track);
95 }
96
97 void Library::updateTrackCount(Track track) {
98         _library_storage->updateTrackCount(track);
99 }
100
101
102 // playlists:
103
104 QList<Playlist> Library::getPlaylists() {
105         return _playlist_storage->getPlaylists();
106 }
107
108 QStringList Library::getPlaylistsNames() {
109         return _playlist_storage->getPlaylistsNames();
110 }
111
112 Playlist Library::getPlaylist(QString name) {
113         return _playlist_storage->getPlaylist(name);
114 }
115
116 void Library::savePlaylist(const Playlist &playlist) {
117         _playlist_storage->savePlaylist(playlist);
118 }
119
120 void Library::removePlaylist(const Playlist &playlist) {
121         _playlist_storage->removePlaylist(playlist);
122 }
123
124 void Library::removePlaylist(QString name) {
125         _playlist_storage->removePlaylist(name);
126 }
127
128 Playlist Library::getCurrentPlaylist() {
129         return _playlist_storage->getCurrentPlaylist();
130 }
131
132 void Library::saveCurrentPlaylist(const Playlist &playlist) {
133         _playlist_storage->saveCurrentPlaylist(playlist);
134 }