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