mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 11:20:22 +02:00
* Load artist-stats.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
*
|
*
|
||||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
* Copyright 2010-2013, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
|
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
|
||||||
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
|
||||||
*
|
*
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "database/Database.h"
|
#include "database/Database.h"
|
||||||
#include "database/DatabaseImpl.h"
|
#include "database/DatabaseImpl.h"
|
||||||
#include "database/DatabaseCommand_AllAlbums.h"
|
#include "database/DatabaseCommand_AllAlbums.h"
|
||||||
|
#include "database/DatabaseCommand_ArtistStats.h"
|
||||||
#include "database/DatabaseCommand_TrackStats.h"
|
#include "database/DatabaseCommand_TrackStats.h"
|
||||||
#include "database/IdThreadWorker.h"
|
#include "database/IdThreadWorker.h"
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
@@ -42,6 +43,7 @@ QHash< unsigned int, artist_wptr > Artist::s_artistsById = QHash< unsigned int,
|
|||||||
|
|
||||||
static QMutex s_nameCacheMutex;
|
static QMutex s_nameCacheMutex;
|
||||||
static QReadWriteLock s_idMutex;
|
static QReadWriteLock s_idMutex;
|
||||||
|
static QMutex s_memberMutex;
|
||||||
|
|
||||||
|
|
||||||
Artist::~Artist()
|
Artist::~Artist()
|
||||||
@@ -132,6 +134,8 @@ Artist::Artist( unsigned int id, const QString& name )
|
|||||||
, m_simArtistsLoaded( false )
|
, m_simArtistsLoaded( false )
|
||||||
, m_biographyLoaded( false )
|
, m_biographyLoaded( false )
|
||||||
, m_infoJobs( 0 )
|
, m_infoJobs( 0 )
|
||||||
|
, m_chartPosition( 0 )
|
||||||
|
, m_chartCount( 0 )
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
, m_cover( 0 )
|
, m_cover( 0 )
|
||||||
#endif
|
#endif
|
||||||
@@ -185,6 +189,16 @@ Artist::deleteLater()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Artist::onArtistStatsLoaded( unsigned int /* plays */, unsigned int chartPos, unsigned int chartCount )
|
||||||
|
{
|
||||||
|
m_chartPosition = chartPos;
|
||||||
|
m_chartCount = chartCount;
|
||||||
|
|
||||||
|
emit statsLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Artist::onTracksLoaded( Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection )
|
Artist::onTracksLoaded( Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection )
|
||||||
{
|
{
|
||||||
@@ -380,8 +394,16 @@ Artist::loadStats()
|
|||||||
{
|
{
|
||||||
artist_ptr a = m_ownRef.toStrongRef();
|
artist_ptr a = m_ownRef.toStrongRef();
|
||||||
|
|
||||||
DatabaseCommand_TrackStats* cmd = new DatabaseCommand_TrackStats( a );
|
{
|
||||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
DatabaseCommand_TrackStats* cmd = new DatabaseCommand_TrackStats( a );
|
||||||
|
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
DatabaseCommand_ArtistStats* cmd = new DatabaseCommand_ArtistStats( a );
|
||||||
|
connect( cmd, SIGNAL( done( unsigned int, unsigned int, unsigned int ) ), SLOT( onArtistStatsLoaded( unsigned int, unsigned int, unsigned int ) ) );
|
||||||
|
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -405,14 +427,20 @@ Artist::playbackHistory( const Tomahawk::source_ptr& source ) const
|
|||||||
void
|
void
|
||||||
Artist::setPlaybackHistory( const QList< Tomahawk::PlaybackLog >& playbackData )
|
Artist::setPlaybackHistory( const QList< Tomahawk::PlaybackLog >& playbackData )
|
||||||
{
|
{
|
||||||
m_playbackHistory = playbackData;
|
{
|
||||||
|
QMutexLocker locker( &s_memberMutex );
|
||||||
|
m_playbackHistory = playbackData;
|
||||||
|
}
|
||||||
|
|
||||||
emit statsLoaded();
|
emit statsLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
Artist::playbackCount( const source_ptr& source )
|
Artist::playbackCount( const source_ptr& source ) const
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker( &s_memberMutex );
|
||||||
|
|
||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
foreach ( const PlaybackLog& log, m_playbackHistory )
|
foreach ( const PlaybackLog& log, m_playbackHistory )
|
||||||
{
|
{
|
||||||
@@ -424,6 +452,20 @@ Artist::playbackCount( const source_ptr& source )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
Artist::chartPosition() const
|
||||||
|
{
|
||||||
|
return m_chartPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
Artist::chartCount() const
|
||||||
|
{
|
||||||
|
return m_chartCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Artist::onAlbumsFound( const QList< album_ptr >& albums, const QVariant& collectionIsNull )
|
Artist::onAlbumsFound( const QList< album_ptr >& albums, const QVariant& collectionIsNull )
|
||||||
{
|
{
|
||||||
|
@@ -61,7 +61,10 @@ public:
|
|||||||
void loadStats();
|
void loadStats();
|
||||||
QList< Tomahawk::PlaybackLog > playbackHistory( const Tomahawk::source_ptr& source = Tomahawk::source_ptr() ) const;
|
QList< Tomahawk::PlaybackLog > playbackHistory( const Tomahawk::source_ptr& source = Tomahawk::source_ptr() ) const;
|
||||||
void setPlaybackHistory( const QList< Tomahawk::PlaybackLog >& playbackData );
|
void setPlaybackHistory( const QList< Tomahawk::PlaybackLog >& playbackData );
|
||||||
unsigned int playbackCount( const Tomahawk::source_ptr& source = Tomahawk::source_ptr() );
|
unsigned int playbackCount( const Tomahawk::source_ptr& source = Tomahawk::source_ptr() ) const;
|
||||||
|
|
||||||
|
unsigned int chartPosition() const;
|
||||||
|
unsigned int chartCount() const;
|
||||||
|
|
||||||
QString biography() const;
|
QString biography() const;
|
||||||
|
|
||||||
@@ -91,6 +94,7 @@ signals:
|
|||||||
void statsLoaded();
|
void statsLoaded();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void onArtistStatsLoaded( unsigned int plays, unsigned int chartPos, unsigned int chartCount );
|
||||||
void onTracksLoaded( Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection );
|
void onTracksLoaded( Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection );
|
||||||
void onAlbumsFound( const QList<Tomahawk::album_ptr>& albums, const QVariant& collectionIsNull = QVariant( false ) );
|
void onAlbumsFound( const QList<Tomahawk::album_ptr>& albums, const QVariant& collectionIsNull = QVariant( false ) );
|
||||||
|
|
||||||
@@ -124,8 +128,9 @@ private:
|
|||||||
QList<Tomahawk::artist_ptr> m_similarArtists;
|
QList<Tomahawk::artist_ptr> m_similarArtists;
|
||||||
QString m_biography;
|
QString m_biography;
|
||||||
|
|
||||||
bool m_playbackHistoryLoaded;
|
|
||||||
QList< PlaybackLog > m_playbackHistory;
|
QList< PlaybackLog > m_playbackHistory;
|
||||||
|
unsigned int m_chartPosition;
|
||||||
|
unsigned int m_chartCount;
|
||||||
|
|
||||||
mutable QByteArray m_coverBuffer;
|
mutable QByteArray m_coverBuffer;
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
|
68
src/libtomahawk/database/DatabaseCommand_ArtistStats.cpp
Normal file
68
src/libtomahawk/database/DatabaseCommand_ArtistStats.cpp
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2013, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "DatabaseCommand_ArtistStats.h"
|
||||||
|
|
||||||
|
#include "Artist.h"
|
||||||
|
#include "DatabaseImpl.h"
|
||||||
|
#include "SourceList.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
|
||||||
|
DatabaseCommand_ArtistStats::DatabaseCommand_ArtistStats( const artist_ptr& artist, QObject* parent )
|
||||||
|
: DatabaseCommand( parent )
|
||||||
|
, m_artist( artist )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DatabaseCommand_ArtistStats::exec( DatabaseImpl* dbi )
|
||||||
|
{
|
||||||
|
TomahawkSqlQuery query = dbi->newquery();
|
||||||
|
|
||||||
|
query.prepare( "SELECT COUNT(*) AS counter, artist.id "
|
||||||
|
"FROM playback_log, track, artist "
|
||||||
|
"WHERE playback_log.source IS NULL AND track.id = playback_log.track AND artist.id = track.artist "
|
||||||
|
"GROUP BY track.artist "
|
||||||
|
"ORDER BY counter DESC" );
|
||||||
|
query.exec();
|
||||||
|
|
||||||
|
unsigned int plays = 0;
|
||||||
|
unsigned int chartPos = 0;
|
||||||
|
unsigned int chartCount = 0;
|
||||||
|
|
||||||
|
QHash< QString, unsigned int > charts;
|
||||||
|
while ( query.next() )
|
||||||
|
{
|
||||||
|
chartCount++;
|
||||||
|
|
||||||
|
if ( query.value( 1 ).toUInt() == m_artist->id() )
|
||||||
|
{
|
||||||
|
chartPos = chartCount;
|
||||||
|
plays = query.value( 0 ).toUInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( plays == 0 )
|
||||||
|
chartPos = chartCount;
|
||||||
|
|
||||||
|
emit done( plays, chartPos, chartCount );
|
||||||
|
}
|
48
src/libtomahawk/database/DatabaseCommand_ArtistStats.h
Normal file
48
src/libtomahawk/database/DatabaseCommand_ArtistStats.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2012, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DATABASECOMMAND_ARTISTSTATS_H
|
||||||
|
#define DATABASECOMMAND_ARTISTSTATS_H
|
||||||
|
|
||||||
|
#include <QVariantMap>
|
||||||
|
|
||||||
|
#include "DatabaseCommand.h"
|
||||||
|
#include "Typedefs.h"
|
||||||
|
#include "Track.h"
|
||||||
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
class DLLEXPORT DatabaseCommand_ArtistStats : public DatabaseCommand
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DatabaseCommand_ArtistStats( const Tomahawk::artist_ptr& artist, QObject* parent = 0 );
|
||||||
|
|
||||||
|
virtual void exec( DatabaseImpl* lib );
|
||||||
|
virtual bool doesMutates() const { return false; }
|
||||||
|
virtual QString commandname() const { return "artiststats"; }
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void done( unsigned int totalPlays, unsigned int chartPosition, unsigned int chartCount );
|
||||||
|
|
||||||
|
private:
|
||||||
|
Tomahawk::trackdata_ptr m_track;
|
||||||
|
Tomahawk::artist_ptr m_artist;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DATABASECOMMAND_ARTISTSTATS_H
|
Reference in New Issue
Block a user