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