File indexing completed on 2024-05-19 04:50:19
0001 /**************************************************************************************** 0002 * Copyright (c) 2006,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 AMAROKMAGNATUNESTORE_H 0018 #define AMAROKMAGNATUNESTORE_H 0019 0020 0021 #include "core/support/Amarok.h" 0022 #include "MagnatuneDownloadHandler.h" 0023 #include "MagnatuneRedownloadHandler.h" 0024 #include "MagnatuneXmlParser.h" 0025 #include "MagnatuneDatabaseHandler.h" 0026 #include "MagnatuneSqlCollection.h" 0027 0028 #include "../ServiceBase.h" 0029 0030 #include <KJob> 0031 0032 #include <QCheckBox> 0033 #include <QComboBox> 0034 #include <QPushButton> 0035 0036 0037 class MagnatuneInfoParser; 0038 class MagnatuneNeedUpdateWidget; 0039 0040 class MagnatuneServiceFactory : public ServiceFactory 0041 { 0042 Q_PLUGIN_METADATA(IID AmarokPluginFactory_iid FILE "amarok_service_magnatunestore.json") 0043 Q_INTERFACES(Plugins::PluginFactory) 0044 Q_OBJECT 0045 0046 public: 0047 MagnatuneServiceFactory(); 0048 ~MagnatuneServiceFactory() override {} 0049 0050 void init() override; 0051 QString name() override; 0052 KConfigGroup config() override; 0053 0054 bool possiblyContainsTrack( const QUrl &url ) const override { return url.url().contains( "magnatune.com", Qt::CaseInsensitive ); } 0055 }; 0056 0057 0058 /** 0059 Amarok browser that displays all the music available at magnatune.com and makes it available for previewing and purchasing. 0060 Implemented as a singleton 0061 0062 @author Nikolaj Hald Nielsen <nhn@kde.org> 0063 */ 0064 class MagnatuneStore: public ServiceBase 0065 { 0066 Q_OBJECT 0067 0068 public: 0069 /** 0070 * Constructor 0071 */ 0072 explicit MagnatuneStore( MagnatuneServiceFactory* parent, const char *name ); 0073 /** 0074 * Destructor 0075 */ 0076 ~MagnatuneStore() override; 0077 0078 void setMembership( int type, const QString &username, const QString &password ); 0079 0080 /** 0081 * OGG, MP3 or LOFI 0082 */ 0083 void setStreamType( int ); 0084 0085 /** 0086 * Do not do expensive initializations before we are actually shown 0087 */ 0088 void polish() override; 0089 // bool updateContextView(); 0090 0091 Collections::Collection * collection() override { return m_collection; } 0092 0093 QString messages() override; 0094 QString sendMessage( const QString &message ) override; 0095 0096 public Q_SLOTS: 0097 /** 0098 * Slot for catching cancelled list downloads 0099 */ 0100 void listDownloadCancelled(); 0101 0102 void downloadTrack( Meta::MagnatuneTrack * track ); 0103 0104 void downloadAlbum( Meta::MagnatuneAlbum * album ); 0105 0106 void showFavoritesPage(); 0107 void showHomePage(); 0108 void showRecommendationsPage(); 0109 0110 void addToFavorites( const QString &sku ); 0111 void removeFromFavorites( const QString &sku ); 0112 0113 private Q_SLOTS: 0114 /** 0115 * Slot called when the download album button is clicked. Starts a download 0116 */ 0117 void download(); 0118 0119 void downloadSku( const QString &sku ); 0120 0121 /** 0122 * Slot for receiving notification that the update button has been clicked. 0123 */ 0124 void updateButtonClicked(); 0125 0126 0127 /** 0128 * Slot for receiving notification when the Magnatune xml file has been downloaded. 0129 * Triggers a parse of the file to get the info added to the database 0130 * @param downLoadJob The calling download Job 0131 */ 0132 void listDownloadComplete( KJob* downLoadJob ); 0133 0134 0135 /** 0136 * Slot called when the parsing of the Magnatune xml file is completed. 0137 * Triggers an update of the list view and the genre combo box 0138 */ 0139 void doneParsing(); 0140 0141 /** 0142 * Starts the process of redownloading a previously bought album 0143 */ 0144 void processRedownload(); 0145 0146 /** 0147 * Slot for receiving notifications of completed download operations 0148 * @param success Was the operation a success? 0149 */ 0150 void downloadCompleted( bool success ); 0151 0152 0153 /** 0154 * Adds all tracks with a common mood to the playlist 0155 * @param mood The mood of the tracks to add 0156 */ 0157 void addMoodyTracksToPlaylist( const QString &mood, int count ); 0158 0159 0160 /** 0161 * Checks if download button should be enabled 0162 * @param selectedItem the new selected item 0163 */ 0164 void itemSelected( CollectionTreeItem * selectedItem ); 0165 0166 0167 void moodMapReady(const QMap<QString, int> &map ); 0168 void moodyTracksReady( const Meta::TrackList &tracks ); 0169 0170 void timestampDownloadComplete( KJob * job ); 0171 void favoritesResult( KJob* addToFavoritesJob ); 0172 0173 private: 0174 /** 0175 * Helper function that initializes the button panel below the list view 0176 */ 0177 void initBottomPanel(); 0178 0179 /** 0180 * Helper function that initializes the genre selection panel above the list view 0181 */ 0182 void initTopPanel(); 0183 0184 /** 0185 * Starts downloading an updated track list xml file from 0186 * http://magnatune.com/info/album_info.xml 0187 * @return Currently always returns true 0188 */ 0189 bool updateMagnatuneList(); 0190 0191 void checkForUpdates(); 0192 0193 /** 0194 * Adds a magnatune preview track to the playlist. 0195 * @param item The track to add 0196 */ 0197 //void addTrackToPlaylist ( Meta::MagnatuneTrack *item ); 0198 0199 void showSignupDialog(); 0200 0201 static MagnatuneStore *s_instance; 0202 0203 QString m_currentInfoUrl; 0204 MagnatuneDownloadHandler *m_downloadHandler; 0205 MagnatuneRedownloadHandler *m_redownloadHandler; 0206 0207 QPushButton *m_downloadAlbumButton; 0208 MagnatuneNeedUpdateWidget *m_needUpdateWidget; 0209 0210 QAction * m_updateAction; 0211 0212 bool m_downloadInProgress; 0213 0214 Meta::MagnatuneAlbum * m_currentAlbum; 0215 0216 KIO::FileCopyJob * m_listDownloadJob; 0217 KIO::StoredTransferJob* m_updateTimestampDownloadJob; 0218 KIO::StoredTransferJob* m_favoritesJob; 0219 0220 Collections::MagnatuneSqlCollection * m_collection; 0221 0222 QString m_tempFileName; 0223 0224 bool m_isMember; 0225 int m_membershipType; 0226 QString m_username; 0227 QString m_password; 0228 0229 int m_streamType; 0230 0231 qulonglong m_magnatuneTimestamp; 0232 ServiceSqlRegistry * m_registry; 0233 0234 MagnatuneInfoParser * m_magnatuneInfoParser; 0235 0236 QDialog *m_signupInfoWidget; 0237 }; 0238 0239 0240 #endif