StelModuleMgr.cpp   StelModuleMgr.cpp 
skipping to change at line 34 skipping to change at line 34
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelModule.hpp" #include "StelModule.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelPluginInterface.hpp" #include "StelPluginInterface.hpp"
#include "StelIniParser.hpp" #include "StelIniParser.hpp"
StelModuleMgr::StelModuleMgr() : callingListsToRegenerate(true), pluginDesc riptorListLoaded(false) StelModuleMgr::StelModuleMgr() : callingListsToRegenerate(true), pluginDesc riptorListLoaded(false)
{ {
qRegisterMetaType<StelModule::StelModuleSelectAction>("StelModule::S telModuleSelectAction");
// Initialize empty call lists for each possible actions // Initialize empty call lists for each possible actions
callOrders[StelModule::ActionDraw]=QList<StelModule*>(); callOrders[StelModule::ActionDraw]=QList<StelModule*>();
callOrders[StelModule::ActionUpdate]=QList<StelModule*>(); callOrders[StelModule::ActionUpdate]=QList<StelModule*>();
callOrders[StelModule::ActionHandleMouseClicks]=QList<StelModule*>() ; callOrders[StelModule::ActionHandleMouseClicks]=QList<StelModule*>() ;
callOrders[StelModule::ActionHandleMouseMoves]=QList<StelModule*>(); callOrders[StelModule::ActionHandleMouseMoves]=QList<StelModule*>();
callOrders[StelModule::ActionHandleKeys]=QList<StelModule*>(); callOrders[StelModule::ActionHandleKeys]=QList<StelModule*>();
} }
StelModuleMgr::~StelModuleMgr() StelModuleMgr::~StelModuleMgr()
{ {
skipping to change at line 60 skipping to change at line 61
generateCallingLists(); generateCallingLists();
callingListsToRegenerate = false; callingListsToRegenerate = false;
} }
/************************************************************************* /*************************************************************************
Register a new StelModule to the list Register a new StelModule to the list
*************************************************************************/ *************************************************************************/
void StelModuleMgr::registerModule(StelModule* m, bool fgenerateCallingList s) void StelModuleMgr::registerModule(StelModule* m, bool fgenerateCallingList s)
{ {
QString name = m->objectName(); QString name = m->objectName();
if (modules.find(name) != modules.end()) if (modules.contains(name))
{ {
qWarning() << "Module \"" << name << "\" is already loaded." ; qWarning() << "Module" << name << "is already loaded.";
return; return;
} }
modules.insert(name, m); modules.insert(name, m);
m->setParent(this); m->setParent(this);
if (fgenerateCallingLists) if (fgenerateCallingLists)
generateCallingLists(); generateCallingLists();
} }
/************************************************************************* /*************************************************************************
Unregister and delete a StelModule. Unregister and delete a StelModule.
*************************************************************************/ *************************************************************************/
void StelModuleMgr::unloadModule(const QString& moduleID, bool alsoDelete) void StelModuleMgr::unloadModule(const QString& moduleID, bool alsoDelete)
{ {
StelModule* m = getModule(moduleID); StelModule* m = getModule(moduleID);
if (!m) if (!m)
{ {
qWarning() << "Module \"" << moduleID << "\" is not loaded." ; qWarning() << "Module" << moduleID << "is not loaded.";
return; return;
} }
modules.remove(moduleID); modules.remove(moduleID);
m->setParent(NULL); m->setParent(NULL);
callingListsToRegenerate = true; callingListsToRegenerate = true;
if (alsoDelete) if (alsoDelete)
{ {
m->deinit(); m->deinit();
delete m; delete m;
} }
} }
/************************************************************************* /*************************************************************************
Get the corresponding module or NULL if can't find it. Get the corresponding module or NULL if can't find it.
*************************************************************************/ *************************************************************************/
StelModule* StelModuleMgr::getModule(const QString& moduleID, bool noWarnin g) StelModule* StelModuleMgr::getModule(const QString& moduleID, bool noWarnin g)
{ {
QMap<QString, StelModule*>::ConstIterator iter = modules.find(module StelModule* module = modules.value(moduleID, NULL);
ID); if (module == NULL)
if (iter==modules.constEnd())
{ {
if (noWarning==false) if (noWarning==false)
qWarning() << "Warning can't find module called " << qWarning() << "Unable to find module called" << modu
moduleID << "."; leID;
return NULL;
} }
return iter.value(); return module;
} }
/************************************************************************* /*************************************************************************
Load an external plugin Load an external plugin
*************************************************************************/ *************************************************************************/
StelModule* StelModuleMgr::loadPlugin(const QString& moduleID) StelModule* StelModuleMgr::loadPlugin(const QString& moduleID)
{ {
foreach (const PluginDescriptor& desc, getPluginsList()) foreach (const PluginDescriptor& desc, getPluginsList())
{ {
if (desc.info.id==moduleID) if (desc.info.id==moduleID)
{ {
Q_ASSERT(desc.pluginInterface); Q_ASSERT(desc.pluginInterface);
StelModule* sMod = desc.pluginInterface->getStelModu le(); StelModule* sMod = desc.pluginInterface->getStelModu le();
qDebug() << "Loaded plugin " << moduleID << "."; qDebug() << "Loaded plugin" << moduleID;
pluginDescriptorList[moduleID].loaded=true; pluginDescriptorList[moduleID].loaded=true;
return sMod; return sMod;
} }
} }
qWarning() << "Can't find plugin called " << moduleID; qWarning() << "Unable to find plugin called" << moduleID;
return NULL; return NULL;
} }
struct StelModuleOrderComparator struct StelModuleOrderComparator
{ {
StelModuleOrderComparator(StelModule::StelModuleActionName aaction) : action(aaction) {;} StelModuleOrderComparator(StelModule::StelModuleActionName aaction) : action(aaction) {;}
bool operator()(StelModule* x, StelModule* y) {return x->getCallOrde r(action)<y->getCallOrder(action);} bool operator()(StelModule* x, StelModule* y) {return x->getCallOrde r(action)<y->getCallOrder(action);}
private: private:
StelModule::StelModuleActionName action; StelModule::StelModuleActionName action;
}; };
skipping to change at line 147 skipping to change at line 147
void StelModuleMgr::unloadAllPlugins() void StelModuleMgr::unloadAllPlugins()
{ {
QListIterator<PluginDescriptor> i(getPluginsList()); QListIterator<PluginDescriptor> i(getPluginsList());
i.toBack(); i.toBack();
while (i.hasPrevious()) while (i.hasPrevious())
{ {
const PluginDescriptor& d = i.previous(); const PluginDescriptor& d = i.previous();
if (d.loaded==false) if (d.loaded==false)
continue; continue;
unloadModule(d.info.id, true); unloadModule(d.info.id, true);
qDebug() << "Unloaded plugin " << d.info.id << "."; qDebug() << "Unloaded plugin" << d.info.id;
} }
// Call update now to make sure that all references to the now delet ed plugins modules // Call update now to make sure that all references to the now delet ed plugins modules
// are removed (fix crashes at application shutdown). // are removed (fix crashes at application shutdown).
update(); update();
} }
void StelModuleMgr::setPluginLoadAtStartup(const QString& key, bool b) void StelModuleMgr::setPluginLoadAtStartup(const QString& key, bool b)
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
skipping to change at line 212 skipping to change at line 212
{ {
StelModuleMgr::PluginDescriptor mDesc; StelModuleMgr::PluginDescriptor mDesc;
mDesc.info = pluginInterface->getPluginInfo(); mDesc.info = pluginInterface->getPluginInfo();
mDesc.pluginInterface = pluginInterface; mDesc.pluginInterface = pluginInterface;
pluginDescriptorList.insert(mDesc.info.id, mDesc); pluginDescriptorList.insert(mDesc.info.id, mDesc);
} }
} }
// Then list dynamic libraries from the modules/ directory // Then list dynamic libraries from the modules/ directory
QSet<QString> moduleDirs; QSet<QString> moduleDirs;
try moduleDirs = StelFileMgr::listContents("modules",StelFileMgr::Direct
{ ory);
moduleDirs = StelFileMgr::listContents("modules",StelFileMgr
::Directory);
}
catch(std::runtime_error& e)
{
qWarning() << "ERROR while trying list list modules:" << e.w
hat();
}
foreach (QString dir, moduleDirs) foreach (QString dir, moduleDirs)
{ {
QString moduleFullPath = QString("modules/") + dir + "/lib" + dir; QString moduleFullPath = QString("modules/") + dir + "/lib" + dir;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
moduleFullPath += ".dll"; moduleFullPath += ".dll";
#else #else
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
moduleFullPath += ".dylib"; moduleFullPath += ".dylib";
#else #else
moduleFullPath += ".so"; moduleFullPath += ".so";
#endif #endif
#endif #endif
try moduleFullPath = StelFileMgr::findFile(moduleFullPath, StelF
{ ileMgr::File);
moduleFullPath = StelFileMgr::findFile(moduleFullPat if (moduleFullPath.isEmpty())
h, StelFileMgr::File);
}
catch (std::runtime_error& e)
{
continue; continue;
}
QPluginLoader loader(moduleFullPath); QPluginLoader loader(moduleFullPath);
if (!loader.load()) if (!loader.load())
{ {
qWarning() << "Couldn't load the dynamic library: " qWarning() << "Couldn't load the dynamic library:" <
<< QDir::toNativeSeparators(moduleFullPath) << ": " << loader.errorString() < QDir::toNativeSeparators(moduleFullPath) << ": " << loader.errorString();
; qWarning() << "Plugin" << dir << "will not be loaded
qWarning() << "Plugin " << dir << " will not be load .";
ed.";
continue; continue;
} }
QObject* obj = loader.instance(); QObject* obj = loader.instance();
if (!obj) if (!obj)
{ {
qWarning() << "Couldn't open the dynamic library: " qWarning() << "Couldn't open the dynamic library:" <
<< QDir::toNativeSeparators(moduleFullPath) << ": " << loader.errorString() < QDir::toNativeSeparators(moduleFullPath) << ": " << loader.errorString();
; qWarning() << "Plugin" << dir << "will not be open."
qWarning() << "Plugin " << dir << " will not be open ;
.";
continue; continue;
} }
StelPluginInterface* pluginInterface = qobject_cast<StelPlug inInterface *>(obj); StelPluginInterface* pluginInterface = qobject_cast<StelPlug inInterface *>(obj);
if (pluginInterface) if (pluginInterface)
{ {
StelModuleMgr::PluginDescriptor mDesc; StelModuleMgr::PluginDescriptor mDesc;
mDesc.info = pluginInterface->getPluginInfo(); mDesc.info = pluginInterface->getPluginInfo();
mDesc.pluginInterface = pluginInterface; mDesc.pluginInterface = pluginInterface;
pluginDescriptorList.insert(mDesc.info.id, mDesc); pluginDescriptorList.insert(mDesc.info.id, mDesc);
} }
} }
// Load for each plugin if it should be loaded at startup // Load for each plugin if it should be loaded at startup
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf);
conf->beginGroup("plugins_load_at_startup");
for (QMap<QString, StelModuleMgr::PluginDescriptor>::Iterator iter=p luginDescriptorList.begin();iter!=pluginDescriptorList.end();++iter) for (QMap<QString, StelModuleMgr::PluginDescriptor>::Iterator iter=p luginDescriptorList.begin();iter!=pluginDescriptorList.end();++iter)
{ {
if (!conf->contains("plugins_load_at_startup/"+iter.key())) bool startByDefault = iter.value().info.startByDefault;
conf->setValue("plugins_load_at_startup/"+iter.key() iter->loadAtStartup = conf->value(iter.key(), startByDefault
, iter.value().info.startByDefault); ).toBool();
iter->loadAtStartup = conf->value("plugins_load_at_startup/" // Save the value in case no such key exists
+iter.key()).toBool(); conf->setValue(iter.key(), iter->loadAtStartup);
} }
conf->endGroup();
pluginDescriptorListLoaded = true; pluginDescriptorListLoaded = true;
return pluginDescriptorList.values(); return pluginDescriptorList.values();
} }
 End of changes. 18 change blocks. 
46 lines changed or deleted 33 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/