diff --git a/src/libtomahawk/Track.cpp b/src/libtomahawk/Track.cpp index cdb9a5316..b4068afdd 100644 --- a/src/libtomahawk/Track.cpp +++ b/src/libtomahawk/Track.cpp @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2013, Christian Muehlhaeuser + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,6 +25,7 @@ #include "database/Database.h" #include "database/DatabaseImpl.h" #include "database/DatabaseCommand_LogPlayback.h" +#include "database/DatabaseCommand_ModifyInboxEntry.h" #include "Album.h" #include "collection/Collection.h" #include "Pipeline.h" @@ -169,6 +171,8 @@ Track::startPlaying() DatabaseCommand_LogPlayback* cmd = new DatabaseCommand_LogPlayback( weakRef().toStrongRef(), DatabaseCommand_LogPlayback::Started ); Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); + + } @@ -180,6 +184,33 @@ Track::finishPlaying( int timeElapsed ) timeElapsed ); Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); + bool isUnlistened = false; + foreach ( Tomahawk::SocialAction action, allSocialActions() ) + { + if ( action.action == "Inbox" && action.value.toBool() == true ) + { + isUnlistened = true; + break; + } + } + + if ( isUnlistened ) + { + DatabaseCommand_ModifyInboxEntry* cmd = new DatabaseCommand_ModifyInboxEntry( toQuery(), false ); + Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); + + // The dbcmd does this in the DB, but let's update the TrackData ASAP + QList< Tomahawk::SocialAction > actions = allSocialActions(); + for ( QList< Tomahawk::SocialAction >::iterator it = actions.begin(); + it != actions.end(); ++it ) + { + if ( it->action == "Inbox" ) + { + it->value = false; //listened! + } + } + m_trackData->setAllSocialActions( actions ); //emits socialActionsLoaded which gets propagated here + } } diff --git a/src/libtomahawk/Track.h b/src/libtomahawk/Track.h index 8160cc93d..8d94f011c 100644 --- a/src/libtomahawk/Track.h +++ b/src/libtomahawk/Track.h @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2013, Christian Muehlhaeuser + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/libtomahawk/playlist/InboxModel.cpp b/src/libtomahawk/playlist/InboxModel.cpp index 3e0360d02..aa7173be3 100644 --- a/src/libtomahawk/playlist/InboxModel.cpp +++ b/src/libtomahawk/playlist/InboxModel.cpp @@ -35,9 +35,6 @@ InboxModel::InboxModel( QObject* parent ) else NewClosure( SourceList::instance(), SIGNAL( ready() ), this, SLOT( loadTracks() ) ); - - connect( this, SIGNAL( currentIndexChanged() ), - SLOT( onCurrentIndexChanged() ) ); } @@ -215,8 +212,7 @@ InboxModel::tracksLoaded( QList< Tomahawk::query_ptr > incoming ) QList< Tomahawk::SocialAction > actions; actions << action; - //FIXME -// newQuery->queryTrack()->setAllSocialActions( actions ); + newQuery->queryTrack()->loadSocialActions(); newQuery->setProperty( "data", QVariant() ); //clear } @@ -233,32 +229,3 @@ InboxModel::tracksLoaded( QList< Tomahawk::query_ptr > incoming ) } } - -void -InboxModel::onCurrentIndexChanged() -{ - QPersistentModelIndex idx = currentItem(); - if ( idx.isValid() ) - { - PlayableItem* item = itemFromIndex( idx ); - if ( item && !item->query().isNull() ) - { - Tomahawk::query_ptr qry = item->query(); - DatabaseCommand_ModifyInboxEntry* cmd = new DatabaseCommand_ModifyInboxEntry( qry, false ); - Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); - - QList< Tomahawk::SocialAction > actions = item->query()->queryTrack()->allSocialActions(); - for ( QList< Tomahawk::SocialAction >::iterator it = actions.begin(); - it != actions.end(); ++it ) - { - if ( it->action == "Inbox" ) - { - it->value = false; //listened! - } - } - //FIXME -// item->query()->queryTrack()->setAllSocialActions( actions ); - } - } -} - diff --git a/src/libtomahawk/playlist/InboxModel.h b/src/libtomahawk/playlist/InboxModel.h index 7e50b52f5..0b4f1f57f 100644 --- a/src/libtomahawk/playlist/InboxModel.h +++ b/src/libtomahawk/playlist/InboxModel.h @@ -49,7 +49,6 @@ private slots: void loadTracks(); void tracksLoaded( QList< Tomahawk::query_ptr > ); - void onCurrentIndexChanged(); private: static QList< Tomahawk::SocialAction > mergeSocialActions( QList< Tomahawk::SocialAction > first,