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

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  * Copyright (c) 2008 Casey Link <unnamedrambler@gmail.com>                             *
0004  *                                                                                      *
0005  * This program is free software; you can redistribute it and/or modify it under        *
0006  * the terms of the GNU General Public License as published by the Free Software        *
0007  * Foundation; either version 2 of the License, or (at your option) any later           *
0008  * version.                                                                             *
0009  *                                                                                      *
0010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0012  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0013  *                                                                                      *
0014  * You should have received a copy of the GNU General Public License along with         *
0015  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0016  ****************************************************************************************/
0017 
0018 #ifndef MP3TUNESSERVICE_H
0019 #define MP3TUNESSERVICE_H
0020 
0021 #include "../ServiceBase.h"
0022 #include "Mp3tunesServiceCollection.h"
0023 #include "Mp3tunesLocker.h"
0024 #include "Mp3tunesWorkers.h"
0025 #include "harmonydaemon/Mp3tunesHarmonyDownload.h"
0026 #include "Mp3tunesHarmonyHandler.h"
0027 #include <QVariantMap>
0028 
0029 class Mp3tunesServiceFactory: public ServiceFactory
0030 {
0031     Q_PLUGIN_METADATA(IID AmarokPluginFactory_iid FILE "amarok_service_mp3tunes.json")
0032     Q_INTERFACES(Plugins::PluginFactory)
0033     Q_OBJECT
0034 
0035     public:
0036         Mp3tunesServiceFactory();
0037         virtual ~Mp3tunesServiceFactory() {}
0038 
0039         virtual bool possiblyContainsTrack( const QUrl &url ) const;
0040 
0041         virtual void init();
0042         virtual QString name();
0043         virtual KConfigGroup config();
0044 
0045     private:
0046         ServiceBase* createService();
0047 };
0048 
0049 
0050 /**
0051     A service for displaying, previewing and downloading music from Mp3tunes.com
0052     @author
0053 */
0054 class Mp3tunesService : public ServiceBase
0055 {
0056 
0057 Q_OBJECT
0058 
0059 public:
0060     explicit Mp3tunesService( Mp3tunesServiceFactory* parent,
0061                               const QString &name,
0062                               const QString &partnerToken,
0063                               const QString &email = QString(),
0064                               const QString &password = QString(),
0065                               bool harmonyEnabled = false );
0066 
0067     ~Mp3tunesService();
0068 
0069     /**
0070      * Helper function to redraw the service's ui elements
0071      */
0072     void polish();
0073 
0074     virtual Collections::Collection * collection() { return m_collection; }
0075 
0076 private Q_SLOTS:
0077     /**
0078      * Enables harmony
0079      */
0080     void enableHarmony();
0081 
0082     /**
0083      * Disables harmony
0084      */
0085     void disableHarmony();
0086 
0087     /**
0088      * Logs the user into the locker, prompts them for a user/pass if not supplied
0089      */
0090     void authenticate( const QString & uname = "", const QString & passwd = "" );
0091 
0092     /**
0093      * Handles authentication reply.
0094      */
0095     void authenticationComplete(  const QString & sessionId );
0096 
0097     /**
0098      * the daemon received the PIN. now that pin has to be presented to the user,
0099      * so he/she (comments must be gender neutral) can add it to his/her mp3tunes
0100      * account.
0101      */
0102     void harmonyWaitingForEmail( const QString &pin );
0103     void harmonyWaitingForPin();
0104     void harmonyConnected();
0105     void harmonyDisconnected();
0106     void harmonyError( const QString &error );
0107     void harmonyDownloadReady( const QVariantMap &download );
0108     void harmonyDownloadPending( const QVariantMap &download );
0109 
0110 private:
0111     /**
0112      * Helper function that draws the menu bar above the tree view
0113      */
0114     void initTopPanel();
0115 
0116     /**
0117      * Helper function that draws the ui elements below the tree view
0118      */
0119     void initBottomPanel();
0120 
0121     QString m_email;
0122     QString m_password;
0123     bool m_harmonyEnabled; // if the user has enabled harmony
0124     QString m_partnerToken;
0125 
0126     bool m_authenticated; // true if mp3tunes has authenticated successfully
0127     bool m_authenticationFailed;
0128     QString m_sessionId; // the mp3tunes sid
0129 
0130     Collections::Mp3tunesServiceCollection *  m_collection;
0131     Mp3tunesLoginWorker * m_loginWorker; // used to see if logging in has completed
0132     Mp3tunesLocker * m_locker; // the actual locker
0133     Mp3tunesHarmonyHandler * m_harmony;
0134 };
0135 
0136 #endif