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

* Fixed TWK-537: Adding social actions for remote sources was broken.

This commit is contained in:
Christian Muehlhaeuser
2011-10-30 06:41:25 +01:00
parent 6c2ed4baed
commit b46af3405e
4 changed files with 34 additions and 23 deletions

View File

@@ -50,7 +50,7 @@ DatabaseCommand_LoadSocialActions::exec( DatabaseImpl* dbi )
return; return;
QString whereToken; QString whereToken;
whereToken = QString( "WHERE id IS %1" ).arg( trkid ); whereToken = QString( "WHERE id IS %1" ).arg( trkid );
QString sql = QString( QString sql = QString(
"SELECT k, v, timestamp, source " "SELECT k, v, timestamp, source "
@@ -66,7 +66,7 @@ DatabaseCommand_LoadSocialActions::exec( DatabaseImpl* dbi )
Tomahawk::SocialAction action; Tomahawk::SocialAction action;
action.action = query.value( 0 ); // action action.action = query.value( 0 ); // action
action.value = query.value( 1 ); // comment action.value = query.value( 1 ); // comment
action.timestamp = query.value( 2 ); // timestamp action.timestamp = query.value( 2 ); // timestamp
action.source = query.value( 3 ); // source action.source = query.value( 3 ); // source
allSocialActions.append( action ); allSocialActions.append( action );

View File

@@ -49,22 +49,17 @@ DatabaseCommand_SocialAction::exec( DatabaseImpl* dbi )
TomahawkSqlQuery query = dbi->newquery(); TomahawkSqlQuery query = dbi->newquery();
QVariant srcid = source()->isLocal() ? QVariant( QVariant::Int ) : source()->id(); QVariant srcid = source()->isLocal() ? QVariant( QVariant::Int ) : source()->id();
int trkid = -2; if ( m_artist.isNull() || m_track.isEmpty() )
if ( !m_result.isNull() && !m_artist.isNull() && !m_track.isEmpty() ) return;
{
bool autoCreate = true;
int artid = dbi->artistId( m_artist, autoCreate );
if ( artid < 1 )
return;
autoCreate = true; // artistId overwrites autoCreate (reference) int artid = dbi->artistId( m_artist, true );
trkid = dbi->trackId( artid, m_track, autoCreate ); if ( artid < 1 )
if ( trkid < 1 ) return;
return; int trkid = dbi->trackId( artid, m_track, true );
} if ( trkid < 1 )
return;
// update if it already exists // update if it already exists
TomahawkSqlQuery find = dbi->newquery(); TomahawkSqlQuery find = dbi->newquery();
@@ -80,12 +75,13 @@ DatabaseCommand_SocialAction::exec( DatabaseImpl* dbi )
.arg( trkid ) .arg( trkid )
.arg( source()->isLocal() ? "IS NULL" : QString( "=%1" ).arg( source()->id() ) ) .arg( source()->isLocal() ? "IS NULL" : QString( "=%1" ).arg( source()->id() ) )
.arg( m_action ) ); .arg( m_action ) );
} else }
else
{ {
query.prepare( "INSERT INTO social_attributes(id, source, k, v, timestamp) " query.prepare( "INSERT INTO social_attributes(id, source, k, v, timestamp) "
"VALUES (?, ?, ?, ?, ?)" ); "VALUES (?, ?, ?, ?, ?)" );
query.bindValue( 0, trkid >= -1 ? trkid : QVariant() ); query.bindValue( 0, trkid );
query.bindValue( 1, srcid ); query.bindValue( 1, srcid );
query.bindValue( 2, m_action ); query.bindValue( 2, m_action );
query.bindValue( 3, m_comment ); query.bindValue( 3, m_comment );

View File

@@ -52,8 +52,11 @@ CustomPlaylistView::CustomPlaylistView( CustomPlaylistView::PlaylistType type, c
} }
} }
CustomPlaylistView::~CustomPlaylistView() CustomPlaylistView::~CustomPlaylistView()
{} {
}
bool bool
CustomPlaylistView::isBeingPlayed() const CustomPlaylistView::isBeingPlayed() const
@@ -61,6 +64,7 @@ CustomPlaylistView::isBeingPlayed() const
return AudioEngine::instance()->currentTrackPlaylist() == playlistInterface(); return AudioEngine::instance()->currentTrackPlaylist() == playlistInterface();
} }
bool bool
CustomPlaylistView::jumpToCurrentTrack() CustomPlaylistView::jumpToCurrentTrack()
{ {
@@ -80,7 +84,7 @@ CustomPlaylistView::generateTracks()
"FROM social_attributes, track, artist " "FROM social_attributes, track, artist "
"WHERE social_attributes.id = track.id AND artist.id = track.artist AND social_attributes.k = 'Love' AND social_attributes.v = 'true' AND social_attributes.source %1 " "WHERE social_attributes.id = track.id AND artist.id = track.artist AND social_attributes.k = 'Love' AND social_attributes.v = 'true' AND social_attributes.source %1 "
"GROUP BY track.id " "GROUP BY track.id "
"ORDER BY counter DESC, social_attributes.timestamp DESC " ).arg( m_source->isLocal() ? "IS NULL" : QString( "=%1" ).arg( m_source->id() ) ); "ORDER BY counter DESC, social_attributes.timestamp DESC " ).arg( m_source->isLocal() ? "IS NULL" : QString( "= %1" ).arg( m_source->id() ) );
break; break;
case AllLovedTracks: case AllLovedTracks:
sql = QString( "SELECT track.name, artist.name, source, COUNT(*) as counter " sql = QString( "SELECT track.name, artist.name, source, COUNT(*) as counter "
@@ -96,6 +100,7 @@ CustomPlaylistView::generateTracks()
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) ); Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
} }
void void
CustomPlaylistView::tracksGenerated( QList< query_ptr > tracks ) CustomPlaylistView::tracksGenerated( QList< query_ptr > tracks )
{ {
@@ -103,6 +108,7 @@ CustomPlaylistView::tracksGenerated( QList< query_ptr > tracks )
m_model->append( q ); m_model->append( q );
} }
QString QString
CustomPlaylistView::title() const CustomPlaylistView::title() const
{ {
@@ -132,18 +138,21 @@ CustomPlaylistView::description() const
} }
} }
QString QString
CustomPlaylistView::longDescription() const CustomPlaylistView::longDescription() const
{ {
return QString(); return QString();
} }
QPixmap QPixmap
CustomPlaylistView::pixmap() const CustomPlaylistView::pixmap() const
{ {
return QPixmap( RESPATH "images/loved_playlist.png" ); return QPixmap( RESPATH "images/loved_playlist.png" );
} }
void void
CustomPlaylistView::reload() CustomPlaylistView::reload()
{ {
@@ -153,7 +162,7 @@ CustomPlaylistView::reload()
void void
CustomPlaylistView::sourceAdded( const source_ptr& s) CustomPlaylistView::sourceAdded( const source_ptr& s )
{ {
connect( s.data(), SIGNAL( socialAttributesChanged() ), this, SLOT( reload() ) ); connect( s.data(), SIGNAL( socialAttributesChanged() ), this, SLOT( reload() ) );
} }

View File

@@ -115,8 +115,11 @@ SourceTreeView::SourceTreeView( QWidget* parent )
connect( this, SIGNAL( catchUpRequest() ), m_latchManager, SLOT( catchUpRequest() ) ); connect( this, SIGNAL( catchUpRequest() ), m_latchManager, SLOT( catchUpRequest() ) );
} }
SourceTreeView::~SourceTreeView() SourceTreeView::~SourceTreeView()
{} {
}
void void
SourceTreeView::setupMenus() SourceTreeView::setupMenus()
@@ -151,7 +154,7 @@ SourceTreeView::setupMenus()
m_latchOnAction->setText( tr( "&Catch Up" ) ); m_latchOnAction->setText( tr( "&Catch Up" ) );
m_latchMenu.addSeparator(); m_latchMenu.addSeparator();
m_latchOffAction = m_latchMenu.addAction( tr( "&Stop Listening Along" ) ); m_latchOffAction = m_latchMenu.addAction( tr( "&Stop Listening Along" ) );
connect( m_latchOffAction, SIGNAL( triggered() ), SLOT( latchOff() ) ); connect( m_latchOffAction, SIGNAL( triggered() ), SLOT( latchOff() ) );
} }
} }
} }
@@ -231,6 +234,7 @@ SourceTreeView::selectRequest( const QPersistentModelIndex& idx )
} }
} }
void void
SourceTreeView::expandRequest( const QPersistentModelIndex &idx ) SourceTreeView::expandRequest( const QPersistentModelIndex &idx )
{ {
@@ -245,6 +249,7 @@ SourceTreeView::loadPlaylist()
onItemActivated( m_contextMenuIndex ); onItemActivated( m_contextMenuIndex );
} }
void void
SourceTreeView::deletePlaylist( const QModelIndex& idxIn ) SourceTreeView::deletePlaylist( const QModelIndex& idxIn )
{ {
@@ -353,6 +358,7 @@ SourceTreeView::latchOnOrCatchUp()
emit latchRequest( source ); emit latchRequest( source );
} }
void void
SourceTreeView::latchOff() SourceTreeView::latchOff()
{ {