mpxplugins/viewplugins/views/metadataeditordialog/src/mpxmetadataeditordialog.cpp
branchRCL_3
changeset 53 3de6c4cf6b67
child 66 1f1dad4af8f8
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:  Music Player metadata editor dialog implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <eikmenub.h>
       
    21 #include <eikcapc.h>
       
    22 #include <eikdialg.h> // for dialog functions
       
    23 #include <eikedwin.h> // for edwins
       
    24 #include <eikmfne.h>  // for number editor
       
    25 #include <AknPopupFieldText.h>
       
    26 #include <AknQueryValueText.h>
       
    27 #include <aknappui.h>
       
    28 #include <eikspane.h> // for status pane update/restore
       
    29 #include <akntitle.h> // for title pane
       
    30 #include <aknnavilabel.h> // for navi label
       
    31 #include <aknnavi.h>
       
    32 #include <aknnavide.h>
       
    33 #include <StringLoader.h>
       
    34 #include <aknnotewrappers.h>
       
    35 #include <aknlists.h>
       
    36 #include <aknclearer.h>
       
    37 #include <hlplch.h>
       
    38 #include <bautils.h>
       
    39 #include <data_caging_path_literals.hrh>
       
    40 #include <drmrightsmanager.rsg>
       
    41 #include <centralrepository.h> // for podcasting cenrep key
       
    42 #include <tz.h>
       
    43 
       
    44 #include <aknSDData.h>
       
    45 #include <AknMediatorFacade.h>
       
    46 #include <mplayersecondarydisplayapi.h>
       
    47 #include <aknEditStateIndicator.h>
       
    48 #include <AknIndicatorContainer.h>
       
    49 #include <avkon.hrh>
       
    50 #include <avkon.rsg>
       
    51 #include <mpxmetadataeditordialog.rsg>
       
    52 #include <mpxcollectionutility.h>
       
    53 #include <mpxmedia.h>
       
    54 #include <mpxmediaarray.h>
       
    55 #include <mpxmediamusicdefs.h>
       
    56 #include <mpxmediaaudiodefs.h>
       
    57 #include <mpxmediacontainerdefs.h>
       
    58 #include <mpxmediadrmdefs.h>
       
    59 #include <mpxpodcastdefs.h>
       
    60 #include <mpxcommandgeneraldefs.h>
       
    61 #include <mpxcollectioncommanddefs.h>
       
    62 
       
    63 #include <mpxcollectionframeworkdefs.h>
       
    64 #include <mpxcollectionmessage.h>
       
    65 #include <mpxcollectionpath.h>
       
    66 #include <mpxcollectionplaylist.h>
       
    67 #include <mpxconstants.h>
       
    68 #include <mpxcollectionhelperfactory.h>
       
    69 #include <mpxcollectionplugin.hrh>
       
    70 #include <mpxinternalcrkeys.h>
       
    71 #include <mpxuser.h>
       
    72 #include <drmuihandling.h>
       
    73 #include <mpxplaybackutility.h>
       
    74 
       
    75 #include "mpxcommonuihelper.h"
       
    76 #include "mpxmetadataeditordialog.h"
       
    77 #include "mpxmetadataeditordialog.hrh"
       
    78 #include "mpxmetadataeditordialog.hlp.hrh"
       
    79 #include "mpxlog.h"
       
    80 #include <mpxmessagegeneraldefs.h>
       
    81 #include <mpxplaybackmessage.h>
       
    82 #include <caf/caferr.h>
       
    83 
       
    84 // CONSTANTS
       
    85 const TInt KMPXFileDetailsMaxTitleLen = 32;
       
    86 const TInt KMPXFileDetailsMaxBufferLen = 255;
       
    87 const TInt KMPXMinNumDateTrack = 0;
       
    88 const TInt KMPXFileDetailsExtraBufferLen = 10;
       
    89 
       
    90 const TInt KMPXMaxTimeLength = 36;
       
    91 const TInt KMPXMaxVal = 512;
       
    92 const TInt KMPXOneDigit = 10;
       
    93 const TInt KMPXTwoDigits = 100;
       
    94 
       
    95 const TInt KMPXBitrateFactor = 1000;
       
    96 const TInt KSecondInMilliseconds = 1000;
       
    97 const TInt KOneHourInSeconds = 3600;
       
    98 
       
    99 
       
   100 
       
   101 const TInt KDigitFive = 5;
       
   102 const TInt KDigitNine = 9;
       
   103 const TInt KDigitTen = 10;
       
   104 const TInt KDigitEleven = 11;
       
   105 const TInt KDigitFourTeen = 14;
       
   106 const TInt KDigitHundred = 100;
       
   107 
       
   108 const TInt KMaxDaysInOneMonths = 31;
       
   109 const TInt KMaxDaysInTwoMonths = 62;
       
   110 const TInt KMaxDaysInThreeMonths = 92;
       
   111 const TInt KMaxDaysInFourMonths = 123;
       
   112 const TInt KMaxDaysInFiveMonths = 153;
       
   113 const TInt KMaxDaysInSixMonths = 184;
       
   114 const TInt KMaxDaysInSevenMonths= 215;
       
   115 const TInt KMaxDaysInEightMonths = 245;
       
   116 const TInt KMaxDaysInNineMonths = 276;
       
   117 const TInt KMaxDaysInTenMonths = 306;
       
   118 const TInt KMaxDaysInElevenMonths = 337;
       
   119 const TInt KMaxDaysInTwelveMonths = 366;
       
   120 
       
   121 // MACROS
       
   122 _LIT( KMPXMetadataEditorRscPath, "mpxmetadataeditordialog.rsc" );
       
   123 _LIT( KMPXDrmManagerRscPath, "drmrightsmanager.rsc" );
       
   124 _LIT( KMPXSpace, " ");
       
   125 
       
   126 const TInt KMPXDurationDisplayResvLen( 10 );
       
   127 const TInt64 KSecondInMicroSeconds( 1000000 );
       
   128 
       
   129 // FUNCTION PROTOTYPES
       
   130 
       
   131 // ============================ MEMBER FUNCTIONS ===============================
       
   132 
       
   133 // ----------------------------------------------------------------------------
       
   134 // CMPXQueryDialog::NewL
       
   135 // Two-phased constructor.
       
   136 // ----------------------------------------------------------------------------
       
   137 //
       
   138 CMPXQueryDialog* CMPXQueryDialog::NewL()
       
   139     {
       
   140     CMPXQueryDialog* self = new (ELeave) CMPXQueryDialog();
       
   141     return self;
       
   142     }
       
   143 
       
   144 // ----------------------------------------------------------------------------
       
   145 // CMPXQueryDialog::OfferKeyEventL
       
   146 // Keyevent handler.
       
   147 // ----------------------------------------------------------------------------
       
   148 //
       
   149 TKeyResponse CMPXQueryDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
       
   150     {
       
   151     // exit from query dialog whever lost forground, currently implementing by mornitor
       
   152     // application key and end key
       
   153     if (( aKeyEvent.iScanCode == EStdKeyNo ||
       
   154         aKeyEvent.iScanCode == EStdKeyApplication0  &&
       
   155         aType == EEventKey ) ||
       
   156         ( aKeyEvent.iScanCode == EStdKeyApplication6  &&
       
   157         aType == EEventKeyDown ))
       
   158         {
       
   159         TryExitL(EEikBidCancel);
       
   160         return EKeyWasNotConsumed;
       
   161         }
       
   162     else
       
   163         {
       
   164         return CAknQueryDialog::OfferKeyEventL( aKeyEvent,aType );
       
   165         }
       
   166     }
       
   167 
       
   168 // ----------------------------------------------------------------------------
       
   169 // CMPXMetadataEditorDialog::NewL
       
   170 // Two-phased constructor.
       
   171 // ----------------------------------------------------------------------------
       
   172 //
       
   173 EXPORT_C CMPXMetadataEditorDialog* CMPXMetadataEditorDialog::NewL()
       
   174     {
       
   175     MPX_FUNC( "CMPXMetadataEditorDialog::NewL" );
       
   176     CMPXMetadataEditorDialog* self =
       
   177           new (ELeave) CMPXMetadataEditorDialog();
       
   178     CleanupStack::PushL(self);
       
   179     self->ConstructL();
       
   180     CleanupStack::Pop();
       
   181     return self;
       
   182     }
       
   183 
       
   184 // ----------------------------------------------------------------------------
       
   185 // CMPXMetadataEditorDialog::~CMPXMetadataEditorDialog
       
   186 // Destructor.
       
   187 // ----------------------------------------------------------------------------
       
   188 //
       
   189 EXPORT_C CMPXMetadataEditorDialog::~CMPXMetadataEditorDialog()
       
   190     {
       
   191     MPX_FUNC( "CMPXMetadataEditorDialog::~CMPXMetadataEditorDialog" );
       
   192     delete iEmptyNaviDecorator;
       
   193     delete iTitlePaneText;
       
   194     delete iCommonUiHelper;
       
   195     delete iParam;
       
   196     delete iIdle;
       
   197     delete iDrmInfo;
       
   198     if ( iPlaybackUtility ) 
       
   199         { 
       
   200         iPlaybackUtility->RemoveObserverL( *this ); 
       
   201         iPlaybackUtility->CancelRequest(); 
       
   202         iPlaybackUtility->Close(); 
       
   203         } 
       
   204     if ( iCollectionUtility )
       
   205         {
       
   206         iCollectionUtility->Close();
       
   207         }
       
   208     if ( iCollectionUiHelper )
       
   209         {
       
   210         iCollectionUiHelper->Close();
       
   211         }
       
   212     if ( iMedia )
       
   213         {
       
   214         delete iMedia;
       
   215         }
       
   216     if ( iTextValues )
       
   217         {
       
   218         delete iTextValues;
       
   219         }
       
   220     if ( iValueTextArray )
       
   221         {
       
   222         delete iValueTextArray;
       
   223         }
       
   224     if ( iGenreArr )
       
   225         {
       
   226         delete iGenreArr;
       
   227         }
       
   228     if ( iLibraryTextValues )
       
   229         {
       
   230         delete iLibraryTextValues;
       
   231         }
       
   232     if ( iLibraryValueTextArray )
       
   233         {
       
   234         delete iLibraryValueTextArray;
       
   235         }
       
   236     if ( iLibraryArr )
       
   237         {
       
   238         delete iLibraryArr;
       
   239         }
       
   240     if ( iResourceOffset )
       
   241         {
       
   242         iEikonEnv->DeleteResourceFile( iResourceOffset );
       
   243         }
       
   244     if ( iDrmResourceOffset )
       
   245         {
       
   246         iEikonEnv->DeleteResourceFile( iDrmResourceOffset );
       
   247         }
       
   248     if(iDrmUiHandler)
       
   249         {
       
   250         delete iDrmUiHandler;
       
   251         }
       
   252     }
       
   253 
       
   254 // ----------------------------------------------------------------------------
       
   255 // CMPXMetadataEditorDialog::SetParamL
       
   256 // parameter passed in from viewframework
       
   257 // ----------------------------------------------------------------------------
       
   258 //
       
   259 EXPORT_C void CMPXMetadataEditorDialog::SetParamL( const TDesC* aParam )
       
   260     {
       
   261     MPX_FUNC( "CMPXMetadataEditorDialog::SetParamL" );
       
   262     delete iParam;
       
   263     iParam = NULL;
       
   264     iParam = aParam->AllocL();
       
   265     }
       
   266 
       
   267 // -----------------------------------------------------------------------------
       
   268 // CMPXMetadataEditorDialog::OkToExitL
       
   269 // This function ALWAYS returns ETrue
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 TBool CMPXMetadataEditorDialog::OkToExitL(TInt aButtonId)
       
   273     {
       
   274     MPX_FUNC( "CMPXMetadataEditorDialog::OkToExitL" );
       
   275     TBool res = EFalse;
       
   276 
       
   277     switch ( aButtonId )
       
   278         {
       
   279         case EAknSoftkeyDone:
       
   280             {
       
   281             SaveFormDataL();
       
   282             RestoreNaviLabelL();
       
   283             RestoreTitlePaneL();
       
   284             res = ETrue;
       
   285             break;
       
   286             }
       
   287         case EAknSoftkeyBack:
       
   288         case EAknSoftkeyExit:
       
   289             {
       
   290             RestoreNaviLabelL();
       
   291             RestoreTitlePaneL();
       
   292             res = ETrue;
       
   293             break;
       
   294             }
       
   295         case EAknSoftkeyOptions:
       
   296         default:
       
   297             {
       
   298             // display the options menu
       
   299             res = CAknForm::OkToExitL( aButtonId );
       
   300             break;
       
   301             }
       
   302         }
       
   303     return res;
       
   304     }
       
   305 
       
   306 // -----------------------------------------------------------------------------
       
   307 // CMPXMetadataEditorDialog::ExecuteLD
       
   308 // -----------------------------------------------------------------------------
       
   309 //
       
   310 TInt CMPXMetadataEditorDialog::ExecuteLD( TInt /*aResourceId*/ )
       
   311     {
       
   312     MPX_FUNC( "CMPXMetadataEditorDialog::ExecuteLD" );
       
   313     TInt resId = R_MPX_CUI_SONG_DETAILS_DIALOG;
       
   314     if ( iCurrentLibrary == EMPXMetadataEditorDlgPodcast )
       
   315         {
       
   316         resId = R_MPX_CUI_PODCAST_DETAILS_DIALOG;
       
   317         }
       
   318     else if( iDisablePodcasting )
       
   319         {
       
   320         resId = R_MPX_CUI_SONG_DETAILS_DIALOG_NO_MOVE_LIBRARY;
       
   321         }
       
   322     return CAknForm::ExecuteLD( resId );
       
   323     }
       
   324 
       
   325 // -----------------------------------------------------------------------------
       
   326 // CMPXMetadataEditorDialog::ViewFileDetailsPopupL
       
   327 // Display file details popup window
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 void CMPXMetadataEditorDialog::ViewFileDetailsPopupL()
       
   331     {
       
   332     MPX_FUNC( "CMPXMetadataEditorDialog::ViewFileDetailsPopupL" );
       
   333     CAknDoublePopupMenuStyleListBox* listBox =
       
   334         new (ELeave) CAknDoublePopupMenuStyleListBox();
       
   335     CleanupStack::PushL( listBox );
       
   336     CAknPopupList* popupList = CAknPopupList::NewL(
       
   337                                 listBox,
       
   338                                 R_AVKON_SOFTKEYS_OK_EMPTY,
       
   339                                 AknPopupLayouts::EMenuDoubleWindow );
       
   340     CleanupStack::PushL( popupList );
       
   341 
       
   342     listBox->ConstructL( popupList, CEikListBox::ELeftDownInViewRect );
       
   343     listBox->CreateScrollBarFrameL( ETrue );
       
   344     listBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   345         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   346 
       
   347     // Enable Marquee
       
   348     static_cast<CEikFormattedCellListBox*>
       
   349         ( listBox )->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
       
   350 
       
   351     // Retrieve heading array
       
   352     CDesCArrayFlat* headingsArray = NULL;
       
   353     TInt itemCount = 0;
       
   354     if ( iCurrentLibrary == EMPXMetadataEditorDlgCollection )
       
   355         {
       
   356         headingsArray = iCoeEnv->ReadDesCArrayResourceL(
       
   357             R_MPX_CUI_FD_HEADINGS_SONGS );
       
   358         itemCount = EMPXSongsFileDetailsHeadingCount;
       
   359         }
       
   360     else if ( iCurrentLibrary == EMPXMetadataEditorDlgPodcast )
       
   361         {
       
   362         headingsArray = iCoeEnv->ReadDesCArrayResourceL(
       
   363             R_MPX_CUI_FD_HEADINGS_PODCASTS );
       
   364         itemCount = EMPXPodcastsFileDetailsHeadingCount;
       
   365         }
       
   366     else
       
   367         {
       
   368         User::Leave( KErrArgument );
       
   369         }
       
   370     CleanupStack::PushL( headingsArray );
       
   371 
       
   372     CAknLocalScreenClearer* clearer = CAknLocalScreenClearer::NewLC( EFalse );
       
   373     CDesCArray* itemArray =
       
   374         static_cast<CDesCArray*>( listBox->Model()->ItemTextArray() );
       
   375     CDesCArrayFlat* dataArray =
       
   376         new ( ELeave ) CDesCArrayFlat( itemCount );
       
   377     CleanupStack::PushL( dataArray );
       
   378 
       
   379     if ( iMedia )
       
   380         {
       
   381         PopulateFileDetailsL( headingsArray, dataArray );
       
   382         // item count might have been updated due to addition of
       
   383         // DRM content details
       
   384         itemCount = headingsArray->MdcaCount();
       
   385         }
       
   386     else
       
   387         {
       
   388         // properties not available
       
   389         for ( TInt i = 0; i < itemCount; i++ )
       
   390             {
       
   391             dataArray->AppendL( KNullDesC );
       
   392             }
       
   393         }
       
   394 
       
   395     for ( TInt i = 0; i < itemCount; i++ )
       
   396         {
       
   397         AddItemToListBoxL( headingsArray->MdcaPoint( i ), dataArray->MdcaPoint( i ), itemArray );
       
   398         }
       
   399     CleanupStack::PopAndDestroy( dataArray );
       
   400     CleanupStack::PopAndDestroy( clearer );
       
   401     CleanupStack::PopAndDestroy( headingsArray );
       
   402 
       
   403     // Set title
       
   404     TBuf<KMPXFileDetailsMaxTitleLen> title;
       
   405     iCoeEnv->ReadResourceL( title, R_MPX_CUI_FD_TITLE );
       
   406     popupList->SetTitleL( title );
       
   407 
       
   408     // Show popup list
       
   409     popupList->ExecuteLD();
       
   410     CleanupStack::Pop();
       
   411     CleanupStack::PopAndDestroy( listBox );
       
   412     }
       
   413 
       
   414 // ---------------------------------------------------------------------------
       
   415 // From MMPXCollectionObserver
       
   416 // Handle collection message.
       
   417 // ---------------------------------------------------------------------------
       
   418 //
       
   419 void CMPXMetadataEditorDialog::HandleCollectionMessage(
       
   420     CMPXMessage* /*aMessage*/, TInt /*aError*/ )
       
   421     {
       
   422     // do nothing
       
   423     }
       
   424 
       
   425 // ---------------------------------------------------------------------------
       
   426 // From MMPXCollectionObserver
       
   427 // Handles the collection entries being opened. Typically called
       
   428 // when client has Open()'d a folder
       
   429 // ---------------------------------------------------------------------------
       
   430 //
       
   431 void CMPXMetadataEditorDialog::HandleOpenL(
       
   432     const CMPXMedia& /*aEntries*/,
       
   433     TInt /*aIndex*/, TBool /*aComplete*/, TInt /*aError*/ )
       
   434     {
       
   435     // do nothing
       
   436     }
       
   437 
       
   438 // ---------------------------------------------------------------------------
       
   439 // From MMPXCollectionObserver
       
   440 // Handles the item being opened. Typically called
       
   441 // when client has Open()'d an item. Client typically responds by
       
   442 // 'playing' the item via the playlist
       
   443 // ---------------------------------------------------------------------------
       
   444 //
       
   445 void CMPXMetadataEditorDialog::HandleOpenL(
       
   446     const CMPXCollectionPlaylist& /*aPlaylist*/, TInt /*aError*/ )
       
   447     {
       
   448     // do nothing
       
   449     }
       
   450 
       
   451 // ---------------------------------------------------------------------------
       
   452 // From MMPXCollectionObserver
       
   453 // Handle media properties.
       
   454 // Notes: The client is responsible for delete the object of aMedia.
       
   455 // ---------------------------------------------------------------------------
       
   456 //
       
   457 void CMPXMetadataEditorDialog::HandleCollectionMediaL(
       
   458     const CMPXMedia& aMedia,
       
   459     TInt aError )
       
   460     {
       
   461     MPX_FUNC( "CMPXMetadataEditorDialog::HandleCollectionMediaL" );
       
   462     TRAP_IGNORE( DoHandleMediaL( aMedia, aError ) );
       
   463     }
       
   464 
       
   465 // ----------------------------------------------------------------------------
       
   466 // CMPXMetadataEditorDialog::CMPXMetadataEditorDialog
       
   467 // C++ default constructor can NOT contain any code, that
       
   468 // might leave.
       
   469 // ----------------------------------------------------------------------------
       
   470 //
       
   471 CMPXMetadataEditorDialog::CMPXMetadataEditorDialog()
       
   472     {
       
   473     // do nothing
       
   474     }
       
   475 
       
   476 // ----------------------------------------------------------------------------
       
   477 // CMPXMetadataEditorDialog::ConstructL
       
   478 // Symbian 2nd phase constructor can leave.
       
   479 // ----------------------------------------------------------------------------
       
   480 //
       
   481 void CMPXMetadataEditorDialog::ConstructL()
       
   482     {
       
   483     MPX_FUNC( "CMPXMetadataEditorDialog::ConstructL" );
       
   484 
       
   485     CCoeEnv* coeEnv = iEikonEnv;
       
   486     TParse parse;
       
   487     parse.Set( KMPXMetadataEditorRscPath, &KDC_APP_RESOURCE_DIR, NULL );
       
   488     TFileName resourceFile( parse.FullName() );
       
   489     User::LeaveIfError( MPXUser::CompleteWithDllPath( resourceFile ) );
       
   490     BaflUtils::NearestLanguageFile( coeEnv->FsSession(), resourceFile );
       
   491     iResourceOffset = coeEnv->AddResourceFileL( resourceFile );
       
   492 
       
   493     parse.Set( KMPXDrmManagerRscPath, &KDC_APP_RESOURCE_DIR, NULL );
       
   494     TFileName drmResourceFile( parse.FullName() );
       
   495     User::LeaveIfError( MPXUser::CompleteWithDllPath( drmResourceFile ) );
       
   496     BaflUtils::NearestLanguageFile( coeEnv->FsSession(), drmResourceFile );
       
   497     TRAPD(drmResourceError,iDrmResourceOffset = coeEnv->AddResourceFileL( drmResourceFile ));
       
   498     iDrmDetails = (drmResourceError == KErrNone) ? ETrue: EFalse;
       
   499 
       
   500     iCollectionUtility = MMPXCollectionUtility::NewL( this, KMcModeDefault );
       
   501     iCommonUiHelper = CMPXCommonUiHelper::NewL();
       
   502     
       
   503     CAknForm::ConstructL( R_MPX_CUI_SONG_DETAILS_MENUBAR );
       
   504 
       
   505     iCurrentLibrary = EMPXMetadataEditorDlgCollection;
       
   506     // check if it's podcast collection
       
   507     CMPXCollectionPath* cpath = iCollectionUtility->Collection().PathL();
       
   508     CleanupStack::PushL( cpath );
       
   509     if ( cpath->Levels() > 0 )
       
   510         {
       
   511         RArray<TUid> ary;
       
   512         CleanupClosePushL( ary );
       
   513         ary.AppendL( TUid::Uid(EMPXCollectionPluginPodCast) );
       
   514         TUid podcastUid = iCollectionUtility->CollectionIDL( ary.Array() );
       
   515         CleanupStack::PopAndDestroy( &ary );
       
   516 
       
   517         if ( cpath->Id( 0 ) == podcastUid.iUid )
       
   518             {
       
   519             MPX_DEBUG1( "CMPXMetadataEditorDialog::ConstructL Podcast collection" );
       
   520             iCurrentLibrary = EMPXMetadataEditorDlgPodcast;
       
   521             }
       
   522         }
       
   523     iCollectionUiHelper = CMPXCollectionHelperFactory::NewCollectionUiHelperL();
       
   524     CleanupStack::PopAndDestroy( cpath );
       
   525 
       
   526     // Get podcasting key
       
   527     TInt val(0);
       
   528     CRepository* repository = CRepository::NewL( KCRUidMPXMPFeatures );
       
   529     repository->Get( KMPXMPLocalVariation, val );
       
   530     iDisablePodcasting = val&KMPXDisablePodcastingOption ? ETrue : EFalse;
       
   531     delete repository;
       
   532     
       
   533     //DRM information popup
       
   534     iDrmUiHandler = DRM::CDrmUiHandling::NewL();
       
   535     }
       
   536 
       
   537 // -----------------------------------------------------------------------------
       
   538 // CMPXMetadataEditorDialog::CleanUpGenreText
       
   539 // Clean up function for genre related members.
       
   540 // -----------------------------------------------------------------------------
       
   541 //
       
   542 void CMPXMetadataEditorDialog::CleanUpGenreText()
       
   543     {
       
   544     MPX_FUNC( "CMPXMetadataEditorDialog::CleanUpGenreText" );
       
   545 
       
   546     if ( iGenreArr )
       
   547         {
       
   548         delete iGenreArr;
       
   549         iGenreArr = NULL;
       
   550         }
       
   551     if ( iValueTextArray )
       
   552         {
       
   553         delete iValueTextArray;
       
   554         iValueTextArray = NULL;
       
   555         }
       
   556     if ( iTextValues )
       
   557         {
       
   558         delete iTextValues;
       
   559         iTextValues = NULL;
       
   560         }
       
   561     }
       
   562 
       
   563 // -----------------------------------------------------------------------------
       
   564 // CMPXMetadataEditorDialog::FetchGenreL
       
   565 // Populates genre popup with genre list for tracks.
       
   566 // -----------------------------------------------------------------------------
       
   567 //
       
   568 void CMPXMetadataEditorDialog::FetchGenreL()
       
   569     {
       
   570     MPX_FUNC( "CMPXMetadataEditorDialog::FetchGenreL" );
       
   571     RArray<TMPXAttribute> attrs;
       
   572     CleanupClosePushL( attrs );
       
   573     attrs.Append( KMPXMediaGeneralTitle );
       
   574     CMPXMedia* criteria = CMPXMedia::NewL();
       
   575     CleanupStack::PushL( criteria );
       
   576     criteria->SetTObjectValueL<TUid>(
       
   577         KMPXMediaGeneralCollectionId, TUid::Uid( 0x101FFC3A ) );
       
   578     criteria->SetTObjectValueL<TMPXGeneralType>(
       
   579         KMPXMediaGeneralType, EMPXGroup );
       
   580     criteria->SetTObjectValueL<TMPXGeneralCategory>(
       
   581         KMPXMediaGeneralCategory, EMPXGenre );
       
   582     iCollectionUtility->Collection().FindAllL( *criteria, attrs.Array(), *this );
       
   583     CleanupStack::PopAndDestroy( criteria );
       
   584     CleanupStack::PopAndDestroy( &attrs );
       
   585     }
       
   586 
       
   587 // ---------------------------------------------------------------------------
       
   588 // Handle media properties.
       
   589 // ---------------------------------------------------------------------------
       
   590 //
       
   591 void CMPXMetadataEditorDialog::DoHandleMediaL(
       
   592     const CMPXMedia& aMedia,
       
   593     TInt aError )
       
   594     {
       
   595     MPX_FUNC( "CMPXMetadataEditorDialog::DoHandleMediaL" );
       
   596 
       
   597     if ( iCurrentMediaLOp == EMPXMetadataEditorGetSongInfo )
       
   598         {
       
   599         delete iMedia;
       
   600         iMedia = NULL;
       
   601         if ( aError == KErrNone )
       
   602             {
       
   603             iMedia = CMPXMedia::NewL( aMedia );
       
   604             // common for both music and podcast
       
   605             // Fetch the artist
       
   606 
       
   607             if ( iMedia->IsSupported( KMPXMediaDrmProtected ) )
       
   608                 {
       
   609                 iIsDrmProtected = iMedia->ValueTObjectL<TBool>( KMPXMediaDrmProtected );
       
   610                 }
       
   611 
       
   612             SetControlTextL( EMPXMetadataEditorDlgCtrlIdArtist,
       
   613                 iMedia->ValueText( KMPXMediaMusicArtist ), KNullDesC );
       
   614 
       
   615             // Fetch the album
       
   616             SetControlTextL( EMPXMetadataEditorDlgCtrlIdAlbum,
       
   617                 iMedia->ValueText( KMPXMediaMusicAlbum ), KNullDesC );
       
   618 
       
   619             // Fetch the track number
       
   620             SetControlNumberL( EMPXMetadataEditorDlgCtrlIdTrackNumber,
       
   621                 iMedia->ValueText( KMPXMediaMusicAlbumTrack ),
       
   622                 KMPXSongDetailsTrackNumMin, KMPXSongDetailsTrackNumMax );
       
   623 				
       
   624            // Fetch the genre
       
   625            SetControlTextL( EMPXMetadataEditorDlgCtrlIdGenre,
       
   626               iMedia->ValueText( KMPXMediaMusicGenre ), KNullDesC );  
       
   627 
       
   628             // Fetch the year
       
   629             TInt64 year(0);
       
   630             if ( iMedia->IsSupported (KMPXMediaMusicYear ) )
       
   631                 {
       
   632                 year = iMedia->ValueTObjectL<TInt64>( KMPXMediaMusicYear );
       
   633                 }
       
   634             TTime yearTime( year);
       
   635             iYear = yearTime.DateTime().Year ( );
       
   636             HBufC* yearBuf = HBufC::NewLC ( KMPXMaxTimeLength );
       
   637             if ( iYear > 0)
       
   638                 {    
       
   639                 yearBuf->Des().AppendNum ( iYear );
       
   640                 }
       
   641             SetControlNumberL ( EMPXMetadataEditorDlgCtrlIdYear, *yearBuf,
       
   642                     KMPXSongDetailsYearMin, KMPXSongDetailsYearMax );
       
   643             CleanupStack::PopAndDestroy ( yearBuf );
       
   644 
       
   645            
       
   646             // Fetch the comment
       
   647             SetControlTextL( EMPXMetadataEditorDlgCtrlIdComment,
       
   648                 iMedia->ValueText( KMPXMediaGeneralComment ), KNullDesC );
       
   649 
       
   650             // Fetch the song name
       
   651             TParsePtrC fileDetail( iMedia->ValueText( KMPXMediaGeneralUri ) );
       
   652             SetControlTextL( EMPXMetadataEditorDlgCtrlIdSongName,
       
   653                 iMedia->ValueText( KMPXMediaGeneralTitle ), fileDetail.Name() );
       
   654 
       
   655             if ( iCurrentLibrary == EMPXMetadataEditorDlgCollection )
       
   656                 {
       
   657                 // Fetch the composer
       
   658                 SetControlTextL( EMPXMetadataEditorDlgCtrlIdComposer,
       
   659                     iMedia->ValueText( KMPXMediaMusicComposer ), KNullDesC );
       
   660                 }
       
   661 
       
   662             PopulateFileDetailsL();            
       
   663             DrawNow();
       
   664             }
       
   665         else
       
   666             {
       
   667             // if error getting metadata, exit editor
       
   668             iCommonUiHelper->HandleErrorL( aError );
       
   669             if ( iIdle )
       
   670                 {
       
   671                 iIdle->Cancel();
       
   672                 delete iIdle;
       
   673                 iIdle = NULL;
       
   674                 }
       
   675             iIdle = CIdle::NewL( CActive::EPriorityStandard );
       
   676             iIdle->Start( TCallBack( CMPXMetadataEditorDialog::DeferredExitCallback, this ) );
       
   677             }
       
   678         }
       
   679     else if ( iCurrentMediaLOp == EMPXMetadataEditorGetDrmInfo )
       
   680         {
       
   681         delete iDrmInfo;
       
   682         iDrmInfo = NULL;
       
   683         if ( aError == KErrNone )
       
   684             {
       
   685             iDrmInfo = CMPXMedia::NewL( aMedia );
       
   686             }
       
   687         else
       
   688             {
       
   689             iDrmInfo = CMPXMedia::NewL();
       
   690             }
       
   691         if ( iIdle )
       
   692             {
       
   693             iIdle->Cancel();
       
   694             delete iIdle;
       
   695             iIdle = NULL;
       
   696             }
       
   697         iIdle = CIdle::NewL( CActive::EPriorityStandard );
       
   698         iIdle->Start( TCallBack( CMPXMetadataEditorDialog::DeferredFileDetailsCallback, this ) );
       
   699         }
       
   700     else
       
   701         {
       
   702         // Should not reach here
       
   703         ASSERT( 0 );
       
   704         }
       
   705     iCurrentMediaLOp = EMPXMetadataEditorIdle;
       
   706     }
       
   707 
       
   708 // ----------------------------------------------------------------------------
       
   709 // CMPXMetadataEditorDialog::SaveFormDataL
       
   710 // Save form data.
       
   711 // ----------------------------------------------------------------------------
       
   712 //
       
   713 TBool CMPXMetadataEditorDialog::SaveFormDataL()
       
   714     {
       
   715     MPX_FUNC( "CMPXMetadataEditorDialog::SaveFormDataL" );
       
   716     if ( iMedia )
       
   717         {
       
   718         MPX_DEBUG1( "CMPXMetadataEditorDialog::SaveFormDataL Saving.." );
       
   719         CMPXMedia* media = CMPXMedia::NewL();
       
   720         CleanupStack::PushL( media );
       
   721 
       
   722         TBool changed = EFalse;
       
   723 
       
   724         // common to both music and podcast
       
   725         // update local copy of media as well because getting media prop is slow
       
   726         changed = UpdateMediaObjectWithControlL( EMPXMetadataEditorDlgCtrlIdSongName,
       
   727             media, KMPXMediaGeneralTitle );
       
   728 
       
   729         changed = UpdateMediaObjectWithControlL( EMPXMetadataEditorDlgCtrlIdArtist,
       
   730             media, KMPXMediaMusicArtist ) || changed;
       
   731 
       
   732         changed = UpdateMediaObjectWithControlL( EMPXMetadataEditorDlgCtrlIdAlbum,
       
   733             media, KMPXMediaMusicAlbum ) || changed;
       
   734 
       
   735         changed = UpdateMediaObjectWithControlL( EMPXMetadataEditorDlgCtrlIdTrackNumber,
       
   736             media, KMPXMediaMusicAlbumTrack ) || changed;
       
   737 
       
   738         changed = UpdateMediaObjectWithControlL( EMPXMetadataEditorDlgCtrlIdComment,
       
   739             media, KMPXMediaGeneralComment ) || changed;
       
   740 
       
   741         // special handling needed for year
       
   742         CCoeControl* coeControl = ControlOrNull( EMPXMetadataEditorDlgCtrlIdYear );
       
   743         if ( coeControl )
       
   744             {
       
   745             CEikEdwin* control = static_cast<CEikEdwin*>( coeControl );
       
   746             if ( control )
       
   747                 {
       
   748                 TBuf<KMPXSongDetailsNumTextWidth> num;
       
   749                 control->GetText( num );
       
   750                 TLex numLex( num );
       
   751                 TInt LexToInt;
       
   752                 numLex.Val( LexToInt );
       
   753                 if ( LexToInt != iYear )
       
   754                     {
       
   755                     MPX_DEBUG3( "CMPXMetadataEditorDialog::SaveFormDataL year changed from %d to %d", iYear, num );
       
   756                     TDateTime newYear;
       
   757                     newYear.Set( LexToInt, EJanuary, 0, 0, 0, 0, 0 );
       
   758                     TTime year( newYear );
       
   759                     iMedia->SetTObjectValueL<TInt64>(
       
   760                         KMPXMediaMusicYear, year.Int64() );
       
   761                     media->SetTObjectValueL<TInt64>(
       
   762                         KMPXMediaMusicYear, year.Int64() );
       
   763                     iYear = LexToInt;
       
   764                     changed = ETrue;
       
   765                     }
       
   766                 else
       
   767                     {
       
   768                     MPX_DEBUG1( "CMPXMetadataEditorDialog::SaveFormDataL year not changed" );
       
   769                     }
       
   770                 }
       
   771             }
       
   772 
       
   773         if ( iCurrentLibrary == EMPXMetadataEditorDlgCollection )
       
   774             {
       
   775             changed = UpdateMediaObjectWithControlL( EMPXMetadataEditorDlgCtrlIdComposer,
       
   776                 media, KMPXMediaMusicComposer ) || changed;
       
   777             }
       
   778         else if ( iCurrentLibrary == EMPXMetadataEditorDlgPodcast )
       
   779             {
       
   780             // no special handling, all covered in common
       
   781             }
       
   782         if ( changed )
       
   783             {
       
   784             // save it back to collection engine
       
   785             SaveMediaPropertiesL( media );
       
   786             MPX_DEBUG1( "CMPXMetadataEditorDialog::SaveFormDataL Saved" );
       
   787             }
       
   788 #ifdef _DEBUG
       
   789         else
       
   790             {
       
   791             MPX_DEBUG1( "CMPXMetadataEditorDialog::SaveFormDataL All equal, not saved" );
       
   792             }
       
   793 #endif
       
   794         CleanupStack::PopAndDestroy( media );
       
   795         }
       
   796     return ETrue;
       
   797     }
       
   798 
       
   799 // ----------------------------------------------------------------------------
       
   800 // CMPXMetadataEditorDialog::DoNotSaveFormDataL
       
   801 // Does not save form data.
       
   802 // ----------------------------------------------------------------------------
       
   803 //
       
   804 void CMPXMetadataEditorDialog::DoNotSaveFormDataL()
       
   805     {
       
   806     // Do nothing
       
   807     }
       
   808 
       
   809 // -----------------------------------------------------------------------------
       
   810 // CMPXMetadataEditorDialog::SetTitlePane
       
   811 // Set Title Pane from descriptor.
       
   812 // -----------------------------------------------------------------------------
       
   813 //
       
   814 void CMPXMetadataEditorDialog::SetTitlePaneL()
       
   815     {
       
   816     MPX_FUNC( "CMPXMetadataEditorDialog::SetTitlePaneL" );
       
   817     // Saving the current title before it's overwritten
       
   818     CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
       
   819 
       
   820     iTitlePane =
       
   821         static_cast<CAknTitlePane*>
       
   822             ( statusPane->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   823     const TDesC* text = iTitlePane->Text();
       
   824     iTitlePaneText = text->AllocL();
       
   825 
       
   826     HBufC* newText = NULL;
       
   827     if ( iCurrentLibrary == EMPXMetadataEditorDlgCollection )
       
   828         {
       
   829         newText = StringLoader::LoadLC( R_MPX_CUI_SONG_DETAILS_TITLE );
       
   830         }
       
   831     else if ( iCurrentLibrary == EMPXMetadataEditorDlgPodcast )
       
   832         {
       
   833         newText = StringLoader::LoadLC( R_MPX_CUI_SONG_DETAILS_EPISODE );
       
   834         }
       
   835 
       
   836     // Update Title Pane
       
   837     if ( newText )
       
   838         {
       
   839         iTitlePane->SetTextL( *newText );
       
   840         }
       
   841     CleanupStack::PopAndDestroy( newText );
       
   842     }
       
   843 
       
   844 // -----------------------------------------------------------------------------
       
   845 // CMPXMetadataEditorDialog::RestoreTitlePane
       
   846 // Restore Title Pane from the member data.
       
   847 // -----------------------------------------------------------------------------
       
   848 //
       
   849 void CMPXMetadataEditorDialog::RestoreTitlePaneL()
       
   850     {
       
   851     MPX_FUNC( "CMPXMetadataEditorDialog::RestoreTitlePaneL" );
       
   852     // Update Title Pane
       
   853     iTitlePane->SetTextL( *iTitlePaneText );
       
   854     }
       
   855 
       
   856 // -----------------------------------------------------------------------------
       
   857 // CMPXMetadataEditorDialog::SetNaviLabelL
       
   858 // Set Navi Label from descriptor.
       
   859 // -----------------------------------------------------------------------------
       
   860 //
       
   861 void CMPXMetadataEditorDialog::SetNaviLabelL()
       
   862     {
       
   863     MPX_FUNC( "CMPXMetadataEditorDialog::SetNaviLabelL" );
       
   864     MAknEditingStateIndicator *editingStateIndicator = CAknEnv::Static()->EditingStateIndicator();
       
   865     CAknIndicatorContainer* indicContainerEditing = editingStateIndicator->IndicatorContainer();
       
   866     indicContainerEditing->SetIndicatorValueL( TUid::Uid( EAknNaviPaneEditorIndicatorMessageInfo), KNullDesC );
       
   867     // Saving the current title before it's overwritten
       
   868     CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
       
   869 
       
   870     iNaviPane = static_cast<CAknNavigationControlContainer*>
       
   871         ( statusPane->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
   872 
       
   873     // store the latest navi pane
       
   874     iNaviDecorator = iNaviPane->Top();
       
   875     
       
   876     if(iNaviDecorator)
       
   877         {   
       
   878         // set the new navi label
       
   879         iEmptyNaviDecorator =
       
   880         iNaviPane->CreateNavigationLabelL(KNullDesC);
       
   881 
       
   882         iNaviPane->PushL( *iEmptyNaviDecorator );
       
   883         }
       
   884     }
       
   885 
       
   886 // -----------------------------------------------------------------------------
       
   887 // CMPXMetadataEditorDialog::RestoreNaviLabelL
       
   888 // Restore Navi Label from the member data.
       
   889 // -----------------------------------------------------------------------------
       
   890 //
       
   891 void CMPXMetadataEditorDialog::RestoreNaviLabelL()
       
   892     {
       
   893     MPX_FUNC( "CMPXMetadataEditorDialog::RestoreNaviLabelL" );
       
   894     iNaviPane->Pop( iEmptyNaviDecorator ); // pop out the empty navi
       
   895     if ( iNaviDecorator )
       
   896         {
       
   897         iNaviPane->PushL( *iNaviDecorator );
       
   898         }
       
   899     }
       
   900 
       
   901 // -----------------------------------------------------------------------------
       
   902 // CMPXMetadataEditorDialog::DynInitMenuPaneL
       
   903 // Dynamically initialises a menu pane.
       
   904 // (other items were commented in a header).
       
   905 // -----------------------------------------------------------------------------
       
   906 //
       
   907 void CMPXMetadataEditorDialog::DynInitMenuPaneL(
       
   908     TInt aResourceId,
       
   909     CEikMenuPane* aMenuPane)
       
   910     {
       
   911     MPX_FUNC( "CMPXMetadataEditorDialog::DynInitMenuPaneL" );
       
   912     CAknForm::DynInitMenuPaneL(aResourceId, aMenuPane);
       
   913 
       
   914     if ( aResourceId == R_AVKON_FORM_MENUPANE )
       
   915         {
       
   916         if ( ( IdOfFocusControl() == EMPXMetadataEditorDlgCtrlIdGenre ) ||
       
   917             ( IdOfFocusControl() == EMPXMetadataEditorDlgCtrlIdLibrary ) )
       
   918             {
       
   919             aMenuPane->SetItemDimmed( EMPXCmdSongDetailsChange, ETrue );
       
   920             }
       
   921         else
       
   922             {
       
   923             aMenuPane->SetItemDimmed( EMPXCmdSongDetailsChange, ETrue );
       
   924             }
       
   925         aMenuPane->SetItemDimmed( EMPXCmdSongDetails, ETrue );
       
   926         
       
   927         // Dim out the Avkon menu items
       
   928         aMenuPane->SetItemDimmed( EAknFormCmdEdit, ETrue );
       
   929         aMenuPane->SetItemDimmed( EAknFormCmdAdd, ETrue );
       
   930         aMenuPane->SetItemDimmed( EAknFormCmdSave, ETrue );
       
   931         aMenuPane->SetItemDimmed( EAknFormCmdLabel, ETrue );
       
   932         aMenuPane->SetItemDimmed( EAknFormCmdDelete, ETrue );
       
   933         }
       
   934     }
       
   935 
       
   936 // ----------------------------------------------------------------------------
       
   937 // CMPXMetadataEditorDialog::ProcessCommandL
       
   938 // Act on the menu selection if menu is showing.
       
   939 // ----------------------------------------------------------------------------
       
   940 //
       
   941 void CMPXMetadataEditorDialog::ProcessCommandL( TInt aCommandId )
       
   942     {
       
   943     MPX_FUNC( "CMPXMetadataEditorDialog::ProcessCommandL" );
       
   944     CAknForm::ProcessCommandL(aCommandId);
       
   945 
       
   946     switch (aCommandId)
       
   947         {
       
   948         case EMPXCmdSongDetailsChange:
       
   949             {
       
   950             if ( IdOfFocusControl() == EMPXMetadataEditorDlgCtrlIdGenre )
       
   951                 {
       
   952                 iPopup = static_cast<CAknPopupField*>
       
   953                     ( ControlOrNull( EMPXMetadataEditorDlgCtrlIdGenre ) );
       
   954                 }
       
   955             else if ( IdOfFocusControl() == EMPXMetadataEditorDlgCtrlIdLibrary )
       
   956                 {
       
   957                 iPopup = static_cast<CAknPopupField*>
       
   958                     ( ControlOrNull( EMPXMetadataEditorDlgCtrlIdLibrary ) );
       
   959                 }
       
   960             if ( iPopup )
       
   961                 {
       
   962                 iPopup->ActivateSelectionListL();
       
   963                 }
       
   964 
       
   965             break;
       
   966             }
       
   967         case EMPXCmdSongDetails:
       
   968             {
       
   969             if ( iIsDrmProtected && !iDrmInfo )
       
   970                 {
       
   971                 CMPXCollectionPath* cpath = iCollectionUtility->Collection().PathL();
       
   972                 CleanupStack::PushL( cpath );
       
   973                 if ( iParam )
       
   974                     {
       
   975                     TLex yearLex( iParam->Des() );
       
   976                     TInt lexToInt = NULL;
       
   977                     if ( yearLex.Val( lexToInt ) == KErrNone )
       
   978                         {
       
   979                         cpath->Set( lexToInt );
       
   980                         RArray<TMPXAttribute> attrs;
       
   981                         CleanupClosePushL(attrs);
       
   982                         attrs.Append( KMPXMediaGeneralUri );
       
   983                         attrs.Append( KMPXMediaDrmAll );
       
   984                         iCurrentMediaLOp = EMPXMetadataEditorGetDrmInfo;
       
   985                         iCollectionUtility->Collection().MediaL( *cpath, attrs.Array() );
       
   986                         CleanupStack::PopAndDestroy( &attrs );
       
   987                         }
       
   988                     }
       
   989                 CleanupStack::PopAndDestroy( cpath );
       
   990                 }
       
   991             else
       
   992                 {
       
   993                 if( iMedia )
       
   994                     {
       
   995                     ViewFileDetailsPopupL();
       
   996                     }
       
   997                 }
       
   998             break;
       
   999             }
       
  1000         case EAknCmdHelp:
       
  1001             {
       
  1002             TCoeHelpContext helpContext;
       
  1003             GetHelpContext( helpContext );
       
  1004 
       
  1005             CArrayFixFlat<TCoeHelpContext>* array =
       
  1006                 new(ELeave)CArrayFixFlat<TCoeHelpContext>( 1 );
       
  1007 
       
  1008             CleanupStack::PushL( array );
       
  1009             array->AppendL( helpContext );
       
  1010             CleanupStack::Pop(); // array
       
  1011 
       
  1012             // HlpLauncher deletes array
       
  1013             HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), array );
       
  1014             break;
       
  1015             }
       
  1016         case EAknCmdExit:
       
  1017             {
       
  1018             static_cast<MEikCommandObserver*>(iEikonEnv->EikAppUi())->
       
  1019                 ProcessCommandL(aCommandId);
       
  1020             }
       
  1021         default :
       
  1022             break;
       
  1023         }
       
  1024     }
       
  1025 
       
  1026 // -----------------------------------------------------------------------------
       
  1027 // CMPXMetadataEditorDialog::PopulateFileDetailsL
       
  1028 // -----------------------------------------------------------------------------
       
  1029 //
       
  1030 void CMPXMetadataEditorDialog::PopulateFileDetailsL(
       
  1031     CDesCArrayFlat* aHeadingsArray, CDesCArrayFlat* aDataArray )
       
  1032     {
       
  1033 
       
  1034     MPX_FUNC( "CMPXMetadataEditorDialog::PopulateFileDetailsL" );
       
  1035 
       
  1036     TBool drmProtected( iMedia->ValueTObjectL<TBool>( KMPXMediaDrmProtected ) );
       
  1037     MPX_DEBUG2( "CMPXMetadataEditorDialog::PopulateFileDetailsL drm protected: %d", drmProtected );
       
  1038 
       
  1039     if ( drmProtected )
       
  1040         {
       
  1041         MakeDrmItemsL( aHeadingsArray, aDataArray );
       
  1042         }
       
  1043 
       
  1044     // Get filename
       
  1045     const TDesC& uri = iMedia->ValueText( KMPXMediaGeneralUri );
       
  1046     TParsePtrC parse(uri);
       
  1047 
       
  1048     AppendStringToArrayL( aDataArray, parse.Name() );
       
  1049 
       
  1050     // Get mime type
       
  1051     const TDesC& mimeType = iMedia->ValueText( KMPXMediaGeneralMimeType );
       
  1052     AppendStringToArrayL( aDataArray, mimeType );
       
  1053 
       
  1054     // Get duration
       
  1055     TInt duration( iMedia->ValueTObjectL<TInt>( KMPXMediaGeneralDuration ) );
       
  1056     if ( duration > 0 )
       
  1057         {
       
  1058         // convert milliseconds to seconds
       
  1059         duration = duration / KSecondInMilliseconds;
       
  1060         CMPXCommonUiHelper::TMPXDuratDisplayMode durationMode =
       
  1061             CMPXCommonUiHelper::EMPXDuratAuto;
       
  1062         if ( duration > KOneHourInSeconds )
       
  1063             {
       
  1064             durationMode = CMPXCommonUiHelper::EMPXDuratHMS;
       
  1065             }
       
  1066         HBufC* stringBuf = iCommonUiHelper->DisplayableDurationL(
       
  1067             duration, durationMode );
       
  1068         CleanupStack::PushL( stringBuf );
       
  1069         aDataArray->AppendL( *stringBuf );
       
  1070         CleanupStack::PopAndDestroy( stringBuf );
       
  1071         }
       
  1072     else
       
  1073         {
       
  1074         aDataArray->AppendL( KNullDesC );
       
  1075         }
       
  1076 
       
  1077     // Get bitrate
       
  1078     TInt bitrate( iMedia->ValueTObjectL<TInt>( KMPXMediaAudioBitrate ) );
       
  1079     if ( bitrate > 0 )
       
  1080         {
       
  1081         // convert bitrate to kpbs
       
  1082         bitrate = bitrate / KMPXBitrateFactor;
       
  1083         HBufC* bitrateText = StringLoader::LoadLC(
       
  1084                         R_MPX_CUI_METADATAEDITOR_BITRATE_TXT, bitrate );
       
  1085         aDataArray->AppendL( bitrateText->Des() );
       
  1086         CleanupStack::PopAndDestroy( bitrateText );
       
  1087         }
       
  1088     else
       
  1089         {
       
  1090         aDataArray->AppendL( KNullDesC );
       
  1091         }
       
  1092 
       
  1093     // Get sampling rate
       
  1094     TInt samplingRateNum( ( TInt )iMedia->ValueTObjectL<TInt>( KMPXMediaAudioSamplerate ) );
       
  1095     if ( samplingRateNum > 0 )
       
  1096         {
       
  1097         HBufC* stringBuf = HBufC::NewLC( KMPXFileDetailsMaxBufferLen );
       
  1098         TPtr stringBufPtr = stringBuf->Des();
       
  1099         stringBufPtr.AppendNum( samplingRateNum );
       
  1100         AknTextUtils::LanguageSpecificNumberConversion( stringBufPtr );
       
  1101         HBufC* samplingrate = StringLoader::LoadLC(
       
  1102                         R_MPX_CUI_METADATAEDITOR_SAMPLINGRATE_TXT, stringBufPtr );
       
  1103         aDataArray->AppendL( samplingrate->Des() );
       
  1104         CleanupStack::PopAndDestroy( samplingrate );
       
  1105         CleanupStack::PopAndDestroy( stringBuf );
       
  1106         }
       
  1107     else
       
  1108         {
       
  1109         aDataArray->AppendL( KNullDesC );
       
  1110         }
       
  1111 
       
  1112     // Get size, not stored in collection, have to use RFile
       
  1113     //
       
  1114     RFs& fs = CEikonEnv::Static()->FsSession();
       
  1115     RFile file;
       
  1116     TInt sizeNum(0);
       
  1117     TInt err ( file.Open( fs, uri, EFileRead | EFileShareReadersOrWriters ) );
       
  1118     if ( err == KErrNone )
       
  1119         {
       
  1120         file.Size(sizeNum);
       
  1121         file.Close();
       
  1122         }
       
  1123 
       
  1124     if ( sizeNum > 0 )
       
  1125         {
       
  1126         HBufC* stringBuf = iCommonUiHelper->UnitConversionL( sizeNum );
       
  1127         CleanupStack::PushL( stringBuf );
       
  1128         aDataArray->AppendL( *stringBuf );
       
  1129         CleanupStack::PopAndDestroy( stringBuf );
       
  1130         }
       
  1131     else
       
  1132         {
       
  1133         aDataArray->AppendL( KNullDesC );
       
  1134         }
       
  1135 
       
  1136     if ( iCurrentLibrary == EMPXMetadataEditorDlgPodcast )
       
  1137         {
       
  1138         PopulatePodcastFileDetailsL( aHeadingsArray, aDataArray );
       
  1139         }
       
  1140 
       
  1141     // Get modified
       
  1142     TTime time;
       
  1143     User::LeaveIfError( fs.Modified( uri, time ) );
       
  1144     ConvertToLocalTimeL( time );
       
  1145 	HBufC* modDateTime = HBufC::NewLC(
       
  1146 		KMPXMaxTimeLength + KMPXDurationDisplayResvLen );
       
  1147 	HBufC* format = StringLoader::LoadLC(
       
  1148 		R_QTN_DATE_USUAL_WITH_ZERO );
       
  1149 	TPtr modDatePtr = modDateTime->Des();
       
  1150 	MPX_TRAPD( error, time.FormatL( modDatePtr, *format ) );
       
  1151 	CleanupStack::PopAndDestroy( format );
       
  1152 	if (error != KErrNone)
       
  1153 		{
       
  1154 		aDataArray->AppendL( KNullDesC );
       
  1155 		}
       
  1156 	else
       
  1157 		{
       
  1158 		format = StringLoader::LoadLC(
       
  1159 			R_QTN_TIME_USUAL_WITH_ZERO );
       
  1160 		HBufC* modTime = HBufC::NewLC(
       
  1161 			format->Length() + KMPXDurationDisplayResvLen );
       
  1162 		TPtr modTimePtr = modTime->Des();
       
  1163 		MPX_TRAPD( err, time.FormatL( modTimePtr, *format ) );
       
  1164 		if ( err != KErrNone )
       
  1165 			{
       
  1166 			aDataArray->AppendL( KNullDesC );
       
  1167 			}
       
  1168 		else
       
  1169 			{
       
  1170 			modDatePtr.Append( KMPXSpace );
       
  1171 			modDatePtr.Append( modTimePtr );
       
  1172 			aDataArray->AppendL( modDatePtr );
       
  1173 			}
       
  1174 		CleanupStack::PopAndDestroy( modTime );
       
  1175 		CleanupStack::PopAndDestroy( format );
       
  1176 		}
       
  1177 	CleanupStack::PopAndDestroy( modDateTime );
       
  1178 
       
  1179     // Get filename
       
  1180     AppendStringToArrayL( aDataArray, iMedia->ValueText(
       
  1181         KMPXMediaGeneralCopyright ) );
       
  1182 
       
  1183     // Get URL
       
  1184     AppendStringToArrayL( aDataArray, iMedia->ValueText(
       
  1185         KMPXMediaMusicURL ) );
       
  1186     }
       
  1187 
       
  1188 // -----------------------------------------------------------------------------
       
  1189 // CMPXMetadataEditorDialog::PopulatePodcastFileDetailsL
       
  1190 // -----------------------------------------------------------------------------
       
  1191 //
       
  1192 void CMPXMetadataEditorDialog::PopulatePodcastFileDetailsL(
       
  1193     CDesCArrayFlat* /*aHeadingsArray*/, CDesCArrayFlat* aDataArray )
       
  1194     {
       
  1195     MPX_FUNC( "CMPXMetadataEditorDialog::PopulatePodcastFileDetailsL" );
       
  1196     // Get last playback position
       
  1197 
       
  1198     TInt lastPbPosition( ( TInt )iMedia->ValueTObjectL<TInt>(
       
  1199         KMPXMediaGeneralLastPlaybackPosition ) );
       
  1200 
       
  1201     if ( lastPbPosition > 0 )
       
  1202         {
       
  1203         // convert milliseconds to seconds
       
  1204         lastPbPosition = lastPbPosition / KSecondInMilliseconds;
       
  1205         CMPXCommonUiHelper::TMPXDuratDisplayMode lastPbPositionMode =
       
  1206             CMPXCommonUiHelper::EMPXDuratAuto;
       
  1207         if ( lastPbPosition > KOneHourInSeconds )
       
  1208             {
       
  1209             lastPbPositionMode = CMPXCommonUiHelper::EMPXDuratHMS;
       
  1210             }
       
  1211         HBufC* stringBuf = iCommonUiHelper->DisplayableDurationL(
       
  1212             lastPbPosition, lastPbPositionMode );
       
  1213         CleanupStack::PushL( stringBuf );
       
  1214         aDataArray->AppendL( *stringBuf );
       
  1215         CleanupStack::PopAndDestroy( stringBuf );
       
  1216         }
       
  1217     else if(lastPbPosition == 0 &&
       
  1218             iMedia->IsSupported(KMPXMediaGeneralPlayCount) &&
       
  1219             iMedia->ValueTObjectL<TInt>(KMPXMediaGeneralPlayCount) > 0 )
       
  1220         {
       
  1221         HBufC* stringBuf = StringLoader::LoadLC( R_MPX_CUI_METADATAEDITOR_PLAYBACK_COMPLETE );
       
  1222         aDataArray->AppendL( *stringBuf );
       
  1223         CleanupStack::PopAndDestroy( stringBuf );
       
  1224 
       
  1225         }
       
  1226     else
       
  1227         {
       
  1228         aDataArray->AppendL( KNullDesC );
       
  1229         }
       
  1230 
       
  1231 
       
  1232     // Get published
       
  1233     if ( iMedia->IsSupported( TMPXAttribute( KMPXMediaIdPodcast,
       
  1234             EMPXMediaPodcastPubDate ) ) )
       
  1235         {
       
  1236         TInt64 timeInt( ( TInt64 )iMedia->ValueTObjectL<TInt64>(
       
  1237             TMPXAttribute( KMPXMediaIdPodcast, EMPXMediaPodcastPubDate ) ) );
       
  1238         TTime time( timeInt );
       
  1239         ConvertToLocalTimeL(time);
       
  1240         HBufC* modDateTime = HBufC::NewLC(
       
  1241             KMPXMaxTimeLength + KMPXDurationDisplayResvLen );
       
  1242         HBufC* format = StringLoader::LoadLC(
       
  1243             R_QTN_DATE_USUAL_WITH_ZERO );
       
  1244         TPtr modDatePtr = modDateTime->Des();
       
  1245         MPX_TRAPD( err, time.FormatL( modDatePtr, *format ) );
       
  1246         CleanupStack::PopAndDestroy( format );
       
  1247         if (err != KErrNone ||
       
  1248             time == 0)
       
  1249             {
       
  1250             aDataArray->AppendL( KNullDesC );
       
  1251             }
       
  1252         else
       
  1253             {
       
  1254             format = StringLoader::LoadLC(
       
  1255                 R_QTN_TIME_USUAL_WITH_ZERO );
       
  1256             HBufC* modTime = HBufC::NewLC(
       
  1257                 format->Length() + KMPXDurationDisplayResvLen );
       
  1258             TPtr modTimePtr = modTime->Des();
       
  1259             MPX_TRAPD( err, time.FormatL( modTimePtr, *format ) );
       
  1260             if ( err != KErrNone )
       
  1261                 {
       
  1262                 aDataArray->AppendL( KNullDesC );
       
  1263                 }
       
  1264             else
       
  1265                 {
       
  1266                 modDatePtr.Append( KMPXSpace );
       
  1267                 modDatePtr.Append( modTimePtr );
       
  1268                 aDataArray->AppendL( modDatePtr );
       
  1269                 }
       
  1270             CleanupStack::PopAndDestroy( modTime );
       
  1271             CleanupStack::PopAndDestroy( format );
       
  1272             }
       
  1273         CleanupStack::PopAndDestroy( modDateTime );
       
  1274         }
       
  1275     else
       
  1276         {
       
  1277         aDataArray->AppendL( KNullDesC );
       
  1278         }
       
  1279     }
       
  1280 
       
  1281 // -----------------------------------------------------------------------------
       
  1282 // CMPXMetadataEditorDialog::MakeDrmItemsL
       
  1283 // -----------------------------------------------------------------------------
       
  1284 //
       
  1285 void CMPXMetadataEditorDialog::MakeDrmItemsL(
       
  1286     CDesCArrayFlat* aHeadingsArray, CDesCArrayFlat* aDataArray )
       
  1287     {
       
  1288     MPX_FUNC( "CMPXMetadataEditorDialog::MakeDrmItemsL" );
       
  1289     if (iDrmDetails )
       
  1290         {
       
  1291         TInt itemCount( 0);
       
  1292         if ( iDrmInfo->IsSupported( KMPXMediaDrmType ) )
       
  1293             {
       
  1294             MPX_DEBUG2( "CMPXMetadataEditorDialog::MakeDrmItemsL drm type: %d",
       
  1295                     iDrmInfo->ValueTObjectL<TInt>( KMPXMediaDrmType ) );
       
  1296             TInt rightStatus( iDrmInfo->ValueTObjectL<TInt>( KMPXMediaDrmRightsStatus ) );
       
  1297             HBufC* rights( StringLoader::LoadLC( R_QTN_DRM_MGR_DET2_PLAY ) );
       
  1298             HBufC* heading( NULL);
       
  1299             HBufC* value( NULL);
       
  1300 
       
  1301             switch ( rightStatus )
       
  1302                 {
       
  1303                 case EMPXDrmRightsFull:
       
  1304                     {
       
  1305                     // status
       
  1306                     heading = StringLoader::LoadLC ( R_QTN_DRM_MGR_DET_STAT );
       
  1307                     value = StringLoader::LoadLC ( R_QTN_DRM_MGR_DET_VALID );
       
  1308                     aHeadingsArray->InsertL ( itemCount, heading->Des ( ) );
       
  1309                     aDataArray->InsertL ( itemCount, value->Des ( ) );
       
  1310                     CleanupStack::PopAndDestroy ( value );
       
  1311                     CleanupStack::PopAndDestroy ( heading );
       
  1312                     itemCount++;
       
  1313 
       
  1314                     // full rights
       
  1315                     heading = StringLoader::LoadLC (
       
  1316                         R_QTN_DRM_MGR_DET_FULL_X, *rights );
       
  1317                     value = StringLoader::LoadLC ( R_QTN_DRM_MGR_DET_UNLIMITED );
       
  1318                     aHeadingsArray->InsertL ( itemCount, heading->Des ( ) );
       
  1319                     aDataArray->InsertL ( itemCount, value->Des ( ) );
       
  1320                     CleanupStack::PopAndDestroy ( value );
       
  1321                     CleanupStack::PopAndDestroy ( heading );
       
  1322                     itemCount++;
       
  1323                     break;
       
  1324                     }
       
  1325                 case EMPXDrmRightsRestricted:
       
  1326                 case EMPXDrmRightsPreview:
       
  1327                     {
       
  1328                     // status
       
  1329                     heading = StringLoader::LoadLC ( R_QTN_DRM_MGR_DET_STAT );
       
  1330                     value = StringLoader::LoadLC ( R_QTN_DRM_MGR_DET_VALID );
       
  1331                     aHeadingsArray->InsertL ( itemCount, heading->Des ( ) );
       
  1332                     aDataArray->InsertL ( itemCount, value->Des ( ) );
       
  1333                     CleanupStack::PopAndDestroy ( value );
       
  1334                     CleanupStack::PopAndDestroy ( heading );
       
  1335                     itemCount++;
       
  1336                     // rights
       
  1337                     MakeRestrictedDrmItemsL(
       
  1338                         rights, itemCount, aHeadingsArray, aDataArray );
       
  1339                     break;
       
  1340                     }
       
  1341                 case EMPXDrmRightsMissing:
       
  1342                     {
       
  1343                     // status
       
  1344                     heading = StringLoader::LoadLC ( R_QTN_DRM_MGR_DET_STAT );
       
  1345                     value = StringLoader::LoadLC ( R_QTN_DRM_MGR_DET_EXP );
       
  1346                     aHeadingsArray->InsertL ( itemCount, heading->Des ( ) );
       
  1347                     aDataArray->InsertL ( itemCount, value->Des ( ) );
       
  1348                     CleanupStack::PopAndDestroy ( value );
       
  1349                     CleanupStack::PopAndDestroy ( heading );
       
  1350                     itemCount++;
       
  1351                     break;
       
  1352                     }
       
  1353                 case EMPXDrmRightsExpired:
       
  1354                     {
       
  1355                     // status
       
  1356                     heading = StringLoader::LoadLC ( R_QTN_DRM_MGR_DET_STAT );
       
  1357                     value = StringLoader::LoadLC ( R_QTN_DRM_MGR_DET_EXP );
       
  1358                     aHeadingsArray->InsertL ( itemCount, heading->Des ( ) );
       
  1359                     aDataArray->InsertL ( itemCount, value->Des ( ) );
       
  1360                     CleanupStack::PopAndDestroy ( value );
       
  1361                     CleanupStack::PopAndDestroy ( heading );
       
  1362                     itemCount++;
       
  1363                     // make rest of the drm items
       
  1364                     MakeRestrictedDrmItemsL(
       
  1365                         rights, itemCount, aHeadingsArray, aDataArray );
       
  1366                     break;
       
  1367                     }
       
  1368                 default:
       
  1369                     {
       
  1370                     break;
       
  1371                     }
       
  1372                 }
       
  1373 
       
  1374             heading = NULL;
       
  1375             value = NULL;
       
  1376 
       
  1377             // sending
       
  1378             heading = StringLoader::LoadLC ( R_QTN_DRM_MGR_DET_CS );
       
  1379             TBool forwardAllowed( iDrmInfo->ValueTObjectL<TBool>( KMPXMediaDrmSendingAllowed ) );
       
  1380             if ( forwardAllowed )
       
  1381                 {
       
  1382                 value = StringLoader::LoadLC ( R_QTN_DRM_MGR_DET_ALLOWED );
       
  1383                 }
       
  1384             else
       
  1385                 {
       
  1386                 value = StringLoader::LoadLC ( R_QTN_DRM_MGR_DET_FORBID );
       
  1387                 }
       
  1388             aHeadingsArray->InsertL ( itemCount, heading->Des ( ) );
       
  1389             aDataArray->InsertL ( itemCount, value->Des ( ) );
       
  1390             CleanupStack::PopAndDestroy ( value );
       
  1391             CleanupStack::PopAndDestroy ( heading );
       
  1392             CleanupStack::PopAndDestroy ( rights ); // heading, value, rights
       
  1393             }
       
  1394         else
       
  1395             {
       
  1396             // if error getting drm info, drm type will not be valid
       
  1397             // by default assume the rights are invalid (since we can't read it)
       
  1398             MPX_DEBUG1( "CMPXMetadataEditorDialog::MakeDrmItemsL unable to get drm data" );
       
  1399             HBufC* heading( StringLoader::LoadLC ( R_QTN_DRM_MGR_DET_STAT ));
       
  1400             HBufC* value( StringLoader::LoadLC ( R_QTN_DRM_MGR_DET_INVALID ));
       
  1401             aHeadingsArray->InsertL ( 0, heading->Des ( ) );
       
  1402             aDataArray->InsertL ( 0, value->Des ( ) );
       
  1403             CleanupStack::PopAndDestroy ( value );
       
  1404             CleanupStack::PopAndDestroy ( heading );
       
  1405             }
       
  1406         }
       
  1407     }
       
  1408 
       
  1409 // -----------------------------------------------------------------------------
       
  1410 // CMPXMetadataEditorDialog::MakeRestrictedDrmItemsL
       
  1411 // -----------------------------------------------------------------------------
       
  1412 //
       
  1413 void CMPXMetadataEditorDialog::MakeRestrictedDrmItemsL(
       
  1414     HBufC* aRights, TInt& aCurrentIndex,
       
  1415     CDesCArrayFlat* aHeadingsArray, CDesCArrayFlat* aDataArray )
       
  1416     {
       
  1417     MPX_FUNC( "CMPXMetadataEditorDialog::MakeRestrictedDrmItemsL" );
       
  1418     TMPXMediaDrmRightsType expireConstraint( EMPXDrmRightsTypeNoRestriction );
       
  1419     if ( iDrmInfo->IsSupported( KMPXMediaDrmRightsType ) )
       
  1420         {
       
  1421         expireConstraint = iDrmInfo->ValueTObjectL<TMPXMediaDrmRightsType>(
       
  1422             KMPXMediaDrmRightsType );
       
  1423         }
       
  1424     MPX_DEBUG2("CMPXMetadataEditorDialog::MakeRestrictedDrmItemsL(): ExpireConstraint = %d", expireConstraint);
       
  1425     TInt64 intervalTime( KErrNotFound );
       
  1426     if ( iDrmInfo->IsSupported( KMPXMediaDrmIntervalStartTime ) )
       
  1427         {
       
  1428         MPX_DEBUG1("CMPXMetadataEditorDialog::MakeRestrictedDrmItemsL(): Interval Start Time");
       
  1429         intervalTime = (TInt64)iDrmInfo->ValueTObjectL<TInt64>( KMPXMediaDrmIntervalStartTime );
       
  1430         }
       
  1431     HBufC* heading = NULL;
       
  1432     HBufC* value = NULL;
       
  1433     // acculated time 
       
  1434     if ( expireConstraint ==  EMPXDrmRightsTypeAccTime )
       
  1435       	{
       
  1436       	MPX_DEBUG1("CMPXMetadataEditorDialog::MakeRestrictedDrmItemsL(): AccTime based");
       
  1437         heading = StringLoader::LoadLC( R_QTN_DRM_MGR_DET_ACCUM_TIME_LEFT  );
       
  1438 
       
  1439         TTimeIntervalSeconds  accTime = iDrmInfo->ValueTObjectL<TTimeIntervalSeconds>(  KMPXMediaDrmAccumulatedTime );
       
  1440         TInt years( 0 );
       
  1441         TInt months( 0 );
       
  1442         TInt days( 0 );
       
  1443         TInt hours( 0 );
       
  1444         TInt minutes( 0 );
       
  1445         TInt seconds( 0 );
       
  1446         SplitTime( accTime, years, months, days, hours, minutes, seconds );
       
  1447         value = AddPartsOfTimeLC( years, months, days, hours, minutes, seconds );      
       
  1448         
       
  1449         TPtr text = value->Des();
       
  1450         LanguageSpecificNumberConversion( text );   
       
  1451       	aHeadingsArray->InsertL( aCurrentIndex, heading->Des() );  
       
  1452         aDataArray->InsertL( aCurrentIndex, value->Des() ); 
       
  1453         
       
  1454         CleanupStack::PopAndDestroy( value );
       
  1455         CleanupStack::PopAndDestroy( heading );         
       
  1456         aCurrentIndex++;   
       
  1457       	}
       
  1458 
       
  1459     // count
       
  1460     if ( expireConstraint == EMPXDrmRightsTypeCount ||
       
  1461          expireConstraint == EMPXDrmRightsTypeTimeCount )
       
  1462         {
       
  1463         MPX_DEBUG1("CMPXMetadataEditorDialog::MakeRestrictedDrmItemsL(): Count based");
       
  1464         heading = StringLoader::LoadLC( R_QTN_DRM_MGR_DET_UTL_X, *aRights );
       
  1465 
       
  1466         TInt counts( iDrmInfo->ValueTObjectL<TInt>( KMPXMediaDrmCount ) );
       
  1467         if ( counts == 1 )
       
  1468             {
       
  1469             value = StringLoader::LoadLC( R_QTN_DRM_MGR_DET_1_COUNT );
       
  1470             }
       
  1471         else
       
  1472             {
       
  1473             value = StringLoader::LoadLC(
       
  1474                 R_QTN_DRM_MGR_DET_N_COUNTS, counts );
       
  1475             }
       
  1476         TPtr text = value->Des();
       
  1477         LanguageSpecificNumberConversion( text );
       
  1478         aHeadingsArray->InsertL( aCurrentIndex, heading->Des() );
       
  1479         aDataArray->InsertL( aCurrentIndex, value->Des() );
       
  1480         CleanupStack::PopAndDestroy( value );
       
  1481         CleanupStack::PopAndDestroy( heading );
       
  1482         aCurrentIndex++;
       
  1483         }
       
  1484 
       
  1485     if ( expireConstraint == EMPXDrmRightsTypeTime ||
       
  1486          expireConstraint == EMPXDrmRightsTypeTimeCount ||
       
  1487          ( expireConstraint == EMPXDrmRightsTypeInterval &&
       
  1488          intervalTime > 0 ) )
       
  1489         {
       
  1490         MPX_DEBUG1("CMPXMetadataEditorDialog::MakeRestrictedDrmItemsL(): Time based");
       
  1491         HBufC* dateFormatString = StringLoader::LoadLC(
       
  1492                 R_QTN_DATE_USUAL_WITH_ZERO );
       
  1493         HBufC* timeFormatString = StringLoader::LoadLC( R_QTN_TIME_USUAL );
       
  1494 
       
  1495         // from
       
  1496         if ( iDrmInfo->IsSupported( KMPXMediaDrmStartTime ) )
       
  1497             {
       
  1498             MPX_DEBUG1("CMPXMetadataEditorDialog::MakeRestrictedDrmItemsL(): Start time found");
       
  1499             TTime from( iDrmInfo->ValueTObjectL<TInt64>( KMPXMediaDrmStartTime ) );
       
  1500             heading = StringLoader::LoadLC( R_QTN_DRM_MGR_DET_RVF_X, *aRights );
       
  1501             HBufC* datePointer = HBufC::NewLC( KMaxFileName );
       
  1502             TPtr date = datePointer->Des();
       
  1503             from.FormatL( date, *dateFormatString );
       
  1504             TBuf<KMPXMaxTimeLength> time;
       
  1505             from.FormatL( time, *timeFormatString );
       
  1506             date.Append( KMPXSpace );
       
  1507             date.Append( time );
       
  1508             LanguageSpecificNumberConversion( date );
       
  1509             aHeadingsArray->InsertL( aCurrentIndex, heading->Des() );
       
  1510             aDataArray->InsertL( aCurrentIndex, date );
       
  1511             CleanupStack::PopAndDestroy( datePointer );
       
  1512             CleanupStack::PopAndDestroy( heading );
       
  1513             aCurrentIndex++;
       
  1514             }
       
  1515 
       
  1516         // until
       
  1517         if ( iDrmInfo->IsSupported( KMPXMediaDrmEndTime ) )
       
  1518             {
       
  1519             MPX_DEBUG1("CMPXMetadataEditorDialog::MakeRestrictedDrmItemsL(): End time found");
       
  1520             TTime until( iDrmInfo->ValueTObjectL<TInt64>( KMPXMediaDrmEndTime ) );
       
  1521             heading = StringLoader::LoadLC( R_QTN_DRM_MGR_DET_RVT_X, *aRights );
       
  1522             HBufC* dateToPntr = HBufC::NewLC( KMaxFileName );
       
  1523             TPtr dateTo = dateToPntr->Des();
       
  1524             until.FormatL( dateTo, *dateFormatString );
       
  1525             TBuf<KMPXMaxTimeLength> timeTo;
       
  1526             until.FormatL( timeTo, *timeFormatString );
       
  1527             dateTo.Append( KMPXSpace );
       
  1528             dateTo.Append( timeTo );
       
  1529             LanguageSpecificNumberConversion( dateTo );
       
  1530             aHeadingsArray->InsertL( aCurrentIndex, heading->Des() );
       
  1531             aDataArray->InsertL( aCurrentIndex, dateTo );
       
  1532             CleanupStack::PopAndDestroy( dateToPntr );
       
  1533             CleanupStack::PopAndDestroy( heading );
       
  1534             aCurrentIndex++;
       
  1535             }
       
  1536         CleanupStack::PopAndDestroy( timeFormatString );
       
  1537         CleanupStack::PopAndDestroy( dateFormatString );
       
  1538         }
       
  1539     else if ( expireConstraint == EMPXDrmRightsTypeInterval &&
       
  1540          intervalTime < 0 )
       
  1541         {
       
  1542         MPX_DEBUG1("CMPXMetadataEditorDialog::MakeRestrictedDrmItemsL(): Time not activated");
       
  1543         // times not activated
       
  1544         heading = StringLoader::LoadLC( R_QTN_DRM_MGR_DET_UTS_X, *aRights );
       
  1545         value  = StringLoader::LoadLC( R_QTN_DRM_MGR_DET_NOT_ACT );
       
  1546         aHeadingsArray->InsertL( aCurrentIndex, heading->Des() );
       
  1547         aDataArray->InsertL( aCurrentIndex, value->Des() );
       
  1548         CleanupStack::PopAndDestroy( value );
       
  1549         CleanupStack::PopAndDestroy( heading );
       
  1550         aCurrentIndex++;
       
  1551 
       
  1552         // query what the current time is
       
  1553         TTime currentTime;
       
  1554         currentTime.HomeTime();
       
  1555         // calculate rights end time
       
  1556         TTimeIntervalSeconds interval = iDrmInfo->ValueTObjectL<TInt64>( KMPXMediaDrmInterval );
       
  1557         TTime endTime( currentTime.Int64() + (TInt64) interval.Int() * KSecondInMicroSeconds );
       
  1558         TBuf<KMPXMaxVal> val;
       
  1559         TInt count = 0;
       
  1560 
       
  1561         // years
       
  1562         TTimeIntervalYears years = endTime.YearsFrom( currentTime );
       
  1563         if ( years.Int() )
       
  1564             {
       
  1565             AddSinglePartOfTimeL( years.Int(),
       
  1566                 R_QTN_DRM_NBR_OF_YEARS_ONE,
       
  1567                 R_QTN_DRM_NBR_OF_YEARS_ONE_FINAL,
       
  1568                 R_QTN_DRM_NBR_OF_YEARS_TWO_FOUR,
       
  1569                 R_QTN_DRM_NBR_OF_YEARS_FIVE_ZERO,
       
  1570                 value );
       
  1571             count++;
       
  1572             val.Append( *value );
       
  1573             endTime -= years;
       
  1574             CleanupStack::PopAndDestroy( value );
       
  1575             }
       
  1576 
       
  1577         // months
       
  1578         TTimeIntervalMonths months = endTime.MonthsFrom( currentTime );
       
  1579         if ( months.Int() )
       
  1580             {
       
  1581             AddSinglePartOfTimeL( months.Int(),
       
  1582                 R_QTN_DRM_NBR_OF_MONTHS_ONE,
       
  1583                 0,
       
  1584                 R_QTN_DRM_NBR_OF_MONTHS_TWO_FOUR,
       
  1585                 R_QTN_DRM_NBR_OF_MONTHS_FIVE_ZERO,
       
  1586                 value );
       
  1587              if ( count )
       
  1588                 {
       
  1589                 val.Append( KMPXSpace );
       
  1590                 }
       
  1591 
       
  1592             count++;
       
  1593             val.Append( *value );
       
  1594             endTime -= months;
       
  1595             CleanupStack::PopAndDestroy( value );
       
  1596             }
       
  1597 
       
  1598         // days
       
  1599         TTimeIntervalDays days = endTime.DaysFrom( currentTime );
       
  1600         if ( days.Int() && count < 2 )
       
  1601             {
       
  1602             AddSinglePartOfTimeL( days.Int(),
       
  1603                 R_QTN_DRM_NBR_OF_DAYS_ONE,
       
  1604                 R_QTN_DRM_NBR_OF_DAYS_ONE_FINAL,
       
  1605                 R_QTN_DRM_NBR_OF_DAYS_TWO_FOUR,
       
  1606                 R_QTN_DRM_NBR_OF_DAYS_FIVE_ZERO,
       
  1607                 value );
       
  1608             if ( count )
       
  1609                 {
       
  1610                 val.Append( KMPXSpace );
       
  1611                 }
       
  1612 
       
  1613             val.Append( *value );
       
  1614             endTime -= days;
       
  1615             CleanupStack::PopAndDestroy( value );
       
  1616             count++;
       
  1617             }
       
  1618 
       
  1619         // hours
       
  1620         TTimeIntervalHours hours;
       
  1621         TInt ret = endTime.HoursFrom( currentTime, hours );
       
  1622         if ( ret == KErrNone && count < 2 && hours.Int() )
       
  1623             {
       
  1624             AddSinglePartOfTimeL( hours.Int(),
       
  1625                 R_QTN_DRM_NBR_OF_HOURS_ONE,
       
  1626                 R_QTN_DRM_NBR_OF_HOURS_ONE_FINAL,
       
  1627                 R_QTN_DRM_NBR_OF_HOURS_TWO_FOUR,
       
  1628                 R_QTN_DRM_NBR_OF_HOURS_FIVE_ZERO,
       
  1629                 value );
       
  1630             if ( count )
       
  1631                 {
       
  1632                 val.Append( KMPXSpace );
       
  1633                 }
       
  1634 
       
  1635             val.Append( *value );
       
  1636             endTime -= hours;
       
  1637             CleanupStack::PopAndDestroy( value );
       
  1638             count++;
       
  1639             }
       
  1640 
       
  1641         // mins
       
  1642         TTimeIntervalMinutes minutes;
       
  1643         ret = endTime.MinutesFrom( currentTime, minutes );
       
  1644         if ( ret == KErrNone && count < 2 && minutes.Int() )
       
  1645             {
       
  1646             AddSinglePartOfTimeL( minutes.Int(),
       
  1647                 R_QTN_DRM_NBR_OF_MINS_ONE,
       
  1648                 R_QTN_DRM_NBR_OF_MINS_ONE_FINAL,
       
  1649                 R_QTN_DRM_NBR_OF_MINS_TWO_FOUR,
       
  1650                 R_QTN_DRM_NBR_OF_MINS_FIVE_ZERO,
       
  1651                 value );
       
  1652             if ( count )
       
  1653                 {
       
  1654                 val.Append( KMPXSpace );
       
  1655                 }
       
  1656 
       
  1657             val.Append( *value );
       
  1658             endTime -= minutes;
       
  1659             CleanupStack::PopAndDestroy( value );
       
  1660             count++;
       
  1661             }
       
  1662 
       
  1663         // seconds
       
  1664         TTimeIntervalSeconds seconds;
       
  1665         ret = endTime.SecondsFrom( currentTime,seconds );
       
  1666         if ( ret == KErrNone && count < 2 && seconds.Int() )
       
  1667             {
       
  1668             AddSinglePartOfTimeL( seconds.Int(),
       
  1669                 R_QTN_DRM_NBR_OF_SECS_ONE,
       
  1670                 R_QTN_DRM_NBR_OF_SECS_ONE_FINAL,
       
  1671                 R_QTN_DRM_NBR_OF_SECS_TWO_FOUR,
       
  1672                 R_QTN_DRM_NBR_OF_SECS_FIVE_ZERO,
       
  1673                 value );
       
  1674 
       
  1675             if ( count )
       
  1676                 {
       
  1677                 val.Append( KMPXSpace );
       
  1678                 }
       
  1679 
       
  1680             val.Append( *value );
       
  1681             CleanupStack::PopAndDestroy(); // value
       
  1682             count++;
       
  1683             }
       
  1684 
       
  1685         heading = StringLoader::LoadLC( R_QTN_DRM_MGR_DET_UDL_X, *aRights );
       
  1686         LanguageSpecificNumberConversion( val );
       
  1687         aHeadingsArray->InsertL( aCurrentIndex, heading->Des() );
       
  1688         aDataArray->InsertL( aCurrentIndex, val );
       
  1689         CleanupStack::PopAndDestroy( heading );
       
  1690         aCurrentIndex++;
       
  1691         }
       
  1692     }
       
  1693   
       
  1694 // -----------------------------------------------------------------------------
       
  1695 // CMPXMetadataEditorDialog::AddPartsOfTimeLC
       
  1696 // -----------------------------------------------------------------------------
       
  1697 //
       
  1698 HBufC* CMPXMetadataEditorDialog::AddPartsOfTimeLC( TInt aIntYrs, TInt aIntMon, TInt aIntDay, 
       
  1699                          TInt aIntHrs, TInt aIntMin, TInt aIntSec )
       
  1700     {
       
  1701     MPX_FUNC( "CMPXMetadataEditorDialog::AddPartsOfTimeLC" );   
       
  1702     // Only the two most meaningful data will be showed
       
  1703     TInt numOfData( 0 );
       
  1704     const TInt KMaxDataItems = 2;
       
  1705 
       
  1706     CDesCArrayFlat* strings = new ( ELeave ) CDesCArrayFlat( KMaxDataItems );
       
  1707     CleanupStack::PushL( strings );
       
  1708 
       
  1709     if ( aIntYrs > 0 )
       
  1710         {
       
  1711         AddSinglePartOfTimeL( aIntYrs, 
       
  1712             R_QTN_DRM_NBR_OF_YEARS_ONE,
       
  1713             R_QTN_DRM_NBR_OF_YEARS_ONE_FINAL,
       
  1714             R_QTN_DRM_NBR_OF_YEARS_TWO_FOUR,
       
  1715             R_QTN_DRM_NBR_OF_YEARS_FIVE_ZERO,
       
  1716             strings );
       
  1717         numOfData++;
       
  1718         }
       
  1719 
       
  1720     if ( aIntMon > 0 )
       
  1721         {
       
  1722         //  Second type not provided because 11 is the maximum
       
  1723         AddSinglePartOfTimeL( aIntMon, 
       
  1724             R_QTN_DRM_NBR_OF_MONTHS_ONE,
       
  1725             0,       
       
  1726             R_QTN_DRM_NBR_OF_MONTHS_TWO_FOUR, 
       
  1727             R_QTN_DRM_NBR_OF_MONTHS_FIVE_ZERO, 
       
  1728             strings );
       
  1729         numOfData++;
       
  1730         }
       
  1731 
       
  1732     // Only if years or months were missing
       
  1733     if ( aIntDay > 0 && numOfData < KMaxDataItems )
       
  1734         {
       
  1735         AddSinglePartOfTimeL( aIntDay, 
       
  1736             R_QTN_DRM_NBR_OF_DAYS_ONE,
       
  1737             R_QTN_DRM_NBR_OF_DAYS_ONE_FINAL,
       
  1738             R_QTN_DRM_NBR_OF_DAYS_TWO_FOUR, 
       
  1739             R_QTN_DRM_NBR_OF_DAYS_FIVE_ZERO, 
       
  1740             strings );
       
  1741         numOfData++;
       
  1742         }
       
  1743 
       
  1744     if ( aIntHrs > 0 && numOfData < KMaxDataItems )
       
  1745         {
       
  1746         AddSinglePartOfTimeL( aIntHrs, 
       
  1747             R_QTN_DRM_NBR_OF_HOURS_ONE, 
       
  1748             R_QTN_DRM_NBR_OF_HOURS_ONE_FINAL,
       
  1749             R_QTN_DRM_NBR_OF_HOURS_TWO_FOUR, 
       
  1750             R_QTN_DRM_NBR_OF_HOURS_FIVE_ZERO, 
       
  1751             strings );
       
  1752         numOfData++;
       
  1753         }
       
  1754 
       
  1755     if ( aIntMin > 0 && numOfData < KMaxDataItems )
       
  1756         {
       
  1757         AddSinglePartOfTimeL( aIntMin, 
       
  1758             R_QTN_DRM_NBR_OF_MINS_ONE,
       
  1759             R_QTN_DRM_NBR_OF_MINS_ONE_FINAL,
       
  1760             R_QTN_DRM_NBR_OF_MINS_TWO_FOUR, 
       
  1761             R_QTN_DRM_NBR_OF_MINS_FIVE_ZERO, 
       
  1762             strings );
       
  1763         numOfData++;
       
  1764         }
       
  1765 
       
  1766     // If interval is 0, then it shows "0 seconds" anyway
       
  1767     if ( ( aIntSec > 0 && numOfData < KMaxDataItems ) || numOfData == 0 )
       
  1768         {
       
  1769         AddSinglePartOfTimeL( aIntSec, 
       
  1770             R_QTN_DRM_NBR_OF_SECS_ONE, 
       
  1771             R_QTN_DRM_NBR_OF_SECS_ONE_FINAL,
       
  1772             R_QTN_DRM_NBR_OF_SECS_TWO_FOUR, 
       
  1773             R_QTN_DRM_NBR_OF_SECS_FIVE_ZERO, 
       
  1774             strings );
       
  1775         numOfData++;
       
  1776         }
       
  1777 
       
  1778     HBufC* stringHolder = NULL;
       
  1779     if ( numOfData == 1 )
       
  1780         {
       
  1781         stringHolder = StringLoader::LoadL( R_QTN_DRM_MGR_DET_INTER,
       
  1782             strings->MdcaPoint(0) );
       
  1783         }
       
  1784     else
       
  1785         {
       
  1786         stringHolder = StringLoader::LoadL( R_QTN_DRM_MGR_DET_INTER_TWO,
       
  1787             *strings );
       
  1788         }
       
  1789 
       
  1790     CleanupStack::PopAndDestroy( strings );
       
  1791     
       
  1792     CleanupStack::PushL( stringHolder );
       
  1793 
       
  1794     return stringHolder;
       
  1795     }
       
  1796 
       
  1797 // -----------------------------------------------------------------------------
       
  1798 // CMPXMetadataEditorDialog::AddSinglePartOfTimeL
       
  1799 // -----------------------------------------------------------------------------
       
  1800 //
       
  1801 void CMPXMetadataEditorDialog::AddSinglePartOfTimeL( TInt aNumOfElements,
       
  1802         TInt aResourceIdSingle,
       
  1803         TInt aResourceIdOneFinal, 
       
  1804         TInt aResourceIdTwoFour,
       
  1805         TInt aResourceIdFiveZero, 
       
  1806         CDesCArrayFlat* aStrings )
       
  1807     {
       
  1808     MPX_FUNC( "CMPXMetadataEditorDialog::AddSinglePartOfTimeL" );   
       
  1809    
       
  1810     HBufC* stringHolder = NULL;
       
  1811     TInt finalOneDigit( aNumOfElements % KDigitTen );
       
  1812     TInt finalTwoDigits( aNumOfElements % KDigitHundred );
       
  1813 
       
  1814     if ( aNumOfElements == 1 )
       
  1815         {
       
  1816         stringHolder = StringLoader::LoadLC( aResourceIdSingle );
       
  1817         }
       
  1818     else if ( finalOneDigit == 1 && finalTwoDigits != KDigitEleven )
       
  1819         {
       
  1820         stringHolder = StringLoader::LoadLC( aResourceIdOneFinal, 
       
  1821             aNumOfElements );
       
  1822         }
       
  1823     else if ( finalOneDigit == 0 || 
       
  1824              ( finalOneDigit >= KDigitFive && finalOneDigit <= KDigitNine ) ||
       
  1825              ( finalTwoDigits >= KDigitEleven && finalTwoDigits <= KDigitFourTeen ) )
       
  1826         {
       
  1827         stringHolder = StringLoader::LoadLC( aResourceIdFiveZero,
       
  1828             aNumOfElements );
       
  1829         }
       
  1830     else
       
  1831         {
       
  1832         stringHolder = StringLoader::LoadLC( aResourceIdTwoFour,
       
  1833             aNumOfElements );
       
  1834         }
       
  1835 
       
  1836     if ( aStrings )
       
  1837         {
       
  1838         aStrings->AppendL( *stringHolder );
       
  1839         }
       
  1840 
       
  1841     CleanupStack::PopAndDestroy ( stringHolder );
       
  1842     }
       
  1843 
       
  1844 // -----------------------------------------------------------------------------
       
  1845 // CMPXMetadataEditorDialog::SplitTime
       
  1846 // 
       
  1847 // -----------------------------------------------------------------------------
       
  1848 //
       
  1849 
       
  1850 void CMPXMetadataEditorDialog::SplitTime( const TTimeIntervalSeconds& aInterval,
       
  1851         TInt& aIntYrs, TInt& aIntMon, TInt& aIntDay,
       
  1852         TInt& aIntHrs, TInt& aIntMin, TInt& aIntSec )
       
  1853     {
       
  1854     MPX_FUNC( "CMPXMetadataEditorDialog::SplitTime" );       
       
  1855     const TInt KSecsInMin( 60 );
       
  1856     const TInt KSecsInHour( KSecsInMin * 60 );
       
  1857     const TInt KSecsInDay( KSecsInHour * 24 );
       
  1858 
       
  1859     // includes leap year day
       
  1860 
       
  1861     const TInt KMaxDaysInMonths[] = {
       
  1862     		KMaxDaysInOneMonths,
       
  1863     		KMaxDaysInTwoMonths,
       
  1864     		KMaxDaysInThreeMonths,
       
  1865     		KMaxDaysInFourMonths,
       
  1866     		KMaxDaysInFiveMonths,
       
  1867     		KMaxDaysInSixMonths,
       
  1868     		KMaxDaysInSevenMonths,
       
  1869     		KMaxDaysInEightMonths,
       
  1870     		KMaxDaysInNineMonths,
       
  1871     		KMaxDaysInTenMonths,
       
  1872     		KMaxDaysInElevenMonths,
       
  1873     		KMaxDaysInEightMonths }; 
       
  1874 
       
  1875     // calculate full days
       
  1876     TInt temp( aInterval.Int() / KSecsInDay );
       
  1877 
       
  1878     // calculate full years, calculate without leap year for user to get the 
       
  1879     // longest time possible
       
  1880     aIntYrs = temp / ( KMaxDaysInMonths[KDigitEleven] - 1 );
       
  1881 
       
  1882     // calc remainder days
       
  1883     temp = temp % ( KMaxDaysInMonths[KDigitEleven] - 1 );
       
  1884 
       
  1885     aIntMon = 0;
       
  1886 
       
  1887     TInt i( 0 );
       
  1888     if ( temp >= KMaxDaysInMonths[0] )
       
  1889         {
       
  1890         for ( i = 0; i < KDigitEleven; i++ )
       
  1891             {
       
  1892             // found correct amount of months
       
  1893             if ( temp >= KMaxDaysInMonths[i] && temp < KMaxDaysInMonths[i+1] )
       
  1894                 {
       
  1895                 // i now contains amount of full months (+1 because of table index)
       
  1896                 aIntMon = i + 1;
       
  1897                 break;
       
  1898                 }
       
  1899             }
       
  1900         }
       
  1901 
       
  1902     // calc remainder days = allSecs - secsInFullYears - secsInFullMonts
       
  1903     if( temp >= KMaxDaysInMonths[i] )
       
  1904         {
       
  1905         aIntDay = temp - KMaxDaysInMonths[i];
       
  1906         }
       
  1907     else
       
  1908         {
       
  1909         aIntDay = temp;
       
  1910         }
       
  1911 
       
  1912     // calculate remainder secs
       
  1913     temp = aInterval.Int() % KSecsInDay;
       
  1914 
       
  1915     aIntHrs = temp / KSecsInHour;
       
  1916 
       
  1917     // calculate remainder secs
       
  1918     temp = temp % KSecsInHour;
       
  1919 
       
  1920     aIntMin = temp / KSecsInMin;
       
  1921 
       
  1922     // calculate remainder secs
       
  1923     aIntSec = temp % KSecsInMin;
       
  1924     }
       
  1925 
       
  1926 // -----------------------------------------------------------------------------
       
  1927 // CMPXMetadataEditorDialog::AddSinglePartOfTimeL
       
  1928 // Language specific time formats
       
  1929 // -----------------------------------------------------------------------------
       
  1930 //
       
  1931 void CMPXMetadataEditorDialog::AddSinglePartOfTimeL(
       
  1932     TInt aNumOfElements,
       
  1933     TInt aResourceIdSingle,
       
  1934     TInt aResourceIdOneFinal,
       
  1935     TInt aResourceIdTwoFour,
       
  1936     TInt aResourceIdFiveZero,
       
  1937     HBufC*& aStrings )
       
  1938     {
       
  1939     MPX_FUNC( "CMPXMetadataEditorDialog::AddSinglePartOfTimeL" );
       
  1940     TInt finalOneDigit = aNumOfElements % KMPXOneDigit;
       
  1941     TInt finalTwoDigits = aNumOfElements % KMPXTwoDigits;
       
  1942 
       
  1943     if ( aNumOfElements == 1 )
       
  1944         {
       
  1945         aStrings = StringLoader::LoadLC( aResourceIdSingle );
       
  1946         }
       
  1947     else if ( finalOneDigit == 1 && finalTwoDigits != KDigitEleven )
       
  1948         {
       
  1949         // Used for period of years ending with 1 from 21 (21, 31, 41, etc.)
       
  1950         aStrings = StringLoader::LoadLC( aResourceIdOneFinal, aNumOfElements );
       
  1951         }
       
  1952     else if ( finalOneDigit == 0 ||
       
  1953             ( finalOneDigit >= KDigitFive && finalOneDigit <= KDigitNine ) ||
       
  1954             ( finalTwoDigits >= KDigitEleven && finalTwoDigits <= KDigitFourTeen ) )
       
  1955         {
       
  1956         // Used for period of minutes ending from 5 to 0 plus range between 11
       
  1957         // and 14 (5-20, 25-30, 35-40, 45-50, 53-59)
       
  1958         aStrings = StringLoader::LoadLC( aResourceIdFiveZero, aNumOfElements );
       
  1959         }
       
  1960     else
       
  1961         {
       
  1962         // Used for period of minutes ending from 2 to 4, excluded 12-14 (2-4,
       
  1963         // 22-24, 32-34, 42-44, 52-54)
       
  1964         aStrings = StringLoader::LoadLC( aResourceIdTwoFour, aNumOfElements );
       
  1965         }
       
  1966     }
       
  1967 
       
  1968 // -----------------------------------------------------------------------------
       
  1969 // CMPXMetadataEditorDialog::LanguageSpecificNumberConversion
       
  1970 // -----------------------------------------------------------------------------
       
  1971 //
       
  1972 void CMPXMetadataEditorDialog::LanguageSpecificNumberConversion( TDes& aText ) const
       
  1973     {
       
  1974     MPX_FUNC( "CMPXMetadataEditorDialog::LanguageSpecificNumberConversion" );
       
  1975     if ( AknTextUtils::DigitModeQuery( AknTextUtils::EDigitModeShownToUser ) )
       
  1976         {
       
  1977         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( aText );
       
  1978         }
       
  1979     }
       
  1980 
       
  1981 
       
  1982 // ----------------------------------------------------------------------------
       
  1983 // Converts the time value to localtime
       
  1984 // ----------------------------------------------------------------------------
       
  1985 //
       
  1986 void CMPXMetadataEditorDialog::ConvertToLocalTimeL(TTime& aTime )
       
  1987     {
       
  1988     RTz timeConverter;
       
  1989     CleanupClosePushL(timeConverter);
       
  1990     User::LeaveIfError( timeConverter.Connect() );
       
  1991     User::LeaveIfError( timeConverter.ConvertToLocalTime( aTime ) );
       
  1992     CleanupStack::PopAndDestroy();
       
  1993     }
       
  1994 
       
  1995 // -----------------------------------------------------------------------------
       
  1996 // CMPXMetadataEditorDialog::AddItemToListBoxL
       
  1997 // -----------------------------------------------------------------------------
       
  1998 //
       
  1999 void CMPXMetadataEditorDialog::AddItemToListBoxL(
       
  2000     const TDesC& aHeading,
       
  2001     const TDesC& aValue,
       
  2002     CDesCArray* aItemArray )
       
  2003     {
       
  2004     MPX_FUNC( "CMPXMetadataEditorDialog::AddItemToListBoxL" );
       
  2005     CDesCArrayFlat* items = new (ELeave) CDesCArrayFlat( 2 );
       
  2006     CleanupStack::PushL( items );
       
  2007     items->AppendL( aHeading ); //First string (heading)
       
  2008     items->AppendL( aValue );   //Second string (value)
       
  2009     HBufC* headingAndValue =
       
  2010             StringLoader::LoadLC( R_MPX_CUI_METADATAEDITOR_FILE_DETAILS_ROW_FORMAT, *items );
       
  2011 
       
  2012     aItemArray->AppendL( *headingAndValue );
       
  2013     CleanupStack::PopAndDestroy( headingAndValue );
       
  2014     CleanupStack::PopAndDestroy( items );
       
  2015     }
       
  2016 
       
  2017 // -----------------------------------------------------------------------------
       
  2018 // CMPXMetadataEditorDialog::HandleControlStateChangeL
       
  2019 // Handle State Changes in Genre popup.
       
  2020 // -----------------------------------------------------------------------------
       
  2021 //
       
  2022 void CMPXMetadataEditorDialog::HandleControlStateChangeL( TInt aControlId )
       
  2023     {
       
  2024     MPX_FUNC( "CMPXMetadataEditorDialog::HandleControlStateChangeL" );
       
  2025     if( !iTryingExit )
       
  2026         {
       
  2027         if ( aControlId == EMPXMetadataEditorDlgCtrlIdGenre )
       
  2028             {
       
  2029             // check to see if the genre pop has item custom selected
       
  2030             if ( iTextValues->CurrentValueIndex() == 0 )
       
  2031                 {
       
  2032                 HBufC* genreName = HBufC::NewLC( KMPXSongDetailsTextMaxLen );
       
  2033                 TPtr genrePtr = genreName->Des();
       
  2034                 CAknTextQueryDialog* queryDlg =
       
  2035                     CAknTextQueryDialog::NewL( genrePtr );
       
  2036                 CleanupStack::PushL( queryDlg );
       
  2037                 HBufC* promptTxt = NULL;
       
  2038                 if ( iCurrentLibrary == EMPXMetadataEditorDlgCollection )
       
  2039                     {
       
  2040                     promptTxt = StringLoader::LoadLC( R_MPX_CUI_CUSTOM_GENRE_RENAME_TEXT );
       
  2041                     }
       
  2042                 else
       
  2043                     {
       
  2044                     promptTxt = StringLoader::LoadLC( R_MPX_CUI_CUSTOM_CATEGORY_RENAME_TEXT );
       
  2045                     }
       
  2046                 queryDlg->SetPromptL( *promptTxt );
       
  2047                 queryDlg->SetPredictiveTextInputPermitted( ETrue );
       
  2048                 CleanupStack::PopAndDestroy( promptTxt );
       
  2049                 CleanupStack::Pop( queryDlg );
       
  2050                 if ( queryDlg->ExecuteLD( R_MPX_CUI_CUSTOM_GENRE_NAME_QUERY_DLG ) )
       
  2051                     {
       
  2052                     TBool isHandled = EFalse;
       
  2053                     TBool tryExit = EFalse;
       
  2054                     if ( iCurrentLibrary == EMPXMetadataEditorDlgCollection )
       
  2055                         {
       
  2056                         // in music libray, if genre is set to podcast, ask user
       
  2057                         // to confirm move to podcast database
       
  2058                         HBufC* podcastText = StringLoader::LoadLC( R_MPX_QTN_NMP_GENRE_PODCAST );
       
  2059                         if ( genreName->Des().CompareF( *podcastText ) == 0 &&
       
  2060                              !iDisablePodcasting )
       
  2061                             {
       
  2062                             isHandled = ETrue;
       
  2063                             // genre is set to podcast
       
  2064                             if ( PromptForLibraryChangeL( EMPXMetadataEditorDlgPodcast ) )
       
  2065                                 {
       
  2066                                 MPX_DEBUG1( "CMPXMetadataEditorDialog::HandleControlStateChangeL Move to a different library" );
       
  2067                                 iCollectionUiHelper->MoveL( iMedia, TUid::Uid(EMPXCollectionPluginPodCast) , this);
       
  2068                                 tryExit = ETrue;
       
  2069                                 iTryingExit = ETrue;
       
  2070                                 }
       
  2071                             }
       
  2072                         CleanupStack::PopAndDestroy( podcastText );
       
  2073                         }
       
  2074                     if ( !isHandled )
       
  2075                         {
       
  2076                         // ok selected
       
  2077                         CMPXMedia* media = CMPXMedia::NewL();
       
  2078                         CleanupStack::PushL( media );
       
  2079                         iMedia->SetTextValueL(
       
  2080                             KMPXMediaMusicGenre, genreName->Des() );
       
  2081                         media->SetTextValueL(
       
  2082                             KMPXMediaMusicGenre, genreName->Des() );
       
  2083                         SaveMediaPropertiesL( media );
       
  2084                         CleanupStack::PopAndDestroy( media );
       
  2085                         }
       
  2086                     if ( !tryExit )
       
  2087                         {
       
  2088                         FetchGenreL();
       
  2089                         }
       
  2090                     }
       
  2091                 else
       
  2092                     {
       
  2093                     // Text query cancelled.  Display popup list again.
       
  2094                     iPopup->ActivateSelectionListL();
       
  2095                     
       
  2096                     // reset to original index
       
  2097                     TInt genreIndex;
       
  2098                     iGenreArr->Find( iMedia->ValueText( KMPXMediaMusicGenre ), genreIndex );
       
  2099                     iTextValues->SetCurrentValueIndex( genreIndex );
       
  2100                     }
       
  2101                 CleanupStack::PopAndDestroy( genreName );
       
  2102                 }
       
  2103             else
       
  2104                 {
       
  2105                 if ( iUnknownGenre &&
       
  2106                     ( iTextValues->CurrentValueIndex() == ( iTextValues->MdcArray()->MdcaCount() - 1 ) ) )
       
  2107                     {
       
  2108                     MPX_DEBUG1( "CMPXMetadataEditorDialog::HandleControlStateChangeL last entry with unknown genre, do nothing" );
       
  2109                     }
       
  2110                 else
       
  2111                     {
       
  2112                     CMPXMedia* media = CMPXMedia::NewL();
       
  2113                     CleanupStack::PushL( media );
       
  2114                     HBufC* currentTxt = iTextValues->CurrentValueTextLC();
       
  2115                     iMedia->SetTextValueL( KMPXMediaMusicGenre, *currentTxt );
       
  2116                     media->SetTextValueL( KMPXMediaMusicGenre, *currentTxt );
       
  2117                     CleanupStack::PopAndDestroy( currentTxt );
       
  2118                     SaveMediaPropertiesL( media );
       
  2119                     CleanupStack::PopAndDestroy( media );
       
  2120                     FetchGenreL();
       
  2121                     }
       
  2122                 }
       
  2123             }
       
  2124         else if ( aControlId == EMPXMetadataEditorDlgCtrlIdLibrary )
       
  2125             {
       
  2126             TInt currentIndex = iLibraryTextValues->CurrentValueIndex();
       
  2127             if ( iCurrentLibrary != currentIndex )
       
  2128                 {
       
  2129                 if ( PromptForLibraryChangeL( currentIndex ) )
       
  2130                     {
       
  2131                     MPX_DEBUG1( "CMPXMetadataEditorDialog::HandleControlStateChangeL Move to a different library" );
       
  2132                     TUid targetCollection = TUid::Uid( EMPXCollectionPluginMusic );
       
  2133                     if ( currentIndex == EMPXMetadataEditorDlgPodcast )
       
  2134                         {
       
  2135                         targetCollection = TUid::Uid(EMPXCollectionPluginPodCast);
       
  2136                         }
       
  2137                     // before moving, save current data
       
  2138                     SaveFormDataL();
       
  2139                     iCurrentLibrary = currentIndex; // Fix for ELWG-7AACMS prevent the if clause to be reentried.
       
  2140                     iCollectionUiHelper->MoveL( iMedia, targetCollection, this );
       
  2141                     iTryingExit = ETrue;
       
  2142                     }
       
  2143                 else
       
  2144                     {
       
  2145                     iLibraryTextValues->SetCurrentValueIndex( iCurrentLibrary );
       
  2146                     // Fix EIZU-7QQAZN, Let it display back to "Music" immediately.
       
  2147                     if ( IdOfFocusControl() == EMPXMetadataEditorDlgCtrlIdLibrary )
       
  2148                         {
       
  2149                         iPopup = static_cast<CAknPopupField*>
       
  2150                                         ( ControlOrNull( EMPXMetadataEditorDlgCtrlIdLibrary ) );
       
  2151                         if ( iPopup )
       
  2152                             {
       
  2153                             iPopup->SetQueryValueL( iLibraryTextValues );
       
  2154                             iPopup->DrawDeferred();
       
  2155                             }
       
  2156                         }
       
  2157                     }
       
  2158                 }
       
  2159             }
       
  2160         }
       
  2161     CAknForm::HandleControlStateChangeL( aControlId );
       
  2162     }
       
  2163 
       
  2164 // -----------------------------------------------------------------------------
       
  2165 // CMPXMetadataEditorDialog::PrepareForFocusTransitionL
       
  2166 // Handle Focus changes for track and year controls.
       
  2167 // -----------------------------------------------------------------------------
       
  2168 //
       
  2169 void CMPXMetadataEditorDialog::PrepareForFocusTransitionL()
       
  2170     {
       
  2171     MPX_FUNC( "CMPXMetadataEditorDialog::PrepareForFocusTransitionL" );
       
  2172     CAknForm::PrepareForFocusTransitionL();
       
  2173     }
       
  2174 
       
  2175 // -----------------------------------------------------------------------------
       
  2176 // CMPXMetadataEditorDialog::GetHelpContext
       
  2177 // Gets Help
       
  2178 // (other items were commented in a header).
       
  2179 // -----------------------------------------------------------------------------
       
  2180 //
       
  2181 void CMPXMetadataEditorDialog::GetHelpContext(
       
  2182     TCoeHelpContext& aContext ) const
       
  2183     {
       
  2184     MPX_FUNC( "CMPXMetadataEditorDialog::GetHelpContext" );
       
  2185     aContext.iMajor = KAppUidMusicPlayerX;
       
  2186     aContext.iContext = KMUS_HLP_METADATA_EDITING;
       
  2187     }
       
  2188 
       
  2189 // -----------------------------------------------------------------------------
       
  2190 // CMPXMetadataEditorDialog::HandleFindAllL
       
  2191 // Handle callback for "find" operation
       
  2192 // -----------------------------------------------------------------------------
       
  2193 //
       
  2194 void CMPXMetadataEditorDialog::HandleFindAllL(const CMPXMedia& aResults,
       
  2195                                TBool /*aComplete*/, TInt aError)
       
  2196     {
       
  2197     MPX_FUNC( "CMPXMetadataEditorDialog::HandleFindAllL" );
       
  2198     iPopup = static_cast<CAknPopupField*>
       
  2199         ( ControlOrNull( EMPXMetadataEditorDlgCtrlIdGenre ) );
       
  2200     CleanUpGenreText();
       
  2201     // populate predefined genre
       
  2202     TResourceReader reader;
       
  2203     if ( iCurrentLibrary == EMPXMetadataEditorDlgCollection )
       
  2204         {
       
  2205         if( !iDisablePodcasting )
       
  2206             {
       
  2207             iEikonEnv->CreateResourceReaderLC( reader, R_MPX_MUSIC_GENRE_STRINGS );
       
  2208             }
       
  2209         else
       
  2210             {
       
  2211             iEikonEnv->CreateResourceReaderLC( reader, R_MPX_MUSIC_GENRE_STRINGS_PODCAST );
       
  2212             }
       
  2213         }
       
  2214     else if ( iCurrentLibrary == EMPXMetadataEditorDlgPodcast )
       
  2215         {
       
  2216         iEikonEnv->CreateResourceReaderLC(
       
  2217             reader, R_MPX_PODCAST_CATEGORY_STRINGS );
       
  2218         }
       
  2219     iGenreArr = reader.ReadDesCArrayL( );
       
  2220     CleanupStack::PopAndDestroy(); // reader
       
  2221 
       
  2222     // populate genres from database
       
  2223     if ( aError == KErrNone )
       
  2224         {
       
  2225         const CMPXMediaArray* mediaArray =
       
  2226             aResults.Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
  2227         User::LeaveIfNull(const_cast<CMPXMediaArray*>(mediaArray));
       
  2228         
       
  2229         TInt entriesCount( mediaArray->Count() );
       
  2230         MPX_DEBUG2( "CMPXMetadataEditorDialog::HandleFindAllL genres from database count = %d", entriesCount );
       
  2231         for ( TInt i = 0; i < entriesCount; i++ )
       
  2232             {
       
  2233             CMPXMedia* media = mediaArray->AtL( i );
       
  2234             TInt location( 0 );
       
  2235             const TDesC& genre = media->ValueText( KMPXMediaGeneralTitle );
       
  2236             if ( i == entriesCount - 1)
       
  2237                 {
       
  2238                 if ( genre.Compare( KNullDesC ) != 0 )
       
  2239                     {
       
  2240                     // if last item is a null descriptor, don't append to array
       
  2241                     if ( iGenreArr->Find( genre, location ) != 0 )
       
  2242                         {
       
  2243                         // a match is not found
       
  2244                         MPX_DEBUG1( "CMPXMetadataEditorDialog::HandleFindAllL adding to genre list" );
       
  2245                         iGenreArr->AppendL( genre );
       
  2246                         }
       
  2247                     }
       
  2248                 }
       
  2249             else
       
  2250                 {
       
  2251                 if ( iGenreArr->Find( genre, location ) != 0 )
       
  2252                     {
       
  2253                     // a match is not found
       
  2254                     MPX_DEBUG1( "CMPXMetadataEditorDialog::HandleFindAllL adding to genre list" );
       
  2255                     iGenreArr->AppendL( genre );
       
  2256                     }
       
  2257                 }
       
  2258             }
       
  2259         }
       
  2260     iGenreArr->Sort(ECmpCollated);
       
  2261     
       
  2262     if ( iCurrentLibrary == EMPXMetadataEditorDlgCollection )
       
  2263         {
       
  2264             HBufC* custTxt =
       
  2265             StringLoader::LoadLC( R_MPX_CUI_CUSTOM_GENRE_PROMPT_TEXT );
       
  2266             iGenreArr->InsertL( 0, *custTxt );
       
  2267             CleanupStack::PopAndDestroy( custTxt );
       
  2268         }
       
  2269     else if ( iCurrentLibrary == EMPXMetadataEditorDlgPodcast )
       
  2270         {
       
  2271             HBufC* custTxt =
       
  2272             StringLoader::LoadLC( R_MPX_CUI_PODCAST_CUSTOM_GENRE_PROMPT_TEXT );
       
  2273             iGenreArr->InsertL( 0, *custTxt );
       
  2274             CleanupStack::PopAndDestroy( custTxt );
       
  2275         }
       
  2276 
       
  2277     iValueTextArray = CAknQueryValueTextArray::NewL();
       
  2278     iValueTextArray->SetArray( *iGenreArr );
       
  2279 
       
  2280     iTextValues = CAknQueryValueText::NewL();
       
  2281     iTextValues->SetArrayL( iValueTextArray );
       
  2282     if ( iMedia->ValueText( KMPXMediaMusicGenre ).Length() == 0 )
       
  2283         {
       
  2284         // no genre
       
  2285         iUnknownGenre = ETrue;
       
  2286         HBufC* unknownGenre( StringLoader::LoadLC( R_MPX_CUI_UNKNOWN_GENRE_TEXT ) );
       
  2287         iGenreArr->AppendL( *unknownGenre );
       
  2288         CleanupStack::PopAndDestroy( unknownGenre );
       
  2289         iTextValues->SetCurrentValueIndex( iGenreArr->Count() - 1 );
       
  2290         }
       
  2291     else
       
  2292         {
       
  2293         // Find the genre
       
  2294         iUnknownGenre = EFalse;
       
  2295         TInt genreIndex;
       
  2296         iGenreArr->Find( iMedia->ValueText( KMPXMediaMusicGenre ), genreIndex );
       
  2297         iTextValues->SetCurrentValueIndex( genreIndex );
       
  2298         }
       
  2299     // Set values into popup fields.
       
  2300     iPopup->SetQueryValueL( iTextValues ); // Moved up from below.
       
  2301     iPopup->DrawDeferred();
       
  2302     }
       
  2303 
       
  2304 // ----------------------------------------------------------------------------
       
  2305 // void CMPXMetadataEditorDialog::HandleOperationCompleteL
       
  2306 // Handle callback for the ui helper.
       
  2307 // ----------------------------------------------------------------------------
       
  2308 //
       
  2309 void CMPXMetadataEditorDialog::HandleOperationCompleteL(
       
  2310     TCHelperOperation aOperation,
       
  2311     TInt aErr, void* aArgument )
       
  2312     {
       
  2313     MPX_FUNC( "CMPXMetadataEditorDialog::HandleOperationCompleteL" );
       
  2314     if ( aOperation == EMoveOp )
       
  2315         {
       
  2316         if ( aErr != KErrNone )
       
  2317             {
       
  2318             // TO-DO: error handling
       
  2319             }
       
  2320         // move complete, quit the editor
       
  2321         if ( iIdle )
       
  2322             {
       
  2323             iIdle->Cancel();
       
  2324             delete iIdle;
       
  2325             iIdle = NULL;
       
  2326             }
       
  2327         iIdle = CIdle::NewL( CActive::EPriorityStandard );
       
  2328         iIdle->Start( TCallBack( CMPXMetadataEditorDialog::DeferredExitCallback, this ) );
       
  2329         }
       
  2330     if ( aArgument )
       
  2331         {
       
  2332         delete (CBase*)aArgument;
       
  2333         }
       
  2334     }
       
  2335 
       
  2336 // ----------------------------------------------------------------------------
       
  2337 // void CMPXMetadataEditorDialog::DeferredExitCallback
       
  2338 // call back function for deferred exit.
       
  2339 // ----------------------------------------------------------------------------
       
  2340 //
       
  2341 TInt CMPXMetadataEditorDialog::DeferredExitCallback( TAny* aPtr )
       
  2342     {
       
  2343     MPX_FUNC( "CMPXMetadataEditorDialog::DeferredExitCallback" );
       
  2344     CMPXMetadataEditorDialog* self =
       
  2345         static_cast<CMPXMetadataEditorDialog*>( aPtr );
       
  2346     TRAP_IGNORE( self->TryExitL( EAknSoftkeyExit ) );
       
  2347     return KErrNone;
       
  2348     }
       
  2349 
       
  2350 // ----------------------------------------------------------------------------
       
  2351 // void CMPXMetadataEditorDialog::DeferredFileDetailsCallback
       
  2352 // call back function for deferred file details dialog.
       
  2353 // ----------------------------------------------------------------------------
       
  2354 //
       
  2355 TInt CMPXMetadataEditorDialog::DeferredFileDetailsCallback( TAny* aPtr )
       
  2356     {
       
  2357     MPX_FUNC( "CMPXMetadataEditorDialog::DeferredFileDetailsCallback" );
       
  2358     CMPXMetadataEditorDialog* self =
       
  2359         static_cast<CMPXMetadataEditorDialog*>( aPtr );
       
  2360     TRAP_IGNORE( self->ViewFileDetailsPopupL() );
       
  2361     return KErrNone;
       
  2362     }
       
  2363 
       
  2364 #ifdef __ENABLE_MSK
       
  2365 // -----------------------------------------------------------------------------
       
  2366 // CMPXAddTracksDialog::UpdateSoftkeyL()
       
  2367 // Update softkey.
       
  2368 // (other items were commented in a header).
       
  2369 // -----------------------------------------------------------------------------
       
  2370 //
       
  2371 void CMPXMetadataEditorDialog::UpdateSoftkeyL()
       
  2372     {
       
  2373     MPX_FUNC( "CMPXMetadataEditorDialog::UpdateSoftkeyL" );
       
  2374     TInt resId( 0 );
       
  2375 
       
  2376     if ( ( IdOfFocusControl() == EMPXMetadataEditorDlgCtrlIdGenre ) ||
       
  2377         ( IdOfFocusControl() == EMPXMetadataEditorDlgCtrlIdLibrary ) )
       
  2378         {
       
  2379         resId = R_MPX_CUI_SONG_DETAILS_SOFTKEYS_OPTIONS_CHANGE_DONE;
       
  2380         }
       
  2381     else
       
  2382         {
       
  2383         resId = R_MPX_CUI_SONG_DETAILS_SOFTKEYS_OPTIONS_EMPTY_BACK;
       
  2384         }
       
  2385 
       
  2386     ButtonGroupContainer().SetCommandSetL( resId );
       
  2387     ButtonGroupContainer().DrawDeferred();
       
  2388     }
       
  2389 
       
  2390 // -----------------------------------------------------------------------------
       
  2391 // CMPXMetadataEditorDialog::OfferKeyEventL
       
  2392 // Handles key-events.
       
  2393 // (other items were commented in a header).
       
  2394 // -----------------------------------------------------------------------------
       
  2395 //
       
  2396 TKeyResponse CMPXMetadataEditorDialog::OfferKeyEventL(
       
  2397     const TKeyEvent& aKeyEvent,
       
  2398     TEventCode aType )
       
  2399     {
       
  2400     MPX_FUNC( "CMPXMetadataEditorDialog::OfferKeyEventL" );
       
  2401     TKeyResponse res = CAknForm::OfferKeyEventL( aKeyEvent, aType );
       
  2402 
       
  2403     if ( aType == EEventKey )
       
  2404         {
       
  2405         if (aKeyEvent.iScanCode && (aKeyEvent.iScanCode == EStdKeyUpArrow
       
  2406                 || aKeyEvent.iScanCode == EStdKeyDownArrow))
       
  2407             {
       
  2408             UpdateSoftkeyL();
       
  2409             }
       
  2410 
       
  2411         else if ((aKeyEvent.iCode == EKeyOK || aKeyEvent.iCode == EKeyEnter)
       
  2412                 && (IdOfFocusControl() == EMPXMetadataEditorDlgCtrlIdDRMDetail))
       
  2413             {
       
  2414             LaunchDrmInfoL();
       
  2415             }
       
  2416         }
       
  2417 
       
  2418     return res;
       
  2419     }
       
  2420 #endif // __ENABLE_MSK
       
  2421 
       
  2422 // ----------------------------------------------------------------------------
       
  2423 // void CMPXMetadataEditorDialog::PreLayoutDynInitL
       
  2424 // Initialises the dialog's controls before the dialog is sized and layed out.
       
  2425 // ----------------------------------------------------------------------------
       
  2426 //
       
  2427 void CMPXMetadataEditorDialog::PreLayoutDynInitL()
       
  2428     {
       
  2429     MPX_FUNC( "CMPXMetadataEditorDialog::PreLayoutDynInitL" );
       
  2430     SetTitlePaneL();
       
  2431     SetNaviLabelL();
       
  2432 
       
  2433     // Get media property for the current song
       
  2434     
       
  2435     if ( iParam ) // Dialog launched from CollectionView
       
  2436         {
       
  2437 		CMPXCollectionPath* cpath = iCollectionUtility->Collection().PathL();
       
  2438         CleanupStack::PushL( cpath );
       
  2439         TLex yearLex( iParam->Des() );
       
  2440         TInt lexToInt = NULL;
       
  2441         if ( yearLex.Val( lexToInt ) == KErrNone )
       
  2442             {
       
  2443             cpath->Set( lexToInt );
       
  2444             RArray<TMPXAttribute> attrs;
       
  2445             CleanupClosePushL(attrs);
       
  2446             attrs.Append( KMPXMediaGeneralAll );
       
  2447             attrs.Append( KMPXMediaAudioAudioAll );
       
  2448             attrs.Append( KMPXMediaMusicAll );
       
  2449             attrs.Append( KMPXMediaDrmProtected );
       
  2450             if ( iCurrentLibrary == EMPXMetadataEditorDlgPodcast )
       
  2451                 {
       
  2452                 attrs.Append(
       
  2453                     TMPXAttribute( KMPXMediaIdPodcast, EMPXMediaPodcastAll ) );
       
  2454                 }
       
  2455             iCurrentMediaLOp = EMPXMetadataEditorGetSongInfo;
       
  2456             iCollectionUtility->Collection().MediaL( *cpath, attrs.Array() );
       
  2457             CleanupStack::PopAndDestroy( &attrs );
       
  2458             }
       
  2459 		CleanupStack::PopAndDestroy( cpath );	
       
  2460         }
       
  2461     else // Dialog launched from NowPlayingView
       
  2462         {
       
  2463         // Get the playback utility instance from engine.
       
  2464         iPlaybackUtility = MMPXPlaybackUtility::UtilityL( KPbModeDefault );
       
  2465         iPlaybackUtility->AddObserverL( *this );
       
  2466         MMPXSource* s = iPlaybackUtility->Source();
       
  2467         if ( s )
       
  2468             {
       
  2469             RArray<TMPXAttribute> attrs;
       
  2470             CleanupClosePushL(attrs);
       
  2471             attrs.Append( KMPXMediaGeneralAll );
       
  2472             attrs.Append( KMPXMediaAudioAudioAll );
       
  2473             attrs.Append( KMPXMediaMusicAll );
       
  2474             attrs.Append( KMPXMediaDrmProtected );
       
  2475             if ( iCurrentLibrary == EMPXMetadataEditorDlgPodcast )
       
  2476                 {
       
  2477                  attrs.Append(
       
  2478                       TMPXAttribute( KMPXMediaIdPodcast, EMPXMediaPodcastAll ) );
       
  2479                 }
       
  2480                 iCurrentMediaLOp = EMPXMetadataEditorGetSongInfo;
       
  2481                 s->MediaL(attrs.Array(), *this);
       
  2482                 CleanupStack::PopAndDestroy( &attrs );
       
  2483             }  
       
  2484         }
       
  2485     }
       
  2486 
       
  2487 // ----------------------------------------------------------------------------
       
  2488 // CMPXMetadataEditorDialog::PostLayoutDynInitL
       
  2489 // Set default field value to member data.
       
  2490 // ----------------------------------------------------------------------------
       
  2491 //
       
  2492 void CMPXMetadataEditorDialog::PostLayoutDynInitL()
       
  2493     {
       
  2494     MPX_FUNC( "CMPXMetadataEditorDialog::PostLayoutDynInitL" );
       
  2495     CAknForm::PostLayoutDynInitL();
       
  2496     SetEditableL( EFalse );
       
  2497     }
       
  2498 
       
  2499 // -----------------------------------------------------------------------------
       
  2500 // CMPXMetadataEditorDialog::HandlePlaybackMessage
       
  2501 // Handle playback message.
       
  2502 // ---------------------------------------------------------------------------
       
  2503 //
       
  2504 void CMPXMetadataEditorDialog::HandlePlaybackMessage(
       
  2505     CMPXMessage* aMessage, TInt aError )
       
  2506     {
       
  2507     MPX_DEBUG2 ( "CMPXMetadataEditorDialog::HandlePlaybackMessage aError %d " ,aError );
       
  2508     if ( aError == KErrNone && aMessage )
       
  2509         {
       
  2510         TRAP_IGNORE( DoHandlePlaybackMessageL( *aMessage ) );
       
  2511         }
       
  2512     else if ( aError != KErrNone )
       
  2513         {
       
  2514         TryExitL( EAknSoftkeyExit );
       
  2515         }
       
  2516     }
       
  2517 
       
  2518 
       
  2519 // ---------------------------------------------------------------------------
       
  2520 // CMPXMetadataEditorDialog::HandlePlaybackMessage
       
  2521 // Handle playback message.
       
  2522 // ---------------------------------------------------------------------------
       
  2523 //
       
  2524 void CMPXMetadataEditorDialog::DoHandlePlaybackMessageL(
       
  2525     const CMPXMessage& aMessage )
       
  2526     {
       
  2527     MPX_FUNC( "CMPXMetadataEditorDialog::DoHandlePlaybackMessageL(CMPXMessage)" );
       
  2528 
       
  2529     TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) );
       
  2530     TInt value = aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent );
       
  2531     if ( KMPXMessageGeneral == id && 
       
  2532         ( ( value  == TMPXPlaybackMessage::EMediaChanged ) || ( value  == TMPXPlaybackMessage::ESkipping ) ) )
       
  2533         {
       
  2534         MPX_DEBUG1( "CMPXMetadataEditorDialog::DoHandlePlaybackMessageL Dismissing Details view - change in playing media" );
       
  2535         TryExitL( EAknSoftkeyExit );
       
  2536         }
       
  2537     }
       
  2538 
       
  2539 // -----------------------------------------------------------------------------
       
  2540 // CMPXMetadataEditorDialog::SaveMediaPropertiesL
       
  2541 // Saves media back to collection engine
       
  2542 // -----------------------------------------------------------------------------
       
  2543 //
       
  2544 void CMPXMetadataEditorDialog::SaveMediaPropertiesL( CMPXMedia* aMedia )
       
  2545     {
       
  2546     MPX_FUNC( "CMPXMetadataEditorDialog::SaveMediaPropertiesL" );
       
  2547     if ( iMedia->IsSupported( KMPXMediaGeneralUri ) )
       
  2548         {
       
  2549         aMedia->SetTextValueL(
       
  2550             KMPXMediaGeneralUri, iMedia->ValueText( KMPXMediaGeneralUri ) );
       
  2551         }
       
  2552 
       
  2553     if ( iMedia->IsSupported( KMPXMediaGeneralType ) )
       
  2554         {
       
  2555         aMedia->SetTObjectValueL<TInt>(
       
  2556             KMPXMediaGeneralType, iMedia->ValueTObjectL<TInt>( KMPXMediaGeneralType ) );
       
  2557         }
       
  2558 
       
  2559     if ( iMedia->IsSupported( KMPXMediaGeneralCategory ) )
       
  2560         {
       
  2561         aMedia->SetTObjectValueL<TInt>(
       
  2562             KMPXMediaGeneralCategory,
       
  2563             iMedia->ValueTObjectL<TInt>( KMPXMediaGeneralCategory ) );
       
  2564         }
       
  2565 
       
  2566     if ( iMedia->IsSupported( KMPXMediaGeneralId ) )
       
  2567         {
       
  2568         aMedia->SetTObjectValueL<TMPXItemId>(
       
  2569             KMPXMediaGeneralId, iMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
  2570         }
       
  2571 
       
  2572     if ( iMedia->IsSupported( KMPXMediaGeneralCollectionId ) )
       
  2573         {
       
  2574         aMedia->SetTObjectValueL<TUid>(
       
  2575             KMPXMediaGeneralCollectionId,
       
  2576             iMedia->ValueTObjectL<TUid>( KMPXMediaGeneralCollectionId ) );
       
  2577         }
       
  2578     
       
  2579     if ( iMedia->IsSupported( KMPXMediaMusicAlbumArtFileName ) )
       
  2580         {
       
  2581         aMedia->SetTextValueL(
       
  2582             KMPXMediaMusicAlbumArtFileName,
       
  2583             iMedia->ValueText( KMPXMediaMusicAlbumArtFileName ) );
       
  2584         }
       
  2585 
       
  2586     // toggle the modified flag for the internal media reference
       
  2587     // or else any subsequent FindAllL calls won't be able to
       
  2588     // match against this object
       
  2589     iMedia->SetTObjectValueL<TBool>(KMPXMediaGeneralModified, ETrue);
       
  2590 
       
  2591     // Set to collection via command
       
  2592     //
       
  2593     CMPXCommand* cmd = CMPXCommand::NewL();
       
  2594     CleanupStack::PushL( cmd );
       
  2595 
       
  2596     cmd->SetTObjectValueL( KMPXCommandGeneralId, KMPXCommandIdCollectionSet );
       
  2597     cmd->SetTObjectValueL( KMPXCommandGeneralDoSync, ETrue );
       
  2598     TUid colId(iMedia->ValueTObjectL<TUid>(KMPXMediaGeneralCollectionId));
       
  2599     cmd->SetTObjectValueL( KMPXCommandGeneralCollectionId, colId.iUid );
       
  2600     cmd->SetCObjectValueL<CMPXMedia>( KMPXCommandColSetMedia, aMedia );
       
  2601 
       
  2602     iCollectionUtility->Collection().CommandL( *cmd );
       
  2603     CleanupStack::PopAndDestroy( cmd );
       
  2604     }
       
  2605 
       
  2606 // -----------------------------------------------------------------------------
       
  2607 // CMPXMetadataEditorDialog::AppendStringToArrayL
       
  2608 // Appends the value to the array, if the vaule has zero length,
       
  2609 // appends "unavailable"
       
  2610 // -----------------------------------------------------------------------------
       
  2611 //
       
  2612 void CMPXMetadataEditorDialog::AppendStringToArrayL(
       
  2613     CDesCArrayFlat* aArray, const TDesC& aValue )
       
  2614     {
       
  2615     MPX_FUNC( "CMPXMetadataEditorDialog::AppendStringToArrayL" );
       
  2616     if ( aValue.Length() > 0 )
       
  2617         {
       
  2618         HBufC* stringBuf = HBufC::NewLC(
       
  2619             aValue.Length() + KMPXFileDetailsExtraBufferLen );
       
  2620         TPtr stringBufPtr = stringBuf->Des();
       
  2621         stringBufPtr.Append( aValue );
       
  2622         aArray->AppendL( stringBufPtr );
       
  2623         CleanupStack::PopAndDestroy( stringBuf );
       
  2624         }
       
  2625     else
       
  2626         {
       
  2627         aArray->AppendL( KNullDesC );
       
  2628         }
       
  2629     }
       
  2630 
       
  2631 // -----------------------------------------------------------------------------
       
  2632 // CMPXMetadataEditorDialog::SetControlTextL
       
  2633 // Sets control text
       
  2634 // -----------------------------------------------------------------------------
       
  2635 //
       
  2636 void CMPXMetadataEditorDialog::SetControlTextL( TInt aControlId,
       
  2637     const TDesC& aValue, const TDesC& aAlternateValue )
       
  2638     {
       
  2639     MPX_FUNC( "CMPXMetadataEditorDialog::SetControlTextL" );
       
  2640     CEikEdwin* myEdwin = static_cast< CEikEdwin* >
       
  2641         ( ControlOrNull( aControlId ) );
       
  2642     if ( myEdwin )
       
  2643         {
       
  2644         if ( aValue.Length() > 0 )
       
  2645             {
       
  2646             myEdwin->SetTextL( &( aValue ) );
       
  2647             }
       
  2648         else if ( aAlternateValue.Length() > 0 )
       
  2649             {
       
  2650             myEdwin->SetTextL( &( aAlternateValue ) );
       
  2651             }
       
  2652         }
       
  2653     }
       
  2654 
       
  2655 // -----------------------------------------------------------------------------
       
  2656 // CMPXMetadataEditorDialog::SetControlNumberL
       
  2657 // Sets control number
       
  2658 // -----------------------------------------------------------------------------
       
  2659 //
       
  2660 void CMPXMetadataEditorDialog::SetControlNumberL( TInt aControlId,
       
  2661     const TDesC& aValue, TInt aMinValue, TInt aMaxValue )
       
  2662     {
       
  2663     MPX_FUNC( "CMPXMetadataEditorDialog::SetControlNumberL" );
       
  2664     CEikEdwin* myEdwin = static_cast< CEikEdwin* >
       
  2665         ( ControlOrNull( aControlId ) );
       
  2666     
       
  2667     if ( myEdwin )
       
  2668         {
       
  2669         if ( aValue.Length() > 0 )
       
  2670             {
       
  2671             TLex numLex( aValue );
       
  2672             TInt LexToInt;
       
  2673             if ( numLex.Val( LexToInt ) == KErrNone )
       
  2674                 {
       
  2675                 if ( LexToInt > aMaxValue )
       
  2676                     {
       
  2677                     LexToInt = aMaxValue;
       
  2678                     }
       
  2679                 if ( LexToInt < aMinValue )
       
  2680                     {
       
  2681                     LexToInt = aMinValue;
       
  2682                     }
       
  2683                 TBuf<KMPXSongDetailsNumTextWidth> num;
       
  2684                 num.AppendNum( LexToInt );
       
  2685 			    myEdwin->SetTextL( &num );
       
  2686                 }
       
  2687             }
       
  2688         }
       
  2689     }
       
  2690 
       
  2691 // -----------------------------------------------------------------------------
       
  2692 // CMPXMetadataEditorDialog::PromptForLibraryChangeL
       
  2693 // prompt user for library change
       
  2694 // -----------------------------------------------------------------------------
       
  2695 //
       
  2696 TBool CMPXMetadataEditorDialog::PromptForLibraryChangeL( TInt aMoveToLibrary )
       
  2697     {
       
  2698     MPX_FUNC( "CMPXMetadataEditorDialog::PromptForLibraryChangeL" );
       
  2699     CMPXQueryDialog* confirmationDlg = CMPXQueryDialog::NewL();
       
  2700     CleanupStack::PushL( confirmationDlg );
       
  2701     HBufC* libraryName = NULL;
       
  2702     if ( aMoveToLibrary == EMPXMetadataEditorDlgCollection )
       
  2703         {
       
  2704         libraryName =
       
  2705             StringLoader::LoadLC( R_MPX_CUI_GENRE_SELECTION_MUSIC_TEXT );
       
  2706         }
       
  2707     else if ( aMoveToLibrary == EMPXMetadataEditorDlgPodcast )
       
  2708         {
       
  2709         libraryName =
       
  2710             StringLoader::LoadLC( R_MPX_CUI_GENRE_SELECTION_PODCAST_TEXT );
       
  2711         }
       
  2712     else
       
  2713         {
       
  2714         // should not reach here
       
  2715         User::Leave( KErrArgument );
       
  2716         }
       
  2717     HBufC* promptTxt = StringLoader::LoadLC(
       
  2718         R_MPX_CUI_QUERY_MOVE_TO_LIBRARY, libraryName->Des() );
       
  2719     confirmationDlg->SetPromptL( *promptTxt );
       
  2720     CleanupStack::PopAndDestroy( promptTxt );
       
  2721 
       
  2722 
       
  2723     confirmationDlg->PublishDialogL(
       
  2724         EMPlayerQueryMoveToLibrary,
       
  2725         KMPlayerNoteCategory);
       
  2726 
       
  2727     CAknMediatorFacade* covercl(
       
  2728         AknMediatorFacade( confirmationDlg ) );
       
  2729     if ( covercl )
       
  2730         {
       
  2731         covercl->BufStream() << libraryName->Des();
       
  2732         }
       
  2733     CleanupStack::PopAndDestroy( libraryName );
       
  2734     CleanupStack::Pop( confirmationDlg );
       
  2735     return confirmationDlg->ExecuteLD( R_MPX_CUI_MOVE_TO_LIBRARY_CONFIRMATION_QUERY );
       
  2736     }
       
  2737 
       
  2738 // -----------------------------------------------------------------------------
       
  2739 // CMPXMetadataEditorDialog::UpdateMediaObjectWithControlL
       
  2740 // Updates media object with current control text, this will also
       
  2741 // update iMedia
       
  2742 // -----------------------------------------------------------------------------
       
  2743 //
       
  2744 TBool CMPXMetadataEditorDialog::UpdateMediaObjectWithControlL(
       
  2745     TInt aControlId, CMPXMedia* aMedia, TMPXAttribute aAttribute )
       
  2746     {
       
  2747     MPX_FUNC( "CMPXMetadataEditorDialog::UpdateMediaObjectWithControlL" );
       
  2748     TBool ret = EFalse;
       
  2749     CCoeControl* coeControl = ControlOrNull( aControlId );
       
  2750     if ( coeControl )
       
  2751         {
       
  2752         HBufC* buf = NULL;
       
  2753         switch ( aControlId )
       
  2754             {
       
  2755             case EMPXMetadataEditorDlgCtrlIdSongName:
       
  2756             case EMPXMetadataEditorDlgCtrlIdArtist:
       
  2757             case EMPXMetadataEditorDlgCtrlIdAlbum:
       
  2758             case EMPXMetadataEditorDlgCtrlIdComment:
       
  2759             case EMPXMetadataEditorDlgCtrlIdComposer:
       
  2760             case EMPXMetadataEditorDlgCtrlIdTrackNumber:
       
  2761                 {
       
  2762                 CEikEdwin* control = static_cast<CEikEdwin*>( coeControl );
       
  2763                 if ( control )
       
  2764                     {
       
  2765                     buf = control->GetTextInHBufL();
       
  2766                     if ( !buf )
       
  2767                         {
       
  2768                         // the text contains nothing
       
  2769                         // special handling is needed for song name
       
  2770                         if ( aControlId == EMPXMetadataEditorDlgCtrlIdSongName && iMedia )
       
  2771                             {
       
  2772                             if ( iMedia->IsSupported( KMPXMediaGeneralUri ) )
       
  2773                                 {
       
  2774                                 // if URI is defined, use filename as song name
       
  2775                                 TParsePtrC fn( iMedia->ValueText( KMPXMediaGeneralUri ) );
       
  2776                                 buf = fn.Name().AllocL();
       
  2777                                 }
       
  2778                             else
       
  2779                                 {
       
  2780                                 buf = HBufC::NewL( 0 );
       
  2781                                 }
       
  2782                             }
       
  2783                         else
       
  2784                             {
       
  2785                             buf = HBufC::NewL( 0 );
       
  2786                             }
       
  2787                         }
       
  2788                     CleanupStack::PushL( buf );
       
  2789                     }
       
  2790                 else
       
  2791                     {
       
  2792                     // should not reach here
       
  2793                     User::Leave( KErrArgument );
       
  2794                     }
       
  2795                 break;
       
  2796                 }
       
  2797             default:
       
  2798                 {
       
  2799                 // should not reach here
       
  2800                 User::Leave( KErrArgument );
       
  2801                 break;
       
  2802                 }
       
  2803             }
       
  2804         if ( buf )
       
  2805             {
       
  2806             const TDesC& origValue = iMedia->ValueText( aAttribute );
       
  2807             if ( origValue.Compare( *buf ) != 0 )
       
  2808                 {
       
  2809 	                //check if the track number is actually changed
       
  2810 	                if (aControlId == EMPXMetadataEditorDlgCtrlIdTrackNumber &&
       
  2811 	                	origValue.Compare(_L("")) == 0 &&
       
  2812 	                	buf->Compare(_L("0")) == 0)
       
  2813 	                	{
       
  2814 	                	//nothing to do
       
  2815 	                	}
       
  2816 	            	else
       
  2817 	            		{
       
  2818 		                ret = ETrue;
       
  2819 		                iMedia->SetTextValueL( aAttribute , *buf );
       
  2820 		                aMedia->SetTextValueL( aAttribute , *buf );
       
  2821 	            		}
       
  2822                 }
       
  2823             CleanupStack::PopAndDestroy( buf );
       
  2824             }
       
  2825         }
       
  2826     return ret;
       
  2827     }
       
  2828 
       
  2829 
       
  2830 
       
  2831 // -----------------------------------------------------------------------------
       
  2832 // CMPXMetadataEditorDialog::PopulateFileDetailsL
       
  2833 // -----------------------------------------------------------------------------
       
  2834 //
       
  2835 void CMPXMetadataEditorDialog::PopulateFileDetailsL()
       
  2836     {
       
  2837     MPX_FUNC( "CMPXMetadataEditorDialog::PopulateFileDetailsL" );
       
  2838     
       
  2839     ASSERT(iMedia);
       
  2840     TBool drmProtected(iMedia->ValueTObjectL<TBool> (KMPXMediaDrmProtected));
       
  2841     MPX_DEBUG2( "CMPXMetadataEditorDialog::PopulateFileDetailsL drm protected: %d", drmProtected );
       
  2842     
       
  2843     if (drmProtected)
       
  2844         {
       
  2845         HBufC* detail = StringLoader::LoadLC( R_MPX_CUI_LICENCE_DET_LINK );
       
  2846         SetControlTextL(EMPXMetadataEditorDlgCtrlIdDRMDetail, detail->Des(),
       
  2847                 KNullDesC);
       
  2848         CleanupStack::PopAndDestroy( detail );	
       
  2849         }
       
  2850     else
       
  2851         {
       
  2852         DeleteLine(EMPXMetadataEditorDlgCtrlIdDRMDetail,EFalse); 
       
  2853         } 
       
  2854     // Get filename
       
  2855     const TDesC& uri = iMedia->ValueText(KMPXMediaGeneralUri);
       
  2856     TParsePtrC parse(uri);
       
  2857 
       
  2858     SetControlTextL(EMPXMetadataEditorDlgCtrlIdFileName, parse.Name(),
       
  2859             KNullDesC);
       
  2860 
       
  2861     // Get mime type
       
  2862     SetControlTextL(EMPXMetadataEditorDlgCtrlIdFileFormat, iMedia->ValueText(
       
  2863             KMPXMediaGeneralMimeType), KNullDesC);
       
  2864 
       
  2865     // Get duration
       
  2866     TInt duration(iMedia->ValueTObjectL<TInt> (KMPXMediaGeneralDuration));
       
  2867     if (duration > 0)
       
  2868         {
       
  2869         // convert milliseconds to seconds
       
  2870         duration = duration / KSecondInMilliseconds;
       
  2871         CMPXCommonUiHelper::TMPXDuratDisplayMode durationMode =
       
  2872         CMPXCommonUiHelper::EMPXDuratAuto;
       
  2873         if (duration > KOneHourInSeconds)
       
  2874             {
       
  2875             durationMode = CMPXCommonUiHelper::EMPXDuratHMS;
       
  2876             }
       
  2877         HBufC* stringBuf = iCommonUiHelper->DisplayableDurationL(duration,
       
  2878                 durationMode);
       
  2879         CleanupStack::PushL(stringBuf);
       
  2880         SetControlTextL(EMPXMetadataEditorDlgCtrlIdFileDuration, *stringBuf,
       
  2881                 KNullDesC);
       
  2882         CleanupStack::PopAndDestroy(stringBuf);
       
  2883         }
       
  2884     else
       
  2885         {
       
  2886         SetControlTextL(EMPXMetadataEditorDlgCtrlIdFileDuration, KNullDesC,
       
  2887                 KNullDesC);
       
  2888         }
       
  2889 
       
  2890     // Get bitrate
       
  2891     TInt bitrate(iMedia->ValueTObjectL<TInt> (KMPXMediaAudioBitrate));
       
  2892     if (bitrate > 0)
       
  2893         {
       
  2894         // convert bitrate to kpbs
       
  2895         bitrate = bitrate / KMPXBitrateFactor;
       
  2896         HBufC* bitrateText = StringLoader::LoadLC(
       
  2897                 R_MPX_CUI_METADATAEDITOR_BITRATE_TXT, bitrate);
       
  2898         SetControlTextL(EMPXMetadataEditorDlgCtrlIdFileBitrate,
       
  2899                 bitrateText->Des(), KNullDesC);
       
  2900         CleanupStack::PopAndDestroy(bitrateText);
       
  2901         }
       
  2902     else
       
  2903         {
       
  2904         SetControlTextL(EMPXMetadataEditorDlgCtrlIdFileBitrate, KNullDesC,
       
  2905                 KNullDesC);
       
  2906         }
       
  2907 
       
  2908     // Get sampling rate
       
  2909     TInt samplingRateNum((TInt) iMedia->ValueTObjectL<TInt> (
       
  2910             KMPXMediaAudioSamplerate));
       
  2911     if (samplingRateNum > 0)
       
  2912         {
       
  2913         HBufC* stringBuf = HBufC::NewLC(KMPXFileDetailsMaxBufferLen);
       
  2914         TPtr stringBufPtr = stringBuf->Des();
       
  2915         stringBufPtr.AppendNum(samplingRateNum);
       
  2916         AknTextUtils::LanguageSpecificNumberConversion( stringBufPtr );
       
  2917         HBufC* samplingrate = StringLoader::LoadLC(
       
  2918                 R_MPX_CUI_METADATAEDITOR_SAMPLINGRATE_TXT, stringBufPtr);
       
  2919         SetControlTextL(EMPXMetadataEditorDlgCtrlIdSamplingrate,
       
  2920                 samplingrate->Des(), KNullDesC);
       
  2921         CleanupStack::PopAndDestroy(samplingrate);
       
  2922         CleanupStack::PopAndDestroy(stringBuf);
       
  2923         }
       
  2924     else
       
  2925         {
       
  2926         SetControlTextL(EMPXMetadataEditorDlgCtrlIdSamplingrate, KNullDesC,
       
  2927                 KNullDesC);
       
  2928         }
       
  2929 
       
  2930     // Get size, not stored in collection, have to use RFile
       
  2931     //
       
  2932     RFs& fs = CEikonEnv::Static()->FsSession();
       
  2933     RFile file;
       
  2934     TInt sizeNum(0);
       
  2935     TInt err(file.Open(fs, uri, EFileRead | EFileShareReadersOrWriters));
       
  2936     if (err == KErrNone)
       
  2937         {
       
  2938         file.Size(sizeNum);
       
  2939         file.Close();
       
  2940         }
       
  2941 
       
  2942     if (sizeNum > 0)
       
  2943         {
       
  2944         HBufC* stringBuf = iCommonUiHelper->UnitConversionL(sizeNum);
       
  2945         CleanupStack::PushL(stringBuf);
       
  2946         TPtr stringBufPtr = stringBuf->Des();
       
  2947         AknTextUtils::DisplayTextLanguageSpecificNumberConversion(stringBufPtr);
       
  2948         SetControlTextL(EMPXMetadataEditorDlgCtrlIdSize, stringBufPtr,
       
  2949                 KNullDesC);
       
  2950         CleanupStack::PopAndDestroy(stringBuf);
       
  2951         }
       
  2952     else
       
  2953         {
       
  2954         SetControlTextL(EMPXMetadataEditorDlgCtrlIdSize, KNullDesC, KNullDesC);
       
  2955         }
       
  2956 
       
  2957     if (iCurrentLibrary == EMPXMetadataEditorDlgPodcast)
       
  2958         {
       
  2959           PopulatePodcastFileDetailsL();
       
  2960         }
       
  2961     // Get last modified time
       
  2962     TTime time;
       
  2963     User::LeaveIfError( fs.Modified( uri, time ) );
       
  2964     ConvertToLocalTimeL( time );
       
  2965     HBufC* modDateTime = HBufC::NewLC(
       
  2966             KMPXMaxTimeLength + KMPXDurationDisplayResvLen );
       
  2967     HBufC* format = StringLoader::LoadLC(
       
  2968             R_QTN_DATE_USUAL_WITH_ZERO );
       
  2969     TPtr modDatePtr = modDateTime->Des();
       
  2970     MPX_TRAPD( error, time.FormatL( modDatePtr, *format ) );
       
  2971     CleanupStack::PopAndDestroy( format );
       
  2972     if ( error != KErrNone)
       
  2973         {
       
  2974         SetControlTextL(EMPXMetadataEditorDlgCtrlIdLastModified,
       
  2975                 KNullDesC, KNullDesC);
       
  2976         }
       
  2977     else
       
  2978         {
       
  2979         format = StringLoader::LoadLC(
       
  2980                 R_QTN_TIME_USUAL_WITH_ZERO );
       
  2981         HBufC* modTime = HBufC::NewLC(
       
  2982                 format->Length() + KMPXDurationDisplayResvLen );
       
  2983         TPtr modTimePtr = modTime->Des();
       
  2984         MPX_TRAPD( err, time.FormatL( modTimePtr, *format ) );
       
  2985         if ( err != KErrNone )
       
  2986             {
       
  2987             SetControlTextL(EMPXMetadataEditorDlgCtrlIdLastModified,
       
  2988                     KNullDesC, KNullDesC);
       
  2989 
       
  2990             }
       
  2991         else
       
  2992             {
       
  2993             modDatePtr.Append( KMPXSpace );
       
  2994             modDatePtr.Append( modTimePtr );
       
  2995             AknTextUtils::DisplayTextLanguageSpecificNumberConversion(modDatePtr);
       
  2996             SetControlTextL(EMPXMetadataEditorDlgCtrlIdLastModified,
       
  2997                     modDatePtr,
       
  2998                     KNullDesC);
       
  2999             }
       
  3000         CleanupStack::PopAndDestroy( modTime );
       
  3001         CleanupStack::PopAndDestroy( format );
       
  3002         }
       
  3003     CleanupStack::PopAndDestroy( modDateTime );
       
  3004 
       
  3005 // Get filename
       
  3006 SetControlTextL(EMPXMetadataEditorDlgCtrlIdCopyright,
       
  3007         iMedia->ValueText(
       
  3008                 KMPXMediaGeneralCopyright ), KNullDesC);
       
  3009 
       
  3010 // Get URL
       
  3011 SetControlTextL(EMPXMetadataEditorDlgCtrlIdWebaddress,
       
  3012         iMedia->ValueText(
       
  3013                 KMPXMediaMusicURL ), KNullDesC);
       
  3014 
       
  3015 CAknForm::SetInitialCurrentLine();
       
  3016 }
       
  3017 
       
  3018 // -----------------------------------------------------------------------------
       
  3019 // CMPXMetadataEditorDialog::PopulatePodcastFileDetailsL
       
  3020 // -----------------------------------------------------------------------------
       
  3021 //
       
  3022 void CMPXMetadataEditorDialog::PopulatePodcastFileDetailsL()
       
  3023     {
       
  3024     TInt lastPbPosition((TInt) iMedia->ValueTObjectL<TInt> ( 
       
  3025 	        KMPXMediaGeneralLastPlaybackPosition ));
       
  3026     if (lastPbPosition > 0)
       
  3027         {
       
  3028         // convert milliseconds to seconds
       
  3029         lastPbPosition = lastPbPosition / KSecondInMilliseconds;
       
  3030         CMPXCommonUiHelper::TMPXDuratDisplayMode lastPbPositionMode =
       
  3031         CMPXCommonUiHelper::EMPXDuratAuto;
       
  3032         if (lastPbPosition > KOneHourInSeconds)
       
  3033             {
       
  3034             lastPbPositionMode = CMPXCommonUiHelper::EMPXDuratHMS;
       
  3035             }
       
  3036         HBufC* stringBuf = iCommonUiHelper->DisplayableDurationL(
       
  3037                 lastPbPosition, lastPbPositionMode);
       
  3038         CleanupStack::PushL(stringBuf);
       
  3039         SetControlTextL(EMPXMetadataEditorDlgCtrlIdLastPlayedPosition,
       
  3040                 *stringBuf, KNullDesC);
       
  3041         CleanupStack::PopAndDestroy(stringBuf);
       
  3042         }
       
  3043     else if (lastPbPosition == 0 && iMedia->IsSupported(
       
  3044             KMPXMediaGeneralPlayCount) && iMedia->ValueTObjectL<TInt> (
       
  3045                    KMPXMediaGeneralPlayCount) > 0)
       
  3046         {
       
  3047         HBufC* stringBuf = StringLoader::LoadLC(
       
  3048                 R_MPX_CUI_METADATAEDITOR_PLAYBACK_COMPLETE);
       
  3049         SetControlTextL(EMPXMetadataEditorDlgCtrlIdLastPlayedPosition,
       
  3050                 *stringBuf, KNullDesC);
       
  3051         CleanupStack::PopAndDestroy(stringBuf);
       
  3052         }
       
  3053     else
       
  3054         {
       
  3055         SetControlTextL(EMPXMetadataEditorDlgCtrlIdLastPlayedPosition,
       
  3056                 KNullDesC, KNullDesC);
       
  3057         }
       
  3058            
       
  3059     // Get published
       
  3060     if (iMedia->IsSupported(TMPXAttribute(KMPXMediaIdPodcast,
       
  3061             EMPXMediaPodcastPubDate)))
       
  3062         {
       
  3063         TInt64 timeInt(
       
  3064                 (TInt64) iMedia->ValueTObjectL<TInt64> (TMPXAttribute(
       
  3065                         KMPXMediaIdPodcast, EMPXMediaPodcastPubDate)));
       
  3066     	TTime time(timeInt);
       
  3067     	ConvertToLocalTimeL(time);
       
  3068     	HBufC* modDateTime = HBufC::NewLC(KMPXMaxTimeLength
       
  3069         	    + KMPXDurationDisplayResvLen);
       
  3070     	HBufC* format = StringLoader::LoadLC(R_QTN_DATE_USUAL_WITH_ZERO);
       
  3071     	TPtr modDatePtr = modDateTime->Des();
       
  3072     	MPX_TRAPD( err, time.FormatL( modDatePtr, *format ) );
       
  3073     	CleanupStack::PopAndDestroy(format);
       
  3074     	if (err != KErrNone || time == 0)
       
  3075         	{
       
  3076         	SetControlTextL(EMPXMetadataEditorDlgCtrlIdLastPublished,
       
  3077             	    KNullDesC, KNullDesC);
       
  3078         	}
       
  3079     	else
       
  3080         	{
       
  3081         	format = StringLoader::LoadLC(R_QTN_TIME_USUAL_WITH_ZERO);
       
  3082         	HBufC* modTime = HBufC::NewLC(format->Length()
       
  3083             	    + KMPXDurationDisplayResvLen);
       
  3084         	TPtr modTimePtr = modTime->Des();
       
  3085         	MPX_TRAPD( err, time.FormatL( modTimePtr, *format ) );
       
  3086         	if (err != KErrNone)
       
  3087            		{
       
  3088             	SetControlTextL(EMPXMetadataEditorDlgCtrlIdLastPublished,
       
  3089                 	    KNullDesC, KNullDesC);
       
  3090             	}
       
  3091         	else
       
  3092             	{
       
  3093             	modDatePtr.Append(KMPXSpace);
       
  3094             	modDatePtr.Append(modTimePtr);
       
  3095             	SetControlTextL(EMPXMetadataEditorDlgCtrlIdLastPublished,
       
  3096                 	    modTimePtr, KNullDesC);
       
  3097             	}
       
  3098         	CleanupStack::PopAndDestroy(modTime);
       
  3099         	CleanupStack::PopAndDestroy(format);
       
  3100         	}
       
  3101         CleanupStack::PopAndDestroy(modDateTime);
       
  3102     	}
       
  3103     else
       
  3104         {
       
  3105         SetControlTextL(EMPXMetadataEditorDlgCtrlIdLastPublished,
       
  3106                 KNullDesC, KNullDesC);
       
  3107         }
       
  3108     }
       
  3109 
       
  3110 // -----------------------------------------------------------------------------
       
  3111 // CMPXMetadataEditorDialog::LaunchDrmInfoL
       
  3112 // -----------------------------------------------------------------------------
       
  3113 //
       
  3114 void CMPXMetadataEditorDialog::LaunchDrmInfoL()
       
  3115 
       
  3116     {
       
  3117     MPX_FUNC( "CMPXMetadataEditorDialog::LaunchDrmInfoL" );
       
  3118     const TDesC& aFileName = iMedia->ValueText(KMPXMediaGeneralUri);
       
  3119     RFs fs;
       
  3120     User::LeaveIfError( fs.Connect() );
       
  3121     CleanupClosePushL( fs );
       
  3122     RFile64 drmFile;
       
  3123     User::LeaveIfError( drmFile.Open( 
       
  3124             fs, aFileName, EFileRead | EFileShareReadersOrWriters ) );
       
  3125     CleanupClosePushL( drmFile );
       
  3126     iDrmUiHandler->ShowDetailsViewL( drmFile );
       
  3127     CleanupStack::PopAndDestroy( &drmFile );
       
  3128     CleanupStack::PopAndDestroy( &fs );
       
  3129     }
       
  3130 
       
  3131 // ---------------------------------------------------------------------------
       
  3132 // From MMPXPlaybackCallback
       
  3133 // Handle playback property.
       
  3134 // ---------------------------------------------------------------------------
       
  3135 //
       
  3136 void CMPXMetadataEditorDialog::HandlePropertyL(
       
  3137     TMPXPlaybackProperty aProperty,
       
  3138     TInt aValue,
       
  3139     TInt aError )
       
  3140     {
       
  3141     MPX_FUNC( "CMPXMetadataEditorDialog::HandleSubPlayerNamesL" );
       
  3142     }
       
  3143 
       
  3144 // ---------------------------------------------------------------------------
       
  3145 // From MMPXPlaybackCallback
       
  3146 // Method is called continously until aComplete=ETrue, signifying that
       
  3147 // it is done and there will be no more callbacks
       
  3148 // Only new items are passed each time
       
  3149 // ---------------------------------------------------------------------------
       
  3150 //
       
  3151 void CMPXMetadataEditorDialog::HandleSubPlayerNamesL(
       
  3152     TUid /* aPlayer */,
       
  3153     const MDesCArray* /* aSubPlayers */,
       
  3154     TBool /* aComplete */,
       
  3155     TInt /* aError */ )
       
  3156     {
       
  3157     MPX_FUNC( "CMPXMetadataEditorDialog::HandleSubPlayerNamesL" );
       
  3158     }
       
  3159 
       
  3160 // ---------------------------------------------------------------------------
       
  3161 // From MMPXPlaybackCallback
       
  3162 // Handle media properties.
       
  3163 // Notes: The client is responsible for delete the object of aMedia.
       
  3164 // ---------------------------------------------------------------------------
       
  3165 //
       
  3166 void CMPXMetadataEditorDialog::HandleMediaL(
       
  3167     const CMPXMedia& aMedia,
       
  3168     TInt aError )
       
  3169     {
       
  3170     MPX_FUNC( "CMPXMetadataEditorDialog::HandleMediaL" );
       
  3171     TRAP_IGNORE( DoHandleMediaL( aMedia, aError ) );
       
  3172     }
       
  3173 // End of File