1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-07 22:56:42 +02:00

Make InfoPluginPtr a QSharedPointer

This commit is contained in:
Dominik Schmidt
2016-02-10 23:36:42 +01:00
parent d87f966d9e
commit 9737b7a8bc
8 changed files with 16 additions and 45 deletions

View File

@@ -253,7 +253,7 @@ namespace Tomahawk
typedef QHash< QString, QString > InfoStringHash; typedef QHash< QString, QString > InfoStringHash;
typedef QPair< QVariantMap, QVariant > PushInfoPair; typedef QPair< QVariantMap, QVariant > PushInfoPair;
typedef QPointer< InfoPlugin > InfoPluginPtr; typedef QSharedPointer< InfoPlugin > InfoPluginPtr;
} }
namespace Network namespace Network

View File

@@ -71,7 +71,7 @@ LastFmAccount::LastFmAccount( const QString& accountId )
if ( infoPlugin() && Tomahawk::InfoSystem::InfoSystem::instance()->workerThread() ) if ( infoPlugin() && Tomahawk::InfoSystem::InfoSystem::instance()->workerThread() )
{ {
infoPlugin().data()->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() ); infoPlugin()->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() );
Tomahawk::InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin() ); Tomahawk::InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin() );
} }
} }
@@ -82,7 +82,6 @@ LastFmAccount::~LastFmAccount()
if ( m_infoPlugin ) if ( m_infoPlugin )
{ {
Tomahawk::InfoSystem::InfoSystem::instance()->removeInfoPlugin( infoPlugin() ); Tomahawk::InfoSystem::InfoSystem::instance()->removeInfoPlugin( infoPlugin() );
delete m_infoPlugin;
} }
delete m_resolver.data(); delete m_resolver.data();
@@ -168,9 +167,11 @@ InfoPluginPtr
LastFmAccount::infoPlugin() LastFmAccount::infoPlugin()
{ {
if ( m_infoPlugin.isNull() ) if ( m_infoPlugin.isNull() )
m_infoPlugin = QPointer< LastFmInfoPlugin >( new LastFmInfoPlugin( this ) ); {
m_infoPlugin = QSharedPointer< LastFmInfoPlugin>( new LastFmInfoPlugin( this ) );
}
return InfoPluginPtr( m_infoPlugin.data() ); return m_infoPlugin;
} }
bool bool

View File

@@ -105,7 +105,7 @@ private:
void hookupResolver(); void hookupResolver();
QPointer<Tomahawk::ExternalResolverGui> m_resolver; QPointer<Tomahawk::ExternalResolverGui> m_resolver;
QPointer<Tomahawk::InfoSystem::LastFmInfoPlugin> m_infoPlugin; QSharedPointer<Tomahawk::InfoSystem::LastFmInfoPlugin> m_infoPlugin;
QPointer<LastFmConfig> m_configWidget; QPointer<LastFmConfig> m_configWidget;
}; };

View File

@@ -135,7 +135,7 @@ SpotifyAccount::init()
if ( infoPlugin() && Tomahawk::InfoSystem::InfoSystem::instance()->workerThread() ) if ( infoPlugin() && Tomahawk::InfoSystem::InfoSystem::instance()->workerThread() )
{ {
infoPlugin().data()->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() ); infoPlugin()->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() );
Tomahawk::InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin() ); Tomahawk::InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin() );
} }
@@ -366,10 +366,10 @@ SpotifyAccount::infoPlugin()
{ {
if ( m_infoPlugin.isNull() ) if ( m_infoPlugin.isNull() )
{ {
m_infoPlugin = QPointer< InfoSystem::SpotifyInfoPlugin >( new InfoSystem::SpotifyInfoPlugin( this ) ); m_infoPlugin = QSharedPointer< InfoSystem::SpotifyInfoPlugin >( new InfoSystem::SpotifyInfoPlugin( this ) );
} }
return InfoSystem::InfoPluginPtr( m_infoPlugin.data() ); return m_infoPlugin;
} }

View File

@@ -170,7 +170,7 @@ private:
QPointer<SpotifyAccountConfig> m_configWidget; QPointer<SpotifyAccountConfig> m_configWidget;
QPointer<QWidget> m_aboutWidget; QPointer<QWidget> m_aboutWidget;
QPointer<ScriptResolver> m_spotifyResolver; QPointer<ScriptResolver> m_spotifyResolver;
QPointer< InfoSystem::SpotifyInfoPlugin > m_infoPlugin; QSharedPointer< InfoSystem::SpotifyInfoPlugin > m_infoPlugin;
QMap<QString, QPair<QObject*, QString> > m_qidToSlotMap; QMap<QString, QPair<QObject*, QString> > m_qidToSlotMap;
QMap<QString, QVariant > m_qidToExtraData; QMap<QString, QVariant > m_qidToExtraData;

