File indexing completed on 2024-05-05 04:49:21
0001 /**************************************************************************************** 0002 * Copyright (c) 2012 Matěj Laitl <matej@laitl.cz> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef STATSYNCING_SCROBBLINGSERVICE_H 0018 #define STATSYNCING_SCROBBLINGSERVICE_H 0019 0020 #include "amarok_export.h" 0021 0022 #include <QDateTime> 0023 #include <QMetaType> 0024 #include <QSharedPointer> 0025 0026 template<class T> class AmarokSharedPointer; 0027 namespace Meta { 0028 class Track; 0029 typedef AmarokSharedPointer<Track> TrackPtr; 0030 } 0031 0032 namespace StatSyncing 0033 { 0034 /** 0035 * Abstract base class for classes that provide track play scrobbling to Last.fm or 0036 * some similar service. 0037 * 0038 * This class is memory-managed as explicitly shared data, use ScrobblingServicePtr 0039 * every time you store reference to this class. 0040 */ 0041 // virtual inheritance to fight dreaded diamond problem in last.fm class 0042 // http://www.parashift.com/c++-faq-lite/mi-diamond.html 0043 class AMAROK_EXPORT ScrobblingService 0044 { 0045 public: 0046 virtual ~ScrobblingService(); 0047 0048 enum ScrobbleError { 0049 NoError, 0050 TooShort, // to short song or too short played time 0051 BadMetadata, // invalid artist, album, title... 0052 FromTheFuture, 0053 FromTheDistantPast, 0054 SkippedByUser //track contains label to be skipped by user in lastfm config 0055 }; 0056 0057 /** 0058 * Return (possibly) localized user-displayable pretty name identifying 0059 * this scrobbling service. 0060 */ 0061 virtual QString prettyName() const = 0; 0062 0063 /** 0064 * Scrobble a track. Scrobbling service may check certain criteria such as 0065 * track length and refuse to scrobble the track. 0066 * 0067 * @param track track to scrobble; you may assume it is non-null 0068 * @param playedFraction fraction which has been actually played, or a number 0069 * greater than 1 if the track was played multiple times 0070 * (for example on a media device) 0071 * @param time time when it was played, invalid QDateTime signifies that the 0072 * track has been played just now. This is the default when the 0073 * parameter is omitted. 0074 */ 0075 virtual ScrobbleError scrobble( const Meta::TrackPtr &track, double playedFraction = 1.0, 0076 const QDateTime &time = QDateTime() ) = 0; 0077 0078 /** 0079 * Update the "Now Playing" info on the scrobbling site without scrobbling the 0080 * track permanently. Scrobbler may check certain criteria and refuse to update 0081 * Now Playing if they are not met. If track is null, it means that no track is 0082 * playing and scrobbler should clear the Now Playing status. You may safely 0083 * assume this is not called too frequently. 0084 * 0085 * @param track that is currently playing or null if playback was stopped 0086 */ 0087 virtual void updateNowPlaying( const Meta::TrackPtr &track ) = 0; 0088 }; 0089 0090 typedef QSharedPointer<ScrobblingService> ScrobblingServicePtr; 0091 } 0092 0093 Q_DECLARE_METATYPE( StatSyncing::ScrobblingServicePtr ) 0094 0095 #endif // STATSYNCING_SCROBBLINGSERVICE_H