|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef CREATORSCRIPTELEMENT_H_ |
|
22 #define CREATORSCRIPTELEMENT_H_ |
|
23 |
|
24 #include "creator_randomdatafield.h" |
|
25 #include "creator_modulebase.h" |
|
26 #include "engine.h" |
|
27 #include <e32base.h> |
|
28 |
|
29 class CCreatorScriptElement; |
|
30 class CCreatorEngine; |
|
31 |
|
32 _LIT(KEmpty, ""); |
|
33 _LIT(KContextSep, "::"); |
|
34 |
|
35 // Common attributes: |
|
36 _LIT(KAmount, "amount"); |
|
37 _LIT(KRandomLength, "randomlength"); |
|
38 _LIT(KId, "id"); |
|
39 _LIT(KMaxAmount, "maxamount"); |
|
40 |
|
41 // Common element names: |
|
42 _LIT(KScript, "creatorscript"); |
|
43 _LIT(KFields, "fields"); |
|
44 _LIT(KContactSetRef, "contact-set-reference"); |
|
45 _LIT(KExistingContacts, "numberofexistingcontacts"); |
|
46 |
|
47 // Common attribute values: |
|
48 _LIT(KMax, "max"); |
|
49 _LIT(KDefault, "default"); |
|
50 _LIT(KIncrease, "incvalueforeachcopy"); |
|
51 |
|
52 class CCreatorScriptElementCache : public CBase |
|
53 { |
|
54 public: |
|
55 static CCreatorScriptElementCache* CCreatorScriptElementCache::NewL(); |
|
56 virtual ~CCreatorScriptElementCache(); |
|
57 |
|
58 void RemoveElements(); |
|
59 void AddElementL(CCreatorScriptElement* aElement); |
|
60 private: |
|
61 CCreatorScriptElementCache(); |
|
62 void ConstructL(); |
|
63 RPointerArray<CCreatorScriptElement> iElementCache; |
|
64 |
|
65 }; |
|
66 |
|
67 |
|
68 class CCreatorScriptAttribute : public CBase |
|
69 { |
|
70 public: |
|
71 static CCreatorScriptAttribute* NewL(const TDesC& aName, const TDesC& aValue); |
|
72 static CCreatorScriptAttribute* NewLC(const TDesC& aName, const TDesC& aValue); |
|
73 virtual ~CCreatorScriptAttribute(); |
|
74 |
|
75 TPtrC Name() const; |
|
76 void SetNameL(const TDesC& aName); |
|
77 TPtrC Value() const; |
|
78 void SetValueL(const TDesC& aValue); |
|
79 |
|
80 protected: |
|
81 |
|
82 CCreatorScriptAttribute(); |
|
83 virtual void ConstructL(const TDesC& aName, const TDesC& aValue); |
|
84 |
|
85 private: |
|
86 HBufC* iName; |
|
87 HBufC* iValue; |
|
88 }; |
|
89 |
|
90 /** |
|
91 * Base class for all elements |
|
92 */ |
|
93 class CCreatorScriptElement : public CBase |
|
94 { |
|
95 public: |
|
96 |
|
97 static CCreatorScriptElement* CCreatorScriptElement::NewL(CCreatorEngine* aEngine, const TDesC& aName, const TDesC& aContext = KNullDesC); |
|
98 |
|
99 /** |
|
100 * Destructor |
|
101 */ |
|
102 virtual ~CCreatorScriptElement(); |
|
103 |
|
104 /** |
|
105 * Returns the array of sub-elements. |
|
106 * @return Reference to the sub-element array. |
|
107 */ |
|
108 virtual RPointerArray<CCreatorScriptElement> const& SubElements() const; |
|
109 virtual RPointerArray<CCreatorScriptElement>& SubElements(); |
|
110 |
|
111 /** |
|
112 * Returns a sub-element. |
|
113 * @param aIndex Sub-element array index. |
|
114 * @return Pointer to a sub-element |
|
115 */ |
|
116 virtual CCreatorScriptElement* SubElement(TInt aIndex); |
|
117 |
|
118 /** |
|
119 * Finds a sub-element by a name. |
|
120 * @param aName Name of the sub-element |
|
121 * @return Pointer to the first matching sub-element. NULL if not found. |
|
122 */ |
|
123 virtual CCreatorScriptElement* FindSubElement(const TDesC& aName); |
|
124 |
|
125 /** |
|
126 * Removes all sub-elements. |
|
127 */ |
|
128 virtual void RemoveSubElements(); |
|
129 |
|
130 /** |
|
131 * Removes a sub-element |
|
132 * @param aIndex Index of the element to be removed |
|
133 */ |
|
134 virtual void RemoveSubElementL(TInt aIndex); |
|
135 |
|
136 /** |
|
137 * Adds an element to the sub-element list. |
|
138 * Leaves with error KErrNotSupported, if sub-element is illegal. |
|
139 * Leaves with error KErrArgument, if the index in out of bounds. |
|
140 * @param aElem Pointer to the element to be added. Takes ownership of the pointer. |
|
141 * @param aIndex Sub-element array index where to add the element. -1 means that |
|
142 * the element is added to the end of the array. |
|
143 */ |
|
144 virtual void AddSubElementL(CCreatorScriptElement* aElem, TInt aIndex = -1); |
|
145 |
|
146 /** |
|
147 * Returns the array of attributes. |
|
148 * @return Reference to the attribute array. |
|
149 */ |
|
150 virtual RPointerArray<CCreatorScriptAttribute> const& Attributes() const; |
|
151 |
|
152 /** |
|
153 * Returns an attribute. |
|
154 * @param aIndex Attribute array index. |
|
155 * @return Pointer to a attribute |
|
156 */ |
|
157 virtual CCreatorScriptAttribute* Attribute(TInt aIndex); |
|
158 |
|
159 /** |
|
160 * Removes all attributes. |
|
161 */ |
|
162 virtual void RemoveAttributes(); |
|
163 |
|
164 /** |
|
165 * Removes an attribute |
|
166 * @param aIndex Index of the attribute to be removed |
|
167 */ |
|
168 virtual void RemoveAttributeL(TInt aIndex); |
|
169 |
|
170 /** |
|
171 * Adds an attribute to the attribute list. |
|
172 * Leaves with error KErrNotSupported, if attribute is illegal. |
|
173 * @param aAttribute Pointer to the element to be added. Takes ownership of the pointer. |
|
174 * @param aIndex Attribute array index where to add the attribute. -1 means that |
|
175 * the attribute is added to the end of the array. |
|
176 */ |
|
177 virtual void AddAttributeL(CCreatorScriptAttribute* aAttribute, TInt aIndex = -1); |
|
178 |
|
179 /** |
|
180 * Finds attribute with the given name. First match is returned. |
|
181 */ |
|
182 virtual const CCreatorScriptAttribute* FindAttributeByName(const TDesC& aName) const; |
|
183 virtual CCreatorScriptAttribute* FindAttributeByName(const TDesC& aName); |
|
184 |
|
185 /** |
|
186 * Returns element name |
|
187 * @return Element name |
|
188 */ |
|
189 virtual TPtrC Name() const; |
|
190 |
|
191 /** |
|
192 * Sets the element name. |
|
193 * @param aName Element name |
|
194 */ |
|
195 virtual void SetNameL(const TDesC& aName); |
|
196 |
|
197 /** |
|
198 * Returns element content |
|
199 * @return Element content |
|
200 */ |
|
201 virtual TPtrC Content() const; |
|
202 |
|
203 /** |
|
204 * Set the content of the element. |
|
205 * @param aContenct Element content |
|
206 */ |
|
207 virtual void SetContentL(const TDesC& aContent); |
|
208 virtual void AppendContentL(const TDesC& aContent); |
|
209 |
|
210 /** |
|
211 * Returns element context |
|
212 * @return Element context |
|
213 */ |
|
214 virtual TPtrC Context() const; |
|
215 |
|
216 /** |
|
217 * Set the context of the element. |
|
218 * @param aContenct Element context |
|
219 */ |
|
220 virtual void SetContextL(const TDesC& aContext); |
|
221 |
|
222 /** |
|
223 * Tells whether the element should be cached for future use. |
|
224 * @return ETrue if the element should be cached for future use, EFalse otherwise. |
|
225 */ |
|
226 virtual TBool IsCacheNeeded(); |
|
227 virtual void AddToCacheL(CCreatorScriptElementCache& aCache); |
|
228 virtual void AddToCacheL(); |
|
229 virtual TBool IsCommandElement() const; |
|
230 virtual void ExecuteCommandL(); |
|
231 //virtual void SaveCommandResultsL(); |
|
232 //virtual void DiscardCommandResultsL(); |
|
233 virtual TBool IsRoot() const; |
|
234 virtual RPointerArray<CCreatorModuleBaseParameters>& CommandParameters(); |
|
235 virtual const RPointerArray<CCreatorModuleBaseParameters>& CommandParameters() const; |
|
236 |
|
237 protected: |
|
238 |
|
239 /** |
|
240 * Constructors. |
|
241 */ |
|
242 CCreatorScriptElement(CCreatorEngine* aEngine = 0); |
|
243 |
|
244 /** |
|
245 * @param aName Name of the element. |
|
246 */ |
|
247 virtual void ConstructL(const TDesC& aName, const TDesC& aContext = KNullDesC); |
|
248 |
|
249 /** |
|
250 * Tells whethet the sub-element is allowed or not. |
|
251 * @param aElem Sub-element to be tested. |
|
252 * @return Boolean value telling whether the sub-element is allowed |
|
253 * to be added or not. |
|
254 */ |
|
255 virtual TBool IsSubElementSupported(const CCreatorScriptElement& aElem) const; |
|
256 |
|
257 virtual MCreatorRandomDataField::TRandomLengthType ResolveRandomDataTypeL(const CCreatorScriptAttribute& aAttr, TInt& aRandomLen ) const; |
|
258 |
|
259 virtual TBool ConvertStrToBooleanL(const TDesC& aStr) const; |
|
260 virtual TInt ConvertStrToIntL(const TDesC& aStr) const; |
|
261 virtual TUint ConvertStrToUintL(const TDesC& aStr) const; |
|
262 virtual void ConvertStrToReal64L(const TDesC& aStr, TReal64& aVal) const; |
|
263 virtual void ConvertStrToReal32L(const TDesC& aStr, TReal32& aVal) const; |
|
264 |
|
265 virtual void AppendContactSetReferenceL(const CCreatorScriptElement& aContactSetRefElem, RArray<TLinkIdParam>& aLinkArray ) const; |
|
266 |
|
267 virtual void SetContentToTextParamL(HBufC*& aPtr, const TDesC& aContent ); |
|
268 |
|
269 virtual TTime ConvertToDateTimeL(const TDesC& aDtStr) const; |
|
270 |
|
271 virtual TInt CompareIgnoreCase(const TDesC& aStr1, const TDesC& aStr2 ) const; |
|
272 |
|
273 /** |
|
274 * Increases phonenumber by aDelta. |
|
275 * |
|
276 * Special cases, that are handled: |
|
277 * +9 -> +9, +10, +11... |
|
278 * +3584098#99 -> +3584098#99, +3584098#100, +3584098#101... |
|
279 * # -> #0, #1, #2... |
|
280 * 123# -> 123#0, 123#1, 123#2... |
|
281 * 099 -> 099, 100, 101... |
|
282 * |
|
283 * @param aOriginal original phonenumber |
|
284 * @param aDelta number to be added to original number. Must be >= 0. |
|
285 * @param aIncreased on return contains the increased number. |
|
286 * The buffer must be allocated by the caller. |
|
287 */ |
|
288 void IncreasePhoneNumL( const TDesC& aOriginal, TInt aDelta, HBufC* aIncreased ) const; |
|
289 |
|
290 protected: |
|
291 |
|
292 // Sub-element array |
|
293 RPointerArray<CCreatorScriptElement> iSubElements; |
|
294 // Attribute array |
|
295 RPointerArray<CCreatorScriptAttribute> iAttributes; |
|
296 // Element name (e.g. "contact") |
|
297 HBufC* iName; |
|
298 // Element content |
|
299 HBufC* iContent; |
|
300 // Context |
|
301 HBufC* iContext; |
|
302 |
|
303 TBool iIsCommandElement; |
|
304 TBool iIsRoot; |
|
305 CCreatorEngine* iEngine; |
|
306 RPointerArray<CCreatorModuleBaseParameters> iParameters; |
|
307 }; |
|
308 |
|
309 /** |
|
310 * Script element |
|
311 */ |
|
312 class CCreatorScriptRoot : public CCreatorScriptElement |
|
313 { |
|
314 public: |
|
315 static CCreatorScriptRoot* NewL(CCreatorEngine* aEngine, const TDesC& aName, const TDesC& aContext = KNullDesC); |
|
316 protected: |
|
317 CCreatorScriptRoot(CCreatorEngine* aEngine); |
|
318 }; |
|
319 |
|
320 /** |
|
321 * Calendar elements |
|
322 */ |
|
323 |
|
324 /** |
|
325 * Base class for calendar elements |
|
326 */ |
|
327 class CCreatorCalendarElementBase : public CCreatorScriptElement |
|
328 { |
|
329 public: |
|
330 static CCreatorCalendarElementBase* NewL(CCreatorEngine* aEngine, const TDesC& aName, const TDesC& aContext = KNullDesC); |
|
331 protected: |
|
332 CCreatorCalendarElementBase(CCreatorEngine* aEngine); |
|
333 }; |
|
334 |
|
335 /** |
|
336 * Message elements |
|
337 */ |
|
338 |
|
339 /** |
|
340 * Base class for message elements |
|
341 */ |
|
342 class CCreatorMessageElementBase : public CCreatorScriptElement |
|
343 { |
|
344 public: |
|
345 static CCreatorMessageElementBase* NewL(CCreatorEngine* aEngine, const TDesC& aName, const TDesC& aContext = KNullDesC); |
|
346 protected: |
|
347 CCreatorMessageElementBase(CCreatorEngine* aEngine); |
|
348 }; |
|
349 |
|
350 #endif /*CREATORSCRIPTELEMENT_H_*/ |