upnpframework/upnpaiwprovider/src/upnpaiwmovetoexternalservice.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     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 UpnpAiwMoveToExternalService
       
    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 "upnpaiwmovetoexternalservice.h"
       
    25 #include "upnpdrmfilter.h"
       
    26 
       
    27 _LIT( KComponentLogfile, "upnpaiwprovider.log" );
       
    28 #include "upnplog.h"
       
    29 
       
    30 // CONSTANTS
       
    31 _LIT( KResFileName, "\\resource\\upnpaiwmenuresources.rsc" );
       
    32 
       
    33 // --------------------------------------------------------------------------
       
    34 // CUPnPAiwMoveToExternalService::NewL
       
    35 // NewL.
       
    36 // --------------------------------------------------------------------------
       
    37 CUPnPAiwMoveToExternalService* CUPnPAiwMoveToExternalService::NewL()
       
    38     {
       
    39     __LOG( "[UpnpAiwProvider]\t CUPnPAiwMoveToExternalService::NewL" );
       
    40 
       
    41     CUPnPAiwMoveToExternalService* self = 
       
    42                 new (ELeave) CUPnPAiwMoveToExternalService;
       
    43     CleanupStack::PushL( self );
       
    44 
       
    45     self->ConstructL();
       
    46 
       
    47     CleanupStack::Pop( self );
       
    48     return self;
       
    49     }
       
    50 
       
    51 // --------------------------------------------------------------------------
       
    52 // CUPnPAiwMoveToExternalService::CUPnPAiwMoveToExternalService
       
    53 // Constructor.
       
    54 // --------------------------------------------------------------------------
       
    55 CUPnPAiwMoveToExternalService::CUPnPAiwMoveToExternalService()
       
    56     {
       
    57     __LOG( "[UpnpAiwProvider]\t CUPnPAiwMoveToExternalService::\
       
    58 CUPnPAiwMoveToExternalService" );
       
    59     }
       
    60 
       
    61 // --------------------------------------------------------------------------
       
    62 // CUPnPAiwMoveToExternalService::~CUPnPAiwMoveToExternalService
       
    63 // Destructor.
       
    64 // --------------------------------------------------------------------------
       
    65 CUPnPAiwMoveToExternalService::~CUPnPAiwMoveToExternalService()
       
    66     {
       
    67     __LOG( "[UpnpAiwProvider]\t CUPnPAiwMoveToExternalService::\
       
    68 ~CUPnPAiwMoveToExternalService" );
       
    69 
       
    70     // Empty the file name array and close it
       
    71     EmptyFileNameArray();
       
    72     iFileNames.Close();
       
    73 
       
    74     // Release the engine instance
       
    75     if( iEngine )
       
    76         {
       
    77         CUPnPAiwEngine::ReleaseInstance();
       
    78         iEngine = NULL;
       
    79         }
       
    80     }
       
    81 
       
    82 // --------------------------------------------------------------------------
       
    83 // CUPnPAiwMoveToExternalService::ConstructL
       
    84 // Second phase constructor.
       
    85 // --------------------------------------------------------------------------
       
    86 void CUPnPAiwMoveToExternalService::ConstructL()
       
    87     {
       
    88     __LOG( "[UpnpAiwProvider]\t CUPnPAiwMoveToExternalService::ConstructL" );
       
    89 
       
    90     // Create the engine and register as an observer for call backs
       
    91     iEngine = CUPnPAiwEngine::NewL();
       
    92     }
       
    93 
       
    94 // --------------------------------------------------------------------------
       
    95 // CUPnPAiwMoveToExternalService::InitializeMenuPaneL
       
    96 // AIW Framework's method for initialising the menu
       
    97 // --------------------------------------------------------------------------
       
    98 void CUPnPAiwMoveToExternalService::InitializeMenuPaneL( 
       
    99                 CAiwMenuPane& aMenuPane,
       
   100                 TInt aIndex,
       
   101                 TInt /*aCascadeId*/,
       
   102                 const CAiwGenericParamList& /*aInParamList*/ )
       
   103     {
       
   104     __LOG( "[UpnpAiwProvider]\t CUPnPAiwMoveToExternalService::\
       
   105 InitializeMenuPaneL" );
       
   106 
       
   107     TUPnPEngineState engineState = iEngine->EngineState();
       
   108     if( engineState == EUPnPEngineNotConnected ||
       
   109         engineState == EUPnPEngineConnectionLost )
       
   110         {
       
   111         // Update the drive letter to the path of the resource file name
       
   112         TFileName resFile( KResFileName );
       
   113         TFileName dllName;
       
   114         Dll::FileName( dllName );
       
   115         TBuf<2> drive = dllName.Left(2); // Drive letter followed by ':' 
       
   116         resFile.Insert( 0, drive );
       
   117     
       
   118         // Add the play menu item to the menu pane
       
   119         aMenuPane.AddMenuItemsL( resFile,
       
   120                                  R_AIW_MOVE_TO_EXTERNAL_MENU,
       
   121                                  KAiwCmdUPnPMove,
       
   122                                  aIndex );
       
   123         }
       
   124     }
       
   125 
       
   126 // --------------------------------------------------------------------------
       
   127 // CUPnPAiwMoveToExternalService::HandleMenuCmdL
       
   128 // AIW Framework's method for handling menu commands
       
   129 // --------------------------------------------------------------------------
       
   130 void CUPnPAiwMoveToExternalService::HandleMenuCmdL( 
       
   131                 TInt aMenuCmdId,
       
   132                 const CAiwGenericParamList& aInParamList,
       
   133                 CAiwGenericParamList& aOutParamList,
       
   134                 TUint /*aCmdOptions*/,
       
   135                 const MAiwNotifyCallback* /*aCallback*/ )
       
   136     {
       
   137     __LOG( "[UpnpAiwProvider]\t CUPnPAiwMoveToExternalService::\
       
   138 HandleMenuCmdL" );
       
   139 
       
   140     // Empty the file name array
       
   141     EmptyFileNameArray();
       
   142 
       
   143     // Get the file name parameters
       
   144     if( aInParamList.Count() > 0 )
       
   145         {
       
   146         for( TInt index = 0; index < aInParamList.Count(); index++ )
       
   147             {
       
   148             // Get the filenames
       
   149             if ( aInParamList[index].SemanticId() == EGenericParamFile )
       
   150                 {
       
   151                 // Store the file name in the array
       
   152                 HBufC* fileName = HBufC::NewLC( 
       
   153                     aInParamList[index].Value().AsDes().Length() );
       
   154                 fileName->Des().Append( 
       
   155                     aInParamList[index].Value().AsDes() );
       
   156                 iFileNames.AppendL( fileName );
       
   157                 CleanupStack::Pop( fileName );
       
   158                 }
       
   159             }
       
   160         }
       
   161 
       
   162     if( aMenuCmdId == KAiwCmdUPnPMove )
       
   163         {
       
   164         if( iEngine )
       
   165             {
       
   166             if( iFileNames.Count()>0 )
       
   167                 {
       
   168                 // Do the move
       
   169                 TInt returnValue = KErrArgument;
       
   170                 TRAP( returnValue,
       
   171                       iEngine->MoveToExternalL( iFileNames ) );
       
   172 
       
   173                 // Do some error translation regarding DRM protected files
       
   174                 if ( returnValue == KErrNotSupported ||
       
   175                     returnValue == KErrPermissionDenied )
       
   176                     {
       
   177                     returnValue = KErrAccessDenied;
       
   178                     }
       
   179 
       
   180                 // Add the return value on the out param list
       
   181                 TAiwGenericParam statusParameter( 
       
   182                                     EGenericParamError,
       
   183                                     returnValue );
       
   184                 aOutParamList.AppendL( statusParameter );
       
   185 
       
   186                 // Add the files that FAILED to copy to out param list.
       
   187                 // finally, reset the array.
       
   188                 for( TInt index=0; index<iFileNames.Count(); index++ )
       
   189                     {
       
   190                     if( iFileNames[index] )
       
   191                         {
       
   192                         // Create TAIWGenericParam for the filename
       
   193                         TFileName fileName( *iFileNames[index] );
       
   194                         TAiwGenericParam fileParameter( 
       
   195                                     EGenericParamFile, 
       
   196                                     fileName );
       
   197 
       
   198                         // Append the file filename param on the out list
       
   199                         aOutParamList.AppendL( fileParameter );
       
   200                         }
       
   201                     }
       
   202                 iFileNames.ResetAndDestroy();
       
   203 
       
   204                 }
       
   205             else
       
   206                 {
       
   207                 __LOG( "[UpnpAiwProvider]\t CUPnPAiwMoveToExternalService, \
       
   208 no files!" );
       
   209                 }
       
   210             }
       
   211         else
       
   212             {
       
   213             __LOG( "[UpnpAiwProvider]\t CUPnPAiwMoveToExternalService, \
       
   214 engine is dead!" );
       
   215             }
       
   216         }
       
   217     }
       
   218 
       
   219 // --------------------------------------------------------------------------
       
   220 // CUPnPAiwMoveToExternalService::EmptyFileNameArray
       
   221 // Empties the file name array (data member variable).
       
   222 // --------------------------------------------------------------------------
       
   223 void CUPnPAiwMoveToExternalService::EmptyFileNameArray()
       
   224     {
       
   225     __LOG( "[UpnpAiwProvider]\t CUPnPAiwMoveToExternalService::\
       
   226 EmptyFileNameArray" );
       
   227 
       
   228     // delete the list of file names and close the file name array
       
   229     for( TInt index=0; index<iFileNames.Count(); index++ )
       
   230         {
       
   231         delete iFileNames[index];
       
   232         iFileNames[index] = NULL;
       
   233         }
       
   234     iFileNames.Reset();
       
   235     }
       
   236 
       
   237 // --------------------------------------------------------------------------
       
   238 // CUPnPAiwMoveToExternalService::ConnectionLostL
       
   239 // Indicates that the connection with the target UPnP device has 
       
   240 // been lost.
       
   241 // --------------------------------------------------------------------------
       
   242 void CUPnPAiwMoveToExternalService::ConnectionLostL()
       
   243     {
       
   244     __LOG( "[UpnpAiwProvider]\t CUPnPAiwMoveToExternalService::\
       
   245 ConnectionLostL" );
       
   246 
       
   247     // If there is a client that has registered as an observer
       
   248     if( iClient )
       
   249         {
       
   250         // Create parameter lists
       
   251         CAiwGenericParamList* emptyParamlist = CAiwGenericParamList::NewLC();
       
   252 
       
   253         TInt eventCode = KAiwEventStopped;
       
   254 
       
   255         // Make the call back
       
   256         iClient->HandleNotifyL( KAiwCmdUPnPMove,
       
   257                                 eventCode,
       
   258                                 *emptyParamlist,
       
   259                                 *emptyParamlist );
       
   260 
       
   261         // Clean up
       
   262         CleanupStack::PopAndDestroy( emptyParamlist );
       
   263         emptyParamlist = NULL;
       
   264         }
       
   265     }
       
   266 
       
   267 // End of file