|
1 /* |
|
2 * Copyright (c) 2008-2009 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: Classes for thumbnail-related tasks. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 /** |
|
21 * @internal reviewed 31/07/2007 by Simon Brooks |
|
22 */ |
|
23 |
|
24 #include "glxtnthumbnailcreator.h" |
|
25 |
|
26 #include "glxpanic.h" |
|
27 #include "glxtnbackgroundgenerationtask.h" |
|
28 #include "glxtncleanuptask.h" |
|
29 #include "glxtndeletethumbnailstask.h" |
|
30 #include "glxtnfileutility.h" |
|
31 #include "glxtnfilteravailabletask.h" |
|
32 #include "glxtngeneratethumbnailtask.h" |
|
33 #include "glxtnquickthumbnailtask.h" |
|
34 #include "glxtntaskmanager.h" |
|
35 #include "glxtnthumbnailrequest.h" |
|
36 #include "glxtnzoomedimagetask.h" |
|
37 #include "mglxtnthumbnailcreatorclient.h" |
|
38 |
|
39 #include <glxtracer.h> |
|
40 #include <glxsettingsmodel.h> |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // InstanceL |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 EXPORT_C CGlxtnThumbnailCreator* CGlxtnThumbnailCreator::InstanceL() |
|
47 { |
|
48 TRACER("CGlxtnThumbnailCreator::InstanceL()"); |
|
49 CGlxtnThumbnailCreator* instance |
|
50 = reinterpret_cast<CGlxtnThumbnailCreator*>(Dll::Tls()); |
|
51 |
|
52 // Create instance if does not exist |
|
53 if ( !instance ) |
|
54 { |
|
55 instance = new (ELeave) CGlxtnThumbnailCreator(); |
|
56 CleanupStack::PushL(instance); |
|
57 instance->ConstructL(); |
|
58 CleanupStack::Pop(instance); |
|
59 |
|
60 Dll::SetTls(instance); |
|
61 } |
|
62 |
|
63 // Add user |
|
64 instance->iReferenceCount++; |
|
65 |
|
66 return instance; |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // Close |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 EXPORT_C void CGlxtnThumbnailCreator::Close(MGlxtnThumbnailStorage* aStorage) |
|
74 { |
|
75 TRACER("CGlxtnThumbnailCreator::Close()"); |
|
76 // Cancel any tasks using the client's storage |
|
77 if ( aStorage ) |
|
78 { |
|
79 iTaskManager->CancelTasks(aStorage); |
|
80 } |
|
81 |
|
82 __ASSERT_DEBUG(iReferenceCount > 0, Panic(EGlxPanicIllegalState)); |
|
83 iReferenceCount--; |
|
84 if ( iReferenceCount < 1 ) |
|
85 { |
|
86 Dll::SetTls(NULL); |
|
87 delete this; |
|
88 } |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // Constructor |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 CGlxtnThumbnailCreator::CGlxtnThumbnailCreator() |
|
96 { |
|
97 TRACER("CGlxtnThumbnailCreator::CGlxtnThumbnailCreator()"); |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // ConstructL |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 void CGlxtnThumbnailCreator::ConstructL() |
|
105 { |
|
106 TRACER("CGlxtnThumbnailCreator::ConstructL()"); |
|
107 iFileUtility = CGlxtnFileUtility::NewL(); |
|
108 iTaskManager = CGlxtnTaskManager::NewL(); |
|
109 iSettingsModel = CGlxSettingsModel::InstanceL(); |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // Destructor |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 CGlxtnThumbnailCreator::~CGlxtnThumbnailCreator() |
|
117 { |
|
118 TRACER("CGlxtnThumbnailCreator::~CGlxtnThumbnailCreator()"); |
|
119 delete iTaskManager; |
|
120 delete iFileUtility; |
|
121 if (iSettingsModel) |
|
122 { |
|
123 iSettingsModel->Close(); |
|
124 } |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // FetchThumbnailL |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 EXPORT_C void CGlxtnThumbnailCreator::FetchThumbnailL( |
|
132 const TGlxThumbnailRequest& aRequestInfo, |
|
133 MGlxtnThumbnailCreatorClient& aClient) |
|
134 { |
|
135 TRACER("void CGlxtnThumbnailCreator::FetchThumbnailL()"); |
|
136 // Create the task |
|
137 CGlxtnTask* task = NULL; |
|
138 |
|
139 if ( 0 == aRequestInfo.iBitmapHandle ) |
|
140 { |
|
141 task = CGlxtnBackgroundGenerationTask::NewL(aRequestInfo.iId, |
|
142 *iFileUtility, aClient, iSettingsModel->SupportedOrientations() ); |
|
143 } |
|
144 else if ( ( 0 == aRequestInfo.iSizeClass.iWidth) || ( 0 == aRequestInfo.iSizeClass.iHeight ) ) |
|
145 { |
|
146 User::Leave(KErrArgument); |
|
147 } |
|
148 else if ( !aRequestInfo.iCroppingRect.IsEmpty() ) |
|
149 { |
|
150 task = CGlxtnZoomedImageTask::NewL(aRequestInfo, |
|
151 *iFileUtility, aClient); |
|
152 } |
|
153 else if ( TGlxThumbnailRequest::EPrioritizeQuality == aRequestInfo.iPriorityMode ) |
|
154 { |
|
155 task = CGlxtnGenerateThumbnailTask::NewL(aRequestInfo, |
|
156 *iFileUtility, aClient); |
|
157 } |
|
158 else |
|
159 { |
|
160 task = CGlxtnQuickThumbnailTask::NewL(aRequestInfo, |
|
161 *iFileUtility, aClient); |
|
162 } |
|
163 |
|
164 iTaskManager->AddTaskL(task); // Takes ownership |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // DeleteThumbnailsL |
|
169 // Starts deleting all stored thumbnails for a given item. This will result |
|
170 // in a callback to MGlxtnThumbnailCreatorClient::ThumbnailDeletionComplete(). |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 EXPORT_C void CGlxtnThumbnailCreator::DeleteThumbnailsL( |
|
174 const TGlxMediaId& aItemId, MGlxtnThumbnailCreatorClient& aClient) |
|
175 { |
|
176 TRACER("void CGlxtnThumbnailCreator::DeleteThumbnailsL()"); |
|
177 iTaskManager->AddTaskL(CGlxtnDeleteThumbnailsTask::NewL(aItemId, aClient)); |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // FilterAvailableThumbnailsL |
|
182 // Starts the filtering of items for which a thumbnail is available from a |
|
183 // list of item IDs. This will result in a callback to |
|
184 // MGlxtnThumbnailCreatorClient::FilterAvailableComplete(). |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 EXPORT_C void CGlxtnThumbnailCreator::FilterAvailableThumbnailsL( |
|
188 const TArray<TGlxMediaId>& aItemArray, const TSize& aSize, |
|
189 MGlxtnThumbnailCreatorClient& aClient) |
|
190 { |
|
191 TRACER("void CGlxtnThumbnailCreator::FilterAvailableThumbnailsL()"); |
|
192 iTaskManager->AddTaskL(CGlxtnFilterAvailableTask::NewL(aItemArray, aSize, |
|
193 aClient)); |
|
194 } |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CleanupThumbnailsL |
|
198 // Starts the cleanup of obsolete thumbnails from storage. There is no |
|
199 // callback indicating completion of the request. |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 EXPORT_C void CGlxtnThumbnailCreator::CleanupThumbnailsL( |
|
203 MGlxtnThumbnailStorage* aStorage) |
|
204 { |
|
205 TRACER("void CGlxtnThumbnailCreator::CleanupThumbnailsL()"); |
|
206 iTaskManager->AddTaskL(CGlxtnCleanupTask::NewL(aStorage)); |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CancelRequest |
|
211 // Cancel any ongoing tasks for a given item. This ensures the TNC is not |
|
212 // locking the media file. |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 EXPORT_C void CGlxtnThumbnailCreator::CancelRequest(const TGlxMediaId& aItemId) |
|
216 { |
|
217 TRACER("void CGlxtnThumbnailCreator::CancelRequest()"); |
|
218 iTaskManager->CancelTasks(aItemId); |
|
219 } |