| 1 |
/**************************************************************************************** |
| 2 |
* Copyright (c) 2013 Konrad Zemek <[email protected]> * |
| 3 |
* * |
| 4 |
* This program is free software; you can redistribute it and/or modify it under * |
| 5 |
* the terms of the GNU General Public License as published by the Free Software * |
| 6 |
* Foundation; either version 2 of the License, or (at your option) any later * |
| 7 |
* version. * |
| 8 |
* * |
| 9 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY * |
| 10 |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * |
| 11 |
* PARTICULAR PURPOSE. See the GNU General Public License for more details. * |
| 12 |
* * |
| 13 |
* You should have received a copy of the GNU General Public License along with * |
| 14 |
* this program. If not, see <http://www.gnu.org/licenses/>. * |
| 15 |
****************************************************************************************/ |
| 16 |
|
| 17 |
#include "BansheeTrack.h" |
| 18 |
|
| 19 |
#include "importers/ImporterSqlConnection.h" |
| 20 |
|
| 21 |
#include <QStringList> |
| 22 |
|
| 23 |
using namespace StatSyncing; |
| 24 |
|
| 25 |
BansheeTrack::BansheeTrack( const qint64 trackId, |
| 26 |
const ImporterSqlConnectionPtr &connection, |
| 27 |
const Meta::FieldHash &metadata ) |
| 28 |
: SimpleWritableTrack( metadata ) |
| 29 |
, m_connection( connection ) |
| 30 |
, m_trackId( trackId ) |
| 31 |
{ |
| 32 |
} |
| 33 |
|
| 34 |
BansheeTrack::~BansheeTrack() |
| 35 |
{ |
| 36 |
} |
| 37 |
|
| 38 |
int |
| 39 |
BansheeTrack::rating() const |
| 40 |
{ |
| 41 |
return SimpleWritableTrack::rating() * 2; |
| 42 |
} |
| 43 |
|
| 44 |
void |
| 45 |
BansheeTrack::setRating( int rating ) |
| 46 |
{ |
| 47 |
SimpleWritableTrack::setRating( (rating + 1) / 2 ); |
| 48 |
} |
| 49 |
|
| 50 |
void |
| 51 |
BansheeTrack::doCommit( const qint64 fields ) |
| 52 |
{ |
| 53 |
QStringList updates; |
| 54 |
QVariantMap bindValues; |
| 55 |
if( fields & Meta::valLastPlayed ) |
| 56 |
{ |
| 57 |
updates << QStringLiteral("LastPlayedStamp = :lastplayed"); |
| 58 |
bindValues.insert( QStringLiteral(":lastplayed"), m_statistics.value( Meta::valLastPlayed ) ); |
| 59 |
} |
| 60 |
if( fields & Meta::valRating ) |
| 61 |
{ |
| 62 |
updates << QStringLiteral("Rating = :rating"); |
| 63 |
bindValues.insert( QStringLiteral(":rating"), m_statistics.value( Meta::valRating ) ); |
| 64 |
} |
| 65 |
if( fields & Meta::valPlaycount ) |
| 66 |
{ |
| 67 |
updates << QStringLiteral("PlayCount = :playcount"); |
| 68 |
bindValues.insert( QStringLiteral(":playcount"), m_statistics.value( Meta::valPlaycount ) ); |
| 69 |
} |
| 70 |
|
| 71 |
if( !updates.empty() ) |
| 72 |
{ |
| 73 |
const QString query = QStringLiteral("UPDATE coretracks SET ") + updates.join(QStringLiteral(", ")) + |
| 74 |
QStringLiteral(" WHERE TrackID = :id"); |
| 75 |
|
| 76 |
bindValues.insert( QStringLiteral(":id"), m_trackId ); |
| 77 |
m_connection->query( query, bindValues ); |
| 78 |
} |
| 79 |
} |