1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-13 09:34:53 +02:00

* Group Dashboard by sources.

This commit is contained in:
Christian Muehlhaeuser
2014-08-15 05:35:07 +02:00
parent 6f19e87436
commit f7246b5830
2 changed files with 45 additions and 17 deletions

View File

@@ -1,6 +1,6 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2012, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2014, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -35,7 +35,7 @@ using namespace Tomahawk;
RecentlyPlayedModel::RecentlyPlayedModel( QObject* parent, unsigned int maxItems ) RecentlyPlayedModel::RecentlyPlayedModel( QObject* parent, unsigned int maxItems )
: PlaylistModel( parent ) : PlayableModel( parent )
, m_limit( maxItems > 0 ? maxItems : HISTORY_TRACK_ITEMS ) , m_limit( maxItems > 0 ? maxItems : HISTORY_TRACK_ITEMS )
{ {
} }
@@ -61,7 +61,7 @@ RecentlyPlayedModel::loadHistory()
cmd->setLimit( m_limit ); cmd->setLimit( m_limit );
connect( cmd, SIGNAL( tracks( QList<Tomahawk::track_ptr>, QList<Tomahawk::PlaybackLog> ) ), connect( cmd, SIGNAL( tracks( QList<Tomahawk::track_ptr>, QList<Tomahawk::PlaybackLog> ) ),
SLOT( appendTracks( QList<Tomahawk::track_ptr>, QList<Tomahawk::PlaybackLog> ) ), Qt::QueuedConnection ); SLOT( onTracksLoaded( QList<Tomahawk::track_ptr>, QList<Tomahawk::PlaybackLog> ) ), Qt::QueuedConnection );
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) ); Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );
} }
@@ -94,8 +94,8 @@ RecentlyPlayedModel::setSource( const Tomahawk::source_ptr& source )
} }
else else
{ {
onSourceAdded( source );
loadHistory(); loadHistory();
onSourceAdded( source );
} }
} }
@@ -105,48 +105,73 @@ RecentlyPlayedModel::onSourceAdded( const Tomahawk::source_ptr& source )
{ {
connect( source.data(), SIGNAL( playbackFinished( Tomahawk::track_ptr, Tomahawk::PlaybackLog ) ), connect( source.data(), SIGNAL( playbackFinished( Tomahawk::track_ptr, Tomahawk::PlaybackLog ) ),
SLOT( onPlaybackFinished( Tomahawk::track_ptr, Tomahawk::PlaybackLog ) ), Qt::UniqueConnection ); SLOT( onPlaybackFinished( Tomahawk::track_ptr, Tomahawk::PlaybackLog ) ), Qt::UniqueConnection );
QPair< int, int > crows;
int c = rowCount( QModelIndex() );
crows.first = c;
crows.second = c;
emit beginInsertRows( QModelIndex(), crows.first, crows.second );
PlayableItem* item = new PlayableItem( source, rootItem() );
item->index = createIndex( rootItem()->children.count() - 1, 0, item );
connect( item, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
emit endInsertRows();
} }
void void
RecentlyPlayedModel::onPlaybackFinished( const Tomahawk::track_ptr& track, const Tomahawk::PlaybackLog& log ) RecentlyPlayedModel::onPlaybackFinished( const Tomahawk::track_ptr& track, const Tomahawk::PlaybackLog& log )
{ {
int count = trackCount(); const QModelIndex parent = indexFromSource( log.source );
const int count = rowCount( parent );
if ( count ) if ( count )
{ {
PlayableItem* oldestItem = itemFromIndex( index( count - 1, 0, QModelIndex() ) ); PlayableItem* oldestItem = itemFromIndex( index( count - 1, 0, parent ) );
if ( oldestItem->playbackLog().timestamp >= log.timestamp ) if ( oldestItem->playbackLog().timestamp >= log.timestamp )
return; return;
PlayableItem* youngestItem = itemFromIndex( index( 0, 0, QModelIndex() ) ); PlayableItem* youngestItem = itemFromIndex( index( 0, 0, parent ) );
if ( youngestItem->playbackLog().timestamp <= log.timestamp ) if ( youngestItem->playbackLog().timestamp <= log.timestamp )
insertQuery( track->toQuery(), 0, log ); insertQuery( track->toQuery(), 0, log, parent );
else else
{ {
for ( int i = 0; i < count - 1; i++ ) for ( int i = 0; i < count - 1; i++ )
{ {
PlayableItem* item1 = itemFromIndex( index( i, 0, QModelIndex() ) ); PlayableItem* item1 = itemFromIndex( index( i, 0, parent ) );
PlayableItem* item2 = itemFromIndex( index( i + 1, 0, QModelIndex() ) ); PlayableItem* item2 = itemFromIndex( index( i + 1, 0, parent ) );
if ( item1->playbackLog().timestamp >= log.timestamp && item2->playbackLog().timestamp <= log.timestamp ) if ( item1->playbackLog().timestamp >= log.timestamp && item2->playbackLog().timestamp <= log.timestamp )
{ {
insertQuery( track->toQuery(), i + 1, log ); insertQuery( track->toQuery(), i + 1, log, parent );
break; break;
} }
} }
} }
} }
else else
insertQuery( track->toQuery(), 0, log ); insertQuery( track->toQuery(), 0, log, parent );
if ( trackCount() > (int)m_limit ) if ( rowCount( parent ) > (int)m_limit )
remove( m_limit ); remove( m_limit, false, parent );
emit dataChanged( parent, parent );
ensureResolved(); ensureResolved();
} }
void
RecentlyPlayedModel::onTracksLoaded( QList<Tomahawk::track_ptr> tracks, QList<Tomahawk::PlaybackLog> logs )
{
for ( int i = tracks.count() - 1; i >= 0; i-- )
{
onPlaybackFinished( tracks.at( i ), logs.at( i ) );
}
}
bool bool
RecentlyPlayedModel::isTemporary() const RecentlyPlayedModel::isTemporary() const
{ {

View File

@@ -1,6 +1,6 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2014, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -25,10 +25,11 @@
#include "Typedefs.h" #include "Typedefs.h"
#include "PlaylistModel.h" #include "PlaylistModel.h"
#include "Source.h"
#include "DllMacro.h" #include "DllMacro.h"
class DLLEXPORT RecentlyPlayedModel : public PlaylistModel class DLLEXPORT RecentlyPlayedModel : public PlayableModel
{ {
Q_OBJECT Q_OBJECT
@@ -53,6 +54,8 @@ private slots:
void onPlaybackFinished( const Tomahawk::track_ptr& track, const Tomahawk::PlaybackLog& log ); void onPlaybackFinished( const Tomahawk::track_ptr& track, const Tomahawk::PlaybackLog& log );
void loadHistory(); void loadHistory();
void onTracksLoaded( QList<Tomahawk::track_ptr> tracks, QList<Tomahawk::PlaybackLog> logs );
private: private:
Tomahawk::source_ptr m_source; Tomahawk::source_ptr m_source;
unsigned int m_limit; unsigned int m_limit;