mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-17 04:51:48 +00:00
Implemented plugin unload.
This commit is contained in:
parent
3eb5115a0b
commit
c3084d5661
5 changed files with 86 additions and 1 deletions
|
@ -55,6 +55,9 @@ public:
|
|||
virtual void setPluginPaths(const QStringList &paths) = 0;
|
||||
virtual QList<ExtensionSystem::IPluginSpec *> plugins() const = 0;
|
||||
|
||||
virtual bool loadPlugin( const char *plugin ) = 0;
|
||||
virtual bool unloadPlugin( ExtensionSystem::IPluginSpec *plugin ) = 0;
|
||||
|
||||
// Settings
|
||||
virtual void setSettings(QSettings *settings) = 0;
|
||||
virtual QSettings *settings() const = 0;
|
||||
|
|
|
@ -114,6 +114,68 @@ void PluginManager::loadPlugins()
|
|||
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
|
||||
{
|
||||
return m_pluginPaths;
|
||||
|
|
|
@ -51,6 +51,10 @@ public:
|
|||
virtual QList<IPluginSpec *> plugins() const;
|
||||
QList<PluginSpec *> loadQueue();
|
||||
|
||||
bool loadPlugin( const char *plugin );
|
||||
bool unloadPlugin( ExtensionSystem::IPluginSpec *plugin );
|
||||
void removePlugin( ExtensionSystem::IPluginSpec *plugin );
|
||||
|
||||
// Settings
|
||||
virtual void setSettings(QSettings *settings);
|
||||
virtual QSettings *settings() const;
|
||||
|
|
|
@ -65,6 +65,7 @@ void PluginView::updateList()
|
|||
static QIcon notLoadedIcon = QApplication::style()->standardIcon(QStyle::SP_DialogResetButton);
|
||||
|
||||
m_specToItem.clear();
|
||||
m_itemToSpec.clear();
|
||||
|
||||
QList<QTreeWidgetItem *> items;
|
||||
Q_FOREACH (ExtensionSystem::IPluginSpec *spec, m_pluginManager->plugins())
|
||||
|
@ -87,6 +88,7 @@ void PluginView::updateList()
|
|||
|
||||
items.append(item);
|
||||
m_specToItem.insert(spec, item);
|
||||
m_itemToSpec.insert(item, spec);
|
||||
}
|
||||
|
||||
m_ui.pluginTreeWidget->clear();
|
||||
|
@ -127,7 +129,18 @@ void PluginView::onUnloadClicked()
|
|||
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()
|
||||
|
@ -141,6 +154,8 @@ void PluginView::onLoadClicked()
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this->m_pluginManager->loadPlugin( f.toAscii().data() );
|
||||
}
|
||||
|
||||
} /* namespace Core */
|
|
@ -52,6 +52,7 @@ private:
|
|||
|
||||
const int m_checkStateColumn;
|
||||
QMap<ExtensionSystem::IPluginSpec *, QTreeWidgetItem *> m_specToItem;
|
||||
QMap<QTreeWidgetItem*, ExtensionSystem::IPluginSpec*> m_itemToSpec;
|
||||
QStringList m_whiteList;
|
||||
ExtensionSystem::IPluginManager *m_pluginManager;
|
||||
Ui::PluginView m_ui;
|
||||
|
|
Loading…
Reference in a new issue