~ubuntu-branches/ubuntu/trusty/kvirc/trusty-proposed

« back to all changes in this revision

Viewing changes to src/kvirc/kvs/KviKvsRunTimeContext.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=============================================================================
 
2
//
 
3
//   File : KviKvsRunTimeContext.cpp
 
4
//   Creation date : Tue 07 Oct 2003 01:49:40 by Szymon Stefanek
 
5
//
 
6
//   This file is part of the KVIrc IRC client distribution
 
7
//   Copyright (C) 2003-2010 Szymon Stefanek <pragma at kvirc dot net>
 
8
//
 
9
//   This program is FREE software. You can redistribute it and/or
 
10
//   modify it under the terms of the GNU General Public License
 
11
//   as published by the Free Software Foundation; either version 2
 
12
//   of the License, or (at your opinion) any later version.
 
13
//
 
14
//   This program is distributed in the HOPE that it will be USEFUL,
 
15
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
17
//   See the GNU General Public License for more details.
 
18
//
 
19
//   You should have received a copy of the GNU General Public License
 
20
//   along with this program. If not, write to the Free Software Foundation,
 
21
//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
22
//
 
23
//=============================================================================
 
24
 
 
25
#include "KviKvsRunTimeContext.h"
 
26
#include "KviKvsScript.h"
 
27
#include "KviKvsKernel.h"
 
28
#include "KviKvsReport.h"
 
29
#include "KviConsoleWindow.h"
 
30
#include "KviKvsTreeNodeBase.h"
 
31
#include "KviLocale.h"
 
32
#include "KviApplication.h"
 
33
#include "KviKvsObject.h"
 
34
 
 
35
KviKvsExtendedRunTimeData::~KviKvsExtendedRunTimeData()
 
36
{
 
37
        if(m_bAutoDelete)
 
38
        {
 
39
                if(m_pExtendedScopeVariables) delete m_pExtendedScopeVariables;
 
40
                if(m_pAliasSwitchList) delete m_pAliasSwitchList;
 
41
                if(m_pThisObject) delete m_pThisObject;
 
42
                if(m_pScriptFilePath) delete m_pScriptFilePath;
 
43
                // don't delete m_pPopupId;
 
44
        }
 
45
}
 
46
 
 
47
void KviKvsExtendedRunTimeData::setPopupId(QString * pPopupId)
 
48
{
 
49
/*      if(m_pPopupId)
 
50
                delete m_pPopupId;*/
 
51
        m_pPopupId=pPopupId;
 
52
};
 
53
 
 
54
KviKvsRunTimeContext::KviKvsRunTimeContext(KviKvsScript * pScript,KviWindow * pWnd,KviKvsVariantList * pParams,KviKvsVariant * pRetVal,KviKvsExtendedRunTimeData * pExtData)
 
55
{
 
56
        m_bError = false;
 
57
        m_pScript = pScript;
 
58
        m_pParameterList = pParams;
 
59
        m_pWindow = pWnd;
 
60
        m_pLocalVariables = new KviKvsHash();
 
61
        m_pReturnValue = pRetVal;
 
62
        m_uRunTimeFlags = 0;
 
63
        m_pExtendedData = pExtData;
 
64
        m_pDefaultReportLocation = 0;
 
65
}
 
66
 
 
67
KviKvsRunTimeContext::~KviKvsRunTimeContext()
 
68
{
 
69
        delete m_pLocalVariables;
 
70
}
 
71
 
 
72
KviKvsHash * KviKvsRunTimeContext::globalVariables()
 
73
{
 
74
        return KviKvsKernel::instance()->globalVariables();
 
75
}
 
76
 
 
77
void KviKvsRunTimeContext::enterBlockingSection()
 
78
{
 
79
        // actually a NO-OP
 
80
}
 
81
 
 
82
bool KviKvsRunTimeContext::leaveBlockingSection()
 
83
{
 
84
        if(g_pApp->kviClosingDown())return false;            // application quitting
 
85
        if(!g_pApp->windowExists(m_pWindow))return false; // window lost
 
86
        return true;
 
87
}
 
88
 
 
89
KviKvsVariant * KviKvsRunTimeContext::swapReturnValuePointer(KviKvsVariant * pNewPointer)
 
90
{
 
91
        KviKvsVariant * pAux = m_pReturnValue;
 
92
        m_pReturnValue = pNewPointer;
 
93
        return pAux;
 
94
}
 
95
 
 
96
void KviKvsRunTimeContext::report(bool bError,KviKvsTreeNode * pNode,const QString &szMsgFmt,kvi_va_list va)
 
