phoneclientserver/phoneclient/Src/ImageHandler/RPhCltImageHandler.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2004-2005 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  TPhoneServer interface for image handling.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 
       
    21 #include    "rphcltimagehandler.h" 
       
    22 #include    "phcltclientserver.h" 
       
    23 #include    <rphcltserver.h> 
       
    24 #include    <e32std.h>
       
    25 #include    <e32base.h>
       
    26 #include    <fbs.h>
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // RPhCltImageHandler::RPhCltImageHandler
       
    32 // 
       
    33 // C++ constructor can NOT contain any code, that might leave.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 RPhCltImageHandler::RPhCltImageHandler()
       
    37 :   RSubSessionBase()
       
    38     {
       
    39     }
       
    40 
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // RPhCltImageHandler::Open
       
    44 // 
       
    45 // Open subsession to Phone Server.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 TInt RPhCltImageHandler::Open( RPhCltServer& aServer )
       
    49     {
       
    50     __ASSERT_ALWAYS( aServer.Handle(), User::Panic( 
       
    51             KPhClientPanicCategory, 
       
    52             EPhCltClientSidePanicNullHandle ) );
       
    53 
       
    54     return CreateSubSession( 
       
    55         aServer, 
       
    56         EPhoneServerImageHandlerSubSessionOpen, 
       
    57         TIpcArgs() );
       
    58     }
       
    59 
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // RPhCltImageHandler::Close
       
    63 // 
       
    64 // Close subsession.
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 void RPhCltImageHandler::Close()
       
    68     {
       
    69     iVTBitMaps.ResetAndDestroy();
       
    70     iOperatorLogos.ResetAndDestroy();
       
    71     CloseSubSession( EPhoneServerImageHandlerSubSessionClose );
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // RPhCltImageHandler::SaveImages
       
    76 // 
       
    77 // Saves images to Phoneserver.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 TInt RPhCltImageHandler::SaveImages( CPhCltImageParams& aParams )
       
    81     {
       
    82     __ASSERT_ALWAYS( 
       
    83         SubSessionHandle(), User::Panic( 
       
    84             KPhClientPanicCategory, EPhCltClientSidePanicNullHandle ) );
       
    85 
       
    86     return SendReceive( 
       
    87         EPhoneServerImageHandlerSubSessionSave, 
       
    88         TIpcArgs( 
       
    89             &aParams.Images()) );
       
    90     }     
       
    91     
       
    92 // -----------------------------------------------------------------------------
       
    93 // RPhCltImageHandler::LoadImages
       
    94 // 
       
    95 // Loads images from Phoneserver.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 TInt RPhCltImageHandler::LoadImages( CPhCltImageParams*& aParams )
       
    99     {
       
   100     __ASSERT_ALWAYS( 
       
   101         SubSessionHandle(), User::Panic( 
       
   102             KPhClientPanicCategory, EPhCltClientSidePanicNullHandle ) );
       
   103 
       
   104     const TInt ret = SendReceive( EPhoneServerImageHandlerSubSessionLoad, 
       
   105         TIpcArgs( &aParams->Images() ) );
       
   106         
       
   107     // No point in commiting if failed.
       
   108     if ( ret != KErrNone )
       
   109         {
       
   110         return ret;
       
   111         }
       
   112     return FinalizeLoad( aParams->Images() );
       
   113     }
       
   114  
       
   115 // -----------------------------------------------------------------------------
       
   116 // RPhCltImageHandler::FinalizeLoad
       
   117 // 
       
   118 // Duplicates loaded images, and commits transaction.
       
   119 // -----------------------------------------------------------------------------
       
   120 //    
       
   121 TInt RPhCltImageHandler::FinalizeLoad( TPckgBuf< TPhCltImageArray >& aImages )
       
   122     {
       
   123     TRAPD( err, 
       
   124         {
       
   125         switch( aImages.operator()().iType )
       
   126             {
       
   127             case EPhCltTypeVTStill:
       
   128             case EPhCltTypeVTDefault:
       
   129                 CopyStillsL( aImages.operator()() );
       
   130                 break;
       
   131             case EPhCltTypeOperatorLogo:
       
   132                 CopyLogosL( aImages.operator()() );
       
   133                 break;
       
   134             default:
       
   135                 break;
       
   136             }
       
   137         } );
       
   138 
       
   139     // Must release in any case
       
   140     const TInt ret = SendReceive( EPhoneServerImageHandlerSubSessionCommitLoad, 
       
   141         TIpcArgs( &aImages ) );
       
   142 
       
   143     return err != KErrNone ? err : ret;
       
   144 
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // RPhCltImageHandler::CopyLogos
       
   149 // 
       
   150 // Replaces / appends a new logo.
       
   151 // -----------------------------------------------------------------------------
       
   152 //    
       
   153 void RPhCltImageHandler::CopyLogosL( TPhCltImageArray& aImages )
       
   154     {
       
   155     TBool found( EFalse );
       
   156     CFbsBitmap* bitMap = 
       
   157         CreateBitMapL( aImages.iImages[ EPhCltExtOperatorLogoIndex ] );
       
   158 
       
   159     // Check if there is one stored already, replace handle if so.
       
   160     for ( TInt i = 0; i < iOperatorLogos.Count(); i ++ )
       
   161         {
       
   162         if ( aImages.iImages[ EPhCltExtCountryCodeIndex ] == 
       
   163             iOperatorLogos[ i ]->iCountryCode && 
       
   164             aImages.iImages[ EPhCltExtNetworkCodeIndex ] == 
       
   165             iOperatorLogos[ i ]->iNetworkCode && 
       
   166             aImages.iImages[ EPhCltExtLogoTypeIndex ] == 
       
   167             iOperatorLogos[ i ]->iLogoType            
       
   168              )
       
   169             {
       
   170             delete iOperatorLogos[ i ]->iBitmap;
       
   171             iOperatorLogos[ i ]->iBitmap = bitMap;
       
   172             found = ETrue;
       
   173             break;
       
   174             }
       
   175         }
       
   176 
       
   177     // Else add a new one.
       
   178     if ( !found )
       
   179         {
       
   180         CPhCltOperatorLogoContainer* logo = 
       
   181             new (ELeave)CPhCltOperatorLogoContainer(
       
   182             aImages.iImages[ EPhCltExtCountryCodeIndex ], 
       
   183             aImages.iImages[ EPhCltExtNetworkCodeIndex ],
       
   184             ( TPhCltExtOperatorLogoType )
       
   185             aImages.iImages[ EPhCltExtLogoTypeIndex ],
       
   186             bitMap );
       
   187         CleanupStack::PushL(logo);
       
   188         iOperatorLogos.AppendL( logo );
       
   189         CleanupStack::Pop(logo);
       
   190         }
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // RPhCltImageHandler::CopyStillsL
       
   195 // 
       
   196 // Creates new duplicates of still images.
       
   197 // -----------------------------------------------------------------------------
       
   198 //   
       
   199 void RPhCltImageHandler::CopyStillsL( TPhCltImageArray& aImages ) 
       
   200     {
       
   201     // Remove all first.
       
   202     iVTBitMaps.ResetAndDestroy();
       
   203     iVTBitMaps.ReserveL(aImages.iImageCount);
       
   204     for ( TInt i = 0 ; i < aImages.iImageCount; i ++ )
       
   205         {
       
   206         CFbsBitmap* bitMap = 
       
   207             CreateBitMapL( aImages.iImages[ i ] );
       
   208         CleanupStack::PushL( bitMap );
       
   209         iVTBitMaps.AppendL( bitMap );
       
   210         CleanupStack::Pop(bitMap);
       
   211         }
       
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // RPhCltImageHandler::CreateBitMapL
       
   216 // 
       
   217 // Creates new duplicate of still image.
       
   218 // -----------------------------------------------------------------------------
       
   219 //   
       
   220 CFbsBitmap* RPhCltImageHandler::CreateBitMapL( const TInt aHandle )
       
   221     {
       
   222     CFbsBitmap* bitMap = new ( ELeave ) CFbsBitmap();
       
   223     CleanupStack::PushL( bitMap );
       
   224     User::LeaveIfError( bitMap->Duplicate( aHandle ) );
       
   225     CleanupStack::Pop( bitMap );
       
   226     return bitMap;
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // RPhCltImageHandler::SaveVtImage
       
   231 // 
       
   232 // Saves VT Image.
       
   233 // -----------------------------------------------------------------------------
       
   234 //   
       
   235 void RPhCltImageHandler::SaveVtImage( 
       
   236     TRequestStatus& aStatus, 
       
   237     const TDesC& aFilePath )
       
   238     {
       
   239     __ASSERT_ALWAYS( 
       
   240         SubSessionHandle(), User::Panic( 
       
   241             KPhClientPanicCategory, EPhCltClientSidePanicNullHandle ) );
       
   242     const TPtrC8 ptr8( reinterpret_cast<const TUint8*> ( aFilePath.Ptr() ), 
       
   243         aFilePath.Size() );
       
   244     TIpcArgs args( &ptr8 );
       
   245     SendReceive( 
       
   246         EPhoneServerSaveVtImage,
       
   247         args,
       
   248         aStatus );
       
   249     }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // RPhCltImageHandler::CancelSaveVtImage
       
   253 // 
       
   254 // 
       
   255 // -----------------------------------------------------------------------------
       
   256 //   
       
   257 void RPhCltImageHandler::CancelSaveVtImage()
       
   258     {
       
   259     SendReceive( EPhoneServerSaveVtImageCancel );
       
   260     }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // RPhCltImageHandler::OpenVtImage
       
   264 // 
       
   265 // Opens VT Image file.
       
   266 // -----------------------------------------------------------------------------
       
   267 //   
       
   268 TInt RPhCltImageHandler::OpenVtImage( 
       
   269     TInt& aFileHandle,
       
   270     const TBool aOpenDefault )
       
   271     {
       
   272     __ASSERT_ALWAYS( 
       
   273         SubSessionHandle(), User::Panic( 
       
   274             KPhClientPanicCategory, EPhCltClientSidePanicNullHandle ) );
       
   275     TPckg<TInt> pckg1( aFileHandle );
       
   276     TPckg<TBool> pckg2( aOpenDefault );
       
   277     TIpcArgs args( &pckg1, &pckg2 );
       
   278     return SendReceive(
       
   279         EPhoneServerOpenVtImage, args );
       
   280     }
       
   281 
       
   282 // End of File