1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-01 11:50:37 +02:00

* DRY: Call main window and let it create a new playlist.

This commit is contained in:
Christian Muehlhaeuser
2012-06-01 03:34:17 +02:00
parent 062e7a5a3e
commit 690c80db60
2 changed files with 14 additions and 38 deletions

View File

@@ -29,7 +29,6 @@
#include "utils/TomahawkUtils.h" #include "utils/TomahawkUtils.h"
#include "widgets/NewPlaylistWidget.h" #include "widgets/NewPlaylistWidget.h"
#include "TomahawkWindow.h" #include "TomahawkWindow.h"
#include "widgets/PlaylistTypeSelectorDialog.h"
#include <playlist/dynamic/GeneratorInterface.h> #include <playlist/dynamic/GeneratorInterface.h>
#include "utils/Logger.h" #include "utils/Logger.h"
#include "DropJob.h" #include "DropJob.h"
@@ -57,11 +56,13 @@ CategoryAddItem::~CategoryAddItem()
QString QString
CategoryAddItem::text() const CategoryAddItem::text() const
{ {
switch( m_categoryType ) { switch( m_categoryType )
{
case SourcesModel::PlaylistsCategory: case SourcesModel::PlaylistsCategory:
return tr( "New Playlist" ); return tr( "Create new Playlist" );
case SourcesModel::StationsCategory: case SourcesModel::StationsCategory:
return tr( "New Station" ); return tr( "Create new Station" );
} }
return QString(); return QString();
@@ -73,46 +74,16 @@ CategoryAddItem::activate()
{ {
switch( m_categoryType ) switch( m_categoryType )
{ {
case SourcesModel::PlaylistsCategory: { case SourcesModel::PlaylistsCategory:
APP->mainWindow()->createPlaylist();
PlaylistTypeSelectorDlg* playlistSelectorDlg = new PlaylistTypeSelectorDlg( TomahawkApp::instance()->mainWindow(), Qt::Sheet );
#ifndef Q_WS_MAC
playlistSelectorDlg->setModal( true );
#endif
connect( playlistSelectorDlg, SIGNAL( finished( int ) ), this, SLOT( dialogClosed( int ) ) );
playlistSelectorDlg->show();
break; break;
}
case SourcesModel::StationsCategory: case SourcesModel::StationsCategory:
APP->mainWindow()->createStation(); APP->mainWindow()->createStation();
break; break;
} }
} }
void
CategoryAddItem::dialogClosed( int ret )
{
PlaylistTypeSelectorDlg* playlistSelectorDlg = qobject_cast< PlaylistTypeSelectorDlg* >( sender() );
Q_ASSERT( playlistSelectorDlg );
QString playlistName = playlistSelectorDlg->playlistName();
if ( playlistName.isEmpty() )
playlistName = tr( "New Playlist" );
if ( !playlistSelectorDlg->playlistTypeIsAuto() && ret ) {
playlist_ptr playlist = Tomahawk::Playlist::create( SourceList::instance()->getLocal(), uuid(), playlistName, "", "", false, QList< query_ptr>() );
ViewManager::instance()->show( playlist );
} else if ( playlistSelectorDlg->playlistTypeIsAuto() && ret ) {
// create Auto Playlist
APP->mainWindow()->createAutomaticPlaylist( playlistName );
} else if ( !ret ) {
model()->viewPageActivated( ViewManager::instance()->currentPage() );
}
playlistSelectorDlg->deleteLater();
}
Qt::ItemFlags Qt::ItemFlags
CategoryAddItem::flags() const CategoryAddItem::flags() const
@@ -121,8 +92,10 @@ CategoryAddItem::flags() const
{ {
case SourcesModel::PlaylistsCategory: case SourcesModel::PlaylistsCategory:
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled; return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
case SourcesModel::StationsCategory: case SourcesModel::StationsCategory:
return Qt::ItemIsEnabled | Qt::ItemIsDropEnabled; return Qt::ItemIsEnabled | Qt::ItemIsDropEnabled;
default: default:
return Qt::ItemIsEnabled; return Qt::ItemIsEnabled;
break; break;
@@ -144,9 +117,11 @@ CategoryAddItem::willAcceptDrag( const QMimeData* data ) const
{ {
return true; return true;
} }
return false; return false;
} }
SourceTreeItem::DropTypes SourceTreeItem::DropTypes
CategoryAddItem::supportedDropTypes( const QMimeData* data ) const CategoryAddItem::supportedDropTypes( const QMimeData* data ) const
{ {
@@ -284,6 +259,7 @@ CategoryAddItem::dropMimeData( const QMimeData* data, Qt::DropAction )
return true; return true;
} }
void void
CategoryAddItem::playlistToRenameLoaded() CategoryAddItem::playlistToRenameLoaded()
{ {

View File

@@ -40,10 +40,10 @@ public:
private slots: private slots:
void parsedDroppedTracks( const QList< Tomahawk::query_ptr >& tracks ); void parsedDroppedTracks( const QList< Tomahawk::query_ptr >& tracks );
void dialogClosed( int ret );
// Do the rename only after the revision is loaded // Do the rename only after the revision is loaded
void playlistToRenameLoaded(); void playlistToRenameLoaded();
private: private:
SourcesModel::CategoryType m_categoryType; SourcesModel::CategoryType m_categoryType;
QIcon m_icon; QIcon m_icon;