1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-13 20:39:57 +01:00

Remove SourceTreePopupDialog usage from Playlist

This commit is contained in:
Teo Mrnjavac 2013-07-03 13:24:50 +02:00
parent 57ab8a5ce9
commit 5b6e9137b8
3 changed files with 35 additions and 89 deletions

View File

@ -286,72 +286,6 @@ Playlist::hasCustomDeleter() const
}
void
Playlist::customDelete( const QPoint& leftCenter )
{
Q_D( Playlist );
if ( !hasCustomDeleter() )
return;
Tomahawk::PlaylistDeleteQuestions questions;
foreach ( PlaylistUpdaterInterface* updater, d->updaters )
{
if ( updater->deleteQuestions().isEmpty() )
continue;
questions.append( updater->deleteQuestions() );
}
SourceTreePopupDialog* dialog = new SourceTreePopupDialog;
NewClosure( dialog, SIGNAL( result( bool ) ), this, SLOT( onDeleteResult( SourceTreePopupDialog* ) ), dialog );
dialog->setMainText( tr( "Would you like to delete the playlist <b>\"%2\"</b>?", "e.g. Would you like to delete the playlist named Foobar?" )
.arg( title() ) );
dialog->setOkButtonText( tr( "Delete" ) );
dialog->setExtraQuestions( questions );
dialog->move( leftCenter.x() - dialog->offset(), leftCenter.y() - dialog->sizeHint().height() / 2. );
dialog->show();
}
void
Playlist::onDeleteResult( SourceTreePopupDialog* dialog )
{
Q_D( Playlist );
dialog->deleteLater();
const bool ret = dialog->resultValue();
if ( !ret )
return;
playlist_ptr p = d->weakSelf.toStrongRef();
if ( p.isNull() )
{
qWarning() << "Got null m_weakSelf weak ref in Playlsit::onDeleteResult!!";
Q_ASSERT( false );
return;
}
const QMap< int, bool > questionResults = dialog->questionResults();
foreach ( PlaylistUpdaterInterface* updater, d->updaters )
{
updater->setQuestionResults( questionResults );
}
dynplaylist_ptr dynpl = p.dynamicCast< DynamicPlaylist >();
if ( !dynpl.isNull() )
{
DynamicPlaylist::remove( dynpl );
}
else
{
remove( p );
}
}
void
Playlist::loadRevision( const QString& rev )
{

View File

@ -140,12 +140,6 @@ public:
* user prompting on delete.
*/
bool hasCustomDeleter() const;
/**
* If this playlist has a custom deleter, let it do the deleting itself.
*
* If it needs user prompting, use the \param customDeleter as the right-most center point.
*/
void customDelete( const QPoint& rightCenter );
Tomahawk::playlistinterface_ptr playlistInterface();
@ -258,8 +252,6 @@ private slots:
void onResultsChanged();
void onResolvingFinished();
void onDeleteResult( SourceTreePopupDialog* );
private:
Playlist();
void init();

View File

@ -398,27 +398,35 @@ SourceTreeView::deletePlaylist( const QModelIndex& idxIn )
playlist_ptr playlist = item->playlist();
QPoint rightCenter = viewport()->mapToGlobal( visualRect( idx ).topRight() + QPoint( 0, visualRect( idx ).height() / 2 ) );
Tomahawk::PlaylistDeleteQuestions questions;
if ( playlist->hasCustomDeleter() )
{
playlist->customDelete( rightCenter );
}
else
{
if ( m_popupDialog.isNull() )
foreach ( Tomahawk::PlaylistUpdaterInterface* updater, playlist->updaters() )
{
m_popupDialog = QPointer< SourceTreePopupDialog >( new SourceTreePopupDialog() );
connect( m_popupDialog.data(), SIGNAL( result( bool ) ), this, SLOT( onDeletePlaylistResult( bool ) ) );
if ( updater->deleteQuestions().isEmpty() )
continue;
questions.append( updater->deleteQuestions() );
}
m_popupDialog.data()->setMainText( tr( "Would you like to delete the %1 <b>\"%2\"</b>?", "e.g. Would you like to delete the playlist named Foobar?" )
.arg( typeDesc ).arg( idx.data().toString() ) );
m_popupDialog.data()->setOkButtonText( tr( "Delete" ) );
m_popupDialog.data()->setProperty( "idx", QVariant::fromValue< QModelIndex >( idx ) );
m_popupDialog.data()->move( rightCenter.x() - m_popupDialog.data()->offset(), rightCenter.y() - m_popupDialog.data()->sizeHint().height() / 2. );
m_popupDialog.data()->show();
}
if ( m_popupDialog.isNull() )
{
m_popupDialog = QPointer< SourceTreePopupDialog >( new SourceTreePopupDialog() );
connect( m_popupDialog.data(), SIGNAL( result( bool ) ), this, SLOT( onDeletePlaylistResult( bool ) ) );
}
m_popupDialog.data()->setMainText( tr( "Would you like to delete the %1 <b>\"%2\"</b>?", "e.g. Would you like to delete the playlist named Foobar?" )
.arg( typeDesc ).arg( idx.data().toString() ) );
m_popupDialog.data()->setOkButtonText( tr( "Delete" ) );
m_popupDialog.data()->setProperty( "idx", QVariant::fromValue< QModelIndex >( idx ) );
if ( !questions.isEmpty() )
m_popupDialog.data()->setExtraQuestions( questions );
m_popupDialog.data()->move( rightCenter.x() - m_popupDialog.data()->offset(), rightCenter.y() - m_popupDialog.data()->sizeHint().height() / 2. );
m_popupDialog.data()->show();
}
@ -433,12 +441,19 @@ SourceTreeView::onDeletePlaylistResult( bool result )
if ( !result )
return;
const QMap< int, bool > questionResults = m_popupDialog.data()->questionResults();
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( idx, SourcesModel::SourceTreeItemTypeRole ).toInt();
if ( type == SourcesModel::StaticPlaylist )
{
PlaylistItem* item = itemFromIndex< PlaylistItem >( idx );
playlist_ptr playlist = item->playlist();
foreach ( Tomahawk::PlaylistUpdaterInterface* updater, playlist->updaters() )
{
updater->setQuestionResults( questionResults );
}
qDebug() << "Doing delete of playlist:" << playlist->title();
Playlist::remove( playlist );
}
@ -446,6 +461,11 @@ SourceTreeView::onDeletePlaylistResult( bool result )
{
DynamicPlaylistItem* item = itemFromIndex< DynamicPlaylistItem >( idx );
dynplaylist_ptr playlist = item->dynPlaylist();
foreach ( Tomahawk::PlaylistUpdaterInterface* updater, playlist->updaters() )
{
updater->setQuestionResults( questionResults );
}
qDebug() << "Doing delete of playlist:" << playlist->title();
DynamicPlaylist::remove( playlist );
}