1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
//=============================================================================
//
// File : kvi_kvs_callbackobject.cpp
// Created on Mon 21 Nov 2005 01:46:51 by Szymon Stefanek
//
// This file is part of the KVIrc IRC Client distribution
// Copyright (C) 2005 Szymon Stefanek <pragma at kvirc dot net>
//
// This program is FREE software. You can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your opinion) any later version.
//
// This program is distributed in the HOPE that it will be USEFUL,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, write to the Free Software Foundation,
// Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================
#define __KVIRC__
#include "kvi_kvs_callbackobject.h"
#include "kvi_console.h"
#include "kvi_app.h"
KviKvsCallbackObject::KviKvsCallbackObject(const TQString &szCallbackName,KviWindow * pTargetWindow,const TQString &szCallbackCode,KviKvsVariantList * pMagicParams,unsigned int uFlags)
: KviHeapObject()
{
m_uFlags = uFlags;
m_pTargetWindow = pTargetWindow;
if(pTargetWindow)
m_pTargetConsole = pTargetWindow->console();
else
m_pTargetConsole = 0;
m_pMagicParams = new KviKvsVariantList();
if(pMagicParams)
for(KviKvsVariant * v = pMagicParams->first();v;v = pMagicParams->next())
m_pMagicParams->append(new KviKvsVariant(*v));
TQString szName;
szName = szCallbackName;
szName += "::";
szName += "callback";
m_pScript = new KviKvsScript(szName,szCallbackCode);
}
KviKvsCallbackObject::~KviKvsCallbackObject()
{
delete m_pScript;
delete m_pMagicParams;
}
KviKvsCallbackObject::CallbackStatus KviKvsCallbackObject::execute(KviKvsVariantList * pParams,KviKvsVariant * pRetVal)
{
// first of all check the window
if(!m_pTargetWindow)
m_pTargetWindow = g_pApp->activeConsole();
if(!g_pApp->windowExists(m_pTargetWindow))
{
// target window dead
if(m_uFlags & OnlyIfWindowExists)
return TargetWindowDead;
// rebind
m_pTargetWindow = m_pTargetConsole;
if(!m_pTargetWindow)
{
m_pTargetWindow = g_pApp->activeConsole();
if(!m_pTargetWindow)
return Error; // ooops...
} else {
if(!g_pApp->windowExists(m_pTargetWindow))
{
m_pTargetWindow = g_pApp->activeConsole();
if(!m_pTargetWindow)
return Error; // ooops...
}
}
}
// ok, got the window
// now take care of the params
KviKvsVariantList params;
params.setAutoDelete(false);
KviKvsVariant * v;
if(pParams)
for(v = pParams->first();v;v = pParams->next())
params.append(v);
for(v = m_pMagicParams->first();v;v = m_pMagicParams->next())
params.append(v);
unsigned int uRet = m_pScript->run(m_pTargetWindow,¶ms,pRetVal,KviKvsScript::PreserveParams);
if(uRet)
{
if(uRet & KviKvsScript::HaltEncountered)
return HaltEncountered;
return Success;
}
// ooops... error
return Error;
}
|