example/lastfmmusiceventplugin/lastfmmusiceventplugin.cpp
changeset 23 574948b60dab
child 26 83d6a149c755
equal deleted inserted replaced
22:b2eb79881f9d 23:574948b60dab
       
     1 /*
       
     2  * lastfmmusiceventplugin.cpp
       
     3  *
       
     4  *  Created on: Jun 21, 2010
       
     5  *      Author: ankitg
       
     6  */
       
     7 
       
     8 //Include files
       
     9 #include <QtPlugin>
       
    10 #include <QCryptographicHash>
       
    11 #include <QDataStream>
       
    12 #include <QTextStream>
       
    13 #include <QFile>
       
    14 #include <QNetworkReply>
       
    15 #include <QMap>
       
    16 #include <QListIterator>
       
    17 #include <QXmlStreamReader>
       
    18 #include <SmfPicture.h>
       
    19 #include <QSettings>
       
    20 #include "lastfmmusiceventplugin.h"
       
    21 
       
    22 
       
    23 
       
    24 //Added for testing - start
       
    25 //static const QString apiKey = "8823ece35e487bada68fa893d7ecf91e";
       
    26 //static const QString apiKey = "50ac6d6581c3784efe40748fe87d8413";
       
    27 //static const QString apiSecret = "20ccb1cc62aa50caf7d8aae31808d429";
       
    28 //static const QString apiSecret = "623f4274bcea772fd6f411cf298b6bfa";
       
    29 //static const QString miniToken = "773193698 ";
       
    30 
       
    31 //static const QString apiKey = "eb3a2d8361718782ebf3887f2bb8775b";
       
    32 //static const QString apiSecret = "7a390c4c1ec4fef41cef4d77354b30f8"; // created on 12th Aug
       
    33 
       
    34 static const QString apiKey = "50ac6d6581c3784efe40748fe87d8413";
       
    35 static const QString apiSecret = "623f4274bcea772fd6f411cf298b6bfa"; // created on 23th Aug
       
    36 
       
    37 //QString fullToken = "72157624000326005-e6cba1c7665a778e";
       
    38 
       
    39 //Payload data array
       
    40 QByteArray payload;
       
    41 QString uids;
       
    42 /**
       
    43  * Method called by plugins for logging
       
    44  * @param log string to be logged
       
    45  */
       
    46 void MusicEventPlugin::writeLog(QString log) const
       
    47 	{
       
    48 	QFile file("c:\\data\\PluginLogs.txt");
       
    49     if (!file.open(QIODevice::Append | QIODevice::Text))
       
    50 	         ;
       
    51     QTextStream out(&file);
       
    52     out << log << "\n";
       
    53     file.close();
       
    54 	}
       
    55 /**
       
    56  * Method to interpret the key sets obtained from credential manager 
       
    57  * @param aApiKey [out] The api key
       
    58  * @param aApiSecret [out] The api secret
       
    59  * @param aSessionKey [out] The session key
       
    60  * @param aSessionSecret [out] The session secret
       
    61  * @param aAppId [out] The application ID
       
    62  */
       
    63 void MusicEventPlugin::fetchKeys( QString &aApiKey, 
       
    64 		QString &aApiSecret, 
       
    65 		QString &aSessionKey, 
       
    66 		QString &aSessionSecret )
       
    67 	{
       
    68 	writeLog("Inside MusicEventPlugin::fetchKeys()");
       
    69 
       
    70 	writeLog("Reg Token = "+m_provider->m_smfRegToken);
       
    71 	writeLog("Expiry Date as int = "+m_provider->m_validity.toTime_t());
       
    72 	
       
    73 	SmfAuthParams keys;
       
    74 	SmfPluginUtil util;
       
    75 	util.getAuthKeys(keys, m_provider->m_smfRegToken, 
       
    76 			m_provider->m_validity, m_provider->m_pluginId);
       
    77 	
       
    78 	writeLog("Number of key-value pairs = "+keys.count());
       
    79 	
       
    80     QByteArray keyName;
       
    81     keyName.append("ApiKey");
       
    82 	aApiKey.append(keys.value(keyName));
       
    83 	
       
    84     keyName.clear();
       
    85     keyName.append("ApiSecret");
       
    86 	aApiSecret.append(keys.value(keyName));
       
    87 	
       
    88 	keyName.clear();
       
    89     keyName.append("SessionKey");
       
    90 	aSessionKey.append(keys.value(keyName));
       
    91 	
       
    92 	keyName.clear();
       
    93     keyName.append("SessionSecret");
       
    94 	aSessionSecret.append(keys.value(keyName));
       
    95 	
       
    96 	writeLog("Api Key = "+aApiKey);
       
    97 	writeLog("Api Secret = "+aApiSecret);
       
    98 	writeLog("session Key = "+aSessionKey);
       
    99 	writeLog("session Secret = "+aSessionSecret);
       
   100 	}
       
   101 /**
       
   102  * Destructor
       
   103  */
       
   104 MusicEventPlugin::~MusicEventPlugin()
       
   105 	{
       
   106 	if(m_provider)
       
   107 		delete m_provider;
       
   108 	}
       
   109 
       
   110 
       
   111 /**
       
   112  * Method called by plugins to generate a signature string from a base string
       
   113  * @param aBaseString The base string
       
   114  * @return The md5 hash of the base string
       
   115  */
       
   116 QString MusicEventPlugin::generateSignature(const QString aBaseString)
       
   117 	{
       
   118 	writeLog("MusicEventPlugin::generateSignature");
       
   119 	
       
   120 	// Create md5 hash of the signature string
       
   121     QByteArray byteArray;
       
   122     byteArray.insert(0, aBaseString.toAscii());
       
   123 
       
   124     QByteArray md5Hash = QCryptographicHash::hash(byteArray,QCryptographicHash::Md5 ).toHex();
       
   125     QString returnString (md5Hash);
       
   126     return returnString;
       
   127 	}
       
   128 
       
   129 /**
       
   130  * Method to get the events based on location
       
   131  * @param aRequest [out] The request data to be sent to network
       
   132  * @param aLocation Location of the event
       
   133  * @param aPageNum The page to be extracted
       
   134  * @param aItemsPerPage Number of items per page
       
   135  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
   136  */
       
   137 /*SmfPluginError MusicEventPlugin::events( SmfPluginRequestData &aRequest,
       
   138 		const QGeoPositionInfo &aLocation,const int aPageNum, 
       
   139 		const int aItemsPerPage)
       
   140 	{
       
   141 	Q_UNUSED(aItemsPerPage);
       
   142 	SmfPluginError error = SmfPluginErrUserNotLoggedIn;
       
   143 	
       
   144 	writeLog("MusicEventPlugin::events()");
       
   145 	
       
   146 	QString baseString;
       
   147 	baseString.append(apiSecret);
       
   148 	baseString.append("api_key"+apiKey);
       
   149 	baseString.append("auth_token");
       
   150 	baseString.append("formatjson");
       
   151 	baseString.append("location=Delhi");
       
   152 	baseString.append("method=geo.getEvents");
       
   153 	writeLog("Url string is :"+baseString);
       
   154 	
       
   155 	// Create the url
       
   156 	 QUrl url("http://ws.audioscrobbler.com/2.0/?");
       
   157 	 url.addQueryItem("method", "geo.getevents");
       
   158 	 url.addQueryItem("location","madrid");
       
   159 	 url.addQueryItem("api_key", apiKey);
       
   160 	 url.addQueryItem("format","json");				
       
   161 	 url.addQueryItem("auth_token","");
       
   162 	 url.addQueryItem("api_sig", generateSignature(baseString));
       
   163 	 writeLog("/n/n"+generateSignature(baseString)); 
       
   164 	 writeLog("/n/n Response is :"+url.toString());
       
   165 				// Create the request, set the url
       
   166 	 aRequest.iNetworkRequest.setUrl(url);
       
   167 	 aRequest.iRequestType = SmfMusicGetEventsOnLoc;
       
   168 	 aRequest.iPostData = NULL;
       
   169 	 aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   170 	 error = SmfPluginErrNone;
       
   171 	 return error;	
       
   172 	}
       
   173 		*/
       
   174 /**
       
   175  * Method to get the venues based on location
       
   176  * @param aRequest [out] The request data to be sent to network
       
   177  * @param aLocation Location of the venue
       
   178  * @param aPageNum The page to be extracted
       
   179  * @param aItemsPerPage Number of items per page
       
   180  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
   181  */
       
   182 SmfPluginError MusicEventPlugin::venues( SmfPluginRequestData &aRequest,
       
   183 		const SmfLocation &aLocation,const int aPageNum, 
       
   184 		const int aItemsPerPage)
       
   185 	{
       
   186 		Q_UNUSED(aItemsPerPage);
       
   187 		Q_UNUSED(aPageNum);
       
   188 		
       
   189 		SmfPluginError error = SmfPluginErrUserNotLoggedIn;
       
   190 		 	
       
   191 		// Get the key sets from SMF Plugin Utility class.
       
   192 		QString apiKey;
       
   193 		QString apiSecret;
       
   194 		QString sessionKey;
       
   195 		QString sessionSecret;
       
   196 		fetchKeys(apiKey, apiSecret, sessionKey, sessionSecret);
       
   197 		writeLog("API KEY"+apiKey);
       
   198 		writeLog("API SECRET"+apiSecret);
       
   199 		writeLog("SessionKey"+sessionKey);
       
   200 		writeLog("sessionSecret"+sessionSecret);
       
   201 		writeLog("MusicEventPlugin::Venues()");
       
   202 		//QString qName("New York");
       
   203 		//aLocation.setCity(qName);
       
   204 		//QString qLocation = aLocation.city();
       
   205 		//640418
       
   206 		//QString qLocation("New York");
       
   207 /*		QString baseString;
       
   208 		baseString.append(apiSecret);
       
   209 		baseString.append("api_key"+apiKey);
       
   210 		baseString.append("auth_token");
       
   211 		baseString.append("formatjson");
       
   212 		baseString.append("location ="+aLocation.city());
       
   213 		baseString.append("method=geo.getEvents");
       
   214 		writeLog("Url string is :"+baseString);
       
   215 		 	
       
   216 		//Create the url
       
   217 		QUrl url("http://ws.audioscrobbler.com/2.0/?");
       
   218 		url.addQueryItem("method", "geo.getevents");
       
   219 		url.addQueryItem("location",aLocation.city());
       
   220 		url.addQueryItem("api_key", apiKey);
       
   221 		url.addQueryItem("api_key", apiKey);
       
   222 		url.addQueryItem("format","json");				
       
   223 		url.addQueryItem("auth_token","");
       
   224 		url.addQueryItem("api_sig", generateSignature(baseString));
       
   225 		
       
   226 		writeLog("/n/n"+generateSignature(baseString)); 
       
   227 		writeLog("/n/n Response is :"+url.toString());
       
   228 		//Create the request, set the url
       
   229 		aRequest.iNetworkRequest.setUrl(url);
       
   230 		aRequest.iRequestType = SmfEventsGetVenues;
       
   231 		aRequest.iPostData = NULL;
       
   232 		aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   233 		error = SmfPluginErrNone;
       
   234 		return error;	*/
       
   235 		
       
   236 
       
   237 	    QString baseString;
       
   238 		baseString.append(apiSecret);
       
   239 		baseString.append("api_key"+apiKey);
       
   240 		baseString.append("auth_token");
       
   241 		baseString.append("formatjson");
       
   242 		baseString.append("location=Newyork");
       
   243 		baseString.append("method=geo.getEvents");
       
   244 		writeLog("Url string is :"+baseString);
       
   245 		
       
   246 		// Create the url
       
   247 		 QUrl url("http://ws.audioscrobbler.com/2.0/?");
       
   248 		 url.addQueryItem("method", "geo.getevents");
       
   249 		 url.addQueryItem("location","Newyork");
       
   250 		 url.addQueryItem("api_key", apiKey);
       
   251 		 url.addQueryItem("format","json");				
       
   252 		 url.addQueryItem("auth_token","");
       
   253 		 url.addQueryItem("api_sig", generateSignature(baseString));
       
   254 		 writeLog("/n/n"+generateSignature(baseString)); 
       
   255 		 writeLog("/n/n Response is :"+url.toString());
       
   256 					// Create the request, set the url
       
   257 		 aRequest.iNetworkRequest.setUrl(url);
       
   258 		 aRequest.iRequestType = SmfEventsGetEvents;
       
   259 		 aRequest.iPostData = NULL;
       
   260 		 aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   261 		 error = SmfPluginErrNone;
       
   262 		 return error;	
       
   263 
       
   264 	
       
   265 	}
       
   266 
       
   267 /**
       
   268  * Method to get the events based on venues
       
   269  * @param aRequest [out] The request data to be sent to network
       
   270  * @param aVenue Venue of the event
       
   271  * @param aPageNum The page to be extracted
       
   272  * @param aItemsPerPage Number of items per page
       
   273  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
   274  */
       
   275 SmfPluginError MusicEventPlugin::events( SmfPluginRequestData &aRequest,
       
   276 		const SmfLocation &aVenue,const int aPageNum, 
       
   277 		const int aItemsPerPage)
       
   278 	{
       
   279 	Q_UNUSED(aItemsPerPage);
       
   280 	Q_UNUSED(aPageNum);
       
   281 	
       
   282 	SmfPluginError error = SmfPluginErrUserNotLoggedIn;
       
   283 		
       
   284 	
       
   285 	// Get the key sets from SMF Plugin Utility class.
       
   286 		QString apiKey;
       
   287 		QString apiSecret;
       
   288 		QString sessionKey;
       
   289 		QString sessionSecret;
       
   290 		fetchKeys(apiKey, apiSecret, sessionKey, sessionSecret);
       
   291 		writeLog("API KEY"+apiKey);
       
   292 		writeLog("API SECRET"+apiSecret);
       
   293 		writeLog("SessionKey"+sessionKey);
       
   294 		writeLog("sessionSecret"+sessionSecret);
       
   295 	
       
   296 	    QString baseString;
       
   297 		baseString.append(apiSecret);
       
   298 		baseString.append("api_key"+apiKey);
       
   299 		baseString.append("auth_token");
       
   300 		baseString.append("formatjson");
       
   301 		baseString.append("location="+aVenue.city());
       
   302 		baseString.append("method=geo.getEvents");
       
   303 		writeLog("Url string is :"+baseString);
       
   304 		
       
   305 		// Create the url
       
   306 		 QUrl url("http://ws.audioscrobbler.com/2.0/?");
       
   307 		url.addQueryItem("method", "geo.getevents");
       
   308 		url.addQueryItem("location",aVenue.city());
       
   309 		url.addQueryItem("api_key", apiKey);
       
   310 		url.addQueryItem("format","json");				
       
   311 		url.addQueryItem("auth_token","");
       
   312 		url.addQueryItem("api_sig", generateSignature(baseString));
       
   313 		writeLog("/n/n"+generateSignature(baseString)); 
       
   314 		writeLog("/n/n Response is :"+url.toString());
       
   315 		//Create the request, set the url
       
   316 		 aRequest.iNetworkRequest.setUrl(url);
       
   317 		 aRequest.iRequestType = SmfEventsGetEvents;
       
   318 		 aRequest.iPostData = NULL;
       
   319 		 aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   320 		 error = SmfPluginErrNone;
       
   321 		 return error;	
       
   322 
       
   323 	}
       
   324 
       
   325 /**
       
   326  * Method to post events
       
   327  * @param aRequest [out] The request data to be sent to network
       
   328  * @param aEventList The list of events to be posted
       
   329  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
   330  */
       
   331 SmfPluginError MusicEventPlugin::postEvents( SmfPluginRequestData &aRequest,
       
   332 		const QList<SmfEvent> &aEventList )
       
   333 	{
       
   334 	       Q_UNUSED(aEventList)
       
   335 		   SmfPluginError error = SmfPluginErrUserNotLoggedIn;
       
   336 		   writeLog("MusicEventPlugin::events()");
       
   337 		   int count =aEventList.count();
       
   338 		   for(int i=0;i<count;i++)
       
   339 			   { 
       
   340 		        SmfEvent ievent=aEventList[i];
       
   341 		        writeLog("Event List"+ievent.id());
       
   342 			   }
       
   343 			// Get the key sets from SMF Plugin Utility class.
       
   344 			QString apiKey;
       
   345 			QString apiSecret;
       
   346 			QString sessionKey;
       
   347 			QString sessionSecret;
       
   348 			fetchKeys(apiKey, apiSecret, sessionKey, sessionSecret);
       
   349 			writeLog("API KEY"+apiKey);
       
   350 			writeLog("API SECRET"+apiSecret);
       
   351 			writeLog("SessionKey"+sessionKey);
       
   352 			writeLog("sessionSecret"+sessionSecret);
       
   353 		/*	QString baseString;
       
   354 			
       
   355 			baseString.append(apiSecret);
       
   356 			baseString.append("api_key"+apiKey);
       
   357 			baseString.append("auth_token");
       
   358 			baseString.append("formatjson");
       
   359 		//	baseString.append("method=event.shout"); // needs authentication
       
   360 		//	baseString.append("Event"+"aEventList.at(0)");
       
   361 			writeLog("Url string is :"+baseString);
       
   362 			
       
   363 		   //Create the url
       
   364 			 QUrl url("http://ws.audioscrobbler.com/2.0/?");
       
   365 			 url.addQueryItem("method", "event.shout");   // needs authentication
       
   366 			 url.addQueryItem("api_key", apiKey);
       
   367 			 url.addQueryItem("format","json");	
       
   368 		//	 url.addQueryItem("Event","aEventList.at(0)");
       
   369 			 url.addQueryItem("auth_token","");
       
   370 			 url.addQueryItem("api_sig", generateSignature(baseString));
       
   371 			 writeLog("/n/n Response is :"+url.toString());
       
   372 						// Create the request, set the url
       
   373 			 aRequest.iNetworkRequest.setUrl(url);
       
   374 			 aRequest.iRequestType = SmfEventsPostEvents;
       
   375 			 aRequest.iPostData = NULL;
       
   376 			 
       
   377 			 aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   378 			 error = SmfPluginErrNone;
       
   379 			 return error;	*/
       
   380 			
       
   381 		   //For Testing Only      
       
   382 		    QString baseString;
       
   383 					
       
   384 		    //QString strId("328799");
       
   385 			
       
   386 		    QString eventId("328799");//= aEvent.id();
       
   387 			//QString eventId;
       
   388 			//eventId = aEvent.id();
       
   389 			baseString.append(apiSecret);
       
   390 		    baseString.append("api_key"+apiKey);
       
   391 					//baseString.append("auth_token");
       
   392 			baseString.append("formatjson");
       
   393 			baseString.append("method=event.getattendees");
       
   394 			baseString.append("event"+eventId);
       
   395 			writeLog("Url string is :"+baseString);
       
   396 					
       
   397 			//Create the url
       
   398 			QUrl url("http://ws.audioscrobbler.com/2.0/?");
       
   399 			url.addQueryItem("method", "event.getattendees");
       
   400 			url.addQueryItem("event",eventId);
       
   401 			url.addQueryItem("api_key", apiKey);
       
   402 			url.addQueryItem("format","json");					 
       
   403 			//url.addQueryItem("auth_token","");
       
   404 			//url.addQueryItem("api_sig", generateSignature(baseString));
       
   405 			writeLog("/n/n Response is :"+url.toString());
       
   406 			//Create the request, set the url
       
   407 			aRequest.iNetworkRequest.setUrl(url);
       
   408 			aRequest.iRequestType = SmfEventsPostEvents;
       
   409 			aRequest.iPostData = NULL;
       
   410 		
       
   411 			aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   412 			error = SmfPluginErrNone;
       
   413 			return error;	
       
   414 	}
       
   415 		
       
   416 /**
       
   417  * Customised method for SmfMusicEventsPlugin interface
       
   418  * @param aRequest [out] The request data to be sent to network
       
   419  * @param aOperation The operation type (should be known between 
       
   420  * the client interface and the plugin)
       
   421  * @param aData The data required to form the request (The type 
       
   422  * of data should be known between client and the plugin)
       
   423  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
   424  */
       
   425 SmfPluginError MusicEventPlugin::attendees( SmfPluginRequestData &aRequest,
       
   426 			const SmfEvent &aEvent, 
       
   427 			const int aPageNum ,
       
   428 			const int aItemsPerPage )
       
   429 	{
       
   430 		Q_UNUSED(aItemsPerPage);
       
   431 		SmfPluginError error = SmfPluginErrUserNotLoggedIn;
       
   432 		writeLog("MusicEventPlugin::events()");
       
   433 				
       
   434 		// Get the key sets from SMF Plugin Utility class.
       
   435 		QString apiKey;
       
   436 		QString apiSecret;
       
   437 		QString sessionKey;
       
   438 		QString sessionSecret;
       
   439 		fetchKeys(apiKey, apiSecret, sessionKey, sessionSecret);
       
   440 		writeLog("API KEY"+apiKey);
       
   441 		writeLog("API SECRET"+apiSecret);
       
   442 		writeLog("SessionKey"+sessionKey);
       
   443 		writeLog("sessionSecret"+sessionSecret);
       
   444 	    QString baseString;
       
   445 				
       
   446 	    //QString strId("328799");
       
   447 		//aEvent.setId(strId);
       
   448 	    //QString eventId = aEvent.id();
       
   449 		QString eventId;
       
   450 		eventId = aEvent.id();
       
   451 		baseString.append(apiSecret);
       
   452 	    baseString.append("api_key"+apiKey);
       
   453 				//baseString.append("auth_token");
       
   454 		baseString.append("formatjson");
       
   455 		baseString.append("method=event.getattendees");
       
   456 		baseString.append("event"+eventId);
       
   457 		writeLog("Url string is :"+baseString);
       
   458 				
       
   459 		//Create the url
       
   460 		QUrl url("http://ws.audioscrobbler.com/2.0/?");
       
   461 		url.addQueryItem("method", "event.getattendees");
       
   462 		url.addQueryItem("event",eventId);
       
   463 		url.addQueryItem("api_key", apiKey);
       
   464 		url.addQueryItem("format","json");					 
       
   465 				// url.addQueryItem("auth_token","");
       
   466 				// url.addQueryItem("api_sig", generateSignature(baseString));
       
   467 		writeLog("/n/n Response is :"+url.toString());
       
   468 		//Create the request, set the url
       
   469 		aRequest.iNetworkRequest.setUrl(url);
       
   470 		aRequest.iRequestType = SmfEventsGetEventAttendees;
       
   471 		aRequest.iPostData = NULL;
       
   472 				 
       
   473 				
       
   474 				 
       
   475 		aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   476 		error = SmfPluginErrNone;
       
   477 		return error;	
       
   478 	}
       
   479 SmfPluginError MusicEventPlugin::customRequest( SmfPluginRequestData &aRequest, 
       
   480 		const int &aOperation, QByteArray *aData )
       
   481 	{
       
   482 	Q_UNUSED(aRequest)
       
   483 	Q_UNUSED(aOperation)
       
   484 	Q_UNUSED(aData)
       
   485     //SmfEventsCustomRequest
       
   486 	return SmfPluginErrServiceNotSupported; 
       
   487 	}
       
   488 
       
   489 /**
       
   490  * The first method to be called in the plugin that implements this interface.
       
   491  * If this method is not called, plugin may not behave as expected.
       
   492  * Plugins are expected to save the aUtil handle and use and when required.
       
   493  * @param aUtil The instance of SmfPluginUtil
       
   494  */
       
   495 void MusicEventPlugin::initialize(/* SmfPluginUtil *aUtil */)
       
   496 	{
       
   497 	// Save the SmfPluginUtil handle
       
   498 	//m_util = aUtil;
       
   499 	
       
   500 	// Create an instance of MusicProviderBase
       
   501 	m_provider = new MusicProviderBase;
       
   502 	m_provider->initialize();
       
   503 	}
       
   504 
       
   505 /**
       
   506  * Method to get the provider information
       
   507  * @return Instance of SmfProviderBase
       
   508  */
       
   509 SmfProviderBase* MusicEventPlugin::getProviderInfo( )
       
   510 	{
       
   511 	return m_provider;
       
   512 	}
       
   513 
       
   514 /**
       
   515  * Method to get the result for a network request.
       
   516  * @param aOperation The type of operation to be requested
       
   517  * @param aTransportResult The result of transport operation
       
   518  * @param aResponse The QByteArray instance containing the network response.
       
   519  * The plugins should delete this instance once they have read the 
       
   520  * data from it.
       
   521  * @param aResult [out] An output parameter to the plugin manager.If the 
       
   522  * return value is SmfSendRequestAgain, QVariant will be of type 
       
   523  * SmfPluginRequestData.
       
   524  * For SmfGalleryPlugin: If last operation was pictures(), aResult will 
       
   525  * be of type QList<SmfPicture>. If last operation was description(), 
       
   526  * aResult will be of type QString. If last operation was upload() or 
       
   527  * postComment(), aResult will be of type bool.
       
   528  * @param aRetType [out] SmfPluginRetType
       
   529  * @param aPageResult [out] The SmfResultPage structure variable
       
   530  */
       
   531 SmfPluginError MusicEventPlugin::responseAvailable( 
       
   532 		const SmfRequestTypeID aOperation,
       
   533 		const SmfTransportResult &aTransportResult, 
       
   534 		QByteArray *aResponse, 
       
   535 		QVariant* aResult, 
       
   536 		SmfPluginRetType &aRetType,
       
   537 		SmfResultPage &aPageResult )
       
   538 	{
       
   539 	writeLog("MusicEventPlugin::responseAvailable");
       
   540 		Q_UNUSED(aPageResult)
       
   541 		SmfPluginError error = SmfPluginErrNetworkError;
       
   542 		
       
   543 		if( !aResponse || (0 == aResponse->size()) ) 
       
   544 			{
       
   545 			writeLog("Response is NULL or empty");
       
   546 			aRetType = SmfRequestError;
       
   547 			return error;
       
   548 			}
       
   549 		
       
   550 		QByteArray response(*aResponse);
       
   551 		delete aResponse;
       
   552 		
       
   553 		//Write the response to a file
       
   554 		QFile file("c:\\data\\musiceventresponse.txt");
       
   555 		writeLog("response data written to c:\\data\\musiceventresponse.txt");
       
   556 				
       
   557 		if (!file.open(QIODevice::Append | QIODevice::Text));
       
   558 		file.write(response);
       
   559 		file.close();
       
   560 		
       
   561 		writeLog("MusicEvent response = "+QString(response));
       
   562 		writeLog("MusicEvent response size = "+QString::number(response.size(), 10));
       
   563 		
       
   564 		if(SmfTransportOpNoError == aTransportResult)
       
   565 			{
       
   566 			  writeLog("No transport error");
       
   567 			//  QVariantMap map1;
       
   568 			 // bool resType=response.startsWith("<?xml");
       
   569 			 /* if(resType) //XML REsponse
       
   570 				{
       
   571 				   writeLog("Before XML Parser--");
       
   572 				  
       
   573 			  }
       
   574 			  else //JSON RESPONSE
       
   575 			  {
       
   576 				  bool ok;
       
   577 				  writeLog("Before JSON Parser--");
       
   578 		
       
   579 				  SmfPluginUtil util;
       
   580 				  QVariant result = util.parse(response, &ok);
       
   581 				  if (!ok) 
       
   582 				   {
       
   583 						writeLog("An error occurred during json parsing");
       
   584 						aRetType = SmfRequestError;
       
   585 						return SmfPluginErrParsingFailed;
       
   586 				   }
       
   587 													
       
   588 			 //map1 = result.toMap();*/
       
   589 			  //}
       
   590 			  if(SmfEventsGetEvents == aOperation /*|| SmfMusicGetEventsOnVenue == aOperation*/)
       
   591 				 {
       
   592 			       
       
   593 			        QDateTime dt = QDateTime::currentDateTime();
       
   594 			        QList<SmfEvent> eventlist;
       
   595 			      
       
   596 			        
       
   597 			        
       
   598 			        //Tested By Hardcoding
       
   599 			        
       
   600 			        SmfEvent event;
       
   601 			        event.setId("111111");
       
   602 			        event.setTitle("bangalore");
       
   603 			      	event.setEventDateTime(dt);
       
   604 			        QStringList stringList; //for artist
       
   605 			        stringList.append("sssss");
       
   606 			        stringList.append("aaaa");
       
   607 			        SmfArtists artists;
       
   608 			        artists.setNames(stringList);
       
   609 					event.setArtists(artists);
       
   610 					
       
   611 					SmfLocation Location;
       
   612 					Location.setCity("Bangalore");
       
   613 					Location.setCountry("india");
       
   614 					
       
   615 					event.setVenue(Location);
       
   616 					eventlist.append(event);
       
   617 					
       
   618 					//2nd Event
       
   619 					SmfEvent event1;
       
   620 					event1.setId("2222");
       
   621 					event1.setTitle("delhi");
       
   622 					event1.setEventDateTime(dt);
       
   623 					QStringList stringList1; //for artist
       
   624 					stringList1.append("ddddd");
       
   625 				    stringList1.append("rrrrrr");
       
   626 				    SmfArtists artists1;
       
   627 					artists1.setNames(stringList1);
       
   628 					event1.setArtists(artists1);
       
   629 										
       
   630 					SmfLocation Location1;
       
   631 					Location1.setCity("Delhi");
       
   632 					Location1.setCountry("india");
       
   633 										
       
   634 					event1.setVenue(Location1);
       
   635 					eventlist.append(event1);
       
   636 										
       
   637 					writeLog("SmfEventsGetEvents = ");
       
   638 					/*QVariantMap eventmap = map1["events"].toMap();
       
   639 					QList<QVariant> list1 = eventmap["event"].toList();
       
   640 					
       
   641 					QListIterator<QVariant> iter(list1);
       
   642 					writeLog("SmfEventsGetEvents123 = ");
       
   643 					while(iter.hasNext())  //not runing for one event
       
   644 					{
       
   645 					  SmfEvent event;
       
   646 					  QVariantMap map2 = iter.next().toMap();
       
   647 					  writeLog("id = "+map2["id"].toString());
       
   648 					  event.setId(map2["id"].toString());
       
   649 					  writeLog("title = "+map2["title"].toString());
       
   650 					  event.setTitle(map2["title"].toString());
       
   651 					  writeLog("EventDateTime= "+map2["startDate"].toString());
       
   652 					  event.setEventDateTime(map2["startDate"].toDateTime());
       
   653 					 // writeLog("SetdUration= "+map2["startDate"].toDateTime());  //didn't find that
       
   654 					  //for Getting the Artist List
       
   655 					  QVariantMap map4 = map2["artists"].toMap();
       
   656 					  QList<QVariant> artistList =map4["artist"].toList();
       
   657 					  
       
   658 					  writeLog("artist"+map4["artist"].toString());
       
   659 					 					  
       
   660 					 //  writeLog("artists"+artistList["artist"].toString());
       
   661 					 // QList<QVariant> artistList =map2["artists"].toList();
       
   662 					
       
   663 					  
       
   664 					 QListIterator<QVariant> iterartists(artistList);
       
   665 					  SmfArtists artists;
       
   666 					  QStringList stringList;
       
   667 					  while(iterartists.hasNext())
       
   668 					  {
       
   669 						
       
   670 						//QString artistName;
       
   671 						QString artistName = iterartists.next().toString();
       
   672 						writeLog("artist Name = "+ artistName);
       
   673 						//artistName.append(map2["artist"].toString());
       
   674 						stringList.append(artistName);
       
   675 						
       
   676 					  }//end while
       
   677 					  //writeLog("artists= "+stringList[0]);
       
   678 					  
       
   679 					  artists.setNames(stringList);
       
   680 					  event.setArtists(artists);
       
   681 					  
       
   682 					  //all Artist list we got 
       
   683 					  //For Venue
       
   684 					  SmfLocation Location;
       
   685 					  QVariantMap map3 = map2["venue"].toMap();
       
   686 					  writeLog("LocationId : "+map3["id"].toString());
       
   687 					  Location.setId(map3["id"].toString());
       
   688 					  //for city
       
   689 					  QVariantMap map6 = map3["location"].toMap();
       
   690 					  writeLog("Location city : "+map6["city"].toString());
       
   691 					  Location.setCity(map6["city"].toString());
       
   692 					  writeLog("Location city : "+map6["country"].toString());
       
   693 					  Location.setCountry(map6["country"].toString());
       
   694 					 // Location.geoPositionInfo()  dont know how to set 
       
   695 					  event.setVenue(Location);
       
   696 					  eventlist.append(event);
       
   697 					}//end While*/
       
   698 					aResult->setValue(eventlist);
       
   699 					aRetType = SmfRequestComplete;
       
   700 					error = SmfPluginErrNone;										
       
   701 				 }
       
   702 			 else if(SmfEventsGetVenues == aOperation)
       
   703 				{
       
   704 				writeLog("SmfEventsGetVenues = ");
       
   705 				QList<SmfLocation> LocationList;
       
   706 				SmfLocation Location;
       
   707 			    Location.setId("111111");
       
   708 				//for city
       
   709 				Location.setCity("delhi");
       
   710 				Location.setCountry("India");
       
   711 				Location.setUrl(QUrl("http://wwwqqqqq/ee"));
       
   712 				LocationList.append(Location);
       
   713 				
       
   714 				SmfLocation Location1;
       
   715 				Location1.setId("22222");
       
   716 				//for city
       
   717 				Location1.setCity("bangalore");
       
   718 				Location1.setCountry("India");
       
   719 				LocationList.append(Location1);
       
   720 				
       
   721 				aResult->setValue(LocationList);
       
   722 				aRetType = SmfRequestComplete;
       
   723 				error = SmfPluginErrNone;
       
   724 				 
       
   725 				
       
   726 				}
       
   727 			
       
   728 			 else if (SmfEventsPostEvents == aOperation)
       
   729 				{
       
   730 				writeLog("SmfEventsPostEvents = ");
       
   731 				bool postEvent=true;	
       
   732 				aResult->setValue(postEvent);
       
   733 				aRetType = SmfRequestComplete;
       
   734 				error = SmfPluginErrNone;
       
   735 				
       
   736 				}
       
   737 			 else if (SmfEventsGetEventAttendees == aOperation)
       
   738 				 {
       
   739 			  
       
   740 				        QList<SmfContact> contactList;
       
   741 				        
       
   742 			             writeLog("SmfMusicGetEventsAttendees = ");
       
   743 			             bool ok;
       
   744 			           	writeLog("Before Parser--");
       
   745 
       
   746 			           	SmfPluginUtil util;
       
   747 			           	QVariantMap result = util.parse(response, &ok).toMap();
       
   748 			           	if (!ok) 
       
   749 			           	{
       
   750 			           	writeLog("An error occurred during json parsing");
       
   751 			           	aRetType = SmfRequestError;
       
   752 			           	return SmfPluginErrParsingFailed;
       
   753 			           		
       
   754 			           	}
       
   755 			           							
       
   756 			           	//QVariantMap map1 = result.toMap();
       
   757 			        	writeLog("MAP1");
       
   758 			            
       
   759 			           
       
   760 			           	QVariantMap map1 = result["attendees"].toMap();
       
   761 			        	//QVariantMap map2 = map1["attendees"].toMap();
       
   762 			           	writeLog("MAP2");
       
   763 			           	//int page = map2["page"].toInt(&ok);
       
   764 			           	QList<QVariant> list1 = map1["user"].toList();
       
   765 			           	writeLog("list count"+QString::number(list1.count(),10));
       
   766 			           				
       
   767 			           	QListIterator<QVariant> i(list1);
       
   768 			           	writeLog("iterate list"); //While loop not work if there is only one attendee
       
   769 			            while(i.hasNext())
       
   770 			           	{
       
   771 			                writeLog("inside loop");
       
   772 			           		SmfContact contact;
       
   773 			           		QVariantMap map2 = i.next().toMap();
       
   774 			           		writeLog("name= "+map2["name"].toString());
       
   775 			           		writeLog("realname = "+map2["realname"].toString());
       
   776 			           					
       
   777 			           		//Contact Name
       
   778 			           		QContactName contactname;
       
   779 			           		QString username = map2["name"].toString();
       
   780 			           		writeLog("name = "+username);
       
   781 			           		contactname.setFirstName(username);
       
   782 			           		contactname.setLastName(username);
       
   783 			           		QVariant nameVar = QVariant::fromValue(contactname);
       
   784 			           		contact.setValue("Name",nameVar);
       
   785 			           		contactList.append(contact);
       
   786 			           	}
       
   787 			             aResult->setValue(contactList);										
       
   788 			 		     aRetType = SmfRequestComplete;
       
   789 			 		     error = SmfPluginErrNone;
       
   790 			 			
       
   791 				 }
       
   792 			 else
       
   793 				{
       
   794 				writeLog("Service unsupported!!!");
       
   795 				aRetType = SmfRequestError;
       
   796 				error = SmfPluginErrServiceNotSupported;
       
   797 				}
       
   798 			}//end if of if(SmfTransportOpNoError == aTransportResult)
       
   799 
       
   800 		else if(SmfTransportOpOperationCanceledError == aTransportResult)
       
   801 			{
       
   802 			writeLog("Operation Cancelled !!!");
       
   803 			error = SmfPluginErrCancelComplete;
       
   804 			aRetType = SmfRequestComplete;
       
   805 			}
       
   806 
       
   807 		else
       
   808 			{
       
   809 			writeLog("Transport Error !!!");
       
   810 			error = SmfPluginErrNetworkError;
       
   811 			aRetType = SmfRequestError;
       
   812 			}
       
   813 		
       
   814 		return error;
       
   815 	}
       
   816 
       
   817 
       
   818 /**
       
   819  * Destructor
       
   820  */
       
   821 MusicProviderBase::~MusicProviderBase( )
       
   822 	{
       
   823 	}
       
   824 
       
   825 /**
       
   826  * Method to get the Localisable name of the service.
       
   827  * @return The Localisable name of the service.
       
   828  */
       
   829 QString MusicProviderBase::serviceName( ) const
       
   830 	{
       
   831 	return m_serviceName;
       
   832 	}
       
   833 
       
   834 /**
       
   835  * Method to get the Logo of the service
       
   836  * @return The Logo of the service
       
   837  */
       
   838 QImage MusicProviderBase::serviceIcon( ) const
       
   839 	{
       
   840 	return m_serviceIcon;
       
   841 	}
       
   842 
       
   843 /**
       
   844  * Method to get the Readable service description
       
   845  * @return The Readable service description
       
   846  */
       
   847 QString MusicProviderBase::description( ) const
       
   848 	{
       
   849 	return m_description;
       
   850 	}
       
   851 
       
   852 /**
       
   853  * Method to get the Website of the service
       
   854  * @return The Website of the service
       
   855  */
       
   856 QUrl MusicProviderBase::serviceUrl( ) const
       
   857 	{
       
   858 	return m_serviceUrl;
       
   859 	}
       
   860 
       
   861 /**
       
   862  * Method to get the URL of the Application providing this service
       
   863  * @return The URL of the Application providing this service
       
   864  */
       
   865 QUrl MusicProviderBase::applicationUrl( ) const
       
   866 	{
       
   867 	return m_applicationUrl;
       
   868 	}
       
   869 
       
   870 /**
       
   871  * Method to get the Icon of the application
       
   872  * @return The Icon of the application
       
   873  */
       
   874 QImage MusicProviderBase::applicationIcon( ) const
       
   875 	{
       
   876 	return m_applicationIcon;
       
   877 	}
       
   878 /**
       
   879 * Method to get the list of interfaces that this provider support
       
   880 * @return List of supported Interafces
       
   881 */
       
   882 QList<QString> MusicProviderBase::supportedInterfaces( ) const
       
   883 	{
       
   884 	return m_serviceType;
       
   885 	}
       
   886 
       
   887 /**
       
   888 * Method to get the list of languages supported by this service provider
       
   889 * @return a QStringList of languages supported by this service 
       
   890 * provider in 2 letter ISO 639-1 format.
       
   891 */
       
   892 QStringList MusicProviderBase::supportedLanguages( ) const
       
   893 	{
       
   894 	return m_supportedLanguages;
       
   895 	}
       
   896 
       
   897 /**
       
   898  * Method to get the Plugin specific ID
       
   899  * @return The Plugin specific ID
       
   900  */
       
   901 QString MusicProviderBase::pluginId( ) const
       
   902 	{
       
   903 	return m_pluginId;
       
   904 	}
       
   905 
       
   906 /**
       
   907  * Method to get the ID of the authentication application 
       
   908  * for this service
       
   909  * @param aProgram The authentication application name
       
   910  * @param aArguments List of arguments required for authentication app
       
   911  * @param aMode Strting mode for authentication application
       
   912  * @return The ID of the authentication application 
       
   913  */
       
   914 QString MusicProviderBase::authenticationApp( QString &aProgram, 
       
   915 		QStringList & aArguments, 
       
   916 		QIODevice::OpenModeFlag aMode ) const
       
   917 	{
       
   918 	return m_authAppId;
       
   919 	}
       
   920 
       
   921 /**
       
   922  * Method to get the unique registration ID provided by the 
       
   923  * Smf for authorised plugins
       
   924  * @return The unique registration ID/token provided by the Smf for 
       
   925  * authorised plugins
       
   926  */
       
   927 QString MusicProviderBase::smfRegistrationId( ) const
       
   928 	{
       
   929 	return m_smfRegToken;
       
   930 	}
       
   931 
       
   932 void MusicProviderBase::initialize()
       
   933 	{
       
   934 	
       
   935 	  m_serviceName = "Last.fm";
       
   936 	  m_description = "Description";
       
   937 	  m_serviceUrl =  QUrl(QString("http://ws.audioscrobbler.com"));
       
   938 	 // m_serviceType << m_serviceName << m_description;// << (QString)(m_serviceUrl);
       
   939 	  m_supportedLanguages << "English" ;
       
   940 	  m_pluginId =    "lastfmmusiceventplugin.qtplugin";
       
   941 	  m_authAppId =   "0xE1D8C7D8";
       
   942 	  QSettings iSettings;
       
   943 	  m_smfRegToken = iSettings.value("CMLastFmRegToken").toString();
       
   944 	  m_validity = iSettings.value("LastFmExpiryTime").toDateTime();
       
   945 	  //m_smfRegToken = "hsdfusdghf";  //yet to be recvd
       
   946 
       
   947 	}
       
   948 
       
   949 
       
   950 /*
       
   951  * Export Macro
       
   952  * plugin name : musiceventplugin
       
   953  * plugin class : MusicEventPlugin
       
   954  */
       
   955 Q_EXPORT_PLUGIN2( musiceventplugin, MusicEventPlugin )