mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-13 17:43:59 +02:00
Remove SourceTreePopupDialog usage from Playlist
This commit is contained in:
@@ -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
|
void
|
||||||
Playlist::loadRevision( const QString& rev )
|
Playlist::loadRevision( const QString& rev )
|
||||||
{
|
{
|
||||||
|
@@ -140,12 +140,6 @@ public:
|
|||||||
* user prompting on delete.
|
* user prompting on delete.
|
||||||
*/
|
*/
|
||||||
bool hasCustomDeleter() const;
|
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();
|
Tomahawk::playlistinterface_ptr playlistInterface();
|
||||||
|
|
||||||
@@ -258,8 +252,6 @@ private slots:
|
|||||||
void onResultsChanged();
|
void onResultsChanged();
|
||||||
void onResolvingFinished();
|
void onResolvingFinished();
|
||||||
|
|
||||||
void onDeleteResult( SourceTreePopupDialog* );
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Playlist();
|
Playlist();
|
||||||
void init();
|
void init();
|
||||||
|
@@ -398,27 +398,35 @@ SourceTreeView::deletePlaylist( const QModelIndex& idxIn )
|
|||||||
playlist_ptr playlist = item->playlist();
|
playlist_ptr playlist = item->playlist();
|
||||||
QPoint rightCenter = viewport()->mapToGlobal( visualRect( idx ).topRight() + QPoint( 0, visualRect( idx ).height() / 2 ) );
|
QPoint rightCenter = viewport()->mapToGlobal( visualRect( idx ).topRight() + QPoint( 0, visualRect( idx ).height() / 2 ) );
|
||||||
|
|
||||||
|
Tomahawk::PlaylistDeleteQuestions questions;
|
||||||
if ( playlist->hasCustomDeleter() )
|
if ( playlist->hasCustomDeleter() )
|
||||||
{
|
{
|
||||||
playlist->customDelete( rightCenter );
|
foreach ( Tomahawk::PlaylistUpdaterInterface* updater, playlist->updaters() )
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( m_popupDialog.isNull() )
|
|
||||||
{
|
{
|
||||||
m_popupDialog = QPointer< SourceTreePopupDialog >( new SourceTreePopupDialog() );
|
if ( updater->deleteQuestions().isEmpty() )
|
||||||
connect( m_popupDialog.data(), SIGNAL( result( bool ) ), this, SLOT( onDeletePlaylistResult( bool ) ) );
|
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 )
|
if ( !result )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const QMap< int, bool > questionResults = m_popupDialog.data()->questionResults();
|
||||||
|
|
||||||
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( idx, SourcesModel::SourceTreeItemTypeRole ).toInt();
|
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( idx, SourcesModel::SourceTreeItemTypeRole ).toInt();
|
||||||
|
|
||||||
if ( type == SourcesModel::StaticPlaylist )
|
if ( type == SourcesModel::StaticPlaylist )
|
||||||
{
|
{
|
||||||
PlaylistItem* item = itemFromIndex< PlaylistItem >( idx );
|
PlaylistItem* item = itemFromIndex< PlaylistItem >( idx );
|
||||||
playlist_ptr playlist = item->playlist();
|
playlist_ptr playlist = item->playlist();
|
||||||
|
foreach ( Tomahawk::PlaylistUpdaterInterface* updater, playlist->updaters() )
|
||||||
|
{
|
||||||
|
updater->setQuestionResults( questionResults );
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "Doing delete of playlist:" << playlist->title();
|
qDebug() << "Doing delete of playlist:" << playlist->title();
|
||||||
Playlist::remove( playlist );
|
Playlist::remove( playlist );
|
||||||
}
|
}
|
||||||
@@ -446,6 +461,11 @@ SourceTreeView::onDeletePlaylistResult( bool result )
|
|||||||
{
|
{
|
||||||
DynamicPlaylistItem* item = itemFromIndex< DynamicPlaylistItem >( idx );
|
DynamicPlaylistItem* item = itemFromIndex< DynamicPlaylistItem >( idx );
|
||||||
dynplaylist_ptr playlist = item->dynPlaylist();
|
dynplaylist_ptr playlist = item->dynPlaylist();
|
||||||
|
foreach ( Tomahawk::PlaylistUpdaterInterface* updater, playlist->updaters() )
|
||||||
|
{
|
||||||
|
updater->setQuestionResults( questionResults );
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "Doing delete of playlist:" << playlist->title();
|
qDebug() << "Doing delete of playlist:" << playlist->title();
|
||||||
DynamicPlaylist::remove( playlist );
|
DynamicPlaylist::remove( playlist );
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user