|
1 /* |
|
2 * Copyright (c) 2008 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: presene avatar decoder handler |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "cservicewidgetimagedecoder.h" |
|
21 #include "servicewidgetcpglobals.h" |
|
22 #include <cbsbitmap.h> |
|
23 #include <ImageConversion.h> |
|
24 |
|
25 const TInt KMimeLength = 16; |
|
26 // --------------------------------------------------------------------------- |
|
27 // CServiceWidgetImageDecoder::NewL |
|
28 // Two-phase construction |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 CServiceWidgetImageDecoder* CServiceWidgetImageDecoder::NewL(MServiceWidgetImagerDecodeObserver& aObserver ) |
|
32 { |
|
33 CServiceWidgetImageDecoder* self = new (ELeave) CServiceWidgetImageDecoder(aObserver); |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop(self); |
|
37 return self; |
|
38 } |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // CServiceWidgetImageDecoder::CServiceWidgetImageDecoder |
|
42 // First phase (C++) constructor |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CServiceWidgetImageDecoder::CServiceWidgetImageDecoder(MServiceWidgetImagerDecodeObserver& aObserver ) |
|
46 : |
|
47 CActive( CActive::EPriorityStandard ), |
|
48 iObserver(aObserver) |
|
49 { |
|
50 CActiveScheduler::Add(this); |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CServiceWidgetImageDecoder::ConstructL |
|
55 // ConstructL, second phase constructor |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 void CServiceWidgetImageDecoder::ConstructL() |
|
59 { |
|
60 User::LeaveIfError( iFs.Connect() ); |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // CServiceWidgetImageDecoder::~CServiceWidgetImageDecoder |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 CServiceWidgetImageDecoder::~CServiceWidgetImageDecoder() |
|
68 { |
|
69 DoCancel(); |
|
70 if (iImgDecoder) |
|
71 { |
|
72 delete iImgDecoder; |
|
73 iImgDecoder = NULL; |
|
74 } |
|
75 if (iBitmap) |
|
76 { |
|
77 delete iBitmap; |
|
78 iBitmap = NULL; |
|
79 } |
|
80 if (iBitmapData) |
|
81 { |
|
82 delete iBitmapData; |
|
83 iBitmapData = NULL; |
|
84 } |
|
85 iFs.Close(); |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // CServiceWidgetImageDecoder::StartDecodingL |
|
90 // Starts the decoding process |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 void CServiceWidgetImageDecoder::StartDecodingL(const TDesC8& aBitmapData ) |
|
94 { |
|
95 iBitmapData = aBitmapData.AllocL(); |
|
96 |
|
97 iMimeType = HBufC8::NewL( KMimeLength); |
|
98 TPtr8 mimePtr = iMimeType->Des(); |
|
99 CImageDecoder::GetMimeTypeDataL( *iBitmapData , mimePtr ); |
|
100 |
|
101 iImgDecoder = CImageDecoder::DataNewL( iFs, *iBitmapData ); |
|
102 TFrameInfo info = iImgDecoder->FrameInfo(); |
|
103 iBitmap = new ( ELeave ) CFbsBitmap; |
|
104 User::LeaveIfError( iBitmap->Create( info.iOverallSizeInPixels, info.iFrameDisplayMode )); |
|
105 |
|
106 iNextOperationId = EOpEncodeBitmap; |
|
107 iStatus = KRequestPending; |
|
108 iImgDecoder->Convert( &iStatus, *iBitmap ); |
|
109 SetActive(); |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // CServiceWidgetImageDecoder::RunL |
|
114 // Called by the active object framework when the decoding (request) is |
|
115 // completed. |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 void CServiceWidgetImageDecoder::RunL() |
|
119 { |
|
120 User::LeaveIfError( iStatus.Int() ); |
|
121 |
|
122 switch( iNextOperationId ) |
|
123 { |
|
124 case EOpEncodeBitmap: |
|
125 { |
|
126 StartEncodingL(); |
|
127 break; |
|
128 } |
|
129 case EOpComplete: |
|
130 { |
|
131 iObserver.HandlerDecodeCompleteL(); |
|
132 break; |
|
133 } |
|
134 } |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // CServiceWidgetImageDecoder::DoCancel |
|
139 // Called when the decoding (request) is cancelled for some reason. |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 void CServiceWidgetImageDecoder::DoCancel() |
|
143 { |
|
144 iImgDecoder->Cancel(); |
|
145 } |
|
146 // --------------------------------------------------------------------------- |
|
147 // CServiceWidgetImageDecoder::StartEncodingL |
|
148 // Called when the decoding (request) is cancelled for some reason. |
|
149 // --------------------------------------------------------------------------- |
|
150 // |
|
151 void CServiceWidgetImageDecoder::StartEncodingL() |
|
152 { |
|
153 iImageEncoder = CImageEncoder::FileNewL(iFs, |
|
154 KSeTAvatarPath, |
|
155 *iMimeType, |
|
156 CImageEncoder::EOptionExtUseWithSetThumbnail ); |
|
157 iImageEncoder->SetThumbnail(ETrue); |
|
158 |
|
159 iNextOperationId = EOpComplete; |
|
160 iStatus = KRequestPending; |
|
161 iImageEncoder->Convert( &iStatus, *iBitmap ); |
|
162 SetActive(); |
|
163 } |
|
164 |
|
165 // end of file |