Changeset View
Changeset View
Standalone View
Standalone View
src/services/lastfm/LastFmServiceCollection.cpp
Show All 31 Lines | 30 | { | |||
---|---|---|---|---|---|
32 | Meta::ServiceGenre * userStreams = new Meta::ServiceGenre( i18n( "%1's Streams", userName ) ); | 32 | Meta::ServiceGenre * userStreams = new Meta::ServiceGenre( i18n( "%1's Streams", userName ) ); | ||
33 | Meta::GenrePtr userStreamsPtr( userStreams ); | 33 | Meta::GenrePtr userStreamsPtr( userStreams ); | ||
34 | addGenre( userStreamsPtr ); | 34 | addGenre( userStreamsPtr ); | ||
35 | 35 | | |||
36 | Meta::ServiceGenre * globalTags = new Meta::ServiceGenre( i18n( "Global Tags" ) ); | 36 | Meta::ServiceGenre * globalTags = new Meta::ServiceGenre( i18n( "Global Tags" ) ); | ||
37 | Meta::GenrePtr globalTagsPtr( globalTags ); | 37 | Meta::GenrePtr globalTagsPtr( globalTags ); | ||
38 | addGenre( globalTagsPtr ); | 38 | addGenre( globalTagsPtr ); | ||
39 | 39 | | |||
40 | m_neighborsLoved = new Meta::ServiceGenre( i18n( "Neighbors' Loved Radio" ) ); | | |||
41 | Meta::GenrePtr neighborsLovedPtr( m_neighborsLoved ); | | |||
42 | addGenre( neighborsLovedPtr ); | | |||
43 | | ||||
44 | m_neighborsPersonal = new Meta::ServiceGenre( i18n( "Neighbors' Personal Radio" ) ); | | |||
45 | Meta::GenrePtr neighborsPersonalPtr( m_neighborsPersonal ); | | |||
46 | addGenre( neighborsPersonalPtr ); | | |||
47 | | ||||
48 | m_friendsLoved = new Meta::ServiceGenre( i18n( "Friends' Loved Radio" ) ); | 40 | m_friendsLoved = new Meta::ServiceGenre( i18n( "Friends' Loved Radio" ) ); | ||
49 | Meta::GenrePtr friendsLovedPtr( m_friendsLoved ); | 41 | Meta::GenrePtr friendsLovedPtr( m_friendsLoved ); | ||
50 | addGenre( friendsLovedPtr ); | 42 | addGenre( friendsLovedPtr ); | ||
51 | 43 | | |||
52 | m_friendsPersonal = new Meta::ServiceGenre( i18n( "Friends' Personal Radio" ) ); | 44 | m_friendsPersonal = new Meta::ServiceGenre( i18n( "Friends' Personal Radio" ) ); | ||
53 | Meta::GenrePtr friendsPersonalPtr( m_friendsPersonal ); | 45 | Meta::GenrePtr friendsPersonalPtr( m_friendsPersonal ); | ||
54 | addGenre( friendsPersonalPtr ); | 46 | addGenre( friendsPersonalPtr ); | ||
55 | 47 | | |||
56 | // Only show these if the user is a subscriber. | 48 | // Only show these if the user is a subscriber. | ||
57 | QStringList lastfmPersonal; | 49 | QStringList lastfmPersonal; | ||
58 | lastfmPersonal << "personal" << "recommended" << "loved" << "neighbours"; | 50 | lastfmPersonal << "personal" << "recommended" << "loved"; | ||
59 | 51 | | |||
60 | foreach( const QString &station, lastfmPersonal ) | 52 | foreach( const QString &station, lastfmPersonal ) | ||
61 | { | 53 | { | ||
62 | LastFm::Track * track = new LastFm::Track( "lastfm://user/" + userName + "/" + station ); | 54 | LastFm::Track * track = new LastFm::Track( "lastfm://user/" + userName + "/" + station ); | ||
63 | Meta::TrackPtr trackPtr( track ); | 55 | Meta::TrackPtr trackPtr( track ); | ||
64 | userStreams->addTrack( trackPtr ); | 56 | userStreams->addTrack( trackPtr ); | ||
65 | addTrack( trackPtr ); | 57 | addTrack( trackPtr ); | ||
66 | } | 58 | } | ||
Show All 9 Lines | |||||
76 | { | 68 | { | ||
77 | LastFm::Track * track = new LastFm::Track( "lastfm://globaltags/" + genre ); | 69 | LastFm::Track * track = new LastFm::Track( "lastfm://globaltags/" + genre ); | ||
78 | Meta::TrackPtr trackPtr( track ); | 70 | Meta::TrackPtr trackPtr( track ); | ||
79 | globalTags->addTrack( trackPtr ); | 71 | globalTags->addTrack( trackPtr ); | ||
80 | addTrack( trackPtr ); | 72 | addTrack( trackPtr ); | ||
81 | } | 73 | } | ||
82 | 74 | | |||
83 | QMap< QString, QString > params; | 75 | QMap< QString, QString > params; | ||
84 | params[ "method" ] = "user.getNeighbours"; | | |||
85 | params[ "user" ] = userName; | | |||
86 | m_jobs[ "user.getNeighbours" ] = lastfm::ws::post( params ); | | |||
87 | | ||||
88 | connect( m_jobs[ "user.getNeighbours" ], &QNetworkReply::finished, this, &LastFmServiceCollection::slotAddNeighboursLoved ); | | |||
89 | //connect( m_jobs[ "user.getNeighbours" ], &QNetworkReply::finished, this, &LastFmServiceCollection::slotAddNeighboursPersonal ); | | |||
90 | // TODO TMP HACK why do i get exceptions there...!? | | |||
91 | | ||||
92 | params[ "method" ] = "user.getFriends"; | 76 | params[ "method" ] = "user.getFriends"; | ||
77 | params[ "user" ] = userName; | ||||
93 | m_jobs[ "user.getFriends" ] = lastfm::ws::post( params ); | 78 | m_jobs[ "user.getFriends" ] = lastfm::ws::post( params ); | ||
94 | 79 | | |||
95 | connect( m_jobs[ "user.getFriends" ], &QNetworkReply::finished, this, &LastFmServiceCollection::slotAddFriendsLoved ); | 80 | connect( m_jobs[ "user.getFriends" ], &QNetworkReply::finished, this, &LastFmServiceCollection::slotAddFriendsLoved ); | ||
96 | //connect( m_jobs[ "user.getFriends" ], &QNetworkReply::finished, this, &LastFmServiceCollection::slotAddFriendsPersonal ); | 81 | //connect( m_jobs[ "user.getFriends" ], &QNetworkReply::finished, this, &LastFmServiceCollection::slotAddFriendsPersonal ); | ||
97 | 82 | | |||
98 | //TODO Automatically add similar artist streams for the users favorite artists. | 83 | //TODO Automatically add similar artist streams for the users favorite artists. | ||
99 | } | 84 | } | ||
100 | 85 | | |||
Show All 24 Lines | |||||
125 | 110 | | |||
126 | 111 | | |||
127 | QString | 112 | QString | ||
128 | LastFmServiceCollection::prettyName() const | 113 | LastFmServiceCollection::prettyName() const | ||
129 | { | 114 | { | ||
130 | return i18n( "Last.fm" ); | 115 | return i18n( "Last.fm" ); | ||
131 | } | 116 | } | ||
132 | 117 | | |||
133 | void LastFmServiceCollection::slotAddNeighboursLoved() | | |||
134 | { | | |||
135 | DEBUG_BLOCK | | |||
136 | if( !m_jobs[ "user.getNeighbours" ] ) | | |||
137 | { | | |||
138 | debug() << "BAD! got no result object"; | | |||
139 | return; | | |||
140 | } | | |||
141 | switch (m_jobs[ "user.getNeighbours" ]->error()) | | |||
142 | { | | |||
143 | case QNetworkReply::NoError: | | |||
144 | { | | |||
145 | // iterate through each neighbour | | |||
146 | lastfm::XmlQuery lfm; | | |||
147 | if( lfm.parse( m_jobs[ "user.getNeighbours" ]->readAll() ) ) | | |||
148 | { | | |||
149 | foreach( const lastfm::XmlQuery &e, lfm[ "neighbours" ].children( "user" ) ) | | |||
150 | { | | |||
151 | const QString name = e[ "name" ].text(); | | |||
152 | //debug() << "got neighbour!!! - " << name; | | |||
153 | LastFm::Track *track = new LastFm::Track( "lastfm://user/" + name + "/loved" ); | | |||
154 | Meta::TrackPtr trackPtr( track ); | | |||
155 | m_neighborsLoved->addTrack( trackPtr ); | | |||
156 | addTrack( trackPtr ); | | |||
157 | } | | |||
158 | | ||||
159 | } | | |||
160 | else | | |||
161 | { | | |||
162 | debug() << "Got exception in parsing from last.fm:" << lfm.parseError().message(); | | |||
163 | } | | |||
164 | break; | | |||
165 | } | | |||
166 | | ||||
167 | case QNetworkReply::AuthenticationRequiredError: | | |||
168 | debug() << "Last.fm: errorMessage: Sorry, we don't recognise that username, or you typed the password incorrectly."; | | |||
169 | break; | | |||
170 | | ||||
171 | default: | | |||
172 | debug() << "Last.fm: errorMessage: There was a problem communicating with the Last.fm services. Please try again later."; | | |||
173 | break; | | |||
174 | } | | |||
175 | | ||||
176 | m_jobs[ "user.getNeighbours" ]->deleteLater(); | | |||
177 | } | | |||
178 | | ||||
179 | void LastFmServiceCollection::slotAddNeighboursPersonal() | | |||
180 | { | | |||
181 | DEBUG_BLOCK | | |||
182 | switch (m_jobs[ "user.getNeighbours" ]->error()) | | |||
183 | { | | |||
184 | case QNetworkReply::NoError: | | |||
185 | { | | |||
186 | // iterate through each neighbour | | |||
187 | if( !m_jobs[ "user.getNeighbours" ] ) | | |||
188 | { | | |||
189 | debug() << "BAD! got no result object"; | | |||
190 | return; | | |||
191 | } | | |||
192 | lastfm::XmlQuery lfm; | | |||
193 | if( lfm.parse( m_jobs[ "user.getNeighbours" ]->readAll() ) ) | | |||
194 | { | | |||
195 | // iterate through each neighbour | | |||
196 | foreach( const lastfm::XmlQuery &e, lfm[ "neighbours" ].children( "user" ) ) | | |||
197 | { | | |||
198 | const QString name = e[ "name" ].text(); | | |||
199 | debug() << "got neighbour!!! - " << name; | | |||
200 | LastFm::Track *track = new LastFm::Track( "lastfm://user/" + name + "/personal" ); | | |||
201 | Meta::TrackPtr trackPtr( track ); | | |||
202 | m_neighborsPersonal->addTrack( trackPtr ); | | |||
203 | addTrack( trackPtr ); | | |||
204 | } | | |||
205 | | ||||
206 | | ||||
207 | // should be safe, as both slots SHOULD get called before we return to the event loop... | | |||
208 | m_jobs[ "user.getNeighbours" ]->deleteLater(); | | |||
209 | } | | |||
210 | else | | |||
211 | { | | |||
212 | debug() << "Got exception in parsing from last.fm:" << lfm.parseError().message(); | | |||
213 | } | | |||
214 | break; | | |||
215 | } | | |||
216 | | ||||
217 | case QNetworkReply::AuthenticationRequiredError: | | |||
218 | debug() << "Last.fm: errorMessage: Sorry, we don't recognise that username, or you typed the password incorrectly."; | | |||
219 | break; | | |||
220 | | ||||
221 | default: | | |||
222 | debug() << "Last.fm: errorMessage: There was a problem communicating with the Last.fm services. Please try again later."; | | |||
223 | break; | | |||
224 | } | | |||
225 | | ||||
226 | } | | |||
227 | | ||||
228 | void LastFmServiceCollection::slotAddFriendsLoved() | 118 | void LastFmServiceCollection::slotAddFriendsLoved() | ||
229 | { | 119 | { | ||
230 | DEBUG_BLOCK | 120 | DEBUG_BLOCK | ||
231 | if( !m_jobs[ "user.getFriends" ] ) | 121 | if( !m_jobs[ "user.getFriends" ] ) | ||
232 | { | 122 | { | ||
233 | debug() << "BAD! got no result object"; | 123 | debug() << "BAD! got no result object"; | ||
234 | return; | 124 | return; | ||
235 | } | 125 | } | ||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |