mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-16 11:04:01 +02:00
Move command factory from DatabaseCommand to Database
This commit is contained in:
@@ -27,6 +27,26 @@
|
|||||||
#include "IdThreadWorker.h"
|
#include "IdThreadWorker.h"
|
||||||
#include "PlaylistEntry.h"
|
#include "PlaylistEntry.h"
|
||||||
|
|
||||||
|
#include "DatabaseCommand_AddFiles.h"
|
||||||
|
#include "DatabaseCommand_CreatePlaylist.h"
|
||||||
|
#include "DatabaseCommand_DeleteFiles.h"
|
||||||
|
#include "DatabaseCommand_DeletePlaylist.h"
|
||||||
|
#include "DatabaseCommand_LogPlayback.h"
|
||||||
|
#include "DatabaseCommand_RenamePlaylist.h"
|
||||||
|
#include "DatabaseCommand_SetPlaylistRevision.h"
|
||||||
|
#include "DatabaseCommand_CreateDynamicPlaylist.h"
|
||||||
|
#include "DatabaseCommand_DeleteDynamicPlaylist.h"
|
||||||
|
#include "DatabaseCommand_SetDynamicPlaylistRevision.h"
|
||||||
|
#include "DatabaseCommand_SocialAction.h"
|
||||||
|
#include "DatabaseCommand_ShareTrack.h"
|
||||||
|
#include "DatabaseCommand_SetCollectionAttributes.h"
|
||||||
|
#include "DatabaseCommand_SetTrackAttributes.h"
|
||||||
|
|
||||||
|
// Forward Declarations breaking QSharedPointer
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK( 5, 0, 0 )
|
||||||
|
#include "collection/Collection.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <boost/concept_check.hpp>
|
#include <boost/concept_check.hpp>
|
||||||
|
|
||||||
#define DEFAULT_WORKER_THREADS 4
|
#define DEFAULT_WORKER_THREADS 4
|
||||||
@@ -206,3 +226,115 @@ Database::markAsReady()
|
|||||||
m_ready = true;
|
m_ready = true;
|
||||||
emit ready();
|
emit ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DatabaseCommand*
|
||||||
|
Database::commandFactory( const QVariant& op, const Tomahawk::source_ptr& source )
|
||||||
|
{
|
||||||
|
const QString name = op.toMap().value( "command" ).toString();
|
||||||
|
|
||||||
|
if( name == "addfiles" )
|
||||||
|
{
|
||||||
|
DatabaseCommand_AddFiles * cmd = new DatabaseCommand_AddFiles;
|
||||||
|
cmd->setSource( source );
|
||||||
|
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
else if( name == "deletefiles" )
|
||||||
|
{
|
||||||
|
DatabaseCommand_DeleteFiles * cmd = new DatabaseCommand_DeleteFiles;
|
||||||
|
cmd->setSource( source );
|
||||||
|
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
else if( name == "createplaylist" )
|
||||||
|
{
|
||||||
|
DatabaseCommand_CreatePlaylist * cmd = new DatabaseCommand_CreatePlaylist;
|
||||||
|
cmd->setSource( source );
|
||||||
|
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
else if( name == "deleteplaylist" )
|
||||||
|
{
|
||||||
|
DatabaseCommand_DeletePlaylist * cmd = new DatabaseCommand_DeletePlaylist;
|
||||||
|
cmd->setSource( source );
|
||||||
|
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
else if( name == "logplayback" )
|
||||||
|
{
|
||||||
|
DatabaseCommand_LogPlayback * cmd = new DatabaseCommand_LogPlayback;
|
||||||
|
cmd->setSource( source );
|
||||||
|
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
else if( name == "renameplaylist" )
|
||||||
|
{
|
||||||
|
DatabaseCommand_RenamePlaylist * cmd = new DatabaseCommand_RenamePlaylist;
|
||||||
|
cmd->setSource( source );
|
||||||
|
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
else if( name == "setplaylistrevision" )
|
||||||
|
{
|
||||||
|
DatabaseCommand_SetPlaylistRevision * cmd = new DatabaseCommand_SetPlaylistRevision;
|
||||||
|
cmd->setSource( source );
|
||||||
|
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
else if( name == "createdynamicplaylist" )
|
||||||
|
{
|
||||||
|
DatabaseCommand_CreateDynamicPlaylist * cmd = new DatabaseCommand_CreateDynamicPlaylist;
|
||||||
|
cmd->setSource( source );
|
||||||
|
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
else if( name == "deletedynamicplaylist" )
|
||||||
|
{
|
||||||
|
DatabaseCommand_DeleteDynamicPlaylist * cmd = new DatabaseCommand_DeleteDynamicPlaylist;
|
||||||
|
cmd->setSource( source );
|
||||||
|
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
else if( name == "setdynamicplaylistrevision" )
|
||||||
|
{
|
||||||
|
qDebug() << "SETDYN CONTENT:" << op;
|
||||||
|
DatabaseCommand_SetDynamicPlaylistRevision * cmd = new DatabaseCommand_SetDynamicPlaylistRevision;
|
||||||
|
cmd->setSource( source );
|
||||||
|
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
else if( name == "socialaction" )
|
||||||
|
{
|
||||||
|
DatabaseCommand_SocialAction * cmd = new DatabaseCommand_SocialAction;
|
||||||
|
cmd->setSource( source );
|
||||||
|
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
else if( name == "setcollectionattributes" )
|
||||||
|
{
|
||||||
|
DatabaseCommand_SetCollectionAttributes * cmd = new DatabaseCommand_SetCollectionAttributes;
|
||||||
|
cmd->setSource( source );
|
||||||
|
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
else if( name == "settrackattributes" )
|
||||||
|
{
|
||||||
|
DatabaseCommand_SetTrackAttributes * cmd = new DatabaseCommand_SetTrackAttributes;
|
||||||
|
cmd->setSource( source );
|
||||||
|
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
else if( name == "sharetrack" )
|
||||||
|
{
|
||||||
|
DatabaseCommand_ShareTrack * cmd = new DatabaseCommand_ShareTrack;
|
||||||
|
cmd->setSource( source );
|
||||||
|
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "Unknown database command" << name;
|
||||||
|
// Q_ASSERT( false );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -60,6 +60,8 @@ public:
|
|||||||
|
|
||||||
DatabaseImpl* impl();
|
DatabaseImpl* impl();
|
||||||
|
|
||||||
|
static DatabaseCommand* commandFactory( const QVariant& op, const Tomahawk::source_ptr& source );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void indexReady(); // search index
|
void indexReady(); // search index
|
||||||
void ready();
|
void ready();
|
||||||
|
@@ -20,25 +20,7 @@
|
|||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include "DatabaseCommand_AddFiles.h"
|
|
||||||
#include "DatabaseCommand_CreatePlaylist.h"
|
|
||||||
#include "DatabaseCommand_DeleteFiles.h"
|
|
||||||
#include "DatabaseCommand_DeletePlaylist.h"
|
|
||||||
#include "DatabaseCommand_LogPlayback.h"
|
|
||||||
#include "DatabaseCommand_RenamePlaylist.h"
|
|
||||||
#include "DatabaseCommand_SetPlaylistRevision.h"
|
|
||||||
#include "DatabaseCommand_CreateDynamicPlaylist.h"
|
|
||||||
#include "DatabaseCommand_DeleteDynamicPlaylist.h"
|
|
||||||
#include "DatabaseCommand_SetDynamicPlaylistRevision.h"
|
|
||||||
#include "DatabaseCommand_SocialAction.h"
|
|
||||||
#include "DatabaseCommand_ShareTrack.h"
|
|
||||||
#include "DatabaseCommand_SetCollectionAttributes.h"
|
|
||||||
#include "DatabaseCommand_SetTrackAttributes.h"
|
|
||||||
|
|
||||||
// Forward Declarations breaking QSharedPointer
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK( 5, 0, 0 )
|
|
||||||
#include "collection/Collection.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
DatabaseCommand::DatabaseCommand( QObject* parent )
|
DatabaseCommand::DatabaseCommand( QObject* parent )
|
||||||
@@ -49,7 +31,7 @@ DatabaseCommand::DatabaseCommand( QObject* parent )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DatabaseCommand::DatabaseCommand( const source_ptr& src, QObject* parent )
|
DatabaseCommand::DatabaseCommand( const Tomahawk::source_ptr& src, QObject* parent )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
, m_state( PENDING )
|
, m_state( PENDING )
|
||||||
, m_source( src )
|
, m_source( src )
|
||||||
@@ -92,114 +74,3 @@ DatabaseCommand::source() const
|
|||||||
{
|
{
|
||||||
return m_source;
|
return m_source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DatabaseCommand*
|
|
||||||
DatabaseCommand::factory( const QVariant& op, const source_ptr& source )
|
|
||||||
{
|
|
||||||
const QString name = op.toMap().value( "command" ).toString();
|
|
||||||
|
|
||||||
if( name == "addfiles" )
|
|
||||||
{
|
|
||||||
DatabaseCommand_AddFiles * cmd = new DatabaseCommand_AddFiles;
|
|
||||||
cmd->setSource( source );
|
|
||||||
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
else if( name == "deletefiles" )
|
|
||||||
{
|
|
||||||
DatabaseCommand_DeleteFiles * cmd = new DatabaseCommand_DeleteFiles;
|
|
||||||
cmd->setSource( source );
|
|
||||||
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
else if( name == "createplaylist" )
|
|
||||||
{
|
|
||||||
DatabaseCommand_CreatePlaylist * cmd = new DatabaseCommand_CreatePlaylist;
|
|
||||||
cmd->setSource( source );
|
|
||||||
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
else if( name == "deleteplaylist" )
|
|
||||||
{
|
|
||||||
DatabaseCommand_DeletePlaylist * cmd = new DatabaseCommand_DeletePlaylist;
|
|
||||||
cmd->setSource( source );
|
|
||||||
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
else if( name == "logplayback" )
|
|
||||||
{
|
|
||||||
DatabaseCommand_LogPlayback * cmd = new DatabaseCommand_LogPlayback;
|
|
||||||
cmd->setSource( source );
|
|
||||||
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
else if( name == "renameplaylist" )
|
|
||||||
{
|
|
||||||
DatabaseCommand_RenamePlaylist * cmd = new DatabaseCommand_RenamePlaylist;
|
|
||||||
cmd->setSource( source );
|
|
||||||
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
else if( name == "setplaylistrevision" )
|
|
||||||
{
|
|
||||||
DatabaseCommand_SetPlaylistRevision * cmd = new DatabaseCommand_SetPlaylistRevision;
|
|
||||||
cmd->setSource( source );
|
|
||||||
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
else if( name == "createdynamicplaylist" )
|
|
||||||
{
|
|
||||||
DatabaseCommand_CreateDynamicPlaylist * cmd = new DatabaseCommand_CreateDynamicPlaylist;
|
|
||||||
cmd->setSource( source );
|
|
||||||
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
else if( name == "deletedynamicplaylist" )
|
|
||||||
{
|
|
||||||
DatabaseCommand_DeleteDynamicPlaylist * cmd = new DatabaseCommand_DeleteDynamicPlaylist;
|
|
||||||
cmd->setSource( source );
|
|
||||||
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
else if( name == "setdynamicplaylistrevision" )
|
|
||||||
{
|
|
||||||
qDebug() << "SETDYN CONTENT:" << op;
|
|
||||||
DatabaseCommand_SetDynamicPlaylistRevision * cmd = new DatabaseCommand_SetDynamicPlaylistRevision;
|
|
||||||
cmd->setSource( source );
|
|
||||||
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
else if( name == "socialaction" )
|
|
||||||
{
|
|
||||||
DatabaseCommand_SocialAction * cmd = new DatabaseCommand_SocialAction;
|
|
||||||
cmd->setSource( source );
|
|
||||||
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
else if( name == "setcollectionattributes" )
|
|
||||||
{
|
|
||||||
DatabaseCommand_SetCollectionAttributes * cmd = new DatabaseCommand_SetCollectionAttributes;
|
|
||||||
cmd->setSource( source );
|
|
||||||
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
else if( name == "settrackattributes" )
|
|
||||||
{
|
|
||||||
DatabaseCommand_SetTrackAttributes * cmd = new DatabaseCommand_SetTrackAttributes;
|
|
||||||
cmd->setSource( source );
|
|
||||||
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
else if( name == "sharetrack" )
|
|
||||||
{
|
|
||||||
DatabaseCommand_ShareTrack * cmd = new DatabaseCommand_ShareTrack;
|
|
||||||
cmd->setSource( source );
|
|
||||||
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
qDebug() << "Unknown database command" << name;
|
|
||||||
// Q_ASSERT( false );
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
@@ -89,8 +89,6 @@ public:
|
|||||||
|
|
||||||
void emitFinished() { emit finished(); }
|
void emitFinished() { emit finished(); }
|
||||||
|
|
||||||
static DatabaseCommand* factory( const QVariant& op, const Tomahawk::source_ptr& source );
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void running();
|
void running();
|
||||||
void finished();
|
void finished();
|
||||||
|
@@ -199,7 +199,7 @@ DBSyncConnection::handleMsg( msg_ptr msg )
|
|||||||
// a db sync op msg
|
// a db sync op msg
|
||||||
if ( msg->is( Msg::DBOP ) )
|
if ( msg->is( Msg::DBOP ) )
|
||||||
{
|
{
|
||||||
DatabaseCommand* cmd = DatabaseCommand::factory( m, m_source );
|
DatabaseCommand* cmd = Database::commandFactory( m, m_source );
|
||||||
if ( cmd )
|
if ( cmd )
|
||||||
{
|
{
|
||||||
QSharedPointer<DatabaseCommand> cmdsp = QSharedPointer<DatabaseCommand>(cmd);
|
QSharedPointer<DatabaseCommand> cmdsp = QSharedPointer<DatabaseCommand>(cmd);
|
||||||
|
Reference in New Issue
Block a user