emailservices/emailclientapi/inc/messageiterator.h
changeset 0 8466d47a6819
child 4 e7aa27f58ae1
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2009 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: Email message iterator
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef CMESSAGEITERATOR_H
       
    19 #define CMESSAGEITERATOR_H
       
    20                                                                              
       
    21 #include <MMessageIterator.h>                                                                             
       
    22 #include "emailapidefs.h"
       
    23 #include "CFSMailCommon.h"
       
    24 
       
    25 using namespace EmailInterface;
       
    26 
       
    27 class MFSMailIterator;
       
    28 class CPluginData;
       
    29 class CFSMailMessage;
       
    30 class CEmailMessage;
       
    31 /**
       
    32  * Iterator for email messages
       
    33  * @since S60 v5.2
       
    34  */
       
    35 NONSHARABLE_CLASS( CMessageIterator ) : public CBase, public MMessageIterator
       
    36 {
       
    37 public:
       
    38     /**
       
    39     * Constructor
       
    40     * @param aIterator
       
    41     * @param aPluginData
       
    42     * @return new iterator
       
    43     */
       
    44     static CMessageIterator* NewL( MFSMailIterator* aIterator,
       
    45                                    CPluginData& aPluginData,
       
    46                                    TUint aCount );
       
    47     
       
    48     ~CMessageIterator();
       
    49 
       
    50 private:
       
    51     CMessageIterator( MFSMailIterator* aIterator, CPluginData& aPluginData, TUint aCount );
       
    52     
       
    53     void ConstructL();
       
    54     
       
    55 public: // from MEmailInterface              
       
    56 
       
    57     virtual TEmailTypeId InterfaceId() const;
       
    58 
       
    59     virtual void Release();
       
    60     
       
    61 public: // from MMessageIterator
       
    62 
       
    63     /** @see MMessageIterator */
       
    64     virtual MEmailMessage* NextL();
       
    65     
       
    66     /** @see MMessageIterator 
       
    67      (not implemented) */
       
    68     
       
    69     virtual MEmailMessage* PreviousL();
       
    70     
       
    71     virtual TUint Count() const;
       
    72         
       
    73 
       
    74 private:   
       
    75     // Reads next chunk of messages from protocol plugin
       
    76     TBool ReadNextChunkL();
       
    77     TBool ReadPreviousChunkL();
       
    78     MEmailMessage* ReadFromChunkL();
       
    79     void CleanCache();    
       
    80     void AddToCacheL( CFSMailMessage* aFsMsg );    
       
    81 private: // data
       
    82     
       
    83     /**
       
    84     * Iterator internal states. "Consuming" in state names mean getting and 
       
    85     * returning next message from the iterator.
       
    86     */
       
    87     enum TState {
       
    88         // No messages available in iterator, read them from protocl plugin.
       
    89         // NextL returns a message from chunk (or NULL if folder is empty)
       
    90         // This is initial state.
       
    91         EReadNextMessageChunk,
       
    92         EReadPreviousMessageChunk,
       
    93         
       
    94         // Message(s) are available (retrieved from plugin). No remaining 
       
    95         // messages excepted from the plugin. NextL returns a message from chunk.
       
    96         EConsumeFromChunk,
       
    97         
       
    98         // Message(s) are available in chunk and more in protocol plugin.
       
    99         EConsumeFromChunkWithMoreChunksToFollow,
       
   100         
       
   101         // Iterator is iterated throuh and NextL would return NULL.
       
   102         EIteratorConsumed
       
   103     };
       
   104 
       
   105     // plugin iterator, owned
       
   106     MFSMailIterator* iIterator;
       
   107     
       
   108     // reference to plugin data
       
   109     CPluginData&    iPluginData;
       
   110 
       
   111     CFSMailPlugin*  iPlugin;
       
   112     
       
   113     // message id used for reading messages from plugin
       
   114     TFSMailMsgId    iStartMsgId;
       
   115     
       
   116     // Internal state  
       
   117     TState           iState;
       
   118     
       
   119     // pointer array of messages read from protocol plugin (aka message chunk)
       
   120     RPointerArray<CFSMailMessage> iFsMessageArray;
       
   121     RPointerArray<CEmailMessage> iMessageArray;
       
   122     
       
   123     TUint iCount;
       
   124     
       
   125     TInt iCursor;
       
   126     
       
   127     TFSMailMsgId iFirstMsgId;
       
   128     
       
   129     TBool iHasMoreNextItems;
       
   130     TBool iHasMorePrevItems;
       
   131 };
       
   132 
       
   133 #endif // CMESSAGEITERATOR_H
       
   134 
       
   135 // End of file.