|
1 /* |
|
2 * Copyright (c) 2005 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 * CUniObjectList, List of attachments. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // ========== INCLUDE FILES ================================ |
|
22 |
|
23 #include <e32std.h> |
|
24 #include <e32def.h> // for basic types |
|
25 #include <eikenv.h> // for CBase |
|
26 #include <mtclbase.h> // for CBaseMtm |
|
27 #include <msvstd.h> // for TMsvId |
|
28 #include <msvids.h> // for KMsvTempIndexEntryId |
|
29 #include <msvstore.h> |
|
30 #include <mmsvattachmentmanager.h> |
|
31 #include <mmsvattachmentmanagersync.h> |
|
32 #include <cmsvattachment.h> |
|
33 |
|
34 #include <uriutils.h> // Uri decoding and encoding |
|
35 |
|
36 #include <MsgMediaInfo.h> |
|
37 |
|
38 #include "UniDataUtils.h" |
|
39 #include "UniModelConst.h" |
|
40 #include "UniMimeInfo.h" |
|
41 #include "UniObject.h" |
|
42 #include "UniObjectList.h" |
|
43 #include "UniSmilUtils.h" |
|
44 |
|
45 // ========== EXTERNAL DATA STRUCTURES ===================== |
|
46 |
|
47 // ========== EXTERNAL FUNCTION PROTOTYPES ================= |
|
48 |
|
49 // ========== CONSTANTS ==================================== |
|
50 |
|
51 const TInt KObjectArrayGranularity = 10; |
|
52 _LIT( KContentIdString, "cid:*" ); |
|
53 _LIT8 ( KCidLeftAngle, "<"); // 8 bit angle bracket |
|
54 _LIT8 ( KCidRightAngle, ">"); // 8 bit angle bracket |
|
55 |
|
56 // ========== MACROS ======================================= |
|
57 |
|
58 // ========== LOCAL CONSTANTS AND MACROS =================== |
|
59 |
|
60 // ========== MODULE DATA STRUCTURES ======================= |
|
61 |
|
62 |
|
63 // ========== LOCAL FUNCTION PROTOTYPES ==================== |
|
64 |
|
65 // ========== LOCAL FUNCTIONS ============================== |
|
66 |
|
67 // ========== MEMBER FUNCTIONS ============================= |
|
68 |
|
69 // --------------------------------------------------------- |
|
70 // CUniObjectList::NewLC |
|
71 // |
|
72 // Factory method. |
|
73 // --------------------------------------------------------- |
|
74 // |
|
75 EXPORT_C CUniObjectList* CUniObjectList::NewL( CBaseMtm& aMtm, CUniDataUtils& aData ) |
|
76 { |
|
77 CUniObjectList* self = new(ELeave) CUniObjectList( aMtm, aData ); |
|
78 CleanupStack::PushL( self ); |
|
79 self->ConstructL(); |
|
80 CleanupStack::Pop( self ); |
|
81 return self; |
|
82 } |
|
83 |
|
84 |
|
85 // --------------------------------------------------------- |
|
86 // CUniObjectList::CUniObjectList |
|
87 // |
|
88 // Constructor. |
|
89 // --------------------------------------------------------- |
|
90 // |
|
91 CUniObjectList::CUniObjectList( CBaseMtm& aMtm, CUniDataUtils& aData ) : |
|
92 iObjectArray( NULL ), |
|
93 iData( aData ), |
|
94 iMtm( aMtm ) |
|
95 { |
|
96 } |
|
97 |
|
98 |
|
99 // --------------------------------------------------------- |
|
100 // CUniObjectList::CUniObjectList |
|
101 // |
|
102 // Destructor. |
|
103 // --------------------------------------------------------- |
|
104 // |
|
105 CUniObjectList::~CUniObjectList() |
|
106 { |
|
107 if ( iObjectArray ) |
|
108 { |
|
109 iObjectArray->ResetAndDestroy(); |
|
110 } |
|
111 delete iObjectArray; |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------- |
|
115 // CUniObjectList::AddObjectL |
|
116 // |
|
117 // AddObjectL. |
|
118 // --------------------------------------------------------- |
|
119 // |
|
120 EXPORT_C void CUniObjectList::AddObjectL( CUniObject* aObject ) |
|
121 { |
|
122 iObjectArray->AppendL( aObject ); |
|
123 |
|
124 if ( iListObserver ) |
|
125 { |
|
126 iListObserver->ObjectAddedL( this, aObject, iObjectArray->Count() - 1 ); |
|
127 } |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------- |
|
131 // CUniObjectList::SpaceNeededForSaveAll |
|
132 // |
|
133 // SpaceNeededForSaveAll. |
|
134 // --------------------------------------------------------- |
|
135 // |
|
136 EXPORT_C TInt CUniObjectList::SpaceNeededForSaveAll() |
|
137 { |
|
138 TInt spaceNeeded( 0 ); |
|
139 /* |
|
140 for (TInt i = iObjectArray->Count(); --i >= 0 ;) |
|
141 { |
|
142 if ( iObjectArray->At( i )->StoreState() == EMmsStoreStateTemporary ) |
|
143 { |
|
144 spaceNeeded += iObjectArray->At( i )->Size( EFalse ); // Count headers too. |
|
145 } |
|
146 } |
|
147 */ |
|
148 return spaceNeeded; |
|
149 } |
|
150 |
|
151 // --------------------------------------------------------- |
|
152 // CUniObjectList::SaveAllL |
|
153 // |
|
154 // SaveAllL. |
|
155 // --------------------------------------------------------- |
|
156 // |
|
157 EXPORT_C void CUniObjectList::SaveAll( MUniObjectSaveObserver& aObserver, CMsvAttachment::TMsvAttachmentType aSaveType ) |
|
158 { |
|
159 if ( iObjectArray->Count() ) |
|
160 { |
|
161 iSaveObserver = &aObserver; |
|
162 iSaveCount = 0; |
|
163 iSaveType = aSaveType; |
|
164 iObjectArray->At( iSaveCount )->Save( *this, aSaveType ); |
|
165 } |
|
166 else |
|
167 { |
|
168 aObserver.ObjectSaveReady( KErrNone ); |
|
169 } |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------- |
|
173 // CUniObjectList::RemoveAllObjectsL |
|
174 // |
|
175 // RemoveAllObjectsL |
|
176 // --------------------------------------------------------- |
|
177 // |
|
178 EXPORT_C void CUniObjectList::RemoveAllObjectsL() |
|
179 { |
|
180 TInt a = iObjectArray->Count(); |
|
181 while ( a-- ) |
|
182 { |
|
183 CUniObject* obj = iObjectArray->At( a ); |
|
184 obj->RemoveFromStoreL(); |
|
185 iObjectArray->Delete( a ); |
|
186 |
|
187 if ( iListObserver ) |
|
188 { |
|
189 iListObserver->ObjectRemovedL( this, obj, a ); |
|
190 } |
|
191 |
|
192 delete obj; |
|
193 } |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------- |
|
197 // CUniObjectList::EnsureAllObjectsHaveContentLocationL |
|
198 // |
|
199 // EnsureAllObjectsHaveContentLocationL |
|
200 // --------------------------------------------------------- |
|
201 // |
|
202 EXPORT_C void CUniObjectList::EnsureAllObjectsHaveContentLocationL() |
|
203 { |
|
204 CMsvStore* store = iMtm.Entry().EditStoreL(); |
|
205 CleanupStack::PushL( store ); |
|
206 MMsvAttachmentManager& manager = store->AttachmentManagerL(); |
|
207 MMsvAttachmentManagerSync& managerSync = store->AttachmentManagerExtensionsL(); |
|
208 TBool commit( EFalse ); |
|
209 TInt a = iObjectArray->Count(); |
|
210 while ( a-- ) |
|
211 { |
|
212 CUniObject* obj = iObjectArray->At( a ); |
|
213 if ( !obj->MimeInfo()->ContentLocation().Length() |
|
214 && obj->AttachmentId( ) ) |
|
215 { |
|
216 CMsvAttachment* attachment = manager.GetAttachmentInfoL( obj->AttachmentId() ); |
|
217 CleanupStack::PushL( attachment ); |
|
218 TParsePtrC parse( obj->MediaInfo()->FullFilePath() ); |
|
219 TPtrC nameAndExt( parse.NameAndExt() ); |
|
220 obj->MimeInfo()->EnsureContentLocationL( |
|
221 manager, |
|
222 *attachment, |
|
223 nameAndExt ); |
|
224 managerSync.ModifyAttachmentInfoL( attachment ); |
|
225 CleanupStack::Pop( attachment ); |
|
226 commit = ETrue; |
|
227 } |
|
228 } |
|
229 if ( commit ) |
|
230 { |
|
231 store->CommitL(); |
|
232 } |
|
233 CleanupStack::PopAndDestroy( store ); |
|
234 } |
|
235 |
|
236 // --------------------------------------------------------- |
|
237 // CUniObjectList::RemoveObjectL |
|
238 // |
|
239 // RemoveObjectL. |
|
240 // --------------------------------------------------------- |
|
241 // |
|
242 EXPORT_C void CUniObjectList::RemoveObjectL( CUniObject* aObject, TBool aRemoveFromStore /*= ETrue*/ ) |
|
243 { |
|
244 if ( aRemoveFromStore ) |
|
245 { |
|
246 aObject->RemoveFromStoreL(); |
|
247 } |
|
248 TInt a = iObjectArray->Count(); |
|
249 while ( a-- ) |
|
250 { |
|
251 if ( iObjectArray->At( a ) == aObject ) |
|
252 { |
|
253 iObjectArray->Delete( a ); |
|
254 |
|
255 if ( iListObserver ) |
|
256 { |
|
257 iListObserver->ObjectRemovedL( this, aObject, a ); |
|
258 } |
|
259 break; |
|
260 } |
|
261 } |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------- |
|
265 // CUniObjectList::GetByIndex |
|
266 // |
|
267 // GetByIndex. |
|
268 // --------------------------------------------------------- |
|
269 // |
|
270 EXPORT_C CUniObject* CUniObjectList::GetByIndex( TInt aIndex ) |
|
271 { |
|
272 if ( aIndex < 0 || aIndex >= iObjectArray->Count() ) |
|
273 { |
|
274 return NULL; |
|
275 } |
|
276 return iObjectArray->At( aIndex ); |
|
277 } |
|
278 |
|
279 // --------------------------------------------------------- |
|
280 // CUniObjectList::GetByAttachmentId |
|
281 // |
|
282 // GetByAttachmentId. |
|
283 // --------------------------------------------------------- |
|
284 // |
|
285 EXPORT_C CUniObject* CUniObjectList::GetByAttachmentId( TMsvAttachmentId aAttachmentId ) |
|
286 { |
|
287 TInt a = iObjectArray->Count(); |
|
288 while ( a-- ) |
|
289 { |
|
290 if ( iObjectArray->At( a )->AttachmentId() == aAttachmentId ) |
|
291 { |
|
292 return iObjectArray->At( a ); |
|
293 } |
|
294 } |
|
295 return NULL; |
|
296 } |
|
297 |
|
298 // --------------------------------------------------------- |
|
299 // CUniSmilModel::GetByNode |
|
300 // |
|
301 // --------------------------------------------------------- |
|
302 // |
|
303 EXPORT_C CUniObject* CUniObjectList::GetByNodeL( CMDXMLNode * aNode ) |
|
304 { |
|
305 TPtrC domsrc = UniSmilUtils::GetSrcL( aNode ); // Get path from DOM. |
|
306 return GetByUrlL( domsrc ); |
|
307 } |
|
308 |
|
309 // --------------------------------------------------------- |
|
310 // CUniObjectList::GetByUrlL |
|
311 // |
|
312 // GetByUrlL. |
|
313 // --------------------------------------------------------- |
|
314 // |
|
315 EXPORT_C CUniObject* CUniObjectList::GetByUrlL( const TDesC& aUrl ) |
|
316 { |
|
317 CUniObject* att = NULL; |
|
318 TBool found = EFalse; |
|
319 |
|
320 HBufC8* url8bit = HBufC8::NewLC( aUrl.Length() ); |
|
321 |
|
322 CUri16* decodedUri = NULL; |
|
323 TUriParser8 parser; |
|
324 if( !url8bit ) |
|
325 { |
|
326 return; |
|
327 } |
|
328 |
|
329 if( aUrl.MatchF( KContentIdString ) == 0 ) |
|
330 { |
|
331 //Remove "cid:" from the beginning |
|
332 url8bit->Des().Copy( aUrl.Right( aUrl.Length() - KContentIdString().Length() + 1 ) ); |
|
333 parser.Parse( *url8bit ); |
|
334 } |
|
335 else |
|
336 { |
|
337 url8bit->Des().Copy( aUrl ); |
|
338 parser.Parse( *url8bit ); |
|
339 } |
|
340 decodedUri = UriUtils::ConvertToDisplayFormL( parser ); |
|
341 CleanupStack::PushL( decodedUri ); |
|
342 |
|
343 TInt count = iObjectArray->Count(); |
|
344 for ( TInt i = 0; i < count && !found ; ++i ) |
|
345 { |
|
346 TPtrC contentLocation = iObjectArray->At( i )->MimeInfo()->ContentLocation(); |
|
347 TPtrC8 contentIdPtr = iObjectArray->At( i )->MimeInfo()->ContentId(); |
|
348 CUri16* contLocUri = NULL; |
|
349 CUri16* contIdUri = NULL; |
|
350 HBufC8* contentLoc = NULL; |
|
351 HBufC8* contentId = NULL; |
|
352 |
|
353 // Convert content location as well. |
|
354 if ( contentIdPtr.Length() ) |
|
355 { |
|
356 //Copy string to 8-bit descriptor |
|
357 contentId = HBufC8::NewLC( contentIdPtr.Length() ); |
|
358 |
|
359 if ( contentId->Find( KCidLeftAngle ) == 0 && |
|
360 contentId->Find( KCidRightAngle ) == contentId->Length() - 1 ) |
|
361 { |
|
362 // When comparing against cid, remove "<" and ">" |
|
363 contentId->Des().Copy( contentIdPtr.Mid( 1, contentIdPtr.Length() - 2 ) ); |
|
364 } |
|
365 else |
|
366 { |
|
367 contentId->Des().Copy( contentIdPtr ); |
|
368 } |
|
369 |
|
370 parser.Parse( *contentId ); |
|
371 contIdUri = UriUtils::ConvertToDisplayFormL( parser ); |
|
372 CleanupStack::PushL( contIdUri ); |
|
373 } |
|
374 if ( contentLocation.Length() ) |
|
375 { |
|
376 //Copy string to 8-bit descriptor |
|
377 contentLoc = HBufC8::NewLC( contentLocation.Length() ); |
|
378 contentLoc->Des().Copy( contentLocation ); |
|
379 parser.Parse( *contentLoc ); |
|
380 contLocUri = UriUtils::ConvertToDisplayFormL( parser ); |
|
381 CleanupStack::PushL( contLocUri ); |
|
382 } |
|
383 |
|
384 if ( |
|
385 ( ( contentLocation.Length() ) && (decodedUri->Uri().UriDes().CompareF( contLocUri->Uri().UriDes() ) == 0 ) ) || |
|
386 ( ( contentIdPtr.Length() ) && (decodedUri->Uri().UriDes().CompareF( contIdUri->Uri().UriDes() ) == 0 ) ) ) |
|
387 { |
|
388 att = iObjectArray->At( i ); |
|
389 } |
|
390 |
|
391 if ( contentLoc ) |
|
392 { |
|
393 CleanupStack::PopAndDestroy( 2, contentLoc ); // contentLoc, contLocUri |
|
394 } |
|
395 if ( contentId ) |
|
396 { |
|
397 CleanupStack::PopAndDestroy( 2, contentId ); // contentId, contIdUri |
|
398 } |
|
399 |
|
400 } |
|
401 CleanupStack::PopAndDestroy( 2, url8bit ); // decodedUri, url8bit |
|
402 return att; |
|
403 } |
|
404 |
|
405 // --------------------------------------------------------- |
|
406 // CUniObjectList::ObjectByteSize |
|
407 // --------------------------------------------------------- |
|
408 // |
|
409 EXPORT_C TInt CUniObjectList::ObjectByteSize() const |
|
410 { |
|
411 TInt byteSize(0); |
|
412 TInt i = iObjectArray->Count(); |
|
413 while ( i-- ) |
|
414 { |
|
415 byteSize += iObjectArray->At( i )->Size(); |
|
416 } |
|
417 |
|
418 return byteSize; |
|
419 } |
|
420 |
|
421 // --------------------------------------------------------- |
|
422 // CUniObjectList::SetListObserver |
|
423 // --------------------------------------------------------- |
|
424 // |
|
425 EXPORT_C void CUniObjectList::SetListObserver( MUniObjectListObserver* aObserver ) |
|
426 { |
|
427 iListObserver = aObserver; |
|
428 } |
|
429 |
|
430 // --------------------------------------------------------- |
|
431 // CUniObjectList::GetObjectByUniqueHandle |
|
432 // --------------------------------------------------------- |
|
433 // |
|
434 EXPORT_C CUniObject* CUniObjectList::GetObjectByUniqueHandle( TInt aUniqueControlHandle ) |
|
435 { |
|
436 for ( TInt index = 0; index < iObjectArray->Count(); ++index ) |
|
437 { |
|
438 CUniObject* current = iObjectArray->At( index ); |
|
439 if( current->UniqueControlHandle() == aUniqueControlHandle ) |
|
440 { |
|
441 return current; |
|
442 } |
|
443 } |
|
444 return NULL; |
|
445 } |
|
446 |
|
447 // --------------------------------------------------------- |
|
448 // CUniObjectList::ConstructL |
|
449 // |
|
450 // 2nd phase constructor. |
|
451 // --------------------------------------------------------- |
|
452 // |
|
453 void CUniObjectList::ConstructL() |
|
454 { |
|
455 iObjectArray = new(ELeave)CArrayPtrFlat<CUniObject>( KObjectArrayGranularity ); |
|
456 } |
|
457 |
|
458 // --------------------------------------------------------- |
|
459 // CUniObjectList::ObjectSaveReady |
|
460 // |
|
461 // --------------------------------------------------------- |
|
462 // |
|
463 void CUniObjectList::ObjectSaveReady( TInt aError ) |
|
464 { |
|
465 if ( aError ) |
|
466 { |
|
467 iSaveObserver->ObjectSaveReady( aError ); |
|
468 } |
|
469 else |
|
470 { |
|
471 iSaveCount++; |
|
472 if ( iSaveCount < iObjectArray->Count() ) |
|
473 { |
|
474 iObjectArray->At( iSaveCount )->Save( *this, iSaveType ); |
|
475 } |
|
476 else |
|
477 { |
|
478 iSaveObserver->ObjectSaveReady( KErrNone ); |
|
479 } |
|
480 } |
|
481 } |
|
482 |
|
483 // EOF |