emailuis/emailui/src/FreestyleEmailUiFolderListModel.cpp
changeset 0 8466d47a6819
child 8 e1b6206813b4
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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 folder list model implementation
       
    15 *
       
    16 */
       
    17 
       
    18  
       
    19 // SYSTEM INCLUDES
       
    20 //<cmail>
       
    21 #include "emailtrace.h"
       
    22 #include "CFSMailBox.h"
       
    23 #include "CFSMailFolder.h"
       
    24 //</cmail>
       
    25 
       
    26 // INTERNAL INCLUDES
       
    27 #include "FreestyleEmailUiFolderListModel.h"
       
    28 
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // Folder list item constructor.
       
    32 // ---------------------------------------------------------------------------
       
    33 CFSEmailUiFolderListItem::CFSEmailUiFolderListItem()
       
    34 	: iListId( KFsTreeNoneID ), 
       
    35 	  iFolderId( TFSMailMsgId() ),
       
    36 	  iMailboxId( TFSMailMsgId() ),
       
    37 	  iSortField( EFSMailDontCare )
       
    38 	{
       
    39     FUNC_LOG;
       
    40 	}
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // Folder list item destructor.
       
    44 // ---------------------------------------------------------------------------
       
    45 CFSEmailUiFolderListItem::~CFSEmailUiFolderListItem()
       
    46 	{
       
    47     FUNC_LOG;
       
    48 	}
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // NewL
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CFSEmailUiFolderListItem* CFSEmailUiFolderListItem::NewL()
       
    55     {
       
    56     FUNC_LOG;
       
    57     CFSEmailUiFolderListItem* self = CFSEmailUiFolderListItem::NewLC();
       
    58     CleanupStack::Pop(self);
       
    59     return self;
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // NewLC
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CFSEmailUiFolderListItem* CFSEmailUiFolderListItem::NewLC()
       
    67 	{
       
    68     FUNC_LOG;
       
    69     CFSEmailUiFolderListItem* self = new (ELeave) CFSEmailUiFolderListItem();
       
    70     CleanupStack::PushL(self);
       
    71     return self;
       
    72 	}
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // Constructor
       
    76 // ---------------------------------------------------------------------------
       
    77 CFSEmailUiFolderListModel::CFSEmailUiFolderListModel()
       
    78 	{
       
    79     FUNC_LOG;
       
    80 	}
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // Destructor.
       
    84 // ---------------------------------------------------------------------------
       
    85 CFSEmailUiFolderListModel::~CFSEmailUiFolderListModel()
       
    86 	{
       
    87     FUNC_LOG;
       
    88 	RemoveAll();
       
    89 	iItemArray.Close();
       
    90 	}
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // Add an item to the end of the list.
       
    94 // ---------------------------------------------------------------------------
       
    95 void CFSEmailUiFolderListModel::AppendL( TFsTreeItemId aListId, CFSMailFolder* aFolder )
       
    96 	{
       
    97     FUNC_LOG;
       
    98 	CFSEmailUiFolderListItem* item = CFSEmailUiFolderListItem::NewLC();
       
    99 	item->iListId = aListId;
       
   100 	item->iFolderId = aFolder->GetFolderId();
       
   101 	iItemArray.AppendL( item );
       
   102     CleanupStack::Pop( item );
       
   103 	}
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // Add an item to the end of the list.
       
   107 // ---------------------------------------------------------------------------
       
   108 void CFSEmailUiFolderListModel::AppendL( TFsTreeItemId aListId, CFSMailBox* aMailbox )
       
   109 	{
       
   110     FUNC_LOG;
       
   111 	CFSEmailUiFolderListItem* item = CFSEmailUiFolderListItem::NewLC();
       
   112 	item->iListId = aListId;
       
   113 	item->iMailboxId = aMailbox->GetId();
       
   114 	iItemArray.AppendL( item );
       
   115     CleanupStack::Pop( item );
       
   116 	}
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // Add an item to the end of the list.
       
   120 // ---------------------------------------------------------------------------
       
   121 void CFSEmailUiFolderListModel::AppendL( TFsTreeItemId aListId, TFSMailSortField aSortField )
       
   122 	{
       
   123     FUNC_LOG;
       
   124 	CFSEmailUiFolderListItem* item = CFSEmailUiFolderListItem::NewLC();
       
   125 	item->iListId = aListId;
       
   126 	item->iSortField = aSortField;
       
   127 	iItemArray.AppendL( item );
       
   128     CleanupStack::Pop( item );
       
   129 	}
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // Remove item by list item id.
       
   133 // ---------------------------------------------------------------------------
       
   134 void CFSEmailUiFolderListModel::Remove( TFsTreeItemId aListId )
       
   135 	{
       
   136     FUNC_LOG;
       
   137 	TInt index = Index( aListId );
       
   138 	if( index != KErrNotFound )
       
   139 		{
       
   140 		delete iItemArray[index];
       
   141 		iItemArray.Remove( index );
       
   142 		}
       
   143 	}
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // Remove all items.
       
   147 // ---------------------------------------------------------------------------	
       
   148 void CFSEmailUiFolderListModel::RemoveAll()
       
   149 	{
       
   150     FUNC_LOG;
       
   151 	iItemArray.ResetAndDestroy();
       
   152 	iSeparatorCount = 0;
       
   153 	}
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // get an item by list item id.
       
   157 // 
       
   158 // @return NULL if not found.
       
   159 // ---------------------------------------------------------------------------
       
   160 CFSEmailUiFolderListItem* CFSEmailUiFolderListModel::ItemByListId( TFsTreeItemId aListId ) const
       
   161 	{
       
   162     FUNC_LOG;
       
   163 	TInt index = Index( aListId );
       
   164 	if( index != KErrNotFound )
       
   165 		{
       
   166 		return iItemArray[ index ];
       
   167 		}
       
   168 	else
       
   169 		{
       
   170 		return NULL;
       
   171 		}
       
   172 	}
       
   173 	
       
   174 // ---------------------------------------------------------------------------
       
   175 // get an item by list index.
       
   176 // 
       
   177 // @return NULL if not found.
       
   178 // ---------------------------------------------------------------------------
       
   179 CFSEmailUiFolderListItem* CFSEmailUiFolderListModel::ItemByIndex( TInt aModelIndex ) const
       
   180 	{
       
   181     FUNC_LOG;
       
   182 	return iItemArray[ aModelIndex ];
       
   183 	}
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // Get number of items in list.
       
   187 // 
       
   188 // @return Number of items.
       
   189 // ---------------------------------------------------------------------------		
       
   190 TInt CFSEmailUiFolderListModel::Count() const
       
   191 	{
       
   192     FUNC_LOG;
       
   193 	return iItemArray.Count();
       
   194 	}
       
   195 	
       
   196 // ---------------------------------------------------------------------------      
       
   197 // Get number of separators in list.
       
   198 // 
       
   199 // @return Number of separators in list.
       
   200 // ---------------------------------------------------------------------------
       
   201 TInt CFSEmailUiFolderListModel::SeparatorCount() const
       
   202     {
       
   203     FUNC_LOG;
       
   204     return iSeparatorCount;
       
   205     }
       
   206 
       
   207 // ---------------------------------------------------------------------------      
       
   208 // Increase separator count in list. 
       
   209 // 
       
   210 // @param aIncreaseBy How much separator count is increased, defaut is 1.
       
   211 //                    If parameter is negative, then the count is decreased.
       
   212 // ---------------------------------------------------------------------------      
       
   213 void CFSEmailUiFolderListModel::IncreaseSeparatorCount( TInt aIncreaseBy )
       
   214     {
       
   215     FUNC_LOG;
       
   216     iSeparatorCount += aIncreaseBy;
       
   217     }
       
   218 
       
   219 // ---------------------------------------------------------------------------
       
   220 // Get the array index of the spcified item.
       
   221 // 
       
   222 // @return Array index of the item.
       
   223 // ---------------------------------------------------------------------------		
       
   224 TInt CFSEmailUiFolderListModel::Index( TFsTreeItemId aListId ) const
       
   225 	{
       
   226     FUNC_LOG;
       
   227 	for( TInt i = 0; i < Count(); i++ )
       
   228 		{
       
   229 		if( iItemArray[i]->iListId == aListId )
       
   230 			{
       
   231 			return i;
       
   232 			}
       
   233 		}
       
   234 	return KErrNotFound;
       
   235 	}
       
   236