1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 13:47:26 +02:00

* Fixed page-history related crash when deleting / creating playlists.

This commit is contained in:
Christian Muehlhaeuser
2011-04-06 07:26:57 +02:00
parent ab2443792a
commit 51a3eb39be
10 changed files with 176 additions and 147 deletions

View File

@@ -137,7 +137,7 @@ DynamicWidget::loadDynamicPlaylist( const Tomahawk::dynplaylist_ptr& playlist )
disconnect( m_playlist->generator().data(), SIGNAL( generated( QList<Tomahawk::query_ptr> ) ), this, SLOT( tracksGenerated( QList<Tomahawk::query_ptr> ) ) );
disconnect( m_playlist.data(), SIGNAL( dynamicRevisionLoaded( Tomahawk::DynamicPlaylistRevision) ), this, SLOT(onRevisionLoaded( Tomahawk::DynamicPlaylistRevision) ) );
disconnect( m_playlist->generator().data(), SIGNAL( error( QString, QString ) ), this, SLOT( generatorError( QString, QString ) ) );
disconnect( m_playlist.data(), SIGNAL( deleted( Tomahawk::dynplaylist_ptr ) ), this, SLOT( deleteLater() ) );
disconnect( m_playlist.data(), SIGNAL( deleted( Tomahawk::dynplaylist_ptr ) ), this, SLOT( onDeleted() ) );
}
@@ -164,7 +164,7 @@ DynamicWidget::loadDynamicPlaylist( const Tomahawk::dynplaylist_ptr& playlist )
connect( m_playlist->generator().data(), SIGNAL( generated( QList<Tomahawk::query_ptr> ) ), this, SLOT( tracksGenerated( QList<Tomahawk::query_ptr> ) ) );
connect( m_playlist.data(), SIGNAL( dynamicRevisionLoaded( Tomahawk::DynamicPlaylistRevision ) ), this, SLOT( onRevisionLoaded( Tomahawk::DynamicPlaylistRevision ) ) );
connect( m_playlist->generator().data(), SIGNAL( error( QString, QString ) ), this, SLOT( generatorError( QString, QString ) ) );
connect( m_playlist.data(), SIGNAL( deleted( Tomahawk::dynplaylist_ptr ) ), this, SLOT( deleteLater() ) );
connect( m_playlist.data(), SIGNAL( deleted( Tomahawk::dynplaylist_ptr ) ), this, SLOT( onDeleted() ) );
}
@@ -409,3 +409,10 @@ DynamicWidget::jumpToCurrentTrack()
m_view->scrollTo( m_view->proxyModel()->currentItem(), QAbstractItemView::PositionAtCenter );
return true;
}
void
DynamicWidget::onDeleted()
{
emit destroyed( widget() );
deleteLater();
}

View File

@@ -96,6 +96,7 @@ public slots:
signals:
void descriptionChanged( const QString& caption );
void destroyed( QWidget* widget );
private slots:
void generate( int = -1 );
@@ -107,6 +108,7 @@ private slots:
void showPreview();
void layoutFloatingWidgets();
void onDeleted();
private:
dynplaylist_ptr m_playlist;

View File

