mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 08:19:42 +01:00
allow factories to be marked as unique
This commit is contained in:
parent
7be0cdb714
commit
81fe1c8061
@ -145,11 +145,11 @@ SipHandler::loadPluginFactories( const QStringList& paths )
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
return sip;
|
||||
@ -269,6 +269,16 @@ SipHandler::removeSipPlugin( SipPlugin* 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
|
||||
SipHandler::loadFromConfig( bool startup )
|
||||
@ -583,7 +593,14 @@ SipHandler::onAvatarReceived( const QPixmap& avatar )
|
||||
|
||||
|
||||
QString
|
||||
SipHandler::factoryFromId( const QString& pluginId )
|
||||
SipHandler::factoryFromId( const QString& pluginId ) const
|
||||
{
|
||||
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 removeSipPlugin( SipPlugin* p );
|
||||
|
||||
bool hasPluginType( const QString& factoryId ) const;
|
||||
SipPluginFactory* factoryFromPlugin( SipPlugin* p ) const;
|
||||
|
||||
const QPixmap avatar( const QString& name ) const;
|
||||
|
||||
public slots:
|
||||
@ -104,7 +107,7 @@ private:
|
||||
|
||||
void loadPluginFactories( const QStringList& paths );
|
||||
void loadPluginFactory( const QString& path );
|
||||
QString factoryFromId( const QString& pluginId );
|
||||
QString factoryFromId( const QString& pluginId ) const;
|
||||
|
||||
QHash< QString, SipPluginFactory* > m_pluginFactories;
|
||||
QList< SipPlugin* > m_allPlugins;
|
||||
|
@ -43,7 +43,8 @@ public:
|
||||
virtual QString factoryId() const = 0;
|
||||
// if the user can create multiple
|
||||
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;
|
||||
|
||||
protected:
|
||||
|
@ -227,8 +227,9 @@ void
|
||||
SettingsDialog::setupSipButtons()
|
||||
{
|
||||
foreach( SipPluginFactory* f, SipHandler::instance()->pluginFactories() ) {
|
||||
if( !f->isCreatable() )
|
||||
if( f->isUnique() && SipHandler::instance()->hasPluginType( f->factoryId() ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QAction* action = new QAction( f->icon(), f->prettyName(), ui->addSipButton );
|
||||
action->setProperty( "factory", QVariant::fromValue< QObject* >( f ) );
|
||||
@ -518,9 +519,9 @@ SettingsDialog::factoryActionTriggered( bool )
|
||||
void
|
||||
SettingsDialog::sipFactoryClicked( SipPluginFactory* factory )
|
||||
{
|
||||
Q_ASSERT( factory->isCreatable() );
|
||||
//if exited with OK, create it, if not, delete it immediately!
|
||||
SipPlugin* p = factory->createPlugin();
|
||||
bool added = false;
|
||||
if( p->configWidget() ) {
|
||||
DelegateConfigWrapper dialog( p->configWidget(), QString("%1 Config" ).arg( p->friendlyName() ), this );
|
||||
QWeakPointer< DelegateConfigWrapper > watcher( &dialog );
|
||||
@ -532,14 +533,33 @@ SettingsDialog::sipFactoryClicked( SipPluginFactory* factory )
|
||||
// accepted, so add it to tomahawk
|
||||
TomahawkSettings::instance()->addSipPlugin( p->pluginId() );
|
||||
SipHandler::instance()->addSipPlugin( p );
|
||||
|
||||
added = true;
|
||||
} else {
|
||||
// canceled, delete it
|
||||
delete p;
|
||||
}
|
||||
} else {
|
||||
// no config, so just add it
|
||||
added = true;
|
||||
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
|
||||
@ -574,6 +594,18 @@ SettingsDialog::sipPluginDeleted( bool )
|
||||
if( idx.isValid() && !idx.data( SipModel::FactoryRole ).toBool() && !idx.data( SipModel::FactoryItemRole ).toBool() )
|
||||
{
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
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 prettyName() const { return "Local Network"; }
|
||||
virtual bool isCreatable() const { return false; };
|
||||
virtual SipPlugin* createPlugin ( const QString& pluginId = QString() );
|
||||
virtual bool isUnique() const { return true; }
|
||||
virtual QIcon icon() const;
|
||||
|
||||
virtual SipPlugin* createPlugin ( const QString& pluginId = QString() );
|
||||
};
|
||||
|
||||
class SIPDLLEXPORT ZeroconfPlugin : public SipPlugin
|
||||
|
Loading…
x
Reference in New Issue
Block a user