|
1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * A class for asyncronous phonebook name lookup |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 // Phonebook debug |
|
23 #include <PbkDebug.h> |
|
24 |
|
25 // Phonebook engine |
|
26 #include "CPbkContactEngine.h" |
|
27 #include "CPbkContactItem.h" |
|
28 #include "CPbkFieldsInfo.h" |
|
29 #include <MPbkContactNameFormat.h> |
|
30 |
|
31 // Phonebook copy |
|
32 #include "CPbkNameLookup.h" |
|
33 |
|
34 |
|
35 // MODULE DATA STRUCTURES |
|
36 |
|
37 |
|
38 // ================= MEMBER FUNCTIONS ======================= |
|
39 |
|
40 inline CPbkNameLookup::CPbkNameLookup |
|
41 (CPbkContactEngine& aEngine, |
|
42 MPbkNameLookupObserver& aObserver) : |
|
43 CActive(EPriorityIdle), |
|
44 iEngine(aEngine), |
|
45 iObserver(aObserver) |
|
46 { |
|
47 CActiveScheduler::Add(this); |
|
48 } |
|
49 |
|
50 CPbkNameLookup* CPbkNameLookup::NewL |
|
51 (CPbkContactEngine& aEngine, |
|
52 MPbkNameLookupObserver& aObserver) |
|
53 { |
|
54 return new(ELeave) CPbkNameLookup(aEngine, aObserver); |
|
55 } |
|
56 |
|
57 void CPbkNameLookup::IssueNameLookupL |
|
58 (CContactIdArray* aContactIds, |
|
59 CPbkContactItem& aEntry) |
|
60 { |
|
61 Cancel(); |
|
62 delete iContactIds; |
|
63 iContactIds = aContactIds; |
|
64 |
|
65 iEntry = &aEntry; |
|
66 |
|
67 IssueRequest(); |
|
68 } |
|
69 |
|
70 CPbkNameLookup::~CPbkNameLookup() |
|
71 { |
|
72 Cancel(); |
|
73 delete iContactIds; |
|
74 } |
|
75 |
|
76 void CPbkNameLookup::DoCancel() |
|
77 { |
|
78 } |
|
79 |
|
80 void CPbkNameLookup::RunL() |
|
81 { |
|
82 PBK_DEBUG_PRINT( |
|
83 PBK_DEBUG_STRING("CPbkNameLookup::RunL start")); |
|
84 |
|
85 TBool result = EFalse; |
|
86 // Load the contact item to display information about it |
|
87 const TInt index = iContactIds->Count()-1; |
|
88 const TContactItemId cid = (*iContactIds)[index]; |
|
89 CPbkContactItem* item = iEngine.ReadContactLC(cid); |
|
90 if (item) |
|
91 { |
|
92 // comparison is based only to the last name |
|
93 HBufC* contactTitle = item->GetContactTitleOrNullL(); |
|
94 if (contactTitle) |
|
95 { |
|
96 CleanupStack::PushL(contactTitle); |
|
97 HBufC* title = iEntry->GetContactTitleOrNullL(); |
|
98 if (title) |
|
99 { |
|
100 CleanupStack::PushL(title); |
|
101 |
|
102 if (!title->CompareF(*contactTitle)) |
|
103 { |
|
104 iObserver.NameLookupCompleted(item->Id()); |
|
105 result = ETrue; |
|
106 } |
|
107 |
|
108 CleanupStack::PopAndDestroy(title); |
|
109 } |
|
110 CleanupStack::PopAndDestroy(contactTitle); |
|
111 } |
|
112 } |
|
113 |
|
114 CleanupStack::PopAndDestroy(item); |
|
115 |
|
116 if (!result) |
|
117 { |
|
118 iContactIds->Remove(iContactIds->Count()-1); |
|
119 IssueRequest(); |
|
120 } |
|
121 |
|
122 PBK_DEBUG_PRINT( |
|
123 PBK_DEBUG_STRING("CPbkNameLookup::RunL end")); |
|
124 } |
|
125 |
|
126 TInt CPbkNameLookup::RunError |
|
127 (TInt aError) |
|
128 { |
|
129 iObserver.NameLookupFailed(aError); |
|
130 return KErrNone; |
|
131 } |
|
132 |
|
133 void CPbkNameLookup::IssueRequest() |
|
134 { |
|
135 PBK_DEBUG_PRINT( |
|
136 PBK_DEBUG_STRING("CPbkNameLookup::IssueRequest start")); |
|
137 |
|
138 if (iContactIds->Count() > 0) |
|
139 { |
|
140 TRequestStatus* sp = &iStatus; |
|
141 User::RequestComplete(sp, KErrNone); |
|
142 SetActive(); |
|
143 } |
|
144 else |
|
145 { |
|
146 iObserver.NameLookupCompleted(KNullContactId); |
|
147 } |
|
148 |
|
149 PBK_DEBUG_PRINT( |
|
150 PBK_DEBUG_STRING("CPbkNameLookup::IssueRequest start")); |
|
151 } |
|
152 |
|
153 // End of File |