5
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-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 the License "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: This Class is observer for thumbnail generation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include<e32std.h>
|
|
20 |
|
|
21 |
#include<ThumbnailData.h>
|
|
22 |
#include<FBS.H>
|
|
23 |
#include"mgthumbobserver.h"
|
|
24 |
#include"mgthumbnailobserver.h"
|
|
25 |
|
|
26 |
|
|
27 |
const TInt KNulLen = 20;
|
|
28 |
const TInt KZero = 0;
|
|
29 |
// -----------------------------------------------------------------------------
|
|
30 |
// CThumbnailObserver::NewL
|
|
31 |
// Returns the instance of CThumbnailObserver.
|
|
32 |
// -----------------------------------------------------------------------------
|
|
33 |
CThumbnailObserver* CThumbnailObserver::NewL()
|
|
34 |
{
|
|
35 |
CThumbnailObserver* self = new ( ELeave )CThumbnailObserver();
|
|
36 |
CActiveScheduler::Add(self);
|
|
37 |
return self;
|
|
38 |
}
|
|
39 |
|
|
40 |
|
|
41 |
// -----------------------------------------------------------------------------
|
|
42 |
// CThumbnailObserver::ThumbnailPreviewReady
|
|
43 |
// This method is called when thumbnail generation operation completes
|
|
44 |
// -----------------------------------------------------------------------------
|
|
45 |
void CThumbnailObserver::ThumbnailPreviewReady(MThumbnailData& aThumbnail, TThumbnailRequestId aId)
|
|
46 |
{
|
|
47 |
// No implementation
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
}
|
|
52 |
|
|
53 |
// -----------------------------------------------------------------------------
|
|
54 |
// CThumbnailObserver::ThumbnailPreviewReady
|
|
55 |
// This method is called when thumbnail generation operation completes
|
|
56 |
// -----------------------------------------------------------------------------
|
|
57 |
void CThumbnailObserver::ThumbnailReady(TInt aError, MThumbnailData& aThumbnail, TThumbnailRequestId aId)
|
|
58 |
{
|
|
59 |
|
|
60 |
// Findingout the ThumbanilRequestInfo object
|
|
61 |
TInt pos = iThumbnailRequestArray.Count() - 1;
|
|
62 |
|
|
63 |
TThumbnailRequestInfo obj;
|
|
64 |
for ( ; pos >= 0; pos-- )
|
|
65 |
{
|
|
66 |
|
|
67 |
obj = iThumbnailRequestArray[pos];
|
|
68 |
if(obj.iThumbnailRequestId == aId )
|
|
69 |
{
|
|
70 |
iThumbnailRequestArray.Remove(pos);
|
|
71 |
iThumbnailRequestArray.Compress();
|
|
72 |
|
|
73 |
break;
|
|
74 |
|
|
75 |
}
|
|
76 |
|
|
77 |
}
|
|
78 |
|
|
79 |
|
|
80 |
if( KErrNone == aError )
|
|
81 |
{
|
|
82 |
|
|
83 |
// Getting Bitmap of thumbnail
|
|
84 |
CFbsBitmap* bitmap = aThumbnail.DetachBitmap();
|
|
85 |
|
|
86 |
// Saving it to local path
|
|
87 |
bitmap->Save(*(obj.iThumbnailPath));
|
|
88 |
// calling observer with thumbanil path
|
|
89 |
obj.iObserver->ThumbnailReady(aError,*(obj.iThumbnailPath),obj.iTransactionId);
|
|
90 |
|
|
91 |
delete bitmap;
|
|
92 |
}
|
|
93 |
else if (KErrNotFound == aError ){
|
|
94 |
|
|
95 |
obj.iObserver->ThumbnailReady(KErrAlreadyExists,*(obj.iThumbnailPath),obj.iTransactionId);
|
|
96 |
|
|
97 |
}
|
|
98 |
else
|
|
99 |
{
|
|
100 |
|
|
101 |
TBuf<KNulLen> buf;
|
|
102 |
buf.Append(KNullDesC);
|
|
103 |
obj.iObserver->ThumbnailReady(aError,buf,obj.iTransactionId);
|
|
104 |
|
|
105 |
}
|
|
106 |
// Deleting the instance of ThumbanilRequestInfo
|
|
107 |
// We need to delete only iThumbnailPath and need to make iObserver as NULL
|
|
108 |
obj.iObserver = NULL;
|
|
109 |
|
|
110 |
if(obj.iThumbnailPath)
|
|
111 |
delete obj.iThumbnailPath;
|
|
112 |
|
|
113 |
}
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
// -----------------------------------------------------------------------------
|
|
118 |
// CThumbnailObserver::CThumbnailObserver
|
|
119 |
// C++ Constructor
|
|
120 |
// -----------------------------------------------------------------------------
|
|
121 |
CThumbnailObserver::CThumbnailObserver():CActive(EPriorityHigh),iThumbnailManager(NULL)
|
|
122 |
{
|
|
123 |
|
|
124 |
}
|
|
125 |
|
|
126 |
// -----------------------------------------------------------------------------
|
|
127 |
// CThumbnailObserver::~CThumbnailObserver
|
|
128 |
// Destructor
|
|
129 |
// -----------------------------------------------------------------------------
|
|
130 |
CThumbnailObserver::~CThumbnailObserver()
|
|
131 |
{
|
|
132 |
|
|
133 |
// logic for cleaning up the array
|
|
134 |
|
|
135 |
TInt pos = iThumbnailRequestArray.Count() - 1;
|
|
136 |
TThumbnailRequestInfo obj;
|
|
137 |
for ( ; pos >= 0; pos-- )
|
|
138 |
{
|
|
139 |
obj = iThumbnailRequestArray[pos];
|
|
140 |
|
|
141 |
//calling Cancel for the request
|
|
142 |
iThumbnailRequestArray.Remove(pos);
|
|
143 |
iThumbnailRequestArray.Compress();
|
|
144 |
if(iThumbnailManager)
|
|
145 |
{
|
|
146 |
TInt ret = iThumbnailManager->CancelRequest(obj.iThumbnailRequestId);
|
|
147 |
|
|
148 |
// Calling users callback for cancellig request
|
|
149 |
if(obj.iObserver)
|
|
150 |
{
|
|
151 |
|
|
152 |
obj.iObserver->ThumbnailRequestCancel(ret,obj.iTransactionId);
|
|
153 |
}
|
|
154 |
|
|
155 |
}
|
|
156 |
// Deleting the instance of ThumbanilRequestInfo
|
|
157 |
// We need to delete only iThumbnailPath and need to make iObserver as NULL
|
|
158 |
obj.iObserver = NULL;
|
|
159 |
|
|
160 |
if(obj.iThumbnailPath)
|
|
161 |
{
|
|
162 |
delete obj.iThumbnailPath;
|
|
163 |
}
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
}
|
|
168 |
iThumbnailRequestArray.Close();
|
|
169 |
|
|
170 |
iThumbnailManager = NULL;
|
|
171 |
|
|
172 |
}
|
|
173 |
// -----------------------------------------------------------------------------
|
|
174 |
// CThumbnailObserver::Cancel
|
|
175 |
// Cancels the request of thumbnail generation
|
|
176 |
// -----------------------------------------------------------------------------
|
|
177 |
TInt CThumbnailObserver::Cancel(TInt32 aTransactionID)
|
|
178 |
{
|
|
179 |
|
|
180 |
// Search for TThumbnailRequest corresponding to thumbanil request
|
|
181 |
|
|
182 |
TInt pos = iThumbnailRequestArray.Count() - 1;
|
|
183 |
TThumbnailRequestInfo obj;
|
|
184 |
for ( ; pos >= 0; pos-- )
|
|
185 |
{
|
|
186 |
obj = iThumbnailRequestArray[pos];
|
|
187 |
|
|
188 |
if( obj.iTransactionId == aTransactionID )
|
|
189 |
{
|
|
190 |
iThumbnailRequestArray.Remove(pos);
|
|
191 |
iThumbnailRequestArray.Compress();
|
|
192 |
TInt ret = iThumbnailManager->CancelRequest(obj.iThumbnailRequestId);
|
|
193 |
|
|
194 |
obj.iObserver->ThumbnailRequestCancel(ret,obj.iTransactionId);
|
|
195 |
|
|
196 |
// Deleting the instance of ThumbanilRequestInfo
|
|
197 |
// We need to delete only iThumbnailPath and need to make iObserver as NULL
|
|
198 |
obj.iObserver = NULL;
|
|
199 |
|
|
200 |
if(obj.iThumbnailPath)
|
|
201 |
{
|
|
202 |
delete obj.iThumbnailPath;
|
|
203 |
}
|
|
204 |
|
|
205 |
return ret;
|
|
206 |
}
|
|
207 |
}
|
|
208 |
return KErrNotFound;
|
|
209 |
}
|
|
210 |
|
|
211 |
// -----------------------------------------------------------------------------
|
|
212 |
// CThumbnailObserver::AddToObserver
|
|
213 |
// Add ThumbnailRequestInfo to observer
|
|
214 |
// -----------------------------------------------------------------------------
|
|
215 |
void CThumbnailObserver::AddToObserverL(MThumbnailObserver* aObserver,TInt32 aTransactionID ,TDesC& aThumbnailPath , TThumbnailRequestId aThumbnailRequestId)
|
|
216 |
{
|
|
217 |
|
|
218 |
|
|
219 |
TThumbnailRequestInfo thumbnailRequestInfo ;
|
|
220 |
|
|
221 |
thumbnailRequestInfo.iObserver = aObserver;
|
|
222 |
thumbnailRequestInfo.iThumbnailPath = aThumbnailPath.Alloc();
|
|
223 |
thumbnailRequestInfo.iThumbnailRequestId = aThumbnailRequestId;
|
|
224 |
thumbnailRequestInfo.iTransactionId = aTransactionID;
|
|
225 |
|
|
226 |
iThumbnailRequestArray.Append( thumbnailRequestInfo ) ;
|
|
227 |
|
|
228 |
|
|
229 |
}
|
|
230 |
// -----------------------------------------------------------------------------
|
|
231 |
// CThumbnailObserver::ThumbnailAlreadyExists
|
|
232 |
//
|
|
233 |
// -----------------------------------------------------------------------------
|
|
234 |
void CThumbnailObserver::ThumbnailAlreadyExists()
|
|
235 |
{
|
|
236 |
|
|
237 |
iStatus = KRequestPending;
|
|
238 |
SetActive();
|
|
239 |
TRequestStatus* temp = &iStatus;
|
|
240 |
User::RequestComplete( temp, KErrNone );
|
|
241 |
}
|
|
242 |
|
|
243 |
// -----------------------------------------------------------------------------
|
|
244 |
// CThumbnailObserver::SetThumbnailMangager
|
|
245 |
// Sets the thumbnail manager instance
|
|
246 |
// -----------------------------------------------------------------------------
|
|
247 |
|
|
248 |
void CThumbnailObserver:: SetThumbnailMangager(CThumbnailManager* aThumbnailManager)
|
|
249 |
{
|
|
250 |
iThumbnailManager = aThumbnailManager;
|
|
251 |
|
|
252 |
}
|
|
253 |
// -----------------------------------------------------------------------------
|
|
254 |
// CThumbnailObserver::RunL
|
|
255 |
//
|
|
256 |
// -----------------------------------------------------------------------------
|
|
257 |
|
|
258 |
void CThumbnailObserver::RunL()
|
|
259 |
{
|
|
260 |
// calling callback method
|
|
261 |
|
|
262 |
TInt pos = iThumbnailRequestArray.Count() - 1;
|
|
263 |
TThumbnailRequestInfo obj;
|
|
264 |
for ( ; pos >= 0; pos-- )
|
|
265 |
{
|
|
266 |
obj = iThumbnailRequestArray[pos];
|
|
267 |
|
|
268 |
if( obj.iThumbnailRequestId == KZero )
|
|
269 |
{
|
|
270 |
iThumbnailRequestArray.Remove(pos);
|
|
271 |
iThumbnailRequestArray.Compress();
|
|
272 |
|
|
273 |
|
|
274 |
obj.iObserver->ThumbnailReady(KErrAlreadyExists ,*obj.iThumbnailPath,obj.iTransactionId);
|
|
275 |
|
|
276 |
// Deleting the instance of ThumbanilRequestInfo
|
|
277 |
// We need to delete only iThumbnailPath and need to make iObserver as NULL
|
|
278 |
obj.iObserver = NULL;
|
|
279 |
if(obj.iThumbnailPath)
|
|
280 |
{
|
|
281 |
delete obj.iThumbnailPath;
|
|
282 |
}
|
|
283 |
|
|
284 |
}
|
|
285 |
}
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
}
|
|
290 |
// -----------------------------------------------------------------------------
|
|
291 |
// CThumbnailObserver::DoCancel
|
|
292 |
//
|
|
293 |
// -----------------------------------------------------------------------------
|
|
294 |
void CThumbnailObserver::DoCancel()
|
|
295 |
{
|
|
296 |
|
|
297 |
}
|