|
1 /* |
|
2 * Copyright (c) 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: Helper utility for Common UI |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <coeutils.h> |
|
22 #include <avkon.hrh> |
|
23 #include <avkon.rsg> |
|
24 #include <AknWaitDialog.h> |
|
25 #include <AknProgressDialog.h> |
|
26 #include <AknCommonDialogs.h> |
|
27 #include <CAknFileNamePromptDialog.h> |
|
28 #include <centralrepository.h> |
|
29 #include <AknsUtils.h> |
|
30 #include <AknIconArray.h> |
|
31 #include <barsread.h> |
|
32 #include <StringLoader.h> |
|
33 #include <AknUtils.h> |
|
34 #include <bautils.h> |
|
35 #include <eikapp.h> |
|
36 #include <cprofiletonehandler.h> |
|
37 #include <pathinfo.h> |
|
38 #ifdef RD_MULTIPLE_DRIVE |
|
39 #include <driveinfo.h> |
|
40 #endif // RD_MULTIPLE_DRIVE |
|
41 #include <MProfileEngine.h> |
|
42 #include <AknQueryDialog.h> |
|
43 #include <aknnotewrappers.h> |
|
44 #include <data_caging_path_literals.hrh> |
|
45 #include <caf/caferr.h> |
|
46 #include <sysutil.h> |
|
47 #include <textresolver.h> |
|
48 #include <aknnotewrappers.h> |
|
49 |
|
50 #include <mpxmedia.h> |
|
51 #include <mpxmediageneraldefs.h> |
|
52 #include <mpxmediadrmdefs.h> |
|
53 #include <mpxmediacontainerdefs.h> |
|
54 #include <mpxmediaarray.h> |
|
55 #include <mpxcommonui.rsg> |
|
56 #include <mpxcommonui.mbg> |
|
57 #include <mpx.rsg> |
|
58 #include <mpxcollectionhelperfactory.h> |
|
59 #include <mpxcollectionpath.h> // TMPXItemId |
|
60 #include <mpxcollectionutility.h> |
|
61 #include <mpxcollectionplugin.hrh> |
|
62 #include <mpxuser.h> |
|
63 #include <AknGlobalNote.h> |
|
64 |
|
65 // Cover UI start |
|
66 //#ifdef __COVER_DISPLAY |
|
67 #include <aknSDData.h> |
|
68 #include <AknMediatorFacade.h> |
|
69 #include <mplayersecondarydisplayapi.h> |
|
70 #include <featmgr.h> |
|
71 //#endif |
|
72 // Cover UI end |
|
73 |
|
74 #include <mpxconstants.h> |
|
75 #include "mpxfilenamequerydlg.h" |
|
76 #include "mpxcommonui.hrh" |
|
77 #include "mpxtlshelper.h" |
|
78 #include "mpxcommonuihelper.h" |
|
79 #include "mpxdrmuihelper.h" |
|
80 #include "mpxinternalcrkeys.h" |
|
81 #include "mpxlog.h" |
|
82 |
|
83 |
|
84 // CONSTANTS |
|
85 const TInt KMPXOneSecInMicroSecs( 1000000 ); |
|
86 const TInt KMPXOneMinInSeconds( 60 ); |
|
87 const TInt KMPXOneHourInSeconds( 3600 ); |
|
88 const TInt KMPXOneDayInSeconds( 86400 ); |
|
89 const TInt KMPXOneHundredHoursInSecs( 360000 ); |
|
90 |
|
91 const TInt KMPXDurationDisplayResvLen( 10 ); |
|
92 |
|
93 const TInt KMPXDecimalPlaces ( 1 ); |
|
94 const TInt KMPXWidthOfChar ( 10 ); |
|
95 |
|
96 const TInt KMPXMaxBufferLen ( 160 ); |
|
97 |
|
98 const TInt KMPXMaxPlaylistPathLen ( 200 ); |
|
99 const TInt KMPXPlaylistinfoLen ( 300 ); |
|
100 |
|
101 const TInt KMPXStandAloneProcessIDTop32( 1 ); |
|
102 const TInt KMPXStandAloneProcessIDBottom32( 2 ); |
|
103 |
|
104 const TReal KMPXOneKB ( 1024 ); |
|
105 const TReal KMPXOneMB ( 1048576 ); |
|
106 const TReal KMPXOneGB ( 1073741824 ); |
|
107 |
|
108 const TText KRightToLeftMark = 0x200F; |
|
109 |
|
110 const TInt KMPXChunkSize = 100; // number of songs added in each chunk, IncAddL |
|
111 const TInt KSQLErrGeneral = -311; // SQL General error. Don't want to include sql header here |
|
112 |
|
113 _LIT( KMPXCommonUiRscPath, "mpxcommonui.rsc" ); |
|
114 _LIT( KMPXAddToPlaylistMemoryCardIcon, "\t0"); |
|
115 _LIT( KMPXCommonUiIconFile, "mpxcommonui.mbm" ); |
|
116 _LIT( KMPXAppUiRscPath, "mpx.rsc" ); |
|
117 |
|
118 // autonaming format |
|
119 _LIT( KAutoNamingFormat, "%S(%S)"); |
|
120 #ifndef RD_MULTIPLE_DRIVE |
|
121 _LIT( KDriveFormatString, ":\\" ); |
|
122 #endif // RD_MULTIPLE_DRIVE |
|
123 _LIT( KAutoNumberFormat, "%u"); |
|
124 _LIT( KAutoNumberPaddedFormat, "%+02u"); |
|
125 _LIT( KWildCardCharacter, "*"); |
|
126 |
|
127 // ======== MEMBER FUNCTIONS ======== |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // C++ default constructor can NOT contain any code, that |
|
131 // might leave. |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 CMPXCommonUiHelper::CMPXCommonUiHelper(MMPXCollectionUtility* aCollectionUtility) |
|
135 : iCollectionUtility(aCollectionUtility) |
|
136 { |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // Symbian 2nd phase constructor can leave. |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 void CMPXCommonUiHelper::ConstructL() |
|
144 { |
|
145 CCoeEnv* coeEnv = CEikonEnv::Static(); |
|
146 TParse parse; |
|
147 parse.Set( KMPXCommonUiRscPath, &KDC_APP_RESOURCE_DIR, NULL ); |
|
148 TFileName resourceFile( parse.FullName() ); |
|
149 User::LeaveIfError( MPXUser::CompleteWithDllPath( resourceFile ) ); |
|
150 BaflUtils::NearestLanguageFile( coeEnv->FsSession(), resourceFile ); |
|
151 iResourceOffset = coeEnv->AddResourceFileL( resourceFile ); |
|
152 |
|
153 TParse appUiparse; |
|
154 appUiparse.Set( KMPXAppUiRscPath, &KDC_APP_RESOURCE_DIR, NULL ); |
|
155 TFileName appUiResourceFile( appUiparse.FullName() ); |
|
156 User::LeaveIfError( MPXUser::CompleteWithDllPath( appUiResourceFile ) ); |
|
157 BaflUtils::NearestLanguageFile( coeEnv->FsSession(), appUiResourceFile ); |
|
158 iAppUiResourceOffset = coeEnv->AddResourceFileL( appUiResourceFile ); |
|
159 |
|
160 iMpxDrmHelper = CMPXDrmUiHelper::NewL( this ); |
|
161 |
|
162 //#ifdef __COVER_DISPLAY |
|
163 if ( FeatureManager::FeatureSupported( KFeatureIdCoverDisplay ) ) |
|
164 { |
|
165 iCoverDisplay = ETrue; |
|
166 } |
|
167 else |
|
168 { |
|
169 iCoverDisplay = EFalse; |
|
170 } |
|
171 //#endif // __COVER_DISPLAY |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------------------------- |
|
175 // Two-phased constructor. |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 EXPORT_C CMPXCommonUiHelper* CMPXCommonUiHelper::NewL(MMPXCollectionUtility* aCollectionUtility) |
|
179 { |
|
180 CMPXCommonUiHelper* self = new ( ELeave ) CMPXCommonUiHelper(aCollectionUtility); |
|
181 CleanupStack::PushL( self ); |
|
182 self->ConstructL(); |
|
183 CleanupStack::Pop(); |
|
184 |
|
185 return self; |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------------------------- |
|
189 // Destructor |
|
190 // --------------------------------------------------------------------------- |
|
191 // |
|
192 CMPXCommonUiHelper::~CMPXCommonUiHelper() |
|
193 { |
|
194 if ( iCollectionUiHelper ) |
|
195 { |
|
196 iCollectionUiHelper->Close(); |
|
197 } |
|
198 |
|
199 if ( iWaitDialog ) |
|
200 { |
|
201 iWaitDialog->SetCallback( NULL ); |
|
202 TRAP_IGNORE( iWaitDialog->ProcessFinishedL() ); |
|
203 } |
|
204 |
|
205 if ( iResourceOffset ) |
|
206 { |
|
207 CEikonEnv::Static()->DeleteResourceFile( iResourceOffset ); |
|
208 } |
|
209 if ( iAppUiResourceOffset ) |
|
210 { |
|
211 CEikonEnv::Static()->DeleteResourceFile( iAppUiResourceOffset ); |
|
212 } |
|
213 delete iMpxDrmHelper; |
|
214 } |
|
215 |
|
216 // --------------------------------------------------------------------------- |
|
217 // Check if the host application is messaging or browser |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 EXPORT_C TBool CMPXCommonUiHelper::IsHostMessagingBrowserL() |
|
221 { |
|
222 return ( IsHostMessagingL() || IsHostBrowserL() ); |
|
223 } |
|
224 |
|
225 // --------------------------------------------------------------------------- |
|
226 // Check if the host application is messaging |
|
227 // --------------------------------------------------------------------------- |
|
228 // |
|
229 EXPORT_C TBool CMPXCommonUiHelper::IsHostMessagingL() |
|
230 { |
|
231 TBool ret( EFalse ); |
|
232 TInt hostUid = MPXTlsHelper::HostUid().iUid; |
|
233 if ( hostUid == KMPXMmsViewerUid || hostUid == KMPXMmsEditorUid || |
|
234 hostUid == KMPXMailViewerUid || hostUid == KMPXMailEditorUid || |
|
235 hostUid == KMPXMessagingUid || hostUid == KMPXUniEditorUid ) |
|
236 { |
|
237 ret = ETrue; |
|
238 } |
|
239 return ret; |
|
240 } |
|
241 |
|
242 // --------------------------------------------------------------------------- |
|
243 // Check if the host application is browser |
|
244 // --------------------------------------------------------------------------- |
|
245 // |
|
246 EXPORT_C TBool CMPXCommonUiHelper::IsHostBrowserL() |
|
247 { |
|
248 TBool ret( EFalse ); |
|
249 TInt hostUid = MPXTlsHelper::HostUid().iUid; |
|
250 if ( hostUid == KMPXBrowserUid || hostUid == KMPXBrowserUid2 ) // browser |
|
251 { |
|
252 ret = ETrue; |
|
253 } |
|
254 return ret; |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // Check if the host application is Podcasting Application |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 EXPORT_C TBool CMPXCommonUiHelper::IsHostPodcastingAppL() |
|
262 { |
|
263 return MPXTlsHelper::HostUid().iUid == KPodcastingAppUid; |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 // Convert to displayable duration. |
|
268 // --------------------------------------------------------------------------- |
|
269 // |
|
270 EXPORT_C HBufC* CMPXCommonUiHelper::DisplayableDurationL( |
|
271 TInt64 aDuration, |
|
272 TMPXDuratDisplayMode aMode ) |
|
273 { |
|
274 TInt resId; |
|
275 HBufC* format = NULL; |
|
276 if ( aDuration >= KMPXOneHundredHoursInSecs ) |
|
277 { |
|
278 resId = R_MPX_TIME_DURAT_HHHMMSS_WITH_ZERO; |
|
279 format = StringLoader::LoadLC( |
|
280 resId, aDuration / KMPXOneHourInSeconds ); |
|
281 } |
|
282 else |
|
283 { |
|
284 resId = R_QTN_TIME_DURAT_MIN_SEC_WITH_ZERO; |
|
285 if ( ( aMode == EMPXDuratHMS ) || |
|
286 ( aDuration >= KMPXOneHourInSeconds ) ) |
|
287 { |
|
288 resId = R_QTN_TIME_DURAT_LONG_WITH_ZERO; |
|
289 } |
|
290 format = StringLoader::LoadLC( resId ); |
|
291 } |
|
292 |
|
293 // Convert total playing time to texts. |
|
294 TTime durTime( aDuration * KMPXOneSecInMicroSecs ); |
|
295 |
|
296 HBufC* buf = |
|
297 HBufC::NewLC( format->Length() + KMPXDurationDisplayResvLen ); |
|
298 TPtr bufTPtr( buf->Des() ); |
|
299 |
|
300 durTime.FormatL( bufTPtr, *format ); |
|
301 AknTextUtils::LanguageSpecificNumberConversion( bufTPtr ); |
|
302 CleanupStack::Pop( buf ); |
|
303 CleanupStack::PopAndDestroy( format ); |
|
304 |
|
305 return buf; |
|
306 } |
|
307 |
|
308 // --------------------------------------------------------------------------- |
|
309 // Convert to displayable duration in text format. |
|
310 // --------------------------------------------------------------------------- |
|
311 // |
|
312 EXPORT_C HBufC* CMPXCommonUiHelper::DisplayableDurationInTextL( |
|
313 TInt64 aDuration ) |
|
314 { |
|
315 HBufC* buf = NULL; |
|
316 TInt days = I64INT( aDuration / KMPXOneDayInSeconds ); |
|
317 TInt hours = |
|
318 I64INT( ( aDuration % KMPXOneDayInSeconds ) / |
|
319 KMPXOneHourInSeconds ); |
|
320 TInt mins = |
|
321 I64INT( ( aDuration % KMPXOneHourInSeconds ) / |
|
322 KMPXOneMinInSeconds ); |
|
323 TInt secs = I64INT( aDuration % KMPXOneMinInSeconds ); |
|
324 |
|
325 CArrayFix< TInt >* intArray = |
|
326 new ( ELeave ) CArrayFixFlat<TInt>( 2 ); // magic number |
|
327 CleanupStack::PushL( intArray ); |
|
328 |
|
329 if ( days > 1 && ( hours == 0 || hours > 1 ) ) |
|
330 { |
|
331 intArray->AppendL( days ); |
|
332 intArray->AppendL( hours ); |
|
333 buf = StringLoader::LoadLC( R_MPX_CUI_TIME_DAYS_HRS_TEXT, *intArray ); |
|
334 } |
|
335 else if ( days > 1 && hours == 1 ) |
|
336 { |
|
337 buf = StringLoader::LoadLC( R_MPX_CUI_TIME_DAYS_HR_TEXT, days ); |
|
338 } |
|
339 else if ( days == 1 && ( hours == 0 || hours > 1 ) ) |
|
340 { |
|
341 buf = StringLoader::LoadLC( R_MPX_CUI_TIME_DAY_HRS_TEXT, hours ); |
|
342 } |
|
343 else if ( days == 1 && hours == 1 ) |
|
344 { |
|
345 buf = StringLoader::LoadLC( R_MPX_CUI_TIME_DAY_HR_TEXT ); |
|
346 } |
|
347 else if ( hours > 1 && ( mins == 0 || mins > 1 ) ) |
|
348 { |
|
349 intArray->AppendL( hours ); |
|
350 intArray->AppendL( mins ); |
|
351 buf = StringLoader::LoadLC( R_MPX_CUI_TIME_HRS_MINS_TEXT, *intArray ); |
|
352 } |
|
353 else if ( hours > 1 && mins == 1 ) |
|
354 { |
|
355 buf = StringLoader::LoadLC( R_MPX_CUI_TIME_HRS_MIN_TEXT, hours ); |
|
356 } |
|
357 else if ( hours == 1 && ( mins == 0 || mins > 1 ) ) |
|
358 { |
|
359 buf = StringLoader::LoadLC( R_MPX_CUI_TIME_HR_MINS_TEXT, mins ); |
|
360 } |
|
361 else if ( hours == 1 && mins == 1 ) |
|
362 { |
|
363 buf = StringLoader::LoadLC( R_MPX_CUI_TIME_HR_MIN_TEXT ); |
|
364 } |
|
365 else if ( mins > 1 && ( secs == 0 || secs > 1 ) ) |
|
366 { |
|
367 intArray->AppendL( mins ); |
|
368 intArray->AppendL( secs ); |
|
369 buf = StringLoader::LoadLC( R_MPX_CUI_TIME_MINS_SECS_TEXT, *intArray ); |
|
370 } |
|
371 else if ( mins > 1 && secs == 1 ) |
|
372 { |
|
373 buf = StringLoader::LoadLC( R_MPX_CUI_TIME_MINS_SEC_TEXT, mins ); |
|
374 } |
|
375 else if ( mins == 1 && ( secs == 0 || secs > 1 ) ) |
|
376 { |
|
377 buf = StringLoader::LoadLC( R_MPX_CUI_TIME_MIN_SECS_TEXT, secs ); |
|
378 } |
|
379 else if ( mins == 1 && secs == 1 ) |
|
380 { |
|
381 buf = StringLoader::LoadLC( R_MPX_CUI_TIME_MIN_SEC_TEXT ); |
|
382 } |
|
383 else if ( secs > 1 ) |
|
384 { |
|
385 buf = StringLoader::LoadLC( R_MPX_CUI_TIME_SECS_TEXT, secs ); |
|
386 } |
|
387 else |
|
388 { |
|
389 buf = StringLoader::LoadLC( R_MPX_CUI_TIME_SEC_TEXT ); |
|
390 } |
|
391 |
|
392 TPtr bufPtr = buf->Des(); |
|
393 AknTextUtils::LanguageSpecificNumberConversion( bufPtr ); |
|
394 CleanupStack::Pop( buf ); |
|
395 CleanupStack::PopAndDestroy( intArray ); |
|
396 |
|
397 return buf; |
|
398 } |
|
399 |
|
400 // --------------------------------------------------------------------------- |
|
401 // Set current file as ringing tone. |
|
402 // --------------------------------------------------------------------------- |
|
403 // |
|
404 EXPORT_C void CMPXCommonUiHelper::DoSetAsRingingToneL( |
|
405 const CMPXMedia& aMedia, |
|
406 TBool aSetToAllProfiles, |
|
407 TBool aShowQuery ) |
|
408 { |
|
409 TInt rightsStatus( KErrNotFound ); |
|
410 TBool canSetAutomated( EFalse ); |
|
411 TBool okToSet( ETrue ); |
|
412 TBool isProtected( EFalse ); |
|
413 |
|
414 if ( aMedia.IsSupported ( KMPXMediaDrmProtected ) ) |
|
415 { |
|
416 isProtected = aMedia.ValueTObjectL<TBool>( KMPXMediaDrmProtected ); |
|
417 } |
|
418 if ( isProtected ) |
|
419 { |
|
420 if ( aMedia.IsSupported ( KMPXMediaDrmRightsStatus ) ) |
|
421 { |
|
422 rightsStatus = aMedia.ValueTObjectL<TInt>( KMPXMediaDrmRightsStatus ); |
|
423 } |
|
424 if ( aMedia.IsSupported ( KMPXMediaDrmCanSetAutomated ) ) |
|
425 { |
|
426 canSetAutomated = aMedia.ValueTObjectL<TBool>( KMPXMediaDrmCanSetAutomated ); |
|
427 } |
|
428 } |
|
429 |
|
430 if ( ( !isProtected ) || ( rightsStatus == EMPXDrmRightsFull ) |
|
431 || ( canSetAutomated ) ) |
|
432 { |
|
433 if ( aShowQuery && aSetToAllProfiles ) |
|
434 { |
|
435 // Show query only if set ringtone to all profiles and needed |
|
436 CAknQueryDialog* query = |
|
437 CAknQueryDialog::NewL( CAknQueryDialog::EConfirmationTone ); |
|
438 okToSet = query->ExecuteLD( |
|
439 R_MPX_CHANGE_RT_FOR_ALL_CONFIRMATION_QUERY ); |
|
440 } |
|
441 |
|
442 if ( okToSet ) |
|
443 { |
|
444 TInt error( KErrNone ); |
|
445 TInt leaveError( KErrNone ); |
|
446 CProfileToneHandler* toneHandler = CProfileToneHandler::NewLC(); |
|
447 |
|
448 if ( aSetToAllProfiles ) |
|
449 { |
|
450 MPX_TRAP( leaveError, error = toneHandler->SetToneForAllProfilesL( |
|
451 EProfileRingingToneSetting, |
|
452 aMedia.ValueText( KMPXMediaGeneralUri ) ) ); |
|
453 } |
|
454 else |
|
455 { |
|
456 MPX_TRAP( leaveError, error = toneHandler->SetActiveProfileRingingToneL( |
|
457 aMedia.ValueText( KMPXMediaGeneralUri ) ) ); |
|
458 } |
|
459 if ( leaveError != KErrNone ) |
|
460 { |
|
461 error = leaveError; |
|
462 } |
|
463 |
|
464 CleanupStack::PopAndDestroy( toneHandler ); |
|
465 |
|
466 if ( KErrNone == error && !aSetToAllProfiles ) |
|
467 { |
|
468 HBufC* text = StringLoader::LoadLC( |
|
469 R_MPX_RINGTONE_SET_TEXT, aMedia.ValueText( |
|
470 KMPXMediaGeneralTitle ) ); |
|
471 DisplayConfirmNoteL( *text ); |
|
472 CleanupStack::PopAndDestroy( text ); |
|
473 } |
|
474 else if ( KErrPermissionDenied == error ) |
|
475 { |
|
476 DisplayInfoNoteL( R_MPX_RINGTONE_UNPROTECTED_FILE_TEXT ); |
|
477 } |
|
478 else if ( KErrArgument == error || |
|
479 KErrAccessDenied == error ) |
|
480 { |
|
481 DisplayInfoNoteL( R_MPX_RINGTONE_NOT_ALLOWED_TEXT ); |
|
482 } |
|
483 else if ( KErrNotFound == error ) |
|
484 { |
|
485 DisplayInfoNoteL( R_MPX_FILE_NOT_FOUND_TEXT ); |
|
486 } |
|
487 else |
|
488 { |
|
489 // do nothing |
|
490 } |
|
491 } |
|
492 } |
|
493 else |
|
494 { |
|
495 DisplayInfoNoteL( R_MPX_DRM_PREV_RIGHTS_SET ); |
|
496 } |
|
497 } |
|
498 |
|
499 // ----------------------------------------------------------------------------- |
|
500 // Check if current profile mode is offline mode. |
|
501 // ----------------------------------------------------------------------------- |
|
502 // |
|
503 EXPORT_C TBool CMPXCommonUiHelper::IsProfileOfflineModeL() |
|
504 { |
|
505 TBool isOfflineMode( EFalse ); |
|
506 MProfileEngine* profileEngine; |
|
507 profileEngine = CreateProfileEngineL(); |
|
508 |
|
509 if ( profileEngine->ActiveProfileId() == EProfileOffLineId ) |
|
510 { |
|
511 isOfflineMode = ETrue; |
|
512 } |
|
513 profileEngine->Release(); |
|
514 |
|
515 return isOfflineMode; |
|
516 } |
|
517 |
|
518 // ----------------------------------------------------------------------------- |
|
519 // Returns a path of the default drive used for saving playlists, ringtones, |
|
520 // downloads and attachments. |
|
521 // ----------------------------------------------------------------------------- |
|
522 // |
|
523 EXPORT_C HBufC* CMPXCommonUiHelper::DefaultDriveLC() |
|
524 { |
|
525 #ifdef RD_MULTIPLE_DRIVE |
|
526 // Use an internal mass storage drive as the default drive. If no internal |
|
527 // drive (other than the phone memory) exists, use an external drive. |
|
528 // Otherwise use the phone memory. |
|
529 RFs& fs = CEikonEnv::Static()->FsSession(); |
|
530 TDriveList driveList; |
|
531 TInt driveCount(0); |
|
532 TInt defaultInternalDrive(0); |
|
533 TInt defaultExternalDrive(0); |
|
534 TBool foundInternalDrive(EFalse); |
|
535 TBool foundExternalDrive(EFalse); |
|
536 User::LeaveIfError( DriveInfo::GetUserVisibleDrives( |
|
537 fs, driveList, driveCount ) ); |
|
538 |
|
539 for( TInt driveNum = EDriveA; |
|
540 ( driveNum <= EDriveZ ) && !foundInternalDrive; |
|
541 driveNum++ ) |
|
542 { |
|
543 if ( driveList[driveNum] && ( driveNum != EDriveC ) ) // ignore C: drive |
|
544 { |
|
545 // Get the drive status |
|
546 TUint driveStatus(0); |
|
547 DriveInfo::GetDriveStatus( fs, driveNum, driveStatus ); |
|
548 |
|
549 if ( driveStatus & DriveInfo::EDriveInternal ) |
|
550 { |
|
551 defaultInternalDrive = driveNum; |
|
552 foundInternalDrive = ETrue; |
|
553 } // internal mass store drive |
|
554 else if ( !foundExternalDrive && |
|
555 (driveStatus & |
|
556 (DriveInfo::EDriveRemovable | DriveInfo::EDriveRemote)) ) |
|
557 { |
|
558 TVolumeInfo volumeInfo; |
|
559 TInt errCode = fs.Volume( volumeInfo, driveNum ); |
|
560 if( errCode == KErrNone ) |
|
561 { |
|
562 //driveNum is really ready for use |
|
563 defaultExternalDrive = driveNum; |
|
564 foundExternalDrive = ETrue; |
|
565 } |
|
566 } // external drive |
|
567 } // if (available drive) |
|
568 } // for (all available drives) |
|
569 |
|
570 // Use the internal drive, external drive or phone memory as the default |
|
571 // path |
|
572 HBufC* defaultRootPath = HBufC::NewLC( 10 ); |
|
573 TPtr pathPtr( defaultRootPath->Des() ); |
|
574 if ( foundInternalDrive ) |
|
575 { |
|
576 User::LeaveIfError( |
|
577 PathInfo::GetRootPath( pathPtr, defaultInternalDrive ) ); |
|
578 } |
|
579 else if ( foundExternalDrive ) |
|
580 { |
|
581 User::LeaveIfError( |
|
582 PathInfo::GetRootPath( pathPtr, defaultExternalDrive ) ); |
|
583 } |
|
584 else // use phone memory path |
|
585 { |
|
586 pathPtr.Copy( PathInfo::PhoneMemoryRootPath() ); |
|
587 } |
|
588 |
|
589 MPX_DEBUG2("CMPXCommonUiHelper::DefaultDriveLC - path = %S", &pathPtr); |
|
590 #else |
|
591 HBufC* defaultRootPath = NULL; |
|
592 // Default drive used for saving playlists, etc |
|
593 // is as following: |
|
594 // 1. if E: drive exists ( MMC card inserted ) |
|
595 // playlist will be saved on the E: drive unless |
|
596 // ( mmc is locked, readonly, or below critical disk space) |
|
597 // 2. E drive is not present ( MMC card ejected ), save the |
|
598 // playlist on the phone memory instead. |
|
599 |
|
600 TChar drive; |
|
601 if ( !IsMemoryCardWritable( drive ) ) |
|
602 { |
|
603 // load phone memory root path |
|
604 defaultRootPath = StringLoader::LoadLC( |
|
605 R_MPX_CUI_PHONE_MEMORY_ROOT_PATH ); |
|
606 } |
|
607 else |
|
608 { |
|
609 defaultRootPath = HBufC::NewLC( 10 ); |
|
610 TPtr ptr( defaultRootPath->Des() ); |
|
611 ptr.Append( drive ); |
|
612 ptr.Append( KDriveFormatString ); |
|
613 } |
|
614 #endif // RD_MULTIPLE_DRIVE |
|
615 return defaultRootPath; |
|
616 } |
|
617 |
|
618 // ----------------------------------------------------------------------------- |
|
619 // Returns a path of the next available drive used for saving playlists, ringtones, |
|
620 // downloads and attachments. The order of priority is internal mass store, |
|
621 // MMC, then phone memory. |
|
622 // ----------------------------------------------------------------------------- |
|
623 // |
|
624 EXPORT_C HBufC* CMPXCommonUiHelper::AvailableDriveLC( TInt aSize ) |
|
625 { |
|
626 #ifdef RD_MULTIPLE_DRIVE |
|
627 // Use an available mass storage drive (other than the phone memory). If |
|
628 // none exists, use an external drive. Otherwise use the phone memory. |
|
629 RFs& fs = CEikonEnv::Static()->FsSession(); |
|
630 TDriveList driveList; |
|
631 TInt driveCount(0); |
|
632 TInt availableInternalDrive(0); |
|
633 TInt availableExternalDrive(0); |
|
634 TBool foundInternalDrive(EFalse); |
|
635 TBool foundExternalDrive(EFalse); |
|
636 User::LeaveIfError( DriveInfo::GetUserVisibleDrives( |
|
637 fs, driveList, driveCount ) ); |
|
638 |
|
639 for( TInt driveNum = EDriveA; |
|
640 ( driveNum <= EDriveZ ) && !foundInternalDrive; |
|
641 driveNum++ ) |
|
642 { |
|
643 if ( driveList[driveNum] && ( driveNum != EDriveC ) ) // ignore C: drive |
|
644 { |
|
645 // Get the drive status |
|
646 TUint driveStatus(0); |
|
647 DriveInfo::GetDriveStatus( fs, driveNum, driveStatus ); |
|
648 |
|
649 if ( driveStatus & DriveInfo::EDriveInternal ) |
|
650 { |
|
651 // Ensure there is enough disk space for the file |
|
652 TBool internalDriveBelowCritical = EFalse; |
|
653 MPX_TRAPD( err, internalDriveBelowCritical = |
|
654 SysUtil::DiskSpaceBelowCriticalLevelL( |
|
655 &fs, aSize, driveNum ) ); |
|
656 if ( internalDriveBelowCritical ) |
|
657 { |
|
658 MPX_DEBUG2("CMPXCommonUiHelper::AvailableDriveLC - Internal drive below critical driveNum=%d", driveNum); |
|
659 } |
|
660 else if ( err == KErrNone ) |
|
661 { |
|
662 availableInternalDrive = driveNum; |
|
663 foundInternalDrive = ETrue; |
|
664 } |
|
665 } // internal mass store drive |
|
666 else if ( !foundExternalDrive && |
|
667 (driveStatus & |
|
668 (DriveInfo::EDriveRemovable | DriveInfo::EDriveRemote)) ) |
|
669 { |
|
670 TBool externalDriveBelowCritical = EFalse; |
|
671 MPX_TRAPD( err, externalDriveBelowCritical = |
|
672 SysUtil::DiskSpaceBelowCriticalLevelL( |
|
673 &fs, aSize, driveNum ) ); |
|
674 if ( externalDriveBelowCritical ) |
|
675 { |
|
676 MPX_DEBUG2("CMPXCommonUiHelper::AvailableDriveLC - External drive below critical driveNum=%d", driveNum); |
|
677 } |
|
678 else if ( err == KErrNone ) |
|
679 { |
|
680 availableExternalDrive = driveNum; |
|
681 foundExternalDrive = ETrue; |
|
682 } |
|
683 } // external drive |
|
684 } // if (available drive) |
|
685 } // for (all available drives) |
|
686 |
|
687 // Use the internal drive, external drive or phone memory as the default |
|
688 // path |
|
689 HBufC* defaultRootPath = HBufC::NewLC( 10 ); |
|
690 TPtr pathPtr( defaultRootPath->Des() ); |
|
691 if ( foundInternalDrive ) |
|
692 { |
|
693 User::LeaveIfError( |
|
694 PathInfo::GetRootPath( pathPtr, availableInternalDrive ) ); |
|
695 } |
|
696 else if ( foundExternalDrive ) |
|
697 { |
|
698 User::LeaveIfError( |
|
699 PathInfo::GetRootPath( pathPtr, availableExternalDrive ) ); |
|
700 } |
|
701 else // use phone memory path |
|
702 { |
|
703 pathPtr.Copy( PathInfo::PhoneMemoryRootPath() ); |
|
704 } |
|
705 |
|
706 MPX_DEBUG2("CMPXCommonUiHelper::AvailableDriveLC - path = %S", &pathPtr); |
|
707 return defaultRootPath; |
|
708 #else |
|
709 (void) aSize; |
|
710 return NULL; |
|
711 #endif // RD_MULTIPLE_DRIVE |
|
712 } |
|
713 |
|
714 // ----------------------------------------------------------------------------- |
|
715 // Display information note |
|
716 // ----------------------------------------------------------------------------- |
|
717 // |
|
718 EXPORT_C void CMPXCommonUiHelper::DisplayInfoNoteL( TInt aResourceId ) |
|
719 { |
|
720 HBufC* text = StringLoader::LoadLC( aResourceId ); |
|
721 DisplayInfoNoteL( *text ); |
|
722 CleanupStack::PopAndDestroy( text ); |
|
723 } |
|
724 |
|
725 // ----------------------------------------------------------------------------- |
|
726 // Display information note |
|
727 // ----------------------------------------------------------------------------- |
|
728 // |
|
729 EXPORT_C void CMPXCommonUiHelper::DisplayInfoNoteL( const TDesC& aText ) |
|
730 { |
|
731 CAknInformationNote* dlg = new ( ELeave ) CAknInformationNote( ETrue ); |
|
732 dlg->ExecuteLD( aText ); |
|
733 } |
|
734 |
|
735 // ----------------------------------------------------------------------------- |
|
736 // Display confirmation note |
|
737 // ----------------------------------------------------------------------------- |
|
738 // |
|
739 EXPORT_C void CMPXCommonUiHelper::DisplayConfirmNoteL( TInt aResourceId ) |
|
740 { |
|
741 HBufC* text = StringLoader::LoadLC( aResourceId ); |
|
742 |
|
743 // Cover UI start |
|
744 //#ifdef __COVER_DISPLAY |
|
745 DisplayConfirmNoteL( *text, aResourceId ); |
|
746 //#else |
|
747 // DisplayConfirmNoteL( *text ); |
|
748 //#endif // __COVER_DISPLAY |
|
749 // CoverUI end |
|
750 |
|
751 CleanupStack::PopAndDestroy( text ); |
|
752 } |
|
753 |
|
754 // ----------------------------------------------------------------------------- |
|
755 // Display confirmation note |
|
756 // ----------------------------------------------------------------------------- |
|
757 // |
|
758 EXPORT_C void CMPXCommonUiHelper::DisplayConfirmNoteL( const TDesC& aText ) |
|
759 { |
|
760 CAknConfirmationNote* dlg = new ( ELeave ) CAknConfirmationNote( ETrue ); |
|
761 dlg->ExecuteLD( aText ); |
|
762 } |
|
763 |
|
764 // Cover UI start |
|
765 //#ifdef __COVER_DISPLAY |
|
766 // ----------------------------------------------------------------------------- |
|
767 // Display confirmation note |
|
768 // ----------------------------------------------------------------------------- |
|
769 // |
|
770 void CMPXCommonUiHelper::DisplayConfirmNoteL( |
|
771 const TDesC& aText, |
|
772 TInt aResourceId ) |
|
773 { |
|
774 CAknConfirmationNote* dlg = new ( ELeave ) CAknConfirmationNote( ETrue ); |
|
775 |
|
776 CleanupStack::PushL( dlg ); |
|
777 if ( aResourceId == R_MPX_SAVED_TO_COLLECTION_NOTE ) |
|
778 { |
|
779 dlg->PublishDialogL( |
|
780 EMPlayerNoteSavedtoCollection, |
|
781 KMPlayerNoteCategory); |
|
782 } |
|
783 else if ( aResourceId == R_MPX_SAVED_NOTE ) |
|
784 { |
|
785 dlg->PublishDialogL( |
|
786 EMPlayerNoteSavedtoGallery, |
|
787 KMPlayerNoteCategory); |
|
788 } |
|
789 CleanupStack::Pop( dlg ); |
|
790 |
|
791 dlg->ExecuteLD( aText ); |
|
792 } |
|
793 //#endif // __COVER_DISPLAY |
|
794 // Cover UI end |
|
795 |
|
796 // ----------------------------------------------------------------------------- |
|
797 // Convert a value from bytes to kB/MB/GB. |
|
798 // ----------------------------------------------------------------------------- |
|
799 // |
|
800 EXPORT_C HBufC* CMPXCommonUiHelper::UnitConversionL( TInt64 aByte, TBool aFree ) |
|
801 { |
|
802 HBufC* res = NULL; |
|
803 |
|
804 if ( aByte >= 0 && aByte < KMPXOneKB ) // unit is B |
|
805 { |
|
806 if ( aFree ) |
|
807 { |
|
808 res = StringLoader::LoadLC( R_MPX_CUI_MEMORY_B_FREE, aByte ); |
|
809 } |
|
810 else |
|
811 { |
|
812 res = StringLoader::LoadLC( R_MPX_CUI_MEMORY_B, aByte ); |
|
813 } |
|
814 } |
|
815 else // unit is larger than a byte and must be displayed with decimal |
|
816 { |
|
817 TReal memoryUnitSize; |
|
818 TInt memoryUnitResId; |
|
819 |
|
820 if ( aByte >= KMPXOneKB && aByte < KMPXOneMB ) // unis is kB |
|
821 { |
|
822 memoryUnitSize = KMPXOneKB; |
|
823 if ( aFree) |
|
824 { |
|
825 memoryUnitResId = R_MPX_CUI_MEMORY_KB1_FREE; |
|
826 } |
|
827 else |
|
828 { |
|
829 memoryUnitResId = R_MPX_CUI_MEMORY_KB; |
|
830 } |
|
831 } |
|
832 else if ( aByte >= KMPXOneMB && aByte < KMPXOneGB ) // unit is MB |
|
833 { |
|
834 memoryUnitSize = KMPXOneMB; |
|
835 if ( aFree ) |
|
836 { |
|
837 memoryUnitResId = R_MPX_CUI_MEMORY_MB1_FREE; |
|
838 } |
|
839 else |
|
840 { |
|
841 memoryUnitResId = R_MPX_CUI_MEMORY_MB; |
|
842 } |
|
843 } |
|
844 else // unit is GB |
|
845 { |
|
846 memoryUnitSize = KMPXOneGB; |
|
847 if ( aFree ) |
|
848 { |
|
849 memoryUnitResId = R_MPX_CUI_MEMORY_GB1_FREE; |
|
850 } |
|
851 else |
|
852 { |
|
853 memoryUnitResId = R_MPX_CUI_MEMORY_GB; |
|
854 } |
|
855 } |
|
856 |
|
857 TBuf<KMPXMaxBufferLen> sizeBuf; |
|
858 TRealFormat format = TRealFormat( KMPXWidthOfChar, KMPXDecimalPlaces ); |
|
859 TReal tmpValue = ( I64REAL(aByte) / memoryUnitSize ); |
|
860 sizeBuf.AppendNum( tmpValue, format ); |
|
861 if ( User::Language() == ELangArabic ) |
|
862 { |
|
863 sizeBuf.Append( KRightToLeftMark ); |
|
864 } |
|
865 res = StringLoader::LoadLC( memoryUnitResId, sizeBuf ); |
|
866 } |
|
867 CleanupStack::Pop( res ); |
|
868 return res; |
|
869 } |
|
870 |
|
871 // ----------------------------------------------------------------------------- |
|
872 // Finds all user playlists in the given collection |
|
873 // ----------------------------------------------------------------------------- |
|
874 // |
|
875 EXPORT_C CMPXMedia* CMPXCommonUiHelper::FindPlaylistsL() |
|
876 { |
|
877 MPX_FUNC( "CMPXCommonUiHelper::FindPlaylistsL" ); |
|
878 |
|
879 RArray<TMPXAttribute> attrs; |
|
880 CleanupClosePushL( attrs ); |
|
881 attrs.Append( KMPXMediaGeneralTitle ); |
|
882 attrs.Append( KMPXMediaGeneralId ); |
|
883 attrs.Append( KMPXMediaGeneralFlags ); |
|
884 |
|
885 CMPXMedia* ret = FindAllL( EMPXPlaylist, attrs.Array() ); |
|
886 CleanupStack::PopAndDestroy( &attrs ); |
|
887 |
|
888 return ret; |
|
889 } |
|
890 |
|
891 // ----------------------------------------------------------------------------- |
|
892 // Add to saved playlist |
|
893 // ----------------------------------------------------------------------------- |
|
894 // |
|
895 EXPORT_C TBool CMPXCommonUiHelper::AddToSavedPlaylistL( |
|
896 const CMPXMedia& aPlaylists, const CMPXMedia& aTracks, |
|
897 MMPXCHelperObserver* aObserver, MProgressDialogCallback* aCallback ) |
|
898 { |
|
899 MPX_FUNC( "CMPXCommonUiHelper::AddToSavedPlaylistL" ); |
|
900 |
|
901 TBool ret( EFalse ); |
|
902 |
|
903 const CMPXMediaArray* mediaArray = |
|
904 aPlaylists.Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
905 User::LeaveIfNull( const_cast<CMPXMediaArray*>( mediaArray )); |
|
906 |
|
907 TInt count( 0 ); |
|
908 if ( mediaArray ) |
|
909 { |
|
910 count = mediaArray->Count(); |
|
911 } |
|
912 else |
|
913 { |
|
914 User::Leave( KErrArgument ); |
|
915 } |
|
916 |
|
917 if ( count < 1) |
|
918 { |
|
919 User::Leave( KErrArgument ); |
|
920 } |
|
921 else |
|
922 { |
|
923 TInt index = 0; |
|
924 CAknListQueryDialog* queryDlg = |
|
925 new ( ELeave ) CAknListQueryDialog( &index ); |
|
926 queryDlg->PrepareLC( R_MPX_CUI_PLAYLIST_QUERY_LIST ); |
|
927 |
|
928 //#ifdef __COVER_DISPLAY |
|
929 queryDlg->PublishDialogL( |
|
930 EMPlayerQuerySelectPlaylist, KMPlayerNoteCategory ); |
|
931 //#endif //__COVER_DISPLAY |
|
932 |
|
933 // Get the text array from the listbox model |
|
934 CTextListBoxModel* lbxModel = |
|
935 static_cast<CTextListBoxModel*>( queryDlg->ListBox()->Model() ); |
|
936 CDesCArray* descArray = |
|
937 static_cast<CDesCArray*>( lbxModel->ItemTextArray() ); |
|
938 descArray->Reset(); |
|
939 |
|
940 // Set up icon array |
|
941 CAknIconArray* icons = new ( ELeave ) CAknIconArray( 1 ); // magic: icon count |
|
942 CleanupStack::PushL( icons ); |
|
943 TParse mbmFileName; |
|
944 mbmFileName.Set( KMPXCommonUiIconFile, |
|
945 &KDC_APP_RESOURCE_DIR, NULL ); |
|
946 TFileName iconFile( mbmFileName.FullName() ); |
|
947 User::LeaveIfError( MPXUser::CompleteWithDllPath( iconFile ) ); |
|
948 |
|
949 CFbsBitmap* bitmap = NULL; |
|
950 CFbsBitmap* mask = NULL; |
|
951 AknsUtils::CreateColorIconLC( |
|
952 AknsUtils::SkinInstance(), // aInstance |
|
953 KAknsIIDQgnIndiMmcAdd, // aID |
|
954 KAknsIIDQsnIconColors, // aColorID |
|
955 EAknsCIQsnIconColorsCG26, // aColorIndex |
|
956 bitmap, |
|
957 mask, |
|
958 iconFile, |
|
959 EMbmMpxcommonuiQgn_indi_mmc_add, |
|
960 EMbmMpxcommonuiQgn_indi_mmc_add_mask, |
|
961 KRgbBlack ); // aDefaultColor |
|
962 CGulIcon* icon = CGulIcon::NewL( bitmap, mask ); |
|
963 icon->SetBitmapsOwnedExternally( EFalse ); |
|
964 |
|
965 // icon now owns the bitmaps, no need to keep on cleanup stack. |
|
966 CleanupStack::Pop(2); // mask, bitmap |
|
967 bitmap = NULL; |
|
968 mask = NULL; |
|
969 CleanupStack::PushL( icon ); |
|
970 icons->AppendL( icon ); |
|
971 queryDlg->SetIconArrayL(icons); |
|
972 CleanupStack::Pop( icon ); |
|
973 CleanupStack::Pop( icons ); |
|
974 |
|
975 TInt mmc = MMCDriveNumber(); |
|
976 // Prepare for query dialog |
|
977 for ( TInt i = 0; i < count; i++ ) |
|
978 { |
|
979 CMPXMedia* media( mediaArray->AtL( i )); |
|
980 TUint flags( 0 ); |
|
981 TRAP_IGNORE(flags = media->ValueTObjectL<TUint>( KMPXMediaGeneralFlags )) |
|
982 TInt driveNum = ( ( flags ) & ( KMPXMediaGeneralFlagsDriveInfo ) ); |
|
983 HBufC* line = NULL; |
|
984 HBufC* title = media->ValueText( KMPXMediaGeneralTitle ).AllocLC(); |
|
985 |
|
986 if( driveNum == mmc ) |
|
987 { |
|
988 line = HBufC::NewLC( |
|
989 KMPXAddToPlaylistMemoryCardIcon().Length() + |
|
990 title->Length() ); |
|
991 TPtr linePtr = line->Des(); |
|
992 linePtr += *title; |
|
993 linePtr.Append( KMPXAddToPlaylistMemoryCardIcon ); |
|
994 } |
|
995 else |
|
996 { |
|
997 line = title->AllocLC(); |
|
998 } |
|
999 descArray->AppendL( *line ); |
|
1000 CleanupStack::PopAndDestroy( line ); |
|
1001 CleanupStack::PopAndDestroy( title ); |
|
1002 } |
|
1003 |
|
1004 if ( queryDlg->RunLD() ) |
|
1005 { |
|
1006 if ( index >= 0 ) |
|
1007 { |
|
1008 CMPXMedia* media( mediaArray->AtL( index )); |
|
1009 TMPXItemId playlistId = |
|
1010 media->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ); |
|
1011 const CMPXMediaArray* tracksArray = |
|
1012 aTracks.Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
1013 User::LeaveIfNull( const_cast<CMPXMediaArray*>( tracksArray )); |
|
1014 if ( tracksArray->Count() < 1 ) |
|
1015 { |
|
1016 User::Leave( KErrArgument ); |
|
1017 } |
|
1018 else |
|
1019 { |
|
1020 if ( tracksArray->Count() == 1 ) |
|
1021 { |
|
1022 HBufC* text = StringLoader::LoadLC( |
|
1023 R_MPX_QTN_NMP_NOTE_ADDING_ONE_SONG ); |
|
1024 ShowWaitNoteL( *text, |
|
1025 R_AVKON_SOFTKEYS_EMPTY, ETrue, aCallback ); |
|
1026 CleanupStack::PopAndDestroy( text ); |
|
1027 } |
|
1028 else |
|
1029 { |
|
1030 HBufC* text = StringLoader::LoadLC( |
|
1031 R_MPX_QTN_MUS_NOTE_ADDING_TRACKS ); |
|
1032 ShowWaitNoteL( *text, |
|
1033 R_MPX_WAITNOTE_SOFTKEYS_EMPTY_STOP, ETrue, aCallback ); |
|
1034 CleanupStack::PopAndDestroy( text ); |
|
1035 } |
|
1036 CMPXMedia* media = CMPXMedia::NewL(); |
|
1037 CleanupStack::PushL( media ); |
|
1038 media->SetTObjectValueL<TMPXItemId>( |
|
1039 KMPXMediaGeneralId, playlistId ); |
|
1040 media->SetTObjectValueL<TMPXGeneralType>( |
|
1041 KMPXMediaGeneralType, EMPXItem ); |
|
1042 media->SetTObjectValueL<TMPXGeneralCategory>( |
|
1043 KMPXMediaGeneralCategory, EMPXPlaylist ); |
|
1044 media->SetCObjectValueL( |
|
1045 KMPXMediaArrayContents, |
|
1046 const_cast<CMPXMediaArray*>(tracksArray )); |
|
1047 media->SetTObjectValueL( |
|
1048 KMPXMediaArrayCount, tracksArray->Count() ); |
|
1049 |
|
1050 RArray<TUid> ary; |
|
1051 CleanupClosePushL( ary ); |
|
1052 ary.AppendL( TUid::Uid(EMPXCollectionPluginMusic) ); |
|
1053 TUid musicCollection = iCollectionUtility->CollectionIDL( ary.Array() ); |
|
1054 CleanupStack::PopAndDestroy( &ary ); |
|
1055 |
|
1056 media->SetTObjectValueL<TUid>( KMPXMediaGeneralCollectionId, musicCollection ); |
|
1057 |
|
1058 if ( !iCollectionUiHelper ) |
|
1059 { |
|
1060 iCollectionUiHelper = CMPXCollectionHelperFactory::NewCollectionUiHelperL(); |
|
1061 } |
|
1062 iCollectionUiHelper->IncAddL( *media, aObserver, KMPXChunkSize ); |
|
1063 ret = ETrue; |
|
1064 CleanupStack::PopAndDestroy( media ); |
|
1065 } |
|
1066 } |
|
1067 } |
|
1068 } |
|
1069 return ret; |
|
1070 } |
|
1071 |
|
1072 // ----------------------------------------------------------------------------- |
|
1073 // Create playlist |
|
1074 // ----------------------------------------------------------------------------- |
|
1075 // |
|
1076 EXPORT_C TBool CMPXCommonUiHelper::CreatePlaylistL( |
|
1077 const CMPXMedia& aTracks, MMPXCHelperObserver* aObserver, |
|
1078 MProgressDialogCallback* aCallback ) |
|
1079 { |
|
1080 MPX_FUNC( "CMPXCommonUiHelper::CreatePlaylistL" ); |
|
1081 |
|
1082 RFs& fs = CEikonEnv::Static()->FsSession(); |
|
1083 HBufC* playlistName = HBufC::NewLC( KMaxFileName ); |
|
1084 TPtr playlistNamePtr = playlistName->Des(); |
|
1085 const TInt playListSize = 8; |
|
1086 |
|
1087 #ifdef RD_MULTIPLE_DRIVE |
|
1088 // Create playlist on the next available drive (internal mass store, |
|
1089 // MMC or phone memory) |
|
1090 HBufC* defaultRootPath = AvailableDriveLC( playListSize ); |
|
1091 playlistNamePtr = *defaultRootPath; |
|
1092 CleanupStack::PopAndDestroy( defaultRootPath ); |
|
1093 #else |
|
1094 HBufC* defaultRootPath = DefaultDriveLC(); |
|
1095 playlistNamePtr = *defaultRootPath; |
|
1096 CleanupStack::PopAndDestroy( defaultRootPath ); |
|
1097 |
|
1098 if ( playlistNamePtr.CompareF( PathInfo::MemoryCardRootPath() ) == 0 ) |
|
1099 { |
|
1100 // only if memory card is supported, check if there is enough space |
|
1101 // on the card. |
|
1102 TBool isBelowCritical = EFalse; |
|
1103 MPX_TRAPD( err, isBelowCritical = SysUtil::MMCSpaceBelowCriticalLevelL( |
|
1104 &fs, playListSize ) ); |
|
1105 if ( err || isBelowCritical ) |
|
1106 { |
|
1107 MPX_DEBUG1( "CMPXCommonUiHelper::CreatePlaylistL Error in MMC, default path changed to phone memory" ); |
|
1108 playlistNamePtr = PathInfo::PhoneMemoryRootPath(); |
|
1109 } |
|
1110 } |
|
1111 #endif // RD_MULTIPLE_DRIVE |
|
1112 |
|
1113 HBufC* defaultPath = |
|
1114 StringLoader::LoadLC( R_MPX_CUI_TARGETFOLDER_PLAYLIST ); |
|
1115 playlistNamePtr += *defaultPath; |
|
1116 CleanupStack::PopAndDestroy( defaultPath ); |
|
1117 |
|
1118 TBool ret( PlaylistCreationQueriesL( playlistNamePtr ) ); |
|
1119 if ( ret ) |
|
1120 { |
|
1121 MPX_DEBUG2( "CMPXCommonUiHelper::CreatePlaylistL Saving playlist %S", &playlistNamePtr ); |
|
1122 const CMPXMediaArray* tracksArray = |
|
1123 aTracks.Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
1124 User::LeaveIfNull( const_cast<CMPXMediaArray*>( tracksArray )); |
|
1125 if ( tracksArray->Count() == 1 ) |
|
1126 { |
|
1127 HBufC* text = StringLoader::LoadLC( |
|
1128 R_MPX_QTN_NMP_NOTE_ADDING_ONE_SONG ); |
|
1129 ShowWaitNoteL( *text, |
|
1130 R_AVKON_SOFTKEYS_EMPTY, ETrue, aCallback ); |
|
1131 CleanupStack::PopAndDestroy( text ); |
|
1132 } |
|
1133 else if ( tracksArray->Count() > 0 ) |
|
1134 { |
|
1135 // only show wait note if we're adding more than 1 song |
|
1136 HBufC* text = StringLoader::LoadLC( |
|
1137 R_MPX_QTN_MUS_NOTE_ADDING_TRACKS ); |
|
1138 ShowWaitNoteL( *text, |
|
1139 R_MPX_WAITNOTE_SOFTKEYS_EMPTY_STOP, ETrue, aCallback ); |
|
1140 CleanupStack::PopAndDestroy( text ); |
|
1141 } |
|
1142 |
|
1143 CMPXMedia* media = CMPXMedia::NewL(); |
|
1144 CleanupStack::PushL( media ); |
|
1145 media->SetTObjectValueL<TMPXGeneralType>( |
|
1146 KMPXMediaGeneralType, EMPXItem ); |
|
1147 media->SetTObjectValueL<TMPXGeneralCategory>( |
|
1148 KMPXMediaGeneralCategory, EMPXPlaylist ); |
|
1149 TParsePtrC fn( playlistNamePtr ); |
|
1150 // no extension in virtual playlist, all "extension" are inputed |
|
1151 // by users as a valid name |
|
1152 media->SetTextValueL( |
|
1153 KMPXMediaGeneralTitle, fn.NameAndExt() ); |
|
1154 |
|
1155 media->SetCObjectValueL( |
|
1156 KMPXMediaArrayContents, |
|
1157 const_cast<CMPXMediaArray*>(tracksArray ) ); |
|
1158 media->SetTObjectValueL( |
|
1159 KMPXMediaArrayCount, tracksArray->Count() ); |
|
1160 media->SetTextValueL( |
|
1161 KMPXMediaGeneralUri, fn.DriveAndPath() ); // exculde the file name |
|
1162 // new playlist |
|
1163 if ( !iCollectionUiHelper ) |
|
1164 { |
|
1165 iCollectionUiHelper = CMPXCollectionHelperFactory::NewCollectionUiHelperL(); |
|
1166 } |
|
1167 iCollectionUiHelper->IncAddL( *media, aObserver, KMPXChunkSize ); |
|
1168 CleanupStack::PopAndDestroy( media ); |
|
1169 } |
|
1170 CleanupStack::PopAndDestroy( playlistName ); |
|
1171 return ret; |
|
1172 } |
|
1173 |
|
1174 // ----------------------------------------------------------------------------- |
|
1175 // Launch rename dialog |
|
1176 // ----------------------------------------------------------------------------- |
|
1177 // |
|
1178 EXPORT_C TInt CMPXCommonUiHelper::LaunchRenameDialogL( |
|
1179 const TDesC& aOldName, |
|
1180 TDes& aNewName, |
|
1181 const TDesC& aPath ) |
|
1182 { |
|
1183 MPX_FUNC( "CMPXCommonUiHelper::LaunchRenameDialogL" ); |
|
1184 CMPXFileNameQueryDlg* renameDlg = CMPXFileNameQueryDlg::NewL( |
|
1185 aOldName, aNewName, aPath, EMPXPlaylist, this ); |
|
1186 TInt ret = renameDlg->ExecuteLD( R_MPX_FILE_NAME_QUERY ); |
|
1187 |
|
1188 if ( ret ) |
|
1189 { |
|
1190 if ( aNewName.CompareF( aOldName ) == 0 ) |
|
1191 { |
|
1192 ret = EFalse; |
|
1193 } |
|
1194 else |
|
1195 { |
|
1196 if ( !iCollectionUiHelper ) |
|
1197 { |
|
1198 iCollectionUiHelper = CMPXCollectionHelperFactory::NewCollectionUiHelperL(); |
|
1199 } |
|
1200 if ( iCollectionUiHelper->TitleExistsL( EMPXPlaylist, aNewName, EMPXOtherType ) ) |
|
1201 { |
|
1202 HBufC* info = StringLoader::LoadLC( R_MPX_PLAYLIST_NAME_EXIST, aNewName ); |
|
1203 |
|
1204 if( CEikonEnv::Static()->QueryWinL( KNullDesC, *info ) ) |
|
1205 { |
|
1206 if ( !LaunchRenameDialogL( aOldName, aNewName, aPath ) ) |
|
1207 { |
|
1208 ret = EFalse; |
|
1209 } |
|
1210 } |
|
1211 else |
|
1212 { |
|
1213 ret = EFalse; |
|
1214 } |
|
1215 CleanupStack::PopAndDestroy( info );//query ,info |
|
1216 } |
|
1217 } |
|
1218 } |
|
1219 |
|
1220 return ret; |
|
1221 } |
|
1222 |
|
1223 // ----------------------------------------------------------------------------- |
|
1224 // Shows wait note |
|
1225 // ----------------------------------------------------------------------------- |
|
1226 // |
|
1227 EXPORT_C void CMPXCommonUiHelper::ShowWaitNoteL( TDesC& aText, TInt aCBAId, |
|
1228 TBool aVisibilityDelayOff, MProgressDialogCallback* aCallback, TInt aResId ) |
|
1229 { |
|
1230 MPX_FUNC( "CMPXCommonUiHelper::ShowWaitNoteL" ); |
|
1231 if( iWaitDialog ) |
|
1232 { |
|
1233 // if wait note is already running |
|
1234 // cancel it and recreate will have timing issues |
|
1235 if ( aCallback ) |
|
1236 { |
|
1237 iWaitDialog->SetCallback( aCallback ); |
|
1238 } |
|
1239 iWaitDialog->SetTextL( aText ); |
|
1240 MEikButtonGroup* buttonGroup = |
|
1241 iWaitDialog->ButtonGroupContainer().ButtonGroup(); |
|
1242 if ( aCBAId ) |
|
1243 { |
|
1244 buttonGroup->SetCommandSetL( aCBAId ); |
|
1245 } |
|
1246 buttonGroup->AsControl()->DrawDeferred(); |
|
1247 iWaitDialog->DrawDeferred(); |
|
1248 } |
|
1249 else |
|
1250 { |
|
1251 iWaitDialog = new ( ELeave ) CAknWaitDialog( |
|
1252 ( CEikDialog** )&iWaitDialog, aVisibilityDelayOff ); |
|
1253 if ( aCallback ) |
|
1254 { |
|
1255 iWaitDialog->SetCallback( aCallback ); |
|
1256 } |
|
1257 iWaitDialog->PrepareLC( aResId ); |
|
1258 iWaitDialog->SetTextL( aText ); |
|
1259 MEikButtonGroup* buttonGroup = |
|
1260 iWaitDialog->ButtonGroupContainer().ButtonGroup(); |
|
1261 if ( aCBAId ) |
|
1262 { |
|
1263 buttonGroup->SetCommandSetL( aCBAId ); |
|
1264 } |
|
1265 buttonGroup->AsControl()->DrawDeferred(); |
|
1266 iWaitDialog->RunLD(); |
|
1267 } |
|
1268 } |
|
1269 |
|
1270 // ----------------------------------------------------------------------------- |
|
1271 // Dismiss wait note |
|
1272 // ----------------------------------------------------------------------------- |
|
1273 // |
|
1274 EXPORT_C void CMPXCommonUiHelper::DismissWaitNoteL() |
|
1275 { |
|
1276 MPX_FUNC( "CMPXCommonUiHelper::DismissWaitNoteL" ); |
|
1277 if( iWaitDialog ) |
|
1278 { |
|
1279 iWaitDialog->ProcessFinishedL(); |
|
1280 } |
|
1281 } |
|
1282 |
|
1283 // ----------------------------------------------------------------------------- |
|
1284 // Handles displaying the error message for given error code |
|
1285 // according to the media object provided |
|
1286 // ----------------------------------------------------------------------------- |
|
1287 // |
|
1288 EXPORT_C TInt CMPXCommonUiHelper::HandleErrorL( |
|
1289 TInt aError, |
|
1290 const CMPXMedia* aMedia, /*=NULL*/ |
|
1291 RFile* aFile /*=NULL*/ ) |
|
1292 { |
|
1293 MPX_DEBUG2("CMPXCommonUiHelper::HandleErrorL(%d) entering", aError); |
|
1294 |
|
1295 TBool usingGlobalNote = EFalse; // To use CAknGlobalNote if necessary |
|
1296 TInt ret( KErrNone ); |
|
1297 CTextResolver* textResolver( NULL ); |
|
1298 HBufC* errorText( NULL ); |
|
1299 switch ( aError ) |
|
1300 { |
|
1301 case KMPXRightsAboutToExpire: |
|
1302 case KErrCANotSupported: |
|
1303 case KErrCANoPermission: |
|
1304 case KErrCANoRights: |
|
1305 case KErrCANoAgent: |
|
1306 case KErrCAOutOfRange: |
|
1307 case KErrCAPendingRights: |
|
1308 case KErrCASizeNotDetermined: |
|
1309 case KErrCANewFileHandleRequired: |
|
1310 { |
|
1311 TRAPD(err, ret = iMpxDrmHelper->HandleDrmErrorL( aError, aMedia, aFile )); |
|
1312 if (err) |
|
1313 { |
|
1314 ret = err; |
|
1315 if ( ret == KErrArgument ) |
|
1316 // If error is KErrArgument, map it to R_MPX_INVALID_CLIP |
|
1317 errorText = StringLoader::LoadLC( R_MPX_INVALID_CLIP ); |
|
1318 else |
|
1319 { |
|
1320 // TextResolver instance for error resolving. |
|
1321 textResolver = CTextResolver::NewLC(); |
|
1322 // Resolve the error text |
|
1323 const TDesC& text = |
|
1324 textResolver->ResolveErrorString( ret ); |
|
1325 errorText = text.AllocLC(); |
|
1326 } |
|
1327 } |
|
1328 break; |
|
1329 } |
|
1330 case KMPXAllTracksInvalid: |
|
1331 { |
|
1332 errorText = |
|
1333 StringLoader::LoadLC( R_MPX_INVALID_GROUP_TEXT ); |
|
1334 break; |
|
1335 } |
|
1336 case KErrNotSupported: |
|
1337 case KErrCorrupt: |
|
1338 { |
|
1339 errorText = StringLoader::LoadLC( R_MPX_INVALID_CLIP ); |
|
1340 break; |
|
1341 } |
|
1342 case KErrAccessDenied: |
|
1343 { |
|
1344 if ( aMedia ) |
|
1345 { |
|
1346 if ( aMedia->IsSupported( KMPXMediaDrmType ) ) |
|
1347 { |
|
1348 TMPXMediaDrmType type = |
|
1349 aMedia->ValueTObjectL<TMPXMediaDrmType>( KMPXMediaDrmType ); |
|
1350 if ( EMPXDrmTypeOMA == type ) |
|
1351 { |
|
1352 errorText = StringLoader::LoadLC( R_MPX_NO_DRM_OVER_BT ); |
|
1353 break; |
|
1354 } |
|
1355 } |
|
1356 } |
|
1357 // fall through on purpose to use default handling |
|
1358 // if error was not handled above |
|
1359 } |
|
1360 case KMPXErrorVideoCall: |
|
1361 { |
|
1362 errorText = StringLoader::LoadLC( R_MPX_VIDEO_CALL_ONGOING ); |
|
1363 usingGlobalNote = ETrue; |
|
1364 break; |
|
1365 } |
|
1366 case KErrLocked: |
|
1367 errorText = StringLoader::LoadLC( R_MPX_CANNOT_PROCEED_WITH_OPERATION ); |
|
1368 break; |
|
1369 case KErrDisMounted: |
|
1370 break; |
|
1371 case KErrDiskFull: |
|
1372 case KSQLErrGeneral: |
|
1373 errorText = StringLoader::LoadLC( R_MPX_CUI_MEMLO_NOT_ENOUGH_MEMORY ); |
|
1374 break; |
|
1375 default: |
|
1376 { |
|
1377 // TextResolver instance for error resolving. |
|
1378 textResolver = CTextResolver::NewLC(); |
|
1379 // Resolve the error text |
|
1380 const TDesC& text = |
|
1381 textResolver->ResolveErrorString( aError ); |
|
1382 errorText = text.AllocLC(); |
|
1383 break; |
|
1384 } |
|
1385 } |
|
1386 |
|
1387 if ( errorText ) |
|
1388 { |
|
1389 if ( !usingGlobalNote ) |
|
1390 { |
|
1391 CAknErrorNote* dlg = new ( ELeave ) CAknErrorNote( ETrue ); |
|
1392 dlg->ExecuteLD( *errorText ); |
|
1393 } |
|
1394 else |
|
1395 { |
|
1396 // CAknErrorNote will not display when mpx is not currently foreground, |
|
1397 // so if necessary, use CAknGlobalNote to replace it. |
|
1398 CAknGlobalNote* globalInfoNote = CAknGlobalNote::NewLC(); |
|
1399 globalInfoNote->ShowNoteL( |
|
1400 EAknGlobalInformationNote, |
|
1401 errorText->Des() ); |
|
1402 CleanupStack::PopAndDestroy( globalInfoNote ); |
|
1403 } |
|
1404 CleanupStack::PopAndDestroy( errorText ); |
|
1405 } |
|
1406 if ( textResolver ) |
|
1407 { |
|
1408 CleanupStack::PopAndDestroy( textResolver ); |
|
1409 } |
|
1410 |
|
1411 MPX_DEBUG2("CMPXCommonUiHelper::HandleErrorL() exiting, returning %d", ret); |
|
1412 return ret; |
|
1413 } |
|
1414 |
|
1415 // --------------------------------------------------------------------------- |
|
1416 // Sets middle softkey label. |
|
1417 // --------------------------------------------------------------------------- |
|
1418 // |
|
1419 EXPORT_C void CMPXCommonUiHelper::SetMiddleSoftKeyLabelL( |
|
1420 CEikButtonGroupContainer& aCba, |
|
1421 TInt aResourceId, |
|
1422 TInt aCommandId ) |
|
1423 { |
|
1424 #ifdef __ENABLE_MSK |
|
1425 MPX_FUNC( "CMPXCommonUiHelper::SetMiddleSoftKeyLabelL" ); |
|
1426 aCba.RemoveCommandFromStack( |
|
1427 CEikButtonGroupContainer::EMiddleSoftkeyPosition, |
|
1428 aCba.ButtonGroup()->CommandId( |
|
1429 CEikButtonGroupContainer::EMiddleSoftkeyPosition ) ); |
|
1430 HBufC* middleSKText = StringLoader::LoadLC( aResourceId ); |
|
1431 TPtr mskPtr = middleSKText->Des(); |
|
1432 aCba.AddCommandToStackL( |
|
1433 CEikButtonGroupContainer::EMiddleSoftkeyPosition, |
|
1434 aCommandId, |
|
1435 mskPtr ); |
|
1436 CleanupStack::PopAndDestroy( middleSKText ); |
|
1437 #else |
|
1438 (void)aCba; |
|
1439 (void)aResourceId; |
|
1440 (void)aCommandId; |
|
1441 User::Leave( KErrNotSupported ); |
|
1442 #endif // __ENABLE_MSK |
|
1443 } |
|
1444 |
|
1445 // --------------------------------------------------------------------------- |
|
1446 // Removes middle softkey label. |
|
1447 // --------------------------------------------------------------------------- |
|
1448 // |
|
1449 EXPORT_C void CMPXCommonUiHelper::RemoveMiddleSoftKeyLabel( |
|
1450 CEikButtonGroupContainer& aCba ) |
|
1451 { |
|
1452 #ifdef __ENABLE_MSK |
|
1453 MPX_FUNC( "CMPXCommonUiHelper::RemoveMiddleSoftKeyLabel" ); |
|
1454 aCba.RemoveCommandFromStack( |
|
1455 CEikButtonGroupContainer::EMiddleSoftkeyPosition, |
|
1456 aCba.ButtonGroup()->CommandId( |
|
1457 CEikButtonGroupContainer::EMiddleSoftkeyPosition ) ); |
|
1458 TRAP_IGNORE( aCba.AddCommandToStackL( |
|
1459 CEikButtonGroupContainer::EMiddleSoftkeyPosition, |
|
1460 EAknSoftkeyEmpty, // no action |
|
1461 KNullDesC() ) ); // empty label |
|
1462 |
|
1463 #else |
|
1464 (void)aCba; |
|
1465 ASSERT(0); |
|
1466 #endif // __ENABLE_MSK |
|
1467 } |
|
1468 |
|
1469 // --------------------------------------------------------------------------- |
|
1470 // Sets middle softkey icon. |
|
1471 // --------------------------------------------------------------------------- |
|
1472 // |
|
1473 EXPORT_C void CMPXCommonUiHelper::SetMiddleSoftKeyIconL( |
|
1474 CEikButtonGroupContainer& aCba, |
|
1475 CFbsBitmap* aBitmap, |
|
1476 CFbsBitmap* aMask ) |
|
1477 { |
|
1478 #ifdef __ENABLE_MSK |
|
1479 MPX_FUNC( "CMPXCommonUiHelper::SetMiddleSoftKeyIconL" ); |
|
1480 aCba.RemoveCommandFromStack( |
|
1481 CEikButtonGroupContainer::EMiddleSoftkeyPosition, |
|
1482 aCba.ButtonGroup()->CommandId( |
|
1483 CEikButtonGroupContainer::EMiddleSoftkeyPosition ) ); |
|
1484 aCba.AddCommandToStackL( |
|
1485 CEikButtonGroupContainer::EMiddleSoftkeyPosition, |
|
1486 EAknSoftkeyContextOptions, |
|
1487 *aBitmap, |
|
1488 *aMask ); |
|
1489 |
|
1490 #else |
|
1491 (void)aCba; |
|
1492 (void)aBitmap; |
|
1493 (void)aMask; |
|
1494 User::Leave( KErrNotSupported ); |
|
1495 #endif // __ENABLE_MSK |
|
1496 } |
|
1497 |
|
1498 // --------------------------------------------------------------------------- |
|
1499 // Generate the next available title from the given title |
|
1500 // --------------------------------------------------------------------------- |
|
1501 // |
|
1502 EXPORT_C HBufC* CMPXCommonUiHelper::GenerateTitleL( TMPXGeneralCategory aCategory, |
|
1503 const TDesC& aBaseTitle ) |
|
1504 { |
|
1505 MPX_FUNC( "CMPXCommonUiHelper::GenerateTitleL" ); |
|
1506 |
|
1507 // |
|
1508 // Find titles of all playlists in the collection |
|
1509 // |
|
1510 RArray<TMPXAttribute> attrs; |
|
1511 CleanupClosePushL( attrs ); |
|
1512 attrs.Append( KMPXMediaGeneralTitle ); |
|
1513 |
|
1514 CMPXMedia* results = FindAllL(aCategory, attrs.Array()); |
|
1515 CleanupStack::PopAndDestroy(&attrs); |
|
1516 CleanupStack::PushL(results); |
|
1517 |
|
1518 if (!results->IsSupported(KMPXMediaArrayContents)) |
|
1519 { |
|
1520 User::Leave(KErrArgument); |
|
1521 } |
|
1522 const CMPXMediaArray* resultArray = results->Value<CMPXMediaArray>(KMPXMediaArrayContents); |
|
1523 User::LeaveIfNull( const_cast<CMPXMediaArray*>( resultArray )); |
|
1524 |
|
1525 // |
|
1526 // shorten this list by removing those that do not contain this pattern: |
|
1527 // aBaseTitle(*) |
|
1528 // |
|
1529 HBufC* matchingPattern = HBufC::NewLC(aBaseTitle.Length()+KWildCardCharacter().Length()+2); |
|
1530 matchingPattern->Des().Format(KAutoNamingFormat, &aBaseTitle, &KWildCardCharacter); |
|
1531 |
|
1532 CMPXMediaArray* medias = CMPXMediaArray::NewL(); |
|
1533 CleanupStack::PushL(medias); |
|
1534 |
|
1535 TInt count(resultArray->Count()); |
|
1536 |
|
1537 for (TInt i=0; i<count; i++) |
|
1538 { |
|
1539 const CMPXMedia* media( resultArray->AtL( i )); |
|
1540 |
|
1541 if (!media->IsSupported(KMPXMediaGeneralTitle)) |
|
1542 { |
|
1543 User::Leave(KErrArgument); |
|
1544 } |
|
1545 |
|
1546 if (media->ValueText(KMPXMediaGeneralTitle).Match(*matchingPattern) != KErrNotFound) |
|
1547 { |
|
1548 medias->AppendL(*media); |
|
1549 } |
|
1550 } |
|
1551 |
|
1552 CleanupStack::Pop(medias); |
|
1553 CleanupStack::PopAndDestroy(2, results); // matchingPattern & results |
|
1554 CleanupStack::PushL(medias); |
|
1555 |
|
1556 // |
|
1557 // determine if the suggested title is already used, if so, suggest another one; |
|
1558 // otherwise, return the suggested title |
|
1559 // |
|
1560 TBool found(EFalse); |
|
1561 TUint autoNumber(0); |
|
1562 |
|
1563 HBufC* autoNumberTextBuf = HBufC::NewLC(KMaxFileName); |
|
1564 TPtr autoNumberText = autoNumberTextBuf->Des(); |
|
1565 |
|
1566 HBufC* suggestedTitle(NULL); |
|
1567 |
|
1568 count = medias->Count(); |
|
1569 |
|
1570 while (!found) |
|
1571 { |
|
1572 autoNumberText.Format( |
|
1573 ++autoNumber < 10 ? KAutoNumberPaddedFormat() : KAutoNumberFormat(), autoNumber); |
|
1574 |
|
1575 AknTextUtils::LanguageSpecificNumberConversion(autoNumberText); |
|
1576 |
|
1577 HBufC* testTitle = HBufC::NewLC(aBaseTitle.Length()+autoNumberText.Length()+2); |
|
1578 testTitle->Des().Format(KAutoNamingFormat, &aBaseTitle, autoNumberTextBuf); |
|
1579 MPX_DEBUG2("testTitle = %S", testTitle); |
|
1580 |
|
1581 TBool exists(EFalse); |
|
1582 for (TInt i=0; i<count && !exists; i++) |
|
1583 { |
|
1584 if (testTitle->Compare((*medias)[i]->ValueText(KMPXMediaGeneralTitle)) == 0) |
|
1585 { |
|
1586 exists = ETrue; |
|
1587 } |
|
1588 } |
|
1589 |
|
1590 if (!exists) |
|
1591 { |
|
1592 found = ETrue; |
|
1593 suggestedTitle = testTitle; |
|
1594 CleanupStack::Pop(testTitle); |
|
1595 } |
|
1596 else |
|
1597 { |
|
1598 CleanupStack::PopAndDestroy(testTitle); |
|
1599 } |
|
1600 } |
|
1601 |
|
1602 CleanupStack::PopAndDestroy(2, medias); // autoNumberTextBuf & medias |
|
1603 |
|
1604 MPX_DEBUG2("SuggestedTitle = %S", suggestedTitle); |
|
1605 |
|
1606 return suggestedTitle; |
|
1607 } |
|
1608 |
|
1609 // --------------------------------------------------------------------------- |
|
1610 // Checks if Exit option should be hidden |
|
1611 // --------------------------------------------------------------------------- |
|
1612 // |
|
1613 EXPORT_C TBool CMPXCommonUiHelper::ExitOptionHiddenL() |
|
1614 { |
|
1615 MPX_FUNC( "CMPXCommonUiHelper::ExitOptionHiddenL" ); |
|
1616 TInt flags( 0 ); |
|
1617 CRepository* repository = CRepository::NewL( KCRUidMPXMPFeatures ); |
|
1618 repository->Get( KMPXMPLocalVariation, flags ); |
|
1619 delete repository; |
|
1620 return !static_cast<TBool>( flags & KMPXEnableExitOption ); |
|
1621 } |
|
1622 |
|
1623 // --------------------------------------------------------------------------- |
|
1624 // Sets standalone mode process ID |
|
1625 // --------------------------------------------------------------------------- |
|
1626 // |
|
1627 EXPORT_C TBool CMPXCommonUiHelper::SetStandAloneModePId( TInt64 aPId ) |
|
1628 { |
|
1629 MPX_FUNC( "CMPXCommonUiHelper::SetStandAloneModePId" ); |
|
1630 TInt err( RProperty::Define( |
|
1631 KAppUidMusicPlayerX, KMPXStandAloneProcessIDTop32, RProperty::EInt ) ); |
|
1632 MPX_DEBUG2( "CMPXCommonUiHelper::SetStandAloneModePId() RProperty top err = %d", err ); |
|
1633 if ( err == KErrNone || err == KErrAlreadyExists ) |
|
1634 { |
|
1635 err = RProperty::Define( |
|
1636 KAppUidMusicPlayerX, KMPXStandAloneProcessIDBottom32, RProperty::EInt ); |
|
1637 MPX_DEBUG2( "CMPXCommonUiHelper::SetStandAloneModePId() RProperty bottom err = %d", err ); |
|
1638 } |
|
1639 if ( err == KErrNone || err == KErrAlreadyExists ) |
|
1640 { |
|
1641 MPX_DEBUG2( "CMPXCommonUiHelper::SetStandAloneModePId() proc id = 0x%lx", aPId ); |
|
1642 TInt top32( aPId >> 32 ); |
|
1643 TInt bottom32( aPId & 0xFFFFFFFF ); |
|
1644 err = RProperty::Set( KAppUidMusicPlayerX, |
|
1645 KMPXStandAloneProcessIDTop32, |
|
1646 top32 ); |
|
1647 MPX_DEBUG2( "CMPXCommonUiHelper::SetStandAloneModePId() set top err = %d", err ); |
|
1648 err = RProperty::Set( KAppUidMusicPlayerX, |
|
1649 KMPXStandAloneProcessIDBottom32, |
|
1650 bottom32 ); |
|
1651 MPX_DEBUG2( "CMPXCommonUiHelper::SetStandAloneModePId() set bottom err = %d", err ); |
|
1652 } |
|
1653 return ( err == KErrNone ? ETrue : EFalse ); |
|
1654 } |
|
1655 |
|
1656 // --------------------------------------------------------------------------- |
|
1657 // Gets stand alone mode's process id |
|
1658 // --------------------------------------------------------------------------- |
|
1659 // |
|
1660 EXPORT_C TInt64 CMPXCommonUiHelper::StandAloneModePId() |
|
1661 { |
|
1662 MPX_FUNC( "CMPXCommonUiHelper::StandAloneModePId" ); |
|
1663 TInt ret( 0 ); |
|
1664 TInt64 procId( 0 ); |
|
1665 TInt err( RProperty::Get( |
|
1666 KAppUidMusicPlayerX, KMPXStandAloneProcessIDTop32, ret ) ); |
|
1667 if ( err == KErrNone ) |
|
1668 { |
|
1669 procId = TInt64( ret ) << 32; |
|
1670 err = RProperty::Get( |
|
1671 KAppUidMusicPlayerX, KMPXStandAloneProcessIDBottom32, ret ); |
|
1672 if ( err == KErrNone ) |
|
1673 { |
|
1674 procId += ret; |
|
1675 } |
|
1676 else |
|
1677 { |
|
1678 procId = 0; |
|
1679 } |
|
1680 } |
|
1681 MPX_DEBUG2( "CMPXCommonUiHelper::StandAloneModePId() combined proc id = 0x%lx", procId ); |
|
1682 return procId; |
|
1683 } |
|
1684 |
|
1685 // --------------------------------------------------------------------------- |
|
1686 // Checks if the application with the provided window group id is in foreground |
|
1687 // This method is required because AppUi()->IsForeground() does not work properly |
|
1688 // when the screen saver is active |
|
1689 // --------------------------------------------------------------------------- |
|
1690 // |
|
1691 EXPORT_C TBool CMPXCommonUiHelper::IsForegroundApplication(TInt aWindowGroupId) |
|
1692 { |
|
1693 TBool applicationInForeground(EFalse); |
|
1694 TApaTaskList taskList(CCoeEnv::Static()->WsSession()); |
|
1695 TApaTask taskInForeground = taskList.FindByPos( 0 ); |
|
1696 if ( taskInForeground.Exists() && |
|
1697 (taskInForeground.WgId() == aWindowGroupId)) |
|
1698 { |
|
1699 applicationInForeground = ETrue; |
|
1700 } |
|
1701 return applicationInForeground; |
|
1702 } |
|
1703 |
|
1704 EXPORT_C TInt CMPXCommonUiHelper::MMCDriveNumber() |
|
1705 { |
|
1706 #ifdef RD_MULTIPLE_DRIVE |
|
1707 TInt mmc( 0 ); |
|
1708 TInt r = DriveInfo::GetDefaultDrive(DriveInfo::EDefaultRemovableMassStorage, mmc ); |
|
1709 if (r != KErrNone) |
|
1710 mmc = r; |
|
1711 #else |
|
1712 TParsePtrC memorycardparse( PathInfo::MemoryCardRootPath() ); |
|
1713 TDriveUnit mmc( memorycardparse.Drive() ); |
|
1714 #endif // RD_MULTIPLE_DRIVE |
|
1715 return mmc; |
|
1716 } |
|
1717 |
|
1718 // ---------------------------------------------------------------------------- |
|
1719 // Cancel subsequent operations scheduled by CollectionUiHelper |
|
1720 // ---------------------------------------------------------------------------- |
|
1721 // |
|
1722 EXPORT_C void CMPXCommonUiHelper::CancelCollectionOperation() |
|
1723 { |
|
1724 iCollectionUiHelper->Cancel(); |
|
1725 } |
|
1726 |
|
1727 // ---------------------------------------------------------------------------- |
|
1728 // MPlayerCommonUi::IsMemoryCardWritable |
|
1729 // ---------------------------------------------------------------------------- |
|
1730 // |
|
1731 TBool CMPXCommonUiHelper::IsMemoryCardWritable( TChar& aDrive ) |
|
1732 { |
|
1733 TBool ret = EFalse; |
|
1734 TDriveList driveList; |
|
1735 TInt driveNum( EDriveE ); |
|
1736 CEikonEnv* eikEnv( CEikonEnv::Static() ); |
|
1737 RFs& fs( eikEnv->FsSession() ); |
|
1738 TInt err( fs.DriveList( driveList ) ); |
|
1739 |
|
1740 if ( err == KErrNone ) |
|
1741 { |
|
1742 // search from drive E to drive N (10 drives) |
|
1743 for (; driveNum <= EDriveN; ++driveNum ) |
|
1744 { |
|
1745 // Check that volume is valid (ie. not corrupted) |
|
1746 TVolumeInfo volumeInfo; |
|
1747 err = eikEnv->FsSession().Volume( volumeInfo, driveNum ); |
|
1748 |
|
1749 if ( ( err == KErrNone ) && |
|
1750 ( RFs::DriveToChar( driveNum, aDrive ) == KErrNone ) ) |
|
1751 { |
|
1752 ret = ETrue; |
|
1753 break; |
|
1754 } |
|
1755 } |
|
1756 } |
|
1757 return ret; |
|
1758 } |
|
1759 |
|
1760 // ----------------------------------------------------------------------------- |
|
1761 // CMPXCommonUiHelper::PlaylistCreationQueriesL |
|
1762 // ----------------------------------------------------------------------------- |
|
1763 // |
|
1764 TBool CMPXCommonUiHelper::PlaylistCreationQueriesL( TDes& aPath ) |
|
1765 { |
|
1766 MPX_FUNC( "CMPXCommonUiHelper::PlaylistCreationQueriesL" ); |
|
1767 |
|
1768 TBool ret = EFalse; |
|
1769 |
|
1770 // Get playlist filename |
|
1771 HBufC* playlistFileName = HBufC::NewLC( KMPXMaxPlaylistPathLen ); |
|
1772 TPtr playlistFileNamePtr = playlistFileName->Des(); |
|
1773 playlistFileNamePtr.Copy( aPath ); |
|
1774 User::LeaveIfError( GetNextPlaylistNameL( playlistFileNamePtr ) ); |
|
1775 TParsePtrC parse( playlistFileNamePtr ); |
|
1776 |
|
1777 HBufC* playlistName = |
|
1778 HBufC::NewLC( KMPXMaxPlaylistPathLen ); |
|
1779 TPtr playlistNamePtr = playlistName->Des(); |
|
1780 playlistNamePtr.Copy( parse.NameAndExt() ); |
|
1781 |
|
1782 if ( aPath.Length() > 0 ) |
|
1783 { |
|
1784 ret = PlaylistCreateNameExistL( playlistNamePtr , parse ); |
|
1785 if ( ret ) |
|
1786 { |
|
1787 aPath = parse.DriveAndPath(); |
|
1788 aPath.Append( playlistName->Des() ); |
|
1789 } |
|
1790 } |
|
1791 else |
|
1792 { |
|
1793 HBufC* saveTitle = |
|
1794 StringLoader::LoadLC( R_MPX_PLAYLIST_NAME_QUERY_TITLE ); |
|
1795 aPath.Copy( playlistNamePtr ); |
|
1796 |
|
1797 ret = AknCommonDialogs::RunSaveDlgNoDirectorySelectionLD( aPath, |
|
1798 R_MPX_PLAYLIST_MEMORY_SELECTION_LOCATIONS, *saveTitle ); |
|
1799 |
|
1800 CleanupStack::PopAndDestroy( saveTitle ); |
|
1801 } |
|
1802 |
|
1803 CleanupStack::PopAndDestroy( playlistName ); |
|
1804 CleanupStack::PopAndDestroy( playlistFileName ); |
|
1805 |
|
1806 return ret; |
|
1807 } |
|
1808 |
|
1809 // ----------------------------------------------------------------------------- |
|
1810 // Get next available playlist full pathname based on the information passed. |
|
1811 // ----------------------------------------------------------------------------- |
|
1812 // |
|
1813 TInt CMPXCommonUiHelper::GetNextPlaylistNameL( TDes& aBuf ) |
|
1814 { |
|
1815 MPX_FUNC( "CMPXCommonUiHelper::GetNextPlaylistNameL" ); |
|
1816 // Keep track of playlist file path |
|
1817 HBufC* filePath = aBuf.AllocLC(); |
|
1818 TParsePtrC pathParse( *filePath ); |
|
1819 HBufC* origPlaylistName( NULL ); |
|
1820 if ( !pathParse.NamePresent() ) |
|
1821 { |
|
1822 // Load default name if filename is missing |
|
1823 origPlaylistName = |
|
1824 StringLoader::LoadLC( R_MPX_CUI_DEFAULT_PLAYLIST_NAME ); |
|
1825 } |
|
1826 else |
|
1827 { |
|
1828 origPlaylistName = pathParse.Name().AllocLC(); |
|
1829 } |
|
1830 |
|
1831 if ( !iCollectionUiHelper ) |
|
1832 { |
|
1833 iCollectionUiHelper = CMPXCollectionHelperFactory::NewCollectionUiHelperL(); |
|
1834 } |
|
1835 if ( iCollectionUiHelper->TitleExistsL( EMPXPlaylist, *origPlaylistName ) ) |
|
1836 { |
|
1837 HBufC* newTitle = GenerateTitleL( EMPXPlaylist, *origPlaylistName ); |
|
1838 aBuf.Copy( pathParse.DriveAndPath() ); |
|
1839 aBuf.Append( *newTitle ); |
|
1840 delete newTitle; |
|
1841 } |
|
1842 else |
|
1843 { |
|
1844 aBuf.Copy( pathParse.DriveAndPath() ); |
|
1845 aBuf.Append( *origPlaylistName ); |
|
1846 } |
|
1847 CleanupStack::PopAndDestroy( 2, filePath ); |
|
1848 return KErrNone; |
|
1849 } |
|
1850 |
|
1851 // ----------------------------------------------------------------------------- |
|
1852 // Finds all items in the specified category |
|
1853 // ----------------------------------------------------------------------------- |
|
1854 // |
|
1855 CMPXMedia* CMPXCommonUiHelper::FindAllL(TMPXGeneralCategory aCategory, const TArray<TMPXAttribute>& aAttrs) |
|
1856 { |
|
1857 MPX_FUNC( "CMPXCommonUiHelper::FindAllL" ); |
|
1858 |
|
1859 if (!iCollectionUtility) |
|
1860 { |
|
1861 User::Leave(KErrArgument); |
|
1862 } |
|
1863 |
|
1864 CMPXMedia* ret( NULL ); |
|
1865 CMPXMedia* criteria = CMPXMedia::NewL(); |
|
1866 CleanupStack::PushL( criteria ); |
|
1867 criteria->SetTObjectValueL<TMPXGeneralType>( |
|
1868 KMPXMediaGeneralType, EMPXGroup ); |
|
1869 criteria->SetTObjectValueL<TMPXGeneralCategory>( |
|
1870 KMPXMediaGeneralCategory, aCategory ); |
|
1871 |
|
1872 // Look up collection UID and set to criteria |
|
1873 // |
|
1874 RArray<TUid> ary; |
|
1875 CleanupClosePushL( ary ); |
|
1876 ary.AppendL( TUid::Uid(EMPXCollectionPluginMusic) ); |
|
1877 TUid musicCollection = iCollectionUtility->CollectionIDL( ary.Array() ); |
|
1878 CleanupStack::PopAndDestroy( &ary ); |
|
1879 |
|
1880 criteria->SetTObjectValueL<TUid>( KMPXMediaGeneralCollectionId, musicCollection ); |
|
1881 |
|
1882 ret = iCollectionUtility->Collection().FindAllL( *criteria, aAttrs ); |
|
1883 CleanupStack::PopAndDestroy( criteria ); |
|
1884 return ret; |
|
1885 } |
|
1886 |
|
1887 // ----------------------------------------------------------------------------- |
|
1888 // Handles the completion of setting a media event. |
|
1889 // ----------------------------------------------------------------------------- |
|
1890 // |
|
1891 void CMPXCommonUiHelper::HandleOperationCompleteL( TCHelperOperation aOperation, |
|
1892 TInt aErr, |
|
1893 void* aArgument ) |
|
1894 { |
|
1895 if ( iAddObserver ) |
|
1896 { |
|
1897 iAddObserver->HandleOperationCompleteL( aOperation, aErr, aArgument ); |
|
1898 } |
|
1899 iAddObserver = NULL; |
|
1900 } |
|
1901 |
|
1902 // ---------------------------------------------------------------------------- |
|
1903 // CMPXCommonUiHelper::PlaylistCreateNameExistL |
|
1904 // ---------------------------------------------------------------------------- |
|
1905 // |
|
1906 TBool CMPXCommonUiHelper::PlaylistCreateNameExistL( TDes& aName, const TParseBase& aParse ) |
|
1907 { |
|
1908 TBool ret( EFalse ); |
|
1909 CMPXFileNameQueryDlg* nameDlg = CMPXFileNameQueryDlg::NewL( |
|
1910 aName, aName, aParse.DriveAndPath(), |
|
1911 EMPXPlaylist, this ); |
|
1912 // Cover UI start |
|
1913 //#ifdef __COVER_DISPLAY |
|
1914 nameDlg->PublishDialogL( |
|
1915 EMPlayerQueryCreatePlaylist, |
|
1916 KMPlayerNoteCategory); |
|
1917 //#endif |
|
1918 // Cover UI end |
|
1919 ret = nameDlg->ExecuteLD( R_MPX_CREATE_PLAYLIST_NAME_QUERY ); |
|
1920 |
|
1921 if ( ret ) |
|
1922 { |
|
1923 if ( iCollectionUiHelper->TitleExistsL( EMPXPlaylist, aName, EMPXOtherType ) ) |
|
1924 { |
|
1925 HBufC* info = StringLoader::LoadLC( R_MPX_PLAYLIST_NAME_EXIST, aName ); |
|
1926 |
|
1927 if( CEikonEnv::Static()->QueryWinL( KNullDesC, *info ) ) |
|
1928 { |
|
1929 if ( !PlaylistCreateNameExistL( aName, aParse ) ) |
|
1930 { |
|
1931 ret = EFalse; |
|
1932 } |
|
1933 } |
|
1934 else |
|
1935 { |
|
1936 ret = EFalse; |
|
1937 } |
|
1938 CleanupStack::PopAndDestroy( info );//query ,info |
|
1939 } |
|
1940 } |
|
1941 |
|
1942 return ret; |
|
1943 } |
|
1944 // End of File |