btobexprofiles/obexsendservices/obexservicesendutils/src/BTServiceStarter.cpp
changeset 32 19bd632b5100
child 40 997690c3397a
child 42 b72428996822
equal deleted inserted replaced
31:a0ea99b6fa53 32:19bd632b5100
       
     1 /*
       
     2 * Copyright (c) 2002-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:  Service starter implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "BTServiceStarter.h"
       
    22 #include "BTSUDebug.h"
       
    23 #include "BTSOPPController.h"
       
    24 #include "BTSBIPController.h"
       
    25 #include "BTSBPPController.h"
       
    26 
       
    27 #include <Obexutils.rsg>
       
    28 #include <obexutilsuilayer.h>
       
    29 #include <obexutilsmessagehandler.h>
       
    30 #include <btnotif.h>
       
    31 #include <featmgr.h>
       
    32 #include "BTSProgresstimer.h"
       
    33 #include <hbdevicenotificationdialogsymbian.h>
       
    34 #include <btservices/bluetoothdevicedialogs.h>
       
    35 
       
    36 // CONSTANTS
       
    37 
       
    38 // From BT SIG - Assigned numbers
       
    39 const TUint KBTServiceOPPSending        = 0x1105;
       
    40 const TUint KBTServiceDirectPrinting    = 0x1118;
       
    41 const TUint KBTServiceImagingResponder  = 0x111B;
       
    42 
       
    43 const TUint KBTProgressInterval         = 1000000;
       
    44 
       
    45 
       
    46 _LIT(KSendingDialog,"com.nokia.hb.btdevicedialog/1.0");
       
    47 
       
    48 // ============================ MEMBER FUNCTIONS ===============================
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CBTServiceStarter::CBTServiceStarter
       
    52 // C++ default constructor can NOT contain any code, that
       
    53 // might leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CBTServiceStarter::CBTServiceStarter() 
       
    57     : CActive( CActive::EPriorityStandard ),
       
    58       iBTEngDiscovery(NULL),
       
    59       iService( EBTSendingService ),
       
    60       iServiceStarted( EFalse ),
       
    61       iMessageServerIndex(0),
       
    62       iBytesSendWithBIP(0),
       
    63       iProgressDialogActive(EFalse),
       
    64       iUserCancel(EFalse), 
       
    65       iFeatureManagerInitialized(EFalse),
       
    66       iTriedBIP(EFalse),
       
    67       iTriedOPP(EFalse)
       
    68     {    
       
    69     CActiveScheduler::Add( this );
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CBTServiceStarter::ConstructL
       
    74 // Symbian 2nd phase constructor can leave.
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 void CBTServiceStarter::ConstructL()
       
    78     {
       
    79     FLOG(_L("[BTSU]\t CBTServiceStarter::ConstructL()"));
       
    80     iDevice = CBTDevice::NewL();
       
    81 //    iDialog = CObexUtilsDialog::NewL( this );
       
    82     iDeviceDialog = CHbDeviceDialogSymbian::NewL();
       
    83     iProgressDialog = CHbDeviceProgressDialogSymbian::NewL(CHbDeviceProgressDialogSymbian::EWaitDialog,this);
       
    84     
       
    85     FeatureManager::InitializeLibL();
       
    86     iFeatureManagerInitialized = ETrue;
       
    87     FLOG(_L("[BTSU]\t CBTServiceStarter::ConstructL() completed"));
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CBTServiceStarter::NewL
       
    92 // Two-phased constructor.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 CBTServiceStarter* CBTServiceStarter::NewL()
       
    96     {
       
    97     CBTServiceStarter* self = new( ELeave ) CBTServiceStarter();
       
    98     CleanupStack::PushL( self );
       
    99     self->ConstructL();
       
   100     CleanupStack::Pop();
       
   101     return self;
       
   102     }
       
   103 
       
   104 CBTServiceStarter::~CBTServiceStarter()
       
   105     {
       
   106     FLOG(_L("[BTSU]\t CBTServiceStarter::Destructor()"));
       
   107     if ( iMessageServerIndex != 0 )
       
   108         {
       
   109         TRAPD( notUsedRetVal, TObexUtilsMessageHandler::DeleteOutboxEntryL( iMessageServerIndex ) );
       
   110         notUsedRetVal=notUsedRetVal;
       
   111         FTRACE(FPrint(_L("[BTSU]\t ~CBTServiceStarter() delete ob entry %d"), notUsedRetVal ) );
       
   112         }
       
   113     StopTransfer(KErrCancel); // Cancels active object
       
   114     
       
   115     delete iList;
       
   116     delete iDevice;
       
   117 
       
   118     delete iController;
       
   119     delete iBTEngDiscovery;
       
   120  //   delete iDialog;
       
   121     delete iDeviceDialog;
       
   122     delete iProgressDialog;
       
   123     if(iProgressTimer)
       
   124         {
       
   125         delete iProgressTimer;
       
   126         }
       
   127 
       
   128     if(iWaiter && iWaiter->IsStarted() )
       
   129         {
       
   130         iWaiter->AsyncStop();
       
   131         }
       
   132     delete iBTEngSettings;
       
   133     
       
   134     if ( iFeatureManagerInitialized )
       
   135         {
       
   136         FeatureManager::UnInitializeLib();
       
   137         }
       
   138     
       
   139     FLOG(_L("[BTSU]\t CBTServiceStarter::Destructor() completed"));
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CBTServiceStarter::StartServiceL
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 void CBTServiceStarter::StartServiceL( TBTServiceType aService, 
       
   147                                        CBTServiceParameterList* aList,
       
   148                                        CActiveSchedulerWait* aWaiter )
       
   149     {
       
   150     FLOG(_L("[BTSU]\t CBTServiceStarter::StartServiceL()"));
       
   151    
       
   152 	// Delete old list and take ownership of the new one
       
   153     //
       
   154 	
       
   155 	delete iList;
       
   156 	iList = aList;
       
   157 
       
   158     if ( iServiceStarted )
       
   159         {
       
   160         User::Leave( KErrInUse );
       
   161         }
       
   162     if ( !ValidParameters( aService, aList ) )
       
   163         {
       
   164         User::Leave( KErrArgument );
       
   165         }	
       
   166     
       
   167     // Store the waiter pointer, a NULL value is also accepted
       
   168     //
       
   169     iWaiter = aWaiter;
       
   170 
       
   171     // Store the requested service
       
   172     //
       
   173     iService = aService;
       
   174 
       
   175     if( !iBTEngSettings )
       
   176         {
       
   177         iBTEngSettings = CBTEngSettings::NewL( this );
       
   178         }
       
   179     TBTPowerStateValue power = EBTPowerOff;
       
   180     User::LeaveIfError( iBTEngSettings->GetPowerState( power ) );
       
   181     TBool offline = EFalse;
       
   182     if( !power )
       
   183         {
       
   184         //offline = CheckOfflineModeL();
       
   185          offline = EFalse;
       
   186         }
       
   187     if( !offline )
       
   188         {
       
   189         FLOG(_L("[BTSU]\t CBTServiceStarter::StartServiceL() Phone is online, request temporary power on."));
       
   190 		TurnBTPowerOnL( power );
       
   191         }
       
   192 
       
   193     FLOG(_L("[BTSU]\t CBTServiceStarter::StartServiceL() completed"));
       
   194     }
       
   195     
       
   196 
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CBTServiceStarter::ControllerComplete
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void CBTServiceStarter::ControllerComplete( TInt aStatus )
       
   203     {
       
   204     FLOG(_L("[BTSU]\t CBTServiceStarter::ControllerComplete()"));    
       
   205     TInt error;
       
   206     if ( iAllSend ) //stop transfer if everything is send
       
   207         {
       
   208         StopTransfer( aStatus );	      	        
       
   209         return;    
       
   210         }
       
   211     if(( aStatus==KErrNone || aStatus==EBTSNoError ) && 
       
   212         iState == EBTSStarterFindingBIP )
       
   213         {
       
   214         iBytesSendWithBIP=0;
       
   215         if( iProgressGetter )
       
   216             {
       
   217             iBytesSendWithBIP=iProgressGetter->GetProgressStatus();
       
   218             iProgressGetter=NULL;
       
   219             delete iController; 
       
   220             iController = NULL;            
       
   221             }
       
   222         if ( !iBTEngDiscovery )
       
   223             {
       
   224             TRAPD(err, iBTEngDiscovery = CBTEngDiscovery::NewL(this) );
       
   225             if (err != KErrNone )
       
   226                 {
       
   227                 StopTransfer(EBTSPuttingFailed);	      	
       
   228                 return;
       
   229                 }
       
   230             }
       
   231         error=iBTEngDiscovery->RemoteProtocolChannelQuery(iDevice->BDAddr(),
       
   232                                TUUID(KBTServiceOPPSending));	                 
       
   233         if( error == KErrNone )
       
   234 	      	{
       
   235 	      	iState = EBTSStarterFindingOPP;	
       
   236         	}
       
   237         else
       
   238         	{
       
   239         	StopTransfer(EBTSPuttingFailed);	      	
       
   240        		}		                           
       
   241         }
       
   242     else
       
   243         {
       
   244         StopTransfer( aStatus );	      	        
       
   245         }   
       
   246     FLOG(_L("[BTSU]\t CBTServiceStarter::ControllerComplete() completed"));
       
   247     }
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CBTServiceStarter::GetProgressStatus
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 TInt CBTServiceStarter::GetProgressStatus()
       
   254     {    
       
   255     if ( iProgressGetter )
       
   256         {
       
   257         return iProgressGetter->GetProgressStatus()+iBytesSendWithBIP;       
       
   258         }
       
   259     else
       
   260         {
       
   261         return iBytesSendWithBIP;
       
   262         }
       
   263     }
       
   264 
       
   265 void CBTServiceStarter::UpdateProgressInfoL()
       
   266     {
       
   267     HBufC* key = HBufC::NewL(50);
       
   268     CleanupStack::PushL(key);
       
   269    
       
   270     HBufC* value = HBufC::NewL(50);
       
   271     CleanupStack::PushL(value);
       
   272     
       
   273     CHbSymbianVariantMap* map = CHbSymbianVariantMap::NewL();
       
   274     CleanupStack::PushL(map);
       
   275     
       
   276     TInt progress = GetProgressStatus();
       
   277     
       
   278     key->Des().Copy(_L("progressValue"));
       
   279     CHbSymbianVariant* progressvalue = CHbSymbianVariant::NewL(&progress, CHbSymbianVariant::EInt);
       
   280     map->Add(*key,progressvalue);
       
   281     
       
   282     key->Des().Copy(_L("currentFileIdx"));
       
   283     value->Des().AppendNum(iFileIndex);
       
   284     CHbSymbianVariant* currentFileIdx = CHbSymbianVariant::NewL(value, CHbSymbianVariant::EDes);
       
   285     map->Add(*key,currentFileIdx);
       
   286 
       
   287     
       
   288     TInt ret = iDeviceDialog->Update(*map);
       
   289     
       
   290     CleanupStack::PopAndDestroy(map);
       
   291     CleanupStack::PopAndDestroy(value);            
       
   292     CleanupStack::PopAndDestroy(key);
       
   293     
       
   294     
       
   295     if ( iProgressTimer )
       
   296         {
       
   297         iProgressTimer->Tickle();
       
   298         }
       
   299     }
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // CBTServiceStarter::ValidParameters
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 TBool CBTServiceStarter::ValidParameters( 
       
   306     TBTServiceType aService, const CBTServiceParameterList* aList) const
       
   307     {
       
   308     FLOG(_L("[BTSU]\t CBTServiceStarter::ValidParameters()"));
       
   309 
       
   310     TBool result = EFalse;
       
   311 
       
   312     if ( aList != NULL )
       
   313         {
       
   314         switch ( aService )
       
   315             {
       
   316             case EBTSendingService:
       
   317                 {
       
   318                 // Sending service must have object or image parameters
       
   319                 //
       
   320                 if ( aList->ObjectCount() > 0 || aList->ImageCount() > 0 )
       
   321                     {
       
   322                     result = ETrue;
       
   323                     }
       
   324                 break;
       
   325                 }
       
   326             case EBTPrintingService:
       
   327                 {
       
   328                 // Printing service must have xhtml parameters
       
   329                 //
       
   330                 if ( aList->XhtmlCount() > 0 )
       
   331                     {
       
   332                     result = ETrue;
       
   333                     }       
       
   334                 break;
       
   335                 }
       
   336             case EBTObjectPushService:
       
   337                 {
       
   338                 // Sending service must have object or image parameters
       
   339                 //
       
   340                 if ( aList->ObjectCount() > 0 || aList->ImageCount() > 0 )
       
   341                     {
       
   342                     result = ETrue;
       
   343                     }      
       
   344                 break;
       
   345                 }
       
   346             default:
       
   347                 {
       
   348                 result = EFalse;
       
   349                 break;
       
   350                 }
       
   351             }
       
   352         }
       
   353     FTRACE(FPrint(_L("[BTSU]\t CBTServiceStarter::ValidParameters() completed with %d"), result ) );
       
   354 
       
   355     return result;
       
   356     }
       
   357 
       
   358 // -----------------------------------------------------------------------------
       
   359 // CBTServiceStarter::StartProfileSelectL
       
   360 // -----------------------------------------------------------------------------
       
   361 //
       
   362 void CBTServiceStarter::StartProfileSelectL( TBTServiceType aService )
       
   363     {
       
   364     FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileSelectL()"));    
       
   365     LaunchWaitNoteL();   
       
   366     iAllSend=EFalse;  
       
   367     iSendToBIPOnlyDevice = EFalse;
       
   368     
       
   369     if ( !iBTEngDiscovery )
       
   370         {
       
   371         iBTEngDiscovery = CBTEngDiscovery::NewL(this);
       
   372         }
       
   373     
       
   374     if ( !FeatureManager::FeatureSupported( KFeatureIdBtImagingProfile ) && (aService != EBTPrintingService) )
       
   375         {
       
   376         // If BTimagingProfile is disabled, use OPP instead.
       
   377         User::LeaveIfError( iBTEngDiscovery->RemoteProtocolChannelQuery(iDevice->BDAddr(), 
       
   378                                                                                        TUUID(KBTServiceOPPSending)));
       
   379         iState = EBTSStarterFindingOPP;  
       
   380         return;
       
   381         }
       
   382     
       
   383     switch ( aService  )
       
   384         {
       
   385         case EBTSendingService: // Find OPP
       
   386             {            
       
   387             if ( iList->ObjectCount() > 0 )  // We try to send files with OPP profile as long as it contains non-bip objects
       
   388                 {
       
   389                 FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileSelectL() OPP"));    
       
   390                 User::LeaveIfError( iBTEngDiscovery->RemoteProtocolChannelQuery(iDevice->BDAddr(), 
       
   391                                                                                 TUUID(KBTServiceOPPSending)));
       
   392                 iState = EBTSStarterFindingOPP;          
       
   393                 }
       
   394             else if(iList->ObjectCount() == 0 && iList->ImageCount() > 0)
       
   395                 {
       
   396                 FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileSelectL() BIP")); 
       
   397                 User::LeaveIfError( iBTEngDiscovery->RemoteProtocolChannelQuery(iDevice->BDAddr(),
       
   398                                                                                 TUUID(KBTServiceImagingResponder)));
       
   399                 iState = EBTSStarterFindingBIP;
       
   400                 }
       
   401             break;
       
   402             }
       
   403         case EBTPrintingService: // Find BPP
       
   404             {
       
   405             FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileSelectL() BPP"));
       
   406             User::LeaveIfError( iBTEngDiscovery->RemoteProtocolChannelQuery(iDevice->BDAddr(),
       
   407                 TUUID(KBTServiceDirectPrinting)));
       
   408             iState = EBTSStarterFindingBPP;            
       
   409             break;
       
   410             }
       
   411         case EBTObjectPushService: // Find BIP
       
   412             {
       
   413             FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileSelectL() BIP"));
       
   414             User::LeaveIfError( iBTEngDiscovery->RemoteProtocolChannelQuery(iDevice->BDAddr(),
       
   415                 TUUID(KBTServiceOPPSending)));
       
   416             iState = EBTSStarterFindingOPP;            
       
   417             break;
       
   418             }
       
   419         default:
       
   420             {
       
   421             FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileSelectL() ERROR, unhandled case"));            
       
   422             break;
       
   423             }
       
   424         }
       
   425 
       
   426     FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileSelectL() completed"));
       
   427     }
       
   428     
       
   429 
       
   430 // -----------------------------------------------------------------------------
       
   431 // CBTServiceStarter::StartProfileL
       
   432 // -----------------------------------------------------------------------------
       
   433 //
       
   434 void CBTServiceStarter::StartProfileL( TBTServiceProfile aProfile )
       
   435     {
       
   436     FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileL()"));
       
   437 
       
   438     switch ( aProfile )
       
   439         {
       
   440         case EBTSBPP:
       
   441             {            
       
   442             iController = CBTSBPPController::NewL( this, iClientChannel, 
       
   443                                                    iDevice->BDAddr(), iList,
       
   444                                                    iBTEngDiscovery );
       
   445             break;
       
   446             }
       
   447         case EBTSOPP:
       
   448             {
       
   449             iController = CBTSOPPController::NewL( this, iClientChannel, 
       
   450                                                    iDevice->BDAddr(), iList );
       
   451             break;
       
   452             }
       
   453         case EBTSBIP:
       
   454             {
       
   455             iController = CBTSBIPController::NewL( this, iClientChannel, 
       
   456                                                    iDevice->BDAddr(), iList );
       
   457             break;
       
   458             }
       
   459         case EBTSNone:
       
   460         default:
       
   461             {
       
   462             FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileL() ERROR, unhandled case"));            
       
   463             break;
       
   464             }
       
   465         }
       
   466 
       
   467     FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileL() completed"));
       
   468     }
       
   469 
       
   470 // -----------------------------------------------------------------------------
       
   471 // CBTServiceStarter::LaunchWaitNoteL
       
   472 // -----------------------------------------------------------------------------
       
   473 //
       
   474 void CBTServiceStarter::LaunchWaitNoteL()
       
   475     {
       
   476     FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchWaitNoteL()"));
       
   477     if ( iService == EBTPrintingService )
       
   478         {
       
   479  //       iDialog->LaunchWaitDialogL( R_BT_PRINTING_WAIT_NOTE );
       
   480         }
       
   481     else
       
   482         {
       
   483         //       iDialog->LaunchWaitDialogL( R_BT_CONNECTING_WAIT_NOTE );
       
   484         _LIT(KConnectText, "Connecting...");
       
   485         iProgressDialog->SetTextL(KConnectText);
       
   486         iProgressDialog->ShowL();
       
   487         
       
   488         }    
       
   489     FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchWaitNoteL() completed"));
       
   490     }
       
   491 
       
   492 // -----------------------------------------------------------------------------
       
   493 // CBTServiceStarter::CancelWaitNote
       
   494 // -----------------------------------------------------------------------------
       
   495 //
       
   496 void CBTServiceStarter::CancelWaitNote()
       
   497     {
       
   498     FLOG(_L("[BTSU]\t CBTServiceStarter::CancelWaitNote()"));
       
   499 
       
   500   //  if ( iDialog )
       
   501   //      {
       
   502         //       TRAP_IGNORE( iDialog->CancelWaitDialogL() );
       
   503         if(iProgressDialog)
       
   504             {
       
   505             //This has to be tested
       
   506             iProgressDialog->Close();
       
   507             }
       
   508     //    }
       
   509 
       
   510     FLOG(_L("[BTSU]\t CBTServiceStarter::CancelWaitNote() completed"));
       
   511     }
       
   512 
       
   513 
       
   514 // -----------------------------------------------------------------------------
       
   515 // CBTServiceStarter::LaunchProgressNoteL
       
   516 // -----------------------------------------------------------------------------
       
   517 //
       
   518 void CBTServiceStarter::LaunchProgressNoteL( MBTServiceProgressGetter* aGetter,
       
   519                                              TInt aTotalSize, TInt aFileCount)
       
   520     {
       
   521     FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchProgressNoteL()"));
       
   522     (void) aTotalSize;
       
   523     
       
   524     if ( iService != EBTPrintingService )
       
   525         {    
       
   526         iProgressGetter = aGetter;     
       
   527         CancelWaitNote();        
       
   528         
       
   529         if ( !iProgressDialogActive )
       
   530         	{
       
   531             iFileCount = aFileCount;
       
   532         	iMessageServerIndex = TObexUtilsMessageHandler::CreateOutboxEntryL( 
       
   533             KUidMsgTypeBt, R_BT_SEND_OUTBOX_SENDING );        
       
   534    //     	iDialog->LaunchProgressDialogL( this, aTotalSize, 
       
   535      //        								R_BT_SENDING_DATA, KBTProgressInterval );	
       
   536             CHbSymbianVariantMap* map = CHbSymbianVariantMap::NewL();
       
   537             CleanupStack::PushL(map);
       
   538             if ( iProgressTimer )
       
   539                 {
       
   540                 iProgressTimer->Cancel();
       
   541                 delete iProgressTimer;
       
   542                 iProgressTimer = NULL;
       
   543                 }
       
   544 
       
   545             iProgressTimer = CBTSProgressTimer::NewL( this );
       
   546             iProgressTimer->SetTimeout( KBTProgressInterval );
       
   547             
       
   548             iProgressTimer->Tickle();
       
   549 
       
   550             CHbSymbianVariant* value = NULL;
       
   551             TBuf<6> key;
       
   552             TInt data = TBluetoothDialogParams::ESend;
       
   553             key.Num(TBluetoothDialogParams::EDialogType);
       
   554             value = CHbSymbianVariant::NewL( (TAny*) &data, CHbSymbianVariant::EInt );
       
   555             User::LeaveIfError(map->Add( key, value ));   // Takes ownership of value
       
   556             iDeviceDialog->Show(KSendingDialog(),*map,this);
       
   557             CleanupStack::PopAndDestroy(map);
       
   558         	}        
       
   559         iProgressDialogActive=ETrue;     
       
   560         }
       
   561 
       
   562     FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchProgressNoteL() completed"));
       
   563     }
       
   564 
       
   565 void CBTServiceStarter::UpdateProgressNoteL(TInt aFileSize,TInt aFileIndex, const TDesC& aFileName )
       
   566     {
       
   567     HBufC* key = HBufC::NewL(50);
       
   568     CleanupStack::PushL(key);
       
   569    
       
   570     HBufC* value = HBufC::NewL(50);
       
   571     CleanupStack::PushL(value);
       
   572     
       
   573     CHbSymbianVariantMap* map = CHbSymbianVariantMap::NewL();
       
   574     CleanupStack::PushL(map);
       
   575     
       
   576     iFileIndex = aFileIndex+1;
       
   577     key->Des().Copy(_L("currentFileIdx"));
       
   578     value->Des().AppendNum(aFileIndex+1);
       
   579     CHbSymbianVariant* currentFileIdx = CHbSymbianVariant::NewL(value, CHbSymbianVariant::EDes);
       
   580     map->Add(*key,currentFileIdx);
       
   581     
       
   582     key->Des().Copy(_L("totalFilesCnt"));
       
   583     value->Des().Zero();
       
   584     value->Des().AppendNum(iFileCount);
       
   585     CHbSymbianVariant* totalFilesCnt = CHbSymbianVariant::NewL(value, CHbSymbianVariant::EDes);
       
   586     map->Add(*key,totalFilesCnt);
       
   587 
       
   588     
       
   589     key->Des().Copy(_L("destinationName"));
       
   590     if ( iDevice->IsValidFriendlyName() )
       
   591         {
       
   592         value->Des().Copy( iDevice->FriendlyName() );
       
   593         }
       
   594     else 
       
   595         {
       
   596         value->Des().Copy( BTDeviceNameConverter::ToUnicodeL(iDevice->DeviceName()));
       
   597         }
       
   598 
       
   599     CHbSymbianVariant* destinationName = CHbSymbianVariant::NewL(value, CHbSymbianVariant::EDes);
       
   600     map->Add(*key,destinationName);
       
   601     
       
   602     key->Des().Copy(_L("fileName"));
       
   603     value->Des().Copy(aFileName);
       
   604     CHbSymbianVariant* fileName = CHbSymbianVariant::NewL(value, CHbSymbianVariant::EDes);
       
   605     map->Add(*key,fileName);
       
   606     
       
   607     key->Des().Copy(_L("fileSzTxt"));
       
   608     value->Des().Zero();
       
   609     if(aFileSize < 1024)
       
   610         {
       
   611         value->Des().AppendNum(aFileSize);
       
   612         value->Des().Append(_L(" Bytes"));
       
   613         }
       
   614     else
       
   615         {
       
   616         TInt filesize =  aFileSize/1024;
       
   617         value->Des().AppendNum(filesize);
       
   618         value->Des().Append(_L(" KB"));
       
   619         }
       
   620 
       
   621     CHbSymbianVariant* fileSzTxt = CHbSymbianVariant::NewL(value, CHbSymbianVariant::EDes);
       
   622     map->Add(*key,fileSzTxt);
       
   623     
       
   624     
       
   625     key->Des().Copy(_L("fileSz"));
       
   626     CHbSymbianVariant* fileSz = CHbSymbianVariant::NewL(&aFileSize, CHbSymbianVariant::EInt);
       
   627     map->Add(*key,fileSz);
       
   628 
       
   629 
       
   630     
       
   631     TInt ret = iDeviceDialog->Update(*map);
       
   632     CleanupStack::PopAndDestroy(map);
       
   633     CleanupStack::PopAndDestroy(value);            
       
   634     CleanupStack::PopAndDestroy(key);
       
   635     }
       
   636 // -----------------------------------------------------------------------------
       
   637 // CBTServiceStarter::CancelProgressNote
       
   638 // -----------------------------------------------------------------------------
       
   639 //
       
   640 void CBTServiceStarter::CancelProgressNote()
       
   641     {
       
   642     FLOG(_L("[BTSU]\t CBTServiceStarter::CancelProgressNote()"));
       
   643 
       
   644  //   if ( iDialog )
       
   645         {
       
   646   //      TRAP_IGNORE( iDialog->CancelProgressDialogL() );
       
   647     if ( iProgressTimer )
       
   648          {
       
   649          iProgressTimer->Cancel();
       
   650          delete iProgressTimer;
       
   651          iProgressTimer = NULL;
       
   652          }
       
   653         }
       
   654     if(iDeviceDialog)
       
   655          {
       
   656          iDeviceDialog->Cancel();
       
   657          }
       
   658     }
       
   659 
       
   660 // -----------------------------------------------------------------------------
       
   661 // CBTServiceStarter::DialogDismissed
       
   662 // -----------------------------------------------------------------------------
       
   663 //
       
   664 void CBTServiceStarter::DialogDismissed( TInt aButtonId )
       
   665     {
       
   666     FLOG(_L("[BTSU]\t CBTServiceStarter::DialogDismissed()"));   
       
   667     if( aButtonId == EAknSoftkeyCancel )
       
   668         {
       
   669         FLOG(_L("[BTSU]\t CBTServiceStarter::DialogDissmissed(), cancelled by user"));        
       
   670         iUserCancel=ETrue;
       
   671         if ( iController )
       
   672             {
       
   673             iController->Abort();
       
   674             }
       
   675         else 
       
   676            {
       
   677            StopTransfer(KErrCancel);
       
   678            }    
       
   679         }
       
   680     else if ( aButtonId == EAknSoftkeyNo )
       
   681         {
       
   682         // user abortion
       
   683         //
       
   684         iUserCancel = ETrue;
       
   685         StopTransfer( KErrCancel );
       
   686         }
       
   687     FLOG(_L("[BTSU]\t CBTServiceStarter::DialogDismissed() completed"));
       
   688     }
       
   689 
       
   690 // -----------------------------------------------------------------------------
       
   691 // CBTServiceStarter::ShowNote
       
   692 // -----------------------------------------------------------------------------
       
   693 //
       
   694 void CBTServiceStarter::ShowNote( TInt aReason ) const
       
   695     {
       
   696     FLOG(_L("[BTSU]\t CBTServiceStarter::ShowNote()"));
       
   697      
       
   698 //    TInt resource = 0;
       
   699     TBuf<255> buf;
       
   700 
       
   701     switch ( aReason )
       
   702         {
       
   703         case EBTSNoError:
       
   704             {
       
   705     /*        if ( iService == EBTPrintingService )
       
   706                 {
       
   707                // resource = R_BT_DATA_SENT2;
       
   708                 
       
   709                 _LIT(KText, "Data Sent");
       
   710                 buf.Copy(KText);
       
   711                 }
       
   712             else
       
   713                 {
       
   714                 //resource = R_BT_DATA_SENT;*/
       
   715                 _LIT(KText, "All files Sent to ");
       
   716                 buf.Copy(KText);
       
   717                 if ( iDevice->IsValidFriendlyName() )
       
   718                     {
       
   719                     buf.Append( iDevice->FriendlyName() );
       
   720                     }
       
   721                 else 
       
   722                     {
       
   723                    TRAP_IGNORE( buf.Append( BTDeviceNameConverter::ToUnicodeL(iDevice->DeviceName())));
       
   724                     }
       
   725 
       
   726 
       
   727 //                }
       
   728             break;
       
   729             }
       
   730         case EBTSConnectingFailed:
       
   731             {
       
   732             //resource = R_BT_DEV_NOT_AVAIL;
       
   733             _LIT(KText, "Cannot establish Bluetooth connection");
       
   734             buf.Copy(KText);
       
   735             break;
       
   736             }
       
   737         case EBTSGettingFailed:
       
   738         case EBTSPuttingFailed:
       
   739             {
       
   740             if ( iService == EBTPrintingService )
       
   741                 {
       
   742                 _LIT(KText, "Sending failed");
       
   743                 //resource = R_BT_FAILED_TO_SEND2;
       
   744                 buf.Copy(KText);
       
   745                 }
       
   746             else
       
   747                 {
       
   748                 _LIT(KText, "Failed to send Data");
       
   749                 //resource = R_BT_FAILED_TO_SEND;
       
   750                 buf.Copy(KText);
       
   751                 }
       
   752             break;
       
   753             }
       
   754         case EBTSNoSuitableProfiles:
       
   755             {
       
   756             if ( iService == EBTPrintingService )
       
   757                 {
       
   758                 _LIT(KText, "Printer not supported");
       
   759                 buf.Copy(KText);
       
   760             //    resource = R_BT_PRINTING_NOT_SUPPORTED;
       
   761                 }
       
   762             else
       
   763                 {
       
   764                 _LIT(KText, "Failed to send Data");
       
   765                 buf.Copy(KText);
       
   766          //       resource = R_BT_FAILED_TO_SEND;
       
   767                 }
       
   768             break;
       
   769             }
       
   770         case EBTSBIPSomeSend:
       
   771         	{
       
   772         	_LIT(KText, "Failed to send Data");
       
   773         	 buf.Copy(KText);
       
   774         	//resource = R_BT_FAILED_TO_SEND;
       
   775         	break;	
       
   776         	}    
       
   777         case EBTSBIPOneNotSend:
       
   778         	{
       
   779         	_LIT(KText, "Receiving device does not support this image format.");
       
   780         	 buf.Copy(KText);
       
   781         	//resource = R_BT_NOT_RECEIVE_ONE;
       
   782         	break;
       
   783         	}
       
   784         case EBTSBIPNoneSend:
       
   785         	{
       
   786         	_LIT(KText, "Receiving device does not support the needed image formats.");
       
   787         	 buf.Copy(KText);
       
   788         	//resource = R_BT_NOT_RECEIVE_ANY;
       
   789         	break;
       
   790         	}	
       
   791         default:
       
   792             {            
       
   793            // resource = R_BT_DEV_NOT_AVAIL;
       
   794             _LIT(KText, "Cannot establish Bluetooth connection");
       
   795             buf.Copy(KText);
       
   796             break;
       
   797             }
       
   798         }        
       
   799     
       
   800 //	TRAP_IGNORE(TObexUtilsUiLayer::ShowInformationNoteL( resource ) );	
       
   801 //    CHbDeviceMessageBoxSymbian::InformationL(buf);
       
   802       TRAP_IGNORE(CHbDeviceNotificationDialogSymbian::NotificationL(KNullDesC, buf, KNullDesC));
       
   803     FLOG(_L("[BTSU]\t CBTServiceStarter::ShowNote() completed"));
       
   804     }
       
   805 
       
   806 // -----------------------------------------------------------------------------
       
   807 // CBTServiceStarter::LaunchConfirmationQuery
       
   808 // -----------------------------------------------------------------------------
       
   809 //
       
   810 TInt CBTServiceStarter::LaunchConfirmationQuery(TInt /*aResourceId*/)
       
   811 	{
       
   812 	TInt keypress=0;
       
   813 //	TRAP_IGNORE( keypress = iDialog->LaunchQueryDialogL(  aResourceId ));	
       
   814 	if ( !keypress )
       
   815 		{
       
   816 		FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchConfirmationQuery(), cancelled by user"));
       
   817 		DialogDismissed(EAknSoftkeyNo);
       
   818 		CancelWaitNote();		
       
   819 		}   		
       
   820 	return keypress;
       
   821 	}
       
   822 
       
   823 // -----------------------------------------------------------------------------
       
   824 // CBTServiceStarter::StopTransfer
       
   825 // -----------------------------------------------------------------------------
       
   826 //	
       
   827 void CBTServiceStarter::StopTransfer(TInt aError)
       
   828 	{
       
   829       
       
   830 	FLOG(_L("[BTSU]\t CBTServiceStarter::StopTransfer()"));
       
   831     Cancel();
       
   832 	if( !iUserCancel )
       
   833 	    {
       
   834 	    CancelWaitNote();
       
   835         CancelProgressNote();
       
   836 	
       
   837         if ( aError != KErrCancel )
       
   838             {
       
   839             ShowNote( aError );
       
   840             }     
       
   841         }
       
   842     if ( iMessageServerIndex != 0 )
       
   843         {                 
       
   844         TRAPD( notUsedRetVal, TObexUtilsMessageHandler::DeleteOutboxEntryL( iMessageServerIndex ) );
       
   845         notUsedRetVal=notUsedRetVal;
       
   846         iMessageServerIndex=0;
       
   847         FTRACE(FPrint(_L("[BTSU]\t CBTServiceStarter::StopTransfer() delete ob entry %d"), notUsedRetVal ) );
       
   848         }
       
   849     // Release resources
       
   850     //
       
   851     if ( iList )
       
   852         {
       
   853         delete iList;
       
   854         iList = NULL;    
       
   855         }
       
   856         
       
   857     if ( iController )
       
   858         {
       
   859         delete iController; 
       
   860         iController = NULL;
       
   861         }
       
   862     
       
   863     if ( iNotifier.Handle() )
       
   864         {
       
   865         iNotifier.Close();
       
   866         }
       
   867 
       
   868     // Reset states
       
   869     //
       
   870     iServiceStarted = EFalse;
       
   871     if ( iWaiter && iWaiter->IsStarted() )
       
   872         {                
       
   873         iWaiter->AsyncStop();                    
       
   874         }    
       
   875         
       
   876     iState = EBTSStarterStoppingService;	    
       
   877 	}
       
   878 	
       
   879 // -----------------------------------------------------------------------------
       
   880 // CBTServiceStarter::ConnectTimedOut()
       
   881 // -----------------------------------------------------------------------------
       
   882 //	
       
   883 void CBTServiceStarter::ConnectTimedOut()
       
   884     {
       
   885     FLOG(_L("[BTSU]\t CBTServiceStarter::ConnectTimedOut()"));            
       
   886     StopTransfer(EBTSConnectingFailed);    
       
   887     FLOG(_L("[BTSU]\t CBTServiceStarter::ConnectTimedOut() completed"));
       
   888     }
       
   889 // -----------------------------------------------------------------------------
       
   890 // CBTServiceStarter::ServiceSearchComplete()
       
   891 // -----------------------------------------------------------------------------
       
   892 //	
       
   893 void CBTServiceStarter::ServiceSearchComplete( const RSdpRecHandleArray& /*aResult*/, 
       
   894                                          TUint /*aTotalRecordsCount*/, TInt /*aErr */)
       
   895     {
       
   896     FLOG(_L("[BTSU]\t CBTServiceStarter::ServiceSearchComplete()"));        
       
   897     }
       
   898 
       
   899 // -----------------------------------------------------------------------------
       
   900 // CBTServiceStarter::AttributeSearchComplete()
       
   901 // -----------------------------------------------------------------------------
       
   902 //	
       
   903 void CBTServiceStarter::AttributeSearchComplete( TSdpServRecordHandle /*aHandle*/, 
       
   904                                            const RSdpResultArray& /*aAttr*/, 
       
   905                                            TInt /*aErr*/ )
       
   906     {
       
   907     FLOG(_L("[BTSU]\t CBTServiceStarter::AttributeSearchComplete()"));           
       
   908     }
       
   909 // -----------------------------------------------------------------------------
       
   910 // CBTServiceStarter::ServiceAttributeSearchComplete()
       
   911 // -----------------------------------------------------------------------------
       
   912 //	
       
   913 void CBTServiceStarter::ServiceAttributeSearchComplete( TSdpServRecordHandle /*aHandle*/, 
       
   914                                                           const RSdpResultArray& aAttr, 
       
   915                                                           TInt aErr )
       
   916     {
       
   917     FLOG(_L("[BTSU]\t CBTServiceStarter::ServiceAttributeSearchComplete()"));               
       
   918     TInt err = KErrNone;
       
   919     if (aErr==KErrEof && aAttr.Count()>0 )
       
   920         {            
       
   921         RSdpResultArray results=aAttr;    
       
   922         iBTEngDiscovery->ParseRfcommChannel(results,iClientChannel);          
       
   923 
       
   924         iBTEngDiscovery->CancelRemoteSdpQuery();
       
   925                
       
   926         switch (iState)
       
   927             {
       
   928             case EBTSStarterFindingBIP:
       
   929                 {
       
   930                 TRAP(err, StartProfileL( EBTSBIP ));  
       
   931                 iTriedBIP = ETrue;
       
   932                 if (err != KErrNone)
       
   933                     {
       
   934                     StopTransfer(EBTSConnectingFailed);        
       
   935                     }
       
   936                 if ( iSendToBIPOnlyDevice )
       
   937                     {
       
   938                     iAllSend = ETrue;
       
   939                     }
       
   940                 else
       
   941                     {
       
   942                     if(iList->ObjectCount() == 0)
       
   943                         {
       
   944                         iAllSend=ETrue;
       
   945                         }
       
   946                     }
       
   947                 break;
       
   948                 }
       
   949             case EBTSStarterFindingOPP:
       
   950                 {
       
   951                 TRAP(err, StartProfileL( EBTSOPP ) ); 
       
   952                 iTriedOPP = ETrue;
       
   953                 if (err != KErrNone)
       
   954                     {
       
   955                     StopTransfer(EBTSConnectingFailed);        
       
   956                     }
       
   957                 iAllSend=ETrue;  
       
   958                 break;
       
   959                 }            
       
   960             case EBTSStarterFindingBPP:          
       
   961                 {
       
   962                 TRAP(err, StartProfileL( EBTSBPP ));           
       
   963                 if (err != KErrNone)
       
   964                     {
       
   965                     StopTransfer(EBTSConnectingFailed);        
       
   966                     }               
       
   967                 break;    
       
   968                 }            
       
   969             }       
       
   970         }      
       
   971     else if ( aErr==KErrEof && aAttr.Count()==0 && 
       
   972               iState == EBTSStarterFindingBIP && !iTriedBIP )
       
   973         {
       
   974         iBTEngDiscovery->RemoteProtocolChannelQuery(iDevice->BDAddr(),TUUID(KBTServiceOPPSending));
       
   975         iState = EBTSStarterFindingOPP;    
       
   976 		iTriedBIP = ETrue;
       
   977         }    
       
   978     else if ( aErr==KErrEof && aAttr.Count()==0 &&
       
   979               iState == EBTSStarterFindingOPP && !iTriedOPP &&
       
   980               iList->ImageCount() > 0 &&
       
   981               FeatureManager::FeatureSupported( KFeatureIdBtImagingProfile ) )
       
   982         {
       
   983         iSendToBIPOnlyDevice = ETrue;
       
   984         iBTEngDiscovery->RemoteProtocolChannelQuery(iDevice->BDAddr(),TUUID(KBTServiceImagingResponder));
       
   985         iState = EBTSStarterFindingBIP;  
       
   986         iTriedOPP = ETrue;
       
   987         }
       
   988     else
       
   989         {
       
   990         delete iBTEngDiscovery;
       
   991         iBTEngDiscovery = NULL;    
       
   992         StopTransfer(EBTSConnectingFailed);    
       
   993         }    
       
   994     FLOG(_L("[BTSU]\t CBTServiceStarter::ServiceAttributeSearchComplete() done"));               
       
   995     }
       
   996 // -----------------------------------------------------------------------------
       
   997 // CBTServiceStarter::DeviceSearchComplete()
       
   998 // -----------------------------------------------------------------------------
       
   999 //	
       
  1000 void CBTServiceStarter::DeviceSearchComplete( CBTDevice* /*aDevice*/, TInt aErr )
       
  1001     {
       
  1002     FLOG(_L("[BTSU]\t CBTServiceStarter::DeviceSearchComplete()"));          
       
  1003     FTRACE(FPrint(_L("[BTSU]\t CBTServiceStarter DeviceSearchComplete()aErr = %d"), aErr) );     
       
  1004     if ( aErr == KErrNone )
       
  1005         {    
       
  1006         TRAPD(err, StartProfileSelectL( iService ));
       
  1007         if (err != KErrNone )
       
  1008             {
       
  1009             StopTransfer(err);            
       
  1010             }
       
  1011             
       
  1012         iServiceStarted = ETrue;
       
  1013         }
       
  1014     else
       
  1015         {
       
  1016         if ( aErr == KErrCancel )
       
  1017             {
       
  1018             iUserCancel=ETrue;
       
  1019             }
       
  1020         StopTransfer(aErr);    
       
  1021         }    
       
  1022     FLOG(_L("[BTSU]\t CBTServiceStarter::DeviceSearchComplete() done"));                   
       
  1023     }        
       
  1024 
       
  1025 // -----------------------------------------------------------------------------
       
  1026 // From class MBTEngSettingsObserver.
       
  1027 // Power has changed, start searching for BT devices.
       
  1028 // -----------------------------------------------------------------------------
       
  1029 //  
       
  1030 void CBTServiceStarter::PowerStateChanged( TBTPowerStateValue aState )
       
  1031     {
       
  1032 	FLOG(_L("[BTSU]\t CBTServiceStarter::PowerStateChanged()"));	
       
  1033     if( aState == EBTPowerOn && iWaitingForBTPower )
       
  1034         {
       
  1035         iWaitingForBTPower = EFalse;
       
  1036         TRAP_IGNORE( StartDiscoveryL() );
       
  1037         }
       
  1038 	FLOG(_L("[BTSU]\t CBTServiceStarter::PowerStateChanged() - completed"));
       
  1039     }
       
  1040 
       
  1041 
       
  1042 // -----------------------------------------------------------------------------
       
  1043 // From class MBTEngSettingsObserver.
       
  1044 // Visibility has changed, ignore event.
       
  1045 // -----------------------------------------------------------------------------
       
  1046 //  
       
  1047 void CBTServiceStarter::VisibilityModeChanged( TBTVisibilityMode aState )
       
  1048     {
       
  1049     (void) aState;
       
  1050     }
       
  1051 
       
  1052 // -----------------------------------------------------------------------------
       
  1053 // Check if the phone is in offline mode, and ask the user if it is.
       
  1054 // -----------------------------------------------------------------------------
       
  1055 //  
       
  1056 TBool CBTServiceStarter::CheckOfflineModeL()
       
  1057     {
       
  1058 	FLOG(_L("[BTSU]\t CBTServiceStarter::CheckOfflineModeL()"));	
       
  1059     TCoreAppUIsNetworkConnectionAllowed offline = ECoreAppUIsNetworkConnectionNotAllowed;
       
  1060     TBTEnabledInOfflineMode offlineAllowed = EBTDisabledInOfflineMode;
       
  1061     User::LeaveIfError( iBTEngSettings->GetOfflineModeSettings( offline, offlineAllowed ) );
       
  1062     if( offline == ECoreAppUIsNetworkConnectionNotAllowed && 
       
  1063          offlineAllowed == EBTEnabledInOfflineMode )
       
  1064         {
       
  1065         User::LeaveIfError( iNotifier.Connect() );
       
  1066         TBTGenericQueryNotiferParamsPckg pckg;
       
  1067         pckg().iMessageType = EBTActivateOffLineQuery;
       
  1068         pckg().iNameExists = EFalse;
       
  1069         iActiveNotifier = EOfflineQuery;
       
  1070         iNotifier.StartNotifierAndGetResponse( iStatus, KBTGenericQueryNotifierUid, 
       
  1071                                                 pckg, iOffline );
       
  1072         SetActive();
       
  1073         }
       
  1074     else if( offline == ECoreAppUIsNetworkConnectionNotAllowed && 
       
  1075             offlineAllowed == EBTDisabledInOfflineMode )
       
  1076            {
       
  1077            StopTransfer( KErrNotSupported );
       
  1078            }
       
  1079 	FLOG(_L("[BTSU]\t CBTServiceStarter::CheckOfflineModeL() - completed"));
       
  1080     return ( offline == ECoreAppUIsNetworkConnectionNotAllowed );
       
  1081     }
       
  1082 
       
  1083 
       
  1084 // -----------------------------------------------------------------------------
       
  1085 // Start BT device discovery.
       
  1086 // -----------------------------------------------------------------------------
       
  1087 //	
       
  1088 void CBTServiceStarter::StartDiscoveryL()
       
  1089     {
       
  1090 	FLOG(_L("[BTSU]\t CBTServiceStarter::StartDiscoveryL()"));	
       
  1091     if( !iBTEngDiscovery )
       
  1092         {
       
  1093         iBTEngDiscovery = CBTEngDiscovery::NewL(this);
       
  1094         }
       
  1095     TInt err = iBTEngDiscovery->SearchRemoteDevice(iDevice );
       
  1096     if( err )
       
  1097         {
       
  1098         StopTransfer( err );
       
  1099         }
       
  1100 	FLOG(_L("[BTSU]\t CBTServiceStarter::StartDiscoveryL() - completed"));		
       
  1101     }
       
  1102 
       
  1103 
       
  1104 // -----------------------------------------------------------------------------
       
  1105 // Turn BT on and start BT device discovery if possible.
       
  1106 // -----------------------------------------------------------------------------
       
  1107 //  
       
  1108 void CBTServiceStarter::TurnBTPowerOnL( const TBTPowerStateValue aState )
       
  1109     {
       
  1110 	FLOG( _L("[BTSU]\t CBTServiceStarter::TurnBTPowerOnL()") );
       
  1111 //    if (iName() != EFalse) 
       
  1112     	{
       
  1113     	if( !iBTEngSettings )
       
  1114 	        {
       
  1115 	        iBTEngSettings = CBTEngSettings::NewL( this );
       
  1116 	        }
       
  1117 	    TInt err = iBTEngSettings->ChangePowerStateTemporarily();
       
  1118 	    iWaitingForBTPower = ETrue;
       
  1119 	    if( err )
       
  1120 	        {
       
  1121 	        iWaitingForBTPower = EFalse;
       
  1122 	        StopTransfer( err );
       
  1123 	        }
       
  1124 	    else if( aState == EBTPowerOn )
       
  1125 	        {
       
  1126 	        // Power is already on, we just registered for turning it off if needed.
       
  1127 	        // Since there is no callback at this point (power is already on), start 
       
  1128 	        // searching straight away.
       
  1129 	        iWaitingForBTPower = EFalse;
       
  1130 	        StartDiscoveryL();
       
  1131 	        }
       
  1132     	}
       
  1133  /*   else
       
  1134     	{
       
  1135         if ( !iNotifier.Handle() )
       
  1136 	        {
       
  1137 			User::LeaveIfError( iNotifier.Connect() );
       
  1138 	        }
       
  1139 		TBTGenericQueryNotiferParamsPckg pckg;
       
  1140         pckg().iMessageType = EBTNameQuery;
       
  1141         pckg().iNameExists = EFalse;
       
  1142         iActiveNotifier = ENameQuery;
       
  1143         iNotifier.StartNotifierAndGetResponse( iStatus, KBTGenericQueryNotifierUid, 
       
  1144                                                   pckg, iName );
       
  1145         SetActive();
       
  1146     	}*/
       
  1147 	FLOG(_L("[BTSU]\t CBTServiceStarter::TurnBTPowerOnL() - completed"));
       
  1148     }
       
  1149 
       
  1150 
       
  1151 // ---------------------------------------------------------------------------
       
  1152 // From class CActive.
       
  1153 // Called by the active scheduler when the request has been cancelled.
       
  1154 // ---------------------------------------------------------------------------
       
  1155 //
       
  1156 void CBTServiceStarter::DoCancel()
       
  1157     {
       
  1158 	FLOG(_L("[BTSU]\t CBTServiceStarter::DoCancel()"));
       
  1159     iNotifier.CancelNotifier( KBTGenericQueryNotifierUid );
       
  1160     iNotifier.Close();
       
  1161 	FLOG(_L("[BTSU]\t CBTServiceStarter::DoCancel() - completed"));
       
  1162     }
       
  1163 
       
  1164 
       
  1165 // ---------------------------------------------------------------------------
       
  1166 // From class CActive.
       
  1167 // Called by the active scheduler when the request has been completed.
       
  1168 // ---------------------------------------------------------------------------
       
  1169 //
       
  1170 void CBTServiceStarter::RunL()
       
  1171     {
       
  1172 	FLOG(_L("[BTSU]\t CBTServiceStarter::RunL()"));
       
  1173     TInt err = iStatus.Int();
       
  1174     if( !err )
       
  1175         {
       
  1176         if ( (iActiveNotifier == ENameQuery && iName() != EFalse ) || ( iActiveNotifier == EOfflineQuery && iOffline() != EFalse ) )
       
  1177             {
       
  1178             TBTPowerStateValue power = EBTPowerOff;
       
  1179             if ( iNotifier.Handle() )
       
  1180                 {
       
  1181                 iNotifier.Close();
       
  1182                 }
       
  1183             User::LeaveIfError( iBTEngSettings->GetPowerState( power ) );
       
  1184             TurnBTPowerOnL( power );
       
  1185             }
       
  1186         else
       
  1187             {
       
  1188             err = KErrCancel;
       
  1189             }    
       
  1190         }
       
  1191 
       
  1192     if( err )
       
  1193         {
       
  1194       
       
  1195         err = ( err == KErrNotSupported ? KErrCancel : err );
       
  1196         if ( iWaiter && err != KErrInUse && err != KErrCancel )
       
  1197             {
       
  1198             err = EBTSPuttingFailed;
       
  1199             }
       
  1200         StopTransfer( err );
       
  1201         }
       
  1202     
       
  1203     FLOG(_L("[BTSU]\t CBTServiceStarter::RunL() - completed"));	
       
  1204     }
       
  1205 
       
  1206 
       
  1207 // ---------------------------------------------------------------------------
       
  1208 // From class CActive.
       
  1209 // Called by the active scheduler when an error in RunL has occurred.
       
  1210 // ---------------------------------------------------------------------------
       
  1211 //
       
  1212 TInt CBTServiceStarter::RunError( TInt aError )
       
  1213     {
       
  1214 	FLOG(_L("[BTSU]\t CBTServiceStarter::RunError()"));
       
  1215     StopTransfer( aError );
       
  1216 	FLOG(_L("[BTSU]\t CBTServiceStarter::RunError() - completed"));
       
  1217     return KErrNone;
       
  1218     }
       
  1219 
       
  1220 
       
  1221 
       
  1222 
       
  1223 void CBTServiceStarter::ProgressDialogCancelled(const CHbDeviceProgressDialogSymbian*/*  aDialog*/)
       
  1224     {
       
  1225     FLOG(_L("[BTSU]\t CBTServiceStarter::ProgressDialogCancelled(), cancelled by user"));        
       
  1226     iUserCancel=ETrue;
       
  1227     if ( iController )
       
  1228         {
       
  1229         iController->Abort();
       
  1230         }
       
  1231     else 
       
  1232        {
       
  1233        StopTransfer(KErrCancel);
       
  1234        }    
       
  1235     }
       
  1236 
       
  1237 
       
  1238 void CBTServiceStarter::ProgressDialogClosed(const CHbDeviceProgressDialogSymbian* /* aDialog*/)
       
  1239     {
       
  1240     }
       
  1241 
       
  1242 
       
  1243 void CBTServiceStarter::DataReceived(CHbSymbianVariantMap& /*aData*/)
       
  1244     {
       
  1245     
       
  1246     }
       
  1247 
       
  1248 
       
  1249 void CBTServiceStarter::DeviceDialogClosed(TInt /* aCompletionCode*/)
       
  1250     {
       
  1251     TBuf<255> buf;
       
  1252     _LIT(KText, "Sending Cancelled to ");
       
  1253     buf.Copy(KText);
       
  1254     if ( iDevice->IsValidFriendlyName() )
       
  1255         {
       
  1256         buf.Append( iDevice->FriendlyName() );
       
  1257         }
       
  1258     else 
       
  1259         {
       
  1260         TRAP_IGNORE(buf.Append( BTDeviceNameConverter::ToUnicodeL(iDevice->DeviceName())));
       
  1261         }
       
  1262 
       
  1263     iUserCancel=ETrue;
       
  1264     if ( iController )
       
  1265         {
       
  1266         iController->Abort();
       
  1267         }
       
  1268     else 
       
  1269        {
       
  1270        StopTransfer(KErrCancel);
       
  1271        }    
       
  1272     
       
  1273     if ( iProgressTimer )
       
  1274         {
       
  1275         iProgressTimer->Cancel();
       
  1276         delete iProgressTimer;
       
  1277         iProgressTimer = NULL;
       
  1278         }
       
  1279     TRAP_IGNORE(CHbDeviceNotificationDialogSymbian::NotificationL(KNullDesC, buf, KNullDesC));
       
  1280     }