Changeset View
Changeset View
Standalone View
Standalone View
src/services/lastfm/LastFmService.cpp
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | |||||
49 | #include <QLabel> | 49 | #include <QLabel> | ||
50 | #include <QPixmap> | 50 | #include <QPixmap> | ||
51 | #include <QStandardPaths> | 51 | #include <QStandardPaths> | ||
52 | #include <QTimer> | 52 | #include <QTimer> | ||
53 | 53 | | |||
54 | #include <XmlQuery.h> | 54 | #include <XmlQuery.h> | ||
55 | 55 | | |||
56 | 56 | | |||
57 | QString md5( const QByteArray& src ) | | |||
58 | { | | |||
59 | QByteArray const digest = QCryptographicHash::hash( src, QCryptographicHash::Md5 ); | | |||
60 | return QString::fromLatin1( digest.toHex() ).rightJustified( 32, '0' ); | | |||
61 | } | | |||
62 | | ||||
63 | LastFmServiceFactory::LastFmServiceFactory() | 57 | LastFmServiceFactory::LastFmServiceFactory() | ||
64 | : ServiceFactory() | 58 | : ServiceFactory() | ||
65 | {} | 59 | {} | ||
66 | 60 | | |||
67 | void | 61 | void | ||
68 | LastFmServiceFactory::init() | 62 | LastFmServiceFactory::init() | ||
69 | { | 63 | { | ||
70 | ServiceBase *service = new LastFmService( this, "Last.fm" ); | 64 | ServiceBase *service = new LastFmService( this, "Last.fm" ); | ||
Show All 29 Lines | 88 | LastFmService::LastFmService( LastFmServiceFactory *parent, const QString &name ) | |||
100 | , m_userinfo( 0 ) | 94 | , m_userinfo( 0 ) | ||
101 | , m_subscriber( false ) | 95 | , m_subscriber( false ) | ||
102 | , m_authenticateReply( 0 ) | 96 | , m_authenticateReply( 0 ) | ||
103 | , m_config( LastFmServiceConfig::instance() ) | 97 | , m_config( LastFmServiceConfig::instance() ) | ||
104 | { | 98 | { | ||
105 | DEBUG_BLOCK | 99 | DEBUG_BLOCK | ||
106 | setShortDescription( i18n( "Last.fm: The social music revolution" ) ); | 100 | setShortDescription( i18n( "Last.fm: The social music revolution" ) ); | ||
107 | setIcon( QIcon::fromTheme( "view-services-lastfm-amarok" ) ); | 101 | setIcon( QIcon::fromTheme( "view-services-lastfm-amarok" ) ); | ||
108 | setLongDescription( i18n( "Last.fm is a popular online service that provides personal radio stations and music recommendations. A personal listening station is tailored based on your listening habits and provides you with recommendations for new music. It is also possible to play stations with music that is similar to a particular artist as well as listen to streams from people you have added as friends or that Last.fm considers your musical \"neighbors\"" ) ); | 102 | setLongDescription( i18n( "Last.fm is a popular online service that provides personal radio stations and music recommendations. A personal listening station is tailored based on your listening habits and provides you with recommendations for new music. It is also possible to play stations with music that is similar to a particular artist as well as listen to streams from people you have added as friends" ) ); | ||
109 | setImagePath( QStandardPaths::locate( QStandardPaths::GenericDataLocation, "amarok/images/hover_info_lastfm.png" ) ); | 103 | setImagePath( QStandardPaths::locate( QStandardPaths::GenericDataLocation, "amarok/images/hover_info_lastfm.png" ) ); | ||
110 | 104 | | |||
111 | //We have no use for searching currently.. | 105 | //We have no use for searching currently.. | ||
112 | m_searchWidget->setVisible( false ); | 106 | m_searchWidget->setVisible( false ); | ||
113 | 107 | | |||
114 | // set the global static Lastfm::Ws stuff | 108 | // set the global static Lastfm::Ws stuff | ||
115 | lastfm::ws::ApiKey = Amarok::lastfmApiKey(); | 109 | lastfm::ws::ApiKey = Amarok::lastfmApiKey(); | ||
116 | lastfm::ws::SharedSecret = Amarok::lastfmApiSharedSecret(); | 110 | lastfm::ws::SharedSecret = Amarok::lastfmApiSharedSecret(); | ||
117 | 111 | | |||
112 | // HTTPS is the only scheme supported by Auth | ||||
113 | lastfm::ws::setScheme(lastfm::ws::Https); | ||||
114 | | ||||
118 | // set the nam TWICE. Yes. It prevents liblastfm from deleting it, see their code | 115 | // set the nam TWICE. Yes. It prevents liblastfm from deleting it, see their code | ||
119 | lastfm::setNetworkAccessManager( The::networkAccessManager() ); | 116 | lastfm::setNetworkAccessManager( The::networkAccessManager() ); | ||
120 | lastfm::setNetworkAccessManager( The::networkAccessManager() ); | 117 | lastfm::setNetworkAccessManager( The::networkAccessManager() ); | ||
121 | 118 | | |||
122 | // enable custom bias | 119 | // enable custom bias | ||
123 | m_biasFactories << new Dynamic::LastFmBiasFactory(); | 120 | m_biasFactories << new Dynamic::LastFmBiasFactory(); | ||
124 | Dynamic::BiasFactory::instance()->registerNewBiasFactory( m_biasFactories.last() ); | 121 | Dynamic::BiasFactory::instance()->registerNewBiasFactory( m_biasFactories.last() ); | ||
125 | m_biasFactories << new Dynamic::WeeklyTopBiasFactory(); | 122 | m_biasFactories << new Dynamic::WeeklyTopBiasFactory(); | ||
Show All 30 Lines | 139 | { | |||
156 | { | 153 | { | ||
157 | CollectionManager::instance()->removeTrackProvider( m_collection ); | 154 | CollectionManager::instance()->removeTrackProvider( m_collection ); | ||
158 | m_collection->deleteLater(); | 155 | m_collection->deleteLater(); | ||
159 | m_collection = 0; | 156 | m_collection = 0; | ||
160 | } | 157 | } | ||
161 | 158 | | |||
162 | StatSyncing::Controller *controller = Amarok::Components::statSyncingController(); | 159 | StatSyncing::Controller *controller = Amarok::Components::statSyncingController(); | ||
163 | if( m_scrobbler && controller ) | 160 | if( m_scrobbler && controller ) | ||
164 | controller->unregisterScrobblingService( StatSyncing::ScrobblingServicePtr( m_scrobbler.data() ) ); | 161 | controller->unregisterScrobblingService( m_scrobbler.staticCast<StatSyncing::ScrobblingService>() ); | ||
165 | if( m_synchronizationAdapter && controller ) | 162 | if( m_synchronizationAdapter && controller ) | ||
166 | controller->unregisterProvider( m_synchronizationAdapter ); | 163 | controller->unregisterProvider( m_synchronizationAdapter ); | ||
167 | } | 164 | } | ||
168 | 165 | | |||
169 | void | 166 | void | ||
170 | LastFmService::slotReconfigure() | 167 | LastFmService::slotReconfigure() | ||
171 | { | 168 | { | ||
172 | lastfm::ws::Username = m_config->username(); | 169 | lastfm::ws::Username = m_config->username(); | ||
Show All 29 Lines | 195 | { | |||
202 | if( m_authenticateReply ) | 199 | if( m_authenticateReply ) | ||
203 | { | 200 | { | ||
204 | disconnect( m_authenticateReply, &QNetworkReply::finished, this, &LastFmService::onAuthenticated ); | 201 | disconnect( m_authenticateReply, &QNetworkReply::finished, this, &LastFmService::onAuthenticated ); | ||
205 | m_authenticateReply->abort(); | 202 | m_authenticateReply->abort(); | ||
206 | m_authenticateReply->deleteLater(); | 203 | m_authenticateReply->deleteLater(); | ||
207 | m_authenticateReply = 0; | 204 | m_authenticateReply = 0; | ||
208 | } | 205 | } | ||
209 | 206 | | |||
210 | const QString authToken = md5( QString( "%1%2" ).arg( m_config->username(), | | |||
211 | md5( m_config->password().toUtf8() ) ).toUtf8() ); | | |||
212 | QMap<QString, QString> query; | 207 | QMap<QString, QString> query; | ||
213 | query[ "method" ] = "auth.getMobileSession"; | 208 | query[ "method" ] = "auth.getMobileSession"; | ||
209 | query[ "password" ] = m_config->password(); | ||||
214 | query[ "username" ] = m_config->username(); | 210 | query[ "username" ] = m_config->username(); | ||
215 | query[ "authToken" ] = authToken; | | |||
216 | m_authenticateReply = lastfm::ws::post( query ); | 211 | m_authenticateReply = lastfm::ws::post( query ); | ||
217 | connect( m_authenticateReply, &QNetworkReply::finished, this, &LastFmService::onAuthenticated ); // calls continueReconfiguring() | 212 | connect( m_authenticateReply, &QNetworkReply::finished, this, &LastFmService::onAuthenticated ); // calls continueReconfiguring() | ||
218 | } | 213 | } | ||
219 | else | 214 | else | ||
220 | { | 215 | { | ||
221 | debug() << __PRETTY_FUNCTION__ << "either last.fm username or password is empty"; | 216 | debug() << __PRETTY_FUNCTION__ << "either last.fm username or password is empty"; | ||
222 | continueReconfiguring(); | 217 | continueReconfiguring(); | ||
223 | } | 218 | } | ||
224 | } | 219 | } | ||
225 | 220 | | |||
226 | void | 221 | void | ||
227 | LastFmService::continueReconfiguring() | 222 | LastFmService::continueReconfiguring() | ||
228 | { | 223 | { | ||
229 | StatSyncing::Controller *controller = Amarok::Components::statSyncingController(); | 224 | StatSyncing::Controller *controller = Amarok::Components::statSyncingController(); | ||
230 | Q_ASSERT( controller ); | 225 | Q_ASSERT( controller ); | ||
231 | 226 | | |||
232 | lastfm::ws::SessionKey = m_config->sessionKey(); | 227 | lastfm::ws::SessionKey = m_config->sessionKey(); | ||
233 | // we also check username, KWallet may deliver it really late, but we need it | 228 | // we also check username, KWallet may deliver it really late, but we need it | ||
234 | bool authenticated = serviceReady() && !m_config->sessionKey().isEmpty(); | 229 | bool authenticated = serviceReady() && !m_config->sessionKey().isEmpty(); | ||
235 | 230 | | |||
236 | if( m_scrobbler && (!authenticated || !m_config->scrobble()) ) | 231 | if( m_scrobbler && (!authenticated || !m_config->scrobble()) ) | ||
237 | { | 232 | { | ||
238 | debug() << __PRETTY_FUNCTION__ << "unregistering and destroying ScrobblerAdapter"; | 233 | debug() << __PRETTY_FUNCTION__ << "unregistering and destroying ScrobblerAdapter"; | ||
239 | controller->unregisterScrobblingService( StatSyncing::ScrobblingServicePtr( m_scrobbler.data() ) ); | 234 | controller->unregisterScrobblingService( m_scrobbler.staticCast<StatSyncing::ScrobblingService>() ); | ||
240 | m_scrobbler.clear(); | 235 | m_scrobbler.clear(); | ||
241 | } | 236 | } | ||
242 | else if( !m_scrobbler && authenticated && m_config->scrobble() ) | 237 | else if( !m_scrobbler && authenticated && m_config->scrobble() ) | ||
243 | { | 238 | { | ||
244 | debug() << __PRETTY_FUNCTION__ << "creating and registering ScrobblerAdapter"; | 239 | debug() << __PRETTY_FUNCTION__ << "creating and registering ScrobblerAdapter"; | ||
245 | m_scrobbler = QSharedPointer<ScrobblerAdapter>( new ScrobblerAdapter( "Amarok", m_config ) ); | 240 | m_scrobbler = QSharedPointer<ScrobblerAdapter>( new ScrobblerAdapter( "Amarok", m_config ) ); | ||
246 | controller->registerScrobblingService( StatSyncing::ScrobblingServicePtr( m_scrobbler.data() ) ); | 241 | controller->registerScrobblingService( m_scrobbler.staticCast<StatSyncing::ScrobblingService>() ); | ||
247 | } | 242 | } | ||
248 | 243 | | |||
249 | if( m_synchronizationAdapter && !authenticated ) | 244 | if( m_synchronizationAdapter && !authenticated ) | ||
250 | { | 245 | { | ||
251 | debug() << __PRETTY_FUNCTION__ << "unregistering and destroying SynchronizationAdapter"; | 246 | debug() << __PRETTY_FUNCTION__ << "unregistering and destroying SynchronizationAdapter"; | ||
252 | controller->unregisterProvider( m_synchronizationAdapter ); | 247 | controller->unregisterProvider( m_synchronizationAdapter ); | ||
253 | m_synchronizationAdapter = 0; | 248 | m_synchronizationAdapter = 0; | ||
254 | } | 249 | } | ||
▲ Show 20 Lines • Show All 279 Lines • Show Last 20 Lines |