KVIrc  4.9.2
DeveloperAPIs
KviModuleExtension.h
Go to the documentation of this file.
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 <QPixmap>
34 #include <QVariant>
35 
36 class KviWindow;
37 class KviModule;
38 class KviModuleExtension;
40 
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
48 
49 typedef KviModuleExtension * (*KviModuleExtensionAllocRoutine)(KviModuleExtensionAllocStruct *);
50 
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
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!)
72 
73  KviModule * m_pModule; // module pointer
74 public:
75  // pParams ownership is NOT taken
76  KviModuleExtension * allocate(KviWindow * pWnd = 0, KviPointerHashTable<QString, QVariant> * pParams = 0, void * pSpecial = 0);
77 
78  int id() { return m_iId; };
79  KviModule * module() { return m_pModule; };
80  const KviCString & type() { return m_szType; };
81  const KviCString & name() { return m_szName; };
82  const QString & visibleName() { return m_szVisibleName; };
83  const KviCString & author() { return m_szAuthor; };
84  const KviCString & description() { return m_szDescription; };
85  const QPixmap * icon() { return m_pIcon; };
86  int flags() { return m_iFlags; };
87 
88  void setAuthor(const KviCString & szAuthor) { m_szAuthor = szAuthor; };
89  void setDescription(const KviCString & szDescription) { m_szDescription = szDescription; };
90  void setVisibleName(const KviCString & szVisibleName) { m_szVisibleName = szVisibleName; };
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 
100 
102 
104 
106 {
107  friend class KviModule;
108  friend class KviApplication;
109 
110 protected:
111  KviModuleExtensionManager(); // KviApplication calls this
112  ~KviModuleExtensionManager(); // and this
113 protected:
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);
124  KviModuleExtensionDescriptorList * getExtensionList(const KviCString & szType);
125  KviModuleExtension * allocateExtension(const KviCString & szType, const KviCString & szName, KviWindow * pWnd = 0, KviPointerHashTable<QString, QVariant> * pParams = 0, void * pSpecial = 0, const QString & preloadModule = QString());
126  KviModuleExtension * allocateExtension(const KviCString & szType, int id, KviWindow * pWnd = 0, KviPointerHashTable<QString, QVariant> * pParams = 0, void * pSpecial = 0, const QString & preloadModule = QString());
127 
128 private:
129  KviModuleExtensionDescriptorList * allocateExtensionGetDescriptorList(const KviCString & szType, const QString & preloadModule);
130 };
131 
133 {
134 public:
136  virtual ~KviModuleExtension();
137 
138 private:
140 
141 public:
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_
int flags()
Definition: KviModuleExtension.h:86
Definition: KviHeapObject.h:124
Definition: KviCString.h:105
KviModuleExtensionAllocRoutine m_allocRoutine
Definition: KviModuleExtension.h:70
const KviCString & name()
Definition: KviModuleExtension.h:81
#define KVIRC_API
Definition: kvi_settings.h:128
struct _KviModuleExtensionAllocStructTag KviModuleExtensionAllocStruct
void setAuthor(const KviCString &szAuthor)
Definition: KviModuleExtension.h:88
m_iId
Definition: KvsObject_buttonGroup.cpp:62
#define m
Definition: detector.cpp:77
const KviCString & author()
Definition: KviModuleExtension.h:83
int id()
Definition: KviModuleExtension.h:78
KviCString m_szType
Definition: KviModuleExtension.h:63
KVIRC_API KviModuleExtensionManager * g_pModuleExtensionManager
Definition: KviModuleExtension.cpp:33
Definition: KviModuleExtension.h:105
Definition: KviModuleExtension.h:41
QString m_szVisibleName
Definition: KviModuleExtension.h:65
KviModuleExtension *(* KviModuleExtensionAllocRoutine)(KviModuleExtensionAllocStruct *)
Definition: KviModuleExtension.h:49
void setDescription(const KviCString &szDescription)
Definition: KviModuleExtension.h:89
KviModule * m_pModule
Definition: KviModuleExtension.h:73
#define e
Definition: detector.cpp:69
static KviModuleExtensionManager * instance()
Definition: KviModuleExtension.h:123
const KviCString & description()
Definition: KviModuleExtension.h:84
Pointer Hash Table.
char s d
Definition: KviIrcNumericCodes.h:391
KviPointerList< KviModuleExtensionDescriptor > KviModuleExtensionDescriptorList
Definition: KviModuleExtension.h:99
KviPointerHashTable< const char *, KviModuleExtensionDescriptorList > * m_pExtensionDict
Definition: KviModuleExtension.h:114
const KviCString & type()
Definition: KviModuleExtension.h:80
KviPointerHashTable< QString, QVariant > * pParams
Definition: KviModuleExtension.h:45
KviPointerList< KviModuleExtension > * m_pObjectList
Definition: KviModuleExtension.h:71
KviCString m_szAuthor
Definition: KviModuleExtension.h:66
void setFlags(int iFlags)
Definition: KviModuleExtension.h:91
const QString & visibleName()
Definition: KviModuleExtension.h:82
KviModuleExtensionDescriptor * pDescriptor
Definition: KviModuleExtension.h:43
#define r
Definition: detector.cpp:82
Definition: KviModuleExtension.h:132
C++ Template based double linked pointer list class.
Base class for all windows in KVIrc.
Definition: KviWindow.h:74
void * allocate(int size)
COMPILE_MEMORY_PROFILE.
Definition: KviMemory.h:113
Definition: KviModuleExtension.h:51
Definition: KviApplication.h:102
Definition: KviModule.h:131
Heap Object.
QPixmap * m_pIcon
Definition: KviModuleExtension.h:69
int m_iFlags
Definition: KviModuleExtension.h:68
static KviModuleExtensionManager * manager()
Definition: KviModuleExtension.h:142
KviWindow * pWindow
Definition: KviModuleExtension.h:44
KviModule * module()
Definition: KviModuleExtension.h:79
void * pSpecial
Definition: KviModuleExtension.h:46
KviModuleExtensionDescriptor * descriptor()
Definition: KviModuleExtension.h:143
This file contains compile time settings.
KviCString m_szName
Definition: KviModuleExtension.h:64
KviModuleExtensionDescriptor * m_pDescriptor
Definition: KviModuleExtension.h:139
KviCString m_szDescription
Definition: KviModuleExtension.h:67
const QPixmap * icon()
Definition: KviModuleExtension.h:85
void setVisibleName(const KviCString &szVisibleName)
Definition: KviModuleExtension.h:90
int m_iId
Definition: KviModuleExtension.h:62