Implemented plugin unload.

--HG--
branch : gsoc2014-dfighter
This commit is contained in:
dfighter1985 2014-06-08 18:17:24 +02:00
parent eb41278369
commit d7536332a6
5 changed files with 86 additions and 1 deletions

View file

@ -55,6 +55,9 @@ public:
virtual void setPluginPaths(const QStringList &paths) = 0; virtual void setPluginPaths(const QStringList &paths) = 0;
virtual QList<ExtensionSystem::IPluginSpec *> plugins() const = 0; virtual QList<ExtensionSystem::IPluginSpec *> plugins() const = 0;
virtual bool loadPlugin( const char *plugin ) = 0;
virtual bool unloadPlugin( ExtensionSystem::IPluginSpec *plugin ) = 0;
// Settings // Settings
virtual void setSettings(QSettings *settings) = 0; virtual void setSettings(QSettings *settings) = 0;
virtual QSettings *settings() const = 0; virtual QSettings *settings() const = 0;

View file

@ -114,6 +114,68 @@ void PluginManager::loadPlugins()
Q_EMIT pluginsChanged(); Q_EMIT pluginsChanged();
} }
bool PluginManager::loadPlugin( const char *plugin )
{
return true;
}
bool PluginManager::unloadPlugin( ExtensionSystem::IPluginSpec *plugin )
{
ExtensionSystem::PluginSpec *spec = static_cast< ExtensionSystem::PluginSpec* >( plugin );
// Let's see if anything depends on this one
QListIterator< ExtensionSystem::PluginSpec* > itr( m_pluginSpecs );
while( itr.hasNext() )
{
ExtensionSystem::PluginSpec *sp = itr.next();
QList< ExtensionSystem::PluginSpec* > l = sp->dependencySpecs();
if( l.contains( spec ) )
return false;
}
// Stop, delete then remove plugin
spec->stop();
spec->kill();
removePlugin( plugin );
return true;
}
void PluginManager::removePlugin( ExtensionSystem::IPluginSpec *plugin )
{
QList< ExtensionSystem::IPluginSpec* >::iterator itr1;
QList< ExtensionSystem::PluginSpec* >::iterator itr2;
QList< ExtensionSystem::IPluginSpec* >::iterator i1 = m_ipluginSpecs.begin();
while( i1 != m_ipluginSpecs.end() )
{
if( *i1 == plugin )
{
itr1 = i1;
break;
}
i1++;
}
QList< ExtensionSystem::PluginSpec* >::iterator i2 = m_pluginSpecs.begin();
while( i2 != m_pluginSpecs.end() )
{
if( *i2 == static_cast< ExtensionSystem::PluginSpec* >( plugin ) )
{
itr2 = i2;
break;
}
i2++;
}
m_ipluginSpecs.erase( itr1 );
m_pluginSpecs.erase( itr2 );
delete plugin;
Q_EMIT pluginsChanged();
}
QStringList PluginManager::getPluginPaths() const QStringList PluginManager::getPluginPaths() const
{ {
return m_pluginPaths; return m_pluginPaths;

View file

@ -51,6 +51,10 @@ public:
virtual QList<IPluginSpec *> plugins() const; virtual QList<IPluginSpec *> plugins() const;
QList<PluginSpec *> loadQueue(); QList<PluginSpec *> loadQueue();
bool loadPlugin( const char *plugin );
bool unloadPlugin( ExtensionSystem::IPluginSpec *plugin );
void removePlugin( ExtensionSystem::IPluginSpec *plugin );
// Settings // Settings
virtual void setSettings(QSettings *settings); virtual void setSettings(QSettings *settings);
virtual QSettings *settings() const; virtual QSettings *settings() const;

View file

@ -65,6 +65,7 @@ void PluginView::updateList()
static QIcon notLoadedIcon = QApplication::style()->standardIcon(QStyle::SP_DialogResetButton); static QIcon notLoadedIcon = QApplication::style()->standardIcon(QStyle::SP_DialogResetButton);
m_specToItem.clear(); m_specToItem.clear();
m_itemToSpec.clear();
QList<QTreeWidgetItem *> items; QList<QTreeWidgetItem *> items;
Q_FOREACH (ExtensionSystem::IPluginSpec *spec, m_pluginManager->plugins()) Q_FOREACH (ExtensionSystem::IPluginSpec *spec, m_pluginManager->plugins())
@ -87,6 +88,7 @@ void PluginView::updateList()
items.append(item); items.append(item);
m_specToItem.insert(spec, item); m_specToItem.insert(spec, item);
m_itemToSpec.insert(item, spec);
} }
m_ui.pluginTreeWidget->clear(); m_ui.pluginTreeWidget->clear();
@ -127,7 +129,18 @@ void PluginView::onUnloadClicked()
return; return;
} }
QMap< QTreeWidgetItem*, ExtensionSystem::IPluginSpec* >::const_iterator itr
= m_itemToSpec.find( item );
if( itr == m_itemToSpec.end() )
return;
bool success = m_pluginManager->unloadPlugin( itr.value() );
if( !success )
{
QMessageBox::warning( this,
tr( "Plugin unload" ),
tr( "Failed to unload plugin." ) );
}
} }
void PluginView::onLoadClicked() void PluginView::onLoadClicked()
@ -141,6 +154,8 @@ void PluginView::onLoadClicked()
{ {
return; return;
} }
this->m_pluginManager->loadPlugin( f.toAscii().data() );
} }
} /* namespace Core */ } /* namespace Core */

View file

@ -52,6 +52,7 @@ private:
const int m_checkStateColumn; const int m_checkStateColumn;
QMap<ExtensionSystem::IPluginSpec *, QTreeWidgetItem *> m_specToItem; QMap<ExtensionSystem::IPluginSpec *, QTreeWidgetItem *> m_specToItem;
QMap<QTreeWidgetItem*, ExtensionSystem::IPluginSpec*> m_itemToSpec;
QStringList m_whiteList; QStringList m_whiteList;
ExtensionSystem::IPluginManager *m_pluginManager; ExtensionSystem::IPluginManager *m_pluginManager;
Ui::PluginView m_ui; Ui::PluginView m_ui;