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