00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <avkon.hrh>
00032 #include <eikmenup.h>
00033 #include <AknGlobalNote.h>
00034 #include <BtPmpEx.rsg>
00035 #include <aknutils.h>
00036
00037 #include "BluetoothPMPExampleAppUi.h"
00038 #include "bluetoothpmpexample.hrh"
00039
00040 #include "BluetoothPMPExampleEngine.h"
00041 #include "BluetoothPMPExampleRTEContainer.h"
00042
00043
00044
00045
00046
00047
00048
00049 void CBluetoothPMPExampleAppUi::ConstructL()
00050 {
00051 BaseConstructL(EAknEnableSkin);
00052
00053 #ifdef __WINS__
00054
00055 _LIT(KEmulatorWarning,"This application should be tested on device or use S60bt driver on Emulator");
00056 CAknGlobalNote* note = CAknGlobalNote::NewLC();
00057 note->ShowNoteL(EAknGlobalConfirmationNote, KEmulatorWarning);
00058 CleanupStack::PopAndDestroy(note);
00059 #endif
00060
00061
00062 TRect rect;
00063 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,rect);
00064 iContainer = CBluetoothPMPExampleRTEContainer::NewL(rect);
00065 iContainer->SetMopParent( this );
00066
00067
00068 ResetUiL();
00069
00070
00071 iEngine = CBluetoothPMPExampleEngine::NewL( *this );
00072 iEngine->TurnBtOnL();
00073
00074
00075 AddToStackL( iContainer );
00076 }
00077
00078 void CBluetoothPMPExampleAppUi::ResetUiL()
00079 {
00080 TBuf<KMaxTimeFormatSpec+KMaxTimeFormatSpec> time;
00081 TTime now;
00082 now.HomeTime();
00083 now.FormatL(time,TTimeFormatSpec());
00084 iContainer->ClearScreenL();
00085 iContainer->DrawTextL(KInfo);
00086 iContainer->DrawTextL(time);
00087 iContainer->AddCarriageReturnL();
00088 }
00089
00090
00091
00092
00093
00094
00095
00096 CBluetoothPMPExampleAppUi::~CBluetoothPMPExampleAppUi()
00097 {
00098 RemoveFromStack( iContainer );
00099
00100 delete iContainer;
00101 iContainer = NULL;
00102
00103 delete iEngine;
00104 iEngine=NULL;
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 void CBluetoothPMPExampleAppUi::DynInitMenuPaneL(TInt aResourceId,
00117 CEikMenuPane* aMenuPane)
00118 {
00119 if (aResourceId == R_BLUETOOTHPMPEXAMPLE_MENU)
00120 {
00121 TBool myActiveDiscovery( iEngine->IsDiscoveryActive() );
00122
00123
00124 aMenuPane->SetItemDimmed(EBTCmdSendMessage, ETrue);
00125 aMenuPane->SetItemDimmed(EBTCmdStartSlave, ETrue);
00126 aMenuPane->SetItemDimmed(EBTCmdDiscoverDevices, ETrue);
00127 aMenuPane->SetItemDimmed(EBTCmdStopDiscovery, ETrue);
00128 aMenuPane->SetItemDimmed(EBTCmdDiscoverServices, ETrue);
00129 aMenuPane->SetItemDimmed(EBTCmdConnectDevices, ETrue);
00130 aMenuPane->SetItemDimmed(EBTCmdDisconnect, ETrue);
00131 aMenuPane->SetItemDimmed(EBTCmdDisconnectDevices, ETrue);
00132 aMenuPane->SetItemDimmed(EBtCmdBluetoothSetLimitedDiscoverableStatusOn, ETrue);
00133 aMenuPane->SetItemDimmed(EBtCmdBluetoothSetLimitedDiscoverableStatusOff, ETrue);
00134 aMenuPane->SetItemDimmed(EBTCmdShowConnectedDevices, ETrue);
00135
00136
00137 if (iEngine->iIsSlave)
00138 {
00139 if ( iEngine->iListener->IsConnected() )
00140 {
00141 aMenuPane->SetItemDimmed(EBTCmdSendMessage, EFalse);
00142 }
00143 aMenuPane->SetItemDimmed(EBTCmdDisconnect, EFalse);
00144 }
00145
00146 else if (iEngine->iIsMaster)
00147 {
00148 aMenuPane->SetItemDimmed(EBTCmdStopDiscovery, !myActiveDiscovery );
00149 aMenuPane->SetItemDimmed(EBTCmdDiscoverDevices, myActiveDiscovery );
00150 if ( iEngine->iDeviceDiscoverer->HasDevices() && !iEngine->iDeviceDiscoverer->IsActive())
00151 {
00152
00153 aMenuPane->SetItemDimmed(EBTCmdDiscoverServices, EFalse);
00154 }
00155 if ( iEngine->iServiceDiscoverer->HasServices() && !iEngine->iServiceDiscoverer->iRunning)
00156 {
00157
00158 aMenuPane->SetItemDimmed(EBTCmdConnectDevices, EFalse);
00159 }
00160 if ( iEngine->HasConnections() )
00161 {
00162
00163 aMenuPane->SetItemDimmed(EBTCmdSendMessage, EFalse);
00164 aMenuPane->SetItemDimmed(EBTCmdShowConnectedDevices, EFalse);
00165 aMenuPane->SetItemDimmed(EBTCmdDisconnectDevices, EFalse);
00166
00167 aMenuPane->SetItemDimmed(EBTCmdConnectDevices, ETrue);
00168 }
00169 }
00170
00171 else
00172 {
00173 aMenuPane->SetItemDimmed(EBTCmdStartSlave, EFalse);
00174 aMenuPane->SetItemDimmed(EBTCmdDiscoverDevices, EFalse);
00175 }
00176
00177
00178 #ifdef ENABLE_LIAC
00179
00180 if (myActiveDiscovery)
00181 {
00182 aMenuPane->SetItemDimmed(
00183 EBtCmdBluetoothSetLimitedDiscoverableStatusOn, ETrue );
00184 aMenuPane->SetItemDimmed(
00185 EBtCmdBluetoothSetLimitedDiscoverableStatusOff, ETrue );
00186 }
00187 else
00188 {
00189 TBool myLIAC( iEngine->LIAC() );
00190 aMenuPane->SetItemDimmed(
00191 EBtCmdBluetoothSetLimitedDiscoverableStatusOn, myLIAC);
00192 aMenuPane->SetItemDimmed(
00193 EBtCmdBluetoothSetLimitedDiscoverableStatusOff, !myLIAC);
00194 }
00195 #else
00196
00197 aMenuPane->SetItemDimmed(
00198 EBtCmdBluetoothSetLimitedDiscoverableStatusOn, ETrue );
00199 aMenuPane->SetItemDimmed(
00200 EBtCmdBluetoothSetLimitedDiscoverableStatusOff, ETrue );
00201 #endif
00202
00203
00204
00205 }
00206 }
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 TKeyResponse CBluetoothPMPExampleAppUi::HandleKeyEventL(
00217 const TKeyEvent& ,TEventCode )
00218 {
00219 return EKeyWasNotConsumed;
00220 }
00221
00222
00223
00224
00225
00226
00227
00228 void CBluetoothPMPExampleAppUi::HandleCommandL(TInt aCommand)
00229 {
00230 switch ( aCommand )
00231 {
00232 case EEikCmdExit:
00233 case EAknSoftkeyExit:
00234 case EAknCmdExit:
00235 case EAknSoftkeyBack:
00236 {
00237 iEngine->StopDiscovery();
00238 Exit();
00239 break;
00240 }
00241 case EBTCmdStartSlave:
00242 {
00243 if ( !iEngine->iIsSlave )
00244 iEngine->StartSlaveL();
00245 break;
00246 }
00247 case EBTCmdDiscoverDevices:
00248 {
00249 if ( !iEngine->iIsSlave )
00250 iEngine->DiscoverDevicesL();
00251 break;
00252 }
00253 case EBTCmdDiscoverServices:
00254 {
00255 if ( !iEngine->iIsSlave )
00256 iEngine->DiscoverServicesL();
00257 break;
00258 }
00259 case EBTCmdConnectDevices:
00260 {
00261 if ( !iEngine->iIsSlave )
00262 iEngine->ConnectDevicesL();
00263 break;
00264 }
00265 case EBTCmdDisconnect:
00266 {
00267 if ( iEngine->iIsSlave )
00268 {
00269 iEngine->StopSlaveL();
00270 ResetUiL();
00271 }
00272 break;
00273 }
00274 case EBTCmdDisconnectDevices:
00275 {
00276 if ( !iEngine->iIsSlave )
00277 iEngine->DisconnectDevices();
00278 break;
00279 }
00280 case EBTCmdShowConnectedDevices:
00281 {
00282 if ( !iEngine->iIsSlave )
00283 iEngine->ShowConnectedDevicesL();
00284 break;
00285 }
00286 case EBTCmdSendMessage:
00287 {
00288 TRAPD(err,iEngine->SendMessageL() );
00289 if( err )
00290 iContainer->ShowMessageL( KMsgSendFailed );
00291 break;
00292 }
00293 case EBtCmdClearScreen:
00294 {
00295 iContainer->ClearScreenL();
00296 break;
00297 }
00298 #ifdef ENABLE_LIAC
00299 case EBtCmdBluetoothSetLimitedDiscoverableStatusOn:
00300 {
00301 iEngine->SetLIAC( ETrue );
00302 break;
00303 }
00304 case EBtCmdBluetoothSetLimitedDiscoverableStatusOff:
00305 {
00306 iEngine->SetLIAC( EFalse );
00307 break;
00308 }
00309 #endif
00310 case EBTCmdStopDiscovery:
00311 {
00312 iEngine->StopDiscovery();
00313 break;
00314 }
00315
00316 default:
00317 break;
00318 }
00319 }
00320
00321 void CBluetoothPMPExampleAppUi::HandleResourceChangeL(TInt aType)
00322 {
00323 CAknAppUi::HandleResourceChangeL(aType);
00324 if ( aType == KEikDynamicLayoutVariantSwitch )
00325 {
00326 TRect rect;
00327 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,rect);
00328 iContainer->SetRect(rect);
00329 }
00330 }
00331
00332
00333 CBluetoothPMPExampleRTEContainer* CBluetoothPMPExampleAppUi::Container()
00334 {
00335 return iContainer;
00336 }
00337
00338