KVIrc 5.2.6
Developer APIs
KviKvsObject.h
Go to the documentation of this file.
1#ifndef _KVI_KVS_OBJECT_H_
2#define _KVI_KVS_OBJECT_H_
3//=============================================================================
4//
5// File : KviKvsObject.h
6// Creation date : Wed 08 Oct 2003 02:31:57 by Szymon Stefanek
7//
8// This file is part of the KVIrc IRC client distribution
9// Copyright (C) 2003-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 "KviQString.h"
29#include "KviPointerList.h"
30#include "KviKvsRunTimeCall.h"
33#include "KviKvsTypes.h"
34
35#include <QObject>
36
38
40{
41 KviKvsObject * pSourceObject = nullptr; // source object (owner of the struct)
42 KviKvsObject * pTargetObject = nullptr; // target object
43 QString szSignal; // source signal name
44 QString szSlot; // target slot function
45};
46
49
50class KVIRC_API KviKvsObject : public QObject
51{
53 friend class KviKvsObjectClass;
54 Q_OBJECT
55public:
56 KviKvsObject(KviKvsObjectClass * pClass, KviKvsObject * pParent, const QString & szName);
58
59protected:
60 // main data
61 QString m_szName; // object name
62 kvs_hobject_t m_hObject; // global object handle
63 KviKvsObjectClass * m_pClass = nullptr; // the class definition
64
65 KviKvsHash * m_pDataContainer = nullptr; // member variables
66
67 KviPointerList<KviKvsObject> * m_pChildList = nullptr;
68
69 KviPointerHashTable<QString, KviKvsObjectFunctionHandler> * m_pFunctionHandlers = nullptr; // our function handlers
70
71 KviPointerHashTable<QString, KviKvsObjectConnectionList> * m_pSignalDict = nullptr; // our signals connected to other object functions
72
73 KviKvsObjectConnectionList * m_pConnectionList = nullptr; // signals connected to this object functions
74
75 // this is valid when processing one of our slots
78
79 // if this object wraps a qt one, it is here
80 QObject * m_pObject = nullptr;
81 bool m_bObjectOwner = true; // do we have to destroy it ?
82
83 // We're going to die soon after the control is given back to the event loop
84 bool m_bInDelayedDeath = false;
85 // We're going to die BEFORE the control is given back to the event loop
86 bool m_bAboutToDie = false;
87 // Did we already call the destructor ?
88 bool m_bDestructorCalled = false;
89
90public:
91 kvs_hobject_t handle() { return m_hObject; }
92
93 // the wrapped Qt object (may be 0!)
94 QObject * object() const { return m_pObject; }
95 void setObject(QObject * o, bool bIsOwned = true);
96
97 const QString & getName() const { return m_szName; }
98
99 KviKvsObject * parentObject() { return (KviKvsObject *)parent(); }
100 QWidget * parentScriptWidget();
101
102 bool connectSignal(const QString & sigName, KviKvsObject * target, const QString & slotName);
103 bool disconnectSignal(const QString & sigName, KviKvsObjectConnection * con);
104 bool disconnectSignal(const QString & sigName, KviKvsObject * target, const QString & slotName);
105
106 // Emits a signal by calling all the attacched slots in an unspecified order.
107 // Returns the number of slots called (may be 0, if no slot is connected)
108 // The parameters are preserved.
109 // this is intended to be called from other function calls (the parameters are copied from pOuterCall)
110 // since we should NEVER emit totally spontaneous signals: all of them
111 // should be generated inside object functions (either from scripting or by core calls)
112 int emitSignal(const QString & sigName, KviKvsObjectFunctionCall * pOuterCall, KviKvsVariantList * pParams = nullptr);
113
114 void setSignalSender(kvs_hobject_t hObject) { m_hSignalSender = hObject; }
115 kvs_hobject_t signalSender() { return m_hSignalSender; }
116 void setSignalName(const QString & szSigName) { m_szSignalName = szSigName; }
117
119
120 KviKvsHash * dataContainer() { return m_pDataContainer; }
121
122 bool die();
123 bool dieNow();
124
125 KviKvsObjectClass * getExactClass() { return m_pClass; }
126 KviKvsObjectClass * getClass(const QString & classOverride = QString());
127 bool inheritsClass(KviKvsObjectClass * pClass);
128 bool inheritsClass(const QString & szClass);
129
130 KviKvsObjectFunctionHandler * lookupFunctionHandler(const QString & funcName, const QString & classOverride = QString());
131
132 // Registers a private implementation of a function
133 // The function may or may not be already registered in the class
134 // If szCode is empty the the private implementation is removed instead
135 void registerPrivateImplementation(const QString & szFunctionName, const QString & szCode);
136
137 // ONLY pCaller can be zero here!
138 // please use one of the wrappers, if possible
139 bool callFunction(
140 KviKvsObject * pCaller, // calling object, can be zero (used for the "internal" access list verification)
141 const QString & fncName, // name of the function to call
142 const QString & classOverride, // eventual class override for the function call, may be QString()
143 KviKvsRunTimeContext * pContext, // calling runtime context (you'll have problems with instantiating this... :P )
144 KviKvsVariant * pRetVal, // the return value
145 KviKvsVariantList * pParams); // the parameters for the call
146 // a nice and simple wrapper: it accepts a parameter list only (eventually 0)
147 bool callFunction(KviKvsObject * pCaller, const QString & fncName, KviKvsVariantList * pParams = nullptr);
148 // this one gets a non null ret val too
149 bool callFunction(KviKvsObject * pCaller, const QString & fncName, KviKvsVariant * pRetVal, KviKvsVariantList * pParams = nullptr);
150
151 KviKvsObject * findChild(const QString & szClass, const QString & szName);
152 void killAllChildrenWithClass(KviKvsObjectClass * cl);
153
154protected:
155 void registerConnection(KviKvsObjectConnection * con);
156 bool unregisterConnection(KviKvsObjectConnection * con);
157
158 virtual bool init(KviKvsRunTimeContext * pContext, KviKvsVariantList * pParams);
159
160 void registerChild(KviKvsObject * c);
161 void unregisterChild(KviKvsObject * c);
162
163 bool eventFilter(QObject * o, QEvent * e) override; //necessary ?
164 void timerEvent(QTimerEvent * e) override;
165
166protected:
167 bool function_name(KviKvsObjectFunctionCall * c);
168 bool function_startTimer(KviKvsObjectFunctionCall * c);
169 bool function_killTimer(KviKvsObjectFunctionCall * c);
170 bool function_className(KviKvsObjectFunctionCall * c);
171 bool function_findChild(KviKvsObjectFunctionCall * c);
172 bool function_childCount(KviKvsObjectFunctionCall * c);
173 bool function_emit(KviKvsObjectFunctionCall * c);
174 bool function_children(KviKvsObjectFunctionCall * c);
175 bool function_signalSender(KviKvsObjectFunctionCall * c);
176 bool function_signalName(KviKvsObjectFunctionCall * c);
177 bool function_destructor(KviKvsObjectFunctionCall * c);
178 bool function_parent(KviKvsObjectFunctionCall * c);
179 bool function_property(KviKvsObjectFunctionCall * c);
180 bool function_setProperty(KviKvsObjectFunctionCall * c);
181 bool function_listProperties(KviKvsObjectFunctionCall * c);
182protected slots:
183 void delayedDie();
184 void objectDestroyed();
185
186private:
187 void callDestructor();
188};
189
190#define KVSO_PARAMETER(a, b, c, d) KVS_PARAMETER(a, b, c, d)
191
192#define KVSO_PARAMETERS_BEGIN(pCall) \
193 KVS_PARAMETERS_BEGIN(parameter_format_list)
194
195#define KVSO_PARAMETERS_END(pCall) \
196 KVS_PARAMETERS_END \
197 if(!KviKvsParameterProcessor::process(pCall->params(), pCall->context(), parameter_format_list)) \
198 return false;
199
200#endif
KviPointerList< KviKvsObjectConnection > KviKvsObjectConnectionList
Definition KviKvsObject.h:47
KviPointerListIterator< KviKvsObjectConnection > KviKvsObjectConnectionListIterator
Definition KviKvsObject.h:48
void * kvs_hobject_t
Definition KviKvsTypes.h:32
C++ Template based double linked pointer list class.
Helper functions for the QString class.
This class defines a new data type which contains hash data.
Definition KviKvsHash.h:48
Definition KviKvsObjectClass.h:50
Definition KviKvsObjectController.h:38
Definition KviKvsObjectFunctionCall.h:34
Definition KviKvsObjectFunctionHandler.h:35
Definition KviKvsObject.h:51
KviPointerHashTable< QString, KviKvsObjectFunctionHandler > * functionHandlers()
Definition KviKvsObject.h:118
KviKvsHash * dataContainer()
Definition KviKvsObject.h:120
kvs_hobject_t signalSender()
Definition KviKvsObject.h:115
const QString & getName() const
Definition KviKvsObject.h:97
kvs_hobject_t m_hObject
Definition KviKvsObject.h:62
kvs_hobject_t handle()
Definition KviKvsObject.h:91
QString m_szName
Definition KviKvsObject.h:61
KviKvsObject * parentObject()
Definition KviKvsObject.h:99
void setSignalSender(kvs_hobject_t hObject)
Definition KviKvsObject.h:114
KviKvsObjectClass * getExactClass()
Definition KviKvsObject.h:125
kvs_hobject_t m_hSignalSender
Definition KviKvsObject.h:76
QObject * object() const
Definition KviKvsObject.h:94
QString m_szSignalName
Definition KviKvsObject.h:77
void setSignalName(const QString &szSigName)
Definition KviKvsObject.h:116
Definition KviKvsRunTimeContext.h:104
Class to handle variant variables lists.
Definition KviKvsVariantList.h:42
This class defines a new data type which contains variant data.
Definition KviKvsVariant.h:352
A fast pointer hash table implementation.
Definition KviPointerHashTable.h:450
A fast KviPointerList iterator.
Definition KviPointerList.h:142
A template double linked list of pointers.
Definition KviPointerList.h:371
#define e
Definition detector.cpp:70
#define o
Definition detector.cpp:80
This file contains compile time settings.
#define KVIRC_API
Definition kvi_settings.h:127
Definition KviKvsObject.h:40
QString szSlot
Definition KviKvsObject.h:44
KviKvsObject * pTargetObject
Definition KviKvsObject.h:42
QString szSignal
Definition KviKvsObject.h:43
KviKvsObject * pSourceObject
Definition KviKvsObject.h:41
int init()
Definition winamp.cpp:118