|
1 /* |
|
2 * Copyright (c) 2009 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 // INCLUDE FILES |
|
19 |
|
20 #include <s32strm.h> |
|
21 #include "menuitemattr.h" |
|
22 |
|
23 // ================= LOCAL FUNCTIONS ======================= |
|
24 |
|
25 /** |
|
26 * Cleanup support method. Call ResetAndDestroy() on the array. |
|
27 * @param RMenuItemArray* as TAny* |
|
28 */ |
|
29 LOCAL_C void ResetAndDestroy( TAny* aArray ) |
|
30 { |
|
31 ((RMenuItemAttrArray*)aArray)->ResetAndDestroy(); |
|
32 } |
|
33 |
|
34 // ================= MEMBER FUNCTIONS ======================= |
|
35 |
|
36 // --------------------------------------------------------- |
|
37 // CMenuItemAttr::~CMenuItemAttr |
|
38 // --------------------------------------------------------- |
|
39 // |
|
40 CMenuItemAttr::~CMenuItemAttr() |
|
41 { |
|
42 iName.Close(); |
|
43 delete iValue; |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------- |
|
47 // CMenuItemAttr::NewL |
|
48 // --------------------------------------------------------- |
|
49 // |
|
50 CMenuItemAttr* CMenuItemAttr::NewL( const TDesC& aName ) |
|
51 { |
|
52 CMenuItemAttr* attr = NewLC( aName ); |
|
53 CleanupStack::Pop( attr ); |
|
54 return attr; |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------- |
|
58 // CMenuItemAttr::NewLC |
|
59 // --------------------------------------------------------- |
|
60 // |
|
61 CMenuItemAttr* CMenuItemAttr::NewLC( const TDesC& aName ) |
|
62 { |
|
63 CMenuItemAttr* attr = new (ELeave) CMenuItemAttr(); |
|
64 CleanupStack::PushL( attr ); |
|
65 attr->ConstructL( aName ); |
|
66 return attr; |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------- |
|
70 // CMenuItemAttr::NewLC |
|
71 // --------------------------------------------------------- |
|
72 // |
|
73 CMenuItemAttr* CMenuItemAttr::NewLC( RReadStream& aStream ) |
|
74 { |
|
75 CMenuItemAttr* attr = new (ELeave) CMenuItemAttr(); |
|
76 CleanupStack::PushL( attr ); |
|
77 attr->InternalizeL( aStream ); |
|
78 return attr; |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------- |
|
82 // CMenuItemAttr::ConstructL |
|
83 // --------------------------------------------------------- |
|
84 // |
|
85 void CMenuItemAttr::ConstructL( const TDesC& aName ) |
|
86 { |
|
87 iName.CreateL( aName ); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------- |
|
91 // CMenuItemAttr::SetValue |
|
92 // --------------------------------------------------------- |
|
93 // |
|
94 void CMenuItemAttr::SetValue( HBufC* aValue ) |
|
95 { |
|
96 if ( iValue ) |
|
97 { |
|
98 if ( aValue && *iValue == *aValue ) |
|
99 { |
|
100 // String to same string: no change. |
|
101 delete aValue; |
|
102 } |
|
103 else |
|
104 { |
|
105 // String to other string or NULL: change. |
|
106 iChanged = ETrue; |
|
107 delete iValue; |
|
108 iValue = aValue; |
|
109 } |
|
110 } |
|
111 else |
|
112 { |
|
113 if ( aValue ) |
|
114 { |
|
115 // NULL to string: change. |
|
116 iChanged = ETrue; |
|
117 iValue = aValue; |
|
118 } |
|
119 else |
|
120 { |
|
121 // NULL to NULL: no change. |
|
122 } |
|
123 } |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------- |
|
127 // CMenuItemAttr::ExternalizeL |
|
128 // --------------------------------------------------------- |
|
129 // |
|
130 void CMenuItemAttr::ExternalizeL( RWriteStream& aStream ) const |
|
131 { |
|
132 aStream.WriteInt32L( iName.Length() ); |
|
133 aStream.WriteL( iName ); |
|
134 if ( iValue ) |
|
135 { |
|
136 aStream.WriteInt32L( iValue->Length() ); |
|
137 aStream.WriteL( *iValue ); |
|
138 } |
|
139 else |
|
140 { |
|
141 aStream.WriteInt32L( KErrNotFound ); |
|
142 } |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------- |
|
146 // CMenuItemAttr::InternalizeL |
|
147 // --------------------------------------------------------- |
|
148 // |
|
149 void CMenuItemAttr::InternalizeL( RReadStream& aStream ) |
|
150 { |
|
151 iName.Close(); |
|
152 delete iValue; iValue = NULL; |
|
153 TInt len; |
|
154 len = aStream.ReadInt32L(); |
|
155 iName.CreateL( len ); |
|
156 aStream.ReadL( iName, len ); |
|
157 len = aStream.ReadInt32L(); |
|
158 if ( len >= 0 ) |
|
159 { |
|
160 iValue = HBufC::NewL( len ); |
|
161 TPtr ptr( iValue->Des() ); |
|
162 aStream.ReadL( ptr, len ); |
|
163 } |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------- |
|
167 // RMenuItemAttrArray::Find |
|
168 // --------------------------------------------------------- |
|
169 // |
|
170 TInt RMenuItemAttrArray::Find( const TDesC& aName ) const |
|
171 { |
|
172 for ( TInt i = 0; i < Count(); i++ ) |
|
173 { |
|
174 if ( !aName.Compare( operator[]( i )->Name() ) ) |
|
175 { |
|
176 return i; |
|
177 } |
|
178 } |
|
179 return KErrNotFound; |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------- |
|
183 // RMenuItemAttrArray::CountChanged |
|
184 // --------------------------------------------------------- |
|
185 // |
|
186 TInt RMenuItemAttrArray::CountChanged() const |
|
187 { |
|
188 TInt count = 0; |
|
189 for ( TInt i = 0; i < Count(); i++ ) |
|
190 { |
|
191 if ( operator[]( i )->Changed() ) |
|
192 { |
|
193 count++; |
|
194 } |
|
195 } |
|
196 return count; |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------- |
|
200 // RMenuItemAttrArray::ClearChanged |
|
201 // --------------------------------------------------------- |
|
202 // |
|
203 void RMenuItemAttrArray::ClearChanged() |
|
204 { |
|
205 for ( TInt i = 0; i < Count(); i++ ) |
|
206 { |
|
207 operator[]( i )->SetChanged( EFalse ); |
|
208 } |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------- |
|
212 // RMenuItemAttrArray::ExternalizeChangesL |
|
213 // --------------------------------------------------------- |
|
214 // |
|
215 void RMenuItemAttrArray::ExternalizeChangesL( RWriteStream& aStream ) const |
|
216 { |
|
217 aStream.WriteInt32L( CountChanged() ); |
|
218 for ( TInt i = 0; i < Count(); i++ ) |
|
219 { |
|
220 const CMenuItemAttr* attr = operator[]( i ); |
|
221 if ( attr->Changed() ) |
|
222 { |
|
223 attr->ExternalizeL( aStream ); |
|
224 } |
|
225 } |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------- |
|
229 // RMenuItemAttrArray::ExternalizeL |
|
230 // --------------------------------------------------------- |
|
231 // |
|
232 void RMenuItemAttrArray::ExternalizeL( RWriteStream& aStream ) const |
|
233 { |
|
234 aStream.WriteInt32L( Count() ); |
|
235 for ( TInt i = 0; i < Count(); i++ ) |
|
236 { |
|
237 operator[]( i )->ExternalizeL( aStream ); |
|
238 } |
|
239 } |
|
240 |
|
241 // --------------------------------------------------------- |
|
242 // RMenuItemAttrArray::InternalizeL |
|
243 // --------------------------------------------------------- |
|
244 // |
|
245 void RMenuItemAttrArray::InternalizeL( RReadStream& aStream ) |
|
246 { |
|
247 TInt count = aStream.ReadInt32L(); |
|
248 for ( TInt i = 0; i < count; i++ ) |
|
249 { |
|
250 CMenuItemAttr* attr = CMenuItemAttr::NewLC( aStream ); |
|
251 AppendL( attr ); |
|
252 CleanupStack::Pop( attr ); |
|
253 } |
|
254 } |
|
255 |
|
256 // --------------------------------------------------------- |
|
257 // CleanupResetAndDestroyPushL |
|
258 // --------------------------------------------------------- |
|
259 // |
|
260 void CleanupResetAndDestroyPushL( RMenuItemAttrArray& aArray ) |
|
261 { |
|
262 CleanupStack::PushL( TCleanupItem( ResetAndDestroy, &aArray ) ); |
|
263 } |
|
264 |
|
265 // End of File |