MythTV  0.26-pre
mythplugin.h
Go to the documentation of this file.
00001 #ifndef MYTHPLUGIN_H_
00002 #define MYTHPLUGIN_H_
00003 
00004 #include <QLibrary>
00005 #include <QMap>
00006 #include <QHash>
00007 
00008 #include <vector>
00009 using namespace std;
00010 
00011 #include "mythexp.h"
00012 
00013 class QSqlDatabase;
00014 class MythContext;
00015 class QPainter;
00016 
00017 typedef enum {
00018     kPluginType_Module = 0,
00019     kPluginType_MenuPlugin
00020 } MythPluginType;
00021 
00022 class MythPlugin : public QLibrary
00023 {
00024   public:
00025     MythPlugin(const QString &, const QString &);
00026     virtual ~MythPlugin();
00027 
00028     // This method will call the mythplugin_init() function of the library. 
00029     int init(const char *libversion);
00030 
00031     // This method will call the mythplugin_run() function of the library.
00032     int run(void);
00033  
00034     // This method will call the mythplugin_config() function of the library.
00035     int config(void);
00036 
00037     // This method will call the mythplugin_type() function of the library.
00038     // If such a function doesn't exist, it's a main module plugin.
00039     MythPluginType type(void);
00040 
00041     // This method will call the mythplugin_destroy() function of the library,
00042     // if such a function exists.
00043     void destroy(void);
00044 
00045     bool isEnabled() { return enabled; }
00046     void setEnabled(bool enable) { enabled = enable; }
00047 
00048     int getPosition() { return position; }
00049     void setPosition(int pos) { position = pos; }
00050 
00051     QString getName(void) { return m_plugName; }
00052 
00053     // mainmenu plugins, probably should separate out
00054 
00055     // setup the plugin -- returns how often (in ms) the plugin wants updated
00056     int setupMenuPlugin(void);
00057 
00058     // draw the plugin
00059     void drawMenuPlugin(QPainter *painter, int x, int y, int w, int h);
00060 
00061   private:
00062     bool enabled;
00063     int position;
00064     QString m_plugName;
00065 };
00066 
00067 // this should only be instantiated through MythContext.
00068 class MPUBLIC MythPluginManager
00069 {
00070   public:   
00071     MythPluginManager();
00072    ~MythPluginManager();
00073    
00074     bool init_plugin(const QString &plugname);
00075     bool run_plugin(const QString &plugname);
00076     bool config_plugin(const QString &plugname);
00077     bool destroy_plugin(const QString &plugname);
00078 
00079     MythPlugin *GetPlugin(const QString &plugname);
00080     MythPlugin *GetMenuPlugin(const QString &plugname);
00081     MythPlugin *GetMenuPluginAt(int pos);
00082 
00083     QStringList EnumeratePlugins(void);
00084     void DestroyAllPlugins();
00085      
00086   private:
00087     QHash<QString,MythPlugin*> m_dict;
00088    
00089     QMap<QString, MythPlugin *> moduleMap;
00090     QMap<QString, MythPlugin *> menuPluginMap;
00091     vector<MythPlugin*> menuPluginList;
00092 
00093     void orderMenuPlugins();
00094 };
00095 
00096 #endif
00097 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends