emailservices/emailstore/message_store/server/inc/MsgStoreInMemorySortRowSet.h
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Message store in memory sort row set.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef MSGSTORE_IN_MEMORY_SORT_ROW_SET
       
    20 #define MSGSTORE_IN_MEMORY_SORT_ROW_SET
       
    21 
       
    22 #include "MsgStoreSortResultRowSet.h"
       
    23 
       
    24 class CContainerStoreSortingTable;
       
    25 
       
    26 class CIntegerRow : public CBase
       
    27 {
       
    28 public:
       
    29     CIntegerRow( TMsgStoreId aMessageId, TInt64 aDate, TInt32 aValue );
       
    30     virtual ~CIntegerRow();
       
    31     
       
    32     //sort by date
       
    33     static TInt DateAsc(const CIntegerRow& aFirst, const CIntegerRow& aSecond);
       
    34     static TInt DateDesc(const CIntegerRow& aFirst, const CIntegerRow& aSecond);
       
    35     
       
    36     //sort by int value and date
       
    37     static TInt ValueAscDateAsc(const CIntegerRow& aFirst, const CIntegerRow& aSecond);
       
    38     static TInt ValueAscDateDesc(const CIntegerRow& aFirst, const CIntegerRow& aSecond);
       
    39     static TInt ValueDescDateAsc(const CIntegerRow& aFirst, const CIntegerRow& aSecond);
       
    40     static TInt ValueDescDateDesc(const CIntegerRow& aFirst, const CIntegerRow& aSecond);
       
    41     
       
    42     //sort by Id
       
    43     static TInt MessageIdAsc( const CIntegerRow& aFirst, const CIntegerRow& aSecond );
       
    44     
       
    45     inline TMsgStoreId MessageId() { return iMessageId; };
       
    46     inline TInt32 Value() { return iValue; }; 
       
    47     inline TInt64 ReceivedTime() { return iDate; };
       
    48     
       
    49 private:    
       
    50     TMsgStoreId iMessageId;
       
    51     TInt64      iDate;
       
    52     TInt32      iValue;
       
    53 };
       
    54 
       
    55 class CIntegerSortGroup : public CBase
       
    56     {
       
    57 public:    
       
    58 	CIntegerSortGroup( TInt64 aValue );
       
    59     virtual ~CIntegerSortGroup();
       
    60     
       
    61     static TInt ValueAscAndUpdateCount( const CIntegerSortGroup& aFirst, const CIntegerSortGroup& aSecond );
       
    62     static TInt ValueDescAndUpdateCount( const CIntegerSortGroup& aFirst, const CIntegerSortGroup& aSecond );
       
    63     
       
    64     static TInt ValueAsc( const CIntegerSortGroup& aFirst, const CIntegerSortGroup& aSecond );
       
    65     static TInt ValueDesc( const CIntegerSortGroup& aFirst, const CIntegerSortGroup& aSecond );
       
    66     
       
    67     inline TInt Count() { return iCount; }
       
    68     inline void DecrementCount() { --iCount; }
       
    69     
       
    70 private:    
       
    71     TInt64 iValue;
       
    72     mutable TUint iCount;
       
    73     };
       
    74 
       
    75 // ==================================
       
    76 // CLASS: CMsgStoreSortResultRowSet
       
    77 // ==================================
       
    78 class CMsgStoreInMemorySortRowSet : public CMsgStoreSortResultRowSet
       
    79 	{
       
    80 
       
    81 	public:
       
    82 		static CMsgStoreInMemorySortRowSet* NewL( const TMsgStoreSortCriteria& aSortCriteria, CContainerStoreSortingTable& aSortingTable );
       
    83 		virtual ~CMsgStoreInMemorySortRowSet();
       
    84         
       
    85         RDbView& DbView() { return iDbView; };
       
    86 		
       
    87 		virtual void ToTopL();
       
    88         virtual void ToEndL();
       
    89 		
       
    90         virtual TBool HasMorePreviousL();
       
    91         virtual TBool HasMoreNextL();
       
    92 		
       
    93 		//CMsgStoreSortResultRow* NextL();
       
    94         virtual TMsgStoreId NextL();          
       
    95         
       
    96         //CMsgStoreSortResultRow* PreviousL();
       
    97 		virtual TMsgStoreId PreviousL();      
       
    98 		
       
    99 		virtual void GotoL( TContainerId aMessageId );
       
   100         //virtual void GotoL( const TDesC& aStartWith, TMsgStoreIteratorDirection aDirection );
       
   101 
       
   102         //for UI "group" support
       
   103         virtual TBool SkipCurrentGroupL( TMsgStoreIteratorDirection aDirection, TUint& aItemsInGroup );
       
   104         
       
   105         virtual TInt GroupCountL( RArray<TUint>& aItemsInGroup );
       
   106         
       
   107         virtual void SortedIdsL( RArray<TContainerId>& aIdArray );
       
   108         
       
   109         virtual TInt IndexOfL( TContainerId aMessageId );
       
   110         
       
   111         //add a un-sorted row to the result set
       
   112         void AppendL( CIntegerRow* aRow );
       
   113         
       
   114         //this method must be called after all the rows have been added
       
   115         void SortL();
       
   116         
       
   117         virtual void MessageUpdate ( TContainerId       aMessageId, 
       
   118                                      TContainerId       aFolderId, 
       
   119                                      TMsgStoreOperation aOperation,
       
   120                                      TUint              aFieldsChanged,
       
   121                                      const TDesC&       aFrom, 
       
   122                                      const TDesC&       aTo, 
       
   123                                      const TDesC&       aSubject,
       
   124                                      TInt64             aDate);
       
   125 
       
   126         virtual void FolderDeleted ( TContainerId aFolderId );
       
   127         
       
   128         virtual void MailBoxDeleted ( TContainerId aMailBoxId );
       
   129 		
       
   130 	protected:
       
   131             
       
   132 	    CMsgStoreInMemorySortRowSet( const TMsgStoreSortCriteria& aSortCriteria, CContainerStoreSortingTable& aSortingTable );
       
   133 		void ConstructL();
       
   134         void InsertInOrderL( CIntegerRow* aRow );
       
   135         void DeleteAllRowsL();
       
   136         void AddRowL( TContainerId aMessageId, TInt64 aDate, TInt32 aValue );
       
   137         void DeleteRowL( TContainerId aMessageId );
       
   138         void UpdateRowL( TContainerId aMessageId, TInt64 aDate, TInt32 aValue );
       
   139         
       
   140         void InitState();
       
   141         
       
   142         void ResetAndEvaluateViewL();
       
   143         
       
   144         void UpdateGroupListL( TInt64 aValue );
       
   145         
       
   146         TInt64 GetGroupValue( CIntegerRow& aRow );
       
   147         TInt32 GetValueFromSortingTableL( TContainerId aMessageId );
       
   148         void GetDateRangeL( CIntegerRow& aRow, TMsgStoreIteratorDirection aDirection, TInt64& aDateStart, TInt64& aDateEnd );
       
   149         void GetStartOfLocalDayL( TInt64 aTime, TTime& aDayBoundary );
       
   150         
       
   151     private:
       
   152         
       
   153         void DoMessageUpdateL ( TContainerId       aMessageId, 
       
   154                                 TContainerId       aFolderId, 
       
   155                                 TMsgStoreOperation aOperation,
       
   156                                 TUint              aFieldsChanged,
       
   157                                 const TDesC&       aFrom, 
       
   158                                 const TDesC&       aTo, 
       
   159                                 const TDesC&       aSubject,
       
   160                                 TInt64             aDate);
       
   161     private:
       
   162         TInt                         iCursorInWindow;
       
   163         RDbView                      iDbView;
       
   164         TMsgStoreSortCriteria        iSortCriteria;
       
   165         CContainerStoreSortingTable& iSortingTable;
       
   166         
       
   167         RPointerArray<CIntegerRow>  iSortedIdArray;
       
   168         RPointerArray<CIntegerRow>  iSortedResultArray;
       
   169         
       
   170         //function pointer for current sorting method
       
   171         TInt (*iSortMethod)(const CIntegerRow& aFirst, const CIntegerRow& aSecond);
       
   172         
       
   173         RPointerArray<CIntegerSortGroup> iGroupNameArray;
       
   174         
       
   175         TTimeIntervalSeconds          iUtcOffsetInSeconds;
       
   176         
       
   177         __LOG_DECLARATION
       
   178 	};
       
   179 
       
   180 #endif /*MSGSTORE_IN_MEMORY_SORT_ROW_SET*/