localconnectivityservice/obexsendservices/obexservicesendutils/src/BTServiceStarter.cpp
changeset 21 23264c07fd05
parent 18 6743bfee309e
equal deleted inserted replaced
18:6743bfee309e 21:23264c07fd05
    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 #include "BTSProgresstimer.h"
       
    33 #include <hbdevicenotificationdialogsymbian.h>
       
    34 #include <btservices/bluetoothdevicedialogs.h>
    33 
    35 
    34 // CONSTANTS
    36 // CONSTANTS
    35 
    37 
    36 // From BT SIG - Assigned numbers
    38 // From BT SIG - Assigned numbers
    37 const TUint KBTServiceOPPSending        = 0x1105;
    39 const TUint KBTServiceOPPSending        = 0x1105;
    38 const TUint KBTServiceDirectPrinting    = 0x1118;
    40 const TUint KBTServiceDirectPrinting    = 0x1118;
    39 const TUint KBTServiceImagingResponder  = 0x111B;
    41 const TUint KBTServiceImagingResponder  = 0x111B;
    40 
    42 
       
    43 const TUint KBTProgressInterval         = 1000000;
       
    44 
       
    45 
       
    46 _LIT(KSendingDialog,"com.nokia.hb.btdevicedialog/1.0");
    41 
    47 
    42 // ============================ MEMBER FUNCTIONS ===============================
    48 // ============================ MEMBER FUNCTIONS ===============================
    43 
    49 
    44 // -----------------------------------------------------------------------------
    50 // -----------------------------------------------------------------------------
    45 // CBTServiceStarter::CBTServiceStarter
    51 // CBTServiceStarter::CBTServiceStarter
    71 void CBTServiceStarter::ConstructL()
    77 void CBTServiceStarter::ConstructL()
    72     {
    78     {
    73     FLOG(_L("[BTSU]\t CBTServiceStarter::ConstructL()"));
    79     FLOG(_L("[BTSU]\t CBTServiceStarter::ConstructL()"));
    74     iDevice = CBTDevice::NewL();
    80     iDevice = CBTDevice::NewL();
    75 //    iDialog = CObexUtilsDialog::NewL( this );
    81 //    iDialog = CObexUtilsDialog::NewL( this );
       
    82     iDeviceDialog = CHbDeviceDialogSymbian::NewL();
       
    83     iProgressDialog = CHbDeviceProgressDialogSymbian::NewL(CHbDeviceProgressDialogSymbian::EWaitDialog,this);
       
    84     
    76     FeatureManager::InitializeLibL();
    85     FeatureManager::InitializeLibL();
    77     iFeatureManagerInitialized = ETrue;
    86     iFeatureManagerInitialized = ETrue;
    78     FLOG(_L("[BTSU]\t CBTServiceStarter::ConstructL() completed"));
    87     FLOG(_L("[BTSU]\t CBTServiceStarter::ConstructL() completed"));
    79     }
    88     }
    80 
    89 
   107     delete iDevice;
   116     delete iDevice;
   108 
   117 
   109     delete iController;
   118     delete iController;
   110     delete iBTEngDiscovery;
   119     delete iBTEngDiscovery;
   111  //   delete iDialog;
   120  //   delete iDialog;
       
   121     delete iDeviceDialog;
   112     delete iProgressDialog;
   122     delete iProgressDialog;
       
   123     if(iProgressTimer)
       
   124         {
       
   125         delete iProgressTimer;
       
   126         }
   113 
   127 
   114     if(iWaiter && iWaiter->IsStarted() )
   128     if(iWaiter && iWaiter->IsStarted() )
   115         {
   129         {
   116         iWaiter->AsyncStop();
   130         iWaiter->AsyncStop();
   117         }
   131         }
   246         {
   260         {
   247         return iBytesSendWithBIP;
   261         return iBytesSendWithBIP;
   248         }
   262         }
   249     }
   263     }
   250 
   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 
   251 // -----------------------------------------------------------------------------
   301 // -----------------------------------------------------------------------------
   252 // CBTServiceStarter::ValidParameters
   302 // CBTServiceStarter::ValidParameters
   253 // -----------------------------------------------------------------------------
   303 // -----------------------------------------------------------------------------
   254 //
   304 //
   255 TBool CBTServiceStarter::ValidParameters( 
   305 TBool CBTServiceStarter::ValidParameters( 
   430         }
   480         }
   431     else
   481     else
   432         {
   482         {
   433         //       iDialog->LaunchWaitDialogL( R_BT_CONNECTING_WAIT_NOTE );
   483         //       iDialog->LaunchWaitDialogL( R_BT_CONNECTING_WAIT_NOTE );
   434         _LIT(KConnectText, "Connecting...");
   484         _LIT(KConnectText, "Connecting...");
   435         iProgressDialog = CHbDeviceProgressDialogSymbian::NewL(CHbDeviceProgressDialogSymbian::EWaitDialog,this);
       
   436         iProgressDialog->SetTextL(KConnectText);
   485         iProgressDialog->SetTextL(KConnectText);
   437         iProgressDialog->ShowL();
   486         iProgressDialog->ShowL();
   438         
   487         
   439         }    
   488         }    
   440     FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchWaitNoteL() completed"));
   489     FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchWaitNoteL() completed"));
   465 // -----------------------------------------------------------------------------
   514 // -----------------------------------------------------------------------------
   466 // CBTServiceStarter::LaunchProgressNoteL
   515 // CBTServiceStarter::LaunchProgressNoteL
   467 // -----------------------------------------------------------------------------
   516 // -----------------------------------------------------------------------------
   468 //
   517 //
   469 void CBTServiceStarter::LaunchProgressNoteL( MBTServiceProgressGetter* aGetter,
   518 void CBTServiceStarter::LaunchProgressNoteL( MBTServiceProgressGetter* aGetter,
   470                                              TInt aTotalSize )
   519                                              TInt aTotalSize, TInt aFileCount)
   471     {
   520     {
   472     FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchProgressNoteL()"));
   521     FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchProgressNoteL()"));
   473     (void) aTotalSize;
   522     (void) aTotalSize;
   474     
   523     
   475     if ( iService != EBTPrintingService )
   524     if ( iService != EBTPrintingService )
   476         {    
   525         {    
   477         iProgressGetter = aGetter;        
   526         iProgressGetter = aGetter;     
   478         CancelWaitNote();        
   527         CancelWaitNote();        
   479         
   528         
   480         if ( !iProgressDialogActive )
   529         if ( !iProgressDialogActive )
   481         	{
   530         	{
       
   531             iFileCount = aFileCount;
   482         	iMessageServerIndex = TObexUtilsMessageHandler::CreateOutboxEntryL( 
   532         	iMessageServerIndex = TObexUtilsMessageHandler::CreateOutboxEntryL( 
   483             KUidMsgTypeBt, R_BT_SEND_OUTBOX_SENDING );        
   533             KUidMsgTypeBt, R_BT_SEND_OUTBOX_SENDING );        
   484    //     	iDialog->LaunchProgressDialogL( this, aTotalSize, 
   534    //     	iDialog->LaunchProgressDialogL( this, aTotalSize, 
   485      //        								R_BT_SENDING_DATA, KBTProgressInterval );	
   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);
   486         	}        
   558         	}        
   487         iProgressDialogActive=ETrue;     
   559         iProgressDialogActive=ETrue;     
   488         }
   560         }
   489 
   561 
   490     FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchProgressNoteL() completed"));
   562     FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchProgressNoteL() completed"));
   491     }
   563     }
   492 
   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     }
   493 // -----------------------------------------------------------------------------
   636 // -----------------------------------------------------------------------------
   494 // CBTServiceStarter::CancelProgressNote
   637 // CBTServiceStarter::CancelProgressNote
   495 // -----------------------------------------------------------------------------
   638 // -----------------------------------------------------------------------------
   496 //
   639 //
   497 void CBTServiceStarter::CancelProgressNote()
   640 void CBTServiceStarter::CancelProgressNote()
   499     FLOG(_L("[BTSU]\t CBTServiceStarter::CancelProgressNote()"));
   642     FLOG(_L("[BTSU]\t CBTServiceStarter::CancelProgressNote()"));
   500 
   643 
   501  //   if ( iDialog )
   644  //   if ( iDialog )
   502         {
   645         {
   503   //      TRAP_IGNORE( iDialog->CancelProgressDialogL() );
   646   //      TRAP_IGNORE( iDialog->CancelProgressDialogL() );
   504         }
   647     if ( iProgressTimer )
       
   648          {
       
   649          iProgressTimer->Cancel();
       
   650          delete iProgressTimer;
       
   651          iProgressTimer = NULL;
       
   652          }
       
   653         }
       
   654     if(iDeviceDialog)
       
   655          {
       
   656          iDeviceDialog->Cancel();
       
   657          }
   505     }
   658     }
   506 
   659 
   507 // -----------------------------------------------------------------------------
   660 // -----------------------------------------------------------------------------
   508 // CBTServiceStarter::DialogDismissed
   661 // CBTServiceStarter::DialogDismissed
   509 // -----------------------------------------------------------------------------
   662 // -----------------------------------------------------------------------------
   547 
   700 
   548     switch ( aReason )
   701     switch ( aReason )
   549         {
   702         {
   550         case EBTSNoError:
   703         case EBTSNoError:
   551             {
   704             {
   552             if ( iService == EBTPrintingService )
   705     /*        if ( iService == EBTPrintingService )
   553                 {
   706                 {
   554                // resource = R_BT_DATA_SENT2;
   707                // resource = R_BT_DATA_SENT2;
   555                 
   708                 
   556                 _LIT(KText, "Data Sent");
   709                 _LIT(KText, "Data Sent");
   557                 buf.Copy(KText);
   710                 buf.Copy(KText);
   558                 }
   711                 }
   559             else
   712             else
   560                 {
   713                 {
   561                 //resource = R_BT_DATA_SENT;
   714                 //resource = R_BT_DATA_SENT;*/
   562                 _LIT(KText, "Data Sent");
   715                 _LIT(KText, "All files Sent to ");
   563                 buf.Copy(KText);
   716                 buf.Copy(KText);
   564                 }
   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 //                }
   565             break;
   728             break;
   566             }
   729             }
   567         case EBTSConnectingFailed:
   730         case EBTSConnectingFailed:
   568             {
   731             {
   569             //resource = R_BT_DEV_NOT_AVAIL;
   732             //resource = R_BT_DEV_NOT_AVAIL;
   633             break;
   796             break;
   634             }
   797             }
   635         }        
   798         }        
   636     
   799     
   637 //	TRAP_IGNORE(TObexUtilsUiLayer::ShowInformationNoteL( resource ) );	
   800 //	TRAP_IGNORE(TObexUtilsUiLayer::ShowInformationNoteL( resource ) );	
   638     CHbDeviceMessageBoxSymbian::InformationL(buf);
   801 //    CHbDeviceMessageBoxSymbian::InformationL(buf);
       
   802       TRAP_IGNORE(CHbDeviceNotificationDialogSymbian::NotificationL(KNullDesC, buf, KNullDesC));
   639     FLOG(_L("[BTSU]\t CBTServiceStarter::ShowNote() completed"));
   803     FLOG(_L("[BTSU]\t CBTServiceStarter::ShowNote() completed"));
   640     }
   804     }
   641 
   805 
   642 // -----------------------------------------------------------------------------
   806 // -----------------------------------------------------------------------------
   643 // CBTServiceStarter::LaunchConfirmationQuery
   807 // CBTServiceStarter::LaunchConfirmationQuery
  1072 
  1236 
  1073 
  1237 
  1074 void CBTServiceStarter::ProgressDialogClosed(const CHbDeviceProgressDialogSymbian* /* aDialog*/)
  1238 void CBTServiceStarter::ProgressDialogClosed(const CHbDeviceProgressDialogSymbian* /* aDialog*/)
  1075     {
  1239     {
  1076     }
  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     }