mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
* Added similar tracks and playback history methods to Query.
This commit is contained in:
@@ -24,10 +24,10 @@
|
|||||||
#include "database/Database.h"
|
#include "database/Database.h"
|
||||||
#include "database/DatabaseImpl.h"
|
#include "database/DatabaseImpl.h"
|
||||||
#include "database/DatabaseCommand_LogPlayback.h"
|
#include "database/DatabaseCommand_LogPlayback.h"
|
||||||
#include "database/DatabaseCommand_PlaybackHistory.h"
|
|
||||||
#include "database/DatabaseCommand_LoadPlaylistEntries.h"
|
#include "database/DatabaseCommand_LoadPlaylistEntries.h"
|
||||||
#include "database/DatabaseCommand_LoadSocialActions.h"
|
#include "database/DatabaseCommand_LoadSocialActions.h"
|
||||||
#include "database/DatabaseCommand_SocialAction.h"
|
#include "database/DatabaseCommand_SocialAction.h"
|
||||||
|
#include "database/DatabaseCommand_TrackStats.h"
|
||||||
#include "Album.h"
|
#include "Album.h"
|
||||||
#include "Collection.h"
|
#include "Collection.h"
|
||||||
#include "Pipeline.h"
|
#include "Pipeline.h"
|
||||||
@@ -74,6 +74,8 @@ Query::Query( const QString& artist, const QString& track, const QString& album,
|
|||||||
, m_album( album )
|
, m_album( album )
|
||||||
, m_track( track )
|
, m_track( track )
|
||||||
, m_socialActionsLoaded( false )
|
, m_socialActionsLoaded( false )
|
||||||
|
, m_simTracksLoaded( false )
|
||||||
|
, m_infoJobs( 0 )
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
|
|
||||||
@@ -505,6 +507,55 @@ Query::playedBy() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Query::loadStats()
|
||||||
|
{
|
||||||
|
query_ptr q = m_ownRef.toStrongRef();
|
||||||
|
|
||||||
|
DatabaseCommand_TrackStats* cmd = new DatabaseCommand_TrackStats( q );
|
||||||
|
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QList< Tomahawk::PlaybackLog >
|
||||||
|
Query::playbackHistory( const Tomahawk::source_ptr& source ) const
|
||||||
|
{
|
||||||
|
QList< Tomahawk::PlaybackLog > history;
|
||||||
|
|
||||||
|
foreach ( const PlaybackLog& log, m_playbackHistory )
|
||||||
|
{
|
||||||
|
if ( source.isNull() || log.source == source )
|
||||||
|
{
|
||||||
|
history << log;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return history;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Query::setPlaybackHistory( const QList< Tomahawk::PlaybackLog >& playbackData )
|
||||||
|
{
|
||||||
|
m_playbackHistory = playbackData;
|
||||||
|
emit statsLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
Query::playbackCount( const source_ptr& source )
|
||||||
|
{
|
||||||
|
unsigned int count = 0;
|
||||||
|
foreach ( const PlaybackLog& log, m_playbackHistory )
|
||||||
|
{
|
||||||
|
if ( source.isNull() || log.source == source )
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Query::loadSocialActions()
|
Query::loadSocialActions()
|
||||||
{
|
{
|
||||||
@@ -512,24 +563,17 @@ Query::loadSocialActions()
|
|||||||
query_ptr q = m_ownRef.toStrongRef();
|
query_ptr q = m_ownRef.toStrongRef();
|
||||||
|
|
||||||
DatabaseCommand_LoadSocialActions* cmd = new DatabaseCommand_LoadSocialActions( q );
|
DatabaseCommand_LoadSocialActions* cmd = new DatabaseCommand_LoadSocialActions( q );
|
||||||
connect( cmd, SIGNAL( finished() ), SLOT( onSocialActionsLoaded() ) );
|
|
||||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Query::onSocialActionsLoaded()
|
|
||||||
{
|
|
||||||
parseSocialActions();
|
|
||||||
|
|
||||||
emit socialActionsLoaded();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Query::setAllSocialActions( const QList< SocialAction >& socialActions )
|
Query::setAllSocialActions( const QList< SocialAction >& socialActions )
|
||||||
{
|
{
|
||||||
m_allSocialActions = socialActions;
|
m_allSocialActions = socialActions;
|
||||||
|
parseSocialActions();
|
||||||
|
|
||||||
|
emit socialActionsLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -690,7 +734,7 @@ Query::cover( const QSize& size, bool forceLoad ) const
|
|||||||
if ( !m_albumPtr->cover( size ).isNull() )
|
if ( !m_albumPtr->cover( size ).isNull() )
|
||||||
return m_albumPtr->cover( size );
|
return m_albumPtr->cover( size );
|
||||||
|
|
||||||
return m_artistPtr->cover( size );
|
return m_artistPtr->cover( size, forceLoad );
|
||||||
}
|
}
|
||||||
|
|
||||||
return QPixmap();
|
return QPixmap();
|
||||||
@@ -698,6 +742,92 @@ Query::cover( const QSize& size, bool forceLoad ) const
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
QList<Tomahawk::query_ptr>
|
||||||
|
Query::similarTracks() const
|
||||||
|
{
|
||||||
|
if ( !m_simTracksLoaded )
|
||||||
|
{
|
||||||
|
Tomahawk::InfoSystem::InfoStringHash trackInfo;
|
||||||
|
trackInfo["artist"] = artist();
|
||||||
|
trackInfo["track"] = track();
|
||||||
|
|
||||||
|
Tomahawk::InfoSystem::InfoRequestData requestData;
|
||||||
|
requestData.caller = id();
|
||||||
|
requestData.customData = QVariantMap();
|
||||||
|
|
||||||
|
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo );
|
||||||
|
requestData.type = Tomahawk::InfoSystem::InfoTrackSimilars;
|
||||||
|
requestData.requestId = TomahawkUtils::infosystemRequestId();
|
||||||
|
|
||||||
|
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
|
||||||
|
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
|
||||||
|
SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), Qt::UniqueConnection );
|
||||||
|
|
||||||
|
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
|
||||||
|
SIGNAL( finished( QString ) ),
|
||||||
|
SLOT( infoSystemFinished( QString ) ), Qt::UniqueConnection );
|
||||||
|
|
||||||
|
m_infoJobs++;
|
||||||
|
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_similarTracks;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Query::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
|
||||||
|
{
|
||||||
|
if ( requestData.caller != id() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QVariantMap returnedData = output.value< QVariantMap >();
|
||||||
|
switch ( requestData.type )
|
||||||
|
{
|
||||||
|
case InfoSystem::InfoTrackSimilars:
|
||||||
|
{
|
||||||
|
const QStringList artists = returnedData["artists"].toStringList();
|
||||||
|
const QStringList tracks = returnedData["tracks"].toStringList();
|
||||||
|
|
||||||
|
for ( int i = 0; i < tracks.count() && i < 50; i++ )
|
||||||
|
{
|
||||||
|
m_similarTracks << Query::get( artists.at( i ), tracks.at( i ), QString(), uuid(), true );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_simTracksLoaded = true;
|
||||||
|
emit similarTracksLoaded();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
Q_ASSERT( false );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Query::infoSystemFinished( QString target )
|
||||||
|
{
|
||||||
|
tDebug() << Q_FUNC_INFO;
|
||||||
|
Q_UNUSED( target );
|
||||||
|
|
||||||
|
if ( target != id() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( --m_infoJobs == 0 )
|
||||||
|
{
|
||||||
|
disconnect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
|
||||||
|
this, SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) );
|
||||||
|
|
||||||
|
disconnect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ),
|
||||||
|
this, SLOT( infoSystemFinished( QString ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
emit updated();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
Query::levenshtein( const QString& source, const QString& target )
|
Query::levenshtein( const QString& source, const QString& target )
|
||||||
{
|
{
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
#include "Result.h"
|
#include "Result.h"
|
||||||
|
#include "infosystem/InfoSystem.h"
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
@@ -39,6 +40,22 @@ namespace Tomahawk
|
|||||||
|
|
||||||
class Resolver;
|
class Resolver;
|
||||||
|
|
||||||
|
struct SocialAction
|
||||||
|
{
|
||||||
|
QVariant action;
|
||||||
|
QVariant value;
|
||||||
|
QVariant timestamp;
|
||||||
|
Tomahawk::source_ptr source;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PlaybackLog
|
||||||
|
{
|
||||||
|
Tomahawk::source_ptr source;
|
||||||
|
unsigned int timestamp;
|
||||||
|
unsigned int secsPlayed;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class DLLEXPORT Query : public QObject
|
class DLLEXPORT Query : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -119,11 +136,18 @@ public:
|
|||||||
void setLoved( bool loved );
|
void setLoved( bool loved );
|
||||||
bool loved();
|
bool loved();
|
||||||
|
|
||||||
|
void loadStats();
|
||||||
|
QList< Tomahawk::PlaybackLog > playbackHistory( const Tomahawk::source_ptr& source = Tomahawk::source_ptr() ) const;
|
||||||
|
void setPlaybackHistory( const QList< Tomahawk::PlaybackLog >& playbackData );
|
||||||
|
unsigned int playbackCount( const Tomahawk::source_ptr& source = Tomahawk::source_ptr() );
|
||||||
|
|
||||||
void loadSocialActions();
|
void loadSocialActions();
|
||||||
QList< Tomahawk::SocialAction > allSocialActions() const;
|
QList< Tomahawk::SocialAction > allSocialActions() const;
|
||||||
void setAllSocialActions( const QList< Tomahawk::SocialAction >& socialActions );
|
void setAllSocialActions( const QList< Tomahawk::SocialAction >& socialActions );
|
||||||
QString socialActionDescription( const QString& action, DescriptionMode mode ) const;
|
QString socialActionDescription( const QString& action, DescriptionMode mode ) const;
|
||||||
|
|
||||||
|
QList<Tomahawk::query_ptr> similarTracks() const;
|
||||||
|
|
||||||
QWeakPointer< Tomahawk::Query > weakRef() { return m_ownRef; }
|
QWeakPointer< Tomahawk::Query > weakRef() { return m_ownRef; }
|
||||||
void setWeakRef( QWeakPointer< Tomahawk::Query > weakRef ) { m_ownRef = weakRef; }
|
void setWeakRef( QWeakPointer< Tomahawk::Query > weakRef ) { m_ownRef = weakRef; }
|
||||||
|
|
||||||
@@ -141,8 +165,9 @@ signals:
|
|||||||
|
|
||||||
void coverChanged();
|
void coverChanged();
|
||||||
|
|
||||||
// emitted when social actions are loaded
|
|
||||||
void socialActionsLoaded();
|
void socialActionsLoaded();
|
||||||
|
void statsLoaded();
|
||||||
|
void similarTracksLoaded();
|
||||||
void updated();
|
void updated();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
@@ -160,9 +185,11 @@ public slots:
|
|||||||
void onResolverRemoved();
|
void onResolverRemoved();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
||||||
|
void infoSystemFinished( QString target );
|
||||||
|
|
||||||
void onResultStatusChanged();
|
void onResultStatusChanged();
|
||||||
void refreshResults();
|
void refreshResults();
|
||||||
void onSocialActionsLoaded();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Query();
|
Query();
|
||||||
@@ -211,12 +238,19 @@ private:
|
|||||||
QList< QWeakPointer< Tomahawk::Resolver > > m_resolvers;
|
QList< QWeakPointer< Tomahawk::Resolver > > m_resolvers;
|
||||||
|
|
||||||
mutable QMutex m_mutex;
|
mutable QMutex m_mutex;
|
||||||
|
|
||||||
QWeakPointer< Tomahawk::Query > m_ownRef;
|
QWeakPointer< Tomahawk::Query > m_ownRef;
|
||||||
|
|
||||||
|
bool m_playbackHistoryLoaded;
|
||||||
|
QList< PlaybackLog > m_playbackHistory;
|
||||||
|
|
||||||
bool m_socialActionsLoaded;
|
bool m_socialActionsLoaded;
|
||||||
QHash< QString, QVariant > m_currentSocialActions;
|
QHash< QString, QVariant > m_currentSocialActions;
|
||||||
QList< SocialAction > m_allSocialActions;
|
QList< SocialAction > m_allSocialActions;
|
||||||
|
|
||||||
|
bool m_simTracksLoaded;
|
||||||
|
QList<Tomahawk::query_ptr> m_similarTracks;
|
||||||
|
|
||||||
|
mutable int m_infoJobs;
|
||||||
};
|
};
|
||||||
|
|
||||||
}; //ns
|
}; //ns
|
||||||
|
Reference in New Issue
Block a user