1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +02:00

* Use new DbCmd interfaces.

This commit is contained in:
Christian Muehlhaeuser
2013-04-22 09:25:28 +02:00
parent 0bde2a5521
commit e905a4b617
6 changed files with 59 additions and 42 deletions

View File

@@ -181,10 +181,7 @@ PlaylistInterface::filterTracks( const QList<Tomahawk::query_ptr>& queries )
if ( picked ) if ( picked )
{ {
query_ptr q = Query::get( q1->artist(), q1->track(), q1->album(), uuid(), false ); result << q1;
q->setAlbumPos( q1->results().first()->albumpos() );
q->setDiscNumber( q1->discnumber() );
result << q;
} }
} }
@@ -222,7 +219,7 @@ PlaylistInterface::onItemsChanged()
Tomahawk::result_ptr nextResult = siblingResult( 1, m_currentIndex ); Tomahawk::result_ptr nextResult = siblingResult( 1, m_currentIndex );
{ {
bool avail = prevResult && prevResult->toQuery()->playable(); bool avail = prevResult && prevResult->playable();
if ( avail != m_prevAvail ) if ( avail != m_prevAvail )
{ {
m_prevAvail = avail; m_prevAvail = avail;
@@ -231,7 +228,7 @@ PlaylistInterface::onItemsChanged()
} }
{ {
bool avail = nextResult && nextResult->toQuery()->playable(); bool avail = nextResult && nextResult->playable();
if ( avail != m_nextAvail ) if ( avail != m_nextAvail )
{ {
m_nextAvail = avail; m_nextAvail = avail;

View File

@@ -152,13 +152,13 @@ LastFmConfig::onHistoryLoaded()
foreach ( lastfm::XmlQuery e, lfm.children( "track" ) ) foreach ( lastfm::XmlQuery e, lfm.children( "track" ) )
{ {
// tDebug() << "Found:" << e.children( "artist" ).first()["name"].text() << e["name"].text() << e["date"].attribute( "uts" ).toUInt(); // tDebug() << "Found:" << e.children( "artist" ).first()["name"].text() << e["name"].text() << e["date"].attribute( "uts" ).toUInt();
Tomahawk::query_ptr query = Tomahawk::Query::get( e.children( "artist" ).first()["name"].text(), e["name"].text(), QString(), QString(), false ); Tomahawk::track_ptr track = Tomahawk::Track::get( e.children( "artist" ).first()["name"].text(), e["name"].text(), QString() );
if ( query.isNull() ) if ( !track )
continue; continue;
m_lastTimeStamp = e["date"].attribute( "uts" ).toUInt(); m_lastTimeStamp = e["date"].attribute( "uts" ).toUInt();
DatabaseCommand_LogPlayback* cmd = new DatabaseCommand_LogPlayback( query, DatabaseCommand_LogPlayback::Finished, m_lastTimeStamp ); DatabaseCommand_LogPlayback* cmd = new DatabaseCommand_LogPlayback( track, DatabaseCommand_LogPlayback::Finished, 0, m_lastTimeStamp );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) ); Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
} }
@@ -297,11 +297,11 @@ LastFmConfig::onLovedFinished( QNetworkReply* reply )
foreach ( lastfm::XmlQuery e, loved.children( "track" ) ) foreach ( lastfm::XmlQuery e, loved.children( "track" ) )
{ {
tDebug() << "Found:" << e.children( "artist" ).first()["name"].text() << e["name"].text() << e["date"].attribute( "uts" ).toUInt(); tDebug() << "Found:" << e.children( "artist" ).first()["name"].text() << e["name"].text() << e["date"].attribute( "uts" ).toUInt();
Tomahawk::query_ptr query = Tomahawk::Query::get( e.children( "artist" ).first()["name"].text(), e["name"].text(), QString(), QString(), false ); Tomahawk::track_ptr track = Tomahawk::Track::get( e.children( "artist" ).first()["name"].text(), e["name"].text(), QString() );
if ( query.isNull() ) if ( track.isNull() )
continue; continue;
m_lastfmLoved.insert( query ); m_lastfmLoved.insert( track );
} }
if ( thisPage == m_totalLovedPages ) if ( thisPage == m_totalLovedPages )
@@ -335,7 +335,8 @@ LastFmConfig::onLovedFinished( QNetworkReply* reply )
} }
bool trackEquality( const Tomahawk::query_ptr& first, const Tomahawk::query_ptr& second ) bool
trackEquality( const Tomahawk::track_ptr& first, const Tomahawk::track_ptr& second )
{ {
qDebug() << "Comparing:" << first->track() << second->track(); qDebug() << "Comparing:" << first->track() << second->track();
qDebug() << "==========" << first->artist() << second->artist(); qDebug() << "==========" << first->artist() << second->artist();
@@ -357,15 +358,15 @@ LastFmConfig::localLovedLoaded( DatabaseCommand_LoadSocialActions::TrackActions
void void
LastFmConfig::syncLoved() LastFmConfig::syncLoved()
{ {
QSet< Tomahawk::query_ptr > localToLove, lastFmToLove, lastFmToUnlove; QSet< Tomahawk::track_ptr > localToLove, lastFmToLove, lastFmToUnlove;
const QSet< Tomahawk::query_ptr > myLoved = m_localLoved.keys().toSet(); const QSet< Tomahawk::track_ptr > myLoved = m_localLoved.keys().toSet();
m_ui->progressBar->setValue( m_ui->progressBar->value() + 1 ); m_ui->progressBar->setValue( m_ui->progressBar->value() + 1 );
foreach ( const Tomahawk::query_ptr& lastfmLoved, m_lastfmLoved ) foreach ( const Tomahawk::track_ptr& lastfmLoved, m_lastfmLoved )
{ {
QSet< Tomahawk::query_ptr >::const_iterator iter = std::find_if( myLoved.begin(), myLoved.end(), boost::bind( &trackEquality, _1, boost::ref( lastfmLoved ) ) ); QSet< Tomahawk::track_ptr >::const_iterator iter = std::find_if( myLoved.begin(), myLoved.end(), boost::bind( &trackEquality, _1, boost::ref( lastfmLoved ) ) );
if ( iter == myLoved.constEnd() ) if ( iter == myLoved.constEnd() )
{ {
// qDebug() << "Found last.fm loved track that we didn't have loved locally:" << lastfmLoved->track() << lastfmLoved->artist(); // qDebug() << "Found last.fm loved track that we didn't have loved locally:" << lastfmLoved->track() << lastfmLoved->artist();
@@ -373,10 +374,10 @@ LastFmConfig::syncLoved()
} }
} }
foreach ( const Tomahawk::query_ptr& localLoved, myLoved ) foreach ( const Tomahawk::track_ptr& localLoved, myLoved )
{ {
qDebug() << "CHECKING FOR LOCAL LOVED ON LAST.FM TOO:" << m_localLoved[ localLoved ].value.toString() << localLoved->track() << localLoved->artist(); qDebug() << "CHECKING FOR LOCAL LOVED ON LAST.FM TOO:" << m_localLoved[ localLoved ].value.toString() << localLoved->track() << localLoved->artist();
QSet< Tomahawk::query_ptr >::const_iterator iter = std::find_if( m_lastfmLoved.begin(), m_lastfmLoved.end(), boost::bind( &trackEquality, _1, boost::ref( localLoved ) ) ); QSet< Tomahawk::track_ptr >::const_iterator iter = std::find_if( m_lastfmLoved.begin(), m_lastfmLoved.end(), boost::bind( &trackEquality, _1, boost::ref( localLoved ) ) );
qDebug() << "Result:" << (iter == m_lastfmLoved.constEnd()); qDebug() << "Result:" << (iter == m_lastfmLoved.constEnd());
// If we unloved it locally, but it's still loved on last.fm, unlove it // If we unloved it locally, but it's still loved on last.fm, unlove it
@@ -391,7 +392,7 @@ LastFmConfig::syncLoved()
} }
} }
foreach ( const Tomahawk::query_ptr& track, localToLove ) foreach ( const Tomahawk::track_ptr& track, localToLove )
{ {
// Don't use the infosystem as we don't want to tweet a few hundred times :) // Don't use the infosystem as we don't want to tweet a few hundred times :)
DatabaseCommand_SocialAction* cmd = new DatabaseCommand_SocialAction( track, QString( "Love" ), QString( "true" ) ); DatabaseCommand_SocialAction* cmd = new DatabaseCommand_SocialAction( track, QString( "Love" ), QString( "true" ) );
@@ -400,7 +401,7 @@ LastFmConfig::syncLoved()
lastFmToLove.unite( lastFmToUnlove ); lastFmToLove.unite( lastFmToUnlove );
foreach ( const Tomahawk::query_ptr& track, lastFmToLove ) foreach ( const Tomahawk::track_ptr& track, lastFmToLove )
{ {
lastfm::MutableTrack lfmTrack; lastfm::MutableTrack lfmTrack;
lfmTrack.stamp(); lfmTrack.stamp();

View File

@@ -19,7 +19,7 @@
#ifndef LASTFMCONFIG_H #ifndef LASTFMCONFIG_H
#define LASTFMCONFIG_H #define LASTFMCONFIG_H
#include "Query.h" #include "Track.h"
#include "accounts/AccountConfigWidget.h" #include "accounts/AccountConfigWidget.h"
#include "database/DatabaseCommand_LoadSocialActions.h" #include "database/DatabaseCommand_LoadSocialActions.h"
@@ -74,7 +74,7 @@ private:
int m_totalLovedPages; int m_totalLovedPages;
bool m_doneFetchingLoved, m_doneFetchingLocal; bool m_doneFetchingLoved, m_doneFetchingLocal;
QSet< Tomahawk::query_ptr > m_lastfmLoved; QSet< Tomahawk::track_ptr > m_lastfmLoved;
DatabaseCommand_LoadSocialActions::TrackActions m_localLoved; DatabaseCommand_LoadSocialActions::TrackActions m_localLoved;
}; };

View File

@@ -86,10 +86,10 @@ PlayableItem::PlayableItem( const Tomahawk::query_ptr& query, PlayableItem* pare
{ {
init( parent, row ); init( parent, row );
connect( query.data(), SIGNAL( socialActionsLoaded() ), connect( query->track().data(), SIGNAL( socialActionsLoaded() ),
SIGNAL( dataChanged() ) ); SIGNAL( dataChanged() ) );
connect( query.data(), SIGNAL( updated() ), connect( query->track().data(), SIGNAL( updated() ),
SIGNAL( dataChanged() ) ); SIGNAL( dataChanged() ) );
connect( query.data(), SIGNAL( resultsChanged() ), connect( query.data(), SIGNAL( resultsChanged() ),
@@ -104,10 +104,10 @@ PlayableItem::PlayableItem( const Tomahawk::plentry_ptr& entry, PlayableItem* pa
m_query = entry->query(); m_query = entry->query();
init( parent, row ); init( parent, row );
connect( m_query.data(), SIGNAL( socialActionsLoaded() ), connect( m_query->track().data(), SIGNAL( socialActionsLoaded() ),
SIGNAL( dataChanged() ) ); SIGNAL( dataChanged() ) );
connect( m_query.data(), SIGNAL( updated() ), connect( m_query->track().data(), SIGNAL( updated() ),
SIGNAL( dataChanged() ) ); SIGNAL( dataChanged() ) );
connect( m_query.data(), SIGNAL( resultsChanged() ), connect( m_query.data(), SIGNAL( resultsChanged() ),
@@ -167,11 +167,11 @@ PlayableItem::name() const
} }
else if ( !m_result.isNull() ) else if ( !m_result.isNull() )
{ {
return m_result->track(); return m_result->track()->track();
} }
else if ( !m_query.isNull() ) else if ( !m_query.isNull() )
{ {
return m_query->track(); return m_query->track()->track();
} }
Q_ASSERT( false ); Q_ASSERT( false );
@@ -184,11 +184,11 @@ PlayableItem::artistName() const
{ {
if ( !m_result.isNull() ) if ( !m_result.isNull() )
{ {
return m_result->artist()->name(); return m_result->track()->artist();
} }
else if ( !m_query.isNull() ) else if ( !m_query.isNull() )
{ {
return m_query->artist(); return m_query->track()->artist();
} }
return QString(); return QString();
@@ -198,13 +198,13 @@ PlayableItem::artistName() const
QString QString
PlayableItem::albumName() const PlayableItem::albumName() const
{ {
if ( !m_result.isNull() && !m_result->album().isNull() ) if ( !m_result.isNull() )
{ {
return m_result->album()->name(); return m_result->track()->album();
} }
else if ( !m_query.isNull() ) else if ( !m_query.isNull() )
{ {
return m_query->album(); return m_query->track()->album();
} }
return QString(); return QString();
@@ -222,3 +222,17 @@ PlayableItem::result() const
return m_result; return m_result;
} }
Tomahawk::PlaybackLog
PlayableItem::playbackLog() const
{
return m_playbackLog;
}
void
PlayableItem::setPlaybackLog( const Tomahawk::PlaybackLog& log )
{
m_playbackLog = log;
}

View File

@@ -24,6 +24,7 @@
#include <QPersistentModelIndex> #include <QPersistentModelIndex>
#include <QPixmap> #include <QPixmap>
#include "Track.h"
#include "Typedefs.h" #include "Typedefs.h"
#include "DllMacro.h" #include "DllMacro.h"
@@ -47,6 +48,9 @@ public:
const Tomahawk::plentry_ptr& entry() const { return m_entry; } const Tomahawk::plentry_ptr& entry() const { return m_entry; }
const Tomahawk::result_ptr& result() const; const Tomahawk::result_ptr& result() const;
Tomahawk::PlaybackLog playbackLog() const;
void setPlaybackLog( const Tomahawk::PlaybackLog& log );
PlayableItem* parent() const { return m_parent; } PlayableItem* parent() const { return m_parent; }
bool isPlaying() const { return m_isPlaying; } bool isPlaying() const { return m_isPlaying; }
@@ -81,6 +85,8 @@ private:
PlayableItem* m_parent; PlayableItem* m_parent;
bool m_fetchingMore; bool m_fetchingMore;
bool m_isPlaying; bool m_isPlaying;
Tomahawk::PlaybackLog m_playbackLog;
}; };
#endif // PLAYABLEITEM_H #endif // PLAYABLEITEM_H

View File

@@ -685,8 +685,7 @@ SourceItem::onTracksDropped( const QList< query_ptr >& queries )
{ {
foreach ( const query_ptr& query, queries ) foreach ( const query_ptr& query, queries )
{ {
DatabaseCommand_ShareTrack* cmd = DatabaseCommand_ShareTrack* cmd = new DatabaseCommand_ShareTrack( query->track(), m_source->nodeId() );
new DatabaseCommand_ShareTrack( query, m_source->nodeId() );
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
} }