43 // ---------------------------------------------------------------------------- |
45 // ---------------------------------------------------------------------------- |
44 // CPsMruAdapter::NewL |
46 // CPsMruAdapter::NewL |
45 // Two Phase Construction |
47 // Two Phase Construction |
46 // ---------------------------------------------------------------------------- |
48 // ---------------------------------------------------------------------------- |
47 CPsMruAdapter* CPsMruAdapter::NewL( TAny* aPsDataPluginParameters ) |
49 CPsMruAdapter* CPsMruAdapter::NewL( TAny* aPsDataPluginParameters ) |
48 { |
50 { |
49 PRINT ( _L( "Enter CPsMruAdapter::NewL" ) ); |
51 FUNC_LOG; |
50 |
52 PRINT ( _L( "Enter CPsMruAdapter::NewL" ) ); |
51 // Get the PsData plugin parametrs |
53 |
52 TPsDataPluginParams* params = |
54 // Get the PsData plugin parametrs |
53 reinterpret_cast<TPsDataPluginParams*>(aPsDataPluginParameters ); |
55 TPsDataPluginParams* params = |
54 CPsMruAdapter* self = new ( ELeave ) CPsMruAdapter(); |
56 reinterpret_cast<TPsDataPluginParams*>(aPsDataPluginParameters ); |
55 CleanupStack::PushL(self); |
57 CPsMruAdapter* self = new ( ELeave ) CPsMruAdapter(); |
56 self->ConstructL( params->iDataStoreObserver, params->iStoreListObserver ); |
58 CleanupStack::PushL(self); |
57 CleanupStack::Pop( self ); |
59 self->ConstructL( params->iDataStoreObserver, params->iStoreListObserver ); |
58 |
60 CleanupStack::Pop( self ); |
59 PRINT ( _L( "End CPsMruAdapter::NewL" ) ); |
61 |
60 |
62 PRINT ( _L( "End CPsMruAdapter::NewL" ) ); |
61 return self; |
63 |
62 } |
64 return self; |
|
65 } |
63 |
66 |
64 // ---------------------------------------------------------------------------- |
67 // ---------------------------------------------------------------------------- |
65 // CPsMruAdapter::CPsMruAdapter |
68 // CPsMruAdapter::CPsMruAdapter |
66 // Two Phase Construction |
69 // Two Phase Construction |
67 // ---------------------------------------------------------------------------- |
70 // ---------------------------------------------------------------------------- |
68 CPsMruAdapter::CPsMruAdapter() |
71 CPsMruAdapter::CPsMruAdapter() |
69 { |
72 { |
70 PRINT ( _L( "Enter CPsMruAdapter::CPsMruAdapter" ) ); |
73 FUNC_LOG; |
71 PRINT ( _L( "End CPsMruAdapter::CPsMruAdapter" ) ); |
74 PRINT ( _L( "Enter CPsMruAdapter::CPsMruAdapter" ) ); |
72 } |
75 iDelayMailboxCreationPtr = NULL; |
|
76 PRINT ( _L( "End CPsMruAdapter::CPsMruAdapter" ) ); |
|
77 } |
73 |
78 |
74 // ---------------------------------------------------------------------------- |
79 // ---------------------------------------------------------------------------- |
75 // CPsMruAdapter::ConstructL |
80 // CPsMruAdapter::ConstructL |
76 // Two Phase Construction |
81 // Two Phase Construction |
77 // ---------------------------------------------------------------------------- |
82 // ---------------------------------------------------------------------------- |
78 void CPsMruAdapter::ConstructL( MDataStoreObserver* aObserverForDataStore, |
83 void CPsMruAdapter::ConstructL( MDataStoreObserver* aObserverForDataStore, |
79 MStoreListObserver* aStoreListObserver ) |
84 MStoreListObserver* aStoreListObserver ) |
80 { |
85 { |
81 PRINT ( _L( "Enter CPsMruAdapter::ConstructL" ) ); |
86 FUNC_LOG; |
82 |
87 PRINT ( _L( "Enter CPsMruAdapter::ConstructL" ) ); |
83 // Mail client for FS Email framework |
88 |
84 iMailClient = CFSMailClient::NewL(); |
89 // Mail client for FS Email framework |
85 |
90 iMailClient = CFSMailClient::NewL(); |
86 // Register as observer for mail client, we'll need this to observe MRU list changes |
91 |
87 // When i.e mail is sent |
92 // Register as observer for mail client, we'll need this to observe MRU list changes |
88 iMailClient->AddObserverL( *this ); |
93 // When i.e mail is sent |
89 |
94 iMailClient->AddObserverL( *this ); |
90 // This updates the list of all the supported datastores |
95 |
91 UpdateSupportedDataStoresList(); |
96 // This updates the list of all the supported datastores |
92 |
97 UpdateSupportedDataStoresList(); |
93 // Store these for later use |
98 |
94 iDataStoreObserver = aObserverForDataStore; |
99 // Store these for later use |
95 iStoreListObserver = aStoreListObserver; |
100 iDataStoreObserver = aObserverForDataStore; |
96 |
101 iStoreListObserver = aStoreListObserver; |
97 PRINT ( _L( "End CPsMruAdapter::ConstructL" ) ); |
102 |
98 } |
103 PRINT ( _L( "End CPsMruAdapter::ConstructL" ) ); |
|
104 } |
99 |
105 |
100 // ---------------------------------------------------------------------------- |
106 // ---------------------------------------------------------------------------- |
101 // CPsMruAdapter::~CPsMruAdapter |
107 // CPsMruAdapter::~CPsMruAdapter |
102 // Destructor |
108 // Destructor |
103 // ---------------------------------------------------------------------------- |
109 // ---------------------------------------------------------------------------- |
104 CPsMruAdapter::~CPsMruAdapter() |
110 CPsMruAdapter::~CPsMruAdapter() |
105 { |
111 { |
|
112 FUNC_LOG; |
106 PRINT ( _L( "Enter CPsMruAdapter::~CPsMruAdapter" ) ); |
113 PRINT ( _L( "Enter CPsMruAdapter::~CPsMruAdapter" ) ); |
107 |
114 |
108 iSupportedUris.ResetAndDestroy(); |
115 iSupportedUris.ResetAndDestroy(); |
109 |
116 |
110 // Remove observer, we don't need it anymore because we're shutting down |
117 // Remove observer, we don't need it anymore because we're shutting down |
114 if ( iMailClient ) |
121 if ( iMailClient ) |
115 { |
122 { |
116 iMailClient->RemoveObserver( *this ); |
123 iMailClient->RemoveObserver( *this ); |
117 iMailClient->Close(); |
124 iMailClient->Close(); |
118 } |
125 } |
119 |
126 if(iDelayMailboxCreationPtr) |
|
127 { |
|
128 iDelayMailboxCreationPtr->Deque(); |
|
129 delete iDelayMailboxCreationPtr; |
|
130 } |
|
131 |
|
132 iDelayedCreatedMailboxes.Reset(); |
|
133 iDelayedCreatedMailboxes.Close(); |
|
134 |
120 PRINT ( _L( "End CPsMruAdapter::~CPsMruAdapter" ) ); |
135 PRINT ( _L( "End CPsMruAdapter::~CPsMruAdapter" ) ); |
121 } |
136 } |
122 |
137 |
123 // ---------------------------------------------------------------------------- |
138 // ---------------------------------------------------------------------------- |
124 // CPsMruAdapter::RequestForDataL |
139 // CPsMruAdapter::RequestForDataL |
125 // |
140 // |
126 // ---------------------------------------------------------------------------- |
141 // ---------------------------------------------------------------------------- |
127 void CPsMruAdapter::RequestForDataL( TDesC& aDataStoreURI ) |
142 void CPsMruAdapter::RequestForDataL( TDesC& aDataStoreURI ) |
128 { |
143 { |
129 PRINT ( _L( "Enter CPsMruAdapter::RequestForDataL" ) ); |
144 FUNC_LOG; |
130 |
145 PRINT ( _L( "Enter CPsMruAdapter::RequestForDataL" ) ); |
131 // Add data to datastore, fill only requested one |
146 |
132 FillDataStoreL( aDataStoreURI ); |
147 // Add data to datastore, fill only requested one |
133 |
148 FillDataStoreL( aDataStoreURI ); |
134 PRINT ( _L( "Enter CPsMruAdapter::RequestForDataL" ) ); |
149 |
135 } |
150 PRINT ( _L( "Enter CPsMruAdapter::RequestForDataL" ) ); |
|
151 } |
136 |
152 |
137 // ---------------------------------------------------------------------------- |
153 // ---------------------------------------------------------------------------- |
138 // CPsMruAdapter::GetSupportedDataStoresL |
154 // CPsMruAdapter::GetSupportedDataStoresL |
139 // |
155 // |
140 // ---------------------------------------------------------------------------- |
156 // ---------------------------------------------------------------------------- |
141 |
157 |
142 void CPsMruAdapter::GetSupportedDataStoresL( |
158 void CPsMruAdapter::GetSupportedDataStoresL( |
143 RPointerArray<TDesC> &aDataStoresURIs ) |
159 RPointerArray<TDesC> &aDataStoresURIs ) |
144 { |
160 { |
145 for ( TInt i = 0; i < iSupportedUris.Count(); i++ ) |
161 FUNC_LOG; |
146 { |
162 for ( TInt i = 0; i < iSupportedUris.Count(); i++ ) |
147 aDataStoresURIs.Append( iSupportedUris[i] ); |
163 { |
148 } |
164 aDataStoresURIs.Append( iSupportedUris[i] ); |
149 } |
165 } |
|
166 } |
150 |
167 |
151 // ---------------------------------------------------------------------------- |
168 // ---------------------------------------------------------------------------- |
152 // CPsMruAdapter::RequestForDataExtensionL |
169 // CPsMruAdapter::RequestForDataExtensionL |
153 // |
170 // |
154 // ---------------------------------------------------------------------------- |
171 // ---------------------------------------------------------------------------- |
155 TAny* CPsMruAdapter::RequestForDataExtensionL(TInt /*aItemId*/) |
172 TAny* CPsMruAdapter::RequestForDataExtensionL(TInt /*aItemId*/) |
156 { |
173 { |
157 // No extention required for this since we have and interger as itemId |
174 FUNC_LOG; |
158 // Simply return NULL |
175 // No extention required for this since we have and interger as itemId |
159 return NULL; |
176 // Simply return NULL |
160 } |
177 return NULL; |
|
178 } |
161 |
179 |
162 // ---------------------------------------------------------------------------- |
180 // ---------------------------------------------------------------------------- |
163 // CPsMruAdapter::UpdateSupportedDataStoresList |
181 // CPsMruAdapter::UpdateSupportedDataStoresList |
164 // |
182 // |
165 // ---------------------------------------------------------------------------- |
183 // ---------------------------------------------------------------------------- |
166 void CPsMruAdapter::UpdateSupportedDataStoresList() |
184 void CPsMruAdapter::UpdateSupportedDataStoresList() |
167 { |
185 { |
168 // Mailboxes will be fetched to this array |
186 FUNC_LOG; |
169 RPointerArray<CFSMailBox> mailBoxes; |
187 // Mailboxes will be fetched to this array |
170 |
188 RPointerArray<CFSMailBox> mailBoxes; |
171 // List all mailboxes |
189 |
172 TFSMailMsgId plugin; |
190 // List all mailboxes |
173 iMailClient->ListMailBoxes( plugin, mailBoxes ); |
191 TFSMailMsgId plugin; |
174 |
192 iMailClient->ListMailBoxes( plugin, mailBoxes ); |
175 iSupportedUris.ResetAndDestroy(); |
193 |
176 |
194 iSupportedUris.ResetAndDestroy(); |
177 // Add all mailboxes as data stores |
195 |
178 for ( TInt i = 0; i < mailBoxes.Count(); i++ ) |
196 // Add all mailboxes as data stores |
179 { |
197 for ( TInt i = 0; i < mailBoxes.Count(); i++ ) |
180 // Get id of mailbox |
198 { |
181 TFSMailMsgId id = mailBoxes[i]->GetId(); |
199 // Get id of mailbox |
182 |
200 TFSMailMsgId id = mailBoxes[i]->GetId(); |
183 // Convert it to string, this will be the unique identifier for this mailbox |
201 |
184 HBufC* identifier = HBufC::New( KMaximumMailboxUriLength ); |
202 // Convert it to string, this will be the unique identifier for this mailbox |
185 if ( identifier && GetUriFromMailboxIdentifier( id, *identifier ) ) |
203 HBufC* identifier = HBufC::New( KMaximumMailboxUriLength ); |
186 { |
204 if ( identifier && GetUriFromMailboxIdentifier( id, *identifier ) ) |
187 // Add to supported Uris list |
205 { |
188 if ( iSupportedUris.Append( identifier ) == KErrNone ) |
206 // Add to supported Uris list |
189 { |
207 if ( iSupportedUris.Append( identifier ) == KErrNone ) |
190 // Ownership of the string is successfully moved to the array |
208 { |
191 identifier = NULL; |
209 // Ownership of the string is successfully moved to the array |
192 } |
210 identifier = NULL; |
193 } |
211 } |
194 delete identifier; |
212 } |
195 } |
213 delete identifier; |
196 |
214 } |
197 // Release allocated memory |
215 |
198 mailBoxes.ResetAndDestroy(); |
216 // Release allocated memory |
199 } |
217 mailBoxes.ResetAndDestroy(); |
|
218 } |
200 |
219 |
201 // ---------------------------------------------------------------------------- |
220 // ---------------------------------------------------------------------------- |
202 // CPsMruAdapter::FillDataStoreL |
221 // CPsMruAdapter::FillDataStoreL |
203 // ---------------------------------------------------------------------------- |
222 // ---------------------------------------------------------------------------- |
204 TBool CPsMruAdapter::FillDataStoreL( TDesC& aDataStoreURI ) |
223 TBool CPsMruAdapter::FillDataStoreL( TDesC& aDataStoreURI ) |
205 { |
224 { |
206 TBool result = EFalse; |
225 FUNC_LOG; |
207 |
226 TBool result = EFalse; |
208 TFSMailMsgId dataStoreId; |
227 |
209 |
228 TFSMailMsgId dataStoreId; |
210 if ( GetMailboxIdentifierFromUri( aDataStoreURI, dataStoreId ) ) |
229 |
211 { |
230 if ( GetMailboxIdentifierFromUri( aDataStoreURI, dataStoreId ) ) |
212 result = FillDataStoreL( dataStoreId, aDataStoreURI ); |
231 { |
213 } |
232 result = FillDataStoreL( dataStoreId, aDataStoreURI ); |
214 |
233 } |
215 return result; |
234 |
216 } |
235 return result; |
|
236 } |
217 |
237 |
218 TBool CPsMruAdapter::FillDataStoreL( TFSMailMsgId& aId ) |
238 TBool CPsMruAdapter::FillDataStoreL( TFSMailMsgId& aId ) |
219 { |
239 { |
220 TBool result = EFalse; |
240 FUNC_LOG; |
221 |
241 TBool result = EFalse; |
222 // Create Uri for this mailbox |
242 |
223 HBufC* identifier = HBufC::NewLC( KMaximumMailboxUriLength ); |
243 // Create Uri for this mailbox |
224 if ( GetUriFromMailboxIdentifier( aId, *identifier ) ) |
244 HBufC* identifier = HBufC::NewLC( KMaximumMailboxUriLength ); |
225 { |
245 if ( GetUriFromMailboxIdentifier( aId, *identifier ) ) |
226 result = FillDataStoreL( aId, *identifier ); |
246 { |
227 } |
247 result = FillDataStoreL( aId, *identifier ); |
228 CleanupStack::PopAndDestroy( identifier ); |
248 } |
229 return result; |
249 CleanupStack::PopAndDestroy( identifier ); |
230 } |
250 return result; |
|
251 } |
|
252 |
|
253 void CPsMruAdapter::AddMruEmailsL( MDesCArray* aMruList, TDesC& aDataStoreURI ) |
|
254 { |
|
255 FUNC_LOG; |
|
256 TInt entryIndex = 0; |
|
257 // Add all data to data store, the format is: |
|
258 // index0: displayname |
|
259 // index1: email |
|
260 // index2: next displayname |
|
261 // index3: next email |
|
262 // etc.. |
|
263 for ( int mruIndex = 0; mruIndex < aMruList->MdcaCount(); mruIndex += 2 ) |
|
264 { |
|
265 TPtrC displayName = aMruList->MdcaPoint( mruIndex ); |
|
266 TPtrC emailAddress = aMruList->MdcaPoint( mruIndex + 1 ); |
|
267 |
|
268 CPsData* mruData = CPsData::NewL(); |
|
269 CleanupStack::PushL(mruData); |
|
270 mruData->SetId( entryIndex++ ); |
|
271 |
|
272 // Set the data |
|
273 mruData->SetDataL( 0, displayName ); |
|
274 mruData->SetDataL( 1, KNullDesC ); |
|
275 mruData->SetDataL( 2, emailAddress ); |
|
276 |
|
277 iDataStoreObserver->AddData( aDataStoreURI, mruData ); |
|
278 CleanupStack::Pop(mruData); // transferred ownership |
|
279 } |
|
280 } |
231 |
281 |
232 TBool CPsMruAdapter::FillDataStoreL( TFSMailMsgId& aId, TDesC& aDataStoreURI ) |
282 TBool CPsMruAdapter::FillDataStoreL( TFSMailMsgId& aId, TDesC& aDataStoreURI ) |
233 { |
283 { |
234 TBool result = EFalse; |
284 FUNC_LOG; |
235 |
285 TBool result = EFalse; |
236 // Mailboxes will be fetched to this array |
286 // code was simplified not to trace all mailboxes |
237 RPointerArray<CFSMailBox> mailBoxes; |
287 // function has trap in Event() -case> TFSEventNewMailbox and in DeleayedMailboxCreationEventL() |
238 CleanupResetAndDestroyPushL( mailBoxes ); |
288 // should not leave when new mailbox only when new mail address |
239 |
289 CFSMailBox *mailBox = iMailClient->GetMailBoxByUidL(aId); |
240 // List all mailboxes |
290 if (mailBox) |
241 TFSMailMsgId plugin; |
291 { |
242 iMailClient->ListMailBoxes( plugin, mailBoxes ); |
292 AddMailboxObserverL( aId ); |
243 |
293 |
244 // Find the requested mailbox |
294 // Get MRU list for this mailbox |
245 for ( TInt i = 0; i < mailBoxes.Count(); i++ ) |
295 MDesCArray* mruList = mailBox->ListMrusL(); |
246 { |
296 mailBox = NULL; |
247 // Get id of mailbox |
297 |
248 TFSMailMsgId id = mailBoxes[i]->GetId(); |
298 // update the caching status as InProgress |
249 |
299 iDataStoreObserver->UpdateCachingStatus( aDataStoreURI, |
250 // Check that this is the requested mailbox |
300 ECachingInProgress ); |
251 if ( id == aId ) |
301 |
252 { |
302 // Update datastore contents, first reset |
253 AddMailboxObserverL( aId ); |
303 iDataStoreObserver->RemoveAll( aDataStoreURI ); |
254 |
304 |
255 // update the caching status as InProgress |
305 TInt trap_err; // for trap macro |
256 iDataStoreObserver->UpdateCachingStatus( aDataStoreURI, |
306 if ( mruList ) |
257 ECachingInProgress ); |
307 { |
258 |
308 // trap the error to enable returning status back |
259 // Update datastore contents, first reset |
309 TRAP(trap_err, AddMruEmailsL( mruList, aDataStoreURI ) ); |
260 iDataStoreObserver->RemoveAll( aDataStoreURI ); |
310 delete mruList; |
261 |
311 } |
262 // Get MRU list for this mailbox |
312 // update the caching status as Complete |
263 MDesCArray* mruList = mailBoxes[i]->ListMrusL(); |
313 iDataStoreObserver->UpdateCachingStatus( aDataStoreURI, |
264 |
314 ECachingComplete ); |
265 if ( mruList ) |
315 if ( trap_err != KErrNone ) // check for error leave code |
266 { |
316 { |
267 TInt entryIndex = 0; |
317 User::Leave(trap_err); |
268 |
318 } |
269 // Add all data to data store, the format is: |
319 result = ETrue; |
270 // index0: displayname |
320 } // if (mailBox) |
271 // index1: email |
321 return result; |
272 // index2: next displayname |
322 } |
273 // index3: next email |
|
274 // etc.. |
|
275 for ( int mruIndex = 0; mruIndex < mruList->MdcaCount(); mruIndex += 2 ) |
|
276 { |
|
277 TPtrC displayName = mruList->MdcaPoint( mruIndex ); |
|
278 TPtrC emailAddress = mruList->MdcaPoint( mruIndex + 1 ); |
|
279 |
|
280 CPsData* mruData = CPsData::NewL(); |
|
281 mruData->SetId( entryIndex++ ); |
|
282 |
|
283 // Set the data |
|
284 mruData->SetDataL( 0, displayName ); |
|
285 mruData->SetDataL( 1, KNullDesC ); |
|
286 mruData->SetDataL( 2, emailAddress ); |
|
287 |
|
288 iDataStoreObserver->AddData( aDataStoreURI, mruData ); |
|
289 } |
|
290 |
|
291 delete mruList; |
|
292 } |
|
293 // update the caching status as Complete |
|
294 iDataStoreObserver->UpdateCachingStatus( aDataStoreURI, |
|
295 ECachingComplete ); |
|
296 |
|
297 result = ETrue; |
|
298 break; |
|
299 } |
|
300 } |
|
301 |
|
302 CleanupStack::PopAndDestroy( &mailBoxes ); |
|
303 return result; |
|
304 } |
|
305 |
323 |
306 // ---------------------------------------------------------------------------- |
324 // ---------------------------------------------------------------------------- |
307 // CPsContactDataAdapter::IsDataStoresSupportedL |
325 // CPsContactDataAdapter::IsDataStoresSupportedL |
308 // |
326 // |
309 // ---------------------------------------------------------------------------- |
327 // ---------------------------------------------------------------------------- |
310 TBool CPsMruAdapter::IsDataStoresSupportedL( TDesC& aDataStoreURI ) |
328 TBool CPsMruAdapter::IsDataStoresSupportedL( TDesC& aDataStoreURI ) |
311 { |
329 { |
312 for ( TInt i = 0; i < iSupportedUris.Count(); i++ ) |
330 FUNC_LOG; |
313 { |
331 for ( TInt i = 0; i < iSupportedUris.Count(); i++ ) |
314 if ( iSupportedUris[i]->Compare( aDataStoreURI ) == 0 ) |
332 { |
315 return ETrue; |
333 if ( iSupportedUris[i]->Compare( aDataStoreURI ) == 0 ) |
316 } |
334 return ETrue; |
317 |
335 } |
318 return EFalse; |
336 return EFalse; |
319 } |
337 } |
320 |
338 |
321 // ---------------------------------------------------------------------------- |
339 // ---------------------------------------------------------------------------- |
322 // CPsContactDataAdapter::GetSupportedDataFieldsL |
340 // CPsContactDataAdapter::GetSupportedDataFieldsL |
323 // |
341 // |
324 // ---------------------------------------------------------------------------- |
342 // ---------------------------------------------------------------------------- |
325 void CPsMruAdapter::GetSupportedDataFieldsL( RArray<TInt>& aDataFields ) |
343 void CPsMruAdapter::GetSupportedDataFieldsL( RArray<TInt>& aDataFields ) |
|
344 { |
|
345 FUNC_LOG; |
|
346 aDataFields.Append( R_VPBK_FIELD_TYPE_FIRSTNAME ); |
|
347 aDataFields.Append( R_VPBK_FIELD_TYPE_LASTNAME ); |
|
348 aDataFields.Append( R_VPBK_FIELD_TYPE_EMAILGEN ); |
|
349 } |
|
350 |
|
351 TBool CPsMruAdapter::GetMailboxIdentifierFromUri( TDesC& aUri, TFSMailMsgId& aId ) |
|
352 { |
|
353 FUNC_LOG; |
|
354 // Find first separator in reverse order |
|
355 TInt lastSeparator = aUri.LocateReverseF( KDefaultMailBoxURISeparator ); |
|
356 if ( lastSeparator == KErrNotFound ) |
|
357 return EFalse; |
|
358 |
|
359 // This is where plugin id string starts |
|
360 TInt pluginIdStartPosition = KDefaultMailBoxURI().Length(); |
|
361 TInt mailboxIdStartPosition = lastSeparator + 1; |
|
362 |
|
363 // It cannot be further than mailbox id |
|
364 if ( pluginIdStartPosition >= mailboxIdStartPosition ) |
|
365 return EFalse; |
|
366 |
|
367 // Use TLex to convert string to integer |
|
368 TLex pluginIdConverter( aUri.Mid( pluginIdStartPosition, |
|
369 mailboxIdStartPosition - pluginIdStartPosition - 1 ) ); |
|
370 |
|
371 // Use TLex to convert string to integer |
|
372 TLex mailboxIdConverter( aUri.Mid( mailboxIdStartPosition, aUri.Length() |
|
373 - mailboxIdStartPosition ) ); |
|
374 |
|
375 TInt pluginId; |
|
376 TInt mailboxId; |
|
377 |
|
378 // Get plugin ID |
|
379 if ( pluginIdConverter.Val( pluginId ) != KErrNone) |
|
380 return EFalse; |
|
381 |
|
382 // Get mailbox ID |
|
383 if ( mailboxIdConverter.Val( mailboxId ) != KErrNone) |
|
384 return EFalse; |
|
385 |
|
386 // Store and we're ready |
|
387 aId.SetPluginId( TUid::Uid( pluginId ) ); |
|
388 aId.SetId( mailboxId ); |
|
389 |
|
390 return ETrue; |
|
391 } |
|
392 |
|
393 TBool CPsMruAdapter::GetUriFromMailboxIdentifier( TFSMailMsgId& aId, HBufC& aUri ) |
|
394 { |
|
395 FUNC_LOG; |
|
396 // Add the uri identifier |
|
397 aUri.Des().Copy( KDefaultMailBoxURI ); |
|
398 // Add plugin ID |
|
399 aUri.Des().AppendNum( aId.PluginId().iUid ); |
|
400 // Add separator |
|
401 aUri.Des().Append( KDefaultMailBoxURISeparator ); |
|
402 // Add mailbox id |
|
403 aUri.Des().AppendNum( aId.Id() ); |
|
404 |
|
405 return true; |
|
406 } |
|
407 |
|
408 void CPsMruAdapter::EventL( TFSMailEvent aEvent, TFSMailMsgId aMailbox, |
|
409 TAny* /*aParam1*/, TAny* aParam2, TAny* /*aParam3*/ ) |
|
410 { |
|
411 FUNC_LOG; |
|
412 switch ( aEvent ) |
|
413 { |
|
414 case TFSEventMailMoved: |
|
415 case TFSEventMailCopied: |
|
416 case TFSEventNewMail: |
|
417 { |
|
418 // Check the new parent folder id for this message |
|
419 // For all these events, param2 indicates the new parent folder |
|
420 TFSMailMsgId* parentFolderId = |
|
421 static_cast< TFSMailMsgId* >( aParam2 ); |
|
422 if ( parentFolderId ) |
|
423 { |
|
424 // Get the parent folder object |
|
425 CFSMailFolder* parentFolder = iMailClient->GetFolderByUidL( |
|
426 aMailbox, *parentFolderId ); |
|
427 if ( parentFolder ) |
|
428 { |
|
429 CleanupStack::PushL( parentFolder ); |
|
430 |
|
431 // If it's sent/outbox folder, |
|
432 // we'll consider that as a new message being sent |
|
433 // and therefore we'll update the MRU list here |
|
434 if ( ( parentFolder->GetFolderType() == EFSSentFolder ) || |
|
435 ( parentFolder->GetFolderType() == EFSOutbox ) ) |
|
436 { |
|
437 FillDataStoreL( aMailbox ); |
|
438 } |
|
439 CleanupStack::PopAndDestroy( parentFolder ); |
|
440 } |
|
441 } |
|
442 } |
|
443 break; |
|
444 |
|
445 case TFSEventNewMailbox: |
|
446 { |
|
447 CFSMailBox *mailboxPtr(NULL); |
|
448 // if mailbox is not ready it may leave here |
|
449 TRAPD(trap_err, mailboxPtr = iMailClient->GetMailBoxByUidL( aMailbox )); |
|
450 if ( trap_err != KErrNone ) |
|
451 { |
|
452 mailboxPtr = NULL; |
|
453 } |
|
454 if (NULL == mailboxPtr) // mailbox still does not exist |
|
455 { |
|
456 DeleayMailboxCreationEventL( aMailbox ); // start timer to postpone creation |
|
457 break; |
|
458 } |
|
459 mailboxPtr = NULL; |
|
460 HBufC* identifier = HBufC::NewLC( KMaximumMailboxUriLength ); // new string ident |
|
461 if ( GetUriFromMailboxIdentifier( aMailbox, *identifier ) ) |
|
462 { |
|
463 // Add to supported Uri list |
|
464 iSupportedUris.AppendL( identifier ); |
|
465 |
|
466 // Add new data store to cache |
|
467 iStoreListObserver->AddDataStore( *identifier ); |
|
468 |
|
469 // Add all data to data store |
|
470 // FillDataStoreL( *identifier ); |
|
471 // FillDataStoreL removed - called by AddDataStore through RequestForDataL callback |
|
472 |
|
473 // In case there is a problem with transferring strings to - should be obsolete |
|
474 AddMailboxObserverL( aMailbox ); // will be added by FillDataStoreL |
|
475 |
|
476 CleanupStack::Pop( identifier ); |
|
477 } |
|
478 else |
|
479 { |
|
480 CleanupStack::PopAndDestroy( identifier ); |
|
481 } |
|
482 } |
|
483 break; |
|
484 |
|
485 case TFSEventMailboxDeleted: |
|
486 { |
|
487 HBufC* identifier = HBufC::NewL( KMaximumMailboxUriLength ); |
|
488 if ( GetUriFromMailboxIdentifier( aMailbox, *identifier ) ) |
|
489 { |
|
490 RemoveMailboxObserver( aMailbox ); |
|
491 |
|
492 // Remove data store from cache |
|
493 iStoreListObserver->RemoveDataStore( *identifier ); |
|
494 |
|
495 // Remove from supported Uri list |
|
496 for ( TInt i = 0; i < iSupportedUris.Count(); i++ ) |
|
497 { |
|
498 if ( iSupportedUris[i]->Compare( *identifier ) == 0 ) |
|
499 { |
|
500 delete iSupportedUris[i]; |
|
501 iSupportedUris.Remove( i ); |
|
502 break; |
|
503 } |
|
504 } |
|
505 } |
|
506 delete identifier; |
|
507 } |
|
508 break; |
|
509 } |
|
510 } |
|
511 |
|
512 TBool CPsMruAdapter::AddMailboxObserverL( TFSMailMsgId& aId ) |
|
513 { |
|
514 FUNC_LOG; |
|
515 for( TInt index = 0; index < iObservedMailboxes.Count(); index++ ) |
|
516 { |
|
517 if( iObservedMailboxes[index] == aId ) |
|
518 { |
|
519 // Already observing |
|
520 return EFalse; |
|
521 } |
|
522 } |
|
523 |
|
524 iMailClient->SubscribeMailboxEventsL( aId, *this ); |
|
525 iObservedMailboxes.Append( aId ); |
|
526 return ETrue; |
|
527 } |
|
528 |
|
529 TBool CPsMruAdapter::RemoveMailboxObserver( TFSMailMsgId& aId ) |
|
530 { |
|
531 FUNC_LOG; |
|
532 for( TInt index = 0; index < iObservedMailboxes.Count(); index++ ) |
|
533 { |
|
534 if( iObservedMailboxes[index] == aId ) |
|
535 { |
|
536 iMailClient->UnsubscribeMailboxEvents( aId, *this ); |
|
537 iObservedMailboxes.Remove( index ); |
|
538 return ETrue; |
|
539 } |
|
540 } |
|
541 |
|
542 return EFalse; |
|
543 } |
|
544 |
|
545 void CPsMruAdapter::RemoveAllMailboxObservers() |
|
546 { |
|
547 FUNC_LOG; |
|
548 for( TInt index = 0; index < iObservedMailboxes.Count(); index++ ) |
|
549 { |
|
550 iMailClient->UnsubscribeMailboxEvents( iObservedMailboxes[index], *this ); |
|
551 } |
|
552 |
|
553 iObservedMailboxes.Reset(); |
|
554 } |
|
555 |
|
556 /** |
|
557 * If problem with NewMailbox this function will be called |
|
558 * by CDelayMailboxCreationHelper timer to try it after some delay |
|
559 */ |
|
560 TBool CPsMruAdapter::DeleayedMailboxCreationEventL() |
326 { |
561 { |
327 aDataFields.Append( R_VPBK_FIELD_TYPE_FIRSTNAME ); |
562 FUNC_LOG; |
328 aDataFields.Append( R_VPBK_FIELD_TYPE_LASTNAME ); |
563 for ( int i = iDelayedCreatedMailboxes.Count()-1; i>=0; i-- ) |
329 aDataFields.Append( R_VPBK_FIELD_TYPE_EMAILGEN ); |
564 { |
330 } |
565 CFSMailBox *mailboxPtr(NULL); |
331 |
566 // if mailbox is not ready it may leave there |
332 TBool CPsMruAdapter::GetMailboxIdentifierFromUri( TDesC& aUri, TFSMailMsgId& aId ) |
567 TRAPD(trap_err, mailboxPtr = iMailClient->GetMailBoxByUidL( iDelayedCreatedMailboxes[i] )); |
333 { |
568 if ( trap_err != KErrNone ) |
334 // Find first separator in reverse order |
569 { |
335 TInt lastSeparator = aUri.LocateReverseF( KDefaultMailBoxURISeparator ); |
570 mailboxPtr = NULL; |
336 if ( lastSeparator == KErrNotFound ) |
571 } |
337 return EFalse; |
572 if ( mailboxPtr ) |
338 |
573 { |
339 // This is where plugin id string starts |
574 HBufC* identifier = HBufC::NewLC( KMaximumMailboxUriLength ); // new string ident |
340 TInt pluginIdStartPosition = KDefaultMailBoxURI().Length(); |
575 if ( GetUriFromMailboxIdentifier( iDelayedCreatedMailboxes[i], *identifier ) ) |
341 TInt mailboxIdStartPosition = lastSeparator + 1; |
576 { |
342 |
577 |
343 // It cannot be further than mailbox id |
578 // Add to supported Uri list |
344 if ( pluginIdStartPosition >= mailboxIdStartPosition ) |
579 iSupportedUris.AppendL( identifier ); |
345 return EFalse; |
580 |
346 |
581 // Add new data store to cache |
347 // Use TLex to convert string to integer |
582 iStoreListObserver->AddDataStore( *identifier ); |
348 TLex pluginIdConverter( aUri.Mid( pluginIdStartPosition, |
583 |
349 mailboxIdStartPosition - pluginIdStartPosition - 1 ) ); |
584 // Add all data to data store |
350 |
585 // removed because this is called by AddDataStore through RequestForDataL callback |
351 // Use TLex to convert string to integer |
586 // FillDataStoreL( *identifier ); |
352 TLex mailboxIdConverter( aUri.Mid( mailboxIdStartPosition, aUri.Length() |
587 |
353 - mailboxIdStartPosition ) ); |
588 // In case there is a problem with transferring strings to - should be obsolete |
354 |
589 AddMailboxObserverL( iDelayedCreatedMailboxes[i] ); // will be added by FillDataStoreL |
355 TInt pluginId; |
590 |
356 TInt mailboxId; |
591 CleanupStack::Pop( identifier ); |
357 |
592 iDelayedCreatedMailboxes.Remove( i ); |
358 // Get plugin ID |
593 } |
359 if ( pluginIdConverter.Val( pluginId ) != KErrNone) |
594 else |
360 return EFalse; |
595 { |
361 |
596 CleanupStack::PopAndDestroy( identifier ); |
362 // Get mailbox ID |
597 } |
363 if ( mailboxIdConverter.Val( mailboxId ) != KErrNone) |
598 } |
364 return EFalse; |
599 } |
365 |
600 return ( 0 == iDelayedCreatedMailboxes.Count() ); |
366 // Store and we're ready |
601 } |
367 aId.SetPluginId( TUid::Uid( pluginId ) ); |
602 |
368 aId.SetId( mailboxId ); |
603 /** |
369 |
604 * If problem with NewMailbox this function will use |
370 return ETrue; |
605 * CDelayMailboxCreationHelper to try it after some delay |
371 } |
606 */ |
372 |
607 void CPsMruAdapter::DeleayMailboxCreationEventL( TFSMailMsgId &aMailbox ) |
373 TBool CPsMruAdapter::GetUriFromMailboxIdentifier( TFSMailMsgId& aId, HBufC& aUri ) |
608 { |
374 { |
609 FUNC_LOG; |
375 // Add the uri identifier |
610 if ( NULL == iDelayMailboxCreationPtr ) |
376 aUri.Des().Copy( KDefaultMailBoxURI ); |
611 { |
377 // Add plugin ID |
612 iDelayMailboxCreationPtr = CDelayMailboxCreationHelper::NewL( this ); |
378 aUri.Des().AppendNum( aId.PluginId().iUid ); |
613 } |
379 // Add separator |
614 iDelayedCreatedMailboxes.Append( aMailbox ); |
380 aUri.Des().Append( KDefaultMailBoxURISeparator ); |
615 iDelayMailboxCreationPtr->StartDelayedCall(); |
381 // Add mailbox id |
616 } |
382 aUri.Des().AppendNum( aId.Id() ); |
617 |
383 |
618 // --------------------------------------------------------------------------------------------------- |
384 return true; |
619 // class CDelayMailboxCreationHelper : public CTimer |
385 } |
620 // --------------------------------------------------------------------------------------------------- |
386 |
621 |
387 void CPsMruAdapter::EventL( TFSMailEvent aEvent, TFSMailMsgId aMailbox, |
622 // static construction leaving on the stack |
388 TAny* /*aParam1*/, TAny* aParam2, TAny* /*aParam3*/ ) |
623 CDelayMailboxCreationHelper* CDelayMailboxCreationHelper::NewLC( CPsMruAdapter *aPsMruAdapterPtr ) |
389 { |
624 { |
390 switch ( aEvent ) |
625 FUNC_LOG; |
391 { |
626 CDelayMailboxCreationHelper* self = new ( ELeave ) CDelayMailboxCreationHelper( aPsMruAdapterPtr ); |
392 case TFSEventMailMoved: |
627 CleanupStack::PushL( self ); |
393 case TFSEventMailCopied: |
628 self->ConstructL(); |
394 case TFSEventNewMail: |
629 return self; |
395 { |
630 } |
396 // Check the new parent folder id for this message |
631 |
397 // For all these events, param2 indicates the new parent folder |
632 // static construction leaving |
398 TFSMailMsgId* parentFolderId = |
633 CDelayMailboxCreationHelper* CDelayMailboxCreationHelper::NewL( CPsMruAdapter *aPsMruAdapterPtr ) |
399 static_cast< TFSMailMsgId* >( aParam2 ); |
634 { |
400 if ( parentFolderId ) |
635 FUNC_LOG; |
401 { |
636 CDelayMailboxCreationHelper* self = CDelayMailboxCreationHelper::NewLC( aPsMruAdapterPtr ); |
402 // Get the parent folder object |
637 CleanupStack::Pop( self ); |
403 CFSMailFolder* parentFolder = iMailClient->GetFolderByUidL( |
638 return self; |
404 aMailbox, *parentFolderId ); |
639 } |
405 if ( parentFolder ) |
640 |
406 { |
641 // used by MruAdapter when delayed datasource adding is needed |
407 CleanupStack::PushL( parentFolder ); |
642 void CDelayMailboxCreationHelper::StartDelayedCall() |
408 |
643 { |
409 // If it's sent/outbox folder, |
644 FUNC_LOG; |
410 // we'll consider that as a new message being sent |
645 if( IsActive() ) // don't call again in case the timer rq is pending |
411 // and therefore we'll update the MRU list here |
646 { |
412 if ( ( parentFolder->GetFolderType() == EFSSentFolder ) || |
647 Cancel(); |
413 ( parentFolder->GetFolderType() == EFSOutbox ) ) |
648 } |
414 { |
649 iNumberOfDelayedTrials = KNumberOfDelayedTrials; |
415 FillDataStoreL( aMailbox ); |
650 After( KDelayToRunAddMailbox ); // CTimer::After contains SetActive() |
416 } |
651 } |
417 CleanupStack::PopAndDestroy( parentFolder ); |
652 |
418 } |
653 // Limited unsuccesful call repeating |
419 } |
654 void CDelayMailboxCreationHelper::RunL() |
420 } |
655 { |
421 break; |
656 FUNC_LOG; |
422 |
657 iNumberOfDelayedTrials --; |
423 case TFSEventNewMailbox: |
658 User::LeaveIfError( iStatus.Int() ); |
424 { |
659 TBool Handled = iPsMruAdapterPtr->DeleayedMailboxCreationEventL(); |
425 HBufC* identifier = HBufC::NewLC( KMaximumMailboxUriLength ); |
660 if (( Handled ) || ( 0 >= iNumberOfDelayedTrials )) |
426 if ( GetUriFromMailboxIdentifier( aMailbox, *identifier ) ) |
661 { // no need to call again |
427 { |
662 Cancel(); |
428 // Add to supported Uri list |
663 } |
429 iSupportedUris.AppendL( identifier ); |
664 else |
430 |
665 { // wait once more |
431 // Add new data store to cache |
666 // SetActive is called by After |
432 iStoreListObserver->AddDataStore( *identifier ); |
667 After( KDelayToRunAddMailbox ); |
433 |
668 } |
434 // Add all data to data store |
669 } |
435 FillDataStoreL( *identifier ); |
670 |
436 |
671 // when leave from RunL, if err handled return KErrNone |
437 CleanupStack::Pop( identifier ); |
672 TInt CDelayMailboxCreationHelper::RunError( TInt aError ) |
438 } |
673 { |
439 else |
674 FUNC_LOG; |
440 { |
675 if ( KErrNone != aError ) |
441 CleanupStack::PopAndDestroy( identifier ); |
676 { |
442 } |
677 Cancel(); // stop pending requiest |
443 } |
678 } |
444 break; |
679 return KErrNone; //not desired to panic the thread in case of error returned |
445 |
680 } |
446 case TFSEventMailboxDeleted: |
681 |
447 { |
682 // 2nd phase of construction |
448 HBufC* identifier = HBufC::NewL( KMaximumMailboxUriLength ); |
683 void CDelayMailboxCreationHelper::ConstructL() |
449 if ( GetUriFromMailboxIdentifier( aMailbox, *identifier ) ) |
684 { |
450 { |
685 FUNC_LOG; |
451 RemoveMailboxObserver( aMailbox ); |
686 CTimer::ConstructL(); |
452 |
687 CActiveScheduler::Add( this ); |
453 // Remove data store from cache |
688 } |
454 iStoreListObserver->RemoveDataStore( *identifier ); |
689 |
455 |
690 // c-tor |
456 // Remove from supported Uri list |
691 CDelayMailboxCreationHelper::CDelayMailboxCreationHelper( |
457 for ( TInt i = 0; i < iSupportedUris.Count(); i++ ) |
692 CPsMruAdapter *aPsMruAdapterPtr ) |
458 { |
693 : CTimer( EPriorityStandard ) //possible also EPriorityLow, EPriorityIdle |
459 if ( iSupportedUris[i]->Compare( *identifier ) == 0 ) |
694 , iPsMruAdapterPtr ( aPsMruAdapterPtr ) // not ownink ptr |
460 { |
695 , iNumberOfDelayedTrials ( KNumberOfDelayedTrials ) //limited repeating num. |
461 delete iSupportedUris[i]; |
696 { |
462 iSupportedUris.Remove( i ); |
697 FUNC_LOG; |
463 break; |
698 } |
464 } |
699 |
465 } |
700 // d-tor |
466 } |
701 CDelayMailboxCreationHelper::~CDelayMailboxCreationHelper() |
467 delete identifier; |
702 { |
468 } |
703 FUNC_LOG; |
469 break; |
704 iPsMruAdapterPtr = NULL; // not owning interface ptr |
470 } |
705 Cancel(); // stop pending request |
471 } |
706 Deque(); // remove from CActiveScheduler |
472 |
707 } |
473 TBool CPsMruAdapter::AddMailboxObserverL( TFSMailMsgId& aId ) |
|
474 { |
|
475 for( TInt index = 0; index < iObservedMailboxes.Count(); index++ ) |
|
476 { |
|
477 if( iObservedMailboxes[index] == aId ) |
|
478 { |
|
479 // Already observing |
|
480 return EFalse; |
|
481 } |
|
482 } |
|
483 |
|
484 iMailClient->SubscribeMailboxEventsL( aId, *this ); |
|
485 iObservedMailboxes.Append( aId ); |
|
486 return ETrue; |
|
487 } |
|
488 |
|
489 TBool CPsMruAdapter::RemoveMailboxObserver( TFSMailMsgId& aId ) |
|
490 { |
|
491 for( TInt index = 0; index < iObservedMailboxes.Count(); index++ ) |
|
492 { |
|
493 if( iObservedMailboxes[index] == aId ) |
|
494 { |
|
495 iMailClient->UnsubscribeMailboxEvents( aId, *this ); |
|
496 iObservedMailboxes.Remove( index ); |
|
497 return ETrue; |
|
498 } |
|
499 } |
|
500 |
|
501 return EFalse; |
|
502 } |
|
503 |
|
504 void CPsMruAdapter::RemoveAllMailboxObservers() |
|
505 { |
|
506 for( TInt index = 0; index < iObservedMailboxes.Count(); index++ ) |
|
507 { |
|
508 iMailClient->UnsubscribeMailboxEvents( iObservedMailboxes[index], *this ); |
|
509 } |
|
510 |
|
511 iObservedMailboxes.Reset(); |
|
512 } |
|
513 |
|
514 |
708 |
515 // End of file |
709 // End of file |
516 |
|
517 |
|