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