upnpframework/upnpcommonui/src/upnpselectiondialog.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-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:  Source file for UPnP Browse UI Implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 // System
       
    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 
       
    28 // upnp stack api
       
    29 #include <upnpstring.h>
       
    30 
       
    31 // upnpframework / avcontroller api
       
    32 #include "upnpavdevice.h"
       
    33 #include "upnpavcontroller.h"
       
    34 #include "upnpavcontrollerfactory.h"
       
    35 #include "upnpavdevicelist.h"
       
    36 #include "upnpavdevice.h"
       
    37 #include "upnpavcontroller.h"
       
    38 
       
    39 // upnpframework / internal api's
       
    40 #include "upnpcommonutils.h"
       
    41 
       
    42 // common ui internal
       
    43 #include <upnpcommonui.rsg>
       
    44 #include <upnpcommonui.mbg> //for icons
       
    45 #include "upnpselectiondialog.h"
       
    46 #include "upnpcommonui.h"
       
    47 
       
    48 // debug stuff
       
    49 _LIT( KComponentLogfile, "commonui.txt");
       
    50 #include "upnplog.h"
       
    51 
       
    52 // CONSTANTS
       
    53 _LIT( KAknCommonUIMbmFileName, "\\resource\\apps\\upnpcommonui.mbm" );
       
    54 const TInt KLength = 100;
       
    55 
       
    56 // --------------------------------------------------------------------------
       
    57 // CUPnPSelectionDialog::NewL
       
    58 // Two-phased constructor.
       
    59 // --------------------------------------------------------------------------
       
    60 CUPnPSelectionDialog* CUPnPSelectionDialog::NewL(
       
    61     MUPnPAVController& aAVControl )
       
    62     {
       
    63     __LOG( "CUPnPSelectionDialog::NewL" );
       
    64     
       
    65     CUPnPSelectionDialog* self = 
       
    66                            new ( ELeave ) CUPnPSelectionDialog( aAVControl );
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69     CleanupStack::Pop();
       
    70     return self;
       
    71     }
       
    72 
       
    73 // --------------------------------------------------------------------------
       
    74 // CUPnPSelectionDialog::ConstructL
       
    75 // Symbian 2nd phase constructor can leave.
       
    76 // --------------------------------------------------------------------------
       
    77 void CUPnPSelectionDialog::ConstructL()
       
    78     {
       
    79     __LOG( "CUPnPSelectionDialog::ConstructL" );
       
    80     
       
    81     iDeviceArray = CUpnpAVDeviceList::NewL();
       
    82     // Register as an observer to device operations
       
    83 
       
    84     iTypeOfDevicesToSearch = EUPnPSearchAllDevices;
       
    85     }
       
    86 
       
    87 // --------------------------------------------------------------------------
       
    88 // CUPnPSelectionDialog::CUPnPSelectionDialog
       
    89 // C++ default constructor can NOT contain any code, that
       
    90 // might leave.
       
    91 // --------------------------------------------------------------------------
       
    92 CUPnPSelectionDialog::CUPnPSelectionDialog( MUPnPAVController& aAVControl ):
       
    93                                            iAVControl( aAVControl )
       
    94     {
       
    95     __LOG( "CUPnPSelectionDialog::CUPnPSelectionDialog" );
       
    96     
       
    97     iDeviceObserver = iAVControl.DeviceObserver();
       
    98     iAVControl.RemoveDeviceObserver();
       
    99     iAVControl.SetDeviceObserver( *this );
       
   100     iPopup = NULL;
       
   101     iExitReason = KErrNone;
       
   102     }
       
   103 
       
   104 // Destructor
       
   105 CUPnPSelectionDialog::~CUPnPSelectionDialog()
       
   106     {
       
   107     __LOG( "CUPnPSelectionDialog::~CUPnPSelectionDialog" );
       
   108 
       
   109     delete iListBox;
       
   110 
       
   111     // Unregister as an observer to device operations
       
   112     iAVControl.RemoveDeviceObserver();
       
   113     if( iDeviceObserver )
       
   114         {
       
   115         iAVControl.SetDeviceObserver( *iDeviceObserver );    
       
   116         }
       
   117 
       
   118     delete iDeviceArray;
       
   119     }
       
   120 
       
   121 // --------------------------------------------------------------------------
       
   122 // CUPnPSelectionDialog::PreLayoutDynInitL();
       
   123 // called by framework before dialog is shown
       
   124 // --------------------------------------------------------------------------
       
   125 void CUPnPSelectionDialog::PreLayoutDynInitL( const TDesC& aTitle )
       
   126     {
       
   127     __LOG( "CUPnPSelectionDialog::PreLayoutDynInitL" );
       
   128 
       
   129     // Browse dialog title text
       
   130     iPopup->SetTitleL( aTitle ); 
       
   131 
       
   132     CAknIconArray* icons = new ( ELeave ) CAknIconArray(2);
       
   133     CleanupStack::PushL( icons );
       
   134 
       
   135     // Mif icons
       
   136     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   137     TFileName iconsPath( AknIconUtils::AvkonIconFileName( ) );
       
   138 
       
   139     TFileName mbmFileName( KAknCommonUIMbmFileName );
       
   140     TFileName dllName;
       
   141     Dll::FileName( dllName );
       
   142     TBuf<2> drive = dllName.Left( 2 ); // Drive letter followed by ':' 
       
   143     mbmFileName.Insert( 0, drive );
       
   144     
       
   145     // Media server icon
       
   146     AppendIconToArrayL( icons, skin, 
       
   147                         mbmFileName, 
       
   148                         KAknsIIDDefault, 
       
   149                         EMbmUpnpcommonuiQgn_server_icon, 
       
   150                         EMbmUpnpcommonuiQgn_server_icon_mask );
       
   151     iListBox->ItemDrawer()->FormattedCellData()->SetIconArrayL( icons );
       
   152     CleanupStack::Pop( icons );
       
   153     
       
   154     // Enable horizontal scrolling
       
   155     iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
       
   156     LoadListItemsL();
       
   157     }
       
   158 
       
   159 
       
   160 // --------------------------------------------------------------------------
       
   161 // CUPnPSelectionDialog::LoadListItemsL
       
   162 // Sends the browse request to UPnP AV Controller. When result set arrives,
       
   163 // UPnP AV Controller will call the "BrowseResultsL" call back method,
       
   164 // which is implemented below.
       
   165 // --------------------------------------------------------------------------
       
   166 void CUPnPSelectionDialog::LoadListItemsL()
       
   167     {
       
   168     __LOG( "CUPnPSelectionDialog::LoadListItemsL" );
       
   169 
       
   170     CTextListBoxModel* model = iListBox->Model();
       
   171     MDesCArray* textArray = model->ItemTextArray();
       
   172     CDesCArray* listBoxItems = static_cast<CDesCArray*>( textArray );
       
   173     
       
   174     //contents inside the array will be owned by iDeviceArray
       
   175     CUpnpAVDeviceList* tempDeviceArray = NULL;
       
   176     // Get the devices from the UPnP Stack according to the search criteria
       
   177     if( iTypeOfDevicesToSearch == EUPnPSearchAllDevices )
       
   178         {
       
   179             CUpnpAVDeviceList* tempDeviceArray2 = NULL;
       
   180             tempDeviceArray2 = iAVControl.GetMediaServersL();
       
   181             if( tempDeviceArray2->Count() > 0 )
       
   182                 {
       
   183                 CleanupStack::PushL( tempDeviceArray2 );
       
   184                 CleanupStack::PushL( tempDeviceArray );
       
   185                 for( TInt i = 0; i < tempDeviceArray2->Count(); i++ )
       
   186                     {
       
   187                     tempDeviceArray->AppendDeviceL( 
       
   188                                                 *( *tempDeviceArray2 )[i] );
       
   189                     }
       
   190                 
       
   191                 CleanupStack::Pop( tempDeviceArray );
       
   192                 CleanupStack::Pop( tempDeviceArray2 );
       
   193                 tempDeviceArray2->Reset();
       
   194                 
       
   195                 }
       
   196             
       
   197             tempDeviceArray2 = iAVControl.GetMediaRenderersL();
       
   198             
       
   199             if(tempDeviceArray2->Count() > 0 )
       
   200                 {
       
   201                 CleanupStack::PushL( tempDeviceArray2 );
       
   202                 CleanupStack::PushL( tempDeviceArray );
       
   203                 for( TInt i = 0; i < tempDeviceArray2->Count(); i++ )
       
   204                     {
       
   205                     tempDeviceArray->AppendDeviceL( 
       
   206                                                 *( *tempDeviceArray2 )[i] );
       
   207                     }
       
   208                 
       
   209                 CleanupStack::Pop( tempDeviceArray );    
       
   210                 CleanupStack::Pop( tempDeviceArray2);
       
   211                 tempDeviceArray2->Reset();
       
   212                 }
       
   213             
       
   214             delete tempDeviceArray2;
       
   215             
       
   216         }
       
   217     else if( iTypeOfDevicesToSearch == EUPnPSearchAllServerDevices ||
       
   218       iTypeOfDevicesToSearch == EUPnPSearchServerDevicesWithCopyCapability ||
       
   219       iTypeOfDevicesToSearch == EUPnPSearchServerDevicesWithSearchCapability )
       
   220         {
       
   221         tempDeviceArray = iAVControl.GetMediaServersL();
       
   222         }
       
   223     else
       
   224         {
       
   225         tempDeviceArray = iAVControl.GetMediaRenderersL();
       
   226         }
       
   227     
       
   228     CleanupStack::PushL( tempDeviceArray );
       
   229     if ( tempDeviceArray->Count() )
       
   230         {
       
   231         for ( TInt i=0; i < tempDeviceArray->Count(); i++ )
       
   232             {
       
   233             // Check if the device match with the search criteria
       
   234             if( MatchWithSearchCriteria( 
       
   235                      const_cast<CUpnpAVDevice*>( ( *tempDeviceArray)[i] ) ) )
       
   236                 {
       
   237                 iDeviceArray->AppendDeviceL( *( *tempDeviceArray )[i] );
       
   238                 }
       
   239             else
       
   240                 {
       
   241                 CUpnpAVDevice* tempDevice = ( *tempDeviceArray )[i];
       
   242                 delete tempDevice;
       
   243                 tempDevice = NULL;
       
   244                 }
       
   245             }        
       
   246         
       
   247         
       
   248         for ( TInt i=0; i < iDeviceArray->Count(); i++ )
       
   249             {
       
   250             // Get device friendly name and replace illegal characters.
       
   251             HBufC8* tmpfriendlyname = 
       
   252             UPnPCommonUtils::ReplaceIllegalFilenameCharactersL(               
       
   253                 ( *iDeviceArray )[i]->FriendlyName().Left( KLength ) );
       
   254             CleanupStack::PushL( tmpfriendlyname);
       
   255             
       
   256             HBufC* device = UpnpString::ToUnicodeL( *tmpfriendlyname );
       
   257             CleanupStack::PushL( device);
       
   258 
       
   259             TBuf<KMaxFileName> item;
       
   260             item.Format( _L( "%d\t%S\t\t" ),0, device ); 
       
   261 
       
   262             CleanupStack::PopAndDestroy( device );
       
   263             CleanupStack::PopAndDestroy( tmpfriendlyname );
       
   264             listBoxItems->AppendL( item );            
       
   265             }
       
   266 
       
   267         // Updates CBA.
       
   268         UpdateCommandSetL();
       
   269 
       
   270         iListBox->HandleItemAdditionL(); // Update listbox
       
   271         iListBox->SetCurrentItemIndexAndDraw( 0 ); // select new item
       
   272  
       
   273         }     
       
   274     else
       
   275         {
       
   276         HBufC* waitText = StringLoader::LoadLC( 
       
   277                             R_UPNPCOMMONUI_EXTERNAL_WAITING_NOTE );
       
   278         iListBox->View()->SetListEmptyTextL( *waitText );
       
   279         CleanupStack::PopAndDestroy( waitText ); 
       
   280         }
       
   281         
       
   282     CleanupStack::Pop( tempDeviceArray );
       
   283     tempDeviceArray->Reset();
       
   284     delete tempDeviceArray;    
       
   285 
       
   286     }
       
   287 
       
   288 // --------------------------------------------------------------------------
       
   289 // CUPnPSelectionDialog::UPnPDeviceDiscovered
       
   290 // Returns discovered device from UPnP AV control point.
       
   291 // --------------------------------------------------------------------------
       
   292 void CUPnPSelectionDialog::UPnPDeviceDiscovered( 
       
   293                                                const CUpnpAVDevice& aDevice )
       
   294     {
       
   295     __LOG( "CUPnPSelectionDialog::UPnPDeviceDiscovered" );
       
   296 
       
   297     TRAPD( error, UPnPDeviceDiscoveredL( aDevice ) );
       
   298     if( error )
       
   299         {
       
   300         __LOG1( "UPnPDeviceDiscoveredL, leave %d .", error );
       
   301         }
       
   302     }
       
   303 
       
   304 // --------------------------------------------------------------------------
       
   305 // CUPnPSelectionDialog::UPnPDeviceDiscoveredL
       
   306 // Returns discovered device from UPnP AV control point.
       
   307 // --------------------------------------------------------------------------
       
   308 void CUPnPSelectionDialog::UPnPDeviceDiscoveredL( 
       
   309                                                const CUpnpAVDevice& aDevice )
       
   310     {
       
   311     __LOG( "CUPnPSelectionDialog::UPnPDeviceDiscovered" );
       
   312 
       
   313     
       
   314     if ( MatchWithSearchCriteria( const_cast<CUpnpAVDevice*>( &aDevice ) ) )
       
   315         {
       
   316         CUpnpAVDevice* tempDevice = CUpnpAVDevice::NewL( aDevice );
       
   317         CleanupStack::PushL( tempDevice );
       
   318         //ownership transferred                                      
       
   319         iDeviceArray->AppendDeviceL( *tempDevice );
       
   320         CleanupStack::Pop( tempDevice );
       
   321 
       
   322         HBufC8* tmpfriendlyname = 
       
   323             UPnPCommonUtils::ReplaceIllegalFilenameCharactersL( 
       
   324             ( ( CUpnpAVDevice* )tempDevice )->FriendlyName() );
       
   325 
       
   326         CleanupStack::PushL( tmpfriendlyname );
       
   327         TPtrC8 friendlyname = *tmpfriendlyname;
       
   328 
       
   329         CTextListBoxModel* model = iListBox->Model();
       
   330         MDesCArray* textArray = model->ItemTextArray();
       
   331         CDesCArray* listBoxItems = static_cast<CDesCArray*>( textArray );
       
   332         TBuf<KMaxFileName> item;
       
   333         HBufC* tmpStr = 
       
   334                     UpnpString::ToUnicodeL( friendlyname.Left( KLength ) );
       
   335         CleanupStack::PushL( tmpStr );
       
   336         item.Format( _L( "%d\t%S\t\t" ),0, tmpStr ); 
       
   337         CleanupStack::PopAndDestroy( tmpStr );
       
   338         CleanupStack::PopAndDestroy( tmpfriendlyname );
       
   339         listBoxItems->AppendL( item  );
       
   340         iListBox->HandleItemAdditionL(); // Update listbox
       
   341 
       
   342         // Updates CBA.
       
   343         UpdateCommandSetL();
       
   344 
       
   345         iListBox->ActivateL();
       
   346         iListBox->DrawDeferred();
       
   347         }
       
   348     }
       
   349 
       
   350 // --------------------------------------------------------------------------
       
   351 // CUPnPSelectionDialog::UPnPDeviceDisappeared
       
   352 // Returns disappeared device from UPnP AV control point.
       
   353 // --------------------------------------------------------------------------
       
   354 void CUPnPSelectionDialog::UPnPDeviceDisappeared(
       
   355                                             const CUpnpAVDevice& aDevice )
       
   356     {
       
   357     __LOG( "CUPnPSelectionDialog::UPnPDeviceDisappeared" );
       
   358 
       
   359     TRAPD( error, UPnPDeviceDisappearedL( aDevice ) );
       
   360     if ( error )
       
   361         {
       
   362         __LOG1( "UPnPDeviceDisappearedL, leave %d", error );
       
   363         }
       
   364     }
       
   365 
       
   366 // --------------------------------------------------------------------------
       
   367 // CUPnPSelectionDialog::UPnPDeviceDisappearedL
       
   368 // Returns disappeared device from UPnP AV control point.
       
   369 // --------------------------------------------------------------------------
       
   370 void CUPnPSelectionDialog::UPnPDeviceDisappearedL(
       
   371     const CUpnpAVDevice& aDevice )
       
   372     {
       
   373     __LOG( "CUPnPSelectionDialog::UPnPDeviceDisappearedL" );
       
   374 
       
   375     CTextListBoxModel* model = iListBox->Model();
       
   376     TInt currentItem = iListBox->CurrentItemIndex();
       
   377     MDesCArray* textArray = model->ItemTextArray();
       
   378     CDesCArray* listBoxItems = static_cast<CDesCArray*>( textArray );
       
   379     TInt i( 0 );
       
   380     TPtrC8 ptr( aDevice.Uuid() );
       
   381     
       
   382     while( i < iDeviceArray->Count() && 
       
   383            ptr.Compare( ( *iDeviceArray )[i]->Uuid() ) )
       
   384         {
       
   385         i++;
       
   386         }
       
   387     if ( i < iDeviceArray->Count() )
       
   388         {
       
   389         iDeviceArray->RemoveAndDestroy( i );
       
   390         listBoxItems->Delete( i, 1 );
       
   391         AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(
       
   392             iListBox, currentItem, ETrue );
       
   393         iListBox->DrawDeferred();
       
   394         }
       
   395 
       
   396     if ( !iDeviceArray->Count() )
       
   397         {
       
   398         // show "Waiting devices" text
       
   399         HBufC* waitText = StringLoader::LoadLC( 
       
   400                                 R_UPNPCOMMONUI_EXTERNAL_WAITING_NOTE );
       
   401         iListBox->View()->SetListEmptyTextL( *waitText );
       
   402         CleanupStack::PopAndDestroy( waitText ); 
       
   403 
       
   404         // Updates CBA.
       
   405         UpdateCommandSetL();
       
   406         }
       
   407     }
       
   408 
       
   409 // --------------------------------------------------------------------------
       
   410 // CUPnPSelectionDialog::WLANConnectionLost
       
   411 // --------------------------------------------------------------------------
       
   412 void CUPnPSelectionDialog::WLANConnectionLost() 
       
   413     {
       
   414     __LOG( "CUPnPSelectionDialog::WLANConnectionLost" );
       
   415     DismissItself( KErrDisconnected );
       
   416     };
       
   417     
       
   418 // --------------------------------------------------------------------------
       
   419 // CUPnPSelectionDialog::AppendIconToArrayL
       
   420 // Load a possibly skinned icon (with mask) and append it to an
       
   421 // icon array.
       
   422 // --------------------------------------------------------------------------
       
   423 void CUPnPSelectionDialog::AppendIconToArrayL( CAknIconArray* aArray,
       
   424                                                MAknsSkinInstance* aSkin,
       
   425                                                const TDesC& aMbmFile,
       
   426                                                const TAknsItemID& aID,
       
   427                                                TInt aBitmapId,
       
   428                                                TInt aMaskId )
       
   429     {
       
   430     __LOG( "CUPnPSelectionDialog::AppendIconToArrayL" );
       
   431     __ASSERTD( aArray != NULL, __FILE__, __LINE__ );
       
   432 
       
   433     CFbsBitmap* bitmap = NULL;
       
   434     CFbsBitmap* mask = NULL;
       
   435 
       
   436     AknsUtils::CreateIconLC( aSkin, aID,
       
   437         bitmap, mask, aMbmFile, aBitmapId, aMaskId );
       
   438 
       
   439     CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
       
   440     icon->SetBitmapsOwnedExternally( EFalse );
       
   441 
       
   442     // icon now owns the bitmaps, no need to keep on cleanup stack.
       
   443     CleanupStack::Pop( 2 ); // mask, bitmap
       
   444     bitmap = NULL;
       
   445     mask = NULL;
       
   446 
       
   447     CleanupStack::PushL( icon );
       
   448     aArray->AppendL( icon );
       
   449 
       
   450     // aArray now owns the icon, no need to delete.
       
   451     CleanupStack::Pop();
       
   452     }
       
   453 
       
   454 // --------------------------------------------------------------------------
       
   455 // CUPnPSelectionDialog::CreatePopupL
       
   456 // Creates a selection popup.
       
   457 // --------------------------------------------------------------------------
       
   458 void CUPnPSelectionDialog::CreatePopupL( 
       
   459                                 const TDesC& aTitle,
       
   460                                 TUPnPDeviceTypesToSearch aDeviceType )
       
   461     {
       
   462     __LOG( "CUPnPSelectionDialog::CreatePopupL" );
       
   463 
       
   464     // Store the type of devices that are searched
       
   465     iTypeOfDevicesToSearch = aDeviceType;
       
   466 
       
   467     // Create and configure the list box 
       
   468     iListBox = new (ELeave) CAknSingleGraphicPopupMenuStyleListBox;
       
   469     iPopup = CAknPopupList::NewL( iListBox, 
       
   470                                   R_UPNPCOMMONUI_SOFTKEYS_EMPTY_CANCEL,
       
   471                                   AknPopupLayouts::EDynMenuWindow );
       
   472     iListBox->ConstructL( iPopup, EAknListBoxSelectionList );
       
   473     iListBox->CreateScrollBarFrameL( ETrue );
       
   474     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   475         CEikScrollBarFrame::EOff, 
       
   476         CEikScrollBarFrame::EAuto );
       
   477     PreLayoutDynInitL( aTitle );
       
   478     }
       
   479 
       
   480 // --------------------------------------------------------------------------
       
   481 // CUPnPSelectionDialog::StartPopupL
       
   482 // Parses the friendly names from the list of UPnPAVDevices and
       
   483 // executes the selection dialog. Returns ID of the selected item.
       
   484 // --------------------------------------------------------------------------
       
   485 TInt CUPnPSelectionDialog::StartPopupL( CUpnpAVDevice& aDevice )
       
   486     {
       
   487     __LOG( "CUPnPSelectionDialog::StartPopupL" );
       
   488 
       
   489     TInt ret = KErrNone;
       
   490     
       
   491     // Start animation
       
   492     RDebug::Print( _L( "CUPnPSelectionDialog::\
       
   493 StartPopupL header animation" ) );
       
   494     iPopup->Heading()-> SetHeaderAnimationL( 
       
   495                         R_UPNPCOMMONUI_ANIMATION_FOR_SELECTION_DIALOG );
       
   496 
       
   497     TInt popupOk = iPopup->ExecuteLD();
       
   498     iPopup = NULL;
       
   499     if ( popupOk )
       
   500         {
       
   501         if ( iListBox->CurrentItemIndex() >= 0 )
       
   502             {
       
   503             CUpnpAVDevice* device =
       
   504                         ( *iDeviceArray )[iListBox->CurrentItemIndex()];
       
   505             aDevice.CopyFromL( *device );
       
   506             ret = KErrNone;
       
   507             }
       
   508         }
       
   509     else
       
   510         {
       
   511         if( KErrNone == iExitReason )
       
   512             {
       
   513             ret = KErrCancel;    
       
   514             }
       
   515         else
       
   516             {
       
   517             ret = iExitReason;
       
   518             }
       
   519         
       
   520         }
       
   521     return ret;    
       
   522     }
       
   523 
       
   524 
       
   525 // --------------------------------------------------------------------------
       
   526 // CUPnPSelectionDialog::DismissItself
       
   527 // Dismiss the selection dialog via an error code.
       
   528 // --------------------------------------------------------------------------
       
   529 void CUPnPSelectionDialog::DismissItself( TInt aError )
       
   530     {
       
   531     iExitReason = aError;
       
   532     if( iPopup )
       
   533         {
       
   534         iPopup->CancelPopup();
       
   535         }
       
   536     }
       
   537 
       
   538 // --------------------------------------------------------------------------
       
   539 // CUPnPSelectionDialog::MatchWithSearchCriteria
       
   540 // Checks if a given device matches with the search criteria.
       
   541 // --------------------------------------------------------------------------
       
   542 TBool CUPnPSelectionDialog::MatchWithSearchCriteria( CUpnpAVDevice *aDevice )
       
   543     {
       
   544     TBool returnValue = EFalse;
       
   545     if( aDevice )
       
   546         {
       
   547         // If all device types are accepted
       
   548         if( iTypeOfDevicesToSearch == EUPnPSearchAllDevices )
       
   549             {
       
   550             returnValue = ETrue;
       
   551             }
       
   552         // If all media server devices are accepted
       
   553         else if( iTypeOfDevicesToSearch == EUPnPSearchAllServerDevices &&
       
   554                  aDevice->DeviceType() == CUpnpAVDevice::EMediaServer )
       
   555             {
       
   556             returnValue = ETrue;
       
   557             }
       
   558         // If all rendering devices are accepted
       
   559         else if( iTypeOfDevicesToSearch == EUPnPSearchAllRenderingDevices &&
       
   560                  aDevice->DeviceType() == CUpnpAVDevice::EMediaRenderer )
       
   561             {
       
   562             returnValue = ETrue;
       
   563             }
       
   564         // If media server devices with copy capability are accepted
       
   565         else if( iTypeOfDevicesToSearch ==
       
   566                  EUPnPSearchServerDevicesWithCopyCapability &&
       
   567                  aDevice->DeviceType() == CUpnpAVDevice::EMediaServer &&
       
   568                  aDevice->CopyCapability() )
       
   569             {
       
   570             returnValue = ETrue;
       
   571             }
       
   572         // If media server devices with search capability are accepted
       
   573         else if( iTypeOfDevicesToSearch ==
       
   574                  EUPnPSearchServerDevicesWithSearchCapability &&
       
   575                  aDevice->DeviceType() == CUpnpAVDevice::EMediaServer &&
       
   576                  aDevice->SearchCapability() )
       
   577             {
       
   578             returnValue = ETrue;
       
   579             }
       
   580         // If rendering devices with image capability are accepted
       
   581         else if( iTypeOfDevicesToSearch ==
       
   582                  EUPnPSearchRenderingDevicesWithImageCapability &&
       
   583                  aDevice->DeviceType() == CUpnpAVDevice::EMediaRenderer &&
       
   584                  aDevice->ImageCapability() )
       
   585             {
       
   586             returnValue = ETrue;
       
   587             }
       
   588         // If rendering devices with video capability are accepted
       
   589         else if( iTypeOfDevicesToSearch ==
       
   590                  EUPnPSearchRenderingDevicesWithVideoCapability &&
       
   591                  aDevice->DeviceType() == CUpnpAVDevice::EMediaRenderer &&
       
   592                  aDevice->VideoCapability() )
       
   593             {
       
   594             returnValue = ETrue;
       
   595             }
       
   596         // If rendering devices with audio capability are accepted
       
   597         else if( iTypeOfDevicesToSearch ==
       
   598                  EUPnPSearchRenderingDevicesWithAudioCapability &&
       
   599                  aDevice->DeviceType() == CUpnpAVDevice::EMediaRenderer &&
       
   600                  aDevice->AudioCapability() )
       
   601             {
       
   602             returnValue = ETrue;
       
   603             }
       
   604         else
       
   605             {
       
   606             returnValue = EFalse;
       
   607             }
       
   608         }
       
   609     return returnValue;
       
   610     }
       
   611 
       
   612 // --------------------------------------------------------------------------
       
   613 // CUPnPSelectionDialog::UpdateCommandSetL
       
   614 // Updates command set of the dialog by the search type of the devices.
       
   615 // --------------------------------------------------------------------------
       
   616 void CUPnPSelectionDialog::UpdateCommandSetL()
       
   617     {
       
   618     // Default values, used when no items in the list.
       
   619     TInt resId = R_UPNPCOMMONUI_SOFTKEYS_EMPTY_CANCEL;
       
   620     if ( iDeviceArray->Count() )
       
   621         {
       
   622         // Updates the commands set by iTypeOfDevicesToSearch variable.
       
   623         switch( iTypeOfDevicesToSearch )
       
   624             {
       
   625             case EUPnPSearchServerDevicesWithCopyCapability:
       
   626                 // When copying or moving we should use "Ok" lsk 
       
   627                 // instead of "Select".
       
   628                 resId = R_AVKON_SOFTKEYS_OK_CANCEL;
       
   629                 break;
       
   630             default:
       
   631                 resId = R_AVKON_SOFTKEYS_SELECT_CANCEL;
       
   632                 break;
       
   633             }
       
   634         }
       
   635     
       
   636     CEikButtonGroupContainer* bgc = iPopup->ButtonGroupContainer();    
       
   637     bgc->SetCommandSetL( resId );
       
   638     bgc->DrawDeferred();
       
   639     }
       
   640 
       
   641 // End of file