1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-21 08:19:42 +01:00

* Wait for the playlist to be created before we add stuff to it.

This commit is contained in:
Christian Muehlhaeuser 2011-05-19 04:42:01 +02:00
parent 4c4af2658b
commit 273eb9654f
4 changed files with 42 additions and 26 deletions

View File

@ -47,7 +47,7 @@ DatabaseCommand_CreatePlaylist::DatabaseCommand_CreatePlaylist( const source_ptr
void
DatabaseCommand_CreatePlaylist::exec( DatabaseImpl* lib )
{
createPlaylist(lib, false);
createPlaylist( lib, false );
}
@ -55,32 +55,29 @@ void
DatabaseCommand_CreatePlaylist::postCommitHook()
{
qDebug() << Q_FUNC_INFO;
if ( source().isNull() || source()->collection().isNull() )
{
qDebug() << "Source has gone offline, not emitting to GUI.";
return;
}
if( m_report == false )
if ( m_report == false )
return;
qDebug() << Q_FUNC_INFO << "..reporting..";
if( m_playlist.isNull() ) {
qDebug() << Q_FUNC_INFO << "reporting...";
if ( m_playlist.isNull() )
{
source_ptr src = source();
QMetaObject::invokeMethod( ViewManager::instance(),
"createPlaylist",
Qt::BlockingQueuedConnection,
QGenericArgument( "Tomahawk::source_ptr", (const void*)&src ),
Q_ARG( QVariant, m_v )
);
} else {
"createPlaylist",
Qt::BlockingQueuedConnection,
QGenericArgument( "Tomahawk::source_ptr", (const void*)&src ),
Q_ARG( QVariant, m_v ) );
}
else
{
m_playlist->reportCreated( m_playlist );
}
if( source()->isLocal() )
if ( source()->isLocal() )
Servent::instance()->triggerDBSync();
}
void
DatabaseCommand_CreatePlaylist::createPlaylist( DatabaseImpl* lib, bool dynamic)
{
@ -89,7 +86,7 @@ DatabaseCommand_CreatePlaylist::createPlaylist( DatabaseImpl* lib, bool dynamic)
Q_ASSERT( !source().isNull() );
uint now = 0;
if( m_playlist.isNull() )
if ( m_playlist.isNull() )
{
now = m_v.toMap()[ "createdon" ].toUInt();
}
@ -106,14 +103,17 @@ DatabaseCommand_CreatePlaylist::createPlaylist( DatabaseImpl* lib, bool dynamic)
cre.bindValue( ":source", source()->isLocal() ? QVariant(QVariant::Int) : source()->id() );
cre.bindValue( ":dynplaylist", dynamic );
cre.bindValue( ":createdOn", now );
if( !m_playlist.isNull() ) {
if ( !m_playlist.isNull() )
{
cre.bindValue( ":guid", m_playlist->guid() );
cre.bindValue( ":shared", m_playlist->shared() );
cre.bindValue( ":title", m_playlist->title() );
cre.bindValue( ":info", m_playlist->info() );
cre.bindValue( ":creator", m_playlist->creator() );
cre.bindValue( ":lastmodified", m_playlist->lastmodified() );
} else {
}
else
{
QVariantMap m = m_v.toMap();
cre.bindValue( ":guid", m.value( "guid" ) );
cre.bindValue( ":shared", m.value( "shared" ) );

View File

@ -137,7 +137,7 @@ GlobalActionManager::handlePlaylistCommand( const QUrl& url )
if( parts[ 0 ] == "import" ) {
if( !url.hasQueryItem( "xspf" ) ) {
qDebug() << "No xspf to load..";
qDebug() << "No xspf to load...";
return false;
}
QUrl xspf = QUrl( url.queryItemValue( "xspf" ) );

View File

@ -133,7 +133,8 @@ XSPFLoader::gotBody()
QString artist, album, track, duration, annotation, url;
QDomElement n = e.firstChildElement();
for ( ; !n.isNull(); n = n.nextSiblingElement() ) {
for ( ; !n.isNull(); n = n.nextSiblingElement() )
{
if (n.namespaceURI() == m_NS && n.localName() == "duration") {
duration = n.text();
} else if (n.namespaceURI() == m_NS && n.localName() == "annotation") {
@ -149,8 +150,10 @@ XSPFLoader::gotBody()
}
}
if( artist.isEmpty() || track.isEmpty() ) {
if( !shownError ) {
if( artist.isEmpty() || track.isEmpty() )
{
if( !shownError )
{
QMessageBox::warning( 0, tr( "Failed to save tracks" ), tr( "Some tracks in the playlist do not contain an artist and a title. They will be ignored." ), QMessageBox::Ok );
shownError = true;
}
@ -167,6 +170,7 @@ XSPFLoader::gotBody()
p->query()->setDuration( duration.toInt() / 1000 );
if( !url.isEmpty() )
p->query()->setResultHint( url );
m_entries << p;
}
@ -194,9 +198,19 @@ XSPFLoader::gotBody()
m_creator,
false );
m_playlist->createNewRevision( uuid(), m_playlist->currentrevision(), m_entries );
deleteLater();
connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), SLOT( onCreated() ) );
}
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();
}

View File

@ -66,6 +66,8 @@ private slots:
void networkLoadFinished();
void networkError( QNetworkReply::NetworkError e );
void onCreated();
private:
void reportError();
void gotBody();