diff --git a/src/libtomahawk/database/Database.cpp b/src/libtomahawk/database/Database.cpp index 9682e834d..2885d651f 100644 --- a/src/libtomahawk/database/Database.cpp +++ b/src/libtomahawk/database/Database.cpp @@ -60,11 +60,21 @@ DatabaseCommandFactory::newInstance() { dbcmd_ptr command = dbcmd_ptr( create() ); - emit created( command ); + notifyCreated( command ); + return command; } +void +DatabaseCommandFactory::notifyCreated( const dbcmd_ptr& command ) +{ + command->setWeakRef( command.toWeakRef() ); + + emit created( command ); +} + + Database* Database::s_instance = 0; @@ -177,6 +187,15 @@ Database::enqueue( const QList< Tomahawk::dbcmd_ptr >& lc ) return; } + foreach ( const Tomahawk::dbcmd_ptr& cmd, lc ) + { + DatabaseCommandFactory* factory = commandFactoryByCommandName( cmd->commandname() ); + if ( factory ) + { + factory->notifyCreated( cmd ); + } + } + tDebug( LOGVERBOSE ) << "Enqueueing" << lc.count() << "commands to rw thread"; if ( m_workerRW && m_workerRW.data()->worker() ) m_workerRW.data()->worker().data()->enqueue( lc ); @@ -193,6 +212,12 @@ Database::enqueue( const Tomahawk::dbcmd_ptr& lc ) return; } + DatabaseCommandFactory* factory = commandFactoryByCommandName( lc->commandname() ); + if ( factory ) + { + factory->notifyCreated( lc ); + } + if ( lc->doesMutates() ) { tDebug( LOGVERBOSE ) << "Enqueueing command to rw thread:" << lc->commandname(); diff --git a/src/libtomahawk/database/Database.h b/src/libtomahawk/database/Database.h index e0f399d57..113f2f85b 100644 --- a/src/libtomahawk/database/Database.h +++ b/src/libtomahawk/database/Database.h @@ -43,6 +43,7 @@ class DatabaseImpl; class DLLEXPORT DatabaseCommandFactory : public QObject { Q_OBJECT + friend class Database; public: virtual ~DatabaseCommandFactory() {}; @@ -52,6 +53,8 @@ signals: void created( const Tomahawk::dbcmd_ptr& command ); protected: + void notifyCreated( const Tomahawk::dbcmd_ptr& command ); + virtual DatabaseCommand* create() const = 0; }; diff --git a/src/libtomahawk/database/DatabaseCommand.cpp b/src/libtomahawk/database/DatabaseCommand.cpp index 179df56fa..3c72f3ca2 100644 --- a/src/libtomahawk/database/DatabaseCommand.cpp +++ b/src/libtomahawk/database/DatabaseCommand.cpp @@ -40,11 +40,13 @@ DatabaseCommand::DatabaseCommand( const Tomahawk::source_ptr& src, QObject* pare //qDebug() << Q_FUNC_INFO; } + DatabaseCommand::DatabaseCommand( const DatabaseCommand& other ) : QObject( other.parent() ) { } + DatabaseCommand::~DatabaseCommand() { // qDebug() << Q_FUNC_INFO; @@ -76,4 +78,18 @@ DatabaseCommand::source() const return m_source; } + +QWeakPointer< DatabaseCommand > +DatabaseCommand::weakRef() +{ + return m_ownRef; +} + + +void +DatabaseCommand::setWeakRef( QWeakPointer< DatabaseCommand > weakRef ) +{ + m_ownRef = weakRef; +} + } diff --git a/src/libtomahawk/database/DatabaseCommand.h b/src/libtomahawk/database/DatabaseCommand.h index 9d783303f..c83377263 100644 --- a/src/libtomahawk/database/DatabaseCommand.h +++ b/src/libtomahawk/database/DatabaseCommand.h @@ -51,7 +51,7 @@ public: explicit DatabaseCommand( QObject* parent = 0 ); explicit DatabaseCommand( const Tomahawk::source_ptr& src, QObject* parent = 0 ); - DatabaseCommand( const DatabaseCommand &other ); + DatabaseCommand( const DatabaseCommand &other ); //needed for QMetaType virtual ~DatabaseCommand(); @@ -90,19 +90,22 @@ public: } void setGuid( const QString& g ) { m_guid = g; } - void emitFinished() { emit finished(this); emit finished(); } - void emitCommitted() { emit committed(this); emit committed(); } - void emitRunning() { emit running(this); emit running(); } + void emitFinished() { emit finished(m_ownRef.toStrongRef()); emit finished(); } + void emitCommitted() { emit committed(m_ownRef.toStrongRef()); emit committed(); } + void emitRunning() { emit running(m_ownRef.toStrongRef()); emit running(); } + + QWeakPointer< Tomahawk::DatabaseCommand > weakRef(); + void setWeakRef( QWeakPointer< Tomahawk::DatabaseCommand > weakRef ); signals: void running(); - void running(DatabaseCommand*); + void running( const Tomahawk::dbcmd_ptr& ); void finished(); - void finished(DatabaseCommand*); + void finished( const Tomahawk::dbcmd_ptr& ); void committed(); - void committed(DatabaseCommand*); + void committed( const Tomahawk::dbcmd_ptr& ); private: State m_state; @@ -110,6 +113,8 @@ private: mutable QString m_guid; QVariant m_data; + + QWeakPointer< Tomahawk::DatabaseCommand > m_ownRef; }; } diff --git a/src/libtomahawk/playlist/InboxModel.cpp b/src/libtomahawk/playlist/InboxModel.cpp index a3f8848d4..3ee967839 100644 --- a/src/libtomahawk/playlist/InboxModel.cpp +++ b/src/libtomahawk/playlist/InboxModel.cpp @@ -260,7 +260,10 @@ InboxModel::onDbcmdCommitted( const Tomahawk::dbcmd_ptr& cmd ) QString myDbid = SourceList::instance()->getLocal()->nodeId(); QString sourceDbid = c->source()->nodeId(); - if ( myDbid != c->recipient() || sourceDbid == c->recipient() ) // if I'm not receiving, or if I'm sending to myself, bail out + if ( sourceDbid == c->recipient() ) // if I'm sending to myself, bail out + return; + + if ( myDbid != c->recipient() && !c->source()->isLocal() ) // if I'm not the sender and not the receiver, bail out return; Tomahawk::trackdata_ptr td = Tomahawk::TrackData::get( 0, c->artist(), c->track() );