example/lastfmmusicserviceplugin/lastfmmusicserviceplugin.cpp
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 services related functionalities from last.fm site
       
    17  *
       
    18  */
       
    19 
       
    20 // Include files
       
    21 #include <QtPlugin>
       
    22 #include <QDebug>
       
    23 #include <QCryptographicHash>
       
    24 #include <QTextStream>
       
    25 #include <QFile>
       
    26 #include <QMap>
       
    27 #include <QListIterator>
       
    28 #include <QSettings>
       
    29 #include <smfpluginutil.h>
       
    30 #include <smfcontact.h>
       
    31 
       
    32 #include "lastfmmusicserviceplugin.h"
       
    33 
       
    34 
       
    35 static int gPageNum = 0; 
       
    36 static int gItemsPerPage = 0;
       
    37 
       
    38 QString gUserId;
       
    39 static int userMusicInfoChance = 0;
       
    40 QList<SmfTrackInfo> gRecentTracks;
       
    41 QList<SmfTrackInfo> gFavorites;
       
    42 QList<SmfEvent> gUserEvents;
       
    43 
       
    44 /**
       
    45  * Destructor
       
    46  */
       
    47 LastFmMusicServicePlugin::~LastFmMusicServicePlugin( )
       
    48 	{
       
    49 	if(m_provider)
       
    50 		delete m_provider;
       
    51 	}
       
    52 
       
    53 /**
       
    54  * Method to interpret the key sets obtained from credential manager 
       
    55  * @param aApiKey [out] The api key
       
    56  * @param aApiSecret [out] The api secret
       
    57  * @param aSessionKey [out] The session key
       
    58  * @param aToken [out] The session token
       
    59  */
       
    60 void LastFmMusicServicePlugin::fetchKeys( QString &aApiKey, 
       
    61 		QString &aApiSecret, 
       
    62 		QString &aToken,
       
    63 		QString &aName )
       
    64 	{
       
    65 	qDebug()<<"Reg Token = "<<m_provider->m_smfRegToken;
       
    66 	qDebug()<<"Expiry Date as int = "<<m_provider->m_validity.toTime_t();
       
    67 	
       
    68 	SmfAuthParams keys;
       
    69 	SmfPluginUtil util;
       
    70 	util.getAuthKeys(keys, m_provider->m_smfRegToken, 
       
    71 			m_provider->m_validity, m_provider->m_pluginId);
       
    72 	
       
    73     QByteArray keyName;
       
    74     keyName.append("ApiKey");
       
    75 	aApiKey.append(keys.value(keyName));
       
    76 	
       
    77     keyName.clear();
       
    78     keyName.append("ApiSecret");
       
    79 	aApiSecret.append(keys.value(keyName));
       
    80 	
       
    81 	keyName.clear();
       
    82     keyName.append("Token");
       
    83 	aToken.append(keys.value(keyName));
       
    84 	
       
    85 	keyName.clear();
       
    86     keyName.append("Name");
       
    87 	aName.append(keys.value(keyName));
       
    88 	
       
    89 	qDebug()<<"Api Key = "<<aApiKey;
       
    90 	qDebug()<<"Api Secret = "<<aApiSecret;
       
    91 	qDebug()<<"Token = "<<aToken;
       
    92 	qDebug()<<"Name = "<<aName;
       
    93 	}
       
    94 
       
    95 /**
       
    96  * Method called by plugins to generate a signature string from a base string
       
    97  * @param aBaseString The base string
       
    98  * @return The md5 hash of the base string
       
    99  */
       
   100 QString LastFmMusicServicePlugin::generateSignature(const QString aBaseString)
       
   101 	{
       
   102 	// Create md5 hash of the signature string
       
   103     QByteArray byteArray;
       
   104     byteArray.insert(0, aBaseString.toAscii());
       
   105 
       
   106     QByteArray md5Hash = QCryptographicHash::hash(byteArray,QCryptographicHash::Md5 ).toHex();
       
   107     QString returnString (md5Hash);
       
   108     return returnString;
       
   109 	}
       
   110 
       
   111 /**
       
   112  * Method to get self profile information
       
   113  * @param aRequest [out] The request data to be sent to network
       
   114  * @return Appropriate value of the enum SmfPluginError.
       
   115  * Plugin error if any, else SmfPluginErrNone for success
       
   116  */
       
   117 SmfPluginError LastFmMusicServicePlugin::userMusicInfo( 
       
   118 		SmfPluginRequestData &aRequest )
       
   119 	{
       
   120 	qDebug()<<"Inside LastFmMusicServicePlugin::userMusicInfo()";
       
   121 	
       
   122 	SmfPluginError error = SmfPluginErrInvalidArguments;
       
   123 
       
   124 	// Get the key sets from SMF Plugin Utility class.
       
   125 	QString apiKey;
       
   126 	QString apiSecret;
       
   127 	QString token;
       
   128 	QString userName;
       
   129 	fetchKeys(apiKey, apiSecret, token, userName);
       
   130 	
       
   131 	// Get the current logged in user id
       
   132 	if(0 == userMusicInfoChance)
       
   133 		{
       
   134 		// Clear the global variables
       
   135 		gUserId.clear();
       
   136 		gRecentTracks.clear();
       
   137 		gFavorites.clear();
       
   138 		gUserEvents.clear();
       
   139 		gPageNum = 1;
       
   140 		gItemsPerPage = 5;
       
   141 		
       
   142 		// Create the API signature string
       
   143 		QString baseString;
       
   144 		baseString.append("api_key"+apiKey);
       
   145 		baseString.append("methoduser.getInfo");
       
   146 		baseString.append("user"+userName);
       
   147 		baseString.append(apiSecret);
       
   148 	
       
   149 		// Create the url
       
   150 		QUrl url("http://ws.audioscrobbler.com/2.0/?");
       
   151 		url.addQueryItem("api_key", apiKey);
       
   152 		url.addQueryItem("format", "json");
       
   153 		url.addQueryItem("method", "user.getInfo");
       
   154 		url.addQueryItem("user", userName);
       
   155 		url.addQueryItem("api_sig", generateSignature(baseString));
       
   156 		
       
   157 		// Create the request, set the url
       
   158 		aRequest.iNetworkRequest.setUrl(url);
       
   159 		aRequest.iRequestType = SmfMusicGetUserInfo;
       
   160 		aRequest.iPostData = NULL;
       
   161 		aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   162 		error = SmfPluginErrNone;
       
   163 		}
       
   164 
       
   165 	// Getting the user's recent tracks
       
   166 	else if(1 == userMusicInfoChance)
       
   167 		{
       
   168 		// Create the API signature string
       
   169 		QString baseString;
       
   170 		baseString.append("api_key"+apiKey);
       
   171 		baseString.append("limit"+QString::number(gItemsPerPage));
       
   172 		baseString.append("methoduser.getRecentTracks");
       
   173 		baseString.append("page"+QString::number(gPageNum));
       
   174 		baseString.append("user"+userName);
       
   175 		baseString.append(apiSecret);
       
   176 	
       
   177 		// Create the url
       
   178 		QUrl url("http://ws.audioscrobbler.com/2.0/?");
       
   179 		url.addQueryItem("api_key", apiKey);
       
   180 		url.addQueryItem("format", "json");
       
   181 		url.addQueryItem("limit", QString::number(gItemsPerPage));		
       
   182 		url.addQueryItem("method", "user.getRecentTracks");
       
   183 		url.addQueryItem("page", QString::number(gPageNum));
       
   184 		url.addQueryItem("user", userName);
       
   185 		url.addQueryItem("api_sig", generateSignature(baseString));
       
   186 		
       
   187 		// Create the request, set the url
       
   188 		aRequest.iNetworkRequest.setUrl(url);
       
   189 		aRequest.iRequestType = SmfMusicGetUserInfo;
       
   190 		aRequest.iPostData = NULL;
       
   191 		aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   192 		error = SmfPluginErrNone;
       
   193 		}
       
   194 	
       
   195 	// Getting the user's favorites
       
   196 	else if(2 == userMusicInfoChance)
       
   197 		{
       
   198 		// Create the API signature string
       
   199 		QString baseString;
       
   200 		baseString.append("api_key"+apiKey);
       
   201 		baseString.append("limit"+QString::number(gItemsPerPage));
       
   202 		baseString.append("methoduser.getLovedTracks");
       
   203 		baseString.append("page"+QString::number(gPageNum));
       
   204 		baseString.append("user"+userName);
       
   205 		baseString.append(apiSecret);
       
   206 	
       
   207 		// Create the url
       
   208 		QUrl url("http://ws.audioscrobbler.com/2.0/?");
       
   209 		url.addQueryItem("api_key", apiKey);
       
   210 		url.addQueryItem("format", "json");
       
   211 		url.addQueryItem("limit", QString::number(gItemsPerPage));		
       
   212 		url.addQueryItem("method", "user.getLovedTracks");
       
   213 		url.addQueryItem("page", QString::number(gPageNum));
       
   214 		url.addQueryItem("user", userName);
       
   215 		url.addQueryItem("api_sig", generateSignature(baseString));
       
   216 		
       
   217 		// Create the request, set the url
       
   218 		aRequest.iNetworkRequest.setUrl(url);
       
   219 		aRequest.iRequestType = SmfMusicGetUserInfo;
       
   220 		aRequest.iPostData = NULL;
       
   221 		aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   222 		error = SmfPluginErrNone;
       
   223 		}
       
   224 	
       
   225 	// Get the user's events
       
   226 	else //if(3 == userMusicInfoChance)
       
   227 		{
       
   228 		// Create the API signature string
       
   229 		QString baseString;
       
   230 		baseString.append("api_key"+apiKey);
       
   231 		baseString.append("methoduser.getEvents");
       
   232 		baseString.append("user"+userName);
       
   233 		baseString.append(apiSecret);
       
   234 	
       
   235 		// Create the url
       
   236 		QUrl url("http://ws.audioscrobbler.com/2.0/?");
       
   237 		url.addQueryItem("api_key", apiKey);
       
   238 		url.addQueryItem("format", "json");
       
   239 		url.addQueryItem("method", "user.getEvents");
       
   240 		url.addQueryItem("user", userName);
       
   241 		url.addQueryItem("api_sig", generateSignature(baseString));
       
   242 		
       
   243 		// Create the request, set the url
       
   244 		aRequest.iNetworkRequest.setUrl(url);
       
   245 		aRequest.iRequestType = SmfMusicGetUserInfo;
       
   246 		aRequest.iPostData = NULL;
       
   247 		aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   248 		error = SmfPluginErrNone;
       
   249 		}
       
   250 		
       
   251 	qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString();
       
   252 	return error;
       
   253 	}
       
   254 
       
   255 /**
       
   256  * Method to search information about artists. All information 
       
   257  * in SmfArtists is not required, however more available the better
       
   258  * @param aRequest [out] The request data to be sent to network
       
   259  * @param aArtist The artist which is the search criteria
       
   260  * @param aPageNum The page to be extracted
       
   261  * @param aItemsPerPage Number of items per page
       
   262  * @return Appropriate value of the enum SmfPluginError.
       
   263  * Plugin error if any, else SmfPluginErrNone for success
       
   264  */
       
   265 SmfPluginError LastFmMusicServicePlugin::searchArtist( 
       
   266 		SmfPluginRequestData &aRequest,
       
   267 		const SmfArtists &aArtist,
       
   268 		const int aPageNum , 
       
   269 		const int aItemsPerPage )
       
   270 	{
       
   271 	qDebug()<<"Inside LastFmMusicServicePlugin::searchArtist()";
       
   272 			
       
   273 	SmfPluginError error = SmfPluginErrInvalidArguments;
       
   274 
       
   275 	// invalid arguments
       
   276 	if( aPageNum < 0 || aItemsPerPage < 0 || aArtist.names().at(0).isEmpty() )
       
   277 		{
       
   278 		qDebug()<<"Invalid arguments";
       
   279 		return error;
       
   280 		}
       
   281 	
       
   282 	qDebug()<<"Valid arguments";
       
   283 	
       
   284 	gPageNum = aPageNum;
       
   285 	gItemsPerPage = aItemsPerPage;
       
   286 
       
   287 	// Get the key sets from SMF Plugin Utility class.
       
   288 	QString apiKey;
       
   289 	QString apiSecret;
       
   290 	QString token;
       
   291 	QString userName;
       
   292 	fetchKeys(apiKey, apiSecret, token, userName);
       
   293 
       
   294 	// Create the API signature string
       
   295 	QString baseString;
       
   296 	baseString.append("api_key"+apiKey);
       
   297 	baseString.append("artist"+aArtist.names().at(0));
       
   298 	baseString.append("limit"+QString::number(aItemsPerPage));
       
   299 	baseString.append("methodartist.search");
       
   300 	baseString.append("page"+QString::number(aPageNum));
       
   301 	baseString.append(apiSecret);
       
   302 
       
   303 	// Create the url
       
   304 	QUrl url("http://ws.audioscrobbler.com/2.0/?");
       
   305 	url.addQueryItem("api_key", apiKey);
       
   306 	url.addQueryItem("artist", aArtist.names().at(0));
       
   307 	url.addQueryItem("format", "json");
       
   308 	url.addQueryItem("limit", QString::number(aItemsPerPage));
       
   309 	url.addQueryItem("page", QString::number(aPageNum));
       
   310 	url.addQueryItem("method", "artist.search");
       
   311 	url.addQueryItem("api_sig", generateSignature(baseString));
       
   312 	
       
   313 	// Create the request, set the url
       
   314 	aRequest.iNetworkRequest.setUrl(url);
       
   315 	aRequest.iRequestType = SmfMusicSearchArtist;
       
   316 	aRequest.iPostData = NULL;
       
   317 	aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   318 	error = SmfPluginErrNone;
       
   319 	
       
   320 	qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString();
       
   321 	return error;
       
   322 	}
       
   323 
       
   324 /**
       
   325  * Method to search information about album. All information 
       
   326  * in SmfAlbum is not required, however more available the better
       
   327  * @param aRequest [out] The request data to be sent to network
       
   328  * @param aAlbum [in] The album which is the search criteria
       
   329  * @param aPageNum [in] The page to be extracted
       
   330  * @param aItemsPerPage [in] Number of items per page
       
   331  * @return Appropriate value of the enum SmfPluginError.
       
   332  * Plugin error if any, else SmfPluginErrNone for success
       
   333  */
       
   334 SmfPluginError LastFmMusicServicePlugin::searchAlbum( 
       
   335 		SmfPluginRequestData &aRequest,
       
   336 		const SmfAlbum &aAlbum,
       
   337 		const int aPageNum, 
       
   338 		const int aItemsPerPage )
       
   339 	{
       
   340 	qDebug()<<"Inside LastFmMusicServicePlugin::searchAlbum()";
       
   341 			
       
   342 	SmfPluginError error = SmfPluginErrInvalidArguments;
       
   343 
       
   344 	// invalid arguments
       
   345 	if( aPageNum < 0 || aItemsPerPage < 0 || aAlbum.name().isEmpty() )
       
   346 		{
       
   347 		qDebug()<<"Invalid arguments";
       
   348 		return error;
       
   349 		}
       
   350 	
       
   351 	qDebug()<<"Valid arguments";
       
   352 	
       
   353 	gPageNum = aPageNum;
       
   354 	gItemsPerPage = aItemsPerPage;
       
   355 
       
   356 	// Get the key sets from SMF Plugin Utility class.
       
   357 	QString apiKey;
       
   358 	QString apiSecret;
       
   359 	QString token;
       
   360 	QString userName;
       
   361 	fetchKeys(apiKey, apiSecret, token, userName);
       
   362 
       
   363 	// Create the API signature string
       
   364 	QString baseString;
       
   365 	baseString.append("album"+aAlbum.name());
       
   366 	baseString.append("api_key"+apiKey);
       
   367 	baseString.append("limit"+QString::number(aItemsPerPage));
       
   368 	baseString.append("methodalbum.search");
       
   369 	baseString.append("page"+QString::number(aPageNum));
       
   370 	baseString.append(apiSecret);
       
   371 
       
   372 	// Create the url
       
   373 	QUrl url("http://ws.audioscrobbler.com/2.0/?");
       
   374 	url.addQueryItem("album", aAlbum.name());
       
   375 	url.addQueryItem("api_key", apiKey);
       
   376 	url.addQueryItem("limit", QString::number(aItemsPerPage));
       
   377 	url.addQueryItem("page", QString::number(aPageNum));
       
   378 	url.addQueryItem("format", "json");
       
   379 	url.addQueryItem("method", "album.search");
       
   380 	url.addQueryItem("api_sig", generateSignature(baseString));
       
   381 	
       
   382 	// Create the request, set the url
       
   383 	aRequest.iNetworkRequest.setUrl(url);
       
   384 	aRequest.iRequestType = SmfMusicSearchAlbum;
       
   385 	aRequest.iPostData = NULL;
       
   386 	aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   387 	error = SmfPluginErrNone;
       
   388 	
       
   389 	qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString();
       
   390 	return error;
       
   391 	}
       
   392 
       
   393 /**
       
   394  * Method to search information about events. All information 
       
   395  * in SmfEvent is not required, however more available the better
       
   396  * @param aRequest [out] The request data to be sent to network
       
   397  * @param aEvent [in] The event which is the search criteria
       
   398  * @param aPageNum [in] The page to be extracted
       
   399  * @param aItemsPerPage [in] Number of items per page
       
   400  * @return Appropriate value of the enum SmfPluginError.
       
   401  * Plugin error if any, else SmfPluginErrNone for success
       
   402  */
       
   403 SmfPluginError LastFmMusicServicePlugin::searchEvents( 
       
   404 		SmfPluginRequestData &aRequest,
       
   405 		const SmfEvent &aEvent,
       
   406 		const int aPageNum, 
       
   407 		const int aItemsPerPage )
       
   408 	{
       
   409 	qDebug()<<"Inside LastFmMusicServicePlugin::searchEvents()";
       
   410 			
       
   411 	SmfPluginError error = SmfPluginErrInvalidArguments;
       
   412 
       
   413 	// invalid arguments
       
   414 	if( aPageNum < 0 || aItemsPerPage < 0 || aEvent.id().isEmpty() )
       
   415 		{
       
   416 		qDebug()<<"Invalid arguments";
       
   417 		return error;
       
   418 		}
       
   419 	
       
   420 	qDebug()<<"Valid arguments";
       
   421 	
       
   422 	gPageNum = aPageNum;
       
   423 	gItemsPerPage = aItemsPerPage;
       
   424 
       
   425 	// Get the key sets from SMF Plugin Utility class.
       
   426 	QString apiKey;
       
   427 	QString apiSecret;
       
   428 	QString token;
       
   429 	QString userName;
       
   430 	fetchKeys(apiKey, apiSecret, token, userName);
       
   431 
       
   432 	// Create the API signature string
       
   433 	QString baseString;
       
   434 	baseString.append("api_key"+apiKey);
       
   435 	baseString.append("event"+aEvent.id());
       
   436 	baseString.append("methodevent.getInfo");
       
   437 	baseString.append(apiSecret);
       
   438 
       
   439 	// Create the url
       
   440 	QUrl url("http://ws.audioscrobbler.com/2.0/?");
       
   441 	url.addQueryItem("event", aEvent.id());
       
   442 	url.addQueryItem("api_key", apiKey);
       
   443 	url.addQueryItem("format", "json");
       
   444 	url.addQueryItem("method", "event.getInfo");
       
   445 	url.addQueryItem("api_sig", generateSignature(baseString));
       
   446 	
       
   447 	// Create the request, set the url
       
   448 	aRequest.iNetworkRequest.setUrl(url);
       
   449 	aRequest.iRequestType = SmfMusicSearchEvent;
       
   450 	aRequest.iPostData = NULL;
       
   451 	aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   452 	error = SmfPluginErrNone;
       
   453 	
       
   454 	qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString();
       
   455 	return error;
       
   456 	}
       
   457 
       
   458 /**
       
   459  * Method to search information about venue. All information 
       
   460  * in SmfLocation is not required, however more available the better
       
   461  * @param aRequest [out] The request data to be sent to network
       
   462  * @param aVenue [in] The venue which is the search criteria
       
   463  * @param aPageNum [in] The page to be extracted
       
   464  * @param aItemsPerPage [in] Number of items per page
       
   465  * @return Appropriate value of the enum SmfPluginError.
       
   466  * Plugin error if any, else SmfPluginErrNone for success
       
   467  */
       
   468 SmfPluginError LastFmMusicServicePlugin::searchVenue( 
       
   469 		SmfPluginRequestData &aRequest,
       
   470 		const SmfLocation &aVenue,
       
   471 		const int aPageNum, 
       
   472 		const int aItemsPerPage )
       
   473 	{
       
   474 	qDebug()<<"Inside LastFmMusicServicePlugin::searchVenue()";
       
   475 			
       
   476 	SmfPluginError error = SmfPluginErrInvalidArguments;
       
   477 
       
   478 	// invalid arguments
       
   479 	if( aPageNum < 0 || aItemsPerPage < 0 || aVenue.name().isEmpty() )
       
   480 		{
       
   481 		qDebug()<<"Invalid arguments";
       
   482 		return error;
       
   483 		}
       
   484 	
       
   485 	qDebug()<<"Valid arguments";
       
   486 	
       
   487 	gPageNum = aPageNum;
       
   488 	gItemsPerPage = aItemsPerPage;
       
   489 
       
   490 	// Get the key sets from SMF Plugin Utility class.
       
   491 	QString apiKey;
       
   492 	QString apiSecret;
       
   493 	QString token;
       
   494 	QString userName;
       
   495 	fetchKeys(apiKey, apiSecret, token, userName);
       
   496 
       
   497 	// Create the API signature string
       
   498 	QString baseString;
       
   499 	baseString.append("api_key"+apiKey);
       
   500 	baseString.append("limit"+QString::number(aItemsPerPage));
       
   501 	baseString.append("methodvenue.search");
       
   502 	baseString.append("page"+QString::number(aPageNum));
       
   503 	baseString.append("venue"+aVenue.name());
       
   504 	baseString.append(apiSecret);
       
   505 
       
   506 	// Create the url
       
   507 	QUrl url("http://ws.audioscrobbler.com/2.0/?");
       
   508 	url.addQueryItem("venue", aVenue.name());
       
   509 	url.addQueryItem("api_key", apiKey);
       
   510 	url.addQueryItem("format", "json");
       
   511 	url.addQueryItem("limit", QString::number(aItemsPerPage));
       
   512 	url.addQueryItem("page", QString::number(aPageNum));
       
   513 	url.addQueryItem("method", "venue.search");
       
   514 	url.addQueryItem("api_sig", generateSignature(baseString));
       
   515 	
       
   516 	// Create the request, set the url
       
   517 	aRequest.iNetworkRequest.setUrl(url);
       
   518 	aRequest.iRequestType = SmfMusicSearchVenue;
       
   519 	aRequest.iPostData = NULL;
       
   520 	aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   521 	error = SmfPluginErrNone;
       
   522 	
       
   523 	qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString();
       
   524 	return error;
       
   525 	}
       
   526 
       
   527 /**
       
   528  * Method to search information about other service users for a 
       
   529  * particular place
       
   530  * @param aRequest [out] The request data to be sent to network
       
   531  * @param aPlace [in] The place which is the search criteria
       
   532  * @param aPageNum [in] The page to be extracted
       
   533  * @param aItemsPerPage [in] Number of items per page
       
   534  * @return Appropriate value of the enum SmfPluginError.
       
   535  * Plugin error if any, else SmfPluginErrNone for success
       
   536  */
       
   537 SmfPluginError LastFmMusicServicePlugin::searchUser( 
       
   538 		SmfPluginRequestData &aRequest,
       
   539 		const SmfLocation &aPlace,
       
   540 		const int aPageNum, 
       
   541 		const int aItemsPerPage )
       
   542 	{
       
   543 	Q_UNUSED(aRequest)
       
   544 	Q_UNUSED(aPlace)
       
   545 	Q_UNUSED(aPageNum)
       
   546 	Q_UNUSED(aItemsPerPage)
       
   547 	qDebug()<<"Inside LastFmMusicServicePlugin::searchUser()";
       
   548 	SmfPluginError error = SmfPluginErrInvalidRequest;
       
   549 	return error;
       
   550 	
       
   551 #if 0
       
   552 	Q_UNUSED(aPlace)
       
   553 	qDebug()<<"Inside LastFmMusicServicePlugin::searchUser()";
       
   554 			
       
   555 	SmfPluginError error = SmfPluginErrInvalidArguments;
       
   556 
       
   557 	// invalid arguments
       
   558 	if( aPageNum < 0 || aItemsPerPage < 0 )
       
   559 		{
       
   560 		qDebug()<<"Invalid arguments";
       
   561 		return error;
       
   562 		}
       
   563 	
       
   564 	qDebug()<<"Valid arguments";
       
   565 	
       
   566 	// Get the key sets from SMF Plugin Utility class.
       
   567 	QString apiKey;
       
   568 	QString apiSecret;
       
   569 	QString token;
       
   570 	QString userName;
       
   571 	fetchKeys(apiKey, apiSecret, token, userName);
       
   572 
       
   573 	// Create the API signature string
       
   574 	QString baseString;
       
   575 	baseString.append("api_key"+apiKey);
       
   576 	baseString.append("methoduser.getNeighbours");
       
   577 	baseString.append("user"+userName);
       
   578 	baseString.append(apiSecret);
       
   579 
       
   580 	// Create the url
       
   581 	QUrl url("http://ws.audioscrobbler.com/2.0/?");
       
   582 	url.addQueryItem("api_key", apiKey);
       
   583 	url.addQueryItem("format", "json");
       
   584 	url.addQueryItem("method", "user.getNeighbours");
       
   585 	url.addQueryItem("user", userName);
       
   586 	url.addQueryItem("api_sig", generateSignature(baseString));
       
   587 	
       
   588 	// Create the request, set the url
       
   589 	aRequest.iNetworkRequest.setUrl(url);
       
   590 	aRequest.iRequestType = SmfMusicSearchUser;
       
   591 	aRequest.iPostData = NULL;
       
   592 	aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   593 	error = SmfPluginErrNone;
       
   594 	
       
   595 	qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString();
       
   596 	return error;
       
   597 #endif
       
   598 	}
       
   599 
       
   600 /**
       
   601  * Method to post the currently playing track
       
   602  * @param aRequest [out] The request data to be sent to network
       
   603  * @param aTrack [in] The current playing track, that should be posted
       
   604  * @return Appropriate value of the enum SmfPluginError.
       
   605  * Plugin error if any, else SmfPluginErrNone for success
       
   606  */
       
   607 SmfPluginError LastFmMusicServicePlugin::postCurrentPlaying( 
       
   608 		SmfPluginRequestData &aRequest,
       
   609 		const SmfTrackInfo &aTrack )
       
   610 	{
       
   611 	Q_UNUSED(aRequest)
       
   612 	Q_UNUSED(aTrack)
       
   613 	qDebug()<<"Inside LastFmMusicServicePlugin::postCurrentPlaying()";
       
   614 	SmfPluginError error = SmfPluginErrInvalidRequest;
       
   615 	return error;
       
   616 	}
       
   617 
       
   618 /**
       
   619  * Method to post the rating on a track
       
   620  * @param aRequest [out] The request data to be sent to network
       
   621  * @param aTrack [in] The track on which rating should be posted
       
   622  * @param aRating [in] The rating values
       
   623  * @return Appropriate value of the enum SmfPluginError.
       
   624  * Plugin error if any, else SmfPluginErrNone for success
       
   625  */
       
   626 SmfPluginError LastFmMusicServicePlugin::postRating( 
       
   627 		SmfPluginRequestData &aRequest, 
       
   628 		const SmfTrackInfo &aTrack, 
       
   629 		const SmfMusicRating &aRating )
       
   630 	{
       
   631 	Q_UNUSED(aRequest)
       
   632 	Q_UNUSED(aTrack)
       
   633 	Q_UNUSED(aRating)
       
   634 	qDebug()<<"Inside LastFmMusicServicePlugin::postRating()";
       
   635 	SmfPluginError error = SmfPluginErrInvalidRequest;
       
   636 	return error;
       
   637 	}
       
   638 
       
   639 /**
       
   640  * Method to post comment on a track
       
   641  * @param aRequest [out] The request data to be sent to network
       
   642  * @param aTrack [in] The track on which comment should be posted
       
   643  * @param aComment [in] The comment content
       
   644  * @return Appropriate value of the enum SmfPluginError.
       
   645  * Plugin error if any, else SmfPluginErrNone for success
       
   646  */
       
   647 SmfPluginError LastFmMusicServicePlugin::postComments( 
       
   648 		SmfPluginRequestData &aRequest, 
       
   649 		const SmfTrackInfo &aTrack, 
       
   650 		const SmfComment &aComment )
       
   651 	{
       
   652 	Q_UNUSED(aRequest)
       
   653 	Q_UNUSED(aTrack)
       
   654 	Q_UNUSED(aComment)
       
   655 	qDebug()<<"Inside LastFmMusicServicePlugin::postComments()";
       
   656 	SmfPluginError error = SmfPluginErrInvalidRequest;
       
   657 	return error;
       
   658 	}
       
   659 
       
   660 /**
       
   661  * Customised method for SmfMusicServicePlugin interface
       
   662  * @param aRequest [out] The request data to be sent to network
       
   663  * @param aOperation [in] The operation type (should be known between 
       
   664  * the client interface and the plugin)
       
   665  * @param aData [in] The data required to form the request (The type 
       
   666  * of data should be known between client and the plugin)
       
   667  * @return Appropriate value of the enum SmfPluginError.
       
   668  * Plugin error if any, else SmfPluginErrNone for success
       
   669  */
       
   670 SmfPluginError LastFmMusicServicePlugin::customRequest( 
       
   671 		SmfPluginRequestData &aRequest, 
       
   672 		const int &aOperation, QByteArray *aData )
       
   673 	{
       
   674 	Q_UNUSED(aRequest)
       
   675 	Q_UNUSED(aOperation)
       
   676 	Q_UNUSED(aData)
       
   677 	qDebug()<<"Inside LastFmMusicServicePlugin::customRequest()";
       
   678 	SmfPluginError error = SmfPluginErrInvalidRequest;
       
   679 	return error;
       
   680 	}
       
   681 
       
   682 /**
       
   683  * The first method to be called in the plugin that implements this interface.
       
   684  * If this method is not called, plugin may not behave as expected.
       
   685  */
       
   686 void LastFmMusicServicePlugin::initialize( )
       
   687 	{
       
   688 	// Create an instance of LastFmMusicServiceProviderBase
       
   689 	m_provider = new LastFmMusicServiceProviderBase;
       
   690 	m_provider->initialize();
       
   691 	}
       
   692 
       
   693 /**
       
   694  * Method to get the provider information
       
   695  * @return Instance of SmfProviderBase
       
   696  */
       
   697 SmfProviderBase* LastFmMusicServicePlugin::getProviderInfo( )
       
   698 	{
       
   699 	return m_provider;
       
   700 	}
       
   701 
       
   702 /**
       
   703  * Method to get the result for a network request.
       
   704  * @param aOperation The type of operation to be requested
       
   705  * @param aTransportResult The result of transport operation
       
   706  * @param aResponse The QByteArray instance containing the network response.
       
   707  * The plugins should delete this instance once they have read the 
       
   708  * data from it.
       
   709  * @param aResult [out] An output parameter to the plugin manager.If the 
       
   710  * return value is SmfSendRequestAgain, QVariant will be of type 
       
   711  * SmfPluginRequestData.
       
   712  * For SmfMusicServicePlugin: If last operation was userMusicInfo(), aResult
       
   713  * will be of type SmfMusicProfile. If last operation was searchArtist(),
       
   714  * aResult will be of type QList<SmfArtists>. If last operation was searchAlbum(),
       
   715  * aResult will be of type QList<SmfAlbum>. If last operation was searchEvents(),
       
   716  * aResult will be of type QList<SmfEvent>. If last operation was searchVenue(),
       
   717  * aResult will be of type QList<Smfocation>. If last operation was searchUser(),
       
   718  * aResult will be of type QList<SmfMusicProfile>. If last operation was
       
   719  * postCurrentPlaying() or postRating() or postComments(), aResult will be of
       
   720  * type bool.
       
   721  * @param aRetType [out] SmfPluginRetType
       
   722  * @param aPageResult [out] The SmfResultPage structure variable
       
   723  */
       
   724 SmfPluginError LastFmMusicServicePlugin::responseAvailable( 
       
   725 		const SmfRequestTypeID aOperation,
       
   726 		const SmfTransportResult &aTransportResult, 
       
   727 		QByteArray *aResponse, 
       
   728 		QVariant* aResult, 
       
   729 		SmfPluginRetType &aRetType,
       
   730 		SmfResultPage &aPageResult )
       
   731 	{
       
   732 	Q_UNUSED(aPageResult)
       
   733 	qDebug()<<"Inside LastFmMusicServicePlugin::responseAvailable()";
       
   734 	
       
   735 	SmfPluginError error = SmfPluginErrNetworkError;
       
   736 	
       
   737 	if( !aResponse || (0 == aResponse->size()) )
       
   738 		{
       
   739 		qDebug()<<"Response is NULL or empty";
       
   740 		aRetType = SmfRequestError;
       
   741 		return error;
       
   742 		}
       
   743 	
       
   744 	QByteArray response(*aResponse);
       
   745 	delete aResponse;
       
   746 	
       
   747 	QFile respFile("c://data//SmfMusicServicePluginResponse.txt");
       
   748 	if(!respFile.open(QIODevice::WriteOnly))
       
   749 		qDebug()<<"File to write the response could not be opened";
       
   750 	else
       
   751 		{
       
   752 		respFile.write(response);
       
   753 		respFile.close();
       
   754 		qDebug()<<"Writing FB response to a file named 'SmfMusicServicePluginResponse.txt'";
       
   755 		}
       
   756 	qDebug()<<"FB response size = "<<response.size();
       
   757 	
       
   758 	if(SmfTransportOpNoError == aTransportResult)
       
   759 		{
       
   760 		qDebug()<<"No transport error";
       
   761 		
       
   762 		// Get music user info
       
   763 		if(SmfMusicGetUserInfo == aOperation)
       
   764 			{
       
   765 			qDebug()<<"Response for getting user profile";
       
   766 						
       
   767 			QString errStr;
       
   768 			errStr.clear();
       
   769 				
       
   770 			bool ok;
       
   771 			SmfPluginUtil util;
       
   772 			QVariantMap result = util.parse(response, &ok).toMap();
       
   773 			if (!ok) 
       
   774 				{
       
   775 				qDebug()<<"An error occurred during json parsing";
       
   776 				aRetType = SmfRequestError;
       
   777 				return SmfPluginErrParsingFailed;
       
   778 				}
       
   779 					
       
   780 			qDebug()<<"Json parsing complete";
       
   781 			
       
   782 			if(response.contains(QByteArray("error")))
       
   783 				{
       
   784 				errStr.append(result["message"].toString());
       
   785 				}
       
   786 			else
       
   787 				{
       
   788 				if(0 == userMusicInfoChance)
       
   789 					{
       
   790 					qDebug()<<"For getting logged in user's name";
       
   791 	
       
   792 					QVariantMap map1 = result["user"].toMap();
       
   793 					gUserId.clear();
       
   794 					gUserId.append(map1["id"].toString());
       
   795 					}
       
   796 				else if(1 == userMusicInfoChance)
       
   797 					{
       
   798 					qDebug()<<"For getting recent tracks";
       
   799 				
       
   800 					QVariantMap map1 = result["recenttracks"].toMap();
       
   801 					QList<QVariant> list1 = map1["track"].toList();
       
   802 					QListIterator<QVariant> iter1(list1);
       
   803 					while(iter1.hasNext())
       
   804 						{
       
   805 						QVariantMap map2 = iter1.next().toMap();
       
   806 						SmfTrackInfo track;
       
   807 						
       
   808 						SmfArtists artist;
       
   809 						QStringList names;
       
   810 						QVariantMap map3 = map2["artist"].toMap();
       
   811 						names.append(map3["#text"].toString());
       
   812 						artist.setNames(names);
       
   813 						
       
   814 						artist.setId(map3["mbid"].toString());
       
   815 						
       
   816 						track.setArtists(artist);
       
   817 						
       
   818 						track.setTitle(map2["name"].toString());
       
   819 						track.setId(map2["mbid"].toString());
       
   820 						
       
   821 						SmfAlbum album;
       
   822 						QVariantMap map4 = map2["album"].toMap();
       
   823 						album.setName(map4["#text"].toString());
       
   824 						album.setId(map4["mbid"].toString());
       
   825 						
       
   826 						track.setAlbum(album);
       
   827 						
       
   828 						gRecentTracks.append(track);
       
   829 						
       
   830 						if(gItemsPerPage == gRecentTracks.count())
       
   831 							break;
       
   832 						}
       
   833 					}
       
   834 				else if(2 == userMusicInfoChance)
       
   835 					{
       
   836 					qDebug()<<"For getting favorites";
       
   837 					
       
   838 					QVariantMap map1 = result["lovedtracks"].toMap();
       
   839 					QList<QVariant> list1 = map1["track"].toList();
       
   840 					QListIterator<QVariant> iter1(list1);
       
   841 					while(iter1.hasNext())
       
   842 						{
       
   843 						QVariantMap map2 = iter1.next().toMap();
       
   844 						SmfTrackInfo track;
       
   845 						
       
   846 						track.setTitle(map2["name"].toString());
       
   847 						qDebug()<<"Track name : "<<track.title();
       
   848 						track.setId(map2["mbid"].toString());
       
   849 						
       
   850 						SmfArtists artist;
       
   851 						QStringList names;
       
   852 						QVariantMap map3 = map2["artist"].toMap();
       
   853 						names.append(map3["name"].toString());
       
   854 						artist.setNames(names);
       
   855 						artist.setId(map3["mbid"].toString());
       
   856 						QUrl url(map3["url"].toString());
       
   857 						artist.setUrl(url);
       
   858 						QList<QVariant> list2 = map3["image"].toList();
       
   859 						QListIterator<QVariant> iter2(list2);
       
   860 						while(iter2.hasNext())
       
   861 							{
       
   862 							QVariantMap map4 = iter2.next().toMap();
       
   863 		
       
   864 							// Set the artist's image url
       
   865 							QUrl url(map4["#text"].toString());
       
   866 							//artist.setImageUrlurl);
       
   867 							qDebug()<<"Track artists image url : "<<url.toString();
       
   868 							}
       
   869 												
       
   870 						track.setArtists(artist);
       
   871 						qDebug()<<"Favorite tracks count = "<<gFavorites.count();
       
   872 						gFavorites.append(track);
       
   873 						
       
   874 						if(gItemsPerPage == gFavorites.count())
       
   875 							break;
       
   876 						}
       
   877 					}
       
   878 				else //if(3 == userMusicInfoChance)
       
   879 					{
       
   880 					qDebug()<<"For getting user's registered events";
       
   881 					QVariantMap map1 = result["events"].toMap();
       
   882 					QList<QVariant> list1 = map1["event"].toList();
       
   883 					QListIterator<QVariant> iter1(list1);
       
   884 					while(iter1.hasNext())
       
   885 						{
       
   886 						QVariantMap map2 = iter1.next().toMap();
       
   887 					
       
   888 						SmfEvent event;
       
   889 						event.setId(map2["id"].toString());
       
   890 						event.setTitle(map2["title"].toString());
       
   891 								
       
   892 						// Set the events date and time
       
   893 						QDateTime dateTime;// = QDateTime::fromString("M1d1y9800:01:02","'M'M'd'd'y'yyhh:mm:ss");
       
   894 						event.setEventDateTime(dateTime);
       
   895 						
       
   896 						// Set the events artists
       
   897 						SmfArtists artists;
       
   898 						QStringList names;
       
   899 						names.clear();
       
   900 						QVariantMap map3 = map2["artists"].toMap();
       
   901 						QList<QVariant> list1 = map3["artist"].toList();
       
   902 						names.clear();
       
   903 						QListIterator<QVariant> iter1(list1);
       
   904 						while(iter1.hasNext())
       
   905 							names.append(iter1.next().toString());
       
   906 						artists.setNames(names);
       
   907 						event.setArtists(artists);
       
   908 						
       
   909 						// Set the events venue information
       
   910 						QVariantMap map4 = map2["venue"].toMap();
       
   911 						SmfLocation location;
       
   912 						location.setId(map4["id"].toString());
       
   913 						location.setName(map4["name"].toString());
       
   914 						QUrl url(map4["url"].toString());
       
   915 						location.setUrl(url);
       
   916 						
       
   917 						
       
   918 						QVariantMap map5 = map4["location"].toMap();
       
   919 						location.setCity(map5["city"].toString());
       
   920 						location.setCountry(map5["country"].toString());
       
   921 						location.setStreet(map5["street"].toString());
       
   922 						location.setZipCode(map5["postalcode"].toString());
       
   923 						
       
   924 						QVariantMap map6 = map5["geo:point"].toMap();
       
   925 						double latitude = map6["geo:lat"].toDouble();
       
   926 						double longitude = map6["geo:long"].toDouble();
       
   927 						QGeoCoordinate coordinate(latitude, longitude);
       
   928 						QGeoPositionInfo geoInfo;
       
   929 						geoInfo.setCoordinate(coordinate);
       
   930 						location.setGeoPositionInfo(geoInfo);
       
   931 						
       
   932 						event.setVenue(location);
       
   933 						
       
   934 						// Set the events ticketUrl
       
   935 						QUrl ticketUrl(map2["tickets"].toString());
       
   936 						event.setTicketUrl(ticketUrl);
       
   937 	
       
   938 	
       
   939 						gUserEvents.append(event);
       
   940 						
       
   941 						if(gItemsPerPage == gUserEvents.count())
       
   942 							break;
       
   943 						}
       
   944 					}
       
   945 				}
       
   946 			
       
   947 			if(errStr.size())
       
   948 				{
       
   949 				qDebug()<<"Response error found = "<<errStr;
       
   950 				error = SmfPluginErrInvalidRequest;
       
   951 				aRetType = SmfRequestError;
       
   952 				aResult->setValue(errStr);
       
   953 				}
       
   954 			else
       
   955 				{
       
   956 				if(0 == userMusicInfoChance)
       
   957 					{
       
   958 					qDebug()<<"current logged in userId  = "<<gUserId;
       
   959 					aRetType = SmfSendRequestAgain;
       
   960 					error = SmfPluginErrNone;
       
   961 					userMusicInfoChance = 1;
       
   962 					}
       
   963 				else if(1 == userMusicInfoChance)
       
   964 					{
       
   965 					qDebug()<<"Count of user's recent tracks  = "<<gRecentTracks.count();
       
   966 					aRetType = SmfSendRequestAgain;
       
   967 					error = SmfPluginErrNone;
       
   968 					userMusicInfoChance = 2;
       
   969 					}
       
   970 				else if(2 == userMusicInfoChance)
       
   971 					{
       
   972 					qDebug()<<"Count of user's favorite tracks  = "<<gFavorites.count();
       
   973 					aRetType = SmfSendRequestAgain;
       
   974 					error = SmfPluginErrNone;
       
   975 					userMusicInfoChance = 3;
       
   976 					}
       
   977 				else //if(3 == userMusicInfoChance)
       
   978 					{
       
   979 					SmfMusicProfile profile;
       
   980 					profile.setFavorites(gFavorites);
       
   981 					profile.setRecentTracks(gRecentTracks);
       
   982 					profile.setUserEvents(gUserEvents);
       
   983 					profile.setId(gUserId);
       
   984 					
       
   985 					qDebug()<<"profile id in last.fm = "<<profile.id();
       
   986 					aResult->setValue(profile);
       
   987 					aRetType = SmfRequestComplete;
       
   988 					error = SmfPluginErrNone;
       
   989 					}
       
   990 				}
       
   991 			
       
   992 			}
       
   993 		// Artists search
       
   994 		else if ( SmfMusicSearchArtist == aOperation )
       
   995 			{
       
   996 			qDebug()<<"Response for searching artists";
       
   997 			
       
   998 			QList<SmfArtists> list;
       
   999 			QString errStr;
       
  1000 			errStr.clear();
       
  1001 				
       
  1002 			bool ok;
       
  1003 			SmfPluginUtil util;
       
  1004 			QVariantMap result = util.parse(response, &ok).toMap();
       
  1005 			if (!ok) 
       
  1006 				{
       
  1007 				qDebug()<<"An error occurred during json parsing";
       
  1008 				aRetType = SmfRequestError;
       
  1009 				return SmfPluginErrParsingFailed;
       
  1010 				}
       
  1011 					
       
  1012 			qDebug()<<"Json parsing complete";
       
  1013 			
       
  1014 			if(response.contains(QByteArray("error")))
       
  1015 				{
       
  1016 				errStr.append(result["message"].toString());
       
  1017 				}
       
  1018 			else
       
  1019 				{
       
  1020 				QVariantMap map1 = result["results"].toMap();
       
  1021 				QVariantMap map2 = map1["artistmatches"].toMap();
       
  1022 				QList<QVariant> list1 = map2["artist"].toList();
       
  1023 				QListIterator<QVariant> iter(list1);
       
  1024 				while(iter.hasNext())
       
  1025 					{
       
  1026 					SmfArtists artist;
       
  1027 					QVariantMap map3 = iter.next().toMap();
       
  1028 					
       
  1029 					// Name of the artist
       
  1030 					QStringList names;
       
  1031 					names.append(map3["name"].toString());
       
  1032 					artist.setNames(names);
       
  1033 					
       
  1034 					// last.fm ID of the artist
       
  1035 					artist.setId(map3["mbid"].toString());
       
  1036 					
       
  1037 					// last.fm url of the artist
       
  1038 					QUrl url(map3["url"].toString());
       
  1039 					artist.setUrl(url);
       
  1040 					
       
  1041 					// last.fm image of the artist
       
  1042 					QList<QVariant> list2 = map3["image"].toList();
       
  1043 					QListIterator<QVariant> iter2(list2);
       
  1044 					while(iter2.hasNext())
       
  1045 						{
       
  1046 						QVariantMap map5 = iter2.next().toMap();
       
  1047 						QUrl imageUrl(map5["#text"].toString());
       
  1048 						//artists.setImageUrl(imageUrl);
       
  1049 						break;
       
  1050 						}
       
  1051 					
       
  1052 					list.append(artist);
       
  1053 					
       
  1054 					if(gItemsPerPage == list.count())
       
  1055 						break;
       
  1056 					}
       
  1057 				}
       
  1058 			
       
  1059 			if(errStr.size())
       
  1060 				{
       
  1061 				qDebug()<<"Response error found = "<<errStr;
       
  1062 				error = SmfPluginErrInvalidRequest;
       
  1063 				aRetType = SmfRequestError;
       
  1064 				aResult->setValue(errStr);
       
  1065 				}
       
  1066 			else
       
  1067 				{
       
  1068 				qDebug()<<"list count = "<<list.count();
       
  1069 				aResult->setValue(list);
       
  1070 				aRetType = SmfRequestComplete;
       
  1071 				error = SmfPluginErrNone;
       
  1072 				}
       
  1073 			}
       
  1074 		
       
  1075 		// Albums search
       
  1076 		else if ( SmfMusicSearchAlbum == aOperation )
       
  1077 			{
       
  1078 			qDebug()<<"Response for searching albums";
       
  1079 			
       
  1080 			QList<SmfAlbum> list;
       
  1081 			QString errStr;
       
  1082 			errStr.clear();
       
  1083 				
       
  1084 			bool ok;
       
  1085 			SmfPluginUtil util;
       
  1086 			QVariantMap result = util.parse(response, &ok).toMap();
       
  1087 			if (!ok) 
       
  1088 				{
       
  1089 				qDebug()<<"An error occurred during json parsing";
       
  1090 				aRetType = SmfRequestError;
       
  1091 				return SmfPluginErrParsingFailed;
       
  1092 				}
       
  1093 					
       
  1094 			qDebug()<<"Json parsing complete";
       
  1095 			
       
  1096 			if(response.contains(QByteArray("error")))
       
  1097 				{
       
  1098 				errStr.append(result["message"].toString());
       
  1099 				}
       
  1100 			else
       
  1101 				{
       
  1102 				QVariantMap map1 = result["results"].toMap();
       
  1103 				QVariantMap map2 = map1["albummatches"].toMap();
       
  1104 				QList<QVariant> list1 = map2["album"].toList();
       
  1105 				QListIterator<QVariant> iter(list1);
       
  1106 				while(iter.hasNext())
       
  1107 					{
       
  1108 					SmfAlbum album;
       
  1109 			
       
  1110 					QVariantMap map3 = iter.next().toMap();
       
  1111 					
       
  1112 					album.setName(map3["name"].toString());
       
  1113 					
       
  1114 					SmfArtists artists;
       
  1115 					QStringList names;
       
  1116 					names.append(map3["artist"].toString());
       
  1117 					artists.setNames(names);
       
  1118 					
       
  1119 					QList<QVariant> list2 = map3["image"].toList();
       
  1120 					QListIterator<QVariant> iter2(list2);
       
  1121 					while(iter2.hasNext())
       
  1122 						{
       
  1123 						QVariantMap map5 = iter2.next().toMap();
       
  1124 						QUrl imageUrl(map5["#text"].toString());
       
  1125 						//artists.setImageUrl(imageUrl);
       
  1126 						break;
       
  1127 						}
       
  1128 					
       
  1129 					album.setArtists(artists);
       
  1130 					
       
  1131 					album.setId(map3["id"].toString());
       
  1132 					
       
  1133 					//QUrl url(map3["url"].toString())
       
  1134 					//album.setUrl(url);
       
  1135 					
       
  1136 					list.append(album);
       
  1137 					
       
  1138 					if(gItemsPerPage == list.count())
       
  1139 						break;
       
  1140 					}
       
  1141 				}
       
  1142 			
       
  1143 			if(errStr.size())
       
  1144 				{
       
  1145 				qDebug()<<"Response error found = "<<errStr;
       
  1146 				error = SmfPluginErrInvalidRequest;
       
  1147 				aRetType = SmfRequestError;
       
  1148 				aResult->setValue(errStr);
       
  1149 				}
       
  1150 			else
       
  1151 				{
       
  1152 				qDebug()<<"list count = "<<list.count();
       
  1153 				aResult->setValue(list);
       
  1154 				aRetType = SmfRequestComplete;
       
  1155 				error = SmfPluginErrNone;
       
  1156 				}
       
  1157 					
       
  1158 			}
       
  1159 		
       
  1160 		// Events search
       
  1161 		else if (SmfMusicSearchEvent == aOperation)
       
  1162 			{
       
  1163 			qDebug()<<"Response for searching events";
       
  1164 			
       
  1165 			QList<SmfEvent> list;
       
  1166 			QString errStr;
       
  1167 			errStr.clear();
       
  1168 				
       
  1169 			bool ok;
       
  1170 			SmfPluginUtil util;
       
  1171 			QVariantMap result = util.parse(response, &ok).toMap();
       
  1172 			if (!ok) 
       
  1173 				{
       
  1174 				qDebug()<<"An error occurred during json parsing";
       
  1175 				aRetType = SmfRequestError;
       
  1176 				return SmfPluginErrParsingFailed;
       
  1177 				}
       
  1178 					
       
  1179 			qDebug()<<"Json parsing complete";
       
  1180 			
       
  1181 			if(response.contains(QByteArray("error")))
       
  1182 				{
       
  1183 				errStr.append(result["message"].toString());
       
  1184 				}
       
  1185 			else
       
  1186 				{
       
  1187 				QVariantMap map1 = result["event"].toMap();
       
  1188 				SmfEvent event;
       
  1189 				
       
  1190 				// Set the events title
       
  1191 				event.setTitle(map1["title"].toString());
       
  1192 				
       
  1193 				// Set the events id
       
  1194 				event.setId(map1["id"].toString());
       
  1195 				
       
  1196 				// Set the events date and time
       
  1197 				QDateTime dateTime;// = QDateTime::fromString("M1d1y9800:01:02","'M'M'd'd'y'yyhh:mm:ss");
       
  1198 				event.setEventDateTime(dateTime);
       
  1199 				
       
  1200 				// Set the events artists
       
  1201 				SmfArtists artists;
       
  1202 				QStringList names;
       
  1203 				names.clear();
       
  1204 				QVariantMap map2 = map1["artists"].toMap();
       
  1205 				QList<QVariant> list1 = map2["artist"].toList();
       
  1206 				QListIterator<QVariant> iter(list1);
       
  1207 				while(iter.hasNext())
       
  1208 					names.append(iter.next().toString());
       
  1209 				artists.setNames(names);
       
  1210 				event.setArtists(artists);
       
  1211 				
       
  1212 				// Set the events venue information
       
  1213 				QVariantMap map3 = map1["venue"].toMap();
       
  1214 				SmfLocation location;
       
  1215 				location.setName(map3["name"].toString());
       
  1216 				QUrl url(map3["url"].toString());
       
  1217 				location.setUrl(url);
       
  1218 				location.setId(map3["id"].toString());
       
  1219 
       
  1220 				QVariantMap map4 = map3["location"].toMap();
       
  1221 				location.setCity(map4["city"].toString());
       
  1222 				location.setCountry(map4["country"].toString());
       
  1223 				location.setStreet(map4["street"].toString());
       
  1224 				location.setZipCode(map4["postalcode"].toString());
       
  1225 
       
  1226 				QVariantMap map5 = map4["geo:point"].toMap();
       
  1227 				double latitude = map5["geo:lat"].toDouble();
       
  1228 				double longitude = map5["geo:long"].toDouble();
       
  1229 				QGeoCoordinate coordinate(latitude, longitude);
       
  1230 				QGeoPositionInfo geoInfo;
       
  1231 				geoInfo.setCoordinate(coordinate);
       
  1232 				location.setGeoPositionInfo(geoInfo);
       
  1233 
       
  1234 				event.setVenue(location);
       
  1235 				
       
  1236 				// Set the events ticketUrl
       
  1237 				QUrl ticketUrl(map1["tickets"].toString());
       
  1238 				event.setTicketUrl(ticketUrl);
       
  1239 				
       
  1240 				// Set the events id
       
  1241 				event.setId(map1["id"].toString());
       
  1242 				
       
  1243 				list.append(event);
       
  1244 				}
       
  1245 		
       
  1246 			if(errStr.size())
       
  1247 				{
       
  1248 				qDebug()<<"Response error found = "<<errStr;
       
  1249 				error = SmfPluginErrInvalidRequest;
       
  1250 				aRetType = SmfRequestError;
       
  1251 				aResult->setValue(errStr);
       
  1252 				}
       
  1253 			else
       
  1254 				{
       
  1255 				qDebug()<<"list count = "<<list.count();
       
  1256 				aResult->setValue(list);
       
  1257 				aRetType = SmfRequestComplete;
       
  1258 				error = SmfPluginErrNone;
       
  1259 				}
       
  1260 			}
       
  1261 		
       
  1262 		// Venues Search
       
  1263 		else if(SmfMusicSearchVenue == aOperation)
       
  1264 			{
       
  1265 			qDebug()<<"Response for searching venues";
       
  1266 			
       
  1267 			QList<SmfLocation> list;
       
  1268 			QString errStr;
       
  1269 			errStr.clear();
       
  1270 				
       
  1271 			bool ok;
       
  1272 			SmfPluginUtil util;
       
  1273 			QVariantMap result = util.parse(response, &ok).toMap();
       
  1274 			if (!ok) 
       
  1275 				{
       
  1276 				qDebug()<<"An error occurred during json parsing";
       
  1277 				aRetType = SmfRequestError;
       
  1278 				return SmfPluginErrParsingFailed;
       
  1279 				}
       
  1280 					
       
  1281 			qDebug()<<"Json parsing complete";
       
  1282 			
       
  1283 			if(response.contains(QByteArray("error")))
       
  1284 				{
       
  1285 				errStr.append(result["message"].toString());
       
  1286 				}
       
  1287 			else
       
  1288 				{
       
  1289 				QVariantMap map1 = result["results"].toMap();
       
  1290 				QVariantMap map2 = map1["venuematches"].toMap();
       
  1291 				QList<QVariant> list1 = map2["venue"].toList();
       
  1292 				QListIterator<QVariant> iter(list1);
       
  1293 				while(iter.hasNext())
       
  1294 					{
       
  1295 					SmfLocation location;
       
  1296 					QVariantMap map3 = iter.next().toMap();
       
  1297 					
       
  1298 					location.setName(map3["name"].toString());
       
  1299 					QUrl url(map3["url"].toString());
       
  1300 					location.setUrl(url);
       
  1301 					location.setId(map3["id"].toString());
       
  1302 	
       
  1303 					QVariantMap map4 = map3["location"].toMap();
       
  1304 					location.setCity(map4["city"].toString());
       
  1305 					location.setCountry(map4["country"].toString());
       
  1306 					location.setStreet(map4["street"].toString());
       
  1307 					location.setZipCode(map4["postalcode"].toString());
       
  1308 	
       
  1309 					QVariantMap map5 = map4["geo:point"].toMap();
       
  1310 					double latitude = map5["geo:lat"].toDouble();
       
  1311 					double longitude = map5["geo:long"].toDouble();
       
  1312 					QGeoCoordinate coordinate(latitude, longitude);
       
  1313 					QGeoPositionInfo geoInfo;
       
  1314 					geoInfo.setCoordinate(coordinate);
       
  1315 					location.setGeoPositionInfo(geoInfo);
       
  1316 					
       
  1317 					list.append(location);
       
  1318 					
       
  1319 					if(gItemsPerPage == list.count())
       
  1320 						break;
       
  1321 					}
       
  1322 				}
       
  1323 			
       
  1324 			if(errStr.size())
       
  1325 				{
       
  1326 				qDebug()<<"Response error found = "<<errStr;
       
  1327 				error = SmfPluginErrInvalidRequest;
       
  1328 				aRetType = SmfRequestError;
       
  1329 				aResult->setValue(errStr);
       
  1330 				}
       
  1331 			else
       
  1332 				{
       
  1333 				qDebug()<<"list count = "<<list.count();
       
  1334 				aResult->setValue(list);
       
  1335 				aRetType = SmfRequestComplete;
       
  1336 				error = SmfPluginErrNone;
       
  1337 				}
       
  1338 			}
       
  1339 		
       
  1340 #if 0
       
  1341 		// User search
       
  1342 		else if(SmfMusicSearchUser == aOperation)
       
  1343 			{
       
  1344 			qDebug()<<"Response for searching users";
       
  1345 			
       
  1346 			QList<SmfMusicProfile> list;
       
  1347 			QString errStr;
       
  1348 			errStr.clear();
       
  1349 			
       
  1350 			bool ok;
       
  1351 			SmfPluginUtil util;
       
  1352 			QVariantMap result = util.parse(response, &ok).toMap();
       
  1353 			if (!ok) 
       
  1354 				{
       
  1355 				qDebug()<<"An error occurred during json parsing";
       
  1356 				aRetType = SmfRequestError;
       
  1357 				return SmfPluginErrParsingFailed;
       
  1358 				}
       
  1359 			
       
  1360 			if(response.contains(QByteArray("error")))
       
  1361 				{
       
  1362 				errStr.append(result["message"].toString());
       
  1363 				}
       
  1364 			else
       
  1365 				{
       
  1366 				qDebug()<<"For getting user's neighbours";
       
  1367 				
       
  1368 				QVariantMap map1 = result["neighbours"].toMap();
       
  1369 				QList<QVariant> list1 = map1["user"].toList();
       
  1370 				QListIterator<QVariant> iter(list1);
       
  1371 				while(iter.hasNext())
       
  1372 					{
       
  1373 					SmfMusicProfile profile;
       
  1374 					QVariantMap map2 = iter.next().toMap();
       
  1375 					
       
  1376 /*					QContactName name;
       
  1377 					name.setFirstName(map2["name"].toString());
       
  1378 					QVariant nameVar = QVariant::fromValue<QContactName>(name);
       
  1379 					contact.setValue("Name", nameVar);
       
  1380 											
       
  1381 					QContactUrl url;
       
  1382 					url.setUrl(map2["url"].toString());
       
  1383 					QVariant urlVar = QVariant::fromValue<QContactUrl>(url);
       
  1384 					contact.setValue("Url", urlVar);
       
  1385 					
       
  1386 					QContactAvatar avatar;
       
  1387 					QList<QVariant> list2 = map2["image"].toList();
       
  1388 					QListIterator<QVariant> iter2(list2);
       
  1389 					while(iter2.hasNext())
       
  1390 						{
       
  1391 						QVariantMap map3 = iter2.next().toMap();
       
  1392 						QUrl imageUrl(map3["#text"].toString());
       
  1393 						avatar.setImageUrl(imageUrl);
       
  1394 						break;
       
  1395 						}
       
  1396 
       
  1397 					QVariant avatarVar = QVariant::fromValue<QContactAvatar>(avatar);
       
  1398 					contact.setValue("Avatar", avatarVar);*/
       
  1399 					
       
  1400 					profile.setId(map2["name"].toString());
       
  1401 					
       
  1402 					list.append(profile);
       
  1403 					
       
  1404 					if(gItemsPerPage == list.count())
       
  1405 						break;
       
  1406 					
       
  1407 					}
       
  1408 				}
       
  1409 				
       
  1410 			if(errStr.size())
       
  1411 				{
       
  1412 				qDebug()<<"Response error found = "<<errStr;
       
  1413 				error = SmfPluginErrInvalidRequest;
       
  1414 				aRetType = SmfRequestError;
       
  1415 				aResult->setValue(errStr);
       
  1416 				}
       
  1417 			else
       
  1418 				{
       
  1419 				qDebug()<<"list count = "<<list.count();
       
  1420 				aResult->setValue(list);
       
  1421 				aRetType = SmfRequestComplete;
       
  1422 				error = SmfPluginErrNone;
       
  1423 				}
       
  1424 			}
       
  1425 #endif
       
  1426 		
       
  1427 		else
       
  1428 			{
       
  1429 			qDebug()<<"Service unsupported!!!";
       
  1430 			aRetType = SmfRequestError;
       
  1431 			error = SmfPluginErrServiceNotSupported;
       
  1432 			}
       
  1433 		}
       
  1434 
       
  1435 		else if(SmfTransportOpOperationCanceledError == aTransportResult)
       
  1436 			{
       
  1437 			qDebug()<<"Operation Cancelled !!!";
       
  1438 			error = SmfPluginErrCancelComplete;
       
  1439 			aRetType = SmfRequestComplete;
       
  1440 			}
       
  1441 
       
  1442 		else
       
  1443 			{
       
  1444 			qDebug()<<"Transport Error !!!";
       
  1445 			error = SmfPluginErrNetworkError;
       
  1446 			aRetType = SmfRequestError;
       
  1447 			}
       
  1448 		
       
  1449 		return error;
       
  1450 	}
       
  1451 
       
  1452 
       
  1453 
       
  1454 /**
       
  1455  * Destructor
       
  1456  */
       
  1457 LastFmMusicServiceProviderBase::~LastFmMusicServiceProviderBase( )
       
  1458 	{
       
  1459 	}
       
  1460 
       
  1461 
       
  1462 /**
       
  1463  * Method to get the Localisable name of the service.
       
  1464  * @return The Localisable name of the service.
       
  1465  */
       
  1466 QString LastFmMusicServiceProviderBase::serviceName( ) const
       
  1467 	{
       
  1468 	return m_serviceName;
       
  1469 	}
       
  1470 
       
  1471 
       
  1472 /**
       
  1473  * Method to get the Logo of the service
       
  1474  * @return The Logo of the service
       
  1475  */
       
  1476 QImage LastFmMusicServiceProviderBase::serviceIcon( ) const
       
  1477 	{
       
  1478 	return m_serviceIcon;
       
  1479 	}
       
  1480 
       
  1481 
       
  1482 /**
       
  1483  * Method to get the Readable service description
       
  1484  * @return The Readable service description
       
  1485  */
       
  1486 QString LastFmMusicServiceProviderBase::description( ) const
       
  1487 	{
       
  1488 	return m_description;
       
  1489 	}
       
  1490 
       
  1491 
       
  1492 /**
       
  1493  * Method to get the Website of the service
       
  1494  * @return The Website of the service
       
  1495  */
       
  1496 QUrl LastFmMusicServiceProviderBase::serviceUrl( ) const
       
  1497 	{
       
  1498 	return m_serviceUrl;
       
  1499 	}
       
  1500 
       
  1501 
       
  1502 /**
       
  1503  * Method to get the URL of the Application providing this service
       
  1504  * @return The URL of the Application providing this service
       
  1505  */
       
  1506 QUrl LastFmMusicServiceProviderBase::applicationUrl( ) const
       
  1507 	{
       
  1508 	return m_applicationUrl;
       
  1509 	}
       
  1510 
       
  1511 
       
  1512 /**
       
  1513  * Method to get the Icon of the application
       
  1514  * @return The Icon of the application
       
  1515  */
       
  1516 QImage LastFmMusicServiceProviderBase::applicationIcon( ) const
       
  1517 	{
       
  1518 	return m_applicationIcon;
       
  1519 	}
       
  1520 
       
  1521 /**
       
  1522 * Method to get the list of interfaces that this provider support
       
  1523 * @return List of supported Interafces
       
  1524 */
       
  1525 QList<QString> LastFmMusicServiceProviderBase::supportedInterfaces( ) const
       
  1526 	{
       
  1527 	return m_supportedInterfaces;
       
  1528 	}
       
  1529 
       
  1530 /**
       
  1531 * Method to get the list of languages supported by this service provider
       
  1532 * @return a QStringList of languages supported by this service 
       
  1533 * provider in 2 letter ISO 639-1 format.
       
  1534 */
       
  1535 QStringList LastFmMusicServiceProviderBase::supportedLanguages( ) const
       
  1536 	{
       
  1537 	return m_supportedLangs;
       
  1538 	}
       
  1539 
       
  1540 /**
       
  1541  * Method to get the Plugin specific ID
       
  1542  * @return The Plugin specific ID
       
  1543  */
       
  1544 QString LastFmMusicServiceProviderBase::pluginId( ) const
       
  1545 	{
       
  1546 	return m_pluginId;
       
  1547 	}
       
  1548 
       
  1549 
       
  1550 /**
       
  1551  * Method to get the ID of the authentication application 
       
  1552  * for this service
       
  1553  * @param aProgram The authentication application name
       
  1554  * @param aArguments List of arguments required for authentication app
       
  1555  * @param aMode Strting mode for authentication application
       
  1556  * @return The ID of the authentication application 
       
  1557  */
       
  1558 QString LastFmMusicServiceProviderBase::authenticationApp( QString &aProgram, 
       
  1559 		QStringList & aArguments, 
       
  1560 		QIODevice::OpenModeFlag aMode ) const
       
  1561 	{
       
  1562 	Q_UNUSED(aProgram)
       
  1563 	Q_UNUSED(aArguments)
       
  1564 	Q_UNUSED(aMode)
       
  1565 	return m_authAppId;
       
  1566 	}
       
  1567 
       
  1568 
       
  1569 /**
       
  1570  * Method to get the unique registration ID provided by the 
       
  1571  * Smf for authorised plugins
       
  1572  * @return The unique registration ID/token provided by the Smf for 
       
  1573  * authorised plugins
       
  1574  */
       
  1575 QString LastFmMusicServiceProviderBase::smfRegistrationId( ) const
       
  1576 	{
       
  1577 	return m_smfRegToken;
       
  1578 	}
       
  1579 
       
  1580 
       
  1581 /**
       
  1582  * Method that initializes this class. This method should be called 
       
  1583  * from the initialize() method of the FBContactFetcherPlugin class
       
  1584  */
       
  1585 void LastFmMusicServiceProviderBase::initialize()
       
  1586 	{
       
  1587 	m_serviceName = "last.fm";
       
  1588 	m_description = "Last.fm music service plugin description";
       
  1589 	m_serviceUrl = QUrl(QString("http://www.last.fm"));
       
  1590 	m_pluginId = "lastfmmusicserviceplugin.qtplugin";
       
  1591 	m_authAppId = "0x12345678";
       
  1592 	m_supportedInterfaces.append("org.symbian.smf.plugin.music.service/v0.2");
       
  1593 	QSettings iSettings;
       
  1594 	m_smfRegToken = iSettings.value("LastFmRegToken").toString();
       
  1595 	m_validity = iSettings.value("LastFmExpiryTime").toDateTime();
       
  1596 	}
       
  1597 
       
  1598 
       
  1599 /*
       
  1600  * Export Macro
       
  1601  * plugin name : LastFmMusicServicePlugin
       
  1602  * plugin class : LastFmMusicServicePlugin
       
  1603  */
       
  1604 Q_EXPORT_PLUGIN2( lastfmmusicserviceplugin, LastFmMusicServicePlugin )