|
1 /* |
|
2 * Copyright (c) 2002-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 * Methods for Phonebook2 contact item field embedded image reader. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include "Pbk2PresentationUtils.h" |
|
23 #include "CPbk2EmbeddedImage.h" |
|
24 #include "CPbk2ImageReader.h" |
|
25 #include "MPbk2ImageOperationObservers.h" |
|
26 #include "MVPbkBaseContactField.h" |
|
27 #include "MVPbkStoreContactField.h" |
|
28 #include "MVPbkContactFieldBinaryData.h" |
|
29 #include "CVPbkContactManager.h" |
|
30 #include "TVPbkFieldTypeMapping.h" |
|
31 #include "MVPbkFieldType.h" |
|
32 #include "CPbk2ImageData.h" |
|
33 |
|
34 #include <e32std.h> |
|
35 #include <eikappui.h> |
|
36 #include <imageconversion.h> |
|
37 #include <aknappui.h> // CEikAppUi |
|
38 #include <AknUtils.h> // TAknLayoutRect |
|
39 #include <barsread.h> // TResourceReader |
|
40 #include <RPbk2LocalizedResourceFile.h> |
|
41 #include "Pbk2DataCaging.hrh" |
|
42 |
|
43 #include <Pbk2Presentation.rsg> |
|
44 |
|
45 /// Unnamed namespace for local definitions |
|
46 namespace { |
|
47 |
|
48 #ifdef _DEBUG |
|
49 enum TPanicCode |
|
50 { |
|
51 EPanicReadPreCond_Constructor = 1, |
|
52 EPanicReadPreCond_StartReadL, |
|
53 |
|
54 EPanicWritePreCond_Constructor = 100, |
|
55 EPanicWritePreCond_CreateImageWriterL, |
|
56 EPanicWritePreCond_StoreImageL_CMdaImageDataWriteUtility |
|
57 }; |
|
58 #endif // _DEBUG |
|
59 |
|
60 |
|
61 // ==================== LOCAL FUNCTIONS ==================== |
|
62 |
|
63 #ifdef _DEBUG |
|
64 void Panic(TPanicCode aPanicCode) |
|
65 { |
|
66 _LIT(KPanicText, "CPbkEmbeddedImage"); |
|
67 User::Panic(KPanicText, aPanicCode); |
|
68 } |
|
69 #endif // _DEBUG |
|
70 |
|
71 } // namespace |
|
72 |
|
73 |
|
74 // ================= MEMBER FUNCTIONS ======================= |
|
75 // -------------------------------------------------------------------------- |
|
76 // CPbk2EmbeddedImageReader::CPbk2EmbeddedImageReader |
|
77 // -------------------------------------------------------------------------- |
|
78 // |
|
79 inline CPbk2EmbeddedImageReader::CPbk2EmbeddedImageReader |
|
80 (const MVPbkBaseContactField& aField, |
|
81 MPbk2ImageGetObserver& aObserver) : |
|
82 CPbk2ImageReaderBase(aObserver), |
|
83 iField(aField) |
|
84 { |
|
85 __ASSERT_DEBUG(iField.FieldData().DataType()==EVPbkFieldStorageTypeBinary, |
|
86 Panic(EPanicReadPreCond_Constructor)); |
|
87 } |
|
88 |
|
89 // -------------------------------------------------------------------------- |
|
90 // CPbk2EmbeddedImageReader::ConstructL |
|
91 // -------------------------------------------------------------------------- |
|
92 // |
|
93 inline void CPbk2EmbeddedImageReader::ConstructL() |
|
94 { |
|
95 CPbk2ImageReaderBase::ConstructL(); |
|
96 } |
|
97 |
|
98 // -------------------------------------------------------------------------- |
|
99 // CPbk2EmbeddedImageReader::NewLC |
|
100 // -------------------------------------------------------------------------- |
|
101 // |
|
102 CPbk2EmbeddedImageReader* CPbk2EmbeddedImageReader::NewLC |
|
103 (const MVPbkBaseContactField& aField, |
|
104 MPbk2ImageGetObserver& aObserver) |
|
105 { |
|
106 CPbk2EmbeddedImageReader* self = |
|
107 new(ELeave) CPbk2EmbeddedImageReader(aField,aObserver); |
|
108 CleanupStack::PushL(self); |
|
109 self->ConstructL(); |
|
110 return self; |
|
111 } |
|
112 |
|
113 // -------------------------------------------------------------------------- |
|
114 // CPbk2EmbeddedImageReader::~CPbk2EmbeddedImageReader |
|
115 // -------------------------------------------------------------------------- |
|
116 // |
|
117 CPbk2EmbeddedImageReader::~CPbk2EmbeddedImageReader() |
|
118 { |
|
119 delete iImageBuffer; |
|
120 } |
|
121 |
|
122 // -------------------------------------------------------------------------- |
|
123 // CPbk2EmbeddedImageReader::StartReadL |
|
124 // -------------------------------------------------------------------------- |
|
125 // |
|
126 void CPbk2EmbeddedImageReader::StartReadL( |
|
127 const TPbk2ImageManagerParams* aParameters) |
|
128 { |
|
129 if (iImageBuffer) |
|
130 { |
|
131 delete iImageBuffer; |
|
132 iImageBuffer = NULL; |
|
133 } |
|
134 |
|
135 iImageBuffer = |
|
136 MVPbkContactFieldBinaryData::Cast(iField.FieldData()).BinaryData().AllocL(); |
|
137 |
|
138 __ASSERT_DEBUG(iImageBuffer && iImageBuffer->Length()>0, |
|
139 Panic(EPanicReadPreCond_StartReadL)); |
|
140 CancelRead(); |
|
141 |
|
142 if (iImageBuffer) |
|
143 { |
|
144 ImageReader().ReadFromBufferL(*iImageBuffer, aParameters); |
|
145 } |
|
146 } |
|
147 |
|
148 // -------------------------------------------------------------------------- |
|
149 // CPbk2EmbeddedImageReader::ImageBuffer |
|
150 // -------------------------------------------------------------------------- |
|
151 // |
|
152 const TDesC8& CPbk2EmbeddedImageReader::ImageBuffer() const |
|
153 { |
|
154 if (iImageBuffer) |
|
155 { |
|
156 return *iImageBuffer; |
|
157 } |
|
158 return KNullDesC8; |
|
159 } |
|
160 |
|
161 // -------------------------------------------------------------------------- |
|
162 // CPbk2EmbeddedImageWriter::CPbk2EmbeddedImageWriter |
|
163 // -------------------------------------------------------------------------- |
|
164 // |
|
165 inline CPbk2EmbeddedImageWriter::CPbk2EmbeddedImageWriter |
|
166 (CVPbkContactManager& aContactManager, |
|
167 MVPbkStoreContactField& aField, |
|
168 MPbk2ImageSetObserver& aObserver) : |
|
169 CPbk2ImageWriterBase(aObserver), |
|
170 iContactManager(aContactManager), |
|
171 iField(aField) |
|
172 { |
|
173 __ASSERT_DEBUG(iField.FieldData().DataType()==EVPbkFieldStorageTypeBinary, |
|
174 Panic(EPanicWritePreCond_Constructor)); |
|
175 } |
|
176 |
|
177 // -------------------------------------------------------------------------- |
|
178 // CPbk2EmbeddedImageWriter::ConstructL |
|
179 // -------------------------------------------------------------------------- |
|
180 // |
|
181 inline void CPbk2EmbeddedImageWriter::ConstructL() |
|
182 { |
|
183 CPbk2ImageWriterBase::ConstructL(); |
|
184 } |
|
185 |
|
186 // -------------------------------------------------------------------------- |
|
187 // CPbk2EmbeddedImageWriter::NewLC |
|
188 // -------------------------------------------------------------------------- |
|
189 // |
|
190 CPbk2EmbeddedImageWriter* CPbk2EmbeddedImageWriter::NewLC |
|
191 (CVPbkContactManager& aContactManager, |
|
192 MVPbkStoreContactField& aField, |
|
193 MPbk2ImageSetObserver& aObserver) |
|
194 { |
|
195 CPbk2EmbeddedImageWriter* self = |
|
196 new(ELeave) CPbk2EmbeddedImageWriter( |
|
197 aContactManager, aField, aObserver ); |
|
198 CleanupStack::PushL(self); |
|
199 self->ConstructL(); |
|
200 return self; |
|
201 } |
|
202 |
|
203 // -------------------------------------------------------------------------- |
|
204 // CPbk2EmbeddedImageWriter::~CPbk2EmbeddedImageWriter |
|
205 // -------------------------------------------------------------------------- |
|
206 // |
|
207 CPbk2EmbeddedImageWriter::~CPbk2EmbeddedImageWriter() |
|
208 { |
|
209 delete iBitmapBlob; |
|
210 } |
|
211 |
|
212 // -------------------------------------------------------------------------- |
|
213 // CPbk2EmbeddedImageWriter::CreateImageWriterL |
|
214 // -------------------------------------------------------------------------- |
|
215 // |
|
216 CImageEncoder* CPbk2EmbeddedImageWriter::CreateImageWriterL() |
|
217 { |
|
218 __ASSERT_DEBUG(!iBitmapBlob, |
|
219 Panic(EPanicWritePreCond_CreateImageWriterL)); |
|
220 |
|
221 return CImageEncoder::DataNewL |
|
222 (iBitmapBlob, CImageEncoder::EOptionNone, KImageTypeJPGUid); |
|
223 } |
|
224 |
|
225 // -------------------------------------------------------------------------- |
|
226 // CPbk2EmbeddedImageWriter::StoreImageL |
|
227 // -------------------------------------------------------------------------- |
|
228 // |
|
229 void CPbk2EmbeddedImageWriter::StoreImageL(const MPbk2ImageData& aImageData) |
|
230 { |
|
231 MVPbkContactFieldBinaryData::Cast(iField.FieldData()) |
|
232 .SetBinaryDataL(aImageData.GetBufferL()); |
|
233 } |
|
234 |
|
235 // -------------------------------------------------------------------------- |
|
236 // CPbk2EmbeddedImageWriter::StoreImageL |
|
237 // -------------------------------------------------------------------------- |
|
238 // |
|
239 void CPbk2EmbeddedImageWriter::StoreImageL |
|
240 (CImageEncoder& /*aImageWriter*/) |
|
241 { |
|
242 __ASSERT_DEBUG(iBitmapBlob, |
|
243 Panic(EPanicWritePreCond_StoreImageL_CMdaImageDataWriteUtility)); |
|
244 MVPbkContactFieldBinaryData::Cast(iField.FieldData()) |
|
245 .SetBinaryDataL(*iBitmapBlob); |
|
246 } |
|
247 |
|
248 // -------------------------------------------------------------------------- |
|
249 // CPbk2EmbeddedImageWriter::DoCancel |
|
250 // -------------------------------------------------------------------------- |
|
251 // |
|
252 void CPbk2EmbeddedImageWriter::DoCancel() |
|
253 { |
|
254 delete iBitmapBlob; |
|
255 iBitmapBlob = NULL; |
|
256 |
|
257 // Let base class do its own canceling |
|
258 CPbk2ImageWriterBase::DoCancel(); |
|
259 } |
|
260 |
|
261 // -------------------------------------------------------------------------- |
|
262 // CPbk2EmbeddedImageWriter::ImageSize |
|
263 // -------------------------------------------------------------------------- |
|
264 // |
|
265 TSize CPbk2EmbeddedImageWriter::ImageSize() const |
|
266 { |
|
267 TBool isCodImage (EFalse); |
|
268 TRAP_IGNORE(isCodImage = IsCodImageL()); |
|
269 |
|
270 if (isCodImage) |
|
271 { |
|
272 return (static_cast<CEikAppUi*>(CCoeEnv::Static()->AppUi()))-> |
|
273 ApplicationRect().Size(); |
|
274 } |
|
275 else |
|
276 { |
|
277 return KPbk2PersonalImageSize; |
|
278 } |
|
279 } |
|
280 |
|
281 // -------------------------------------------------------------------------- |
|
282 // CPbk2EmbeddedImageWriter::IsCodImageL |
|
283 // -------------------------------------------------------------------------- |
|
284 // |
|
285 TBool CPbk2EmbeddedImageWriter::IsCodImageL() const |
|
286 { |
|
287 // If iField's type is |
|
288 // EVPbkNonVersitCodImage return ETrue otherwise EFalse. |
|
289 |
|
290 const MVPbkFieldTypeList& masterFieldTypeList = |
|
291 iContactManager.FieldTypes(); |
|
292 RPbk2LocalizedResourceFile resFile(*CCoeEnv::Static()); |
|
293 resFile.OpenLC(KPbk2RomFileDrive, |
|
294 KDC_RESOURCE_FILES_DIR, |
|
295 Pbk2PresentationUtils::PresentationResourceFile()); |
|
296 TResourceReader reader; |
|
297 CCoeEnv::Static()->CreateResourceReaderLC(reader, R_CODIMAGE_FIELD_TYPE); |
|
298 const TInt count = reader.ReadInt16(); |
|
299 TBool found(EFalse); |
|
300 for (TInt i = 0; i < count && !found; ++i) |
|
301 { |
|
302 TVPbkFieldTypeMapping mapping(reader); |
|
303 const MVPbkFieldType* fieldType = |
|
304 mapping.FindMatch(masterFieldTypeList); |
|
305 if (!fieldType) |
|
306 { |
|
307 User::Leave(KErrNotFound); |
|
308 } |
|
309 if (IsSameFieldType(*fieldType)) |
|
310 { |
|
311 found = ETrue; |
|
312 } |
|
313 } |
|
314 CleanupStack::PopAndDestroy(2); // resFile, CreateResourceReaderLC |
|
315 |
|
316 return found; |
|
317 } |
|
318 |
|
319 // -------------------------------------------------------------------------- |
|
320 // CPbk2EmbeddedImageWriter::IsSameFieldType |
|
321 // -------------------------------------------------------------------------- |
|
322 // |
|
323 TBool CPbk2EmbeddedImageWriter::IsSameFieldType( |
|
324 const MVPbkFieldType& aFieldType ) const |
|
325 { |
|
326 TInt maxMatchPriority(iContactManager.FieldTypes().MaxMatchPriority()); |
|
327 for ( TInt matchPriority = 0; |
|
328 matchPriority <= maxMatchPriority; |
|
329 ++matchPriority ) |
|
330 { |
|
331 const MVPbkFieldType* fieldType = |
|
332 iField.MatchFieldType(matchPriority); |
|
333 if (fieldType && fieldType->IsSame(aFieldType)) |
|
334 { |
|
335 return ETrue; |
|
336 } |
|
337 } |
|
338 return EFalse; |
|
339 } |
|
340 |
|
341 // End of File |