mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-11 16:44:05 +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
|
bool
|
||||||
Playlist::remove( const playlist_ptr& playlist )
|
Playlist::remove( const playlist_ptr& playlist )
|
||||||
{
|
{
|
||||||
|
playlist->aboutToBeDeleted( playlist );
|
||||||
|
|
||||||
TomahawkSettings *s = TomahawkSettings::instance();
|
TomahawkSettings *s = TomahawkSettings::instance();
|
||||||
s->removePlaylistSettings( playlist->guid() );
|
s->removePlaylistSettings( playlist->guid() );
|
||||||
|
|
||||||
|
@@ -190,6 +190,12 @@ signals:
|
|||||||
/// renamed etc.
|
/// renamed etc.
|
||||||
void changed();
|
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?
|
/// was deleted, eh?
|
||||||
void deleted( const Tomahawk::playlist_ptr& pl );
|
void deleted( const Tomahawk::playlist_ptr& pl );
|
||||||
|
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include "database/databasecommand_setdynamicplaylistrevision.h"
|
#include "database/databasecommand_setdynamicplaylistrevision.h"
|
||||||
#include "database/databasecommand_loaddynamicplaylist.h"
|
#include "database/databasecommand_loaddynamicplaylist.h"
|
||||||
#include "database/databasecommand_deletedynamicplaylist.h"
|
#include "database/databasecommand_deletedynamicplaylist.h"
|
||||||
|
#include "tomahawksettings.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -249,6 +250,10 @@ DynamicPlaylist::loadRevision( const QString& rev )
|
|||||||
bool
|
bool
|
||||||
DynamicPlaylist::remove( const Tomahawk::dynplaylist_ptr& playlist )
|
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() );
|
DatabaseCommand_DeletePlaylist* cmd = new DatabaseCommand_DeleteDynamicPlaylist( playlist->author(), playlist->guid() );
|
||||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
||||||
|
|
||||||
|
@@ -115,6 +115,7 @@ signals:
|
|||||||
/// emitted when the playlist revision changes (whenever the playlist changes)
|
/// emitted when the playlist revision changes (whenever the playlist changes)
|
||||||
void dynamicRevisionLoaded( Tomahawk::DynamicPlaylistRevision );
|
void dynamicRevisionLoaded( Tomahawk::DynamicPlaylistRevision );
|
||||||
|
|
||||||
|
void aboutToBeDeleted( const Tomahawk::dynplaylist_ptr& pl );
|
||||||
void deleted( const Tomahawk::dynplaylist_ptr& pl );
|
void deleted( const Tomahawk::dynplaylist_ptr& pl );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@@ -80,18 +80,10 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons
|
|||||||
|
|
||||||
connect( source->collection().data(), SIGNAL( playlistsAdded( QList<Tomahawk::playlist_ptr> ) ),
|
connect( source->collection().data(), SIGNAL( playlistsAdded( QList<Tomahawk::playlist_ptr> ) ),
|
||||||
SLOT( onPlaylistsAdded( QList<Tomahawk::playlist_ptr> ) ), Qt::QueuedConnection );
|
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 > ) ),
|
connect( source->collection().data(), SIGNAL( autoPlaylistsAdded( QList< Tomahawk::dynplaylist_ptr > ) ),
|
||||||
SLOT( onAutoPlaylistsAdded( QList<Tomahawk::dynplaylist_ptr> ) ), Qt::QueuedConnection );
|
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> ) ),
|
connect( source->collection().data(), SIGNAL( stationsAdded( QList<Tomahawk::dynplaylist_ptr> ) ),
|
||||||
SLOT( onStationsAdded( QList<Tomahawk::dynplaylist_ptr> ) ), Qt::QueuedConnection );
|
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();
|
// qDebug() << "Dynamic Playlist added:" << p->title() << p->creator() << p->info();
|
||||||
p->loadRevision();
|
p->loadRevision();
|
||||||
items << plItem;
|
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();
|
parent->endRowsAdded();
|
||||||
}
|
}
|
||||||
@@ -170,20 +170,17 @@ CollectionItem::playlistsAddedInternal( SourceTreeItem* parent, const QList< dyn
|
|||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
void
|
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?
|
Q_ASSERT( parent ); // How can we delete playlists if we have none?
|
||||||
QList< SourceTreeItem* > items;
|
int curCount = parent->children().count();
|
||||||
foreach( const T& playlist, playlists ) {
|
for( int i = 0; i < curCount; i++ ) {
|
||||||
int curCount = parent->children().count();
|
PlaylistItem* pl = qobject_cast< PlaylistItem* >( parent->children().at( i ) );
|
||||||
for( int i = 0; i < curCount; i++ ) {
|
if( pl && pl->playlist() == p ) {
|
||||||
PlaylistItem* pl = qobject_cast< PlaylistItem* >( parent->children().at( i ) );
|
parent->beginRowsRemoved( i, i );
|
||||||
if( pl && pl->playlist() == playlist ) {
|
parent->removeChild( pl );
|
||||||
parent->beginRowsRemoved( i, i );
|
parent->endRowsRemoved();
|
||||||
parent->removeChild( pl );
|
break;
|
||||||
parent->endRowsRemoved();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -217,15 +214,19 @@ CollectionItem::onPlaylistsAdded( const QList< playlist_ptr >& playlists )
|
|||||||
// qDebug() << "Playlist added:" << p->title() << p->creator() << p->info();
|
// qDebug() << "Playlist added:" << p->title() << p->creator() << p->info();
|
||||||
p->loadRevision();
|
p->loadRevision();
|
||||||
items << plItem;
|
items << plItem;
|
||||||
|
|
||||||
|
connect( p.data(), SIGNAL( aboutToBeDeleted( Tomahawk::playlist_ptr ) ),
|
||||||
|
SLOT( onPlaylistDeleted( Tomahawk::playlist_ptr ) ), Qt::QueuedConnection );
|
||||||
|
|
||||||
}
|
}
|
||||||
m_playlists->endRowsAdded();
|
m_playlists->endRowsAdded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
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
|
void
|
||||||
CollectionItem::onAutoPlaylistsDeleted( const QList< dynplaylist_ptr >& playlists )
|
CollectionItem::onAutoPlaylistDeleted( const dynplaylist_ptr& playlist )
|
||||||
{
|
{
|
||||||
if( !m_playlists )
|
if( !m_playlists )
|
||||||
qDebug() << "NO playlist category item for a deleting playlist..";
|
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
|
void
|
||||||
CollectionItem::onStationsDeleted( const QList< dynplaylist_ptr >& stations )
|
CollectionItem::onStationDeleted( const dynplaylist_ptr& station )
|
||||||
{
|
{
|
||||||
playlistsDeletedInternal( m_stations, stations );
|
playlistDeletedInternal( m_stations, station );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -45,11 +45,11 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onPlaylistsAdded( const QList<Tomahawk::playlist_ptr>& playlists );
|
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 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 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* );
|
void tempPageActivated( Tomahawk::ViewPage* );
|
||||||
Tomahawk::ViewPage* tempItemClicked();
|
Tomahawk::ViewPage* tempItemClicked();
|
||||||
@@ -61,7 +61,7 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
void playlistsAddedInternal( SourceTreeItem* parent, const QList< Tomahawk::dynplaylist_ptr >& playlists );
|
void playlistsAddedInternal( SourceTreeItem* parent, const QList< Tomahawk::dynplaylist_ptr >& playlists );
|
||||||
template< typename T >
|
template< typename T >
|
||||||
void playlistsDeletedInternal( SourceTreeItem* parent, const QList< T >& playlists );
|
void playlistDeletedInternal( SourceTreeItem* parent, const T& playlists );
|
||||||
|
|
||||||
Tomahawk::source_ptr m_source;
|
Tomahawk::source_ptr m_source;
|
||||||
CategoryItem* m_playlists;
|
CategoryItem* m_playlists;
|
||||||
|
Reference in New Issue
Block a user