diff --git a/src/libtomahawk/database/databasecommand_createplaylist.cpp b/src/libtomahawk/database/databasecommand_createplaylist.cpp index 8a5bfa940..8fac07f33 100644 --- a/src/libtomahawk/database/databasecommand_createplaylist.cpp +++ b/src/libtomahawk/database/databasecommand_createplaylist.cpp @@ -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" ) ); diff --git a/src/libtomahawk/globalactionmanager.cpp b/src/libtomahawk/globalactionmanager.cpp index 1526b96b3..28b811569 100644 --- a/src/libtomahawk/globalactionmanager.cpp +++ b/src/libtomahawk/globalactionmanager.cpp @@ -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" ) ); diff --git a/src/libtomahawk/utils/xspfloader.cpp b/src/libtomahawk/utils/xspfloader.cpp index c02897ec8..8cb6cf9e6 100644 --- a/src/libtomahawk/utils/xspfloader.cpp +++ b/src/libtomahawk/utils/xspfloader.cpp @@ -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(); +} diff --git a/src/libtomahawk/utils/xspfloader.h b/src/libtomahawk/utils/xspfloader.h index e058faf22..6be105739 100644 --- a/src/libtomahawk/utils/xspfloader.h +++ b/src/libtomahawk/utils/xspfloader.h @@ -66,6 +66,8 @@ private slots: void networkLoadFinished(); void networkError( QNetworkReply::NetworkError e ); + void onCreated(); + private: void reportError(); void gotBody();