|
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 * Handling thumbnail save/retrieve operations and making these |
|
16 * operations synchronous |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "CBCardThumbnailHandler.h" |
|
23 #include <fbs.h> |
|
24 #include <CPbkThumbnailManager.h> |
|
25 #include <PbkImageData.h> |
|
26 #include <TPbkImageLoadParameters.h> |
|
27 #include "CBCardImageUtil.h" |
|
28 |
|
29 |
|
30 /// Unnamed namespace for local definitions |
|
31 namespace { |
|
32 |
|
33 // LOCAL CONSTANTS AND MACROS |
|
34 // Default size for thumbnail images |
|
35 #define KDefaultThumbnailSize TSize(80,96) |
|
36 /// JPEG file mime type |
|
37 _LIT8(KJpegMimeType, "image/jpeg"); |
|
38 |
|
39 #ifdef _DEBUG |
|
40 enum TPanicCode |
|
41 { |
|
42 EPanicPreCond_ProcessComplete = 1, |
|
43 EPanicPreCond_ProcessError, |
|
44 }; |
|
45 |
|
46 void Panic(TPanicCode aReason) |
|
47 { |
|
48 _LIT(KPanicText, "CBCardThumbnailHandler"); |
|
49 User::Panic(KPanicText,aReason); |
|
50 } |
|
51 |
|
52 #endif // _DEBUG |
|
53 |
|
54 } // namespace |
|
55 |
|
56 // ==================== MEMBER FUNCTIONS ==================== |
|
57 |
|
58 |
|
59 CBCardThumbnailHandler* CBCardThumbnailHandler::NewL(CPbkContactEngine& aEngine) |
|
60 { |
|
61 CBCardThumbnailHandler* self = new (ELeave) CBCardThumbnailHandler(); |
|
62 CleanupStack::PushL(self); |
|
63 self->ConstructL(aEngine); |
|
64 CleanupStack::Pop(self); |
|
65 return self; |
|
66 } |
|
67 |
|
68 CBCardThumbnailHandler::CBCardThumbnailHandler() |
|
69 { |
|
70 } |
|
71 |
|
72 CBCardThumbnailHandler::~CBCardThumbnailHandler() |
|
73 { |
|
74 delete iImageBlob; |
|
75 delete iBitmap; |
|
76 delete iImageData; |
|
77 delete iThumbOperation; |
|
78 delete iManager; |
|
79 } |
|
80 |
|
81 void CBCardThumbnailHandler::ConstructL(CPbkContactEngine& aEngine) |
|
82 { |
|
83 iManager = CPbkThumbnailManager::NewL(aEngine); |
|
84 } |
|
85 |
|
86 void CBCardThumbnailHandler::SaveThumbnailL( |
|
87 CPbkContactItem& aContactItem,const TDesC8& aSource) |
|
88 { |
|
89 iError = KErrNone; |
|
90 delete iThumbOperation; |
|
91 iThumbOperation = NULL; |
|
92 |
|
93 iThumbOperation = iManager->SetThumbnailAsyncL(*this, aContactItem, aSource); |
|
94 if(iWait.IsStarted()) |
|
95 { |
|
96 iWait.AsyncStop(); |
|
97 } |
|
98 iWait.Start(); |
|
99 User::LeaveIfError(iError); |
|
100 } |
|
101 |
|
102 TBool CBCardThumbnailHandler::HasThumbnail( |
|
103 const CPbkContactItem& aContactItem) const |
|
104 { |
|
105 return iManager->HasThumbnail(aContactItem); |
|
106 } |
|
107 |
|
108 const TDesC8& CBCardThumbnailHandler::GetThumbnailL(CPbkContactItem& aContactItem) |
|
109 { |
|
110 if (IsAlreadyExportableL(aContactItem)) |
|
111 { |
|
112 const TDesC8& imageBuf = iImageData->ImageData().GetBufferL(); |
|
113 return imageBuf; |
|
114 } |
|
115 else |
|
116 { |
|
117 delete iImageData; |
|
118 iImageData = NULL; |
|
119 |
|
120 delete iImageBlob; |
|
121 iImageBlob = NULL; |
|
122 iImageBlob = GetThumbnailBitmapL(aContactItem); |
|
123 |
|
124 return *iImageBlob; |
|
125 } |
|
126 } |
|
127 |
|
128 TBool CBCardThumbnailHandler::IsAlreadyExportableL(CPbkContactItem& aContactItem) |
|
129 { |
|
130 iError = KErrNone; |
|
131 delete iThumbOperation; |
|
132 iThumbOperation = NULL; |
|
133 |
|
134 iThumbOperation = iManager->GetThumbnailImageAsyncL(*this, aContactItem); |
|
135 if(iWait.IsStarted()) |
|
136 { |
|
137 iWait.AsyncStop(); |
|
138 } |
|
139 iWait.Start(); |
|
140 User::LeaveIfError(iError); |
|
141 |
|
142 // Image must be in jpeg format |
|
143 if (iImageData->MimeType() != KJpegMimeType) |
|
144 { |
|
145 return EFalse; |
|
146 } |
|
147 |
|
148 // Image must be of size 80x96 |
|
149 return (iImageData->ImageSizeInPixels() == KDefaultThumbnailSize); |
|
150 } |
|
151 |
|
152 |
|
153 HBufC8* CBCardThumbnailHandler::GetThumbnailBitmapL(CPbkContactItem& aContactItem) |
|
154 { |
|
155 iError = KErrNone; |
|
156 delete iThumbOperation; |
|
157 iThumbOperation = NULL; |
|
158 |
|
159 |
|
160 // Define parameters for thumbnail |
|
161 TPbkImageLoadParameters params; |
|
162 params.iSize = KDefaultThumbnailSize; |
|
163 params.iFlags = TPbkImageLoadParameters::EScaleImage | |
|
164 TPbkImageLoadParameters::EKeepAspectRatio; |
|
165 |
|
166 iThumbOperation = iManager->GetThumbnailAsyncL(*this, aContactItem ,params); |
|
167 if(iWait.IsStarted()) |
|
168 { |
|
169 iWait.AsyncStop(); |
|
170 } |
|
171 iWait.Start(); |
|
172 User::LeaveIfError(iError); |
|
173 |
|
174 CBCardImageUtil* util = CBCardImageUtil::NewL(); |
|
175 CleanupStack::PushL(util); |
|
176 |
|
177 if (!iBitmap) |
|
178 { |
|
179 User::Leave(KErrNotFound); |
|
180 } |
|
181 |
|
182 |
|
183 // convert bitmap to jpeg descriptor |
|
184 HBufC8* imageBlob = util->BitmapToDescL(*iBitmap); |
|
185 |
|
186 delete iBitmap; |
|
187 iBitmap = NULL; |
|
188 |
|
189 CleanupStack::PopAndDestroy(util); |
|
190 |
|
191 return imageBlob; |
|
192 } |
|
193 |
|
194 void CBCardThumbnailHandler::PbkThumbnailGetImageComplete( |
|
195 MPbkThumbnailOperation& aOperation, CPbkImageDataWithInfo* aImageData) |
|
196 { |
|
197 ProcessComplete(aOperation); |
|
198 |
|
199 delete iImageData; |
|
200 iImageData = aImageData; |
|
201 } |
|
202 |
|
203 void CBCardThumbnailHandler::PbkThumbnailGetImageFailed( |
|
204 MPbkThumbnailOperation& aOperation, TInt aError) |
|
205 { |
|
206 ProcessError(aOperation, aError); |
|
207 } |
|
208 |
|
209 void CBCardThumbnailHandler::PbkThumbnailGetComplete( |
|
210 MPbkThumbnailOperation& aOperation, CFbsBitmap* aBitmap) |
|
211 { |
|
212 ProcessComplete(aOperation); |
|
213 |
|
214 delete iBitmap; |
|
215 iBitmap = aBitmap; |
|
216 } |
|
217 |
|
218 void CBCardThumbnailHandler::PbkThumbnailGetFailed( |
|
219 MPbkThumbnailOperation& aOperation, TInt aError) |
|
220 { |
|
221 ProcessError(aOperation, aError); |
|
222 } |
|
223 |
|
224 void CBCardThumbnailHandler::PbkThumbnailSetComplete( |
|
225 MPbkThumbnailOperation& aOperation) |
|
226 { |
|
227 ProcessComplete(aOperation); |
|
228 } |
|
229 |
|
230 void CBCardThumbnailHandler::PbkThumbnailSetFailed( |
|
231 MPbkThumbnailOperation& aOperation, TInt aError) |
|
232 { |
|
233 ProcessError(aOperation, aError); |
|
234 } |
|
235 |
|
236 void CBCardThumbnailHandler::ProcessError( |
|
237 MPbkThumbnailOperation& |
|
238 #ifdef _DEBUG |
|
239 aOperation |
|
240 #endif |
|
241 , TInt aError) |
|
242 { |
|
243 __ASSERT_DEBUG(iThumbOperation && iThumbOperation == &aOperation, |
|
244 Panic(EPanicPreCond_ProcessError)); |
|
245 |
|
246 iWait.AsyncStop(); |
|
247 iError = aError; |
|
248 } |
|
249 |
|
250 void CBCardThumbnailHandler::ProcessComplete( |
|
251 MPbkThumbnailOperation& |
|
252 #ifdef _DEBUG |
|
253 aOperation |
|
254 #endif |
|
255 ) |
|
256 { |
|
257 __ASSERT_DEBUG(iThumbOperation && iThumbOperation == &aOperation, |
|
258 Panic(EPanicPreCond_ProcessComplete)); |
|
259 |
|
260 iWait.AsyncStop(); |
|
261 iError = KErrNone; |
|
262 } |
|
263 |
|
264 // End of File |