File indexing completed on 2024-05-05 04:48:17
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 META_STATISTICS_H 0018 #define META_STATISTICS_H 0019 0020 #include "core/amarokcore_export.h" 0021 0022 #include "AmarokSharedPointer.h" 0023 0024 class QDateTime; 0025 0026 namespace Meta 0027 { 0028 /** 0029 * Interface that can be provided by tracks that can support play-related statistics: 0030 * rating, score, first/last played, play count. 0031 * 0032 * This class is memory-managed exclusively using AmarokSharedPointers: always use 0033 * StatisticsPtr to store or pass pointer to this class. This class must be 0034 * implemented in a reentrant manner. Additionally, underlying Meta::Track must be 0035 * thread-safe -- if you return same instance of Statistics every time then it means 0036 * that even the instance must be thread-safe. 0037 */ 0038 class AMAROKCORE_EXPORT Statistics : public virtual QSharedData // virtual inheritance 0039 // so that Track implementations can inherit both Meta::Track and Meta::Statistics 0040 { 0041 public: 0042 virtual ~Statistics(); 0043 0044 /** 0045 * Return the score of this track in range 0 .. 100. Default implementation 0046 * returns 0. 0047 */ 0048 virtual double score() const; 0049 0050 /** 0051 * Set score of this track. If you touch more fields, consider using 0052 * @see beginUpdate(), @see endUpdate() 0053 */ 0054 virtual void setScore( double newScore ); 0055 0056 /** 0057 * Return the rating of this track as a count of half-stars in range 0 .. 10. 0058 * Default implementation returns 0. 0059 */ 0060 virtual int rating() const; 0061 0062 /** 0063 * Set rating of this track. If you touch more fields, consider using 0064 * @see beginUpdate(), @see endUpdate() 0065 */ 0066 virtual void setRating( int newRating ); 0067 0068 /** 0069 * Return the time the song was last played, or an invalid QDateTime if it 0070 * has not been played yet (done by the default implementation). 0071 */ 0072 virtual QDateTime lastPlayed() const; 0073 0074 /** 0075 * Set the last played time. @param date may be an invalid date to reset 0076 * the date to "never played". If you touch more fields, consider using 0077 * @see beginUpdate(), @see endUpdate() 0078 */ 0079 virtual void setLastPlayed( const QDateTime &date ); 0080 0081 /** 0082 * Return the time the song was first played, or an invalid QDateTime if it 0083 * has not been played yet (done by the default implementation). 0084 */ 0085 virtual QDateTime firstPlayed() const; 0086 0087 /** 0088 * Set the first played time. @param date may be an invalid date to reset 0089 * the date to "never played". If you touch more fields, consider using 0090 * @see beginUpdate(), @see endUpdate() 0091 */ 0092 virtual void setFirstPlayed( const QDateTime &date ); 0093 0094 /** 0095 * Returns the number of times the track was played, 0 id it is unknown. 0096 * Default implementation returns 0. 0097 */ 0098 virtual int playCount() const; 0099 0100 /** 0101 * Return play count on device since it has been last connected to a computer. 0102 * This number is _already_ _included_ in playCount()! Subclasses returning 0103 * nonzero must also implement setPlayCount() and setting play count must 0104 * reset recent playcount to 0. Default implementation returns 0. 0105 */ 0106 virtual int recentPlayCount() const; 0107 0108 /** 0109 * Set play count. If you touch more fields, consider using 0110 * @see beginUpdate(), @see endUpdate() 0111 */ 0112 virtual void setPlayCount( int newPlayCount ); 0113 0114 /** 0115 * If you call multiple set*() methods, enclose the calls in beginUpdate() ... 0116 * endUpdate(); to allow more efficient processing. 0117 */ 0118 virtual void beginUpdate(); 0119 0120 /** 0121 * If you call multiple set*() methods, enclose the calls in beginUpdate() ... 0122 * endUpdate(); to allow more efficient processing. 0123 */ 0124 virtual void endUpdate(); 0125 }; 0126 0127 typedef AmarokSharedPointer<Statistics> StatisticsPtr; 0128 typedef AmarokSharedPointer<const Statistics> ConstStatisticsPtr; 0129 } 0130 0131 #endif // META_STATISTICS_H