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 #include "creator_noteelement.h" |
|
20 #include "creator_traces.h" |
|
21 #include "creator_note.h" |
|
22 |
|
23 using namespace creatornote; |
|
24 |
|
25 /* |
|
26 * |
|
27 */ |
|
28 CCreatorNoteElement* CCreatorNoteElement::NewL(CCreatorEngine* aEngine, const TDesC& aName, const TDesC& aContext ) |
|
29 { |
|
30 CCreatorNoteElement* self = new (ELeave) CCreatorNoteElement(aEngine); |
|
31 CleanupStack::PushL(self); |
|
32 self->ConstructL(aName, aContext); |
|
33 CleanupStack::Pop(self); |
|
34 return self; |
|
35 } |
|
36 /* |
|
37 * |
|
38 */ |
|
39 CCreatorNoteElement::CCreatorNoteElement(CCreatorEngine* aEngine) |
|
40 : |
|
41 CCreatorScriptElement(aEngine) |
|
42 { |
|
43 iIsCommandElement = ETrue; |
|
44 } |
|
45 |
|
46 void CCreatorNoteElement::ExecuteCommandL() |
|
47 { |
|
48 const CCreatorScriptAttribute* amountAttr = FindAttributeByName(KAmount); |
|
49 TInt noteAmount = 1; |
|
50 if( amountAttr ) |
|
51 { |
|
52 noteAmount = ConvertStrToIntL(amountAttr->Value()); |
|
53 } |
|
54 // Get 'fields' element |
|
55 CCreatorScriptElement* fieldsElement = FindSubElement(KFields); |
|
56 if( fieldsElement && fieldsElement->SubElements().Count() > 0) |
|
57 { |
|
58 // Get sub-elements |
|
59 const RPointerArray<CCreatorScriptElement>& fields = fieldsElement->SubElements(); |
|
60 // Create note entries, the amount of entries is defined by noteAmount: |
|
61 for( TInt cI = 0; cI < noteAmount; ++cI ) |
|
62 { |
|
63 CNotepadParameters* param = new (ELeave) CNotepadParameters; |
|
64 CleanupStack::PushL(param); |
|
65 |
|
66 for( TInt i = 0; i < fields.Count(); ++i ) |
|
67 { |
|
68 CCreatorScriptElement* field = fields[i]; |
|
69 TPtrC elemName = field->Name(); |
|
70 TPtrC elemContent = field->Content(); |
|
71 const CCreatorScriptAttribute* randomAttr = fields[i]->FindAttributeByName(KRandomLength); |
|
72 TBool useMax = EFalse; |
|
73 if( randomAttr && randomAttr->Value() == KMax ) |
|
74 { |
|
75 useMax = ETrue; |
|
76 } |
|
77 |
|
78 if( elemName == KText ) |
|
79 { |
|
80 if( randomAttr || elemContent.Length() == 0 ) |
|
81 { |
|
82 if( useMax ) |
|
83 { |
|
84 TDesC* temp = iEngine->CreateRandomStringLC(KNotepadFieldLength); |
|
85 SetContentToTextParamL(param->iNoteText, *temp); |
|
86 CleanupStack::PopAndDestroy(); // temp |
|
87 } |
|
88 else |
|
89 { |
|
90 SetContentToTextParamL(param->iNoteText, iEngine->RandomString(CCreatorEngine::EMessageText)); |
|
91 } |
|
92 } |
|
93 else |
|
94 { |
|
95 SetContentToTextParamL(param->iNoteText, elemContent); |
|
96 } |
|
97 } |
|
98 } |
|
99 iEngine->AppendToCommandArrayL(ECmdCreateMiscEntryNotes, param); |
|
100 CleanupStack::Pop(); // param |
|
101 } |
|
102 } |
|
103 else |
|
104 { |
|
105 iEngine->AppendToCommandArrayL(ECmdCreateMiscEntryNotes, 0, noteAmount); |
|
106 } |
|
107 } |
|