|
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: |
|
15 * Provides Phonebook2 image manager methods. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "CPbk2ImageManager.h" |
|
23 |
|
24 // From Phonebook2 |
|
25 #include "MPbk2ImageOperationObservers.h" |
|
26 #include "CPbk2ImageManagerImpl.h" |
|
27 |
|
28 // From Virtual Phonebook |
|
29 #include "CVPbkContactManager.h" |
|
30 #include "MVPbkFieldType.h" |
|
31 #include <MVPbkStoreContact.h> |
|
32 #include <MVPbkContactFieldData.h> |
|
33 |
|
34 // From System |
|
35 |
|
36 // Unnamed namespace for local definitions |
|
37 namespace |
|
38 { |
|
39 /** |
|
40 * Finds field index from contact. |
|
41 * |
|
42 * @param aContactManager Reference to contact manager. |
|
43 * @param aContact Reference to contact, |
|
44 * @param aFieldType Reference to field type. |
|
45 * @return Found field index. KErrNotFound if field cannot be found. |
|
46 */ |
|
47 TInt FindFieldIndex( |
|
48 CVPbkContactManager& aContactManager, |
|
49 const MVPbkBaseContact& aContact, |
|
50 const MVPbkFieldType& aFieldType) |
|
51 { |
|
52 const MVPbkBaseContactFieldCollection& fields = aContact.Fields(); |
|
53 const TInt fieldCount = fields.FieldCount(); |
|
54 |
|
55 const TInt maxMatchPriority = |
|
56 aContactManager.FieldTypes().MaxMatchPriority(); |
|
57 for (TInt matchPriority = 0; |
|
58 matchPriority <= maxMatchPriority; |
|
59 ++matchPriority) |
|
60 { |
|
61 for (TInt i = 0; i < fieldCount; ++i) |
|
62 { |
|
63 const MVPbkFieldType* fieldType = |
|
64 fields.FieldAt(i).MatchFieldType(matchPriority); |
|
65 if (fieldType && fieldType->IsSame(aFieldType)) |
|
66 { |
|
67 return i; |
|
68 } |
|
69 } |
|
70 } |
|
71 return KErrNotFound; |
|
72 } |
|
73 } // unnamed namespace |
|
74 |
|
75 // ================= MEMBER FUNCTIONS ======================= |
|
76 |
|
77 // -------------------------------------------------------------------------- |
|
78 // CPbk2ImageManager::CPbk2ImageManager |
|
79 // -------------------------------------------------------------------------- |
|
80 // |
|
81 inline CPbk2ImageManager::CPbk2ImageManager |
|
82 (CVPbkContactManager& aContactManager) |
|
83 : iContactManager(aContactManager) |
|
84 { |
|
85 } |
|
86 |
|
87 // -------------------------------------------------------------------------- |
|
88 // CPbk2ImageManager::~CPbk2ImageManager |
|
89 // -------------------------------------------------------------------------- |
|
90 // |
|
91 CPbk2ImageManager::~CPbk2ImageManager() |
|
92 { |
|
93 } |
|
94 |
|
95 // -------------------------------------------------------------------------- |
|
96 // CPbk2ImageManager::NewL |
|
97 // -------------------------------------------------------------------------- |
|
98 // |
|
99 EXPORT_C CPbk2ImageManager* CPbk2ImageManager::NewL( |
|
100 CVPbkContactManager& aContactManager) |
|
101 { |
|
102 CPbk2ImageManager* self = |
|
103 new(ELeave) CPbk2ImageManager(aContactManager); |
|
104 CleanupStack::PushL(self); |
|
105 self->ConstructL(); |
|
106 CleanupStack::Pop(self); |
|
107 return self; |
|
108 } |
|
109 |
|
110 // -------------------------------------------------------------------------- |
|
111 // CPbk2ImageManager::ConstructL |
|
112 // -------------------------------------------------------------------------- |
|
113 // |
|
114 inline void CPbk2ImageManager::ConstructL() |
|
115 { |
|
116 } |
|
117 |
|
118 // -------------------------------------------------------------------------- |
|
119 // CPbk2ImageManager::GetImageAsyncL |
|
120 // -------------------------------------------------------------------------- |
|
121 // |
|
122 EXPORT_C MPbk2ImageOperation* CPbk2ImageManager::GetImageAsyncL |
|
123 (TPbk2ImageManagerParams* aParams, |
|
124 MVPbkBaseContact& aContact, |
|
125 const MVPbkFieldType& aFieldType, |
|
126 MPbk2ImageGetObserver& aObserver) |
|
127 { |
|
128 MPbk2ImageReader* reader = Pbk2ImageOperationFactory::CreateReaderLC |
|
129 (iContactManager, aContact, aObserver, aFieldType); |
|
130 if (reader) |
|
131 { |
|
132 reader->StartReadL(aParams); |
|
133 CleanupStack::Pop(); // reader |
|
134 } |
|
135 return reader; |
|
136 } |
|
137 |
|
138 // -------------------------------------------------------------------------- |
|
139 // CPbk2ImageManager::SetImageAsyncL |
|
140 // -------------------------------------------------------------------------- |
|
141 // |
|
142 EXPORT_C MPbk2ImageOperation* CPbk2ImageManager::SetImageAsyncL( |
|
143 MVPbkStoreContact& aContact, |
|
144 const MVPbkFieldType& aFieldType, |
|
145 MPbk2ImageSetObserver& aObserver, |
|
146 const CFbsBitmap& aBitmap) |
|
147 { |
|
148 MPbk2ImageWriter* writer = Pbk2ImageOperationFactory::CreateWriterLC |
|
149 (iContactManager, aContact, aObserver, aFieldType); |
|
150 if ( writer ) |
|
151 { |
|
152 writer->StartWriteL(aBitmap); |
|
153 CleanupStack::Pop(); // writer |
|
154 } |
|
155 return writer; |
|
156 } |
|
157 |
|
158 // -------------------------------------------------------------------------- |
|
159 // CPbk2ImageManager::SetImageAsyncL |
|
160 // -------------------------------------------------------------------------- |
|
161 // |
|
162 EXPORT_C MPbk2ImageOperation* CPbk2ImageManager::SetImageAsyncL( |
|
163 MVPbkStoreContact& aContact, |
|
164 const MVPbkFieldType& aFieldType, |
|
165 MPbk2ImageSetObserver& aObserver, |
|
166 const TDesC8& aImageBuffer) |
|
167 { |
|
168 MPbk2ImageWriter* writer = Pbk2ImageOperationFactory::CreateWriterLC |
|
169 (iContactManager, aContact, aObserver, aFieldType); |
|
170 writer->StartWriteL(aImageBuffer); |
|
171 CleanupStack::Pop(); // writer |
|
172 return writer; |
|
173 } |
|
174 |
|
175 // -------------------------------------------------------------------------- |
|
176 // CPbk2ImageManager::SetImageAsyncL |
|
177 // -------------------------------------------------------------------------- |
|
178 // |
|
179 EXPORT_C MPbk2ImageOperation* CPbk2ImageManager::SetImageAsyncL( |
|
180 MVPbkStoreContact& aContact, |
|
181 const MVPbkFieldType& aFieldType, |
|
182 MPbk2ImageSetObserver& aObserver, |
|
183 const TDesC& aFileName) |
|
184 { |
|
185 MPbk2ImageWriter* writer = Pbk2ImageOperationFactory::CreateWriterLC |
|
186 (iContactManager, aContact, aObserver, aFieldType); |
|
187 writer->StartWriteL(aFileName); |
|
188 CleanupStack::Pop(); // writer |
|
189 return writer; |
|
190 } |
|
191 |
|
192 // -------------------------------------------------------------------------- |
|
193 // CPbk2ImageManager::HasImage |
|
194 // -------------------------------------------------------------------------- |
|
195 // |
|
196 EXPORT_C TBool CPbk2ImageManager::HasImage |
|
197 (const MVPbkBaseContact& aContact, |
|
198 const MVPbkFieldType& aFieldType) const |
|
199 { |
|
200 TInt fieldId = FindFieldIndex(iContactManager, aContact, aFieldType); |
|
201 if ( fieldId != KErrNotFound ) |
|
202 { |
|
203 const MVPbkBaseContactField& field = aContact.Fields().FieldAt(fieldId); |
|
204 if ( !field.FieldData().IsEmpty() ) |
|
205 { |
|
206 return ETrue; |
|
207 } |
|
208 } |
|
209 return EFalse; |
|
210 } |
|
211 |
|
212 // -------------------------------------------------------------------------- |
|
213 // CPbk2ImageManager::RemoveImage |
|
214 // -------------------------------------------------------------------------- |
|
215 // |
|
216 EXPORT_C void CPbk2ImageManager::RemoveImage( |
|
217 MVPbkStoreContact& aContact, |
|
218 const MVPbkFieldType& aFieldType) |
|
219 { |
|
220 TInt index(FindFieldIndex(iContactManager, aContact, aFieldType)); |
|
221 if (index != KErrNotFound) |
|
222 { |
|
223 aContact.RemoveField(index); |
|
224 } |
|
225 } |
|
226 |
|
227 // End of File |