mpxplugins/viewplugins/views/upnpbrowsedialog/src/mpxupnpbrowsedialog.cpp
changeset 0 ff3acec5bc43
child 4 beaa16f65879
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:  Implementation of UPnP players browse Dialog
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <aknPopupHeadingPane.h>
       
    22 #include <aknPopup.h>
       
    23 #include <aknlists.h>
       
    24 #include <AknIconArray.h>
       
    25 #include <gulicon.h>
       
    26 #include <StringLoader.h>
       
    27 #include <data_caging_path_literals.hrh>  // KDC_APP_RESOURCE_DIR
       
    28 #include <bautils.h>  // BaflUtils
       
    29 #include <AknsConstants.h>
       
    30 #include <aknnotewrappers.h>
       
    31 
       
    32 #include "mpxupnpbrowsedialog.h"
       
    33 #include <mpxupnpbrowsedialog.rsg>
       
    34 #include <mpxmessagegeneraldefs.h>
       
    35 #include <mpxviewutility.h>
       
    36 #include <mpxmusicplayerviewplugin.hrh>
       
    37 #include "mpxplayermanagerstub.h"
       
    38 #include "mpxlog.h"
       
    39 
       
    40 #include <aknconsts.h>
       
    41 #include <avkon.mbg>
       
    42 #include <errorres.rsg>
       
    43 #include <wlanerrorcodes.h>
       
    44 
       
    45 #include <mpxmedia.h>
       
    46 #include <mpxplaybackutility.h> // MMPXPlayerManager, MMPXPlaybackUtility
       
    47 #include <mpxplaybackmessage.h>
       
    48 #include <mpxplaybackframeworkdefs.h>
       
    49 #include <mpxcommandgeneraldefs.h> // KMPXCommandGeneralDoSync
       
    50 #include <mpxcollectionplaylist.h>
       
    51 #include <mpxuser.h>
       
    52 
       
    53 // CONSTANTS
       
    54 _LIT( KMPlayerUPnPBrowserDialogRscPath, "mpxupnpbrowsedialog.rsc" );
       
    55 
       
    56 _LIT( KUPnPBrowseListboxString, "%S\t%d\t" );
       
    57 _LIT(KTab,"\t");
       
    58 _LIT(KSpace, " ");
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // CMPXUPnPBrowseDialog::NewL
       
    62 // Two-phased constructor.
       
    63 // ---------------------------------------------------------------------------
       
    64 EXPORT_C CMPXUPnPBrowseDialog* CMPXUPnPBrowseDialog::NewL(TInt aPlayerUid)
       
    65     {
       
    66     CMPXUPnPBrowseDialog* self = new (ELeave) CMPXUPnPBrowseDialog(aPlayerUid);
       
    67     CleanupStack::PushL(self);
       
    68     self->ConstructL();
       
    69     CleanupStack::Pop();
       
    70     return self;
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CMPXUPnPBrowseDialog::ConstructL
       
    75 // Symbian 2nd phase constructor can leave.
       
    76 // ---------------------------------------------------------------------------
       
    77 void CMPXUPnPBrowseDialog::ConstructL( )
       
    78     {
       
    79     MPX_FUNC( "CMPXUPnPBrowseDialog::ConstructL" );
       
    80 
       
    81     // Get the playback utility instance from engine.
       
    82     iPlaybackUtility = MMPXPlaybackUtility::UtilityL( KPbModeDefault );
       
    83     iPlaybackUtility->AddObserverL( *this );
       
    84 
       
    85     // Load resource file
       
    86     //
       
    87     TParse parse;
       
    88     parse.Set( KMPlayerUPnPBrowserDialogRscPath, &KDC_APP_RESOURCE_DIR, NULL );
       
    89     TFileName resourceFile( parse.FullName() );
       
    90     User::LeaveIfError( MPXUser::CompleteWithDllPath( resourceFile ) );
       
    91     BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(),
       
    92                                     resourceFile );
       
    93     iResourceOffset = CCoeEnv::Static()->AddResourceFileL( resourceFile );
       
    94 
       
    95     iViewUtility = MMPXViewUtility::UtilityL();
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // CMPXUPnPBrowseDialog::CMPXUPnPBrowseDialog
       
   100 // C++ default constructor can NOT contain any code, that
       
   101 // might leave.
       
   102 // ---------------------------------------------------------------------------
       
   103 CMPXUPnPBrowseDialog::CMPXUPnPBrowseDialog(TInt aPlayerUid) :
       
   104     iPlayerUid(aPlayerUid)
       
   105     {
       
   106     }
       
   107 
       
   108 // Destructor
       
   109 CMPXUPnPBrowseDialog::~CMPXUPnPBrowseDialog()
       
   110     {
       
   111     MPX_FUNC( "CMPXUPnPBrowseDialog::Destructor" );
       
   112     if (iResourceOffset)
       
   113         {
       
   114         CCoeEnv::Static()->DeleteResourceFile( iResourceOffset );
       
   115         }
       
   116     delete iListBox;
       
   117 
       
   118     //Already cancelled in the destructor
       
   119     delete iPlayerManagerStub;
       
   120 
       
   121     if ( iPlaybackUtility )
       
   122         {
       
   123         TRAP_IGNORE( iPlaybackUtility->RemoveObserverL( *this ) );
       
   124         iPlaybackUtility->Close();
       
   125         }
       
   126 
       
   127     delete iCurrentlySelectedSubPlayerName;
       
   128 
       
   129     if ( iViewUtility )
       
   130         {
       
   131         iViewUtility->Close();
       
   132         }
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // Executes the popup list
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 EXPORT_C TInt CMPXUPnPBrowseDialog::ExecuteLD(TInt aPlayerUid)
       
   140     {
       
   141     MPX_FUNC( "CMPXUPnPBrowseDialog::ExecuteLD()" );
       
   142     TInt errorSelectSubPlayer = KErrNone;
       
   143     TBool okToExit = EFalse;
       
   144     TInt selectedSubplayerIndex = KErrNotFound;
       
   145     iPlayerUnavailableError = EFalse;
       
   146 
       
   147     iPlayerUid = aPlayerUid;
       
   148 
       
   149     while ( !okToExit )
       
   150         {
       
   151         RetrieveCurrentlySelectSubplayerNameL();
       
   152     	CreatePopupL();
       
   153         TInt returnValue = StartPopupL();
       
   154         MPX_DEBUG2( "CMPXUPnPBrowseDialog::ExecuteLD() after StartPopupL() returnValue %d", returnValue );
       
   155 
       
   156         // if 1, Select was pressed
       
   157         if ( returnValue )
       
   158             {
       
   159             TInt currentItemIndex = iListBox->CurrentItemIndex();
       
   160             TInt numberOfItems = iListBox->Model()->NumberOfItems();
       
   161 
       
   162             // check for boundaries
       
   163             // if currentItemIndex is valid
       
   164             if ( ( currentItemIndex >= 0 ) &&
       
   165                  ( currentItemIndex < numberOfItems ) )
       
   166                 {
       
   167                 MPX_DEBUG2( "CMPXUPnPBrowseDialog::ExecuteLD() currentItemIndex %d", currentItemIndex );
       
   168                 MPX_DEBUG2( "CMPXUPnPBrowseDialog::ExecuteLD() numberOfItems %d", numberOfItems );
       
   169 
       
   170                 // if a subplayer was selected (and not <search again>)
       
   171                 HBufC* listText =
       
   172                         StringLoader::LoadLC(R_UPNP_LIST_UPNP_MORE_SUBPLAYERS);
       
   173                 TInt isSelectedItemASubplayerName =
       
   174                         listText->CompareF(
       
   175                              (iListBox->Model()->ItemText(currentItemIndex)) );
       
   176                 MPX_DEBUG2( "CMPXUPnPBrowseDialog::ExecuteLD() isSelectedItemASubplayerName %d", isSelectedItemASubplayerName );
       
   177                 CleanupStack::PopAndDestroy( listText );
       
   178 
       
   179                 if ( isSelectedItemASubplayerName )
       
   180                     {
       
   181                     if ( iPlaybackUtility )
       
   182                         {
       
   183                         iPlaybackUtility->CancelRequest();
       
   184                         }
       
   185 
       
   186                     TBool selecDifferentSubPlayer = ETrue;
       
   187 
       
   188                     if ( iCurrentlySelectedSubPlayerName )
       
   189                         {
       
   190                         TFileName listName(iListBox->Model()->ItemText(currentItemIndex));
       
   191                         TInt index = listName.Find(KTab);
       
   192                         if ( index >= 0 )
       
   193                             {
       
   194                             TFileName subPlayerName = listName.LeftTPtr(index);
       
   195                             selecDifferentSubPlayer =
       
   196                               ( ( subPlayerName.CompareF(
       
   197                                   *iCurrentlySelectedSubPlayerName ) ) &&
       
   198                                   ( aPlayerUid == iCurrentlyUsedPlayer.iUid) );
       
   199                             }
       
   200                         else
       
   201                             {
       
   202                             selecDifferentSubPlayer =
       
   203                               ( ( listName.CompareF(
       
   204                                   *iCurrentlySelectedSubPlayerName ) ) &&
       
   205                                   ( aPlayerUid == iCurrentlyUsedPlayer.iUid) );
       
   206                             }
       
   207                         MPX_DEBUG2( "CMPXUPnPBrowseDialog::ExecuteLD() selecDifferentSubPlayer %d", selecDifferentSubPlayer);
       
   208                         }
       
   209 
       
   210                     MMPXSource* source = iPlaybackUtility->Source();
       
   211                     CMPXCollectionPlaylist* playlist = NULL;
       
   212                     if ( source )
       
   213                         {
       
   214                         playlist = source->PlaylistL();
       
   215                         if ( playlist )
       
   216                             {
       
   217                             CleanupStack::PushL( playlist );
       
   218                             }
       
   219                         }
       
   220 
       
   221                     MMPXPlayerManager& manager = iPlaybackUtility->PlayerManager();
       
   222                     // user selects a different remote player
       
   223                     if ( iCurrentlySelectedSubPlayerName &&
       
   224                          selecDifferentSubPlayer )
       
   225                         {
       
   226                         // need to clean up the current plugin
       
   227                         TRAP_IGNORE( manager.ClearSelectPlayersL() );
       
   228                         }
       
   229 
       
   230                     MPX_DEBUG3( "CMPXUPnPBrowseDialog::ExecuteLD() before call to manager.SelectSubPlayerL(%d, %d)", iPlayerUid, currentItemIndex );
       
   231                     MPX_TRAP( errorSelectSubPlayer,
       
   232                           manager.SelectSubPlayerL( TUid::Uid(iPlayerUid),
       
   233                                                     currentItemIndex ) );
       
   234 
       
   235                     MPX_DEBUG2( "CMPXUPnPBrowseDialog::ExecuteLD() after manager.SelectSubPlayerL()", errorSelectSubPlayer );
       
   236                     if ( errorSelectSubPlayer == KErrNone )
       
   237                         {
       
   238                         okToExit = ETrue;
       
   239 
       
   240                         if ( selecDifferentSubPlayer )
       
   241                             {
       
   242                             selectedSubplayerIndex = currentItemIndex;
       
   243                             }
       
   244                         else // subplayer selected is the same as the current one
       
   245                             {
       
   246                             selectedSubplayerIndex = KErrInUse;
       
   247                             }
       
   248                         }
       
   249                     else
       
   250                         {
       
   251                         TRAP_IGNORE( manager.ClearSelectPlayersL() );
       
   252                         if ( playlist )
       
   253                             {
       
   254                             iPlaybackUtility->InitL( *playlist, EFalse );
       
   255                             }
       
   256 
       
   257                         DisplayErrorNoteL( R_UPNP_ERROR_PLAYER_UNAVAILABLE );
       
   258                         }
       
   259 
       
   260                     if ( playlist )
       
   261                         {
       
   262                         CleanupStack::PopAndDestroy( playlist );
       
   263                         }
       
   264                     } // if ( isSelectedItemASubplayerName )
       
   265                 } // check for boundaries
       
   266             else
       
   267                 {
       
   268                 okToExit = ETrue;
       
   269                 selectedSubplayerIndex = KErrCancel;
       
   270                 }
       
   271             } // if ( returnValue )
       
   272         else // Cancel was selected
       
   273             {
       
   274             if ( !iPlayerUnavailableError )
       
   275                 {
       
   276                 if ( iPlaybackUtility )
       
   277                     {
       
   278                     iPlaybackUtility->CancelRequest();
       
   279                     }
       
   280 
       
   281                 CMPXCommand* cmd = CMPXCommand::NewL();
       
   282                 CleanupStack::PushL(cmd);
       
   283                 cmd->SetTObjectValueL<TInt>(KMPXCommandGeneralId, KMPXCommandIdPlaybackGeneral);
       
   284                 // All of current commands are sync
       
   285                 cmd->SetTObjectValueL<TBool>(KMPXCommandGeneralDoSync, ETrue);
       
   286                 cmd->SetTObjectValueL<TInt>(KMPXCommandPlaybackGeneralType, EPbCmdUnloadNonActivePlugin);
       
   287                 cmd->SetTObjectValueL<TInt>(KMPXCommandPlaybackGeneralData, aPlayerUid);
       
   288                 iPlaybackUtility->CommandL(*cmd, NULL);
       
   289                 CleanupStack::PopAndDestroy(cmd);
       
   290 
       
   291                 okToExit = ETrue;
       
   292                 selectedSubplayerIndex = KErrCancel;
       
   293                 }
       
   294             // else we display the popup again
       
   295             else
       
   296                 {
       
   297                 iPlayerUnavailableError = EFalse;
       
   298                 }
       
   299             }
       
   300         } // while ( !okToExit )
       
   301 
       
   302     return selectedSubplayerIndex;
       
   303     }
       
   304 
       
   305 // ---------------------------------------------------------------------------
       
   306 // CMPXUPnPBrowseDialog::PreLayoutDynInitL();
       
   307 // called by framework before dialog is shown
       
   308 // ---------------------------------------------------------------------------
       
   309 void CMPXUPnPBrowseDialog::PreLayoutDynInitL()
       
   310     {
       
   311     MPX_FUNC( "CMPXUPnPBrowseDialog::PreLayoutDynInitL()" );
       
   312 
       
   313     // Browse dialog title text
       
   314     HBufC* dialogTitle = StringLoader::LoadLC(R_UPNP_MENU_TITLE_SELECT_PLAYER);
       
   315     iPopup->SetTitleL(*dialogTitle);
       
   316     CleanupStack::PopAndDestroy(dialogTitle);
       
   317 
       
   318     // Previous UPNP code
       
   319 
       
   320     CAknIconArray* icons = new ( ELeave ) CAknIconArray(2);
       
   321     CleanupStack::PushL(icons);
       
   322 
       
   323     // Mif icons
       
   324     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   325     TFileName iconsPath( AknIconUtils::AvkonIconFileName( ) );
       
   326 
       
   327     // Media server icon
       
   328     AppendIconToArrayL( icons, skin,
       
   329                         KAvkonBitmapFile,
       
   330                         KAknsIIDQgnIndiMarkedAdd,
       
   331                         EMbmAvkonQgn_indi_marked_add,
       
   332                         EMbmAvkonQgn_indi_marked_add_mask );
       
   333     iListBox->ItemDrawer()->FormattedCellData()->SetIconArrayL( icons );
       
   334     CleanupStack::Pop(icons);
       
   335 
       
   336     // Previous UPNP code
       
   337 
       
   338     LoadListItemsL();
       
   339     }
       
   340 
       
   341 
       
   342 // --------------------------------------------------------------------------
       
   343 // CUPnPBrowsePopup::LoadListItemsL
       
   344 // Sends the browse request to MPXPlayerManager. When result set arrives,
       
   345 // Playback callback will call the "HandleSubPlayerNamesL" call back method,
       
   346 // which is implemented below.
       
   347 // --------------------------------------------------------------------------
       
   348 void CMPXUPnPBrowseDialog::LoadListItemsL()
       
   349     {
       
   350     MPX_FUNC( "CMPXUPnPBrowseDialog::LoadListItemsL()" );
       
   351 
       
   352     MMPXPlayerManager& manager = iPlaybackUtility->PlayerManager();
       
   353 
       
   354     DisplayWaitingTextL();
       
   355 
       
   356     if ( iPlayerManagerStub )
       
   357         {
       
   358         iPlayerManagerStub->SubPlayerNamesL(*this, TUid::Uid(iPlayerUid));
       
   359         }
       
   360     else
       
   361         {
       
   362         MPX_DEBUG1( "CMPXUPnPBrowseDialog::LoadListItemsL() before call to manager.SubPlayerNamesL()" );
       
   363         manager.SubPlayerNamesL(*this, TUid::Uid(iPlayerUid));
       
   364         }
       
   365     }
       
   366 
       
   367 // --------------------------------------------------------------------------
       
   368 // CUPnPBrowsePopup::DisplaySubPlayersNamesL
       
   369 // --------------------------------------------------------------------------
       
   370 void CMPXUPnPBrowseDialog::DisplaySubPlayersNamesL( const MDesCArray* aSubPlayers,
       
   371                                                     const TBool aComplete )
       
   372     {
       
   373     MPX_FUNC( "CMPXUPnPBrowseDialog::DisplaySubPlayersNamesL()" );
       
   374 
       
   375     CTextListBoxModel* model = iListBox->Model();
       
   376     MDesCArray* textArray = model->ItemTextArray();
       
   377     CDesCArray* listBoxItems = static_cast<CDesCArray*>(textArray);
       
   378     TInt subPlayersCount = 0;
       
   379 
       
   380     listBoxItems->Reset();
       
   381 
       
   382     if ( aSubPlayers )
       
   383         {
       
   384         subPlayersCount = aSubPlayers->MdcaCount();
       
   385         MPX_DEBUG2( "CMPXUPnPBrowseDialog::DisplaySubPlayersNamesL(), aSubPlayer exists %d",
       
   386                     subPlayersCount );
       
   387 
       
   388         if ( subPlayersCount > 0 )
       
   389             {
       
   390             for (TInt i=0; i < subPlayersCount; i++)
       
   391                 {
       
   392                 TPtrC temp = aSubPlayers->MdcaPoint(i);
       
   393                 TFileName subPlayerName;
       
   394                 
       
   395                 subPlayerName.Copy(temp);
       
   396                 subPlayerName.TrimAll();        // trim all leading and trailing spaces (including tab)
       
   397                 
       
   398                 TInt tabPos = subPlayerName.Find(KTab);
       
   399                 
       
   400                 // replace tab with single space
       
   401                 while (tabPos != KErrNotFound)
       
   402                     {
       
   403                     subPlayerName.Replace(tabPos, 1, KSpace);
       
   404                     tabPos = subPlayerName.Find(KTab);
       
   405                     }                
       
   406                 
       
   407                 // Append name of the subplayer in the listbox
       
   408                 if ( iCurrentlySelectedSubPlayerName )
       
   409                     {
       
   410                     if ( !subPlayerName.CompareF( *iCurrentlySelectedSubPlayerName ) )
       
   411                         {
       
   412                         // names are the same and we add the selection icon
       
   413                         TFileName item;
       
   414                         
       
   415                         item.Format(KUPnPBrowseListboxString, &subPlayerName, 0);
       
   416                         listBoxItems->AppendL(item);
       
   417                         }
       
   418                     else
       
   419                         {
       
   420                         listBoxItems->AppendL(subPlayerName);
       
   421                         }
       
   422                     }
       
   423                 else
       
   424                     {
       
   425                     listBoxItems->AppendL(subPlayerName);
       
   426                     }
       
   427                 }
       
   428 
       
   429             // if search is complete we add the <search again> listbox item last
       
   430             if ( aComplete )
       
   431                 {
       
   432                 HBufC* listText = StringLoader::LoadLC(R_UPNP_LIST_UPNP_MORE_SUBPLAYERS);
       
   433                 listBoxItems->AppendL(*listText);
       
   434                 CleanupStack::PopAndDestroy( listText );
       
   435                 }
       
   436 
       
   437             iPopup->ButtonGroupContainer()->SetCommandSetL(
       
   438                                                 R_AVKON_SOFTKEYS_SELECT_CANCEL);
       
   439             iPopup->ButtonGroupContainer()->DrawDeferred();
       
   440 
       
   441             iListBox->HandleItemAdditionL(); // Update listbox
       
   442             iListBox->SetCurrentItemIndexAndDraw(0); // select new item
       
   443             }
       
   444         }
       
   445 
       
   446     if ( !aSubPlayers || (subPlayersCount <= 0) )
       
   447         {
       
   448         if ( aComplete ) // search is complete
       
   449             {
       
   450             HBufC* searchAgainText = StringLoader::LoadLC(R_UPNP_LIST_UPNP_MORE_SUBPLAYERS);
       
   451             listBoxItems->AppendL(*searchAgainText);
       
   452             CleanupStack::PopAndDestroy(searchAgainText);
       
   453 
       
   454             iPopup->ButtonGroupContainer()->SetCommandSetL(
       
   455                                                 R_AVKON_SOFTKEYS_SELECT_CANCEL);
       
   456             iPopup->ButtonGroupContainer()->DrawDeferred();
       
   457             iListBox->HandleItemAdditionL(); // Update listbox
       
   458             iListBox->SetCurrentItemIndexAndDraw(0); // select new item
       
   459             }
       
   460         else  // not complete, we're still searching
       
   461             {
       
   462             DisplayWaitingTextL();
       
   463             }
       
   464         }
       
   465     }
       
   466 
       
   467 // ---------------------------------------------------------------------------
       
   468 // CMPXUPnPBrowseDialog::HandlePropertyL
       
   469 // Handle playback property.
       
   470 // ---------------------------------------------------------------------------
       
   471 void CMPXUPnPBrowseDialog::HandlePropertyL( TMPXPlaybackProperty /*aProperty*/,
       
   472                                             TInt /*aValue*/,
       
   473                                             TInt /*aError*/)
       
   474     {
       
   475     MPX_FUNC( "CMPXUPnPBrowseDialog::HandlePropertyL()" );
       
   476     // empty
       
   477     }
       
   478 
       
   479 // ---------------------------------------------------------------------------
       
   480 // CMPXUPnPBrowseDialog::HandleSubPlayerNamesL
       
   481 // Method is called continously until aComplete=ETrue, signifying that
       
   482 // it is done and there will be no more callbacks
       
   483 // Only new items are passed each time.
       
   484 // ---------------------------------------------------------------------------
       
   485 void CMPXUPnPBrowseDialog::HandleSubPlayerNamesL( TUid /*aPlayer*/,
       
   486                             const MDesCArray* aSubPlayers,
       
   487                             TBool aComplete,
       
   488                             TInt aError)
       
   489     {
       
   490     MPX_FUNC( "CMPXUPnPBrowseDialog::HandleSubPlayerNamesL()" );
       
   491     MPX_DEBUG3( "CMPXUPnPBrowseDialog::HandleSubPlayerNamesL(complete %d, error: %d)",
       
   492                 aComplete, aError );
       
   493 
       
   494     if ( aError == KErrNone )
       
   495         {
       
   496         DisplaySubPlayersNamesL(aSubPlayers, aComplete);
       
   497         }
       
   498     else
       
   499         {
       
   500         if ( ( aError == KErrServerTerminated ) ||
       
   501              ( aError == KErrCouldNotConnect ) ||
       
   502              ( aError == KErrWlanNetworkNotFound ))
       
   503             {
       
   504             // defined in errorres.rsg
       
   505             DisplayErrorNoteL( R_ERRE_GE_WLAN_WLAN_NETWORK_LOST );
       
   506             }
       
   507 
       
   508         // No error note specified, we can't get list of subplayers so
       
   509         // we just exit the dialog
       
   510         iPopup->CancelPopup();
       
   511         }
       
   512     }
       
   513 
       
   514 // ---------------------------------------------------------------------------
       
   515 // CMPXUPnPBrowseDialog::HandleMediaL
       
   516 // Call back of media request
       
   517 // ---------------------------------------------------------------------------
       
   518 void CMPXUPnPBrowseDialog::HandleMediaL( const CMPXMedia& /*aProperties*/,
       
   519                                          TInt /*aError*/)
       
   520     {
       
   521     MPX_FUNC( "CMPXUPnPBrowseDialog::HandleMediaL()" );
       
   522     // empty
       
   523     }
       
   524 
       
   525 // ---------------------------------------------------------------------------
       
   526 // CMPXUPnPBrowseDialog::AppendIconToArrayL
       
   527 // Load a possibly skinned icon (with mask) and append it to an
       
   528 // icon array.
       
   529 // ---------------------------------------------------------------------------
       
   530 void CMPXUPnPBrowseDialog::AppendIconToArrayL(CAknIconArray* aArray,
       
   531                                                MAknsSkinInstance* aSkin,
       
   532                                                const TDesC& aMbmFile,
       
   533                                                const TAknsItemID& aID,
       
   534                                                TInt aBitmapId,
       
   535                                                TInt aMaskId)
       
   536     {
       
   537     MPX_FUNC( "CMPXUPnPBrowseDialog::AppendIconToArrayL()" );
       
   538 
       
   539     __ASSERT_DEBUG(aArray != NULL, User::Leave(KErrArgument));
       
   540 
       
   541     CFbsBitmap* bitmap = NULL;
       
   542     CFbsBitmap* mask = NULL;
       
   543 
       
   544     AknsUtils::CreateIconLC(aSkin, aID,
       
   545         bitmap, mask, aMbmFile, aBitmapId, aMaskId);
       
   546 
       
   547     CGulIcon* icon = CGulIcon::NewL(bitmap, mask);
       
   548     icon->SetBitmapsOwnedExternally(EFalse);
       
   549 
       
   550     // icon now owns the bitmaps, no need to keep on cleanup stack.
       
   551     CleanupStack::Pop(2); // mask, bitmap
       
   552     bitmap = NULL;
       
   553     mask = NULL;
       
   554 
       
   555     CleanupStack::PushL(icon);
       
   556     aArray->AppendL(icon);
       
   557 
       
   558     // aArray now owns the icon, no need to delete.
       
   559     CleanupStack::Pop();
       
   560     }
       
   561 
       
   562 // ---------------------------------------------------------------------------
       
   563 // CMPXUPnPBrowseDialog::CreatePopupL
       
   564 // Creates a selection popup.
       
   565 // ---------------------------------------------------------------------------
       
   566 void CMPXUPnPBrowseDialog::CreatePopupL()
       
   567     {
       
   568     MPX_FUNC( "CMPXUPnPBrowseDialog::CreatePopupL()" );
       
   569 
       
   570     // Create and configure the list box
       
   571     if ( iListBox )
       
   572         {
       
   573         delete iListBox;
       
   574         iListBox = NULL;
       
   575         }
       
   576     iListBox = new (ELeave) CAknSinglePopupMenuStyleListBox;
       
   577     iPopup = CAknPopupList::NewL(iListBox,
       
   578                                  R_MPX_SOFTKEYS_UPNP_EMPTY_CANCEL,
       
   579                                  AknPopupLayouts::EDynMenuWindow);
       
   580     iListBox->ConstructL(iPopup, EAknListBoxSelectionList);
       
   581     iListBox->CreateScrollBarFrameL( ETrue );
       
   582     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   583         CEikScrollBarFrame::EOff,
       
   584         CEikScrollBarFrame::EAuto );
       
   585     // Enable Marquee
       
   586     CEikFormattedCellListBox* eikListbox = 
       
   587     static_cast<CEikFormattedCellListBox*>( iListBox );
       
   588     eikListbox->EnableExtendedDrawingL();
       
   589     eikListbox->ItemDrawer()->FormattedCellData()->EnableMarqueeL( ETrue );
       
   590     PreLayoutDynInitL();
       
   591     }
       
   592 
       
   593 // ---------------------------------------------------------------------------
       
   594 // CMPXUPnPBrowseDialog::StartPopupL
       
   595 // Parses the friendly names from the list of UPnPDevices and
       
   596 // executes the selection dialog. Returns 0 or 1 (Cancel or Select)
       
   597 // ---------------------------------------------------------------------------
       
   598 //
       
   599 TInt CMPXUPnPBrowseDialog::StartPopupL()
       
   600     {
       
   601     MPX_FUNC( "CMPXUPnPBrowseDialog::StartPopupL()" );
       
   602 
       
   603     TInt popupOk = iPopup->ExecuteLD();
       
   604     iPopup = NULL;
       
   605     return popupOk;
       
   606     }
       
   607 
       
   608 // ---------------------------------------------------------------------------
       
   609 // From MMPXPlaybackObserver
       
   610 // Handle playback message.
       
   611 // ---------------------------------------------------------------------------
       
   612 //
       
   613 void CMPXUPnPBrowseDialog::HandlePlaybackMessage(
       
   614     CMPXMessage* aMessage, TInt aError )
       
   615     {
       
   616     MPX_FUNC( "CMPXUPnPBrowseDialog::HandlePlaybackMessage()" );
       
   617 
       
   618     if ( aError == KErrNone && aMessage )
       
   619         {
       
   620         TRAP_IGNORE( DoHandlePlaybackMessageL( *aMessage ) );
       
   621         }
       
   622     }
       
   623 
       
   624 // ---------------------------------------------------------------------------
       
   625 // CMPXUPnPBrowseDialog::RetrieveCurrentlySelectSubplayerNameL
       
   626 // Retrieves the name and other info of the currently used subplayer
       
   627 // ---------------------------------------------------------------------------
       
   628 //
       
   629 void CMPXUPnPBrowseDialog::RetrieveCurrentlySelectSubplayerNameL()
       
   630     {
       
   631     MPX_FUNC( "CMPXUPnPBrowseDialog::RetrieveCurrentlySelectSubplayerName()" );
       
   632 
       
   633     if ( iCurrentlySelectedSubPlayerName )
       
   634         {
       
   635         delete iCurrentlySelectedSubPlayerName;
       
   636         iCurrentlySelectedSubPlayerName = NULL;
       
   637         }
       
   638 
       
   639     MMPXPlayerManager& manager = iPlaybackUtility->PlayerManager();
       
   640     TMPXPlaybackPlayerType playerType;
       
   641     TInt currentlyUsedSubPlayer;
       
   642     MPX_DEBUG1( "CMPXUPnPBrowseDialog::RetrieveCurrentlySelectSubplayerName() before call to manager.GetSelectionL()" );
       
   643     MPX_TRAPD( errorSelectSubPlayer, manager.GetSelectionL( playerType,
       
   644                                                         iCurrentlyUsedPlayer,
       
   645                                                         currentlyUsedSubPlayer,
       
   646                                                         iCurrentlySelectedSubPlayerName));
       
   647     MPX_DEBUG4( "CMPXUPnPBrowseDialog::RetrieveCurrentlySelectSubplayerName() after call to manager.GetSelectionL(%d, %d, %d)",
       
   648                                                         playerType,
       
   649                                                         iCurrentlyUsedPlayer.iUid,
       
   650                                                         currentlyUsedSubPlayer );
       
   651     if (iCurrentlySelectedSubPlayerName)
       
   652         {
       
   653         MPX_DEBUG2( "CMPXUPnPBrowseDialog::RetrieveCurrentlySelectSubplayerName() after call to manager.GetSelectionL(%S)",
       
   654                                                         iCurrentlySelectedSubPlayerName );
       
   655         }
       
   656     if ( errorSelectSubPlayer != KErrNone  && iCurrentlySelectedSubPlayerName )
       
   657         {
       
   658         MPX_DEBUG2( "CMPXUPnPBrowseDialog::RetrieveCurrentlySelectSubplayerName() after call to manager.GetSelectionL() error %d",
       
   659                                                         errorSelectSubPlayer );
       
   660         delete iCurrentlySelectedSubPlayerName;
       
   661         iCurrentlySelectedSubPlayerName = NULL;
       
   662         }
       
   663     }
       
   664 
       
   665 // ---------------------------------------------------------------------------
       
   666 // CMPXUPnPBrowseDialog::DisplayErrorNoteL
       
   667 // Retrieves the name and other info of the currently used subplayer
       
   668 // ---------------------------------------------------------------------------
       
   669 //
       
   670 void CMPXUPnPBrowseDialog::DisplayErrorNoteL( TInt aResourceId )
       
   671     {
       
   672     MPX_FUNC( "CMPXUPnPBrowseDialog::DisplayErrorNoteL()" );
       
   673 
       
   674     // error note
       
   675     HBufC* dialogText = StringLoader::LoadLC( aResourceId );
       
   676     CAknErrorNote* errNote = new(ELeave) CAknErrorNote(ETrue);
       
   677     errNote->SetTimeout(CAknNoteDialog::ELongTimeout);
       
   678     errNote->ExecuteLD( *dialogText );
       
   679     CleanupStack::PopAndDestroy( dialogText );
       
   680     }
       
   681 
       
   682 // ---------------------------------------------------------------------------
       
   683 // CMPXUPnPBrowseDialog::DisplayWaitingTextL
       
   684 // Displays the waiting text during retrieval of subplayer names
       
   685 // ---------------------------------------------------------------------------
       
   686 //
       
   687 void CMPXUPnPBrowseDialog::DisplayWaitingTextL()
       
   688     {
       
   689     MPX_FUNC( "CMPXUPnPBrowseDialog::DisplayWaitingTextL()" );
       
   690 
       
   691     if ( iListBox && iListBox->View() )
       
   692         {
       
   693         HBufC* waitText = StringLoader::LoadLC(R_UPNP_DIALOG_WAITING_FOR_DEVICES);
       
   694         iListBox->View()->SetListEmptyTextL(*waitText);
       
   695         CleanupStack::PopAndDestroy(waitText);
       
   696         }
       
   697     }
       
   698 
       
   699 // ---------------------------------------------------------------------------
       
   700 // Handle playback message.
       
   701 // ---------------------------------------------------------------------------
       
   702 //
       
   703 void CMPXUPnPBrowseDialog::DoHandlePlaybackMessageL(
       
   704     const CMPXMessage& aMessage )
       
   705     {
       
   706     MPX_FUNC( "CMPXUPnPBrowseDialog::DoHandlePlaybackMessageL" );
       
   707 
       
   708     TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) );
       
   709     if ( KMPXMessageGeneral == id )
       
   710         {
       
   711         TInt type( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ) );
       
   712         TInt data( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData ) );
       
   713         switch ( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) )
       
   714             {
       
   715             case TMPXPlaybackMessage::EPlayerUnavailable:
       
   716                 {
       
   717                 MPX_DEBUG2( "HandlePlaybackMessageL - EPlayerUnavailable(%d)", type );
       
   718                 TUid activeView = iViewUtility->ActiveViewType();
       
   719                 if ( activeView == TUid::Uid( KMPXPluginTypeUPnPBrowseDialogUid ) )
       
   720                     {
       
   721                     iPlayerUnavailableError = ETrue;
       
   722                     MMPXPlayerManager& manager = iPlaybackUtility->PlayerManager();
       
   723                     TRAP_IGNORE( manager.ClearSelectPlayersL() );
       
   724                     DisplayErrorNoteL( R_UPNP_ERROR_PLAYER_UNAVAILABLE );
       
   725 
       
   726                     iPopup->CancelPopup();
       
   727                     }
       
   728                 break;
       
   729                 }
       
   730             default:
       
   731                 {
       
   732                 break;
       
   733                 }
       
   734             }
       
   735         }
       
   736     }
       
   737 
       
   738 // End of file
       
   739