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

« back to all changes in this revision

Viewing changes to src/kvirc/kvs/KviKvsUserAction.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 : KviKvsUserAction.cpp
 
4
//   Creation date : Tue 07 Dec 2004 02:00:24 by Szymon Stefanek
 
5
//
 
6
//   This file is part of the KVIrc IRC client distribution
 
7
//   Copyright (C) 2004-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 "KviKvsUserAction.h"
 
26
#include "KviKvsScript.h"
 
27
#include "KviConfigurationFile.h"
 
28
#include "KviIconManager.h"
 
29
#include "KviActionManager.h"
 
30
#include "KviKvsScript.h"
 
31
#include "KviWindow.h"
 
32
#include "KviCommandFormatter.h"
 
33
 
 
34
KviKvsUserAction::KviKvsUserAction(QObject * pParent,
 
35
        const QString &szName,
 
36
        const QString &szScriptCode,
 
37
        const QString &szVisibleNameCode,
 
38
        const QString &szDescriptionCode,
 
39
        const QString &szCategory,
 
40
        const QString &szBigIconId,
 
41
        const QString &szSmallIconId,
 
42
        unsigned int uFlags,
 
43
        const QString &szKeySequence
 
44
)
 
45
: KviKvsAction(
 
46
        pParent,
 
47
        szName,
 
48
        szScriptCode,
 
49
        szVisibleNameCode,
 
50
        szDescriptionCode,
 
51
        NULL,
 
52
        szBigIconId,
 
53
        szSmallIconId,
 
54
        uFlags,
 
55
        szKeySequence
 
56
)
 
57
{
 
58
        QString szKvsName = "action::";
 
59
        szKvsName += szName;
 
60
 
 
61
        QString szTmp = szKvsName;
 
62
        szTmp += "::description";
 
63
        m_pDescriptionScript = new KviKvsScript(szTmp,szDescriptionCode,KviKvsScript::Parameter);
 
64
 
 
65
        szTmp = szKvsName;
 
66
        szTmp += "::label";
 
67
        m_pVisibleNameScript = new KviKvsScript(szTmp,szVisibleNameCode,KviKvsScript::Parameter);
 
68
 
 
69
        m_szCategory = szCategory;
 
70
        m_pCategory = KviActionManager::instance()->category(szCategory);
 
71
}
 
72
 
 
73
 
 
74
KviKvsUserAction::KviKvsUserAction(QObject * pParent)
 
75
        : KviKvsAction(pParent,QString(),QString(),QString(),QString())
 
76
{
 
77
        // needs loading!
 
78
        m_pDescriptionScript = 0;
 
79
        m_pVisibleNameScript = 0;
 
80
}
 
81
 
 
82
KviKvsUserAction::~KviKvsUserAction()
 
83
{
 
84
        if(m_pDescriptionScript)
 
85
                delete m_pDescriptionScript;
 
86
        if(m_pVisibleNameScript)
 
87
                delete m_pVisibleNameScript;
 
88
}
 
89
 
 
90
KviKvsUserAction * KviKvsUserAction::createInstance(
 
91
                QObject * pParent,
 
92
                const QString & szName,
 
93
                const QString & szScriptCode,
 
94
                const QString & szVisibleNameCode,
 
95
                const QString & szDescriptionCode,
 
96
                const QString & szCategory,
 
97
                const QString & szBigIconId,
 
98
                const QString & szSmallIconId,
 
99
                unsigned int uFlags,
 
100
                const QString & szKeySequence
 
101
        )
 
102
{
 
103
        return new KviKvsUserAction(
 
104
                        pParent,
 
105
                        szName,
 
106
                        szScriptCode,
 
107
                        szVisibleNameCode,
 
108
                        szDescriptionCode,
 
109
                        szCategory,
 
110
                        szBigIconId,
 
111
                        szSmallIconId,
 
112
                        uFlags,
 
113
                        szKeySequence
 
114
                );
 
115
}
 
116
 
 
117
void KviKvsUserAction::exportToKvs(QString & szBuffer)
 
118
{
 
119
        exportToKvs(
 
120
                szBuffer,
 
121
                m_szName,
 
122
                scriptCode(),
 
123
                visibleNameCode(),
 
124
                descriptionCode(),
 
125
                m_szCategory,
 
126
                m_szBigIconId,
 
127
                m_szSmallIconId,
 
128
                m_uFlags,
 
129
                m_szKeySequence
 
130
        );
 
131
}
 
132
 
 
133
void KviKvsUserAction::exportToKvs(
 
134
        QString & szBuffer,
 
135
        const QString & szName,
 
136
        const QString & szScriptCode,
 
137
        const QString & szVisibleName,
 
138
        const QString & szDescription,
 
139
        const QString & szCategory,
 
140
        const QString & szBigIconId,
 
141
        const QString & szSmallIconId,
 
142
        unsigned int uFlags,
 
143
        const QString & szKeySequence
 
144
)
 
