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