emailuis/emailui/inc/FreestyleEmailUiMailListModel.h
branchRCL_3
changeset 64 3533d4323edc
child 80 726fba06891a
equal deleted inserted replaced
63:d189ee25cf9d 64:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 2007 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:  FreestyleEmailUi mail list model and model item definition.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __FREESTYLEEMAILUI_MAILLISTMODEL_H__
       
    20 #define __FREESTYLEEMAILUI_MAILLISTMODEL_H__
       
    21 
       
    22 // SYSTEM INCLUDES
       
    23 #include <e32base.h>
       
    24 
       
    25 // INTERNAL INCLUDES
       
    26 #include "FreestyleEmailUiListModel.h"
       
    27 #include "fstreelistconstants.h"
       
    28 
       
    29 // FORWARD DECLARATIONS
       
    30 class CFreestyleEmailUiAppUi;
       
    31 class CFSMailMessage;
       
    32 
       
    33 enum TModelItemType
       
    34 	{
       
    35 	ETypeMailItem=0,
       
    36 	ETypeSeparator
       
    37 	};
       
    38 
       
    39 /**
       
    40  * Mail list model item.
       
    41  */
       
    42 class CFSEmailUiMailListModelItem : public CBase, public MFSListModelItem
       
    43     {
       
    44 public:
       
    45     static CFSEmailUiMailListModelItem* NewL( CFSMailMessage* aMessagePtr, TModelItemType aModelItemtype );
       
    46     static CFSEmailUiMailListModelItem* NewLC( CFSMailMessage* aMessagePtr, TModelItemType aModelItemtype );
       
    47     virtual ~CFSEmailUiMailListModelItem();
       
    48 
       
    49 private:
       
    50     CFSEmailUiMailListModelItem::CFSEmailUiMailListModelItem( CFSMailMessage* aMessagePtr, TModelItemType aModelItemtype );
       
    51 public:
       
    52     inline void SetMessagePtr( CFSMailMessage* aMessagePtr ) { iMessagePtr = aMessagePtr; }
       
    53 	inline CFSMailMessage& MessagePtr() { return *iMessagePtr; }
       
    54 	inline const CFSMailMessage& MessagePtr() const { return *iMessagePtr; }
       
    55 	inline TModelItemType ModelItemType() const { return iModelItemType; }
       
    56 	void SetSeparatorTextL( const TDesC& aSeparatorText );
       
    57 	inline HBufC* SeparatorText() { return iSeparatorText; }
       
    58     inline const HBufC* SeparatorText() const { return iSeparatorText; }
       
    59 	inline void AddCorrespondingListId( TInt aFsTreeListId ) { iFsTreeListId = aFsTreeListId; }
       
    60 	inline TInt CorrespondingListId() const { return iFsTreeListId; }
       
    61 	
       
    62 private:
       
    63 	CFSMailMessage* iMessagePtr;   //!< ownded IFF item type is ETypeMailItem
       
    64 	TModelItemType iModelItemType;
       
    65 	HBufC* iSeparatorText;         //!< owned
       
    66 	TInt iFsTreeListId;
       
    67   }; 
       
    68  
       
    69 
       
    70 /**
       
    71  * Mail list model.
       
    72  */
       
    73 class CFSEmailUiMailListModel : public CBase, public MFSEmailListModel
       
    74   {
       
    75 public: // construction and destruction
       
    76     
       
    77     /** Two-phased constructor. */
       
    78 	static CFSEmailUiMailListModel* NewL( CFreestyleEmailUiAppUi* aAppUi, TBool aSearchList = EFalse );
       
    79 	/** Two-phased constructor. */
       
    80 	static CFSEmailUiMailListModel* NewLC( CFreestyleEmailUiAppUi* aAppUi, TBool aSearchList = EFalse );
       
    81 	/** Destructor. */
       
    82 	~CFSEmailUiMailListModel();
       
    83 
       
    84 public: // from base class MFSEmailListModel
       
    85 
       
    86 	void AppendL(MFSListModelItem* aItem);
       
    87 	void InsertL(MFSListModelItem* aItem, TInt aIndex);
       
    88 	void RemoveAndDestroy(TInt aIndex);
       
    89 	MFSListModelItem* Item(TInt aIndex);
       
    90     const MFSListModelItem* Item(TInt aIndex) const;
       
    91 	TInt Count() const;
       
    92 
       
    93 public: // new methods
       
    94 	
       
    95 	CFreestyleEmailUiAppUi* AppUi();
       
    96 	
       
    97 	void SetSortCriteria( TFSMailSortCriteria aSortCriteria );
       
    98 	TFSMailSortCriteria SortCriteria();
       
    99 
       
   100 	void SortL();
       
   101 	
       
   102 	/**
       
   103 	 * Replaces the message pointer of the given item. Previous message is destroyed
       
   104 	 * if owned by the item. Also message pointer in the parent node is updated if
       
   105 	 * necessary.
       
   106 	 * @param  aIndex  Index of the item for which message pointer is replaced
       
   107 	 * @param  aNewPtr Pointer to the new message for the item. Ownership is transferred
       
   108 	 *                 if the updated item is a message item (not divider).
       
   109 	 */
       
   110 	void ReplaceMessagePtr( TInt aIndex, CFSMailMessage* aNewPtr );
       
   111 	
       
   112 	/**
       
   113 	 * Get index for item to be inserted in case the title dividers are not in use
       
   114 	 * @param  aMessageToInsert    The message which should be inserted
       
   115 	 * @param  aSortCriteria       The sorting criteria to be used in insertion
       
   116 	 * @return The index within the model for the new item.
       
   117 	 */
       
   118     TInt GetInsertionPointL( const CFSEmailUiMailListModelItem& aItemToInsert ) const;
       
   119     
       
   120     /**
       
   121      * Get index for item to be inserted in case the title dividers are in use.
       
   122      * also gets the index of the parent node and place of the new item under its parent.
       
   123      * @param  aMessageToInsert    The message which should be inserted
       
   124      * @param  aSortCriteria       The sorting criteria to be used in insertion
       
   125      * @param  aChildIdx           On return, contains index of the item to be inserted relative to its parent node.
       
   126      * @param  aParentNodeIdx      On return, contains the index of the parent node within the model.
       
   127      *                             KErrNotFound if a new node is needed for the item.
       
   128      * @return The index within the model for the new item.
       
   129      */ 
       
   130 	TInt GetInsertionPointL( const CFSEmailUiMailListModelItem& aItemToInsert, //!< input arg
       
   131 	                         TInt& aChildIdx,                                  //!< output arg
       
   132 	                         TInt& aParentNodeIdx ) const;                     //!< output arg
       
   133 
       
   134 	static TInt CompareModelItemsL( const CFSEmailUiMailListModelItem& aItem1,
       
   135 	                                const CFSEmailUiMailListModelItem& aItem2 );
       
   136 	
       
   137 	/**
       
   138 	 * Compares given messages using the given sorting mode. 
       
   139 	 * @return Positive value if aMessage1 is greater, negative value if aMessage1 is smaller, and 0 
       
   140 	 *         if the messages are equal.
       
   141 	 */
       
   142 	static TInt CompareMessagesL( const CFSMailMessage& aMessage1, 
       
   143 	                              const CFSMailMessage& aMessage2, 
       
   144 	                              TFSMailSortField aSortField );	    
       
   145 
       
   146 	static TBool MessagesBelongUnderSameSeparatorL( const CFSMailMessage& aMessage1, 
       
   147 	                                                const CFSMailMessage& aMessage2,
       
   148 	                                                TFSMailSortField aSortField );
       
   149 	
       
   150 	/**
       
   151 	 * Resets the data. Use this instead of deleting the model to avoid NULL
       
   152 	 * pointer checks.
       
   153 	 */
       
   154     void Reset();
       
   155 
       
   156     /**
       
   157      * Returns ItemIds for items under specific node.
       
   158      */
       
   159     void GetItemIdsUnderNodeL( const TFsTreeItemId aNodeId, RFsTreeItemIdList& aMessageIds ) const;
       
   160     
       
   161 protected: // construction
       
   162     
       
   163     // C++ constructor.
       
   164 	CFSEmailUiMailListModel( CFreestyleEmailUiAppUi* aAppUi );
       
   165 	// Second phase constructor.
       
   166 	void ConstructL( TBool aSearchList );
       
   167 
       
   168 private: // data
       
   169 
       
   170     // Pointer to app ui. Not own.
       
   171 	CFreestyleEmailUiAppUi* iAppUi;
       
   172   	RPointerArray<CFSEmailUiMailListModelItem> iItems;   
       
   173   	TFSMailSortCriteria iSortCriteria;
       
   174   };
       
   175 
       
   176 #endif //__FREESTYLEEMAILUI_MAILLISTMODEL_H__
       
   177