btobexprofiles/obexsendservices/obexservicesendutils/src/BTServiceStarter.cpp
changeset 57 5ebadcda06cb
parent 45 b0aebde9b1fb
equal deleted inserted replaced
51:625f43ae9362 57:5ebadcda06cb
    25 #include "BTSBPPController.h"
    25 #include "BTSBPPController.h"
    26 
    26 
    27 #include <obexutilsmessagehandler.h>
    27 #include <obexutilsmessagehandler.h>
    28 #include <featmgr.h>
    28 #include <featmgr.h>
    29 #include <hbdevicenotificationdialogsymbian.h>
    29 #include <hbdevicenotificationdialogsymbian.h>
    30 #include <hbtextresolversymbian.h>
    30 #include <btservices/bluetoothdevicedialogs.h>
    31 
    31 
    32 // CONSTANTS
    32 // CONSTANTS
    33 
    33 
    34 // From BT SIG - Assigned numbers
    34 // From BT SIG - Assigned numbers
    35 const TUint KBTServiceOPPSending        = 0x1105;
    35 const TUint KBTServiceOPPSending        = 0x1105;
    39 const TUint KBTProgressInterval         = 1000000;
    39 const TUint KBTProgressInterval         = 1000000;
    40 
    40 
    41 const TUid KUidMsgTypeBt                 = {0x10009ED5};
    41 const TUid KUidMsgTypeBt                 = {0x10009ED5};
    42 //todo  need to find a suitable header to include. This is from obexutilslayer.h
    42 //todo  need to find a suitable header to include. This is from obexutilslayer.h
    43 
    43 
    44 const TInt KMaxDesCLength  = 256;
    44 const TInt KMinStringSize = 10;
    45 
    45 
    46 
    46 
    47 //_LIT(KSendingDialog,"com.nokia.hb.btdevicedialog/1.0");
    47 
    48 
    48 _LIT( KBTDevDialogId, "com.nokia.hb.btdevicedialog/1.0" );
    49 _LIT(KLocFileName, "btdialogs_");
       
    50 _LIT(KPath, "z:/resource/qt/translations/");  
       
    51 
       
    52 _LIT(KFilesSentText, "txt_bt_dpophead_all_files_sent");//All files sent 
       
    53 _LIT(KDeviceText,"txt_bt_dpopinfo_sent_to_1");
       
    54 //_LIT(KNotConnectedText,"txt_bt_info_unable_to_connect_with_bluetooth");
       
    55 _LIT(KSendingFailedText,"txt_bt_dpophead_sending_failed");
       
    56 
    49 
    57 // ============================ MEMBER FUNCTIONS ===============================
    50 // ============================ MEMBER FUNCTIONS ===============================
    58 
    51 
    59 // -----------------------------------------------------------------------------
    52 // -----------------------------------------------------------------------------
    60 // CBTServiceStarter::CBTServiceStarter
    53 // CBTServiceStarter::CBTServiceStarter
    71       iBytesSendWithBIP(0),
    64       iBytesSendWithBIP(0),
    72       iProgressDialogActive(EFalse),
    65       iProgressDialogActive(EFalse),
    73       iUserCancel(EFalse), 
    66       iUserCancel(EFalse), 
    74       iFeatureManagerInitialized(EFalse),
    67       iFeatureManagerInitialized(EFalse),
    75       iTriedBIP(EFalse),
    68       iTriedBIP(EFalse),
    76       iTriedOPP(EFalse)
    69       iTriedOPP(EFalse),
       
    70       iShowDialogNote(EFalse)
    77     {    
    71     {    
    78     CActiveScheduler::Add( this );
    72     CActiveScheduler::Add( this );
    79     }
    73     }
    80 
    74 
    81 // -----------------------------------------------------------------------------
    75 // -----------------------------------------------------------------------------
    89     iDevice = CBTDevice::NewL();
    83     iDevice = CBTDevice::NewL();
    90     iDialog = CObexUtilsDialog::NewL( this );
    84     iDialog = CObexUtilsDialog::NewL( this );
    91     iDelayedDestroyer = CBTServiceDelayedDestroyer::NewL(CActive::EPriorityStandard);
    85     iDelayedDestroyer = CBTServiceDelayedDestroyer::NewL(CActive::EPriorityStandard);
    92     FeatureManager::InitializeLibL();
    86     FeatureManager::InitializeLibL();
    93     iFeatureManagerInitialized = ETrue;
    87     iFeatureManagerInitialized = ETrue;
    94     iLocalisationInit = HbTextResolverSymbian::Init(KLocFileName, KPath);
       
    95     FLOG(_L("[BTSU]\t CBTServiceStarter::ConstructL() completed"));
    88     FLOG(_L("[BTSU]\t CBTServiceStarter::ConstructL() completed"));
    96     }
    89     }
    97 
    90 
    98 // -----------------------------------------------------------------------------
    91 // -----------------------------------------------------------------------------
    99 // CBTServiceStarter::NewL
    92 // CBTServiceStarter::NewL
   125 
   118 
   126     delete iController;
   119     delete iController;
   127     delete iBTEngDiscovery;
   120     delete iBTEngDiscovery;
   128     delete iDialog;
   121     delete iDialog;
   129     delete iDelayedDestroyer;
   122     delete iDelayedDestroyer;
       
   123     iRemoteDeviceName.Close();
   130     
   124     
   131     if(iWaiter && iWaiter->IsStarted() )
   125     if(iWaiter && iWaiter->IsStarted() )
   132         {
   126         {
   133         iWaiter->AsyncStop();
   127         iWaiter->AsyncStop();
   134         }
   128         }
   137     if ( iFeatureManagerInitialized )
   131     if ( iFeatureManagerInitialized )
   138         {
   132         {
   139         FeatureManager::UnInitializeLib();
   133         FeatureManager::UnInitializeLib();
   140         }
   134         }
   141     
   135     
       
   136     if (iNotificationDialog)
       
   137         {
       
   138         iNotificationDialog->Cancel();
       
   139         delete iNotificationDialog;
       
   140         }
   142     FLOG(_L("[BTSU]\t CBTServiceStarter::Destructor() completed"));
   141     FLOG(_L("[BTSU]\t CBTServiceStarter::Destructor() completed"));
   143     }
   142     }
   144 
   143 
   145 // -----------------------------------------------------------------------------
   144 // -----------------------------------------------------------------------------
   146 // CBTServiceStarter::StartServiceL
   145 // CBTServiceStarter::StartServiceL
   446         {
   445         {
   447  //       iDialog->LaunchWaitDialogL( R_BT_PRINTING_WAIT_NOTE );
   446  //       iDialog->LaunchWaitDialogL( R_BT_PRINTING_WAIT_NOTE );
   448         }
   447         }
   449     else
   448     else
   450         {
   449         {
       
   450         iShowDialogNote = ETrue;
   451     //todo need to do the localisation here
   451     //todo need to do the localisation here
   452         _LIT(KConnectText, "Connecting...");
   452         _LIT(KConnectText, "Connecting...");
   453         iDialog->LaunchWaitDialogL(KConnectText);
   453         iDialog->LaunchWaitDialogL(KConnectText);
   454         
   454         
   455         }    
   455         }    
   488         iProgressGetter = aGetter;     
   488         iProgressGetter = aGetter;     
   489         CancelWaitNote();        
   489         CancelWaitNote();        
   490         
   490         
   491         if ( !iProgressDialogActive )
   491         if ( !iProgressDialogActive )
   492         	{
   492         	{
       
   493             iShowDialogNote = ETrue;  
   493             // todo need to change the last parameter because we are now using the textmap id which is a string
   494             // todo need to change the last parameter because we are now using the textmap id which is a string
   494             // whether we replace it with that or remove the parameter is to be decided
   495             // whether we replace it with that or remove the parameter is to be decided
   495         	iMessageServerIndex = TObexUtilsMessageHandler::CreateOutboxEntryL( 
   496         	iMessageServerIndex = TObexUtilsMessageHandler::CreateOutboxEntryL( 
   496             KUidMsgTypeBt, 0 );     
   497             KUidMsgTypeBt, 0 );     
   497 
   498 
   498             deviceName.CreateL(KMaxDesCLength);
       
   499             
   499             
   500             if ( iDevice->IsValidFriendlyName() )
   500             if ( iDevice->IsValidFriendlyName() )
   501                 {
   501                 {
   502                 deviceName.Copy( iDevice->FriendlyName() );
   502                 deviceName.CreateL( iDevice->FriendlyName() );
   503                 }
   503                 }
   504             else 
   504             else 
   505                 {
   505                 {
   506                 deviceName.Copy( BTDeviceNameConverter::ToUnicodeL(iDevice->DeviceName()));
   506                 deviceName.CreateL( BTDeviceNameConverter::ToUnicodeL(iDevice->DeviceName()));
   507                 }        	
   507                 }        	
   508         	iDialog->LaunchProgressDialogL( this, aFileCount, 
   508         	iDialog->LaunchProgressDialogL( this, aFileCount, 
   509                                 deviceName, KBTProgressInterval );	
   509                                 deviceName, KBTProgressInterval );	
   510         	deviceName.Close();
   510         	deviceName.Close();
   511         	}        
   511         	}        
   548     FLOG(_L("[BTSU]\t CBTServiceStarter::DialogDismissed()"));   
   548     FLOG(_L("[BTSU]\t CBTServiceStarter::DialogDismissed()"));   
   549     if( aButtonId == ECancelButton )
   549     if( aButtonId == ECancelButton )
   550         { // this condition is hit for the progress dialog and connecting dialog cancel
   550         { // this condition is hit for the progress dialog and connecting dialog cancel
   551         FLOG(_L("[BTSU]\t CBTServiceStarter::DialogDissmissed(), cancelled by user"));        
   551         FLOG(_L("[BTSU]\t CBTServiceStarter::DialogDissmissed(), cancelled by user"));        
   552         iUserCancel=ETrue;
   552         iUserCancel=ETrue;
       
   553         iShowDialogNote = EFalse;
       
   554 /*        if ( iDevice->IsValidFriendlyName() )
       
   555             {
       
   556             TRAP_IGNORE(iRemoteDeviceName.CreateL( iDevice->FriendlyName()) );
       
   557             }
       
   558         else 
       
   559             {
       
   560             TRAP_IGNORE( iRemoteDeviceName.CreateL( BTDeviceNameConverter::ToUnicodeL(iDevice->DeviceName())));
       
   561             }
       
   562         
       
   563         iRemoteDeviceClass = iDevice->DeviceClass().DeviceClass();        
       
   564         
       
   565         TRAP_IGNORE( ShowSendCompleteNoteL(ESendCancelled) );*/
       
   566         
   553         if ( iController )
   567         if ( iController )
   554             {
   568             {
   555             iController->Abort();
   569             iController->Abort();
   556             }
   570             }
   557         else 
   571         else 
   561         }
   575         }
   562     else if ( aButtonId == ENoButton )
   576     else if ( aButtonId == ENoButton )
   563         {
   577         {
   564         // user abortion
   578         // user abortion
   565         //
   579         //
       
   580         iShowDialogNote = EFalse;
   566         iUserCancel = ETrue;
   581         iUserCancel = ETrue;
   567         StopTransfer( KErrCancel );
   582         StopTransfer( KErrCancel );
   568         CancelWaitNote();
   583         CancelWaitNote();
   569         }
   584         }
   570     else //EYesButton
   585     else //EYesButton
   576 
   591 
   577 // -----------------------------------------------------------------------------
   592 // -----------------------------------------------------------------------------
   578 // CBTServiceStarter::ShowErrorNote
   593 // CBTServiceStarter::ShowErrorNote
   579 // -----------------------------------------------------------------------------
   594 // -----------------------------------------------------------------------------
   580 //
   595 //
   581 void CBTServiceStarter::ShowErrorNote( TInt aReason ) const
   596 void CBTServiceStarter::ShowErrorNote( TInt aReason ) 
   582     {
   597     {
   583     FLOG(_L("[BTSU]\t CBTServiceStarter::ShowErrorNote()"));
   598     FLOG(_L("[BTSU]\t CBTServiceStarter::ShowErrorNote()"));
   584      
   599      
   585     TBuf<KMaxDesCLength> buf;
       
   586     TPtrC sendTextMapId;
       
   587     
       
   588     if ( iDevice->IsValidFriendlyName() )
   600     if ( iDevice->IsValidFriendlyName() )
   589         {
   601         {
   590         buf.Copy( iDevice->FriendlyName() );
   602         iRemoteDeviceName.CreateL( iDevice->FriendlyName() );
   591         }
   603         }
   592     else 
   604     else 
   593         {
   605         {
   594         TRAP_IGNORE( buf.Copy( BTDeviceNameConverter::ToUnicodeL(iDevice->DeviceName())));
   606         TRAP_IGNORE( iRemoteDeviceName.CreateL( BTDeviceNameConverter::ToUnicodeL(iDevice->DeviceName())));
   595         }
   607         }
   596     
   608     
       
   609     iRemoteDeviceClass = iDevice->DeviceClass().DeviceClass();    
   597 
   610 
   598     switch ( aReason )
   611     switch ( aReason )
   599         {
   612         {
   600         case EBTSNoError:
   613         case EBTSNoError:
   601             {
   614             {
   602             sendTextMapId.Set(KFilesSentText());
   615             TRAP_IGNORE( ShowSendCompleteNoteL(ESendCompleted) );
   603             break;
   616             break;
   604             }
   617             }
   605         case EBTSConnectingFailed:
   618         case EBTSConnectingFailed:
   606         case EBTSGettingFailed:
   619         case EBTSGettingFailed:
   607         case EBTSPuttingFailed:
   620         case EBTSPuttingFailed:
       
   621             {
       
   622             TRAP_IGNORE( ShowErrorMessageL(TBluetoothDialogParams::ESendFailed) );
       
   623             break;
       
   624             }
   608         case EBTSNoSuitableProfiles:
   625         case EBTSNoSuitableProfiles:
   609       //todo below three enums are not valid and it is not being used at anywhere do we need to have it 
   626       //todo below three enums are not valid and it is not being used at anywhere do we need to have it 
   610             
   627             
   611 //        case EBTSBIPSomeSend:
   628 //        case EBTSBIPSomeSend:
   612 //        case EBTSBIPOneNotSend:
   629 //        case EBTSBIPOneNotSend:
   613 //        case EBTSBIPNoneSend:
   630 //        case EBTSBIPNoneSend:
   614         default:            
   631         default:            
   615             {
       
   616             sendTextMapId.Set(KSendingFailedText());
       
   617             break;
   632             break;
   618             }
       
   619         }        
   633         }        
   620     
       
   621     
       
   622     if(iLocalisationInit)
       
   623         {
       
   624         TRAP_IGNORE(
       
   625                HBufC* sendText = HbTextResolverSymbian::LoadLC(sendTextMapId);
       
   626                HBufC* deviceName =  HbTextResolverSymbian::LoadLC(KDeviceText,buf);
       
   627                CHbDeviceNotificationDialogSymbian::NotificationL(KNullDesC, deviceName->Des(), sendText->Des());
       
   628                CleanupStack::PopAndDestroy( deviceName );
       
   629                CleanupStack::PopAndDestroy( sendText );
       
   630                );
       
   631         }
       
   632     else
       
   633         {
       
   634         TRAP_IGNORE(CHbDeviceNotificationDialogSymbian::NotificationL(KNullDesC, KDeviceText(), sendTextMapId));
       
   635         }
       
   636     FLOG(_L("[BTSU]\t CBTServiceStarter::ShowErrorNote() completed"));
   634     FLOG(_L("[BTSU]\t CBTServiceStarter::ShowErrorNote() completed"));
   637     }
   635     }
   638 
   636 
   639 
   637 
   640 
   638 
   642 // CBTServiceStarter::LaunchConfirmationQuery
   640 // CBTServiceStarter::LaunchConfirmationQuery
   643 // -----------------------------------------------------------------------------
   641 // -----------------------------------------------------------------------------
   644 //
   642 //
   645 void  CBTServiceStarter::LaunchConfirmationQuery(const TDesC& aConfirmText)
   643 void  CBTServiceStarter::LaunchConfirmationQuery(const TDesC& aConfirmText)
   646     {
   644     {
   647     TRAP_IGNORE(iDialog->LaunchQueryDialogL(aConfirmText ));
   645     TInt dialogTitle = TBluetoothDialogParams::EUnsupportedImages;
       
   646     iRemoteDeviceClass = iDevice->DeviceClass().DeviceClass();
       
   647     ShowErrorMessageL(dialogTitle,aConfirmText);
   648     }
   648     }
   649 
   649 
   650 // -----------------------------------------------------------------------------
   650 // -----------------------------------------------------------------------------
   651 // CBTServiceStarter::StopTransfer
   651 // CBTServiceStarter::StopTransfer
   652 // -----------------------------------------------------------------------------
   652 // -----------------------------------------------------------------------------
   693         }
   693         }
   694 
   694 
   695     // Reset states
   695     // Reset states
   696     //
   696     //
   697     iServiceStarted = EFalse;
   697     iServiceStarted = EFalse;
   698     if ( iWaiter && iWaiter->IsStarted() )
   698     if (( iWaiter && iWaiter->IsStarted() )&&(!iShowDialogNote))
   699         {                
   699         {                
   700         iWaiter->AsyncStop();                    
   700         iWaiter->AsyncStop();                    
   701         }    
   701         }    
   702         
   702         
   703     iState = EBTSStarterStoppingService;	    
   703     iState = EBTSStarterStoppingService;	    
  1051     StopTransfer( aError );
  1051     StopTransfer( aError );
  1052 	FLOG(_L("[BTSU]\t CBTServiceStarter::RunError() - completed"));
  1052 	FLOG(_L("[BTSU]\t CBTServiceStarter::RunError() - completed"));
  1053     return KErrNone;
  1053     return KErrNone;
  1054     }
  1054     }
  1055 
  1055 
  1056 
  1056 void CBTServiceStarter::ShowSendCompleteNoteL(const TInt aDialogTitle)
  1057 
  1057     {
  1058 
  1058     iNotificationDialog = CHbDeviceDialogSymbian::NewL();
       
  1059     iNotificationDialog->SetObserver(this);
       
  1060     
       
  1061     CHbSymbianVariantMap* variantMap = CHbSymbianVariantMap::NewL();
       
  1062     CleanupStack::PushL(variantMap);
       
  1063     
       
  1064     TInt dialogIdx = TBluetoothDialogParams::EGlobalNotif;
       
  1065     AddDataL(variantMap,TBluetoothDialogParams::EDialogType,&dialogIdx,CHbSymbianVariant::EInt);
       
  1066 
       
  1067     
       
  1068     AddDataL(variantMap,TBluetoothDeviceDialog::EDeviceName,&iRemoteDeviceName,
       
  1069             CHbSymbianVariant::EDes);
       
  1070     
       
  1071     AddDataL(variantMap,TBluetoothDialogParams::EResource,&aDialogTitle,
       
  1072             CHbSymbianVariant::EInt);
       
  1073     
       
  1074     AddDataL(variantMap,TBluetoothDeviceDialog::EDeviceClass,&iRemoteDeviceClass,
       
  1075             CHbSymbianVariant::EInt);
       
  1076 
       
  1077     iNotificationDialog->Show( KBTDevDialogId(), *variantMap, this );
       
  1078     CleanupStack::PopAndDestroy(variantMap);
       
  1079     }
       
  1080 
       
  1081 void CBTServiceStarter::ShowErrorMessageL(const TInt aDialogTitle,
       
  1082                                             const TDesC& aConfirmText)
       
  1083     {
       
  1084     iNotificationDialog = CHbDeviceDialogSymbian::NewL();
       
  1085     iNotificationDialog->SetObserver(this);
       
  1086     
       
  1087     CHbSymbianVariantMap* variantMap = CHbSymbianVariantMap::NewL();
       
  1088     CleanupStack::PushL(variantMap);
       
  1089     
       
  1090     TInt dialogIdx = TBluetoothDialogParams::EInformationDialog;
       
  1091     AddDataL(variantMap,TBluetoothDialogParams::EDialogType,&dialogIdx,CHbSymbianVariant::EInt);
       
  1092     
       
  1093     if(aDialogTitle == TBluetoothDialogParams::EUnsupportedImages )
       
  1094         {
       
  1095         AddDataL(variantMap,TBluetoothDeviceDialog::EAdditionalDesc,&aConfirmText,
       
  1096             CHbSymbianVariant::EDes);
       
  1097         }
       
  1098     else
       
  1099         {
       
  1100         AddDataL(variantMap,TBluetoothDeviceDialog::EDeviceName,&iRemoteDeviceName,
       
  1101             CHbSymbianVariant::EDes);
       
  1102         }
       
  1103     
       
  1104     AddDataL(variantMap,TBluetoothDialogParams::EDialogTitle,&aDialogTitle,
       
  1105             CHbSymbianVariant::EInt);
       
  1106     
       
  1107     AddDataL(variantMap,TBluetoothDeviceDialog::EDeviceClass,&iRemoteDeviceClass,
       
  1108             CHbSymbianVariant::EInt);
       
  1109 
       
  1110     iNotificationDialog->Show( KBTDevDialogId(), *variantMap, this );
       
  1111     CleanupStack::PopAndDestroy(variantMap);
       
  1112     }
       
  1113 
       
  1114 void CBTServiceStarter::AddDataL(CHbSymbianVariantMap* aMap, const TInt aKey, 
       
  1115     const TAny* aData, CHbSymbianVariant::TType aDataType)
       
  1116     {
       
  1117     TBuf<KMinStringSize> key;
       
  1118     key.Num(aKey);
       
  1119 
       
  1120     CHbSymbianVariant* value = CHbSymbianVariant::NewL(aData, aDataType);
       
  1121     CleanupStack::PushL( value );
       
  1122     User::LeaveIfError( aMap->Add( key, value ) ); // aMap takes the ownership of value
       
  1123     CleanupStack::Pop( value );
       
  1124     }
       
  1125 
       
  1126 
       
  1127 void CBTServiceStarter::DataReceived(CHbSymbianVariantMap& aData)
       
  1128     {
       
  1129     if(aData.Keys().MdcaPoint(0).Compare(_L("actionResult"))==KErrNone)
       
  1130         {
       
  1131         TBool val = *(static_cast<TBool*>(aData.Get(_L("actionResult"))->Data()));
       
  1132         if(val)
       
  1133             {
       
  1134             DialogDismissed(EYesButton);
       
  1135             }
       
  1136         else
       
  1137             {
       
  1138             DialogDismissed(ENoButton);
       
  1139             }
       
  1140         if(iNotificationDialog)
       
  1141             {
       
  1142             delete iNotificationDialog;
       
  1143             iNotificationDialog = NULL;
       
  1144             }
       
  1145         }
       
  1146     }
       
  1147 
       
  1148 void CBTServiceStarter::DeviceDialogClosed(TInt aCompletionCode)
       
  1149     {
       
  1150     (void) aCompletionCode;
       
  1151     if(iNotificationDialog)
       
  1152         {
       
  1153         delete iNotificationDialog;
       
  1154         iNotificationDialog = NULL;
       
  1155         }
       
  1156     if ( iWaiter && iWaiter->IsStarted() )
       
  1157         {                
       
  1158         iWaiter->AsyncStop();                    
       
  1159         }
       
  1160     }
       
  1161