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

* Prevented loading a dupe SIP plugin.

This commit is contained in:
Christian Muehlhaeuser
2011-03-19 03:05:43 +01:00
parent feed05463f
commit 64846c1abd
4 changed files with 36 additions and 19 deletions

View File

@@ -123,7 +123,7 @@ ControlConnection::registerSource()
void void
ControlConnection::setupDbSyncConnection( bool ondemand ) ControlConnection::setupDbSyncConnection( bool ondemand )
{ {
qDebug() << Q_FUNC_INFO << ondemand << m_source->id() << ondemand << m_dbconnkey << m_dbsyncconn << m_registered; qDebug() << Q_FUNC_INFO << ondemand << m_source->id() << m_dbconnkey << m_dbsyncconn << m_registered;
if ( m_dbsyncconn || !m_registered ) if ( m_dbsyncconn || !m_registered )
return; return;

View File

@@ -31,6 +31,7 @@
#include "config.h" #include "config.h"
SipHandler::SipHandler( QObject* parent ) SipHandler::SipHandler( QObject* parent )
: QObject( parent ) : QObject( parent )
, m_connected( false ) , m_connected( false )
@@ -113,29 +114,31 @@ SipHandler::loadPlugins( const QStringList& paths )
continue; continue;
qDebug() << "Trying to load plugin:" << fileName; qDebug() << "Trying to load plugin:" << fileName;
loadPlugin( fileName );
QPluginLoader loader( fileName );
QObject* plugin = loader.instance();
if ( plugin )
{
// Connect via that plugin
qDebug() << "Loaded plugin:" << loader.fileName();
loadPlugin( plugin );
}
else
{
qDebug() << "Error loading library:" << loader.errorString();
}
} }
} }
void void
SipHandler::loadPlugin( QObject* plugin ) SipHandler::loadPlugin( const QString& path )
{ {
QPluginLoader loader( path );
QObject* plugin = loader.instance();
if ( !plugin )
{
qDebug() << "Error loading plugin:" << loader.errorString();
}
SipPlugin* sip = qobject_cast<SipPlugin*>(plugin); SipPlugin* sip = qobject_cast<SipPlugin*>(plugin);
if ( sip ) if ( sip )
{ {
if ( pluginLoaded( sip->name() ) )
{
qDebug() << "Plugin" << sip->name() << "already loaded! Not loading:" << loader.fileName();
return;
}
qDebug() << "Loaded plugin:" << loader.fileName();
QObject::connect( sip, SIGNAL( peerOnline( QString ) ), SLOT( onPeerOnline( QString ) ) ); QObject::connect( sip, SIGNAL( peerOnline( QString ) ), SLOT( onPeerOnline( QString ) ) );
QObject::connect( sip, SIGNAL( peerOffline( QString ) ), SLOT( onPeerOffline( QString ) ) ); QObject::connect( sip, SIGNAL( peerOffline( QString ) ), SLOT( onPeerOffline( QString ) ) );
QObject::connect( sip, SIGNAL( msgReceived( QString, QString ) ), SLOT( onMessage( QString, QString ) ) ); QObject::connect( sip, SIGNAL( msgReceived( QString, QString ) ), SLOT( onMessage( QString, QString ) ) );
@@ -149,6 +152,19 @@ SipHandler::loadPlugin( QObject* plugin )
} }
bool
SipHandler::pluginLoaded( const QString& name ) const
{
foreach( SipPlugin* plugin, m_plugins )
{
if ( plugin->name() == name )
return true;
}
return false;
}
void void
SipHandler::connectPlugins( bool startup, const QString &pluginName ) SipHandler::connectPlugins( bool startup, const QString &pluginName )
{ {

View File

@@ -58,8 +58,10 @@ private slots:
private: private:
QStringList findPlugins(); QStringList findPlugins();
bool pluginLoaded( const QString& name ) const;
void loadPlugins( const QStringList& paths ); void loadPlugins( const QStringList& paths );
void loadPlugin( QObject* plugin ); void loadPlugin( const QString& path );
QList< SipPlugin* > m_plugins; QList< SipPlugin* > m_plugins;
bool m_connected; bool m_connected;

View File

@@ -70,7 +70,6 @@ TwitterPlugin::isValid()
const QString const QString
TwitterPlugin::name() TwitterPlugin::name()
{ {
qDebug() << "TwitterPlugin returning plugin name " << QString( MYNAME );
return QString( MYNAME ); return QString( MYNAME );
} }