|
1 #include <smf/smfprovider.h> |
|
2 #include <smf/smfgallery.h> |
|
3 #include <smf/smfcontact.h> |
|
4 #include <smf/smfpostprovider.h> |
|
5 #include <smf/smffcontactfetcher.h> |
|
6 #include <smf/smfmusic.h> |
|
7 |
|
8 /** 1. Display a gallery on the screen for some remote service. |
|
9 * assume m_view is some gallery view object in the application.*/ |
|
10 void MyApplication::displayGallery() |
|
11 { |
|
12 // Some common interface for finding implementations. |
|
13 QList<SmfGallery> galleries = Smf::GetServices("org.symbian.smf.gallery"); |
|
14 |
|
15 // We will use the first one now |
|
16 SmfGallery myGallery = galleries[0]; |
|
17 |
|
18 // Adjust our view to show where these pictures came from |
|
19 m_view.setIcon(myGallery.serviceIcon()); |
|
20 m_view.setProvder(myGallery.serviceName()); |
|
21 m_view.setDescription(myGallery.description()); |
|
22 |
|
23 QList<SmfPicture> pics = myGallery.pictures(); |
|
24 foreach(SmfPicture pic, pics) { |
|
25 m_view.add(pic); // do something with the picture in this gallery |
|
26 } |
|
27 } |
|
28 |
|
29 /** 2. Upload a picture captured by the user to some selection of galeries.*/ |
|
30 void MyApplication::uploadPicture(QImage picture, QList<SmfGallery> galleries) |
|
31 { |
|
32 // The list could be from a selection of galleries chosen by the user, |
|
33 // think multiple TweetDeck accounts? |
|
34 foreach(SmfGallery gallery, galleries) { |
|
35 gallery.upload(picture); |
|
36 } |
|
37 } |
|
38 |
|
39 |
|
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 |
|
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 } |
|
71 } |
|
72 |
|
73 void MyApplication::showlist(SmfContactFetcher fetcher) |
|
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); |
|
149 } |
|
150 |
|
151 //allow user to select a track and get purchase links |
|
152 QList<SmfProvider> stores = mServer.stores(selectedTrack); |
|
153 |
|
154 } |
|
155 |
|
156 void MyApplication::updateCurrentPlaying(QList<SmfMusicSearch> musicServices, SmfTrackInfo currTrack) |
|
157 { |
|
158 //after purchasing and downloading is over, user plays the track |
|
159 //now post the current platying track to all service providers |
|
160 foreach(SmfMusicSearch provider, musicServices) { |
|
161 provider.postCurrentPlaying(currTrack); |
|
162 } |
|
163 //postCurrentPlaying is also a slot funtion, may be application can use connect |
|
164 } |
|
165 |
|
166 void MyApplication::displayLyrics(SmfTrackInfo currTrack) |
|
167 { |
|
168 // Some common interface for finding implementations. |
|
169 SmfLyricsService lyricsService = Smf::GetServices("org.symbian.smf.music.lyrics","lyricsfly.com"); |
|
170 |
|
171 QList<SmfLyrics> list = lyricsService.lyrics(currTrack); |
|
172 //now display the latest edited lyrics |
|
173 qSort(list.begin(),list.end(),caseCompareTimeMoreThan); |
|
174 m_view.setLyricsData(list.at(0)); |
|
175 } |