homesync/contentmanager/homesyncgsplugin/src/mssettingitemdevices.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2009 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:  CMSSettingItemDevices class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <msgspluginsrc.rsg>
       
    20 #include <StringLoader.h>
       
    21 #include "upnpavdevice.h"
       
    22 #include "upnpavcontroller.h" // for MUPnPAVController
       
    23 #include "upnpavcontrollerfactory.h" // for UPnPAVControllerFactory
       
    24 #include <AknWaitDialog.h>
       
    25 #include <utf.h> // for CnvUtfConverter
       
    26 
       
    27 #include "cmmediaserverfull.h"
       
    28 #include "cmcommonutils.h"
       
    29 #include <aknnotewrappers.h>
       
    30 #include "mssettingitemdevices.h"
       
    31 #include "msmultiselectionpopup.h"
       
    32 #include "msengine.h"
       
    33 #include "upnpavdevicelist.h"
       
    34 #include "msdebug.h"
       
    35 
       
    36 // CONSTANTS
       
    37 
       
    38 // reserved list size
       
    39 const TInt KItemArrayGranularity = 3;
       
    40 
       
    41 // ================= MEMBER FUNCTIONS =======================
       
    42 
       
    43 // --------------------------------------------------------------------------
       
    44 // CMSSettingItemDevices::NewL
       
    45 // --------------------------------------------------------------------------
       
    46 //
       
    47 CMSSettingItemDevices* CMSSettingItemDevices::NewL(
       
    48                         TInt aIdentifier,
       
    49                         TDes& aText,
       
    50                         CMSEngine& aMSEngine,
       
    51                         RPointerArray<CCmMediaServerFull>& aStoredServers,
       
    52                         TBool aUploadCapabilitySupport )
       
    53     {
       
    54     LOG(_L("[MSGSPlugin]\t CMSSettingItemDevices::NewL"));
       
    55 
       
    56     CMSSettingItemDevices* self = CMSSettingItemDevices::NewLC(
       
    57                                           aIdentifier,
       
    58                                           aText,
       
    59                                           aMSEngine,
       
    60                                           aStoredServers,
       
    61                                           aUploadCapabilitySupport );
       
    62 
       
    63     CleanupStack::Pop( self );
       
    64     return self;
       
    65     }
       
    66 
       
    67 // --------------------------------------------------------------------------
       
    68 // CMSSettingItemDevices::NewLC
       
    69 // --------------------------------------------------------------------------
       
    70 //
       
    71 CMSSettingItemDevices* CMSSettingItemDevices::NewLC(
       
    72                         TInt aIdentifier,
       
    73                         TDes& aText,
       
    74                         CMSEngine& aMSEngine,
       
    75                         RPointerArray<CCmMediaServerFull>& aStoredServers,
       
    76                         TBool aUploadCapabilitySupport )
       
    77     {
       
    78     LOG(_L("[MSGSPlugin]\t CMSSettingItemDevices::NewLC"));
       
    79 	
       
    80     CMSSettingItemDevices* self = new ( ELeave ) CMSSettingItemDevices(
       
    81                                           aIdentifier,
       
    82                                           aText,
       
    83                                           aMSEngine,
       
    84                                           aStoredServers,
       
    85                                           aUploadCapabilitySupport );
       
    86 
       
    87     CleanupStack::PushL( self );
       
    88     self->ConstructL();
       
    89     return self;
       
    90     }
       
    91 	
       
    92 // --------------------------------------------------------------------------
       
    93 // CMSSettingItemDevices::ConstructL
       
    94 // --------------------------------------------------------------------------
       
    95 //
       
    96 void CMSSettingItemDevices::ConstructL()
       
    97     {
       
    98     LOG(_L("[MSGSPlugin]\t CMSSettingItemDevices::ConstructL begins"));
       
    99 
       
   100     iSettingText = HBufC::NewL( KMaxFileName );
       
   101 
       
   102     iSelectedServers =
       
   103         new (ELeave) CArrayFixFlat<TInt>( KItemArrayGranularity );
       
   104     
       
   105     SetSettingItemTextL();
       
   106 
       
   107     LOG(_L("[MSGSPlugin]\t CMSSettingItemDevices::ConstructL ends"));
       
   108     }
       
   109 
       
   110 // --------------------------------------------------------------------------
       
   111 // CMSSettingItemDevices::~~CMSSettingItemDevices()
       
   112 // --------------------------------------------------------------------------
       
   113 //
       
   114 CMSSettingItemDevices::~CMSSettingItemDevices()
       
   115     {
       
   116     LOG(_L("[MSGSPlugin]\t CMSSettingItemDevices::~CMSSettingItemDevices"));
       
   117 
       
   118     delete iSettingText;
       
   119 
       
   120     delete iSelectedServers;
       
   121 
       
   122     iServerList.Reset();
       
   123     iServerList.Close();
       
   124     
       
   125     if ( iAvController )
       
   126         {
       
   127         iAvController->RemoveDeviceObserver();
       
   128 		iAvController->Release();
       
   129 		iAvController = NULL;
       
   130         }
       
   131 
       
   132     if ( iWaitDialog )
       
   133         {
       
   134         TRAP_IGNORE( iWaitDialog->ProcessFinishedL() );
       
   135         iWaitDialog = NULL;
       
   136         }
       
   137 
       
   138     if ( iWait.IsStarted() )
       
   139         {
       
   140         iWait.AsyncStop();
       
   141         }
       
   142 
       
   143     }
       
   144 
       
   145 // --------------------------------------------------------------------------
       
   146 // CMSSettingItemDevices::EditItemL( TBool aCalledFromMenu )
       
   147 // --------------------------------------------------------------------------
       
   148 //
       
   149 void CMSSettingItemDevices::EditItemL( TBool /*aCalledFromMenu*/ )
       
   150     {
       
   151     LOG( _L("[MSGSPlugin]\t CMSSettingItemDevices::EditItemL") );
       
   152 
       
   153     // restore original state
       
   154     SetAcceptState( EFalse );
       
   155 
       
   156     // Create list for selection
       
   157     ReadServerListL();
       
   158 
       
   159     // Create Avcontroller and fetch already discovered devices from it.
       
   160     CreateAvcAndFetchDevicesL();           
       
   161             
       
   162     if( !iUserCancelledSearch )
       
   163         {
       
   164         if ( iUploadCapabilitySupport )
       
   165             {
       
   166             iDevSelectionDlg = CMSMultiselectionPopup::NewL(
       
   167                                     iUploadCapabilitySupport,
       
   168                                     &iServerList,
       
   169                                     iSelectedServers );
       
   170             iDevSelectionDlg->PrepareLC(
       
   171                             R_MS_TARGET_DEVICE_SELECTION_DIALOG );
       
   172             }
       
   173         else
       
   174             {
       
   175             iDevSelectionDlg = CMSMultiselectionPopup::NewL(
       
   176                                     iUploadCapabilitySupport,
       
   177                                     &iServerList,
       
   178                                     iSelectedServers );           
       
   179             iDevSelectionDlg->PrepareLC(
       
   180                             R_MS_SOURCE_DEVICE_SELECTION_DIALOG );
       
   181             }            
       
   182 
       
   183         #ifndef __WINS__
       
   184             iDevSelectionDlg->QueryHeading()->SetHeaderAnimationL(
       
   185                 R_MSGS_ANIMATION_FOR_SELECTION_DIALOG );
       
   186         #endif
       
   187 
       
   188         TInt returnValue = iDevSelectionDlg->RunLD();            
       
   189 
       
   190         iDevSelectionDlg = NULL;
       
   191         
       
   192         CancelDeviceSearch();
       
   193 
       
   194         if( returnValue )
       
   195             {
       
   196             // User presses OK
       
   197             SetAcceptState( ETrue );
       
   198 
       
   199             SetServersActivity();
       
   200             SetSettingItemTextL();
       
   201 
       
   202             iMSEngine.SetMediaServersL( iStoredServers );
       
   203 
       
   204             LoadL();
       
   205             UpdateListBoxTextL();
       
   206             }
       
   207         }
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // CMSSettingItemDevices::SetServersActivity
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 void CMSSettingItemDevices::SetServersActivity()
       
   215     {
       
   216     LOG(_L("[MSGSPlugin]\t CMSSettingItemDevices::SetServersActivity \
       
   217     begins"));
       
   218 
       
   219     // Set all servers inactive
       
   220     for( TInt ind=0; ind < iStoredServers.Count(); ind++ )
       
   221         {
       
   222         CCmMediaServerFull* server = iStoredServers[ind];
       
   223 
       
   224         if ( iUploadCapabilitySupport )
       
   225             {
       
   226             server->SetStoreUsage( EFalse );
       
   227             }
       
   228         else
       
   229             {            
       
   230             server->SetFillUsage( EFalse );
       
   231             }
       
   232             
       
   233         if ( !server->StoreUsage() && !server->FillUsage() )
       
   234             {
       
   235             server->SetIsActive( EFalse );	
       
   236             }
       
   237         }
       
   238 
       
   239     // Set selected servers active
       
   240     if( iSelectedServers )
       
   241         {
       
   242         // loop trough selected servers
       
   243         for ( TInt iy = 0; iy < iSelectedServers->Count(); iy++ )
       
   244             {
       
   245 
       
   246             // Look for the server in selection array
       
   247             TInt selectedIndex = iSelectedServers->At( iy );
       
   248             // server points to iStoredServers table
       
   249             CCmMediaServerFull* server = iServerList[selectedIndex];
       
   250            
       
   251             if ( iUploadCapabilitySupport )
       
   252                 {
       
   253                 server->SetStoreUsage( ETrue );
       
   254                 }
       
   255             else // fill server
       
   256                 {
       
   257                 server->SetFillUsage( ETrue );
       
   258                 }
       
   259             server->SetIsActive( ETrue );
       
   260             }
       
   261         }
       
   262 
       
   263     LOG(_L("[MSGSPlugin]\t CMSSettingItemDevices::SetServersActivity \
       
   264     ends"));
       
   265     }
       
   266 
       
   267 // --------------------------------------------------------------------------
       
   268 // CMSSettingItemDevices::CMSSettingItemDevices
       
   269 // --------------------------------------------------------------------------
       
   270 //
       
   271 CMSSettingItemDevices::CMSSettingItemDevices( TInt aIdentifier, TDes& aText,
       
   272     CMSEngine& aMSEngine,
       
   273     RPointerArray<CCmMediaServerFull>& aStoredServers,
       
   274     TBool aUploadCapabilitySupport  ):
       
   275     CMSTextSettingItem( aIdentifier, aText ),
       
   276     iMSEngine( aMSEngine ),
       
   277     iStoredServers( aStoredServers ),
       
   278     iUploadCapabilitySupport( aUploadCapabilitySupport )
       
   279     {
       
   280     LOG( _L("[MSGSPlugin]\t CMSSettingItemDevices::CMSSettingItemDevices") );
       
   281     }
       
   282 
       
   283 // --------------------------------------------------------------------------
       
   284 // CMSSettingItemDevices::ReadServerListL
       
   285 //
       
   286 // --------------------------------------------------------------------------
       
   287 //
       
   288 void CMSSettingItemDevices::ReadServerListL()
       
   289     {
       
   290     LOG(_L("[MSGSPlugin]\t CMSSettingItemDevices::ReadServerListL"));
       
   291 
       
   292     // delete old ones
       
   293     iServerList.Reset();
       
   294 
       
   295     for ( TInt i = 0; i < iStoredServers.Count(); i++ )
       
   296         {
       
   297         // Add selected/marked servers to list
       
   298         if (iUploadCapabilitySupport && iStoredServers[i]->CopyCapability()
       
   299                 && iStoredServers[i]->StoreUsage() )
       
   300             {
       
   301             // Add selected target servers
       
   302             iServerList.AppendL(iStoredServers[i]);
       
   303             }
       
   304         else if (!iUploadCapabilitySupport && iStoredServers[i]->FillUsage() )
       
   305             {
       
   306             // Add selected source servers
       
   307             iServerList.AppendL(iStoredServers[i]);
       
   308             }
       
   309         else
       
   310             {
       
   311             LOG(_L("[MSGSPlugin]\t CMSSettingItemDevices::ReadServerListL \
       
   312             Not selected servers should not show to user"));
       
   313             }
       
   314         }
       
   315     }
       
   316 
       
   317 // --------------------------------------------------------------------------
       
   318 // CMSSettingItemDevices::SetSettingItemTextL
       
   319 // Sets setting item secondary text according to selected items
       
   320 // --------------------------------------------------------------------------
       
   321 //
       
   322 void CMSSettingItemDevices::SetSettingItemTextL()
       
   323     {
       
   324     LOG( _L("[MSGSPlugin]\t CMSSettingItemDevices::SetSettingItemTextL") );
       
   325     
       
   326     // count how many active devices threre are
       
   327     TInt count = CountSelectedItems();
       
   328     HBufC* itemText = NULL;
       
   329 
       
   330     if ( count == 1 )
       
   331         {
       
   332         // one active found - need to get server name
       
   333         for ( TInt index = 0; index < iStoredServers.Count(); index++ )
       
   334             {
       
   335             CCmMediaServerFull* server = iStoredServers[index];
       
   336 
       
   337             if ( ( iUploadCapabilitySupport && server->StoreUsage() ) ||
       
   338                  ( !iUploadCapabilitySupport && server->FillUsage() ) )
       
   339                 {
       
   340                 itemText = CnvUtfConverter::ConvertToUnicodeFromUtf8L(                                                
       
   341                                                 server->MediaServerName() );
       
   342                 CleanupStack::PushL(itemText);
       
   343 
       
   344                 iSettingText->Des().Copy( itemText->Left( KMaxFileName) );
       
   345 
       
   346                 CleanupStack::PopAndDestroy( itemText );
       
   347                 index = iStoredServers.Count(); // break loop                
       
   348                 }
       
   349             else
       
   350                 {
       
   351                 LOG(_L("[MSGSPlugin]\t CMSSettingItemDevices::\
       
   352                 SetSettingItemTextL copycapability required but not \
       
   353                 supported by server"));
       
   354                 }
       
   355             }
       
   356         }
       
   357     // more than one item selected
       
   358     else
       
   359         {
       
   360         if ( count > 1 )
       
   361             {
       
   362             itemText = StringLoader::LoadLC( R_MS_ITEM_DEVICES, count );
       
   363             }
       
   364         else
       
   365             {
       
   366             itemText = StringLoader::LoadLC( R_MS_NO_SERVER_SELECTED );
       
   367             }
       
   368 
       
   369         // do number conversion
       
   370         TPtr ptr = itemText->Des();
       
   371         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr );
       
   372 
       
   373         iSettingText->Des().Copy( *itemText );
       
   374         CleanupStack::PopAndDestroy( itemText );
       
   375         }
       
   376 
       
   377      // Set new value
       
   378      SetExternalText( *iSettingText );
       
   379     }
       
   380 
       
   381 // --------------------------------------------------------------------------
       
   382 // CMSSettingItemDevices::CountSelectedItems
       
   383 // Counts selected items
       
   384 // --------------------------------------------------------------------------
       
   385 //
       
   386 TInt CMSSettingItemDevices::CountSelectedItems() const
       
   387     {
       
   388     LOG(_L("[MSGSPlugin]\t CMSSettingItemDevices::CountSelectedItems"));
       
   389 
       
   390     TInt count(0);
       
   391 
       
   392     if( iStoredServers.Count() )
       
   393         {
       
   394         TRACE(Print(_L("[MSGSPlugin]\t server COUNT:  = %d"),
       
   395             iStoredServers.Count() ));
       
   396         for ( TInt index = 0; index < iStoredServers.Count(); index++ )
       
   397             {
       
   398 
       
   399             CCmMediaServerFull* server = iStoredServers[index];
       
   400 
       
   401             if ( iUploadCapabilitySupport && server->StoreUsage() )
       
   402                 {
       
   403                 count++;
       
   404                 }
       
   405             else if ( !iUploadCapabilitySupport && server->FillUsage() )
       
   406                 {
       
   407                 count++;
       
   408                 }
       
   409             else
       
   410                 {
       
   411                 LOG(_L("[MSGSPlugin]\t CMSSettingItemDevices::\
       
   412                 CountSelectedItems server not used"));
       
   413                 }
       
   414             }
       
   415         }
       
   416     TRACE(Print(_L("[MSGSPlugin]\t active server COUNT:  = %d"),
       
   417     count ));
       
   418     return count;
       
   419     }
       
   420 
       
   421 // ---------------------------------------------------------------------------
       
   422 // CMSSettingItemDevices::DialogDismissedL
       
   423 // ---------------------------------------------------------------------------
       
   424 //
       
   425 void CMSSettingItemDevices::DialogDismissedL( TInt aButtonId )
       
   426     {
       
   427     LOG(_L("[MSGSPlugin]\t CMSSettingItemDevices::DialogDismissedL"));
       
   428 
       
   429     if( aButtonId != EAknSoftkeyDone )
       
   430         {
       
   431         LOG(_L("[MSGSPlugin]\t CMSSettingItemDevices::\
       
   432         DialogDismissedL CANCEL"));
       
   433         iUserCancelledSearch = ETrue;
       
   434         // cancel server search if it was started
       
   435         CancelDeviceSearch();
       
   436         }
       
   437 
       
   438     if ( iWait.IsStarted() )
       
   439         {
       
   440         iWait.AsyncStop();
       
   441         }
       
   442     }
       
   443 
       
   444 // ---------------------------------------------------------------------------
       
   445 // CMSSettingItemDevices::UPnPDeviceDiscoveredL
       
   446 // Returns discovered device from UPnP AV control point.
       
   447 // ---------------------------------------------------------------------------
       
   448 //
       
   449 void CMSSettingItemDevices::UPnPDeviceDiscoveredL(
       
   450                                     const CUpnpAVDevice& aDevice)
       
   451     {
       
   452     LOG(_L("[MSGSPlugin]\t CMSSettingItemDevices::UPnPDeviceDiscoveredL"));
       
   453 
       
   454     // Check that this is mediaserver
       
   455     if ( aDevice.DeviceType() == CUpnpAVDevice::EMediaServer &&
       
   456          aDevice.SearchCapability() && aDevice.DlnaCompatible() )
       
   457         {
       
   458         LOG(_L("[MSGSPlugin]\t Found device is Media server!"));
       
   459 
       
   460 #ifdef __DEBUG
       
   461         HBufC* devName = UpnpString::ToUnicodeL( aDevice.FriendlyName() );
       
   462         TRACE(Print(_L("[MSGSPlugin]\t device Name= %S"), devName ));
       
   463         delete devName;
       
   464 #endif
       
   465         TPtrC8 deviceUDN = aDevice.Uuid();
       
   466 
       
   467         TInt serverCount = iStoredServers.Count();
       
   468         TBool newServer( ETrue );
       
   469         CCmMediaServerFull* tempServer = NULL;
       
   470 
       
   471         // Check if server is already on the list
       
   472         for ( TInt i=0; i < serverCount; i++ )
       
   473             {
       
   474             // Compare server udn
       
   475             if ( deviceUDN.Compare(
       
   476                     iStoredServers[i]->MediaServer() ) == 0 )
       
   477                 {
       
   478                 tempServer = iStoredServers[i];
       
   479                 // server already on the list
       
   480                 i = serverCount; // end loop
       
   481                 newServer = EFalse;
       
   482                 }
       
   483             }
       
   484 
       
   485         if ( newServer )
       
   486             {
       
   487             tempServer = CCmMediaServerFull::NewL();
       
   488             CleanupStack::PushL( tempServer );
       
   489             tempServer->SetUDNL( aDevice.Uuid() );
       
   490             tempServer->SetMediaServerNameL( aDevice.FriendlyName() );
       
   491             tempServer->SetCopyCapability( aDevice.CopyCapability() );
       
   492             
       
   493             // Add the server to found list            
       
   494             iStoredServers.Append( tempServer );
       
   495             
       
   496             CleanupStack::Pop( tempServer );
       
   497             }
       
   498         // Add unselected servers to show to user
       
   499         if ( ( iUploadCapabilitySupport && tempServer->CopyCapability()
       
   500               && !tempServer->StoreUsage() )
       
   501              || ( !iUploadCapabilitySupport && !tempServer->FillUsage() ) )
       
   502             {
       
   503             iServerList.AppendL( tempServer );
       
   504             if ( iWaitDialog )
       
   505                 {
       
   506                 TRAP_IGNORE( iWaitDialog->ProcessFinishedL() );
       
   507                 iWaitDialog = NULL;
       
   508                 }
       
   509 
       
   510             // If devices are searched for the first time
       
   511             // the dialog needs to be created in EditItemL.
       
   512             // This call is for updating existing dialog.
       
   513             if ( iDevSelectionDlg )
       
   514                 {
       
   515                 iDevSelectionDlg->UpdateAndDrawPopupL( tempServer );
       
   516                 }
       
   517             }
       
   518         }
       
   519     }
       
   520 
       
   521 // ---------------------------------------------------------------------------
       
   522 // CMSSettingItemDevices::UPnPDeviceDiscovered
       
   523 // Returns discovered device from UPnP AV control point
       
   524 // ---------------------------------------------------------------------------
       
   525 //
       
   526 void CMSSettingItemDevices::UPnPDeviceDiscovered(
       
   527                                     const CUpnpAVDevice& aDevice )
       
   528     {
       
   529     LOG(_L("[MSGSPlugin]\t CMSSettingItemDevices::\
       
   530              UPnPDeviceDiscovered"));
       
   531 
       
   532     TRAP_IGNORE( UPnPDeviceDiscoveredL( aDevice ) );       
       
   533     }
       
   534 
       
   535 // ---------------------------------------------------------------------------
       
   536 // CMSSettingItemDevices::UPnPDeviceDisappeared
       
   537 // Returns disappeared device from UPnP AV control point.
       
   538 // ---------------------------------------------------------------------------
       
   539 //
       
   540 void CMSSettingItemDevices::UPnPDeviceDisappeared(
       
   541                                     const CUpnpAVDevice& /*aDevice*/ )
       
   542     {
       
   543     LOG(_L("[MSGSPlugin]\t CMSSettingItemDevices::\
       
   544              UPnPDeviceDisappeared"));
       
   545     // do nothing
       
   546     }
       
   547 
       
   548 // ---------------------------------------------------------------------------
       
   549 // CMSSettingItemDevices::WLANConnectionLost
       
   550 // Notifies wlan connection lost
       
   551 // ---------------------------------------------------------------------------
       
   552 //
       
   553 void CMSSettingItemDevices::WLANConnectionLost()
       
   554     {
       
   555     LOG(_L("[MSGSPlugin]\t CMSSettingItemDevices::WLANConnectionLost"));
       
   556     
       
   557     TRAP_IGNORE( DialogDismissedL( EAknSoftkeyCancel ) );
       
   558     if ( iWaitDialog )
       
   559         {
       
   560         TRAP_IGNORE( iWaitDialog->ProcessFinishedL() );
       
   561         iWaitDialog = NULL;
       
   562         }
       
   563     }
       
   564 
       
   565 // --------------------------------------------------------------------------
       
   566 // CMSSettingItemDevices::CreateAvcontrollerL
       
   567 //
       
   568 // --------------------------------------------------------------------------
       
   569 //
       
   570 TInt CMSSettingItemDevices::CreateAvcontrollerL()
       
   571     {
       
   572     LOG( _L("[MSGSPlugin]\t CMSSettingItemDevices::CreateAvcontrollerL" ) );
       
   573 
       
   574     if( iAvController )
       
   575         {
       
   576         iAvController->Release();
       
   577         iAvController = NULL;
       
   578         }
       
   579 
       
   580     iAvController = UPnPAVControllerFactory::NewUPnPAVControllerL();
       
   581 
       
   582     if( iAvController )
       
   583         {
       
   584         iAvController->SetDeviceObserver( *this );
       
   585         }
       
   586 
       
   587     return KErrNone;
       
   588     }
       
   589 
       
   590 // --------------------------------------------------------------------------
       
   591 // CMSSettingItemDevices::CancelDeviceSearch
       
   592 //
       
   593 // --------------------------------------------------------------------------
       
   594 //
       
   595 void CMSSettingItemDevices::CancelDeviceSearch()
       
   596     {
       
   597     LOG( _L( "[MSGSPlugin]\t CMSSettingItemDevices::CancelDeviceSearch" ) );
       
   598 
       
   599     if ( iAvController )
       
   600         {
       
   601         iAvController->RemoveDeviceObserver();
       
   602 		iAvController->Release();
       
   603 		iAvController = NULL;
       
   604         }
       
   605     }
       
   606     
       
   607 // ---------------------------------------------------------------------------
       
   608 // CMSSettingItemDevices::FetchAlreadyDiscoveredDevicesL
       
   609 // Fetches devices from AVController and calls
       
   610 // DeviceDiscovered-callback for each of them.
       
   611 // ---------------------------------------------------------------------------
       
   612 //
       
   613 void CMSSettingItemDevices::FetchAlreadyDiscoveredDevicesL()
       
   614     {
       
   615     LOG( _L("[MSGSPlugin]\t CMSSettingItemDevices::\
       
   616     FetchAlreadyDiscoveredDevicesL") );
       
   617     
       
   618     // If iAvController is not created, this method is unusable. 
       
   619     // Call CreateAvControllerL first.
       
   620     User::LeaveIfNull( iAvController );
       
   621     
       
   622     // Fetch already found devices from AVController.
       
   623     CUpnpAVDeviceList* discoveredDevices = 
       
   624         iAvController->GetMediaServersL();
       
   625     CleanupStack::PushL( discoveredDevices );
       
   626         
       
   627     if ( discoveredDevices && discoveredDevices->Count() > 0 ) 
       
   628         {
       
   629         // the AVController already has some devices.
       
   630         LOG(_L("[MSGSPlugin]\t \
       
   631                 CMSSettingItemDevices::FetchAlreadyDiscoveredDevicesL: \
       
   632                 AVController has already discovered devices" ) );
       
   633 
       
   634         // process the already existing devices
       
   635         for ( TInt i = 0 ; i < discoveredDevices->Count() ; i++ ) 
       
   636             {
       
   637             UPnPDeviceDiscovered( 
       
   638                 *( discoveredDevices->operator[](i) ) );
       
   639             }
       
   640         }
       
   641 
       
   642     // clean up        
       
   643     CleanupStack::PopAndDestroy( discoveredDevices );
       
   644     discoveredDevices = NULL;
       
   645     }
       
   646     
       
   647 // ---------------------------------------------------------------------------
       
   648 // CMSSettingItemDevices::CreateAvcAndFetchDevicesL
       
   649 // Creates AVController, fetches devices from it and calls
       
   650 // DeviceDiscovered-callback for each of them. Starts wait note if no devices 
       
   651 // are already discovered.
       
   652 // ---------------------------------------------------------------------------
       
   653 //
       
   654 TInt CMSSettingItemDevices::CreateAvcAndFetchDevicesL()
       
   655     {
       
   656     LOG( _L(
       
   657         "[MSGSPlugin]\t CMSSettingItemDevices::CreateAvcAndFetchDevicesL" )
       
   658        );
       
   659     
       
   660     iUserCancelledSearch = EFalse;
       
   661 
       
   662     if( iSelectedServers )
       
   663         {
       
   664         iSelectedServers->Reset();
       
   665         delete iSelectedServers;
       
   666         iSelectedServers = NULL;
       
   667         }
       
   668     iSelectedServers =
       
   669             new (ELeave) CArrayFixFlat<TInt>( KItemArrayGranularity );
       
   670 
       
   671     iCreateAvCState = EPhaseNotActive;
       
   672     CAknWaitNoteWrapper* waitNoteWrapper = CAknWaitNoteWrapper::NewL();
       
   673     CleanupStack::PushL( reinterpret_cast<CBase*>( waitNoteWrapper ) );
       
   674     TRAPD( err, waitNoteWrapper->ExecuteL(
       
   675               R_MS_WAIT_FOR_CREATEAVC_DIALOG,
       
   676               *this,
       
   677               ETrue ) );//ETrue = show immediately
       
   678     CleanupStack::PopAndDestroy( waitNoteWrapper );
       
   679 
       
   680 
       
   681     if ( iAvController )
       
   682         {
       
   683         // Process devices that AVController has already discovered.
       
   684         FetchAlreadyDiscoveredDevicesL();
       
   685 
       
   686         // If still no devices discovered, start wait note.
       
   687         if ( iServerList.Count() == 0 )
       
   688             {
       
   689             iWaitDialog = new ( ELeave ) CAknWaitDialog(
       
   690             ( REINTERPRET_CAST( CEikDialog**, &iWaitDialog ) ) );
       
   691             iWaitDialog->SetCallback( this );
       
   692             iWaitDialog->ExecuteLD( R_MS_WAIT_DIALOG );
       
   693             LOG( _L( "[MSGSPlugin]\t CMSSettingItemDevices::\
       
   694             CreateAvcAndFetchDevicesL starting wait" ) );
       
   695             iWait.Start(); // wait here until first server is found.
       
   696             }
       
   697         }
       
   698     else
       
   699         {
       
   700         //handle the error
       
   701         if( KErrDiskFull == err )
       
   702             {
       
   703             ShowErrorNoteL( R_MS_GS_MEMORY_FULL );
       
   704             }
       
   705         iUserCancelledSearch = ETrue; // Don't show selection dialog.
       
   706         }
       
   707 
       
   708     return err;
       
   709     }
       
   710 
       
   711 // ---------------------------------------------------------------------------
       
   712 // CMSSettingItemDevices::ShowErrorNoteL
       
   713 // ---------------------------------------------------------------------------
       
   714 //
       
   715 void CMSSettingItemDevices::ShowErrorNoteL( TInt aTextResource )
       
   716     {
       
   717     LOG( _L( "[MSGSPlugin]\t CMSSettingItemDevices::ShowErrorNoteL" ) );
       
   718     HBufC* warningText =
       
   719                       StringLoader::LoadLC( aTextResource );
       
   720     CAknErrorNote* dlg = new ( ELeave ) CAknErrorNote( );
       
   721     dlg->ExecuteLD( *warningText );
       
   722     CleanupStack::PopAndDestroy( warningText );
       
   723     }
       
   724 
       
   725 // ---------------------------------------------------------------------------
       
   726 // CMSSettingItemDevices::StepL
       
   727 // ---------------------------------------------------------------------------
       
   728 //
       
   729 void CMSSettingItemDevices::StepL()
       
   730     {
       
   731     LOG( _L( "[MSGSPlugin]\t CMSSettingItemDevices::StepL" ) );
       
   732     if( EPhaseNotActive == iCreateAvCState )
       
   733         {
       
   734         CreateAvcontrollerL();
       
   735         iCreateAvCState = EPhaseCompleted;
       
   736         }
       
   737     }
       
   738 
       
   739 // ---------------------------------------------------------------------------
       
   740 // CMSSettingItemDevices::IsProcessDone
       
   741 // ---------------------------------------------------------------------------
       
   742 //
       
   743 TBool CMSSettingItemDevices::IsProcessDone() const
       
   744     {
       
   745     LOG( _L( "[MSGSPlugin]\t CMSSettingItemDevices::IsProcessDone" ) );
       
   746     TBool ret( EFalse );
       
   747     if ( EPhaseNotActive == iCreateAvCState )
       
   748         {
       
   749         // try to start avcontroller
       
   750         }
       
   751     else if ( EPhaseCompleted  == iCreateAvCState )
       
   752         {
       
   753         ret = ETrue;
       
   754         }
       
   755     else
       
   756         {
       
   757         LOG( _L( "[MSGSPlugin]\t CMSSettingItemDevices::IsProcessDone \
       
   758         other branch" ) );
       
   759         }
       
   760     return ret;
       
   761     }
       
   762 
       
   763 // ---------------------------------------------------------------------------
       
   764 // CMSSettingItemDevices::CycleError
       
   765 // handles the error
       
   766 // ---------------------------------------------------------------------------
       
   767 //
       
   768 TInt CMSSettingItemDevices::CycleError( TInt aError )
       
   769     {
       
   770     TRACE( Print( _L( " CMSSettingItemDevices::CycleError \
       
   771             aError = %d " ), aError ) );
       
   772 
       
   773     return aError;
       
   774     }
       
   775 
       
   776 // End of File