upnpframework/upnpcommonui/src/upnpexternaldevicedialog.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2005 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:  Source file for UPnP External device dialog
       
    15 *                UI Implementation
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 // System
       
    22 #include <aknnavide.h> // CAknNavigationDecorator
       
    23 #include <barsread.h> // TResourceReader
       
    24 #include <AknIconArray.h>
       
    25 #include <eikclbd.h>
       
    26 #include <StringLoader.h>
       
    27 #include <featmgr.h>
       
    28 #include <hlplch.h>
       
    29 #include <upnpstring.h>
       
    30 #include <layoutmetadata.cdl.h>
       
    31 
       
    32 // upnpframework / avcontroller api
       
    33 #include "upnpavdevice.h"
       
    34 #include "upnpavcontroller.h"
       
    35 #include "upnpavbrowsingsession.h"
       
    36 #include "upnpavdevicelist.h"
       
    37 
       
    38 // upnpframework / internal api's
       
    39 #include "upnpcommonutils.h"
       
    40 
       
    41 // common ui internal
       
    42 #include "upnpadvfinddialog.h"
       
    43 #include "upnpcommonui.hrh"
       
    44 #include "upnpexternaldevicedialog.h"
       
    45 #include <upnpcommonui.rsg>
       
    46 #include <upnpcommonui.mbg> //for icons
       
    47 #include "upnpcommonui.h"
       
    48 #include "upnpnavipanecontainer.h"
       
    49 
       
    50 _LIT( KComponentLogfile, "commonui.txt");
       
    51 #include "upnplog.h"
       
    52 
       
    53 // CONSTANTS
       
    54 _LIT( KAknCommonUIMbmFileName, "\\resource\\apps\\upnpcommonui.mbm" );
       
    55 const TInt KLength = 100;
       
    56 _LIT(KUPNP_HLP_MAIN_EXTERNAL,"UPNP_HLP_MAIN_EXTERNAL"); 
       
    57 
       
    58 
       
    59 // --------------------------------------------------------------------------
       
    60 // CUPnPExternalDeviceDialog::CUPnPExternalDeviceDialog
       
    61 // C++ default constructor can NOT contain any code, that
       
    62 // might leave.
       
    63 // --------------------------------------------------------------------------
       
    64 //
       
    65 CUPnPExternalDeviceDialog::CUPnPExternalDeviceDialog(
       
    66                                         MUPnPAVController& aAVControl,
       
    67                                         CUPnPCommonUI& aCommonUI):
       
    68                                         iAVControl(aAVControl),
       
    69                                         iCommonUI(aCommonUI)
       
    70     {
       
    71     iPreDeviceObserver = iAVControl.DeviceObserver();
       
    72     iAVControl.RemoveDeviceObserver();
       
    73     iAVControl.SetDeviceObserver( *this );
       
    74     }
       
    75     
       
    76 // Destructor
       
    77 CUPnPExternalDeviceDialog::~CUPnPExternalDeviceDialog()
       
    78     {
       
    79     __LOG( "CUPnPExternalDeviceDialog::~CUPnPExternalDeviceDialog" );
       
    80     
       
    81     delete iDeviceArray;
       
    82     iAVControl.RemoveDeviceObserver();
       
    83     
       
    84     if( iPreDeviceObserver )
       
    85         {
       
    86         iAVControl.SetDeviceObserver( *iPreDeviceObserver );
       
    87         }
       
    88     
       
    89     if ( iNaviDecorator && iNaviPaneContainer )
       
    90         {
       
    91         iNaviPaneContainer->Pop( iNaviDecorator );
       
    92         }
       
    93     delete iNaviDecorator;
       
    94     iNaviDecorator = NULL;
       
    95     
       
    96     __LOG( "CUPnPExternalDeviceDialog::~CUPnPExternalDeviceDialog End." );
       
    97     }
       
    98     
       
    99 // --------------------------------------------------------------------------
       
   100 // CUPnPExternalDeviceDialog::ConstructL
       
   101 // Symbian 2nd phase constructor can leave.
       
   102 // --------------------------------------------------------------------------
       
   103 //
       
   104 void CUPnPExternalDeviceDialog::ConstructL( TInt aMenuResource )
       
   105     {
       
   106     __LOG( "CUPnPExternalDeviceDialog::ConstructL" );
       
   107     
       
   108     iDeviceArray = CUpnpAVDeviceList::NewL();
       
   109     
       
   110     CAknDialog::ConstructL( aMenuResource );
       
   111     __LOG( "CUPnPExternalDeviceDialog::ConstructL End" );
       
   112     }
       
   113 
       
   114 // --------------------------------------------------------------------------
       
   115 // CUPnPExternalDeviceDialog::NewL
       
   116 // Two-phased constructor.
       
   117 // --------------------------------------------------------------------------
       
   118 //
       
   119 CUPnPExternalDeviceDialog* CUPnPExternalDeviceDialog::NewL(
       
   120     TInt aMenuResource, 
       
   121     MUPnPAVController& aAVControl,
       
   122     CUPnPCommonUI& aCommonUI)
       
   123     {
       
   124     __LOG( "CUPnPExternalDeviceDialog::NewL" );
       
   125 
       
   126     CUPnPExternalDeviceDialog* self = 
       
   127                         new ( ELeave ) CUPnPExternalDeviceDialog( aAVControl,
       
   128                                                                 aCommonUI );
       
   129     CleanupStack::PushL( self );
       
   130     self->ConstructL( aMenuResource );
       
   131     CleanupStack::Pop();
       
   132     __LOG( "CUPnPExternalDeviceDialog::NewL End" );
       
   133     return self;
       
   134     }
       
   135 
       
   136 // --------------------------------------------------------------------------
       
   137 // CUPnPExternalDeviceDialog::PreLayoutDynInitL();
       
   138 // called by framework before dialog is shown
       
   139 // --------------------------------------------------------------------------
       
   140 //
       
   141 void CUPnPExternalDeviceDialog::PreLayoutDynInitL()
       
   142     {
       
   143     __LOG( "CUPnPExternalDeviceDialog::PreLayoutDynInitL" );
       
   144 
       
   145     // Create dialog title text
       
   146     CEikStatusPane* statusPane = 
       
   147                     ( ( CAknAppUi* )iEikonEnv->EikAppUi() )->StatusPane();    
       
   148     iTitlePane = ( CAknTitlePane* )statusPane->ControlL(
       
   149                     TUid::Uid( EEikStatusPaneUidTitle ) );
       
   150     iTitlePane->SetTextL( *StringLoader::LoadLC(
       
   151                                 R_UPNPCOMMONUI_EXTERNAL_MEDIA_TITLE ) );
       
   152     CleanupStack::PopAndDestroy();
       
   153     
       
   154     iListBox = static_cast<CAknSingleGraphicStyleListBox*>
       
   155               ( Control( EUPnPExternDevicesListBoxId ) );
       
   156     iListBox->CreateScrollBarFrameL( ETrue );
       
   157     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( 
       
   158             CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   159     iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
       
   160     
       
   161     
       
   162     CAknIconArray* icons = new ( ELeave ) CAknIconArray( 3 );
       
   163     CleanupStack::PushL(icons);
       
   164 
       
   165     // Mif icons
       
   166     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   167     TFileName iconsPath( AknIconUtils::AvkonIconFileName( ) );
       
   168     
       
   169     // Folder icon
       
   170     
       
   171     TFileName mbmFileName( KAknCommonUIMbmFileName );
       
   172     TFileName dllName;
       
   173     Dll::FileName( dllName );
       
   174     TBuf<2> drive = dllName.Left( 2 ); // Drive letter followed by ':' 
       
   175     mbmFileName.Insert( 0, drive );
       
   176     
       
   177     AppendIconToArrayL( icons, skin, 
       
   178                         mbmFileName, 
       
   179                         KAknsIIDDefault, 
       
   180                         EMbmUpnpcommonuiQgn_server_icon, 
       
   181                         EMbmUpnpcommonuiQgn_server_icon_mask );
       
   182    
       
   183                                         
       
   184     iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons );
       
   185         
       
   186     CleanupStack::Pop( icons );
       
   187 
       
   188     // Enable horizontal scrolling
       
   189     iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
       
   190 
       
   191     DisplayMediaServersL();
       
   192 
       
   193     if ( !iDeviceArray->Count() )  
       
   194         {
       
   195         // show "Waiting devices" text
       
   196         iListBox->View()->SetListEmptyTextL(
       
   197             *StringLoader::LoadLC( R_UPNPCOMMONUI_EXTERNAL_WAITING_NOTE ) );
       
   198         CleanupStack::PopAndDestroy(); 
       
   199         }
       
   200     else
       
   201         {
       
   202         CEikButtonGroupContainer* cba = &ButtonGroupContainer();
       
   203         cba->SetCommandSetL( R_UPNPCOMMONUI_SOFTKEYS_OPTIONS_BACK__OPEN );
       
   204         cba->DrawDeferred();
       
   205         }
       
   206     __LOG( "CUPnPExternalDeviceDialog::PreLayoutDynInitL End" );    
       
   207     }
       
   208 
       
   209 // --------------------------------------------------------------------------
       
   210 // CUPnPExternalDeviceDialog::PostLayoutDynInitL();
       
   211 // --------------------------------------------------------------------------
       
   212 //
       
   213 void CUPnPExternalDeviceDialog::PostLayoutDynInitL()
       
   214     {
       
   215     iNaviPaneActive = ETrue;
       
   216     UpDateAnimationWindowL(iNaviPaneActive);//DateAnimationWindow();
       
   217     }
       
   218 
       
   219 // --------------------------------------------------------------------------
       
   220 // CUPnPExternalDeviceDialog::OkToExitL(TInt aButtonId)
       
   221 // see upnpexternaldevicedialog.h
       
   222 // --------------------------------------------------------------------------
       
   223 //
       
   224 TBool CUPnPExternalDeviceDialog::OkToExitL( TInt aButtonId )
       
   225     {
       
   226     __LOG( "CUPnPExternalDeviceDialog::OkToExitL" );
       
   227     
       
   228     TBool returnValue = EFalse;
       
   229     iCommonUI.HandleCommonErrorL( aButtonId, NULL );
       
   230     // Translate the button presses into commands for the appui & current
       
   231     // view to handle
       
   232     switch ( aButtonId )
       
   233         {
       
   234         case EAknSoftkeyOptions:
       
   235             {
       
   236             DisplayMenuL(); 
       
   237             break;
       
   238             }
       
   239         case EAknSoftkeyOpen: //fall through
       
   240         case EAknSoftkeyOk:
       
   241             {
       
   242             CTextListBoxModel *model = iListBox->Model();
       
   243 
       
   244             if (model->NumberOfItems()) //browse only if list have items
       
   245                 {
       
   246                 iNaviPaneActive = EFalse;                
       
   247                 UpDateAnimationWindowL(iNaviPaneActive);
       
   248 
       
   249                 TInt ret = ExecuteBrowseL();
       
   250                 if (ret == EAknCmdExit || 
       
   251                     ret == EEikCmdExit ||
       
   252                     ret == KErrDisconnected ||
       
   253                     ret == KErrSessionClosed
       
   254                     )
       
   255                     {
       
   256                     TryExitL( ret );
       
   257                     }
       
   258                 else
       
   259                     {
       
   260                     DisplayMediaServersL();
       
   261                     iNaviPaneActive = ETrue;
       
   262                     UpDateAnimationWindowL(iNaviPaneActive);
       
   263                     }
       
   264                 }
       
   265             break;
       
   266             }
       
   267         case EAknSoftkeyBack: // fall through
       
   268         case EUPnPBackCmd: // fall through
       
   269         case EAknSoftkeyCancel: // fall through
       
   270         case EAknSoftkeyExit: // fall through
       
   271         case EAknCmdExit: // fall through
       
   272         case EEikCmdExit: // fall through
       
   273         case KErrNotReady: // fall through
       
   274         case KErrDisconnected:
       
   275             {
       
   276             if( iTitlePane )
       
   277                 {
       
   278                 iTitlePane->SetTextToDefaultL();
       
   279                 }
       
   280             returnValue = ETrue; //back to previous dialog
       
   281             break;
       
   282             }
       
   283         case KErrSessionClosed:
       
   284             {
       
   285             DisplayMediaServersL();
       
   286             iNaviPaneActive = ETrue;
       
   287             UpDateAnimationWindowL(iNaviPaneActive);
       
   288 
       
   289             break;
       
   290             }
       
   291         default:
       
   292             {
       
   293             // ignore
       
   294             }
       
   295         }
       
   296   
       
   297     __LOG( "CUPnPExternalDeviceDialog::OkToExitL End." );
       
   298     return returnValue;
       
   299     }
       
   300 
       
   301 // --------------------------------------------------------------------------
       
   302 // CUPnPExternalDevice::DynInitMenuPaneL(TInt aResourceId, 
       
   303 // CEikMenuPane *aMenuPane)
       
   304 // called by framework before menu panel is shown
       
   305 // --------------------------------------------------------------------------
       
   306 void  CUPnPExternalDeviceDialog::DynInitMenuPaneL( TInt aResourceId,
       
   307                                                    CEikMenuPane *aMenuPane )
       
   308     {
       
   309     __LOG( "CUPnPExternalDeviceDialog::DynInitMenuPaneL" );
       
   310 
       
   311     if( aResourceId ==  R_UPNPCOMMONUI_EXTERNAL_DEVICE_OPTION_MENU )
       
   312         {
       
   313         // Hide menu items if empty list
       
   314         CTextListBoxModel *model = iListBox->Model();
       
   315         if ( !model->NumberOfItems() ) 
       
   316             {
       
   317             aMenuPane->SetItemDimmed( EUPnPOpen, ETrue );
       
   318             aMenuPane->SetItemDimmed( EUPnPFind, ETrue );
       
   319             }
       
   320 
       
   321         // Hide "Find" if the currently focused device does not support it
       
   322         TInt selected_item = iListBox->CurrentItemIndex();
       
   323         if( selected_item >= 0 &&
       
   324             !( *iDeviceArray )[ selected_item ]->SearchCapability() )
       
   325             {
       
   326             aMenuPane->SetItemDimmed( EUPnPFind, ETrue );
       
   327             }
       
   328 
       
   329         // Hide "Help" if the help file is not available
       
   330         if( !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   331             {
       
   332             aMenuPane->SetItemDimmed( EUPnPHelp, ETrue );
       
   333             }
       
   334         }
       
   335     __LOG( "CUPnPExternalDeviceDialog::DynInitMenuPaneL End" );    
       
   336     }
       
   337 
       
   338 // --------------------------------------------------------------------------
       
   339 // CUPnPExternalDeviceDialog::ProcessCommandL(TInt aCommand)
       
   340 // called by framework when menu item is selected
       
   341 // --------------------------------------------------------------------------
       
   342 //
       
   343 void CUPnPExternalDeviceDialog::ProcessCommandL( TInt aCommand )
       
   344     {
       
   345     __LOG( "CUPnPExternalDeviceDialog::ProcessCommandL" );
       
   346     
       
   347     TInt error = KErrNone;
       
   348     HideMenu();
       
   349     switch ( aCommand ) 
       
   350         {
       
   351         case EAknCmdExit:
       
   352         case EEikCmdExit:
       
   353             {
       
   354             TryExitL( aCommand );
       
   355             break;
       
   356             }
       
   357         case EUPnPOpen:
       
   358             {
       
   359             iNaviPaneActive = EFalse;
       
   360             UpDateAnimationWindowL(iNaviPaneActive);
       
   361 
       
   362             error = ExecuteBrowseL();
       
   363             if ( error == EAknCmdExit ||
       
   364                  error == EEikCmdExit ||
       
   365                  error == KErrDisconnected ||
       
   366                  error == KErrSessionClosed )
       
   367                 {
       
   368                 TryExitL( error );
       
   369                 }
       
   370             else 
       
   371                 {
       
   372                 DisplayMediaServersL(); 
       
   373                 iNaviPaneActive = ETrue;
       
   374                 UpDateAnimationWindowL(iNaviPaneActive); 
       
   375                 }
       
   376             break;
       
   377             }
       
   378         case EUPnPFind:
       
   379             {
       
   380             iNaviPaneActive = EFalse;
       
   381             UpDateAnimationWindowL(iNaviPaneActive);  
       
   382             
       
   383             error = ExecuteFindL();
       
   384             if ( error == EAknCmdExit ||
       
   385                  error == EEikCmdExit ||
       
   386                  error == KErrDisconnected || 
       
   387                  error == KErrNotReady || 
       
   388                  error == KErrSessionClosed )
       
   389                 {
       
   390                 TryExitL( error );
       
   391                 }
       
   392             else
       
   393                 {
       
   394                 iNaviPaneActive = ETrue;
       
   395                 UpDateAnimationWindowL(iNaviPaneActive);
       
   396                 }
       
   397             break;
       
   398             }
       
   399         case EUPnPHelp:
       
   400             {
       
   401             iNaviPaneActive = EFalse;
       
   402             UpDateAnimationWindowL(iNaviPaneActive);
       
   403             HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(),
       
   404             iEikonEnv->EikAppUi()->AppHelpContextL() );
       
   405             iNaviPaneActive = ETrue;
       
   406             UpDateAnimationWindowL(iNaviPaneActive);
       
   407             break;
       
   408             }
       
   409         default:
       
   410             break;
       
   411         }
       
   412     __LOG( "CUPnPExternalDeviceDialog::ProcessCommandL End" );    
       
   413     }
       
   414 
       
   415 // --------------------------------------------------------------------------
       
   416 // CUPnPExternalDeviceDialog::UPnPDeviceDiscovered
       
   417 // Returns discovered device from UPnP AV control point.
       
   418 // --------------------------------------------------------------------------
       
   419 //
       
   420 void CUPnPExternalDeviceDialog::UPnPDeviceDiscovered(
       
   421                                         const CUpnpAVDevice& aDevice )
       
   422     {
       
   423     __LOG( "CUPnPExternalDeviceDialog::UPnPDeviceDiscovered" );
       
   424     TInt error = KErrNone;
       
   425     TRAP( error, UPnPDeviceDiscoveredL( aDevice ) );
       
   426     
       
   427     __LOG1( "CUPnPExternalDeviceDialog::UPnPDeviceDiscovered %d", error);
       
   428     }
       
   429 
       
   430 // --------------------------------------------------------------------------
       
   431 // CUPnPExternalDeviceDialog::UPnPDeviceDiscoveredL
       
   432 // Returns discovered device from UPnP AV control point.
       
   433 // --------------------------------------------------------------------------
       
   434 //
       
   435 void CUPnPExternalDeviceDialog::UPnPDeviceDiscoveredL(
       
   436                                         const CUpnpAVDevice& aDevice )
       
   437     {
       
   438     __LOG( "CUPnPExternalDeviceDialog::UPnPDeviceDiscovered" );
       
   439               
       
   440     // Display only Media servers
       
   441     if( aDevice.DeviceType() == CUpnpAVDevice::EMediaServer )
       
   442         {
       
   443         CUpnpAVDevice* tempDevice = CUpnpAVDevice::NewL( aDevice ) ;
       
   444                                       
       
   445         CleanupStack::PushL( tempDevice );
       
   446         iDeviceArray->AppendDeviceL( *tempDevice );
       
   447         CleanupStack::Pop( tempDevice ); 
       
   448         
       
   449         // Get device friendly name and replace illegal characters.
       
   450         HBufC8* tmpfriendlyname = 
       
   451             UPnPCommonUtils::ReplaceIllegalFilenameCharactersL( 
       
   452             ( ( CUpnpAVDevice* )tempDevice )->FriendlyName() );
       
   453             
       
   454         CleanupStack::PushL( tmpfriendlyname );
       
   455         TPtrC8 friendlyname = *tmpfriendlyname;
       
   456                 
       
   457         CTextListBoxModel* model = iListBox->Model();
       
   458         MDesCArray* textArray = model->ItemTextArray();
       
   459         CDesCArray* listBoxItems = static_cast<CDesCArray*>( textArray );
       
   460         TBuf<256> item;
       
   461         
       
   462         HBufC *tmpbuf = UpnpString::ToUnicodeL( friendlyname.Left( KLength ) );
       
   463         CleanupStack::PushL( tmpbuf ); 
       
   464         
       
   465         item.Format( _L( "%d\t%S\t\t" ),0, tmpbuf ); 
       
   466         CleanupStack::PopAndDestroy( tmpbuf ); 
       
   467         CleanupStack::PopAndDestroy( tmpfriendlyname );
       
   468 
       
   469         listBoxItems->AppendL( item );
       
   470         iListBox->HandleItemAdditionL(); // Update listbox
       
   471 
       
   472         iListBox->ActivateL();
       
   473         iListBox->DrawDeferred();
       
   474         
       
   475         //update menu pane
       
   476         CEikButtonGroupContainer* cba = &ButtonGroupContainer();
       
   477         
       
   478         cba->SetCommandSetL( R_UPNPCOMMONUI_SOFTKEYS_OPTIONS_BACK__OPEN );
       
   479         cba->DrawDeferred();
       
   480         }
       
   481     __LOG( "CUPnPExternalDeviceDialog::UPnPDeviceDiscovered End" );
       
   482     }
       
   483 
       
   484 // --------------------------------------------------------------------------
       
   485 // CUPnPExternalDeviceDialog::UPnPDeviceDisappeared
       
   486 // Returns disappeared device from UPnP AV control point.
       
   487 // --------------------------------------------------------------------------
       
   488 //
       
   489 void CUPnPExternalDeviceDialog::UPnPDeviceDisappeared(
       
   490                                         const CUpnpAVDevice& aDevice )
       
   491     {
       
   492     __LOG( "CUPnPExternalDeviceDialog::UPnPDeviceDisappeared" );
       
   493     
       
   494     TRAP_IGNORE( UPnPDeviceDisappearedL( aDevice ) );
       
   495     
       
   496     }
       
   497 
       
   498 // --------------------------------------------------------------------------
       
   499 // CUPnPExternalDeviceDialog::UPnPDeviceDisappearedL
       
   500 // Returns disappeared device from UPnP AV control point.
       
   501 // --------------------------------------------------------------------------
       
   502 //
       
   503 void CUPnPExternalDeviceDialog::UPnPDeviceDisappearedL(
       
   504                                                const CUpnpAVDevice& aDevice )
       
   505     {
       
   506     __LOG( "CUPnPExternalDeviceDialog::UPnPDeviceDissapearedL" );
       
   507     
       
   508     CTextListBoxModel* model = iListBox->Model();
       
   509     TInt currentItem = iListBox->CurrentItemIndex();
       
   510     MDesCArray* textArray = model->ItemTextArray();
       
   511     CDesCArray* listBoxItems = static_cast<CDesCArray*>( textArray );
       
   512     TInt i = 0;
       
   513     TPtrC8 ptr(aDevice.Uuid());
       
   514     while( i < iDeviceArray->Count() &&
       
   515         ptr.Compare( ( *iDeviceArray)[ i ]->Uuid() ) )
       
   516         {
       
   517         i++;
       
   518         }
       
   519     if ( i < iDeviceArray->Count() )
       
   520         {
       
   521         iDeviceArray->RemoveAndDestroy( i );
       
   522         listBoxItems->Delete( i,1 );
       
   523         AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(
       
   524             iListBox, currentItem, ETrue );
       
   525         iListBox->DrawDeferred();
       
   526         }
       
   527             
       
   528     if ( !iDeviceArray->Count() )
       
   529         {
       
   530         // show "Waiting devices" text
       
   531         iListBox->View()->SetListEmptyTextL(
       
   532             *StringLoader::LoadLC( R_UPNPCOMMONUI_EXTERNAL_WAITING_NOTE ) );
       
   533         CleanupStack::PopAndDestroy(); // R_EXTERNAL_WAITING_NOTE
       
   534         
       
   535         CEikButtonGroupContainer* cba = &ButtonGroupContainer();
       
   536         cba->SetCommandSetL( R_UPNPCOMMONUI_SOFTKEYS_EMPTY_BACK );
       
   537         cba->DrawDeferred();
       
   538         }
       
   539    
       
   540     __LOG( "CUPnPExternalDeviceDialog::UPnPDeviceDissapearedL-END" );
       
   541     }
       
   542     
       
   543 // --------------------------------------------------------------------------
       
   544 // CUPnPExternalDeviceDialog::AppendIconToArrayL
       
   545 // Load a possibly skinned icon (with mask) and append it to an 
       
   546 // icon array.
       
   547 // --------------------------------------------------------------------------
       
   548 //
       
   549 void CUPnPExternalDeviceDialog::AppendIconToArrayL( CAknIconArray* aArray,
       
   550                                            MAknsSkinInstance* aSkin,
       
   551                                            const TDesC& aMbmFile,
       
   552                                            const TAknsItemID& aID,
       
   553                                            TInt aBitmapId,
       
   554                                            TInt aMaskId )
       
   555     {
       
   556     __LOG( "CUPnPExternalDeviceDialog::AppendIconToArrayL" );
       
   557     
       
   558     __ASSERTD( aArray != NULL, __FILE__, __LINE__ );
       
   559 
       
   560     CFbsBitmap* bitmap = NULL;
       
   561     CFbsBitmap* mask = NULL;
       
   562 
       
   563     AknsUtils::CreateIconLC( aSkin, aID,
       
   564         bitmap, mask, aMbmFile, aBitmapId, aMaskId );
       
   565 
       
   566     CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
       
   567     icon->SetBitmapsOwnedExternally( EFalse );
       
   568 
       
   569     // icon now owns the bitmaps, no need to keep on cleanup stack.
       
   570     CleanupStack::Pop( 2 ); // mask, bitmap
       
   571     bitmap = NULL;
       
   572     mask = NULL;
       
   573 
       
   574     CleanupStack::PushL( icon );
       
   575     aArray->AppendL( icon );
       
   576 
       
   577     // aArray now owns the icon, no need to delete.
       
   578     CleanupStack::Pop();
       
   579     __LOG( "CUPnPExternalDeviceDialog::AppendIconToArrayL End" );
       
   580     }
       
   581 
       
   582 // --------------------------------------------------------------------------
       
   583 // CUPnPBrowseDialog::DisplayMediaServersL
       
   584 // Add visible Media Servers to Listbox of dialog
       
   585 // --------------------------------------------------------------------------
       
   586 void CUPnPExternalDeviceDialog::DisplayMediaServersL()
       
   587     {
       
   588     __LOG( "CUPnPExternalDeviceDialog::DisplayMediaServersL" );
       
   589     
       
   590     CTextListBoxModel* model = iListBox->Model();
       
   591     MDesCArray* textArray = model->ItemTextArray();
       
   592     CDesCArray* listBoxItems = static_cast<CDesCArray*>( textArray );
       
   593     
       
   594     //clear list        
       
   595     delete iDeviceArray; iDeviceArray = NULL;
       
   596     listBoxItems->Reset();
       
   597     
       
   598     TBuf<256> item;
       
   599     
       
   600     iDeviceArray=iAVControl.GetMediaServersL();
       
   601     
       
   602 
       
   603     if ( iDeviceArray->Count() )
       
   604         {
       
   605         for ( TInt i=0; i < iDeviceArray->Count(); i++ )
       
   606             {
       
   607             // Get device frienly name and replace illegal characters.
       
   608             HBufC8* tmpfriendlyname = 
       
   609             UPnPCommonUtils::ReplaceIllegalFilenameCharactersL( 
       
   610                 ( *iDeviceArray )[ i ]->FriendlyName() );
       
   611 
       
   612             CleanupStack::PushL( tmpfriendlyname );
       
   613             TPtrC8 friendlyname = *tmpfriendlyname;
       
   614 
       
   615             HBufC* tmpbuf = UpnpString::ToUnicodeL( 
       
   616                 friendlyname.Left( KLength ) );
       
   617             CleanupStack::PushL( tmpbuf ); 
       
   618             item.Format( _L( "%d\t%S\t\t" ),0, tmpbuf ); 
       
   619             CleanupStack::PopAndDestroy( tmpbuf );
       
   620             CleanupStack::PopAndDestroy( tmpfriendlyname ); 
       
   621             listBoxItems->AppendL( item );
       
   622             }
       
   623         
       
   624         iListBox->HandleItemAdditionL(); // Update listbox
       
   625         iListBox->SetCurrentItemIndexAndDraw( 0 ); // select new item        
       
   626         }
       
   627     __LOG( "CUPnPExternalDeviceDialog::DisplayMediaServersL End" );        
       
   628     }
       
   629 
       
   630 
       
   631 // --------------------------------------------------------------------------
       
   632 // CUPnPExternalDeviceDialog::ExecuteBrowseL
       
   633 // see upnpexternaldevicedialog.h
       
   634 // --------------------------------------------------------------------------
       
   635 TInt CUPnPExternalDeviceDialog::ExecuteBrowseL()
       
   636     {
       
   637     __LOG( "CUPnPExternalDeviceDialog::ExecuteBrowseL" );
       
   638     
       
   639     TInt selected_item = iListBox->CurrentItemIndex();
       
   640 
       
   641     const CUpnpAVDevice* selectedDevice = ( *iDeviceArray )[ selected_item ];
       
   642     
       
   643     TInt ret = iCommonUI.ExecuteBrowseDialogL(
       
   644         iAVControl, *selectedDevice );
       
   645     
       
   646     iTitlePane->SetTextL( *StringLoader::LoadLC(
       
   647         R_UPNPCOMMONUI_EXTERNAL_MEDIA_TITLE ) );
       
   648     CleanupStack::PopAndDestroy();
       
   649 
       
   650     
       
   651     __LOG( "CUPnPExternalDeviceDialog::ExecuteBrowseL End" );
       
   652     return ret;
       
   653     }
       
   654     
       
   655 // --------------------------------------------------------------------------
       
   656 // CUPnPExternalDeviceDialog::ExecuteFindL
       
   657 // see upnpexternaldevicedialog.h
       
   658 // --------------------------------------------------------------------------
       
   659 TInt CUPnPExternalDeviceDialog::ExecuteFindL()
       
   660     {
       
   661     __LOG( "CUPnPExternalDeviceDialog::ExecuteFindL" );
       
   662     
       
   663     TInt ret = KErrNone;
       
   664     TInt selected_item = iListBox->CurrentItemIndex();
       
   665     CUpnpAVDevice* selectedDevice = 
       
   666                             ( *iDeviceArray )[ selected_item ];
       
   667     
       
   668     if( selectedDevice )
       
   669         {
       
   670         //create a browsessesion only for advFind dialog
       
   671         
       
   672         MUPnPAVBrowsingSession* browsingSession = NULL;    
       
   673         browsingSession = &( iAVControl.StartBrowsingSessionL(
       
   674                                                 *selectedDevice ) );
       
   675         
       
   676         ret = iCommonUI.ExecuteAdvFindDialogL( iAVControl,
       
   677                                                *browsingSession );
       
   678         browsingSession->RemoveObserver();
       
   679         iAVControl.StopBrowsingSession( *browsingSession );    
       
   680         }
       
   681     
       
   682     if( KErrDisconnected != ret ) //if not WLAN lost
       
   683         {
       
   684         DisplayMediaServersL();    
       
   685         }
       
   686 
       
   687     __LOG( "CUPnPExternalDeviceDialog::ExecuteFindL End" );
       
   688     return ret;
       
   689     }
       
   690     
       
   691 
       
   692             
       
   693 // --------------------------------------------------------------------------
       
   694 // CUPnPExternalDeviceDialog::WLANConnectionLost
       
   695 // see upnpexternaldevicedialog.h
       
   696 // --------------------------------------------------------------------------
       
   697 void CUPnPExternalDeviceDialog::WLANConnectionLost() 
       
   698     {
       
   699     __LOG( "CUPnPExternalDeviceDialog::WLANConnectionLost" );
       
   700     //if no dialog created in CUPnPExternalDeviceDialog, destory itself 
       
   701     //Otherwise destory other dialogs like in normal by KErrAbort
       
   702     if( !iCommonUI.PresenceOfDialog() )
       
   703         {
       
   704         TRAP_IGNORE( TryExitL( KErrDisconnected ) );
       
   705         }
       
   706     
       
   707     }
       
   708 
       
   709 
       
   710 // --------------------------------------------------------------------------
       
   711 // CUPnPExternalDeviceDialog::GetHelpContext
       
   712 // see upnpexternaldevicedialog.h
       
   713 // --------------------------------------------------------------------------
       
   714 //
       
   715 void CUPnPExternalDeviceDialog::GetHelpContext(
       
   716                                         TCoeHelpContext& aContext ) const
       
   717     {
       
   718     __LOG( "CUPnPExternalDeviceDialog::GetHelpContext" );
       
   719     
       
   720 //  aContext.iMajor = TUid::Uid( KMediaGalleryUID3 );    
       
   721     aContext.iContext = KUPNP_HLP_MAIN_EXTERNAL;
       
   722     
       
   723     __LOG( "CUPnPExternalDeviceDialog::GetHelpContext End" );
       
   724     }
       
   725 
       
   726 // --------------------------------------------------------------------------
       
   727 // CUPnPExternalDeviceDialog::UpDateAnimationWindowL
       
   728 // see upnpexternaldevicedialog.h
       
   729 // --------------------------------------------------------------------------
       
   730 //
       
   731 void CUPnPExternalDeviceDialog::UpDateAnimationWindowL(TBool aAnimationState)
       
   732     {    
       
   733     __LOG( "CUPnPExternalDeviceDialog::UpDateAnimationWindowL" );
       
   734     if ( iNaviDecorator )
       
   735         {
       
   736         iNaviPaneContainer->Pop( iNaviDecorator );
       
   737         }
       
   738     
       
   739     // destroy iNaviDecorator
       
   740     delete iNaviDecorator;
       
   741     iNaviDecorator = NULL;
       
   742         
       
   743     if ( ( !Layout_Meta_Data::IsLandscapeOrientation() )
       
   744          && ( aAnimationState ) )
       
   745         {
       
   746         iStatusPane = iEikonEnv->AppUiFactory()->StatusPane();
       
   747 
       
   748         TBool naviFaded = iStatusPane->IsFaded();
       
   749 
       
   750         if (!naviFaded)
       
   751             {
       
   752             iNaviPaneContainer = ( CAknNavigationControlContainer* )
       
   753                 iStatusPane->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) );
       
   754         
       
   755             TPoint screenPosition = iNaviPaneContainer->
       
   756                 PositionRelativeToScreen();
       
   757             /**
       
   758              * adjust the screen position so that the "Searching..." could be 
       
   759              * exactly in that "blue" NaviPane
       
   760              */                        
       
   761             screenPosition.iY = screenPosition.iY+1;
       
   762             iNaviContainer = CUPnPNaviPaneContainer::NewL(
       
   763                                                  iNaviPaneContainer->Rect(),
       
   764                                                  screenPosition,
       
   765                                                  iNaviPaneContainer );
       
   766         
       
   767             iNaviDecorator = CAknNavigationDecorator::NewL(
       
   768                 iNaviPaneContainer, iNaviContainer );
       
   769         iNaviDecorator->SetContainerWindowL( *iNaviPaneContainer );
       
   770         iNaviDecorator->MakeScrollButtonVisible(EFalse);
       
   771         iNaviDecorator->SetComponentsToInheritVisibility( ETrue );
       
   772             iNaviPaneContainer->PushL( *iNaviDecorator );        
       
   773             }
       
   774         }
       
   775     iListBox->ActivateL();
       
   776     
       
   777     __LOG( "CUPnPExternalDeviceDialog::UpDateAnimationWindowL End" );
       
   778     }
       
   779 
       
   780 // --------------------------------------------------------------------------
       
   781 // CUPnPExternalDeviceDialog::HandleResourceChange
       
   782 // --------------------------------------------------------------------------
       
   783 //    
       
   784 void CUPnPExternalDeviceDialog::HandleResourceChange(TInt aType)
       
   785     {
       
   786     __LOG("[UPnPCommonUI]\t CUPnPExternalDeviceDialog::HandleResourceChange");
       
   787     CAknDialog::HandleResourceChange(aType);
       
   788     
       
   789     // Update Titlepane only if there is no other dialogs open
       
   790     if( !iCommonUI.PresenceOfDialog() )
       
   791         {
       
   792         __LOG("[UPnPCommonUI]\t CUPnPExternalDeviceDialog::HandleResourceChange\
       
   793 updating iTitlePane");
       
   794 
       
   795     TRAPD( err,
       
   796             iTitlePane->SetTextL( *StringLoader::LoadLC(
       
   797                 R_UPNPCOMMONUI_EXTERNAL_MEDIA_TITLE ) );
       
   798             CleanupStack::PopAndDestroy();
       
   799             );
       
   800             
       
   801     if( err != KErrNone )
       
   802         {
       
   803         __LOG("[UPnPCommonUI]\t CUPnPExternalDeviceDialog::HandleResourceChange\
       
   804 iTitlePane->SetTextL failed");
       
   805             }
       
   806         }
       
   807     
       
   808     if (iNaviPaneActive)
       
   809         {
       
   810         TRAP_IGNORE( UpDateAnimationWindowL(iNaviPaneActive) );
       
   811         }    
       
   812     }         
       
   813 // end of file