email/pop3andsmtpmtm/imapservermtm/inc/IMPSMTM.H
changeset 25 84d9eb65b26f
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
       
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __IMPSMTM_H__
       
    17 #define __IMPSMTM_H__
       
    18 
       
    19 #include <mtsr.h>
       
    20 #include <msvstd.h>
       
    21 
       
    22 #include <imapset.h>
       
    23 #include <imapcmds.h>
       
    24 #include "mimapsessionobserver.h"
       
    25 
       
    26 #include <offop.h>
       
    27 
       
    28 // Forward declarations
       
    29 class CImImap4Session;
       
    30 class CImImap4FolderSync;
       
    31 class CImImap4Synchronise;
       
    32 class CImap4ServerMtm;
       
    33 class CImImap4Compound;
       
    34 class CImap4OffLineControl;
       
    35 class CImap4Utils;
       
    36 
       
    37 //******************
       
    38 // MActiveWrapperObserver - A Mixin class which provides mechanism to communicate to CActiveOwner
       
    39 //******************
       
    40 class MActiveWrapperObserver
       
    41 /**
       
    42 @internalComponent
       
    43 @released
       
    44 */
       
    45 	{
       
    46 public:	
       
    47 	virtual void RequestCompleted(TInt aChildActiveObjectID, TInt aError)=0;
       
    48 	virtual void Activate()=0;
       
    49 	virtual void NonCompletedFailureOnSession(TInt aId)=0;
       
    50 	};
       
    51 
       
    52 //*******************
       
    53 // CActiveWrapper - The wrapper class which owns a CmsgActive and signals its Cactive parent
       
    54 //*******************
       
    55 
       
    56 // CActiveWrapper is the 'thin' CActive object which wraps each of your CMsgActive objects
       
    57 class CActiveWrapper : public CActive, public MImapSessionObserver
       
    58 /**
       
    59 @internalComponent
       
    60 @released
       
    61 */
       
    62 	{
       
    63 public:
       
    64 	static CActiveWrapper* NewL(TInt aID);
       
    65 	void StartL(MActiveWrapperObserver* aManager);
       
    66 	~CActiveWrapper();
       
    67 	TRequestStatus* SessionStatus();
       
    68 	void SetEntry(CMsvServerEntry* aEntry);
       
    69 	
       
    70 	// Return of current imap4session
       
    71 	CImImap4Session* GetImap4Session();
       
    72 	
       
    73 protected:
       
    74 	void RunL();
       
    75 	void DoCancel();
       
    76 	void DoComplete(TInt aStatus);
       
    77 
       
    78 private:
       
    79 	CActiveWrapper(TInt aID);
       
    80 	void ConstructL();
       
    81 
       
    82 	// From MImapSessionObserver
       
    83 	void NonCompletedFailure();
       
    84 private:
       
    85 	TInt iID;							// my unique ID which my parent uses to identify me
       
    86 	MActiveWrapperObserver* iParentPtr;	// handle to my parent (and hence its Completed() function)
       
    87 
       
    88 protected:
       
    89 	// The session which CActiveWrapper owns
       
    90 	CImImap4Session*	iSession;
       
    91 
       
    92 	// Class for compound operations
       
    93 	CImImap4Compound*	iCompound;
       
    94 
       
    95 	// Full synchronise class (only ever instantiated on primary session)
       
    96 	CImImap4Synchronise*	iFullSync;
       
    97 
       
    98 private:
       
    99 	friend class CImap4ServerMtm;
       
   100 	};
       
   101 
       
   102 // package buffer for progress info.
       
   103 typedef TPckgBuf<TImap4CompoundProgress> TImap4ProgressBuf;
       
   104 
       
   105 // States that MTM can be in
       
   106 /**
       
   107 @internalComponent
       
   108 @released
       
   109 */
       
   110 enum TMtmState
       
   111 	{
       
   112 	EMtmStateIdle=0,
       
   113 	EMtmStateCopyToLocal,
       
   114 	EMtmStateCopyFromLocal,
       
   115 	EMtmStateCopyWithinService,
       
   116 	EMtmStateMoveToLocal,
       
   117 	EMtmStateMoveFromLocal,
       
   118 	EMtmStateMoveWithinService,
       
   119 	EMtmStateDeleteAfterMove,
       
   120 	EMtmStateDelete,
       
   121 	EMtmStateDeleteFolder,
       
   122 	EMtmStateCreateFolder,
       
   123 	EMtmStateRenameFolder,
       
   124 	EMtmStatePrimaryConnect,
       
   125 	EMtmStateSecondaryConnect,
       
   126 	EMtmStateForegroundSync,
       
   127 	EMtmStateMiscCommand,
       
   128 	EMtmStateWaitingForBackgroundToFinish,
       
   129 	EMtmStateSyncCompleted,
       
   130 	EMtmStatePopulate,
       
   131 	EMtmStateLogging,
       
   132 	EMtmStateOffLineDelete,
       
   133 	EMtmStateOffLineUndelete,
       
   134 	EMtmStateOffLineCopyToLocal,
       
   135 	EMtmStateOffLineMoveToLocal,
       
   136 	EMtmStateOffLineCopyFromLocal,
       
   137 	EMtmStateOffLineMoveFromLocal,
       
   138 	EMtmStateOffLineCopyWithinService,
       
   139 	EMtmStateOffLineMoveWithinService,
       
   140 	EMtmStateOffLinePopulate,
       
   141 	EMtmStateSecondarySessionIdle
       
   142 	};
       
   143 
       
   144 class CImap4ServerMtm : public CBaseServerMtm, public MActiveWrapperObserver
       
   145 /**
       
   146 @internalTechnology
       
   147 @released
       
   148 */
       
   149 	{
       
   150 public:
       
   151 	IMPORT_C static CImap4ServerMtm* NewL(CRegisteredMtmDll& aRegisteredMtmDll,CMsvServerEntry* aEntry);
       
   152 	~CImap4ServerMtm();
       
   153 
       
   154 	void CopyToLocalL(const CMsvEntrySelection& aSelection,TMsvId aDestination, TRequestStatus& aStatus);
       
   155 	void CopyFromLocalL(const CMsvEntrySelection& aSelection,TMsvId aDestination, TRequestStatus& aStatus);
       
   156 	void CopyWithinServiceL(const CMsvEntrySelection& aSelection,TMsvId aDestination, TRequestStatus& aStatus);
       
   157 	void MoveToLocalL(const CMsvEntrySelection& aSelection,TMsvId aDestination, TRequestStatus& aStatus);
       
   158 	void MoveFromLocalL(const CMsvEntrySelection& aSelection,TMsvId aDestination, TRequestStatus& aStatus);
       
   159 	void MoveWithinServiceL(const CMsvEntrySelection& aSelection,TMsvId aDestination, TRequestStatus& aStatus);
       
   160 	void DeleteAllL(const CMsvEntrySelection& aSelection, TRequestStatus& aStatus);
       
   161 	void CreateL(TMsvEntry aNewEntry, TRequestStatus& aStatus);
       
   162 	void ChangeL(TMsvEntry aNewEntry, TRequestStatus& aStatus);
       
   163 	//
       
   164 	void StartCommandL(CMsvEntrySelection& aSelection, TInt aCommand, const TDesC8& aParameter, TRequestStatus& aStatus);
       
   165 	//
       
   166 	TBool CommandExpected();
       
   167 	//
       
   168 	const TDesC8& Progress();
       
   169 
       
   170 	// What state we're in
       
   171 	enum
       
   172 		{
       
   173 		EBothIdle=0,
       
   174 		EPrimaryBusy,
       
   175 		EBothBusy,
       
   176 		ESecondaryBusy
       
   177 		};
       
   178 protected:
       
   179 	void DoCancel();
       
   180 	void DoRunL();
       
   181 	void DoComplete(TInt aError);
       
   182 	
       
   183 	// From MActiveWrapperObserver
       
   184 	void RequestCompleted(TInt aId, TInt aCode);
       
   185 	void Activate();
       
   186 	void NonCompletedFailureOnSession(TInt aId);
       
   187 
       
   188 private:
       
   189 	CImap4ServerMtm(CRegisteredMtmDll& aRegisteredMtmDll,CMsvServerEntry* aEntry);
       
   190 	void ConstructL();
       
   191 	TInt CheckSelectionL(const CMsvEntrySelection& aSelection,
       
   192 					 	 CMsvEntrySelection* aLocalCopy,
       
   193 				 		 const TBool aMessages,
       
   194 				 		 const TBool aParts,
       
   195 						 const TBool aFolders,
       
   196 						 const TBool aIsInService);
       
   197 //	void SaveOperationL(CImOffLineOperation& aOperation);
       
   198 	void MessageErrorL(const TMsvId aMessageId, const TInt aError);
       
   199 	TInt SetLocalSubscription(const TMsvId aFolder, const TBool aSubscribed);
       
   200 	void MtmCommandL(const TInt aType,const CMsvEntrySelection& aSelection, TMsvId aDestination, TRequestStatus& aStatus);
       
   201 	void MarkOnOrOfflineL(const TBool aOnline);
       
   202 	void ChangeVisibilityL(TMsvId aParent, TBool aInvisible);
       
   203 	void ChangeVisibilityL(TMsvId aParent, TBool aInvisible, TBool aRecurse, TUid aType);
       
   204 	void PropagateInvisibleFlagL(TMsvId aId);
       
   205 	void GoneOffline();
       
   206 
       
   207 	// Set entry, leave if error (not related to setentry() which sets iEntry)
       
   208 	void SetEntryL(const TMsvId aId);
       
   209 
       
   210 	// Change entry, leave if error
       
   211 	void ChangeEntryL(const TMsvEntry& aEntry);
       
   212 
       
   213 	// Get children, leave if error
       
   214 	void GetChildrenL(CMsvEntrySelection& aSelection);
       
   215 
       
   216 	void DeleteEntryL(TMsvId aId);
       
   217 	void UndeleteAllL(const CMsvEntrySelection& aSelection, TRequestStatus& aStatus);
       
   218 
       
   219 	// now used instead of ChangeL
       
   220 	TBool RenameFolderL(TMsvId aId, const TImap4RenameFolder& aRename);
       
   221 
       
   222 	// load or reload service settings
       
   223 	void LoadSettingsL(TMsvId aId);
       
   224 
       
   225 	void ClearNewFlagL(TMsvId aParent);
       
   226 
       
   227 	TBool PruneMessages(const CMsvEntrySelection& aSelection);
       
   228 	TBool IsPartialPopulate(TDes8& aParameter);
       
   229 
       
   230 private:
       
   231 	TInt						iProgressMsgsToDo;
       
   232 	TInt						iProgressMsgsDone;
       
   233 	TInt						iProgressErrorCode;
       
   234 	TImap4ProgressBuf			iProgressBuf;
       
   235 
       
   236 	TImap4GenericProgress::TImap4GenericProgressState	iLastSessionState;
       
   237 	TImap4GenericProgress::TImap4GenericProgressOp		iRequestedOperation;
       
   238 
       
   239 	TMsvId						iServiceId;
       
   240 
       
   241 	// Copy of the service's settings
       
   242 	CImImap4Settings*			iServiceSettings;
       
   243 
       
   244 	// Internal state for multipart operations
       
   245 	TMtmState					iState;
       
   246 	TMtmState					iSavedState;
       
   247 	TInt						iLastCommand;
       
   248 	CMsvEntrySelection*			iSelection;
       
   249 	CMsvEntrySelection*			iOneSelection;
       
   250 	TMsvId						iDestination;
       
   251 
       
   252 	// The two sessions that we can deal with
       
   253 	CActiveWrapper*				iPrimarySession;
       
   254 	CActiveWrapper*				iSecondarySession;
       
   255 
       
   256 	// the object that manages our offline operations
       
   257 	CImap4OffLineControl*		iOffLineControl;
       
   258 	
       
   259 	// The session the last command was issued to
       
   260 	CActiveWrapper*				iCurrentSession;
       
   261 	TInt						iId;
       
   262 	TInt						iCode;
       
   263 
       
   264 	// State of sessions
       
   265 	//TInt						iSessionState;
       
   266 	TBool						iBackgroundSyncInProgress;
       
   267 	TBool						iBatchInProgress;
       
   268 
       
   269 	// Can we be deleted now?
       
   270 	TBool						iCanBeDeletedNow;
       
   271 
       
   272 	// Should we clear New flag on messages?
       
   273 	TBool						iClearNewFlagOnNextSync;
       
   274 
       
   275 	TRequestStatus*				iRequest;
       
   276 
       
   277 	TImap4GetMailOptions		iGetMailOptions;
       
   278 
       
   279 	CImap4Utils*				iUtils;
       
   280 
       
   281 	TInt						iTotalSize;
       
   282 	TImImap4GetPartialMailInfo	iPartialMailInfo;
       
   283 	};
       
   284 #endif