|
1 /* |
|
2 * Copyright (c) 2005-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: Utility class for finding duplicate contacts |
|
15 * from the stores. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef CPBK2DUPLICATECONTACTFINDER_H |
|
21 #define CPBK2DUPLICATECONTACTFINDER_H |
|
22 |
|
23 #include <e32base.h> |
|
24 #include <MVPbkContactFindObserver.h> |
|
25 #include <MVPbkSingleContactOperationObserver.h> |
|
26 |
|
27 class CVPbkContactManager; |
|
28 class MVPbkContactStore; |
|
29 class MVPbkBaseContact; |
|
30 class MVPbkContactLinkArray; |
|
31 class MVPbkContactOperationBase; |
|
32 class MVPbkFieldTypeList; |
|
33 class MPbk2ContactNameFormatter; |
|
34 class MPbk2DuplicateContactObserver; |
|
35 class MVPbkBaseContactField; |
|
36 |
|
37 /** |
|
38 * Utility class for finding duplicate contacts from the stores. |
|
39 * Finds duplicates from stores by using the name formatter. |
|
40 */ |
|
41 class CPbk2DuplicateContactFinder : public CActive, |
|
42 private MVPbkContactFindObserver, |
|
43 private MVPbkSingleContactOperationObserver |
|
44 { |
|
45 public: // Construction and destruction |
|
46 |
|
47 /** |
|
48 * Constructs a duplicate finder that finds duplicate contacts |
|
49 * from all the stores. |
|
50 * |
|
51 * @param aContactManager Virtual Phonebook contact manager |
|
52 * that owns the field types and can |
|
53 * be used for finding the stores. |
|
54 * @param aNameFormatter Name formatter for recognizing |
|
55 * duplicate contacts. |
|
56 * @param aFieldTypesForFind These are the field types that are |
|
57 * usedfor the find. Most probably the |
|
58 * same field types as are in the sort |
|
59 * order. These define also the order |
|
60 * for getting the find text. |
|
61 * E.g if last name is the first in |
|
62 * the list and first name is the second |
|
63 * one then the last name is taken from |
|
64 * the given contact and that text is |
|
65 * used for the find. If there was no |
|
66 * last name in the contact then the |
|
67 * first name text is taken. |
|
68 * @param aDuplicateContacts The result array for |
|
69 * duplicate contacts. |
|
70 * @return A new instance of this class. |
|
71 */ |
|
72 IMPORT_C static CPbk2DuplicateContactFinder* NewL( |
|
73 CVPbkContactManager& aContactManager, |
|
74 MPbk2ContactNameFormatter& aNameFormatter, |
|
75 const MVPbkFieldTypeList& aFieldTypesForFind, |
|
76 RPointerArray<MVPbkStoreContact>& aDuplicateContacts ); |
|
77 |
|
78 /** |
|
79 * Destructor. |
|
80 */ |
|
81 virtual ~CPbk2DuplicateContactFinder(); |
|
82 |
|
83 public: // Interface |
|
84 |
|
85 /** |
|
86 * Starts asynchronous duplicate find from the given store. |
|
87 * |
|
88 * @param aContact The source contact whose duplicates |
|
89 * are searched for. |
|
90 * @param aStore A store for creating find operation. |
|
91 * @param aObserver An observer to notify after the |
|
92 * checking has been done. |
|
93 * @param aMaxDuplicatesToFind Finder stops if the it finds more |
|
94 * than max amount of duplicates. |
|
95 */ |
|
96 IMPORT_C void StartL( |
|
97 const MVPbkBaseContact& aContact, |
|
98 MVPbkContactStore& aStore, |
|
99 MPbk2DuplicateContactObserver& aObserver, |
|
100 TInt aMaxDuplicatesToFind ); |
|
101 /** |
|
102 * Starts asynchronous duplicate find from all the stores. |
|
103 * |
|
104 * @param aContact The source contact whose duplicates |
|
105 * are searched for. |
|
106 * @param aObserver An observer to notify after the |
|
107 * checking has been done. |
|
108 * @param aMaxDuplicatesToFind Finder stops if the it finds more |
|
109 * than max amount of duplicates. |
|
110 */ |
|
111 IMPORT_C void StartL( |
|
112 const MVPbkBaseContact& aContact, |
|
113 MPbk2DuplicateContactObserver& aObserver, |
|
114 TInt aMaxDuplicatesToFind ); |
|
115 |
|
116 private: // From CActive |
|
117 void RunL(); |
|
118 void DoCancel(); |
|
119 TInt RunError( |
|
120 TInt aError ); |
|
121 |
|
122 private: // From MVPbkContactFindObserver |
|
123 void FindCompleteL( |
|
124 MVPbkContactLinkArray* aResults ); |
|
125 void FindFailed( |
|
126 TInt aError ); |
|
127 |
|
128 private: // From MVPbkSingleContactOperationObserver |
|
129 void VPbkSingleContactOperationComplete( |
|
130 MVPbkContactOperationBase& aOperation, |
|
131 MVPbkStoreContact* aContact ); |
|
132 void VPbkSingleContactOperationFailed( |
|
133 MVPbkContactOperationBase& aOperation, |
|
134 TInt aError ); |
|
135 |
|
136 private: // Implementation |
|
137 CPbk2DuplicateContactFinder( |
|
138 CVPbkContactManager& aContactManager, |
|
139 MPbk2ContactNameFormatter& aNameFormatter, |
|
140 const MVPbkFieldTypeList& aFieldTypesForFind, |
|
141 RPointerArray<MVPbkStoreContact>& aDuplicateContacts ); |
|
142 void ConstructL(); |
|
143 void IssueRequest(); |
|
144 TPtrC FindText(); |
|
145 MVPbkContactOperationBase* FindOperationL( |
|
146 const TDesC& aFindText ); |
|
147 void StartFindL(); |
|
148 void RetrieveContactL(); |
|
149 void CompleteL(); |
|
150 TBool LastContactRetrieved(); |
|
151 void DestroyOperation(); |
|
152 void CheckDuplicateL( |
|
153 MVPbkStoreContact* aContact ); |
|
154 TBool IsFieldMatched( const MVPbkBaseContact* aContact, TInt aFieldId ); |
|
155 const MVPbkBaseContactField* FindFieldById( const MVPbkBaseContact* aContact, |
|
156 TInt aFieldId ); |
|
157 |
|
158 private: // Data |
|
159 /// Ref: Virtual Phonebook contact manager |
|
160 CVPbkContactManager& iContactManager; |
|
161 /// ReF: Name formatter |
|
162 MPbk2ContactNameFormatter& iNameFormatter; |
|
163 /// Ref: These are the field types that are used for find |
|
164 const MVPbkFieldTypeList& iFieldTypesForFind; |
|
165 /// Own: A pointer to find text |
|
166 TPtrC iFindText; |
|
167 /// Ref: A store for single store check |
|
168 MVPbkContactStore* iStore; |
|
169 /// Ref: Observer |
|
170 MPbk2DuplicateContactObserver* iObserver; |
|
171 /// Ref:: A contact whose duplicates are searched for |
|
172 const MVPbkBaseContact* iContactToCompare; |
|
173 /// Own: a title of iContactToCompare |
|
174 HBufC* iContactTitle; |
|
175 /// Own: Find operation |
|
176 MVPbkContactOperationBase* iContactOperation; |
|
177 /// Own: Results of the find |
|
178 MVPbkContactLinkArray* iFindResults; |
|
179 /// Ref: Duplicate contacts |
|
180 RPointerArray<MVPbkStoreContact>& iDuplicates; |
|
181 /// An index in iFindResults for retrieving. |
|
182 TInt iContactIndex; |
|
183 /// Internal state of the finder |
|
184 TInt iState; |
|
185 /// The maximum amount of duplicates to find |
|
186 TInt iMaxDuplicatesToFind; |
|
187 }; |
|
188 |
|
189 #endif // CPBK2DUPLICATECONTACTFINDER_H |
|
190 |
|
191 // End of File |