1 /* |
1 /* |
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
14 * Description: |
14 * Description: |
15 * Contains imap specified sync logic |
15 * Contains imap specified sync logic |
16 * |
16 * |
17 */ |
17 */ |
18 |
18 |
19 |
19 #include "ipssosaopluginheaders.h" |
20 #include "emailtrace.h" |
|
21 #include <cemailaccounts.h> |
|
22 #include <imapcmds.h> |
|
23 #include <miutset.h> |
|
24 #include <impcmtm.h> |
|
25 #include <msvapi.h> |
|
26 #include <AlwaysOnlineManagerCommon.h> |
|
27 //<cmail> |
|
28 #include "cfsmailcommon.h" |
|
29 //</cmail> |
|
30 |
|
31 |
|
32 #include "IpsSosAOImapAgent.h" |
|
33 #include "IpsSosAOImapPopLogic.h" |
|
34 |
|
35 |
|
36 // from settings |
|
37 #include "ipssetdataapi.h" |
|
38 #include "ipssetutilsconsts.h" |
|
39 |
|
40 // from ipsplugin |
|
41 #include "ipsplgimap4populateop.h" |
|
42 #include "ipsplgcommon.h" |
|
43 |
20 |
44 // ---------------------------------------------------------------------------- |
21 // ---------------------------------------------------------------------------- |
45 // ---------------------------------------------------------------------------- |
22 // ---------------------------------------------------------------------------- |
46 CIpsSosAOImapAgent::CIpsSosAOImapAgent( |
23 CIpsSosAOImapAgent::CIpsSosAOImapAgent( |
47 CMsvSession& aSession, |
24 CMsvSession& aSession, |
96 CActiveScheduler::Add(this); |
75 CActiveScheduler::Add(this); |
97 |
76 |
98 iMtmReg = CClientMtmRegistry::NewL( iSession ); |
77 iMtmReg = CClientMtmRegistry::NewL( iSession ); |
99 CBaseMtm* bmtm = iMtmReg->NewMtmL( KUidMsgTypeIMAP4 ); |
78 CBaseMtm* bmtm = iMtmReg->NewMtmL( KUidMsgTypeIMAP4 ); |
100 iImapClientMtm = static_cast<CImap4ClientMtm*>(bmtm); |
79 iImapClientMtm = static_cast<CImap4ClientMtm*>(bmtm); |
101 iDataApi = CIpsSetDataApi::NewL( iSession ); |
80 //<QMail> |
|
81 |
|
82 //</QMail> |
102 iState = EStateIdle; |
83 iState = EStateIdle; |
103 } |
84 } |
104 |
85 |
105 // ---------------------------------------------------------------------------- |
86 // ---------------------------------------------------------------------------- |
106 // ---------------------------------------------------------------------------- |
87 // ---------------------------------------------------------------------------- |
179 break; |
160 break; |
180 case EStateConnectAndSyncOnHold: |
161 case EStateConnectAndSyncOnHold: |
181 StartSyncL(); |
162 StartSyncL(); |
182 break; |
163 break; |
183 case EStateRefreshFolderArray: |
164 case EStateRefreshFolderArray: |
184 iDataApi->GetSubscribedImapFoldersL( iServiceId , iFoldersArray ); |
165 //<QMail> |
|
166 { |
|
167 CIpsSosAOSettingsHandler* settings = |
|
168 CIpsSosAOSettingsHandler::NewL(iSession, iServiceId); |
|
169 CleanupStack::PushL(settings); |
|
170 settings->GetSubscribedImapFoldersL( iServiceId , iFoldersArray ); |
|
171 CleanupStack::PopAndDestroy(settings); |
|
172 } |
|
173 //</QMail> |
185 iState = EStatePopulateAll; |
174 iState = EStatePopulateAll; |
186 SetActiveAndCompleteThis(); |
175 SetActiveAndCompleteThis(); |
187 break; |
176 break; |
188 case EStatePopulateAll: |
177 case EStatePopulateAll: |
189 PopulateAllL(); |
178 PopulateAllL(); |
194 case EStateFetchOngoing: |
183 case EStateFetchOngoing: |
195 break; |
184 break; |
196 case EStateFetchOnHold: |
185 case EStateFetchOnHold: |
197 break; |
186 break; |
198 case EStateDisconnect: |
187 case EStateDisconnect: |
|
188 NM_COMMENT("CIpsSosAOImapAgent: disconnecting"); |
199 if ( !iDoNotDisconnect ) |
189 if ( !iDoNotDisconnect ) |
200 { |
190 { |
201 CancelAllAndDisconnectL(); |
191 CancelAllAndDisconnectL(); |
202 } |
192 } |
203 else |
193 else |
205 iState = EStateCompleted; |
195 iState = EStateCompleted; |
206 SetActiveAndCompleteThis(); |
196 SetActiveAndCompleteThis(); |
207 } |
197 } |
208 break; |
198 break; |
209 case EStateCompleted: |
199 case EStateCompleted: |
|
200 NM_COMMENT("CIpsSosAOImapAgent: completed"); |
210 TRAP_IGNORE( iOpResponse.OperationCompletedL( iError ) ); |
201 TRAP_IGNORE( iOpResponse.OperationCompletedL( iError ) ); |
211 SignalSyncCompleted( iServiceId, iError ); |
202 SignalSyncCompleted( iServiceId, iError ); |
212 iError = KErrNone; |
203 iError = KErrNone; |
213 ClearSignaledFlags(); |
204 ClearSignaledFlags(); |
214 iState = EStateIdle; |
205 iState = EStateIdle; |
317 User::Leave( KErrNotReady ); |
308 User::Leave( KErrNotReady ); |
318 } |
309 } |
319 LoadSettingsL( ); |
310 LoadSettingsL( ); |
320 if ( !IsConnected() ) |
311 if ( !IsConnected() ) |
321 { |
312 { |
|
313 NM_COMMENT("CIpsSosAOImapAgent: starting sync"); |
322 TPckg<MMsvImapConnectionObserver*> parameter(this); |
314 TPckg<MMsvImapConnectionObserver*> parameter(this); |
323 // connect and synchronise starts background sync or idle |
315 // connect and synchronise starts background sync or idle |
324 CMsvEntrySelection* sel = new ( ELeave ) CMsvEntrySelection(); |
316 CMsvEntrySelection* sel = new ( ELeave ) CMsvEntrySelection(); |
325 CleanupStack::PushL( sel ); |
317 CleanupStack::PushL( sel ); |
326 sel->AppendL( iServiceId ); |
318 sel->AppendL( iServiceId ); |
332 SetActive(); |
324 SetActive(); |
333 iState = EStateConnectAndSync; |
325 iState = EStateConnectAndSync; |
334 } |
326 } |
335 else |
327 else |
336 { |
328 { |
|
329 NM_COMMENT("CIpsSosAOImapAgent: already connected do not sync"); |
337 // do not do anything if we are connected, especially do never |
330 // do not do anything if we are connected, especially do never |
338 // try to sync if sync is is already started (ex. from ips plugin) |
331 // try to sync if sync is is already started (ex. from ips plugin) |
339 // that cause problems with imap flags etc. |
332 // that cause problems with imap flags etc. |
340 iError = KErrNone; |
333 iError = KErrCancel; |
341 iState = EStateCompleted; |
334 iState = EStateCompleted; |
342 SetActiveAndCompleteThis(); |
335 SetActiveAndCompleteThis(); |
343 } |
336 } |
344 } |
337 } |
345 |
338 |
355 // ---------------------------------------------------------------------------- |
348 // ---------------------------------------------------------------------------- |
356 // ---------------------------------------------------------------------------- |
349 // ---------------------------------------------------------------------------- |
357 void CIpsSosAOImapAgent::CancelAllAndDisconnectL() |
350 void CIpsSosAOImapAgent::CancelAllAndDisconnectL() |
358 { |
351 { |
359 FUNC_LOG; |
352 FUNC_LOG; |
|
353 // if we are already idle state, do nothing, |
|
354 // completing in idle state might cause unvanted events to ui |
|
355 if (iState == EStateIdle) |
|
356 { |
|
357 return; |
|
358 } |
|
359 |
360 iDoNotDisconnect = EFalse; |
360 iDoNotDisconnect = EFalse; |
361 iState = EStateCompleted; |
361 iState = EStateCompleted; |
362 iFoldersArray.Reset(); |
362 iFoldersArray.Reset(); |
363 |
|
364 if ( IsActive() ) |
363 if ( IsActive() ) |
365 { |
364 { |
366 Cancel(); |
365 Cancel(); |
367 } |
366 } |
368 |
367 |
466 // ---------------------------------------------------------------------------- |
465 // ---------------------------------------------------------------------------- |
467 void CIpsSosAOImapAgent::PopulateAllL() |
466 void CIpsSosAOImapAgent::PopulateAllL() |
468 { |
467 { |
469 FUNC_LOG; |
468 FUNC_LOG; |
470 TImImap4GetPartialMailInfo info; |
469 TImImap4GetPartialMailInfo info; |
471 CIpsSetDataApi::ConstructImapPartialFetchInfo( info, *iImapSettings ); |
470 //<QMail> |
|
471 CIpsSosAOSettingsHandler* settings = |
|
472 CIpsSosAOSettingsHandler::NewL(iSession, iServiceId); |
|
473 CleanupStack::PushL(settings); |
|
474 settings->ConstructImapPartialFetchInfo( info, *iImapSettings ); |
|
475 CleanupStack::PopAndDestroy(settings); |
|
476 //</QMail> |
472 |
477 |
473 if ( !IsConnected() ) |
478 if ( !IsConnected() ) |
474 { |
479 { |
475 SignalSyncCompleted( iServiceId, iError ); |
480 SignalSyncCompleted( iServiceId, iError ); |
476 CancelAllAndDisconnectL(); |
481 CancelAllAndDisconnectL(); |
477 } |
482 } |
|
483 //<QMail> |
478 else if ( iFoldersArray.Count() > 0 && info.iTotalSizeLimit |
484 else if ( iFoldersArray.Count() > 0 && info.iTotalSizeLimit |
479 != KIpsSetDataHeadersOnly ) |
485 != KIpsSetDataHeadersOnly ) |
|
486 //</QMail> |
480 { |
487 { |
481 |
488 |
482 // only inbox is set, do we have to populate other folders also |
489 // only inbox is set, do we have to populate other folders also |
483 TMsvId id = iFoldersArray[0]; |
490 TMsvId id = iFoldersArray[0]; |
484 CMsvEntry* cEntry = iSession.GetEntryL( id ); |
491 CMsvEntry* cEntry = iSession.GetEntryL( id ); |
491 |
498 |
492 CIpsPlgTimerOperation* dummy = NULL; |
499 CIpsPlgTimerOperation* dummy = NULL; |
493 iImapClientMtm->SwitchCurrentEntryL( iServiceId ); |
500 iImapClientMtm->SwitchCurrentEntryL( iServiceId ); |
494 TFSMailMsgId mbox( KIpsPlgImap4PluginUidValue, iServiceId ); |
501 TFSMailMsgId mbox( KIpsPlgImap4PluginUidValue, iServiceId ); |
495 iStatus = KRequestPending; |
502 iStatus = KRequestPending; |
|
503 //<Qmail> |
496 iOngoingOp = CIpsPlgImap4PopulateOp::NewL( |
504 iOngoingOp = CIpsPlgImap4PopulateOp::NewL( |
497 iSession, |
505 iSession, |
498 this->iStatus, |
506 this->iStatus, |
499 CActive::EPriorityLow, |
|
500 iServiceId, |
507 iServiceId, |
501 *dummy, |
508 *dummy, |
502 info, |
509 info, |
503 *sel, |
510 *sel, |
504 mbox, |
511 mbox, |
505 *this, |
512 this, |
506 0, |
513 0, |
507 NULL ); |
514 NULL ); |
508 |
515 //</Qmail> |
509 iFoldersArray.Remove( 0 ); |
516 iFoldersArray.Remove( 0 ); |
510 SetActive(); |
517 SetActive(); |
511 iState = EStatePopulateAll; |
518 iState = EStatePopulateAll; |
512 CleanupStack::PopAndDestroy( 2, cEntry ); |
519 CleanupStack::PopAndDestroy( 2, cEntry ); |
513 |
520 |