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