example/clientapi/example_usage.cpp
changeset 5 edb9dc8273d9
parent 3 0446eb7b28aa
equal deleted inserted replaced
4:969092730d34 5:edb9dc8273d9
     8 #include "smfmusic.h"
     8 #include "smfmusic.h"
     9 #include "smfpicture.h"
     9 #include "smfpicture.h"
    10 #include "smftrackinfo.h"
    10 #include "smftrackinfo.h"
    11 #include "smfmusicprofile.h"
    11 #include "smfmusicprofile.h"
    12 #include "smflyrics.h"
    12 #include "smflyrics.h"
       
    13 #include "smfactions.h"
       
    14 #include "smfactivityfetcher.h"
    13 #include <qalgorithms.h>
    15 #include <qalgorithms.h>
    14 #include "qtcontacts.h"
    16 #include "qtcontacts.h"
    15 #include <qdatastream.h>
    17 #include <qdatastream.h>
    16 #include <QSharedData>
    18 #include <QSharedData>
    17 #include <smfclientglobal.h>
    19 #include <smfclientglobal.h>
    53 	void showStore(SmfProviderList* stores);
    55 	void showStore(SmfProviderList* stores);
    54 	void updateCurrentPlaying(QList<SmfMusicSearch> musicServices, SmfTrackInfo currTrack);
    56 	void updateCurrentPlaying(QList<SmfMusicSearch> musicServices, SmfTrackInfo currTrack);
    55 	void displayLyrics(SmfTrackInfo currTrack);
    57 	void displayLyrics(SmfTrackInfo currTrack);
    56 	void showLyrics(SmfLyricsList* list);
    58 	void showLyrics(SmfLyricsList* list);
    57 
    59 
       
    60 	void getActivities();
       
    61 	void showActivities(SmfActivityEntryList* entries);
    58 private:
    62 private:
    59 	MyAppView* m_view;
    63 	MyAppView* m_view;
    60 	SmfClient client;
    64 	SmfClient client;
    61 	SmfGallery* m_smfgl;
    65 	SmfGallery* m_smfgl;
    62 	SmfContactFetcher* m_smfcf;
    66 	SmfContactFetcher* m_smfcf;
    66 /** 1. Display a gallery on the screen for some remote service.
    70 /** 1. Display a gallery on the screen for some remote service.
    67  * assume m_view is some gallery view object in the application.*/
    71  * assume m_view is some gallery view object in the application.*/
    68 void MyApplication::displayGallery()
    72 void MyApplication::displayGallery()
    69 	{
    73 	{
    70 	// Some common interface for finding implementations.
    74 	// Some common interface for finding implementations.
    71 	QList<SmfProvider>* galleries = client.GetServices("org.symbian.smf.gallery\0.2");
    75 	QList<SmfProvider>* galleries = client.GetServices("org.symbian.smf.client.gallery\0.2");
    72 
    76 
    73 	// We will use the first one now
    77 	// We will use the first one now
    74 	SmfProvider smfp = galleries->value(0);
    78 	SmfProvider smfp = galleries->value(0);
    75 	SmfGallery* myGallery = new SmfGallery(&smfp);
    79 	SmfGallery* myGallery = new SmfGallery(&smfp);
    76 
    80 
   137  * e.g. last.fm music service where users maintain profiles and friends.
   141  * e.g. last.fm music service where users maintain profiles and friends.
   138  */
   142  */
   139 void MyApplication::displayFriends()
   143 void MyApplication::displayFriends()
   140 	{
   144 	{
   141 	// Some common interface for finding implementations.
   145 	// Some common interface for finding implementations.
   142 	QList<SmfProvider>* contactFetcherList = client.GetServices("org.symbian.smf.contact.fetcher\0.2");
   146 	QList<SmfProvider>* contactFetcherList = client.GetServices("org.symbian.smf.cleint.contact.fetcher\0.2");
   143 	SmfProvider smfp = contactFetcherList->value(0);
   147 	SmfProvider smfp = contactFetcherList->value(0);
   144 	SmfContactFetcher* smfcf = new SmfContactFetcher(&smfp);
   148 	SmfContactFetcher* smfcf = new SmfContactFetcher(&smfp);
   145 	
   149 	
   146 	//Request friend list, the friendsListAvailable() signal
   150 	//Request friend list, the friendsListAvailable() signal
   147 	//is emitted with SmfContactList once data is arrived.
   151 	//is emitted with SmfContactList once data is arrived.
   174  * 4. This is an example of posting and reading user updates to social netowrking sites
   178  * 4. This is an example of posting and reading user updates to social netowrking sites
   175  */
   179  */
   176 void MyApplication::postUpdate()
   180 void MyApplication::postUpdate()
   177 	{
   181 	{
   178 	// Some common interface for finding implementations.
   182 	// Some common interface for finding implementations.
   179 	QList<SmfProvider>* postServices = client.GetServices("org.symbian.smf.contact.posts\0.2");
   183 	QList<SmfProvider>* postServices = client.GetServices("org.symbian.smf.client.contact.posts\0.2");
   180 
   184 
   181 	//let us use the first one
   185 	//let us use the first one
   182 	QString servName = postServices->value(0).serviceName();
   186 	QString servName = postServices->value(0).serviceName();
   183 	if(!servName.compare("Facebook.com")) return;
   187 	if(!servName.compare("Facebook.com")) return;
   184 	SmfProvider smfp = postServices->value(0);
   188 	SmfProvider smfp = postServices->value(0);
   214  * 5. This is an example of getting song recommendations from a social netowrking sites
   218  * 5. This is an example of getting song recommendations from a social netowrking sites
   215  */
   219  */
   216 void MyApplication::getMusic(SmfTrackInfo currTrack)
   220 void MyApplication::getMusic(SmfTrackInfo currTrack)
   217 	{
   221 	{
   218 	// Some common interface for finding implementations.
   222 	// Some common interface for finding implementations.
   219 	QList<SmfProvider>* smfProList = client.GetServices("org.symbian.smf.music\0.2");
   223 	QList<SmfProvider>* smfProList = client.GetServices("org.symbian.smf.client.music\0.2");
   220 	SmfProvider smfp = smfProList->value(0);
   224 	SmfProvider smfp = smfProList->value(0);
   221 	SmfMusicSearch* mServer = new SmfMusicSearch(&smfp);
   225 	SmfMusicSearch* mServer = new SmfMusicSearch(&smfp);
   222 
   226 
   223 	QObject::connect(mServer,SIGNAL(trackSearchAvailable(SmfTrackInfoList*, QString,SmfResultPage )),this,SLOT(showTrackSearch(SmfTrackInfoList*)));
   227 	QObject::connect(mServer,SIGNAL(trackSearchAvailable(SmfTrackInfoList*, QString,SmfResultPage )),this,SLOT(showTrackSearch(SmfTrackInfoList*)));
   224 	QObject::connect(mServer,SIGNAL(storeSearchAvailable(SmfProviderList*, QString,SmfResultPage )),this,SLOT(showStoreSearch(SmfProviderList*)));
   228 	QObject::connect(mServer,SIGNAL(storeSearchAvailable(SmfProviderList*, QString,SmfResultPage )),this,SLOT(showStoreSearch(SmfProviderList*)));
   262 
   266 
   263 void MyApplication::displayLyrics(SmfTrackInfo currTrack)
   267 void MyApplication::displayLyrics(SmfTrackInfo currTrack)
   264 	{
   268 	{
   265 
   269 
   266 	// Some common interface for finding implementations.
   270 	// Some common interface for finding implementations.
   267 	QList<SmfProvider>* smfProList = client.GetServices("org.symbian.smf.music.lyrics\0.2","lyricsfly.com");
   271 	QList<SmfProvider>* smfProList = client.GetServices("org.symbian.smf.client.music.lyrics\0.2","lyricsfly.com");
   268 	SmfProvider smfp = smfProList->value(0);
   272 	SmfProvider smfp = smfProList->value(0);
   269 	SmfLyricsService* lyricsService = new SmfLyricsService(&smfp);
   273 	SmfLyricsService* lyricsService = new SmfLyricsService(&smfp);
   270 	QObject::connect(lyricsService,SIGNAL(lyricsAvailable(SmfLyricsList*, QString, SmfResultPage )),this,SLOT(showLyrics(SmfLyricsList*)));
   274 	QObject::connect(lyricsService,SIGNAL(lyricsAvailable(SmfLyricsList*, QString, SmfResultPage )),this,SLOT(showLyrics(SmfLyricsList*)));
   271 
   275 
   272 	//Request to get the lyrics
   276 	//Request to get the lyrics
   278 	{
   282 	{
   279 	//now display the latest edited lyrics
   283 	//now display the latest edited lyrics
   280 	//qSort(list->begin(),list->end(),caseInsensitiveLessThan);
   284 	//qSort(list->begin(),list->end(),caseInsensitiveLessThan);
   281 	m_view->setLyricsData(list->at(0));
   285 	m_view->setLyricsData(list->at(0));
   282 	}
   286 	}
       
   287 
       
   288 void MyApplication::getActivities()
       
   289 	{
       
   290 	// Some common interface for finding implementations.
       
   291 	QList<SmfProvider>* activityServices = client.GetServices("org.symbian.smf.client.activity.fetcher\0.2");
       
   292 
       
   293 	//let us use the Facebook one
       
   294 	QString servName = activityServices->value(0).serviceName();
       
   295 	if(!servName.compare("Facebook.com")) return;
       
   296 	SmfProvider smfp = activityServices->value(0);
       
   297 	SmfActivityFetcher* myActivityServer = new SmfActivityFetcher(&smfp);
       
   298 
       
   299 	//Adjust our view to show where these posts came from (e.g. streams from Facebook)
       
   300 	//display service name description and the logo
       
   301 	m_view->setIcon((myActivityServer->getProvider())->serviceIcon() );
       
   302 	m_view->setProvider(myActivityServer->getProvider());
       
   303 	m_view->setDescription((myActivityServer->getProvider())->description() );
       
   304 	
       
   305 	QObject::connect(myActivityServer,
       
   306 			SIGNAL(resultsAvailable(SmfActivityEntryList*,QString,SmfResultPage)),
       
   307 			this,SLOT(showActivities(SmfActivityEntryList*)));	
       
   308 
       
   309 	//get a list of updates to my wall
       
   310 	myActivityServer->selfActivities();
       
   311 	}
       
   312 
       
   313 void MyApplication::showActivities(SmfActivityEntryList* entries)
       
   314 	{
       
   315 	foreach(SmfActivityEntry entry, *entries) {
       
   316 		SmfContact sc = entry.author();
       
   317 		QString desc = (sc.value("Name")).toString();
       
   318 		SmfPost details = entry.details();
       
   319 		QList<SmfActivityObject> aol = entry.activities();
       
   320 		SmfActivityObject sao = aol.value(0);
       
   321 		if(SmfActivityMarkAsFavorite == entry.actionName() )
       
   322 			{
       
   323 			desc.append("  has marked  ");
       
   324 			QVariant qv = sao.objData();
       
   325 			SmfActivityObjectType otype = sao.type();
       
   326 			if((SmfActivityObjTypePhoto == otype ) && (qv.canConvert<SmfPicture>()))
       
   327 				{
       
   328 				SmfPicture pic = qv.value<SmfPicture>();
       
   329 				desc.append( pic.description() );
       
   330 				}
       
   331 			desc.append("  as Favorite at");
       
   332 			QDateTime qdt = sao.time();
       
   333 			desc.append(qdt.toString("h:m:s ap"));
       
   334 			}
       
   335 	}
       
   336 	}