From 7966926d0c978012c72bf52d92d46da9470bfdc0 Mon Sep 17 00:00:00 2001 From: Lucas Lira Gomes Date: Tue, 25 Sep 2012 16:40:41 -0300 Subject: [PATCH] * Added methods to create playlists in SourceList class --- src/libtomahawk/SourceList.cpp | 18 ++++++++++++++++++ src/libtomahawk/SourceList.h | 5 +++++ src/libtomahawk/ViewManager.cpp | 18 ------------------ src/libtomahawk/ViewManager.h | 4 ---- .../DatabaseCommand_CreateDynamicPlaylist.cpp | 12 ++++++------ .../DatabaseCommand_CreatePlaylist.cpp | 16 ++++++---------- 6 files changed, 35 insertions(+), 38 deletions(-) diff --git a/src/libtomahawk/SourceList.cpp b/src/libtomahawk/SourceList.cpp index 5284397b1..842730cfe 100644 --- a/src/libtomahawk/SourceList.cpp +++ b/src/libtomahawk/SourceList.cpp @@ -216,6 +216,24 @@ SourceList::get( const QString& username, const QString& friendlyName, bool auto } +void +SourceList::createPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents ) +{ + Tomahawk::playlist_ptr p = Tomahawk::playlist_ptr( new Tomahawk::Playlist( src ) ); + QJson::QObjectHelper::qvariant2qobject( contents.toMap(), p.data() ); + p->reportCreated( p ); +} + + +void +SourceList::createDynamicPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents ) +{ + Tomahawk::dynplaylist_ptr p = Tomahawk::dynplaylist_ptr( new Tomahawk::DynamicPlaylist( src, contents.toMap().value( "type", QString() ).toString() ) ); + QJson::QObjectHelper::qvariant2qobject( contents.toMap(), p.data() ); + p->reportCreated( p ); +} + + void SourceList::sourceSynced() { diff --git a/src/libtomahawk/SourceList.h b/src/libtomahawk/SourceList.h index 1c515b8a6..618fa2d90 100644 --- a/src/libtomahawk/SourceList.h +++ b/src/libtomahawk/SourceList.h @@ -54,6 +54,11 @@ public: Tomahawk::source_ptr get( const QString& username, const QString& friendlyName = QString(), bool autoCreate = false ); Tomahawk::source_ptr get( int id ) const; +public slots: + // called by the playlist creation dbcmds + void createPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents ); + void createDynamicPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents ); + signals: void ready(); diff --git a/src/libtomahawk/ViewManager.cpp b/src/libtomahawk/ViewManager.cpp index c9619dabd..90c106071 100644 --- a/src/libtomahawk/ViewManager.cpp +++ b/src/libtomahawk/ViewManager.cpp @@ -666,24 +666,6 @@ ViewManager::onWidgetDestroyed( QWidget* widget ) } -void -ViewManager::createPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents ) -{ - Tomahawk::playlist_ptr p = Tomahawk::playlist_ptr( new Tomahawk::Playlist( src ) ); - QJson::QObjectHelper::qvariant2qobject( contents.toMap(), p.data() ); - p->reportCreated( p ); -} - - -void -ViewManager::createDynamicPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents ) -{ - Tomahawk::dynplaylist_ptr p = Tomahawk::dynplaylist_ptr( new Tomahawk::DynamicPlaylist( src, contents.toMap().value( "type", QString() ).toString() ) ); - QJson::QObjectHelper::qvariant2qobject( contents.toMap(), p.data() ); - p->reportCreated( p ); -} - - void ViewManager::setTomahawkLoaded() { diff --git a/src/libtomahawk/ViewManager.h b/src/libtomahawk/ViewManager.h index d8466a601..a4379516f 100644 --- a/src/libtomahawk/ViewManager.h +++ b/src/libtomahawk/ViewManager.h @@ -153,10 +153,6 @@ public slots: void playlistInterfaceChanged( Tomahawk::playlistinterface_ptr ); - // called by the playlist creation dbcmds - void createPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents ); - void createDynamicPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents ); - void setTomahawkLoaded(); private slots: diff --git a/src/libtomahawk/database/DatabaseCommand_CreateDynamicPlaylist.cpp b/src/libtomahawk/database/DatabaseCommand_CreateDynamicPlaylist.cpp index b64c45b5f..7f90cd9d7 100644 --- a/src/libtomahawk/database/DatabaseCommand_CreateDynamicPlaylist.cpp +++ b/src/libtomahawk/database/DatabaseCommand_CreateDynamicPlaylist.cpp @@ -24,7 +24,7 @@ #include "playlist/dynamic/DynamicControl.h" #include "playlist/dynamic/GeneratorInterface.h" -#include "Source.h" +#include "SourceList.h" #include "network/Servent.h" #include "utils/Logger.h" @@ -113,11 +113,11 @@ DatabaseCommand_CreateDynamicPlaylist::postCommitHook() qDebug() << Q_FUNC_INFO << "..reporting.."; if( m_playlist.isNull() ) { - source_ptr src = source(); - - Tomahawk::dynplaylist_ptr p = Tomahawk::dynplaylist_ptr( new Tomahawk::DynamicPlaylist( src, m_v.toMap().value( "type", QString() ).toString() ) ); - QJson::QObjectHelper::qvariant2qobject( m_v.toMap(), p.data() ); - p->reportCreated( p ); + QMetaObject::invokeMethod( SourceList::instance(), + "createDynamicPlaylist", + Qt::BlockingQueuedConnection, + QGenericArgument( "Tomahawk::source_ptr", (const void*)&source() ), + Q_ARG( QVariant, m_v ) ); } else { diff --git a/src/libtomahawk/database/DatabaseCommand_CreatePlaylist.cpp b/src/libtomahawk/database/DatabaseCommand_CreatePlaylist.cpp index f2e2ce771..c6a545c27 100644 --- a/src/libtomahawk/database/DatabaseCommand_CreatePlaylist.cpp +++ b/src/libtomahawk/database/DatabaseCommand_CreatePlaylist.cpp @@ -20,16 +20,12 @@ #include -#include "Source.h" +#include "SourceList.h" #include "DatabaseImpl.h" #include "TomahawkSqlQuery.h" #include "network/Servent.h" #include "utils/Logger.h" -#ifndef ENABLE_HEADLESS - #include "ViewManager.h" -#endif - using namespace Tomahawk; @@ -81,11 +77,11 @@ DatabaseCommand_CreatePlaylist::postCommitHook() tDebug() << Q_FUNC_INFO << "reporting..."; if ( m_playlist.isNull() ) { - source_ptr src = source(); - - Tomahawk::playlist_ptr p = Tomahawk::playlist_ptr( new Tomahawk::Playlist( src ) ); - QJson::QObjectHelper::qvariant2qobject( m_v.toMap(), p.data() ); - p->reportCreated( p ); + QMetaObject::invokeMethod( SourceList::instance(), + "createPlaylist", + Qt::BlockingQueuedConnection, + QGenericArgument( "Tomahawk::source_ptr", (const void*)&source() ), + Q_ARG( QVariant, m_v ) ); } else {