example/MusicLyricsPlugin/MusicLyricsPlugin.h
changeset 23 574948b60dab
child 26 83d6a149c755
equal deleted inserted replaced
22:b2eb79881f9d 23:574948b60dab
       
     1 /*
       
     2  * MusicLyricsPlugin.h
       
     3  *
       
     4  *  Created on: Aug 18, 2010
       
     5  *      Author: sanpra
       
     6  */
       
     7 
       
     8 
       
     9 
       
    10 #ifndef MUSICLYRICSPLUGIN_H_
       
    11 #define MUSICLYRICSPLUGIN_H_
       
    12 
       
    13 // Include files
       
    14 #include "smflyricsserviceplugin.h"
       
    15 #include "smfpluginutil.h"
       
    16 
       
    17 #include <parser.h>
       
    18 
       
    19 // Forward declarations
       
    20 class MusicProviderBase;
       
    21 class QVariant;
       
    22 class QNetworkReply;
       
    23 
       
    24 // Class declaration
       
    25 class MusicLyricsPlugin : public QObject, public SmfLyricsServicePlugin
       
    26 {
       
    27 	Q_OBJECT
       
    28 	Q_INTERFACES( SmfLyricsServicePlugin SmfPluginBase )
       
    29 
       
    30 public:
       
    31 	virtual ~MusicLyricsPlugin();
       
    32 	
       
    33 public: // From SmfMusicEventsPlugin
       
    34 	
       
    35 	/**
       
    36 		 * Method to get the lyrics
       
    37 		 * @param aRequest [out] The request data to be sent to network
       
    38 		 * @param aTrack The track whose lyrics need to be fetched
       
    39 		 * @param aPageNum The page to be extracted
       
    40 		 * @param aItemsPerPage Number of items per page
       
    41 		 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
    42 		 */
       
    43 		 SmfPluginError lyrics( SmfPluginRequestData &aRequest, 
       
    44 				const SmfTrackInfo &aTrack,
       
    45 				const int aPageNum = SMF_FIRST_PAGE, 
       
    46 				const int aItemsPerPage = SMF_ITEMS_PER_PAGE ) ;
       
    47 		
       
    48 		/**
       
    49 		 * Method to get the subtitle
       
    50 		 * @param aRequest [out] The request data to be sent to network
       
    51 		 * @param aTrack The track whose subtitle need to be fetched
       
    52 		 * @param aFilter The subtitle search filter if any
       
    53 		 * @param aPageNum The page to be extracted
       
    54 		 * @param aItemsPerPage Number of items per page
       
    55 		 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
    56 		 */
       
    57 		 SmfPluginError subtitles( SmfPluginRequestData &aRequest, 
       
    58 				const SmfTrackInfo &aTrack,
       
    59 				const SmfSubtitleSearchFilter &aFilter = SubtitleAll,
       
    60 				const int aPageNum = SMF_FIRST_PAGE, 
       
    61 				const int aItemsPerPage = SMF_ITEMS_PER_PAGE ) ;
       
    62 		/**
       
    63 		 * Customised method for SmfMusicEventsPlugin interface
       
    64 		 * @param aRequest [out] The request data to be sent to network
       
    65 		 * @param aOperation The operation type (should be known between 
       
    66 		 * the client interface and the plugin)
       
    67 		 * @param aData The data required to form the request (The type 
       
    68 		 * of data should be known between client and the plugin)
       
    69 		 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
    70 		 */
       
    71 		SmfPluginError customRequest( SmfPluginRequestData &aRequest, 
       
    72 				const int &aOperation, QByteArray *aData );
       
    73 	
       
    74 public: // From SmfPluginBase
       
    75 	     /**
       
    76 	     * The first method to be called in the plugin that implements this interface.
       
    77 	     * If this method is not called, plugin may not behave as expected.
       
    78 	     * Plugins are expected to save the aUtil handle and use and when required.
       
    79 	     * @param aUtil The instance of SmfPluginUtil
       
    80 	     */
       
    81 	     void initialize(/*SmfPluginUtil *aUtil*/);
       
    82 	
       
    83 	    /**
       
    84 	     * Method to get the provider information
       
    85 	     * @return Instance of SmfProviderBase
       
    86 	     */
       
    87 	    SmfProviderBase* getProviderInfo( );
       
    88 	
       
    89 	   /**
       
    90 	    * Method to get the result for a network request.
       
    91 	    * @param aTransportResult The result of transport operation
       
    92 	    * @param aReply The QNetworkReply instance for the request
       
    93 	    * @param aResult [out] An output parameter to the plugin manager.If the 
       
    94 	    * return value is SmfSendRequestAgain, QVariant will be of type 
       
    95 	    * SmfPluginRequestData.
       
    96 	    * For SmfGalleryPlugin: If last operation was pictures(), aResult will 
       
    97 	    * be of type QList<SmfPicture>. If last operation was description(), 
       
    98 	    * aResult will be of type QString. If last operation was upload() or 
       
    99 	    * postComment(), aResult will be of type bool.
       
   100 	    * @param aRetType [out] SmfPluginRetType
       
   101 	    * @param aPageResult [out] The SmfResultPage structure variable
       
   102 	    */
       
   103         /*	SmfPluginError responseAvailable( 
       
   104 			const SmfTransportResult &aTransportResult, 
       
   105 			QNetworkReply *aReply, 
       
   106 			QVariant* aResult, 
       
   107 			SmfPluginRetType &aRetType,
       
   108 			SmfResultPage &aPageResult );*/
       
   109         SmfPluginError responseAvailable( 
       
   110 			const SmfRequestTypeID aOperation,
       
   111 			const SmfTransportResult &aTransportResult, 
       
   112 			QByteArray *aResponse, 
       
   113 			QVariant* aResult, 
       
   114 			SmfPluginRetType &aRetType,
       
   115 			SmfResultPage &aPageResult );
       
   116 	
       
   117 	     void writeLog(QString log) const;
       
   118 	
       
   119 	
       
   120 private:
       
   121     
       
   122       QString generateSignature(const QString aBaseString);
       
   123     
       
   124     
       
   125 private slots:
       
   126    
       
   127     
       
   128 	
       
   129 private:
       
   130 	  /**
       
   131 	   * Method called by plugins to generate a request data
       
   132 	   * @param aRequest [out] The request data to be sent to network
       
   133 	   * @param aOperation The type of http operation
       
   134 	   * @param aSignatureMethod The signature method to be used
       
   135 	   * @param aParams A map of parameters to its values
       
   136 	   * @param aMode The mode of creation of the request
       
   137 	   * @param aPostData The data to be posted (for HTTP POST 
       
   138 	   * only, else it will be NULL)
       
   139 	   * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
   140 	   */
       
   141 	   SmfPluginError createRequest( SmfPluginRequestData &aRequest,const QNetworkAccessManager::Operation aOperation, 
       
   142 			const SmfSignatureMethod aSignatureMethod, 
       
   143 			QMultiMap<QByteArray, QByteArray> &aParams, 
       
   144 			const SmfParsingMode aMode,
       
   145 			QBuffer *aPostData );
       
   146 
       
   147 private:
       
   148 	   MusicProviderBase *m_provider;
       
   149 	   SmfPluginUtil *m_util;
       
   150 };
       
   151 
       
   152 // Class declaration
       
   153 class MusicProviderBase : public QObject, public SmfProviderBase
       
   154 	{
       
   155 	 Q_OBJECT
       
   156 	 Q_INTERFACES( SmfProviderBase )
       
   157 
       
   158 public:
       
   159 	virtual ~MusicProviderBase( );
       
   160 
       
   161 	/**
       
   162 	 * Method to get the Localisable name of the service.
       
   163 	 * @return The Localisable name of the service.
       
   164 	 */
       
   165 	QString serviceName( ) const;
       
   166 	
       
   167 	/**
       
   168 	 * Method to get the Logo of the service
       
   169 	 * @return The Logo of the service
       
   170 	 */
       
   171 	QImage serviceIcon( ) const;
       
   172 	
       
   173 	/**
       
   174 	 * Method to get the Readable service description
       
   175 	 * @return The Readable service description
       
   176 	 */
       
   177 	QString description( ) const;
       
   178 	
       
   179 	/**
       
   180 	 * Method to get the Website of the service
       
   181 	 * @return The Website of the service
       
   182 	 */
       
   183 	QUrl serviceUrl( ) const;
       
   184 	
       
   185 	/**
       
   186 	 * Method to get the URL of the Application providing this service
       
   187 	 * @return The URL of the Application providing this service
       
   188 	 */
       
   189 	QUrl applicationUrl( ) const;
       
   190 	
       
   191 	/**
       
   192 	 * Method to get the Icon of the application
       
   193 	 * @return The Icon of the application
       
   194 	 */
       
   195 	QImage applicationIcon( ) const;
       
   196 	
       
   197 	/**
       
   198 	* Method to get the list of interfaces that this provider support
       
   199 	* @return List of supported Interafces
       
   200 	*/
       
   201 	QList<QString> supportedInterfaces( ) const;
       
   202 	
       
   203 	/**
       
   204 	* Method to get the list of languages supported by this service provider
       
   205 	* @return a QStringList of languages supported by this service 
       
   206 	* provider in 2 letter ISO 639-1 format.
       
   207 	*/
       
   208 	QStringList supportedLanguages( ) const;
       
   209 	
       
   210 	/**
       
   211 	 * Method to get the Plugin specific ID
       
   212 	 * @return The Plugin specific ID
       
   213 	 */
       
   214 	QString pluginId( ) const;
       
   215 	
       
   216 	/**
       
   217 	 * Method to get the ID of the authentication application 
       
   218 	 * for this service
       
   219 	 * @param aProgram The authentication application name
       
   220 	 * @param aArguments List of arguments required for authentication app
       
   221 	 * @param aMode Strting mode for authentication application
       
   222 	 * @return The ID of the authentication application 
       
   223 	 */
       
   224 	QString authenticationApp( QString &aProgram, QStringList & aArguments, 
       
   225 			QIODevice::OpenModeFlag aMode = QIODevice::ReadWrite ) const;
       
   226 	
       
   227 	/**
       
   228 	 * Method to get the unique registration ID provided by the 
       
   229 	 * Smf for authorised plugins
       
   230 	 * @return The unique registration ID/token provided by the Smf for 
       
   231 	 * authorised plugins
       
   232 	 */
       
   233 	QString smfRegistrationId( ) const;
       
   234 	
       
   235 private:
       
   236 	friend class MusicLyricsPlugin;
       
   237 	void initialize();
       
   238 	QString m_serviceName;
       
   239 	QImage m_serviceIcon;
       
   240 	QString m_description;
       
   241 	QUrl m_serviceUrl;
       
   242 	QUrl m_applicationUrl;
       
   243 	QImage m_applicationIcon;
       
   244 	QStringList m_serviceType;
       
   245 	QStringList m_supportedLanguages;
       
   246 	QString m_pluginId;
       
   247 	QString m_authAppId;
       
   248 	QString m_smfRegToken;
       
   249 	};
       
   250 
       
   251 
       
   252 
       
   253 #endif /* MUSICLYRICSPLUGIN_H_ */