1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-18 20:04:00 +02:00

Make dbcmds keep their own weakref, and make ShareTrack work.

This commit is contained in:
Teo Mrnjavac
2013-07-06 18:33:51 +02:00
parent 29f09e4ed1
commit f113a40c77
5 changed files with 61 additions and 9 deletions

View File

@@ -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();

View File

@@ -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;
};

View File

@@ -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;
}
}

View File

@@ -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;
};
}

View File

@@ -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() );