1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 16:44:05 +02:00

* Protect DynamicPlaylists, too.

* Only load the five most recent playlists & 25 tracks in the WelcomeWidget.
This commit is contained in:
Christian Muehlhaeuser
2011-05-19 03:12:46 +02:00
parent 0d23934200
commit 5a64fc1361
10 changed files with 50 additions and 29 deletions

View File

@@ -40,7 +40,6 @@ DatabaseCommand_SetPlaylistRevision::DatabaseCommand_SetPlaylistRevision(
, m_entries( entries ) , m_entries( entries )
{ {
Q_ASSERT( !newrev.isEmpty() ); Q_ASSERT( !newrev.isEmpty() );
Q_ASSERT( !oldrev.isEmpty() );
m_localOnly = ( newrev == oldrev ); m_localOnly = ( newrev == oldrev );
setPlaylistguid( playlistguid ); setPlaylistguid( playlistguid );

View File

@@ -175,7 +175,7 @@ Playlist::create( const source_ptr& author,
// reportCreated for us automatically, which should cause new playlists to be added to the GUI. // reportCreated for us automatically, which should cause new playlists to be added to the GUI.
DatabaseCommand_CreatePlaylist* cmd = new DatabaseCommand_CreatePlaylist( author, playlist ); DatabaseCommand_CreatePlaylist* cmd = new DatabaseCommand_CreatePlaylist( author, playlist );
connect( cmd, SIGNAL(finished()), playlist.data(), SIGNAL(created()) ); connect( cmd, SIGNAL( finished() ), playlist.data(), SIGNAL( created() ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) ); Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
playlist->reportCreated( playlist ); playlist->reportCreated( playlist );
return playlist; return playlist;
@@ -244,6 +244,7 @@ Playlist::loadRevision( const QString& rev )
{ {
qDebug() << Q_FUNC_INFO << currentrevision() << rev << m_title; qDebug() << Q_FUNC_INFO << currentrevision() << rev << m_title;
setBusy( true );
DatabaseCommand_LoadPlaylistEntries* cmd = DatabaseCommand_LoadPlaylistEntries* cmd =
new DatabaseCommand_LoadPlaylistEntries( rev.isEmpty() ? currentrevision() : rev ); new DatabaseCommand_LoadPlaylistEntries( rev.isEmpty() ? currentrevision() : rev );

View File

@@ -114,6 +114,7 @@ Q_PROPERTY( bool shared READ shared WRITE setShared )
friend class ::DatabaseCommand_LoadAllPlaylists; friend class ::DatabaseCommand_LoadAllPlaylists;
friend class ::DatabaseCommand_SetPlaylistRevision; friend class ::DatabaseCommand_SetPlaylistRevision;
friend class ::DatabaseCommand_CreatePlaylist; friend class ::DatabaseCommand_CreatePlaylist;
friend class DynamicPlaylist;
public: public:
~Playlist(); ~Playlist();

View File

@@ -153,6 +153,9 @@ DynamicPlaylist::createNewRevision( const QString& newrev,
const QList< dyncontrol_ptr>& controls, const QList< dyncontrol_ptr>& controls,
const QList< plentry_ptr >& entries ) const QList< plentry_ptr >& entries )
{ {
Q_ASSERT( !busy() );
setBusy( true );
// get the newly added tracks // get the newly added tracks
QList< plentry_ptr > added = newEntries( entries ); QList< plentry_ptr > added = newEntries( entries );
@@ -162,21 +165,21 @@ DynamicPlaylist::createNewRevision( const QString& newrev,
// no conflict resolution or partial updating for controls. all or nothing baby // no conflict resolution or partial updating for controls. all or nothing baby
// source making the change (local user in this case) // source making the change (local user in this case)
source_ptr author = SourceList::instance()->getLocal(); source_ptr author = SourceList::instance()->getLocal();
// command writes new rev to DB and calls setRevision, which emits our signal // command writes new rev to DB and calls setRevision, which emits our signal
DatabaseCommand_SetDynamicPlaylistRevision* cmd = DatabaseCommand_SetDynamicPlaylistRevision* cmd =
new DatabaseCommand_SetDynamicPlaylistRevision( author, new DatabaseCommand_SetDynamicPlaylistRevision( author,
guid(), guid(),
newrev, newrev,
oldrev, oldrev,
orderedguids, orderedguids,
added, added,
entries, entries,
type, type,
Static, Static,
controls ); controls );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) ); Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
} }
// create a new revision that will be an ondemand playlist, as it has no entries // create a new revision that will be an ondemand playlist, as it has no entries
@@ -205,6 +208,7 @@ DynamicPlaylist::loadRevision( const QString& rev )
{ {
qDebug() << Q_FUNC_INFO << "Loading with:" << ( rev.isEmpty() ? currentrevision() : rev ); qDebug() << Q_FUNC_INFO << "Loading with:" << ( rev.isEmpty() ? currentrevision() : rev );
setBusy( true );
DatabaseCommand_LoadDynamicPlaylist* cmd = new DatabaseCommand_LoadDynamicPlaylist( rev.isEmpty() ? currentrevision() : rev ); DatabaseCommand_LoadDynamicPlaylist* cmd = new DatabaseCommand_LoadDynamicPlaylist( rev.isEmpty() ? currentrevision() : rev );
if( m_generator->mode() == OnDemand ) { if( m_generator->mode() == OnDemand ) {
@@ -335,10 +339,11 @@ void DynamicPlaylist::setRevision( const QString& rev,
dpr.type = type; dpr.type = type;
dpr.mode = Static; dpr.mode = Static;
if( applied ) { if( applied )
setCurrentrevision( rev ); setCurrentrevision( rev );
}
// qDebug() << "EMITTING REVISION LOADED 1!"; // qDebug() << "EMITTING REVISION LOADED 1!";
setBusy( false );
emit dynamicRevisionLoaded( dpr ); emit dynamicRevisionLoaded( dpr );
} }

View File

@@ -221,7 +221,11 @@ void
PlaylistModel::trackResolved( bool ) PlaylistModel::trackResolved( bool )
{ {
Tomahawk::Query* q = qobject_cast< Query* >( sender() ); Tomahawk::Query* q = qobject_cast< Query* >( sender() );
Q_ASSERT( q ); if ( !q )
{
// Track has been removed from the playlist by now
return;
}
m_waitingForResolved.removeAll( q ); m_waitingForResolved.removeAll( q );
disconnect( q, SIGNAL( resolvingFinished( bool ) ), this, SLOT( trackResolved( bool ) ) ); disconnect( q, SIGNAL( resolvingFinished( bool ) ), this, SLOT( trackResolved( bool ) ) );

View File

@@ -385,9 +385,14 @@ TomahawkSettings::recentlyPlayedPlaylists() const
} }
QStringList QStringList
TomahawkSettings::recentlyPlayedPlaylistGuids() const TomahawkSettings::recentlyPlayedPlaylistGuids( unsigned int amount ) const
{ {
return value( "playlists/recentlyPlayed" ).toStringList(); QStringList p = value( "playlists/recentlyPlayed" ).toStringList();
while ( amount && p.count() > (int)amount )
p.removeAt( p.count() - 1 );
return p;
} }

View File

@@ -66,7 +66,7 @@ public:
void setPlaylistColumnSizes( const QString& playlistid, const QByteArray& state ); void setPlaylistColumnSizes( const QString& playlistid, const QByteArray& state );
QList<Tomahawk::playlist_ptr> recentlyPlayedPlaylists() const; QList<Tomahawk::playlist_ptr> recentlyPlayedPlaylists() const;
QStringList recentlyPlayedPlaylistGuids() const; QStringList recentlyPlayedPlaylistGuids( unsigned int amount = 0 ) const;
void appendRecentlyPlayedPlaylist( const Tomahawk::playlist_ptr& playlist ); void appendRecentlyPlayedPlaylist( const Tomahawk::playlist_ptr& playlist );
/// SIP plugins /// SIP plugins

View File

@@ -28,6 +28,7 @@ using namespace Tomahawk;
WelcomePlaylistModel::WelcomePlaylistModel( QObject* parent ) WelcomePlaylistModel::WelcomePlaylistModel( QObject* parent )
: QAbstractListModel( parent ) : QAbstractListModel( parent )
, m_waitingForSome( true ) , m_waitingForSome( true )
, m_maxPlaylists( 0 )
{ {
loadFromSettings(); loadFromSettings();
@@ -49,7 +50,7 @@ WelcomePlaylistModel::loadFromSettings()
m_recplaylists.clear(); m_recplaylists.clear();
m_waitingForSome = false; m_waitingForSome = false;
QStringList playlist_guids = TomahawkSettings::instance()->recentlyPlayedPlaylistGuids(); QStringList playlist_guids = TomahawkSettings::instance()->recentlyPlayedPlaylistGuids( m_maxPlaylists );
for( int i = playlist_guids.size() - 1; i >= 0; i-- ) for( int i = playlist_guids.size() - 1; i >= 0; i-- )
{ {

View File

@@ -34,6 +34,9 @@ public:
{ ArtistRole = Qt::UserRole, TrackCountRole, PlaylistRole }; { ArtistRole = Qt::UserRole, TrackCountRole, PlaylistRole };
explicit WelcomePlaylistModel( QObject* parent = 0 ); explicit WelcomePlaylistModel( QObject* parent = 0 );
void setMaxPlaylists( unsigned int max ) { m_maxPlaylists = max; }
virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const; virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
virtual int rowCount( const QModelIndex& parent = QModelIndex() ) const; virtual int rowCount( const QModelIndex& parent = QModelIndex() ) const;
@@ -53,6 +56,7 @@ private:
QHash< QString, Tomahawk::playlist_ptr > m_cached; QHash< QString, Tomahawk::playlist_ptr > m_cached;
mutable QHash< Tomahawk::playlist_ptr, QString > m_artists; mutable QHash< Tomahawk::playlist_ptr, QString > m_artists;
unsigned int m_maxPlaylists;
bool m_waitingForSome; bool m_waitingForSome;
}; };

View File

@@ -33,8 +33,8 @@
#include <QPainter> #include <QPainter>
#include "welcomeplaylistmodel.h" #include "welcomeplaylistmodel.h"
#define HISTORY_TRACK_ITEMS 50 #define HISTORY_TRACK_ITEMS 25
#define HISTORY_PLAYLIST_ITEMS 10 #define HISTORY_PLAYLIST_ITEMS 5
#define HISTORY_RESOLVING_TIMEOUT 2500 #define HISTORY_RESOLVING_TIMEOUT 2500
@@ -44,14 +44,15 @@ WelcomeWidget::WelcomeWidget( QWidget* parent )
{ {
ui->setupUi( this ); ui->setupUi( this );
WelcomePlaylistModel* model = new WelcomePlaylistModel( this );
model->setMaxPlaylists( HISTORY_PLAYLIST_ITEMS );
ui->playlistWidget->setItemDelegate( new PlaylistDelegate() ); ui->playlistWidget->setItemDelegate( new PlaylistDelegate() );
WelcomePlaylistModel* model = new WelcomePlaylistModel( this );
ui->playlistWidget->setModel( model ); ui->playlistWidget->setModel( model );
ui->playlistWidget->overlay()->resize( 380, 86 ); ui->playlistWidget->overlay()->resize( 380, 86 );
ui->tracksView->overlay()->setEnabled( false ); ui->tracksView->overlay()->setEnabled( false );
connect( model,SIGNAL( emptinessChanged( bool) ), this, SLOT( updatePlaylists() ) ); connect( model, SIGNAL( emptinessChanged( bool) ), this, SLOT( updatePlaylists() ) );
m_tracksModel = new PlaylistModel( ui->tracksView ); m_tracksModel = new PlaylistModel( ui->tracksView );
ui->tracksView->setPlaylistModel( m_tracksModel ); ui->tracksView->setPlaylistModel( m_tracksModel );