Improved random mode
[someplayer] / src / dbstorage.h
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 #ifndef DB_STORAGE
21 #define DB_STORAGE
22
23 #include "someplayer.h"
24 #include "storage.h"
25 #include <QSqlDatabase>
26 #include <QSqlQuery>
27 #include "track.h"
28 #include "playlist.h"
29
30 #define _DATABASE_NAME_ "/library.sqlite3"
31
32 // represents database storage
33 // it store date into some database (e.g. tracks)
34
35 using SomePlayer::DataObjects::Playlist;
36 using SomePlayer::DataObjects::Track;
37
38 namespace SomePlayer {
39         namespace Storage {
40
41                 class DbStorage {
42                 public:
43                         DbStorage(QString path);
44                         ~DbStorage();
45                         QList<QString> getArtists();
46                         QList<QString> getAlbumsForArtist(QString artist);
47                         QList<Track> getTracksForAlbum(QString album, QString artist); // hm...
48
49                         Playlist getFavorites();
50                         Playlist getMostPlayed();
51                         Playlist getNeverPlayed();
52                         Playlist getRecentlyAdded();
53
54                         void removeTrack(Track track);
55                         void addToFavorites(Track track);
56
57                         void updateTrackCount(Track track);
58                         Track updateTrack(Track);
59                         void addTrack(Track track);
60
61                 private:
62                         QSqlDatabase db;
63                         void _create_database_structure();
64                         void _prepare_queries();
65
66                         int _check_add_artist(QString artist);
67                         int _check_add_album(QString album, int artist_id);
68
69                         // queries
70                         QSqlQuery *_get_artists_query;
71                         QSqlQuery *_get_albums_for_artist_query;
72                         QSqlQuery *_get_tracks_for_album_query;
73                         QSqlQuery *_get_favorites_query;
74                         QSqlQuery *_get_most_played_query;
75                         QSqlQuery *_get_never_played_query;
76                         QSqlQuery *_get_recently_added_query;
77                         QSqlQuery *_get_track_count;
78                         QSqlQuery *_get_track_by_source_query;
79
80                         QSqlQuery *_check_artist_query;
81                         QSqlQuery *_check_album_query;
82                         QSqlQuery *_check_track_query;
83
84                         QSqlQuery *_insert_artist_query;
85                         QSqlQuery *_insert_album_query;
86                         QSqlQuery *_insert_track_query;
87                         QSqlQuery *_insert_date_query;
88                         QSqlQuery *_insert_favorites_query;
89
90                         QSqlQuery *_update_track_count_query;
91
92                         QSqlQuery *_remove_track_query;
93                 };
94         };
95 };
96
97 #endif