btobexprofiles/obexsendservices/obexservicesendutils/src/BTSBIPController.cpp
branchRCL_3
changeset 56 9386f31cc85b
parent 55 613943a21004
child 61 269724087bed
equal deleted inserted replaced
55:613943a21004 56:9386f31cc85b
     1 /*
       
     2 * Copyright (c) 2002-2010 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:  Image push implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "BTSBIPController.h"
       
    22 #include "BTSUDebug.h"
       
    23 #include "BTSUImageConverter.h"
       
    24 #include "BTSUXmlParser.h"
       
    25 #include <hbtextresolversymbian.h>
       
    26 
       
    27 
       
    28 
       
    29 // CONSTANTS
       
    30 // image push target header
       
    31 _LIT8( KBIPImagePushID, "\xE3\x3D\x95\x45\x83\x74\x4A\xD7\x9E\xC5\xC1\x6B\xE3\x1E\xDE\x8E" );
       
    32 
       
    33 // type headers
       
    34 _LIT8( KBTSBIPCapabilities, "x-bt/img-capabilities\0");
       
    35 _LIT8( KBTSBIPImageType,    "x-bt/img-img\0");
       
    36 _LIT8( KBTSBIPThmType,      "x-bt/img-thm\0");
       
    37 
       
    38 // imageBTS descriptor
       
    39 _LIT8( KBTSBIPDescriptorStart,     "<image-descriptor version=\"1.0\">\r" );
       
    40 _LIT8( KBTSBIPDescriptorEncoding,  "<image encoding=\"" );
       
    41 _LIT8( KBTSBIPDescriptorPixel,     "\" pixel=\"" );
       
    42 _LIT8( KBTSBIPDescriptorSize,      "\" size=\"" );
       
    43 _LIT8( KBTSBIPDescriptorEnd,       "\"/>\r</image-descriptor>" );
       
    44 
       
    45 // temp file path for capabilities object
       
    46 
       
    47 //temp file path drive letter
       
    48 _LIT(KBTSBIPTempPathDrive,"c:");
       
    49 const TInt KBTSUMaxPathLenght=256;
       
    50 const TInt KBTSUMaxPrivatePathLenght=20;
       
    51 
       
    52 _LIT(KBTNotSendSomeText,"txt_bt_info_receiving_device_does_not_support_all");
       
    53 _LIT(KBTNotSendOneText,"txt_bt_info_receiving_device_does_not_support_this");
       
    54 
       
    55 
       
    56 
       
    57 
       
    58 // ============================ MEMBER FUNCTIONS ===============================
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CBTSBIPController::CBTSBIPController
       
    62 // C++ default constructor can NOT contain any code, that
       
    63 // might leave.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CBTSBIPController::CBTSBIPController( MBTServiceObserver* aObserver, 
       
    67                                       CBTServiceParameterList* aList ) :
       
    68                                       iListPtr( aList ),
       
    69                                       iObserverPtr( aObserver )
       
    70 									  
       
    71     {
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CBTSBIPController::ConstructL
       
    76 // Symbian 2nd phase constructor can leave.
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void CBTSBIPController::ConstructL( const TUint aRemotePort, 
       
    80                                     const TBTDevAddr& aRemoteDeviceAddr )
       
    81     {
       
    82     FLOG(_L("[BTSU]\t CBTSBIPController::ConstructL()"));
       
    83     
       
    84     // Add image push target header
       
    85     //
       
    86     CObexHeader* header = CObexHeader::NewL();
       
    87     CleanupStack::PushL( header );
       
    88     header->SetByteSeqL( KBTSUTargetHeader, KBIPImagePushID );
       
    89 
       
    90     RArray<CObexHeader*> headerList;
       
    91     CleanupClosePushL( headerList );
       
    92     headerList.Append( header );
       
    93     
       
    94     CreateClientL ( this, aRemoteDeviceAddr, aRemotePort, headerList );    
       
    95 
       
    96     CleanupStack::Pop( 2 ); //header, headerlist
       
    97     headerList.Close();
       
    98 
       
    99     FLOG(_L("[BTSU]\t CBTSBIPController::ConstructL() completed"));
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CBTSBIPController::NewL
       
   104 // Two-phased constructor.
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 CBTSBIPController* CBTSBIPController::NewL( MBTServiceObserver* aObserver,
       
   108                                            const TUint aRemotePort,
       
   109                                            const TBTDevAddr& aRemoteDeviceAddr,
       
   110                                            CBTServiceParameterList* aList )
       
   111     {
       
   112     CBTSBIPController* self = 
       
   113         new( ELeave ) CBTSBIPController( aObserver, aList );
       
   114     CleanupStack::PushL( self );
       
   115     self->ConstructL( aRemotePort, aRemoteDeviceAddr );
       
   116     CleanupStack::Pop(self);
       
   117     return self;
       
   118     }
       
   119 
       
   120 // Destructor
       
   121 CBTSBIPController::~CBTSBIPController()
       
   122     {
       
   123     DeleteTempFile( iThumbnailFileName );
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CBTSBIPController::ConnectCompleted
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CBTSBIPController::ConnectCompleted( TInt aStatus )
       
   131     {
       
   132     FLOG(_L("[BTSU]\t CBTSBIPController::ConnectCompleted()"));
       
   133 
       
   134     if ( aStatus == KErrNone )
       
   135         {
       
   136         iFileIndex = 0;
       
   137         // get remote device capabilities
       
   138         //
       
   139         TRAPD( error, GetL() );
       
   140         if ( error != KErrNone )
       
   141             {
       
   142             iObserverPtr->ControllerComplete( EBTSGettingFailed );
       
   143             }
       
   144         }
       
   145     else
       
   146         {
       
   147         //Error on Obex level
       
   148         //
       
   149         iObserverPtr->ControllerComplete( EBTSConnectingFailed );
       
   150         }
       
   151 
       
   152     FLOG(_L("[BTSU]\t CBTSBIPController::ConnectCompleted() completed"));
       
   153     }
       
   154 // -----------------------------------------------------------------------------
       
   155 // CBTSBIPController::ClientConnectionClosed
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 void CBTSBIPController::ClientConnectionClosed()
       
   159     {
       
   160     FLOG(_L("[BTSU]\t CBTSBIPController::ClientConnectionClosed()"));
       
   161 
       
   162     // Everything ready, stop service
       
   163     //    
       
   164     iObserverPtr->ControllerComplete( EBTSNoError );	
       
   165     FLOG(_L("[BTSU]\t CBTSBIPController::ClientConnectionClosed() completed"));
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CBTSBIPController::PutCompleted
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void CBTSBIPController::PutCompleted( TInt aStatus, 
       
   173                                       const CObexHeaderSet* aPutResponse )
       
   174     {
       
   175     FLOG(_L("[BTSU]\t CBTSBIPController::PutCompleted()"));
       
   176 
       
   177     // Remove temporary thumbnail file
       
   178     //
       
   179     DeleteTempFile( iThumbnailFileName );
       
   180     if ( aStatus == KErrNone )
       
   181         {              
       
   182         iFileIndex++;
       
   183         // Send was ok. Start sending next image
       
   184         //
       
   185         TRAPD( error, SendL() );
       
   186         if ( error )
       
   187             {
       
   188             FTRACE(FPrint(_L("[BTSU]\t CBTSBPPController::Send leaved with %d"), error ));
       
   189             iObserverPtr->ControllerComplete( EBTSPuttingFailed);
       
   190             }                
       
   191         }
       
   192     else if ( aStatus == KErrIrObexRespPartialContent )
       
   193         {
       
   194         // Remote device has requested a thumbnail image
       
   195         //
       
   196         TRAPD( error, SendThumbnailL(aPutResponse ) );
       
   197         if ( error )
       
   198             {
       
   199             FTRACE(FPrint(_L("[BTSU]\t CBTSBPPController::Send thumbnail leaved with %d"), error ));
       
   200             iObserverPtr->ControllerComplete( EBTSPuttingFailed );
       
   201             }
       
   202         }
       
   203     else
       
   204         {
       
   205         // Some error on Obex level
       
   206         //
       
   207         iObserverPtr->ControllerComplete( EBTSPuttingFailed);
       
   208         }
       
   209 
       
   210     FLOG(_L("[BTSU]\t CBTSBIPController::PutCompleted() done"));
       
   211     }
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CBTSBIPController::GetCompleted
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 void CBTSBIPController::GetCompleted( TInt aStatus, 
       
   218                                       CObexBufObject* aGetResponse )
       
   219     {
       
   220     FLOG(_L("[BTSU]\t CBTSBIPController::GetCompleted()"));	
       
   221 
       
   222     if ( aStatus == KErrAbort )
       
   223         {
       
   224         // Connection is cancelled
       
   225         //
       
   226         iObserverPtr->ControllerComplete( EBTSGettingFailed );
       
   227         }
       
   228     
       
   229     else if ( aStatus == KErrNone )
       
   230         {
       
   231         TRAPD( error, HandleGetCompleteIndicationL( aGetResponse ) );
       
   232         if ( error != KErrNone )
       
   233             {
       
   234             DeleteTempFile( iTempFileName );
       
   235             // Error on capability handling
       
   236             //
       
   237             iObserverPtr->ControllerComplete( EBTSGettingFailed );
       
   238             }
       
   239         }
       
   240     else if( aStatus != KErrAbort && aGetResponse->BytesReceived()==0 )
       
   241         {
       
   242         TRAPD( error,iObserverPtr->LaunchProgressNoteL( iClient,iListPtr->ImageCount() ) );
       
   243         error=KErrNone;
       
   244         TRAP(error, SendL() );    	 
       
   245         if ( error != KErrNone )
       
   246             {            
       
   247             iObserverPtr->ControllerComplete( EBTSPuttingFailed );
       
   248             }    	      
       
   249         } 	
       
   250     else if ( aStatus != KErrNone && aGetResponse->BytesReceived()>0 )
       
   251         {
       
   252         // Error on Obex level
       
   253         //
       
   254         iObserverPtr->ControllerComplete( EBTSGettingFailed );
       
   255         }
       
   256     
       
   257 
       
   258     FLOG(_L("[BTSU]\t CBTSBIPController::GetCompleted() done"));
       
   259     }
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // CBTSBIPController::SendL
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 void CBTSBIPController::SendL()
       
   266     {
       
   267     FLOG(_L("[BTSU]\t CBTSBIPController::SendL()"));
       
   268 
       
   269     
       
   270     if ( iListPtr->ImageCount() > 0 && iFileIndex < iListPtr->ImageCount())
       
   271         {        
       
   272         
       
   273         RArray<CObexHeader*> headerList;
       
   274         CleanupClosePushL( headerList );
       
   275 
       
   276         // Add Type header
       
   277         //
       
   278         CObexHeader* typeHeader = CObexHeader::NewL();
       
   279         CleanupStack::PushL( typeHeader );
       
   280         typeHeader->SetByteSeqL( KBTSUTypeHeader, KBTSBIPImageType );
       
   281         headerList.Append( typeHeader );
       
   282 
       
   283         // Add image descriptor
       
   284         //
       
   285         HBufC8* imagedescriptor = CreateImageDescriptorL( );
       
   286         CleanupStack::PushL( imagedescriptor );
       
   287   
       
   288         CObexHeader* imageDescriptorHeader = CObexHeader::NewL();
       
   289         CleanupStack::PushL( imageDescriptorHeader );
       
   290         imageDescriptorHeader->SetByteSeqL( KBTSUImgDescriptorHeader, imagedescriptor->Des() );
       
   291         headerList.Append( imageDescriptorHeader );
       
   292 
       
   293         // Send image
       
   294         //
       
   295         
       
   296         TBTSUImageParam imageparam = iListPtr->ImageAtL( iFileIndex );        
       
   297         RBuf filename;
       
   298         filename.CreateL(KMaxFileName);
       
   299         CleanupClosePushL(filename);
       
   300         imageparam.iFile.Name(filename);
       
   301         
       
   302         iObserverPtr->UpdateProgressNoteL(imageparam.iFileSize,iFileIndex,filename);
       
   303         CleanupStack::PopAndDestroy(&filename);
       
   304         
       
   305         iListPtr->MarkAsSendL(iFileIndex);
       
   306         
       
   307         
       
   308         iClient->PutObjectL( headerList, imageparam.iFile );
       
   309         
       
   310           
       
   311         CleanupStack::Pop(4); // headerList, imageDescriptorHeader, typeHeader, imagedescriptor
       
   312         delete imagedescriptor;
       
   313         headerList.Close();
       
   314         }
       
   315     else
       
   316         {
       
   317         FLOG(_L("[BTSU]\t CBTSBIPController::SendL() all images sent, closing connection"));
       
   318 
       
   319         // All images sent, close client connection.
       
   320         //
       
   321         iClient->CloseClientConnection();
       
   322         }
       
   323 
       
   324     FLOG(_L("[BTSU]\t CBTSBIPController::SendL() completed"));
       
   325     }
       
   326 
       
   327 // -----------------------------------------------------------------------------
       
   328 // CBTSBIPController::GetL
       
   329 // -----------------------------------------------------------------------------
       
   330 //
       
   331 void CBTSBIPController::GetL()
       
   332     {
       
   333     FLOG(_L("[BTSU]\t CBTSBIPController::GetL()"));
       
   334 
       
   335     RArray<CObexHeader*> headerList;
       
   336     CleanupClosePushL(headerList);
       
   337     
       
   338     // Add capabilities type header
       
   339     //
       
   340     CObexHeader* typeHeader = CObexHeader::NewL();
       
   341     CleanupStack::PushL( typeHeader );
       
   342     typeHeader->SetByteSeqL( KBTSUTypeHeader, KBTSBIPCapabilities );
       
   343     headerList.Append( typeHeader );
       
   344 
       
   345     // Get capabilities object from remote device
       
   346     //
       
   347     iClient->GetObjectL( headerList );
       
   348 
       
   349     CleanupStack::Pop(2); // headerList, typeHeader
       
   350     headerList.Close();
       
   351     }
       
   352 
       
   353 // -----------------------------------------------------------------------------
       
   354 // CBTSBIPController::SendThumbnailL
       
   355 // -----------------------------------------------------------------------------
       
   356 //
       
   357 void CBTSBIPController::SendThumbnailL( const CObexHeaderSet *aPutResponse )
       
   358     {
       
   359     FLOG(_L("[BTSU]\t CBTSBIPController::SendThumbnail()"));
       
   360 
       
   361     // Create thumbnail for sending
       
   362     // Delete the created thumbnail on PutComplete
       
   363     //
       
   364 
       
   365     // Fill header array
       
   366     //
       
   367 	
       
   368     RArray<CObexHeader*> headerList;
       
   369     CleanupClosePushL(headerList);
       
   370 
       
   371     // Add ImageHandle header
       
   372     //
       
   373     CObexHeader* imageHandleHeader = CObexHeader::NewL();
       
   374     CleanupStack::PushL( imageHandleHeader );
       
   375 
       
   376     aPutResponse->First();
       
   377 	User::LeaveIfError(aPutResponse->Find(KBTSUImageHandleHeader,
       
   378 			 *imageHandleHeader ) );
       
   379 	headerList.Append( imageHandleHeader );
       
   380 	
       
   381     // Add Type header
       
   382     //
       
   383     CObexHeader* typeHeader = CObexHeader::NewL();
       
   384     CleanupStack::PushL( typeHeader );
       
   385     typeHeader->SetByteSeqL( KBTSUTypeHeader, KBTSBIPThmType );
       
   386     headerList.Append( typeHeader );
       
   387 	
       
   388 	
       
   389     CreateTempFileL( iThumbnailFileName );
       
   390     CBTSUImageConverter* imageConverter = CBTSUImageConverter::NewL();
       
   391     CleanupStack::PushL( imageConverter );
       
   392     
       
   393     TBTSUImageParam imgparam = iListPtr->ImageAtL( iFileIndex );
       
   394     imageConverter->CreateThumbnailL(imgparam.iFile, iThumbnailFileName );
       
   395     
       
   396     CleanupStack::PopAndDestroy(imageConverter);    
       
   397 
       
   398 	// Add Name header
       
   399     //
       
   400     TParse parse;
       
   401     User::LeaveIfError( parse.Set( iThumbnailFileName, NULL, NULL ) );
       
   402     CObexHeader* nameHeader = CObexHeader::NewL();
       
   403     CleanupStack::PushL( nameHeader );
       
   404     nameHeader->SetUnicodeL( KBTSUNameHeader, parse.NameAndExt() );
       
   405     headerList.Append( nameHeader );
       
   406 
       
   407     // send thumbnail
       
   408     //
       
   409     iClient->PutObjectL( headerList, iThumbnailFileName );
       
   410     
       
   411     // Cleanup
       
   412     //
       
   413     CleanupStack::Pop(4); // headerList, imageHandleHeader, typeHeader, nameHeader
       
   414     headerList.Close();
       
   415     }
       
   416 
       
   417 // -----------------------------------------------------------------------------
       
   418 // CBTSBIPController::CreateTempFileL
       
   419 // -----------------------------------------------------------------------------
       
   420 //
       
   421 void CBTSBIPController::CreateTempFileL( TFileName& aFileName )
       
   422     {
       
   423     FLOG(_L("[BTSU]\t CBTSBIPController::CreateTempFileL()"));
       
   424 
       
   425     RFs fileSession;
       
   426     RFile file;    
       
   427     
       
   428     TBuf<KBTSUMaxPrivatePathLenght> privatepath;     
       
   429     TBuf<KBTSUMaxPathLenght> tempPath;     
       
   430     
       
   431     User::LeaveIfError( fileSession.Connect() );
       
   432     CleanupClosePushL( fileSession );    
       
   433     
       
   434     User::LeaveIfError(fileSession.CreatePrivatePath(EDriveC));
       
   435     User::LeaveIfError(fileSession.PrivatePath(privatepath));
       
   436     tempPath.Append(KBTSBIPTempPathDrive());
       
   437     tempPath.Append(privatepath);    
       
   438     User::LeaveIfError( file.Temp( fileSession, privatepath, 
       
   439                             aFileName, EFileWrite ) );
       
   440     
       
   441     file.Flush();
       
   442     file.Close();
       
   443     CleanupStack::Pop();    // Close fileSession
       
   444     fileSession.Close();
       
   445     }
       
   446 
       
   447 
       
   448 // -----------------------------------------------------------------------------
       
   449 // CBTSBIPController::GenerateTempFileNameL
       
   450 // -----------------------------------------------------------------------------
       
   451 //
       
   452 void CBTSBIPController::GenerateTempFileNameL( TFileName& aFileName )
       
   453     {
       
   454     FLOG(_L("[BTSU]\t CBTSBIPController::GenerateTempFileNameL()"));
       
   455 
       
   456     RFs fileSession;
       
   457     RFile file;  
       
   458     
       
   459     TBuf<KBTSUMaxPrivatePathLenght> privatepath;     
       
   460     TBuf<KBTSUMaxPathLenght> tempPath;     
       
   461     
       
   462     User::LeaveIfError( fileSession.Connect() );
       
   463     CleanupClosePushL( fileSession );
       
   464     
       
   465     User::LeaveIfError(fileSession.CreatePrivatePath(EDriveC));
       
   466     User::LeaveIfError(fileSession.PrivatePath(privatepath ));
       
   467     tempPath.Append(KBTSBIPTempPathDrive());
       
   468     tempPath.Append(privatepath);
       
   469     User::LeaveIfError(file.Temp( fileSession, tempPath, 
       
   470                             aFileName, EFileWrite ) );                            
       
   471     
       
   472     file.Flush();
       
   473     file.Close();
       
   474     // Delete the file so that only a unique name is created
       
   475     fileSession.Delete( aFileName );
       
   476     CleanupStack::Pop();    // Close fileSession
       
   477     fileSession.Close();
       
   478     }    
       
   479 
       
   480 
       
   481 // -----------------------------------------------------------------------------
       
   482 // CBTSBIPController::DeleteTempFileL
       
   483 // -----------------------------------------------------------------------------
       
   484 //
       
   485 void CBTSBIPController::DeleteTempFile( TFileName& aFileName )
       
   486     {
       
   487     FLOG(_L("[BTSU]\t CBTSBIPController::DeleteTempFile()"));
       
   488 
       
   489     if ( &aFileName != NULL )
       
   490         {
       
   491         if ( aFileName.Length() > 0 )
       
   492             {
       
   493             RFs fileSession;
       
   494             TInt retVal = fileSession.Connect();
       
   495             if (retVal == KErrNone)
       
   496                 {
       
   497                 fileSession.Delete( aFileName );
       
   498                 }
       
   499             fileSession.Close();
       
   500             }
       
   501         }
       
   502 
       
   503     FLOG(_L("[BTSU]\t CBTSBIPController::DeleteTempFile() complete"));
       
   504     }
       
   505 
       
   506 // -----------------------------------------------------------------------------
       
   507 // CBTSBIPController::CreateImageDescriptorL
       
   508 // -----------------------------------------------------------------------------
       
   509 //
       
   510 HBufC8*  CBTSBIPController::CreateImageDescriptorL()
       
   511     {
       
   512     FLOG(_L("[BTSU]\t CBTSBIPController::CreateImageDescriptorL()"));
       
   513 
       
   514     //   Example image descriptor of an small jpeg picture
       
   515     //   with size 160*120 pixels and a size of 5000 bytes.
       
   516     //
       
   517     //  <image-descriptor version=\"1.0\">
       
   518     //  <image encoding=\"JPEG\" pixel=\"160*120\" size=\"5000\"/>
       
   519     //  </image-descriptor>
       
   520     TBTSUImageParam param = iListPtr->ImageAtL( iFileIndex );
       
   521     
       
   522     // Add start of image description
       
   523     //
       
   524     TBuf8<KBTSUMaxStringLength> string( KBTSBIPDescriptorStart );
       
   525 
       
   526     // Add image encoding
       
   527     //
       
   528     string.Append( KBTSBIPDescriptorEncoding );
       
   529     string.Append( *param.iDisplayName );
       
   530 
       
   531     // Add image pixel size
       
   532     //
       
   533     string.Append( KBTSBIPDescriptorPixel );
       
   534     string.AppendNum( param.iPixelSize.iWidth );
       
   535     string.Append( '*' );
       
   536     string.AppendNum( param.iPixelSize.iHeight );
       
   537 
       
   538     // Add image size
       
   539     //
       
   540     string.Append( KBTSBIPDescriptorSize );
       
   541     string.AppendNum( param.iFileSize );
       
   542 
       
   543     // Add end of image description
       
   544     //
       
   545     string.Append( KBTSBIPDescriptorEnd );
       
   546 
       
   547     FLOG(_L("[BTSU]\t CBTSBIPController::CreateImageDescriptorL() completed"));
       
   548     
       
   549     return string.AllocL();
       
   550     }
       
   551 
       
   552 
       
   553 // -----------------------------------------------------------------------------
       
   554 // CBTSBIPController::HandleGetCompleteIndicationL
       
   555 // -----------------------------------------------------------------------------
       
   556 //
       
   557 void CBTSBIPController::HandleGetCompleteIndicationL( CObexBufObject* aGetResponse )
       
   558     {
       
   559     FLOG(_L("[BTSU]\t CBTSBIPController::HandleGetCompleteIndicationL()"));
       
   560 
       
   561     TBool found;
       
   562     TBool allSupported;
       
   563     TInt picindex,capindex;
       
   564     CBTSUXmlParser* xmlParser = CBTSUXmlParser::NewL();
       
   565     CleanupStack::PushL( xmlParser );
       
   566     GenerateTempFileNameL( iTempFileName );
       
   567     aGetResponse->WriteToFile( iTempFileName );
       
   568     aGetResponse->Reset();
       
   569     
       
   570     // Parse capability object and create a list of supported image encodings
       
   571     //
       
   572     RArray<TBTSUImageCap>* remoteCapabilityList = 
       
   573         xmlParser->GetImgCapabilityListL( iTempFileName );
       
   574     
       
   575     // Delete the temp file since we dont need it anymore
       
   576     //
       
   577     DeleteTempFile( iTempFileName );
       
   578 
       
   579     // Go through all the images on our sending list and check 
       
   580     // if remote device is capable of receiving those.
       
   581     // 
       
   582     allSupported= ETrue;   
       
   583     for (picindex=0; picindex< iListPtr->ImageCount(); picindex++ )
       
   584     	{
       
   585     	found=EFalse;
       
   586     	for (capindex=0; capindex < remoteCapabilityList->Count(); capindex++)
       
   587     		{
       
   588     		//Find first is encoding suported			
       
   589     		if((iListPtr->ImageAtL( picindex ).iDisplayName->Compare(*(*remoteCapabilityList)[capindex].iEncoding))==0)		
       
   590     			{
       
   591     			found=ETrue;    			
       
   592     			//Check pixel size
       
   593     			if((*remoteCapabilityList)[capindex].iMinPixelSize.iHeight>=0)
       
   594     				{
       
   595     				if(((*remoteCapabilityList)[capindex].iMaxPixelSize.iWidth < iListPtr->ImageAtL( picindex ).iPixelSize.iWidth)  ||
       
   596     				   ((*remoteCapabilityList)[capindex].iMaxPixelSize.iHeight < iListPtr->ImageAtL( picindex ).iPixelSize.iHeight)|| 
       
   597     				   ((*remoteCapabilityList)[capindex].iMinPixelSize.iHeight > iListPtr->ImageAtL( picindex ).iPixelSize.iHeight)||
       
   598     				   ((*remoteCapabilityList)[capindex].iMinPixelSize.iWidth > iListPtr->ImageAtL( picindex ).iPixelSize.iWidth)
       
   599     				   )
       
   600     					{
       
   601     					found=EFalse;
       
   602     					}
       
   603     				}
       
   604     		
       
   605     			//Check byte size
       
   606     			if((*remoteCapabilityList)[capindex].iMaxByteSize>=0)
       
   607     				{    				
       
   608     				if((*remoteCapabilityList)[capindex].iMaxByteSize<iListPtr->ImageAtL( picindex ).iFileSize)
       
   609     					{
       
   610     					found=EFalse;
       
   611     					}
       
   612     				}    	
       
   613     			// If file is supported, stop the loop.
       
   614     			//
       
   615     			if ( found )
       
   616     			    break;
       
   617     			}
       
   618      		}
       
   619     	allSupported = found & allSupported;
       
   620     	}
       
   621     	
       
   622 	for (TInt index=0; index < remoteCapabilityList->Count(); index++)
       
   623 		{
       
   624 		if((*remoteCapabilityList)[index].iEncoding)
       
   625 			{
       
   626 			delete ((*remoteCapabilityList)[index].iEncoding);
       
   627 			}
       
   628 
       
   629 		}
       
   630 		
       
   631 	remoteCapabilityList->Close();
       
   632 	delete remoteCapabilityList;
       
   633     CleanupStack::PopAndDestroy( xmlParser ); 
       
   634     
       
   635     if(!allSupported  && iListPtr->ImageCount() > 1)
       
   636     	{      	
       
   637         HBufC* sendText = HbTextResolverSymbian::LoadLC(KBTNotSendSomeText);
       
   638     	iObserverPtr->LaunchConfirmationQuery(sendText->Des());
       
   639     	CleanupStack::PopAndDestroy( sendText );
       
   640     	}
       
   641     else if ( !allSupported  &&  iListPtr->ImageCount() == 1)
       
   642         {
       
   643         // We allow user to choose wheather to send the image file which is not supported on target device
       
   644         HBufC* sendText = HbTextResolverSymbian::LoadLC(KBTNotSendOneText);
       
   645         iObserverPtr->LaunchConfirmationQuery(sendText->Des());
       
   646         CleanupStack::PopAndDestroy( sendText );
       
   647         } 	
       
   648     else if( allSupported )  	
       
   649         {
       
   650     	iObserverPtr->LaunchProgressNoteL( iClient, iListPtr->ImageCount() + iListPtr->ObjectCount());
       
   651     
       
   652 	    // Start sending images
       
   653     	//   	
       
   654    		SendL();   		
       
   655     	}
       
   656     	
       
   657     
       
   658     FLOG(_L("[BTSU]\t CBTSBIPController::HandleGetCompleteIndicationL() #3"));
       
   659     }
       
   660     
       
   661 
       
   662 //-----------------------------------------------------------------------------
       
   663 // void CBTSBIPController::ConnectTimedOut()
       
   664 // -----------------------------------------------------------------------------
       
   665 //        
       
   666 void CBTSBIPController::ConnectTimedOut()    
       
   667     {
       
   668     iObserverPtr->ConnectTimedOut();    
       
   669     }
       
   670 
       
   671 
       
   672 
       
   673 void CBTSBIPController::SendUnSupportedFiles()
       
   674     {
       
   675     // Everything went ok. Start sending images
       
   676 
       
   677     // group leaving functions in one trap for better performance:
       
   678     TRAPD(err, {
       
   679             iObserverPtr->LaunchProgressNoteL( iClient, iListPtr->ImageCount() );
       
   680             SendL(); } );
       
   681     
       
   682     if ( err != KErrNone )
       
   683         {
       
   684         DeleteTempFile( iTempFileName );
       
   685         // Error on capability handling
       
   686         //
       
   687         iObserverPtr->ControllerComplete( EBTSGettingFailed );
       
   688         }
       
   689     }
       
   690 
       
   691 //  End of File