145
{
 
146
        szBuffer += "action.create";
 
147
        if(uFlags & NeedsContext)
 
148
        {
 
149
                szBuffer += " -i";
 
150
                if(uFlags & NeedsConnection)
 
151
                {
 
152
                        szBuffer += " -c";
 
153
                        if(uFlags & EnableAtLogin)
 
154
                                szBuffer += " -l";
 
155
                }
 
156
        }
 
157
        if(uFlags & InternalWindowMask)
 
158
        {
 
159
                QString szWins;
 
160
                if(uFlags & WindowConsole)
 
161
                        szWins += "x";
 
162
                if(uFlags & WindowChannel)
 
163
                        szWins += "c";
 
164
                if(uFlags & WindowQuery)
 
165
                        szWins += "q";
 
166
                if(uFlags & WindowDccChat)
 
167
                        szWins += "d";
 
168
                szBuffer += " -w=";
 
169
                szBuffer += szWins;
 
170
                if(uFlags & (WindowConsole | WindowChannel | WindowQuery))
 
171
                {
 
172
                        if(uFlags & WindowOnlyIfUsersSelected)
 
173
                                szBuffer += " -s";
 
174
                }
 
175
        }
 
176
 
 
177
        if(!szCategory.isEmpty())
 
178
        {
 
179
                szBuffer += " -t=";
 
180
                szBuffer += szCategory;
 
181
        }
 
182
 
 
183
        if(!szKeySequence.isEmpty())
 
184
        {
 
185
                szBuffer += " -k=\"";
 
186
                szBuffer += szKeySequence;
 
187
                szBuffer += "\"";
 
188
        }
 
189
 
 
190
        szBuffer += " (\"";
 
191
        szBuffer += szName;
 
192
        szBuffer += "\",";
 
193
        
 
194
        QString szTmp;
 
195
        if(szVisibleName.contains('$'))
 
196
        {
 
197
                szBuffer += szVisibleName;
 
198
                szBuffer += ",";
 
199
        } else {
 
200
                szTmp = szVisibleName.trimmed();
 
201
                if(szTmp.startsWith(QChar('\"')) && szTmp.endsWith(QChar('\"')))
 
202
                {
 
203
                        szBuffer += szTmp;
 
204
                        szBuffer += ",";
 
205
                } else {
 
206
                        szTmp.replace("\"","\\\"");
 
207
                        szBuffer += "\"";
 
208
                        szBuffer += szTmp;
 
209
                        szBuffer += "\",";
 
210
                }
 
211
        }
 
212
 
 
213
        if(szDescription.contains('$'))
 
214
        {
 
215
                szBuffer += szDescription;
 
216
                szBuffer += ",";
 
217
        } else {
 
218
                szTmp = szDescription.trimmed();
 
219
                if(szTmp.startsWith(QChar('\"')) && szTmp.endsWith(QChar('\"')))
 
220
                {
 
221
                        szBuffer += szTmp;
 
222
                        szBuffer += ",";
 
223
                } else {
 
224
                        szTmp.replace("\"","\\\"");
 
225
                        szBuffer += "\"";
 
226
                        szBuffer += szTmp;
 
227
                        szBuffer += "\",";
 
228
                }
 
229
        }
 
230
 
 
231
        if(szBigIconId.contains('$'))
 
232
        {
 
233
                szBuffer += szBigIconId;
 
234
                szBuffer += ",";
 
235
        } else {
 
236
                szTmp = szBigIconId.trimmed();
 
237
                if(szTmp.startsWith(QChar('\"')) && szTmp.endsWith(QChar('\"')))
 
238
                {
 
239
                        szBuffer += szTmp;
 
240
                        szBuffer += ",";
 
241
                } else {
 
242
                        szTmp.replace("\"","\\\"");
 
243
                        szBuffer += "\"";
 
244
                        szBuffer += szTmp;
 
245
                        szBuffer += "\",";
 
246
                }
 
247
        }
 
248
 
 
249
        if(szSmallIconId.contains('$'))
 
250
        {
 
251
                szBuffer += szSmallIconId;
 
252
                szBuffer += ")\n";
 
253
        } else {
 
254
                szTmp = szSmallIconId.trimmed();
 
255
                if(szTmp.startsWith(QChar('\"')) && szTmp.endsWith(QChar('\"')))
 
256
                {
 
257
                        szBuffer += szTmp;
 
258
                        szBuffer += ")\n";
 
259
                } else {
 
260
                        szTmp.replace("\"","\\\"");
 
261
                        szBuffer += "\"";
 
262
                        szBuffer += szTmp;
 
263
                        szBuffer += "\")\n";
 
264
                }
 
265
        }
 
266
 
 
267
        szTmp = szScriptCode;
 
268
        KviCommandFormatter::blockFromBuffer(szTmp);
 
269
        szBuffer += szTmp;
 
270
        szBuffer += "\n";
 
271
}
 
