File indexing completed on 2024-05-19 04:50:18

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #ifndef MAGNATUNEMETA_H
0018 #define MAGNATUNEMETA_H
0019 
0020 
0021 #include "../ServiceMetaBase.h"
0022 #include "../ServiceAlbumCoverDownloader.h"
0023 
0024 #include <QDateTime>
0025 #include <QList>
0026 #include <QString>
0027 #include <QStringList>
0028 
0029 class MagnatuneStore;
0030 
0031 namespace Meta
0032 {
0033     
0034 class MagnatuneTrack  : public ServiceTrack
0035 {
0036     Q_OBJECT
0037 public:
0038     explicit MagnatuneTrack( const QString &name );
0039     explicit  MagnatuneTrack( const QStringList &resultRow );
0040 
0041     QString lofiUrl();
0042     void setLofiUrl( const QString &url );
0043 
0044     QList<QString> moods() const;
0045     void setMoods(  const QList<QString> &moods );
0046 
0047     void setDownloadMembership();
0048 
0049     QString sourceName() override;
0050     QString sourceDescription() override;
0051     QPixmap emblem() override;
0052 
0053     bool isBookmarkable() const override { return true; }
0054     QString collectionName() const override { return QStringLiteral("Magnatune.com"); }
0055     bool simpleFiltering() const override { return false; }
0056 
0057     void setOggUrl( const QString& url );
0058     QString oggUrl() const;
0059 
0060     void setAlbumPtr( const Meta::AlbumPtr &album ) override;
0061 
0062 public Q_SLOTS:
0063     void download();
0064 
0065 private:
0066     QString m_lofiUrl;
0067     QString m_oggUrl;
0068     bool m_downloadMembership;
0069     QList<QString> m_moods;
0070 };
0071 
0072 
0073 class MagnatuneArtist : public ServiceArtist
0074 {
0075 private:
0076 
0077     QUrl m_photoUrl;
0078     QUrl m_magnatuneUrl;
0079 
0080 public:
0081     explicit MagnatuneArtist( const QString &name );
0082     explicit MagnatuneArtist( const QStringList &resultRow );
0083 
0084     void setPhotoUrl( const QUrl &photoUrl );
0085     QUrl photoUrl() const;
0086 
0087     void setMagnatuneUrl( const QUrl &url );
0088     QUrl magnatuneUrl() const;
0089 
0090     bool isBookmarkable() const override { return true; }
0091     QString collectionName() const override { return QStringLiteral("Magnatune.com"); }
0092     bool simpleFiltering() const override { return false; }
0093 };
0094 
0095 class MagnatuneAlbum : public ServiceAlbumWithCover
0096 {
0097     Q_OBJECT
0098 private:
0099     QString m_coverUrl;
0100     int m_launchYear;
0101     QString m_albumCode;
0102     MagnatuneStore * m_store;
0103     bool m_downloadMembership;
0104 
0105 
0106 public:
0107     explicit MagnatuneAlbum( const QString &name );
0108     explicit MagnatuneAlbum( const QStringList &resultRow );
0109 
0110     ~MagnatuneAlbum() override;
0111     
0112     QString downloadPrefix() const override { return QStringLiteral("magnatune"); }
0113 
0114     void setLaunchYear( int launchYear );
0115     int launchYear() const;
0116 
0117     void setCoverUrl( const QString &coverUrl ) override;
0118     QString coverUrl() const override;
0119 
0120     QUrl imageLocation( int size = 1 ) override { Q_UNUSED( size ); return QUrl( coverUrl() ); }
0121     
0122     void setAlbumCode(  const QString &albumCode );
0123     QString albumCode();
0124 
0125     void setStore( MagnatuneStore * store );
0126     MagnatuneStore * store();
0127 
0128     void setDownloadMembership();
0129 
0130     bool isBookmarkable() const override { return true; }
0131     QString collectionName() const override { return QStringLiteral("Magnatune.com"); }
0132     bool simpleFiltering() const override { return false; }
0133 
0134 public Q_SLOTS:
0135     void download();
0136     void addToFavorites();
0137 };
0138 
0139 class MagnatuneGenre  : public ServiceGenre
0140 {
0141 
0142 public:
0143     explicit MagnatuneGenre( const QString &name );
0144     explicit MagnatuneGenre( const QStringList &resultRow );
0145 
0146     bool isBookmarkable() const override { return true; }
0147     QString collectionName() const override { return QStringLiteral("Magnatune.com"); }
0148     bool simpleFiltering() const override { return false; }
0149 };
0150 
0151 }
0152 
0153 class MagnatuneMetaFactory : public ServiceMetaFactory
0154 {
0155 
0156     public:
0157         enum { OGG = 0, MP3 = 1, LOFI = 2 };
0158         
0159         MagnatuneMetaFactory( const QString &dbPrefix, MagnatuneStore * store );
0160         ~MagnatuneMetaFactory() override {}
0161 
0162         int getTrackSqlRowCount() override;
0163         QString getTrackSqlRows() override;
0164         Meta::TrackPtr createTrack( const QStringList &rows ) override;
0165 
0166         int getAlbumSqlRowCount() override;
0167         QString getAlbumSqlRows() override;
0168         Meta::AlbumPtr createAlbum( const QStringList &rows ) override;
0169 
0170         int getArtistSqlRowCount() override;
0171         QString getArtistSqlRows() override;
0172         Meta::ArtistPtr createArtist( const QStringList &rows ) override;
0173 
0174     //virtual int getGenreSqlRowCount();
0175     //virtual QString getGenreSqlRows();
0176         Meta::GenrePtr createGenre( const QStringList &rows ) override;
0177 
0178         //stuff for supporting the new membership services at Magnatune.com
0179 
0180         void setMembershipInfo ( const QString &prefix, const QString &userName, const QString &password );
0181         void setStreamType( int type );
0182 
0183     private:
0184         QString m_membershipPrefix;
0185         int m_streamType;
0186 
0187         QString m_userName;
0188         QString m_password;
0189         MagnatuneStore * m_store;
0190 };
0191 
0192 
0193 #endif