localconnectivityservice/obexsendservices/obexservicesendutils/src/BTServiceStarter.cpp
changeset 32 51f207bebb06
parent 26 d74a43a4aa59
child 21 23264c07fd05
equal deleted inserted replaced
31:3b92f7acdc91 32:51f207bebb06
    27 #include <Obexutils.rsg>
    27 #include <Obexutils.rsg>
    28 #include <obexutilsuilayer.h>
    28 #include <obexutilsuilayer.h>
    29 #include <obexutilsmessagehandler.h>
    29 #include <obexutilsmessagehandler.h>
    30 #include <btnotif.h>
    30 #include <btnotif.h>
    31 #include <featmgr.h>
    31 #include <featmgr.h>
       
    32 #include "hbdevicemessageboxsymbian.h"
    32 
    33 
    33 // CONSTANTS
    34 // CONSTANTS
    34 
    35 
    35 // From BT SIG - Assigned numbers
    36 // From BT SIG - Assigned numbers
    36 const TUint KBTServiceOPPSending        = 0x1105;
    37 const TUint KBTServiceOPPSending        = 0x1105;
    37 const TUint KBTServiceDirectPrinting    = 0x1118;
    38 const TUint KBTServiceDirectPrinting    = 0x1118;
    38 const TUint KBTServiceImagingResponder  = 0x111B;
    39 const TUint KBTServiceImagingResponder  = 0x111B;
    39 
    40 
    40 const TUint KBTProgressInterval         = 1000000;
       
    41 
    41 
    42 // ============================ MEMBER FUNCTIONS ===============================
    42 // ============================ MEMBER FUNCTIONS ===============================
    43 
    43 
    44 // -----------------------------------------------------------------------------
    44 // -----------------------------------------------------------------------------
    45 // CBTServiceStarter::CBTServiceStarter
    45 // CBTServiceStarter::CBTServiceStarter
    70 //
    70 //
    71 void CBTServiceStarter::ConstructL()
    71 void CBTServiceStarter::ConstructL()
    72     {
    72     {
    73     FLOG(_L("[BTSU]\t CBTServiceStarter::ConstructL()"));
    73     FLOG(_L("[BTSU]\t CBTServiceStarter::ConstructL()"));
    74     iDevice = CBTDevice::NewL();
    74     iDevice = CBTDevice::NewL();
    75     iDialog = CObexUtilsDialog::NewL( this );
    75 //    iDialog = CObexUtilsDialog::NewL( this );
    76     FeatureManager::InitializeLibL();
    76     FeatureManager::InitializeLibL();
    77     iFeatureManagerInitialized = ETrue;
    77     iFeatureManagerInitialized = ETrue;
    78     FLOG(_L("[BTSU]\t CBTServiceStarter::ConstructL() completed"));
    78     FLOG(_L("[BTSU]\t CBTServiceStarter::ConstructL() completed"));
    79     }
    79     }
    80 
    80 
   106     delete iList;
   106     delete iList;
   107     delete iDevice;
   107     delete iDevice;
   108 
   108 
   109     delete iController;
   109     delete iController;
   110     delete iBTEngDiscovery;
   110     delete iBTEngDiscovery;
   111     delete iDialog;
   111  //   delete iDialog;
       
   112     delete iProgressDialog;
   112 
   113 
   113     if(iWaiter && iWaiter->IsStarted() )
   114     if(iWaiter && iWaiter->IsStarted() )
   114         {
   115         {
   115         iWaiter->AsyncStop();
   116         iWaiter->AsyncStop();
   116         }
   117         }
   164     TBTPowerStateValue power = EBTPowerOff;
   165     TBTPowerStateValue power = EBTPowerOff;
   165     User::LeaveIfError( iBTEngSettings->GetPowerState( power ) );
   166     User::LeaveIfError( iBTEngSettings->GetPowerState( power ) );
   166     TBool offline = EFalse;
   167     TBool offline = EFalse;
   167     if( !power )
   168     if( !power )
   168         {
   169         {
   169         offline = CheckOfflineModeL();
   170         //offline = CheckOfflineModeL();
       
   171          offline = EFalse;
   170         }
   172         }
   171     if( !offline )
   173     if( !offline )
   172         {
   174         {
   173         FLOG(_L("[BTSU]\t CBTServiceStarter::StartServiceL() Phone is online, request temporary power on."));
   175         FLOG(_L("[BTSU]\t CBTServiceStarter::StartServiceL() Phone is online, request temporary power on."));
   174 		TurnBTPowerOnL( power );
   176 		TurnBTPowerOnL( power );
   422 void CBTServiceStarter::LaunchWaitNoteL()
   424 void CBTServiceStarter::LaunchWaitNoteL()
   423     {
   425     {
   424     FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchWaitNoteL()"));
   426     FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchWaitNoteL()"));
   425     if ( iService == EBTPrintingService )
   427     if ( iService == EBTPrintingService )
   426         {
   428         {
   427         iDialog->LaunchWaitDialogL( R_BT_PRINTING_WAIT_NOTE );
   429  //       iDialog->LaunchWaitDialogL( R_BT_PRINTING_WAIT_NOTE );
   428         }
   430         }
   429     else
   431     else
   430         {
   432         {
   431         iDialog->LaunchWaitDialogL( R_BT_CONNECTING_WAIT_NOTE );
   433         //       iDialog->LaunchWaitDialogL( R_BT_CONNECTING_WAIT_NOTE );
       
   434         _LIT(KConnectText, "Connecting...");
       
   435         iProgressDialog = CHbDeviceProgressDialogSymbian::NewL(CHbDeviceProgressDialogSymbian::EWaitDialog,this);
       
   436         iProgressDialog->SetTextL(KConnectText);
       
   437         iProgressDialog->ShowL();
       
   438         
   432         }    
   439         }    
   433     FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchWaitNoteL() completed"));
   440     FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchWaitNoteL() completed"));
   434     }
   441     }
   435 
   442 
   436 // -----------------------------------------------------------------------------
   443 // -----------------------------------------------------------------------------
   439 //
   446 //
   440 void CBTServiceStarter::CancelWaitNote()
   447 void CBTServiceStarter::CancelWaitNote()
   441     {
   448     {
   442     FLOG(_L("[BTSU]\t CBTServiceStarter::CancelWaitNote()"));
   449     FLOG(_L("[BTSU]\t CBTServiceStarter::CancelWaitNote()"));
   443 
   450 
   444     if ( iDialog )
   451   //  if ( iDialog )
   445         {
   452   //      {
   446         TRAP_IGNORE( iDialog->CancelWaitDialogL() );
   453         //       TRAP_IGNORE( iDialog->CancelWaitDialogL() );
   447         }
   454         if(iProgressDialog)
       
   455             {
       
   456             //This has to be tested
       
   457             iProgressDialog->Close();
       
   458             }
       
   459     //    }
   448 
   460 
   449     FLOG(_L("[BTSU]\t CBTServiceStarter::CancelWaitNote() completed"));
   461     FLOG(_L("[BTSU]\t CBTServiceStarter::CancelWaitNote() completed"));
   450     }
   462     }
   451 
   463 
   452 
   464 
   456 //
   468 //
   457 void CBTServiceStarter::LaunchProgressNoteL( MBTServiceProgressGetter* aGetter,
   469 void CBTServiceStarter::LaunchProgressNoteL( MBTServiceProgressGetter* aGetter,
   458                                              TInt aTotalSize )
   470                                              TInt aTotalSize )
   459     {
   471     {
   460     FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchProgressNoteL()"));
   472     FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchProgressNoteL()"));
   461 
   473     (void) aTotalSize;
       
   474     
   462     if ( iService != EBTPrintingService )
   475     if ( iService != EBTPrintingService )
   463         {    
   476         {    
   464         iProgressGetter = aGetter;        
   477         iProgressGetter = aGetter;        
   465         CancelWaitNote();        
   478         CancelWaitNote();        
   466         
   479         
   467         if ( !iProgressDialogActive )
   480         if ( !iProgressDialogActive )
   468         	{
   481         	{
   469         	iMessageServerIndex = TObexUtilsMessageHandler::CreateOutboxEntryL( 
   482         	iMessageServerIndex = TObexUtilsMessageHandler::CreateOutboxEntryL( 
   470             KUidMsgTypeBt, R_BT_SEND_OUTBOX_SENDING );        
   483             KUidMsgTypeBt, R_BT_SEND_OUTBOX_SENDING );        
   471         	iDialog->LaunchProgressDialogL( this, aTotalSize, 
   484    //     	iDialog->LaunchProgressDialogL( this, aTotalSize, 
   472              								R_BT_SENDING_DATA, KBTProgressInterval );	
   485      //        								R_BT_SENDING_DATA, KBTProgressInterval );	
   473         	}        
   486         	}        
   474         iProgressDialogActive=ETrue;     
   487         iProgressDialogActive=ETrue;     
   475         }
   488         }
   476 
   489 
   477     FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchProgressNoteL() completed"));
   490     FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchProgressNoteL() completed"));
   483 //
   496 //
   484 void CBTServiceStarter::CancelProgressNote()
   497 void CBTServiceStarter::CancelProgressNote()
   485     {
   498     {
   486     FLOG(_L("[BTSU]\t CBTServiceStarter::CancelProgressNote()"));
   499     FLOG(_L("[BTSU]\t CBTServiceStarter::CancelProgressNote()"));
   487 
   500 
   488     if ( iDialog )
   501  //   if ( iDialog )
   489         {
   502         {
   490         TRAP_IGNORE( iDialog->CancelProgressDialogL() );
   503   //      TRAP_IGNORE( iDialog->CancelProgressDialogL() );
   491         }
   504         }
   492     }
   505     }
   493 
   506 
   494 // -----------------------------------------------------------------------------
   507 // -----------------------------------------------------------------------------
   495 // CBTServiceStarter::DialogDismissed
   508 // CBTServiceStarter::DialogDismissed
   527 //
   540 //
   528 void CBTServiceStarter::ShowNote( TInt aReason ) const
   541 void CBTServiceStarter::ShowNote( TInt aReason ) const
   529     {
   542     {
   530     FLOG(_L("[BTSU]\t CBTServiceStarter::ShowNote()"));
   543     FLOG(_L("[BTSU]\t CBTServiceStarter::ShowNote()"));
   531      
   544      
   532     TInt resource = 0;    
   545 //    TInt resource = 0;
       
   546     TBuf<255> buf;
   533 
   547 
   534     switch ( aReason )
   548     switch ( aReason )
   535         {
   549         {
   536         case EBTSNoError:
   550         case EBTSNoError:
   537             {
   551             {
   538             if ( iService == EBTPrintingService )
   552             if ( iService == EBTPrintingService )
   539                 {
   553                 {
   540                 resource = R_BT_DATA_SENT2;
   554                // resource = R_BT_DATA_SENT2;
       
   555                 
       
   556                 _LIT(KText, "Data Sent");
       
   557                 buf.Copy(KText);
   541                 }
   558                 }
   542             else
   559             else
   543                 {
   560                 {
   544                 resource = R_BT_DATA_SENT;
   561                 //resource = R_BT_DATA_SENT;
       
   562                 _LIT(KText, "Data Sent");
       
   563                 buf.Copy(KText);
   545                 }
   564                 }
   546             break;
   565             break;
   547             }
   566             }
   548         case EBTSConnectingFailed:
   567         case EBTSConnectingFailed:
   549             {
   568             {
   550             resource = R_BT_DEV_NOT_AVAIL;
   569             //resource = R_BT_DEV_NOT_AVAIL;
       
   570             _LIT(KText, "Cannot establish Bluetooth connection");
       
   571             buf.Copy(KText);
   551             break;
   572             break;
   552             }
   573             }
   553         case EBTSGettingFailed:
   574         case EBTSGettingFailed:
   554         case EBTSPuttingFailed:
   575         case EBTSPuttingFailed:
   555             {
   576             {
   556             if ( iService == EBTPrintingService )
   577             if ( iService == EBTPrintingService )
   557                 {
   578                 {
   558                 resource = R_BT_FAILED_TO_SEND2;
   579                 _LIT(KText, "Sending failed");
       
   580                 //resource = R_BT_FAILED_TO_SEND2;
       
   581                 buf.Copy(KText);
   559                 }
   582                 }
   560             else
   583             else
   561                 {
   584                 {
   562                 resource = R_BT_FAILED_TO_SEND;
   585                 _LIT(KText, "Failed to send Data");
       
   586                 //resource = R_BT_FAILED_TO_SEND;
       
   587                 buf.Copy(KText);
   563                 }
   588                 }
   564             break;
   589             break;
   565             }
   590             }
   566         case EBTSNoSuitableProfiles:
   591         case EBTSNoSuitableProfiles:
   567             {
   592             {
   568             if ( iService == EBTPrintingService )
   593             if ( iService == EBTPrintingService )
   569                 {
   594                 {
   570                 resource = R_BT_PRINTING_NOT_SUPPORTED;
   595                 _LIT(KText, "Printer not supported");
       
   596                 buf.Copy(KText);
       
   597             //    resource = R_BT_PRINTING_NOT_SUPPORTED;
   571                 }
   598                 }
   572             else
   599             else
   573                 {
   600                 {
   574                 resource = R_BT_FAILED_TO_SEND;
   601                 _LIT(KText, "Failed to send Data");
       
   602                 buf.Copy(KText);
       
   603          //       resource = R_BT_FAILED_TO_SEND;
   575                 }
   604                 }
   576             break;
   605             break;
   577             }
   606             }
   578         case EBTSBIPSomeSend:
   607         case EBTSBIPSomeSend:
   579         	{
   608         	{
   580         	resource = R_BT_FAILED_TO_SEND;
   609         	_LIT(KText, "Failed to send Data");
       
   610         	 buf.Copy(KText);
       
   611         	//resource = R_BT_FAILED_TO_SEND;
   581         	break;	
   612         	break;	
   582         	}    
   613         	}    
   583         case EBTSBIPOneNotSend:
   614         case EBTSBIPOneNotSend:
   584         	{
   615         	{
   585         	resource = R_BT_NOT_RECEIVE_ONE;
   616         	_LIT(KText, "Receiving device does not support this image format.");
       
   617         	 buf.Copy(KText);
       
   618         	//resource = R_BT_NOT_RECEIVE_ONE;
   586         	break;
   619         	break;
   587         	}
   620         	}
   588         case EBTSBIPNoneSend:
   621         case EBTSBIPNoneSend:
   589         	{
   622         	{
   590         	resource = R_BT_NOT_RECEIVE_ANY;
   623         	_LIT(KText, "Receiving device does not support the needed image formats.");
       
   624         	 buf.Copy(KText);
       
   625         	//resource = R_BT_NOT_RECEIVE_ANY;
   591         	break;
   626         	break;
   592         	}	
   627         	}	
   593         default:
   628         default:
   594             {            
   629             {            
   595             resource = R_BT_DEV_NOT_AVAIL;
   630            // resource = R_BT_DEV_NOT_AVAIL;
       
   631             _LIT(KText, "Cannot establish Bluetooth connection");
       
   632             buf.Copy(KText);
   596             break;
   633             break;
   597             }
   634             }
   598         }        
   635         }        
   599     
   636     
   600 	TRAP_IGNORE(TObexUtilsUiLayer::ShowInformationNoteL( resource ) );	
   637 //	TRAP_IGNORE(TObexUtilsUiLayer::ShowInformationNoteL( resource ) );	
       
   638     CHbDeviceMessageBoxSymbian::InformationL(buf);
   601     FLOG(_L("[BTSU]\t CBTServiceStarter::ShowNote() completed"));
   639     FLOG(_L("[BTSU]\t CBTServiceStarter::ShowNote() completed"));
   602     }
   640     }
   603 
   641 
   604 // -----------------------------------------------------------------------------
   642 // -----------------------------------------------------------------------------
   605 // CBTServiceStarter::LaunchConfirmationQuery
   643 // CBTServiceStarter::LaunchConfirmationQuery
   606 // -----------------------------------------------------------------------------
   644 // -----------------------------------------------------------------------------
   607 //
   645 //
   608 TInt CBTServiceStarter::LaunchConfirmationQuery(TInt aResourceId)
   646 TInt CBTServiceStarter::LaunchConfirmationQuery(TInt /*aResourceId*/)
   609 	{
   647 	{
   610 	TInt keypress=0;
   648 	TInt keypress=0;
   611 	TRAP_IGNORE( keypress = iDialog->LaunchQueryDialogL(  aResourceId ));	
   649 //	TRAP_IGNORE( keypress = iDialog->LaunchQueryDialogL(  aResourceId ));	
   612 	if ( !keypress )
   650 	if ( !keypress )
   613 		{
   651 		{
   614 		FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchConfirmationQuery(), cancelled by user"));
   652 		FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchConfirmationQuery(), cancelled by user"));
   615 		DialogDismissed(EAknSoftkeyNo);
   653 		DialogDismissed(EAknSoftkeyNo);
   616 		CancelWaitNote();		
   654 		CancelWaitNote();		
   622 // CBTServiceStarter::StopTransfer
   660 // CBTServiceStarter::StopTransfer
   623 // -----------------------------------------------------------------------------
   661 // -----------------------------------------------------------------------------
   624 //	
   662 //	
   625 void CBTServiceStarter::StopTransfer(TInt aError)
   663 void CBTServiceStarter::StopTransfer(TInt aError)
   626 	{
   664 	{
       
   665       
   627 	FLOG(_L("[BTSU]\t CBTServiceStarter::StopTransfer()"));
   666 	FLOG(_L("[BTSU]\t CBTServiceStarter::StopTransfer()"));
   628     Cancel();
   667     Cancel();
   629 	if( !iUserCancel )
   668 	if( !iUserCancel )
   630 	    {
   669 	    {
   631 	    CancelWaitNote();
   670 	    CancelWaitNote();
   903 // -----------------------------------------------------------------------------
   942 // -----------------------------------------------------------------------------
   904 //  
   943 //  
   905 void CBTServiceStarter::TurnBTPowerOnL( const TBTPowerStateValue aState )
   944 void CBTServiceStarter::TurnBTPowerOnL( const TBTPowerStateValue aState )
   906     {
   945     {
   907 	FLOG( _L("[BTSU]\t CBTServiceStarter::TurnBTPowerOnL()") );
   946 	FLOG( _L("[BTSU]\t CBTServiceStarter::TurnBTPowerOnL()") );
   908     if (iName() != EFalse) 
   947 //    if (iName() != EFalse) 
   909     	{
   948     	{
   910     	if( !iBTEngSettings )
   949     	if( !iBTEngSettings )
   911 	        {
   950 	        {
   912 	        iBTEngSettings = CBTEngSettings::NewL( this );
   951 	        iBTEngSettings = CBTEngSettings::NewL( this );
   913 	        }
   952 	        }
   925 	        // searching straight away.
   964 	        // searching straight away.
   926 	        iWaitingForBTPower = EFalse;
   965 	        iWaitingForBTPower = EFalse;
   927 	        StartDiscoveryL();
   966 	        StartDiscoveryL();
   928 	        }
   967 	        }
   929     	}
   968     	}
   930     else
   969  /*   else
   931     	{
   970     	{
   932         if ( !iNotifier.Handle() )
   971         if ( !iNotifier.Handle() )
   933 	        {
   972 	        {
   934 			User::LeaveIfError( iNotifier.Connect() );
   973 			User::LeaveIfError( iNotifier.Connect() );
   935 	        }
   974 	        }
   938         pckg().iNameExists = EFalse;
   977         pckg().iNameExists = EFalse;
   939         iActiveNotifier = ENameQuery;
   978         iActiveNotifier = ENameQuery;
   940         iNotifier.StartNotifierAndGetResponse( iStatus, KBTGenericQueryNotifierUid, 
   979         iNotifier.StartNotifierAndGetResponse( iStatus, KBTGenericQueryNotifierUid, 
   941                                                   pckg, iName );
   980                                                   pckg, iName );
   942         SetActive();
   981         SetActive();
   943     	}
   982     	}*/
   944 	FLOG(_L("[BTSU]\t CBTServiceStarter::TurnBTPowerOnL() - completed"));
   983 	FLOG(_L("[BTSU]\t CBTServiceStarter::TurnBTPowerOnL() - completed"));
   945     }
   984     }
   946 
   985 
   947 
   986 
   948 // ---------------------------------------------------------------------------
   987 // ---------------------------------------------------------------------------
   986             }    
  1025             }    
   987         }
  1026         }
   988 
  1027 
   989     if( err )
  1028     if( err )
   990         {
  1029         {
       
  1030       
   991         err = ( err == KErrNotSupported ? KErrCancel : err );
  1031         err = ( err == KErrNotSupported ? KErrCancel : err );
   992         if ( iWaiter && err != KErrInUse && err != KErrCancel )
  1032         if ( iWaiter && err != KErrInUse && err != KErrCancel )
   993             {
  1033             {
   994             err = EBTSPuttingFailed;
  1034             err = EBTSPuttingFailed;
   995             }
  1035             }
  1010 	FLOG(_L("[BTSU]\t CBTServiceStarter::RunError()"));
  1050 	FLOG(_L("[BTSU]\t CBTServiceStarter::RunError()"));
  1011     StopTransfer( aError );
  1051     StopTransfer( aError );
  1012 	FLOG(_L("[BTSU]\t CBTServiceStarter::RunError() - completed"));
  1052 	FLOG(_L("[BTSU]\t CBTServiceStarter::RunError() - completed"));
  1013     return KErrNone;
  1053     return KErrNone;
  1014     }
  1054     }
  1015 //  End of File
  1055 
       
  1056 
       
  1057 
       
  1058 
       
  1059 void CBTServiceStarter::ProgressDialogCancelled(const CHbDeviceProgressDialogSymbian*/*  aDialog*/)
       
  1060     {
       
  1061     FLOG(_L("[BTSU]\t CBTServiceStarter::ProgressDialogCancelled(), cancelled by user"));        
       
  1062     iUserCancel=ETrue;
       
  1063     if ( iController )
       
  1064         {
       
  1065         iController->Abort();
       
  1066         }
       
  1067     else 
       
  1068        {
       
  1069        StopTransfer(KErrCancel);
       
  1070        }    
       
  1071     }
       
  1072 
       
  1073 
       
  1074 void CBTServiceStarter::ProgressDialogClosed(const CHbDeviceProgressDialogSymbian* /* aDialog*/)
       
  1075     {
       
  1076     }