View File

@@ -58,13 +58,7 @@ InfoSystemWorker::InfoSystemWorker()
InfoSystemWorker::~InfoSystemWorker() InfoSystemWorker::~InfoSystemWorker()
{ {
tDebug() << Q_FUNC_INFO << " beginning"; tDebug() << Q_FUNC_INFO;
Q_FOREACH( InfoPluginPtr plugin, m_plugins )
{
if( plugin )
delete plugin.data();
}
tDebug() << Q_FUNC_INFO << " finished";
} }
@@ -136,29 +130,6 @@ InfoSystemWorker::addInfoPlugin( Tomahawk::InfoSystem::InfoPluginPtr plugin )
emit updatedSupportedGetTypes( QSet< InfoType >::fromList( m_infoGetMap.keys() ) ); emit updatedSupportedGetTypes( QSet< InfoType >::fromList( m_infoGetMap.keys() ) );
emit updatedSupportedPushTypes( QSet< InfoType >::fromList( m_infoPushMap.keys() ) ); emit updatedSupportedPushTypes( QSet< InfoType >::fromList( m_infoPushMap.keys() ) );
connect( plugin.data(), SIGNAL( destroyed( QObject* ) ), SLOT( onInfoPluginDeleted() ) );
}
void
InfoSystemWorker::onInfoPluginDeleted()
{
foreach( const InfoPluginPtr& plugin, m_plugins )
{
if ( plugin.isNull() )
{
m_plugins.removeOne( plugin );
foreach( InfoType type, m_infoGetMap.keys() )
{
m_infoGetMap[type].removeOne( plugin );
}
foreach( InfoType type, m_infoPushMap.keys() )
{
m_infoPushMap[type].removeOne( plugin );
}
}
}
} }

View File

@@ -72,7 +72,6 @@ public slots:
private slots: private slots:
void checkTimeoutsTimerFired(); void checkTimeoutsTimerFired();
void onInfoPluginDeleted();
private: private:
void registerInfoTypes( const InfoPluginPtr &plugin, const QSet< InfoType > &getTypes, const QSet< InfoType > &pushTypes ); void registerInfoTypes( const InfoPluginPtr &plugin, const QSet< InfoType > &getTypes, const QSet< InfoType > &pushTypes );

View File

@@ -25,14 +25,14 @@ using namespace Tomahawk;
void void
ScriptInfoPluginFactory::addPlugin( const QSharedPointer< ScriptInfoPlugin >& infoPlugin ) const ScriptInfoPluginFactory::addPlugin( const QSharedPointer< ScriptInfoPlugin >& infoPlugin ) const
{ {
Tomahawk::InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin.data() ); Tomahawk::InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin );
} }
void void
ScriptInfoPluginFactory::removePlugin( const QSharedPointer< ScriptInfoPlugin >& infoPlugin ) const ScriptInfoPluginFactory::removePlugin( const QSharedPointer< ScriptInfoPlugin >& infoPlugin ) const
{ {
Tomahawk::InfoSystem::InfoSystem::instance()->removeInfoPlugin( infoPlugin.data() ); Tomahawk::InfoSystem::InfoSystem::instance()->removeInfoPlugin( infoPlugin );
} }
@@ -42,10 +42,10 @@ ScriptInfoPluginFactory::createPlugin( const scriptobject_ptr& object, ScriptAcc
// create infoplugin instance // create infoplugin instance
ScriptInfoPlugin* scriptInfoPlugin = new ScriptInfoPlugin( object, scriptAccount->name() ); ScriptInfoPlugin* scriptInfoPlugin = new ScriptInfoPlugin( object, scriptAccount->name() );
Tomahawk::InfoSystem::InfoPluginPtr infoPlugin( scriptInfoPlugin ); QSharedPointer< ScriptInfoPlugin > infoPlugin( scriptInfoPlugin );
// move it to infosystem thread // move it to infosystem thread
infoPlugin->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() ); infoPlugin->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() );
return QSharedPointer< ScriptInfoPlugin >( scriptInfoPlugin ); return infoPlugin;
} }