272
 
 
273
 
 
274
// FIXME: Cache this stuff ??
 
275
 
 
276
const QString & KviKvsUserAction::visibleName()
 
277
{
 
278
        if(!m_pVisibleNameScript)
 
279
                return m_szVisibleName;
 
280
        if(!m_pVisibleNameScript->run(g_pActiveWindow,0,m_szVisibleName))
 
281
                m_szVisibleName = m_pVisibleNameScript->code();
 
282
        return m_szVisibleName;
 
283
}
 
284
 
 
285
const QString & KviKvsUserAction::description()
 
286
{
 
287
        if(!m_pDescriptionScript)
 
288
                return m_szDescription;
 
289
        if(!m_pDescriptionScript->run(g_pActiveWindow,0,m_szDescription))
 
290
                m_szDescription = m_pDescriptionScript->code();
 
291
        return m_szDescription;
 
292
}
 
293
 
 
294
const QString & KviKvsUserAction::visibleNameCode()
 
295
{
 
296
        if(!m_pVisibleNameScript)
 
297
                return m_szVisibleName;
 
298
        return m_pVisibleNameScript->code();
 
299
}
 
300
 
 
301
const QString & KviKvsUserAction::descriptionCode()
 
302
{
 
303
        if(!m_pDescriptionScript)
 
304
                return m_szDescription;
 
305
        return m_pDescriptionScript->code();
 
306
}
 
307
 
 
308
bool KviKvsUserAction::isKviUserActionNeverOverrideThis()
 
309
{
 
310
        return true;
 
311
}
 
312
 
 
313
bool KviKvsUserAction::load(KviConfigurationFile * cfg)
 
314
{
 
315
        m_szName = cfg->group();
 
316
        if(m_szName.isEmpty())return false;
 
317
        m_szVisibleName = cfg->readEntry("VisibleName");
 
318
        if(m_szVisibleName.isEmpty())return false;
 
319
        QString szKvsName = "action::";
 
320
        szKvsName += m_szName;
 
321
        QString szTmp = szKvsName;
 
322
        szTmp += "::label";
 
323
 
 
324
        if(m_pVisibleNameScript)delete m_pVisibleNameScript;
 
325
        m_pVisibleNameScript = new KviKvsScript(szTmp,m_szVisibleName,KviKvsScript::Parameter);
 
326
 
 
327
        if(m_szVisibleName.isEmpty())return false;
 
328
        m_szDescription = cfg->readEntry("Description");
 
329
        szTmp = szKvsName;
 
330
        szTmp += "::description";
 
331
 
 
332
        if(m_pDescriptionScript)delete m_pDescriptionScript;
 
333
        m_pDescriptionScript = new KviKvsScript(szTmp,m_szDescription,KviKvsScript::Parameter);
 
334
 
 
335
 
 
336
        m_szBigIconId = cfg->readEntry("BigIcon");
 
337
        m_szSmallIconId = cfg->readEntry("SmallIcon");
 
338
        m_szKeySequence = cfg->readEntry("KeySequence");
 
339
        m_szCategory = cfg->readEntry("Category");
 
340
        m_pCategory = KviActionManager::instance()->category(m_szCategory);
 
341
        m_uFlags = cfg->readUIntEntry("Flags",0);
 
342
 
 
343
        QString szCode = cfg->readEntry("Code");
 
344
        if(szCode.isEmpty())return false;
 
345
 
 
346
        m_szScript = QString(szCode);
 
347
 
 
348
        return true;
 
349
}
 
350
 
 
351
void KviKvsUserAction::save(KviConfigurationFile * cfg)
 
352
{
 
353
        cfg->setGroup(m_szName);
 
354
        if(m_pVisibleNameScript)cfg->writeEntry("VisibleName",m_pVisibleNameScript->code());
 
355
        if(m_pDescriptionScript)
 
356
        {
 
357
                if(!m_pDescriptionScript->code().isEmpty())cfg->writeEntry("Description",m_pDescriptionScript->code());
 
358
        }
 
359
        if(!m_szBigIconId.isEmpty())cfg->writeEntry("BigIcon",m_szBigIconId);
 
360
        if(!m_szSmallIconId.isEmpty())cfg->writeEntry("SmallIcon",m_szSmallIconId);
 
361
        if(!m_szCategory.isEmpty())cfg->writeEntry("Category",m_szCategory);
 
362
        if(!m_szKeySequence.isEmpty())cfg->writeEntry("KeySequence",m_szKeySequence);
 
363
        if(m_uFlags != 0)cfg->writeEntry("Flags",m_uFlags);
 
364
        cfg->writeEntry("Code",m_szScript);
 
365
}