97
{
 
98
        QString szMsg;
 
99
        KviQString::vsprintf(szMsg,szMsgFmt,va);
 
100
 
 
101
        KviPointerList<QString> * pCodeListing = 0;
 
102
        KviPointerList<QString> * pCallStack = 0;
 
103
        QString szLocation;
 
104
 
 
105
        if(pNode)
 
106
        {
 
107
                if(pNode->location() && m_pScript)
 
108
                {
 
109
                        pCodeListing = new KviPointerList<QString>;
 
110
                        pCodeListing->setAutoDelete(true);
 
111
 
 
112
                        int iLine,iCol;
 
113
 
 
114
                        KviKvsReport::findLineColAndListing(m_pScript->buffer(),pNode->location(),iLine,iCol,pCodeListing);
 
115
 
 
116
                        szLocation = QString(__tr2qs_ctx("line %1, near character %2","kvs")).arg(iLine).arg(iCol);
 
117
                }
 
118
 
 
119
                // create the call stack
 
120
                int iFrame = 0;
 
121
 
 
122
                pCallStack = new KviPointerList<QString>;
 
123
                pCallStack->setAutoDelete(true);
 
124
 
 
125
                while(pNode && (iFrame < 12))
 
126
                {
 
127
                        QString * pString = new QString();
 
128
                        QString szTmp;
 
129
                        pNode->contextDescription(szTmp);
 
130
                        *pString = QString("#%1 %2").arg(iFrame).arg(szTmp);
 
131
                        if(pNode->location())
 
132
                        {
 
133
                                int iLine,iCol;
 
134
                                KviKvsReport::findLineAndCol(m_pScript->buffer(),pNode->location(),iLine,iCol);
 
135
                                QString tmpi = QString(" [line %1, near character %2]").arg(iLine).arg(iCol);
 
136
                                *pString += tmpi;
 
137
                        }
 
138
                        pCallStack->append(pString);
 
139
                        iFrame++;
 
140
                        pNode = pNode->parent();
 
141
                }
 
142
                if(pNode)
 
143
                        pCallStack->append(new QString("#12 ..."));
 
144
        }
 
145
 
 
146
        QString szContext = m_pScript ? m_pScript->name() : "kvirc core code";
 
147
        KviKvsReport rep(bError ? KviKvsReport::RunTimeError : KviKvsReport::RunTimeWarning,szContext,szMsg,szLocation,m_pWindow);
 
148
        if(pCodeListing)
 
149
                rep.setCodeListing(pCodeListing);
 
150
        if(pCallStack)
 
151
                rep.setCallStack(pCallStack);
 
152
 
 
153
        KviKvsReport::report(&rep,m_pWindow);
 
154
}
 
155
 
 
156
void KviKvsRunTimeContext::error(KviKvsTreeNode * pNode,const QString &szMsgFmt,...)
 
157
{
 
158
        m_bError = true;
 
159
 
 
160
        kvi_va_list va;
 
161
        kvi_va_start_by_reference(va,szMsgFmt);
 
162
        report(true,pNode,szMsgFmt,va);
 
163
        kvi_va_end(va);
 
164
}
 
165
 
 
166
void KviKvsRunTimeContext::warning(KviKvsTreeNode * pNode,const QString &szMsgFmt,...)
 
167
{
 
168
        kvi_va_list va;
 
169
        kvi_va_start_by_reference(va,szMsgFmt);
 
170
        report(false,pNode,szMsgFmt,va);
 
171
        kvi_va_end(va);
 
172
}
 
173
 
 
174
void KviKvsRunTimeContext::error(const QString &szMsgFmt,...)
 
175
{
 
176
        m_bError = true;
 
177
 
 
178
        kvi_va_list va;
 
179
        kvi_va_start_by_reference(va,szMsgFmt);
 
180
        report(true,m_pDefaultReportLocation,szMsgFmt,va);
 
181
        kvi_va_end(va);
 
182
}
 
183
 
 
184
void KviKvsRunTimeContext::warning(const QString &szMsgFmt,...)
 
185
{
 
186
        kvi_va_list va;
 
187
        kvi_va_start_by_reference(va,szMsgFmt);
 
188
        report(false,m_pDefaultReportLocation,szMsgFmt,va);
 
189
        kvi_va_end(va);
 
190
}
 
191
 
 
192
bool KviKvsRunTimeContext::errorNoIrcContext()
 
193
{
 
194
        error(m_pDefaultReportLocation,__tr2qs_ctx("This command can be used only in windows bound to an IRC context","kvs"));
 
195
        return false;
 
196
}
 
197
 
 
198
bool KviKvsRunTimeContext::warningNoIrcConnection()
 
199
{
 
200
        warning(m_pDefaultReportLocation,__tr2qs_ctx("You're not connected to an IRC server","kvs"));
 
201
        return true;
 
202
}
 
203
 
 
204
bool KviKvsRunTimeContext::warningMissingParameter()
 
205
{
 
206
        warning(m_pDefaultReportLocation,__tr2qs_ctx("Missing parameter","kvs"));
 
207
        return true;
 
208
}
 
209
 
 
210
void KviKvsRunTimeContext::setDefaultReportLocation(KviKvsTreeNode * pNode)
 
211
{
 
212
        m_pDefaultReportLocation = pNode;
 
213
}