emailuis/emailui/src/FreestyleEmailUiMsgDetailsModel.cpp
branchRCL_3
changeset 8 e1b6206813b4
parent 0 8466d47a6819
equal deleted inserted replaced
4:e7aa27f58ae1 8:e1b6206813b4
    17 
    17 
    18 
    18 
    19 // SYSTEM INCLUDES
    19 // SYSTEM INCLUDES
    20 //<cmail>
    20 //<cmail>
    21 #include "emailtrace.h"
    21 #include "emailtrace.h"
    22 #include "CFSMailAddress.h"
    22 #include "cfsmailaddress.h"
    23 //</cmail>
    23 //</cmail>
    24 
    24 
    25 // INTERNAL INCLUDES
    25 // INTERNAL INCLUDES
    26 #include "FreestyleEmailUiMsgDetailsModel.h"
    26 #include "FreestyleEmailUiMsgDetailsModel.h"
    27 
    27 
    28 // ---------------------------------------------------------------------------
    28 // ---------------------------------------------------------------------------
    29 // Folder list item constructor.
    29 // Folder list item constructor.
    30 // ---------------------------------------------------------------------------
    30 // ---------------------------------------------------------------------------
    31 CFSEmailUiMsgDetailsItem::CFSEmailUiMsgDetailsItem( TFsTreeItemId aListId )
    31 CFSEmailUiMsgDetailsItem::CFSEmailUiMsgDetailsItem( TFsTreeItemId aListId )
    32 	: iListId( aListId ), iMailAddress( NULL ), iText( NULL )
    32     : iListId( aListId ), iMailAddress( NULL ), iText( NULL )
    33 	{
    33     {
    34     FUNC_LOG;
    34     FUNC_LOG;
    35 	}
    35     }
    36 
    36 
    37 // ---------------------------------------------------------------------------
    37 // ---------------------------------------------------------------------------
    38 // Folder list item destructor.
    38 // Folder list item destructor.
    39 // ---------------------------------------------------------------------------
    39 // ---------------------------------------------------------------------------
    40 CFSEmailUiMsgDetailsItem::~CFSEmailUiMsgDetailsItem()
    40 CFSEmailUiMsgDetailsItem::~CFSEmailUiMsgDetailsItem()
    41 	{
    41     {
    42     FUNC_LOG;
    42     FUNC_LOG;
    43 	}
    43     }
    44 
    44 
    45 // ---------------------------------------------------------------------------
    45 // ---------------------------------------------------------------------------
    46 // NewLC
    46 // NewLC
    47 // ---------------------------------------------------------------------------
    47 // ---------------------------------------------------------------------------
    48 //
    48 //
    57 
    57 
    58 // ---------------------------------------------------------------------------
    58 // ---------------------------------------------------------------------------
    59 // Constructor
    59 // Constructor
    60 // ---------------------------------------------------------------------------
    60 // ---------------------------------------------------------------------------
    61 CFSEmailUiMsgDetailsModel::CFSEmailUiMsgDetailsModel()
    61 CFSEmailUiMsgDetailsModel::CFSEmailUiMsgDetailsModel()
    62 	{
    62     {
    63     FUNC_LOG;
    63     FUNC_LOG;
    64 	}
    64     }
    65 
    65 
    66 // ---------------------------------------------------------------------------
    66 // ---------------------------------------------------------------------------
    67 // Destructor.
    67 // Destructor.
    68 // ---------------------------------------------------------------------------
    68 // ---------------------------------------------------------------------------
    69 CFSEmailUiMsgDetailsModel::~CFSEmailUiMsgDetailsModel()
    69 CFSEmailUiMsgDetailsModel::~CFSEmailUiMsgDetailsModel()
    70 	{
    70     {
    71     FUNC_LOG;
    71     FUNC_LOG;
    72 	RemoveAll();
    72     RemoveAll();
    73 	iItemArray.Close();
    73     iItemArray.Close();
    74 	}
    74     }
    75 
    75 
    76 // ---------------------------------------------------------------------------
    76 // ---------------------------------------------------------------------------
    77 // Add an item to the end of the list.
    77 // Add an item to the end of the list.
    78 // ---------------------------------------------------------------------------
    78 // ---------------------------------------------------------------------------
    79 void CFSEmailUiMsgDetailsModel::AppendL( TFsTreeItemId aListId, CFSMailAddress* aMailAddress )
    79 void CFSEmailUiMsgDetailsModel::AppendL( TFsTreeItemId aListId, CFSMailAddress* aMailAddress )
    80 	{
    80     {
    81     FUNC_LOG;
    81     FUNC_LOG;
    82 	CFSEmailUiMsgDetailsItem* item = CFSEmailUiMsgDetailsItem::NewLC( aListId );
    82     CFSEmailUiMsgDetailsItem* item = CFSEmailUiMsgDetailsItem::NewLC( aListId );
    83 	item->iMailAddress = aMailAddress;
    83     item->iMailAddress = aMailAddress;
    84 	iItemArray.AppendL( item );
    84     iItemArray.AppendL( item );
    85     CleanupStack::Pop( item );
    85     CleanupStack::Pop( item );
    86 	}
    86     }
    87 
    87 
    88 // ---------------------------------------------------------------------------
    88 // ---------------------------------------------------------------------------
    89 // Add an item to the end of the list.
    89 // Add an item to the end of the list.
    90 // ---------------------------------------------------------------------------
    90 // ---------------------------------------------------------------------------
    91 void CFSEmailUiMsgDetailsModel::AppendL( TFsTreeItemId aListId, TDesC* aText )
    91 void CFSEmailUiMsgDetailsModel::AppendL( TFsTreeItemId aListId, TDesC* aText )
    92 	{
    92     {
    93     FUNC_LOG;
    93     FUNC_LOG;
    94 	CFSEmailUiMsgDetailsItem* item = CFSEmailUiMsgDetailsItem::NewLC( aListId );
    94     CFSEmailUiMsgDetailsItem* item = CFSEmailUiMsgDetailsItem::NewLC( aListId );
    95 	item->iText = aText;
    95     item->iText = aText;
    96 	iItemArray.AppendL( item );
    96     iItemArray.AppendL( item );
    97     CleanupStack::Pop( item );
    97     CleanupStack::Pop( item );
    98 	}
    98     }
    99 
    99 
   100 // ---------------------------------------------------------------------------
   100 // ---------------------------------------------------------------------------
   101 // Remove item by list item id.
   101 // Remove item by list item id.
   102 // ---------------------------------------------------------------------------
   102 // ---------------------------------------------------------------------------
   103 void CFSEmailUiMsgDetailsModel::Remove( TFsTreeItemId aListId )
   103 void CFSEmailUiMsgDetailsModel::Remove( TFsTreeItemId aListId )
   104 	{
   104     {
   105     FUNC_LOG;
   105     FUNC_LOG;
   106 	TInt index = Index( aListId );
   106     TInt index = Index( aListId );
   107 	if( index != KErrNotFound )
   107     if( index != KErrNotFound )
   108 		{
   108         {
   109 		delete iItemArray[index];
   109         delete iItemArray[index];
   110 		iItemArray.Remove( index );
   110         iItemArray.Remove( index );
   111 		}
   111         }
   112 	}
   112     }
   113 
   113 
   114 // ---------------------------------------------------------------------------
   114 // ---------------------------------------------------------------------------
   115 // Remove all items.
   115 // Remove all items.
   116 // ---------------------------------------------------------------------------	
   116 // ---------------------------------------------------------------------------  
   117 void CFSEmailUiMsgDetailsModel::RemoveAll()
   117 void CFSEmailUiMsgDetailsModel::RemoveAll()
   118 	{
   118     {
   119     FUNC_LOG;
   119     FUNC_LOG;
   120 	iItemArray.ResetAndDestroy();
   120     iItemArray.ResetAndDestroy();
   121 	}
   121     }
   122 
   122 
   123 // ---------------------------------------------------------------------------
   123 // ---------------------------------------------------------------------------
   124 // Get an item by list item id.
   124 // Get an item by list item id.
   125 // 
   125 // 
   126 // @return NULL if not found.
   126 // @return NULL if not found.
   127 // ---------------------------------------------------------------------------
   127 // ---------------------------------------------------------------------------
   128 CFSEmailUiMsgDetailsItem* CFSEmailUiMsgDetailsModel::ItemByListId( TFsTreeItemId aListId ) const
   128 CFSEmailUiMsgDetailsItem* CFSEmailUiMsgDetailsModel::ItemByListId( TFsTreeItemId aListId ) const
   129 	{
   129     {
   130     FUNC_LOG;
   130     FUNC_LOG;
   131 	TInt index = Index( aListId );
   131     TInt index = Index( aListId );
   132 	if( index != KErrNotFound )
   132     if( index != KErrNotFound )
   133 		{
   133         {
   134 		return iItemArray[ index ];
   134         return iItemArray[ index ];
   135 		}
   135         }
   136 	else
   136     else
   137 		{
   137         {
   138 		return NULL;
   138         return NULL;
   139 		}
   139         }
   140 	}
   140     }
   141 	
   141     
   142 // ---------------------------------------------------------------------------
   142 // ---------------------------------------------------------------------------
   143 // Get an item by list index.
   143 // Get an item by list index.
   144 // 
   144 // 
   145 // @return NULL if not found.
   145 // @return NULL if not found.
   146 // ---------------------------------------------------------------------------
   146 // ---------------------------------------------------------------------------
   147 CFSEmailUiMsgDetailsItem* CFSEmailUiMsgDetailsModel::ItemByIndex( TInt aModelIndex ) const
   147 CFSEmailUiMsgDetailsItem* CFSEmailUiMsgDetailsModel::ItemByIndex( TInt aModelIndex ) const
   148 	{
   148     {
   149     FUNC_LOG;
   149     FUNC_LOG;
   150 	return iItemArray[ aModelIndex ];
   150     return iItemArray[ aModelIndex ];
   151 	}
   151     }
   152 
   152 
   153 // ---------------------------------------------------------------------------
   153 // ---------------------------------------------------------------------------
   154 // Get number of items in list.
   154 // Get number of items in list.
   155 // 
   155 // 
   156 // @return Number of items.
   156 // @return Number of items.
   157 // ---------------------------------------------------------------------------		
   157 // ---------------------------------------------------------------------------      
   158 TInt CFSEmailUiMsgDetailsModel::Count() const
   158 TInt CFSEmailUiMsgDetailsModel::Count() const
   159 	{
   159     {
   160     FUNC_LOG;
   160     FUNC_LOG;
   161 	return iItemArray.Count();
   161     return iItemArray.Count();
   162 	}
   162     }
   163 	
   163     
   164 // ---------------------------------------------------------------------------
   164 // ---------------------------------------------------------------------------
   165 // Get the array index of the spcified item.
   165 // Get the array index of the spcified item.
   166 // 
   166 // 
   167 // @return Array index of the item.
   167 // @return Array index of the item.
   168 // ---------------------------------------------------------------------------		
   168 // ---------------------------------------------------------------------------      
   169 TInt CFSEmailUiMsgDetailsModel::Index( TFsTreeItemId aListId ) const
   169 TInt CFSEmailUiMsgDetailsModel::Index( TFsTreeItemId aListId ) const
   170 	{
   170     {
   171     FUNC_LOG;
   171     FUNC_LOG;
   172 	for( TInt i = 0; i < Count(); i++ )
   172     for( TInt i = 0; i < Count(); i++ )
   173 		{
   173         {
   174 		if( iItemArray[i]->iListId == aListId )
   174         if( iItemArray[i]->iListId == aListId )
   175 			{
   175             {
   176 			return i;
   176             return i;
   177 			}
   177             }
   178 		}
   178         }
   179 	return KErrNotFound;
   179     return KErrNotFound;
   180 	}
   180     }
   181 
   181