upnpframework/upnpaiwprovider/src/upnpaiwcopytoexternalservice.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-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of the UpnpAiwCopyToExternalService
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <AiwCommon.hrh>
       
    20 #include <AiwMenu.h>
       
    21 #include <aknnotewrappers.h>
       
    22 #include <upnpaiwmenuresources.rsg>
       
    23 #include "upnpaiwengine.h"
       
    24 #include "upnpaiwcopytoexternalservice.h"
       
    25 
       
    26 _LIT( KComponentLogfile, "upnpaiwprovider.log" );
       
    27 #include "upnplog.h"
       
    28 
       
    29 // CONSTANTS
       
    30 _LIT( KResFileName, "\\resource\\upnpaiwmenuresources.rsc" );
       
    31 
       
    32 // --------------------------------------------------------------------------
       
    33 // CUPnPAiwCopyToExternalService::NewL
       
    34 // NewL.
       
    35 // --------------------------------------------------------------------------
       
    36 CUPnPAiwCopyToExternalService* CUPnPAiwCopyToExternalService::NewL()
       
    37     {
       
    38     __LOG( "[UpnpAiwProvider]\t CUPnPAiwCopyToExternalService::NewL" );
       
    39 
       
    40     CUPnPAiwCopyToExternalService* self = 
       
    41                     new (ELeave) CUPnPAiwCopyToExternalService;
       
    42     CleanupStack::PushL( self );
       
    43 
       
    44     self->ConstructL();
       
    45 
       
    46     CleanupStack::Pop( self );
       
    47     return self;
       
    48     }
       
    49 
       
    50 // --------------------------------------------------------------------------
       
    51 // CUPnPAiwCopyToExternalService::CUPnPAiwMoveToExternalService
       
    52 // Constructor.
       
    53 // --------------------------------------------------------------------------
       
    54 CUPnPAiwCopyToExternalService::CUPnPAiwCopyToExternalService()
       
    55     {
       
    56     __LOG( "[UpnpAiwProvider]\t CUPnPAiwCopyToExternalService::\
       
    57 CUPnPAiwCopyToExternalService" );
       
    58     }
       
    59 
       
    60 // --------------------------------------------------------------------------
       
    61 // CUPnPAiwCopyToExternalService::~CUPnPAiwCopyToExternalService
       
    62 // Destructor.
       
    63 // --------------------------------------------------------------------------
       
    64 CUPnPAiwCopyToExternalService::~CUPnPAiwCopyToExternalService()
       
    65     {
       
    66     __LOG( "[UpnpAiwProvider]\t CUPnPAiwCopyToExternalService::\
       
    67 ~CUPnPAiwCopyToExternalService" );
       
    68 
       
    69     // Empty the file name array and close it
       
    70     EmptyFileNameArray();
       
    71     iFileNames.Close();
       
    72 
       
    73     // Delete the playlist name (if not yet deleted)
       
    74     delete iPlaylistName;
       
    75 
       
    76     // Release the engine instance
       
    77     if( iEngine )
       
    78         {
       
    79         CUPnPAiwEngine::ReleaseInstance();
       
    80         iEngine = NULL;
       
    81         }
       
    82     }
       
    83 
       
    84 // --------------------------------------------------------------------------
       
    85 // CUPnPAiwCopyToExternalService::ConstructL
       
    86 // Second phase constructor.
       
    87 // --------------------------------------------------------------------------
       
    88 void CUPnPAiwCopyToExternalService::ConstructL()
       
    89     {
       
    90     __LOG( "[UpnpAiwProvider]\t CUPnPAiwCopyToExternalService::\
       
    91 ConstructL" );
       
    92 
       
    93     // Create the engine and register as an observer for call backs
       
    94     iEngine = CUPnPAiwEngine::NewL();
       
    95     }
       
    96 
       
    97 // --------------------------------------------------------------------------
       
    98 // CUPnPAiwCopyToExternalService::InitializeMenuPaneL
       
    99 // AIW Framework's method for initialising the menu
       
   100 // --------------------------------------------------------------------------
       
   101 void CUPnPAiwCopyToExternalService::InitializeMenuPaneL( 
       
   102                 CAiwMenuPane& aMenuPane,
       
   103                 TInt aIndex,
       
   104                 TInt /*aCascadeId*/,
       
   105                 const CAiwGenericParamList& /*aInParamList*/ )
       
   106     {
       
   107     __LOG( "[UpnpAiwProvider]\t CUPnPAiwCopyToExternalService::\
       
   108 InitializeMenuPaneL" );
       
   109 
       
   110     // Update the drive letter to the path of the resource file name
       
   111     TUPnPEngineState engineState = iEngine->EngineState();
       
   112     if( engineState == EUPnPEngineNotConnected ||
       
   113         engineState == EUPnPEngineConnectionLost )
       
   114         {
       
   115 
       
   116         TFileName resFile( KResFileName );
       
   117         TFileName dllName;
       
   118         Dll::FileName( dllName );
       
   119         TBuf<2> drive = dllName.Left(2); // Drive letter followed by ':' 
       
   120         resFile.Insert( 0, drive );
       
   121     
       
   122         // Add the play menu item to the menu pane
       
   123         aMenuPane.AddMenuItemsL( resFile,
       
   124                                  R_AIW_COPY_TO_EXTERNAL_MENU,
       
   125                                  KAiwCmdUPnPCopy,
       
   126                                  aIndex );
       
   127         }
       
   128     }
       
   129 
       
   130 // --------------------------------------------------------------------------
       
   131 // CUPnPAiwCopyToExternalService::HandleMenuCmdL
       
   132 // AIW Framework's method for handling menu commands
       
   133 // --------------------------------------------------------------------------
       
   134 void CUPnPAiwCopyToExternalService::HandleMenuCmdL( 
       
   135                 TInt aMenuCmdId,
       
   136                 const CAiwGenericParamList& aInParamList,
       
   137                 CAiwGenericParamList& aOutParamList,
       
   138                 TUint /*aCmdOptions*/,
       
   139                 const MAiwNotifyCallback* /*aCallback*/ )
       
   140     {
       
   141     __LOG( "[UpnpAiwProvider]\t CUPnPAiwCopyToExternalService::\
       
   142 HandleMenuCmdL" );
       
   143 
       
   144     // Empty the file name array
       
   145     EmptyFileNameArray();
       
   146 
       
   147     // The playlist name (if we are doing a playlist copy)
       
   148     delete iPlaylistName;
       
   149     iPlaylistName = NULL;
       
   150 
       
   151     // Get the file name parameters
       
   152     if( aInParamList.Count() > 0 )
       
   153         {
       
   154         for( TInt index = 0; index < aInParamList.Count(); index++ )
       
   155             {
       
   156             // Get the filenames
       
   157             if ( aInParamList[index].SemanticId() == EGenericParamFile )
       
   158                 {
       
   159                 // Store the file name in the array
       
   160                 HBufC* fileName = HBufC::NewLC( 
       
   161                         aInParamList[index].Value().AsDes().Length() );
       
   162                 fileName->Des().Append( aInParamList[index].Value().AsDes() );
       
   163                 iFileNames.AppendL( fileName );
       
   164                 CleanupStack::Pop( fileName );
       
   165                 }
       
   166             // Get the playlist name if it is not set already (only the first
       
   167             // playlist name will be used)
       
   168             if( aInParamList[index].SemanticId() == EGenericParamAlbumName &&
       
   169                 !iPlaylistName )
       
   170                 {
       
   171                 iPlaylistName = HBufC::NewL( 
       
   172                         aInParamList[index].Value().AsDes().Length() );
       
   173                 iPlaylistName->Des().Append( 
       
   174                         aInParamList[index].Value().AsDes() );
       
   175                 }
       
   176             }
       
   177         }
       
   178 
       
   179     if( aMenuCmdId == KAiwCmdUPnPCopy )
       
   180         {
       
   181         if( iEngine )
       
   182             {
       
   183             if( iFileNames.Count()>0 )
       
   184                 {
       
   185                 // Do the copy
       
   186                 TInt returnValue = KErrArgument;
       
   187                 if( iPlaylistName == NULL )
       
   188                     {
       
   189                     // Normal copy
       
   190                     TRAP( returnValue,
       
   191                           iEngine->CopyToExternalL( iFileNames ) );
       
   192                     }
       
   193                 else
       
   194                     {
       
   195                     // Playlist copy
       
   196                     TRAP( returnValue,
       
   197                           iEngine->CopyPlaylistToExternalL(
       
   198                                                     *iPlaylistName,
       
   199                                                     iFileNames ) );
       
   200                     }
       
   201 
       
   202                 // Do some error translation regarding DRM protected files
       
   203                 if ( returnValue == KErrNotSupported ||
       
   204                     returnValue == KErrPermissionDenied )
       
   205                     {
       
   206                     returnValue = KErrAccessDenied;
       
   207                     }
       
   208 
       
   209                 // Add the return value on the out param list
       
   210                 TAiwGenericParam statusParameter( 
       
   211                             EGenericParamError, 
       
   212                             returnValue );
       
   213                 aOutParamList.AppendL( statusParameter );
       
   214 
       
   215                 // Add the files that FAILED to copy to out param list.
       
   216                 // finally, reset the array.
       
   217                 for( TInt index=0; index<iFileNames.Count(); index++ )
       
   218                     {
       
   219                     if( iFileNames[index] )
       
   220                         {
       
   221                         // Create TAIWGenericParam for the filename
       
   222                         TFileName fileName( *iFileNames[index] );
       
   223                         TAiwGenericParam fileParameter( 
       
   224                                         EGenericParamFile, 
       
   225                                         fileName );
       
   226 
       
   227                         // Append the file filename param on the out list
       
   228                         aOutParamList.AppendL( fileParameter );
       
   229                         }
       
   230                     }
       
   231                 iFileNames.ResetAndDestroy();
       
   232 
       
   233                 }
       
   234             else
       
   235                 {
       
   236                 __LOG( "[UpnpAiwProvider]\t CUPnPAiwCopyToExternalService, \
       
   237 no files!" );
       
   238                 }
       
   239             }
       
   240         else
       
   241             {
       
   242             __LOG( "[UpnpAiwProvider]\t CUPnPAiwCopyToExternalService, \
       
   243 engine is dead!" );
       
   244             }
       
   245         }
       
   246 
       
   247     // Clean up
       
   248     delete iPlaylistName;
       
   249     iPlaylistName = NULL;
       
   250     }
       
   251 
       
   252 // --------------------------------------------------------------------------
       
   253 // CUPnPAiwCopyToExternalService::EmptyFileNameArray
       
   254 // Empties the file name array (data member variable).
       
   255 // --------------------------------------------------------------------------
       
   256 void CUPnPAiwCopyToExternalService::EmptyFileNameArray()
       
   257     {
       
   258     // delete the list of file names and close the file name array
       
   259     for( TInt index=0;index< iFileNames.Count();index++ )
       
   260         {
       
   261         delete iFileNames[index];
       
   262         iFileNames[index] = NULL;
       
   263         }
       
   264     iFileNames.Reset();
       
   265     }
       
   266 
       
   267 // --------------------------------------------------------------------------
       
   268 // CUPnPAiwCopyToExternalService::ConnectionLostL
       
   269 // Indicates that the connection with the target UPnP device has
       
   270 // been lost.
       
   271 // --------------------------------------------------------------------------
       
   272 void CUPnPAiwCopyToExternalService::ConnectionLostL()
       
   273     {
       
   274     __LOG( "[UpnpAiwProvider]\t CUPnPAiwCopyToExternalService::\
       
   275 ConnectionLostL" );
       
   276 
       
   277     // If there is a client that has registered as an observer
       
   278     if( iClient )
       
   279         {
       
   280         // Create parameter lists
       
   281         CAiwGenericParamList* emptyParamlist = CAiwGenericParamList::NewLC();
       
   282 
       
   283         TInt eventCode = KAiwEventStopped;
       
   284 
       
   285         // Make the call back
       
   286         iClient->HandleNotifyL( KAiwCmdUPnPCopy,
       
   287                                 eventCode,
       
   288                                 *emptyParamlist,
       
   289                                 *emptyParamlist );
       
   290 
       
   291         // Clean up
       
   292         CleanupStack::PopAndDestroy( emptyParamlist );
       
   293         emptyParamlist = NULL;
       
   294         }
       
   295     }
       
   296 
       
   297 // End of file