6 #include <smf/smfmusic.h> |
6 #include <smf/smfmusic.h> |
7 |
7 |
8 /** 1. Display a gallery on the screen for some remote service. |
8 /** 1. Display a gallery on the screen for some remote service. |
9 * assume m_view is some gallery view object in the application.*/ |
9 * assume m_view is some gallery view object in the application.*/ |
10 void MyApplication::displayGallery() |
10 void MyApplication::displayGallery() |
11 { |
11 { |
12 // Some common interface for finding implementations. |
12 // Some common interface for finding implementations. |
13 QList<SmfGallery> galleries = Smf::GetServices("org.symbian.smf.gallery"); |
13 QList<SmfGallery> galleries = Smf::GetServices("org.symbian.smf.gallery\0.2"); |
14 |
14 |
15 // We will use the first one now |
15 // We will use the first one now |
16 SmfGallery myGallery = galleries[0]; |
16 SmfGallery myGallery = galleries[0]; |
17 |
17 |
18 // Adjust our view to show where these pictures came from |
18 // Adjust our view to show where these pictures came from |
19 m_view.setIcon(myGallery.serviceIcon()); |
19 m_view.setIcon(myGallery.serviceIcon()); |
20 m_view.setProvder(myGallery.serviceName()); |
20 m_view.setProvder(myGallery.serviceName()); |
21 m_view.setDescription(myGallery.description()); |
21 m_view.setDescription(myGallery.description()); |
22 |
22 |
23 QList<SmfPicture> pics = myGallery.pictures(); |
23 /** |
24 foreach(SmfPicture pic, pics) { |
24 * Asynchrnous request to fetch the pictures. |
25 m_view.add(pic); // do something with the picture in this gallery |
25 * The picturesAvailable() signal is emitted |
26 } |
26 * with SmfPictureList once the pictures have arrived. |
|
27 */ |
|
28 myGallery.pictures(); |
|
29 QObject::connect(myGallery,SIGNAL(picturesAvailable(SmfPictureList*, QString, int)),this,SLOT(showPicsSlot(SmfPictureList*, QString))); |
|
30 } |
27 } |
31 } |
|
32 void MyApplication::showPicsSlot(SmfPictureList* pics, QString err) |
|
33 { |
|
34 //check err string if there is any error |
|
35 |
|
36 //if no error |
|
37 foreach(SmfPicture* pic, pics) { |
|
38 m_view.add(pic); // do something with the picture in this gallery |
|
39 } |
|
40 } |
28 |
41 |
29 /** 2. Upload a picture captured by the user to some selection of galeries.*/ |
42 /** 2. Upload a picture captured by the user to some selection of galeries.*/ |
30 void MyApplication::uploadPicture(QImage picture, QList<SmfGallery> galleries) |
43 void MyApplication::uploadPicture(QImage picture, QList<SmfGallery> galleries) |
31 { |
44 { |
32 // The list could be from a selection of galleries chosen by the user, |
45 /** |
33 // think multiple TweetDeck accounts? |
46 * When uploading is finished we can check the success of the uploading |
34 foreach(SmfGallery gallery, galleries) { |
47 */ |
35 gallery.upload(picture); |
48 QObject::connect(myGallery,SIGNAL(uploadFinished(bool)),this,SLOT(uploaded(bool))); |
36 } |
49 // The list could be from a selection of galleries chosen by the user, |
37 } |
50 // think multiple TweetDeck accounts? |
|
51 foreach(SmfGallery gallery, galleries) { |
|
52 gallery.upload(picture); |
|
53 } |
|
54 } |
|
55 void MyApplication::uploaded(bool success) |
|
56 { |
|
57 if(!success) |
|
58 { |
|
59 //error occured while uploading |
|
60 } |
|
61 } |
|
62 |
|
63 /** |
|
64 * 3. This is an example of displaying the friends profile image in a view from one or more |
|
65 * service provider. Note that this service can be provided by any kind of service provider, |
|
66 * e.g. last.fm music service where users maintain profiles and friends. |
|
67 */ |
|
68 void MyApplication::displayFriends() |
|
69 { |
|
70 // Some common interface for finding implementations. |
|
71 QList<SmfContactFetcher> contactFetcherList = Smf::GetServices("org.symbian.smf.contact.fetcher\0.2"); |
|
72 //Request friend list, |
|
73 //The friendsListAvailable() signal |
|
74 //is emitted with SmfContactList once data is arrived. |
|
75 QObject::Connect(contactFetcherList[0],SIGNAL(friendsListAvailable(SmfContactList*, QString, int)), |
|
76 this,SLOT(showlist(SmfContactList*)); |
|
77 fetcher.friends(); |
|
78 } |
|
79 |
|
80 void MyApplication::showlist(SmfContactList* friendsList) |
|
81 { |
|
82 |
|
83 // Adjust our view to show where these pictures came from |
|
84 //display service name description and the logo |
|
85 m_view.setIcon( myFetcher.serviceIcon() ); |
|
86 m_view.setProvider( myFetcher.serviceName() ); |
|
87 m_view.setDescription( myFetcher.description() ); |
|
88 |
|
89 //now display the images |
|
90 foreach(SmfContact* contact, friendsList) { |
|
91 QImage pic = contact.value("Avatar"); |
|
92 m_view.setPicture(pic); |
|
93 m_view.setTitle(contact.value("Name")); |
|
94 } |
|
95 } |
|
96 /** |
|
97 * 4. This is an example of posting and reading user updates to social netowrking sites |
|
98 */ |
|
99 void MyApplication::postUpdate() |
|
100 { |
|
101 // Some common interface for finding implementations. |
|
102 QList<SmfPostProvider> postServices = Smf::GetServices("org.symbian.smf.contact.posts\0.2"); |
|
103 |
|
104 //let us use the first one |
|
105 SmfPostProvider myPostServer = postServices[ 0 ]; |
|
106 |
|
107 //Adjust our view to show where these posts came from (e.g. tweets from twitter) |
|
108 //display service name description and the logo |
|
109 m_view.setIcon( myPostServer.serviceIcon() ); |
|
110 m_view.setProvider( myPostServer.serviceName() ); |
|
111 m_view.setDescription( myPostServer.description() ); |
|
112 |
|
113 SmfPost reply = new SmfPost(sampleString,samplmage, sampleUrl); |
|
114 //post my udpate to be visible to all, connect to updatePostFinished() |
|
115 // signal of SmfPostProvider to track the success |
|
116 myPostServer.updatePost(reply); |
|
117 |
|
118 //Asynchronously get all posts to me in my profle (e.g. twits from all friends) |
|
119 //connect to postsAvailable to show the post |
|
120 postServices.getPosts(); |
|
121 |
|
122 QObject::Connect(myPostServer,SIGNAL(postsAvailable(SmfPostList*, QString, int)),this,SLOT(showPosts(SmfPostList*, QString))); |
|
123 } |
|
124 void MyApplication::showPosts(SmfPostList* posts, QString err) |
|
125 { |
|
126 //Show the first post |
|
127 m_view.setPostData(posts->at(0)); |
|
128 } |
|
129 /** |
|
130 * 5. This is an example of getting song recommendations from a social netowrking sites |
|
131 */ |
|
132 void MyApplication::getMusic() |
|
133 { |
|
134 // Some common interface for finding implementations. |
|
135 QList<SmfMusicSearch> musicServices = Smf::GetServices("org.symbian.smf.music\0.2"); |
|
136 |
|
137 //let us use the first one |
|
138 SmfMusicSearch mServer = musicServices.at(0); |
|
139 QObject::Connect(mServer,SIGNAL(trackSearchAvailable(SmfTrackInfoList*, QString,int)),this,SLOT(showTrackSearch(SmfTrackInfoList*))); |
|
140 QObject::Connect(mServer,SIGNAL(storeSearchAvailable(SmfProviderList*, QString,int)),this,SLOT(showStoreSearch(SmfProviderList*))); |
|
141 //search songs similar to currently playing, |
|
142 //connect to trackSearchAvailable signal to get the result |
|
143 mServer.recommendations(currTrack); |
|
144 //display to the user |
|
145 m_view.setIcon( mServer.serviceIcon() ); |
|
146 m_view.setProvider( mServer.serviceName() ); |
|
147 m_view.setDescription( mServer.description() ); |
38 |
148 |
39 |
149 |
40 /** |
|
41 * 3. This is an example of displaying the friends profile image in a view from one or more |
|
42 * service provider. Note that this service can be provided by any kind of service provider, |
|
43 * e.g. last.fm music service where users maintain profiles and friends. |
|
44 */ |
|
45 void MyApplication::displayFriends() |
|
46 { |
|
47 // Some common interface for finding implementations. |
|
48 QList<SmfContactFetcher> contactFetcherList = Smf::GetServices("org.symbian.smf.contact.fetcher"); |
|
49 |
150 |
50 //let us show list of friends from first one |
|
51 showlist(contactFetcherList [ 0 ]); |
|
52 |
|
53 //now from the second provider |
|
54 showlist(contactFetcherList [ 1 ]); |
|
55 |
|
56 //user now matches one contact from list 1 to another contact in list 2 - |
|
57 SmfRelationMgr mgr = Smf::GetRelationMgr(); |
|
58 SmfRelationId id = mgr.create(contactFetcherList [ 0 ], selectedContact1); |
|
59 mgr.associate(id,contactFetcherList [ 1 ], selectedContact2); |
|
60 |
|
61 //now show user all the relations he has made so far |
|
62 QList<SmfRelationId> relations = mgr.getAll(); |
|
63 foreach(SmfRelationId id, relations) { |
|
64 QList<SmfRelationItem> items = mgr.get(id); |
|
65 foreach(SmfRelationItem item,items) { |
|
66 SmfProvider provider* = item.getProvider(); |
|
67 m_view.setIcon(provider.serviceIcon()); |
|
68 m_view.setTitle(item.value("Name")); |
|
69 } |
|
70 } |
151 } |
71 } |
152 void MyApplication::showTrackSearch(SmfTrackInfoList* songs) |
72 |
153 { |
73 void MyApplication::showlist(SmfContactFetcher fetcher) |
154 foreach(SmfTrackInfo* track, songs){ |
74 { |
|
75 //get users friend list |
|
76 QList<SmfContact> friendsList = fetcher.friends(); |
|
77 |
|
78 // Adjust our view to show where these pictures came from |
|
79 //display service name description and the logo |
|
80 m_view.setIcon( myFetcher.serviceIcon() ); |
|
81 m_view.setProvider( myFetcher.serviceName() ); |
|
82 m_view.setDescription( myFetcher.description() ); |
|
83 |
|
84 //now display the images |
|
85 foreach(SmfContact contact, friendsList) { |
|
86 QImage pic = contact.value("Avatar"); |
|
87 m_view.setPicture(pic); |
|
88 m_view.setTitle(contact.value("Name")); |
|
89 } |
|
90 } |
|
91 /** |
|
92 * 4. This is an example of posting and reading user updates to social netowrking sites |
|
93 */ |
|
94 void MyApplication::postUpdate() |
|
95 { |
|
96 // Some common interface for finding implementations. |
|
97 QList<SmfPostProvider> postServices = Smf::GetServices("org.symbian.smf.contact.posts"); |
|
98 |
|
99 //let us use the first one |
|
100 SmfPostProvider myPostServer = postServices[ 0 ]; |
|
101 |
|
102 //Adjust our view to show where these posts came from (e.g. tweets from twitter) |
|
103 //display service name description and the logo |
|
104 m_view.setIcon( myPostServer.serviceIcon() ); |
|
105 m_view.setProvider( myPostServer.serviceName() ); |
|
106 m_view.setDescription( myPostServer.description() ); |
|
107 |
|
108 SmfPost reply = new SmfPost(sampleString,samplmage, sampleUrl); |
|
109 //post my udpate to be visible to all |
|
110 myPostServer.updatePost(reply); |
|
111 |
|
112 //get all posts to me in my profle (e.g. twits from all friends) |
|
113 QList <SmfPost> posts = postServices.getPosts(); |
|
114 |
|
115 //read the first post |
|
116 SmfPost firstPost = posts.at(0); |
|
117 SmfContact currentContact = firstPost.contact(); |
|
118 |
|
119 //reply only to the sender - can check availability this service before sending |
|
120 myPostServer.postDirected(currentContact,reply); |
|
121 //presentation layout to be decided |
|
122 |
|
123 //now display the latest post |
|
124 qSort(posts.begin(),posts.end(),caseCompareTimeMoreThan); |
|
125 m_view.setPostData(posts.at(0)); |
|
126 |
|
127 } |
|
128 |
|
129 /** |
|
130 * 5. This is an example of getting song recommendations from a social netowrking sites |
|
131 */ |
|
132 void MyApplication::getMusic() |
|
133 { |
|
134 // Some common interface for finding implementations. |
|
135 QList<SmfMusicSearch> musicServices = Smf::GetServices("org.symbian.smf.music"); |
|
136 |
|
137 //let us use the first one |
|
138 SmfMusicSearch mServer = musicServices.at(0); |
|
139 |
|
140 //search songs similar to currently playing |
|
141 QList<SmfTrackInfo> songs = mServer.recommendations(currTrack); |
|
142 |
|
143 //display to the user |
|
144 m_view.setIcon( mServer.serviceIcon() ); |
|
145 m_view.setProvider( mServer.serviceName() ); |
|
146 m_view.setDescription( mServer.description() ); |
|
147 foreach(SmfTrackInfo track, songs) { |
|
148 m_view.add(track); |
155 m_view.add(track); |
149 } |
156 } |
150 |
157 //allow user to select a track and get purchase links |
151 //allow user to select a track and get purchase links |
158 //connect to showStoreSearch signal to display the stores for that track |
152 QList<SmfProvider> stores = mServer.stores(selectedTrack); |
159 mServer.stores(selectedTrack); |
153 |
160 } |
154 } |
161 void MyApplication::showStoreSearch(SmfProviderList* stores) |
155 |
162 { |
|
163 //show stores |
|
164 } |
156 void MyApplication::updateCurrentPlaying(QList<SmfMusicSearch> musicServices, SmfTrackInfo currTrack) |
165 void MyApplication::updateCurrentPlaying(QList<SmfMusicSearch> musicServices, SmfTrackInfo currTrack) |
157 { |
166 { |
158 //after purchasing and downloading is over, user plays the track |
167 //after purchasing and downloading is over, user plays the track |
159 //now post the current platying track to all service providers |
168 //now post the current platying track to all service providers |
160 foreach(SmfMusicSearch provider, musicServices) { |
169 //postFinished() signal of SmfMusicSearch can be tracked to check the success of the posts |
|
170 foreach(SmfMusicSearch provider, musicServices) { |
161 provider.postCurrentPlaying(currTrack); |
171 provider.postCurrentPlaying(currTrack); |
162 } |
172 } |
163 //postCurrentPlaying is also a slot funtion, may be application can use connect |
173 //postCurrentPlaying is also a slot funtion, may be application can use connect |
164 } |
174 } |
165 |
175 |
166 void MyApplication::displayLyrics(SmfTrackInfo currTrack) |
176 void MyApplication::displayLyrics(SmfTrackInfo currTrack) |
167 { |
177 { |
168 // Some common interface for finding implementations. |
178 // Some common interface for finding implementations. |
169 SmfLyricsService lyricsService = Smf::GetServices("org.symbian.smf.music.lyrics","lyricsfly.com"); |
179 SmfLyricsService lyricsService = Smf::GetServices("org.symbian.smf.music.lyrics\0.2","lyricsfly.com"); |
|
180 QObject::connect(lyricsService,SIGNAL(lyricsAvailable(SmfLyricsList*, QString, int)),this,SLOT(showLyrics(SmfLyricsList*)); |
170 |
181 |
171 QList<SmfLyrics> list = lyricsService.lyrics(currTrack); |
182 //Request to get the lyrics |
172 //now display the latest edited lyrics |
183 //lyricsAvailable() signal of SmfLyricsService is emitted when lyrics is available |
173 qSort(list.begin(),list.end(),caseCompareTimeMoreThan); |
184 lyricsService.lyrics(currTrack); |
174 m_view.setLyricsData(list.at(0)); |
185 |
175 } |
186 } |
|
187 void MyApplication::showLyrics(SmfLyricsList* list) |
|
188 { |
|
189 //now display the latest edited lyrics |
|
190 qSort(list->begin(),list->end(),caseCompareTimeMoreThan); |
|
191 m_view.setLyricsData(list->at(0)); |
|
192 } |