|
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 * SetThumbnail command event handling class. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbk2SetThumbnailCmd.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 |
|
33 // Virtual Phonebook |
|
34 #include <MVPbkStoreContact.h> |
|
35 |
|
36 // System includes |
|
37 #include <AknWaitDialog.h> |
|
38 #include <aknnotewrappers.h> |
|
39 #include <StringLoader.h> |
|
40 #include <MGFetch.h> |
|
41 |
|
42 // Debugging headers |
|
43 #include <Pbk2Debug.h> |
|
44 |
|
45 /// Unnamed namespace for local definitons |
|
46 namespace { |
|
47 |
|
48 #ifdef _DEBUG |
|
49 |
|
50 enum TPanicCode |
|
51 { |
|
52 EPanicPreCond_Pbk2ThumbnailSetComplete, |
|
53 EPanicPreCond_Pbk2ThumbnailSetFailed |
|
54 }; |
|
55 |
|
56 void Panic(TInt aReason) |
|
57 { |
|
58 _LIT(KPanicText, "CPbk2SetThumbnailCmd"); |
|
59 User::Panic(KPanicText, aReason); |
|
60 } |
|
61 |
|
62 #endif // _DEBUG |
|
63 |
|
64 } /// namespace |
|
65 |
|
66 |
|
67 // ========================= MEMBER FUNCTIONS =============================== |
|
68 |
|
69 // -------------------------------------------------------------------------- |
|
70 // CPbk2SetThumbnailCmd::CPbk2SetThumbnailCmd |
|
71 // -------------------------------------------------------------------------- |
|
72 // |
|
73 CPbk2SetThumbnailCmd::CPbk2SetThumbnailCmd( |
|
74 MPbk2ContactUiControl& aUiControl ) : |
|
75 CPbk2ThumbnailCmdBase( aUiControl ) |
|
76 { |
|
77 } |
|
78 |
|
79 // -------------------------------------------------------------------------- |
|
80 // CPbk2SetThumbnailCmd::ConstructL |
|
81 // -------------------------------------------------------------------------- |
|
82 // |
|
83 void CPbk2SetThumbnailCmd::ConstructL() |
|
84 { |
|
85 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
86 ("CPbk2SetThumbnailCmd::ConstructL(0x%x), start"), this); |
|
87 |
|
88 CPbk2ThumbnailCmdBase::BaseConstructL(); |
|
89 |
|
90 iDrmManager = CPbk2DrmManager::NewL(); |
|
91 |
|
92 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
93 ("CPbk2SetThumbnailCmd::ConstructL(0x%x), end"), this); |
|
94 } |
|
95 |
|
96 // -------------------------------------------------------------------------- |
|
97 // CPbk2SetThumbnailCmd::NewL |
|
98 // -------------------------------------------------------------------------- |
|
99 // |
|
100 CPbk2SetThumbnailCmd* CPbk2SetThumbnailCmd::NewL( |
|
101 MPbk2ContactUiControl& aUiControl ) |
|
102 { |
|
103 CPbk2SetThumbnailCmd* self = |
|
104 new (ELeave) CPbk2SetThumbnailCmd( aUiControl ); |
|
105 CleanupStack::PushL( self ); |
|
106 self->ConstructL(); |
|
107 CleanupStack::Pop( self ); |
|
108 return self; |
|
109 } |
|
110 |
|
111 // -------------------------------------------------------------------------- |
|
112 // CPbk2SetThumbnailCmd::~CPbk2SetThumbnailCmd |
|
113 // -------------------------------------------------------------------------- |
|
114 // |
|
115 CPbk2SetThumbnailCmd::~CPbk2SetThumbnailCmd() |
|
116 { |
|
117 delete iDrmManager; |
|
118 delete iThumbOperation; |
|
119 delete iWaitNote; |
|
120 } |
|
121 |
|
122 // -------------------------------------------------------------------------- |
|
123 // CPbk2SetThumbnailCmd::ExecuteCommandL |
|
124 // -------------------------------------------------------------------------- |
|
125 // |
|
126 TBool CPbk2SetThumbnailCmd::ExecuteCommandL() |
|
127 { |
|
128 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
129 ("CPbk2SetThumbnailCmd::ExecuteCommandL(0x%x), start"), this); |
|
130 |
|
131 TBool result = EFalse; |
|
132 Cancel(); |
|
133 |
|
134 // fetch thumbnail from media gallery |
|
135 CDesCArray* selectedFile = new(ELeave) CDesCArrayFlat( 1 ); |
|
136 CleanupStack::PushL( selectedFile ); |
|
137 TBool res( EFalse ); |
|
138 res = MGFetch::RunL( *selectedFile, EImageFile, EFalse, this ); |
|
139 |
|
140 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
141 ("CPbk2SetThumbnailCmd::ExecuteCommandL(%d), MGFetch res"), TInt(res)); |
|
142 |
|
143 if ( res && selectedFile->Count() > 0 ) |
|
144 { |
|
145 CAknWaitDialog* waitNote = |
|
146 new(ELeave) CAknWaitDialog( |
|
147 reinterpret_cast<CEikDialog**>( &iWaitNote ) ); |
|
148 waitNote->ExecuteLD( R_QTN_GEN_NOTE_FETCHING ); |
|
149 CleanupStack::PushL( waitNote ); |
|
150 |
|
151 TPtrC fileName = (*selectedFile)[0]; |
|
152 |
|
153 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
154 ("CPbk2SetThumbnailCmd::ExecuteCommandL(%S), fileName"), &fileName); |
|
155 |
|
156 iThumbOperation = |
|
157 iThumbnailManager->SetImageAsyncL( |
|
158 *iStoreContact, *iFieldType, *this, fileName ); |
|
159 |
|
160 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
161 ("CPbk2SetThumbnailCmd::ExecuteCommandL(0x%x), iThumbOperation"), |
|
162 iThumbOperation); |
|
163 |
|
164 CleanupStack::Pop( waitNote ); |
|
165 iWaitNote = waitNote; |
|
166 result = ETrue; |
|
167 } |
|
168 CleanupStack::PopAndDestroy( selectedFile ); |
|
169 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
170 ("CPbk2SetThumbnailCmd::ExecuteCommandL(0x%x), end"), this); |
|
171 return result; |
|
172 } |
|
173 |
|
174 // -------------------------------------------------------------------------- |
|
175 // CPbk2SetThumbnailCmd::Pbk2ImageSetComplete |
|
176 // -------------------------------------------------------------------------- |
|
177 // |
|
178 void CPbk2SetThumbnailCmd::Pbk2ImageSetComplete( |
|
179 MPbk2ImageOperation& PBK2_DEBUG_ONLY( aOperation ) ) |
|
180 { |
|
181 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
182 ("CPbk2SetThumbnailCmd::Pbk2ImageSetComplete(0x%x), start"), this); |
|
183 |
|
184 __ASSERT_DEBUG(&aOperation == iThumbOperation, |
|
185 Panic(EPanicPreCond_Pbk2ThumbnailSetComplete)); |
|
186 |
|
187 delete iThumbOperation; |
|
188 iThumbOperation = NULL; |
|
189 |
|
190 DismissWaitNote(); |
|
191 |
|
192 TRAPD( error, iStoreContact->CommitL( *this ) ); |
|
193 if ( error != KErrNone ) |
|
194 { |
|
195 CCoeEnv::Static()->HandleError( error ); |
|
196 } |
|
197 |
|
198 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
199 ("CPbk2SetThumbnailCmd::Pbk2ImageSetComplete(0x%x), end"), this); |
|
200 } |
|
201 |
|
202 // -------------------------------------------------------------------------- |
|
203 // CPbk2SetThumbnailCmd::Pbk2ImageSetFailed |
|
204 // -------------------------------------------------------------------------- |
|
205 // |
|
206 void CPbk2SetThumbnailCmd::Pbk2ImageSetFailed |
|
207 ( MPbk2ImageOperation& PBK2_DEBUG_ONLY( aOperation ), TInt aError ) |
|
208 { |
|
209 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
210 ("CPbk2SetThumbnailCmd::Pbk2ImageSetFailed(0x%x), aError"), this); |
|
211 |
|
212 __ASSERT_DEBUG(&aOperation == iThumbOperation, |
|
213 Panic(EPanicPreCond_Pbk2ThumbnailSetFailed)); |
|
214 |
|
215 delete iThumbOperation; |
|
216 iThumbOperation = NULL; |
|
217 |
|
218 DismissWaitNote(); |
|
219 |
|
220 ProcessDismissed( aError ); |
|
221 |
|
222 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
223 ("CPbk2SetThumbnailCmd::Pbk2ImageSetFailed(0x%x), end"), this); |
|
224 } |
|
225 |
|
226 // -------------------------------------------------------------------------- |
|
227 // CPbk2SetThumbnailCmd::DismissWaitNote |
|
228 // -------------------------------------------------------------------------- |
|
229 // |
|
230 void CPbk2SetThumbnailCmd::DismissWaitNote() |
|
231 { |
|
232 // Dismiss the wait note |
|
233 TRAPD( err, iWaitNote->ProcessFinishedL() ); |
|
234 if ( err != KErrNone ) |
|
235 { |
|
236 delete iWaitNote; |
|
237 iWaitNote = NULL; |
|
238 } |
|
239 } |
|
240 |
|
241 // -------------------------------------------------------------------------- |
|
242 // CPbk2SetThumbnailCmd::VerifySelectionL |
|
243 // -------------------------------------------------------------------------- |
|
244 // |
|
245 TBool CPbk2SetThumbnailCmd::VerifySelectionL |
|
246 (const MDesCArray* aSelectedFiles) |
|
247 { |
|
248 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
249 ("CPbk2SetThumbnailCmd::VerifySelectionL(0x%x), start"), this); |
|
250 |
|
251 TBool result = EFalse; |
|
252 if ( aSelectedFiles && aSelectedFiles->MdcaCount() > 0 ) |
|
253 { |
|
254 // DRM for phonebook thumbnail fetch |
|
255 TPtrC fileName = aSelectedFiles->MdcaPoint( 0 ); |
|
256 TBool IsProtected( ETrue ); |
|
257 User::LeaveIfError( |
|
258 iDrmManager->IsProtectedFile( fileName, IsProtected ) ); |
|
259 if ( IsProtected ) |
|
260 { |
|
261 RPbk2LocalizedResourceFile resFile( *CCoeEnv::Static() ); |
|
262 resFile.OpenLC( |
|
263 KPbk2RomFileDrive, |
|
264 KDC_RESOURCE_FILES_DIR, |
|
265 Pbk2PresentationUtils::PresentationResourceFile() ); |
|
266 // show user copyright note |
|
267 HBufC* prompt = |
|
268 CCoeEnv::Static()->AllocReadResourceLC( R_PBK2_QTN_DRM_NOT_ALLOWED ); |
|
269 CAknInformationNote* dlg = new(ELeave) CAknInformationNote( ETrue ); |
|
270 dlg->ExecuteLD( *prompt ); |
|
271 CleanupStack::PopAndDestroy( 2 ); // resFile, prompt |
|
272 } |
|
273 else |
|
274 { |
|
275 result = ETrue; |
|
276 } |
|
277 } |
|
278 |
|
279 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
280 ("CPbk2SetThumbnailCmd::VerifySelectionL(0x%x), end"), this); |
|
281 |
|
282 return result; |
|
283 } |
|
284 |
|
285 // -------------------------------------------------------------------------- |
|
286 // CPbk2SetThumbnailCmd::Cancel |
|
287 // -------------------------------------------------------------------------- |
|
288 // |
|
289 void CPbk2SetThumbnailCmd::Cancel() |
|
290 { |
|
291 delete iWaitNote; |
|
292 iWaitNote = NULL; |
|
293 delete iThumbOperation; |
|
294 iThumbOperation = NULL; |
|
295 } |
|
296 |
|
297 // End of File |