|
1 /* |
|
2 * Copyright (c) 2002-2006 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: Base class for WML subitems. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include "WmlSubItemBase.h" // CWmlSubItemBase |
|
24 #include "WmlBioControl.pan" // Panic() |
|
25 |
|
26 #include <msgnamevalue.h> // CMsgNameValue |
|
27 #include <MsgBioUtils.h> |
|
28 |
|
29 // ==================== LOCAL FUNCTIONS ==================== |
|
30 |
|
31 /// Helper method when an array is pushed to CleanupStack |
|
32 static void CleanupResetAndDestroy(TAny* aSelf) |
|
33 { |
|
34 __ASSERT_DEBUG(aSelf, User::Panic( _L("wmlbc.dll"), ENullPtr )); |
|
35 CArrayPtrSeg<CMsgNameValue>* self = |
|
36 static_cast<CArrayPtrSeg<CMsgNameValue>* >(aSelf); |
|
37 self->ResetAndDestroy(); |
|
38 delete self; |
|
39 } |
|
40 |
|
41 // ================= MEMBER FUNCTIONS ======================= |
|
42 |
|
43 // --------------------------------------------------------- |
|
44 // CWmlSubItemBase::~CWmlSubItemBase |
|
45 // --------------------------------------------------------- |
|
46 // |
|
47 CWmlSubItemBase::~CWmlSubItemBase() |
|
48 { |
|
49 delete iOriginalName; |
|
50 delete iName; |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------- |
|
54 // CWmlSubItemBase::SaveItemL |
|
55 // Contains logic for storing either bookmark or accespoint. |
|
56 // --------------------------------------------------------- |
|
57 // |
|
58 |
|
59 TBool CWmlSubItemBase::SaveItemL( const TBool aShowNote, |
|
60 const TBool aShowPreferredQuery, |
|
61 const TInt aPreferredInformation, |
|
62 const TBool aCreateBookmarkIfNotSetAsDefault) |
|
63 { |
|
64 |
|
65 // Set all the member variables to the initial state. |
|
66 Initialize(); |
|
67 |
|
68 // Name checking part |
|
69 |
|
70 // If the item don't have name get the default name |
|
71 // and increment it as long as it's unique. |
|
72 if (!HasNameL()) |
|
73 { |
|
74 SetDefaultNameL(); |
|
75 while (!IsNameValidL( EFalse )) // Don't update the list from database |
|
76 { |
|
77 IncrementNameL(); |
|
78 } |
|
79 QueryNewNameL(); |
|
80 } |
|
81 |
|
82 // Keep asking as long as the name is not unique. |
|
83 while ( !IsNameValidL() ) |
|
84 { |
|
85 if ( !RenameQueryL() ) |
|
86 { |
|
87 // Operation stops if user didn't want to rename. |
|
88 return EFalse; |
|
89 } |
|
90 IncrementNameL(); |
|
91 while (!IsNameValidL( EFalse )) // Dont' update the list from database |
|
92 { |
|
93 IncrementNameL(); |
|
94 } |
|
95 QueryNewNameL(); |
|
96 } |
|
97 |
|
98 // Actual storing part |
|
99 |
|
100 PreStoreL( aShowPreferredQuery ); |
|
101 |
|
102 // Set the new name as item's name. |
|
103 SetNameL( *iName ); |
|
104 StoreL(); |
|
105 // Set the original name back as the item's name. |
|
106 SetNameL( *iOriginalName ); |
|
107 |
|
108 PostStoreL( aShowNote, aPreferredInformation, aCreateBookmarkIfNotSetAsDefault ); |
|
109 |
|
110 return ETrue; |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------- |
|
114 // CWmlSubItemBase::Initialize |
|
115 // Set all the member variables to the initial state. |
|
116 // --------------------------------------------------------- |
|
117 // |
|
118 void CWmlSubItemBase::Initialize() |
|
119 { |
|
120 // Set the variables to the default values, because if |
|
121 // leave occurs at some point of the SaveItem-operation, |
|
122 // variables MUST NOT keep their current state. |
|
123 |
|
124 delete iName; |
|
125 iName = NULL; |
|
126 |
|
127 delete iOriginalName; |
|
128 iOriginalName = NULL; |
|
129 |
|
130 // Let the actual implementation initialize itself. |
|
131 DoInitialize(); |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------- |
|
135 // CWmlSubItemBase::~CWmlSubItemBase |
|
136 // --------------------------------------------------------- |
|
137 // |
|
138 TBool CWmlSubItemBase::HasNameL() |
|
139 { |
|
140 // Assert that iName and iOriginalName are NULL before this operation. |
|
141 __ASSERT_DEBUG(iName == NULL, |
|
142 Panic(ENameNotNull)); |
|
143 __ASSERT_DEBUG(iOriginalName == NULL, |
|
144 Panic(EOriginalNameNotNull)); |
|
145 |
|
146 // Get the name from the bmItem. |
|
147 HBufC* name = NameLC(); |
|
148 CleanupStack::Pop( name ); |
|
149 |
|
150 // Put the retrieved name to the iName member variable. |
|
151 // This is changed during the storing sequence. |
|
152 iName = name; |
|
153 |
|
154 // Allocate the original name to the member variable. |
|
155 // This is not changed during the storing sequence and |
|
156 // is restored to the item's name in PostStoreL |
|
157 iOriginalName = name->AllocL(); |
|
158 |
|
159 // Check that there's actually something. |
|
160 if (iName->Length() == 0) |
|
161 { |
|
162 return EFalse; |
|
163 } |
|
164 |
|
165 return ETrue; |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------- |
|
169 // CWmlSubItemBase::~CWmlSubItemBase |
|
170 // --------------------------------------------------------- |
|
171 // |
|
172 void CWmlSubItemBase::SetDefaultNameL() |
|
173 { |
|
174 delete iName; |
|
175 iName = NULL; |
|
176 iName = DefaultNameLC(); |
|
177 CleanupStack::Pop( iName ); |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------- |
|
181 // CWmlSubItemBase::~CWmlSubItemBase |
|
182 // --------------------------------------------------------- |
|
183 // |
|
184 TBool CWmlSubItemBase::IsNameValidL( TBool aUpdateList ) |
|
185 { |
|
186 return IsNameValidL( *iName, aUpdateList ); |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------- |
|
190 // CWmlSubItemBase::IncrementNameL() |
|
191 // Calls the static implementation method by giving |
|
192 // iName as a parameter. |
|
193 // --------------------------------------------------------- |
|
194 // |
|
195 void CWmlSubItemBase::IncrementNameL() |
|
196 { |
|
197 TInt maxLength = NameMaxLength(); |
|
198 HBufC* newName = DoIncrementNameL(*iName, maxLength); |
|
199 |
|
200 delete iName; |
|
201 iName = NULL; |
|
202 |
|
203 iName = newName; |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------- |
|
207 // CWmlSubItemBase::DoIncrementNameL() |
|
208 // --------------------------------------------------------- |
|
209 // |
|
210 HBufC* CWmlSubItemBase::DoIncrementNameL( const TDesC& aName, TInt aMaxLength ) |
|
211 { |
|
212 // Create buffer descriptor that is used to append a running number |
|
213 // to given name. The lenght of the buffer is set to maximum because |
|
214 // IncrementNameL doesn't realloc the buffer. |
|
215 HBufC* buf = HBufC::NewLC( aMaxLength ); |
|
216 TPtr ptr = buf->Des(); |
|
217 ptr = aName; |
|
218 MsgBioUtils::IncrementNameL( ptr, aMaxLength ); |
|
219 CleanupStack::Pop( buf ); |
|
220 return buf; |
|
221 } |
|
222 |
|
223 // --------------------------------------------------------- |
|
224 // CWmlSubItemBase::QueryNewNameL() |
|
225 // Calls the static implementation method by giving |
|
226 // iName as a parameter. |
|
227 // --------------------------------------------------------- |
|
228 // |
|
229 void CWmlSubItemBase::QueryNewNameL() |
|
230 { |
|
231 HBufC* newName = DoQueryNewNameLC(*iName); |
|
232 CleanupStack::Pop( newName ); |
|
233 |
|
234 delete iName; |
|
235 iName = NULL; |
|
236 |
|
237 iName = newName; |
|
238 } |
|
239 |
|
240 TBool CWmlSubItemBase::RenameQueryL() |
|
241 { |
|
242 return DoRenameQueryL(*iName); |
|
243 } |
|
244 |
|
245 CArrayPtrFlat<CMsgNameValue>* CWmlSubItemBase::LabelsAndValuesLC() |
|
246 { |
|
247 TInt count = FieldCount(); |
|
248 |
|
249 CArrayPtrFlat<CMsgNameValue>* data = |
|
250 new (ELeave) CArrayPtrFlat<CMsgNameValue>( count ); |
|
251 CleanupStack::PushL( TCleanupItem(CleanupResetAndDestroy, data ) ); |
|
252 |
|
253 for (TInt i = 0; i < count; i++) |
|
254 { |
|
255 CMsgNameValue* fieldData = GetFieldDataAtLC( i ); |
|
256 if ( fieldData->Value().Length() > 0 ) |
|
257 { |
|
258 data->AppendL( fieldData ); |
|
259 CleanupStack::Pop( fieldData ); |
|
260 } |
|
261 else |
|
262 { |
|
263 CleanupStack::PopAndDestroy( fieldData ); |
|
264 } |
|
265 } |
|
266 return data; |
|
267 } |
|
268 |
|
269 // End of File |