|
1 /* |
|
2 * Copyright (c) 2002-2006 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 * Implements assign ringing tone provider. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbkAiwCmdAssignProvider.h" |
|
22 |
|
23 #include <AiwMenu.h> |
|
24 #include <AiwCommon.h> |
|
25 #include <AiwCommon.hrh> |
|
26 #include <barsread.h> |
|
27 #include <PbkAiwProvidersRes.rsg> |
|
28 #include <Phonebook.rsg> |
|
29 #include <CPbkContactEngine.h> |
|
30 #include <AknNoteWrappers.h> |
|
31 #include <CPbkMultipleEntryFetchDlg.h> |
|
32 #include "CPbkAssignRingingToneCmd.h" |
|
33 #include "CPbkAssignImageCmd.h" |
|
34 #include "PbkDataCaging.hrh" |
|
35 #include "PbkAiwProviders.hrh" |
|
36 #include "PbkProviderUtils.h" |
|
37 #include <CPbkDrmManager.h> |
|
38 |
|
39 #include <stringloader.h> |
|
40 #include <centralrepository.h> |
|
41 #include <ProfileEngineDomainCRKeys.h> //KProEngRingingToneMaxSize |
|
42 #include <pbkdebug.h> |
|
43 |
|
44 |
|
45 /// Unnamed namespace for local definitions |
|
46 namespace { |
|
47 |
|
48 _LIT(KViewResFileName, "PbkView.rsc"); |
|
49 |
|
50 const TInt Kkilo = 1024; |
|
51 |
|
52 } |
|
53 |
|
54 // ================= MEMBER FUNCTIONS ======================= |
|
55 |
|
56 CPbkAiwCmdAssignProvider* CPbkAiwCmdAssignProvider::NewL() |
|
57 { |
|
58 CPbkAiwCmdAssignProvider* self = |
|
59 new(ELeave) CPbkAiwCmdAssignProvider; |
|
60 CleanupStack::PushL(self); |
|
61 self->ConstructL(); |
|
62 CleanupStack::Pop(self); |
|
63 return self; |
|
64 } |
|
65 |
|
66 CPbkAiwCmdAssignProvider::CPbkAiwCmdAssignProvider() |
|
67 : iViewResourceFile(*CCoeEnv::Static()) |
|
68 { |
|
69 } |
|
70 |
|
71 |
|
72 void CPbkAiwCmdAssignProvider::ConstructL() |
|
73 { |
|
74 PBK_DEBUG_PRINT(PBK_DEBUG_STRING |
|
75 ("CPbkAiwCmdAssignProvider::ConstructL start")); |
|
76 |
|
77 BaseConstructL(); |
|
78 |
|
79 _LIT(KSeparator, "\\"); |
|
80 |
|
81 { |
|
82 TFileName fileName; |
|
83 fileName.Copy(KPbkRomFileDrive); |
|
84 fileName.Append(KDC_RESOURCE_FILES_DIR); |
|
85 fileName.Append(KSeparator); |
|
86 fileName.Append(KViewResFileName); |
|
87 iViewResourceFile.OpenL(fileName); |
|
88 } // TFileName goes out of scope |
|
89 |
|
90 iDrmManager = CPbkDrmManager::NewL(); |
|
91 GetMaxToneFileSizeL( iToneFileSizeLimitKB ); |
|
92 |
|
93 PBK_DEBUG_PRINT(PBK_DEBUG_STRING |
|
94 ("CPbkAiwCmdAssignProvider::ConstructL end")); |
|
95 } |
|
96 |
|
97 |
|
98 CPbkAiwCmdAssignProvider::~CPbkAiwCmdAssignProvider() |
|
99 { |
|
100 delete iDrmManager; |
|
101 iViewResourceFile.Close(); |
|
102 } |
|
103 |
|
104 void CPbkAiwCmdAssignProvider::HandleServiceCmdL |
|
105 (const TInt& aCmdId, const CAiwGenericParamList& aInParamList, |
|
106 CAiwGenericParamList& /*aOutParamList*/, TUint /*aCmdOptions*/, |
|
107 const MAiwNotifyCallback* aCallback) |
|
108 { |
|
109 if ((aCmdId == EPbkAiwCmdAssignThumbnail) || |
|
110 (aCmdId == EPbkAiwCmdAssignRingingTone) || |
|
111 (aCmdId == EPbkAiwCmdAssignCallImage)) |
|
112 { |
|
113 // Retrieve filename and file MIME type from AIW param list |
|
114 TPtrC fileName = PbkProviderUtils::GetAiwParamAsDescriptor |
|
115 (aInParamList, EGenericParamFile); |
|
116 |
|
117 TPtrC mimeTypeString = PbkProviderUtils::GetAiwParamAsDescriptor |
|
118 (aInParamList, EGenericParamMIMEType); |
|
119 |
|
120 // Leave, if there were not given all the required parameters |
|
121 if ((fileName == KNullDesC) || (mimeTypeString == KNullDesC)) |
|
122 { |
|
123 User::Leave(KErrArgument); |
|
124 } |
|
125 |
|
126 VerifyMimeTypeL(aCmdId, mimeTypeString); |
|
127 |
|
128 TInt rtSizeLimitError = KErrNone; |
|
129 |
|
130 // Ringing tone size limit check returns KErrNone or KErrTooBig |
|
131 if (aCmdId == EPbkAiwCmdAssignRingingTone) |
|
132 { |
|
133 rtSizeLimitError = CheckFileSizeLimit( fileName ); |
|
134 } |
|
135 |
|
136 if ( rtSizeLimitError == KErrNone ) |
|
137 { |
|
138 // Perform the operation |
|
139 CmdAssignL(aCmdId, fileName, aInParamList, aCallback); |
|
140 } |
|
141 } |
|
142 } |
|
143 |
|
144 |
|
145 void CPbkAiwCmdAssignProvider::InitializeMenuPaneL |
|
146 (CAiwMenuPane& aMenuPane, TInt aIndex, |
|
147 TInt /*aCascadeId*/, const CAiwGenericParamList& aInParamList) |
|
148 { |
|
149 // Get MIME type string from parameters |
|
150 TPtrC mimeTypeString = PbkProviderUtils::GetAiwParamAsDescriptor |
|
151 (aInParamList, EGenericParamMIMEType); |
|
152 |
|
153 TPtrC fileNameString = PbkProviderUtils::GetAiwParamAsDescriptor |
|
154 (aInParamList, EGenericParamFile); |
|
155 |
|
156 if ((mimeTypeString.Length() > 0) && (fileNameString.Length() > 0)) |
|
157 { |
|
158 // Map the MIME type |
|
159 TInt mimeType = PbkProviderUtils::MapMimeTypeL(mimeTypeString); |
|
160 |
|
161 // Create the appropriate menu based on received MIME type |
|
162 if (mimeType != EPbkMimeTypeNotSupported) |
|
163 { |
|
164 TInt menuResId; |
|
165 if (mimeType == EPbkMimeTypeImage) |
|
166 { |
|
167 menuResId = R_AIW_ASSIGN_IMAGE_MENU; |
|
168 } |
|
169 else |
|
170 { |
|
171 menuResId = R_AIW_ASSIGN_TONE_MENU; |
|
172 } |
|
173 TResourceReader reader; |
|
174 CCoeEnv::Static()->CreateResourceReaderLC(reader, menuResId); |
|
175 aMenuPane.AddMenuItemsL(reader, KAiwCmdAssign, aIndex); |
|
176 CleanupStack::PopAndDestroy(); // reader |
|
177 } |
|
178 } |
|
179 } |
|
180 |
|
181 |
|
182 void CPbkAiwCmdAssignProvider::HandleMenuCmdL |
|
183 (TInt aMenuCmdId, const CAiwGenericParamList& aInParamList, |
|
184 CAiwGenericParamList& aOutParamList, TUint aCmdOptions, |
|
185 const MAiwNotifyCallback* aCallback) |
|
186 { |
|
187 // Route to HandleServiceCmdL |
|
188 HandleServiceCmdL(aMenuCmdId, aInParamList, |
|
189 aOutParamList, aCmdOptions, aCallback); |
|
190 } |
|
191 |
|
192 |
|
193 void CPbkAiwCmdAssignProvider::CmdAssignL |
|
194 (TInt aMenuCmdId, const TDesC& aFileName, |
|
195 const CAiwGenericParamList& aInParamList, |
|
196 const MAiwNotifyCallback* aCallback) |
|
197 { |
|
198 if ( aMenuCmdId == EPbkAiwCmdAssignRingingTone && |
|
199 iDrmManager->IsRingingToneProtectedL( aFileName ) ) |
|
200 { |
|
201 return; |
|
202 } |
|
203 else if ( aMenuCmdId == EPbkAiwCmdAssignThumbnail && |
|
204 iDrmManager->IsThumbnailProtectedL( aFileName ) ) |
|
205 { |
|
206 return; |
|
207 } |
|
208 |
|
209 SaveStatusPaneL(); |
|
210 |
|
211 CContactViewBase& allContactsView = iEngine->AllContactsView(); |
|
212 |
|
213 CPbkMultipleEntryFetchDlg::TParams params; |
|
214 params.iContactView = &allContactsView; |
|
215 |
|
216 // Cope with the design problems of AIW framework |
|
217 MAiwNotifyCallback* nonConstCallback = |
|
218 const_cast<MAiwNotifyCallback*> (aCallback); |
|
219 |
|
220 CPbkMultipleEntryFetchDlg* fetchDlg = CPbkMultipleEntryFetchDlg::NewL |
|
221 (params, *iEngine); |
|
222 const TInt res = fetchDlg->ExecuteLD(); |
|
223 if (res) |
|
224 { |
|
225 CleanupStack::PushL(params); |
|
226 |
|
227 switch (aMenuCmdId) |
|
228 { |
|
229 case EPbkAiwCmdAssignThumbnail: |
|
230 { |
|
231 CPbkAssignImageCmd* cmd = |
|
232 CPbkAssignImageCmd::NewL( |
|
233 aFileName, |
|
234 params.iMarkedEntries, |
|
235 EPbkFieldIdThumbnailImage, |
|
236 *iEngine, |
|
237 aInParamList, |
|
238 nonConstCallback); |
|
239 AddAndExecuteCommandL(cmd); |
|
240 CleanupStack::Pop(); // params, ownership was taken above |
|
241 break; |
|
242 } |
|
243 |
|
244 case EPbkAiwCmdAssignRingingTone: |
|
245 { |
|
246 CPbkAssignRingingToneCmd* cmd = |
|
247 CPbkAssignRingingToneCmd::NewL( |
|
248 aFileName, |
|
249 params.iMarkedEntries, |
|
250 *iEngine, |
|
251 aInParamList, |
|
252 nonConstCallback); |
|
253 AddAndExecuteCommandL(cmd); |
|
254 CleanupStack::Pop(); // params, ownership was taken above |
|
255 break; |
|
256 } |
|
257 |
|
258 default: |
|
259 { |
|
260 // Unsupported MIME type somehow slipped through, |
|
261 // ignore it |
|
262 CleanupStack::PopAndDestroy(); // params |
|
263 break; |
|
264 } |
|
265 } |
|
266 } |
|
267 else |
|
268 { |
|
269 if (aCallback) |
|
270 { |
|
271 // Cope with the design errors of AIW framework, it declares |
|
272 // the event param list is optional, but still takes it as |
|
273 //a reference |
|
274 CAiwGenericParamList* eventParamList = NULL; |
|
275 nonConstCallback->HandleNotifyL( |
|
276 KAiwCmdAssign, |
|
277 KAiwEventCanceled, |
|
278 *eventParamList, |
|
279 aInParamList); |
|
280 } |
|
281 } |
|
282 |
|
283 RestoreStatusPaneL(); |
|
284 } |
|
285 |
|
286 void CPbkAiwCmdAssignProvider::VerifyMimeTypeL |
|
287 (TInt aMenuCmdId, const TDesC& aMimeTypeString) |
|
288 { |
|
289 // Map the MIME type |
|
290 TInt mimeType = PbkProviderUtils::MapMimeTypeL(aMimeTypeString); |
|
291 |
|
292 // Verify MIME type |
|
293 if (mimeType == EPbkMimeTypeImage) |
|
294 { |
|
295 if (aMenuCmdId == EPbkAiwCmdAssignRingingTone) |
|
296 { |
|
297 User::Leave(KErrArgument); |
|
298 } |
|
299 } |
|
300 else if (mimeType == EPbkMimeTypeAudio) |
|
301 { |
|
302 if (aMenuCmdId != EPbkAiwCmdAssignRingingTone) |
|
303 { |
|
304 User::Leave(KErrArgument); |
|
305 } |
|
306 } |
|
307 else if (mimeType == EPbkMimeTypeRingingTone) |
|
308 { |
|
309 if (aMenuCmdId != EPbkAiwCmdAssignRingingTone) |
|
310 { |
|
311 User::Leave(KErrArgument); |
|
312 } |
|
313 } |
|
314 |
|
315 #ifdef RD_VIDEO_AS_RINGING_TONE |
|
316 |
|
317 else if (mimeType == EPbkMimeTypeVideo) |
|
318 { |
|
319 if (aMenuCmdId != EPbkAiwCmdAssignRingingTone) |
|
320 { |
|
321 User::Leave(KErrArgument); |
|
322 } |
|
323 } |
|
324 #endif // RD_VIDEO_AS_RINGING_TONE |
|
325 |
|
326 else |
|
327 { |
|
328 User::Leave(KErrArgument); |
|
329 } |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // CPbkAiwCmdAssignProvider::CheckFileSizeLimit |
|
334 // ----------------------------------------------------------------------------- |
|
335 // |
|
336 TInt CPbkAiwCmdAssignProvider::CheckFileSizeLimit( const TDesC& aFileName ) |
|
337 { |
|
338 TInt error = KErrNone; |
|
339 |
|
340 if ( iToneFileSizeLimitKB ) |
|
341 { |
|
342 if ( CheckToneFileSize( aFileName, iToneFileSizeLimitKB) != KErrNone ) |
|
343 { |
|
344 TRAP_IGNORE( |
|
345 ShowSizeErrorNoteL( iToneFileSizeLimitKB )); |
|
346 error = KErrTooBig; |
|
347 } |
|
348 } |
|
349 |
|
350 return error; |
|
351 } |
|
352 |
|
353 // ----------------------------------------------------------------------------- |
|
354 // CPbkAiwCmdAssignProvider::GetMaxToneFileSizeL |
|
355 // ----------------------------------------------------------------------------- |
|
356 // |
|
357 void CPbkAiwCmdAssignProvider::GetMaxToneFileSizeL( TInt& aMaxSizeKB ) const |
|
358 { |
|
359 CRepository* cenrep = CRepository::NewL( KCRUidProfileEngine ); |
|
360 CleanupStack::PushL( cenrep ); |
|
361 TInt error = cenrep->Get( KProEngRingingToneMaxSize, aMaxSizeKB ); |
|
362 CleanupStack::PopAndDestroy( cenrep ); |
|
363 if ( error != KErrNone ) |
|
364 { |
|
365 aMaxSizeKB = 0; |
|
366 } |
|
367 if ( aMaxSizeKB < 0 ) |
|
368 { |
|
369 aMaxSizeKB = 0; |
|
370 } |
|
371 } |
|
372 |
|
373 // ----------------------------------------------------------------------------- |
|
374 // CPbkAiwCmdAssignProvider::CheckToneFileSize |
|
375 // ----------------------------------------------------------------------------- |
|
376 // |
|
377 TInt CPbkAiwCmdAssignProvider::CheckToneFileSize( const TDesC& aFile, TInt aSizeLimitKB ) |
|
378 { |
|
379 // Get file size |
|
380 TInt size = 0; |
|
381 TInt error = KErrNone; |
|
382 RFs fs; |
|
383 error = fs.Connect(); |
|
384 if ( !error ) |
|
385 { |
|
386 TEntry entry; |
|
387 error = fs.Entry( aFile, entry ); |
|
388 if ( !error ) |
|
389 { |
|
390 size = entry.iSize; |
|
391 } |
|
392 fs.Close(); |
|
393 } |
|
394 |
|
395 // Note: if file size can't be determined, the check fails. |
|
396 aSizeLimitKB *= Kkilo; |
|
397 if ( aSizeLimitKB && size > aSizeLimitKB ) |
|
398 { |
|
399 error = KErrTooBig; |
|
400 } |
|
401 |
|
402 return error; |
|
403 } |
|
404 |
|
405 // ----------------------------------------------------------------------------- |
|
406 // CPbkAiwCmdAssignProvider::ShowSizeErrorNoteL |
|
407 // ----------------------------------------------------------------------------- |
|
408 // |
|
409 void CPbkAiwCmdAssignProvider::ShowSizeErrorNoteL( TInt aSizeLimitKB ) const |
|
410 { |
|
411 HBufC* errorText = StringLoader::LoadLC( R_PROFILE_TEXT_TONE_MAXSIZE_ERROR, aSizeLimitKB ); |
|
412 CAknInformationNote* note = new( ELeave ) CAknInformationNote( ETrue ); |
|
413 note->ExecuteLD( *errorText ); |
|
414 |
|
415 CleanupStack::PopAndDestroy( errorText ); |
|
416 } |
|
417 |
|
418 // End of File |
|
419 |