mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 13:47:26 +02:00
* Streamlined creating new playlists with entries.
* Made XSPFLoader, NewPlaylistWidget & GlobalActionManager use the new Playlist API. * This prevents race-conditions. * Fixed not being able to re-order playlist items.
This commit is contained in:
@@ -62,6 +62,10 @@ void
|
|||||||
Collection::addPlaylist( const Tomahawk::playlist_ptr& p )
|
Collection::addPlaylist( const Tomahawk::playlist_ptr& p )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
|
if ( m_playlists.contains( p->guid() ) )
|
||||||
|
return;
|
||||||
|
|
||||||
QList<playlist_ptr> toadd;
|
QList<playlist_ptr> toadd;
|
||||||
toadd << p;
|
toadd << p;
|
||||||
qDebug() << "Inserted playlist with guid:" << p->guid();
|
qDebug() << "Inserted playlist with guid:" << p->guid();
|
||||||
|
@@ -56,12 +56,6 @@ void
|
|||||||
DatabaseCommand_SetPlaylistRevision::postCommitHook()
|
DatabaseCommand_SetPlaylistRevision::postCommitHook()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
if ( source().isNull() || source()->collection().isNull() )
|
|
||||||
{
|
|
||||||
qDebug() << "Source has gone offline, not emitting to GUI.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( m_localOnly )
|
if ( m_localOnly )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@@ -153,7 +153,6 @@ GlobalActionManager::handlePlaylistCommand( const QUrl& url )
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Tomahawk::playlist_ptr pl = Tomahawk::Playlist::create( SourceList::instance()->getLocal(), uuid(), url.queryItemValue( "title" ), QString(), QString(), false );
|
Tomahawk::playlist_ptr pl = Tomahawk::Playlist::create( SourceList::instance()->getLocal(), uuid(), url.queryItemValue( "title" ), QString(), QString(), false );
|
||||||
pl->createNewRevision( uuid(), pl->currentrevision(), QList< Tomahawk::plentry_ptr >() );
|
|
||||||
ViewManager::instance()->show( pl );
|
ViewManager::instance()->show( pl );
|
||||||
} else if( parts[ 0 ] == "add" ) {
|
} else if( parts[ 0 ] == "add" ) {
|
||||||
if( !url.hasQueryItem( "playlistid" ) || !url.hasQueryItem( "title" ) || !url.hasQueryItem( "artist" ) ) {
|
if( !url.hasQueryItem( "playlistid" ) || !url.hasQueryItem( "title" ) || !url.hasQueryItem( "artist" ) ) {
|
||||||
|
@@ -125,7 +125,8 @@ Playlist::Playlist( const source_ptr& author,
|
|||||||
const QString& title,
|
const QString& title,
|
||||||
const QString& info,
|
const QString& info,
|
||||||
const QString& creator,
|
const QString& creator,
|
||||||
bool shared )
|
bool shared,
|
||||||
|
const QList< Tomahawk::plentry_ptr >& entries )
|
||||||
: QObject()
|
: QObject()
|
||||||
, m_source( author )
|
, m_source( author )
|
||||||
, m_guid( guid )
|
, m_guid( guid )
|
||||||
@@ -136,6 +137,7 @@ Playlist::Playlist( const source_ptr& author,
|
|||||||
, m_createdOn( 0 ) // will be set by db command
|
, m_createdOn( 0 ) // will be set by db command
|
||||||
, m_shared( shared )
|
, m_shared( shared )
|
||||||
, m_busy( false )
|
, m_busy( false )
|
||||||
|
, m_initEntries( entries )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << "2";
|
qDebug() << Q_FUNC_INFO << "2";
|
||||||
init();
|
init();
|
||||||
@@ -159,9 +161,24 @@ Playlist::create( const source_ptr& author,
|
|||||||
const QString& title,
|
const QString& title,
|
||||||
const QString& info,
|
const QString& info,
|
||||||
const QString& creator,
|
const QString& creator,
|
||||||
bool shared )
|
bool shared,
|
||||||
|
const QList<Tomahawk::query_ptr>& queries )
|
||||||
{
|
{
|
||||||
playlist_ptr playlist( new Playlist( author, guid, title, info, creator, shared ) );
|
QList< plentry_ptr > entries;
|
||||||
|
foreach( const Tomahawk::query_ptr& query, queries )
|
||||||
|
{
|
||||||
|
plentry_ptr p( new PlaylistEntry );
|
||||||
|
p->setGuid( uuid() );
|
||||||
|
p->setDuration( query->duration() );
|
||||||
|
p->setLastmodified( 0 );
|
||||||
|
p->setAnnotation( "" );
|
||||||
|
p->setQuery( query );
|
||||||
|
|
||||||
|
entries << p;
|
||||||
|
}
|
||||||
|
|
||||||
|
playlist_ptr playlist( new Playlist( author, guid, title, info, creator, shared, entries ) );
|
||||||
|
|
||||||
// save to DB in the background
|
// save to DB in the background
|
||||||
// Hope this doesn't cause any problems..
|
// Hope this doesn't cause any problems..
|
||||||
// Watch for the created() signal if you need to be sure it's written.
|
// Watch for the created() signal if you need to be sure it's written.
|
||||||
@@ -178,6 +195,7 @@ Playlist::create( const source_ptr& author,
|
|||||||
connect( cmd, SIGNAL( finished() ), playlist.data(), SIGNAL( created() ) );
|
connect( cmd, SIGNAL( finished() ), playlist.data(), SIGNAL( created() ) );
|
||||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
||||||
playlist->reportCreated( playlist );
|
playlist->reportCreated( playlist );
|
||||||
|
|
||||||
return playlist;
|
return playlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,7 +241,6 @@ Playlist::reportCreated( const playlist_ptr& self )
|
|||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
Q_ASSERT( self.data() == this );
|
Q_ASSERT( self.data() == this );
|
||||||
// will emit Collection::playlistCreated(...)
|
|
||||||
m_source->collection()->addPlaylist( self );
|
m_source->collection()->addPlaylist( self );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,6 +354,13 @@ Playlist::setRevision( const QString& rev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
setBusy( false );
|
setBusy( false );
|
||||||
|
|
||||||
|
if ( m_initEntries.count() && currentrevision().isEmpty() )
|
||||||
|
{
|
||||||
|
// add initial tracks
|
||||||
|
createNewRevision( uuid(), currentrevision(), m_initEntries );
|
||||||
|
}
|
||||||
|
else
|
||||||
emit revisionLoaded( pr );
|
emit revisionLoaded( pr );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -127,7 +127,8 @@ public:
|
|||||||
const QString& title,
|
const QString& title,
|
||||||
const QString& info,
|
const QString& info,
|
||||||
const QString& creator,
|
const QString& creator,
|
||||||
bool shared );
|
bool shared,
|
||||||
|
const QList<Tomahawk::query_ptr>& queries = QList<Tomahawk::query_ptr>() );
|
||||||
|
|
||||||
static bool remove( const playlist_ptr& playlist );
|
static bool remove( const playlist_ptr& playlist );
|
||||||
bool rename( const QString& title );
|
bool rename( const QString& title );
|
||||||
@@ -232,7 +233,8 @@ protected:
|
|||||||
const QString& title,
|
const QString& title,
|
||||||
const QString& info,
|
const QString& info,
|
||||||
const QString& creator,
|
const QString& creator,
|
||||||
bool shared );
|
bool shared,
|
||||||
|
const QList< Tomahawk::plentry_ptr >& entries = QList< Tomahawk::plentry_ptr >() );
|
||||||
|
|
||||||
QList< plentry_ptr > newEntries( const QList< plentry_ptr >& entries );
|
QList< plentry_ptr > newEntries( const QList< plentry_ptr >& entries );
|
||||||
PlaylistRevision setNewRevision( const QString& rev,
|
PlaylistRevision setNewRevision( const QString& rev,
|
||||||
@@ -260,7 +262,9 @@ private:
|
|||||||
unsigned int m_createdOn;
|
unsigned int m_createdOn;
|
||||||
bool m_shared;
|
bool m_shared;
|
||||||
|
|
||||||
|
QList< plentry_ptr > m_initEntries;
|
||||||
QList< plentry_ptr > m_entries;
|
QList< plentry_ptr > m_entries;
|
||||||
|
|
||||||
bool m_locallyChanged;
|
bool m_locallyChanged;
|
||||||
bool m_busy;
|
bool m_busy;
|
||||||
};
|
};
|
||||||
|
@@ -326,10 +326,6 @@ PlaylistModel::dropMimeData( const QMimeData* data, Qt::DropAction action, int r
|
|||||||
&& !data->hasFormat( "application/tomahawk.result.list" ) )
|
&& !data->hasFormat( "application/tomahawk.result.list" ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( data->hasFormat( "application/tomahawk.playlist.id" ) &&
|
|
||||||
data->data( "application/tomahawk.playlist.id" ) == m_playlist->guid() )
|
|
||||||
return false; // don't allow dropping on ourselves
|
|
||||||
|
|
||||||
int beginRow;
|
int beginRow;
|
||||||
if ( row != -1 )
|
if ( row != -1 )
|
||||||
beginRow = row;
|
beginRow = row;
|
||||||
|
@@ -160,18 +160,12 @@ XSPFLoader::gotBody()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
plentry_ptr p( new PlaylistEntry );
|
query_ptr q = Tomahawk::Query::get( artist, track, album, uuid() );
|
||||||
p->setGuid( uuid() );
|
q->setDuration( duration.toInt() / 1000 );
|
||||||
p->setDuration( duration.toInt() / 1000 );
|
|
||||||
p->setLastmodified( 0 );
|
|
||||||
p->setAnnotation( annotation );
|
|
||||||
|
|
||||||
p->setQuery( Tomahawk::Query::get( artist, track, album, uuid() ) );
|
|
||||||
p->query()->setDuration( duration.toInt() / 1000 );
|
|
||||||
if( !url.isEmpty() )
|
if( !url.isEmpty() )
|
||||||
p->query()->setResultHint( url );
|
q->setResultHint( url );
|
||||||
|
|
||||||
m_entries << p;
|
m_entries << q;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( origTitle.isEmpty() && m_entries.isEmpty() )
|
if ( origTitle.isEmpty() && m_entries.isEmpty() )
|
||||||
@@ -196,21 +190,11 @@ XSPFLoader::gotBody()
|
|||||||
m_title,
|
m_title,
|
||||||
m_info,
|
m_info,
|
||||||
m_creator,
|
m_creator,
|
||||||
false );
|
false,
|
||||||
|
m_entries );
|
||||||
|
|
||||||
connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), SLOT( onCreated() ) );
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
emit ok( m_playlist );
|
emit ok( m_playlist );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
XSPFLoader::onCreated()
|
|
||||||
{
|
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
|
|
||||||
Playlist* playlist = qobject_cast<Playlist*>(sender());
|
|
||||||
m_playlist->createNewRevision( uuid(), m_playlist->currentrevision(), m_entries );
|
|
||||||
deleteLater();
|
|
||||||
}
|
|
||||||
|
@@ -51,9 +51,10 @@ public:
|
|||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList< Tomahawk::plentry_ptr > entries() const { return m_entries; }
|
QList< Tomahawk::query_ptr > entries() const { return m_entries; }
|
||||||
|
|
||||||
void setOverrideTitle( const QString& newTitle );
|
void setOverrideTitle( const QString& newTitle );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void failed();
|
void failed();
|
||||||
void ok( const Tomahawk::playlist_ptr& );
|
void ok( const Tomahawk::playlist_ptr& );
|
||||||
@@ -66,15 +67,13 @@ private slots:
|
|||||||
void networkLoadFinished();
|
void networkLoadFinished();
|
||||||
void networkError( QNetworkReply::NetworkError e );
|
void networkError( QNetworkReply::NetworkError e );
|
||||||
|
|
||||||
void onCreated();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void reportError();
|
void reportError();
|
||||||
void gotBody();
|
void gotBody();
|
||||||
|
|
||||||
bool m_autoCreate;
|
bool m_autoCreate;
|
||||||
QString m_NS,m_overrideTitle;
|
QString m_NS,m_overrideTitle;
|
||||||
QList< Tomahawk::plentry_ptr > m_entries;
|
QList< Tomahawk::query_ptr > m_entries;
|
||||||
QString m_title, m_info, m_creator;
|
QString m_title, m_info, m_creator;
|
||||||
|
|
||||||
QByteArray m_body;
|
QByteArray m_body;
|
||||||
|
@@ -119,17 +119,17 @@ NewPlaylistWidget::suggestionsFound()
|
|||||||
{
|
{
|
||||||
XSPFLoader* loader = qobject_cast<XSPFLoader*>( sender() );
|
XSPFLoader* loader = qobject_cast<XSPFLoader*>( sender() );
|
||||||
|
|
||||||
m_entries = loader->entries();
|
m_queries = loader->entries();
|
||||||
|
|
||||||
delete m_suggestionsModel;
|
delete m_suggestionsModel;
|
||||||
m_suggestionsModel = new PlaylistModel( ui->suggestionsView );
|
m_suggestionsModel = new PlaylistModel( ui->suggestionsView );
|
||||||
ui->suggestionsView->setPlaylistModel( m_suggestionsModel );
|
ui->suggestionsView->setPlaylistModel( m_suggestionsModel );
|
||||||
|
|
||||||
QList<Tomahawk::query_ptr> ql;
|
QList<Tomahawk::query_ptr> ql;
|
||||||
foreach( const Tomahawk::plentry_ptr& entry, m_entries )
|
foreach( const Tomahawk::query_ptr& query, m_queries )
|
||||||
{
|
{
|
||||||
m_suggestionsModel->append( entry->query() );
|
m_suggestionsModel->append( query );
|
||||||
ql.append( entry->query() );
|
ql.append( query );
|
||||||
}
|
}
|
||||||
|
|
||||||
loader->deleteLater();
|
loader->deleteLater();
|
||||||
@@ -141,8 +141,7 @@ NewPlaylistWidget::savePlaylist()
|
|||||||
{
|
{
|
||||||
Tomahawk::playlist_ptr playlist;
|
Tomahawk::playlist_ptr playlist;
|
||||||
|
|
||||||
playlist = Tomahawk::Playlist::create( SourceList::instance()->getLocal(), uuid(), ui->titleEdit->text(), "", "", false );
|
playlist = Tomahawk::Playlist::create( SourceList::instance()->getLocal(), uuid(), ui->titleEdit->text(), "", "", false, m_queries );
|
||||||
playlist->createNewRevision( uuid(), playlist->currentrevision(), m_entries );
|
|
||||||
|
|
||||||
ViewManager::instance()->show( playlist );
|
ViewManager::instance()->show( playlist );
|
||||||
cancel();
|
cancel();
|
||||||
|
@@ -75,7 +75,7 @@ private:
|
|||||||
Ui::NewPlaylistWidget *ui;
|
Ui::NewPlaylistWidget *ui;
|
||||||
|
|
||||||
PlaylistModel* m_suggestionsModel;
|
PlaylistModel* m_suggestionsModel;
|
||||||
QList< Tomahawk::plentry_ptr > m_entries;
|
QList< Tomahawk::query_ptr > m_queries;
|
||||||
|
|
||||||
QTimer m_filterTimer;
|
QTimer m_filterTimer;
|
||||||
QString m_tag;
|
QString m_tag;
|
||||||
|
@@ -34,12 +34,10 @@ CategoryAddItem::CategoryAddItem( SourcesModel* model, SourceTreeItem* parent, S
|
|||||||
: SourceTreeItem( model, parent, SourcesModel::CategoryAdd )
|
: SourceTreeItem( model, parent, SourcesModel::CategoryAdd )
|
||||||
, m_categoryType( type )
|
, m_categoryType( type )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CategoryAddItem::~CategoryAddItem()
|
CategoryAddItem::~CategoryAddItem()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
@@ -124,8 +122,7 @@ CategoryAddItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
playlist_ptr newpl = Playlist::create( SourceList::instance()->getLocal(), uuid(), "New Playlist", "", SourceList::instance()->getLocal()->friendlyName(), false );
|
playlist_ptr newpl = Playlist::create( SourceList::instance()->getLocal(), uuid(), "New Playlist", "", SourceList::instance()->getLocal()->friendlyName(), false, queries );
|
||||||
newpl->addEntries( queries, newpl->currentrevision() );
|
|
||||||
ViewManager::instance()->show( newpl );
|
ViewManager::instance()->show( newpl );
|
||||||
|
|
||||||
// Give a shot to try to rename it. The playlist has to be created first. ugly.
|
// Give a shot to try to rename it. The playlist has to be created first. ugly.
|
||||||
|
@@ -34,7 +34,6 @@ public:
|
|||||||
virtual bool willAcceptDrag(const QMimeData* data) const;
|
virtual bool willAcceptDrag(const QMimeData* data) const;
|
||||||
virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action);
|
virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SourcesModel::CategoryType m_categoryType;
|
SourcesModel::CategoryType m_categoryType;
|
||||||
};
|
};
|
||||||
|
@@ -131,7 +131,6 @@ PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
|
|||||||
data->data( "application/tomahawk.playlist.id" ) == m_playlist->guid() )
|
data->data( "application/tomahawk.playlist.id" ) == m_playlist->guid() )
|
||||||
return false; // don't allow dropping on ourselves
|
return false; // don't allow dropping on ourselves
|
||||||
|
|
||||||
|
|
||||||
if ( data->hasFormat( "application/tomahawk.result.list" ) )
|
if ( data->hasFormat( "application/tomahawk.result.list" ) )
|
||||||
{
|
{
|
||||||
QByteArray itemData = data->data( "application/tomahawk.result.list" );
|
QByteArray itemData = data->data( "application/tomahawk.result.list" );
|
||||||
@@ -174,8 +173,6 @@ PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
|
|||||||
{
|
{
|
||||||
qDebug() << "on playlist:" << m_playlist->title() << m_playlist->guid() << m_playlist->currentrevision();
|
qDebug() << "on playlist:" << m_playlist->title() << m_playlist->guid() << m_playlist->currentrevision();
|
||||||
|
|
||||||
// TODO do we need to use this in the refactor?
|
|
||||||
// QString rev = item->currentlyLoadedPlaylistRevision( playlist->guid() );
|
|
||||||
m_playlist->addEntries( queries, m_playlist->currentrevision() );
|
m_playlist->addEntries( queries, m_playlist->currentrevision() );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user