|
1 /* |
|
2 * Copyright (c) 2002-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 "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 * Set image command event handling class. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbk2SetImageCmd.h" |
|
22 |
|
23 // Phonebook 2 |
|
24 #include "CPbk2ImageManager.h" |
|
25 #include "CPbk2DrmManager.h" |
|
26 #include "Pbk2DataCaging.hrh" |
|
27 #include "Pbk2PresentationUtils.h" |
|
28 #include <Pbk2Commands.rsg> |
|
29 #include <Pbk2CommonUi.rsg> |
|
30 #include <MPbk2CommandObserver.h> |
|
31 #include <RPbk2LocalizedResourceFile.h> |
|
32 #include <CPbk2DriveSpaceCheck.h> |
|
33 #include <CPbk2AppUiBase.h> |
|
34 |
|
35 // Virtual Phonebook |
|
36 #include <MVPbkStoreContact.h> |
|
37 #include <MVPbkFieldType.h> |
|
38 #include <MVPbkContactFieldTextData.h> |
|
39 |
|
40 // System includes |
|
41 #include <AknWaitDialog.h> |
|
42 #include <aknnotewrappers.h> |
|
43 #include <StringLoader.h> |
|
44 #include <MGFetch.h> |
|
45 #include <aknnavi.h> |
|
46 #include <aknnavide.h> |
|
47 |
|
48 // Debugging headers |
|
49 #include <Pbk2Debug.h> |
|
50 |
|
51 /// Unnamed namespace for local definitons |
|
52 namespace { |
|
53 |
|
54 #ifdef _DEBUG |
|
55 |
|
56 enum TPanicCode |
|
57 { |
|
58 EPanicPreCond_Pbk2ImageSetComplete, |
|
59 EPanicPreCond_Pbk2ImageSetFailed, |
|
60 EPanicPreCond_SetImageRefL |
|
61 }; |
|
62 |
|
63 void Panic(TInt aReason) |
|
64 { |
|
65 _LIT(KPanicText, "CPbk2SetImageCmd"); |
|
66 User::Panic(KPanicText, aReason); |
|
67 } |
|
68 #endif // _DEBUG |
|
69 |
|
70 } /// namespace |
|
71 |
|
72 |
|
73 // ================= MEMBER FUNCTIONS ======================= |
|
74 |
|
75 // -------------------------------------------------------------------------- |
|
76 // CPbk2SetImageCmd::CPbk2SetImageCmd |
|
77 // -------------------------------------------------------------------------- |
|
78 // |
|
79 CPbk2SetImageCmd::CPbk2SetImageCmd( |
|
80 MPbk2ContactUiControl& aUiControl ) : |
|
81 CPbk2ImageCmdBase( aUiControl ) |
|
82 { |
|
83 } |
|
84 |
|
85 // -------------------------------------------------------------------------- |
|
86 // CPbk2SetImageCmd::ConstructL |
|
87 // -------------------------------------------------------------------------- |
|
88 // |
|
89 void CPbk2SetImageCmd::ConstructL() |
|
90 { |
|
91 CPbk2ImageCmdBase::BaseConstructL(); |
|
92 CPbk2DriveSpaceCheck* driveSpaceCheck = CPbk2DriveSpaceCheck::NewL |
|
93 ( CCoeEnv::Static()->FsSession() ); |
|
94 CleanupStack::PushL( driveSpaceCheck ); |
|
95 // check FFS situation |
|
96 driveSpaceCheck->DriveSpaceCheckL(); |
|
97 CleanupStack::PopAndDestroy( driveSpaceCheck ); |
|
98 iDrmManager = CPbk2DrmManager::NewL(); |
|
99 } |
|
100 |
|
101 // -------------------------------------------------------------------------- |
|
102 // CPbk2SetImageCmd::NewL |
|
103 // -------------------------------------------------------------------------- |
|
104 // |
|
105 CPbk2SetImageCmd* CPbk2SetImageCmd::NewL( |
|
106 MPbk2ContactUiControl& aUiControl ) |
|
107 { |
|
108 CPbk2SetImageCmd* self = |
|
109 new (ELeave) CPbk2SetImageCmd( aUiControl ); |
|
110 CleanupStack::PushL( self ); |
|
111 self->ConstructL(); |
|
112 CleanupStack::Pop( self ); |
|
113 return self; |
|
114 } |
|
115 |
|
116 // -------------------------------------------------------------------------- |
|
117 // CPbk2SetImageCmd::~CPbk2SetImageCmd |
|
118 // -------------------------------------------------------------------------- |
|
119 // |
|
120 CPbk2SetImageCmd::~CPbk2SetImageCmd() |
|
121 { |
|
122 delete iDrmManager; |
|
123 delete iImageOperation; |
|
124 delete iWaitNote; |
|
125 } |
|
126 |
|
127 // -------------------------------------------------------------------------- |
|
128 // CPbk2SetImageCmd::ExecuteCommandL |
|
129 // -------------------------------------------------------------------------- |
|
130 // |
|
131 TBool CPbk2SetImageCmd::ExecuteCommandL() |
|
132 { |
|
133 TBool result = EFalse; |
|
134 Cancel(); |
|
135 |
|
136 // fetch image from media gallery |
|
137 CDesCArray* selectedFile = new(ELeave) CDesCArrayFlat( 1 ); |
|
138 CleanupStack::PushL( selectedFile ); |
|
139 TBool res( EFalse ); |
|
140 res = MGFetchL( *selectedFile, EImageFile, EFalse, this ); |
|
141 |
|
142 if ( res && selectedFile->Count() > 0 ) |
|
143 { |
|
144 CAknWaitDialog* waitNote = |
|
145 new(ELeave) CAknWaitDialog( |
|
146 reinterpret_cast<CEikDialog**>( &iWaitNote ), ETrue ); |
|
147 waitNote->ExecuteLD( R_QTN_GEN_NOTE_FETCHING ); |
|
148 CleanupStack::PushL( waitNote ); |
|
149 |
|
150 TPtrC fileName = (*selectedFile)[0]; |
|
151 |
|
152 // store reference to image field |
|
153 SetImageRefL( fileName ); |
|
154 |
|
155 // write data to thumbnail field |
|
156 iImageOperation = |
|
157 iImageManager->SetImageAsyncL( |
|
158 *iStoreContact, *iThumbnailFieldType, *this, fileName ); |
|
159 |
|
160 CleanupStack::Pop( waitNote ); |
|
161 iWaitNote = waitNote; |
|
162 result = ETrue; |
|
163 } |
|
164 |
|
165 CleanupStack::PopAndDestroy( selectedFile ); |
|
166 return result; |
|
167 } |
|
168 |
|
169 // -------------------------------------------------------------------------- |
|
170 // CPbk2SetImageCmd::Pbk2ImageSetComplete |
|
171 // -------------------------------------------------------------------------- |
|
172 // |
|
173 void CPbk2SetImageCmd::Pbk2ImageSetComplete |
|
174 ( MPbk2ImageOperation& PBK2_DEBUG_ONLY( aOperation ) ) |
|
175 { |
|
176 __ASSERT_DEBUG(&aOperation == iImageOperation, |
|
177 Panic(EPanicPreCond_Pbk2ImageSetComplete)); |
|
178 |
|
179 delete iImageOperation; |
|
180 iImageOperation = NULL; |
|
181 |
|
182 DismissWaitNote(); |
|
183 |
|
184 TRAPD( error, iStoreContact->CommitL( *this ) ); |
|
185 if ( error != KErrNone ) |
|
186 { |
|
187 CCoeEnv::Static()->HandleError( error ); |
|
188 } |
|
189 } |
|
190 |
|
191 // -------------------------------------------------------------------------- |
|
192 // CPbk2SetImageCmd::Pbk2ImageSetFailed |
|
193 // -------------------------------------------------------------------------- |
|
194 // |
|
195 void CPbk2SetImageCmd::Pbk2ImageSetFailed |
|
196 ( MPbk2ImageOperation& PBK2_DEBUG_ONLY( aOperation ), TInt aError ) |
|
197 { |
|
198 __ASSERT_DEBUG( &aOperation == iImageOperation, |
|
199 Panic( EPanicPreCond_Pbk2ImageSetFailed ) ); |
|
200 |
|
201 delete iImageOperation; |
|
202 iImageOperation = NULL; |
|
203 |
|
204 DismissWaitNote(); |
|
205 |
|
206 ProcessDismissed( aError ); |
|
207 } |
|
208 |
|
209 // -------------------------------------------------------------------------- |
|
210 // CPbk2SetImageCmd::DismissWaitNote |
|
211 // -------------------------------------------------------------------------- |
|
212 // |
|
213 void CPbk2SetImageCmd::DismissWaitNote() |
|
214 { |
|
215 // Dismiss the wait note |
|
216 if ( iWaitNote ) |
|
217 { |
|
218 TRAPD( err, iWaitNote->ProcessFinishedL() ); |
|
219 if ( err != KErrNone ) |
|
220 { |
|
221 delete iWaitNote; |
|
222 } |
|
223 iWaitNote = NULL; |
|
224 } |
|
225 } |
|
226 |
|
227 // -------------------------------------------------------------------------- |
|
228 // CPbk2SetImageCmd::VerifySelectionL |
|
229 // -------------------------------------------------------------------------- |
|
230 // |
|
231 TBool CPbk2SetImageCmd::VerifySelectionL |
|
232 (const MDesCArray* aSelectedFiles) |
|
233 { |
|
234 TBool result = EFalse; |
|
235 if ( aSelectedFiles && aSelectedFiles->MdcaCount() > 0 ) |
|
236 { |
|
237 // DRM for phonebook image fetch |
|
238 TPtrC fileName = aSelectedFiles->MdcaPoint( 0 ); |
|
239 TBool isProtected( ETrue ); |
|
240 User::LeaveIfError( |
|
241 iDrmManager->IsProtectedFile( fileName, isProtected ) ); |
|
242 if ( isProtected ) |
|
243 { |
|
244 RPbk2LocalizedResourceFile resFile( *CCoeEnv::Static() ); |
|
245 resFile.OpenLC( |
|
246 KPbk2RomFileDrive, |
|
247 KDC_RESOURCE_FILES_DIR, |
|
248 Pbk2PresentationUtils::PresentationResourceFile() ); |
|
249 // show user copyright note |
|
250 HBufC* prompt = |
|
251 CCoeEnv::Static()->AllocReadResourceLC( R_PBK2_QTN_DRM_NOT_ALLOWED ); |
|
252 CAknInformationNote* dlg = new(ELeave) CAknInformationNote( ETrue ); |
|
253 dlg->ExecuteLD( *prompt ); |
|
254 CleanupStack::PopAndDestroy( 2 ); // resFile, prompt |
|
255 } |
|
256 else |
|
257 { |
|
258 result = ETrue; |
|
259 } |
|
260 } |
|
261 |
|
262 return result; |
|
263 } |
|
264 |
|
265 // -------------------------------------------------------------------------- |
|
266 // CPbk2SetImageCmd::Cancel |
|
267 // -------------------------------------------------------------------------- |
|
268 // |
|
269 void CPbk2SetImageCmd::Cancel() |
|
270 { |
|
271 delete iWaitNote; |
|
272 iWaitNote = NULL; |
|
273 delete iImageOperation; |
|
274 iImageOperation = NULL; |
|
275 } |
|
276 |
|
277 // -------------------------------------------------------------------------- |
|
278 // CPbk2SetImageCmd::SetImageRefL |
|
279 // -------------------------------------------------------------------------- |
|
280 // |
|
281 void CPbk2SetImageCmd::SetImageRefL(const TDesC& aFileName) |
|
282 { |
|
283 __ASSERT_DEBUG(iImageFieldType && iStoreContact, Panic(EPanicPreCond_SetImageRefL)); |
|
284 |
|
285 MVPbkStoreContactField* field = NULL; |
|
286 TInt fieldIndex = FindFieldIndex( *iImageFieldType ); |
|
287 |
|
288 if ( fieldIndex != KErrNotFound ) |
|
289 { |
|
290 // If filename has been set and the contact has the field |
|
291 // field should be updated. |
|
292 field = &iStoreContact->Fields().FieldAt( fieldIndex ); |
|
293 MVPbkContactFieldTextData::Cast( field->FieldData() ). |
|
294 SetTextL( aFileName ); |
|
295 } |
|
296 else if ( aFileName.Length() > 0 ) |
|
297 { |
|
298 // Contact does not have the field, so create new one. |
|
299 field = iStoreContact->CreateFieldLC( *iImageFieldType ); |
|
300 MVPbkContactFieldTextData::Cast( field->FieldData() ). |
|
301 SetTextL( aFileName ); |
|
302 iStoreContact->AddFieldL( field ); |
|
303 CleanupStack::Pop(); // field |
|
304 } |
|
305 } |
|
306 |
|
307 TBool CPbk2SetImageCmd::MGFetchL( CDesCArray& aSelectedFiles, |
|
308 TMediaFileType aMediaType, |
|
309 TBool aMultiSelect, |
|
310 MMGFetchVerifier* aVerifier ) |
|
311 { |
|
312 CEikAppUi* pAppUi = CEikonEnv::Static()->EikAppUi(); |
|
313 CAknNavigationDecorator *pNaviDecorator = NULL; |
|
314 if ( pAppUi ) |
|
315 { |
|
316 CEikStatusPane* StatusPane = |
|
317 static_cast<CAknAppUi*>(pAppUi)->StatusPane(); |
|
318 TUid naviPaneUid = TUid::Uid( EEikStatusPaneUidNavi ); |
|
319 CAknNavigationControlContainer* naviPane = |
|
320 static_cast<CAknNavigationControlContainer*>( |
|
321 StatusPane->ControlL(naviPaneUid) ); |
|
322 pNaviDecorator = naviPane->Top(); |
|
323 if ( pNaviDecorator ) |
|
324 { |
|
325 pNaviDecorator->MakeVisible( EFalse ); // Hide navi pane |
|
326 pNaviDecorator->DrawNow(); |
|
327 } |
|
328 } |
|
329 |
|
330 TBool result( EFalse ); |
|
331 // run image fetch dialog |
|
332 TRAPD(error, result = MGFetch::RunL( aSelectedFiles, |
|
333 aMediaType, |
|
334 aMultiSelect, // multiselection |
|
335 aVerifier)); // provide MMGFetchVerifier interface to check DRM |
|
336 |
|
337 if ( pNaviDecorator ) |
|
338 { |
|
339 pNaviDecorator->MakeVisible( ETrue ); // Show again |
|
340 pNaviDecorator->DrawNow(); |
|
341 } |
|
342 User::LeaveIfError(error); |
|
343 |
|
344 return result; |
|
345 } |
|
346 |
|
347 // End of File |