|
1 /* |
|
2 * Copyright (c) 2004 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 the License "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 * Implementation of class CFavouritesItemImpl |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include "FavouritesItemImpl.h" |
|
24 #include "FavouritesPanic.h" |
|
25 |
|
26 // ================= MEMBER FUNCTIONS ======================= |
|
27 |
|
28 // --------------------------------------------------------- |
|
29 // CFavouritesItemImpl::NewL |
|
30 // --------------------------------------------------------- |
|
31 // |
|
32 CFavouritesItemImpl* CFavouritesItemImpl::NewL() |
|
33 { |
|
34 CFavouritesItemImpl* item = NewLC(); |
|
35 CleanupStack::Pop( item ); |
|
36 return item; |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------- |
|
40 // CFavouritesItemImpl::NewLC |
|
41 // --------------------------------------------------------- |
|
42 // |
|
43 CFavouritesItemImpl* CFavouritesItemImpl::NewLC() |
|
44 { |
|
45 CFavouritesItemImpl* item = new (ELeave) CFavouritesItemImpl(); |
|
46 CleanupStack::PushL( item ); |
|
47 item->ConstructL(); |
|
48 return item; |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------- |
|
52 // CFavouritesItemImpl::~CFavouritesItemImpl |
|
53 // --------------------------------------------------------- |
|
54 // |
|
55 CFavouritesItemImpl::~CFavouritesItemImpl() |
|
56 { |
|
57 delete iName; |
|
58 delete iUrl; |
|
59 delete iUserName; |
|
60 delete iPassword; |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------- |
|
64 // CFavouritesItemImpl::operator= |
|
65 // --------------------------------------------------------- |
|
66 // |
|
67 CFavouritesItemImpl& CFavouritesItemImpl::operator= |
|
68 ( const CFavouritesItemImpl& aCopyFrom ) |
|
69 { |
|
70 if( &aCopyFrom != this ) |
|
71 { |
|
72 iUid = aCopyFrom.iUid; |
|
73 iParentFolder = aCopyFrom.iParentFolder; |
|
74 iType = aCopyFrom.iType; |
|
75 SetNameL( *(aCopyFrom.iName) ); |
|
76 SetUrlL( *(aCopyFrom.iUrl) ); |
|
77 iWapAp = aCopyFrom.iWapAp; |
|
78 SetUserNameL( *(aCopyFrom.iUserName) ); |
|
79 SetPasswordL( *(aCopyFrom.iPassword) ); |
|
80 iFactoryItem = aCopyFrom.iFactoryItem; |
|
81 iReadOnly = aCopyFrom.iReadOnly; |
|
82 iContextId = aCopyFrom.iContextId; |
|
83 iModified = aCopyFrom.iModified; |
|
84 iHidden = aCopyFrom.iHidden; |
|
85 } |
|
86 return *this; |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------- |
|
90 // CFavouritesItemImpl::ConstructL |
|
91 // --------------------------------------------------------- |
|
92 // |
|
93 void CFavouritesItemImpl::ConstructL() |
|
94 { |
|
95 iUid = KFavouritesNullUid; |
|
96 iParentFolder = KFavouritesNullUid; |
|
97 iType = CFavouritesItem::EItem; |
|
98 iName = HBufC::NewL( 0 ); |
|
99 iUrl = HBufC::NewL( 0 ); |
|
100 iWapAp.SetDefault(); |
|
101 iUserName = HBufC::NewL( 0 ); |
|
102 iPassword = HBufC::NewL( 0 ); |
|
103 iFactoryItem = EFalse; |
|
104 iReadOnly = EFalse; |
|
105 iContextId = KFavouritesNullContextId; |
|
106 iModified = Time::NullTTime(); |
|
107 iHidden = EFalse; |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------- |
|
111 // CFavouritesItemImpl::SetNameL |
|
112 // --------------------------------------------------------- |
|
113 // |
|
114 void CFavouritesItemImpl::SetNameL( const TDesC& aName ) |
|
115 { |
|
116 HBufC* buf = HBufC::NewLC( aName.Length() ); |
|
117 TPtr bufp( buf->Des() ); |
|
118 User::LeaveIfError( MakeName( aName, bufp ) ); |
|
119 CleanupStack::Pop( buf ); |
|
120 delete iName; |
|
121 iName = buf; |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------- |
|
125 // CFavouritesItemImpl::ExternalizeL |
|
126 // --------------------------------------------------------- |
|
127 // |
|
128 void CFavouritesItemImpl::ExternalizeL( RWriteStream& aStream ) const |
|
129 { |
|
130 aStream.WriteInt32L( iUid ); |
|
131 aStream.WriteInt32L( iParentFolder ); |
|
132 aStream.WriteInt32L( STATIC_CAST( TInt, iType ) ); |
|
133 BufToStreamL( *iName, aStream ); |
|
134 BufToStreamL( *iUrl, aStream ); |
|
135 iWapAp.ExternalizeL( aStream ); |
|
136 BufToStreamL( *iUserName, aStream ); |
|
137 BufToStreamL( *iPassword, aStream ); |
|
138 aStream.WriteInt32L( STATIC_CAST( TInt, iReadOnly ) ); |
|
139 aStream.WriteInt32L( STATIC_CAST( TInt, iFactoryItem ) ); |
|
140 aStream.WriteInt32L( iContextId ); |
|
141 aStream.WriteInt32L( I64HIGH( iModified.Int64() ) ); |
|
142 aStream.WriteInt32L( I64LOW( iModified.Int64() ) ); |
|
143 aStream.WriteInt32L( STATIC_CAST( TInt, iHidden ) ); |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------- |
|
147 // CFavouritesItemImpl::InternalizeL |
|
148 // --------------------------------------------------------- |
|
149 // |
|
150 void CFavouritesItemImpl::InternalizeL( RReadStream& aStream ) |
|
151 { |
|
152 iUid = aStream.ReadInt32L(); |
|
153 iParentFolder = aStream.ReadInt32L(); |
|
154 iType = STATIC_CAST( CFavouritesItem::TType, aStream.ReadInt32L() ); |
|
155 BufFromStreamL( iName, aStream ); |
|
156 BufFromStreamL( iUrl, aStream ); |
|
157 iWapAp.InternalizeL( aStream ); |
|
158 BufFromStreamL( iUserName, aStream ); |
|
159 BufFromStreamL( iPassword, aStream ); |
|
160 iReadOnly = STATIC_CAST( TBool, aStream.ReadInt32L() ); |
|
161 iFactoryItem = STATIC_CAST( TBool, aStream.ReadInt32L() ); |
|
162 iContextId = aStream.ReadInt32L(); |
|
163 // Need to use local variables, cannot read to TInt64 constructor directly |
|
164 // from stream. Order of argument evaluation is compiler dependent! |
|
165 TUint32 high = aStream.ReadInt32L(); |
|
166 TUint32 low = aStream.ReadInt32L(); |
|
167 iModified = MAKE_TINT64( high, low ); |
|
168 iHidden = STATIC_CAST( TBool, aStream.ReadInt32L() ); |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------- |
|
172 // CFavouritesItemImpl::ExternalizeUpdateDeltaL |
|
173 // --------------------------------------------------------- |
|
174 // |
|
175 void CFavouritesItemImpl::ExternalizeUpdateDeltaL( RWriteStream& aStream ) const |
|
176 { |
|
177 aStream.WriteInt32L( iUid ); |
|
178 BufToStreamL( *iName, aStream ); |
|
179 aStream.WriteInt32L( I64HIGH( iModified.Int64() ) ); |
|
180 aStream.WriteInt32L( I64LOW( iModified.Int64() ) ); |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------- |
|
184 // CFavouritesItemImpl::InternalizeUpdateDeltaL |
|
185 // --------------------------------------------------------- |
|
186 // |
|
187 void CFavouritesItemImpl::InternalizeUpdateDeltaL( RReadStream& aStream ) |
|
188 { |
|
189 iUid = aStream.ReadInt32L(); |
|
190 BufFromStreamL( iName, aStream ); |
|
191 // Need to use local variables, cannot read to TInt64 constructor directly |
|
192 // from stream. Order of argument evaluation is compiler dependent! |
|
193 TUint32 high = aStream.ReadInt32L(); |
|
194 TUint32 low = aStream.ReadInt32L(); |
|
195 iModified = MAKE_TINT64( high, low ); |
|
196 } |
|
197 |
|
198 // --------------------------------------------------------- |
|
199 // CFavouritesItemImpl::BufToStreamL |
|
200 // --------------------------------------------------------- |
|
201 // |
|
202 void CFavouritesItemImpl::BufToStreamL |
|
203 ( const TDesC& aBuf, RWriteStream& aStream ) const |
|
204 { |
|
205 aStream.WriteInt32L( aBuf.Length() ); |
|
206 aStream.WriteL( aBuf ); |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------- |
|
210 // CFavouritesItemImpl::BufFromStreamL |
|
211 // --------------------------------------------------------- |
|
212 // |
|
213 void CFavouritesItemImpl::BufFromStreamL( HBufC*& aBuf, RReadStream& aStream ) |
|
214 { |
|
215 TInt len = aStream.ReadInt32L(); |
|
216 HBufC* buf = HBufC::NewLC( len ); |
|
217 TPtr ptr( buf->Des() ); ptr.SetLength( len ); |
|
218 aStream.ReadL( ptr, len ); |
|
219 delete aBuf; |
|
220 aBuf = buf; |
|
221 CleanupStack::Pop( buf ); // Now member. |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------- |
|
225 // CFavouritesItemImpl::SetBufL |
|
226 // --------------------------------------------------------- |
|
227 // |
|
228 void CFavouritesItemImpl::SetBufL |
|
229 ( HBufC*& aBuf, const TDesC& aDesc, TInt aMaxLength ) |
|
230 { |
|
231 if ( aDesc.Length() > aMaxLength ) |
|
232 { |
|
233 User::Leave( KErrOverflow ); |
|
234 } |
|
235 HBufC* buf = aDesc.AllocL(); |
|
236 delete aBuf; |
|
237 aBuf = buf; |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------- |
|
241 // CFavouritesItemImpl::IsValid |
|
242 // --------------------------------------------------------- |
|
243 // |
|
244 TBool CFavouritesItemImpl::IsValid() const |
|
245 { |
|
246 TBool ret = ETrue; |
|
247 if ( !IsValidName( *iName ) ) |
|
248 { |
|
249 // Valid name is required for all (except the root folder). |
|
250 ret = EFalse; |
|
251 } |
|
252 else |
|
253 { |
|
254 switch ( iType ) |
|
255 { |
|
256 case CFavouritesItem::EItem: |
|
257 if ( !iUrl->Length() ) |
|
258 { |
|
259 // URL is required for items. |
|
260 ret = EFalse; |
|
261 } |
|
262 break; |
|
263 |
|
264 case CFavouritesItem::EFolder: |
|
265 if ( |
|
266 iUrl->Length() || |
|
267 iUserName->Length() || |
|
268 iPassword->Length() |
|
269 ) |
|
270 { |
|
271 // URL, Username, Password are not allowed |
|
272 // for folders. |
|
273 ret = EFalse; |
|
274 } |
|
275 break; |
|
276 |
|
277 default: |
|
278 { |
|
279 FavouritesPanic( EFavouritesBadType ); |
|
280 } |
|
281 } |
|
282 } |
|
283 return ret; |
|
284 } |
|
285 |
|
286 // --------------------------------------------------------- |
|
287 // CFavouritesItemImpl::MakeName |
|
288 // --------------------------------------------------------- |
|
289 // |
|
290 TInt CFavouritesItemImpl::MakeName( const TDesC& aSource, TDes& aTarget ) |
|
291 { |
|
292 TInt err( KErrNone ); |
|
293 _LIT(KEikEdwinRightToLeftMark, "\x200F" ); |
|
294 // Copy source to target. |
|
295 aTarget = aSource; |
|
296 TBool rightRemove, leftRemove; |
|
297 rightRemove = EFalse; |
|
298 leftRemove = EFalse; |
|
299 |
|
300 // Remove leading/trailing spaces. |
|
301 if(aTarget.Right(1).Compare(KEikEdwinRightToLeftMark) ==0) |
|
302 { |
|
303 aTarget.Delete(aTarget.Length() -1,1); |
|
304 rightRemove = ETrue; |
|
305 } |
|
306 |
|
307 if(aTarget.Left(1).Compare(KEikEdwinRightToLeftMark) ==0) |
|
308 { |
|
309 aTarget.Delete(0,1); |
|
310 leftRemove = ETrue; |
|
311 } |
|
312 |
|
313 |
|
314 aTarget.Trim(); |
|
315 if(rightRemove) |
|
316 { |
|
317 if(aTarget.Right(1).Compare(KEikEdwinRightToLeftMark) ==0) |
|
318 { |
|
319 aTarget.Delete(aTarget.Length() -1,1); |
|
320 } |
|
321 |
|
322 } |
|
323 if(leftRemove) |
|
324 { |
|
325 if(aTarget.Left(1).Compare(KEikEdwinRightToLeftMark) ==0) |
|
326 { |
|
327 aTarget.Delete(0,1); |
|
328 } |
|
329 } |
|
330 |
|
331 // Trim to valid length. |
|
332 if ( aTarget.Length() > KFavouritesMaxName ) |
|
333 { |
|
334 aTarget.SetLength( KFavouritesMaxName ); |
|
335 err = KErrOverflow; |
|
336 } |
|
337 return err; |
|
338 } |
|
339 |
|
340 // --------------------------------------------------------- |
|
341 // CFavouritesItemImpl::IsValidName |
|
342 // --------------------------------------------------------- |
|
343 // |
|
344 TBool CFavouritesItemImpl::IsValidName( const TDesC& aName ) |
|
345 { |
|
346 // All characters accepted (no exclusion of special characters.). |
|
347 // Name must contain at least non-whitespace; since this method expects |
|
348 // a trimmed name, this is equivalent of checking if the name is empty. |
|
349 // This method always gets a trimmed name (MakeName generated). |
|
350 return aName.Length(); |
|
351 } |
|
352 |
|
353 // End of File |