1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

Factor out some code

This commit is contained in:
Leo Franchi 2012-06-17 00:09:59 +02:00
parent 89ab3344d4
commit acd6e75a10
2 changed files with 30 additions and 26 deletions

View File

@ -433,21 +433,13 @@ GlobalActionManager::handlePlaylistCommand( const QUrl& url )
}
if ( url.hasQueryItem( "xspf" ) )
{
QUrl xspf = QUrl::fromUserInput( url.queryItemValue( "xspf" ) );
QString title = url.hasQueryItem( "title" ) ? url.queryItemValue( "title" ) : QString();
XSPFLoader* l= new XSPFLoader( true, this );
l->setOverrideTitle( title );
l->load( xspf );
connect( l, SIGNAL( ok( Tomahawk::playlist_ptr ) ), this, SLOT( playlistCreatedToShow( Tomahawk::playlist_ptr) ) );
createPlaylistFromUrl( "xspf", url.queryItemValue( "xspf" ), url.hasQueryItem( "title" ) ? url.queryItemValue( "title" ) : QString() );
return true;
}
else if ( url.hasQueryItem( "jspf" ) )
{
QUrl jspf = QUrl::fromUserInput( url.queryItemValue( "jspf" ) );
QString title = url.hasQueryItem( "title" ) ? url.queryItemValue( "title" ) : QString();
JSPFLoader* l= new JSPFLoader( true, this );
l->setOverrideTitle( title );
l->load( jspf );
connect( l, SIGNAL( ok( Tomahawk::playlist_ptr ) ), this, SLOT( playlistCreatedToShow( Tomahawk::playlist_ptr) ) );
createPlaylistFromUrl( "jspf", url.queryItemValue( "jspf" ), url.hasQueryItem( "title" ) ? url.queryItemValue( "title" ) : QString() );
return true;
}
}
else if ( parts [ 0 ] == "new" )
@ -486,24 +478,12 @@ GlobalActionManager::handleImportCommand( const QUrl& url )
{
if ( url.hasQueryItem( "xspf" ) )
{
QUrl xspf = QUrl::fromUserInput( url.queryItemValue( "xspf" ) );
QString title = url.hasQueryItem( "title" ) ? url.queryItemValue( "title" ) : QString();
XSPFLoader* l= new XSPFLoader( true, this );
l->setOverrideTitle( title );
l->load( xspf );
connect( l, SIGNAL( ok( Tomahawk::playlist_ptr ) ), this, SLOT( playlistCreatedToShow( Tomahawk::playlist_ptr) ) );
createPlaylistFromUrl( "xspf", url.queryItemValue( "xspf" ), url.hasQueryItem( "title" ) ? url.queryItemValue( "title" ) : QString() );
return true;
}
else if ( url.hasQueryItem( "jspf" ) )
{
QUrl jspf = QUrl::fromUserInput( url.queryItemValue( "jspf" ) );
QString title = url.hasQueryItem( "title" ) ? url.queryItemValue( "title" ) : QString();
JSPFLoader* l= new JSPFLoader( true, this );
l->setOverrideTitle( title );
l->load( jspf );
connect( l, SIGNAL( ok( Tomahawk::playlist_ptr ) ), this, SLOT( playlistCreatedToShow( Tomahawk::playlist_ptr) ) );
createPlaylistFromUrl( "jspf", url.queryItemValue( "jspf" ), url.hasQueryItem( "title" ) ? url.queryItemValue( "title" ) : QString() );
return true;
}
}
@ -512,6 +492,28 @@ GlobalActionManager::handleImportCommand( const QUrl& url )
}
void
GlobalActionManager::createPlaylistFromUrl( const QString& type, const QString &url, const QString& title )
{
if ( type == "xspf" )
{
QUrl xspf = QUrl::fromUserInput( url );
XSPFLoader* l= new XSPFLoader( true, this );
l->setOverrideTitle( title );
l->load( xspf );
connect( l, SIGNAL( ok( Tomahawk::playlist_ptr ) ), this, SLOT( playlistCreatedToShow( Tomahawk::playlist_ptr) ) );
}
else if ( type == "jspf" )
{
QUrl jspf = QUrl::fromUserInput( url );
JSPFLoader* l= new JSPFLoader( true, this );
l->setOverrideTitle( title );
l->load( jspf );
connect( l, SIGNAL( ok( Tomahawk::playlist_ptr ) ), this, SLOT( playlistCreatedToShow( Tomahawk::playlist_ptr) ) );
}
}
void
GlobalActionManager::playlistCreatedToShow( const playlist_ptr& pl )
{

View File

@ -125,6 +125,8 @@ private:
bool handleBookmarkCommand( const QUrl& url );
bool handleOpenCommand( const QUrl& url );
void createPlaylistFromUrl( const QString& type, const QString& url, const QString& title );
QString hostname() const;
Tomahawk::playlist_ptr m_toShow;