60
|
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 |
* CUniObject, Storage for single attachment in presentation.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
// ========== INCLUDE FILES ================================
|
|
22 |
|
|
23 |
#include <e32def.h> // for basic types
|
|
24 |
#include <eikenv.h> // for CBase
|
|
25 |
#include <mtclbase.h> // for CBaseMtm
|
|
26 |
#include <msvids.h> // for KMsvTempIndexEntryId
|
|
27 |
#include <msvstore.h>
|
|
28 |
#include <mmsvattachmentmanager.h>
|
|
29 |
#include <mmsvattachmentmanagersync.h>
|
|
30 |
#include <cmsvattachment.h>
|
|
31 |
#include <miutmsg.h>
|
|
32 |
|
|
33 |
// Features
|
|
34 |
#include <featmgr.h>
|
|
35 |
#include <bldvariant.hrh>
|
|
36 |
#include <DRMNotifier.h>
|
|
37 |
|
|
38 |
// DRM
|
|
39 |
#include <fileprotectionresolver.h>
|
|
40 |
|
|
41 |
#include <msgtextutils.h>
|
|
42 |
#include <MsgMimeTypes.h>
|
|
43 |
#include <MsgMediaInfo.h>
|
|
44 |
#include <MsgTextInfo.h>
|
|
45 |
|
|
46 |
#include "UniModelConst.h"
|
|
47 |
#include "UniMimeInfo.h"
|
|
48 |
#include "UniDrmInfo.h"
|
|
49 |
#include "UniObject.h"
|
|
50 |
#include "UniDataUtils.h"
|
|
51 |
|
|
52 |
|
|
53 |
// ========== EXTERNAL DATA STRUCTURES =====================
|
|
54 |
|
|
55 |
// ========== EXTERNAL FUNCTION PROTOTYPES =================
|
|
56 |
|
|
57 |
// ========== CONSTANTS ====================================
|
|
58 |
|
|
59 |
// ========== MACROS =======================================
|
|
60 |
|
|
61 |
// ========== LOCAL CONSTANTS AND MACROS ===================
|
|
62 |
|
|
63 |
// ========== MODULE DATA STRUCTURES =======================
|
|
64 |
|
|
65 |
// ========== LOCAL FUNCTION PROTOTYPES ====================
|
|
66 |
|
|
67 |
// ========== LOCAL FUNCTIONS ==============================
|
|
68 |
|
|
69 |
// ========== MEMBER FUNCTIONS =============================
|
|
70 |
|
|
71 |
// ---------------------------------------------------------
|
|
72 |
// CUniObject::NewLC
|
|
73 |
//
|
|
74 |
// Factory method.
|
|
75 |
// ---------------------------------------------------------
|
|
76 |
//
|
|
77 |
EXPORT_C CUniObject* CUniObject::NewLC( RFs& aFs,
|
|
78 |
CBaseMtm& aMtm,
|
|
79 |
CUniDataUtils& aData,
|
|
80 |
CMsgMediaInfo* aMedia,
|
|
81 |
MMsvAttachmentManager& aManager,
|
|
82 |
CMsvAttachment& aAttachment )
|
|
83 |
{
|
|
84 |
CUniObject* self =
|
|
85 |
new ( ELeave ) CUniObject( aFs, aMtm, aData, aMedia );
|
|
86 |
CleanupStack::PushL( self );
|
|
87 |
self->ConstructL();
|
|
88 |
self->ConstructFromAttachmentL( aManager, aAttachment );
|
|
89 |
return self;
|
|
90 |
}
|
|
91 |
|
|
92 |
// ---------------------------------------------------------
|
|
93 |
// CUniObject::NewL
|
|
94 |
//
|
|
95 |
// Factory method.
|
|
96 |
// ---------------------------------------------------------
|
|
97 |
//
|
|
98 |
EXPORT_C CUniObject* CUniObject::NewL( RFs& aFs,
|
|
99 |
CBaseMtm& aMtm,
|
|
100 |
CUniDataUtils& aData,
|
|
101 |
CMsgMediaInfo* aMedia,
|
|
102 |
MMsvAttachmentManager& aManager,
|
|
103 |
CMsvAttachment& aAttachment )
|
|
104 |
{
|
|
105 |
CUniObject* self = NewLC( aFs, aMtm, aData, aMedia, aManager, aAttachment );
|
|
106 |
CleanupStack::Pop( self );
|
|
107 |
return self;
|
|
108 |
}
|
|
109 |
|
|
110 |
// ---------------------------------------------------------
|
|
111 |
// CUniObject::NewLC
|
|
112 |
//
|
|
113 |
// Factory method.
|
|
114 |
// ---------------------------------------------------------
|
|
115 |
//
|
|
116 |
EXPORT_C CUniObject* CUniObject::NewLC( RFs& aFs,
|
|
117 |
CBaseMtm& aMtm,
|
|
118 |
CUniDataUtils& aData,
|
|
119 |
CMsgMediaInfo* aMedia )
|
|
120 |
{
|
|
121 |
CUniObject* self =
|
|
122 |
new ( ELeave ) CUniObject( aFs, aMtm, aData, aMedia );
|
|
123 |
CleanupStack::PushL( self );
|
|
124 |
self->ConstructL();
|
|
125 |
self->CreateMimeInfoL();
|
|
126 |
return self;
|
|
127 |
}
|
|
128 |
|
|
129 |
// ---------------------------------------------------------
|
|
130 |
// CUniObject::NewL
|
|
131 |
//
|
|
132 |
// Factory method.
|
|
133 |
// ---------------------------------------------------------
|
|
134 |
//
|
|
135 |
EXPORT_C CUniObject* CUniObject::NewL( RFs& aFs,
|
|
136 |
CBaseMtm& aMtm,
|
|
137 |
CUniDataUtils& aData,
|
|
138 |
CMsgMediaInfo* aMedia )
|
|
139 |
{
|
|
140 |
CUniObject* self = NewLC( aFs, aMtm, aData, aMedia );
|
|
141 |
CleanupStack::Pop( self );
|
|
142 |
return self;
|
|
143 |
}
|
|
144 |
|
|
145 |
// ---------------------------------------------------------
|
|
146 |
// CUniObject::CUniObject
|
|
147 |
//
|
|
148 |
// Constructor.
|
|
149 |
// ---------------------------------------------------------
|
|
150 |
//
|
|
151 |
CUniObject::CUniObject( RFs& aFs,
|
|
152 |
CBaseMtm& aMtm,
|
|
153 |
CUniDataUtils& aData,
|
|
154 |
CMsgMediaInfo* aMedia ) :
|
|
155 |
CActive( EPriorityStandard ),
|
|
156 |
iFs( aFs ),
|
|
157 |
iMtm( aMtm ),
|
|
158 |
iData( aData ),
|
|
159 |
iAttachmentId( KMsvNullIndexEntryId ),
|
|
160 |
iMimeInfo( NULL ),
|
|
161 |
iMediaInfo( aMedia ),
|
|
162 |
iReferenceCount( 0 ),
|
|
163 |
iRegion( EUniRegionUnresolved ),
|
|
164 |
iMediaTypeBySmilTag( EMsgMediaUnknown ),
|
|
165 |
iUniqueControlHandle( KErrNotFound )
|
|
166 |
{
|
|
167 |
CActiveScheduler::Add( this );
|
|
168 |
}
|
|
169 |
|
|
170 |
|
|
171 |
// ---------------------------------------------------------
|
|
172 |
// CUniObject::CUniObject
|
|
173 |
//
|
|
174 |
// Destructor.
|
|
175 |
// ---------------------------------------------------------
|
|
176 |
//
|
|
177 |
CUniObject::~CUniObject()
|
|
178 |
{
|
|
179 |
Cancel();
|
|
180 |
if ( iDrmNotifier )
|
|
181 |
{
|
|
182 |
// When one observer left, remove
|
|
183 |
TRAP_IGNORE( iDrmNotifier->UnRegisterEventObserverL( *this,
|
|
184 |
KEventAddRemove,
|
|
185 |
*iMediaInfo->DRMContentURI() ) );
|
|
186 |
TRAP_IGNORE( iDrmNotifier->UnRegisterEventObserverL( *this,
|
|
187 |
KEventModify,
|
|
188 |
*iMediaInfo->DRMContentURI() ) );
|
|
189 |
}
|
|
190 |
delete iEditStore;
|
|
191 |
delete iDrmInfo;
|
|
192 |
delete iMediaInfo;
|
|
193 |
delete iMimeInfo;
|
|
194 |
|
|
195 |
iFileHandle.Close();
|
|
196 |
delete iDrmNotifier;
|
|
197 |
delete iObservers;
|
|
198 |
}
|
|
199 |
|
|
200 |
// ---------------------------------------------------------
|
|
201 |
// CUniObject::Save
|
|
202 |
// ---------------------------------------------------------
|
|
203 |
//
|
|
204 |
void CUniObject::Save( MUniObjectSaveObserver& aObserver,
|
|
205 |
CMsvAttachment::TMsvAttachmentType aSaveType )
|
|
206 |
{
|
|
207 |
iObserver = &aObserver;
|
|
208 |
iSaveType = aSaveType;
|
|
209 |
iSaveState = EObjectSavingIdle;
|
|
210 |
CompleteSelf();
|
|
211 |
}
|
|
212 |
|
|
213 |
// ---------------------------------------------------------
|
|
214 |
// CUniObject::DoSaveL
|
|
215 |
// ---------------------------------------------------------
|
|
216 |
//
|
|
217 |
void CUniObject::DoSaveL()
|
|
218 |
{
|
|
219 |
switch ( iSaveState )
|
|
220 |
{
|
|
221 |
case EObjectSavingIdle:
|
|
222 |
{
|
|
223 |
StartObjectSaveL();
|
|
224 |
break;
|
|
225 |
}
|
|
226 |
case EObjectCreatingAttachment:
|
|
227 |
{
|
|
228 |
FinalizeObjectSaveL();
|
|
229 |
break;
|
|
230 |
}
|
|
231 |
default:
|
|
232 |
break;
|
|
233 |
}
|
|
234 |
}
|
|
235 |
|
|
236 |
// ---------------------------------------------------------
|
|
237 |
// CUniObject::InitializeObjectSaveL
|
|
238 |
// ---------------------------------------------------------
|
|
239 |
//
|
|
240 |
void CUniObject::StartObjectSaveL()
|
|
241 |
{
|
|
242 |
if ( iAttachmentId != KMsvNullIndexEntryId )
|
|
243 |
{
|
|
244 |
if ( iSaveType == CMsvAttachment::EMsvLinkedFile )
|
|
245 |
{
|
|
246 |
iObserver->ObjectSaveReady( KErrNone );
|
|
247 |
return;
|
|
248 |
}
|
|
249 |
else
|
|
250 |
{
|
|
251 |
CMsvStore* readStore = iMtm.Entry().ReadStoreL();
|
|
252 |
MMsvAttachmentManager& manager = readStore->AttachmentManagerL();
|
|
253 |
CleanupStack::PushL( readStore );
|
|
254 |
CMsvAttachment* attachment = manager.GetAttachmentInfoL( iAttachmentId );
|
|
255 |
CMsvAttachment::TMsvAttachmentType type = attachment->Type();
|
|
256 |
delete attachment;
|
|
257 |
CleanupStack::PopAndDestroy( readStore );
|
|
258 |
if ( type == CMsvAttachment::EMsvLinkedFile )
|
|
259 |
{
|
|
260 |
// Remove the "linked attachment" from store & create new "file attachment"
|
|
261 |
RemoveFromStoreL();
|
|
262 |
CreateAttachmentL();
|
|
263 |
}
|
|
264 |
else
|
|
265 |
{
|
|
266 |
// Already a "file attachment"
|
|
267 |
iObserver->ObjectSaveReady( KErrNone );
|
|
268 |
return;
|
|
269 |
}
|
|
270 |
}
|
|
271 |
}
|
|
272 |
else
|
|
273 |
{
|
|
274 |
// Create new attachment
|
|
275 |
CreateAttachmentL();
|
|
276 |
}
|
|
277 |
}
|
|
278 |
|
|
279 |
|
|
280 |
// ---------------------------------------------------------
|
|
281 |
// CUniObject::InitializeObjectSaveL
|
|
282 |
// ---------------------------------------------------------
|
|
283 |
//
|
|
284 |
void CUniObject::FinalizeObjectSaveL()
|
|
285 |
{
|
|
286 |
// TODO: Cleanup attachment in some cases?
|
|
287 |
// -> Just use Revert() instead of CommitL()?
|
|
288 |
iAttachmentId = iAttachment->Id();
|
|
289 |
iMimeInfo->SaveMimeInfoL( *iManager, *iAttachment );
|
|
290 |
|
|
291 |
CMsvAttachment::TMsvAttachmentType type = iAttachment->Type();
|
|
292 |
if ( type == CMsvAttachment::EMsvLinkedFile )
|
|
293 |
{
|
|
294 |
iFileHandle.Close();
|
|
295 |
iFileHandle = iManager->GetAttachmentFileL( iAttachmentId );
|
|
296 |
}
|
|
297 |
|
|
298 |
iAttachment = NULL;
|
|
299 |
iEditStore->CommitL();
|
|
300 |
|
|
301 |
if ( iSaveType == CMsvAttachment::EMsvFile )
|
|
302 |
{
|
|
303 |
// Update media info
|
|
304 |
RFile attachmentFile = iManager->GetAttachmentFileL( iAttachmentId );
|
|
305 |
CleanupClosePushL( attachmentFile );
|
|
306 |
iMediaInfo->SetFileL( attachmentFile );
|
|
307 |
CleanupStack::PopAndDestroy( &attachmentFile );
|
|
308 |
}
|
|
309 |
|
|
310 |
delete iEditStore;
|
|
311 |
iEditStore = NULL;
|
|
312 |
iManager = NULL;
|
|
313 |
|
|
314 |
//DoSaveL();
|
|
315 |
iObserver->ObjectSaveReady( KErrNone );
|
|
316 |
}
|
|
317 |
|
|
318 |
|
|
319 |
// ---------------------------------------------------------
|
|
320 |
// CUniObject::CreateAttachmentL
|
|
321 |
//
|
|
322 |
// Create attachment to message store
|
|
323 |
// ---------------------------------------------------------
|
|
324 |
//
|
|
325 |
void CUniObject::CreateAttachmentL()
|
|
326 |
{
|
|
327 |
if ( !( iMediaInfo->FullFilePath().Length() ) )
|
|
328 |
{
|
|
329 |
User::Leave( KErrNotSupported );
|
|
330 |
}
|
|
331 |
TParsePtrC fileParse( iMediaInfo->FullFilePath() );
|
|
332 |
|
|
333 |
iEditStore = iMtm.Entry().EditStoreL();
|
|
334 |
iManager = &( iEditStore->AttachmentManagerL() );
|
|
335 |
CMsvAttachment* attachment = CMsvAttachment::NewL( iSaveType );
|
|
336 |
CleanupStack::PushL( attachment );
|
|
337 |
|
|
338 |
attachment->SetSize( iMediaInfo->FileSize() );
|
|
339 |
attachment->SetMimeTypeL( iMimeInfo->ContentType() );
|
|
340 |
//TODO: Set complete flag?
|
|
341 |
//attachment->SetComplete( iSaveType != EHiddenSave );
|
|
342 |
|
|
343 |
attachment->SetIntAttributeL( KUidAttachmentIndication, Attachment() );
|
|
344 |
|
|
345 |
if ( iSaveType == CMsvAttachment::EMsvLinkedFile )
|
|
346 |
{
|
|
347 |
iManager->AddLinkedAttachmentL( fileParse.FullName(), attachment, iStatus );
|
|
348 |
}
|
|
349 |
else
|
|
350 |
{
|
|
351 |
iManager->AddAttachmentL( fileParse.FullName(), attachment, iStatus );
|
|
352 |
}
|
|
353 |
|
|
354 |
CleanupStack::Pop( attachment );
|
|
355 |
iAttachment = attachment;
|
|
356 |
iSaveState = EObjectCreatingAttachment;
|
|
357 |
SetActive();
|
|
358 |
}
|
|
359 |
|
|
360 |
// ---------------------------------------------------------
|
|
361 |
// CUniObject::SetVisibleL
|
|
362 |
//
|
|
363 |
// Set "Visible" and "InPreparation" flags
|
|
364 |
// ---------------------------------------------------------
|
|
365 |
//
|
|
366 |
/*
|
|
367 |
void CUniObject::SetHiddenL( TBool aHidden )
|
|
368 |
{
|
|
369 |
// TODO: Use Complete flag?!
|
|
370 |
|
|
371 |
if ( iAttachmentId == KMsvNullIndexEntryId )
|
|
372 |
{
|
|
373 |
return;
|
|
374 |
}
|
|
375 |
CMsvEntry* cAttEntry = iMtm.Entry().ChildEntryL( iAttachmentId );
|
|
376 |
CleanupStack::PushL( cAttEntry );
|
|
377 |
TMsvEntry tAttEntry = cAttEntry->Entry();
|
|
378 |
tAttEntry.SetInPreparation( aHidden );
|
|
379 |
cAttEntry->ChangeL( tAttEntry );
|
|
380 |
CleanupStack::PopAndDestroy( cAttEntry );
|
|
381 |
}
|
|
382 |
*/
|
|
383 |
|
|
384 |
|
|
385 |
// ---------------------------------------------------------
|
|
386 |
// CUniObject::RemoveFromStoreL
|
|
387 |
//
|
|
388 |
// Remove from store.
|
|
389 |
// ---------------------------------------------------------
|
|
390 |
//
|
|
391 |
void CUniObject::RemoveFromStoreL()
|
|
392 |
{
|
|
393 |
if ( iAttachmentId == KMsvNullIndexEntryId )
|
|
394 |
{
|
|
395 |
return;
|
|
396 |
}
|
|
397 |
|
|
398 |
iFileHandle.Close();
|
|
399 |
|
|
400 |
CMsvStore* store = iMtm.Entry().EditStoreL();
|
|
401 |
CleanupStack::PushL( store );
|
|
402 |
MMsvAttachmentManager& manager = store->AttachmentManagerL();
|
|
403 |
MMsvAttachmentManagerSync& managerSync = store->AttachmentManagerExtensionsL();
|
|
404 |
managerSync.RemoveAttachmentL( CUniDataUtils::IndexPositionOfAttachmentL( manager, iAttachmentId ) );
|
|
405 |
store->CommitL();
|
|
406 |
CleanupStack::PopAndDestroy( store );
|
|
407 |
iAttachmentId = KMsvNullIndexEntryId;
|
|
408 |
}
|
|
409 |
|
|
410 |
|
|
411 |
// ---------------------------------------------------------
|
|
412 |
// CUniObject::CreateMimeInfoL
|
|
413 |
//
|
|
414 |
// ---------------------------------------------------------
|
|
415 |
//
|
|
416 |
void CUniObject::CreateMimeInfoL()
|
|
417 |
{
|
|
418 |
// Content-type
|
|
419 |
iMimeInfo->SetContentTypeL( iMediaInfo->MimeType() );
|
|
420 |
|
|
421 |
HBufC* fileName = NULL;
|
|
422 |
if ( iMediaInfo->FullFilePath().Length() )
|
|
423 |
{
|
|
424 |
TParsePtrC parse( iMediaInfo->FullFilePath() );
|
|
425 |
fileName = parse.NameAndExt().AllocLC();
|
|
426 |
}
|
|
427 |
|
|
428 |
if ( fileName )
|
|
429 |
{
|
|
430 |
// Content-location
|
|
431 |
TPtr ptr = fileName->Des();
|
|
432 |
CMsgTextUtils::TrimAndRemoveNonAlphaDigit( ptr );
|
|
433 |
iMimeInfo->SetContentLocationL( *fileName );
|
|
434 |
CleanupStack::PopAndDestroy( fileName );
|
|
435 |
|
|
436 |
// Character set. Recognize charset if atta is text.
|
|
437 |
if ( iMediaInfo->MediaType() == EMsgMediaText ||
|
|
438 |
iMediaInfo->MediaType() == EMsgMediaXhtml )
|
|
439 |
{
|
|
440 |
CMsgTextInfo* info = static_cast<CMsgTextInfo*>( iMediaInfo );
|
|
441 |
TUint charConvCharset = info->CharacterSet();
|
|
442 |
TUint mibCharset( 0 );
|
|
443 |
if ( charConvCharset == 0 )
|
|
444 |
{
|
|
445 |
// UCS2
|
|
446 |
mibCharset = KCharacterSetMIBEnumIso10646Ucs2;
|
|
447 |
}
|
|
448 |
else
|
|
449 |
{
|
|
450 |
mibCharset = iData.CharconvIdToMibIdL( charConvCharset );
|
|
451 |
}
|
|
452 |
iMimeInfo->SetCharset( mibCharset );
|
|
453 |
}
|
|
454 |
}
|
|
455 |
}
|
|
456 |
|
|
457 |
// ---------------------------------------------------------
|
|
458 |
// CUniObject::Size
|
|
459 |
//
|
|
460 |
// Accessor.
|
|
461 |
// ---------------------------------------------------------
|
|
462 |
//
|
|
463 |
TInt CUniObject::Size( TBool aWithoutHeaders )
|
|
464 |
{
|
|
465 |
return ( aWithoutHeaders
|
|
466 |
? iMediaInfo->FileSize()
|
|
467 |
: iMediaInfo->FileSize() + iMimeInfo->Size() );
|
|
468 |
}
|
|
469 |
|
|
470 |
// ---------------------------------------------------------
|
|
471 |
// CUniObject::MimeType
|
|
472 |
// ---------------------------------------------------------
|
|
473 |
//
|
|
474 |
EXPORT_C TPtrC8 CUniObject::MimeType() const
|
|
475 |
{
|
|
476 |
if ( iMediaInfo->MediaType() == EMsgMediaAudio ||
|
|
477 |
iMediaInfo->MediaType() == EMsgMediaImage ||
|
|
478 |
iMediaInfo->MediaType() == EMsgMediaVideo ||
|
|
479 |
#ifdef RD_SVGT_IN_MESSAGING
|
|
480 |
iMediaInfo->MediaType() == EMsgMediaSvg ||
|
|
481 |
#endif
|
|
482 |
#ifdef RD_MSG_XHTML_SUPPORT
|
|
483 |
iMediaInfo->MediaType() == EMsgMediaXhtml ||
|
|
484 |
#endif
|
|
485 |
( iMediaInfo->Protection() &
|
|
486 |
( EFileProtForwardLocked | EFileProtSuperDistributable ) ) )
|
|
487 |
{
|
|
488 |
return iMediaInfo->MimeType();
|
|
489 |
}
|
|
490 |
else
|
|
491 |
{
|
|
492 |
return iMimeInfo->ContentType();
|
|
493 |
}
|
|
494 |
}
|
|
495 |
|
|
496 |
// ---------------------------------------------------------
|
|
497 |
// CUniObject::MediaType
|
|
498 |
// ---------------------------------------------------------
|
|
499 |
//
|
|
500 |
EXPORT_C TMsgMediaType CUniObject::MediaType() const
|
|
501 |
{
|
|
502 |
if ( iMediaInfo->MediaType() == EMsgMediaText &&
|
|
503 |
iMimeInfo->ContentType().CompareF( KMsgMimeTextPlain ) != 0 )
|
|
504 |
{
|
|
505 |
return EMsgMediaUnknown;
|
|
506 |
}
|
|
507 |
else
|
|
508 |
{
|
|
509 |
return iMediaInfo->MediaType();
|
|
510 |
}
|
|
511 |
}
|
|
512 |
|
|
513 |
// ---------------------------------------------------------
|
|
514 |
// CUniObject::ConstructL
|
|
515 |
//
|
|
516 |
// 2nd phase constructor.
|
|
517 |
// ---------------------------------------------------------
|
|
518 |
//
|
|
519 |
void CUniObject::ConstructL()
|
|
520 |
{
|
|
521 |
iMimeInfo = new ( ELeave ) CUniMimeInfo;
|
|
522 |
|
|
523 |
if ( iMediaInfo )
|
|
524 |
{
|
|
525 |
if ( iMediaInfo->Corrupt() )
|
|
526 |
{
|
|
527 |
SetCorrupted( ETrue );
|
|
528 |
}
|
|
529 |
|
|
530 |
if ( iMediaInfo->DRMContentURI() )
|
|
531 |
{
|
|
532 |
iDrmInfo = CUniDrmInfo::NewL( iFs, iMtm, iAttachmentId, *iMediaInfo );
|
|
533 |
iDrmNotifier = CDRMNotifier::NewL( );
|
|
534 |
iDrmNotifier->RegisterEventObserverL( *this,
|
|
535 |
KEventAddRemove,
|
|
536 |
*iMediaInfo->DRMContentURI() );
|
|
537 |
iDrmNotifier->RegisterEventObserverL( *this,
|
|
538 |
KEventModify,
|
|
539 |
*iMediaInfo->DRMContentURI() );
|
|
540 |
}
|
|
541 |
}
|
|
542 |
|
|
543 |
iObservers = new( ELeave ) CArrayPtrFlat<MUniObjectObserver>( 1 );
|
|
544 |
|
|
545 |
}
|
|
546 |
|
|
547 |
// ---------------------------------------------------------
|
|
548 |
// CUniObject::ConstructFromAttachmentL
|
|
549 |
//
|
|
550 |
// 2nd phase constructor.
|
|
551 |
// ---------------------------------------------------------
|
|
552 |
//
|
|
553 |
void CUniObject::ConstructFromAttachmentL(
|
|
554 |
MMsvAttachmentManager& aManager,
|
|
555 |
CMsvAttachment& aAttachment )
|
|
556 |
{
|
|
557 |
iAttachmentId = aAttachment.Id();
|
|
558 |
TPtrC8 dummy;
|
|
559 |
TInt err = aAttachment.GetDesC8Attribute( KUidMimeHeaders, dummy );
|
|
560 |
if( err == KErrNone )
|
|
561 |
{
|
|
562 |
iMimeInfo->ReadMimeInfoL( aAttachment );
|
|
563 |
|
|
564 |
if ( iMediaInfo->MediaType() == EMsgMediaText )
|
|
565 |
{
|
|
566 |
TUint mibCharset = iMimeInfo->Charset();
|
|
567 |
if ( !mibCharset )
|
|
568 |
{
|
|
569 |
//assume US-ASCII - mandated by RFC 2046
|
|
570 |
mibCharset = KCharacterSetMIBEnumUsAscii;
|
|
571 |
}
|
|
572 |
TUint charConvCharset = iData.MibIdToCharconvIdL( mibCharset );
|
|
573 |
|
|
574 |
CMsgTextInfo* info = static_cast<CMsgTextInfo*>( iMediaInfo );
|
|
575 |
info->SetCharacterSet( charConvCharset );
|
|
576 |
}
|
|
577 |
|
|
578 |
//iStoreState = EMmsStoreStateAttachment;
|
|
579 |
}
|
|
580 |
else
|
|
581 |
{
|
|
582 |
CreateMimeInfoL();
|
|
583 |
aAttachment.SetMimeTypeL( iMimeInfo->ContentType() );
|
|
584 |
iMimeInfo->SaveMimeInfoL( aManager, aAttachment );
|
|
585 |
// TODO: Set hidden
|
|
586 |
//SetHiddenL( ETrue );
|
|
587 |
//iStoreState = EMmsStoreStateHidden;
|
|
588 |
//iStoreState = EMmsStoreStateAttachment;
|
|
589 |
}
|
|
590 |
|
|
591 |
TInt isAttachment( 0 );
|
|
592 |
err = aAttachment.GetIntAttribute( KUidAttachmentIndication, isAttachment );
|
|
593 |
|
|
594 |
if ( err == KErrNone )
|
|
595 |
{
|
|
596 |
SetAttachment( isAttachment );
|
|
597 |
}
|
|
598 |
|
|
599 |
iSaveType = aAttachment.Type();
|
|
600 |
if ( iSaveType == CMsvAttachment::EMsvLinkedFile )
|
|
601 |
{
|
|
602 |
iFileHandle = aManager.GetAttachmentFileL( iAttachmentId );
|
|
603 |
}
|
|
604 |
}
|
|
605 |
|
|
606 |
// ---------------------------------------------------------
|
|
607 |
// CUniObject::DoCancel
|
|
608 |
//
|
|
609 |
// ---------------------------------------------------------
|
|
610 |
//
|
|
611 |
void CUniObject::DoCancel()
|
|
612 |
{
|
|
613 |
if ( iManager )
|
|
614 |
{
|
|
615 |
iManager->CancelRequest();
|
|
616 |
}
|
|
617 |
}
|
|
618 |
|
|
619 |
// ---------------------------------------------------------
|
|
620 |
// CUniObject::RunL
|
|
621 |
//
|
|
622 |
// ---------------------------------------------------------
|
|
623 |
//
|
|
624 |
void CUniObject::RunL()
|
|
625 |
{
|
|
626 |
DoSaveL();
|
|
627 |
}
|
|
628 |
|
|
629 |
// ---------------------------------------------------------
|
|
630 |
// CUniObject::RunError
|
|
631 |
//
|
|
632 |
// ---------------------------------------------------------
|
|
633 |
//
|
|
634 |
TInt CUniObject::RunError( TInt aError )
|
|
635 |
{
|
|
636 |
delete iEditStore;
|
|
637 |
iEditStore = NULL;
|
|
638 |
iManager = NULL;
|
|
639 |
iAttachmentId = NULL;
|
|
640 |
|
|
641 |
iObserver->ObjectSaveReady( aError );
|
|
642 |
return KErrNone;
|
|
643 |
}
|
|
644 |
|
|
645 |
// ---------------------------------------------------------
|
|
646 |
// CUniObject::CompleteSelf
|
|
647 |
//
|
|
648 |
// ---------------------------------------------------------
|
|
649 |
//
|
|
650 |
void CUniObject::CompleteSelf()
|
|
651 |
{
|
|
652 |
iStatus = KRequestPending;
|
|
653 |
TRequestStatus* pStatus = &iStatus;
|
|
654 |
SetActive();
|
|
655 |
User::RequestComplete( pStatus, KErrNone );
|
|
656 |
}
|
|
657 |
|
|
658 |
|
|
659 |
// ---------------------------------------------------------
|
|
660 |
// CUniObject::ResolveDrmRightsWhenLoadedL
|
|
661 |
//
|
|
662 |
// ---------------------------------------------------------
|
|
663 |
//
|
|
664 |
EXPORT_C void CUniObject::ResolveDrmRightsWhenLoadedL()
|
|
665 |
{
|
|
666 |
iObjectFlags &= ~EObjectDrmRightsWhenLoaded;
|
|
667 |
|
|
668 |
if ( iDrmInfo )
|
|
669 |
{
|
|
670 |
TBool alreadyConsumed( EFalse );
|
|
671 |
TBool result = ( iDrmInfo->EvaluateRights( alreadyConsumed ) == KErrNone ? ETrue :
|
|
672 |
EFalse );
|
|
673 |
if ( alreadyConsumed
|
|
674 |
|| result )
|
|
675 |
{
|
|
676 |
iObjectFlags |= EObjectDrmRightsWhenLoaded;
|
|
677 |
}
|
|
678 |
}
|
|
679 |
|
|
680 |
}
|
|
681 |
|
|
682 |
// ---------------------------------------------------------
|
|
683 |
// CUniObject::SetDrmRightsWhenLoaded
|
|
684 |
//
|
|
685 |
// ---------------------------------------------------------
|
|
686 |
//
|
|
687 |
EXPORT_C void CUniObject::SetDrmRightsWhenLoaded( TBool aRights )
|
|
688 |
{
|
|
689 |
aRights ? ( iObjectFlags |= EObjectDrmRightsWhenLoaded ) : ( iObjectFlags &= ~EObjectDrmRightsWhenLoaded );
|
|
690 |
}
|
|
691 |
|
|
692 |
// ---------------------------------------------------------
|
|
693 |
// CUniObject::SetDrmRightsWhenLoadedObjects
|
|
694 |
//
|
|
695 |
// ---------------------------------------------------------
|
|
696 |
//
|
|
697 |
EXPORT_C void CUniObject::SetDrmRightsWhenLoadedObjects( TBool aRights )
|
|
698 |
{
|
|
699 |
aRights ? ( iObjectFlags |= EObjectDrmRightsWhenLoadedObjects ) : ( iObjectFlags &= ~EObjectDrmRightsWhenLoadedObjects );
|
|
700 |
}
|
|
701 |
|
|
702 |
|
|
703 |
// ---------------------------------------------------------
|
|
704 |
// CUniObject::HandleEventL from MDRMEventObserver
|
|
705 |
//
|
|
706 |
// ---------------------------------------------------------
|
|
707 |
//
|
|
708 |
void CUniObject::HandleEventL( MDRMEvent* aEvent )
|
|
709 |
{
|
|
710 |
TDRMEventType event = KEventNone;
|
|
711 |
if ( aEvent )
|
|
712 |
{
|
|
713 |
aEvent->GetEventType( event );
|
|
714 |
|
|
715 |
switch ( event )
|
|
716 |
{
|
|
717 |
case KEventNone:
|
|
718 |
break;
|
|
719 |
case KEventAddRemove:
|
|
720 |
case KEventModify:
|
|
721 |
case KEventTimeChange:
|
|
722 |
default:
|
|
723 |
{
|
|
724 |
for ( TInt current = 0; current < iObservers->Count(); current++ )
|
|
725 |
{
|
|
726 |
if ( iObservers->At( current ) )
|
|
727 |
{
|
|
728 |
iObservers->At( current )->HandleUniObjectEvent(
|
|
729 |
*this,
|
|
730 |
EUniObjectEventDrmRightsChanged );
|
|
731 |
}
|
|
732 |
}
|
|
733 |
}
|
|
734 |
}
|
|
735 |
}
|
|
736 |
}
|
|
737 |
|
|
738 |
// ---------------------------------------------------------
|
|
739 |
// CUniObject::SetObserverL
|
|
740 |
//
|
|
741 |
// ---------------------------------------------------------
|
|
742 |
//
|
|
743 |
EXPORT_C void CUniObject::SetObserverL( MUniObjectObserver* aObserver )
|
|
744 |
{
|
|
745 |
iObservers->AppendL( aObserver );
|
|
746 |
}
|
|
747 |
|
|
748 |
// ---------------------------------------------------------
|
|
749 |
// CUniObject::RemoveObserver
|
|
750 |
//
|
|
751 |
// ---------------------------------------------------------
|
|
752 |
//
|
|
753 |
EXPORT_C void CUniObject::RemoveObserver( MUniObjectObserver* aObserver )
|
|
754 |
{
|
|
755 |
for ( TInt current = 0; current < iObservers->Count(); current++ )
|
|
756 |
{
|
|
757 |
if ( iObservers->At( current ) == aObserver )
|
|
758 |
{
|
|
759 |
iObservers->Delete( current );
|
|
760 |
break;
|
|
761 |
}
|
|
762 |
}
|
|
763 |
}
|
|
764 |
|
|
765 |
// ---------------------------------------------------------
|
|
766 |
// CUniObject::IsValid
|
|
767 |
//
|
|
768 |
// ---------------------------------------------------------
|
|
769 |
//
|
|
770 |
EXPORT_C TBool CUniObject::IsValid() const
|
|
771 |
{
|
|
772 |
TBool bFlag = ETrue;
|
|
773 |
if ( iSaveType == CMsvAttachment::EMsvLinkedFile )
|
|
774 |
{
|
|
775 |
TParsePtrC fileParse( iMediaInfo->FullFilePath() );
|
|
776 |
|
|
777 |
RFile file;
|
|
778 |
TInt err = file.Open( iFs, fileParse.FullName(), EFileShareAny );
|
|
779 |
|
|
780 |
if(err == KErrNotReady)
|
|
781 |
{
|
|
782 |
bFlag = EFalse;
|
|
783 |
}
|
|
784 |
if(err == KErrNone)
|
|
785 |
{
|
|
786 |
file.Close();
|
|
787 |
}
|
|
788 |
}
|
|
789 |
return bFlag;
|
|
790 |
}
|
|
791 |
|
|
792 |
// EOF
|