williamr@2: // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2: // All rights reserved.
williamr@2: // This component and the accompanying materials are made available
williamr@4: // under the terms of "Eclipse Public License v1.0"
williamr@2: // which accompanies this distribution, and is available
williamr@4: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
williamr@2: //
williamr@2: // Initial Contributors:
williamr@2: // Nokia Corporation - initial contribution.
williamr@2: //
williamr@2: // Contributors:
williamr@2: //
williamr@2: // Description:
williamr@4: // CACHEMAN.H
williamr@2: //
williamr@4: /**
williamr@4:  * @file 
williamr@4:  * @publishedAll
williamr@4:  * @released
williamr@4:  */
williamr@2: #if !defined (__CACHEMAN_H__)
williamr@2: #define __CACHEMAN_H__
williamr@2: 
williamr@2: #include <mentact.h>
williamr@2: #include <msvstd.h>
williamr@2: #include <msvapi.h>
williamr@4: #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS  
williamr@4: #include <cimprunemessage.h>
williamr@4: #include "cimfinder.h"
williamr@4: #endif
williamr@2: 
williamr@4: class CImMessageFinder;
williamr@4: class CImMessageCounter;
williamr@2: 
williamr@2: struct TImCacheManagerProgress
williamr@2: /** Holds progress of a cache management cleanup operation.
williamr@2: 
williamr@2: @see CImCacheManager::ProgressL() 
williamr@2: @publishedAll
williamr@2: @released
williamr@2: */
williamr@2: 	{
williamr@2: public:
williamr@2: 	/** Total number of messages to process.
williamr@2: 	
williamr@2: 	Note that, immediately after a CImCacheManager object is started, the progress 
williamr@2: 	operation may return 1 for iTotalMessages and 0 for iMessagesProcessed, regardless 
williamr@2: 	of the total number of messages. This is because the counter for the iTotalMessages 
williamr@2: 	operates asynchronously and may not have counted all of the messages at that 
williamr@2: 	time. */
williamr@2: 	TInt iTotalMessages;
williamr@2: 	/** Number of messages processed so far. */
williamr@2: 	TInt iMessagesProcessed;
williamr@2: 	};
williamr@2: 
williamr@2: class CImCacheManager : public CMsvOperation
williamr@2: /** Provides management of the local cache of messages in remote mailboxes.
williamr@2: 
williamr@2: A mailbox that is being used in disconnected mode allows the user access to 
williamr@2: message data by opening the message directly from the remote mailbox. If the 
williamr@2: required message has been downloaded previously, then it will not necessarily 
williamr@2: need to be downloaded again. This functionality is achieved by preserving 
williamr@2: the message data locally, under the remote service entry. The preserved message 
williamr@2: data acts as a cache to allow the user access to the message without the need 
williamr@2: for it to be downloaded every time. 
williamr@2: 
williamr@2: The cache management functionality is required to reduce the amount of memory 
williamr@2: that is consumed by the message cache. CImCacheManager provides a mechanism 
williamr@2: for asynchronously traversing a message tree and for removing text and attachment 
williamr@2: data from messages. Deleting more message data will free up more memory but 
williamr@2: there is a higher chance that a user will need to download a message for a 
williamr@2: second time. 
williamr@2: 
williamr@2: CImCacheManager is an abstract base class, which can be specialised to implement 
williamr@2: a filter (Filter()) that decides if data for a message shoulded be deleted: 
williamr@2: for example, deletion could be restricted to 'all read messages over a week 
williamr@2: old,' or, 'all read messages, over 20K in size which are also over a day old.' 
williamr@2: @publishedAll
williamr@2: @released
williamr@2: */
williamr@2: 	{
williamr@2: public:
williamr@2: 	IMPORT_C void StartL(TMsvId aRootEntry, TRequestStatus &aStatus);
williamr@2: 	IMPORT_C void StartL(const CMsvEntrySelection& aSelection, TRequestStatus &aStatus);
williamr@2: 	IMPORT_C ~CImCacheManager();
williamr@2: 	IMPORT_C const TDesC8& ProgressL();
williamr@2: 	IMPORT_C void DoCancel();
williamr@2: 
williamr@2: protected:
williamr@2: 	IMPORT_C void ConstructL();
williamr@2: 	IMPORT_C CImCacheManager(CMsvSession& aSession, TRequestStatus& aObserverRequestStatus);
williamr@2: 
williamr@2: 	IMPORT_C void RunL();
williamr@2: 
williamr@2: private:
williamr@2: 	// Override this function to filter the currently selected message (iCurrentEntry).
williamr@2: 	// Return TRUE if the current entry is to be pruned.
williamr@2: 	/** Tests if cache cleanup should be performed on a message entry.
williamr@2: 	
williamr@2: 	After StartL() has been called, this is called once for each message entry. 
williamr@2: 	It should return true if the body text and attachment data belonging to the 
williamr@2: 	current message, as held in iCurrentEntry, should be deleted, or false if 
williamr@2: 	the message should be left unchanged.
williamr@2: 	
williamr@2: 	This function must be implemented in any classes derived from CImCacheManager.
williamr@2: 	
williamr@2: 	@return True to clean the entry, false to leave it unchanged */
williamr@2: 	virtual TBool Filter() const = 0;
williamr@2: 
williamr@2: 	void DoRunL();
williamr@2: 
williamr@2: 	// Remove the store from the currently selected entry
williamr@2: 	inline void PruneMessageL();
williamr@2: 	
williamr@2: protected:
williamr@2: 	/** Message entry currently being processed. */
williamr@2: 	CMsvEntry* iCurrentEntry;
williamr@2: 
williamr@2: private:
williamr@2: 	CMsvSession& iSession;
williamr@2: 	CImMessageFinder* iMessageFinder;
williamr@2: 	CImMessageCounter* iMessageCounter;
williamr@2: 	CMsvOperation* iDeleteOperation;
williamr@2: 
williamr@2: 	TImCacheManagerProgress iProgress;
williamr@2: 	TRequestStatus* iReport;
williamr@2: 
williamr@2: 	enum TImcmState
williamr@2: 		{
williamr@2: 		EImcmLookingForMessage,
williamr@2: 		EImcmPruningMessages,
williamr@2: 		EImcmCountingMessages,
williamr@2: 		EImcmSkippingPrune
williamr@2: 		};
williamr@2: 
williamr@2: 	TMsvId iRootEntry;
williamr@2: 	TImcmState iState;
williamr@2: 	TPckgBuf<TImCacheManagerProgress> iProgressBuf;
williamr@2: 
williamr@2: 	CMsvEntrySelection* iMessagesToPrune;
williamr@2: 	};
williamr@2: 
williamr@2: #endif