Stellarium 0.13.0
StelModuleMgr.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2006 Fabien Chereau
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _STELMODULEMGR_HPP_
21 #define _STELMODULEMGR_HPP_
22 
23 #include <QObject>
24 #include <QMap>
25 #include <QList>
26 #include "StelModule.hpp"
27 #include "StelPluginInterface.hpp"
28 
31 #define GETSTELMODULE( m ) (( m *)StelApp::getInstance().getModuleMgr().getModule( #m ))
32 
36 class StelModuleMgr : public QObject
37 {
38  Q_OBJECT
39 
40 public:
41  StelModuleMgr();
42  ~StelModuleMgr();
43 
45  void update();
46 
49  void registerModule(StelModule* m, bool generateCallingLists=false);
50 
54  void unloadModule(const QString& moduleID, bool alsoDelete=true);
55 
60  StelModule* loadPlugin(const QString& moduleID);
61 
63  void unloadAllPlugins();
64 
68  void setPluginLoadAtStartup(const QString& key, bool b);
69 
73  StelModule* getModule(const QString& moduleID, bool noWarning=false);
74 
76  QList<StelModule*> getAllModules() {return modules.values();}
77 
79  const QList<StelModule*>& getCallOrders(StelModule::StelModuleActionName action)
80  {
81  return callOrders[action];
82  }
83 
86  {
87  PluginDescriptor() : loadAtStartup(false), loaded(false) {;}
93  bool loaded;
94 
95  private:
96  friend class StelModuleMgr;
97  StelPluginInterface* pluginInterface;
98  };
99 
101  QList<PluginDescriptor> getPluginsList();
102 
103 private:
106  void generateCallingLists();
107 
109  QMap<QString, StelModule*> modules;
110 
112  QMap<StelModule::StelModuleActionName, QList<StelModule*> > callOrders;
113 
115  bool callingListsToRegenerate;
116 
117  QMap<QString, StelModuleMgr::PluginDescriptor> pluginDescriptorList;
118  bool pluginDescriptorListLoaded;
119 };
120 
121 #endif // _STELMODULEMGR_HPP_
StelModule * getModule(const QString &moduleID, bool noWarning=false)
Get the corresponding module or NULL if can't find it.
Define the interface to implement when creating a plugin.
Definition: StelPluginInterface.hpp:54
Contains the information read from the module.ini file.
Definition: StelModuleMgr.hpp:85
void update()
Regenerate calling lists if necessary.
bool loadAtStartup
If true, the module is automatically loaded at startup.
Definition: StelModuleMgr.hpp:91
const QList< StelModule * > & getCallOrders(StelModule::StelModuleActionName action)
Get the list of modules in the correct order for calling the given action.
Definition: StelModuleMgr.hpp:79
QList< StelModule * > getAllModules()
Get the list of all the currently registered modules.
Definition: StelModuleMgr.hpp:76
Manage a collection of StelModules including both core and plugin modules.
Definition: StelModuleMgr.hpp:36
QList< PluginDescriptor > getPluginsList()
Return the list of all the external module found in the modules directories.
bool loaded
True if the plugin is currently loaded.
Definition: StelModuleMgr.hpp:93
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:120
void registerModule(StelModule *m, bool generateCallingLists=false)
Register a new StelModule to the list The module is later referenced by its QObject name...
void unloadAllPlugins()
Unload all plugins.
void unloadModule(const QString &moduleID, bool alsoDelete=true)
Unregister and delete a StelModule.
void setPluginLoadAtStartup(const QString &key, bool b)
Define whether a plugin should be loaded at startup.
StelModule * loadPlugin(const QString &moduleID)
Load dynamically a module.
StelPluginInfo info
The static info for the plugin.
Definition: StelModuleMgr.hpp:89
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:52
Contains information about a Stellarium plugin.
Definition: StelPluginInterface.hpp:28