mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-11 08:34:34 +02:00
Remove deleted playlists from the UI immediately, not after dbcmd is completed
Otherwise if the DB is busy the user can delete playlists multiple times, crashing all his peers
This commit is contained in:
@@ -220,6 +220,8 @@ Playlist::load( const QString& guid )
|
||||
bool
|
||||
Playlist::remove( const playlist_ptr& playlist )
|
||||
{
|
||||
playlist->aboutToBeDeleted( playlist );
|
||||
|
||||
TomahawkSettings *s = TomahawkSettings::instance();
|
||||
s->removePlaylistSettings( playlist->guid() );
|
||||
|
||||
|
@@ -190,6 +190,12 @@ signals:
|
||||
/// renamed etc.
|
||||
void changed();
|
||||
|
||||
/**
|
||||
* delete command is scheduled but not completed. Do not call remove() again once this
|
||||
* is emitted.
|
||||
*/
|
||||
void aboutToBeDeleted( const Tomahawk::playlist_ptr& pl );
|
||||
|
||||
/// was deleted, eh?
|
||||
void deleted( const Tomahawk::playlist_ptr& pl );
|
||||
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#include "database/databasecommand_setdynamicplaylistrevision.h"
|
||||
#include "database/databasecommand_loaddynamicplaylist.h"
|
||||
#include "database/databasecommand_deletedynamicplaylist.h"
|
||||
#include "tomahawksettings.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
@@ -249,6 +250,10 @@ DynamicPlaylist::loadRevision( const QString& rev )
|
||||
bool
|
||||
DynamicPlaylist::remove( const Tomahawk::dynplaylist_ptr& playlist )
|
||||
{
|
||||
playlist->aboutToBeDeleted( playlist );
|
||||
|
||||
TomahawkSettings::instance()->removePlaylistSettings( playlist->guid() );
|
||||
|
||||
DatabaseCommand_DeletePlaylist* cmd = new DatabaseCommand_DeleteDynamicPlaylist( playlist->author(), playlist->guid() );
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
||||
|
||||
|
@@ -115,6 +115,7 @@ signals:
|
||||
/// emitted when the playlist revision changes (whenever the playlist changes)
|
||||
void dynamicRevisionLoaded( Tomahawk::DynamicPlaylistRevision );
|
||||
|
||||
void aboutToBeDeleted( const Tomahawk::dynplaylist_ptr& pl );
|
||||
void deleted( const Tomahawk::dynplaylist_ptr& pl );
|
||||
|
||||
public slots:
|
||||
|
@@ -80,18 +80,10 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons
|
||||
|
||||
connect( source->collection().data(), SIGNAL( playlistsAdded( QList<Tomahawk::playlist_ptr> ) ),
|
||||
SLOT( onPlaylistsAdded( QList<Tomahawk::playlist_ptr> ) ), Qt::QueuedConnection );
|
||||
connect( source->collection().data(), SIGNAL( playlistsDeleted( QList<Tomahawk::playlist_ptr> ) ),
|
||||
SLOT( onPlaylistsDeleted( QList<Tomahawk::playlist_ptr> ) ), Qt::QueuedConnection );
|
||||
|
||||
connect( source->collection().data(), SIGNAL( autoPlaylistsAdded( QList< Tomahawk::dynplaylist_ptr > ) ),
|
||||
SLOT( onAutoPlaylistsAdded( QList<Tomahawk::dynplaylist_ptr> ) ), Qt::QueuedConnection );
|
||||
connect( source->collection().data(), SIGNAL( autoPlaylistsDeleted( QList<Tomahawk::dynplaylist_ptr> ) ),
|
||||
SLOT( onAutoPlaylistsDeleted( QList<Tomahawk::dynplaylist_ptr> ) ), Qt::QueuedConnection );
|
||||
|
||||
connect( source->collection().data(), SIGNAL( stationsAdded( QList<Tomahawk::dynplaylist_ptr> ) ),
|
||||
SLOT( onStationsAdded( QList<Tomahawk::dynplaylist_ptr> ) ), Qt::QueuedConnection );
|
||||
connect( source->collection().data(), SIGNAL( stationsDeleted( QList<Tomahawk::dynplaylist_ptr> ) ),
|
||||
SLOT( onStationsDeleted( QList<Tomahawk::dynplaylist_ptr> ) ), Qt::QueuedConnection );
|
||||
}
|
||||
|
||||
|
||||
@@ -163,6 +155,14 @@ CollectionItem::playlistsAddedInternal( SourceTreeItem* parent, const QList< dyn
|
||||
// qDebug() << "Dynamic Playlist added:" << p->title() << p->creator() << p->info();
|
||||
p->loadRevision();
|
||||
items << plItem;
|
||||
|
||||
if( p->mode() == Static ) {
|
||||
connect( p.data(), SIGNAL( aboutToBeDeleted( Tomahawk::dynplaylist_ptr ) ),
|
||||
SLOT( onAutoPlaylistDeleted( Tomahawk::dynplaylist_ptr ) ), Qt::QueuedConnection );
|
||||
} else {
|
||||
connect( p.data(), SIGNAL( aboutToBeDeleted( Tomahawk::dynplaylist_ptr ) ),
|
||||
SLOT( onStationDeleted( Tomahawk::dynplaylist_ptr ) ), Qt::QueuedConnection );
|
||||
}
|
||||
}
|
||||
parent->endRowsAdded();
|
||||
}
|
||||
@@ -170,20 +170,17 @@ CollectionItem::playlistsAddedInternal( SourceTreeItem* parent, const QList< dyn
|
||||
|
||||
template< typename T >
|
||||
void
|
||||
CollectionItem::playlistsDeletedInternal( SourceTreeItem* parent, const QList< T >& playlists )
|
||||
CollectionItem::playlistDeletedInternal( SourceTreeItem* parent, const T& p )
|
||||
{
|
||||
Q_ASSERT( parent ); // How can we delete playlists if we have none?
|
||||
QList< SourceTreeItem* > items;
|
||||
foreach( const T& playlist, playlists ) {
|
||||
int curCount = parent->children().count();
|
||||
for( int i = 0; i < curCount; i++ ) {
|
||||
PlaylistItem* pl = qobject_cast< PlaylistItem* >( parent->children().at( i ) );
|
||||
if( pl && pl->playlist() == playlist ) {
|
||||
parent->beginRowsRemoved( i, i );
|
||||
parent->removeChild( pl );
|
||||
parent->endRowsRemoved();
|
||||
break;
|
||||
}
|
||||
int curCount = parent->children().count();
|
||||
for( int i = 0; i < curCount; i++ ) {
|
||||
PlaylistItem* pl = qobject_cast< PlaylistItem* >( parent->children().at( i ) );
|
||||
if( pl && pl->playlist() == p ) {
|
||||
parent->beginRowsRemoved( i, i );
|
||||
parent->removeChild( pl );
|
||||
parent->endRowsRemoved();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,15 +214,19 @@ CollectionItem::onPlaylistsAdded( const QList< playlist_ptr >& playlists )
|
||||
// qDebug() << "Playlist added:" << p->title() << p->creator() << p->info();
|
||||
p->loadRevision();
|
||||
items << plItem;
|
||||
|
||||
connect( p.data(), SIGNAL( aboutToBeDeleted( Tomahawk::playlist_ptr ) ),
|
||||
SLOT( onPlaylistDeleted( Tomahawk::playlist_ptr ) ), Qt::QueuedConnection );
|
||||
|
||||
}
|
||||
m_playlists->endRowsAdded();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CollectionItem::onPlaylistsDeleted( const QList< playlist_ptr >& playlists )
|
||||
CollectionItem::onPlaylistDeleted( const playlist_ptr& playlist )
|
||||
{
|
||||
playlistsDeletedInternal( m_playlists, playlists );
|
||||
playlistDeletedInternal( m_playlists, playlist );
|
||||
}
|
||||
|
||||
|
||||
@@ -247,12 +248,12 @@ CollectionItem::onAutoPlaylistsAdded( const QList< dynplaylist_ptr >& playlists
|
||||
|
||||
|
||||
void
|
||||
CollectionItem::onAutoPlaylistsDeleted( const QList< dynplaylist_ptr >& playlists )
|
||||
CollectionItem::onAutoPlaylistDeleted( const dynplaylist_ptr& playlist )
|
||||
{
|
||||
if( !m_playlists )
|
||||
qDebug() << "NO playlist category item for a deleting playlist..";
|
||||
|
||||
playlistsDeletedInternal( m_playlists, playlists );
|
||||
playlistDeletedInternal( m_playlists, playlist );
|
||||
}
|
||||
|
||||
|
||||
@@ -274,9 +275,9 @@ CollectionItem::onStationsAdded( const QList< dynplaylist_ptr >& stations )
|
||||
|
||||
|
||||
void
|
||||
CollectionItem::onStationsDeleted( const QList< dynplaylist_ptr >& stations )
|
||||
CollectionItem::onStationDeleted( const dynplaylist_ptr& station )
|
||||
{
|
||||
playlistsDeletedInternal( m_stations, stations );
|
||||
playlistDeletedInternal( m_stations, station );
|
||||
}
|
||||
|
||||
void
|
||||
|
@@ -45,11 +45,11 @@ public:
|
||||
|
||||
private slots:
|
||||
void onPlaylistsAdded( const QList<Tomahawk::playlist_ptr>& playlists );
|
||||
void onPlaylistsDeleted( const QList<Tomahawk::playlist_ptr>& playlists );
|
||||
void onPlaylistDeleted( const Tomahawk::playlist_ptr& playlists );
|
||||
void onAutoPlaylistsAdded( const QList<Tomahawk::dynplaylist_ptr>& playlists );
|
||||
void onAutoPlaylistsDeleted( const QList<Tomahawk::dynplaylist_ptr>& playlists );
|
||||
void onAutoPlaylistDeleted( const Tomahawk::dynplaylist_ptr& playlists );
|
||||
void onStationsAdded( const QList<Tomahawk::dynplaylist_ptr>& stations );
|
||||
void onStationsDeleted( const QList<Tomahawk::dynplaylist_ptr>& stations );
|
||||
void onStationDeleted( const Tomahawk::dynplaylist_ptr& stations );
|
||||
|
||||
void tempPageActivated( Tomahawk::ViewPage* );
|
||||
Tomahawk::ViewPage* tempItemClicked();
|
||||
@@ -61,7 +61,7 @@ private slots:
|
||||
private:
|
||||
void playlistsAddedInternal( SourceTreeItem* parent, const QList< Tomahawk::dynplaylist_ptr >& playlists );
|
||||
template< typename T >
|
||||
void playlistsDeletedInternal( SourceTreeItem* parent, const QList< T >& playlists );
|
||||
void playlistDeletedInternal( SourceTreeItem* parent, const T& playlists );
|
||||
|
||||
Tomahawk::source_ptr m_source;
|
||||
CategoryItem* m_playlists;
|
||||
|
Reference in New Issue
Block a user