mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-19 04:11:46 +02:00
Make dbcmds keep their own weakref, and make ShareTrack work.
This commit is contained in:
@@ -60,11 +60,21 @@ DatabaseCommandFactory::newInstance()
|
|||||||
{
|
{
|
||||||
dbcmd_ptr command = dbcmd_ptr( create() );
|
dbcmd_ptr command = dbcmd_ptr( create() );
|
||||||
|
|
||||||
emit created( command );
|
notifyCreated( command );
|
||||||
|
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DatabaseCommandFactory::notifyCreated( const dbcmd_ptr& command )
|
||||||
|
{
|
||||||
|
command->setWeakRef( command.toWeakRef() );
|
||||||
|
|
||||||
|
emit created( command );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Database* Database::s_instance = 0;
|
Database* Database::s_instance = 0;
|
||||||
|
|
||||||
|
|
||||||
@@ -177,6 +187,15 @@ Database::enqueue( const QList< Tomahawk::dbcmd_ptr >& lc )
|
|||||||
return;
|
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";
|
tDebug( LOGVERBOSE ) << "Enqueueing" << lc.count() << "commands to rw thread";
|
||||||
if ( m_workerRW && m_workerRW.data()->worker() )
|
if ( m_workerRW && m_workerRW.data()->worker() )
|
||||||
m_workerRW.data()->worker().data()->enqueue( lc );
|
m_workerRW.data()->worker().data()->enqueue( lc );
|
||||||
@@ -193,6 +212,12 @@ Database::enqueue( const Tomahawk::dbcmd_ptr& lc )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DatabaseCommandFactory* factory = commandFactoryByCommandName( lc->commandname() );
|
||||||
|
if ( factory )
|
||||||
|
{
|
||||||
|
factory->notifyCreated( lc );
|
||||||
|
}
|
||||||
|
|
||||||
if ( lc->doesMutates() )
|
if ( lc->doesMutates() )
|
||||||
{
|
{
|
||||||
tDebug( LOGVERBOSE ) << "Enqueueing command to rw thread:" << lc->commandname();
|
tDebug( LOGVERBOSE ) << "Enqueueing command to rw thread:" << lc->commandname();
|
||||||
|
@@ -43,6 +43,7 @@ class DatabaseImpl;
|
|||||||
class DLLEXPORT DatabaseCommandFactory : public QObject
|
class DLLEXPORT DatabaseCommandFactory : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
friend class Database;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~DatabaseCommandFactory() {};
|
virtual ~DatabaseCommandFactory() {};
|
||||||
@@ -52,6 +53,8 @@ signals:
|
|||||||
void created( const Tomahawk::dbcmd_ptr& command );
|
void created( const Tomahawk::dbcmd_ptr& command );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void notifyCreated( const Tomahawk::dbcmd_ptr& command );
|
||||||
|
|
||||||
virtual DatabaseCommand* create() const = 0;
|
virtual DatabaseCommand* create() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -40,11 +40,13 @@ DatabaseCommand::DatabaseCommand( const Tomahawk::source_ptr& src, QObject* pare
|
|||||||
//qDebug() << Q_FUNC_INFO;
|
//qDebug() << Q_FUNC_INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DatabaseCommand::DatabaseCommand( const DatabaseCommand& other )
|
DatabaseCommand::DatabaseCommand( const DatabaseCommand& other )
|
||||||
: QObject( other.parent() )
|
: QObject( other.parent() )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DatabaseCommand::~DatabaseCommand()
|
DatabaseCommand::~DatabaseCommand()
|
||||||
{
|
{
|
||||||
// qDebug() << Q_FUNC_INFO;
|
// qDebug() << Q_FUNC_INFO;
|
||||||
@@ -76,4 +78,18 @@ DatabaseCommand::source() const
|
|||||||
return m_source;
|
return m_source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QWeakPointer< DatabaseCommand >
|
||||||
|
DatabaseCommand::weakRef()
|
||||||
|
{
|
||||||
|
return m_ownRef;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DatabaseCommand::setWeakRef( QWeakPointer< DatabaseCommand > weakRef )
|
||||||
|
{
|
||||||
|
m_ownRef = weakRef;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -51,7 +51,7 @@ public:
|
|||||||
explicit DatabaseCommand( QObject* parent = 0 );
|
explicit DatabaseCommand( QObject* parent = 0 );
|
||||||
explicit DatabaseCommand( const Tomahawk::source_ptr& src, 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();
|
virtual ~DatabaseCommand();
|
||||||
|
|
||||||
@@ -90,19 +90,22 @@ public:
|
|||||||
}
|
}
|
||||||
void setGuid( const QString& g ) { m_guid = g; }
|
void setGuid( const QString& g ) { m_guid = g; }
|
||||||
|
|
||||||
void emitFinished() { emit finished(this); emit finished(); }
|
void emitFinished() { emit finished(m_ownRef.toStrongRef()); emit finished(); }
|
||||||
void emitCommitted() { emit committed(this); emit committed(); }
|
void emitCommitted() { emit committed(m_ownRef.toStrongRef()); emit committed(); }
|
||||||
void emitRunning() { emit running(this); emit running(); }
|
void emitRunning() { emit running(m_ownRef.toStrongRef()); emit running(); }
|
||||||
|
|
||||||
|
QWeakPointer< Tomahawk::DatabaseCommand > weakRef();
|
||||||
|
void setWeakRef( QWeakPointer< Tomahawk::DatabaseCommand > weakRef );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void running();
|
void running();
|
||||||
void running(DatabaseCommand*);
|
void running( const Tomahawk::dbcmd_ptr& );
|
||||||
|
|
||||||
void finished();
|
void finished();
|
||||||
void finished(DatabaseCommand*);
|
void finished( const Tomahawk::dbcmd_ptr& );
|
||||||
|
|
||||||
void committed();
|
void committed();
|
||||||
void committed(DatabaseCommand*);
|
void committed( const Tomahawk::dbcmd_ptr& );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
State m_state;
|
State m_state;
|
||||||
@@ -110,6 +113,8 @@ private:
|
|||||||
mutable QString m_guid;
|
mutable QString m_guid;
|
||||||
|
|
||||||
QVariant m_data;
|
QVariant m_data;
|
||||||
|
|
||||||
|
QWeakPointer< Tomahawk::DatabaseCommand > m_ownRef;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -260,7 +260,10 @@ InboxModel::onDbcmdCommitted( const Tomahawk::dbcmd_ptr& cmd )
|
|||||||
QString myDbid = SourceList::instance()->getLocal()->nodeId();
|
QString myDbid = SourceList::instance()->getLocal()->nodeId();
|
||||||
QString sourceDbid = c->source()->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;
|
return;
|
||||||
|
|
||||||
Tomahawk::trackdata_ptr td = Tomahawk::TrackData::get( 0, c->artist(), c->track() );
|
Tomahawk::trackdata_ptr td = Tomahawk::TrackData::get( 0, c->artist(), c->track() );
|
||||||
|
Reference in New Issue
Block a user