|
1 /* |
|
2 * Copyright (c) 2007 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: CLS lists class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "emailtrace.h" |
|
19 #include <eikenv.h> // CEikonEnv |
|
20 #include <centralrepository.h> // CRepository |
|
21 #include <AknFepInternalCRKeys.h> // KCRUidAknFep |
|
22 //<cmail> |
|
23 #include "cfsmailbox.h" // cfsmailbox |
|
24 //</cmail> |
|
25 #include <CPsRequestHandler.h> |
|
26 #include <CPsSettings.h> |
|
27 #include <VPbkEng.rsg> |
|
28 |
|
29 #include "FreestyleEmailUiCLSListsHandler.h" // CFSEmailUiClsListsHandler |
|
30 #include "FreestyleEMailUiCLSMatchObserverInterface.h"// CFSEmailUiClsContactMatchObserver |
|
31 #include "FreestyleEmailUiInputModeObserver.h" // CFSEmailUiInputModeObserver |
|
32 #include "FreestyleEmailUiUtilities.h" |
|
33 #include "FreestyleEmailUiCLSItem.h" |
|
34 |
|
35 // ================= MEMBER FUNCTIONS ========================================== |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CFSEmailUiClsListsHandler::NewL |
|
38 // ----------------------------------------------------------------------------- |
|
39 CFSEmailUiClsListsHandler* CFSEmailUiClsListsHandler::NewL( RFs& aFs, |
|
40 CVPbkContactManager* aContactManager ) |
|
41 { |
|
42 FUNC_LOG; |
|
43 CFSEmailUiClsListsHandler* object = |
|
44 CFSEmailUiClsListsHandler::NewLC( aFs, aContactManager ); |
|
45 CleanupStack::Pop( object ); |
|
46 return object; |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CFSEmailUiClsListsHandler::NewLC |
|
51 // ----------------------------------------------------------------------------- |
|
52 CFSEmailUiClsListsHandler* CFSEmailUiClsListsHandler::NewLC( RFs& aFs, CVPbkContactManager* aContactManager ) |
|
53 { |
|
54 FUNC_LOG; |
|
55 CFSEmailUiClsListsHandler* object = new (ELeave) CFSEmailUiClsListsHandler( aFs, aContactManager ); |
|
56 CleanupStack::PushL( object ); |
|
57 object->ConstructL(); |
|
58 return object; |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CFSEmailUiClsListsHandler::~CFSEmailUiClsListsHandler |
|
63 // ----------------------------------------------------------------------------- |
|
64 CFSEmailUiClsListsHandler::~CFSEmailUiClsListsHandler() |
|
65 { |
|
66 FUNC_LOG; |
|
67 delete iSearchedText; |
|
68 delete iPcsMatchObserver; |
|
69 |
|
70 iMatchingCompleteContacts.Reset(); |
|
71 iMatchingMRUContacts.Reset(); |
|
72 iMatchingMissingEmailContacts.Reset(); |
|
73 |
|
74 delete iAllMRUContacts; |
|
75 delete iInputObserver; |
|
76 delete iAknFepCenRep; |
|
77 delete iRequestHandler; |
|
78 } |
|
79 |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CFSEmailUiClsListsHandler::UpdateContactMatchListsL |
|
83 // ----------------------------------------------------------------------------- |
|
84 void CFSEmailUiClsListsHandler::UpdateContactMatchListsL( |
|
85 const RPointerArray<CFSEmailUiClsItem>& aMatches ) |
|
86 { |
|
87 FUNC_LOG; |
|
88 for( TInt i = 0 ; i < aMatches.Count() ; ++i ) |
|
89 { |
|
90 if( aMatches[i]->IsMruItem() ) |
|
91 { |
|
92 // If this is MRU item, we need to check that it doesn't |
|
93 // already exist in iMatchingCompleteContacts |
|
94 TInt itemIndex = FindDuplicate( *aMatches[i], iMatchingCompleteContacts ); |
|
95 if( itemIndex == KErrNotFound ) |
|
96 { |
|
97 iMatchingMRUContacts.AppendL( aMatches[i] ); |
|
98 } |
|
99 |
|
100 } |
|
101 else if( aMatches[i]->EmailAddress().Length() > 0 ) |
|
102 { |
|
103 // If this is Phonebook item, we need to check that it doesn't |
|
104 // already exist in iMatchingMRUContacts |
|
105 TInt itemIndex = FindDuplicate( *aMatches[i], iMatchingMRUContacts ); |
|
106 if( itemIndex != KErrNotFound ) |
|
107 { |
|
108 // Found, this needs to be removed from the MRU list |
|
109 iMatchingMRUContacts.Remove( itemIndex ); |
|
110 } |
|
111 |
|
112 // Phonebook items are always added to the top of the list |
|
113 iMatchingCompleteContacts.AppendL( aMatches[i] ); |
|
114 } |
|
115 else |
|
116 { |
|
117 // No email, nothing to compare, so add this always to the end of the list |
|
118 iMatchingMissingEmailContacts.AppendL( aMatches[i] ); |
|
119 } |
|
120 } |
|
121 |
|
122 RPointerArray<CFSEmailUiClsItem> allMatches = ConstructOneListL( iMatchingCompleteContacts, |
|
123 iMatchingMRUContacts, |
|
124 iMatchingMissingEmailContacts ); |
|
125 CleanupResetAndDestroyClosePushL( allMatches ); // Ownership is taken |
|
126 iClsListObserver->ArrayUpdatedL( allMatches ); |
|
127 CleanupStack::PopAndDestroy(&allMatches ); // Array is released, destructors are called |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CFSEmailUiClsListsHandler::InputModeChangedL |
|
132 // ----------------------------------------------------------------------------- |
|
133 void CFSEmailUiClsListsHandler::InputModeChangedL( TKeyboardModes aNewInputMode ) |
|
134 { |
|
135 FUNC_LOG; |
|
136 iPcsMatchObserver->SetInputMode( aNewInputMode ); |
|
137 } |
|
138 |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CFSEmailUiClsListsHandler::CurrentSearchText |
|
142 // ----------------------------------------------------------------------------- |
|
143 const TDesC& CFSEmailUiClsListsHandler::CurrentSearchText() |
|
144 { |
|
145 FUNC_LOG; |
|
146 return *iSearchedText; |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CFSEmailUiClsListsHandler::SearchMatchesL |
|
151 // ----------------------------------------------------------------------------- |
|
152 void CFSEmailUiClsListsHandler::SearchMatchesL( const TDesC& aText ) |
|
153 { |
|
154 FUNC_LOG; |
|
155 // The ownership of the object is in caller of UpdateContactMatchListsL |
|
156 iMatchingCompleteContacts.Reset(); |
|
157 iMatchingMRUContacts.Reset(); |
|
158 iMatchingMissingEmailContacts.Reset(); |
|
159 |
|
160 delete iSearchedText; |
|
161 iSearchedText = NULL; |
|
162 iSearchedText = aText.AllocL(); |
|
163 |
|
164 iPcsMatchObserver->SearchMatchesL( aText ); |
|
165 } |
|
166 |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CFSEmailUiClsListsHandler::CFSEmailUiClsListsHandler |
|
170 // ----------------------------------------------------------------------------- |
|
171 CFSEmailUiClsListsHandler::CFSEmailUiClsListsHandler( RFs& aFs, CVPbkContactManager* aContactManager ) : |
|
172 iContactManager( aContactManager ), |
|
173 iClsListObserver( NULL ), |
|
174 iFs( aFs ), |
|
175 iMailBox ( NULL ) |
|
176 { |
|
177 FUNC_LOG; |
|
178 // Nothing |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CFSEmailUiClsListsHandler::ConstructL |
|
183 // ----------------------------------------------------------------------------- |
|
184 void CFSEmailUiClsListsHandler::ConstructL() |
|
185 { |
|
186 FUNC_LOG; |
|
187 iRequestHandler = CPSRequestHandler::NewL(); |
|
188 |
|
189 iAknFepCenRep = CRepository::NewL( KCRUidAknFep ); |
|
190 |
|
191 iPcsMatchObserver = CFSEmailUiClsMatchObserver::NewL( *iAknFepCenRep, *this, *iRequestHandler, iContactManager ); |
|
192 SetSearchSettingsForPcsMatchObserverL(); |
|
193 |
|
194 // Monitors inputMode changes (predictive vs. non-predictive |
|
195 iInputObserver = CFSEmailUiInputModeObserver::NewL( *iAknFepCenRep, *this ); |
|
196 |
|
197 if( !iSearchedText ) |
|
198 iSearchedText = KNullDesC().AllocL(); |
|
199 |
|
200 //iRemoteLookupSupported = TFsEmailUiUtility::IsRemoteLookupSupported( *iMailBox ); |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CFSEmailUiClsListsHandler::CopyClsItemL |
|
205 // ----------------------------------------------------------------------------- |
|
206 CFSEmailUiClsItem* CFSEmailUiClsListsHandler::CopyClsItemLC( |
|
207 const CFSEmailUiClsItem& aClsItem ) |
|
208 { |
|
209 FUNC_LOG; |
|
210 CFSEmailUiClsItem* newClsItem = aClsItem.CloneLC(); |
|
211 return newClsItem; |
|
212 } |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // CFSEmailUiClsListsHandler::ReadCLSInfoFromMRUListIndexL |
|
216 // ----------------------------------------------------------------------------- |
|
217 TBool CFSEmailUiClsListsHandler::ReadCLSInfoFromMRUListIndexL( MDesCArray& aTextArray, |
|
218 CFSEmailUiClsItem& aClsItem, |
|
219 const TInt aCurrentMatchIndex, const TInt aPreviousMatchIndex ) |
|
220 { |
|
221 FUNC_LOG; |
|
222 TBool retVal = EFalse; |
|
223 // This should be even number |
|
224 TInt currentRealItemIndex = aCurrentMatchIndex - ( aCurrentMatchIndex % 2 ); |
|
225 // Here we need to check if match is found both from the display name and email address |
|
226 if( currentRealItemIndex != aPreviousMatchIndex ) |
|
227 { |
|
228 aClsItem.SetDisplayNameL( aTextArray.MdcaPoint( currentRealItemIndex ) ); |
|
229 aClsItem.SetEmailAddressL( aTextArray.MdcaPoint( currentRealItemIndex + 1 ) ); |
|
230 retVal = ETrue; |
|
231 } |
|
232 return retVal; |
|
233 } |
|
234 |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CFSEmailUiClsListsHandler::FindAndDestroyDuplicate |
|
238 // ----------------------------------------------------------------------------- |
|
239 TInt CFSEmailUiClsListsHandler::FindDuplicate( const CFSEmailUiClsItem& aClsItem, |
|
240 RPointerArray<CFSEmailUiClsItem>& aContacts ) |
|
241 { |
|
242 FUNC_LOG; |
|
243 // find duplicate email addresses from aContacts |
|
244 const TDesC& emailAddress = aClsItem.EmailAddress(); |
|
245 |
|
246 for( TInt i = 0; i < aContacts.Count(); ++i ) |
|
247 { |
|
248 const TDesC& currentItemEmailAddress = aContacts[i]->EmailAddress(); |
|
249 |
|
250 if( emailAddress.CompareF( currentItemEmailAddress ) == 0 ) |
|
251 { |
|
252 return i; |
|
253 } |
|
254 } |
|
255 |
|
256 return KErrNotFound; |
|
257 } |
|
258 |
|
259 // ----------------------------------------------------------------------------- |
|
260 // CFSEmailUiClsListsHandler::ConstructOneListL |
|
261 // ----------------------------------------------------------------------------- |
|
262 RPointerArray<CFSEmailUiClsItem> CFSEmailUiClsListsHandler::ConstructOneListL( |
|
263 const RPointerArray<CFSEmailUiClsItem>& aContactMatchesWithEmail, |
|
264 const RPointerArray<CFSEmailUiClsItem>& aMRUMatches, |
|
265 const RPointerArray<CFSEmailUiClsItem>& aContactMatchesWithoutEmail ) |
|
266 { |
|
267 FUNC_LOG; |
|
268 RPointerArray<CFSEmailUiClsItem> allMatches; |
|
269 CleanupResetAndDestroyClosePushL( allMatches ); |
|
270 |
|
271 // Copy all the objects from three other lists to the all matches list |
|
272 TInt matchingComleteItemsCount = aContactMatchesWithEmail.Count(); |
|
273 for( TInt i = 0 ; i < matchingComleteItemsCount; i++ ) |
|
274 { |
|
275 CFSEmailUiClsItem* newClsItem = CopyClsItemLC( *aContactMatchesWithEmail[i] ); |
|
276 allMatches.AppendL( newClsItem ); |
|
277 CleanupStack::Pop( newClsItem ); |
|
278 } |
|
279 |
|
280 TInt matchingMRUItemsCount = aMRUMatches.Count(); |
|
281 for ( TInt i = 0 ; i < matchingMRUItemsCount ; i++ ) |
|
282 { |
|
283 CFSEmailUiClsItem* newClsItem = CopyClsItemLC( *aMRUMatches[i] ); |
|
284 allMatches.AppendL( newClsItem ); |
|
285 CleanupStack::Pop( newClsItem ); |
|
286 } |
|
287 |
|
288 TInt mathingContactItemsWithoutEmailCount = aContactMatchesWithoutEmail.Count(); |
|
289 for( TInt i = 0 ; i < mathingContactItemsWithoutEmailCount ; i++ ) |
|
290 { |
|
291 CFSEmailUiClsItem* newClsItem = CopyClsItemLC( *aContactMatchesWithoutEmail[i] ); |
|
292 allMatches.AppendL( newClsItem ); |
|
293 CleanupStack::Pop( newClsItem ); |
|
294 } |
|
295 |
|
296 CleanupStack::Pop( &allMatches ); |
|
297 return allMatches; |
|
298 } |
|
299 |
|
300 // ----------------------------------------------------------------------------- |
|
301 // CFSEmailUiClsListsHandler::SetSearchSettingsForPcsMatchObserverL() |
|
302 // ----------------------------------------------------------------------------- |
|
303 void CFSEmailUiClsListsHandler::SetSearchSettingsForPcsMatchObserverL() |
|
304 { |
|
305 FUNC_LOG; |
|
306 // Create predictive search settings |
|
307 CPsSettings* searchSettings = CPsSettings::NewL(); |
|
308 CleanupStack::PushL(searchSettings); |
|
309 |
|
310 RPointerArray<TDesC> databases; |
|
311 CleanupClosePushL(databases); |
|
312 |
|
313 HBufC* store1 = HBufC::NewLC(50); |
|
314 store1->Des().Copy( KVPbkDefaultCntDbURI ); // To specify phone contacts store |
|
315 |
|
316 databases.AppendL(store1); |
|
317 HBufC* store2 = NULL; |
|
318 if ( iMailBox ) |
|
319 { |
|
320 store2 = HBufC::NewLC(50); |
|
321 GetMruDatastoreUriFromMailbox( *iMailBox, *store2 ); |
|
322 databases.AppendL( store2 ); |
|
323 } |
|
324 searchSettings->SetSearchUrisL(databases); |
|
325 |
|
326 // Set displayfields (first name, last name, email addresses) |
|
327 RArray<TInt> displayFields(6); |
|
328 CleanupClosePushL(displayFields); |
|
329 displayFields.AppendL(R_VPBK_FIELD_TYPE_FIRSTNAME); |
|
330 displayFields.AppendL(R_VPBK_FIELD_TYPE_LASTNAME); |
|
331 displayFields.AppendL(R_VPBK_FIELD_TYPE_EMAILGEN); |
|
332 displayFields.AppendL(R_VPBK_FIELD_TYPE_EMAILHOME); |
|
333 displayFields.AppendL(R_VPBK_FIELD_TYPE_EMAILWORK); |
|
334 searchSettings->SetDisplayFieldsL(displayFields); |
|
335 CleanupStack::Pop(&displayFields); |
|
336 displayFields.Close(); |
|
337 |
|
338 // Set the new sort order of data fields |
|
339 RArray<TInt> sortOrder; |
|
340 CleanupClosePushL(sortOrder); |
|
341 |
|
342 // change sorting order for Chinese to LNFN |
|
343 if ( User::Language() == ELangPrcChinese ) |
|
344 { |
|
345 sortOrder.AppendL( R_VPBK_FIELD_TYPE_LASTNAME ); |
|
346 sortOrder.AppendL( R_VPBK_FIELD_TYPE_FIRSTNAME ); |
|
347 } |
|
348 else // default sorting order FN LN |
|
349 { |
|
350 sortOrder.AppendL( R_VPBK_FIELD_TYPE_FIRSTNAME ); |
|
351 sortOrder.AppendL( R_VPBK_FIELD_TYPE_LASTNAME ); |
|
352 } |
|
353 |
|
354 sortOrder.AppendL(R_VPBK_FIELD_TYPE_EMAILGEN); |
|
355 sortOrder.AppendL(R_VPBK_FIELD_TYPE_EMAILHOME); |
|
356 sortOrder.AppendL(R_VPBK_FIELD_TYPE_EMAILWORK); |
|
357 iRequestHandler->ChangeSortOrderL(*store1, sortOrder); |
|
358 if ( store2 ) |
|
359 { |
|
360 iRequestHandler->ChangeSortOrderL(*store2, sortOrder); |
|
361 } |
|
362 |
|
363 CleanupStack::Pop(&sortOrder); |
|
364 sortOrder.Close(); |
|
365 |
|
366 // Set maximum for search results |
|
367 //How many results is shown on the screen?? |
|
368 //searchSettings->SetMaxResults(const TInt aMaxResults); |
|
369 |
|
370 // Set the new search settings |
|
371 iRequestHandler->SetSearchSettingsL(*searchSettings); |
|
372 |
|
373 if ( store2 ) |
|
374 { |
|
375 CleanupStack::PopAndDestroy(store2); |
|
376 } |
|
377 CleanupStack::PopAndDestroy(store1); |
|
378 CleanupStack::Pop(&databases); |
|
379 databases.Close(); |
|
380 CleanupStack::PopAndDestroy(searchSettings); |
|
381 |
|
382 } |
|
383 |
|
384 // ----------------------------------------------------------------------------- |
|
385 // CFSEmailUiClsListsHandler::isLanguageSupported() |
|
386 // ----------------------------------------------------------------------------- |
|
387 TBool CFSEmailUiClsListsHandler::IsLanguageSupportedL() |
|
388 { |
|
389 FUNC_LOG; |
|
390 // Get the current language |
|
391 TLanguage lang = User::Language(); |
|
392 |
|
393 // Check for language support |
|
394 return iRequestHandler->IsLanguageSupportedL(lang); |
|
395 } |
|
396 |
|
397 void CFSEmailUiClsListsHandler::GetMruDatastoreUriFromMailbox( CFSMailBox& aMailbox, HBufC& aUri ) |
|
398 { |
|
399 FUNC_LOG; |
|
400 aUri.Des().Copy( KDefaultMailBoxURI ); |
|
401 aUri.Des().AppendNum( aMailbox.GetId().PluginId().iUid ); |
|
402 aUri.Des().Append( KDefaultMailBoxURISeparator ); |
|
403 aUri.Des().AppendNum( aMailbox.GetId().Id() ); |
|
404 } |
|
405 |
|
406 void CFSEmailUiClsListsHandler::SetObserver( MFSEmailUiClsListsObserver* aClsListObserver ) |
|
407 { |
|
408 FUNC_LOG; |
|
409 iClsListObserver = aClsListObserver; |
|
410 } |
|
411 |
|
412 void CFSEmailUiClsListsHandler::SetCurrentMailboxL( CFSMailBox* aMailBox ) |
|
413 { |
|
414 FUNC_LOG; |
|
415 TFSMailMsgId currentMailboxId; |
|
416 TFSMailMsgId newMailboxId; |
|
417 |
|
418 if( iMailBox ) |
|
419 { |
|
420 currentMailboxId = iMailBox->GetId(); |
|
421 } |
|
422 if( aMailBox ) |
|
423 { |
|
424 newMailboxId = aMailBox->GetId(); |
|
425 } |
|
426 |
|
427 if( currentMailboxId != newMailboxId ) |
|
428 { |
|
429 iMailBox = aMailBox; |
|
430 SetSearchSettingsForPcsMatchObserverL(); |
|
431 } |
|
432 } |
|
433 |
|
434 void CFSEmailUiClsListsHandler::OperationErrorL( TInt aErrorCode ) |
|
435 { |
|
436 FUNC_LOG; |
|
437 iClsListObserver->OperationErrorL( aErrorCode ); |
|
438 } |
|
439 |