mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 07:49:42 +01:00
* Correctly sort recently played tracks on Dashboard and filter out irrelevant tracks, which speeds up syncing.
This commit is contained in:
parent
7832dd42b2
commit
e0d63535a6
@ -26,14 +26,16 @@
|
||||
#include "network/servent.h"
|
||||
#include "utils/logger.h"
|
||||
|
||||
#define STARTED_THRESHOLD 600 // Don't advertise tracks older than X seconds as currently playing
|
||||
#define FINISHED_THRESHOLD 10 // Don't store tracks played less than X seconds in the playback log
|
||||
#define SUBMISSION_THRESHOLD 20 // Don't broadcast playback logs when a track was played less than X seconds
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
|
||||
void
|
||||
DatabaseCommand_LogPlayback::postCommitHook()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
connect( this, SIGNAL( trackPlaying( Tomahawk::query_ptr ) ),
|
||||
source().data(), SLOT( onPlaybackStarted( Tomahawk::query_ptr ) ), Qt::QueuedConnection );
|
||||
connect( this, SIGNAL( trackPlayed( Tomahawk::query_ptr ) ),
|
||||
@ -53,13 +55,11 @@ DatabaseCommand_LogPlayback::postCommitHook()
|
||||
|
||||
if ( m_action == Finished )
|
||||
{
|
||||
tDebug( LOGEXTRA ) << Q_FUNC_INFO << " logging finished from source " << source().data()->id();
|
||||
emit trackPlayed( q );
|
||||
}
|
||||
// if the play time is more than 10 minutes in the past, ignore
|
||||
else if ( m_action == Started && QDateTime::fromTime_t( playtime() ).secsTo( QDateTime::currentDateTime() ) < 600 )
|
||||
else if ( m_action == Started && QDateTime::fromTime_t( playtime() ).secsTo( QDateTime::currentDateTime() ) < STARTED_THRESHOLD )
|
||||
{
|
||||
tDebug( LOGEXTRA ) << Q_FUNC_INFO << " logging started from source " << source().data()->id();
|
||||
emit trackPlaying( q );
|
||||
}
|
||||
|
||||
@ -73,12 +73,11 @@ DatabaseCommand_LogPlayback::postCommitHook()
|
||||
void
|
||||
DatabaseCommand_LogPlayback::exec( DatabaseImpl* dbi )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
Q_ASSERT( !source().isNull() );
|
||||
|
||||
if ( m_action != Finished )
|
||||
return;
|
||||
if ( m_secsPlayed < 10 )
|
||||
if ( m_secsPlayed < FINISHED_THRESHOLD )
|
||||
return;
|
||||
|
||||
TomahawkSqlQuery query = dbi->newquery();
|
||||
@ -86,9 +85,7 @@ DatabaseCommand_LogPlayback::exec( DatabaseImpl* dbi )
|
||||
"VALUES (?, ?, ?, ?)" );
|
||||
|
||||
QVariant srcid = source()->isLocal() ? QVariant( QVariant::Int ) : source()->id();
|
||||
|
||||
qDebug() << "Logging playback of" << m_artist << "-" << m_track << "for source" << srcid;
|
||||
|
||||
query.bindValue( 0, srcid );
|
||||
|
||||
bool autoCreate = true;
|
||||
@ -113,7 +110,7 @@ bool
|
||||
DatabaseCommand_LogPlayback::localOnly() const
|
||||
{
|
||||
if ( m_action == Finished )
|
||||
return m_secsPlayed < 20;
|
||||
return m_secsPlayed < SUBMISSION_THRESHOLD;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ Source::Source( int id, const QString& username )
|
||||
, m_online( false )
|
||||
, m_username( username )
|
||||
, m_id( id )
|
||||
, m_state( DBSyncConnection::UNKNOWN )
|
||||
, m_cc( 0 )
|
||||
, m_avatar( 0 )
|
||||
, m_fancyAvatar( 0 )
|
||||
@ -256,6 +257,7 @@ Source::onStateChanged( DBSyncConnection::State newstate, DBSyncConnection::Stat
|
||||
msg = QString();
|
||||
}
|
||||
|
||||
m_state = newstate;
|
||||
m_textStatus = msg;
|
||||
emit stateChanged();
|
||||
}
|
||||
@ -301,6 +303,7 @@ Source::onPlaybackFinished( const Tomahawk::query_ptr& query )
|
||||
m_currentTrackTimer.start();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Source::trackTimerFired()
|
||||
{
|
||||
@ -309,6 +312,7 @@ Source::trackTimerFired()
|
||||
emit stateChanged();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Source::reportSocialAttributesChanged( DatabaseCommand_SocialAction* action )
|
||||
{
|
||||
|
@ -77,6 +77,7 @@ public:
|
||||
|
||||
Tomahawk::query_ptr currentTrack() const { return m_currentTrack; }
|
||||
QString textStatus() const { return m_textStatus; }
|
||||
DBSyncConnection::State state() const { return m_state; }
|
||||
|
||||
Tomahawk::playlistinterface_ptr getPlaylistInterface();
|
||||
|
||||
@ -133,6 +134,7 @@ private:
|
||||
|
||||
Tomahawk::query_ptr m_currentTrack;
|
||||
QString m_textStatus;
|
||||
DBSyncConnection::State m_state;
|
||||
QTimer m_currentTrackTimer;
|
||||
|
||||
ControlConnection* m_cc;
|
||||
|
@ -148,7 +148,35 @@ WelcomeWidget::checkQueries()
|
||||
void
|
||||
WelcomeWidget::onPlaybackFinished( const Tomahawk::query_ptr& query )
|
||||
{
|
||||
m_tracksModel->insert( 0, query );
|
||||
int count = m_tracksModel->trackCount();
|
||||
int playtime = query->playedBy().second;
|
||||
|
||||
if ( count )
|
||||
{
|
||||
TrackModelItem* oldestItem = m_tracksModel->itemFromIndex( m_tracksModel->index( count - 1, 0, QModelIndex() ) );
|
||||
if ( oldestItem->query()->playedBy().second >= playtime )
|
||||
return;
|
||||
|
||||
TrackModelItem* youngestItem = m_tracksModel->itemFromIndex( m_tracksModel->index( 0, 0, QModelIndex() ) );
|
||||
if ( youngestItem->query()->playedBy().second <= playtime )
|
||||
m_tracksModel->insert( 0, query );
|
||||
else
|
||||
{
|
||||
for ( int i = 0; i < count - 1; i++ )
|
||||
{
|
||||
TrackModelItem* item1 = m_tracksModel->itemFromIndex( m_tracksModel->index( i, 0, QModelIndex() ) );
|
||||
TrackModelItem* item2 = m_tracksModel->itemFromIndex( m_tracksModel->index( i + 1, 0, QModelIndex() ) );
|
||||
|
||||
if ( item1->query()->playedBy().second >= playtime && item2->query()->playedBy().second <= playtime )
|
||||
{
|
||||
m_tracksModel->insert( i + 1, query );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
m_tracksModel->insert( 0, query );
|
||||
|
||||
if ( m_tracksModel->trackCount() > HISTORY_TRACK_ITEMS )
|
||||
m_tracksModel->remove( HISTORY_TRACK_ITEMS );
|
||||
@ -162,8 +190,6 @@ WelcomeWidget::onPlaybackFinished( const Tomahawk::query_ptr& query )
|
||||
void
|
||||
WelcomeWidget::onPlaylistActivated( const QModelIndex& item )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
Tomahawk::playlist_ptr pl = item.data( RecentlyPlayedPlaylistsModel::PlaylistRole ).value< Tomahawk::playlist_ptr >();
|
||||
if( Tomahawk::dynplaylist_ptr dynplaylist = pl.dynamicCast< Tomahawk::DynamicPlaylist >() )
|
||||
ViewManager::instance()->show( dynplaylist );
|
||||
|
@ -396,7 +396,8 @@ SourceDelegate::editorEvent ( QEvent* event, QAbstractItemModel* model, const QS
|
||||
|
||||
if ( r.contains( ev->pos() ) )
|
||||
gpi->removeFromList();
|
||||
} else if ( type == SourcesModel::Collection )
|
||||
}
|
||||
else if ( type == SourcesModel::Collection )
|
||||
{
|
||||
CollectionItem* colItem = qobject_cast< CollectionItem* >( index.data( SourcesModel::SourceTreeItemRole ).value< SourceTreeItem* >() );
|
||||
Q_ASSERT( colItem );
|
||||
|
Loading…
x
Reference in New Issue
Block a user