@@ -163,8 +163,6 @@ PlaylistManager::show( const Tomahawk::playlist_ptr& playlist )
playlist->resolve();
m_playlistViews.insert( playlist, view );
connect( playlist.data(), SIGNAL( deleted( Tomahawk::playlist_ptr ) ), this, SLOT( onPlaylistDeleted( Tomahawk::playlist_ptr ) ) );
}
else
{
@@ -540,11 +538,11 @@ PlaylistManager::setPage( ViewPage* page, bool trackHistory )
setHistoryPosition( m_pageHistory.count() - 1 );
}
if ( playlistForInterface( currentPlaylistInterface() ) )
if ( !playlistForInterface( currentPlaylistInterface() ).isNull() )
emit playlistActivated( playlistForInterface( currentPlaylistInterface() ) );
if ( dynamicPlaylistForInterface( currentPlaylistInterface() ) )
if ( !dynamicPlaylistForInterface( currentPlaylistInterface() ).isNull() )
emit dynamicPlaylistActivated( dynamicPlaylistForInterface( currentPlaylistInterface() ) );
if ( collectionForInterface( currentPlaylistInterface() ) )
if ( !collectionForInterface( currentPlaylistInterface() ).isNull() )
emit collectionActivated( collectionForInterface( currentPlaylistInterface() ) );
if ( isSuperCollectionVisible() )
emit superCollectionActivated();
@@ -555,10 +553,17 @@ PlaylistManager::setPage( ViewPage* page, bool trackHistory )
AudioEngine::instance()->setPlaylist( currentPlaylistInterface() );
// UGH!
if( QObject* obj = dynamic_cast< QObject* >( currentPage() ) ) {
if ( QObject* obj = dynamic_cast< QObject* >( currentPage() ) )
{
// if the signal exists (just to hide the qobject runtime warning...)
if( obj->metaObject()->indexOfSignal( "descriptionChanged(QString)" ) > -1 )
connect( obj, SIGNAL( descriptionChanged( QString ) ), m_infobar, SLOT( setDescription( QString ) ) );
connect( obj, SIGNAL( descriptionChanged( QString ) ), m_infobar, SLOT( setDescription( QString ) ), Qt::UniqueConnection );
}
if ( QObject* obj = dynamic_cast< QObject* >( currentPage() ) )
{
// if the signal exists (just to hide the qobject runtime warning...)
if( obj->metaObject()->indexOfSignal( "destroyed(QWidget*)" ) > -1 )
connect( obj, SIGNAL( destroyed( QWidget* ) ), SLOT( onWidgetDestroyed( QWidget* ) ), Qt::UniqueConnection );
}
m_stack->setCurrentWidget( page->widget() );
@@ -638,24 +643,6 @@ PlaylistManager::updateView()
m_infobar->setPixmap( currentPage()->pixmap() );
}
void
PlaylistManager::onDynamicDeleted( const Tomahawk::dynplaylist_ptr& pl )
{
QWidget* w = m_dynamicWidgets.value( pl );
m_dynamicWidgets.remove( pl );
onWidgetDestroyed( w );
}
void
PlaylistManager::onPlaylistDeleted( const Tomahawk::playlist_ptr& pl )
{
QWidget* w = m_playlistViews.value( pl );
m_playlistViews.remove( pl );
onWidgetDestroyed( w );
}
void
PlaylistManager::onWidgetDestroyed( QWidget* widget )
@@ -663,11 +650,20 @@ PlaylistManager::onWidgetDestroyed( QWidget* widget )
qDebug() << "Destroyed child:" << widget << widget->metaObject()->className();
bool resetWidget = ( m_stack->currentWidget() == widget );
m_stack->removeWidget( widget );
for ( int i = 0; i < m_pageHistory.count(); i++ )
{
ViewPage* page = m_pageHistory.at( i );
if ( !playlistForInterface( page->playlistInterface() ).isNull() )
{
m_playlistViews.remove( playlistForInterface( page->playlistInterface() ) );
}
if ( !dynamicPlaylistForInterface( page->playlistInterface() ).isNull() )
{
m_dynamicWidgets.remove( dynamicPlaylistForInterface( page->playlistInterface() ) );
}
if ( page->widget() == widget )
{
m_pageHistory.removeAt( i );
@@ -677,6 +673,8 @@ PlaylistManager::onWidgetDestroyed( QWidget* widget )
}
}
m_stack->removeWidget( widget );
if ( resetWidget )
{
if ( m_pageHistory.count() )
@@ -783,6 +781,7 @@ PlaylistManager::playlistForInterface( PlaylistInterface* interface ) const
{
foreach ( PlaylistView* view, m_playlistViews.values() )
{
qDebug() << "LAAAA:" << view;
if ( view->playlistInterface() == interface )
{
return m_playlistViews.key( view );

View File

@@ -136,8 +136,6 @@ private slots:
void setFilter( const QString& filter );
void applyFilter();
void onPlaylistDeleted( const Tomahawk::playlist_ptr& pl );
void onDynamicDeleted( const Tomahawk::dynplaylist_ptr& pl );
void onWidgetDestroyed( QWidget* widget );
private:

View File

@@ -71,7 +71,10 @@ void
PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist, bool loadEntries )
{
if ( !m_playlist.isNull() )
{
disconnect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( onRevisionLoaded( Tomahawk::PlaylistRevision ) ) );
disconnect( m_playlist.data(), SIGNAL( deleted( Tomahawk::playlist_ptr ) ), this, SIGNAL( playlistDeleted() ) );
}
if ( rowCount( QModelIndex() ) && loadEntries )
{
@@ -80,6 +83,7 @@ PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist, bool loadEn
m_playlist = playlist;
connect( playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), SLOT( onRevisionLoaded( Tomahawk::PlaylistRevision ) ) );
connect( playlist.data(), SIGNAL( deleted( Tomahawk::playlist_ptr ) ), this, SIGNAL( playlistDeleted() ) );
setReadOnly( !m_playlist->author()->isLocal() );
setTitle( playlist->title() );

View File

@@ -70,6 +70,9 @@ signals:
void shuffleModeChanged( bool enabled );
void itemSizeChanged( const QModelIndex& index );
void playlistDeleted();
private slots:
void onDataChanged();
@@ -80,6 +83,7 @@ private slots:
void onTracksInserted( unsigned int row, const QList<Tomahawk::query_ptr>& tracks );
void trackResolved( bool );
private:
QList<Tomahawk::plentry_ptr> playlistEntries() const;

View File

@@ -58,6 +58,7 @@ PlaylistView::setModel( PlaylistModel* model )
setGuid( "playlistview" );
connect( model, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) );
connect( model, SIGNAL( playlistDeleted() ), SLOT( onDeleted() ) );
}
@@ -154,3 +155,12 @@ PlaylistView::jumpToCurrentTrack()
scrollTo( proxyModel()->currentItem(), QAbstractItemView::PositionAtCenter );
return true;
}
void
PlaylistView::onDeleted()
{
qDebug() << Q_FUNC_INFO;
emit destroyed( widget() );
deleteLater();
}

View File

@@ -50,6 +50,9 @@ public:
virtual bool jumpToCurrentTrack();
signals:
void destroyed( QWidget* widget );
protected:
void keyPressEvent( QKeyEvent* event );
@@ -60,6 +63,8 @@ private slots:
void addItemsToPlaylist();
void deleteItems();
void onDeleted();
private:
void setupMenus();

View File

@@ -50,7 +50,7 @@ public:
/** subclasses implementing ViewPage can emit the following signals:
* descriptionChanged( const QString& )
* deleted()
* destroyed( QWidget* widget );
*
* See DynamicWidget for an example
*/