37 FlickrContactFetcherPlugin::~FlickrContactFetcherPlugin( ) |
39 FlickrContactFetcherPlugin::~FlickrContactFetcherPlugin( ) |
38 { |
40 { |
39 if(m_provider) |
41 if(m_provider) |
40 delete m_provider; |
42 delete m_provider; |
41 } |
43 } |
|
44 |
|
45 /** |
|
46 * Method to interpret the key sets obtained from credential manager |
|
47 * @param aApiKey [out] The api key |
|
48 * @param aApiSecret [out] The api secret |
|
49 * @param aAuthToken [out] The auth token provided by Flickr |
|
50 */ |
|
51 void FlickrContactFetcherPlugin::fetchKeys( QString &aApiKey, |
|
52 QString &aApiSecret, |
|
53 QString &aAuthToken ) |
|
54 { |
|
55 qDebug()<<"Inside FlickrContactFetcherPlugin::fetchKeys()"; |
|
56 |
|
57 qDebug()<<"Reg Token = "<<m_provider->m_smfRegToken; |
|
58 qDebug()<<"Expiry Date as int = "<<m_provider->m_validity.toTime_t(); |
|
59 |
|
60 SmfAuthParams keys; |
|
61 SmfPluginUtil util; |
|
62 util.getAuthKeys(keys, m_provider->m_smfRegToken, |
|
63 m_provider->m_validity, m_provider->m_pluginId); |
|
64 |
|
65 qDebug()<<"Number of key-value pairs = "<<keys.count(); |
|
66 |
|
67 QByteArray keyName; |
|
68 keyName.append("ApiKey"); |
|
69 aApiKey.append(keys.value(keyName)); |
|
70 |
|
71 keyName.clear(); |
|
72 keyName.append("ApiSecret"); |
|
73 aApiSecret.append(keys.value(keyName)); |
|
74 |
|
75 keyName.clear(); |
|
76 keyName.append("AuthToken"); |
|
77 aAuthToken.append(keys.value(keyName)); |
|
78 |
|
79 qDebug()<<"Api Key = "<<aApiKey; |
|
80 qDebug()<<"Api Secret = "<<aApiSecret; |
|
81 qDebug()<<"Auth Token = "<<aAuthToken; |
|
82 } |
|
83 |
42 |
84 |
43 /** |
85 /** |
44 * Method to get the list of friends |
86 * Method to get the list of friends |
45 * @param aRequest [out] The request data to be sent to network |
87 * @param aRequest [out] The request data to be sent to network |
46 * @param aPageNum The page to be extracted |
88 * @param aPageNum The page to be extracted |
62 return error; |
104 return error; |
63 } |
105 } |
64 |
106 |
65 qDebug()<<"Valid arguments"; |
107 qDebug()<<"Valid arguments"; |
66 |
108 |
67 #if 1 |
109 // Get the key sets from SMF Plugin Utility class. |
68 // Reading the keys, CSM Stubbed - START |
110 QString apiKey; |
69 QFile file("c:\\data\\FlickrKeys.txt"); |
111 QString apiSecret; |
70 if (!file.open(QIODevice::ReadOnly)) |
112 QString authToken; |
71 { |
113 fetchKeys(apiKey, apiSecret, authToken ); |
72 qDebug()<<"File to read the keys could not be opened"; |
|
73 return SmfPluginErrUserNotLoggedIn; |
|
74 } |
|
75 |
|
76 qDebug()<<"Key file read, going to parse the key values from file"; |
|
77 |
|
78 QByteArray arr = file.readAll(); |
|
79 QList<QByteArray> list = arr.split('\n'); |
|
80 file.close(); |
|
81 |
|
82 QString apiKey(list[0]); |
|
83 QString apiSecret(list[1]); |
|
84 QString authToken(list[2]); |
|
85 |
|
86 qDebug()<<"Api Key = "<<apiKey; |
|
87 qDebug()<<"Api Secret = "<<apiSecret; |
|
88 qDebug()<<"Auth Token = "<<authToken; |
|
89 // Reading the keys, CSM Stubbed - END |
|
90 #endif |
|
91 |
114 |
92 // Create the API signature string |
115 // Create the API signature string |
93 QString baseString; |
116 QString baseString; |
94 baseString.append(apiSecret); |
117 baseString.append(apiSecret); |
95 baseString.append("api_key"+apiKey); |
118 baseString.append("api_key"+apiKey); |
272 } |
295 } |
273 |
296 |
274 /** |
297 /** |
275 * The first method to be called in the plugin that implements this interface. |
298 * The first method to be called in the plugin that implements this interface. |
276 * If this method is not called, plugin may not behave as expected. |
299 * If this method is not called, plugin may not behave as expected. |
277 * Plugins are expected to save the aUtil handle and use and when required. |
300 */ |
278 * @param aUtil The instance of SmfPluginUtil |
301 void FlickrContactFetcherPlugin::initialize( ) |
279 */ |
302 { |
280 void FlickrContactFetcherPlugin::initialize( SmfPluginUtil *aUtil ) |
|
281 { |
|
282 // Save the SmfPluginUtil handle |
|
283 m_util = aUtil; |
|
284 |
|
285 // Create an instance of FlickrProviderBase |
303 // Create an instance of FlickrProviderBase |
286 m_provider = new FlickrProviderBase; |
304 m_provider = new FlickrProviderBase; |
287 m_provider->initialize(); |
305 m_provider->initialize(); |
288 } |
306 } |
289 |
307 |
333 return error; |
351 return error; |
334 } |
352 } |
335 |
353 |
336 QByteArray response(*aResponse); |
354 QByteArray response(*aResponse); |
337 delete aResponse; |
355 delete aResponse; |
338 qDebug()<<"FB response = "<<QString(response); |
356 |
|
357 QFile respFile("c://data//SmfPluginFlickrContactResponse.txt"); |
|
358 if(!respFile.open(QIODevice::WriteOnly)) |
|
359 { |
|
360 qDebug()<<"File to write the response could not be opened, so writing to this file"; |
|
361 qDebug()<<"Flickr response = "<<QString(response); |
|
362 } |
|
363 else |
|
364 { |
|
365 respFile.write(response); |
|
366 respFile.close(); |
|
367 qDebug()<<"Writing FB response to a file named 'SmfPluginFlickrContactResponse.txt'"; |
|
368 } |
339 qDebug()<<"FB response size = "<<response.size(); |
369 qDebug()<<"FB response size = "<<response.size(); |
340 |
370 |
341 if(SmfTransportOpNoError == aTransportResult) |
371 if(SmfTransportOpNoError == aTransportResult) |
342 { |
372 { |
343 qDebug()<<"No transport error"; |
373 qDebug()<<"No transport error"; |
379 response.remove(0, 14); |
409 response.remove(0, 14); |
380 response.chop(1); |
410 response.chop(1); |
381 |
411 |
382 // For getting contacts from json response |
412 // For getting contacts from json response |
383 bool ok; |
413 bool ok; |
384 QVariantMap result = m_util->parse(response, &ok).toMap(); |
414 SmfPluginUtil util; |
|
415 QVariantMap result = util.parse(response, &ok).toMap(); |
385 if (!ok) { |
416 if (!ok) { |
386 qDebug()<<"An error occurred during json parsing"; |
417 qDebug()<<"An error occurred during json parsing"; |
387 aResult->setValue(list); |
418 aResult->setValue(list); |
388 aRetType = SmfRequestError; |
419 aRetType = SmfRequestError; |
389 return SmfPluginErrParsingFailed; |
420 return SmfPluginErrParsingFailed; |
412 qDebug()<<"friend = "<<map2["friend"].toString(); |
443 qDebug()<<"friend = "<<map2["friend"].toString(); |
413 qDebug()<<"family = "<<map2["family"].toString(); |
444 qDebug()<<"family = "<<map2["family"].toString(); |
414 qDebug()<<"path_alias = "<<map2["path_alias"].toString(); |
445 qDebug()<<"path_alias = "<<map2["path_alias"].toString(); |
415 qDebug()<<"location = "<<map2["location"].toString(); |
446 qDebug()<<"location = "<<map2["location"].toString(); |
416 |
447 |
|
448 // Contact Name |
417 QContactName contactname; |
449 QContactName contactname; |
418 QString username = map2["username"].toString(); |
450 QString username = map2["username"].toString(); |
419 qDebug()<<"Username = "<<username; |
451 qDebug()<<"Username = "<<username; |
420 contactname.setFirstName(username); |
452 contactname.setFirstName(username); |
421 contactname.setLastName(username); |
453 contactname.setLastName(username); |
422 QVariant nameVar = QVariant::fromValue(contactname); |
454 QVariant nameVar = QVariant::fromValue(contactname); |
423 contact.setValue("Name",nameVar); |
455 contact.setValue("Name",nameVar); |
|
456 |
|
457 // Contact's Flickr Specific ID to QContactGuid |
|
458 QContactGuid guid; |
|
459 guid.setGuid(map2["nsid"].toString()); |
|
460 QVariant guidVar = QVariant::fromValue(guid); |
|
461 contact.setValue("Guid",guidVar); |
|
462 |
|
463 // Contact's profile image url |
|
464 QUrl url; |
|
465 if((0 == map2["iconfarm"].toInt()) && (0 == map2["iconserver"].toInt())) |
|
466 url = QString("http://www.flickr.com/images/buddyicon.jpg"); |
|
467 else |
|
468 { |
|
469 QString str("http://farm"); |
|
470 str.append(map2["iconfarm"].toString()); |
|
471 str.append(".static.flickr.com/"); |
|
472 str.append(map2["iconserver"].toString()); |
|
473 str.append("/buddyicons/"); |
|
474 str.append(map2["nsid"].toString()); |
|
475 str.append(".jpg"); |
|
476 url = str; |
|
477 } |
|
478 QContactAvatar avatar; |
|
479 qDebug()<<"Profile image URL = "<<url.toString(); |
|
480 avatar.setImageUrl(url); |
|
481 QVariant avatarVar = QVariant::fromValue(avatar); |
|
482 contact.setValue("Avatar",avatarVar); |
|
483 |
|
484 |
424 list.append(contact); |
485 list.append(contact); |
425 } |
486 } |
426 #endif |
487 #endif |
427 |
488 |
428 qDebug()<<"list count = "<<list.count(); |
489 qDebug()<<"list count = "<<list.count(); |
578 { |
639 { |
579 m_serviceName = "Flickr"; |
640 m_serviceName = "Flickr"; |
580 m_description = "Flickr contact fetcher plugin description"; |
641 m_description = "Flickr contact fetcher plugin description"; |
581 m_serviceUrl = QUrl(QString("http://api.flickr.com")); |
642 m_serviceUrl = QUrl(QString("http://api.flickr.com")); |
582 m_pluginId = "flickrcontactfetcherplugin.qtplugin"; |
643 m_pluginId = "flickrcontactfetcherplugin.qtplugin"; |
583 m_authAppId = "Flickr AuthAppId"; |
644 m_authAppId = "0xE1D8C7D7"; |
584 m_smfRegToken = "Flickr RegToken"; |
|
585 m_supportedInterfaces.append("org.symbian.smf.plugin.contact.fetcher/v0.2"); |
645 m_supportedInterfaces.append("org.symbian.smf.plugin.contact.fetcher/v0.2"); |
|
646 QSettings iSettings; |
|
647 m_smfRegToken = iSettings.value("CMFlickrRegToken").toString(); |
|
648 m_validity = iSettings.value("FlckrExpiryTime").toDateTime(); |
586 } |
649 } |
587 |
650 |
588 |
651 |
589 /* |
652 /* |
590 * Export Macro |
653 * Export Macro |