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

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 "BansheeTrack.h"
0018 
0019 #include "importers/ImporterSqlConnection.h"
0020 
0021 #include <QStringList>
0022 
0023 using namespace StatSyncing;
0024 
0025 BansheeTrack::BansheeTrack( const qint64 trackId,
0026                             const ImporterSqlConnectionPtr &connection,
0027                             const Meta::FieldHash &metadata )
0028     : SimpleWritableTrack( metadata )
0029     , m_connection( connection )
0030     , m_trackId( trackId )
0031 {
0032 }
0033 
0034 BansheeTrack::~BansheeTrack()
0035 {
0036 }
0037 
0038 int
0039 BansheeTrack::rating() const
0040 {
0041     return SimpleWritableTrack::rating() * 2;
0042 }
0043 
0044 void
0045 BansheeTrack::setRating( int rating )
0046 {
0047     SimpleWritableTrack::setRating( (rating + 1) / 2 );
0048 }
0049 
0050 void
0051 BansheeTrack::doCommit( const qint64 fields )
0052 {
0053     QStringList updates;
0054     QVariantMap bindValues;
0055     if( fields & Meta::valLastPlayed )
0056     {
0057         updates << "LastPlayedStamp = :lastplayed";
0058         bindValues.insert( ":lastplayed", m_statistics.value( Meta::valLastPlayed ) );
0059     }
0060     if( fields & Meta::valRating )
0061     {
0062         updates << "Rating = :rating";
0063         bindValues.insert( ":rating", m_statistics.value( Meta::valRating ) );
0064     }
0065     if( fields & Meta::valPlaycount )
0066     {
0067         updates << "PlayCount = :playcount";
0068         bindValues.insert( ":playcount", m_statistics.value( Meta::valPlaycount ) );
0069     }
0070 
0071     if( !updates.empty() )
0072     {
0073         const QString query = "UPDATE coretracks SET " + updates.join(", ") +
0074                               " WHERE TrackID = :id";
0075 
0076         bindValues.insert( ":id", m_trackId );
0077         m_connection->query( query, bindValues );
0078     }
0079 }