1 #ifndef _KVI_MODULEEXTENSION_H_ 2 #define _KVI_MODULEEXTENSION_H_ 3 //============================================================================= 4 // 5 // File : KviModuleExtension.h 6 // Creation date : Tue Sep 10 01:16:24 2002 GMT by Szymon Stefanek 7 // 8 // This file is part of the KVIrc IRC client distribution 9 // Copyright (C) 2002-2010 Szymon Stefanek (pragma at kvirc dot net) 10 // 11 // This program is FREE software. You can redistribute it and/or 12 // modify it under the terms of the GNU General Public License 13 // as published by the Free Software Foundation; either version 2 14 // of the License, or (at your option) any later version. 15 // 16 // This program is distributed in the HOPE that it will be USEFUL, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 // See the GNU General Public License for more details. 20 // 21 // You should have received a copy of the GNU General Public License 22 // along with this program. If not, write to the Free Software Foundation, 23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 24 // 25 //============================================================================= 26 27 #include "kvi_settings.h" 28 #include "KviCString.h" 29 #include "KviPointerList.h" 30 #include "KviHeapObject.h" 31 #include "KviPointerHashTable.h" 32 33 #include <QVariant> 34 35 class KviModule; 36 class KviModuleExtension; 37 class KviModuleExtensionDescriptor; 38 class KviWindow; 39 class QPixmap; 40 41 struct KviModuleExtensionAllocStruct 42 { 43 KviModuleExtensionDescriptor * pDescriptor; // module extension that this alloc routine refers to 44 KviWindow * pWindow; // may be 0! 45 KviPointerHashTable<QString, QVariant> * pParams; // parameter dict (may be 0!) 46 void * pSpecial; // special parameter passed to the alloc routine, may be 0 47 }; 48 49 typedef KviModuleExtension * (*KviModuleExtensionAllocRoutine)(KviModuleExtensionAllocStruct *); 50 51 class KVIRC_API KviModuleExtensionDescriptor 52 { 53 friend class KviModuleExtension; 54 friend class KviModuleExtensionManager; // only the manager allocates and deallocates these structures 55 protected: 56 KviModuleExtensionDescriptor(KviModule * m, const KviCString & szType, const KviCString & szName, const QString & szVisibleName, KviModuleExtensionAllocRoutine r, const QPixmap & pix); 57 58 public: // this has to be public because of QPtrList... but should be protected 59 ~KviModuleExtensionDescriptor(); 60 61 private: 62 int m_iId; // unique id assigned at creation time 63 KviCString m_szType; // name of the service (toolbar, crypt engine...) 64 KviCString m_szName; // name of the extension 65 QString m_szVisibleName; // name that is VISIBLE and possibly translated 66 KviCString m_szAuthor; // Author (visible) 67 KviCString m_szDescription; // Description (visible!) 68 int m_iFlags; // Flags (0 if not applicable) 69 QPixmap * m_pIcon; // Icon (may be null!) 70 KviModuleExtensionAllocRoutine m_allocRoutine; 71 KviPointerList<KviModuleExtension> * m_pObjectList; 72 73 KviModule * m_pModule; // module pointer 74 public: 75 // pParams ownership is NOT taken 76 KviModuleExtension * allocate(KviWindow * pWnd = nullptr, KviPointerHashTable<QString, QVariant> * pParams = nullptr, void * pSpecial = nullptr); 77 id()78 int id() { return m_iId; }; module()79 KviModule * module() { return m_pModule; }; type()80 const KviCString & type() { return m_szType; }; name()81 const KviCString & name() { return m_szName; }; visibleName()82 const QString & visibleName() { return m_szVisibleName; }; author()83 const KviCString & author() { return m_szAuthor; }; description()84 const KviCString & description() { return m_szDescription; }; icon()85 const QPixmap * icon() { return m_pIcon; }; flags()86 int flags() { return m_iFlags; }; 87 setAuthor(const KviCString & szAuthor)88 void setAuthor(const KviCString & szAuthor) { m_szAuthor = szAuthor; }; setDescription(const KviCString & szDescription)89 void setDescription(const KviCString & szDescription) { m_szDescription = szDescription; }; setVisibleName(const KviCString & szVisibleName)90 void setVisibleName(const KviCString & szVisibleName) { m_szVisibleName = szVisibleName; }; setFlags(int iFlags)91 void setFlags(int iFlags) { m_iFlags = iFlags; }; 92 void setIcon(const QPixmap & pix); 93 94 protected: 95 void registerObject(KviModuleExtension * e); 96 void unregisterObject(KviModuleExtension * e); 97 }; 98 99 typedef KviPointerList<KviModuleExtensionDescriptor> KviModuleExtensionDescriptorList; 100 101 class KviModuleExtensionManager; 102 103 extern KVIRC_API KviModuleExtensionManager * g_pModuleExtensionManager; 104 105 class KVIRC_API KviModuleExtensionManager 106 { 107 friend class KviModule; 108 friend class KviApplication; 109 110 protected: 111 KviModuleExtensionManager(); // KviApplication calls this 112 ~KviModuleExtensionManager(); // and this 113 protected: 114 KviPointerHashTable<const char *, KviModuleExtensionDescriptorList> * m_pExtensionDict; 115 116 protected: 117 // Only KviModule can call this 118 KviModuleExtensionDescriptor * registerExtension(KviModule * m, const KviCString & szType, const KviCString & szName, const QString & szVisibleName, KviModuleExtensionAllocRoutine r, const QPixmap & icon); 119 void unregisterExtensionsByModule(KviModule * m); 120 121 public: 122 KviModuleExtensionDescriptor * findExtensionDescriptor(const KviCString & szType, const KviCString & szName); instance()123 static KviModuleExtensionManager * instance() { return g_pModuleExtensionManager; }; 124 KviModuleExtensionDescriptorList * getExtensionList(const KviCString & szType); 125 KviModuleExtension * allocateExtension(const KviCString & szType, const KviCString & szName, KviWindow * pWnd = nullptr, KviPointerHashTable<QString, QVariant> * pParams = nullptr, void * pSpecial = nullptr, const QString & preloadModule = QString()); 126 KviModuleExtension * allocateExtension(const KviCString & szType, int id, KviWindow * pWnd = nullptr, KviPointerHashTable<QString, QVariant> * pParams = nullptr, void * pSpecial = nullptr, const QString & preloadModule = QString()); 127 128 private: 129 KviModuleExtensionDescriptorList * allocateExtensionGetDescriptorList(const KviCString & szType, const QString & preloadModule); 130 }; 131 132 class KVIRC_API KviModuleExtension : public KviHeapObject 133 { 134 public: 135 KviModuleExtension(KviModuleExtensionDescriptor * d); 136 virtual ~KviModuleExtension(); 137 138 private: 139 KviModuleExtensionDescriptor * m_pDescriptor; 140 141 public: manager()142 static KviModuleExtensionManager * manager() { return g_pModuleExtensionManager; }; descriptor()143 KviModuleExtensionDescriptor * descriptor() { return m_pDescriptor; }; 144 // A module extension MUST implement die() as "delete this" <-- FIXME: this should be no longer necessary with KviHeapObject 145 virtual void die() = 0; 146 }; 147 148 #endif //_KVI_MODULEEXTENSION_H_ 149