File indexing completed on 2024-04-21 15:08:23

0001 //
0002 // C++ Interface: cpluginmanager
0003 //
0004 // Description: plug-in manager
0005 //
0006 /*
0007 Copyright 2006-2011 Tomas Mecir <kmuddy@kmuddy.com>
0008 
0009 This program is free software; you can redistribute it and/or
0010 modify it under the terms of the GNU General Public License as
0011 published by the Free Software Foundation; either version 2 of 
0012 the License, or (at your option) any later version.
0013 
0014 This program is distributed in the hope that it will be useful,
0015 but WITHOUT ANY WARRANTY; without even the implied warranty of
0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017 GNU General Public License for more details.
0018 
0019 You should have received a copy of the GNU General Public License
0020 along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 
0023 #ifndef CPLUGINMANAGER_H
0024 #define CPLUGINMANAGER_H
0025 
0026 
0027 #include <cactionbase.h>
0028 #include <kmuddy_export.h>
0029 
0030 #include <qobject.h>
0031 #include <qstringlist.h>
0032 #include <map>
0033 
0034 #include <KConfigGroup>
0035 #include <KPluginMetaData>
0036 
0037 using namespace std;
0038 
0039 class cPlugin;
0040 class cTextChunk;
0041 class QDialog;
0042 class KPluginWidget;
0043 
0044 /**
0045 Plug-in manager handles plug-in information, loads plug-ins, and passes data/events to them as needed.
0046 
0047 @author Tomas Mecir
0048 */
0049 
0050 class KMUDDY_EXPORT cPluginManager : public QObject, public cActionBase
0051 {
0052 Q_OBJECT
0053  public:
0054   ~cPluginManager () override;
0055 
0056   static cPluginManager *self();
0057 
0058   /** load a plug-in into memory, if possible */
0059   bool loadPlugin (const QString &name);
0060   /** unload a plug-in from memory, if possible */
0061   bool unloadPlugin (const QString &name);
0062   bool isLoaded (const QString &name);
0063 
0064   /** list of plug-ins that should not be loaded - from preferences */
0065   void setConfigGroup (const KConfigGroup &group) { pluginConfig = group; }
0066   
0067   /** Load all available plug-ins expect those that should not be loaded.
0068   This ensures that all newly installed plug-ins get loaded initially. */
0069   void loadAll ();
0070   /** unload all plug-ins that are currently loaded, but are to be disabled */
0071   void unloadUnwanted ();
0072   /** unload all plug-ins */
0073   void unloadAll ();
0074 
0075 public slots:
0076   /** show the Plugins dialog */
0077   void showPluginsDialog ();
0078   
0079 protected slots:
0080   /** apply settings from the plugins dialog */
0081   void applyPluginDialog ();
0082   void closeDialog();
0083   
0084 protected:
0085   cPluginManager ();
0086   
0087   static cPluginManager *_self;
0088 
0089   void eventIntHandler (QString event, int session, int par1, int par2) override;
0090   void eventStringHandler (QString event, int session, QString &par1, const QString &par2) override;
0091   void eventNothingHandler (QString event, int session) override;
0092   void eventChunkHandler (QString event, int session, cTextChunk *par) override;
0093   
0094   void findPlugins ();
0095   
0096   void passSessionAdd (int sess);
0097   void passSessionRemove (int sess);
0098   void passSessionSwitch (int sess);
0099   void passConnected (int sess);
0100   void passDisconnected (int sess);
0101   void passSave (int sess);
0102   void passRawData (int sess, char *);
0103   void passDecompressedData (int sess, char *);
0104   void passInput (int sess, int phase, cTextChunk *chunk, bool gagged);
0105   void passPrompt (int sess, cTextChunk *chunk);
0106   void passCommand (int sess, QString &command);
0107   
0108   map<QString, KPluginMetaData> pluginInfo;
0109   map<QString, cPlugin *> loadedPlugins;
0110   /** plug-ins sorted by priority */
0111   multimap<int, cPlugin *> plugins;
0112   /** iterator, it's not a local variable, so that passing data to plug-ins is a bit faster :) */
0113   multimap<int, cPlugin *>::iterator it;
0114   KConfigGroup pluginConfig;
0115   /** existing sessions */
0116   map<int, bool> sessions;
0117   /** active session */
0118   int activeSess;
0119   bool lastGagged;
0120 
0121   QDialog *pluginDialog;
0122   KPluginWidget *pluginSelector;
0123 };
0124 
0125 #endif