Stellarium  0.16.1
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 
62  QObjectList loadExtensions(const QString& moduleID);
63 
65  void unloadAllPlugins();
66 
70  void setPluginLoadAtStartup(const QString& key, bool b);
71 
75  StelModule* getModule(const QString& moduleID, bool noWarning=false);
76 
78  QList<StelModule*> getAllModules() {return modules.values();}
79 
81  const QList<StelModule*>& getCallOrders(StelModule::StelModuleActionName action)
82  {
83  return callOrders[action];
84  }
85 
88  {
89  PluginDescriptor() : loadAtStartup(false), loaded(false), pluginInterface(Q_NULLPTR) {;}
95  bool loaded;
96 
97  private:
98  friend class StelModuleMgr;
99  StelPluginInterface* pluginInterface;
100  };
101 
103  QList<PluginDescriptor> getPluginsList();
104 
108  QObjectList getExtensionList() { return extensions; }
109 signals:
111  void extensionsAdded(QObjectList newExtensions);
112 
113 private:
116  void generateCallingLists();
117 
119  QMap<QString, StelModule*> modules;
120 
122  QObjectList extensions;
123 
125  QMap<StelModule::StelModuleActionName, QList<StelModule*> > callOrders;
126 
128  bool callingListsToRegenerate;
129 
130  QMap<QString, StelModuleMgr::PluginDescriptor> pluginDescriptorList;
131  bool pluginDescriptorListLoaded;
132 };
133 
134 #endif // _STELMODULEMGR_HPP_
StelModule * getModule(const QString &moduleID, bool noWarning=false)
Get the corresponding module or Q_NULLPTR if can&#39;t find it.
Define the interface to implement when creating a plugin.
Contains the information read from the module.ini file.
void update()
Regenerate calling lists if necessary.
bool loadAtStartup
If true, the module is automatically loaded at startup.
QObjectList getExtensionList()
Returns the list of all currently registered extensions.
const QList< StelModule * > & getCallOrders(StelModule::StelModuleActionName action)
Get the list of modules in the correct order for calling the given action.
void extensionsAdded(QObjectList newExtensions)
Called whenever new plugin extensions are added.
QList< StelModule * > getAllModules()
Get the list of all the currently registered modules.
Manage a collection of StelModules including both core and plugin modules.
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.
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:121
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.
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:49
Contains information about a Stellarium plugin.