messagingapp/msgutils/unidatautils/unidatamodel/inc/UniObject.h
changeset 25 84d9eb65b26f
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 #ifndef __UNIOBJECT_H
       
    22 #define __UNIOBJECT_H
       
    23 
       
    24 // INCLUDES
       
    25 
       
    26 #include <e32std.h>
       
    27 #include <msvstd.h>     // for TMsvId
       
    28 #include <cmsvattachment.h>
       
    29 
       
    30 #include <DRMEvent.h>
       
    31 #include <DRMEventObserver.h>
       
    32 
       
    33 #include <MsgMedia.hrh>
       
    34 
       
    35 #include <UniModelConst.h>
       
    36 
       
    37 // CONSTANTS
       
    38 const TUid KUidAttachmentIndication = {0x10282CB0};
       
    39 
       
    40 // MACROS
       
    41 
       
    42 // FORWARD DECLARATIONS
       
    43 class CUniMimeInfo;
       
    44 class CMsgMediaInfo;
       
    45 class CUniDrmInfo;
       
    46 class CBaseMtm;
       
    47 class CUniDataUtils;
       
    48 class CMsvStore;
       
    49 class MMsvAttachmentManager;
       
    50 class CUniObject;
       
    51 class CDRMNotifier;
       
    52 // DATA TYPES
       
    53 
       
    54 // FUNCTION PROTOTYPES
       
    55 
       
    56 // CLASS DECLARATION
       
    57 
       
    58 /**
       
    59 * MUniObjectSaveObserver - Callback API for object saving.
       
    60 *
       
    61 * @since 3.1
       
    62 */
       
    63 class MUniObjectSaveObserver
       
    64     {
       
    65     public:
       
    66         virtual void ObjectSaveReady( TInt aError ) = 0;
       
    67     };
       
    68 
       
    69 enum TUniObjectEvent
       
    70     {
       
    71 	EUniObjectEventDrmRightsChanged = 0
       
    72     };
       
    73 
       
    74 class MUniObjectObserver
       
    75     {
       
    76     public:
       
    77         virtual void HandleUniObjectEvent(  CUniObject&  aUniObject,
       
    78                                             TUniObjectEvent aUniEvent ) = 0;
       
    79     };
       
    80 
       
    81 /**
       
    82 * CUniObject - Representation of a single attachment of a message.
       
    83 *
       
    84 * @lib UniDataModel.lib
       
    85 * @since 3.1
       
    86 */
       
    87 class CUniObject : public CActive,
       
    88                    public MDRMEventObserver
       
    89 
       
    90     {
       
    91 
       
    92     public:  // New methods
       
    93 
       
    94         /**
       
    95         * Factory method that creates this object
       
    96         * from an attachment.
       
    97         *
       
    98         * @since    3.1
       
    99         * @param    aMtm    IN reference to client mtm
       
   100         * @param    aMedia  IN initialized media info object - takes ownership!
       
   101         * @param    aManager        IN reference to attachment manager
       
   102         * @param    aAttachmentId   IN id of the attachment from
       
   103         *                           which to create the object
       
   104         * @return   Pointer to instance in cleanup stack
       
   105         */
       
   106         IMPORT_C static CUniObject* NewLC(
       
   107             RFs& aFs,
       
   108             CBaseMtm& aMtm,
       
   109             CUniDataUtils& aData,
       
   110             CMsgMediaInfo* aMedia,
       
   111             MMsvAttachmentManager& aManager,
       
   112             CMsvAttachment& aAttachment );
       
   113 
       
   114         /**
       
   115         * Factory method that creates this object
       
   116         * from an attachment.
       
   117         *
       
   118         * @since    3.1
       
   119         * @param    aMtm    IN reference to client mtm
       
   120         * @param    aMedia  IN initialized media info object - takes ownership!
       
   121         * @param    aAttachmentId   IN id of the attachment from
       
   122         *                           which to create the object
       
   123         * @return   Pointer to instance
       
   124         */
       
   125         IMPORT_C static CUniObject* NewL(
       
   126             RFs& aFs,
       
   127             CBaseMtm& aMtm,
       
   128             CUniDataUtils& aData,
       
   129             CMsgMediaInfo* aMedia,
       
   130             MMsvAttachmentManager& aManager,
       
   131             CMsvAttachment& aAttachment );
       
   132 
       
   133         /**
       
   134         * Factory method that creates this object
       
   135         * from a file.
       
   136         *
       
   137         * @since    3.1
       
   138         * @param    aData   IN reference to MsgData object
       
   139         * @param    aMedia  IN initialized media info object - takes ownership!
       
   140         * @return   Pointer to instance in cleanup stack
       
   141         */
       
   142         IMPORT_C static CUniObject* NewLC(
       
   143             RFs& aFs,
       
   144             CBaseMtm& aMtm,
       
   145             CUniDataUtils& aData,
       
   146             CMsgMediaInfo* aMedia );
       
   147 
       
   148         /**
       
   149         * Factory method that creates this object
       
   150         * from a file.
       
   151         *
       
   152         * @since    3.1
       
   153         * @param    aData   IN reference to MsgData object
       
   154         * @param    aMedia  IN initialized media info object - takes ownership!
       
   155         * @return   Pointer to instance
       
   156         */
       
   157         IMPORT_C static CUniObject* NewL(
       
   158             RFs& aFs,
       
   159             CBaseMtm& aMtm,
       
   160             CUniDataUtils& aData,
       
   161             CMsgMediaInfo* aMedia );
       
   162 
       
   163         /**
       
   164         * Destructor
       
   165         *
       
   166         * @since    3.1
       
   167         */
       
   168         virtual ~CUniObject();
       
   169 
       
   170         /**
       
   171         * Save
       
   172         * Save the object to message store.
       
   173         * If leave occurs, attachment is cleaned up from the
       
   174         * message store.
       
   175         *
       
   176         * @since    3.1
       
   177         * @param    aObserver   IN operation observer
       
   178         * @param    aSaveType   IN save type
       
   179         */
       
   180         virtual void Save(
       
   181             MUniObjectSaveObserver& aObserver,
       
   182             CMsvAttachment::TMsvAttachmentType aSaveType );
       
   183 
       
   184         /**
       
   185         * Remove from store
       
   186         * Removes attachment from message store.
       
   187         *
       
   188         * @since    3.1
       
   189         * @param    aMtm    IN reference to MMS client mtm
       
   190         */
       
   191         virtual void RemoveFromStoreL();
       
   192 
       
   193         /**
       
   194         * AttachmentId
       
   195         * Accessor.
       
   196         *
       
   197         * @since    3.1
       
   198         * @return   Attachment id of the object
       
   199         */
       
   200         inline TMsvAttachmentId AttachmentId() const;
       
   201 
       
   202         /**
       
   203         * MimeInfo
       
   204         * Accessor.
       
   205         *
       
   206         * @since    3.1
       
   207         * @return   Pointer to the object's mime header class
       
   208         */
       
   209         inline CUniMimeInfo* MimeInfo() const;
       
   210 
       
   211         /**
       
   212         * DrmInfo
       
   213         * Accessor.
       
   214         *
       
   215         * @since    3.1
       
   216         * @return   Pointer to the object's mime header class
       
   217         */
       
   218         inline CUniDrmInfo* DrmInfo() const;
       
   219 
       
   220         /**
       
   221         * MimeType
       
   222         * Returns the mime type of the object. Use this instead
       
   223         * of MimeInfo's or MediaInfo's mime type unless you are
       
   224         * absolutely sure what you are doing.
       
   225         *
       
   226         * @since    3.1
       
   227         * @return   Mime type of the object.
       
   228         */
       
   229         IMPORT_C TPtrC8 MimeType() const;
       
   230 
       
   231         /**
       
   232         * MediaInfo
       
   233         * Accessor.
       
   234         *
       
   235         * @since    3.1
       
   236         * @return   Pointer to the object's media info class
       
   237         */
       
   238         inline CMsgMediaInfo* MediaInfo() const;
       
   239 
       
   240         /**
       
   241         * MediaType
       
   242         * Returns the media type of the object. Use this instead
       
   243         * of MediaInfo's media type unless you are absolutely
       
   244         * sure what you are doing.
       
   245         *
       
   246         * @since    3.1
       
   247         * @return   Media type of the object.
       
   248         */
       
   249         IMPORT_C TMsgMediaType MediaType() const;
       
   250 
       
   251         /*
       
   252         * Size
       
   253         *
       
   254         * @since    3.1
       
   255         * @param    aWithoutHeaders IN if ETrue include MIME headers' sizes
       
   256         *                           if EFalse count only file sizes
       
   257         * @return   Size of the object in bytes
       
   258         */
       
   259         virtual TInt Size( TBool aWithoutHeaders = ETrue );
       
   260 
       
   261         /**
       
   262         * Corrupted
       
   263         * Accessor.
       
   264         *
       
   265         * @since    3.1
       
   266         * @return   ETrue, if object corrupted,
       
   267         *           EFalse otherwise
       
   268         */
       
   269         inline TBool Corrupted() const;
       
   270 
       
   271         /**
       
   272         * SetCorrupted
       
   273         * Mutator.
       
   274         *
       
   275         * @since    3.1
       
   276         * @param    aCorrupted  IN ETrue to mark object corrupted
       
   277         */
       
   278         inline void SetCorrupted( TBool aCorrupted );
       
   279 
       
   280         /**
       
   281         * StoreState
       
   282         * Accessor.
       
   283         *
       
   284         * @since    3.1
       
   285         * @return   Store state of the object:
       
   286         *           EStoreStateAttachment if object is stored into message store and "visible"
       
   287         *           EStoreStateTemporary if is not yet in message store
       
   288         *           EStoreStateHidden if object is stored into message store and "hidden"
       
   289         */
       
   290         //inline TMsgObjectStoreState StoreState() const;
       
   291 
       
   292         /**
       
   293         * SetReferenceCount
       
   294         * Mutator.
       
   295         *
       
   296         * @since    3.1
       
   297         * @param    aCount  IN number of times the object is referenced in
       
   298         *                   the message (normally in the SMIL).
       
   299         */
       
   300         inline void SetReferenceCount( TInt aCount );
       
   301 
       
   302         /**
       
   303         * ReferenceCount
       
   304         * Accessor.
       
   305         *
       
   306         * @since    3.1
       
   307         * @return   Number of times the object is referenced in
       
   308         *           the message (normally in the SMIL).
       
   309         */
       
   310         inline TInt ReferenceCount() const;
       
   311 
       
   312         /**
       
   313         * SetRegion
       
   314         * Mutator.
       
   315         *
       
   316         * @since    3.1
       
   317         * @param    region object is in SMIL
       
   318         */
       
   319         inline void SetRegion( TUniRegion aRegion );
       
   320 
       
   321         /**
       
   322         * Region
       
   323         * Accessor.
       
   324         *
       
   325         * @since    3.1
       
   326         * @return   region object is in SMIL
       
   327         */
       
   328         inline TUniRegion Region() const;
       
   329 
       
   330         /**
       
   331         * SetMediaTypeBySmilTag
       
   332         * Mutator.
       
   333         *
       
   334         * @since    3.1
       
   335         * @param    media type by SMIL media tag
       
   336         */
       
   337         inline void SetMediaTypeBySmilTag( TMsgMediaType aMediaType );
       
   338 
       
   339         /**
       
   340         * ReferenceCount
       
   341         * Accessor.
       
   342         *
       
   343         * @since    3.1
       
   344         * @return   media type by SMIL media tag
       
   345         */
       
   346         inline TMsgMediaType MediaTypeBySmilTag() const;
       
   347 
       
   348         /**
       
   349         * SetUniqueControlHandle
       
   350         * Mutator.
       
   351         *
       
   352         * @since    3.2
       
   353         * @param    UniqueControlHandle, -1 for "resetting".
       
   354         */
       
   355         inline void SetUniqueControlHandle( TInt aUniqueControlHandle );
       
   356 
       
   357         /**
       
   358         * UniqueControlHandle
       
   359         * Accessor.
       
   360         *
       
   361         * @since    3.2
       
   362         * @return   UniqueControlHandle, -1 if not set.
       
   363         */
       
   364         inline TInt UniqueControlHandle() const;
       
   365 
       
   366         /**
       
   367         * SetAttachment
       
   368         * Mutator.
       
   369         *
       
   370         * @since    3.2
       
   371         * @param    aObjectAttachment ETrue if object is attachment, otherwise EFalse
       
   372         */
       
   373         inline void SetAttachment( TBool aObjectAttachment );
       
   374 
       
   375         /**
       
   376         * Attachment
       
   377         * Accessor.
       
   378         *
       
   379         * @since    3.2
       
   380         * @return   ETrue if object is attachment, otherwise EFalse
       
   381         */
       
   382         inline TBool Attachment() const;
       
   383 
       
   384         /**
       
   385         * IsSaved
       
   386         * Accessor.
       
   387         *
       
   388         * @since    3.2
       
   389         * @return   Information whether this object has been saved into file system
       
   390         *           in Viewer.
       
   391         */
       
   392         inline TBool IsSaved( );
       
   393 
       
   394         /**
       
   395         * IsSaved
       
   396         * Mutator.
       
   397         *
       
   398         * @since    3.2
       
   399         * @param    aSaved ETrue attachment has been saved
       
   400         *                  EFalse attachment has not been saved
       
   401         */
       
   402         inline void SetSaved( TBool aSaved );
       
   403 
       
   404         /**
       
   405         * IsDrmRightsWhenLoaded. Function is applicable only, if DrmInfo exists.
       
   406         * Accessor.
       
   407         *
       
   408         * @since    5.0
       
   409         * @return   Checks whether object had DRM rights when this object was loaded
       
   410         *           into screen. If last DRM rights were consumed during loading,
       
   411         *           it returns ETrue.
       
   412         *
       
   413         */
       
   414         inline TBool IsDrmRightsWhenLoaded( ) const;
       
   415 
       
   416         /**
       
   417         * ResolveDrmRightsWhenLoadedL. Saves information whether this object had DRM
       
   418         *           rights when slide having the object was loaded. Uses
       
   419         *           CDrmInfo::EvaluateRights() to resolve status
       
   420         * Mutator.
       
   421         *
       
   422         * @since    5.0
       
   423         *
       
   424         */
       
   425         IMPORT_C void ResolveDrmRightsWhenLoadedL( );
       
   426 
       
   427         /**
       
   428         * SetDrmRightsWhenLoadedL. Saves information whether this object had DRM
       
   429         *            rights when slide having the object was loaded.
       
   430         * Mutator.
       
   431         *
       
   432         * @since    5.0
       
   433         * @param    aRights ETrue: objects had rights, which were already consumed or if not consumed,
       
   434         *                   have still rights left
       
   435         *                   EFalse: rights have not been consumed and they are not left
       
   436         *
       
   437         */
       
   438         IMPORT_C void SetDrmRightsWhenLoaded( TBool aRights );
       
   439 
       
   440         /**
       
   441         * IsDrmRightsWhenLoadedObjects. Function is applicable only, if DrmInfo exists.
       
   442         * Accessor.
       
   443         *
       
   444         * @since    5.0
       
   445         * @return   Checks whether object had DRM rights when this object was loaded
       
   446         *           into screen in the Objects view. If last DRM rights were consumed during loading,
       
   447         *           it returns ETrue.
       
   448         *
       
   449         */
       
   450         inline TBool IsDrmRightsWhenLoadedObjects( ) const;
       
   451 
       
   452         /**
       
   453         * SetDrmRightsWhenLoadedObjects. Saves information whether this object had DRM
       
   454         *            rights when slide having the object was loaded into screen in the
       
   455         *            Objects view.
       
   456         * Mutator.
       
   457         *
       
   458         * @since    5.0
       
   459         * @param    aRights ETrue: objects had rights, which were already consumed or if not consumed,
       
   460         *                   have still rights left
       
   461         *                   EFalse: rights have not been consumed and they are not left
       
   462         *
       
   463         */
       
   464         IMPORT_C void SetDrmRightsWhenLoadedObjects( TBool aRights );
       
   465 
       
   466         /**
       
   467         * Sets observer of UniObject events. Several observers are supported at the same time.
       
   468         * Mutator.
       
   469         *
       
   470         * @since    5.0
       
   471         * @param    aObserver observer
       
   472         *
       
   473         */
       
   474         IMPORT_C void SetObserverL(  MUniObjectObserver* aObserver );                       
       
   475 
       
   476         /**
       
   477         * Removes observer of UniObject events.
       
   478         * Accessor.
       
   479         *
       
   480         * @since    5.0
       
   481         *
       
   482         */
       
   483         IMPORT_C void RemoveObserver(   MUniObjectObserver*     aObserver );
       
   484 
       
   485     protected:
       
   486 
       
   487         /**
       
   488         * From CActive
       
   489         */
       
   490         void DoCancel();
       
   491 
       
   492         /**
       
   493         * From CActive
       
   494         */
       
   495         void RunL();
       
   496 
       
   497         /**
       
   498         * From CActive
       
   499         */
       
   500         TInt RunError( TInt aError );
       
   501 
       
   502     protected:
       
   503 
       
   504         /**
       
   505         * Constructor.
       
   506         *
       
   507         * @since    3.1
       
   508         */
       
   509         CUniObject(
       
   510             RFs& aFs,
       
   511             CBaseMtm& aMtm,
       
   512             CUniDataUtils& aData,
       
   513             CMsgMediaInfo* aMedia );
       
   514 
       
   515         /**
       
   516         * 2nd phase constructor.
       
   517         *
       
   518         * @since    3.1
       
   519         */
       
   520         void ConstructL();
       
   521 
       
   522         /**
       
   523         * 2nd phase constructor.
       
   524         *
       
   525         * @since    3.1
       
   526         * @param    aManager        IN reference to attachment manager
       
   527         * @param    aAttachmentId   IN id of the attachment from
       
   528         *                           which to create the object
       
   529         */
       
   530         void ConstructFromAttachmentL(
       
   531             MMsvAttachmentManager& aManager,
       
   532             CMsvAttachment& aAttachment );
       
   533 
       
   534         /**
       
   535         * CreateMimeInfoL
       
   536         * Create mime info for the object from the file information
       
   537         * and in-parameters.
       
   538         *
       
   539         * @since    3.1
       
   540         */
       
   541         void CreateMimeInfoL();
       
   542 
       
   543         /**
       
   544         * CreateAttachmentL
       
   545         * Creates an attachment to message store.
       
   546         * If leave occurs, attachment is cleaned up from the
       
   547         * message store.
       
   548         *
       
   549         * @since    3.1
       
   550         */
       
   551         void CreateAttachmentL( );
       
   552 
       
   553         /**
       
   554         * SetHiddenL
       
   555         * Sets attachment "hidden" or "visible"
       
   556         * "Hidden" means InPreparation flag is set on and
       
   557         * "visible" means InPreparation flag is set off
       
   558         * Not to be called for "temporary" object
       
   559         *
       
   560         * @since    3.1
       
   561         * @param    aHidden IN ETrue for "hidden", EFalse for "visible"
       
   562         */
       
   563         //void SetHiddenL( TBool aHidden );
       
   564 
       
   565         virtual void DoSaveL();
       
   566 
       
   567         void StartObjectSaveL();
       
   568         void FinalizeObjectSaveL();
       
   569 
       
   570         void CompleteSelf();
       
   571 
       
   572         /// From MDRMEventObserver
       
   573         virtual void HandleEventL( MDRMEvent* aEvent );
       
   574 
       
   575 
       
   576     protected: // data
       
   577 
       
   578         enum TMsgObjectSaveState
       
   579             {
       
   580             EObjectSavingIdle,
       
   581             EObjectCreatingAttachment
       
   582             };
       
   583 
       
   584         enum TMsgObjectFlags
       
   585             {
       
   586             EObjectCorrupted = 0x1,
       
   587             EObjectAttachment = 0x2,
       
   588             EObjectDrmRightsWhenLoaded = 0x4,
       
   589             EObjectDrmRightsWhenLoadedObjects = 0x8
       
   590             };
       
   591 
       
   592         RFs&                    iFs;
       
   593         CBaseMtm&               iMtm;
       
   594         CUniDataUtils&          iData;
       
   595 
       
   596 		TInt                    iSupportedFeatures;
       
   597 
       
   598         TMsvAttachmentId        iAttachmentId;  // Attachment id of object. Can be id to Link file in store or to real atta.
       
   599 
       
   600         CUniMimeInfo*           iMimeInfo;      // Contains objects mime headers.
       
   601         CMsgMediaInfo*          iMediaInfo;     // Contains objects media information.
       
   602         CUniDrmInfo*            iDrmInfo;
       
   603         TInt                    iObjectFlags;
       
   604         TInt                    iReferenceCount;
       
   605         //TMsgObjectStoreState    iStoreState;
       
   606         TUniRegion              iRegion;
       
   607         TMsgMediaType           iMediaTypeBySmilTag;
       
   608         TInt                    iUniqueControlHandle;
       
   609 
       
   610         MUniObjectSaveObserver* iObserver;
       
   611         CMsvAttachment::TMsvAttachmentType iSaveType;
       
   612 
       
   613         MMsvAttachmentManager*  iManager;
       
   614         CMsvAttachment*         iAttachment;
       
   615         CMsvStore*              iEditStore;
       
   616         TInt                    iSaveState;
       
   617 
       
   618         TBool                   iSavedToFs;
       
   619         RFile                   iFileHandle;
       
   620 
       
   621         CDRMNotifier*           iDrmNotifier;
       
   622         CArrayPtrFlat<MUniObjectObserver>* iObservers;
       
   623 
       
   624     };
       
   625 
       
   626 #include <UniObject.inl>
       
   627 
       
   628 #endif // __UNIOBJECT_H