2 Copyright (c) 2004 Christian Muehlhaeuser <chris@chris.de>
3 Copyright (c) 2004 Sami Nieminen <sami.nieminen@iki.fi>
4 Copyright (c) 2006 Shane King <kde@dontletsstart.com>
5 Copyright (c) 2006 Iain Benson <iain@arctos.me.uk>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 #ifndef AMAROK_SCROBBLER_H
23 #define AMAROK_SCROBBLER_H
25 #include "engineobserver.h"
27 #include <QDomDocument>
28 #include <QDomElement>
34 //some setups require this
35 #undef PROTOCOL_VERSION
37 namespace KIO
{ class Job
; }
43 class ScrobblerSubmitter
;
45 class Scrobbler
: public QObject
, public EngineObserver
47 friend class MediaDevice
;
52 static Scrobbler
*instance();
54 void similarArtists( const QString
& /*artist*/ );
58 void similarArtistsFetched( const QString
& artist
, const QStringList
& suggestions
);
61 void subTrack( long currentPos
, long startPos
, long endPos
); // cuefiles can update length without track change
67 void engineNewMetaData( const MetaBundle
& /*bundle*/, bool /*state*/ );
68 void engineTrackPositionChanged( long /*position*/ , bool /*userSeek*/ );
71 void audioScrobblerSimilarArtistsResult( KIO::Job
* /*job*/ );
72 void audioScrobblerSimilarArtistsData(
73 KIO::Job
* /*job*/, const QByteArray
& /*data*/ );
76 QTimer m_timer
; //works around xine bug
77 //http://sourceforge.net/tracker/index.php?func=detail&aid=1401026&group_id=9655&atid=109655
78 QByteArray m_similarArtistsBuffer
;
79 KIO::Job
* m_similarArtistsJob
;
81 bool m_validForSending
;
83 ScrobblerSubmitter
* m_submitter
;
90 friend class ScrobblerSubmitter
;
94 const QString
& /*artist*/,
95 const QString
& /*album*/,
96 const QString
& /*title*/,
99 SubmitItem( const QDomElement
& /* domElement */ );
102 bool operator==( const SubmitItem
& item
);
104 void setArtist( const QString
& artist
) { m_artist
= artist
; }
105 void setAlbum( const QString
& album
) { m_album
= album
; }
106 void setTitle( const QString
& title
) { m_title
= title
; }
107 const QString
artist() const { return m_artist
; }
108 const QString
album() const { return m_album
; }
109 const QString
title() const { return m_title
; }
110 int length() const { return m_length
; }
111 uint
playStartTime() const { return m_playStartTime
; }
113 QDomElement
toDomElement( QDomDocument
& /* document */ ) const;
115 bool valid() const { return !m_artist
.isEmpty() && !m_title
.isEmpty() && m_length
>= 30; }
122 uint m_playStartTime
;
126 class SubmitQueue
: public QList
<SubmitItem
*>
129 static bool compareItems( SubmitItem
*sItem1
, SubmitItem
*sItem2
);
133 class ScrobblerSubmitter
: public QObject
138 static QString PROTOCOL_VERSION
;
139 static QString CLIENT_ID
;
140 static QString CLIENT_VERSION
;
141 static QString HANDSHAKE_URL
;
143 ScrobblerSubmitter();
144 ~ScrobblerSubmitter();
146 void submitItem( SubmitItem
* /* item */ );
148 void configure( const QString
& /*username*/, const QString
& /* password*/, bool /*enabled*/ );
153 void scheduledTimeReached();
154 void audioScrobblerHandshakeResult( KIO::Job
* /*job*/ );
155 void audioScrobblerSubmitResult( KIO::Job
* /*job*/ );
156 void audioScrobblerSubmitData(
157 KIO::Job
* /*job*/, const QByteArray
& /*data*/ );
160 bool canSubmit() const;
161 void enqueueItem( SubmitItem
* /* item */ );
162 SubmitItem
* dequeueItem();
163 void enqueueJob( KIO::Job
* /* job */ );
164 void finishJob( KIO::Job
* /* job */ );
166 SubmitItem
* /* item */, int /* tracks */, bool /* success */ ) const;
167 void saveSubmitQueue();
168 void readSubmitQueue();
169 bool schedule( bool failure
);
170 void performHandshake();
171 void performSubmit();
173 // on failure, start at MIN_BACKOFF, and double on subsequent failures
174 // until MAX_BACKOFF is reached
175 static const int MIN_BACKOFF
= 60;
176 static const int MAX_BACKOFF
= 60 * 60;
178 QString m_submitResultBuffer
;
184 bool m_scrobblerEnabled
;
185 bool m_holdFakeQueue
;
187 bool m_needHandshake
;
188 uint m_prevSubmitTime
;
191 uint m_lastSubmissionFinishTime
;
192 uint m_fakeQueueLength
;
194 //Q3PtrDict<SubmitItem> m_ongoingSubmits;
195 QHash
<KIO::Job
*, SubmitItem
* > m_ongoingSubmits
;
196 SubmitQueue m_submitQueue
; // songs played by Amarok
197 SubmitQueue m_fakeQueue
; // songs for which play times have to be faked (e.g. when submitting from media device)
203 #endif /* AMAROK_SCROBBLER_H */