Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying songs in playlist creation URL #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions src/libtomahawk/GlobalActionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,39 @@ GlobalActionManager::parseTomahawkLink( const QString& urlIn )
}
}

bool GlobalActionManager::handleNewPlaylistCommand( const QUrl& url )
{
QList< Tomahawk::query_ptr > entries;
if ( !urlHasQueryItem( url, "title" ) )
{
tLog() << "New playlist command needs a title...";
return false;
}
// Add tracks to the playlist using track_X_artist and track_X_title where X is the postition (starting at 0)
unsigned int trackIndex = 0;
QString artistTemplate = QString( "track_%1_artist" );
QString titleTemplate = QString( "track_%1_title" );
while ( urlHasQueryItem( url, titleTemplate.arg( QString::number(trackIndex) ) ) || urlHasQueryItem( url, artistTemplate.arg( QString::number(trackIndex) ) ) )
{
if ( !urlHasQueryItem( url, artistTemplate.arg( QString::number( trackIndex ) ) ) )
{
tLog() << "Each track needs an artist...";
return false;
}
if ( !urlHasQueryItem( url, titleTemplate.arg( QString::number( trackIndex ) ) ) )
{
tLog() << "Each track needs a title...";
return false;
}
QString artist = urlQueryItemValue( url, artistTemplate.arg( QString::number( trackIndex ) ) );
QString title = urlQueryItemValue( url, titleTemplate.arg( QString::number( trackIndex ) ) );
entries << Tomahawk::Query::get( artist, title, QString(), uuid(), true );
trackIndex++;
}
playlist_ptr pl = Playlist::create( SourceList::instance()->getLocal(), uuid(), urlQueryItemValue( url, "title" ), QString(), QString(), false, entries );
ViewManager::instance()->show( pl );
return true;
}

bool
GlobalActionManager::handlePlaylistCommand( const QUrl& url )
Expand Down Expand Up @@ -430,13 +463,7 @@ GlobalActionManager::handlePlaylistCommand( const QUrl& url )
}
else if ( parts [ 0 ] == "new" )
{
if ( !urlHasQueryItem( url, "title" ) )
{
tLog() << "New playlist command needs a title...";
return false;
}
playlist_ptr pl = Playlist::create( SourceList::instance()->getLocal(), uuid(), urlQueryItemValue( url, "title" ), QString(), QString(), false );
ViewManager::instance()->show( pl );
handleNewPlaylistCommand( url );
}
else if ( parts[ 0 ] == "add" )
{
Expand Down
1 change: 1 addition & 0 deletions src/libtomahawk/GlobalActionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private slots:

/// handle opening of urls
#ifndef ENABLE_HEADLESS
bool handleNewPlaylistCommand( const QUrl& url );
bool handlePlaylistCommand( const QUrl& url );
bool handleViewCommand( const QUrl& url );
bool handleStationCommand( const QUrl& url );
Expand Down