File indexing completed on 2024-05-19 04:49:45

0001 /****************************************************************************************
0002  * Copyright (c) 2013 Konrad Zemek <konrad.zemek@gmail.com>                             *
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 #include "ITunesTrack.h"
0018 
0019 #include <QReadLocker>
0020 #include <QWriteLocker>
0021 
0022 using namespace StatSyncing;
0023 
0024 ITunesTrack::ITunesTrack( const int trackId, const Meta::FieldHash &metadata )
0025     : SimpleWritableTrack( metadata )
0026     , m_trackId( trackId )
0027 {
0028 }
0029 
0030 ITunesTrack::~ITunesTrack()
0031 {
0032 }
0033 
0034 int
0035 ITunesTrack::rating() const
0036 {
0037     return SimpleWritableTrack::rating() / 10;
0038 }
0039 
0040 void
0041 ITunesTrack::setRating( int rating )
0042 {
0043     if( rating & 1 )
0044         ++rating;
0045 
0046     SimpleWritableTrack::setRating( rating * 10 );
0047 }
0048 
0049 QDateTime
0050 ITunesTrack::lastPlayed() const
0051 {
0052     QReadLocker lock( &m_lock );
0053 
0054     QDateTime date = QDateTime::fromString(
0055                                 m_statistics.value( Meta::valLastPlayed ).toString(),
0056                                 "yyyy'-'MM'-'dd'T'hh':'mm':'ss'Z'" );
0057     if( date.isValid() )
0058         date.setTimeSpec( Qt::UTC );
0059 
0060     return date;
0061 }
0062 
0063 void
0064 ITunesTrack::doCommit( const qint64 changes )
0065 {
0066     Q_UNUSED( changes );
0067     Q_EMIT commitCalled( m_trackId, m_statistics );
0068 }