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

« back to all changes in this revision

Viewing changes to src/kvirc/kvs/kvi_kvs_runtimecontext.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 : kvi_kvs_runtimecontext.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-2008 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 "kvi_kvs_runtimecontext.h"
26
 
#include "kvi_kvs_script.h"
27
 
#include "kvi_kvs_kernel.h"
28
 
#include "kvi_kvs_report.h"
29
 
#include "kvi_console.h"
30
 
#include "kvi_kvs_treenode_base.h"
31
 
#include "kvi_locale.h"
32
 
#include "kvi_app.h"
33
 
#include "kvi_kvs_object.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
 
        }
44
 
}
45
 
 
46
 
KviKvsRunTimeContext::KviKvsRunTimeContext(KviKvsScript * pScript,KviWindow * pWnd,KviKvsVariantList * pParams,KviKvsVariant * pRetVal,KviKvsExtendedRunTimeData * pExtData)
47
 
{
48
 
        m_bError = false;
49
 
        m_pScript = pScript;
50
 
        m_pParameterList = pParams;
51
 
        m_pWindow = pWnd;
52
 
        m_pLocalVariables = new KviKvsHash();
53
 
        m_pReturnValue = pRetVal;
54
 
        m_uRunTimeFlags = 0;
55
 
        m_pExtendedData = pExtData;
56
 
        m_pDefaultReportLocation = 0;
57
 
}
58
 
 
59
 
KviKvsRunTimeContext::~KviKvsRunTimeContext()
60
 
{
61
 
        delete m_pLocalVariables;
62
 
}
63
 
 
64
 
KviKvsHash * KviKvsRunTimeContext::globalVariables()
65
 
{
66
 
        return KviKvsKernel::instance()->globalVariables();
67
 
}
68
 
 
69
 
void KviKvsRunTimeContext::enterBlockingSection()
70
 
{
71
 
        // actually a NO-OP
72
 
}
73
 
 
74
 
bool KviKvsRunTimeContext::leaveBlockingSection()
75
 
{
76
 
        if(g_pApp->closingDown())return false;            // application quitting
77
 
        if(!g_pApp->windowExists(m_pWindow))return false; // window lost
78
 
        return true;
79
 
}
80
 
 
81
 
KviKvsVariant * KviKvsRunTimeContext::swapReturnValuePointer(KviKvsVariant * pNewPointer)
82
 
{
83
 
        KviKvsVariant * pAux = m_pReturnValue;
84
 
        m_pReturnValue = pNewPointer;
85
 
        return pAux;
86
 
}
87
 
 
88
 
void KviKvsRunTimeContext::report(bool bError,KviKvsTreeNode * pNode,const QString &szMsgFmt,kvi_va_list va)
89
 
