messagingapp/msgutils/unidatautils/unidatamodel/inc/UniDataModel.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 *       CUniDataModel
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #ifndef __UNIDATAMODEL_H
       
    22 #define __UNIDATAMODEL_H
       
    23 
       
    24 //  INCLUDES
       
    25 #include <gmxmlparser.h>
       
    26 #include <gmxmldocument.h>
       
    27 #include <msvapi.h>                     // CMsvEntry
       
    28 #include <UniDataUtils.h>
       
    29 #include <UniSmilModel.h>
       
    30 #include <UniSmilList.h>
       
    31 #include <UniObject.h>
       
    32 
       
    33 #include <mmsvattachmentmanager.h>
       
    34 #include <mmsvattachmentmanagersync.h>
       
    35 #include <MsgMediaInfo.h>
       
    36 
       
    37 // CONSTANTS
       
    38 
       
    39 // MACROS
       
    40 
       
    41 // DATA TYPES
       
    42 
       
    43 // FUNCTION PROTOTYPES
       
    44 
       
    45 // FORWARD DECLARATIONS
       
    46 
       
    47 class CBaseMtm;
       
    48 class CUniDataUtils;
       
    49 class CUniObjectsModel;
       
    50 class CUniObjectList;
       
    51 class CUniObjectsInfo;
       
    52 class CMsgMediaResolver;
       
    53 class CMmsConformance;
       
    54 class CMsvMimeHeaders;
       
    55 class CMsvAttachment;
       
    56 
       
    57 // CLASS DECLARATION
       
    58 
       
    59 /**
       
    60 * MUniDataModelObserver - Callback API for model operations.
       
    61 *
       
    62 * @since 3.1
       
    63 */
       
    64 class MUniDataModelObserver
       
    65     {
       
    66     public:
       
    67         virtual void RestoreReady( TInt aParseResult, TInt aError ) = 0;
       
    68     };
       
    69 
       
    70 /**
       
    71 * CUniDataModel - A container class that owns instances of CMsgMediaResolver,
       
    72 * CMmsConformance, CUniDataUtils, CUniObjectList, CUniSmilList and CUniSmilModel.
       
    73 * It also handles the initialization of the lists & the SMIL model.
       
    74 *
       
    75 * @lib UniDataModel.lib
       
    76 * @since 3.1
       
    77 */
       
    78 class CUniDataModel : public CBase,
       
    79                       public MMDXMLParserObserver,
       
    80                       public MMediaInfoObserver
       
    81     {
       
    82     public:  // Constructors and destructor
       
    83 
       
    84         static IMPORT_C CUniDataModel* NewL( RFs& aFs, CBaseMtm& aMtm );
       
    85         
       
    86         /**
       
    87         * Destructor.
       
    88         */
       
    89         IMPORT_C ~CUniDataModel();
       
    90 
       
    91     public: // New functions
       
    92 
       
    93         /**
       
    94         * RestoreL
       
    95         * Loads attachments from message store and initializes
       
    96         * the model.
       
    97         * @param aObserver          IN Callback observer
       
    98         * @param aRemoveCorrupted   IN If ETrue removes corrupted attachments
       
    99         *                              If EFalse leaves if corrupted attachments detected
       
   100         * @param aAllowSmil         IN If ETrue puts SMIL files to "SmilList"
       
   101         *                              If EFalse puts SMIL files to "AttachmentList"
       
   102         */ 
       
   103         IMPORT_C void RestoreL(
       
   104             MUniDataModelObserver& aObserver,
       
   105             TBool aRemoveCorrupted = ETrue,
       
   106             TBool aAllowSmil = ETrue );
       
   107 
       
   108         /**
       
   109         * AddObjectL
       
   110         * Adds an object into msg store and smil slide
       
   111         *
       
   112         * @since    3.1
       
   113         * @param    aObserver   IN Object save observer
       
   114         * @param    aMedia      IN media info - ownership transferred to MsgObject
       
   115         * @param    aSaveType   IN either "file" or "linked file"
       
   116         * @return   Pointer to the added object
       
   117         *           Ownership NOT transferred.
       
   118         */
       
   119         IMPORT_C CUniObject* AddAttachmentL(
       
   120             MUniObjectSaveObserver& aObserver,
       
   121             CMsgMediaInfo* aMedia,
       
   122             CMsvAttachment::TMsvAttachmentType aSaveType = CMsvAttachment::EMsvLinkedFile );
       
   123 
       
   124        /**
       
   125         * AddStoredAttachmentL
       
   126         * Adds an object that is already in msg store to smil slide
       
   127         *
       
   128         * @since    3.1
       
   129         * @param    aAttachmentId   IN file to be added
       
   130         * @param    aMedia      IN media info - ownership transferred to MsgObject
       
   131         * @return   Pointer to the added object
       
   132         *           Ownership NOT transferred.
       
   133         */
       
   134         IMPORT_C CUniObject* AddStoredAttachmentL(
       
   135             TMsvAttachmentId aAttachmentId,
       
   136             CMsgMediaInfo* aMedia );
       
   137 
       
   138        /**
       
   139         * FinalizeMediaParse
       
   140         * This function synchronizes asynchronous media info parsing if it is still ongoing
       
   141         * To be called from editor/viewer when the message is to be send/saved/forwarded
       
   142         * @since    3.2
       
   143         */
       
   144         IMPORT_C void FinalizeMediaParse();
       
   145 
       
   146     public:
       
   147 
       
   148        /**
       
   149         * MediaInfoParsed
       
   150         * Callback for MediaInfo active object
       
   151         * @since    3.2
       
   152         */
       
   153         void MediaInfoParsed();
       
   154 
       
   155        /**
       
   156         * ParseNextObject
       
   157         * Parses the next object in a to-be-parsed list
       
   158         * Actual parsing is dedicated to MediaInfo's asynchronous method
       
   159         * @since    3.2
       
   160         */
       
   161         void ParseNextObject();
       
   162 
       
   163         /**
       
   164         * ParseFileCompleteL
       
   165         * Call back function used to inform client of Parser when RunL function completes
       
   166         */
       
   167         void ParseFileCompleteL();
       
   168 
       
   169     public: // inlines
       
   170 
       
   171         /**
       
   172         * Returns number of corrupted attachments encountered at load time
       
   173         * i.e. entry is stil there but binary file is missing
       
   174         * Includes corrupted link, presentations etc.
       
   175         *
       
   176         * @return attachment count
       
   177         */
       
   178         inline TInt CorruptedCount() const;
       
   179 
       
   180         /**
       
   181         * Returns attachment count before any filtering for "presentation objects"
       
   182         * or corrupted attachments. SMIL attachments are not included in the count.
       
   183         *
       
   184         * @return attachment count
       
   185         */
       
   186         inline TInt OriginalAttachmentCount() const;
       
   187 
       
   188         /**
       
   189         * Get reference to file session
       
   190         *
       
   191         * @return reference to RFs
       
   192         */
       
   193         inline RFs& FsSession() const;
       
   194 
       
   195         /**
       
   196         * Get reference to base mtm
       
   197         *
       
   198         * @return reference to CBaseMtm
       
   199         */
       
   200         inline CBaseMtm& Mtm() const;
       
   201 
       
   202         /**
       
   203         * Returns object list owned by the model. Object list includes all
       
   204         * attachments that are referenced from the SMIL part (or if there is no
       
   205         * SMIL part attachments that are of supported media type).
       
   206         *
       
   207         * @return reference to the object list.
       
   208         */
       
   209         inline CUniObjectList& ObjectList() const;
       
   210 
       
   211         /**
       
   212         * Returns attachment list owned by the model. Attachment list includes all
       
   213         * attachments that are NOT referenced from the SMIL part.
       
   214         *
       
   215         * @return reference to the attachment list.
       
   216         */
       
   217         inline CUniObjectList& AttachmentList() const;
       
   218 
       
   219         /**
       
   220         * Returns SMIL list owned by the model. SMIL list includes all
       
   221         * attachments that are of type "application/smil".
       
   222         *
       
   223         * @return reference to the SMIL attachment list.
       
   224         */
       
   225         inline CUniSmilList& SmilList() const;
       
   226 
       
   227         /**
       
   228         * Returns data utils object used by the model.
       
   229         *
       
   230         * @return reference to the data utils object.
       
   231         */
       
   232         inline CUniDataUtils& DataUtils() const;
       
   233 
       
   234         /**
       
   235         * Returns SMIL type of the message.
       
   236         * @return Possible return values are:
       
   237         *         -ENoSmil
       
   238         *         -EMmsSmil
       
   239         *         -EOtherSmil
       
   240         *         -EMultipleSmil
       
   241         *         -ETemplateSmil
       
   242         */
       
   243         inline TUniSmilType SmilType();
       
   244 
       
   245         /**
       
   246         * Returns SMIL type of the message.
       
   247         * @param aSmilType:
       
   248         *         -ENoSmil
       
   249         *         -EMmsSmil
       
   250         *         -EOtherSmil
       
   251         *         -EMultipleSmil
       
   252         *         -ETemplateSmil
       
   253         */
       
   254         inline void SetSmilType( TUniSmilType aSmilType );
       
   255 
       
   256         /**
       
   257         * Get reference to SmilModel
       
   258         *
       
   259         * @return reference to SmilModel
       
   260         */
       
   261         inline CUniSmilModel& SmilModel() const;
       
   262 
       
   263         /**
       
   264         * Get reference to MediaResolver
       
   265         *
       
   266         * @return reference to MediaResolver
       
   267         */
       
   268         inline CMsgMediaResolver& MediaResolver() const;
       
   269 
       
   270         /**
       
   271         * Get reference to MmsConformance
       
   272         *
       
   273         * @return reference to MmsConformance
       
   274         */
       
   275         inline CMmsConformance& MmsConformance() const;
       
   276 
       
   277         /**
       
   278         * Return SMIL DOM
       
   279         *
       
   280         * @return Pointer to SMIL DOM
       
   281         */
       
   282         inline CMDXMLDocument* Dom();
       
   283 
       
   284         /**
       
   285         * Set SMIL DOM
       
   286         *
       
   287         * @param Pointer to SMIL DOM, takes ownership
       
   288         */
       
   289         inline void SetDom( CMDXMLDocument* aDom );
       
   290 
       
   291         /*
       
   292         * Accessor
       
   293         *
       
   294         * @return parse result from CUniSmilModel::ParseL()
       
   295         */
       
   296         inline TInt ParseResult() const;
       
   297 
       
   298     private:  // New functions
       
   299 
       
   300         /**
       
   301         * CUniDataModel
       
   302         * Constructor.
       
   303         */
       
   304         CUniDataModel( RFs& aFs, CBaseMtm& aMtm );
       
   305 
       
   306         /**
       
   307         * ConstructL
       
   308         * 2nd phase constructor.
       
   309         */
       
   310         void ConstructL();
       
   311 
       
   312     private: // New Functions
       
   313 
       
   314 
       
   315         /**
       
   316         * DoParseFileCompleteL
       
   317         */
       
   318         void DoParseFileCompleteL();
       
   319 
       
   320         /**
       
   321         * FinalizeRestoreL
       
   322         */
       
   323         void FinalizeRestoreL( TInt aError );
       
   324 
       
   325         /**
       
   326         * Handles corrupted attachments.
       
   327         *
       
   328         * @param aRemoveCorrupted   IN
       
   329         *   - If ETrue tries to recover by removing corrupted attachments.
       
   330         *
       
   331         *     Note: This means that SMIL parsing will fail with ESmil_Missing_Objects.
       
   332         *           and object order is not maintained. But better to do it this
       
   333         *           way so that message can be opened.
       
   334         *
       
   335         *   - If EFalse leaves with KErrCorrupt if corrupted attachments detected.
       
   336         *     Model not made caller should exit!
       
   337         */
       
   338         void FindAndHandleCorruptL( TBool aRemoveCorrupted );
       
   339 
       
   340         /**
       
   341         * Finds corrupted attachments from context message.
       
   342         */
       
   343         CMsvEntrySelection* FindCorruptLC();
       
   344 
       
   345         /**
       
   346         * FindAttachmentsL
       
   347         * Browses through SMIL and separates objects that are
       
   348         * referenced from attachments.
       
   349         */
       
   350         void FindAttachmentsL();
       
   351 
       
   352         /**
       
   353         * Creates an object from msg store attachment
       
   354         * @param aMimeType - mime type of new object.
       
   355         * @param aAttachmentId - ID to be used for searching
       
   356         *                        attachment from store
       
   357         */
       
   358         CUniObject* CreateObjectFromAttachmentLC(
       
   359             const TPtrC8& aMimeType,
       
   360             RFile& aFile,
       
   361             MMsvAttachmentManager& aManager,
       
   362             CMsvAttachment& aAttachment );
       
   363 
       
   364         /**
       
   365         * Browses through (non-MMS) SMIL and searches reference counts for objects and separates
       
   366         * objects and attachments in different lists.
       
   367         */
       
   368         void FindDomObjectRefCountsL();
       
   369 
       
   370     protected:  // data
       
   371 
       
   372         RFs&                iFs;
       
   373         CBaseMtm&           iMtm;
       
   374 
       
   375         CMsgMediaResolver*  iMediaResolver;
       
   376 
       
   377         CUniDataUtils*      iDataUtils;
       
   378         CUniObjectList*     iObjectList;
       
   379         CUniObjectList*     iAttachmentList;
       
   380         CUniSmilList*       iSmilList;
       
   381 
       
   382         CUniSmilModel*      iSmilModel;
       
   383         TUniSmilType        iSmilType;
       
   384         TInt                iOrigAttachmentCount;
       
   385         TInt                iCorruptedCount; // Number of attas detected to be corrupted when loading
       
   386 
       
   387         CMDXMLParser*       iParser;
       
   388         CMDXMLDocument*     iDom;
       
   389 
       
   390         MUniDataModelObserver* iObserver;
       
   391         TInt                iParseResult;
       
   392         CActiveSchedulerWait     iObjWait;
       
   393         CUniObject*         iObjectToParse;
       
   394         CMmsConformance* iMmsConformance;
       
   395 };
       
   396 
       
   397 #include <UniDataModel.inl>
       
   398 
       
   399 #endif   // __UNIDATAMODEL_H
       
   400 
       
   401 // End of file