example/lastfmmusicsearchplugin/lastfmmusicsearchplugin.h
changeset 23 574948b60dab
child 26 83d6a149c755
equal deleted inserted replaced
22:b2eb79881f9d 23:574948b60dab
       
     1 /**
       
     2  * Copyright (c) 2010 Sasken Communication Technologies Ltd.
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the "Eclipse Public License v1.0" 
       
     6  * which accompanies  this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html"
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution
       
    11  *
       
    12  * Contributors:
       
    13  * Nalina Hariharan
       
    14  * 
       
    15  * Description:
       
    16  * The Plugin that does music search related functionalities from last.fm site
       
    17  *
       
    18  */
       
    19 
       
    20 #ifndef _LASTFMMUSICSEARCHPLUGIN_H
       
    21 #define _LASTFMMUSICSEARCHPLUGIN_H
       
    22 
       
    23 // Include files
       
    24 #include <smfmusicsearchplugin.h>
       
    25 
       
    26 // Class declaration
       
    27 class LastFmMusicSearchProviderBase;
       
    28 class QVariant;
       
    29 
       
    30 /**
       
    31  * The Plugin does music serach related functionalities from last.fm site
       
    32  */
       
    33 class LastFmMusicSearchPlugin : public QObject, public SmfMusicSearchPlugin
       
    34 	{
       
    35 	Q_OBJECT
       
    36 	Q_INTERFACES( SmfMusicSearchPlugin SmfPluginBase )
       
    37 	
       
    38 public:
       
    39 	/**
       
    40 	 * Destructor
       
    41 	 */
       
    42 	virtual ~LastFmMusicSearchPlugin ( );
       
    43 
       
    44 public: // From SmfMusicSearchPlugin interface
       
    45 	/**
       
    46 	 * Method to get recommended tracks
       
    47 	 * @param aRequest [out] The request data to be sent to network
       
    48 	 * @param aTrack The track for which similar recommendations 
       
    49 	 * need to be fetched.
       
    50 	 * @param aPageNum The page to be extracted
       
    51 	 * @param aItemsPerPage Number of items per page
       
    52 	 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
    53 	 */
       
    54 	SmfPluginError recommendations( SmfPluginRequestData &aRequest,
       
    55 			const SmfTrackInfo &aTrack,
       
    56 			const int aPageNum = SMF_FIRST_PAGE, 
       
    57 			const int aItemsPerPage = SMF_ITEMS_PER_PAGE );
       
    58 	
       
    59 	/**
       
    60 	 * Method to search for tracks similar to a given track
       
    61 	 * @param aRequest [out] The request data to be sent to network
       
    62 	 * @param aTrack The track for which similar tracks 
       
    63 	 * need to be fetched.
       
    64 	 * @param aPageNum The page to be extracted
       
    65 	 * @param aItemsPerPage Number of items per page
       
    66 	 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
    67 	 */
       
    68 	SmfPluginError tracksSimilar( SmfPluginRequestData &aRequest,
       
    69 			const SmfTrackInfo &aTrack,
       
    70 			const int aPageNum = SMF_FIRST_PAGE, 
       
    71 			const int aItemsPerPage = SMF_ITEMS_PER_PAGE );
       
    72 	
       
    73 	/**
       
    74 	 * Method to search for tracks of a given album
       
    75 	 * @param aRequest [out] The request data to be sent to network
       
    76 	 * @param aAlbum The album whose tracks need to be fetched.
       
    77 	 * @param aPageNum The page to be extracted
       
    78 	 * @param aItemsPerPage Number of items per page
       
    79 	 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
    80 	 */
       
    81 	SmfPluginError tracksOfAlbum( SmfPluginRequestData &aRequest,
       
    82 			const SmfAlbum &aAlbum,
       
    83 			const int aPageNum = SMF_FIRST_PAGE, 
       
    84 			const int aItemsPerPage = SMF_ITEMS_PER_PAGE );
       
    85 	
       
    86 	/**
       
    87 	 * Method to search for tracks of the given artist(s)
       
    88 	 * @param aRequest [out] The request data to be sent to network
       
    89 	 * @param aArtist The artist(s) whose tracks need to be fetched.
       
    90 	 * @param aPageNum The page to be extracted
       
    91 	 * @param aItemsPerPage Number of items per page
       
    92 	 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
    93 	 */
       
    94 	SmfPluginError tracksOfArtist( SmfPluginRequestData &aRequest,
       
    95 			const SmfArtists &aArtist,
       
    96 			const int aPageNum = SMF_FIRST_PAGE, 
       
    97 			const int aItemsPerPage = SMF_ITEMS_PER_PAGE );
       
    98 	
       
    99 	/**
       
   100 	 * Method to get tracks having a similar finger print
       
   101 	 * @param aRequest [out] The request data to be sent to network
       
   102 	 * @param aSignature The finger print to be searched for need to be 
       
   103 	 * fetched.
       
   104 	 * @param aPageNum The page to be extracted
       
   105 	 * @param aItemsPerPage Number of items per page
       
   106 	 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
   107 	 */
       
   108 	SmfPluginError trackInfo( SmfPluginRequestData &aRequest,
       
   109 			const SmfMusicFingerPrint &aSignature,
       
   110 			const int aPageNum = SMF_FIRST_PAGE, 
       
   111 			const int aItemsPerPage = SMF_ITEMS_PER_PAGE );
       
   112 	
       
   113 	/**
       
   114 	 * Method to search information about where to buy this song from
       
   115 	 * @param aRequest [out] The request data to be sent to network
       
   116 	 * @param aTrack The track for which stores need to be searched
       
   117 	 * @param aPageNum The page to be extracted
       
   118 	 * @param aItemsPerPage Number of items per page
       
   119 	 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
   120 	 */
       
   121 	SmfPluginError stores( SmfPluginRequestData &aRequest,
       
   122 			const SmfTrackInfo &aTrack,
       
   123 			const int aPageNum = SMF_FIRST_PAGE, 
       
   124 			const int aItemsPerPage = SMF_ITEMS_PER_PAGE );
       
   125 	
       
   126 	/**
       
   127 	 * Customised method for SmfMusicSearchPlugin interface
       
   128 	 * @param aRequest [out] The request data to be sent to network
       
   129 	 * @param aOperation The operation type (should be known between 
       
   130 	 * the client interface and the plugin)
       
   131 	 * @param aData The data required to form the request (The type 
       
   132 	 * of data should be known between client and the plugin)
       
   133 	 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
   134 	 */
       
   135 	SmfPluginError customRequest( SmfPluginRequestData &aRequest, 
       
   136 			const int &aOperation, QByteArray *aData );
       
   137 	
       
   138 public: // From SmfPluginBase interface
       
   139 	/**
       
   140 	 * The first method to be called in the plugin that implements this interface.
       
   141 	 * If this method is not called, plugin may not behave as expected.
       
   142 	 */
       
   143 	void initialize( );
       
   144 	
       
   145 	/**
       
   146 	 * Method to get the provider information
       
   147 	 * @return Instance of SmfProviderBase
       
   148 	 */
       
   149 	SmfProviderBase* getProviderInfo( );
       
   150 	
       
   151 	/**
       
   152 	 * Method to get the result for a network request.
       
   153 	 * @param aOperation The type of operation to be requested
       
   154 	 * @param aTransportResult The result of transport operation
       
   155 	 * @param aResponse The QByteArray instance containing the network response.
       
   156 	 * The plugins should delete this instance once they have read the 
       
   157 	 * data from it.
       
   158 	 * @param aResult [out] An output parameter to the plugin manager.If the 
       
   159 	 * return value is SmfSendRequestAgain, QVariant will be of type 
       
   160 	 * SmfPluginRequestData.
       
   161 	 * For SmfMusicSearchPlugin: If last operation was recommendations(), 
       
   162 	 * tracksSimilar() or tracksOfAlbum() or tracksOfArtist() or trackInfo(), 
       
   163 	 * aResult will be of type QList<SmfTrackInfo>. 
       
   164 	 * If last operation was stores(), aResult will be of type QList<SmfProvider>.
       
   165 	 * @param aRetType [out] SmfPluginRetType
       
   166 	 * @param aPageResult [out] The SmfResultPage structure variable
       
   167 	 */
       
   168 	SmfPluginError responseAvailable( 
       
   169 			const SmfRequestTypeID aOperation,
       
   170 			const SmfTransportResult &aTransportResult, 
       
   171 			QByteArray *aResponse, 
       
   172 			QVariant* aResult, 
       
   173 			SmfPluginRetType &aRetType,
       
   174 			SmfResultPage &aPageResult );
       
   175 	
       
   176 private:
       
   177 	/**
       
   178 	 * Method called by plugins to generate a signature string from a base string
       
   179 	 * @param aBaseString The base string
       
   180 	 * @return The md5 hash of the base string
       
   181 	 */
       
   182 	QString generateSignature(const QString aBaseString);
       
   183 	
       
   184 	/**
       
   185 	 * Method to interpret the key sets obtained from credential manager 
       
   186 	 * @param aApiKey [out] The api key
       
   187 	 * @param aApiSecret [out] The api secret
       
   188 	 * @param aSessionKey [out] The session key
       
   189 	 * @param aToken [out] The session token
       
   190 	 */
       
   191 	void fetchKeys( QString &aApiKey, 
       
   192 			QString &aApiSecret, 
       
   193 			QString &aToken );
       
   194 	
       
   195 	/**
       
   196 	 * Method to get the last.fm specific ID of the given album
       
   197 	 * @param aRequest [out] The request data to be sent to network
       
   198 	 * @param aAlbum The album whose tracks need to be fetched.
       
   199 	 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
   200 	 */
       
   201 	SmfPluginError getAlbumId( SmfPluginRequestData &aRequest,
       
   202 			const SmfAlbum &aAlbum );
       
   203 	/**
       
   204 	 * Method to search for tracks of a given album using its ID in last.fm
       
   205 	 * @param aRequest [out] The request data to be sent to network
       
   206 	 * @param aAlbum The album whose tracks need to be fetched.
       
   207 	 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
   208 	 */
       
   209 	SmfPluginError getTracksOfAlbum( SmfPluginRequestData &aRequest,
       
   210 			const SmfAlbum &aAlbum );
       
   211 	
       
   212 	/**
       
   213 	 * Method to get the current country name as per ISO 3166-1 standard.
       
   214 	 * @return Current country name
       
   215 	 */
       
   216 	QString currentCountryName() const;
       
   217 	
       
   218 private: // Data
       
   219 	LastFmMusicSearchProviderBase *m_provider;
       
   220 	};
       
   221 
       
   222 
       
   223 
       
   224 /**
       
   225  * The Plugin class that implements SmfProviderBase for this last.fm plugin
       
   226  */
       
   227 class LastFmMusicSearchProviderBase : public QObject, public SmfProviderBase
       
   228 	{
       
   229 	Q_OBJECT
       
   230 	Q_INTERFACES( SmfProviderBase )
       
   231 
       
   232 public:
       
   233 	/**
       
   234 	 * Destructor
       
   235 	 */
       
   236 	virtual ~LastFmMusicSearchProviderBase( );
       
   237 
       
   238 	/**
       
   239 	 * Method to get the Localisable name of the service.
       
   240 	 * @return The Localisable name of the service.
       
   241 	 */
       
   242 	QString serviceName( ) const;
       
   243 	
       
   244 	/**
       
   245 	 * Method to get the Logo of the service
       
   246 	 * @return The Logo of the service
       
   247 	 */
       
   248 	QImage serviceIcon( ) const;
       
   249 	
       
   250 	/**
       
   251 	 * Method to get the Readable service description
       
   252 	 * @return The Readable service description
       
   253 	 */
       
   254 	QString description( ) const;
       
   255 	
       
   256 	/**
       
   257 	 * Method to get the Website of the service
       
   258 	 * @return The Website of the service
       
   259 	 */
       
   260 	QUrl serviceUrl( ) const;
       
   261 	
       
   262 	/**
       
   263 	 * Method to get the URL of the Application providing this service
       
   264 	 * @return The URL of the Application providing this service
       
   265 	 */
       
   266 	QUrl applicationUrl( ) const;
       
   267 	
       
   268 	/**
       
   269 	 * Method to get the Icon of the application
       
   270 	 * @return The Icon of the application
       
   271 	 */
       
   272 	QImage applicationIcon( ) const;
       
   273 	
       
   274 	/**
       
   275 	* Method to get the list of interfaces that this provider support
       
   276 	* @return List of supported Interafces
       
   277 	*/
       
   278 	QList<QString> supportedInterfaces( ) const;
       
   279 	
       
   280 	/**
       
   281 	* Method to get the list of languages supported by this service provider
       
   282 	* @return a QStringList of languages supported by this service 
       
   283 	* provider in 2 letter ISO 639-1 format.
       
   284 	*/
       
   285 	QStringList supportedLanguages( ) const;
       
   286 	
       
   287 	/**
       
   288 	 * Method to get the Plugin specific ID
       
   289 	 * @return The Plugin specific ID
       
   290 	 */
       
   291 	QString pluginId( ) const;
       
   292 	
       
   293 	/**
       
   294 	 * Method to get the ID of the authentication application 
       
   295 	 * for this service
       
   296 	 * @param aProgram The authentication application name
       
   297 	 * @param aArguments List of arguments required for authentication app
       
   298 	 * @param aMode Strting mode for authentication application
       
   299 	 * @return The ID of the authentication application 
       
   300 	 */
       
   301 	QString authenticationApp( QString &aProgram, QStringList & aArguments, 
       
   302 			QIODevice::OpenModeFlag aMode = QIODevice::ReadWrite ) const;
       
   303 	
       
   304 	/**
       
   305 	 * Method to get the unique registration ID provided by the 
       
   306 	 * Smf for authorised plugins
       
   307 	 * @return The unique registration ID/token provided by the Smf for 
       
   308 	 * authorised plugins
       
   309 	 */
       
   310 	QString smfRegistrationId( ) const;
       
   311 	
       
   312 private:
       
   313 	/**
       
   314 	 * Method that initializes this class. This method should be called 
       
   315 	 * from the initialize() method of the FBContactFetcherPlugin class
       
   316 	 */
       
   317 	void initialize();
       
   318 	
       
   319 private:
       
   320 	friend class LastFmMusicSearchPlugin;
       
   321 	QString m_serviceName;
       
   322 	QImage m_serviceIcon;
       
   323 	QString m_description;
       
   324 	QUrl m_serviceUrl;
       
   325 	QUrl m_applicationUrl;
       
   326 	QImage m_applicationIcon;
       
   327 	QString m_pluginId;
       
   328 	QString m_authAppId;
       
   329 	QString m_smfRegToken;
       
   330 	QList<QString> m_supportedInterfaces;
       
   331 	QStringList m_supportedLangs;
       
   332 	QDateTime m_validity;
       
   333 	};
       
   334 
       
   335 #endif //_LASTFMMUSICSEARCHPLUGIN_H