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