|
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: ImapFolderSyncOperation.cpp |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <MuiuOperationWait.h> |
|
20 #include <mtmuibas.h> |
|
21 #include <imapcmds.h> |
|
22 #include <msvuids.h> |
|
23 #include <imapset.h> |
|
24 #include "ImapFolderSyncOperation.h" |
|
25 #include "EmailUtils.H" |
|
26 #include "ImumMtmLogging.h" |
|
27 |
|
28 // ---------------------------------------------------------------------------- |
|
29 // CImapFolderSyncOperation::NewL |
|
30 // ---------------------------------------------------------------------------- |
|
31 CImapFolderSyncOperation* CImapFolderSyncOperation::NewL( CImumInternalApi& aMailboxApi, TRequestStatus& aStatus, TMsvId aMailbox, CBaseMtmUi& aMtmUi ) |
|
32 { |
|
33 IMUM_STATIC_CONTEXT( CImapFolderSyncOperation::NewL, 0, mtm, KImumMtmLog ); |
|
34 IMUM_IN(); |
|
35 |
|
36 CImapFolderSyncOperation* self = new( ELeave ) CImapFolderSyncOperation( aMailboxApi, CActive::EPriorityIdle, aStatus, aMtmUi ); |
|
37 CleanupStack::PushL( self ); |
|
38 self->ConstructL( aMailbox ); |
|
39 CleanupStack::Pop( self ); |
|
40 IMUM_OUT(); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // ---------------------------------------------------------------------------- |
|
45 // CImapFolderSyncOperation::CImapFolderSyncOperation |
|
46 // ---------------------------------------------------------------------------- |
|
47 CImapFolderSyncOperation::CImapFolderSyncOperation(CImumInternalApi& aMailboxApi, TInt aPriority, TRequestStatus& aObserverRequestStatus, CBaseMtmUi& aMtmUi) |
|
48 : CMsvOperation(aMailboxApi.MsvSession(), aPriority, aObserverRequestStatus), |
|
49 iMtmUi( aMtmUi ), |
|
50 iMailboxApi( aMailboxApi ) |
|
51 { |
|
52 IMUM_CONTEXT( CImapFolderSyncOperation::CImapFolderSyncOperation, 0, KImumMtmLog ); |
|
53 IMUM_IN(); |
|
54 IMUM_OUT(); |
|
55 |
|
56 } |
|
57 |
|
58 |
|
59 // ---------------------------------------------------------------------------- |
|
60 // CImapFolderSyncOperation::~CImapFolderSyncOperation() |
|
61 // ---------------------------------------------------------------------------- |
|
62 CImapFolderSyncOperation::~CImapFolderSyncOperation() |
|
63 { |
|
64 IMUM_CONTEXT( CImapFolderSyncOperation::~CImapFolderSyncOperation, 0, KImumMtmLog ); |
|
65 IMUM_IN(); |
|
66 |
|
67 iTimer.Close(); |
|
68 delete iOperation; |
|
69 IMUM_OUT(); |
|
70 } |
|
71 |
|
72 |
|
73 // ---------------------------------------------------------------------------- |
|
74 // CImapFolderSyncOperation::ConstructL() |
|
75 // ---------------------------------------------------------------------------- |
|
76 void CImapFolderSyncOperation::ConstructL( TMsvId aMailbox ) |
|
77 { |
|
78 IMUM_CONTEXT( CImapFolderSyncOperation::ConstructL, 0, KImumMtmLog ); |
|
79 IMUM_IN(); |
|
80 |
|
81 iMailboxId = aMailbox; |
|
82 |
|
83 //get syncRate from imap4 settings. We use that for folder updates |
|
84 /*CImumMboxData* accountSettings = CImumMboxData::NewLC(); |
|
85 accountSettings->iImap4Settings = new(ELeave) CImImap4Settings; |
|
86 CMsvEntry* cEntry = iSession.GetEntryL( iMailboxId ); |
|
87 CleanupStack::PushL( cEntry ); |
|
88 MsvEmailMtmUiUtils::RestoreSettingsL( *cEntry, *( accountSettings->iImap4Settings ) ); |
|
89 iInterval = ( accountSettings->iImap4Settings->SyncRate() / KImumSecondsInMinute );//syncRate is in seconds |
|
90 CleanupStack::PopAndDestroy(2);//cEntry, accountSettings |
|
91 |
|
92 User::LeaveIfError( iTimer.CreateLocal() );*/ |
|
93 CActiveScheduler::Add(this); |
|
94 IMUM_OUT(); |
|
95 } |
|
96 |
|
97 |
|
98 // ---------------------------------------------------------------------------- |
|
99 // CImapFolderSyncOperation::ProgressL |
|
100 // ---------------------------------------------------------------------------- |
|
101 const TDesC8& CImapFolderSyncOperation::ProgressL() |
|
102 { |
|
103 IMUM_CONTEXT( CImapFolderSyncOperation::ProgressL, 0, KImumMtmLog ); |
|
104 IMUM_IN(); |
|
105 |
|
106 IMUM_OUT(); |
|
107 return iProgress; |
|
108 } |
|
109 |
|
110 // ---------------------------------------------------------------------------- |
|
111 // CImapFolderSyncOperation::SetInterval |
|
112 // ---------------------------------------------------------------------------- |
|
113 void CImapFolderSyncOperation::SetInterval() |
|
114 { |
|
115 IMUM_CONTEXT( CImapFolderSyncOperation::SetInterval, 0, KImumMtmLog ); |
|
116 IMUM_IN(); |
|
117 |
|
118 TTime home; |
|
119 home.HomeTime(); |
|
120 home+=iInterval; |
|
121 |
|
122 iTimer.Cancel(); |
|
123 iTimer.At(iStatus, home); |
|
124 iStatus = KRequestPending; |
|
125 SetActive(); |
|
126 IMUM_OUT(); |
|
127 } |
|
128 |
|
129 // ---------------------------------------------------------------------------- |
|
130 // CImapFolderSyncOperation::DoCancel |
|
131 // ---------------------------------------------------------------------------- |
|
132 void CImapFolderSyncOperation::DoCancel() |
|
133 { |
|
134 IMUM_CONTEXT( CImapFolderSyncOperation::DoCancel, 0, KImumMtmLog ); |
|
135 IMUM_IN(); |
|
136 |
|
137 iTimer.Cancel(); |
|
138 TRequestStatus* status = &iObserverRequestStatus; |
|
139 User::RequestComplete( status, KErrCancel ); |
|
140 IMUM_OUT(); |
|
141 } |
|
142 |
|
143 |
|
144 // ---------------------------------------------------------------------------- |
|
145 // CImapFolderSyncOperation::RunL |
|
146 // ---------------------------------------------------------------------------- |
|
147 void CImapFolderSyncOperation::RunL() |
|
148 { |
|
149 IMUM_CONTEXT( CImapFolderSyncOperation::RunL, 0, KImumMtmLog ); |
|
150 IMUM_IN(); |
|
151 |
|
152 if ( iOperation ) |
|
153 { |
|
154 // operation completed, start new timer |
|
155 delete iOperation; |
|
156 iOperation = NULL; |
|
157 SetInterval(); |
|
158 } |
|
159 else |
|
160 { |
|
161 TBool operationStarted = EFalse; |
|
162 // timer completed, start folder sync operation |
|
163 TMsvEntry tEntry; |
|
164 TMsvId service; |
|
165 if ( iMailboxApi.MsvSession().GetEntry( iMailboxId, service, tEntry ) == KErrNone ) |
|
166 { |
|
167 if ( iMailboxApi.MsvSession().ServiceActive( iMailboxId ) ) |
|
168 { |
|
169 // mailbox is doing something else, wait... |
|
170 SetInterval(); |
|
171 return; |
|
172 } |
|
173 //do sync only if connected. |
|
174 if( tEntry.Connected() && HasSubscribedFoldersL() ) |
|
175 { |
|
176 TBuf8<1> dummyParam; |
|
177 |
|
178 CMsvEntrySelection* sel = new (ELeave) CMsvEntrySelection; |
|
179 CleanupStack::PushL( sel ); |
|
180 sel->AppendL( iMailboxId ); |
|
181 |
|
182 //fullsync used to sync folders. Less code and less traffic than |
|
183 //if we would sync each folder separately |
|
184 iOperation = iMtmUi.InvokeAsyncFunctionL( |
|
185 KIMAP4MTMFullSync, |
|
186 *sel, |
|
187 iStatus, |
|
188 dummyParam); |
|
189 |
|
190 CleanupStack::PopAndDestroy( sel ); |
|
191 iStatus = KRequestPending; |
|
192 SetActive(); |
|
193 operationStarted = ETrue; |
|
194 } |
|
195 } |
|
196 if ( !operationStarted ) |
|
197 { |
|
198 // something wrong, complete observer |
|
199 TRequestStatus* status = &iObserverRequestStatus; |
|
200 User::RequestComplete(status, KErrNone); |
|
201 } |
|
202 } |
|
203 IMUM_OUT(); |
|
204 } |
|
205 |
|
206 // ---------------------------------------------------------------------------- |
|
207 // CImapFolderSyncOperation::HasSubscribedFoldersL |
|
208 // ---------------------------------------------------------------------------- |
|
209 TBool CImapFolderSyncOperation::HasSubscribedFoldersL() |
|
210 { |
|
211 IMUM_CONTEXT( CImapFolderSyncOperation::HasSubscribedFoldersL, 0, KImumMtmLog ); |
|
212 IMUM_IN(); |
|
213 |
|
214 TInt count = 0; |
|
215 CountSubscribedFoldersL( iMailboxId, count ); |
|
216 IMUM_OUT(); |
|
217 return count > 1; // return ETrue if more than inbox is subscribed |
|
218 } |
|
219 |
|
220 // ---------------------------------------------------- |
|
221 // CAlwaysOnlineImap4Agent::AddSubscribedFoldersL() |
|
222 // NOTE: This is recursive! |
|
223 // ---------------------------------------------------- |
|
224 void CImapFolderSyncOperation::CountSubscribedFoldersL( |
|
225 TMsvId aFolderId, TInt& aCount ) |
|
226 { |
|
227 IMUM_CONTEXT( CImapFolderSyncOperation::CountSubscribedFoldersL, 0, KImumMtmLog ); |
|
228 IMUM_IN(); |
|
229 |
|
230 CMsvEntry* entry = iMailboxApi.MsvSession().GetEntryL( aFolderId ); |
|
231 CleanupStack::PushL( entry ); |
|
232 |
|
233 const TInt count = entry->Count(); |
|
234 for ( TInt loop = 0; loop < count; loop++ ) |
|
235 { |
|
236 TMsvEmailEntry mailEntry = (*entry)[loop]; |
|
237 if ( mailEntry.iType.iUid == KUidMsvFolderEntryValue ) |
|
238 { |
|
239 if ( mailEntry.LocalSubscription() ) |
|
240 { |
|
241 aCount++; |
|
242 } |
|
243 CountSubscribedFoldersL( mailEntry.Id(), aCount ); |
|
244 } |
|
245 } |
|
246 |
|
247 CleanupStack::PopAndDestroy(); // entry |
|
248 |
|
249 IMUM_OUT(); |
|
250 } |
|
251 |
|
252 // End of File |