{
90
 
        QString szMsg;
91
 
        KviQString::vsprintf(szMsg,szMsgFmt,va);
92
 
 
93
 
        KviPointerList<QString> * pCodeListing = 0;
94
 
        KviPointerList<QString> * pCallStack = 0;
95
 
        QString szLocation;
96
 
 
97
 
        if(pNode)
98
 
        {
99
 
                if(pNode->location() && m_pScript)
100
 
                {
101
 
                        pCodeListing = new KviPointerList<QString>;
102
 
                        pCodeListing->setAutoDelete(true);
103
 
 
104
 
                        int iLine,iCol;
105
 
 
106
 
                        KviKvsReport::findLineColAndListing(m_pScript->buffer(),pNode->location(),iLine,iCol,pCodeListing);
107
 
 
108
 
                        KviQString::sprintf(szLocation,__tr2qs_ctx("line %d, near character %d","kvs"),iLine,iCol);
109
 
                }
110
 
 
111
 
                // create the call stack
112
 
                int iFrame = 0;
113
 
 
114
 
                pCallStack = new KviPointerList<QString>;
115
 
                pCallStack->setAutoDelete(true);
116
 
 
117
 
                while(pNode && (iFrame < 12))
118
 
                {
119
 
                        QString * pString = new QString();
120
 
                        QString szTmp;
121
 
                        pNode->contextDescription(szTmp);
122
 
                        KviQString::sprintf(*pString,"#%d %Q",iFrame,&szTmp);
123
 
                        if(pNode->location())
124
 
                        {
125
 
                                int iLine,iCol;
126
 
                                KviKvsReport::findLineAndCol(m_pScript->buffer(),pNode->location(),iLine,iCol);
127
 
                                QString tmpi;
128
 
                                KviQString::sprintf(tmpi," [line %d, near character %d]",iLine,iCol);
129
 
                                *pString += tmpi;
130
 
                        }
131
 
                        pCallStack->append(pString);
132
 
                        iFrame++;
133
 
                        pNode = pNode->parent();
134
 
                }
135
 
                if(pNode)
136
 
                        pCallStack->append(new QString("#12 ..."));
137
 
        }
138
 
 
139
 
        QString szContext = m_pScript ? m_pScript->name() : "kvirc core code";
140
 
        KviKvsReport rep(bError ? KviKvsReport::RunTimeError : KviKvsReport::RunTimeWarning,szContext,szMsg,szLocation,m_pWindow);
141
 
        if(pCodeListing)rep.setCodeListing(pCodeListing);
142
 
        if(pCallStack)rep.setCallStack(pCallStack);
143
 
 
144
 
        KviKvsReport::report(&rep,m_pWindow);
145
 
}
146
 
 
147
 
void KviKvsRunTimeContext::error(KviKvsTreeNode * pNode,const QString &szMsgFmt,...)
148
 
{
149
 
        m_bError = true;
150
 
 
151
 
        kvi_va_list va;
152
 
        kvi_va_start_by_reference(va,szMsgFmt);
153
 
        report(true,pNode,szMsgFmt,va);
154
 
        kvi_va_end(va);
155
 
}
156
 
 
157
 
void KviKvsRunTimeContext::warning(KviKvsTreeNode * pNode,const QString &szMsgFmt,...)
158
 
{
159
 
        kvi_va_list va;
160
 
        kvi_va_start_by_reference(va,szMsgFmt);
161
 
        report(false,pNode,szMsgFmt,va);
162
 
        kvi_va_end(va);
163
 
}
164
 
 
165
 
void KviKvsRunTimeContext::error(const QString &szMsgFmt,...)
166
 
{
167
 
        m_bError = true;
168
 
 
169
 
        kvi_va_list va;
170
 
        kvi_va_start_by_reference(va,szMsgFmt);
171
 
        report(true,m_pDefaultReportLocation,szMsgFmt,va);
172
 
        kvi_va_end(va);
173
 
}
174
 
 
175
 
void KviKvsRunTimeContext::warning(const QString &szMsgFmt,...)
176
 
{
177
 
        kvi_va_list va;
178
 
        kvi_va_start_by_reference(va,szMsgFmt);
179
 
        report(false,m_pDefaultReportLocation,szMsgFmt,va);
180
 
        kvi_va_end(va);
181
 
}
182
 
 
183
 
bool KviKvsRunTimeContext::errorNoIrcContext()
184
 
{
185
 
        error(m_pDefaultReportLocation,__tr2qs_ctx("This command can be used only in windows bound to an IRC context","kvs"));
186
 
        return false;
187
 
}
188
 
 
189
 
bool KviKvsRunTimeContext::warningNoIrcConnection()
190
 
{
191
 
        warning(m_pDefaultReportLocation,__tr2qs_ctx("You're not connected to an IRC server","kvs"));
192
 
        return true;
193
 
}
194
 
 
195
 
bool KviKvsRunTimeContext::warningMissingParameter()
196
 
{
197
 
        warning(m_pDefaultReportLocation,__tr2qs_ctx("Missing parameter","kvs"));
198
 
        return true;
199
 
}
200
 
 
201
 
void KviKvsRunTimeContext::setDefaultReportLocation(KviKvsTreeNode * pNode)
202
 
{
203
 
        m_pDefaultReportLocation = pNode;
204
 
}