example/clientapi/example_usage.cpp
changeset 2 86af6c333601
parent 1 4b1e636e8a71
child 3 0446eb7b28aa
equal deleted inserted replaced
1:4b1e636e8a71 2:86af6c333601
     1 #include <smf/smfprovider.h>
     1 #include "smfglobal.h"
     2 #include <smf/smfgallery.h>
     2 #include "smfclient.h"
     3 #include <smf/smfcontact.h>
     3 #include "smfprovider.h"
     4 #include <smf/smfpostprovider.h>
     4 #include "smfgallery.h"
     5 #include <smf/smffcontactfetcher.h>
     5 #include "smfcontact.h"
     6 #include <smf/smfmusic.h>
     6 #include "smfpostprovider.h"
     7 
     7 #include "smfcontactfetcher.h"
       
     8 #include "smfmusic.h"
       
     9 #include "smfpicture.h"
       
    10 #include "smftrackinfo.h"
       
    11 #include "smfmusicprofile.h"
       
    12 #include "smflyrics.h"
       
    13 #include <qalgorithms.h>
       
    14 #include "qtcontacts.h"
       
    15 #include <qdatastream.h>
       
    16 #include <QSharedData>
       
    17 #include <smfclientglobal.h>
       
    18 
       
    19 using namespace QtMobility;
       
    20 
       
    21 class MyAppView //: public QAbstractItemView
       
    22 	{
       
    23 public:
       
    24 	void add(QImage pic);
       
    25 	void add(SmfTrackInfo trackInfo);
       
    26 	void add(QContact qc);
       
    27 	void setPicture(QImage image);
       
    28 	void setTitle(QString cap);	
       
    29 	void setIcon(QImage image);
       
    30 	void setDescription(QString desc);
       
    31 	void setProvider(SmfProvider p);
       
    32 	void setLyricsData(SmfLyrics l);
       
    33 	};
       
    34 
       
    35 
       
    36 class MyApplication :public QObject
       
    37 	{
       
    38 	Q_OBJECT
       
    39 	
       
    40 public slots:
       
    41 	void displayGallery();
       
    42 	void showPicsSlot(SmfPictureList* pics, QString err);
       
    43 	void uploadPicture(QImage* picture, QList<SmfGallery> galleries);
       
    44 	void uploaded(bool success);
       
    45 
       
    46 	void displayFriends();
       
    47 	void showlist(SmfContactList* friendsList);
       
    48 	void postUpdate();
       
    49 	void showPosts(SmfPostList* posts, QString err);
       
    50 
       
    51 	void getMusic(SmfTrackInfo currTrack);
       
    52 	void showTrackSearch(SmfTrackInfoList* songs);
       
    53 	void showStore(SmfProviderList* stores);
       
    54 	void updateCurrentPlaying(QList<SmfMusicSearch> musicServices, SmfTrackInfo currTrack);
       
    55 	void displayLyrics(SmfTrackInfo currTrack);
       
    56 	void showLyrics(SmfLyricsList* list);
       
    57 
       
    58 private:
       
    59 	MyAppView* m_view;
       
    60 	SmfGallery* m_smfgl;
       
    61 	SmfContactFetcher* m_smfcf;
       
    62 	SmfMusicService* m_smfms;
       
    63 	QList<SmfContact> m_myfrndz;
       
    64 	};
     8 /** 1. Display a gallery on the screen for some remote service.
    65 /** 1. Display a gallery on the screen for some remote service.
     9  * assume m_view is some gallery view object in the application.*/
    66  * assume m_view is some gallery view object in the application.*/
    10 void MyApplication::displayGallery()
    67 void MyApplication::displayGallery()
    11 	{
    68 	{
    12 	// Some common interface for finding implementations.
    69 	// Some common interface for finding implementations.
    13 	QList<SmfGallery> galleries = Smf::GetServices("org.symbian.smf.gallery\0.2");
    70 	QList<SmfProvider>* galleries = SmfClient::GetServices("org.symbian.smf.gallery\0.2");
    14 
    71 
    15 	// We will use the first one now
    72 	// We will use the first one now
    16 	SmfGallery myGallery = galleries[0];
    73 	SmfProvider smfp = galleries->value(0);
       
    74 	SmfGallery* myGallery = new SmfGallery(&smfp);
    17 
    75 
    18 	// Adjust our view to show where these pictures came from
    76 	// Adjust our view to show where these pictures came from
    19 	m_view.setIcon(myGallery.serviceIcon());
    77 	QImage imge = smfp.serviceIcon();
    20 	m_view.setProvder(myGallery.serviceName());
    78 	QString desc = smfp.description();
    21 	m_view.setDescription(myGallery.description());
    79 	QString name = smfp.serviceName();
       
    80 	m_view->setIcon(imge);
       
    81 	m_view->setProvider(smfp);
       
    82 	m_view->setDescription(desc);
    22 
    83 
    23 	/**
    84 	/**
    24 	 * Asynchrnous request to fetch the pictures.
    85 	 * Asynchrnous request to fetch the pictures.
    25 	 * The picturesAvailable() signal is emitted 
    86 	 * The picturesAvailable() signal is emitted 
    26 	 * with SmfPictureList once the pictures have arrived.
    87 	 * with SmfPictureList once the pictures have arrived.
    27 	 */
    88 	 */
    28 	myGallery.pictures();
    89 	myGallery->pictures();
    29 	QObject::connect(myGallery,SIGNAL(picturesAvailable(SmfPictureList*, QString, int)),this,SLOT(showPicsSlot(SmfPictureList*, QString)));
    90 	connect(myGallery,SIGNAL(picturesAvailable(SmfPictureList*, QString, SmfResultPage )),
    30 	}
    91 			SLOT(showPicsSlot(SmfPictureList*, QString)));
    31 }
    92 	
       
    93 	m_smfgl = myGallery;
       
    94 	}
       
    95 
    32 void MyApplication::showPicsSlot(SmfPictureList* pics, QString err)
    96 void MyApplication::showPicsSlot(SmfPictureList* pics, QString err)
    33 	{
    97 	{
    34 	//check err string if there is any error
    98 	//check err string if there is any error
    35 
    99 	if(err.compare("Err")) return;
    36 	//if no error
   100 	//if no error
    37 	foreach(SmfPicture* pic, pics) {
   101 	foreach(SmfPicture pic, *pics) {
    38 		m_view.add(pic); // do something with the picture in this gallery
   102 		m_view->add(pic.picture() ); // do something with the picture in this gallery
    39 	}
   103 	}
    40 	}
   104 	}
    41 
   105 
    42 /** 2. Upload a picture captured by the user to some selection of galeries.*/
   106 /** 2. Upload a picture captured by the user to some selection of galeries.*/
    43 void MyApplication::uploadPicture(QImage picture, QList<SmfGallery> galleries)
   107 void MyApplication::uploadPicture(QImage* picture, QList<SmfGallery> galleries)
    44 	{
   108 	{
    45 	/**
   109 	/**
    46 	 * When uploading is finished we can check the success of the uploading
   110 	 * When uploading is finished we can check the success of the uploading
    47 	 */	
   111 	 */	
    48 	QObject::connect(myGallery,SIGNAL(uploadFinished(bool)),this,SLOT(uploaded(bool)));
   112 	QObject::connect(m_smfcf,SIGNAL(uploadFinished(bool)),SLOT(uploaded(bool)));
       
   113 	SmfPicture*  smfPic = new SmfPicture(*picture);
    49 	// The list could be from a selection of galleries chosen by the user,
   114 	// The list could be from a selection of galleries chosen by the user,
    50 	// think multiple TweetDeck accounts?
   115 	// think multiple TweetDeck accounts?
    51 	foreach(SmfGallery gallery, galleries) {
   116 	foreach(SmfGallery gallery, galleries)
    52 		gallery.upload(picture);
   117 		{
    53 	}
   118 		gallery.upload(smfPic);
    54 	}
   119 		}
       
   120 	}
       
   121 
       
   122 /**
       
   123  * Slot to catch the uploading finished event
       
   124  */
    55 void MyApplication::uploaded(bool success)
   125 void MyApplication::uploaded(bool success)
    56 	{
   126 	{
    57 	if(!success)
   127 	if(!success)
    58 		{
   128 		{
    59 	//error occured while uploading
   129 	//error occured while uploading
    66  * e.g. last.fm music service where users maintain profiles and friends.
   136  * e.g. last.fm music service where users maintain profiles and friends.
    67  */
   137  */
    68 void MyApplication::displayFriends()
   138 void MyApplication::displayFriends()
    69 	{
   139 	{
    70 	// Some common interface for finding implementations.
   140 	// Some common interface for finding implementations.
    71 	QList<SmfContactFetcher> contactFetcherList = Smf::GetServices("org.symbian.smf.contact.fetcher\0.2");
   141 	QList<SmfProvider>* contactFetcherList = SmfClient::GetServices("org.symbian.smf.contact.fetcher\0.2");
    72 	//Request friend list,
   142 	SmfProvider smfp = contactFetcherList->value(0);
    73 	//The friendsListAvailable() signal
   143 	SmfContactFetcher* smfcf = new SmfContactFetcher(&smfp);
       
   144 	
       
   145 	//Request friend list, the friendsListAvailable() signal
    74 	//is emitted with SmfContactList once data is arrived.
   146 	//is emitted with SmfContactList once data is arrived.
    75 	QObject::Connect(contactFetcherList[0],SIGNAL(friendsListAvailable(SmfContactList*, QString, int)),
   147 	QObject::connect(smfcf,SIGNAL(friendsListAvailable(SmfContactList*, QString, SmfResultPage )),
    76 			this,SLOT(showlist(SmfContactList*));
   148 			SLOT(showlist(SmfContactList*)));
    77 	fetcher.friends();
   149 	smfcf->friends();
       
   150 	
       
   151 	m_smfcf = smfcf;
    78 	}
   152 	}
    79 
   153 
    80 void MyApplication::showlist(SmfContactList* friendsList)
   154 void MyApplication::showlist(SmfContactList* friendsList)
    81 	{
   155 	{
    82 
   156 
    83 	// Adjust our view to show where these pictures came from
   157 	// Adjust our view to show where these pictures came from
    84 	//display service name description and the logo
   158 	//display service name description and the logo
    85 	m_view.setIcon( myFetcher.serviceIcon() );
   159 	m_view->setIcon( (m_smfcf->getProvider())->serviceIcon() );
    86 	m_view.setProvider( myFetcher.serviceName() );
   160 	m_view->setDescription( (m_smfcf->getProvider())->description() );
    87 	m_view.setDescription( myFetcher.description() );
       
    88 
   161 
    89 	//now display the images
   162 	//now display the images
    90 	foreach(SmfContact* contact, friendsList) {
   163 	foreach(SmfContact contact, *friendsList) {
    91 		QImage pic = contact.value("Avatar");
   164 		QVariant data = contact.value("Avatar"); 
    92 		m_view.setPicture(pic);
   165 		QImage pic = data.value<QImage>();
    93 		m_view.setTitle(contact.value("Name"));
   166 		QContact qc;
       
   167 		contact.convert(qc);
       
   168 		m_view->add(qc);
       
   169 		m_myfrndz.append(contact);
    94 	}
   170 	}
    95 	}
   171 	}
    96 /**
   172 /**
    97  * 4. This is an example of posting and reading user updates to social netowrking sites
   173  * 4. This is an example of posting and reading user updates to social netowrking sites
    98  */
   174  */
    99 void MyApplication::postUpdate()
   175 void MyApplication::postUpdate()
   100 	{
   176 	{
   101 	// Some common interface for finding implementations.
   177 	// Some common interface for finding implementations.
   102 	QList<SmfPostProvider> postServices = Smf::GetServices("org.symbian.smf.contact.posts\0.2");
   178 	QList<SmfProvider>* postServices = SmfClient::GetServices("org.symbian.smf.contact.posts\0.2");
   103 
   179 
   104 	//let us use the first one
   180 	//let us use the first one
   105 	SmfPostProvider myPostServer = postServices[ 0 ];
   181 	QString servName = postServices->value(0).serviceName();
       
   182 	if(!servName.compare("Facebook.com")) return;
       
   183 	SmfProvider smfp = postServices->value(0);
       
   184 	SmfPostProvider* myPostServer = new SmfPostProvider(&smfp);
   106 
   185 
   107 	//Adjust our view to show where these posts came from (e.g. tweets from twitter)
   186 	//Adjust our view to show where these posts came from (e.g. tweets from twitter)
   108 	//display service name description and the logo
   187 	//display service name description and the logo
   109 	m_view.setIcon( myPostServer.serviceIcon() );
   188 	m_view->setIcon((myPostServer->getProvider())->serviceIcon() );
   110 	m_view.setProvider( myPostServer.serviceName() );
   189 	m_view->setProvider(myPostServer->getProvider());
   111 	m_view.setDescription( myPostServer.description() );
   190 	m_view->setDescription((myPostServer->getProvider())->description() );
   112 
   191 
   113 	SmfPost reply = new SmfPost(sampleString,samplmage, sampleUrl);
   192 	SmfPost reply("this is a text post", this);
   114 	//post my udpate to be visible to all, connect to updatePostFinished()
   193 	//post my udpate to be visible to all, connect to updatePostFinished()
   115 	// signal of SmfPostProvider to track the success
   194 	// signal of SmfPostProvider to track the success
   116 	myPostServer.updatePost(reply);
   195 	SmfContact frnd(m_myfrndz.value(0));
       
   196 	myPostServer->postDirected(reply,frnd);
   117 
   197 
   118 	//Asynchronously get all posts to me in my profle (e.g. twits from all friends)
   198 	//Asynchronously get all posts to me in my profle (e.g. twits from all friends)
   119 	//connect to postsAvailable to show the post
   199 	//connect to postsAvailable to show the post
   120 	postServices.getPosts();
   200 	myPostServer->posts();
   121 
   201 
   122 	QObject::Connect(myPostServer,SIGNAL(postsAvailable(SmfPostList*, QString, int)),this,SLOT(showPosts(SmfPostList*, QString)));
   202 	QObject::connect(myPostServer,
   123 	}
   203 			SIGNAL(postsAvailable(SmfPostList*, QString, SmfResultPage )),
   124 void MyApplication::showPosts(SmfPostList* posts, QString err)
   204 			SLOT(showPosts(SmfPostList*, QString)));
       
   205 	}
       
   206 void MyApplication::showPosts(SmfPostList* posts, QString /*err*/)
   125 	{
   207 	{
   126 	//Show the first post  
   208 	//Show the first post  
   127 	m_view.setPostData(posts->at(0));
   209 	SmfPost post = posts->at(0);
       
   210 	m_view->setDescription( post.toPlainText() );
   128 	}
   211 	}
   129 /**
   212 /**
   130  * 5. This is an example of getting song recommendations from a social netowrking sites
   213  * 5. This is an example of getting song recommendations from a social netowrking sites
   131  */
   214  */
   132 void MyApplication::getMusic()
   215 void MyApplication::getMusic(SmfTrackInfo currTrack)
   133 	{
   216 	{
   134 	// Some common interface for finding implementations.
   217 	// Some common interface for finding implementations.
   135 	QList<SmfMusicSearch> musicServices = Smf::GetServices("org.symbian.smf.music\0.2");
   218 	QList<SmfProvider>* smfProList = SmfClient::GetServices("org.symbian.smf.music\0.2");
   136 
   219 	SmfProvider smfp = smfProList->value(0);
   137 	//let us use the first one
   220 	SmfMusicSearch* mServer = new SmfMusicSearch(&smfp);
   138 	SmfMusicSearch mServer = musicServices.at(0);
   221 
   139 	QObject::Connect(mServer,SIGNAL(trackSearchAvailable(SmfTrackInfoList*, QString,int)),this,SLOT(showTrackSearch(SmfTrackInfoList*)));
   222 	QObject::connect(mServer,SIGNAL(trackSearchAvailable(SmfTrackInfoList*, QString,SmfResultPage )),this,SLOT(showTrackSearch(SmfTrackInfoList*)));
   140 	QObject::Connect(mServer,SIGNAL(storeSearchAvailable(SmfProviderList*, QString,int)),this,SLOT(showStoreSearch(SmfProviderList*)));
   223 	QObject::connect(mServer,SIGNAL(storeSearchAvailable(SmfProviderList*, QString,SmfResultPage )),this,SLOT(showStoreSearch(SmfProviderList*)));
   141 	//search songs similar to currently playing,
   224 	//search songs similar to currently playing,
   142 	//connect to trackSearchAvailable signal to get the result
   225 	//connect to trackSearchAvailable signal to get the result
   143 	mServer.recommendations(currTrack);
   226 	mServer->recommendations(currTrack);
   144 	//display to the user
   227 	//display to the user
   145 	m_view.setIcon( mServer.serviceIcon() );
   228 	m_view->setIcon( mServer->getProvider()->serviceIcon() );
   146 	m_view.setProvider( mServer.serviceName() );
   229 	m_view->setProvider( mServer->getProvider());
   147 	m_view.setDescription( mServer.description() );
   230 	m_view->setDescription( mServer->getProvider()->description() );
   148 
   231 
   149 
   232 
   150 
   233 
   151 	}
   234 	}
   152 void MyApplication::showTrackSearch(SmfTrackInfoList* songs)
   235 void MyApplication::showTrackSearch(SmfTrackInfoList* songs)
   153 	{
   236 	{
   154 	foreach(SmfTrackInfo* track, songs){
   237 	foreach(SmfTrackInfo track, *songs){
   155 		m_view.add(track);
   238 		m_view->add(track);
   156 	}
   239 	}
       
   240 	QList<SmfProvider>* smfProList = SmfClient::GetServices("org.symbian.smf.client.music.search\0.2");
       
   241 	SmfProvider smfp = smfProList->value(0);
       
   242 	SmfMusicSearch* mServer = new SmfMusicSearch(&smfp);
   157 	//allow user to select a track and get purchase links
   243 	//allow user to select a track and get purchase links
   158 	//connect to showStoreSearch signal to display the stores for that track
   244 	//connect to showStoreSearch signal to display the stores for that track
   159 	mServer.stores(selectedTrack);
   245 	mServer->stores(songs->value(0));
   160 	}
   246 	}
   161 void MyApplication::showStoreSearch(SmfProviderList* stores)
   247 void MyApplication::showStore(SmfProviderList* /*stores*/)
   162 	{
   248 	{
   163 	//show stores
   249 	//show stores
   164 	}
   250 	}
   165 void MyApplication::updateCurrentPlaying(QList<SmfMusicSearch> musicServices, SmfTrackInfo currTrack)
   251 void MyApplication::updateCurrentPlaying(QList<SmfMusicSearch> musicServices, SmfTrackInfo currTrack)
   166 	{
   252 	{
   173 	//postCurrentPlaying is also a slot funtion, may be application can use connect
   259 	//postCurrentPlaying is also a slot funtion, may be application can use connect
   174 	}
   260 	}
   175 
   261 
   176 void MyApplication::displayLyrics(SmfTrackInfo currTrack)
   262 void MyApplication::displayLyrics(SmfTrackInfo currTrack)
   177 	{
   263 	{
   178 	// Some common interface for finding implementations.
   264 
   179 	SmfLyricsService lyricsService = Smf::GetServices("org.symbian.smf.music.lyrics\0.2","lyricsfly.com");
   265 	// Some common interface for finding implementations.
   180 	QObject::connect(lyricsService,SIGNAL(lyricsAvailable(SmfLyricsList*, QString, int)),this,SLOT(showLyrics(SmfLyricsList*));
   266 	QList<SmfProvider>* smfProList = SmfClient::GetServices("org.symbian.smf.music.lyrics\0.2","lyricsfly.com");
       
   267 	SmfProvider smfp = smfProList->value(0);
       
   268 	SmfLyricsService* lyricsService = new SmfLyricsService(&smfp);
       
   269 	QObject::connect(lyricsService,SIGNAL(lyricsAvailable(SmfLyricsList*, QString, SmfResultPage )),this,SLOT(showLyrics(SmfLyricsList*)));
   181 
   270 
   182 	//Request to get the lyrics
   271 	//Request to get the lyrics
   183 	//lyricsAvailable() signal of SmfLyricsService is emitted when lyrics is available
   272 	//lyricsAvailable() signal of SmfLyricsService is emitted when lyrics is available
   184 	lyricsService.lyrics(currTrack);
   273 	lyricsService->lyrics(currTrack);
   185 
   274 
   186 	}
   275 	}
   187 void MyApplication::showLyrics(SmfLyricsList* list)
   276 void MyApplication::showLyrics(SmfLyricsList* list)
   188 	{
   277 	{
   189 	//now display the latest edited lyrics
   278 	//now display the latest edited lyrics
   190 	qSort(list->begin(),list->end(),caseCompareTimeMoreThan);
   279 	//qSort(list->begin(),list->end(),caseInsensitiveLessThan);
   191 	m_view.setLyricsData(list->at(0));
   280 	m_view->setLyricsData(list->at(0));
   192 	}
   281 	}