Changeset View
Changeset View
Standalone View
Standalone View
src/services/lastfm/LastFmService.cpp
Context not available. | |||||
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 | {} | ||
Context not available. | |||||
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.. | ||
Context not available. | |||||
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() ); | ||
Context not available. | |||||
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 | } | ||
Context not available. | |||||
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 | } | ||
Context not available. | |||||
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 ) | ||
Context not available. |