1 /****************************************************************************************
2  * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org>                                *
3  *                                                                                      *
4  * This program is free software; you can redistribute it and/or modify it under        *
5  * the terms of the GNU General Public License as published by the Free Software        *
6  * Foundation; either version 2 of the License, or (at your option) any later           *
7  * version.                                                                             *
8  *                                                                                      *
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
11  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
12  *                                                                                      *
13  * You should have received a copy of the GNU General Public License along with         *
14  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
15  ****************************************************************************************/
16 
17 #ifndef MAGNATUNEMETA_H
18 #define MAGNATUNEMETA_H
19 
20 
21 #include "../ServiceMetaBase.h"
22 #include "../ServiceAlbumCoverDownloader.h"
23 
24 #include <QDateTime>
25 #include <QList>
26 #include <QString>
27 #include <QStringList>
28 
29 class MagnatuneStore;
30 
31 namespace Meta
32 {
33 
34 class MagnatuneTrack  : public ServiceTrack
35 {
36     Q_OBJECT
37 public:
38     explicit MagnatuneTrack( const QString &name );
39     explicit  MagnatuneTrack( const QStringList &resultRow );
40 
41     QString lofiUrl();
42     void setLofiUrl( const QString &url );
43 
44     QList<QString> moods() const;
45     void setMoods(  const QList<QString> &moods );
46 
47     void setDownloadMembership();
48 
49     QString sourceName() override;
50     QString sourceDescription() override;
51     QPixmap emblem() override;
52 
isBookmarkable()53     bool isBookmarkable() const override { return true; }
collectionName()54     QString collectionName() const override { return QStringLiteral("Magnatune.com"); }
simpleFiltering()55     bool simpleFiltering() const override { return false; }
56 
57     void setOggUrl( const QString& url );
58     QString oggUrl() const;
59 
60     void setAlbumPtr( const Meta::AlbumPtr &album ) override;
61 
62 public Q_SLOTS:
63     void download();
64 
65 private:
66     QString m_lofiUrl;
67     QString m_oggUrl;
68     bool m_downloadMembership;
69     QList<QString> m_moods;
70 };
71 
72 
73 class MagnatuneArtist : public ServiceArtist
74 {
75 private:
76 
77     QUrl m_photoUrl;
78     QUrl m_magnatuneUrl;
79 
80 public:
81     explicit MagnatuneArtist( const QString &name );
82     explicit MagnatuneArtist( const QStringList &resultRow );
83 
84     void setPhotoUrl( const QUrl &photoUrl );
85     QUrl photoUrl() const;
86 
87     void setMagnatuneUrl( const QUrl &url );
88     QUrl magnatuneUrl() const;
89 
isBookmarkable()90     bool isBookmarkable() const override { return true; }
collectionName()91     QString collectionName() const override { return QStringLiteral("Magnatune.com"); }
simpleFiltering()92     bool simpleFiltering() const override { return false; }
93 };
94 
95 class MagnatuneAlbum : public ServiceAlbumWithCover
96 {
97     Q_OBJECT
98 private:
99     QString m_coverUrl;
100     int m_launchYear;
101     QString m_albumCode;
102     MagnatuneStore * m_store;
103     bool m_downloadMembership;
104 
105 
106 public:
107     explicit MagnatuneAlbum( const QString &name );
108     explicit MagnatuneAlbum( const QStringList &resultRow );
109 
110     ~MagnatuneAlbum() override;
111 
downloadPrefix()112     QString downloadPrefix() const override { return QStringLiteral("magnatune"); }
113 
114     void setLaunchYear( int launchYear );
115     int launchYear() const;
116 
117     void setCoverUrl( const QString &coverUrl ) override;
118     QString coverUrl() const override;
119 
120     QUrl imageLocation( int size = 1 ) override { Q_UNUSED( size ); return QUrl( coverUrl() ); }
121 
122     void setAlbumCode(  const QString &albumCode );
123     QString albumCode();
124 
125     void setStore( MagnatuneStore * store );
126     MagnatuneStore * store();
127 
128     void setDownloadMembership();
129 
isBookmarkable()130     bool isBookmarkable() const override { return true; }
collectionName()131     QString collectionName() const override { return QStringLiteral("Magnatune.com"); }
simpleFiltering()132     bool simpleFiltering() const override { return false; }
133 
134 public Q_SLOTS:
135     void download();
136     void addToFavorites();
137 };
138 
139 class MagnatuneGenre  : public ServiceGenre
140 {
141 
142 public:
143     explicit MagnatuneGenre( const QString &name );
144     explicit MagnatuneGenre( const QStringList &resultRow );
145 
isBookmarkable()146     bool isBookmarkable() const override { return true; }
collectionName()147     QString collectionName() const override { return QStringLiteral("Magnatune.com"); }
simpleFiltering()148     bool simpleFiltering() const override { return false; }
149 };
150 
151 }
152 
153 class MagnatuneMetaFactory : public ServiceMetaFactory
154 {
155 
156     public:
157         enum { OGG = 0, MP3 = 1, LOFI = 2 };
158 
159         MagnatuneMetaFactory( const QString &dbPrefix, MagnatuneStore * store );
~MagnatuneMetaFactory()160         ~MagnatuneMetaFactory() override {}
161 
162         int getTrackSqlRowCount() override;
163         QString getTrackSqlRows() override;
164         Meta::TrackPtr createTrack( const QStringList &rows ) override;
165 
166         int getAlbumSqlRowCount() override;
167         QString getAlbumSqlRows() override;
168         Meta::AlbumPtr createAlbum( const QStringList &rows ) override;
169 
170         int getArtistSqlRowCount() override;
171         QString getArtistSqlRows() override;
172         Meta::ArtistPtr createArtist( const QStringList &rows ) override;
173 
174     //virtual int getGenreSqlRowCount();
175     //virtual QString getGenreSqlRows();
176         Meta::GenrePtr createGenre( const QStringList &rows ) override;
177 
178         //stuff for supporting the new membership services at Magnatune.com
179 
180         void setMembershipInfo ( const QString &prefix, const QString &userName, const QString &password );
181         void setStreamType( int type );
182 
183     private:
184         QString m_membershipPrefix;
185         int m_streamType;
186 
187         QString m_userName;
188         QString m_password;
189         MagnatuneStore * m_store;
190 };
191 
192 
193 #endif
194