mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-08 23:26:40 +02:00
allow factories to be marked as unique
This commit is contained in:
@@ -145,11 +145,11 @@ SipHandler::loadPluginFactories( const QStringList& paths )
|
|||||||
}
|
}
|
||||||
|
|
||||||
SipPlugin*
|
SipPlugin*
|
||||||
SipHandler::createPlugin( const QString& factoryName )
|
SipHandler::createPlugin( const QString& factoryId )
|
||||||
{
|
{
|
||||||
Q_ASSERT( m_pluginFactories.contains( factoryName ) );
|
Q_ASSERT( m_pluginFactories.contains( factoryId ) );
|
||||||
|
|
||||||
SipPlugin* sip = m_pluginFactories[ factoryName ]->createPlugin();
|
SipPlugin* sip = m_pluginFactories[ factoryId ]->createPlugin();
|
||||||
hookUpPlugin( sip );
|
hookUpPlugin( sip );
|
||||||
|
|
||||||
return sip;
|
return sip;
|
||||||
@@ -269,6 +269,16 @@ SipHandler::removeSipPlugin( SipPlugin* p )
|
|||||||
m_enabledPlugins.removeAll( p );
|
m_enabledPlugins.removeAll( p );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
SipHandler::hasPluginType( const QString& factoryId ) const
|
||||||
|
{
|
||||||
|
foreach( SipPlugin* p, m_allPlugins ) {
|
||||||
|
if( factoryFromId( p->pluginId() ) == factoryId )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SipHandler::loadFromConfig( bool startup )
|
SipHandler::loadFromConfig( bool startup )
|
||||||
@@ -583,7 +593,14 @@ SipHandler::onAvatarReceived( const QPixmap& avatar )
|
|||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
SipHandler::factoryFromId( const QString& pluginId )
|
SipHandler::factoryFromId( const QString& pluginId ) const
|
||||||
{
|
{
|
||||||
return pluginId.split( "_" ).first();
|
return pluginId.split( "_" ).first();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SipPluginFactory*
|
||||||
|
SipHandler::factoryFromPlugin( SipPlugin* p ) const
|
||||||
|
{
|
||||||
|
QString factoryId = factoryFromId( p->pluginId() );
|
||||||
|
return m_pluginFactories.value( factoryId, 0 );
|
||||||
|
}
|
||||||
|
@@ -47,6 +47,9 @@ public:
|
|||||||
void addSipPlugin( SipPlugin* p, bool enable = true, bool connectImmediately = true );
|
void addSipPlugin( SipPlugin* p, bool enable = true, bool connectImmediately = true );
|
||||||
void removeSipPlugin( SipPlugin* p );
|
void removeSipPlugin( SipPlugin* p );
|
||||||
|
|
||||||
|
bool hasPluginType( const QString& factoryId ) const;
|
||||||
|
SipPluginFactory* factoryFromPlugin( SipPlugin* p ) const;
|
||||||
|
|
||||||
const QPixmap avatar( const QString& name ) const;
|
const QPixmap avatar( const QString& name ) const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
@@ -104,7 +107,7 @@ private:
|
|||||||
|
|
||||||
void loadPluginFactories( const QStringList& paths );
|
void loadPluginFactories( const QStringList& paths );
|
||||||
void loadPluginFactory( const QString& path );
|
void loadPluginFactory( const QString& path );
|
||||||
QString factoryFromId( const QString& pluginId );
|
QString factoryFromId( const QString& pluginId ) const;
|
||||||
|
|
||||||
QHash< QString, SipPluginFactory* > m_pluginFactories;
|
QHash< QString, SipPluginFactory* > m_pluginFactories;
|
||||||
QList< SipPlugin* > m_allPlugins;
|
QList< SipPlugin* > m_allPlugins;
|
||||||
|
@@ -43,7 +43,8 @@ public:
|
|||||||
virtual QString factoryId() const = 0;
|
virtual QString factoryId() const = 0;
|
||||||
// if the user can create multiple
|
// if the user can create multiple
|
||||||
virtual QIcon icon() const { return QIcon(); }
|
virtual QIcon icon() const { return QIcon(); }
|
||||||
virtual bool isCreatable() const { return true; }
|
virtual bool isUnique() const { return false; }
|
||||||
|
|
||||||
virtual SipPlugin* createPlugin( const QString& pluginId = QString() ) = 0;
|
virtual SipPlugin* createPlugin( const QString& pluginId = QString() ) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@@ -227,8 +227,9 @@ void
|
|||||||
SettingsDialog::setupSipButtons()
|
SettingsDialog::setupSipButtons()
|
||||||
{
|
{
|
||||||
foreach( SipPluginFactory* f, SipHandler::instance()->pluginFactories() ) {
|
foreach( SipPluginFactory* f, SipHandler::instance()->pluginFactories() ) {
|
||||||
if( !f->isCreatable() )
|
if( f->isUnique() && SipHandler::instance()->hasPluginType( f->factoryId() ) ) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
QAction* action = new QAction( f->icon(), f->prettyName(), ui->addSipButton );
|
QAction* action = new QAction( f->icon(), f->prettyName(), ui->addSipButton );
|
||||||
action->setProperty( "factory", QVariant::fromValue< QObject* >( f ) );
|
action->setProperty( "factory", QVariant::fromValue< QObject* >( f ) );
|
||||||
@@ -518,9 +519,9 @@ SettingsDialog::factoryActionTriggered( bool )
|
|||||||
void
|
void
|
||||||
SettingsDialog::sipFactoryClicked( SipPluginFactory* factory )
|
SettingsDialog::sipFactoryClicked( SipPluginFactory* factory )
|
||||||
{
|
{
|
||||||
Q_ASSERT( factory->isCreatable() );
|
|
||||||
//if exited with OK, create it, if not, delete it immediately!
|
//if exited with OK, create it, if not, delete it immediately!
|
||||||
SipPlugin* p = factory->createPlugin();
|
SipPlugin* p = factory->createPlugin();
|
||||||
|
bool added = false;
|
||||||
if( p->configWidget() ) {
|
if( p->configWidget() ) {
|
||||||
DelegateConfigWrapper dialog( p->configWidget(), QString("%1 Config" ).arg( p->friendlyName() ), this );
|
DelegateConfigWrapper dialog( p->configWidget(), QString("%1 Config" ).arg( p->friendlyName() ), this );
|
||||||
QWeakPointer< DelegateConfigWrapper > watcher( &dialog );
|
QWeakPointer< DelegateConfigWrapper > watcher( &dialog );
|
||||||
@@ -532,14 +533,33 @@ SettingsDialog::sipFactoryClicked( SipPluginFactory* factory )
|
|||||||
// accepted, so add it to tomahawk
|
// accepted, so add it to tomahawk
|
||||||
TomahawkSettings::instance()->addSipPlugin( p->pluginId() );
|
TomahawkSettings::instance()->addSipPlugin( p->pluginId() );
|
||||||
SipHandler::instance()->addSipPlugin( p );
|
SipHandler::instance()->addSipPlugin( p );
|
||||||
|
|
||||||
|
added = true;
|
||||||
} else {
|
} else {
|
||||||
// canceled, delete it
|
// canceled, delete it
|
||||||
delete p;
|
delete p;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// no config, so just add it
|
// no config, so just add it
|
||||||
|
added = true;
|
||||||
SipHandler::instance()->addSipPlugin( p );
|
SipHandler::instance()->addSipPlugin( p );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SipPluginFactory* f = SipHandler::instance()->factoryFromPlugin( p );
|
||||||
|
if( added && f && f->isUnique() ) {
|
||||||
|
// remove from actions list
|
||||||
|
QAction* toremove = 0;
|
||||||
|
foreach( QAction* a, ui->addSipButton->actions() )
|
||||||
|
{
|
||||||
|
if( f == qobject_cast< SipPluginFactory* >( a->property( "factory" ).value< QObject* >() ) )
|
||||||
|
{
|
||||||
|
toremove = a;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( toremove )
|
||||||
|
ui->addSipButton->removeAction( toremove );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -574,6 +594,18 @@ SettingsDialog::sipPluginDeleted( bool )
|
|||||||
if( idx.isValid() && !idx.data( SipModel::FactoryRole ).toBool() && !idx.data( SipModel::FactoryItemRole ).toBool() )
|
if( idx.isValid() && !idx.data( SipModel::FactoryRole ).toBool() && !idx.data( SipModel::FactoryItemRole ).toBool() )
|
||||||
{
|
{
|
||||||
SipPlugin* p = qobject_cast< SipPlugin* >( idx.data( SipModel::SipPluginData ).value< QObject* >() );
|
SipPlugin* p = qobject_cast< SipPlugin* >( idx.data( SipModel::SipPluginData ).value< QObject* >() );
|
||||||
|
|
||||||
|
if( SipPluginFactory* f = SipHandler::instance()->factoryFromPlugin( p ) )
|
||||||
|
{
|
||||||
|
if( f->isUnique() ) // just deleted a unique plugin->re-add to add menu
|
||||||
|
{
|
||||||
|
QAction* action = new QAction( f->icon(), f->prettyName(), ui->addSipButton );
|
||||||
|
action->setProperty( "factory", QVariant::fromValue< QObject* >( f ) );
|
||||||
|
ui->addSipButton->addAction( action );
|
||||||
|
|
||||||
|
connect( action, SIGNAL( triggered(bool) ), this, SLOT( factoryActionTriggered( bool ) ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
SipHandler::instance()->removeSipPlugin( p );
|
SipHandler::instance()->removeSipPlugin( p );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 2.4 KiB |
@@ -36,9 +36,10 @@ public:
|
|||||||
|
|
||||||
virtual QString factoryId() const { return "sipzeroconf"; }
|
virtual QString factoryId() const { return "sipzeroconf"; }
|
||||||
virtual QString prettyName() const { return "Local Network"; }
|
virtual QString prettyName() const { return "Local Network"; }
|
||||||
virtual bool isCreatable() const { return false; };
|
virtual bool isUnique() const { return true; }
|
||||||
virtual SipPlugin* createPlugin ( const QString& pluginId = QString() );
|
|
||||||
virtual QIcon icon() const;
|
virtual QIcon icon() const;
|
||||||
|
|
||||||
|
virtual SipPlugin* createPlugin ( const QString& pluginId = QString() );
|
||||||
};
|
};
|
||||||
|
|
||||||
class SIPDLLEXPORT ZeroconfPlugin : public SipPlugin
|
class SIPDLLEXPORT ZeroconfPlugin : public SipPlugin
|
||||||
|
Reference in New Issue
Block a user