# HG changeset patch # User hgs # Date 1274083583 -10800 # Node ID a0ea99b6fa53f7645811722ccef2befc54a9700e # Parent df7a93ede42e5ffe4d6de8e11a65b7aed8ba96b7 201019_1 diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btaudioman/expinc/BTAccObserver.h --- a/bluetoothengine/btaudioman/expinc/BTAccObserver.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btaudioman/expinc/BTAccObserver.h Mon May 17 11:06:23 2010 +0300 @@ -91,6 +91,7 @@ virtual TInt ConnectionStatus(const TBTDevAddr& aAddr) = 0; virtual TBool IsAvrcpVolCTSupported() = 0; + virtual TBool IsAvrcpLegacyVolCTSupported() = 0; virtual TBool IsAbsoluteVolumeSupported(const TBTDevAddr& aAddr) = 0; /** diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btaudioman/inc/basrvaccman.h --- a/bluetoothengine/btaudioman/inc/basrvaccman.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btaudioman/inc/basrvaccman.h Mon May 17 11:06:23 2010 +0300 @@ -16,7 +16,7 @@ * Name : basrvaccman.h * Part of : BTEng / Bluetooth Accessory Server * Description : -* Version : %version: 3.1.4.1.2.2.13 % +* Version : %version: 3.1.4.1.2.2.14 % * */ @@ -101,6 +101,7 @@ TBTEngConnectionStatus ConnectionStatus4Client(const TBTDevAddr& aAddr) const; TBool IsAvrcpVolCTSupported(); + TBool IsAvrcpLegacyVolCTSupported(); TBool IsAbsoluteVolumeSupported(const TBTDevAddr& aAddr); TBool DisconnectIfAudioOpenFails(); @@ -223,6 +224,7 @@ CBasrvActive* iAsyncHandlingActive; TBool iAvrcpVolCTSupported; + TBool iAvrcpLegacyVolCTSupported; TBool iDisconnectIfAudioOpenFails; }; diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btaudioman/src/basrvaccman.cpp --- a/bluetoothengine/btaudioman/src/basrvaccman.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btaudioman/src/basrvaccman.cpp Mon May 17 11:06:23 2010 +0300 @@ -12,7 +12,7 @@ * Contributors: * * Description: Implementation of an accessory management. -* Version : %version: 14.1.10 % +* Version : %version: 14.1.11 % * */ @@ -53,17 +53,21 @@ CRepository* cenrep = NULL; TRAP_IGNORE(cenrep = CRepository::NewL(KCRUidBluetoothEngine)); TInt avrcpVol = EBTAvrcpVolCTNotSupported; + TInt avrcpLegacyVol = EBTAvrcpLegacyVolCTNotSupported; TInt autoDisconnect = EBTDisconnectIfAudioOpenFails; if (cenrep) { cenrep->Get(KBTAvrcpVolCTLV, avrcpVol); + cenrep->Get(KBTAvrcpLegacyVolCTLV, avrcpLegacyVol); cenrep->Get(KBTDisconnectIfAudioOpenFailsLV, autoDisconnect); delete cenrep; } iAvrcpVolCTSupported = (avrcpVol == EBTAvrcpVolCTSupported); + iAvrcpLegacyVolCTSupported = (avrcpLegacyVol == EBTAvrcpLegacyVolCTSupported); iDisconnectIfAudioOpenFails = (autoDisconnect == EBTDisconnectIfAudioOpenFails); TRACE_INFO((_L("[AVRCP_Vol_CT] %d [DisconnectIfAudioOpenFails] %d"), iAvrcpVolCTSupported, iDisconnectIfAudioOpenFails)) + TRACE_INFO((_L("[EBTAvrcpLegacyVolCTSupported] %d"), iAvrcpLegacyVolCTSupported)) LoadServicesL(); } @@ -532,6 +536,11 @@ { return iAvrcpVolCTSupported; } + +TBool CBasrvAccMan::IsAvrcpLegacyVolCTSupported() + { + return iAvrcpLegacyVolCTSupported; + } TBool CBasrvAccMan::IsAbsoluteVolumeSupported(const TBTDevAddr& aAddr) { diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/bteng/btengsettings/src/btengsettings.cpp --- a/bluetoothengine/bteng/btengsettings/src/btengsettings.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/bteng/btengsettings/src/btengsettings.cpp Mon May 17 11:06:23 2010 +0300 @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). +* Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" @@ -191,7 +191,7 @@ TRACE_FUNC_ENTRY aName.Zero(); TBool nameStatus = EFalse; - TBuf tmpName; + TBuf tmpName; TInt err = GetLocalNameModified( nameStatus ); @@ -413,7 +413,7 @@ if( !err ) { // BT registry keeps the device name in UTF-8 format. - TBuf8 utf8Name; + TBuf8 utf8Name; if( aName.Length() == 0 ) { // The error can be > 0 if there are unconverted characters. diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/bteng/bttoggle/src/bttoggle.cpp --- a/bluetoothengine/bteng/bttoggle/src/bttoggle.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/bteng/bttoggle/src/bttoggle.cpp Mon May 17 11:06:23 2010 +0300 @@ -1,5 +1,5 @@ /* -* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" @@ -154,7 +154,7 @@ } else //other than offline { - TBuf localName; + TBuf localName; iSettings->GetLocalName(localName); //There is no BT local name defined diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/bteng/conf/bteng.confml Binary file bluetoothengine/bteng/conf/bteng.confml has changed diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/bteng/conf/bteng_10204DAB.crml Binary file bluetoothengine/bteng/conf/bteng_10204DAB.crml has changed diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btmac/common/atcodec.h --- a/bluetoothengine/btmac/common/atcodec.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btmac/common/atcodec.h Mon May 17 11:06:23 2010 +0300 @@ -21,6 +21,7 @@ // INCLUDES #include +#include enum TATId { @@ -88,7 +89,6 @@ EATIntParam }; -const TInt KMaxATSize = 512; const TInt KMaxATParamSize = 256; class RReadStream; diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btmac/inc/btmonobearer/bmbcmdlistener.h --- a/bluetoothengine/btmac/inc/btmonobearer/bmbcmdlistener.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btmac/inc/btmonobearer/bmbcmdlistener.h Mon May 17 11:06:23 2010 +0300 @@ -90,7 +90,7 @@ RProperty iATRespProperty; // At command buffer - TBuf8 iAtCmdBuf; + TBuf8 iAtCmdBuf; }; #endif diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btmac/inc/btmonobearer/bmbplugin.h --- a/bluetoothengine/btmac/inc/btmonobearer/bmbplugin.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btmac/inc/btmonobearer/bmbplugin.h Mon May 17 11:06:23 2010 +0300 @@ -202,7 +202,7 @@ private: // owned // Last received and corrected-decoded message. - TBuf8 iInData; + TBuf8 iInData; TUid iInterfaceUid; TUint iTransactionId; TUint iOperationId; diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btmac/inc/btmonocmdhandler/HfpAtCmdHandler.h --- a/bluetoothengine/btmac/inc/btmonocmdhandler/HfpAtCmdHandler.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btmac/inc/btmonocmdhandler/HfpAtCmdHandler.h Mon May 17 11:06:23 2010 +0300 @@ -31,7 +31,7 @@ class MATExtObserver { public: - virtual void ATExtHandleCommandCompletedL(TInt aErr, const TDesC8& aReply) = 0; + virtual void ATExtHandleReplyReceivedL(TInt aErr, const TDesC8& aReply) = 0; virtual void UnsolicitedResultFromATExtL(TInt aErr, const TDesC8& aAT) = 0; }; diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btmac/inc/btmonocmdhandler/btmcprotdatabuf.h --- a/bluetoothengine/btmac/inc/btmonocmdhandler/btmcprotdatabuf.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btmac/inc/btmonocmdhandler/btmcprotdatabuf.h Mon May 17 11:06:23 2010 +0300 @@ -43,7 +43,7 @@ private: - TBuf8 iBuf; + TBuf8 iBuf; }; diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btmac/inc/btmonocmdhandler/btmcprotocol.h --- a/bluetoothengine/btmac/inc/btmonocmdhandler/btmcprotocol.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btmac/inc/btmonocmdhandler/btmcprotocol.h Mon May 17 11:06:23 2010 +0300 @@ -104,7 +104,7 @@ // From MATExtObserver - void ATExtHandleCommandCompletedL(TInt aErr, const TDesC8& aReply); + void ATExtHandleReplyReceivedL(TInt aErr, const TDesC8& aReply); void UnsolicitedResultFromATExtL(TInt aErr, const TDesC8& aAT); diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btmac/src/ATCodec/atccommand.cpp --- a/bluetoothengine/btmac/src/ATCodec/atccommand.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btmac/src/ATCodec/atccommand.cpp Mon May 17 11:06:23 2010 +0300 @@ -125,7 +125,7 @@ if (version == KStreamVersion1) { - iText.CreateL(KMaxATSize); + iText.CreateL(KDefaultCmdBufLength); aStream >> iText; iId = static_cast(aStream.ReadInt32L()); iType = static_cast(aStream.ReadInt32L()); @@ -491,7 +491,7 @@ TInt CATResult::Parse(TATId aId, TATType aType, const RATParamArray* aParams) { TRACE_FUNC - TInt err = iText.Create(KMaxATSize); + TInt err = iText.Create(KDefaultCmdBufLength); if (err != KErrNone) { @@ -541,14 +541,14 @@ { return err; } - if (iText.Length() + (*aParams)[j].Des().Length() > KMaxATSize) + if (iText.Length() + (*aParams)[j].Des().Length() > KDefaultCmdBufLength) { return KErrArgument; } iText.Append((*aParams)[j].Des()); if (j != aParams->Count() - 1) { - if (iText.Length() + comma.Length() > KMaxATSize) + if (iText.Length() + comma.Length() > KDefaultCmdBufLength) { return KErrArgument; } @@ -565,11 +565,11 @@ TInt CATResult::AddCRLF(TDes8& aText) { - if (aText.Length() + KCRLFSize > KMaxATSize) + if (aText.Length() + KCRLFSize > KDefaultCmdBufLength) { return KErrOverflow; } - TBuf8 buf(aText); + TBuf8 buf(aText); aText.Format(KCRLFFormat, &buf); return KErrNone; } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btmac/src/BTMonoCmdHandler/HfpAtCmdhandler.cpp --- a/bluetoothengine/btmac/src/BTMonoCmdHandler/HfpAtCmdhandler.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btmac/src/BTMonoCmdHandler/HfpAtCmdhandler.cpp Mon May 17 11:06:23 2010 +0300 @@ -63,7 +63,7 @@ } iATExtClient.HandleCommand(iCommander->iStatus, iCmdBuffer, iReplyBuffer, iRemainingReplyLengthPckg, iReplyTypePckg); - iCommander->GoActive(); + iCommander->GoActive(); } void CHFPAtCmdHandler::RequestCompletedL(CBtmcActive& aActive, TInt aErr) @@ -74,32 +74,37 @@ { case EHandleCommandRequest: { - if(err == KErrNone) - { - if (iRemainingReplyLengthPckg()) - { - /*RBuf8 reply2; - reply2.CreateL(iRemainingReplyLengthPckg() + iReplyBuffer.Length()); - err = iATExtClient.GetNextPartOfReply(reply2, iRemainingReplyLengthPckg); - if (!err) + if(err == KErrNone) + { + if (iRemainingReplyLengthPckg()) + { + TRACE_INFO((_L8("reply '%S'"), &iReplyBuffer)) + iObserver.ATExtHandleReplyReceivedL(err, iReplyBuffer); + do { - reply2.Insert(0, iReplyBuffer); + TRACE_INFO((_L8("iRemainingReplyLength '%d'"), iRemainingReplyLengthPckg())) + RBuf8 reply; + reply.CreateL(iRemainingReplyLengthPckg()); + err = iATExtClient.GetNextPartOfReply(iRecvBuffer, iRemainingReplyLengthPckg()); + if (!err) + { + reply.Insert(0, iRecvBuffer); + } + TRACE_INFO((_L8("reply '%S'"), &reply)) + iObserver.ATExtHandleReplyReceivedL(err, reply); + reply.Close(); } - TRACE_INFO((_L8("reply '%S'"), &reply2)) - iObserver.ATExtHandleCommandCompletedL(err, reply2); - reply2.Close();*/ - iATExtClient.GetNextPartOfReply( iRecvBuffer, - iRemainingReplyLength ); - } - else - { + while (iRemainingReplyLengthPckg()); + } + else + { TRACE_INFO((_L8("reply '%S'"), &iReplyBuffer)) - iObserver.ATExtHandleCommandCompletedL(err, iReplyBuffer); - } - } + iObserver.ATExtHandleReplyReceivedL(err, iReplyBuffer); + } + } else { - iObserver.ATExtHandleCommandCompletedL(err, iSystemReply); + iObserver.ATExtHandleReplyReceivedL(err, iSystemReply); } break; } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btmac/src/BTMonoCmdHandler/btmccallinghandler.cpp --- a/bluetoothengine/btmac/src/BTMonoCmdHandler/btmccallinghandler.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btmac/src/BTMonoCmdHandler/btmccallinghandler.cpp Mon May 17 11:06:23 2010 +0300 @@ -94,7 +94,7 @@ TInt result = KErrNone; if (!aErr) { - TBuf8 buf; + TBuf8 buf; aErr = iRespProperty.Get(buf); if (!aErr && buf.Length() >= sizeof(TInt)) { diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btmac/src/BTMonoCmdHandler/btmcoperator.cpp --- a/bluetoothengine/btmac/src/BTMonoCmdHandler/btmcoperator.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btmac/src/BTMonoCmdHandler/btmcoperator.cpp Mon May 17 11:06:23 2010 +0300 @@ -20,6 +20,7 @@ #include "btmcprotocol.h" #include #include "debug.h" +#include // ----------------------------------------------------------------------------- // CBtmcOperator::NewL @@ -90,8 +91,12 @@ { LEAVE_IF_ERROR(params.Append(TATParam(0))); TBuf8 buf8; - buf8.Copy(iInfo.iName); // need Unicode convert? - LEAVE_IF_ERROR(params.Append(TATParam(buf8, EATDQStringParam))); + buf8.Copy(iInfo.iName); // Unicode convert: + TBuf16 buf16; + TBuf8 buf8Copy; + LEAVE_IF_ERROR(CnvUtfConverter::ConvertToUnicodeFromUtf8(buf16,buf8)); + buf8Copy.Copy(buf16); + LEAVE_IF_ERROR(params.Append(TATParam(buf8Copy, EATDQStringParam))); } else { diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btmac/src/BTMonoCmdHandler/btmcprotocol.cpp --- a/bluetoothengine/btmac/src/BTMonoCmdHandler/btmcprotocol.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btmac/src/BTMonoCmdHandler/btmcprotocol.cpp Mon May 17 11:06:23 2010 +0300 @@ -399,7 +399,7 @@ { return; } - TBuf8 cmddes; + TBuf8 cmddes; if (iInDataBuf.NextCommand(cmddes)) { return; @@ -410,7 +410,7 @@ } TRACE_INFO_SEG( { - TBuf8 buf; + TBuf8 buf; buf = cmddes; buf.Trim(); Trace(_L8("[HFP] [I] %S"), &buf); @@ -1083,7 +1083,7 @@ for (TInt i = 0; iCredit >0 && i < count; i++) { iCredit--; - TBuf8 buf; + TBuf8 buf; buf.Copy(iOutgoPacketQueue->MdcaPoint(0)); iObserver.SendProtocolDataL(buf); iOutgoPacketQueue->Delete(0); @@ -1199,7 +1199,7 @@ } } -void CBtmcProtocol::ATExtHandleCommandCompletedL(TInt aErr, const TDesC8& aReply) +void CBtmcProtocol::ATExtHandleReplyReceivedL(TInt aErr, const TDesC8& aReply) { TRACE_FUNC if(aErr) diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btdevicedialogplugin/btdevicedialogplugin.pro --- a/bluetoothengine/btnotif/btdevicedialogplugin/btdevicedialogplugin.pro Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/btdevicedialogplugin.pro Mon May 17 11:06:23 2010 +0300 @@ -31,13 +31,18 @@ inc/btdevicedialogpluginerrors.h \ inc/btdevicedialogplugin.h \ inc/btdevicesearchdialogwidget.h \ - inc/btdevicedialogplugintrace.h + inc/btmoredevicesdialogwidget.h \ + inc/btsenddialogwidget.h \ + inc/btdevicedialogplugintrace.h + SOURCES += src/btdevicedialogplugin.cpp \ src/btdevicedialoginputwidget.cpp \ src/btdevicedialogquerywidget.cpp \ src/btdevicedialognotifwidget.cpp \ - src/btdevicesearchdialogwidget.cpp + src/btdevicesearchdialogwidget.cpp \ + src/btmoredevicesdialogwidget.cpp \ + src/btsenddialogwidget.cpp RESOURCES += btdevicedialogplugin.qrc diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btdevicedialogplugin/btdevicedialogplugin.qrc --- a/bluetoothengine/btnotif/btdevicedialogplugin/btdevicedialogplugin.qrc Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/btdevicedialogplugin.qrc Mon May 17 11:06:23 2010 +0300 @@ -1,6 +1,9 @@ docml/bt-device-search-dialog.docml + docml/bt-more-devices-dialog.docml + docml/bt-send-dialog.docml icons/qgn_prop_sml_bt.svg + icons/qtg_large_bluetooth.svg diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-device-search-dialog.docml --- a/bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-device-search-dialog.docml Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-device-search-dialog.docml Mon May 17 11:06:23 2010 +0300 @@ -1,44 +1,63 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - + - - - + + + - - - - - - - - + + + + + - - + + + - + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-more-devices-dialog.docml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-more-devices-dialog.docml Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-send-dialog.docml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-send-dialog.docml Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btdevicedialogplugin/icons/qtg_large_bluetooth.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/icons/qtg_large_bluetooth.svg Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicesearchdialogwidget.h --- a/bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicesearchdialogwidget.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicesearchdialogwidget.h Mon May 17 11:06:23 2010 +0300 @@ -28,7 +28,8 @@ #include #include #include - +#include +#include struct device { @@ -53,11 +54,12 @@ HbPopup *deviceDialogWidget() const; public slots: - void stopClicked(); + void stopRetryClicked(); void retryClicked(); -// void viewByClicked(); + void viewByClicked(); void deviceSelected(const QModelIndex& modelIndex); // void viewByItemSelected(int index); + void selectionDialogClosed(HbAction*); private: bool constructDialog(const QVariantMap ¶meters); @@ -85,6 +87,11 @@ QList mDeviceTypeList; QList mDeviceList; HbListView* mListView; + HbPushButton* mStopRetryBtn; + HbPushButton* mViewByBtn; + HbLabel* mSearchLabel; + HbLabel* mSearchIconLabel; + HbLabel* mSearchDoneLabel; bool mViewByChosen; QList mDeviceLstOfType; int mDeviceLstIdx; diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btdevicedialogplugin/inc/btmoredevicesdialogwidget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/inc/btmoredevicesdialogwidget.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0"" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ + + +#ifndef BTMOREDEVICESDIALOGWIDGET_H_ +#define BTMOREDEVICESDIALOGWIDGET_H_ + +#include +#include +#include +#include +#include +#include +#include + + +class BTMoreDevicesDialogWidget : public HbDialog, + public HbDeviceDialogInterface + { + Q_OBJECT + +public: + BTMoreDevicesDialogWidget(const QVariantMap ¶meters); + ~BTMoreDevicesDialogWidget(); + +public: // from HbDeviceDialogInterface + bool setDeviceDialogParameters(const QVariantMap ¶meters); + int deviceDialogError() const; + void closeDeviceDialog(bool byClient); + HbPopup *deviceDialogWidget() const; + // virtual QObject *signalSender() const; + +public slots: + void moreDevicesClicked(); + void cancelClicked(); + void deviceSelected(const QModelIndex& modelIndex); + // void inputClosed(HbAction *action); + +private: + bool constructDialog(const QVariantMap ¶meters); + void hideEvent(QHideEvent *event); + void showEvent(QShowEvent *event); + QIcon icon(/*QString deviceType*/); + +signals: + void deviceDialogClosed(); + void deviceDialogData(QVariantMap data); + +private: + HbDocumentLoader *mLoader; + int mDeviceDialogData; +// HbAction *mMoreAction; +// HbAction *mCancelAction; + + /** + * + * item model for content list view. + */ + + QStandardItemModel* mContentItemModel; + + Q_DISABLE_COPY(BTMoreDevicesDialogWidget) + }; + +#endif /* BTMOREDEVICESDIALOGWIDGET_H_ */ diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btdevicedialogplugin/inc/btsenddialogwidget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/inc/btsenddialogwidget.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0"" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ + + +#ifndef BTSENDDIALOGWIDGET_H_ +#define BTSENDDIALOGWIDGET_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +class BTSendDialogWidget : public HbDialog, + public HbDeviceDialogInterface + { + Q_OBJECT + +public: + BTSendDialogWidget(const QVariantMap ¶meters); + ~BTSendDialogWidget(); + +public: // from HbDeviceDialogInterface + bool setDeviceDialogParameters(const QVariantMap ¶meters); + int deviceDialogError() const; + void closeDeviceDialog(bool byClient); + HbPopup *deviceDialogWidget() const; + virtual QObject *signalSender() const; + +public slots: +// void hideClicked(); +// void cancelClicked(); + void inputClosed(HbAction* action); +private: + bool constructDialog(const QVariantMap ¶meters); + void hideEvent(QHideEvent *event); + void showEvent(QShowEvent *event); + +signals: + void deviceDialogClosed(); + +private: + HbDocumentLoader *mLoader; + QStandardItemModel* mContentItemModel; + HbProgressBar* mProgressBar; + HbLabel* mLabel; + HbListView* mListView; + int mFileIndex; + + Q_DISABLE_COPY(BTSendDialogWidget) + }; + +#endif /* BTSENDDIALOGWIDGET_H_ */ diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialogplugin.cpp --- a/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialogplugin.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialogplugin.cpp Mon May 17 11:06:23 2010 +0300 @@ -27,6 +27,8 @@ #include "btdevicedialogpluginerrors.h" #include "btdevicesearchdialogwidget.h" +#include "btmoredevicesdialogwidget.h" +#include "btsenddialogwidget.h" Q_EXPORT_PLUGIN2(btdevicedialogplugin, BtDeviceDialogPlugin) @@ -191,9 +193,15 @@ case TBluetoothDialogParams::EInput: deviceDialog = new BtDeviceDialogInputWidget(parameters); break; + case TBluetoothDialogParams::EMoreDevice: + deviceDialog = new BTMoreDevicesDialogWidget(parameters); + break; case TBluetoothDialogParams::EDeviceSearch: deviceDialog = new BTDeviceSearchDialogWidget(parameters); break; + case TBluetoothDialogParams::ESend: + deviceDialog = new BTSendDialogWidget(parameters); + break; case TBluetoothDialogParams::EGlobalNotif: deviceDialog = new BtDeviceDialogNotifWidget(parameters); break; diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicesearchdialogwidget.cpp --- a/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicesearchdialogwidget.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicesearchdialogwidget.cpp Mon May 17 11:06:23 2010 +0300 @@ -17,11 +17,13 @@ #include "btdevicesearchdialogwidget.h" -#include + #include #include -#include +#include + #include +#include const char* DOCML_BTDEV_SEARCH_DIALOG = ":/docml/bt-device-search-dialog.docml"; @@ -38,54 +40,75 @@ BTDeviceSearchDialogWidget::~BTDeviceSearchDialogWidget() { - delete mLoader; - mLoader = NULL; - delete mContentItemModel; - mContentItemModel = NULL; + if(mLoader) + { + delete mLoader; + mLoader = NULL; + } + if(mContentItemModel) + { + delete mContentItemModel; + mContentItemModel = NULL; + } // delete mRbl; // delete mViewByDialog; } bool BTDeviceSearchDialogWidget::setDeviceDialogParameters(const QVariantMap ¶meters) { - device newDevice; - - // newDevice.mDeviceName = parameters.value("deviceName").toString(); - newDevice.mDeviceName = parameters.value(parameters.keys().at(0)).toString(); - - // newDevice.mDeviceType = parameters.value("deviceType").toString(); - newDevice.mDeviceIdx = mDeviceLstIdx; - - mDeviceList.append(newDevice); - mDeviceLstIdx++; + if(parameters.keys().at(0).compare("Search Completed")==0) + { + mSearchLabel->hide(); + + mSearchIconLabel->hide(); + + mSearchDoneLabel->show(); + mSearchDoneLabel->setTextWrapping(Hb::TextWordWrap); + mSearchDoneLabel->setAlignment(Qt::AlignLeft); + mSearchDoneLabel->setPlainText("Search Done"); + + mStopRetryBtn->setText("Retry"); + } + else + { + device newDevice; - - QStringList info; - // if(!mViewByChosen) - { - info.append(newDevice.mDeviceName); - // info.append(newDevice.mDeviceType); - QStandardItem* listitem = new QStandardItem(); - listitem->setData(info, Qt::DisplayRole); + // newDevice.mDeviceName = parameters.value("deviceName").toString(); + newDevice.mDeviceName = parameters.value(parameters.keys().at(0)).toString(); + + // newDevice.mDeviceType = parameters.value("deviceType").toString(); + newDevice.mDeviceIdx = mDeviceLstIdx; + + mDeviceList.append(newDevice); + mDeviceLstIdx++; - listitem->setIcon(icon()); - - mContentItemModel->appendRow(listitem); - } - /* else - { - if(mDeviceTypeList[mSelectedType] == newDevice.mDeviceType) + QStringList info; + // if(!mViewByChosen) { info.append(newDevice.mDeviceName); - info.append(newDevice.mDeviceType); + // info.append(newDevice.mDeviceType); QStandardItem* listitem = new QStandardItem(); listitem->setData(info, Qt::DisplayRole); - - listitem->setIcon(icon(newDevice.mDeviceType)); - + + listitem->setIcon(icon()); + mContentItemModel->appendRow(listitem); } - }*/ + /* else + { + if(mDeviceTypeList[mSelectedType] == newDevice.mDeviceType) + { + info.append(newDevice.mDeviceName); + info.append(newDevice.mDeviceType); + QStandardItem* listitem = new QStandardItem(); + listitem->setData(info, Qt::DisplayRole); + + listitem->setIcon(icon(newDevice.mDeviceType)); + + mContentItemModel->appendRow(listitem); + } + }*/ + } return true; } @@ -115,20 +138,28 @@ mLoader->load(DOCML_BTDEV_SEARCH_DIALOG, &ok); if(ok) { - HbLabel* label = qobject_cast(mLoader->findWidget("heading")); - if(label) - { - label->setTextWrapping(Hb::TextWordWrap); - label->setAlignment(Qt::AlignHCenter); - label->setPlainText("Bluetooth - Found devices"); - } - this->setHeadingWidget(label); - this->setFrameType(HbDialog::Strong); - this->setBackgroundFaded(false); + HbLabel* heading = qobject_cast(mLoader->findWidget("heading")); + heading->setTextWrapping(Hb::TextWordWrap); + heading->setAlignment(Qt::AlignHCenter); + heading->setPlainText("Bluetooth - Found devices"); + setHeadingWidget(heading); + + mSearchLabel = qobject_cast(mLoader->findWidget("searchLabel")); + mSearchLabel->setTextWrapping(Hb::TextWordWrap); + mSearchLabel->setAlignment(Qt::AlignHCenter); + mSearchLabel->setPlainText("Searching..."); + + mSearchIconLabel = qobject_cast(mLoader->findWidget("iconLabel")); + mSearchIconLabel->setIcon(icon()); - HbPushButton* viewBy = qobject_cast(mLoader->findWidget("viewBy")); - HbPushButton* stop = qobject_cast(mLoader->findWidget("stop")); - HbPushButton* retry = qobject_cast(mLoader->findWidget("retry")); + mSearchDoneLabel = qobject_cast(mLoader->findWidget("searchDoneLabel")); + mSearchDoneLabel->hide(); + + setFrameType(HbDialog::Strong); + setBackgroundFaded(false); + + mViewByBtn = qobject_cast(mLoader->findWidget("viewby")); + mStopRetryBtn = qobject_cast(mLoader->findWidget("stop")); mListView = qobject_cast(mLoader->findWidget("listView")); mListView->setSelectionMode(HbAbstractItemView::SingleSelection); @@ -137,19 +168,13 @@ mListView->setModel(mContentItemModel);//, prototype); connect(mListView, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex))); - connect(stop, SIGNAL(clicked()), this, SLOT(stopClicked())); - connect(retry, SIGNAL(clicked()), this, SLOT(retryClicked())); - connect(viewBy, SIGNAL(clicked()), this, SLOT(viewByClicked())); + connect(mStopRetryBtn, SIGNAL(clicked()), this, SLOT(stopRetryClicked())); + connect(mViewByBtn, SIGNAL(clicked()), this, SLOT(viewByClicked())); QGraphicsWidget *widget = mLoader->findWidget(QString("container")); - this->setContentWidget(widget); + setContentWidget(widget); } - else - { - - } - - this->setBackgroundFaded(false); + setBackgroundFaded(false); setDismissPolicy(HbPopup::TapOutside); setTimeout(HbPopup::NoTimeout); @@ -163,13 +188,10 @@ void BTDeviceSearchDialogWidget::hideEvent(QHideEvent *event) { HbDialog::hideEvent(event); - if(mDeviceDialogData == 0) - { - QVariantMap val; - QVariant index(-1); - val.insert("selectedindex",index); - emit deviceDialogData(val); - } + QVariantMap val; + QVariant index(-1); + val.insert("selectedindex",index); + emit deviceDialogData(val); emit deviceDialogClosed(); } @@ -178,12 +200,48 @@ HbDialog::showEvent(event); } -void BTDeviceSearchDialogWidget::stopClicked() +void BTDeviceSearchDialogWidget::stopRetryClicked() { QVariantMap val; - QVariant index("Stop"); - val.insert("Stop",index); - emit deviceDialogData(val); + if(mStopRetryBtn->text().compare("Retry")==0) + { + QVariant index("Retry"); + val.insert("Retry",index); + emit deviceDialogData(val); + delete mContentItemModel; + mContentItemModel = new QStandardItemModel(this); + mListView->setModel(mContentItemModel); + mStopRetryBtn->setText("Stop"); + + mSearchLabel->setTextWrapping(Hb::TextWordWrap); + mSearchLabel->setAlignment(Qt::AlignHCenter); + mSearchLabel->setPlainText("Searching..."); + + mSearchIconLabel->setIcon(icon()); + mSearchLabel->show(); + + mSearchIconLabel->show(); + + mSearchDoneLabel->hide(); + } + else + { + mStopRetryBtn->setText("Retry"); + + mSearchLabel->hide(); + + mSearchIconLabel->hide(); + + mSearchDoneLabel->show(); + mSearchDoneLabel->setTextWrapping(Hb::TextWordWrap); + mSearchDoneLabel->setAlignment(Qt::AlignLeft); + mSearchDoneLabel->setPlainText("Search Done"); + + QVariantMap val; + QVariant index("Stop"); + val.insert("Stop",index); + emit deviceDialogData(val); + } } void BTDeviceSearchDialogWidget::retryClicked() @@ -195,10 +253,29 @@ delete mContentItemModel; mContentItemModel = new QStandardItemModel(this); mListView->setModel(mContentItemModel); + + } -//void BTDeviceSearchDialogWidget::viewByClicked() -// { +void BTDeviceSearchDialogWidget::viewByClicked() + { + QStringList list; + list << "Select all" << "Audio devices" << "Computers" << "Input devices" << "Phones" << "Other devices"; + + HbSelectionDialog *query = new HbSelectionDialog; + query->setStringItems(list); + query->setSelectionMode(HbAbstractItemView::MultiSelection); + + QList current; + current.append(QVariant(0)); + query->setSelectedItems(current); + + query->setAttribute(Qt::WA_DeleteOnClose); + + query->open(this,SLOT(selectionDialogClosed(HbAction*))); + + //connect(query, SIGNAL(finished(HbAction*)), this, SLOT(selectionDialogClosed(HbAction*))); + /* mViewByDialog->setDismissPolicy(HbPopup::NoDismiss); mViewByDialog->setTimeout(HbPopup::NoTimeout); @@ -234,7 +311,19 @@ mViewByDialog->setMaximumWidth(500); mViewByDialog->show();*/ - // } + } + +void BTDeviceSearchDialogWidget::selectionDialogClosed(HbAction* action) + { + Q_UNUSED(action); + + /* HbSelectionDialog *dlg = (HbSelectionDialog*)(sender()); + if(dlg->actions().first() == action) { + + } + else if(dlg->actions().at(1) == action) { + }*/ + } void BTDeviceSearchDialogWidget::deviceSelected(const QModelIndex& modelIndex) { @@ -254,9 +343,9 @@ QVariant index(row); val.insert("selectedindex",index); emit deviceDialogData(val); - mDeviceDialogData = 1;//flag is to say that device dialog data is emitted required when we cancel the dialog +// mDeviceDialogData = 1;//flag is to say that device dialog data is emitted required when we cancel the dialog //emit deviceDialogClosed(); - this->close(); + // this->close(); } //void BTDeviceSearchDialogWidget::viewByItemSelected(int index) @@ -354,6 +443,6 @@ { return (QIcon(QString(":/icons/qgn_prop_bt_unknown.svg"))); }*/ - return QIcon(QString(":/icons/qgn_prop_sml_bt.svg")); + return QIcon(QString(":/icons/qtg_large_bluetooth.svg")); } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btdevicedialogplugin/src/btmoredevicesdialogwidget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btmoredevicesdialogwidget.cpp Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,234 @@ +/* + * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0"" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ + + +#include +#include +#include +#include +#include +#include +#include "btmoredevicesdialogwidget.h" + + +const char* DOCML_BT_MORE_DEV_DIALOG = ":/docml/bt-more-devices-dialog.docml"; + + +BTMoreDevicesDialogWidget::BTMoreDevicesDialogWidget(const QVariantMap ¶meters) +:HbDialog() + { + mDeviceDialogData = 0; + constructDialog(parameters); + } + +BTMoreDevicesDialogWidget::~BTMoreDevicesDialogWidget() + { + if(mLoader) + { + delete mLoader; + mLoader = NULL; + } + if(mContentItemModel) + { + delete mContentItemModel; + mContentItemModel =NULL; + } + } + +bool BTMoreDevicesDialogWidget::setDeviceDialogParameters(const QVariantMap ¶meters) + { + QStandardItem* listitem = new QStandardItem(); + QStringList info; + // info.append(parameters.value("deviceName").toString()); + //info.append(parameters.value("deviceType").toString()); + info.append(parameters.value(parameters.keys().at(0)).toString()); + + + listitem->setData(info, Qt::DisplayRole); + listitem->setIcon(icon()); + // listitem->setIcon(icon(parameters.value("deviceType").toString())); + + mContentItemModel->appendRow(listitem); + + return true; + } + +int BTMoreDevicesDialogWidget::deviceDialogError() const + { + return 0; + } + +void BTMoreDevicesDialogWidget::closeDeviceDialog(bool byClient) + { + Q_UNUSED(byClient); + this->close(); + } + +HbPopup* BTMoreDevicesDialogWidget::deviceDialogWidget() const + { + return const_cast(this); + } + +bool BTMoreDevicesDialogWidget::constructDialog(const QVariantMap &/*parameters*/) + { + mLoader = new HbDocumentLoader(); + bool ok = false; + + mLoader->load(DOCML_BT_MORE_DEV_DIALOG, &ok); + if(ok) + { + HbLabel* label = qobject_cast(mLoader->findWidget("label")); + if(label) + { + label->setTextWrapping(Hb::TextWordWrap); + label->setPlainText("Send to:"); + } + this->setHeadingWidget(label); + HbPushButton* moreDevices = qobject_cast(mLoader->findWidget("moreDevices")); + HbPushButton* cancel = qobject_cast(mLoader->findWidget("cancel")); + + HbListView* listView = qobject_cast(mLoader->findWidget("listView")); + listView->setSelectionMode(HbAbstractItemView::SingleSelection); + + mContentItemModel = new QStandardItemModel(this); + listView->setModel(mContentItemModel);//, prototype); + + // QList values = parameters.values(); + + /* for(int i=0;i < values.count();i++) + { + QStandardItem* listitem = new QStandardItem(); + // parameters. + // QString string = values.at(i).toString(); + + listitem->setData(values.at(i).toString(), Qt::DisplayRole); + // listitem->setData(QString("search"), Qt::DisplayRole); + //Todo - Insert icons based on the device class + QIcon icon(QString(":/qgn_prop_sml_bt.svg")); + listitem->setIcon(icon); + + mContentItemModel->appendRow(listitem); + }*/ + + connect(listView, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex))); + connect(moreDevices, SIGNAL(clicked()), this, SLOT(moreDevicesClicked())); + connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked())); + + QGraphicsWidget *widget = mLoader->findWidget(QString("container")); + this->setContentWidget(widget); + } + + + this->setBackgroundFaded(false); + setDismissPolicy(HbPopup::NoDismiss); + setTimeout(HbPopup::NoTimeout); + return true; + } + +void BTMoreDevicesDialogWidget::hideEvent(QHideEvent *event) + { + HbDialog::hideEvent(event); +// if(mDeviceDialogData == 0) + { + QVariantMap val; + QVariant index(-1); + val.insert("selectedindex",index); + emit deviceDialogData(val); + emit deviceDialogClosed(); + } + // + } + +void BTMoreDevicesDialogWidget::showEvent(QShowEvent *event) + { + HbDialog::showEvent(event); + } + +void BTMoreDevicesDialogWidget::moreDevicesClicked() + { + QVariantMap val; + QVariant index("MoreDevices"); + val.insert("MoreDevices",index); + emit deviceDialogData(val); + // mDeviceDialogData = 1;//flag is to say that device dialog data is emitted required when we cancel the dialog + // this->close(); + // TODO + } + +void BTMoreDevicesDialogWidget::cancelClicked() + { + // TODO + this->close(); + } + +void BTMoreDevicesDialogWidget::deviceSelected(const QModelIndex& modelIndex) + { + int row = modelIndex.row(); + QVariantMap val; + QVariant index(row); + val.insert("selectedindex",index); + + + + + emit deviceDialogData(val); + // mDeviceDialogData = 1;//flag is to say that device dialog data is emitted required when we cancel the dialog + // this->close(); + + } + +QIcon BTMoreDevicesDialogWidget::icon(/*QString deviceType*/) + { + /* if(deviceType == "Audio") + { + return (QIcon(QString(":/qgn_prop_bt_audio.svg"))); + } + else if(deviceType == "Car-kit") + { + return (QIcon(QString(":/qgn_prop_bt_car_kit.svg"))); + } + else if(deviceType == "Computer") + { + return (QIcon(QString(":/qgn_prop_bt_computer.svg"))); + } + else if(deviceType == "Headset") + { + return (QIcon(QString(":/qgn_prop_bt_headset.svg"))); + } + else if(deviceType == "Keyboard") + { + return (QIcon(QString(":/qgn_prop_bt_keyboard.svg"))); + } + else if(deviceType == "Mouse") + { + return (QIcon(QString(":/qgn_prop_bt_mouse.svg"))); + } + else if(deviceType == "Phone") + { + return (QIcon(QString(":/qgn_prop_bt_phone.svg"))); + } + else if(deviceType == "Printer") + { + return (QIcon(QString(":/qgn_prop_bt_printer.svg"))); + } + else + { + return (QIcon(QString(":/qgn_prop_bt_unknown.svg"))); + }*/ + return QIcon(QString(":/icons/qtg_large_bluetooth.svg")); + } + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btdevicedialogplugin/src/btsenddialogwidget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btsenddialogwidget.cpp Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0"" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ + + +#include +#include +#include +#include +#include +#include +#include "btsenddialogwidget.h" + + + +const char* DOCML_BT_SEND_DIALOG = ":/docml/bt-send-dialog.docml"; + +BTSendDialogWidget::BTSendDialogWidget(const QVariantMap ¶meters) +:HbDialog() + { + // LOG(ELevel1,_L("BTSendDialogWidget::BTSendDialogWidget")); + constructDialog(parameters); + + } + +BTSendDialogWidget::~BTSendDialogWidget() + { + if(mLoader) + { + delete mLoader; + mLoader = NULL; + } + if(mContentItemModel) + { + delete mContentItemModel; + mContentItemModel = NULL; + } + } + +bool BTSendDialogWidget::setDeviceDialogParameters(const QVariantMap ¶meters) + { + // LOG(ELevel1,_L("BTSendDialogWidget::setDeviceDialogParameters ")); + + if(mFileIndex != parameters.value("currentFileIdx").toString().toInt() ) + { + mLabel->setTextWrapping(Hb::TextWordWrap); + mLabel->setAlignment(Qt::AlignHCenter); + //Todo - replace this with the actual text from parameters + + QString headLabel; + headLabel.append(QString("Sending file ")); + headLabel.append(parameters.value("currentFileIdx").toString()); + headLabel.append('/'); + headLabel.append(parameters.value("totalFilesCnt").toString()); + headLabel.append(QString(" to ")); + headLabel.append(parameters.value("destinationName").toString()); + mLabel->setPlainText(headLabel); + + QStringList info; + info.append(parameters.value("fileName").toString()); + info.append(parameters.value("fileSzTxt").toString()); + + QStandardItem* listitem = new QStandardItem(); + // parameters. + listitem->setData(info, Qt::DisplayRole); + + //Todo - Insert icons based on the device class + QIcon icon(QString(":/icons/qtg_large_bluetooth.svg")); + listitem->setIcon(icon); + + delete mContentItemModel; + mContentItemModel = new QStandardItemModel(this); + mListView->setModel(mContentItemModel);//, prototype); + + mContentItemModel->appendRow(listitem); + + mProgressBar->setMinimum(0); + mProgressBar->setProgressValue(0); + mProgressBar->setMaximum(parameters.value("fileSz").toInt()); + mFileIndex = parameters.value("currentFileIdx").toString().toInt(); + } + else + { + mProgressBar->setProgressValue(parameters.value("progressValue").toInt()); + } + // LOG(ELevel1,_L("BTSendDialogWidget::setDeviceDialogParameters Completed")); + return true; + } + +int BTSendDialogWidget::deviceDialogError() const + { + return 0; + } + +void BTSendDialogWidget::closeDeviceDialog(bool byClient) + { + Q_UNUSED(byClient); + this->close(); + } + +HbPopup* BTSendDialogWidget::deviceDialogWidget() const + { + return const_cast(this); + } + +QObject *BTSendDialogWidget::signalSender() const +{ + return const_cast(this); +} + +bool BTSendDialogWidget::constructDialog(const QVariantMap&/*parameters*/) + { + // LOG(ELevel1,_L("BTSendDialogWidget::constructDialog ")); + mLoader = new HbDocumentLoader(); + bool ok = false; + + mLoader->load(DOCML_BT_SEND_DIALOG, &ok); + if(ok) + { + mLabel = qobject_cast(mLoader->findWidget("heading")); + this->setHeadingWidget(mLabel); + mListView = qobject_cast(mLoader->findWidget("listView")); + if(mListView) + { + //Todo - replace this with the actual text from parameters + mContentItemModel = new QStandardItemModel(this); + mListView->setModel(mContentItemModel);//, prototype); + } + + mProgressBar = qobject_cast(mLoader->findWidget("horizontalProgressBar")); + + HbAction* hide = new HbAction("Hide"); + HbAction* cancel = new HbAction("Cancel"); + + this->addAction(hide); + this->addAction(cancel); + + QGraphicsWidget *widget = mLoader->findWidget(QString("container")); + this->setContentWidget(widget); + } + + this->setBackgroundFaded(false); + setDismissPolicy(HbPopup::NoDismiss); + setTimeout(HbPopup::NoTimeout); + + this->actions().first()->disconnect(this); + connect(this, SIGNAL(finished(HbAction*)), this, SLOT(inputClosed(HbAction*))); + + return true; + } + +void BTSendDialogWidget::hideEvent(QHideEvent *event) + { + HbDialog::hideEvent(event); + emit deviceDialogClosed(); + } + +void BTSendDialogWidget::showEvent(QShowEvent *event) + { + HbDialog::showEvent(event); + } + +/*void BTSendDialogWidget::hideClicked() + { + // TODO + this->close(); + emit deviceDialogClosed(); + } + +void BTSendDialogWidget::cancelClicked() + { + // TODO + this->close(); + emit deviceDialogClosed(); + }*/ + +void BTSendDialogWidget::inputClosed(HbAction* action) + { + QVariantMap data; + + HbDialog *dlg=static_cast(sender()); + if(dlg->actions().first() == action) { + } + else if(dlg->actions().at(1) == action) { + } + } + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifclient/group/bld.inf --- a/bluetoothengine/btnotif/btnotifclient/group/bld.inf Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifclient/group/bld.inf Mon May 17 11:06:23 2010 +0300 @@ -3,7 +3,6 @@ * Name : bld.inf * Part of : bluetoothengine / bluetoothengine * Description : Build information file for bluetoothengine subsystem -* Version : %version: 1 % * * Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifclient/group/btnotifclient.mmp --- a/bluetoothengine/btnotif/btnotifclient/group/btnotifclient.mmp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifclient/group/btnotifclient.mmp Mon May 17 11:06:23 2010 +0300 @@ -3,7 +3,6 @@ * Name : btnotifclient.mmp * Part of : bluetoothengine / btnotifclient * Description : Project definition file for project btnotifclient -* Version : %version: 1 % * * Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifclient/src/btnotifclient.cpp --- a/bluetoothengine/btnotif/btnotifclient/src/btnotifclient.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifclient/src/btnotifclient.cpp Mon May 17 11:06:23 2010 +0300 @@ -153,8 +153,8 @@ EXPORT_C void RBTNotifier::PairDevice( const TBTDevAddrPckgBuf& aDevice, TInt32 aDeviceClass, TRequestStatus& aStatus ) { - SendReceive( EBTEngPairDevice, - TIpcArgs( (TInt) EBTEngPairDevice, &aDevice, aDeviceClass ), aStatus ); + SendReceive( EBTNotifPairDevice, + TIpcArgs( (TInt) EBTNotifPairDevice, &aDevice, aDeviceClass ), aStatus ); } // --------------------------------------------------------------------------- @@ -163,5 +163,5 @@ // EXPORT_C void RBTNotifier::CancelPairDevice() { - (void) SendReceive( EBTEngCancelPairDevice ); + (void) SendReceive( EBTNotifCancelPairDevice ); } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/inc/bluetoothnotification.h --- a/bluetoothengine/btnotif/btnotifsrv/inc/bluetoothnotification.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/bluetoothnotification.h Mon May 17 11:06:23 2010 +0300 @@ -1,24 +1,19 @@ /* -* ============================================================================ -* Name : bluetoothnotification.h -* Part of : bluetoothengine / btnotif -* Description : Class for managing an actual user notification or query. -* It hides UI framework-specifics in a private class. +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". * -* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* Initial Contributors: +* Nokia Corporation - initial contribution. * -* Initial Contributors: -* Nokia Corporation - initial contribution. +* Contributors: * -* Contributors: -* Nokia Corporation -* ============================================================================ -* Template version: 4.2 +* Description: Class for managing an actual user notification or query. +* It hides UI framework-specifics in a private class. +* */ #ifndef BLUETOOTHNOTIFICATION_H @@ -75,13 +70,6 @@ { iObserver = NULL; } /** - * Reset the notification. - * - * @since Symbian^4 - */ - void Reset(); - - /** * Getter for the notification type. * * @since Symbian^4 @@ -151,7 +139,7 @@ * @param ?arg1 ?description * @return Error code */ - TInt Show(); + void ShowL(); /** * Stop showing the notification. @@ -200,8 +188,8 @@ * From MHbDeviceDialogObserver. * This callback is called when a device dialog is closed. Any data sent by * the dialog is indicated by the dataReceived() callback. If no observer is - * set in CHbDeviceDialog::Show the latest data can be retrieved with - * CHbDeviceDialog::receivedData(). + * set in CHbDeviceDialogSymbian::Show the latest data can be retrieved with + * CHbDeviceDialogSymbian::receivedData(). * * @since Symbian^4 * @param aCompletionCode gives the result of the dialog completion. Code can be diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/inc/btnotifbasepairinghandler.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifbasepairinghandler.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,176 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTNOTIFBASEPAIRINGHANDLER_H +#define BTNOTIFBASEPAIRINGHANDLER_H + +#include +#include +#include +#include +#include + +class CBTNotifPairingManager; + +/** + * Class CBTNotifBasePairingHandler + * + * The base class for pairing handling. + * When the pairing has completed (successfully or unsuccessfully), the user + * is informed of the result + * + * @since Symbian^4 + */ +NONSHARABLE_CLASS( CBTNotifBasePairingHandler ) : + public CBase, public MBtSimpleActiveObserver + { +public: + + /** + * Destructor + */ + virtual ~CBTNotifBasePairingHandler(); + + /** + * Handle a pairing result from the pairing server. + * + * @param aAddr the address of the remote device which the result is for. + * @param aResult The status code of the pairing or authentication result. + */ + void HandlePairServerResult( const TBTDevAddr& aAddr, TInt aResult ); + + /** + * Handles event of new paired device event in registry. + * @param aDev the remote device which the pair is with. + */ + void HandleRegistryNewPairedEvent( const TBTNamelessDevice& aDev ); + + /** + * Start observing the result of the pairing originated by + * the remote device. + * Must be specialized by subclass. + * @param the address of the remote device to be paired + * @return KErrNone if this request is accepted; otherwise an error code + */ + virtual TInt ObserveIncomingPair( const TBTDevAddr& aAddr ) = 0; + + /** + * Start an outgoing pairing with the remote device. + * Must be specialized by subclass. + * @param the address of the remote device to be paired + * @return KErrNone if this request is accepted; otherwise an error code + */ + virtual void HandleOutgoingPairL( const TBTDevAddr& aAddr, TUint aCod ) = 0; + + /** + * Cancel the outstanding pairing operation. + */ + virtual void CancelOutgoingPair(); + + /** + * Cancels pairing handling with the specified device + * @param aAddr the address of the device the pairing is with + */ + virtual void StopPairHandling( const TBTDevAddr& aAddr ) = 0; + + /** + * Gets the pin code to be used for pairing a device. + * @param aPin contains the pin code if it is not empty + * @param aAddr the device to which pairing is performed. + * @param the required minimum length of a pin code. + */ + virtual void GetPinCode( TBTPinCode& aPin, const TBTDevAddr& aAddr, TInt aMinPinLength ); + +protected: + + /** + * Handle a pairing result with the remote device which this is for. + * Must be specialized by subclass. + * + * @param aResult The status code of the pairing or authentication result. + */ + virtual void DoHandlePairServerResult( TInt aResult ) = 0; + + /** + * Handles a registry new paired event with the remote + * device with which this handler is dealing. + * Must be specialized by subclass. + * @aType the type of authentication with the device. + */ + virtual void DoHandleRegistryNewPairedEvent( const TBTNamelessDevice& aDev ) = 0; + +protected: + + /** + * C++ default constructor + */ + CBTNotifBasePairingHandler(CBTNotifPairingManager& aParent, const TBTDevAddr& aAddr); + + /** + * Symbian 2nd-phase constructor + */ + void BaseConstructL(); + + /** + * Invalidate the pair result flag of this + */ + void UnSetPairResult(); + + /** + * Sets the pair result and validate pair result flag + */ + void SetPairResult( TInt aResult ); + + /** + * Tells if the pair result has been set. + * @ETrue if the result has been set. + */ + TBool IsPairResultSet(); + +protected: + + /** + * Address of the remote device we are trying to pair. + */ + TBTDevAddr iAddr; + + /** + * Contains the final result of pairing with the remote device + */ + TInt iPairResult; + + /** + * Pair result flag, ETrue if iPairResult is been set. + */ + TBool iPairResultSet; + + /** + * Reference to the owner of this object. + */ + CBTNotifPairingManager& iParent; + + /** + * Active object helper for asynchronous operations. + * Own. + */ + CBtSimpleActive* iActive; + }; + +#endif /*BTNOTIFBASEPAIRINGHANDLER_H*/ + + + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/inc/btnotifconnection.h --- a/bluetoothengine/btnotif/btnotifsrv/inc/btnotifconnection.h Wed May 05 09:56:48 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,490 +0,0 @@ -/* -* ============================================================================ -* Name : btnotifconnection.h -* Part of : bluetoothengine / btnotif -* Description : Class for observing events of a single connection, and for -* managing any user notifications related to the connection. -* -* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* Nokia Corporation -* ============================================================================ -* Template version: 4.2 -*/ - -#ifndef BTNOTIFCONNECTION_H -#define BTNOTIFCONNECTION_H - -#include -#include -#include -#include - -#include "bluetoothnotification.h" - -#include "bluetoothtrace.h" - -class CBTNotifConnectionTracker; -class CBTNotifPairingHelper; - -/** - * Utility function for getting the name of a device to display. - * - * @since Symbian^4 - * @param aName On return, will hold the device name to display. - * @param aDevice Data dtructure holding the device record. - */ -void GetDeviceNameL( TBTDeviceName& aName, const CBTDevice& aDevice ); - - -/** - * CBTNotifConnection handles the connection information and operations - * related to remote devices. - * - * @since Symbian^4 - */ -NONSHARABLE_CLASS( CBTNotifConnection ) : public CBase, - public MBTNotificationResult, - public MBtSimpleActiveObserver, - public MBTEngDevManObserver - { - -public: - - /** Enumeration for the current active operation. */ - enum TOperation - { - EIdle, - EAuthorizing, - EPairing, - EBonding, - EAdditionalNotes, // Marks the queries and notes which follow - // notifier requests, but are done after completing - // the actual notifier message - EBlocking, - EInternalOperations, // Marks internal operations such as registry update. - EReadingRegistry, - EUpdatingRegistry - }; - - /** Array of BT profiles. */ - typedef RArray RBTProfileArray; - - /** - * Two-phased constructor. - * @param aAddr Address of the remote device for this connection. - * @param aTracker Pointer to our parent - */ - static CBTNotifConnection* NewLC( const TBTDevAddr& aAddr, - CBTNotifConnectionTracker* aTracker ); - - /** - * Destructor. - */ - virtual ~CBTNotifConnection(); - - /** - * Get the address of the remote device for this connection. - * - * @since Symbian^4 - * @return The BD_ADDR. - */ - inline const TBTDevAddr& Address() const - { return iAddr; } - - /** - * Get the device record of the remote device for this connection. - * - * @since Symbian^4 - * @return The CBTDevice device record. - */ - inline CBTDevice* BTDevice() const - { return iDevice; } - - /** - * Get the current operation for this connection. - * - * @since Symbian^4 - * @param aProfile The profile identifying the service. - */ - inline CBTNotifConnection::TOperation CurrentOperation() const - { return iCurrentOp; } - - /** - * Checks if we have any outstanding request, and handle the next - * in line. Also checks the link state, and informs the tracker - * if we have finished processing and the link is down. - * - * @since Symbian^4 - */ - void CheckNextOperationL(); - - /** - * Completes the first outstanding client request and removes - * it from the queue. - * - * @since Symbian^4 - * @param aReason The reason code to complete the message with. - * @param aReply Data to write back to the client. - */ - void CompleteClientRequest( TInt aReason, const TDesC8& aReply ); - - /** - * Distinguish the type request of this connection and queue it - * or handle it. - * - * @since Symbian^4 - * @param aParams The parameters for this request from the client. - * @param aMessage The message from the client. - */ - void HandleNotifierRequestL( const TDesC8& aParams, const RMessage2& aMessage ); - - /** - * Update an outstanding request for this connection. - * - * @since Symbian^4 - * @param aParams The parameters of the original request from the client. - * @param aMessage The update message from the client. - */ - void HandleNotifierUpdateL( const TDesC8& aParams, const RMessage2& aMessage ); - - /** - * Cancel an outstanding request for this connection. - * - * @since Symbian^4 - * @param aMessage The message from the client. (Temp! find better way!) - */ - void CancelNotifierRequestL( const RMessage2& aMessage ); - - /** - * Start a bonding operation with the remote device. - * - * @since Symbian^4 - * @param aMessage The message from the client. - */ - void StartBondingL( const RMessage2& aMessage ); - - /** - * Cancel an ongoing bonding operation with the remote device. - * - * @since Symbian^4 - */ - void CancelBondingL(); - - /** - * The pairing handler has completed a pairing operation. If this was part - * of a bonding procedure then this will complete the client request. - * - * @since Symbian^4 - */ - void PairingCompleted(); - - /** - * Process a new pairing result, and determine if we need to show - * anything to the user. - * - * @since Symbian^4 - * @param aError Result of the pairing operation. - */ - void PairingResult( TInt aError ); - - /** - * A service-level connection has been made with the device - * observed by this instance. The appropriate notification - * will be shown to the user. - * - * @since Symbian^4 - * @param aProfile The profile identifying the service. - */ - void ServiceConnectedL( TBTProfile aProfile ); - - /** - * A service-level connection has disconnected from the device - * observed by this instance. The appropriate notification - * will be shown to the user. - * - * @since Symbian^4 - * @param aProfile The profile identifying the service. - */ - void ServiceDisconnectedL( TBTProfile aProfile ); - - /** - * Ask the user if he/she wants to block future connection requests. - * - * @since Symbian^4 - */ - void LaunchBlockingQueryL(); - - /** - * Modify the record for the remote device in BTRegistry, with the - * changes already made in the local record. - * - * @since Symbian^4 - */ - void UpdateRegistryEntryL(); - - /** - * Modify the record for the remote device in BTRegistry, if - * aTrusted == true, then update trusted status after reading device - * info from registry - * - * @since Symbian^4 - */ - void UpdateRegistryEntryL(TBool aTrusted); - -// from base class MBTNotificationResult - - /** - * From MBTNotificationResult. - * Handle an intermediate result from a user query. - * This ffunction is called if the user query passes information - * back before it has finished i.e. is dismissed. The final acceptance/ - * denial of a query is passed back in MBRNotificationClosed. - * - * @since Symbian^4 - * @param aData the returned data. The actual format - * is dependent on the actual notifier. - */ - virtual void MBRDataReceived( CHbSymbianVariantMap & aData ); - - /** - * From MBTNotificationResult. - * The notification is finished. The resulting data (e.g. user input or - * acceptance/denial of the query) is passed back here. - * - * @since Symbian^4 - * @param aErr KErrNone or one of the system-wide error codes. - * @param aData the returned data. The actual format - * is dependent on the actual notifier. - */ - virtual void MBRNotificationClosed( TInt aError, const TDesC8& aData ); - -// from base class MBtSimpleActiveObserver - - /** - * From MBtSimpleActiveObserver. - * Callback to notify that an outstanding request has completed. - * - * @since Symbian^4 - * @param aActive The active object helper that completed this request. - * @param aStatus The status of the completed request. - */ - virtual void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ); - - /** - * From MBtSimpleActiveObserver. - * Callback for handling cancelation of an outstanding request. - * - * @since Symbian^4 - * @param aId The ID that identifies the outstanding request. - */ - virtual void CancelRequest( TInt aRequestId ); - - /** - * Callback to notify that an error has occurred in RunL. - * - * @param aActive Pointer to the active object that completed. - * @param sError The error occured in RunL - */ - virtual void HandleError( CBtSimpleActive* aActive, - TInt aError ); - -// from base class MBTEngDevmanObserver - - /** - * From MBTEngDevManObserver. - * Indicates to the caller that adding, deleting or modifying a device - * has completed. - * When this function is called, new commands can be issued to the - * CBTEngDevMan API immediately. - * - * @since S60 v3.2 - * @param aErr Status information, if there is an error. - */ - virtual void HandleDevManComplete( TInt aErr ); - - /** - * From MBTEngDevManObserver. - * Indicates to the caller that getting a device from registry - * has completed. - * - * @param aErr Status information, if there is an error. - * @param aDeviceArray Array of devices that match the given criteria - * (the array provided by the caller). - */ - virtual void HandleGetDevicesComplete( - TInt err, CBTDeviceArray* deviceArray ); - -private: - - /** - * C++ default constructor. - */ - CBTNotifConnection( const TBTDevAddr& aAddr, - CBTNotifConnectionTracker* aTracker ); - - /** - * Symbian 2nd-phase constructor. - */ - void ConstructL(); - - /** - * Get a notification and configure it according to the current operation. - * - * @since Symbian^4 - * @param aType The notification type. - * @param aResourceId Identifier for the resource to display. - */ - void PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType, - TBTDialogResourceId aResourceId ); - - /** - * Handle the result from a notification that is finished. - * - * @since Symbian^4 - * @param aErr KErrNone or one of the system-wide error codes. - * @param aData The returned data. The actual format - * is dependent on the actual notifier. - */ - void NotificationClosedL( TInt aError, const TDesC8& aData ); - - /** - * Handle a request for authorization of this connection. - * - * @since Symbian^4 - * @param aParams The parameters for this request from the client. - */ - void HandleAuthorizationReqL( const TDesC8& aParams ); - - /** - * Process the user input and complete the outstanding authorization request. - * - * @since Symbian^4 - * @param aError The result off the notification. - * @param aData The data returned from the notification dialog. - */ - void CompleteAuthorizationReqL( TInt aError, const TDesC8& aData ); - - /** - * Process the user input for blocking a device. - * - * @since Symbian^4 - * @param aError The result off the notification. - * @param aData The data returned from the notification dialog. - */ - void CompleteBlockingReqL( TInt aError, const TDesC8& aData ); - - /** - * Fetch device from registry - * - * @since Symbian^4 - * @param addr BT address of device to fetch from registry - */ - void GetDeviceFromRegistry( const TBTDevAddr &addr ); - -private: // data - - /** - * The current operation we are carrying out. - */ - TOperation iCurrentOp; - - /** - * Address of the remote device, identifying this connection. - */ - TBTDevAddr iAddr; - - /** - * Package to receive updates of the physical link state. - */ - TBTBasebandEvent iBasebandEvent; - - /** - * Queue of handles (identifier) of client messages we have been requested to work on. - */ - RArray iMsgHandleQ; - - /** - * Array of accepted profile connections (as known here). - */ - RBTProfileArray iAcceptedConnections; - - /** - * Array of rejected profile connections (as known here). - */ - RBTProfileArray iDeniedConnections; - - /** - * Handle to observe and control the baseband connection. - */ - RBTPhysicalLinkAdapter iPhyLink; - - /** - * Subsession with BT registry. - */ - RBTRegistry iRegistry; - - /** - * Details of the remote device. - * Own. - */ - CBTDevice* iDevice; - - /** - * Details of the remote device as retrieved from BT registry. - * Own. - */ - CBTRegistryResponse* iRegistryResponse; - - /** - * helper for modifying registry. - * Own. - */ - CBTEngDevMan* iDevMan; - - /** - * Active object helper for observing physical link changes. - * Own. - */ - CBtSimpleActive* iPhyActive; - - /** - * Active object helper for observing BT registry changes. - * Own. - */ - CBtSimpleActive* iRegActive; - - /** - * Helper class for processing pairing-related operations. - * Own. - */ - CBTNotifPairingHelper* iPairingHelper; - - /** - * Pointer to an outstanding user interaction. - * Not own. - */ - CBluetoothNotification* iNotification; - - /** - * Pointer to our parent. - * Not own. - */ - CBTNotifConnectionTracker* iTracker; - - CBTDeviceArray* iRegDevArray; // used for retrieving devices from registry - - BTUNITTESTHOOK - - }; - -#endif // BTNOTIFCONNECTION_H diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/inc/btnotifconnectiontracker.h --- a/bluetoothengine/btnotif/btnotifsrv/inc/btnotifconnectiontracker.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifconnectiontracker.h Mon May 17 11:06:23 2010 +0300 @@ -1,23 +1,18 @@ /* -* ============================================================================ -* Name : btnotifconnectiontracker.h -* Part of : bluetoothengine / btnotif -* Description : Bluetooth connection tracker and manager. +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". * -* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* Initial Contributors: +* Nokia Corporation - initial contribution. * -* Initial Contributors: -* Nokia Corporation - initial contribution. +* Contributors: * -* Contributors: -* Nokia Corporation -* ============================================================================ -* Template version: 4.2 +* Description: Bluetooth connection tracker and manager. +* */ #ifndef BTNOTIFCONNECTIONTRACKER_H @@ -27,13 +22,11 @@ #include #include #include -#include -#include #include "btnotifserver.h" -class CBTNotifConnection; class CBTNotificationManager; class CbtnotifConnectionTrackerTest; +class CBTNotifPairingManager; @@ -42,10 +35,7 @@ * * @since Symbian^4 */ -NONSHARABLE_CLASS( CBTNotifConnectionTracker ) : public CBase, - public MBluetoothPhysicalLinksNotifier, - public MBTEngConnObserver, - public MBtSimpleActiveObserver +NONSHARABLE_CLASS( CBTNotifConnectionTracker ) : public CBase { public: @@ -99,43 +89,26 @@ */ inline RSocketServ& SocketServerSession() { return iSockServ; } - + /** - * Get the handle to the Bluetooth pairing server. - * This handle can be used for creating subsessions. - * - * @since Symbian^4 - * @return Session with the socket server or NULL. - */ - inline RBluetoothPairingServer* PairingServerSession() - { return iPairingServ; } - - /** - * Processes a message from a notifier client related to connections. + * Processes a message for notifiers related to pairings. + * ( These are usually issued by BT stack. However, any application + * is not restricted to do so (e.g., for testing purpose). * * @since Symbian^4 * @param aMessage The message containing the details of the client request. */ - void DispatchNotifierMessageL( const RMessage2& aMessage ); - + void HandlePairingNotifierRequestL( const RMessage2& aMessage ); + /** * Handle a request related to pairing. * * @since Symbian^4 - * @param aUid The UID of the notification request. + * @param aMessage The message containing the details of the client request. */ void HandleBondingRequestL( const RMessage2& aMessage ); /** - * Handle a change in the number of physical connections. - * This also handles the case where a connection monitor has finished - * its processing, and is now ready for removal. - * - * @since Symbian^4 - */ - void HandleLinkCountChangeL(); - - /** * Check repeated connection attempts, and record rejected/accepted queries. * * @since Symbian^4 @@ -146,104 +119,6 @@ */ TBool UpdateBlockingHistoryL( const CBTDevice* aDevice, TBool aAccepted ); -// from base class MBluetoothPhysicalLinksNotifier - /** Notification of a requested connection coming up. - * If no error is reported, then that connection is ready for use. - * - * @since Symbian^4 - * @param aErr the returned error - */ - virtual void HandleCreateConnectionCompleteL( TInt aErr ); - - /** Notification of a requested disconnection having taken place. - * If no error is reported, then that connection has been closed. - * - * @since Symbian^4 - * @param aErr the returned error - */ - virtual void HandleDisconnectCompleteL( TInt aErr ); - - /** Notification that all existing connections have been torn down. - * If no error is reported, then there are no Bluetooth connections existing. - * - * @since Symbian^4 - * @param aErr the returned error - */ - virtual void HandleDisconnectAllCompleteL( TInt aErr ); - -// from base class MBTEngConnObserver - - /** - * From MBTEngConnObserver. - * Indicates to the caller that a service-level connection has completed. - * This function is called for both incoming and outgoing connections. - * This function is also called when an outgoing connection request fails, - * e.g. with error code KErrCouldNotConnect. - * When this function is called, new commands can be issued to the - * CBTEngConnMan API immediately. - * - * @since S60 v3.2 - * @param aAddr The address of the remote device. - * @param aErr Status information of the connection. KErrNone if the - * connection succeeded, otherwise the error code with - * which the outgoing connection failed. KErrAlreadyExists - * is returned if there already is an existing connection - * for the selected profile(s), or otherwise e.g. - * KErrCouldNotConnect or KErrDisconnected for indicating - * connection problems. - * @param aConflicts If there already is a connection for the selected - * profile(s) of an outgoing connection request (the - * selection is performed by BTEng), then this array - * contains the bluetooth device addresses of the - * remote devices for those connections. - */ - virtual void ConnectComplete( TBTDevAddr& aAddr, TInt aErr, - RBTDevAddrArray* aConflicts = NULL ); - - /** - * From MBTEngConnObserver. - * Indicates to the caller that a service-level connection has disconnected. - * When this function is called, new commands can be issued to the - * CBTEngConnMan API immediately. - * - * @since S60 v3.2 - * @param aAddr The address of the remote device. - * @param aErr The error code with which the disconnection occured. - * KErrNone for a normal disconnection, - * or e.g. KErrDisconnected if the connection was lost. - */ - virtual void DisconnectComplete( TBTDevAddr& aAddr, TInt aErr ); - -// from base class MBtSimpleActiveObserver - - /** - * From MBtSimpleActiveObserver. - * Callback to notify that an outstanding request has completed. - * - * @since Symbian^4 - * @param aActive The active object helper that completed this request. - * @param aStatus The status of the completed request. - */ - virtual void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ); - - /** - * From MBtSimpleActiveObserver. - * Callback for handling cancelation of an outstanding request. - * - * @since Symbian^4 - * @param aId The ID that identifies the outstanding request. - */ - virtual void CancelRequest( TInt aRequestId ); - - /** - * Callback to notify that an error has occurred in RunL. - * - * @param aActive Pointer to the active object that completed. - * @param sError The error occured in RunL - */ - virtual void HandleError( CBtSimpleActive* aActive, - TInt aError ); - private: CBTNotifConnectionTracker( CBTNotifServer* aServer ); @@ -251,43 +126,6 @@ void ConstructL(); /** - * Parse a client message and find the correct connection handler - * for dispatching a request. - * The parsed client message may be a request that is being served, - * in case a cancel request has come in. The opcode identifies the - * client message that is currently being dispatched. - * - * @since Symbian^4 - * @param aOpcode The opcode of the original request. - * @param aMessage The client message to parse. - * @param aBuffer On return this contains the parameters read from the message. - * @return The connection that is identified by the address in the - * message, or NULL if none found. - */ - CBTNotifConnection* FindConnectionFromMessageL( TInt aOpcode, - const RMessage2& aMessage, TDes8& aBuffer ); - - /** - * Parse the Bluetooth address from a request for some notification. - * - * @since Symbian^4 - * @param aUid The UID of the notification request. - * @param aParamsBuf Descriptor containing the parameter read from the - * client message. - * @return Bluetooth address parsed from the descriptor. - */ - TBTDevAddr ParseAddressL( TInt aUid, const TDesC8& aParamsBuf ) const; - - /** - * Find the handler of a specific connection. - * - * @since Symbian^4 - * @param aAddr The remote device address identifying the connection. - * @return Connnection handler or NULL; - */ - CBTNotifConnection* FindConnectionHandler( const TBTDevAddr& aAddr ) const; - - /** * Record and check the time between connection attempts. * * @since Symbian^4 @@ -300,30 +138,6 @@ private: // data /** - * PubSub key for tracking the number of connections. - */ - RProperty iLinkCount; - -// ToDo: remove this when registry notifications API is available!! - /** - * PubSub key for tracking registry changes. - */ - RProperty iRegistryChange; - - /** - * Helper active object for observing the link count. - * Own. - */ - CBtSimpleActive* iRegistryActive; -// End ToDo - - /** - * Array of pointers to observers of individual connections. - */ - RPointerArray iConnArray; -// RHashMap iConnArray; - - /** * Time of the last denied connection attempt. */ TInt64 iLastReject; @@ -344,50 +158,16 @@ RSocketServ iSockServ; /** - * Address placeholder for receiving secure simple pairing results. - */ - TBTDevAddr iSspResultAddr; - - /** - * Session with pairing server for receiving secure simple pairing results. - */ - RBluetoothPairingResult iSspResultSession; - - /** - * Single session with the pairing server, to be used for subsessions. - * Own. - */ - RBluetoothPairingServer* iPairingServ; - - /** - * Object for managing the piconet. - * Own. - */ - CBTEngConnMan* iConnMan; - - /** - * Object for managing the piconet. - * Own. - */ - CBluetoothPhysicalLinks* iPhyLinks; - - /** - * Helper active object for observing the link count. - * Own. - */ - CBtSimpleActive* iLinkCountActive; - - /** - * Helper active object for receiving secure simple pairing results. - * Own. - */ - CBtSimpleActive* iSspResultActive; - - /** * Reference to our parent the server class. * Not own. */ CBTNotifServer* iServer; + + /** + * Object for managing the application pairing. + * Own. + */ + CBTNotifPairingManager* iPairingManager; BTUNITTESTHOOK diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/inc/btnotifdeviceselector.h --- a/bluetoothengine/btnotif/btnotifsrv/inc/btnotifdeviceselector.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifdeviceselector.h Mon May 17 11:06:23 2010 +0300 @@ -29,6 +29,7 @@ #include #include #include "bluetoothnotification.h" +#include class CBTNotifServer; class CAdvanceDevDiscoverer; @@ -48,7 +49,8 @@ NONSHARABLE_CLASS( CBTNotifDeviceSelector ) : public CBase, public MBTNotificationResult, - public MDevDiscoveryObserver + public MDevDiscoveryObserver, + public MBtDevRepositoryObserver { public: @@ -127,6 +129,21 @@ */ virtual void HandleDiscoveryCompleted( TInt aErr ); + + // From MBtDeviceRepositoryObserver + + void RepositoryInitialized(); + + void DeletedFromRegistry( const TBTDevAddr& addr ); + + void AddedToRegistry( const CBtDevExtension& dev ); + + void ChangedInRegistry( const CBtDevExtension& dev, TUint similarity ); + + void ServiceConnectionChanged( + const CBtDevExtension& dev, TBool connected ); + + private: CBTNotifDeviceSelector( CBTNotifServer& aServer ); @@ -136,6 +153,8 @@ void PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType, TBTDialogResourceId aResourceId ); + + void LoadUsedDevicesL(); private: // data @@ -166,6 +185,10 @@ */ RMessage2 iMessage; + TBool iRepositoryInitialized; + + TBool iLoadDevices; + }; #endif // BTNOTIFDEVICESELECTOR_H diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/inc/btnotificationmanager.h --- a/bluetoothengine/btnotif/btnotifsrv/inc/btnotificationmanager.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotificationmanager.h Mon May 17 11:06:23 2010 +0300 @@ -1,23 +1,19 @@ /* -* ============================================================================ -* Name : btnotificationmanager.h -* Part of : bluetoothengine / btnotif -* Description : Class for managing user notification and query objects, and for serializing access to the notification server. +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". * -* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* Initial Contributors: +* Nokia Corporation - initial contribution. * -* Initial Contributors: -* Nokia Corporation - initial contribution. +* Contributors: * -* Contributors: -* Nokia Corporation -* ============================================================================ -* Template version: 4.2 +* Description: Class for managing user notification and query objects, +* and for serializing access to the notification server. +* */ #ifndef BTNOTIFICATIONMANAGER_H @@ -74,9 +70,8 @@ * EPriorityStandard means that it is appended to the end, * and should be used for most notes. EPriorityLow is not * used yet. - * @return Error code. */ - TInt QueueNotification( CBluetoothNotification* aNotification, + void QueueNotificationL( CBluetoothNotification* aNotification, TNotificationPriority aPriority = EPriorityStandard ); private: @@ -107,32 +102,12 @@ */ void CheckIdle(); - /** - * Callback function for asynchronous processing of - * queued notification requests. - * - * @since Symbian^4 - * @param aPtr Pointer to notification manager instance. - */ - static TInt AsyncCallback( TAny* aPtr ); - private: // data /** * The queue of notifications to be shown to the user. */ RPointerArray iNotificationQ; - - /** - * The queue of spare notifications. - */ - RPointerArray iUnusedQ; - - /** - * Callback for asynchronous processing. - * Own. - */ - CAsyncCallBack* iAsyncCb; /** * Pointer to our parent. diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/inc/btnotifincomingpairinghandler.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifincomingpairinghandler.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,191 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef BTNOTIFINCOMINGPAIRINGHANDLER_H +#define BTNOTIFINCOMINGPAIRINGHANDLER_H + +#include +#include "btnotifBasePairingHandler.h" + +/** + * Class CBTNotifIncomingPairingHandler + * + * Handles an incoming pairing. + * + * @since Symbian^4 + */ +NONSHARABLE_CLASS( CBTNotifIncomingPairingHandler ) : public CBTNotifBasePairingHandler + { +public: + + /** + * Two-phase constructor + * @param aParent the owner of this observer + * @param aAddr the remote device this observer is targeted to + */ + static CBTNotifBasePairingHandler* NewL( CBTNotifPairingManager& aParent, + const TBTDevAddr& aAddr); + + /** + * Destructor + */ + ~CBTNotifIncomingPairingHandler(); + + +private: // From CBTNotifBasePairingHandler + + /** + * Start observing the result of pairing which was originated from + * the remote device. + * @param the address of the remote device to be paired + * @return KErrNone if this request is accepted; otherwise an error code + */ + TInt ObserveIncomingPair( const TBTDevAddr& aAddr ); + + /** + * Start an outgoing pairing with the remote device. + * @param the address of the remote device to be paired + * @return KErrNone if this request is accepted; otherwise an error code + */ + void HandleOutgoingPairL( const TBTDevAddr& aAddr, TUint aCod ); + + /** + * Cancels pairing handling with the specified device + * @param aAddr the address of the device the pairing is with + */ + void StopPairHandling( const TBTDevAddr& aAddr ); + + /** + * Handle a pairing result with the remote device which this is for. + * Must be specialized by subclass. + * + * @param aResult The status code of the pairing or authentication result. + */ + void DoHandlePairServerResult( TInt aResult ); + + /** + * Handles event of registry new paired event with the remote + * device this is for. + * @aType the type of authentication with the device. + */ + void DoHandleRegistryNewPairedEvent( const TBTNamelessDevice& aDev ); + +private: // from base class MBtSimpleActiveObserver + + /** + * Callback to notify that an outstanding request has completed. + * + * @since Symbian^4 + * @param aActive Pointer to the active object that completed. + * @param aId The ID that identifies the outstanding request. + * @param aStatus The status of the completed request. + */ + virtual void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ); + + /** + * Callback from Docancel() for handling cancelation of an outstanding request. + * + * @since Symbian^4 + * @param aId The ID that identifies the outstanding request. + */ + virtual void CancelRequest( TInt aRequestId ); + + /** + * Callback to notify that an error has occurred in RunL. + * + * @since Symbian^4 + * @param aActive Pointer to the active object that completed. + * @param aId The ID that identifies the outstanding request. + * @param aStatus The status of the completed request. + */ + virtual void HandleError( CBtSimpleActive* aActive, TInt aError ); + +private: + + /** + * C++ default constructor + */ + CBTNotifIncomingPairingHandler(CBTNotifPairingManager& aParent, const TBTDevAddr& aAddr); + + /** + * 2nd phase constructor. + */ + void ConstructL(); + + /** + * Start monitoring physical link events if it hasn't yet. + * + * @since Symbian^4 + * + */ + void MonitorPhysicalLink(); + + /** + * Opens physical link adaptor with the device. + * + * @since Symbian^4 + * @return KErrNone if the physical link exists. + * + */ + TInt OpenPhysicalLinkAdaptor(); + + /** + * Cancel all outstanding requests. + * + * @since Symbian^4 + */ + void CancelPlaNotification(); + + /** + * Handle a physical link event. + * + * @since Symbian^4 + * @param aResult The status code of the event. + */ + void HandlePhysicalLinkResultL( TInt aResult ); + +private: + + /** + * Package buffer for retrieving physical link events. + */ + TBTBasebandEvent iBbEvent; + + /** + * Subsession with the socket server for + * getting physical link event notifications. + */ + RBTPhysicalLinkAdapter iPla; + + /** + * iPairingOkTimer is activated if the link goes down. + * If it expires it means the pairing process has failed, + * then the error popup will be shown. + * If the pairing process ends correctly, DoHandleRegistryNewPairedEvent + * will be called and it will cancel the timer. + * iActivePairingOk is the active object associated to the timer. + */ + RTimer iPairingOkTimer; + CBtSimpleActive* iActivePairingOk; + TBool iUserAwarePairing; + }; + +#endif /*BTNOTIFINCOMINGPAIRINGHANDLER_H*/ + + + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/inc/btnotifoutgoingpairinghandler.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifoutgoingpairinghandler.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,209 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Pairing handler for local device initiated pairing +* +*/ + +#ifndef BTNOTIFOUTGOINGPAIRINGHANDLER_H_ +#define BTNOTIFOUTGOINGPAIRINGHANDLER_H_ + +#include +#include +#include +#include "btnotifclientserver.h" +#include "btnotifBasePairingHandler.h" + + +enum TBTOutgoingPairMode + { + /** + * not outgoing pairing operation + */ + EBTOutgoingPairNone = 0, + + /** + * outgoing automatic 0000 pin pairing with headset in progress + */ + EBTOutgoingHeadsetAutoPairing, + + /** + * outgoing manual pairing with headset in progress + */ + EBTOutgoingHeadsetManualPairing, + + /** + * outgoing pairing with non-headset device in progress + */ + EBTOutgoingNoneHeadsetPairing, + }; + +/** + * Perform a outgoing pair with a BT device. + * + * @since Symbian^4 + */ +NONSHARABLE_CLASS( CBTNotifOutgoingPairingHandler ) : public CBTNotifBasePairingHandler + { + +public: + + /** + * Two-phase constructor + * @param aParent the owner of this object + * @param aAddr the remote device this observer is targeted to + */ + static CBTNotifBasePairingHandler* NewL( CBTNotifPairingManager& aParent, + const TBTDevAddr& aAddr ); + + /** + * Destructor + */ + ~CBTNotifOutgoingPairingHandler(); + +private: // From CBTEngPairBase + + /** + * Start observing the result of pairing which was originated from + * the remote device. + * @param the address of the remote device to be paired + * @return KErrNone if this request is accepted; otherwise an error code + */ + TInt ObserveIncomingPair( const TBTDevAddr& aAddr ); + + /** + * Start an outgoing pairing with the remote device. + * @param the address of the remote device to be paired + * @return KErrNone if this request is accepted; otherwise an error code + */ + void HandleOutgoingPairL( const TBTDevAddr& aAddr, TUint aCod ); + + /** + * Cancel any outstanding pairing operation. + */ + void CancelOutgoingPair(); + + /** + * Gets the pin code to be used for pairing a device. + * @param aPin contains the pin code if it is not empty + * @param aAddr the device to which pairing is performed. + * @param the required minimum length of a pin code. + */ + void GetPinCode( TBTPinCode& aPin, const TBTDevAddr& aAddr, TInt aMinPinLength ); + + /** + * Cancels pairing handling with the specified device + * @param aAddr the address of the device the pairing is with + */ + void StopPairHandling( const TBTDevAddr& aAddr ); + + /** + * Handle a pairing result with the remote device which this is for. + * Must be specialized by subclass. + * + * @param aResult The status code of the pairing or authentication result. + */ + void DoHandlePairServerResult( TInt aResult ); + + /** + * Handles registry new paired event for the remote + * device this is pairing with. + * @aType the type of authentication with the device. + */ + void DoHandleRegistryNewPairedEvent( const TBTNamelessDevice& aDev ); + +private: // from base class MBtSimpleActiveObserver + + /** + * Callback to notify that an outstanding request has completed. + * + * @since Symbian^4 + * @param aActive Pointer to the active object that completed. + * @param aId The ID that identifies the outstanding request. + * @param aStatus The status of the completed request. + */ + void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ); + + /** + * Callback from Docancel() for handling cancelation of an outstanding request. + * + * @since Symbian^4 + * @param aId The ID that identifies the outstanding request. + */ + virtual void CancelRequest( TInt aRequestId ); + + /** + * Callback to notify that an error has occurred in RunL. + * + * @since Symbian^4 + * @param aActive Pointer to the active object that completed. + * @param aId The ID that identifies the outstanding request. + * @param aStatus The status of the completed request. + */ + void HandleError( CBtSimpleActive* aActive, TInt aError ); + +private: + + /** + * C++ default constructor + */ + CBTNotifOutgoingPairingHandler( CBTNotifPairingManager& aParent, const TBTDevAddr& aAddr ); + + /** + * Symbian 2nd-phase constructor + */ + void ConstructL(); + + /** + * Starts an actual pair operation. + */ + void DoPairingL(); + +private: // data + + /** + * Socket address of the remote device to pair with. + */ + TBTSockAddr iSockAddr; + + /** + * The CoD of the device to be paired + */ + TBTDeviceClass iCod; + + /** + * Dedicated bonding session to the pairing server. + */ + RBluetoothDedicatedBondingInitiator iBondingSession; + + /** + * socket for creating L2CAP link with the remote device. + */ + RSocket iSocket; + + /** + * Timer for recovery from Repeated Attempts + */ + RTimer iTimer; + + /** + * the current pairing mode this class is in + */ + TBTOutgoingPairMode iPairMode; + + }; + + +#endif /* BTNOTIFOUTGOINGPAIRINGHANDLER_H_ */ + + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/inc/btnotifpairinghelper.h --- a/bluetoothengine/btnotif/btnotifsrv/inc/btnotifpairinghelper.h Wed May 05 09:56:48 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,471 +0,0 @@ -/* -* ============================================================================ -* Name : btnotifpairinghelper.h -* Part of : bluetoothengine / btnotif -* Description : Helper class for processing pairing requests and results, as extended functionality for CBTNotifConnection. -* -* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* Nokia Corporation -* ============================================================================ -* Template version: 4.2 -*/ - -#ifndef BTNOTIFPAIRINGHELPER_H -#define BTNOTIFPAIRINGHELPER_H - -#include -#include -#include -#include - -#include "bluetoothnotification.h" -#include "bluetoothtrace.h" - -class CBTNotifConnection; -class CBTNotifConnectionTracker; -class CBTDevice; - - -/** - * Helper class for performing pairing-related operations. - * - * This class is constructed only when there is a pairing-related event, - * and destructed after completion. Pairing-related events are bonding - * (outgoing bonding request from an application), pairing notifiers - * (PIN input i.e. legacy pairing, numeric comparison and passkey display), - * and Just Works pairing completion. - * - * The structure of operations is as follows: each event is initiated through - * StartXxL() operation, and finished with CompleteXxL(), there is also a - * CancelXxL() operation where needed. In addition there are the base class virtual - * functions, a few helper functions and HandleAuthenticationCompleteL, which - * processes a baseband authentication result. The same structure applies to - * suboperations, such as StartTrustedQueryL and CompleteTrustedQueryL. - * - * For bonding, there is StartBondingL, CompleteBondingL() CancelBondingL(); - * for pairing notifiers there is StartPairingNotifierL(), - * CancelPairingNotifierL(), CompletePairingNotifierL() and also - * UpdatePairingNotifierL(). For Just Works processing, there is - * StartJustWorksProcessingL(), CancelJustWorksProcessingL() and - * CompleteJustWorksProcessingL(). - * - * The design of this class is focussed on structure and maintainability first. - * Duplicate (state) information is kept to a minimum. And memory usage comes - * before processing. Pairing is an infrequent operation, and this class is - * only instantiated when there is pairing-related processing, so extreme - * focus on memory or processing efficiency would have relatively little effect. - * - * @since Symbian^4 - */ -NONSHARABLE_CLASS( CBTNotifPairingHelper ) : public CBase, - public MBTNotificationResult, - public MBtSimpleActiveObserver - { - -public: - - /** Enumeration identifying the stage of the pairing operation. */ - enum TPairingOp - { - EIdle, - EAcceptPairing, - ELegacyPairing, - ESspPairing, - EJustWorksPairing, - EAutoPairing, - EPostPairingOperations, // Marks the queries and notes which follow - // the real pairing input from the user. - EDedicatedBonding, - EUnpairing, - EAwaitingPairingResult, - EShowPairingSuccess, - EShowPairingFailure, - EQueryTrust, - EBlocking, - EPairingCancelled - }; - - /** - * Two-phased constructor. - * @param aConnection Pointer to the parent. - * @param aDevice Pointer to information of the remote device. - * aParam aTracker Pointer to the connection tracker. - */ - static CBTNotifPairingHelper* NewL( CBTNotifConnection* aConnection, - CBTNotifConnectionTracker* aTracker ); - - /** - * Destructor. - */ - virtual ~CBTNotifPairingHelper(); - - /** - * Get the address of the remote device for this connection. - * - * @since Symbian^4 - * @param aProfile The profile identifying the service. - */ - inline CBTNotifPairingHelper::TPairingOp CurrentOperation() const - { return iOperation; } - - /** - * The baseband authentication has completed, handle the result. - * - * @since Symbian^4 - * @param aError The result of the authentication procedure. - */ - void HandleAuthenticationCompleteL( TInt aError ); - - /** - * Start a bonding operation with the remote device. - * - * @since Symbian^4 - * @param aMessage The handle of the message from the client. - */ - void StartBondingL( TInt aHandle ); - - /** - * Cancel an ongoing bonding operation with the remote device. - * - * @since Symbian^4 - */ - void CancelBondingL(); - - /** - * Handle a notifier request for pairing with the remote device - * of this connection. - * - * @since Symbian^4 - * @param aUid The UID of the notifier for this pairing request. - * @param aParams The parameters for this request from the client. - */ - void StartPairingNotifierL( TInt aUid, const TDesC8& aParams ); - - /** - * Update an outstanding request for this connection. - * - * @since Symbian^4 - * @param aUid The UID of the notifier for this update. - * @param aParams The updated parameters for this request from the client. - */ - void UpdatePairingNotifierL( TInt aUid, const TDesC8& aParams ); - - /** - * Cancel an outstanding request for this connection. - * - * @since Symbian^4 - * @param aUid The UID of the notifier for this pairing request. - */ - void CancelPairingNotifierL( TInt aUid ); - - /** - * Start the processing of a completed Just Works pairing. - * This needs special attention, as this class is not notified - * other than by observing the registry, and the user is not - * notified otherwise either (which is the point of this association - * model). It needs to be verified that the pairing is related to - * a service access, as dedicated bonding should not be possible - * (for devices that do not have any IO capabilities). - * - * @since Symbian^4 - * @param aMessage The handle of the message from the client. - */ - void StartJustWorksProcessingL(); - - /** - * Cancel the processing of a completed Just Works pairing. - * - * @since Symbian^4 - */ - void CancelJustWorksProcessingL(); - -// from base class MBTNotificationResult - - /** - * From MBTNotificationResult. - * Handle an intermediate result from a user query. - * This function is called if the user query passes information - * back before it has finished i.e. is dismissed. The final acceptance/ - * denial of a query is passed back in MBRNotificationClosed. - * - * @since Symbian^4 - * @param aData the returned data. The actual format - * is dependent on the actual notifier. - */ - virtual void MBRDataReceived( CHbSymbianVariantMap& aData ); - - /** - * From MBTNotificationResult. - * The notification is finished. The resulting data (e.g. user input or - * acceptance/denial of the query) is passed back here. - * - * @since Symbian^4 - * @param aErr KErrNone or one of the system-wide error codes. - * @param aData the returned data. The actual format - * is dependent on the actual notifier. - */ - virtual void MBRNotificationClosed( TInt aError, const TDesC8& aData ); - -// from base class MBtSimpleActiveObserver - - /** - * From MBtSimpleActiveObserver. - * Callback to notify that an outstanding request has completed. - * - * @since Symbian^4 - * @param aActive The active object helper that completed this request. - * @param aStatus The status of the completed request. - */ - virtual void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ); - - /** - * From MBtSimpleActiveObserver. - * Callback for handling cancelation of an outstanding request. - * - * @since Symbian^4 - * @param aId The ID that identifies the outstanding request. - */ - virtual void CancelRequest( TInt aRequestId ); - - /** - * Callback to notify that an error has occurred in RunL. - * - * @param aActive Pointer to the active object that completed. - * @param aError The error occurred in RunL. - */ - virtual void HandleError( CBtSimpleActive* aActive, TInt aError ); - -private: - - /** - * C++ default constructor. - */ - CBTNotifPairingHelper( CBTNotifConnection* aConnection, - CBTNotifConnectionTracker* aTracker ); - - /** - * Symbian 2nd-phase constructor. - */ - void ConstructL(); - - /** - * Process the user input and complete the outstanding pairing request. - * - * @since Symbian^4 - * @param aError The result off the notification. - * @param aResult The user response; ETrue if the user accepted the query, - * otherwise EFalse. - * @param aData The data returned from the notification dialog. - */ - void CompletePairingNotifierL( TInt aError, TBool aResult, const TDesC8& aData ); - - /** - * Completes a bonding operation. - * - * @since Symbian^4 - * @param aError The result of the bonding attempt. - */ - void CompleteBondingL( TInt aError ); - - /** - * Completes a bonding operation. - * - * @since Symbian^4 - * @param aError The result of the bonding attempt. - */ - void CompleteJustWorksProcessingL( TInt aError ); - - /** - * Ask the user to allow incoming pairing. - * - * @since Symbian^4 - */ - void StartAcceptPairingQueryL(); - - /** - * Process the user input and for accepting an incoming pairing and - * continue with the outstanding pairing request. - * - * @since Symbian^4 - * @param aError The result of the notification. - * @param aResult The user response; ETrue if the user accepted the query, - * otherwise EFalse. - */ - void CompleteAcceptPairingQueryL( TInt aError, TBool aResult ); - - /** - * Ask the user to set the device as trusted. - * - * @since Symbian^4 - * @param aData The data returned from the notification dialog. - */ - void StartTrustedQueryL(); - - /** - * Process the user input for setting the device as trusted. - * - * @since Symbian^4 - * @param aError The result of the notification. - * @param aResult The user response; ETrue if the user accepted the query, - * otherwise EFalse. - */ - void CompleteTrustedQueryL( TInt aError, TBool aResult ); - - /** - * Parse the parameters of a request for pairing. - * This function also returns values to use for dialog config, and sets - * the operation state member variable (iOperation). - * - * @since Symbian^4 - * @param aLocallyInitiated On return, will be set to ETrue if the pairing - * was initiated by us. - * @param aNumVal On return, this descriptor will contain a number to use in - * the pairing dialog. The meaning depends on the type of pairing. - * @param aDialogType On return, will contain the dialog type. - * @param aResourceId On return, will contain the resource id. - */ - void ParseNotifierReqParamsL( TBool& aLocallyInitiated, TDes& aNumVal, - TBluetoothDialogParams::TBTDialogType& aDialogType, - TBTDialogResourceId& aResourceId ); - - /** - * Parse the parameters of a request for pairing using pin query. - * - * @since Symbian^4 - * @param aLocallyInitiated On return, will be set to ETrue if the pairing - * was initiated by us. - * @param aNumVal On return, this will contain the minimum passcode length. - */ - void ParsePinCodeReqParamsL( TBool& aLocallyInitiated, TUint& aNumVal ); - - /** - * Parse the parameters of a request for pairing using numeric comparison. - * - * @since Symbian^4 - * @param aLocallyInitiated On return, will be set to ETrue if the pairing - * was initiated by us. - * @param aNumVal On return, this descriptor will contain the passkey to - * show to the user. - */ - void ParseNumericCompReqParamsL( TBool& aLocallyInitiated, TDes& aNumVal ); - - /** - * Parse the parameters of a request for pairing using passkey display. - * - * @since Symbian^4 - * @param aLocallyInitiated On return, will be set to ETrue if the pairing - * was initiated by us. - * @param aNumVal On return, this descriptor will contain the passkey to - * show to the user. - */ - void ParsePasskeyDisplayReqParamsL( TBool& aLocallyInitiated, TDes& aNumVal ); - - /** - * Check if we can guess the PIN and complete the notifier without - * user interaction. - * - * @since Symbian^4 - * @param aLocallyInitiated ETrue if we initiated the pairing, otherwise EFalse. - * @param aNumVal The minimum lenght of the passcode. - */ - void CheckAutoPairingL( TBool aLocallyInitiated, const TDesC& aNumVal ); - - /** - * Get a notification and configure it according to the current operation. - * - * @since Symbian^4 - * @param aType The notification type. - * @param aResourceId Identifier for the resource to display. - */ - void PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType, - TBTDialogResourceId aResourceId ); - - /** - * Handle the result from a notification that is finished. - * - * @since Symbian^4 - * @param aErr KErrNone or one of the system-wide error codes. - * @param aData The returned data. The actual format - * is dependent on the actual notifier. - */ - void NotificationClosedL( TInt aError, const TDesC8& aData ); - -private: // data - - /** - * Identifier for the current operation. - */ - TPairingOp iOperation; - - /** - * UID of the notifier pairing dialog request. - */ - TInt iNotifierUid; - - /** - * Handle to the client message for dedicated bonding. Also serves as flag - * indicating that we are performing dedicated bonding. - */ - TInt iDedicatedBonding; - - /** - * Subsession with pairing server for dedicated bonding. - */ - RBluetoothDedicatedBondingInitiator iBondingSession; - - /** - * Handle for general bonding. - */ - RBTPhysicalLinkAdapter iBondingSocket; - - /** - * Buffer containing the parameters of the client message. - * Own. - */ - HBufC8* iParams; - - /** - * Active object helper for outgoing bonding. - * Own. - */ - CBtSimpleActive* iBondingActive; - - /** - * Pointer to the data record of the remote device. - * Not own. - */ - CBTDevice* iDevice; - - /** - * Pointer to an outstanding user interaction. - * Not own. - */ - CBluetoothNotification* iNotification; - - /** - * Pointer to the class that we are helping. - * Not own. - */ - CBTNotifConnection* iConnection; - - /** - * Pointer to our grandparent. - * Not own. - */ - CBTNotifConnectionTracker* iTracker; - - BTUNITTESTHOOK - - }; - -#endif // BTNOTIFPAIRINGHELPER_H diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/inc/btnotifpairingmanager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifpairingmanager.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,400 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTNOTIFPAIRINGMANAGER_H +#define BTNOTIFPAIRINGMANAGER_H + +#include +#include +#include +#include +#include +#include + +class CBTNotifBasePairingHandler; +class CBTNotifPairNotifier; +class CBTNotifConnectionTracker; +class CBtDevRepository; + +/** + * Class CBTNotifPairingManager + * + * This class manages pairing with BT devices. + * The responsibility of handling incoming and outgoing pairings is + * delegated to CBTNotifIncomingPairingHandler and CBTNotifOutgoingPairingHandler + * respectively. + * + * @since Symbian^4 + */ +NONSHARABLE_CLASS( CBTNotifPairingManager ) : + public CBase, + public MBtSimpleActiveObserver, + public MBtDevRepositoryObserver + { +public: + + /** + * Two-phase constructor + */ + static CBTNotifPairingManager* NewL( + CBTNotifConnectionTracker& aParent, + CBtDevRepository& aDevRepository ); + + /** + * Destructor + */ + ~CBTNotifPairingManager(); + + /** + * Cancels an outstanding pairing request. + */ + void CancelOutgoingPair(); + + /** + * Process commands relevant to pairing + */ + void HandleBondingRequestL( const RMessage2& aMessage ); + + void HandlePairingNotifierRequestL( const RMessage2& aMessage ); + + /** + * Gets the instance of pairing server. + * @return the server instance. NULL if dedicated bonding is unavailable. + */ + RBluetoothPairingServer* PairingServer(); + + /** + * gets the reference of socket server session + */ + RSocketServ& SocketServ(); + + /** + * gets the reference of devrepository. + */ + CBtDevRepository& BTDevRepository(); + + /** + * gets the reference of connection tracker. + */ + CBTNotifConnectionTracker& ConnectionTracker(); + + /** + * Transfer responsiblity to the specified object. + * @param aPairer the object whose the responsibility is transfered. + */ + void RenewPairingHandler( CBTNotifBasePairingHandler* aPairingHandler ); + + /** + * Be notified when handling of an outgoing pair has been completed. + * @param aErr the result of pairing + * + */ + void OutgoingPairCompleted( TInt aErr ); + + /** + * Be informed that a session will be closed. + * + * @since Symbian^4 + * @param aSession the session to be cloased. + */ + void SessionClosed(CSession2* aSession ); + + /** + * Unpair a device via registry + */ + void UnpairDevice( const TBTDevAddr& aAddr ); + + /** + * Add the bit indicating the device is user-aware Just worked paired to + * UI cookie. + */ + TInt AddUiCookieJustWorksPaired( const TBTNamelessDevice& aDev ); + + /** + * Update a nameless device in registry + */ + TInt UpdateRegDevice( const TBTNamelessDevice& aDev ); + + /** + * Gets the pin code to be used for pairing a device. + * @param aPin contains the pin code if it is not empty + * @param aAddr the device to which pairing is performed. + * @param the required minimum length of a pin code. + */ + void GetPinCode( TBTPinCode& aPin, const TBTDevAddr& aAddr, TInt aMinPinLength ); + + /** + * Returns the service (limited to services managed in bteng scope) + * level connection status of the specified device. + * + * @param aAddr the address of the device + * @return one of TBTEngConnectionStatus enums + */ + TBTEngConnectionStatus ConnectStatus( const TBTDevAddr& aAddr ); + +private: + + // from base class MBtSimpleActiveObserver + + /** + * + * Callback to notify that an outstanding request has completed. + * + * @since Symbian^4 + * @param aActive Pointer to the active object that completed. + * @param aId The ID that identifies the outstanding request. + * @param aStatus The status of the completed request. + */ + virtual void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ); + + /** + * Callback from Docancel() for handling cancelation of an outstanding request. + * + * @since Symbian^4 + * @param aId The ID that identifies the outstanding request. + */ + virtual void CancelRequest( TInt aRequestId ); + + /** + * Callback to notify that an error has occurred in RunL. + * + * @since Symbian^4 + * @param aActive Pointer to the active object that completed. + * @param aId The ID that identifies the outstanding request. + * @param aStatus The status of the completed request. + */ + virtual void HandleError( CBtSimpleActive* aActive, TInt aError ); + + // From base class MBtDevRepositoryObserver + + /** + * Callback to notify that the repository has finished initialization. + * Initialization completion means the repository has retieved all + * Bluetooth devices from BT registry, and it is subscribing to + * registry update events. + */ + virtual void RepositoryInitialized(); + + /** + * Callback to notify that a device has been deleted from BT registry. + * + * + * @param aAddr the bd_addr of the deleted device + */ + virtual void DeletedFromRegistry( const TBTDevAddr& aAddr ); + + /** + * Callback to notify that the device has been added to BT registry. + * + * @param aDevice the device that has been added to registry + */ + virtual void AddedToRegistry( const CBtDevExtension& aDevice ); + + /** + * Callback to notify that the property of a device in BT registry has been + * changed. + * + * @param aDevice the device that possesses the latest properties. + * @param aSimilarity the similarity of the properties comparing to the ones + * prior to this change. + * Refer CBTDevice::TBTDeviceNameSelector and + * TBTNamelessDevice::TBTDeviceSet for the meanings of the bits + * in this parameter. + */ + virtual void ChangedInRegistry( + const CBtDevExtension& aDevice, TUint aSimilarity ); + + /** + * Callback to notify that the status of service (limited to + * services maintained in btengsrv scope) connections with + * a device has changed. + * + * @param aDevice the device to which the status change refers + * @param aConnected ETrue if at least one service is currently connected. + * EFalse if no service is currently connected. + */ + virtual void ServiceConnectionChanged( + const CBtDevExtension& aDevice, TBool aConnected ); + + +private: + + /** + * C++ default constructor + */ + CBTNotifPairingManager( + CBTNotifConnectionTracker& aParent, + CBtDevRepository& aDevRepository ); + + /** + * Symbian 2nd-phase constructor + */ + void ConstructL(); + + /** + * Subscribe local device address for determining + * Bluetooth HW power status + */ + void SubscribeLocalAddress(); + + TBool IsLocalAddressAvailable(); + + /** + * Activate / deactivate a pair observer + */ + TInt SetPairObserver(const TBTDevAddr& aAddr, TBool aActivate); + + /** + * Pair a BT device. + */ + void PairDeviceL( const TBTDevAddr& aAddr, TUint32 aCod ); + + /** + * Cancel all subscribes to pairng server + */ + void CancelSubscribePairingAuthenticate(); + + /** + * subscribe to receive SSP pairing result from pairing server + */ + void SubscribeSspPairingResult(); + + /** + * Subscribe to receive authentication result from pairing server + */ + void SubscribeAuthenticateResult(); + + /** + * Handle a pairing result from the pairing server. + * + * @since Symbian^4 + * @param aResult The status code of the authentication result. + */ + void HandlePairingResultL( const TBTDevAddr& aAddr, TInt aResult ); + + /** + * Copy the paired devices to internal array storage. + */ + void UpdatePairedDeviceListL(); + + /** + * Handles a new bonding event from Registry. + */ + void HandleRegistryBondingL( const TBTNamelessDevice& aNameless ); + + +private: + + /** + * Owner of this class. + * Not owned. + */ + CBTNotifConnectionTracker& iParent; + + /** + * Reference to repository. + * Not owned. + */ + CBtDevRepository& iDevRepository; + + /** + * The session with BT registry. + * own. + */ + RBTRegistry iRegistry; + + /** + * contains the list of all paired devices. + */ + RArray iPairedDevices; + + /** + * Session with the pairing server. + * Allocate it in heap to ease the handling for + * situation of unavailable dedicated pairing service. + * + * own. + */ + RBluetoothPairingServer* iPairingServ; + + /** + * Subsession with the pairing server for + * getting the simple pairing result. + * own + */ + RBluetoothPairingResult iPairingResult; + + /** + * Subsession with the pairing server for + * getting the authentication result. + * own + */ + RBluetoothAuthenticationResult iAuthenResult; + + /** + * the address with which a simple pairing has been performed + */ + TBTDevAddr iSimplePairingRemote; + + /** + * the address with which an authentication has been performed + */ + TBTDevAddr iAuthenticateRemote; + + /** + * Active object helper for receiving simple pairing results. + * Own. + */ + CBtSimpleActive* iSSPResultActive; + + /** + * Active object helper for receiving authentication results. + * Own. + */ + CBtSimpleActive* iAuthenResultActive; + + /** + * pairing hanlder at the time. + * Own. + */ + CBTNotifBasePairingHandler* iPairingHandler; + + /** + * The handler for pairing notifiers + */ + CBTNotifPairNotifier* iPairNotifier; + + /** + * Client-server message for power change requests. + */ + RMessage2 iMessage; + + /** + * AO for local address updates. + */ + CBtSimpleActive* iLocalAddrActive; + + /** + * Provides access to the BT local device address. + */ + RProperty iPropertyLocalAddr; + }; + +#endif /*BTNOTIFPAIRINGMANAGER_H*/ + + + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/inc/btnotifpairnotifier.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifpairnotifier.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,297 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTNOTIFPAIRNOTIFIER_H +#define BTNOTIFPAIRNOTIFIER_H + +#include +#include +#include "bluetoothdevicedialogs.h" +#include "btnotificationresult.h" +#include "bluetoothtrace.h" + +class CBTNotifPairingManager; +class CBTNotifConnectionTracker; +class CBluetoothNotification; + +/** + * Helper class for performing user prompt for pairing and authorization. + * + * The design of this class is focussed on structure and maintainability first. + * Duplicate (state) information is kept to a minimum. And memory usage comes + * before processing. Pairing is an infrequent operation, and this class is + * only instantiated when there is pairing-related processing, so extreme + * focus on memory or processing efficiency would have relatively little effect. + * + * Auth represents Authenticate and Authorize + * + * @since Symbian^4 + */ +NONSHARABLE_CLASS( CBTNotifPairNotifier ) : public CBase, + public MBTNotificationResult + { + +public: + + /** + * Two-phased constructor. + * @param aConnection Pointer to the parent. + * @param aDevice Pointer to information of the remote device. + * aParam The owner of this object + */ + static CBTNotifPairNotifier* NewL( CBTNotifPairingManager& aParent ); + + /** + * Destructor. + */ + virtual ~CBTNotifPairNotifier(); + + /** + * Handle a notifier request for pairing with the remote device + * of this connection. + * + * @since Symbian^4 + * @param aMessage The client of this request. + */ + void StartPairingNotifierL( const RMessage2& aMessage ); + + /** + * Update an outstanding request for this connection. + * + * @since Symbian^4 + * @param aUid The UID of the notifier for this update. + * @param aParams The updated parameters for this request from the client. + */ + void UpdatePairingNotifierL( TInt aUid, const TDesC8& aParams ); + + /** + * Cancel an outstanding request for this connection. + * + * @since Symbian^4 + * @param aUid The UID of the notifier for this pairing request. + */ + void CancelPairingNotifierL( TInt aUid ); + +// from base class MBTNotificationResult + + /** + * From MBTNotificationResult. + * Handle an intermediate result from a user query. + * This function is called if the user query passes information + * back before it has finished i.e. is dismissed. The final acceptance/ + * denial of a query is passed back in MBRNotificationClosed. + * + * @since Symbian^4 + * @param aData the returned data. The actual format + * is dependent on the actual notifier. + */ + virtual void MBRDataReceived( CHbSymbianVariantMap& aData ); + + /** + * From MBTNotificationResult. + * The notification is finished. The resulting data (e.g. user input or + * acceptance/denial of the query) is passed back here. + * + * @since Symbian^4 + * @param aErr KErrNone or one of the system-wide error codes. + * @param aData the returned data. The actual format + * is dependent on the actual notifier. + */ + virtual void MBRNotificationClosed( TInt aError, const TDesC8& aData ); + +private: + + /** + * C++ default constructor. + */ + CBTNotifPairNotifier( CBTNotifPairingManager& aParent ); + + /** + * Symbian 2nd-phase constructor. + */ + void ConstructL(); + + void StartPairingUserInputL(); + + /** + * Process the user input and complete the outstanding pairing request. + * + * @since Symbian^4 + * @param aError The result off the notification. + * @param aResult The user response; ETrue if the user accepted the query, + * otherwise EFalse. + * @param aData The data returned from the notification dialog. + */ + void CompletePairingNotifierL( TInt aError, TBool aResult, const TDesC8& aData ); + + /** + * Ask the user to allow incoming pairing. + * + * @since Symbian^4 + */ + void StartAcceptPairingQueryL(); + + /** + * Process the user input and for accepting an incoming pairing and + * continue with the outstanding pairing request. + * + * @since Symbian^4 + * @param aError The result of the notification. + * @param aResult The user response; ETrue if the user accepted the query, + * otherwise EFalse. + */ + void CompleteAcceptPairingQueryL( TInt aError, TBool aResult ); + + /** + * Parse the parameters of a request for pairing. + * This function also returns values to use for dialog config, and sets + * the operation state member variable (iOperation). + * + * @since Symbian^4 + */ + void ParseNotifierReqParamsL(); + + /** + * Parse the parameters of a request for pairing using pin query. + * + * @since Symbian^4 + * @param aLocallyInitiated On return, will be set to ETrue if the pairing + * was initiated by us. + * @param aMinPinLength On return, this will contain the minimum passcode length. + */ + void ParseLegacyPinCodeReqParamsL( TBool& aLocallyInitiated, + TInt& aMinPinLength, TBTDevAddr& aAddr ); + + /** + * Parse the parameters of a request for pairing using pin query. + * + * @since Symbian^4 + * @param aLocallyInitiated On return, will be set to ETrue if the pairing + * was initiated by us. + * @param aMinPinLength On return, this will contain the minimum passcode length. + */ + void ParsePinCodeReqParamsL( TBool& aLocallyInitiated, TInt& aMinPinLength, + TBTDevAddr& aAddr); + + /** + * Parse the parameters of a request for pairing using numeric comparison. + * + * @since Symbian^4 + * @param aLocallyInitiated On return, will be set to ETrue if the pairing + * was initiated by us. + * @param aNumVal On return, this descriptor will contain the passkey to + * show to the user. + */ + void ParseNumericCompReqParamsL( TBool& aLocallyInitiated, TDes& aNumVal, + TBTDevAddr& aAddr); + + /** + * Parse the parameters of a request for pairing using passkey display. + * + * @since Symbian^4 + * @param aLocallyInitiated On return, will be set to ETrue if the pairing + * was initiated by us. + * @param aNumVal On return, this descriptor will contain the passkey to + * show to the user. + */ + void ParsePasskeyDisplayReqParamsL( TBool& aLocallyInitiated, TDes& aNumVal, + TBTDevAddr& aAddr ); + + /** + * Get a notification and configure it according to the current operation. + * + * @since Symbian^4 + * @param aType The notification type. + * @param aResourceId Identifier for the resource to display. + */ + void PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType, + TBTDialogResourceId aResourceId ); + + /** + * Handle the result from a notification that is finished. + * + * @since Symbian^4 + * @param aErr KErrNone or one of the system-wide error codes. + * @param aData The returned data. The actual format + * is dependent on the actual notifier. + */ + void NotificationClosedL( TInt aError, const TDesC8& aData ); + + /** + * Ask the user if he/she wants to block future connection requests. + * + * @since Symbian^4 + */ + void LaunchBlockingQueryL(); + +private: // data + + enum TNotifierState + { + EIncomingPairingAcceptconfirm, + EPairingInputConfirm, + }; + + CBTNotifPairingManager& iParent; + + /** + * The client request. + */ + RMessage2 iNotifierMessage; + + /** + * Buffer containing the parameters of the client message. + * Own. + */ + RBuf8 iParams; + + /** + * Pointer to an outstanding user interaction. + * Not own. + */ + CBluetoothNotification* iNotification; + + // will be set to ETrue if the pairing + // was initiated by us. + TBool iLocallyInitiated; + + // contain a number to use in the pairing dialog. + TBuf<8> iDialogNumeric; + + // the dialog type. + TBluetoothDialogParams::TBTDialogType iDialog; + + // the resource id to be loaded to the dialog + TBTDialogResourceId iDialogResource; + + // the address of the device with which the pairing is performed. + TBTDevAddr iRemote; + + // contains the minimum requirements for pin + // code length. -1 indicates this is not PIn code pairing. + TInt iMinPinLength; + + // Contains the device name provided in params + TBTDeviceName iCurrentDeviceName; + + TNotifierState iState; + + BTUNITTESTHOOK + + }; + +#endif // BTNOTIFPAIRNOTIFIER_H diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/inc/btnotifserver.h --- a/bluetoothengine/btnotif/btnotifsrv/inc/btnotifserver.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifserver.h Mon May 17 11:06:23 2010 +0300 @@ -1,24 +1,19 @@ /* -* ============================================================================ -* Name : btnotifserver.h -* Part of : bluetoothengine / btnotif -* Description : Server class for handling commands from clients, and the +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Server class for handling commands from clients, and the * central class in btnotif thread. * -* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* Nokia Corporation -* ============================================================================ -* Template version: 4.2 */ #ifndef BTNOTIFSERVER_H @@ -151,40 +146,6 @@ CBTNotifDeviceSelector& DeviceSelectorL(); - /** - * Searches for a specific client message from a message handle - * on all active sessions, and complete the message with the - * specified reason code. - * - * @since Symbian^4 - * @param aHandle The handle identifying the message. - * @param aReply Data to write back to the client. - * @return KErrNone on success; KErrNotFound if the message is not found. - */ - TInt CompleteMessage( TInt aHandle, TInt aReason, const TDesC8& aReply ); - - /** - * Searches for and returns a specific client message from a message - * handle on all active sessions. - * - * @since Symbian^4 - * @param aHandle The handle identifying the message. - * @return Pointer to the message, NULL if not found. - */ - const RMessage2* FindMessageFromHandle( TInt aHandle ); - - /** - * Searches for and returns a specific client message from a message - * UID on all active sessions. - * The use of this method assumes that there can be only one message - * outstanding for a specific UID. This is enforced by RNotifier backend. - * - * @since Symbian^4 - * @param aUid The UID identifying the message. - * @return Pointer to the message, NULL if not found. - */ - const RMessage2* FindMessageFromUid( TInt aUid ); - // from base class CPolicyServer /** @@ -280,6 +241,9 @@ */ CDeltaTimer* iTimer; + /** + * The function entry of shutdown timeout. + */ TDeltaTimerEntry iShutdownTimerEntry; BTUNITTESTHOOK diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/inc/btnotifsession.h --- a/bluetoothengine/btnotif/btnotifsrv/inc/btnotifsession.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifsession.h Mon May 17 11:06:23 2010 +0300 @@ -1,23 +1,18 @@ /* -* ============================================================================ -* Name : btnotifsession.h -* Part of : bluetoothengine / btnotif -* Description : Session class for handling commands from clients. +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". * -* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* Initial Contributors: +* Nokia Corporation - initial contribution. * -* Initial Contributors: -* Nokia Corporation - initial contribution. +* Contributors: * -* Contributors: -* Nokia Corporation -* ============================================================================ -* Template version: 4.2 +* Description: Session class for handling commands from clients. +* */ #ifndef BTNOTIFSESSION_H @@ -64,35 +59,6 @@ */ virtual void CreateL(); - /** - * Complete a client message from a message handle. - * - * @since Symbian^4 - * @param aHandle The handle identifying the message. - * @param aReason The reason code to complete the message with. - * @param aReply Data to write back to the client. - * @return KErrNone on success; KErrNotFound if the message is not found. - */ - TInt CompleteMessage( TInt aHandle, TInt aReason, const TDesC8& aReply ); - - /** - * Find a message identified by an RMessage2 handle. - * - * @since Symbian^4 - * @param aHandle The handle identifying the message. - * @return The message. - */ - const RMessage2* FindMessageFromHandle( TInt aHandle ) const; - - /** - * Find a message identified by an RNotifier notifier UID. - * - * @since Symbian^4 - * @param aUid The UID identifying the message. - * @return The message. - */ - const RMessage2* FindMessageFromUid( TInt aUid ) const; - private: CBTNotifSession(); @@ -108,21 +74,8 @@ inline CBTNotifServer* Server() const { return (CBTNotifServer*) CSession2::Server(); } - /** - * Processes a message from a client. - * - * @since Symbian^4 - * @param aMessage The message containing the details of the client request. - */ - void DispatchMessageL( const RMessage2& aMessage ); - private: // data - /** - * Array of messages currently being processed. - */ - RArray iMessageQ; - BTUNITTESTHOOK }; diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/inc/btnotifsettingstracker.h --- a/bluetoothengine/btnotif/btnotifsrv/inc/btnotifsettingstracker.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifsettingstracker.h Mon May 17 11:06:23 2010 +0300 @@ -1,24 +1,19 @@ /* -* ============================================================================ -* Name : btnotifsettingstracker.h -* Part of : BTProximity / BTProximity -* Description : Class for tracking Bluetooth settings, and also for -* handling notes unrelated to specific connection. +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". * -* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* Initial Contributors: +* Nokia Corporation - initial contribution. * -* Initial Contributors: -* Nokia Corporation - initial contribution. +* Contributors: * -* Contributors: -* Nokia Corporation -* ============================================================================ -* Template version: 4.2 +* Description: Class for tracking Bluetooth settings, and also for +* handling notes unrelated to specific connection. +* */ #ifndef BTNOTIFSETTINGSTRACKER_H diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/inc/traceconfig.h --- a/bluetoothengine/btnotif/btnotifsrv/inc/traceconfig.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/traceconfig.h Mon May 17 11:06:23 2010 +0300 @@ -71,13 +71,13 @@ * Tracing media configuration */ #ifdef BLUETOOTHTRACE_ENABLED - #ifdef __WINS__ - #define BLUETOOTHTRACE_MEDIA_FILE - #else + //#ifdef __WINS__ + //#define BLUETOOTHTRACE_MEDIA_FILE + //#else // RDEBUG is used for tracing output before we migrate to OST tracing. #define BLUETOOTHTRACE_MEDIA_RDEBUG // #define BLUETOOTHTRACE_MEDIA_OST - #endif // __WINS__ + //#endif // __WINS__ #endif //BLUETOOTHTRACE_ENABLED /* diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/src/bluetoothnotification.cpp --- a/bluetoothengine/btnotif/btnotifsrv/src/bluetoothnotification.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifsrv/src/bluetoothnotification.cpp Mon May 17 11:06:23 2010 +0300 @@ -1,24 +1,19 @@ /* -* ============================================================================ -* Name : bluetoothnotification.cpp -* Part of : bluetoothengine / btnotif -* Description : Class for managing an actual user notification or query. -* It hides UI framework-specifics in a private class. +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". * -* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* Initial Contributors: +* Nokia Corporation - initial contribution. * -* Initial Contributors: -* Nokia Corporation - initial contribution. +* Contributors: * -* Contributors: -* Nokia Corporation -* ============================================================================ -* Template version: 4.1 +* Description: Description: Class for managing an actual user notification or query. +* It hides UI framework-specifics in a private class. +* */ #include "bluetoothnotification.h" @@ -87,29 +82,6 @@ BOstraceFunctionExit1( DUMMY_DEVLIST, this ) } - -// --------------------------------------------------------------------------- -// Resets the notification, clean all the internals. -// --------------------------------------------------------------------------- -// -void CBluetoothNotification::Reset() - { - BOstraceFunctionEntry1( DUMMY_DEVLIST, this ); - iType = TBluetoothDialogParams::EInvalidDialog; - iResourceId = ENoResource; - iObserver = NULL; - iDialog->Cancel(); - iDialog->SetObserver( NULL ); // Not interested in a callback anymore. - delete iNotificationData; - iNotificationData = NULL; - iNotificationData = CHbSymbianVariantMap::NewL(); - delete iReturnData; - iReturnData = NULL; - iReturnData = CHbSymbianVariantMap::NewL(); - BOstraceFunctionExit1( DUMMY_DEVLIST, this ); - } - - // --------------------------------------------------------------------------- // Sets the data to be shown to the user. // --------------------------------------------------------------------------- @@ -142,7 +114,7 @@ int ret = iDialog->Update( *iNotificationData ); delete iNotificationData; iNotificationData = NULL; - iNotificationData = CHbSymbianVariantMap::NewL(); + TRAP( ret, iNotificationData = CHbSymbianVariantMap::NewL() ); BOstraceFunctionExit1( DUMMY_DEVLIST, this ); return ret; } @@ -152,38 +124,21 @@ // Show the notification, which means that it is added to the queue. // --------------------------------------------------------------------------- // -TInt CBluetoothNotification::Show() +void CBluetoothNotification::ShowL() { BOstraceFunctionEntry1( DUMMY_DEVLIST, this ); - TRAPD( err, SetDataL( TBluetoothDialogParams::EDialogType, iType ) ); - if( !err ) - { - TRAP( err, SetDataL( TBluetoothDialogParams::EResource, iResourceId ) ); - } + SetDataL( TBluetoothDialogParams::EDialogType, iType ); + SetDataL( TBluetoothDialogParams::EResource, iResourceId ); delete iReturnData; iReturnData = NULL; - if( !err ) - { - TRAP( err, iReturnData = CHbSymbianVariantMap::NewL() ); - } - if( !err ) - { - err = iDialog->Show( KBTDevDialogId(), *iNotificationData, this ); - } + iReturnData = CHbSymbianVariantMap::NewL(); + iDialog->Show( KBTDevDialogId(), *iNotificationData, this ); delete iNotificationData; iNotificationData = NULL; iNotificationData = CHbSymbianVariantMap::NewL(); - - const TInt KPluginErr = CHbDeviceDialogSymbian::EPluginErrors + 1; - if( err == KPluginErr ) - { - err = KErrNotFound; - } - BOstraceFunctionExitExt( DUMMY_DEVLIST, this, err ); - return err; + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); } - // --------------------------------------------------------------------------- // Stop showing the notification. // --------------------------------------------------------------------------- @@ -325,13 +280,22 @@ { BOstraceFunctionEntry1( DUMMY_DEVLIST, this ); BtTraceBlock( debugHbSymbianVariantMap(aData); ); + CHbSymbianVariant* value = NULL; for( TInt i = 0; i < aData.Keys().MdcaCount(); i++ ) { TPtrC key( aData.Keys().MdcaPoint( i ).Ptr(), aData.Keys().MdcaPoint( i ).Length() ); const CHbSymbianVariant* valueRef = aData.Get( key ); - CHbSymbianVariant* value = CHbSymbianVariant::NewL( valueRef->Data(), valueRef->Type() ); - TInt err = iReturnData->Add( key, value ); - NOTIF_NOTHANDLED( !err ) + value = NULL; + TRAP_IGNORE( value = + CHbSymbianVariant::NewL( valueRef->Data(), valueRef->Type() ) ); + if ( value ) + { + TInt err = iReturnData->Add( key, value ); + if ( err ) + { + // todo: better exception handing than ignoring this failure? + } + } } iObserver->MBRDataReceived( aData ); BOstraceFunctionExit1( DUMMY_DEVLIST, this ); @@ -433,6 +397,7 @@ } iObserver->MBRNotificationClosed( aCompletionCode, resultPtr ); } + resultBuf.Close(); iManager->ReleaseNotification( this ); // Note that we might get deleted after releasing ourselves. BOstraceFunctionExit1( DUMMY_DEVLIST, this ); diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/src/btnotifbasepairinghandler.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifbasepairinghandler.cpp Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,126 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "btnotifpairingmanager.h" +#include "btnotifbasepairinghandler.h" + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor +// --------------------------------------------------------------------------- +// +CBTNotifBasePairingHandler::CBTNotifBasePairingHandler( CBTNotifPairingManager& aParent, const TBTDevAddr& aAddr) + : iAddr( aAddr ), iParent( aParent ) + { + } + +// --------------------------------------------------------------------------- +// Symbian 2nd-phase constructor +// --------------------------------------------------------------------------- +// +void CBTNotifBasePairingHandler::BaseConstructL( ) + { + iActive = CBtSimpleActive::NewL( *this, 0 ); + } + +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +CBTNotifBasePairingHandler::~CBTNotifBasePairingHandler() + { + delete iActive; + } + +// --------------------------------------------------------------------------- +// Message passes through only if the result is for the same device this +// object is for. +// --------------------------------------------------------------------------- +// +void CBTNotifBasePairingHandler::HandlePairServerResult( const TBTDevAddr& aAddr, TInt aResult ) + { + if ( aAddr == iAddr ) + { + DoHandlePairServerResult( aResult ); + } + } + +// --------------------------------------------------------------------------- +// Message passes through only if the result is for the same device this +// object is for. +// --------------------------------------------------------------------------- +// +void CBTNotifBasePairingHandler::HandleRegistryNewPairedEvent( const TBTNamelessDevice& aDev ) + { + if ( aDev.Address() == iAddr ) + { + DoHandleRegistryNewPairedEvent( aDev ); + } + } + +// --------------------------------------------------------------------------- +// Default impl of virtual function. do nothing +// --------------------------------------------------------------------------- +// +void CBTNotifBasePairingHandler::CancelOutgoingPair() + { + } + +// --------------------------------------------------------------------------- +// Default impl does not offer a known PIN code for pairing +// --------------------------------------------------------------------------- +// +void CBTNotifBasePairingHandler::GetPinCode( + TBTPinCode& aPin, const TBTDevAddr& aAddr, TInt aMinPinLength ) + { + aPin().iLength = 0; + (void) aAddr; + (void) aMinPinLength; + } + +// --------------------------------------------------------------------------- +// Invalidate iPairResultSet +// --------------------------------------------------------------------------- +// +void CBTNotifBasePairingHandler::UnSetPairResult() + { + iPairResultSet = EFalse; + } + +// --------------------------------------------------------------------------- +// Save the result and validate the flag +// --------------------------------------------------------------------------- +// +void CBTNotifBasePairingHandler::SetPairResult( TInt aResult ) + { + iPairResult = aResult; + iPairResultSet = ETrue; + } + +// --------------------------------------------------------------------------- +// Returns the flag +// --------------------------------------------------------------------------- +// +TBool CBTNotifBasePairingHandler::IsPairResultSet() + { + return iPairResultSet; + } + + + + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/src/btnotifconnection.cpp --- a/bluetoothengine/btnotif/btnotifsrv/src/btnotifconnection.cpp Wed May 05 09:56:48 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,964 +0,0 @@ -/* -* ============================================================================ -* Name : btnotifconnection.cpp -* Part of : bluetoothengine / btnotif -* Description : Class for observing events of a single connection, and for -* managing any user notifications related to the connection. -* -* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* Nokia Corporation -* ============================================================================ -* Template version: 4.1 -*/ - -#include "btnotifconnection.h" -#include -#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS -#include -#endif - -#include "btnotifconnectiontracker.h" -#include "btnotifpairinghelper.h" -#include "btnotificationmanager.h" -#include "btnotifclientserver.h" -#include "bluetoothtrace.h" - -/** Id for the baseband connection watcher active object. */ -const TInt KConnectionWatcher = 40; -/** Id for the registry watcher active object. */ -const TInt KRegistryWatcher = 41; -/** Id for the active object for updating the registry. */ -const TInt KRegistryRetriever = 42; -/** Event mask for subscribing to baseband connection events - * (need to check if these are appropriate). */ -const TInt KBbEventMask = ENotifyAnyRole | ENotifyAuthenticationComplete | - ENotifyPhysicalLinkUp | ENotifyPhysicalLinkDown | ENotifyPhysicalLinkError; - - -// ======== LOCAL FUNCTIONS ======== - -// --------------------------------------------------------------------------- -// Decide the device name to display from the device information, and -// converts the name if necessary. -// --------------------------------------------------------------------------- -// -void GetDeviceNameL( TBTDeviceName& aName, const CBTDevice& aDevice ) - { - if( aDevice.IsValidFriendlyName() ) - { - aName.Copy( aDevice.FriendlyName() ); - } - else - { - aName.Zero(); - if( aDevice.IsValidDeviceName() ) - { - aName = BTDeviceNameConverter::ToUnicodeL( aDevice.DeviceName() ); - } - } - } - - -// --------------------------------------------------------------------------- -// Compare 2 device records device pairing has succeeded. -// aDev2 is the updated device record, aDev1 is the previous record. -// --------------------------------------------------------------------------- -// -TBool CheckRegistryPairedStatus( const CBTDevice* aOrig, const CBTDevice* aNew ) - { - TBool result = EFalse; - // Use the device class to check that this has any valid information. - if( aOrig->AsNamelessDevice().IsValidDeviceClass() && - !( aOrig->IsValidPaired() && aOrig->IsPaired() ) || - aOrig->LinkKeyType() == ELinkKeyUnauthenticatedUpgradable ) - { - // Only consider the result if the original device is not marked as paired. - if( aNew->IsValidPaired() && aNew->IsPaired() && aNew->IsValidLinkKey() && - aNew->LinkKeyType() != ELinkKeyUnauthenticatedUpgradable ) - { - // The new device record has valid pairing information, so - // this device is now paired. - result = ETrue; - } - } - return result; - } - - -// ======== MEMBER FUNCTIONS ======== - -// --------------------------------------------------------------------------- -// C++ default constructor -// --------------------------------------------------------------------------- -// -CBTNotifConnection::CBTNotifConnection( const TBTDevAddr& aAddr, - CBTNotifConnectionTracker* aTracker ) -: iAddr( aAddr ), - iTracker( aTracker ) - { - } - - -// --------------------------------------------------------------------------- -// Symbian 2nd-phase constructor -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::ConstructL() - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - iDevice = CBTDevice::NewL( iAddr ); - iPhyActive = CBtSimpleActive::NewL(*this, KConnectionWatcher ); - iRegActive = CBtSimpleActive::NewL( *this, KRegistryRetriever ); - // ToDo: need to check if this succeeds if a connection is - // being created, in case of outgoing pairing. - User::LeaveIfError( iPhyLink.Open( iTracker->SocketServerSession(), iAddr ) ); - // Subscribe to events. - iBasebandEvent.FillZ(); // To be sure that we are not reading false events. - iPhyLink.NotifyNextBasebandChangeEvent( iBasebandEvent, - iPhyActive->RequestStatus(), KBbEventMask ); - iPhyActive->GoActive(); - // Get the details from BT registry - TBTRegistrySearch pattern; - pattern.FindAddress( iAddr ); - User::LeaveIfError( iRegistry.Open( iTracker->RegistryServerSession() ) ); - iRegistry.CreateView( pattern, iRegActive->RequestStatus() ); - iRegActive->GoActive(); - iCurrentOp = EReadingRegistry; - iRegDevArray = new CBTDeviceArray(1); // only 1 entry ever used - // ToDo: more initialization needed? - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// NewLC. -// --------------------------------------------------------------------------- -// -CBTNotifConnection* CBTNotifConnection::NewLC( const TBTDevAddr& aAddr, - CBTNotifConnectionTracker* aTracker ) - { - CBTNotifConnection* self = new( ELeave ) CBTNotifConnection( aAddr, aTracker ); - CleanupStack::PushL( self ); - self->ConstructL(); - return self; - } - - -// --------------------------------------------------------------------------- -// Destructor -// --------------------------------------------------------------------------- -// -CBTNotifConnection::~CBTNotifConnection() - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - if( iNotification ) - { - // Clear the notification callback, we cannot receive them anymore. - iNotification->RemoveObserver(); - iNotification->Close(); // Also dequeues the notification from the queue. - iNotification = NULL; - } - delete iRegActive; - delete iRegistryResponse; - iRegistry.Close(); - delete iDevMan; - - delete iPhyActive; - iPhyLink.Close(); - delete iDevice; - delete iPairingHelper; - - while( iMsgHandleQ.Count() ) - { - CompleteClientRequest( KErrDisconnected, KNullDesC8 ); - } - iMsgHandleQ.Close(); - iAcceptedConnections.Close(); - iDeniedConnections.Close(); - iRegDevArray->ResetAndDestroy(); - delete iRegDevArray; - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// Check what to do next. -// This function should be called whenever we may be ready for the next -// request/action, which is from any callback function i.e. -// MBAORequestCompletedL, MBRNotificationClosed, HandleNotifierRequestL and -// CancelNotifierRequestL. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::CheckNextOperationL() - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - if( iCurrentOp == EIdle ) - { - // Check the link state, to see if it has gone down already. - TUint32 linkState = 0; - TInt err = iPhyLink.PhysicalLinkState( linkState ); - TBool linkDown = linkState & ENotifyPhysicalLinkDown; - if( ( !err && linkDown ) || err == KErrDisconnected ) - { - // The link state tells us that the link is down, - // inform the connection tracker the we are done. - iTracker->HandleLinkCountChangeL(); - // Note that we may be deleted now! - } - else if( iMsgHandleQ.Count() ) - { - // Get the next request and handle it. - // ToDo: differentiate between notifier and pairing message! - const RMessage2* message = iTracker->Server()->FindMessageFromHandle( iMsgHandleQ[0] ); - NOTIF_NOTHANDLED( message ) - TInt opcode = message->Function(); - if( opcode <= EBTNotifUpdateNotifier ) - { - TBuf8<0x250> paramsBuf; // Size needs to be long enough to read all possible parameter sizes. - message->ReadL( EBTNotifSrvParamSlot, paramsBuf ); - HandleNotifierRequestL( paramsBuf, *message ); - } - else - { - iMsgHandleQ.Remove( 0 ); - StartBondingL( *message ); - } - } - } - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// Complete the first outstanding client request and removes it from the queue. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::CompleteClientRequest( TInt aReason, const TDesC8& aReply ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - NOTIF_NOTHANDLED( iMsgHandleQ.Count() ) - TInt err = iTracker->Server()->CompleteMessage( iMsgHandleQ[0], aReason, aReply ); - NOTIF_NOTHANDLED( !err ) - iMsgHandleQ.Remove( 0 ); - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// Distinguish a request and pass to corresponding handle. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::HandleNotifierRequestL( const TDesC8& aParams, - const RMessage2& aMessage ) - { - BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aMessage.Int0() ); - if( !iMsgHandleQ.Count() || iMsgHandleQ[0] != aMessage.Handle() ) - { - // If we are processing a queued request, we of course don't queue - // it again. In that case we are handling the first request from the queue. - iMsgHandleQ.AppendL( aMessage.Handle() ); - } - if( iCurrentOp == EIdle || iCurrentOp == EBonding ) - { - // ToDo: check non-pairing operation when bonding - TInt uid = aMessage.Int0(); - if( uid == KBTManAuthNotifierUid.iUid ) - { - HandleAuthorizationReqL( aParams ); - } - else if( uid == KBTManPinNotifierUid.iUid || - uid == KBTPinCodeEntryNotifierUid.iUid || - uid == KBTNumericComparisonNotifierUid.iUid || - uid == KBTPasskeyDisplayNotifierUid.iUid ) - { - if( !iPairingHelper ) - { - BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, - "[BTNOTIF]\t CBTNotifConnection::HandleNotifierRequestL: creating CBTNotifPairingHelper"); - iPairingHelper = CBTNotifPairingHelper::NewL( this, iTracker ); - } - if( iCurrentOp != EBonding ) - { - iCurrentOp = EPairing; - } - iPairingHelper->StartPairingNotifierL( uid, aParams ); - } - // We may be done with the current request, proceed to the next one - CheckNextOperationL(); - } - BOstraceFunctionExit1( DUMMY_DEVLIST, this ); - } - - -// --------------------------------------------------------------------------- -// Update a notifier, update the outstanding dialog if the notifier request -// is currently being served. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::HandleNotifierUpdateL( const TDesC8& aParams, - const RMessage2& aMessage ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - NOTIF_NOTHANDLED( iCurrentOp != EIdle ) - (void) aParams; - TBuf8<0x250> paramsBuf; // Size needs to be long enough to read all possible sizes. - aMessage.ReadL( EBTNotifSrvParamSlot, paramsBuf ); - TInt uid = aMessage.Int0(); - if( uid == KBTManAuthNotifierUid.iUid ) - { - TBTNotifierUpdateParams params; - TPckgC paramsPckg( params ); - paramsPckg.Set( paramsBuf ); - // The result means result of conversion to unicode - if( !paramsPckg().iResult ) - { - // Only update locally, registry will update us with the same info later on. - iDevice->SetDeviceNameL( BTDeviceNameConverter::ToUTF8L( paramsPckg().iName ) ); - if( iNotification ) - { - // Update the dialog with the new name. It is up to the dialog to - // determine the validity (in case another dialog is shown). - //iNotification->Update( ) - } - } - } - else if( iPairingHelper && ( uid == KBTPinCodeEntryNotifierUid.iUid || - uid == KBTNumericComparisonNotifierUid.iUid || - uid == KBTPasskeyDisplayNotifierUid.iUid ) ) - { - // Just forward to pairing helper - iPairingHelper->UpdatePairingNotifierL( uid, paramsBuf ); - } - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// Cancel a request, dismiss the outstanding dialog if the notifier request -// is currently being served. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::CancelNotifierRequestL( const RMessage2& aMessage ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - NOTIF_NOTHANDLED( iCurrentOp != EIdle ) - TInt pos = iMsgHandleQ.Find( aMessage.Handle() ); - if( pos > KErrNotFound ) - { - // We have queued the message, remove it from the queue. - iMsgHandleQ.Remove( pos ); - // We use the supplied handle to remove it, as it may not be - // the first in the queue. - TInt err = iTracker->Server()->CompleteMessage( aMessage.Handle(), KErrCancel, KNullDesC8 ); - NOTIF_NOTHANDLED( !err ) - if( pos == 0 ) - { - // There could be the case that we are still post-processing - // the previous request (e.g. blocking query), then the next - // notification is not yet started but the first in the queue. - // We can see that from the current operation type. - if( iNotification && iCurrentOp < EAdditionalNotes ) - { - // Cancel the user query - // This will also unregister us from the notification. - TInt err = iNotification->Close(); - NOTIF_NOTHANDLED( !err ) - iNotification = NULL; - iCurrentOp = EIdle; - } - if( iPairingHelper ) - { - // The pairing helper calls back PairingCompleted and sets state. - iPairingHelper->CancelPairingNotifierL( aMessage.Int0() ); - // The pairing helper may have now been deleted. - } - } - } - // We may be done with the current request, proceed to the next one - CheckNextOperationL(); - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// Start a bonding operation with the remote device. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::StartBondingL( const RMessage2& aMessage ) - { - BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aMessage.Function() ); - if( iCurrentOp == EIdle || iCurrentOp > EInternalOperations ) - { - __ASSERT_ALWAYS( !iPairingHelper, PanicServer( EBTNotifPanicBadState ) ); - iPairingHelper = CBTNotifPairingHelper::NewL( this, iTracker ); - // The pairingg helper stored the handle, not in our queue here. - // This is because bonding will generate a pairing notifier request, which - // will be completed first. The bookkeeping gets complicated if we have to - // re-order the queue here. - iPairingHelper->StartBondingL( aMessage.Handle() ); - iCurrentOp = EBonding; - } - else if( iCurrentOp == EPairing || iCurrentOp == EBonding ) - { - // We only do one pairing at the time. - User::Leave( KErrInUse ); - } - else - { - // We only store it here if it is not handled immediately. - iMsgHandleQ.AppendL( aMessage.Handle() ); - } - BOstraceFunctionExit1( DUMMY_DEVLIST, this ); - } - - -// --------------------------------------------------------------------------- -// Cancel an ongoing bonding operation with the remote device. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::CancelBondingL() - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - if( iPairingHelper ) - { - iPairingHelper->CancelBondingL(); - } - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// The pairing handler has completed a pairing operation. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::PairingCompleted() - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - __ASSERT_ALWAYS( iPairingHelper, PanicServer( EBTNotifPanicNullMember ) ); - if( iPairingHelper->CurrentOperation() == CBTNotifPairingHelper::EIdle ) - { - // We are still idle. Remove the pairing helper - delete iPairingHelper; - iPairingHelper = NULL; - } - if( iCurrentOp == EPairing || iCurrentOp == EBonding ) - { - iCurrentOp = EIdle; - TRAP_IGNORE( CheckNextOperationL() ); - } - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// Process a new pairing result, and determine if we need to show -// anything to the user. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::PairingResult( TInt aError ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - if( !iPairingHelper ) - { - TRAP_IGNORE( iPairingHelper = CBTNotifPairingHelper::NewL( this, iTracker ) ); - } - if( iPairingHelper ) - { - iPairingHelper->HandleAuthenticationCompleteL( aError ); - } - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// Process the new service-level connection, and determine if we need to -// show anything to the user. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::ServiceConnectedL( TBTProfile aProfile ) - { - (void) aProfile; - } - - -// --------------------------------------------------------------------------- -// Process the new service-level disconnection, and determine if we need to -// show anything to the user. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::ServiceDisconnectedL( TBTProfile aProfile ) - { - (void) aProfile; - } - - -// --------------------------------------------------------------------------- -// Ask the user if he/she wants to block future connection requests. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::LaunchBlockingQueryL() - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - iCurrentOp = EBlocking; - TBTDialogResourceId resourceId = EBlockUnpairedDevice; - if( iDevice->IsValidPaired() && iDevice->IsPaired() && - iDevice->LinkKeyType() != ELinkKeyUnauthenticatedUpgradable ) - { - resourceId = EBlockPairedDevice; - } - PrepareNotificationL( TBluetoothDialogParams::EQuery, resourceId ); - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// Modify the record for the remote device in BTRegistry, with the changes -// already made in the local record. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::UpdateRegistryEntryL() - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - // We use CBTEngDevMan here. We could use the registry API directly, however, - // using this convenience API makes the registry processing much simpler. - if( !iDevMan ) - { - iDevMan = CBTEngDevMan::NewL( this ); - } - iDevMan->ModifyDevice( *iDevice ); - if( iCurrentOp == EIdle || - ( ( iCurrentOp == EPairing || iCurrentOp == EBonding ) && - iPairingHelper->CurrentOperation() == CBTNotifPairingHelper::EIdle ) ) - { - // To make sure that we don't get deleted while updating. - iCurrentOp = EUpdatingRegistry; - } - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - -// --------------------------------------------------------------------------- -// Modify the record for the remote device in BTRegistry, if aTrusted == true, then -// update trusted status after reading device info from registry -// -// --------------------------------------------------------------------------- - -void CBTNotifConnection::UpdateRegistryEntryL( TBool aTrusted ) - { - BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aTrusted ); - if (!aTrusted) { - UpdateRegistryEntryL(); - return; - } - // We use CBTEngDevMan here. We could use the registry API directly, however, - // using this convenience API makes the registry processing much simpler. - if( !iDevMan ) - { - iDevMan = CBTEngDevMan::NewL( this ); - } - // first read device info from registry, to make sure we have up-to-date local info - iCurrentOp = EReadingRegistry; - GetDeviceFromRegistry( iDevice->BDAddr() ); - BOstraceFunctionExit1( DUMMY_DEVLIST, this ); - } - -// --------------------------------------------------------------------------- -// From class MBTNotificationResult. -// Handle a result from a user query. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::MBRDataReceived( CHbSymbianVariantMap & aData ) - { - (void) aData; - NOTIF_NOTIMPL - } - - -// --------------------------------------------------------------------------- -// From class MBTNotificationResult. -// The notification is finished. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::MBRNotificationClosed( TInt aError, const TDesC8& aData ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - // ToDo: call leaving function from here! - __ASSERT_ALWAYS( iCurrentOp != EIdle, PanicServer( EBTNotifPanicBadState ) ); - // First unregister from the notification, so we can already get the next one. - iNotification->RemoveObserver(); - iNotification = NULL; - TRAP_IGNORE( NotificationClosedL( aError, aData ) ); - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// From class MBtSimpleActiveObserver. -// Handle the active object completion. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::RequestCompletedL( CBtSimpleActive* aActive, - TInt aStatus ) - { - BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aActive->RequestId() ); - switch( aActive->RequestId() ) - { - case KRegistryRetriever: - { - BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, - "[BTNOTIF]\t CBTNotifConnection::MBAORequestCompletedL: KRegistryRetriever" ); - if( !iRegistryResponse ) - { - // We have just created the view, now get the results. - // There can only be one result, as the address is unique. - // (note: how about LE random addresses?) - // Or then we have tried to re-open an existing view, so we get KErrInuse. - // We anyway just get the results. - __ASSERT_ALWAYS( aStatus < 2, PanicServer( EBTNotifPanicCorrupt ) ); - iRegistryResponse = CBTRegistryResponse::NewL( iRegistry ); - iRegistryResponse->Start( iRegActive->RequestStatus() ); - iRegActive->GoActive(); - } - else - { - if( !aStatus ) - { - // There can be only one result. - __ASSERT_ALWAYS( iRegistryResponse->Results().Count() == 1, PanicServer( EBTNotifPanicCorrupt ) ); - CBTDevice* regDevice = iRegistryResponse->Results()[0]; - TBool paired = CheckRegistryPairedStatus( iDevice, regDevice ); - iDevice->UpdateL( *regDevice ); - if( paired ) - { - __ASSERT_ALWAYS( iPairingHelper, PanicServer( EBTNotifPanicNullMember ) ); - iPairingHelper->HandleAuthenticationCompleteL( KErrNone ); - } - } - // ToDo: error handling of registry response result? - delete iRegistryResponse; - iRegistryResponse = NULL; - } - if( iCurrentOp == EReadingRegistry && !iRegActive->IsActive() ) - { - // If this is part of the sequence of operations, we are done. - // Otherwise we just update with the latest info from registry, - // and then we don't interrupt or change the state. - iCurrentOp = EIdle; - } - } - // ToDo: start registry watching (preferably using registry API when this is available) - break; - case KRegistryWatcher: - { - BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, - "[BTNOTIF]\t CBTNotifConnection::MBAORequestCompletedL: KRegistryWatcher" ); - NOTIF_NOTHANDLED( !aStatus ) - // Ignore updates while we are already retrieving. - if( !iRegActive->IsActive() ) - { - // Refresh our information with the latest from registry - iRegActive->SetRequestId( KRegistryRetriever ); - TBTRegistrySearch pattern; - pattern.FindAddress( iAddr ); - iRegistry.CreateView( pattern, iRegActive->RequestStatus() ); - iRegActive->GoActive(); - } - } - break; - case KConnectionWatcher: - { - BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, - "[BTNOTIF]\t CBTNotifConnection::MBAORequestCompletedL: KConnectionWatcher" ); - TUint32 event = iBasebandEvent().EventType(); - // First subscribe to the next event notification. - // This will overwrite iBasebandEvent().EventType() with KBbEventMask - iPhyLink.NotifyNextBasebandChangeEvent( iBasebandEvent, - iPhyActive->RequestStatus(), KBbEventMask ); - iPhyActive->GoActive(); - // Link down and link error are handled in CheckNextOperationL below. - // ToDo: handle events! - if( event & ( ENotifyPhysicalLinkDown | ENotifyPhysicalLinkError ) ) - { - // We re-use the error code to store the indication that the - // link has disconnected. This will only be overridden by next - // event, which can only be a connection up event. - iBasebandEvent().SetErrorCode( KErrDisconnected ); - } - if( iPairingHelper ) - { - if( event & ( ENotifyPhysicalLinkDown | ENotifyPhysicalLinkError | - ENotifyAuthenticationComplete ) ) - { - // Results interesting for pairing result processing. - iPairingHelper->HandleAuthenticationCompleteL( iBasebandEvent().SymbianErrorCode() ); - } - else if( event & ENotifyPhysicalLinkUp && - iPairingHelper->CurrentOperation() == CBTNotifPairingHelper::EDedicatedBonding ) - { - iPairingHelper->StartBondingL( 0 ); - } - } - } - break; - default: - PanicServer( EBTNotifPanicBadState ); - break; - } - // We may be done with the current request, proceed to the next one - CheckNextOperationL(); - BOstraceFunctionExit1( DUMMY_DEVLIST, this ); - } - - -// --------------------------------------------------------------------------- -// From class MBtSimpleActiveObserver. -// Cancel and clean up all requests related to the active object. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::CancelRequest( TInt aRequestId ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - if ( aRequestId == KConnectionWatcher ) - { - iPhyLink.CancelNextBasebandChangeEventNotifier(); - } - else if ( aRequestId == KRegistryWatcher && iRegistryResponse ) - { - iRegistryResponse->Cancel(); - } - else if ( aRequestId == KRegistryRetriever ) - { - iRegistry.CancelRequest( iRegActive->RequestStatus()); - } - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - -// --------------------------------------------------------------------------- -// From class MBtSimpleActiveObserver. -// -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::HandleError( CBtSimpleActive* aActive, - TInt aError ) - { - (void) aActive; - (void) aError; - } - -// --------------------------------------------------------------------------- -// From class MBTEngDevmanObserver. -// Registry modification has completed. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::HandleDevManComplete( TInt aErr ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - (void) aErr; - NOTIF_NOTHANDLED( !aErr ) - if( iCurrentOp == EUpdatingRegistry ) - { - // To make sure that we don't get deleted while updating. - iCurrentOp = EIdle; - } - // Refresh is done separately, we will get notified through - // the registry watcher of the change. - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// From class MBTEngDevmanObserver. -// Callback for getting a device from the registry -// -// Currently only used in context of setting device to trusted -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::HandleGetDevicesComplete( - TInt err, CBTDeviceArray* deviceArray ) - { - BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, err ); - // err is not used here very much, -1 could be returned if there is no device in registry, - // but this case is covered by examing mRegDevArray. - if (!err && (iCurrentOp == EReadingRegistry) ) { - CBTDevice* dev (0); - if ( deviceArray->Count() ) { - dev = deviceArray->At( 0 ); - } - if ( dev ) { - iDevice = dev->CopyL(); - } - // Set device to trusted - // Copy the existing security settings. - TBTDeviceSecurity sec( iDevice->GlobalSecurity().SecurityValue(), - iDevice->GlobalSecurity().PasskeyMinLength() ); - sec.SetNoAuthorise( ETrue ); // new value: set device as trusted - iDevice->SetGlobalSecurity( sec ); - iDevMan->ModifyDevice( *iDevice ); // write trusted (& paired) status to registry - // To make sure that we don't get deleted while updating. - iCurrentOp = EUpdatingRegistry; - } - BOstraceFunctionExit1( DUMMY_DEVLIST, this ); - } - -// --------------------------------------------------------------------------- -// Retrieves device from registry based on BT address parameter -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::GetDeviceFromRegistry( const TBTDevAddr &addr ) -{ - BOstraceFunctionEntry1( DUMMY_DEVLIST, this ); - TBTRegistrySearch searchPattern; - searchPattern.FindAddress( addr ); - // and get this device from registry - iRegDevArray->ResetAndDestroy(); - iDevMan->GetDevices(searchPattern, iRegDevArray); - BOstraceFunctionExit1( DUMMY_DEVLIST, this ); -} - -// --------------------------------------------------------------------------- -// Get and configure a notification. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType, - TBTDialogResourceId aResourceId ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - iNotification = iTracker->NotificationManager()->GetNotification(); - User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory - iNotification->SetObserver( this ); - iNotification->SetNotificationType( aType, aResourceId ); - // Set the address of the remote device - TBuf addr; - addr.Copy( iAddr.Des() ); - TInt err = iNotification->SetData( TBluetoothDialogParams::EAddress, addr ); - NOTIF_NOTHANDLED( !err ) - // Set the name of the remote device - TBTDeviceName name; - GetDeviceNameL( name, *iDevice ); - // ToDo: handle leave in name conversion! - err = iNotification->SetData( (TInt) TBluetoothDeviceDialog::EDeviceName, name ); - NOTIF_NOTHANDLED( !err ) - // Queue the notification for displaying to the user - err = iTracker->NotificationManager()->QueueNotification( iNotification ); - NOTIF_NOTHANDLED( !err ) - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// The notification is finished, handle the result. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::NotificationClosedL( TInt aError, const TDesC8& aData ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - switch( iCurrentOp ) - { - case EAuthorizing: - CompleteAuthorizationReqL( aError, aData ); - break; - case EBlocking: - CompleteBlockingReqL( aError, aData ); - break; - default: - NOTIF_NOTIMPL - break; - } - // We may be done with the current request, proceed to the next one - CheckNextOperationL(); - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// Handle a request for authorization of this connection. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::HandleAuthorizationReqL( const TDesC8& aParams ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - __ASSERT_ALWAYS( iCurrentOp == EIdle, PanicServer( EBTNotifPanicBadState ) ); - __ASSERT_ALWAYS( !iNotification, PanicServer( EBTNotifPanicCorrupt ) ); - TBTAuthorisationParams params; - TPckgC paramsPckg( params ); - paramsPckg.Set( aParams ); - iCurrentOp = EAuthorizing; - // The name in the parameter package is the latest one, retrieved from - // the remote device during this connection. - if( paramsPckg().iName.Length() ) - { - // Update the local device record. No need to update the registry, - // that will be done by the stack, and we will receive the update - // information when that has completed. - iDevice->SetDeviceNameL( BTDeviceNameConverter::ToUTF8L( paramsPckg().iName ) ); - } - PrepareNotificationL( TBluetoothDialogParams::EQuery, EAuthorization ); - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// Process the user input and complete the outstanding authorization request. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::CompleteAuthorizationReqL( TInt aError, const TDesC8& aData ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - // Set our state to idle for now. This may get changed if the user just chose - // to block, or if we have a pending request. - iCurrentOp = EIdle; - if( !aError ) - { - TPckgC result( EFalse ); - result.Set( aData ); - TBool proceed = iTracker->UpdateBlockingHistoryL( iDevice, result() ); - if( result() == EFalse && proceed ) - { - // The user denied the connection, ask to block the device. - LaunchBlockingQueryL(); - } - CompleteClientRequest( KErrNone, aData ); - } - else - { - CompleteClientRequest( aError, KNullDesC8 ); - } - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// Process the user input for blocking a device. -// --------------------------------------------------------------------------- -// -void CBTNotifConnection::CompleteBlockingReqL( TInt aError, const TDesC8& aData ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - TPckgC result( EFalse ); - result.Set( KNullDesC8 ); // to test! - result.Set( aData ); - iCurrentOp = EIdle; // May get changed if we have a pending request. - if( !aError && result() ) - { - // The user accepted to block this device. - TBTDeviceSecurity sec; // use default values when setting as banned. - sec.SetBanned( ETrue ); - iDevice->SetGlobalSecurity( sec ); - if( iDevice->IsValidPaired() && iDevice->IsPaired() ) - { - // Deleting the link key will also set the device as unpaired. - iDevice->DeleteLinkKey(); - } - UpdateRegistryEntryL(); - } - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/src/btnotifconnectiontracker.cpp --- a/bluetoothengine/btnotif/btnotifsrv/src/btnotifconnectiontracker.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifconnectiontracker.cpp Mon May 17 11:06:23 2010 +0300 @@ -1,23 +1,18 @@ /* -* ============================================================================ -* Name : btnotifconnectiontracker.cpp -* Part of : bluetoothengine / btnotif -* Description : Bluetooth connection tracker and manager. +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". * -* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* Initial Contributors: +* Nokia Corporation - initial contribution. * -* Initial Contributors: -* Nokia Corporation - initial contribution. +* Contributors: * -* Contributors: -* Nokia Corporation -* ============================================================================ -* Template version: 4.1 +* Description: Bluetooth connection tracker and manager. +* */ #include "btnotifconnectiontracker.h" @@ -26,17 +21,14 @@ #include #endif -#include "btnotifconnection.h" +#include +#include + #include "btnotifsession.h" #include "btnotifclientserver.h" #include "bluetoothtrace.h" +#include "btnotifpairingmanager.h" -/** Id for the link key watcher active object. */ -const TInt KLinkCountWatcher = 30; -/** Id for the pairing result watcher active object. */ -const TInt KSspResultWatcher = 31; -/** Id for the registry watcher active object (TEMP!). */ -const TInt KRegistryWatcher = 41; /** Time window for determining if there are too many requests. */ #ifndef __WINS__ #define KDENYTHRESHOLD TTimeIntervalSeconds(3) @@ -47,24 +39,6 @@ // ======== LOCAL FUNCTIONS ======== -// --------------------------------------------------------------------------- -// Checks if the notifier is one launched by the security manager of the -// protocol stack. These notifiers need to be served unless really not possible. -// --------------------------------------------------------------------------- -// -TBool IsStackSecmanNotifier( TInt aUid ) - { - TBool result = EFalse; - if( aUid == KBTManAuthNotifierUid.iUid || aUid == KBTManPinNotifierUid.iUid || - aUid == KBTPinCodeEntryNotifierUid.iUid || aUid == KBTNumericComparisonNotifierUid.iUid || - aUid == KBTPasskeyDisplayNotifierUid.iUid ) - { - result = ETrue; - } - return result; - } - - // ======== MEMBER FUNCTIONS ======== // --------------------------------------------------------------------------- @@ -84,42 +58,11 @@ void CBTNotifConnectionTracker::ConstructL() { BOstraceFunctionEntry0( DUMMY_DEVLIST ); - // Start watching the number of baseband links. - TInt err = iLinkCount.Attach( KPropertyUidBluetoothCategory, - KPropertyKeyBluetoothGetPHYCount ); - // There is not much point to continue if we can't attach to - // the link count key. - User::LeaveIfError( err ); - iLinkCountActive = CBtSimpleActive::NewL( *this, KLinkCountWatcher ); - iLinkCount.Subscribe( iLinkCountActive->RequestStatus() ); - iLinkCountActive->GoActive(); // Open a handle to the registry server User::LeaveIfError( iBTRegistrySession.Connect() ); // Open a handle to the socket server User::LeaveIfError( iSockServ.Connect() ); - iPairingServ = new( ELeave ) RBluetoothPairingServer(); - if( iPairingServ->Connect() ) - { - // Delete in case of error - there is no good other way to keep track. - delete iPairingServ; - iPairingServ = NULL; - } - else - { - iSspResultActive = CBtSimpleActive::NewL( *this, KSspResultWatcher ); - User::LeaveIfError( iSspResultSession.Open( *iPairingServ ) ); - iSspResultSession.SimplePairingResult( iSspResultAddr, iSspResultActive->RequestStatus() ); - iSspResultActive->GoActive(); - } - iConnMan = CBTEngConnMan::NewL( this ); - iPhyLinks = CBluetoothPhysicalLinks::NewL( *this, iSockServ ); -// ToDo: remove this when registry notifications API is available!! - err = iRegistryChange.Attach( KPropertyUidBluetoothCategory, KPropertyKeyBluetoothRegistryTableChange ); - User::LeaveIfError( err ); - iRegistryActive = CBtSimpleActive::NewL( *this, KRegistryWatcher ); - iRegistryChange.Subscribe( iRegistryActive->RequestStatus() ); - iRegistryActive->GoActive(); -// End ToDo + iPairingManager = CBTNotifPairingManager::NewL(*this, iServer->DevRepository() ); BOstraceFunctionExit0( DUMMY_DEVLIST ); } @@ -145,92 +88,24 @@ CBTNotifConnectionTracker::~CBTNotifConnectionTracker() { BOstraceFunctionEntry0( DUMMY_DEVLIST ); - iConnArray.ResetAndDestroy(); - iConnArray.Close(); iDeniedRequests.Close(); - delete iLinkCountActive; - iLinkCount.Close(); - - delete iConnMan; - delete iPhyLinks; + delete iPairingManager; iSockServ.Close(); - delete iSspResultActive; - iSspResultSession.Close(); - if( iPairingServ ) - { - iPairingServ->Close(); - delete iPairingServ; - } - delete iRegistryActive; - iRegistryChange.Close(); iBTRegistrySession.Close(); BOstraceFunctionExit0( DUMMY_DEVLIST ); } // --------------------------------------------------------------------------- -// Process a client message related to notifiers. +// Process notifier message related to pairing notifiers. // --------------------------------------------------------------------------- // -void CBTNotifConnectionTracker::DispatchNotifierMessageL( const RMessage2& aMessage ) +void CBTNotifConnectionTracker::HandlePairingNotifierRequestL( const RMessage2& aMessage ) { BOstraceFunctionEntryExt ( DUMMY_LIST, this, aMessage.Function() ); - TInt opcode = aMessage.Function(); - TInt uid = aMessage.Int0(); - const RMessage2* message = &aMessage; - // Use a pointer to the original message, so that we don't duplicate it. - // Then we avoid any bookkeeping for keeping them in sync. - if( opcode == EBTNotifCancelNotifier ) - { - // We only accept a cancel message from the same session as the original - // request (this is enforced by the RNotifier backend). So we use the - // session of the cancel request (if this would change, the same way as - // for updates can be followed). - // We need to find the original request to identify the handler of the - // connection; the uid points to the original request. - message = ( (CBTNotifSession *) aMessage.Session() )->FindMessageFromUid( uid ); - } - else if( opcode == EBTNotifUpdateNotifier ) - { - // We accept a update messages from any client, although in practice, - // they will all come from the same session (through RNotifier). - // We need to find the original request to identify the handler of the - // connection (the uid points to the original request). Through the - // server, we get it from any session. - message = iServer->FindMessageFromUid( uid ); - } - if( !message ) - { - // It's hard to continue if we don't know where to route the message. - User::Leave( KErrDisconnected ); - } - TBuf8<0x250> paramsBuf; // Size needs to be long enough to read all possible parameter sizes. - CBTNotifConnection* connection = FindConnectionFromMessageL( opcode, *message, paramsBuf ); - if( !connection ) - { - User::Leave( KErrDisconnected ); - } - switch( opcode ) - { - case EBTNotifStartSyncNotifier: - case EBTNotifStartAsyncNotifier: - connection->HandleNotifierRequestL( paramsBuf, aMessage ); - break; - case EBTNotifUpdateNotifier: - connection->HandleNotifierUpdateL( paramsBuf, aMessage ); - break; - case EBTNotifCancelNotifier: - // Complete the cancel message already here, so that the caller can - // continue, and the next operation can close sessions with the caller. - aMessage.Complete( KErrNone ); - connection->CancelNotifierRequestL( *message ); - break; - default: - break; - } + iPairingManager->HandlePairingNotifierRequestL(aMessage); BOstraceFunctionExit1( DUMMY_DEVLIST, this ); } - // --------------------------------------------------------------------------- // Handle a request related to pairing. // --------------------------------------------------------------------------- @@ -238,145 +113,10 @@ void CBTNotifConnectionTracker::HandleBondingRequestL( const RMessage2& aMessage ) { BOstraceFunctionEntryExt ( DUMMY_LIST, this, aMessage.Function() ); - // Bonding is an infrequently occurring operation, so we don't waste memory - // to keep a copy of the parameters. Instead we read them again when needed. - TPckgBuf addrBuf; - TInt opcode = aMessage.Function(); - if( opcode == EBTEngPairDevice ) - { - aMessage.ReadL( EBTNotifSrvParamSlot, addrBuf ); - } - else if( opcode == EBTEngCancelPairDevice ) - { - const RMessage2* message = - ( (CBTNotifSession *) aMessage.Session() )->FindMessageFromUid( EBTEngPairDevice ); - message->ReadL( EBTNotifSrvParamSlot, addrBuf ); - } - BtTraceBtAddr1( TRACE_DEBUG, DUMMY_LIST, "CBTNotifConnectionTracker::HandleBondingRequestL() addr=", addrBuf() ); - TInt err = KErrNotFound; - CBTNotifConnection* connection = FindConnectionHandler( addrBuf() ); - if( opcode == EBTEngPairDevice ) - { - if( !connection ) - { - // Create a connection first, then tell it to bond. - err = iPhyLinks->CreateConnection( addrBuf() ); - connection = CBTNotifConnection::NewLC( addrBuf(), this ); - iConnArray.AppendL( connection ); - CleanupStack::Pop( connection ); - } - else - { - // There is an existing connection. Care must be taken, the connection - // _should_ be disconnect first if this device is already paired, so that - // we are sure that we don't mix up the state of the connection. - RBTPhysicalLinkAdapter link; - err = link.Open( iSockServ, addrBuf() ); - TUint32 linkState = 0; - if( !err ) - { - err = link.PhysicalLinkState( linkState ); - } - if( !err && linkState & ( ENotifyAuthenticationComplete | ENotifyEncryptionChangeOn ) ) - { - // For now, we just reject the request. - err = KErrAlreadyExists; - } - link.Close(); - } - if( !err ) - { - // Start bonding immediately so that the connection object is in the right state. - connection->StartBondingL( aMessage ); - } - } - else if( opcode == EBTEngCancelPairDevice && connection ) - { - connection->CancelBondingL(); - err = KErrNone; - aMessage.Complete( err ); - } - // KErrNotFound is returned for a request to cancel pairing that has no connection. - if( err ) - { - aMessage.Complete( err ); - } + iPairingManager->HandleBondingRequestL(aMessage); BOstraceFunctionExit1( DUMMY_DEVLIST, this ); } - -// --------------------------------------------------------------------------- -// Handle a change in the number of connections. -// --------------------------------------------------------------------------- -// -void CBTNotifConnectionTracker::HandleLinkCountChangeL() - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - TInt linkCount = 0; - User::LeaveIfError( iLinkCount.Get( linkCount ) ); - if( linkCount ) - { - RBTDevAddrArray links; - CleanupClosePushL( links ); - User::LeaveIfError( iPhyLinks->Enumerate( links, 10 ) ); - __ASSERT_ALWAYS( links.Count(), PanicServer( EBTNotifPanicBadState ) ); - for( TInt i = iConnArray.Count() -1; i >= 0 ; i-- ) - { - // Loop backwards, as we may remove entries from the array. - - // First check the existing connections, and - // remove disconnected links - TBTDevAddr addr = iConnArray[i]->Address(); - TInt pos = links.Find( addr ); - if( pos > KErrNotFound ) - { - // The link we know is still connected, - // remove the watceher from the array. - links.Remove( pos ); - // ToDo: see comment below! - } - else if( iConnArray[i]->CurrentOperation() == CBTNotifConnection::EIdle ) - { - // This link is no more connected and idle, remove. - CBTNotifConnection* connection = iConnArray[i]; - iConnArray.Remove( i ); // Does not delete the object. - delete connection; - } - // else we wait for the link to complete its operations. - } - // Now we have an array with only the new connections. - // Add new watchers. - for( TInt i = 0; i < links.Count(); i++ ) - { - CBTNotifConnection* connection = CBTNotifConnection::NewLC( links[i], this ); - iConnArray.AppendL( connection ); - CleanupStack::Pop( connection ); - } - // Close the links RBTDevAddrArray, needed before going out of scope. - CleanupStack::PopAndDestroy(); - } - else - { - for( TInt i = iConnArray.Count() -1; i >= 0 ; i-- ) - { - if( iConnArray[i]->CurrentOperation() == CBTNotifConnection::EIdle ) - { - // This link is now idle, so we can remove it safely. - CBTNotifConnection* connection = iConnArray[i]; - iConnArray.Remove( i ); // Does not delete the object. - delete connection; - } - } - if( !iConnArray.Count() ) - { - // The array is idle, clean up the array resources. - iConnArray.Reset(); - } - } - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - // --------------------------------------------------------------------------- // Check if this device has been denied a connection already before. // Also check if a previous connection attempt has just been rejected. @@ -415,276 +155,6 @@ return result; } - -// --------------------------------------------------------------------------- -// From class MBluetoothPhysicalLinksNotifier. -// Handle baseband connection completion. -// --------------------------------------------------------------------------- -// -void CBTNotifConnectionTracker::HandleCreateConnectionCompleteL( TInt aErr ) - { - BOstraceFunctionEntryExt ( DUMMY_LIST, this, aErr ); - // We only connect links for starting outgoing bonding. - const RMessage2* message = iServer->FindMessageFromUid( (TInt) EBTEngPairDevice ); - if( message ) - { - TPckgBuf addrBuf; - message->ReadL( EBTNotifSrvParamSlot, addrBuf ); - CBTNotifConnection* connection = FindConnectionHandler( addrBuf() ); - __ASSERT_ALWAYS( connection, PanicServer( EBTNotifPanicBadState ) ); - if( !aErr && connection->CurrentOperation() == CBTNotifConnection::EIdle ) - { - TRAP( aErr, connection->StartBondingL( *message ) ); - } - if( aErr && connection->CurrentOperation() == CBTNotifConnection::EBonding ) - { - connection->PairingResult( aErr ); // Launch error note - } - } - BOstraceFunctionExit1( DUMMY_DEVLIST, this ); - } - - -// --------------------------------------------------------------------------- -// From class MBluetoothPhysicalLinksNotifier. -// Handle baseband disconnection. -// --------------------------------------------------------------------------- -// -void CBTNotifConnectionTracker::HandleDisconnectCompleteL( TInt aErr ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - // We only disconnect links for starting outgoing bonding. - const RMessage2* message = iServer->FindMessageFromUid( (TInt) EBTEngPairDevice ); - if( message ) - { - TPckgBuf addrBuf; - message->ReadL( EBTNotifSrvParamSlot, addrBuf ); - if( !aErr ) - { - aErr = iPhyLinks->CreateConnection( addrBuf() ); - } - if( aErr ) - { - iServer->CompleteMessage( message->Handle(), aErr, KNullDesC8 ); - CBTNotifConnection* connection = FindConnectionHandler( addrBuf() ); - __ASSERT_ALWAYS( connection, PanicServer( EBTNotifPanicBadState ) ); - connection->PairingResult( aErr ); // Launch error note - } - } - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// From class MBluetoothPhysicalLinksNotifier. -// Handle disconnection of all links. -// --------------------------------------------------------------------------- -// -void CBTNotifConnectionTracker::HandleDisconnectAllCompleteL( TInt aErr ) - { - (void) aErr; - } - - -// --------------------------------------------------------------------------- -// From class MBTEngConnObserver. -// Handle service-level connection completion. -// --------------------------------------------------------------------------- -// -void CBTNotifConnectionTracker::ConnectComplete( TBTDevAddr& aAddr, - TInt aErr, RBTDevAddrArray* aConflicts ) - { - (void) aAddr; - (void) aErr; - (void) aConflicts; - } - - -// --------------------------------------------------------------------------- -// From class MBTEngConnObserver. -// Handle service-level disconnection. -// --------------------------------------------------------------------------- -// -void CBTNotifConnectionTracker::DisconnectComplete( TBTDevAddr& aAddr, TInt aErr ) - { - (void) aAddr; - (void) aErr; - } - - -// --------------------------------------------------------------------------- -// From class MBtSimpleActiveObserver. -// Handle the active object completion. -// --------------------------------------------------------------------------- -// -void CBTNotifConnectionTracker::RequestCompletedL( CBtSimpleActive* aActive, - TInt aStatus ) - { - BOstraceFunctionEntryExt ( DUMMY_LIST, this, aActive->RequestId() ); - BOstraceExt2( TRACE_DEBUG, DUMMY_DEVLIST, - "CBTNotifConnectionTracker::MBAORequestCompletedL() requestid=%d status=%d", - aActive->RequestId(), aStatus); - if( aActive->RequestId() == KLinkCountWatcher ) - { - iLinkCount.Subscribe( aActive->RequestStatus() ); - aActive->GoActive(); - if( !aStatus ) - { - // HandleLinkCountChangeL(); - } - } -// ToDo: remove this when registry notifications API is available!! - else if( aActive->RequestId() == KRegistryWatcher ) - { - // BTRegistry notifies of a change. Check which one. - iRegistryChange.Subscribe( aActive->RequestStatus() ); - aActive->GoActive(); - TInt tableChanged = 0; - if( !aStatus && !iRegistryChange.Get( tableChanged ) && - tableChanged == KRegistryChangeRemoteTable ) - { - // A record for a remote device has changed. Tell all - // connections to update their record. - for( TInt i = 0; i < iConnArray.Count(); i++ ) - { - // Reuse the functionality in the connection - if( iConnArray[i]->CurrentOperation() < CBTNotifConnection::EReadingRegistry ) - { - iConnArray[i]->RequestCompletedL( aActive, aStatus ); - } - } - } - } -// End ToDo - else if( aActive->RequestId() == KSspResultWatcher ) - { - iSspResultSession.SimplePairingResult( iSspResultAddr, iSspResultActive->RequestStatus() ); - iSspResultActive->GoActive(); - CBTNotifConnection* connection = FindConnectionHandler( iSspResultAddr ); - // ToDo: how to handle a result of a link that already disconnected? - if( connection ) - { - connection->PairingResult( aStatus ); - } - } - BOstraceFunctionExit1( DUMMY_DEVLIST, this ); - } - - -// --------------------------------------------------------------------------- -// From class MBtSimpleActiveObserver. -// Cancel and clean up all requests related to the active object. -// --------------------------------------------------------------------------- -// -void CBTNotifConnectionTracker::CancelRequest( TInt aRequestId ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - if( aRequestId == KLinkCountWatcher ) - { - iLinkCount.Cancel(); - } - else if( aRequestId == KSspResultWatcher ) - { - iSspResultSession.CancelSimplePairingResult(); - } - else if ( aRequestId == KRegistryWatcher ) - { - iRegistryChange.Cancel(); - } - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - -// --------------------------------------------------------------------------- -// From class MBtSimpleActiveObserver. -// -// --------------------------------------------------------------------------- -// -void CBTNotifConnectionTracker::HandleError( CBtSimpleActive* aActive, - TInt aError ) - { - (void) aActive; - (void) aError; - } - -// --------------------------------------------------------------------------- -// Parse the details from a client message and find the associated handler. -// --------------------------------------------------------------------------- -// -CBTNotifConnection* CBTNotifConnectionTracker::FindConnectionFromMessageL( - TInt aOpcode, const RMessage2& aMessage, TDes8& aBuffer ) - { - BOstraceFunctionEntry1( DUMMY_DEVLIST, this ); - TInt uid = aMessage.Int0(); - aMessage.ReadL( EBTNotifSrvParamSlot, aBuffer ); - TBTDevAddr addr = ParseAddressL( uid, aBuffer ); - // If this is a - CBTNotifConnection* connection = FindConnectionHandler( addr ); - if( !connection && IsStackSecmanNotifier( uid ) && - ( aOpcode == EBTNotifStartAsyncNotifier || aOpcode == EBTNotifStartSyncNotifier ) ) - { - // A notifier from stack. This happens if e.g. the pairing - // request comes in before the link count changes (like security - // mode 3). Create the handler and queue the request. - // And note that - connection = CBTNotifConnection::NewLC( addr, this ); - iConnArray.AppendL( connection ); - CleanupStack::Pop( connection ); - } - BOstraceFunctionExitExt( DUMMY_DEVLIST, this, connection ); - return connection; - } - - -// --------------------------------------------------------------------------- -// read the address from a client message. -// --------------------------------------------------------------------------- -// -TBTDevAddr CBTNotifConnectionTracker::ParseAddressL( TInt aUid, - const TDesC8& aParamsBuf ) const - { - BOstraceFunctionEntry1( DUMMY_DEVLIST, this ); - TBTDevAddr addr; - if( IsStackSecmanNotifier( aUid ) ) - { - // For all these, the address is the first data member, - // so can be read using the TBTNotifierParams data structure. - TBTNotifierParams params; - TPckgC paramsPckg( params ); - paramsPckg.Set( aParamsBuf ); - addr = paramsPckg().iBDAddr; - } - //else if( ) other notifier types - BOstraceFunctionExitExt( DUMMY_DEVLIST, this, &addr ); - return addr; - } - - -// --------------------------------------------------------------------------- -// Find a specific connection. -// --------------------------------------------------------------------------- -// -CBTNotifConnection* CBTNotifConnectionTracker::FindConnectionHandler( - const TBTDevAddr& aAddr ) const - { - BOstraceFunctionEntry1( DUMMY_DEVLIST, this ); - CBTNotifConnection* conn = NULL; - if( aAddr != TBTDevAddr() ) - { - // This may be replaced by RArray::Find with appropriate key - for( TInt i = 0; i < iConnArray.Count(); i++ ) - { - if( iConnArray[i]->Address() == aAddr ) - { - conn = iConnArray[i]; - break; - } - } - } - BOstraceFunctionExitExt( DUMMY_DEVLIST, this, conn ); - return conn; - } - - // --------------------------------------------------------------------------- // Record and check the time between connection attempts. // --------------------------------------------------------------------------- @@ -719,3 +189,4 @@ BOstraceFunctionExitExt( DUMMY_DEVLIST, this, result ); return result; } + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/src/btnotifdeviceselector.cpp --- a/bluetoothengine/btnotif/btnotifsrv/src/btnotifdeviceselector.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifdeviceselector.cpp Mon May 17 11:06:23 2010 +0300 @@ -45,6 +45,7 @@ // void CBTNotifDeviceSelector::ConstructL() { + iServer.DevRepository().AddObserverL(this); iDiscoverer = CAdvanceDevDiscoverer::NewL( iServer.DevRepository(), *this ); } @@ -67,6 +68,7 @@ // CBTNotifDeviceSelector::~CBTNotifDeviceSelector() { + iServer.DevRepository().RemoveObserver(this); if( iNotification ) { // Clear the notification callback, we cannot receive them anymore. @@ -77,6 +79,7 @@ iDevices.ResetAndDestroy(); iDevices.Close(); delete iDiscoverer; + } // --------------------------------------------------------------------------- @@ -122,9 +125,24 @@ aMessage.Complete( KErrServerBusy ); return; } - PrepareNotificationL(TBluetoothDialogParams::EDeviceSearch, ENoResource); - iDevices.ResetAndDestroy(); - iDiscoverer->DiscoverDeviceL(); + + iLoadDevices = EFalse; + if(iServer.DevRepository().IsInitialized()) + { + iLoadDevices = ETrue; + if(iServer.DevRepository().AllDevices().Count()==0) + { + PrepareNotificationL(TBluetoothDialogParams::EDeviceSearch, ENoResource); + iDevices.ResetAndDestroy(); + iDiscoverer->DiscoverDeviceL(); + } + else + { + iDevices.ResetAndDestroy(); + PrepareNotificationL(TBluetoothDialogParams::EMoreDevice, ENoResource); + LoadUsedDevicesL(); + } + } iMessage = aMessage; break; } @@ -154,7 +172,6 @@ void CBTNotifDeviceSelector::MBRDataReceived( CHbSymbianVariantMap& aData ) { TInt err = KErrCancel; -// const CHbSymbianVariant* value = aData.Get(_L("selectedindex")); if(aData.Keys().MdcaPoint(0).Compare(_L("selectedindex"))==KErrNone) { TInt val = *(static_cast(aData.Get(_L("selectedindex"))->Data())); @@ -167,11 +184,15 @@ if ( val > -1 && val < iDevices.Count() ) { devParams().SetDeviceAddress( iDevices[val]->Addr() ); + devParams().SetDeviceClass(iDevices[val]->Device().DeviceClass()); + devParams().SetDeviceName(iDevices[val]->Alias()); err = iMessage.Write( EBTNotifSrvReplySlot, devParams ); + iNotification->Close(); // Also dequeues the notification from the queue. + iNotification->RemoveObserver(); + iNotification = NULL; } iMessage.Complete( err ); } - iDiscoverer->CancelDiscovery(); } else if(aData.Keys().MdcaPoint(0).Compare(_L("Stop"))==KErrNone) @@ -182,10 +203,18 @@ { iDiscoverer->CancelDiscovery(); iDevices.ResetAndDestroy(); - delete iDiscoverer; - iDiscoverer = NULL; - iDiscoverer = CAdvanceDevDiscoverer::NewL( iServer.DevRepository(), *this ); - iDiscoverer->DiscoverDeviceL(); + TRAP_IGNORE( iDiscoverer->DiscoverDeviceL() ); + + } + else if(aData.Keys().MdcaPoint(0).Compare(_L("MoreDevices"))==KErrNone) + { + iNotification->Close(); // Also dequeues the notification from the queue. + iNotification->RemoveObserver(); + iNotification = NULL; + iDevices.ResetAndDestroy(); + TRAP_IGNORE( { + PrepareNotificationL(TBluetoothDialogParams::EDeviceSearch, ENoResource); + iDiscoverer->DiscoverDeviceL(); } ); } } @@ -232,9 +261,81 @@ void CBTNotifDeviceSelector::HandleDiscoveryCompleted( TInt aErr ) { (void) aErr; - // todo: update dialog + CHbSymbianVariantMap* map = iNotification->Data(); + TBuf<25> keyStr; + + + //TODO compile fail here we need to send the discovery completed text to the dialog + keyStr.Copy(_L("Search Completed")); + CHbSymbianVariant* devEntry( NULL ); + TRAP_IGNORE( devEntry = CHbSymbianVariant::NewL( (TAny*) &(keyStr), + CHbSymbianVariant::EDes ) ); + if ( devEntry ) + { + map->Add( keyStr, devEntry ); + iNotification->Update(); + } + else + { + // todo: Complete client request with error + } } +// From MBtDeviceRepositoryObserver + +void CBTNotifDeviceSelector::RepositoryInitialized() + { + iRepositoryInitialized = ETrue; + TInt err(KErrNone); + if(!iLoadDevices) + { + iLoadDevices = ETrue; + if(iServer.DevRepository().AllDevices().Count()==0) + { + iDevices.ResetAndDestroy(); + TRAP(err, { + PrepareNotificationL(TBluetoothDialogParams::EDeviceSearch, ENoResource); + iDiscoverer->DiscoverDeviceL(); } ); + } + else + { + iDevices.ResetAndDestroy(); + TRAP( err, + {PrepareNotificationL( + TBluetoothDialogParams::EMoreDevice, ENoResource); + LoadUsedDevicesL(); + } ); + } + } + if ( err ) + { + // todo: complete client request + } + } + +void CBTNotifDeviceSelector::DeletedFromRegistry( const TBTDevAddr& aAddr ) + { + (void) aAddr; + } + +void CBTNotifDeviceSelector::AddedToRegistry( const CBtDevExtension& aDev ) + { + (void) aDev; + } + +void CBTNotifDeviceSelector::ChangedInRegistry( const CBtDevExtension& aDev, TUint aSimilarity ) + { + (void) aDev; + (void) aSimilarity; + } + +void CBTNotifDeviceSelector::ServiceConnectionChanged(const CBtDevExtension& aDev, TBool aConnected ) + { + (void) aDev; + (void) aConnected; + } + + // --------------------------------------------------------------------------- // Get and configure a notification. // --------------------------------------------------------------------------- @@ -249,14 +350,31 @@ iNotification->SetObserver( this ); iNotification->SetNotificationType( aType, aResourceId ); - /* - _LIT(KTitleValue, "BT Search"); - TPtrC ptr; - ptr.Set( KTitleValue ); - iNotification->SetData( TBluetoothDialogParams::EDialogTitle, ptr ); - */ - - /*err = */ iServer.NotificationManager()->QueueNotification( iNotification ); - //NOTIF_NOTHANDLED( !err ) + iServer.NotificationManager()->QueueNotificationL( iNotification,CBTNotificationManager::EPriorityHigh ); BOstraceFunctionExit0( DUMMY_DEVLIST ); } + +void CBTNotifDeviceSelector::LoadUsedDevicesL() + { + const RDevExtensionArray& devArray= iServer.DevRepository().AllDevices(); + for(TInt i=0; i< devArray.Count(); i++ ) + { + const TTime& usedTime = devArray[i]->Device().Used(); + TTime monthBack; + monthBack.HomeTime(); + monthBack -= TTimeIntervalDays(30); + if(usedTime >= monthBack) + { + iDevices.AppendL( devArray[i]->CopyL() ); + CHbSymbianVariantMap* map = iNotification->Data(); + TBuf<8> keyStr; + CHbSymbianVariant* devEntry; + + keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 ); + devEntry = CHbSymbianVariant::NewL( (TAny*) &(devArray[i]->Alias()), + CHbSymbianVariant::EDes ); + map->Add( keyStr, devEntry ); + iNotification->Update(); + } + } + } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/src/btnotificationmanager.cpp --- a/bluetoothengine/btnotif/btnotifsrv/src/btnotificationmanager.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotificationmanager.cpp Mon May 17 11:06:23 2010 +0300 @@ -1,23 +1,19 @@ /* -* ============================================================================ -* Name : btnotificationmanager.cpp -* Part of : bluetoothengine / btnotif -* Description : Class for managing user notification and query objects, and for serializing access to the notification server. +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". * -* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* Initial Contributors: +* Nokia Corporation - initial contribution. * -* Initial Contributors: -* Nokia Corporation - initial contribution. +* Contributors: * -* Contributors: -* Nokia Corporation -* ============================================================================ -* Template version: 4.1 +* Description: Class for managing user notification and query objects, +* and for serializing access to the notification server. +* */ #include "btnotificationmanager.h" @@ -44,9 +40,6 @@ // void CBTNotificationManager::ConstructL() { - iAsyncCb = new( ELeave ) CAsyncCallBack( iServer->Priority() ); - TCallBack cb( AsyncCallback, this ); - iAsyncCb->Set( cb ); } @@ -72,9 +65,6 @@ { iNotificationQ.ResetAndDestroy(); iNotificationQ.Close(); - iUnusedQ.ResetAndDestroy(); - iUnusedQ.Close(); - delete iAsyncCb; } @@ -85,16 +75,7 @@ CBluetoothNotification* CBTNotificationManager::GetNotification() { CBluetoothNotification* notification = NULL; - if( iUnusedQ.Count() ) - { - // Re-use the first idle notification. - notification = iUnusedQ[0]; - iUnusedQ.Remove( 0 ); - } - else - { - TRAP_IGNORE( notification = CBluetoothNotification::NewL( this ) ); - } + TRAP_IGNORE( notification = CBluetoothNotification::NewL( this ) ); if( notification ) { if( iNotificationQ.Append( notification ) ) @@ -118,23 +99,13 @@ __ASSERT_ALWAYS( aNotification, PanicServer( EBTNotifPanicBadArgument ) ); TInt pos = iNotificationQ.Find( aNotification ); __ASSERT_ALWAYS( pos > KErrNotFound, PanicServer( EBTNotifPanicMissing ) ); - // ToDo: Cancel outstanding notification! iNotificationQ.Remove( pos ); - TInt err = iUnusedQ.Append( aNotification ); - aNotification->Reset(); // Clean up notification's resources - if( err ) + // Just delete the notification. + delete aNotification; + if(!iNotificationQ.Count() ) { - // Just delete the notification. - delete aNotification; - } - if( !iAsyncCb->IsActive() ) - { - if( !iNotificationQ.Count() ) - { - // Set the priority so that this is the last scheduled active object to execute. - iAsyncCb->SetPriority( CActive::EPriorityIdle ); - } - iAsyncCb->CallBack(); + // the queue is empty, reset it. + iNotificationQ.Compress(); } } @@ -143,30 +114,23 @@ // Queue the notification with given priority // --------------------------------------------------------------------------- // -TInt CBTNotificationManager::QueueNotification( CBluetoothNotification* aNotification, - TNotificationPriority aPriority ) +void CBTNotificationManager::QueueNotificationL( + CBluetoothNotification* aNotification, + TNotificationPriority aPriority ) { + (void) aPriority; TInt pos = iNotificationQ.Find( aNotification ); __ASSERT_ALWAYS( pos > KErrNotFound, PanicServer( EBTNotifPanicMissing ) ); - if( aPriority == EPriorityHigh && pos != 0 ) - { - // ToDo: Move the note to the front of the queue - } - if( !iAsyncCb->IsActive() ) + if( /*aPriority == EPriorityHigh &&*/ pos != 0 ) { - if( iAsyncCb->Priority() != iServer->Priority() ) - { - // Reset priority back to original value - // We first check the current priority, otherwise CActive will do an - // unnecessary removal and adding of the callback from the active scheduler. - iAsyncCb->SetPriority( iServer->Priority() ); - } - iAsyncCb->CallBack(); + CBluetoothNotification* notification = NULL; + notification = iNotificationQ[pos]; + iNotificationQ.Remove( pos ); + iNotificationQ.InsertL(notification,0); } - return KErrNone; + ProcessNotificationQueueL(); } - // --------------------------------------------------------------------------- // Process the notification queue and launch the next notification. // --------------------------------------------------------------------------- @@ -175,28 +139,12 @@ { if( iNotificationQ.Count() ) { - TInt err = iNotificationQ[0]->Show(); - // If the note is already showing, it will return KErrAlreadyExists - (void) err; // ToDo: add error handling!! - NOTIF_NOTHANDLED( !err || err == KErrAlreadyExists || err == KErrNotFound ) + iNotificationQ[0]->ShowL(); } else { - // No outstanding notifications, and unused notifications. - // Clean up the unused notifications. - iUnusedQ.ResetAndDestroy(); - iNotificationQ.Reset(); // the queue is empty, reset it. - // Also clean up any resources. + // No outstanding notifications + iNotificationQ.Compress(); // the queue is empty, reset it. } } - -// --------------------------------------------------------------------------- -// Callback for asynchronous processing of queued notification requests. -// --------------------------------------------------------------------------- -// -TInt CBTNotificationManager::AsyncCallback( TAny* aPtr ) - { - TRAPD( err, ( (CBTNotificationManager*) aPtr )->ProcessNotificationQueueL() ); - return err; - } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/src/btnotifincomingpairinghandler.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifincomingpairinghandler.cpp Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,368 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "btnotifincomingpairinghandler.h" +#include "btnotifpairingmanager.h" +#include "btnotifoutgoingpairinghandler.h" +#include + +const TInt KBTNotifWaitingForPairingOkDelay = 500000; // 0.5s + +enum TPairingStageId + { + /** + * is monitoring physical link status + */ + EPhysicalLinkNotify = 100, + EWaitingForPairingOk, + }; + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor +// --------------------------------------------------------------------------- +// +CBTNotifIncomingPairingHandler::CBTNotifIncomingPairingHandler( CBTNotifPairingManager& aParent, + const TBTDevAddr& aAddr) : CBTNotifBasePairingHandler( aParent, aAddr ) + { + } + +// --------------------------------------------------------------------------- +// 2nd phase constructor +// --------------------------------------------------------------------------- +// +void CBTNotifIncomingPairingHandler::ConstructL() + { + BaseConstructL(); + iActivePairingOk = CBtSimpleActive::NewL(*this, EWaitingForPairingOk ); + User::LeaveIfError( iPairingOkTimer.CreateLocal() ); + } + +// --------------------------------------------------------------------------- +// NewL +// --------------------------------------------------------------------------- +// +CBTNotifBasePairingHandler* CBTNotifIncomingPairingHandler::NewL( CBTNotifPairingManager& aParent, + const TBTDevAddr& aAddr) + { + CBTNotifIncomingPairingHandler* self = new (ELeave) CBTNotifIncomingPairingHandler(aParent, aAddr); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + return self; + } + +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +CBTNotifIncomingPairingHandler::~CBTNotifIncomingPairingHandler() + { + // TRACE_FUNC_ENTRY + // Cancel all outstanding requests + CancelPlaNotification(); + iPla.Close(); + delete iActivePairingOk; + iPairingOkTimer.Close(); + // TRACE_FUNC_EXIT + } + +// --------------------------------------------------------------------------- +// Accept this message only if the specified device is the same as this is +// dealing with. +// --------------------------------------------------------------------------- +// +TInt CBTNotifIncomingPairingHandler::ObserveIncomingPair( const TBTDevAddr& aAddr ) + { + TInt err( KErrServerBusy ); + if ( iAddr == aAddr ) + { + err = KErrNone; + iUserAwarePairing = ETrue; // This function is called by a notifier, which means the UI has been involved + // Therefore we can display it in the paired devices list + if ( !iActive->IsActive() && !OpenPhysicalLinkAdaptor() ) + { + // If we are observing physical link, or showing user a note, + // we won't interrupt it. + UnSetPairResult(); + MonitorPhysicalLink(); + } + } + return err; + } + +// --------------------------------------------------------------------------- +// Assign the responsibility of outgoing pair handling to CBTEngOtgPair +// --------------------------------------------------------------------------- +// +void CBTNotifIncomingPairingHandler::HandleOutgoingPairL( const TBTDevAddr& aAddr, TUint aCod ) + { + // TRACE_FUNC_ENTRY + // Outgoing pairing always takes highest priority: + CBTNotifBasePairingHandler* pairinghandler = CBTNotifOutgoingPairingHandler::NewL( iParent, aAddr ); + pairinghandler->HandleOutgoingPairL( aAddr, aCod ); + iParent.RenewPairingHandler( pairinghandler ); + // TRACE_FUNC_EXIT + } + +// --------------------------------------------------------------------------- +// Accept this message only if the specified device is the same as this is +// dealing with. +// --------------------------------------------------------------------------- +// +void CBTNotifIncomingPairingHandler::StopPairHandling( const TBTDevAddr& aAddr ) + { + if ( aAddr == iAddr ) + { + // TRACE_FUNC_ENTRY + iParent.RenewPairingHandler( NULL ); + // TRACE_FUNC_EXIT + } + } + +// --------------------------------------------------------------------------- +// Notify user if pairing failed. +// --------------------------------------------------------------------------- +// +void CBTNotifIncomingPairingHandler::DoHandlePairServerResult( TInt aResult ) + { + CancelPlaNotification(); + // For a successful pairing, we need wait for registry table change. + if( aResult != KErrNone && aResult != KHCIErrorBase ) + { + // Pair failure situation. + SetPairResult( aResult ); + // todo: show pairing failure note. + } + } + +// --------------------------------------------------------------------------- +// Kill this if the linkkey type indicates OBEX authentication. +// Otherwise notify user the pair result. +// --------------------------------------------------------------------------- +// +void CBTNotifIncomingPairingHandler::DoHandleRegistryNewPairedEvent( const TBTNamelessDevice& aDev ) + { + // TRACE_FUNC_ENTRY + + // First of all cancel the iPairingOkTimer timer, if active + if (iActivePairingOk->IsActive()) + { + iActivePairingOk->Cancel(); + UnSetPairResult(); // we might have set it before (if the link went down) so we want to reset it. + } + if (aDev.LinkKeyType() == ELinkKeyUnauthenticatedNonUpgradable && !iUserAwarePairing) + { + // If an application uses btengconnman API to connect a service of + // this device and JW pairing occurred as part of security enforcement, + // it shall be a user aware pairing, and we shall add this device in paired + // view. In this way, user is able to disconnect the device from our UI. + // Otherwise the link key has been created by a device without IO requesting + // a service connection with phone. We won't take any action (e.g. remove + // link key) in this case. As the result, this device can't be seen in our UI, + // however other applications are still freely to use its services. + // TRACE_INFO(_L("[BTEng]: CBTEngIncPair: JW pairing with no IO device" ) ) + TBTEngConnectionStatus status = iParent.ConnectStatus( aDev.Address() ); + if ( status == EBTEngConnecting || status == EBTEngConnected ) + { + // the return error is ingore as we can not have other proper + // exception handling option: + (void) iParent.AddUiCookieJustWorksPaired( aDev ); + } + iParent.RenewPairingHandler( NULL ); + } + else if (aDev.LinkKeyType() == ELinkKeyUnauthenticatedUpgradable && !iUserAwarePairing) + { + // The linkkey has been created by an incoming OBEX service request + // which resulted a pairing event received from pair server. + // TRACE_INFO(_L("[BTEng]: CBTEngIncPair: JW pairing with IO device" ) ) + iParent.RenewPairingHandler( NULL ); + } + else + { + if (aDev.LinkKeyType() == ELinkKeyUnauthenticatedNonUpgradable || aDev.LinkKeyType() == ELinkKeyUnauthenticatedUpgradable) + { + // The user was involved in the pairing, so display in the paired devices list + (void) iParent.AddUiCookieJustWorksPaired(aDev); + } + // TRACE_INFO(_L("[BTEng]: CBTEngIncPair: Non-JW pairing")) + // Other pairing model than Just Works: + CancelPlaNotification(); + SetPairResult( KErrNone ); + iParent.RenewPairingHandler( NULL ); + } + // TRACE_FUNC_EXIT + } + +// --------------------------------------------------------------------------- +// From class MBTNotifPairingAOObserver. +// --------------------------------------------------------------------------- +// +void CBTNotifIncomingPairingHandler::RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ) + { + // TRACE_FUNC_ARG( ( _L( "aId: %d, aStatus: %d"), aId, aStatus ) ) + // Check which request completed. + switch( aActive->RequestId() ) + { + case EPhysicalLinkNotify: + { + // Check if the link has disconnected. + HandlePhysicalLinkResultL( aStatus ); + break; + } + case EWaitingForPairingOk: + { + // pairing failed, inform user: + if (iPairResult == KErrNone) + { + // iPairResult must have been set as an error. if it's not it means somewhere else + // it has been reset. But we need to have it set to an error as we are notifying + // the "unable to pair" message. + SetPairResult(KErrGeneral); + } + iParent.RenewPairingHandler( NULL ); + break; + } + default: + // Should not be possible, but no need for handling. + break; + } + // TRACE_FUNC_EXIT + } + + +// --------------------------------------------------------------------------- +// From class MBTEngActiveObserver. +// cancels an outstanding request according to the given id. +// --------------------------------------------------------------------------- +// +void CBTNotifIncomingPairingHandler::CancelRequest( TInt aRequestId ) + { + switch ( aRequestId ) + { + case EPhysicalLinkNotify: + { + iPla.CancelNextBasebandChangeEventNotifier(); + } + case EWaitingForPairingOk: + { + iPairingOkTimer.Cancel(); + } + } + } + +// --------------------------------------------------------------------------- +// From class MBTNotifPairingAOObserver. +// Handles a leave in RequestCompleted by simply self-destructing. +// --------------------------------------------------------------------------- +// +void CBTNotifIncomingPairingHandler::HandleError( CBtSimpleActive* aActive, TInt aError ) + { + // TRACE_FUNC_ARG( ( _L( "request id: %d, error: %d" ), aId, aError ) ) + (void) aActive; + (void) aError; + // Our error handling is to just stop observing. + // Nothing critical to be preserved here, the user + // just won't get any notification of pairing result. + iParent.RenewPairingHandler( NULL ); + } + +// --------------------------------------------------------------------------- +// Subscribe to physical link notifications. +// physical link must exist when calling this function. +// --------------------------------------------------------------------------- +// +void CBTNotifIncomingPairingHandler::MonitorPhysicalLink() + { + // TRACE_FUNC_ENTRY + iActive->SetRequestId( EPhysicalLinkNotify ); + // Subscribe to disconnect and error events. + iPla.NotifyNextBasebandChangeEvent( iBbEvent, + iActive->RequestStatus(), + ENotifyPhysicalLinkDown | ENotifyPhysicalLinkError ); + iActive->GoActive(); + // TRACE_FUNC_EXIT + } + +// --------------------------------------------------------------------------- +// Opens the adaptor if physical link exists. +// --------------------------------------------------------------------------- +// +TInt CBTNotifIncomingPairingHandler::OpenPhysicalLinkAdaptor() + { + // TRACE_FUNC_ENTRY + TInt err ( KErrNone ); + if( !iPla.IsOpen() ) + { + // Try to open the adapter in case it failed earlier. + // This can happen for outgoing dedicated bonding with + // non-SSP device, as the PIN dialog can be kept open even + // though the link has dropped because of a time-out. + err = iPla.Open( iParent.SocketServ(), iAddr ); + } + // TRACE_INFO( (_L("[BTEng]: CBTEngIncPair::HasPhysicalLink ? %d"), iPla.IsOpen() ) ) + return err; + } + +// --------------------------------------------------------------------------- +// Cancel outstanding physical link notification +// --------------------------------------------------------------------------- +// +void CBTNotifIncomingPairingHandler::CancelPlaNotification() + { + // TRACE_FUNC_ENTRY + if( iActive && iActive->RequestId() == EPhysicalLinkNotify ) + { + // cancel Baseband monitor + iActive->Cancel(); + } + // TRACE_FUNC_EXIT + } + +// --------------------------------------------------------------------------- +// Handle a physical link event. Notify pair failed if physical link is down. +// --------------------------------------------------------------------------- +// +void CBTNotifIncomingPairingHandler::HandlePhysicalLinkResultL( TInt aResult ) + { + // TRACE_FUNC_ARG( ( _L( " BBEvent 0x%08X, code %d"), + // iBbEvent().EventType(), iBbEvent().SymbianErrorCode() ) ) + // Check if the connection is still alive. + TBool physicalLinkDown = + ( iBbEvent().EventType() == ENotifyPhysicalLinkDown | ENotifyPhysicalLinkError ); + + if( aResult || physicalLinkDown ) + { + // link went down. It might be because of pairing failed or the remote device disconnected the + // physical link after a successful pairing. + // we wait for 0.5 secs before notifying the "unable to pair" message as, if the pair is + // successful, we manage it to show the right confirmation message. + SetPairResult( (aResult == 0) ? KErrGeneral : aResult ); + iPairingOkTimer.After(iActivePairingOk->iStatus, KBTNotifWaitingForPairingOkDelay); + iActivePairingOk->GoActive(); + } + else + { + // Uninteresting event, re-subscribe. + MonitorPhysicalLink(); + } + // TRACE_FUNC_EXIT + } + + + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/src/btnotifoutgoingpairinghandler.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifoutgoingpairinghandler.cpp Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,381 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Pairing handler for local device initiated pairing +* +*/ + +#include "btnotifoutgoingpairinghandler.h" +#include +#include +#include "btnotifpairingmanager.h" + +/** Length of the default PIN. */ +const TInt KDefaultHeadsetPinLength = 4; + +enum TPairingStageId + { + /** + * no pairing operation ongoing + */ + ENoBonding = 0, + + /** + * pair with dedicated bonding method + */ + EDedicatedBonding = 200, + + /** + * pair with general bonding by establishing L2CAP connection. + */ + EGeneralBonding, + + /** + * delaying next pairing request for a while + */ + EGeneralBondingRetryTimer, + + /** + * The last pairing retry + */ + EGeneralBondingRetry, + + /** + * disconnecting physical link after pairing operation. + * + * todo: not used yet. + */ + EDisconnectLinkAfterBonding, + }; + +/** SDP PSM (used for pairing) */ +const TInt KSDPPSM = 0x0001; + +// Delay time to void Repeated Attempts on pairing +const TInt KGeneralBondingRetryDelayMicroSeconds = 5000000; // 5.0s + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor +// --------------------------------------------------------------------------- +// +CBTNotifOutgoingPairingHandler::CBTNotifOutgoingPairingHandler( CBTNotifPairingManager& aParent, const TBTDevAddr& aAddr) + : CBTNotifBasePairingHandler( aParent, aAddr ) + { + } + +// --------------------------------------------------------------------------- +// Symbian 2nd-phase constructor +// --------------------------------------------------------------------------- +// +void CBTNotifOutgoingPairingHandler::ConstructL() + { + BaseConstructL(); + User::LeaveIfError( iTimer.CreateLocal() ); + } + +// --------------------------------------------------------------------------- +// NewL +// --------------------------------------------------------------------------- +// +CBTNotifBasePairingHandler* CBTNotifOutgoingPairingHandler::NewL( CBTNotifPairingManager& aParent, + const TBTDevAddr& aAddr ) + { + CBTNotifOutgoingPairingHandler* self = new( ELeave ) CBTNotifOutgoingPairingHandler( aParent, aAddr ); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + return self; + } + +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +CBTNotifOutgoingPairingHandler::~CBTNotifOutgoingPairingHandler() + { + if ( iActive ) + { + iActive->Cancel(); + } + iBondingSession.Close(); + iSocket.Close(); + iTimer.Close(); + } + +// --------------------------------------------------------------------------- +// Simply deny the request as this is handing outgoing pairing +// --------------------------------------------------------------------------- +// +TInt CBTNotifOutgoingPairingHandler::ObserveIncomingPair( const TBTDevAddr& /*aAddr*/ ) + { + return KErrServerBusy; + } + +// --------------------------------------------------------------------------- +// Accept the request only this device is not busy with another pairing request. +// --------------------------------------------------------------------------- +// +void CBTNotifOutgoingPairingHandler::HandleOutgoingPairL( const TBTDevAddr& aAddr, TUint aCod ) + { + // TRACE_FUNC_ARG( ( _L(" cod 0x%08x"), aCod ) ) + if ( iActive->IsActive() || aAddr != iAddr ) + { + // we don't allow another pairing request. + User::Leave( KErrServerBusy ); + } + + iAddr = aAddr; + iCod = TBTDeviceClass( aCod ); + UnSetPairResult(); + iParent.UnpairDevice( iAddr ); + if ( CBtDevExtension::IsHeadset( iCod ) ) + { + // If the devie is a headset, set to 0000 pin auto pairing + iPairMode = EBTOutgoingHeadsetAutoPairing; + } + else + { + iPairMode = EBTOutgoingNoneHeadsetPairing; + } + // SetOutgoPairProperty( iOutgoProperty, iAddr, iPairMode ); + DoPairingL(); + } + +// --------------------------------------------------------------------------- +// Cancels an outstanding pair request by self-destruct +// --------------------------------------------------------------------------- +// +void CBTNotifOutgoingPairingHandler::CancelOutgoingPair() + { + iParent.RenewPairingHandler( NULL ); + } + + +// --------------------------------------------------------------------------- +// when phone initiated a pairing request towards a headset, +// Pin code 0000 is first tried. +// --------------------------------------------------------------------------- +// +void CBTNotifOutgoingPairingHandler::GetPinCode( + TBTPinCode& aPin, const TBTDevAddr& aAddr, TInt aMinPinLength ) + { + aPin().iLength = 0; + if ( aMinPinLength <= KDefaultHeadsetPinLength + && aAddr == iAddr + && iPairMode == EBTOutgoingHeadsetAutoPairing) + { + // if the pairing requires a stronger security level (indicated + // by aMinPinLength), + // 0000 will not be supplied as it does not mmet the security + // requirements + const TUint8 KZeroPinValue = '0'; + for (TInt i = 0; i < KDefaultHeadsetPinLength; ++i) + { + aPin().iPIN[i] = KZeroPinValue; + } + aPin().iLength = KDefaultHeadsetPinLength; + } + } + +// --------------------------------------------------------------------------- +// Abort pairing handling, request the owner to destroy this. +// --------------------------------------------------------------------------- +// +void CBTNotifOutgoingPairingHandler::StopPairHandling( const TBTDevAddr& aAddr ) + { + if ( aAddr == iAddr ) + { + iParent.OutgoingPairCompleted( KErrCancel ); + iParent.RenewPairingHandler( NULL ); + } + } + +// --------------------------------------------------------------------------- +// Pairing result will be received when pairing operation completes. +// --------------------------------------------------------------------------- +// +void CBTNotifOutgoingPairingHandler::DoHandlePairServerResult( TInt aResult ) + { + if (aResult == (KHCIErrorBase-EPairingNotAllowed)) + { + // if EPairingNotAllowed is recieved then any further pairing attempts will fail + // so don't attampt to pair + iPairMode = EBTOutgoingPairNone; + } + } + +// --------------------------------------------------------------------------- +// Cancels possible outstanding pairing and notify user pair success. +// --------------------------------------------------------------------------- +// +void CBTNotifOutgoingPairingHandler::DoHandleRegistryNewPairedEvent( + const TBTNamelessDevice& aDev ) + { + TInt err( KErrNone ); + // If pairing was performed using Just Works mode, we set a + // UICookie to indicate that the device is successfully + // bonded so that this device will be listed in paired device view of + // bluetooth application: + if ( aDev.LinkKeyType() == ELinkKeyUnauthenticatedNonUpgradable ) + { + // TRACE_INFO( ( _L( "[BTENG] CBTEngOtgPair, Just Works pairing" ) ) ); + err = iParent.AddUiCookieJustWorksPaired( aDev ); + } + iActive->Cancel(); + SetPairResult( err ? err : KErrNone ); + iParent.OutgoingPairCompleted( err ); + iParent.RenewPairingHandler( NULL ); + } + +// --------------------------------------------------------------------------- +// From class MBTNotifPairingAOObserver. +// Based on the result code, decides the next operation, either try pairing +// with another mode, or complete pair request. +// --------------------------------------------------------------------------- +// +void CBTNotifOutgoingPairingHandler::RequestCompletedL( + CBtSimpleActive* aActive, TInt aStatus ) + { + // TRACE_FUNC_ARG( ( _L( "reqid %d, status: %d, pair mode %d " ), aId, aStatus, iPairMode ) ) + if( aActive->RequestId() == EDedicatedBonding && + ( aStatus == KErrRemoteDeviceIndicatedNoBonding || + ( aStatus && iPairMode != EBTOutgoingNoneHeadsetPairing && iPairMode != EBTOutgoingPairNone ) ) ) + { + // try general pairing if the remote doesn't have dedicated bonding, or + // pairing fails with a headset. + DoPairingL(); + } + else if ( aStatus && iPairMode == EBTOutgoingHeadsetAutoPairing ) + { + iPairMode = EBTOutgoingHeadsetManualPairing; + // auto pairing with headset failed, try to pair again with manual pin: + // ( void ) SetOutgoPairProperty( iOutgoProperty, iAddr, iPairMode ); + // TRACE_INFO( _L( " auto pairing failed, switch to manual pairing") ); + DoPairingL(); + } + else if ( aStatus && aActive->RequestId() == EGeneralBonding && + iPairMode == EBTOutgoingHeadsetManualPairing ) + { + // pairing headset with manual pin failed, wait for a while and try again: + iActive->SetRequestId( EGeneralBondingRetryTimer ); + iTimer.After( iActive->iStatus, KGeneralBondingRetryDelayMicroSeconds ); + iActive->GoActive(); + } + else if( aActive->RequestId() == EGeneralBondingRetryTimer ) + { + // try to pair headset again with manual pin again: + DoPairingL(); + } + else if ( aStatus ) + { + // we only starts showing note if pairing failed. + // For a successful pair, we must wait until registry has been updated. + if ( !IsPairResultSet() ) + { + SetPairResult( aStatus ); + } + if ( aStatus ) + { + // todo: show error note? + iParent.OutgoingPairCompleted( aStatus ); + } + } + } + +// --------------------------------------------------------------------------- +// From class MBTEngActiveObserver. +// cancels an outstanding request according to the given id. +// --------------------------------------------------------------------------- +// +void CBTNotifOutgoingPairingHandler::CancelRequest( TInt aRequestId ) + { + switch ( aRequestId ) + { + case EDedicatedBonding: + { + iBondingSession.Close(); + } + case EGeneralBonding: + case EGeneralBondingRetry: + { + iSocket.CancelConnect(); + iSocket.Close(); + } + case EGeneralBondingRetryTimer: + { + iTimer.Cancel(); + } + } + } + +// --------------------------------------------------------------------------- +// From class MBTEngActiveObserver. +// Handles a leave in RequestCompleted by self-destructing. +// --------------------------------------------------------------------------- +// +void CBTNotifOutgoingPairingHandler::HandleError( + CBtSimpleActive* aActive, TInt aError ) + { + // TRACE_FUNC_ARG( ( _L( "error: %d" ), aError ) ) + // Our RunL can actually not leave, so we should never reach here. + (void) aActive; + iParent.OutgoingPairCompleted( aError ); + iParent.RenewPairingHandler( NULL ); + } + +// --------------------------------------------------------------------------- +// decide the next state and issue pair request +// --------------------------------------------------------------------------- +// +void CBTNotifOutgoingPairingHandler::DoPairingL() + { + // TRACE_FUNC_ENTRY + TPairingStageId currentMode = ( TPairingStageId ) iActive->RequestId(); + ASSERT( !iActive->IsActive() ); + TPairingStageId nextMode( EGeneralBonding ); + + // if running BTv2.0 stack, dedicated bonding method + // is not available. + if ( currentMode == ENoBonding && iParent.PairingServer() != NULL ) + { + nextMode = EDedicatedBonding; + } + else if(currentMode == EGeneralBondingRetryTimer) + { + nextMode = EGeneralBondingRetry; + } + + // TRACE_INFO( ( _L( "[BTENG] CBTEngOtgPair::DoPairingL: bonding mode: pre %d, next %d"), currentMode, nextMode ) ); + + iActive->SetRequestId( nextMode ); + if ( nextMode == EDedicatedBonding ) + { + iBondingSession.Start( *iParent.PairingServer(), iAddr, iActive->RequestStatus() ); + } + else + { + TBTServiceSecurity sec; + sec.SetAuthentication( ETrue ); + iSockAddr.SetBTAddr( iAddr ); + iSockAddr.SetPort(KSDPPSM); + iSockAddr.SetSecurity( sec ); + iSocket.Close(); + User::LeaveIfError( iSocket.Open( iParent.SocketServ(), KL2CAPDesC ) ); + iSocket.Connect( iSockAddr, iActive->RequestStatus() ); + } + iActive->GoActive(); + // TRACE_FUNC_EXIT + } + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/src/btnotifpairinghelper.cpp --- a/bluetoothengine/btnotif/btnotifsrv/src/btnotifpairinghelper.cpp Wed May 05 09:56:48 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,958 +0,0 @@ -/* -* ============================================================================ -* Name : btnotifpairinghelper.cpp -* Part of : bluetoothengine / btnotif -* Description : Helper class for processing pairing requests and results, as extended functionality for CBTNotifConnection. -* -* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* Nokia Corporation -* ============================================================================ -* Template version: 4.1 -*/ - -#include "btnotifpairinghelper.h" -#include -#include -#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS -#include -#endif - -#include "btnotifconnection.h" -#include "btnotifconnectiontracker.h" -#include "btnotificationmanager.h" -#include "btnotifserver.h" -#include "bluetoothtrace.h" - -/** Id for the active object for a dedicated bonding session. */ -const TInt KDedicatedBonding = 50; -/** Length of the default PIN. */ -const TInt KDefaultPinLength = 4; -/** Default PIN character. */ -const TText8 KDefaultPinValue = '0'; -/** Format syntax for numeric comparison value. */ -_LIT( KNumCompFormat, "%06u" ); -/** Format syntax for passkey display value. */ -_LIT( KPassKeyFormat, "%06u" ); - - -// ======== LOCAL FUNCTIONS ======== - -// --------------------------------------------------------------------------- -// ?description -// --------------------------------------------------------------------------- -// -/*?type ?function_name( ?arg_type ?arg, - ?arg_type ?arg ) - { - } -*/ - -// ======== MEMBER FUNCTIONS ======== - -// --------------------------------------------------------------------------- -// C++ default constructor. -// --------------------------------------------------------------------------- -// -CBTNotifPairingHelper::CBTNotifPairingHelper( CBTNotifConnection* aConnection, - CBTNotifConnectionTracker* aTracker ) -: iConnection( aConnection ), - iTracker( aTracker ) - { - } - - -// --------------------------------------------------------------------------- -// Symbian 2nd-phase constructor. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::ConstructL() - { - if( iConnection ) - { - iDevice = iConnection->BTDevice(); - } - } - - -// --------------------------------------------------------------------------- -// NewL -// --------------------------------------------------------------------------- -// -CBTNotifPairingHelper* CBTNotifPairingHelper::NewL( CBTNotifConnection* aConnection, - CBTNotifConnectionTracker* aTracker ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - CBTNotifPairingHelper* self = new( ELeave ) CBTNotifPairingHelper( aConnection, aTracker ); - CleanupStack::PushL( self ); - self->ConstructL(); - CleanupStack::Pop( self ); - BOstraceFunctionExit0( DUMMY_DEVLIST ); - return self; - } - - -// --------------------------------------------------------------------------- -// Destructor. -// --------------------------------------------------------------------------- -// -CBTNotifPairingHelper::~CBTNotifPairingHelper() - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - if( iNotification ) - { - // Clear the notification callback, we cannot receive them anymore. - iNotification->RemoveObserver(); - iNotification->Close(); // Also dequeues the notification from the queue. - iNotification = NULL; - } - delete iParams; - if( iBondingActive ) - { - iBondingActive->Cancel(); // Will close subsession; - } - delete iBondingActive; - iBondingSession.Close(); - iBondingSocket.Close(); - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// Handle the authentication result from the baseband. Show the result in a note. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::HandleAuthenticationCompleteL( TInt aError ) - { - BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); - if( iOperation == EDedicatedBonding || iOperation == EAwaitingPairingResult || - iOperation == EAutoPairing ) - { - // Default case (aError == 0): Success, we are now paired. - TBTDialogResourceId resourceId = EPairingSuccess; - TBool autoPairing = ( iOperation == EAutoPairing ); // Remember the autopairing state - iOperation = EShowPairingSuccess; - if( aError && aError != KHCIErrorBase ) - { - // Authentication failure, means pairing failed. - resourceId = EPairingFailure; - iOperation = EShowPairingFailure; - // Communicate the error now that we still remember it. - if( iDedicatedBonding ) - { - if( autoPairing && aError == KHCIErrorBase - EAuthenticationFailure ) - { - BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, - "[BTNOTIF]\t CBTNotifPairingHelper::HandleAuthenticationCompleteL: Autopairing failed, we need to try again."); - // Autopairing failed, we need to try again. - iOperation = EAutoPairing; // Reset back - resourceId = ENoResource; - } - CompleteBondingL( aError ); - } - } - if( resourceId ) - { - // Inform the user of the result. - BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, - "[BTNOTIF]\t CBTNotifPairingHelper::HandleAuthenticationCompleteL: pairing successful, inform user" ); - PrepareNotificationL( TBluetoothDialogParams::EGlobalNotif, resourceId ); - // MBRNotificationClosed will be called from this, which will - // check the next stage. - } - } - BOstraceFunctionExit1( DUMMY_DEVLIST, this ); - } - - -// --------------------------------------------------------------------------- -// Start a bonding operation with the remote device. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::StartBondingL( TInt aHandle ) - { - BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aHandle ); - __ASSERT_ALWAYS( iOperation == EIdle || iOperation == EDedicatedBonding - || iOperation == EAutoPairing, PanicServer( EBTNotifPanicBadState ) ); - if( !iBondingActive ) - { - iBondingActive = CBtSimpleActive::NewL( *this, KDedicatedBonding ); - } - if( aHandle ) - { - iDedicatedBonding = aHandle; - } - if( iOperation == EIdle ) - { - iOperation = EDedicatedBonding; - } - if( iOperation == EDedicatedBonding && iTracker->PairingServerSession() ) - { - if( !iBondingActive->IsActive() ) - { - BtTraceBtAddr1( TRACE_DEBUG,DUMMY_LIST,"CBTNotifPairingHelper::StartBondingL()",iDevice->BDAddr() ); - iBondingSession.Start( *iTracker->PairingServerSession(), - iDevice->BDAddr(), iBondingActive->RequestStatus() ); - iBondingActive->GoActive(); - } - } - else - { - // We are doing autopairing (or the unlikely situation that the pairing server is unavailable) - CompleteBondingL( KErrServerTerminated ); - } - BOstraceFunctionExit1( DUMMY_DEVLIST, this); - } - - -// --------------------------------------------------------------------------- -// Cancel an ongoing bonding operation with the remote device. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::CancelBondingL() - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - if( iDedicatedBonding ) - { - CompleteBondingL( KErrCancel ); // Closes sessions - if( iNotification ) - { - // Cancel the outstanding user query - // This will also unregister us from the notification. - TInt err = iNotification->Close(); - NOTIF_NOTHANDLED( !err ) - iNotification = NULL; - } - if( iNotifierUid ) - { - // Also finish up the notifier processing. - CompletePairingNotifierL( KErrCancel, EFalse, KNullDesC8 ); - } - iOperation = EIdle; - iConnection->PairingCompleted(); // This may delete us. - } - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// Handle a notifier request for pairing with the remote device of this connection. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::StartPairingNotifierL( TInt aUid, const TDesC8& aParams ) - { - BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aUid ); - if( iDevice->GlobalSecurity().Banned() && !iDedicatedBonding ) - { - // ToDo: should this case actually be ignored, and presume that - // the caller will take care of unblocking the device? - iOperation = EIdle; - User::Leave( KErrAccessDenied ); - } - // Store the parameters locally, we need them later again. - delete iParams; - iParams = NULL; - iParams = HBufC8::NewL( aParams.Length() ); - *iParams = aParams; - iNotifierUid = aUid; - - if( iDevice->IsValidPaired() && iDevice->IsPaired() ) - { - // The device is still paired, we unpair it first. - // Deleting the link key will set the device as unpaired. - iDevice->DeleteLinkKey(); - iOperation = EUnpairing; // So that parent state does not get changed. - iConnection->UpdateRegistryEntryL(); - // Note that this will only be done before trying autopairing, so - // it not interfere with a second attempt; - } - // Update the device name - TBTPasskeyDisplayParams params; // Enough for reading the base class type parameter - TPckgC paramsPckg( params ); - paramsPckg.Set( *iParams ); - if( paramsPckg().DeviceName().Length() ) - { - // The name in the parameter package is the latest one, retrieved from - // the remote device during this connection. Update locally. - iDevice->SetDeviceNameL( BTDeviceNameConverter::ToUTF8L( paramsPckg().DeviceName() ) ); - } - - TBool locallyInitiated = EFalse; - TBuf<8> numVal; - TBluetoothDialogParams::TBTDialogType dialog = TBluetoothDialogParams::EInvalidDialog; - TBTDialogResourceId resource = ENoResource; - // Read the notifier parameters (sets iOperation as well) - ParseNotifierReqParamsL( locallyInitiated, numVal, dialog, resource ); - // If this is an incoming pairing, we first ask the user to accept it. - if( !locallyInitiated && !iDedicatedBonding ) - { - // Ignore the initatior if we initiated bonding. - StartAcceptPairingQueryL(); // Overrides iOperation - } - else - { - __ASSERT_ALWAYS( resource != ENoResource, PanicServer( EBTNotifPanicBadState ) ); - CheckAutoPairingL( locallyInitiated, numVal ); - // CheckAutoPairingL sets - if( iOperation != EAutoPairing ) - { - PrepareNotificationL( dialog, resource ); - if( numVal.Length() ) - { - TInt err = iNotification->SetData( TBluetoothDeviceDialog::EAdditionalDesc, numVal ); - NOTIF_NOTHANDLED( !err ) - } - } - } - BOstraceFunctionExit1( DUMMY_DEVLIST, this ); - } - - -// --------------------------------------------------------------------------- -// Update a notifier, update the outstanding dialog if the notifier request -// is currently being served. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::UpdatePairingNotifierL( TInt aUid, const TDesC8& aParams ) - { - (void) aUid; - TBTNotifierUpdateParams2 params; // Enough for reading the base class type parameter - TPckgC paramsPckg( params ); - paramsPckg.Set( aParams ); - if( paramsPckg().Type() == TBTNotifierUpdateParams2::EPasskeyDisplay ) - { - // Paskey display update - keypress on remote device. - } - else - { - // name update - TBTDeviceNameUpdateParams nameUpdate; - TPckgC nameUpdatePckg( nameUpdate ); - nameUpdatePckg.Set( aParams ); - // The result means result of conversion to unicode - if( !nameUpdatePckg().Result() ) - { - // Only update locally, registry will update us with the same info later on. - iDevice->SetDeviceNameL( BTDeviceNameConverter::ToUTF8L( nameUpdatePckg().DeviceName() ) ); - if( iNotification ) - { - // Update the dialog with the new name. It is up to the dialog to - // determine the validity (in case another dialog is shown). - //iNotification->Update( ) - } - } - } - } - - -// --------------------------------------------------------------------------- -// Cancel a request, dismiss the outstanding dialog if the notifier request -// is currently being served. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::CancelPairingNotifierL( TInt aUid ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - // ToDo: we need to check that the UID and the outstanding notification - // type are matching? - if( iOperation > EIdle && iOperation < EPostPairingOperations && aUid == iNotifierUid && - ( aUid == KBTPinCodeEntryNotifierUid.iUid || - aUid == KBTNumericComparisonNotifierUid.iUid || - aUid == KBTPasskeyDisplayNotifierUid.iUid ) ) - { - if( iNotification ) - { - // Cancel the user query - // This will also unregister us from the notification. - TInt err = iNotification->Close(); - NOTIF_NOTHANDLED( !err ) - iNotification = NULL; - } - iOperation = EIdle; - iNotifierUid = 0; - // We do not call pairing completed from here, our parent will - // check our status by itself, and may delete us. - - // Any bonding requester needs to be informed though. - CancelBondingL(); - } - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::StartJustWorksProcessingL() - { - } - - -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::CancelJustWorksProcessingL() - { - } - - -// --------------------------------------------------------------------------- -// From class MBTNotificationResult. -// Handle a result from a user query. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::MBRDataReceived( CHbSymbianVariantMap& aData ) - { - (void) aData; - NOTIF_NOTIMPL - } - - -// --------------------------------------------------------------------------- -// From class MBTNotificationResult. -// The notification is finished. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::MBRNotificationClosed( TInt aError, const TDesC8& aData ) - { - BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); - // First unregister from the notification, so we can already get the next one. - iNotification->RemoveObserver(); - iNotification = NULL; - TRAP_IGNORE( NotificationClosedL( aError, aData ) ); - if( iOperation == EIdle ) - { - // Any error has been communicated already. - iConnection->PairingCompleted(); // This may delete us. - } - BOstraceFunctionExit1( DUMMY_DEVLIST, this ); - } - - -// --------------------------------------------------------------------------- -// From class MBtSimpleActiveObserver. -// Handle the active object completion. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::RequestCompletedL( CBtSimpleActive* aActive, - TInt aStatus ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - switch( aActive->RequestId() ) - { - case KDedicatedBonding: - { - if( iDedicatedBonding ) - { - // If the result hasn't been processed already. - HandleAuthenticationCompleteL( aStatus ); - } - } - break; - default: - NOTIF_NOTIMPL - break; - } - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// From class MBtSimpleActiveObserver. -// Cancel and clean up all requests related to the active object. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::CancelRequest( TInt aRequestId ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - switch( aRequestId ) - { - case KDedicatedBonding: - iBondingSession.Close(); - break; - default: - NOTIF_NOTIMPL - break; - } - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - -// --------------------------------------------------------------------------- -// From class MBtSimpleActiveObserver. -// -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::HandleError( CBtSimpleActive* aActive, - TInt aError ) - { - (void) aActive; - (void) aError; - } - -// --------------------------------------------------------------------------- -// Process the user input and complete the outstanding pairing request. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::CompletePairingNotifierL( TInt aError, TBool aResult, - const TDesC8& aData ) - { - BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); - TInt err = aError; - TPtrC8 resultData; - if( !err ) - { - // The returned data is the entered passkey. - TBool proceed = iTracker->UpdateBlockingHistoryL( iDevice, aResult ); - if( iOperation == ESspPairing && iNotifierUid == KBTNumericComparisonNotifierUid.iUid ) - { - // Numeric comparison needs the boolean result passed back. - TPckgBuf userAcceptance( aResult ); - resultData.Set( userAcceptance ); - } - if( aResult ) - { - if( iOperation == ELegacyPairing || iOperation == EAutoPairing ) - { - // Check the passkey entered by the user. - // The length of the returned data equals the number of characters - // entered by the user. - TBTPinCode pinCode; - pinCode().iLength = aData.Length(); - TUint minLen = 0; - TBool locallyInitiated = EFalse; // Not used here. - ParsePinCodeReqParamsL( locallyInitiated, minLen ); - if( aData.Length() >= minLen ) - { - // Check that the length of the passkey meets the minimum - // required pin code length - for( TInt i = 0; i < aData.Length(); i++ ) - { - pinCode().iPIN[i] = aData[i]; - } - resultData.Set( pinCode ); - } - else - { - // PIN wasn't long enough. This should be handled by the dialog though. - err = KErrCompletion; - } - } - // Now we just wait for the result to come in. - if( iOperation != EAutoPairing ) - { - iOperation = EAwaitingPairingResult; - } - } - else - { - err = KErrCancel; - TBool locallyInitiated = EFalse; // Needed below - TBuf<8> numVal; // Not needed here. - TBluetoothDialogParams::TBTDialogType type = TBluetoothDialogParams::EInvalidDialog; - TBTDialogResourceId resource = ENoResource; // Resources and type are not needed here. - // Check the notifier parameters - ParseNotifierReqParamsL( locallyInitiated, numVal, type, resource ); - if( proceed && locallyInitiated && !iDedicatedBonding ) - { - // The user denied the connection, ask to block the device. - // This is only for pairing (and not bonding) initiated by us, - // as the user already gets the opportunity to block when - // rejecting an incoming pairing request. - // This case may be for someone requesting to access a service - // which requires authentication by us, but not by the remote device. - iConnection->LaunchBlockingQueryL(); - // For incoming pairing, blocking is asked after rejecting the - // pairing request. This is done in CompleteAcceptPairingQueryL - } - CompleteBondingL( err ); // Notify the client if there was a bonding request. - } - } - iNotifierUid = 0; // Clean up notifier data - delete iParams; - iParams = NULL; - if( err ) - { - iOperation = EIdle; // We are done now. - } - // Complete the message with the result, and result data if any. - iConnection->CompleteClientRequest( err, resultData ); - BOstraceFunctionExit1( DUMMY_DEVLIST, this ); - } - - -// --------------------------------------------------------------------------- -// Completes a bonding operation. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::CompleteBondingL( TInt aError ) - { - BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); - if( iDedicatedBonding ) - { - if( iBondingActive ) - { - iBondingActive->Cancel(); // Will close subsession; - } - iBondingSession.Close(); // In case not active - iBondingSocket.Close(); - } - // Determine if we try another time. - if( ( iOperation == EAutoPairing && aError == KHCIErrorBase - EAuthenticationFailure ) || - ( iDedicatedBonding && iOperation == EAwaitingPairingResult && - aError == KErrRemoteDeviceIndicatedNoBonding ) || - aError == KErrServerTerminated ) - { - // The cases are: 2) autopairing with a headset that has a non-default passkey - // 2) SSP dedicated bonding with a device that does not allow that. - // 3) the pairing server is unavailable (unlikely) - // Then we try another time, requesting authentication on a - // RBTPhysicialLinkAdapter - BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, - "[BTNOTIF]\t CBTNotifPairingHelper::CompleteBondingL: trying another time." ); - TInt err = iBondingSocket.Open( iTracker->SocketServerSession(), iConnection->Address() ); - TUint32 linkState = 0; - if( !err ) - { - err = iBondingSocket.PhysicalLinkState( linkState ); - } - if( !err && linkState & ENotifyPhysicalLinkUp ) - { - err = iBondingSocket.Authenticate(); - // Now wait for the dialog and then the link state notification - } - else - { - // We need to wait for the link to come up. We wait until our - // parent calls us again. - iBondingSocket.Close(); - } - if( err ) - { - // Cannot continue, show the result to the user. - BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, - "[BTNOTIF]\t CBTNotifPairingHelper::HandleAuthenticationCompleteL: pairing failed, complete message." ); - iOperation = EShowPairingFailure; - PrepareNotificationL( TBluetoothDialogParams::ENote, EPairingFailure ); - } - } - if( iDedicatedBonding && iOperation != EAutoPairing ) - { - BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, - "[BTNOTIF]\t CBTNotifPairingHelper::CompleteBondingL: complete message." ); - TInt err = iTracker->Server()->CompleteMessage( iDedicatedBonding, aError, KNullDesC8 ); - NOTIF_NOTHANDLED( !err ) - iDedicatedBonding = 0; - } - BOstraceFunctionExit1( DUMMY_DEVLIST, this ); - } - - -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::CompleteJustWorksProcessingL( TInt aError ) - { - (void) aError; - } - - -// --------------------------------------------------------------------------- -// Ask the user to allow incoming pairing. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::StartAcceptPairingQueryL() - { - iOperation = EAcceptPairing; - PrepareNotificationL( TBluetoothDialogParams::EQuery, EIncomingPairing ); - // if rejected, the client message is completed in CompleteAcceptPairingQueryL - } - - -// --------------------------------------------------------------------------- -// The user was asked to accept an incoming pairing. Process and proceed. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::CompleteAcceptPairingQueryL( TInt aError, TBool aResult ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - // Set our state to idle for now. This may get changed if the user just chose - // to block, or if we have a pending request. - iOperation = EIdle; - TInt err = aError; - if( !err ) - { - TBool proceed = iTracker->UpdateBlockingHistoryL( iDevice, aResult ); - if( aResult ) - { - // User accepted, continue to show pairing query. - // Minimum lenght does not apply, should only be set on outgoing pairing - TBool locallyInitiated = EFalse; - TBuf<8> numVal; - TBluetoothDialogParams::TBTDialogType dialog = TBluetoothDialogParams::EInvalidDialog; - TBTDialogResourceId resource = ENoResource; - // Read the notifier parameters - ParseNotifierReqParamsL( locallyInitiated, numVal, dialog, resource ); - __ASSERT_ALWAYS( resource != ENoResource, PanicServer( EBTNotifPanicBadState ) ); - PrepareNotificationL( dialog, resource ); - if( numVal.Length() ) - { - TInt err = iNotification->SetData( TBluetoothDeviceDialog::EAdditionalDesc, numVal ); - NOTIF_NOTHANDLED( !err ) - } - } - else - { - err = KErrCancel; - if( proceed ) - { - // The user denied the connection, ask to block the device. - iConnection->LaunchBlockingQueryL(); - } - } - } - if( err ) - { - // The user denied the connection, or something else prevented completion. - CompletePairingNotifierL( err, EFalse, KNullDesC8 ); - } - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// Launch a dialog for setting the device as trusted. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::StartTrustedQueryL() - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - // Assume that the registry update has come through by now. - iOperation = EQueryTrust; - PrepareNotificationL( TBluetoothDialogParams::EQuery, ESetTrusted ); - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// Process the user input for setting the device as trusted. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::CompleteTrustedQueryL( TInt aError, TBool aResult ) - { - BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); - BOstraceExt2( TRACE_DEBUG, DUMMY_DEVLIST, - "CBTNotifPairingHelper::CompleteTrustedQueryL() err=%d result=%d", aError, aResult ); - iOperation = EIdle; // We are done with pairing now. - if( !aError && aResult ) - { - // need to update pairing info from registry before writing trusted status - iConnection->UpdateRegistryEntryL(true); - } - CompleteBondingL( KErrNone ); // Notify the client if there was a bonding request. - BOstraceFunctionExit1( DUMMY_DEVLIST, this ); - } - - -// --------------------------------------------------------------------------- -// Parse the parameters of a request for pairing. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::ParseNotifierReqParamsL( TBool& aLocallyInitiated, - TDes& aNumVal, TBluetoothDialogParams::TBTDialogType& aDialogType, - TBTDialogResourceId& aResourceId ) - { - // Determine the notifier type by the length of the parameter buffer - if( iNotifierUid == KBTPinCodeEntryNotifierUid.iUid ) - { - aNumVal.Zero(); - TUint minLen = 0; - ParsePinCodeReqParamsL( aLocallyInitiated, minLen ); - if( minLen ) - { - // Don't set zero to this buffer, the buffer length serves for this. - aNumVal.Num( minLen ); - } - aDialogType = TBluetoothDialogParams::EInput; - aResourceId = EPinInput; - if( iOperation != EAutoPairing ) - { - iOperation = ELegacyPairing; - } - } - else if( iNotifierUid == KBTNumericComparisonNotifierUid.iUid ) - { - ParseNumericCompReqParamsL( aLocallyInitiated, aNumVal ); - aDialogType = TBluetoothDialogParams::EQuery; - aResourceId = ENumericComparison; - iOperation = ESspPairing; - } - else if( iNotifierUid == KBTPasskeyDisplayNotifierUid.iUid ) - { - ParsePasskeyDisplayReqParamsL( aLocallyInitiated, aNumVal ); - aDialogType = TBluetoothDialogParams::EQuery; - aResourceId = EPasskeyDisplay; - iOperation = ESspPairing; - } - } - - -// --------------------------------------------------------------------------- -// Parse the parameters of a request for pairing using pin query. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::ParsePinCodeReqParamsL( TBool& aLocallyInitiated, - TUint& aNumVal ) - { - TBTPinCodeEntryNotifierParams params; - TPckgC paramsPckg( params ); - paramsPckg.Set( *iParams ); - aLocallyInitiated = paramsPckg().LocallyInitiated(); - aNumVal = paramsPckg().PinCodeMinLength(); - } - - -// --------------------------------------------------------------------------- -// Parse the parameters of a request for pairing using numeric comparison. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::ParseNumericCompReqParamsL( TBool& aLocallyInitiated, - TDes& aNumVal ) - { - TBTNumericComparisonParams params; - TPckgC paramsPckg( params ); - paramsPckg.Set( *iParams ); - aLocallyInitiated = paramsPckg().LocallyInitiated(); - TBTNumericComparisonParams::TComparisonScenario scenario = - paramsPckg().ComparisonScenario(); - aNumVal.Format( KNumCompFormat, paramsPckg().NumericalValue() ); - } - - -// --------------------------------------------------------------------------- -// Parse the parameters of a request for pairing using passkey display. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::ParsePasskeyDisplayReqParamsL( TBool& aLocallyInitiated, - TDes& aNumVal ) - { - TBTPasskeyDisplayParams params; - TPckgC paramsPckg( params ); - paramsPckg.Set( *iParams ); - aLocallyInitiated = paramsPckg().LocallyInitiated(); - aNumVal.Format( KPassKeyFormat, paramsPckg().NumericalValue() ); - } - - -// --------------------------------------------------------------------------- -// Check if we can guess the PIN and complete the notifier without user interaction. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::CheckAutoPairingL( TBool aLocallyInitiated, const TDesC& aNumVal ) - { - TUint minLen = 0; - if( aNumVal.Length() ) - { - ParsePinCodeReqParamsL( aLocallyInitiated, minLen ); - } - // ToDo: Add support for NFC OOB pairing - if( iDedicatedBonding && iOperation == ELegacyPairing && - iDevice->DeviceClass().MajorDeviceClass() == EMajorDeviceAV && - iDevice->DeviceClass().MinorDeviceClass() != EMinorDeviceAVHandsfree && - minLen <= KDefaultPinLength ) - { - // Outgoing bonding with headset and no passkey requirement => AutomatedPairing - // Complete message with 0000 and return. - iOperation = EAutoPairing; - TBuf8 )> defaultPin( KDefaultPinLength ); - for( TInt i = 0; i < KDefaultPinLength; i++ ) - { - defaultPin[i] = KDefaultPinValue; - } - // Complete the pairing through the function dedicated to that. - CompletePairingNotifierL( KErrNone, ETrue, defaultPin ); - } - else if( iOperation == EAutoPairing ) - { - iOperation = ELegacyPairing; // Reset the autopairing status - } - } - - -// --------------------------------------------------------------------------- -// Get and configure a notification. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType, - TBTDialogResourceId aResourceId ) - { - BOstraceFunctionEntry0( DUMMY_DEVLIST ); - __ASSERT_ALWAYS( iOperation != EIdle || aType == TBluetoothDialogParams::ENote, PanicServer( EBTNotifPanicBadState ) ); - iNotification = iTracker->NotificationManager()->GetNotification(); - User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory - iNotification->SetObserver( this ); - iNotification->SetNotificationType( aType, aResourceId ); - TBTDeviceName name; - GetDeviceNameL( name, *iDevice ); - TInt err = iNotification->SetData( TBluetoothDeviceDialog::EDeviceName, name ); - NOTIF_NOTHANDLED( !err ) - // Re-use name buffer for 16-bit descriptor representation of remote address. - iConnection->Address().GetReadable( name ); - err = iNotification->SetData( TBluetoothDialogParams::EAddress, name ); - NOTIF_NOTHANDLED( !err ) - err = iNotification->SetData( (TInt) TBluetoothDeviceDialog::EDeviceClass, - iDevice->DeviceClass().DeviceClass() ); - err = iTracker->NotificationManager()->QueueNotification( iNotification ); - NOTIF_NOTHANDLED( !err ) - BOstraceFunctionExit0( DUMMY_DEVLIST ); - } - - -// --------------------------------------------------------------------------- -// The notification is finished, handle the result. -// --------------------------------------------------------------------------- -// -void CBTNotifPairingHelper::NotificationClosedL( TInt aError, const TDesC8& aData ) - { - BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); - // Read the result. - TPckgC result( EFalse ); - result.Set( aData.Ptr(), result.Length() ); // Read the part containing the result - // Set a pointer descriptor to capture the remaining data, if any. - TPtrC8 dataPtr( aData.Mid( result.Length() ) ); - switch( iOperation ) - { - case EAcceptPairing: - CompleteAcceptPairingQueryL( aError, result() ); - break; - case ELegacyPairing: - case ESspPairing: - CompletePairingNotifierL( aError, result(), dataPtr ); - break; - case EQueryTrust: - CompleteTrustedQueryL( aError, result() ); - break; - case EShowPairingSuccess: - StartTrustedQueryL(); - break; - case EShowPairingFailure: - // Pairing failure, we are done. - iOperation = EIdle; - break; - default: - NOTIF_NOTIMPL - break; - } - BOstraceFunctionExit1( DUMMY_DEVLIST, this ); - } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/src/btnotifpairingmanager.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifpairingmanager.cpp Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,809 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "btnotifpairingmanager.h" +#include "btnotifoutgoingpairinghandler.h" +#include "btnotifincomingpairinghandler.h" +#include "btnotifpairnotifier.h" +#include "btnotifclientserver.h" +#include +#include "btnotifconnectiontracker.h" + +/** Identification for active object */ +enum TPairManActiveRequestId + { + ESimplePairingResult, + EAuthenticationResult, + ERegistryGetLocalAddress, + }; + +// --------------------------------------------------------------------------- +// Tells if two TBTNamelessDevice instances are for the same remote device +// --------------------------------------------------------------------------- +// +TBool CompareDeviceByAddress( const TBTNamelessDevice& aDevA, const TBTNamelessDevice& aDevB ) + { + return aDevA.Address() == aDevB.Address(); + } + +// --------------------------------------------------------------------------- +// Tells if these two instances are for the same remote device +// --------------------------------------------------------------------------- +// +TBool MatchDeviceAddress(const TBTDevAddr* aAddr, const TBTNamelessDevice& aDev) + { + return *aAddr == aDev.Address(); + } + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor +// --------------------------------------------------------------------------- +// +CBTNotifPairingManager::CBTNotifPairingManager( + CBTNotifConnectionTracker& aParent, + CBtDevRepository& aDevRepository) + : iParent( aParent ), iDevRepository( aDevRepository ) + { + } + +// --------------------------------------------------------------------------- +// Symbian 2nd-phase constructor +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::ConstructL() + { + // Connect to pairing server for authentication & simple pairing + // results directly from the BT stack. + // Pairing server doesn't exist if we run BT 2.0 stack: + iPairingServ = new (ELeave) RBluetoothPairingServer; + TInt err = iPairingServ->Connect(); + if ( err) + { + delete iPairingServ; + iPairingServ = NULL; + } + else + { + User::LeaveIfError( iPairingResult.Open( *iPairingServ ) ); + User::LeaveIfError( iAuthenResult.Open( *iPairingServ ) ); + iSSPResultActive = CBtSimpleActive::NewL( *this, ESimplePairingResult ); + iAuthenResultActive = CBtSimpleActive::NewL( *this, EAuthenticationResult ); + SubscribeSspPairingResult(); + SubscribeAuthenticateResult(); + } + User::LeaveIfError( iRegistry.Open( iParent.RegistryServerSession() ) ); + // RProperty for accessing the local device address + User::LeaveIfError( iPropertyLocalAddr.Attach( + KPropertyUidBluetoothCategory, KPropertyKeyBluetoothGetLocalDeviceAddress) ); + // Initialise paired devices list + iLocalAddrActive = CBtSimpleActive::NewL( *this, ERegistryGetLocalAddress ); + SubscribeLocalAddress(); + iPairNotifier = CBTNotifPairNotifier::NewL( *this ); + iDevRepository.AddObserverL( this ); + } + +// --------------------------------------------------------------------------- +// NewL +// --------------------------------------------------------------------------- +// +CBTNotifPairingManager* CBTNotifPairingManager::NewL( + CBTNotifConnectionTracker& aParent, + CBtDevRepository& aDevRepository ) + { + CBTNotifPairingManager* self = NULL; + self = new CBTNotifPairingManager( aParent, aDevRepository ); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + return self; + } + +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +CBTNotifPairingManager::~CBTNotifPairingManager() + { + delete iSSPResultActive; + delete iAuthenResultActive; + delete iPairNotifier; + delete iPairingHandler; + iPairedDevices.Close(); + iPairingResult.Close(); + iAuthenResult.Close(); + if ( iPairingServ ) + { + iPairingServ->Close(); + delete iPairingServ; + } + iRegistry.Close(); + delete iLocalAddrActive; + iPropertyLocalAddr.Close(); + if ( !iMessage.IsNull() ) + { + iMessage.Complete( KErrCancel ); + } + } + +// --------------------------------------------------------------------------- +// Initialises the paired devices list. +// If the local address is not available from the P&S key +// KPropertyKeyBluetoothGetLocalDeviceAddress, then the list may need to be +// updated once the H/W is switched on. This is so that any registry update +// from a restore operation can be included in the list, without mistaking the +// new devices for new pairings. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::SubscribeLocalAddress() + { + // Check that we have the Bluetooth local address. If we don't then initialise anyway, but subscribe for an update. + // This allows us to refresh our paired devices list to include updates made to the remote devices table of the + // Bluetooth registry from a restore operation. We need to include these devices without mistaking them for new + // pairings. We look solely at the P&S key for the address to avoid the condition whereby the address has been + // entered into the reigstry but the Bluetooth Manager server has not begun the restore process yet. The signalling + // of the P&S key will cause Bluetooth Manager to update the registry with any restored devices before fulfilling + // any further requests. + + // Subscribe to local address property in case we need an update. + iPropertyLocalAddr.Subscribe( iLocalAddrActive->iStatus ); + iLocalAddrActive->SetRequestId( ERegistryGetLocalAddress ); + iLocalAddrActive->GoActive(); + } + +// --------------------------------------------------------------------------- +// Tells whether the local address is available from the P&S key +// KPropertyKeyBluetoothGetLocalDeviceAddress. +// --------------------------------------------------------------------------- +// +TBool CBTNotifPairingManager::IsLocalAddressAvailable() + { + // Attempt to read address from P&S key. + TBuf8 btAddrDes; + TInt err = iPropertyLocalAddr.Get( btAddrDes ); + + // Is the P&S key defined yet? (if not, stack not up yet) + if ( err == KErrNone ) + { + // P&S key defined, is local address set? (if not, H/W not initialised yet) + if ( btAddrDes.Length() == KBTDevAddrSize ) + { + TBTDevAddr btAddr = btAddrDes; + if ( btAddr != TBTDevAddr() ) + { + return ETrue; + } + } + } + return EFalse; + } + +// --------------------------------------------------------------------------- +// Handles pairing related requests from BTNotif clients. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::HandleBondingRequestL( const RMessage2& aMessage ) + { + TInt opcode = aMessage.Function(); + TBTDevAddrPckgBuf addrPkg; + switch( opcode ) + { + case EBTNotifPairDevice: + { + if ( !iMessage.IsNull() ) + { + User::Leave( KErrServerBusy ); + } + TBTDevAddrPckgBuf addrPkg; + aMessage.ReadL( EBTNotifSrvParamSlot, addrPkg ); + UnpairDevice( addrPkg() ); + PairDeviceL( addrPkg(), aMessage.Int2() ); + iMessage = RMessage2( aMessage ); + break; + } + case EBTNotifCancelPairDevice: + { + // Only the client who requested pairing can cancel it: + if ( !iMessage.IsNull() && aMessage.Session() == iMessage.Session() ) + { + iPairingHandler->CancelOutgoingPair(); + iMessage.Complete( KErrCancel ); + } + aMessage.Complete( KErrNone ); + break; + } + default: + { + User::Leave( KErrArgument ); + } + } + } + +// --------------------------------------------------------------------------- +// Process a client message related to notifiers. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::HandlePairingNotifierRequestL( const RMessage2& aMessage ) + { + iPairNotifier->StartPairingNotifierL( aMessage ); + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + +// --------------------------------------------------------------------------- +// Returns the RBluetoothPairingServer instance. +// --------------------------------------------------------------------------- +// +RBluetoothPairingServer* CBTNotifPairingManager::PairingServer() + { + return iPairingServ; + } + +// --------------------------------------------------------------------------- +// Access the reference of RSockServ +// --------------------------------------------------------------------------- +// +RSocketServ& CBTNotifPairingManager::SocketServ() + { + return iParent.SocketServerSession(); + } + +// --------------------------------------------------------------------------- +// Access the reference of RBTRegSrv +// --------------------------------------------------------------------------- +// +CBtDevRepository& CBTNotifPairingManager::BTDevRepository() + { + return iDevRepository; + } + +// --------------------------------------------------------------------------- +// Access the reference of CBTNotifConnectionTracker +// --------------------------------------------------------------------------- +// +CBTNotifConnectionTracker& CBTNotifPairingManager::ConnectionTracker() + { + return iParent; + } + +// --------------------------------------------------------------------------- +// Deletes the current pairing handler and transfer the responsibility +// to the specified. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::RenewPairingHandler( + CBTNotifBasePairingHandler* aPairingHandler ) + { + delete iPairingHandler; + iPairingHandler = aPairingHandler; + } + +// --------------------------------------------------------------------------- +// Find the session who requested this and completes its request. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::OutgoingPairCompleted( TInt aErr ) + { + // the meaning of KHCIErrorBase equals KErrNone. Hide this specific BT stack + // detail from clients: + if ( !iMessage.IsNull() ) + { + iMessage.Complete( (aErr == KHCIErrorBase) ? KErrNone : aErr ); + } + } + +// --------------------------------------------------------------------------- +// A session will be ended, completes the pending request for this session. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::SessionClosed( CSession2* aSession ) + { + // TRACE_FUNC_ARG( ( _L( " session %x"), aSession ) ) + if ( !iMessage.IsNull() && iMessage.Session() == aSession ) + { + iMessage.Complete( KErrCancel ); + } + } + +// --------------------------------------------------------------------------- +// Unpair the device from registry +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::UnpairDevice( const TBTDevAddr& aAddr ) + { + TIdentityRelation addrComp( CompareDeviceByAddress ); + TBTNamelessDevice dev; + dev.SetAddress( aAddr ); + // only do unpairing if the we have a link key with it. + TInt index = iPairedDevices.Find( dev, addrComp ); + if ( index > KErrNotFound ) + { + dev = iPairedDevices[index]; + TRequestStatus status( KRequestPending ); + // Unpair the device in registry (synchronously) + iRegistry.UnpairDevice( dev.Address(), status ); + User::WaitForRequest( status ); + // TRACE_INFO( ( _L( "Delete link key, res %d"), status.Int() ) ) + if ( status == KErrNone ) + { + TBTDeviceSecurity security = dev.GlobalSecurity(); + // Clear trust setting so that correct icon will be shown in ui applications. + security.SetNoAuthenticate(EFalse ); + security.SetNoAuthorise(EFalse ); + dev.SetGlobalSecurity(security); + dev.DeleteLinkKey(); + if ( dev.IsValidUiCookie() && + ( dev.UiCookie() & EBTUiCookieJustWorksPaired ) ) + { + // Remove the UI cookie bit for Just Works pairing. + TInt32 cookie = dev.UiCookie() & ~EBTUiCookieJustWorksPaired; + dev.SetUiCookie( cookie ); + // TRACE_INFO( ( _L( "UI cookie %x cleared"), EBTUiCookieJustWorksPaired ) ); + } + // modify the device in registry synchronously + // status.Int() could be -1 if the device is not in registry + // which is totally fine for us. + (void) UpdateRegDevice( dev ); + } + } + } + +TInt CBTNotifPairingManager::AddUiCookieJustWorksPaired( const TBTNamelessDevice& aDev ) + { + TInt err( KErrNone ); + // There might be UI cookies used by other applications, + // we should not overwrite them. + TInt32 cookie = aDev.IsValidUiCookie() ? aDev.UiCookie() : EBTUiCookieUndefined; + if ( !( cookie & EBTUiCookieJustWorksPaired ) ) + { + // Only update the cookie if the wanted one is not in registry yet + // to keep minimal operations with registry. + TBTNamelessDevice dev = aDev; + cookie |= EBTUiCookieJustWorksPaired; + dev.SetUiCookie( cookie ); + err = UpdateRegDevice( dev ); + // TRACE_INFO( ( _L( "[BTENG] CBTEngOtgPair write Ui cookie ret %d"), err ) ); + } + return err; + } + +// --------------------------------------------------------------------------- +// update a nameless device in registry +// --------------------------------------------------------------------------- +// +TInt CBTNotifPairingManager::UpdateRegDevice( const TBTNamelessDevice& aDev ) + { + TRequestStatus status( KRequestPending ); + // update the device in registry synchronously + iRegistry.ModifyDevice( aDev, status ); + User::WaitForRequest( status ); + // TRACE_INFO( ( _L( "UpdateRegDevice, ret %d"), status.Int() ) ) + return status.Int(); + } + +// --------------------------------------------------------------------------- +// 0000 for outgoing pairing with a headset. +// The placeholder for future extension (pin code passed in for pairing) +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::GetPinCode( + TBTPinCode& aPin, const TBTDevAddr& aAddr, TInt aMinPinLength ) + { + if ( iPairingHandler ) + { + iPairingHandler->GetPinCode( aPin, aAddr, aMinPinLength ); + } + else + { + // make sure not to leave any text as PIN. + aPin.Zero(); + } + } + +// --------------------------------------------------------------------------- +// Ask server class the connection status of the specified device +// --------------------------------------------------------------------------- +// +TBTEngConnectionStatus CBTNotifPairingManager::ConnectStatus( const TBTDevAddr& aAddr ) + { + const CBtDevExtension* devExt = iDevRepository.Device(aAddr); + TBTEngConnectionStatus status = EBTEngNotConnected; + if ( devExt ) + { + status = devExt->ServiceConnectionStatus(); + } + return status; + } + +// --------------------------------------------------------------------------- +// From class MBTNotifPairingAOObserver. +// Checks if there is an authentication result. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ) + { + // TRACE_FUNC_ARG( ( _L( "aId: %d, aStatus: %d"), aId, aStatus ) ) + // Check which request is completed. + switch( aActive->RequestId() ) + { + case ESimplePairingResult: + { + TBTDevAddr tmpAddr = iSimplePairingRemote; + if (aStatus != KErrServerTerminated) + { + SubscribeSspPairingResult(); + } + HandlePairingResultL( tmpAddr, aStatus ); + break; + } + case EAuthenticationResult: + { + TBTDevAddr tmpAddr = iAuthenticateRemote; + if (aStatus != KErrServerTerminated) + { + SubscribeAuthenticateResult(); + } + HandlePairingResultL( tmpAddr, aStatus ); + break; + } + case ERegistryGetLocalAddress: + { + TBool value = IsLocalAddressAvailable(); + SubscribeLocalAddress(); + if ( value ) + { + // Refresh paired devices list to include any restored devices. + iDevRepository.ReInitialize(); + } + break; + } + default: + // Should not be possible, but no need for handling. + break; + } + } + +// --------------------------------------------------------------------------- +// From class MBTEngActiveObserver. +// cancels an outstanding request according to the given id. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::CancelRequest( TInt aRequestId ) + { + switch ( aRequestId ) + { + case ESimplePairingResult: + { + // Cancel listening Simple pairing result + iPairingResult.CancelSimplePairingResult(); + break; + } + case EAuthenticationResult: + { + // Cancel listening authentication result + iAuthenResult.CancelAuthenticationResult(); + break; + } + case ERegistryGetLocalAddress: + { + // cancel listening local address status change + iPropertyLocalAddr.Cancel(); + break; + } + } + } + +// --------------------------------------------------------------------------- +// From class MBtSimpleActiveObserver. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::HandleError( CBtSimpleActive* aActive, TInt aError ) + { + // TRACE_FUNC_ARG( ( _L( "request id: %d, error: %d" ), aId, aError ) ) + (void) aActive; + (void) aError; + } + +// --------------------------------------------------------------------------- +// From class MBtDevRepositoryObserver. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::RepositoryInitialized() + { + TRAPD(err, UpdatePairedDeviceListL() ); + if ( !err && iPairingHandler ) + { + // non-null pairing handler means we are involved in a + // pairing operation already. + // todo: is some handling for above case needed? + } + } + +// --------------------------------------------------------------------------- +// From class MBtDevRepositoryObserver. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::DeletedFromRegistry( const TBTDevAddr& aAddr ) + { + // We are only interested in the removal of a paired device. + // thus check whether it is in our local paired list: + TInt i = iPairedDevices.Find( aAddr, MatchDeviceAddress); + if ( i > KErrNotFound ) + { + iPairedDevices.Remove( i ); + } + } + +// --------------------------------------------------------------------------- +// From class MBtDevRepositoryObserver. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::AddedToRegistry( const CBtDevExtension& aDevice ) + { + // We are only interested in paired device. + if ( CBtDevExtension::IsBonded( aDevice.Device().AsNamelessDevice() ) ) + { + TRAP_IGNORE( + HandleRegistryBondingL( aDevice.Device().AsNamelessDevice() ) ); + } + } + + +// --------------------------------------------------------------------------- +// From class MBtDevRepositoryObserver. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::ChangedInRegistry( + const CBtDevExtension& aDevice, TUint aSimilarity ) + { + // We are only interested in paired device. + // thus check whether it is in our local paired list: + TInt i = iPairedDevices.Find( aDevice.Addr(), MatchDeviceAddress); + TBool bonded = CBtDevExtension::IsBonded( aDevice.Device().AsNamelessDevice() ); + if ( i == KErrNotFound ) + { + if ( bonded ) + { + TRAP_IGNORE( + HandleRegistryBondingL( + aDevice.Device().AsNamelessDevice() ) ); + } + return; + } + // Device was inregistry before, but we need to evaluate its bonding + // status. + // The given similarity will tell if the linkkey and paired is changed + // or not. + TInt pairingProperty = TBTNamelessDevice::EIsPaired + | TBTNamelessDevice::ELinkKey; + if ( ( pairingProperty & aSimilarity) == pairingProperty ) + { + // no pairing or linkkey change. Nothing to do for pairing handling. + // but we'd better update local copy just in case other data + // of this device is needed by someone: + iPairedDevices[i] = aDevice.Device().AsNamelessDevice(); + return; + } + if ( !CBtDevExtension::IsBonded( aDevice.Device().AsNamelessDevice() ) ) + { + // device is not user-bonded. + iPairedDevices.Remove( i ); + return; + } + // it is a new paired device if its link-key has been upgraded + if ( aDevice.Device().LinkKeyType() != ELinkKeyUnauthenticatedUpgradable ) + { + iPairedDevices.Remove( i ); + TRAP_IGNORE( + HandleRegistryBondingL( + aDevice.Device().AsNamelessDevice() ) ); + } + } + +// --------------------------------------------------------------------------- +// From class MBtDevRepositoryObserver. +// This class is not interested in such events. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::ServiceConnectionChanged( + const CBtDevExtension& aDevice, TBool aConnected ) + { + (void) aDevice; + (void) aConnected; + } + +// --------------------------------------------------------------------------- +// Activate or deactivate a pairing handler +// --------------------------------------------------------------------------- +// +TInt CBTNotifPairingManager::SetPairObserver(const TBTDevAddr& aAddr, TBool aActivate) + { + // TRACE_FUNC_ARG( ( _L( "%d" ), aActivate ) ) + // TRACE_BDADDR( aAddr ) + TInt err( KErrNone ); + if ( !aActivate ) + { + if ( iPairingHandler ) + { + iPairingHandler->StopPairHandling( aAddr ); + } + return err; + } + + if ( !iPairingHandler) + { + // This is an incoming pair, unpair it from registry and + // create the handler: + UnpairDevice( aAddr ); + TRAP( err, iPairingHandler = CBTNotifIncomingPairingHandler::NewL( *this, aAddr )); + } + if ( iPairingHandler) + { + // let the handler decide what to do: + err = iPairingHandler->ObserveIncomingPair( aAddr ); + } + return err; + } + +// --------------------------------------------------------------------------- +// Delegates the request to current pair handler +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::PairDeviceL( const TBTDevAddr& aAddr, TUint32 aCod ) + { + if ( !iPairingHandler) + { + // no existing pair handling, create one: + iPairingHandler = CBTNotifOutgoingPairingHandler::NewL( *this, aAddr ); + } + // let pair handler decide what to do: + iPairingHandler->HandleOutgoingPairL( aAddr, aCod ); + } + +// --------------------------------------------------------------------------- +// cancel Subscribings to simple pairing result and authentication result from +// Pairing Server +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::CancelSubscribePairingAuthenticate() + { + if( iSSPResultActive ) + { + // Cancel listening Simple pairing result + iSSPResultActive->Cancel(); + } + if( iAuthenResultActive ) + { + iAuthenResultActive->Cancel(); + } + } + +// --------------------------------------------------------------------------- +// Subscribes to simple pairing result from Pairing Server (if not already +// subscribed). +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::SubscribeSspPairingResult() + { + if ( !iSSPResultActive->IsActive() ) + { + iPairingResult.SimplePairingResult( iSimplePairingRemote, iSSPResultActive->RequestStatus() ); + iSSPResultActive->GoActive(); + } + } + +// --------------------------------------------------------------------------- +// Subscribes to authentication result from Pairing Server (if not already +// subscribed). +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::SubscribeAuthenticateResult() + { + if ( !iAuthenResultActive->IsActive() ) + { + // Subscribe authentication result (which requires pairing for unpaired devices) + iAuthenResult.AuthenticationResult( iAuthenticateRemote, iAuthenResultActive->RequestStatus() ); + iAuthenResultActive->GoActive(); + } + } + +// --------------------------------------------------------------------------- +// Handle a pairing result from the pairing server. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::HandlePairingResultL( const TBTDevAddr& aAddr, TInt aResult ) + { + // TRACE_FUNC_ARG( (_L("result %d"), aResult ) ) + // TRACE_BDADDR( aAddr ); + if ( !iPairingHandler && ( aResult == KErrNone || aResult == KHCIErrorBase ) ) + { + // we only create new handler if incoming pairing succeeds. + // Pairing failure could be caused by user local cancellation, as the + // result, the handler was destroyed by notifier. We shall not + // instantiate the handler again. + // If a pairing failed due to other reasons than user local cancelling, + // it will be catched by the already started handler + // (except Just Works pairing - no handler for it at all until we receive + // registry change event. Thus if incoming JWs pairing failed, no user + // notification will be shown.) + iPairedDevices.Find( aAddr, MatchDeviceAddress); + TInt index = iPairedDevices.Find( aAddr, MatchDeviceAddress); + // If the device is not found in the old paired device list, it is a new + // paired device: + if ( index == KErrNotFound) + { + // No handler yet, create incoming pairing handler: + iPairingHandler = CBTNotifIncomingPairingHandler::NewL( *this, aAddr ); + } + } + if ( iPairingHandler ) + { + iPairingHandler->HandlePairServerResult( aAddr, aResult ); + } + } + +// --------------------------------------------------------------------------- +// copy the nameless devices to local array +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::UpdatePairedDeviceListL() + { + iPairedDevices.Reset(); + const RDevExtensionArray& alldevs = iDevRepository.AllDevices(); + for ( TInt i = 0; i < alldevs.Count(); i++ ) + { + // TRACE_BDADDR( iPairedDevicesResp->Results()[i]->BDAddr() ); + // TRACE_INFO((_L("[BTENG]\t linkkeytype %d"), + // iPairedDevicesResp->Results()[i]->LinkKeyType())) + if ( CBtDevExtension::IsBonded( alldevs[i]->Device().AsNamelessDevice() ) ) + { + iPairedDevices.AppendL( alldevs[i]->Device().AsNamelessDevice() ); + } + } + } + +// --------------------------------------------------------------------------- +// Create incoming pairing handler if no one exists yet. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingManager::HandleRegistryBondingL( + const TBTNamelessDevice& aNameless) + { + TInt err = iPairedDevices.Append( aNameless ); + if ( !err && !iPairingHandler) + { + // New paired device, but no pairing handler yet. + // this means an incoming pairing has occured: + TRAP( err, iPairingHandler = + CBTNotifIncomingPairingHandler::NewL( *this, aNameless.Address() ) ); + } + if ( !err ) + { + // We have a pairing handler now. + // Ask pair handler to decide what to do: + iPairingHandler->HandleRegistryNewPairedEvent( + aNameless ); + } + else if ( iPairingHandler ) + { + // error could occur due to no memory, + // let us try aborting pairing handling + iPairingHandler->StopPairHandling( aNameless.Address() ); + } + } + + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/src/btnotifpairnotifier.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifpairnotifier.cpp Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,676 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "btnotifpairnotifier.h" +#include "btnotifclientserver.h" +#include +#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS +#include +#endif +#include "btnotifconnectiontracker.h" +#include "btnotifpairingmanager.h" +#include "btnotificationmanager.h" +#include "bluetoothnotification.h" +#include "btnotifserver.h" +#include "bluetoothtrace.h" + + +/** Format syntax for numeric comparison value. */ +_LIT( KNumCompFormat, "%06u" ); +/** Format syntax for passkey display value. */ +_LIT( KPassKeyFormat, "%06u" ); + + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor. +// --------------------------------------------------------------------------- +// +CBTNotifPairNotifier::CBTNotifPairNotifier( + CBTNotifPairingManager& aParent ) +: iParent( aParent ) + { + } + +// --------------------------------------------------------------------------- +// Symbian 2nd-phase constructor. +// --------------------------------------------------------------------------- +// +void CBTNotifPairNotifier::ConstructL() + { + } + +// --------------------------------------------------------------------------- +// NewL +// --------------------------------------------------------------------------- +// +CBTNotifPairNotifier* CBTNotifPairNotifier::NewL( + CBTNotifPairingManager& aParent ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + CBTNotifPairNotifier* self = new( ELeave ) CBTNotifPairNotifier( aParent ); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + BOstraceFunctionExit0( DUMMY_DEVLIST ); + return self; + } + + +// --------------------------------------------------------------------------- +// Destructor. +// --------------------------------------------------------------------------- +// +CBTNotifPairNotifier::~CBTNotifPairNotifier() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + if( iNotification ) + { + // Clear the notification callback, we cannot receive them anymore. + iNotification->RemoveObserver(); + iNotification->Close(); // Also dequeues the notification from the queue. + iNotification = NULL; + } + iParams.Close(); + if ( !iNotifierMessage.IsNull() ) + { + iNotifierMessage.Complete( KErrServerTerminated ); + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// Handle a notifier request for pairing with a remote device. +// --------------------------------------------------------------------------- +// +void CBTNotifPairNotifier::StartPairingNotifierL(const RMessage2& aMessage ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + + // todo: move Authorize notifier to a separate class + TInt uid = aMessage.Int0(); + if ( KBTManAuthNotifierUid.iUid == uid ) + { + TPckgBuf answer; + answer() = ETrue; + TInt err = aMessage.Write( EBTNotifSrvReplySlot, answer); + aMessage.Complete( KErrNone ); + return; + } + + //BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aUid ); + if ( !iNotifierMessage.IsNull() ) + { + // todo: do we allow concurrent pairing? + User::Leave(KErrServerBusy ); + } + + // Store the parameters locally, we need them later again. + iParams.CreateL( aMessage.GetDesLengthL( EBTNotifSrvParamSlot ) ); + aMessage.ReadL( EBTNotifSrvParamSlot, iParams ); + iNotifierMessage = aMessage; + + // Read the notifier parameters + ParseNotifierReqParamsL(); + + const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote); + if(dev) + { + if (!iLocallyInitiated && dev->Device().GlobalSecurity().Banned() ) + { + // If the device is banned and pairing is not locally initiated + // then we ignore. + aMessage.Complete( KErrNone ); + } + if (iLocallyInitiated && dev->Device().GlobalSecurity().Banned()) + { + // Remove the banned device from the blocking history + iParent.ConnectionTracker().UpdateBlockingHistoryL(&dev->Device(),ETrue); + } + if(0 != dev->Device().FriendlyName().Length()&& dev->Device().IsValidFriendlyName()) + { + // If we have a friendly name use it for the UI + iCurrentDeviceName = dev->Device().FriendlyName(); + } + else + { + // We don't have any friendly name then chek if we have the device name + // otherwise use the Alias + if(0 >= iCurrentDeviceName.Length()) + { + iCurrentDeviceName = dev->Alias(); + } + } + } + else + { + //If we didn't get a name then we make one from the Bluetooth device address + if(0 >= iCurrentDeviceName.Length()) + { + iRemote.GetReadable(iCurrentDeviceName); + } + } + // If this is an incoming pairing, we first ask the user to accept it. + if( !iLocallyInitiated ) + { + StartAcceptPairingQueryL(); + } + else + { + TInt uid = iNotifierMessage.Int0(); + if(uid == KBTNumericComparisonNotifierUid.iUid) + { + StartPairingUserInputL(); + } + else + { + TBTPinCode pinCode; + if ( iMinPinLength > -1 ) + { + // Legacy Pin pairing. Check if a pin code is already available + // in pairing manager for this device: + iParent.GetPinCode( pinCode, iRemote, iMinPinLength ); + } + if ( pinCode().iLength != 0 ) + { + // a pin is ready for this pairing. + // write it back to client (stack) + TInt err = iNotifierMessage.Write( EBTNotifSrvReplySlot, pinCode ); + iNotifierMessage.Complete( err ); + } + else + { + // no pin code is available or a pin code does not meet + // the security requirement. + // User need to interact: + StartPairingUserInputL(); + } + } + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + +// --------------------------------------------------------------------------- +// Update a notifier, update the outstanding dialog if the notifier request +// is currently being served. +// --------------------------------------------------------------------------- +// +void CBTNotifPairNotifier::UpdatePairingNotifierL( TInt aUid, const TDesC8& aParams ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + (void) aUid; + TBTNotifierUpdateParams2 params; // Enough for reading the base class type parameter + TPckgC paramsPckg( params ); + paramsPckg.Set( aParams ); + if( paramsPckg().Type() == TBTNotifierUpdateParams2::EPasskeyDisplay ) + { + // Paskey display update - keypress on remote device. + } + else + { + // name update + TBTDeviceNameUpdateParams nameUpdate; + TPckgC nameUpdatePckg( nameUpdate ); + nameUpdatePckg.Set( aParams ); + // The result means result of conversion to unicode + if( !nameUpdatePckg().Result() ) + { + // Check first if we already have a friendly name + const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote); + if(dev) + { + if(0 != dev->Device().FriendlyName().Length()&& dev->Device().IsValidFriendlyName()) + { + return; + } + // We don't have a friendly name then use this name + iCurrentDeviceName = nameUpdatePckg().DeviceName(); + if(0 == iCurrentDeviceName.Length()) + { + // The new name is empty then use the Alias + iCurrentDeviceName = dev->Alias(); + } + } + else + { + // We don't have a friendly name then use this name + iCurrentDeviceName = nameUpdatePckg().DeviceName(); + if(0 == iCurrentDeviceName.Length()) + { + // The new name is empty then use the Alias + iRemote.GetReadable(iCurrentDeviceName); + } + } + if( iNotification ) + { + // Update the dialog with the new name. It is up to the dialog to + // determine the validity (in case another dialog is shown). + iNotification->Update(iCurrentDeviceName); + } + } + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// Cancel a request, dismiss the outstanding dialog if the notifier request +// is currently being served. +// --------------------------------------------------------------------------- +// +void CBTNotifPairNotifier::CancelPairingNotifierL( TInt aUid ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + if( iNotifierMessage.Int0() == aUid ) + { + if( iNotification ) + { + // Cancel the user query + // This will also unregister us from the notification. + TInt err = iNotification->Close(); + NOTIF_NOTHANDLED( !err ) + iNotification = NULL; + } + // todo: Any bonding requester needs to be informed. + // Currently we don't show any "Unable to pair" note + // so no need to inform any bonding requester. + if ( !iNotifierMessage.IsNull() ) + { + iNotifierMessage.Complete( KErrCancel ); + } + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// From class MBTNotificationResult. +// Handle a result from a user query. +// --------------------------------------------------------------------------- +// +void CBTNotifPairNotifier::MBRDataReceived( CHbSymbianVariantMap& aData ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + (void) aData; + NOTIF_NOTIMPL + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// From class MBTNotificationResult. +// The notification is finished. +// --------------------------------------------------------------------------- +// +void CBTNotifPairNotifier::MBRNotificationClosed( TInt aError, const TDesC8& aData ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); + // First unregister from the notification, so we can already get the next one. + //iNotification->RemoveObserver(); + //iNotification = NULL; + TRAP_IGNORE( NotificationClosedL( aError, aData ) ); + iNotification = NULL; + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + +// --------------------------------------------------------------------------- +// Request a user input for the outstanding pairing request. +// --------------------------------------------------------------------------- +// +void CBTNotifPairNotifier::StartPairingUserInputL() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + PrepareNotificationL( iDialog, iDialogResource ); + iState = EPairingInputConfirm; + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// Process the user input and complete the outstanding pairing request. +// --------------------------------------------------------------------------- +// +void CBTNotifPairNotifier::CompletePairingNotifierL( TInt aError, TBool aResult, + const TDesC8& aData ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); + if ( iNotifierMessage.IsNull() ) + { + // Request not anymore active -> ignore + return; + } + TInt err = aError; + TPtrC8 resultData(KNullDesC8); + TBTPinCode pinCode; + TPckgBuf userAcceptance; + if( !err ) + { + TInt uid = iNotifierMessage.Int0(); + // The returned data is the entered passkey. + // const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote); + // TBool proceed = iParent.ConnectionTracker().UpdateBlockingHistoryL(&dev->Device(),aResult); + if( uid == KBTNumericComparisonNotifierUid.iUid ) + { + // Numeric comparison needs the boolean result passed back. + userAcceptance() = aResult; + resultData.Set( userAcceptance ); + } + if( aResult ) + { + if( uid == KBTManPinNotifierUid.iUid + || uid == KBTPinCodeEntryNotifierUid.iUid ) + { + // Check the passkey entered by the user. + // The length of the returned data equals the number of characters + // entered by the user. + pinCode().iLength = aData.Length(); + // Check that the length of the passkey meets the minimum + // required pin code length + if( aData.Length() >= iMinPinLength ) + { + for( TInt i = 0; i < aData.Length(); i++ ) + { + pinCode().iPIN[i] = aData[i]; + } + resultData.Set( pinCode ); + } + else + { + // todo: PIN wasn't long enough. This should be handled by the dialog though. + err = KErrCompletion; + } + } + } + else + { + err = KErrCancel; + if( iLocallyInitiated ) + { + // The user denied the connection, ask to block the device. + // This is only for pairing (and not bonding) initiated by us, + // as the user already gets the opportunity to block when + // rejecting an incoming pairing request. + // This case may be for someone requesting to access a service + // which requires authentication by us, but not by the remote device. + // if(proceed) + // { + // LaunchBlockingQueryL(); + // } + // For incoming pairing, blocking is asked after rejecting the + // pairing request. This is done in CompleteAcceptPairingQueryL + } + } + } + // Complete the message with the result, and result data if any. + if ( !err && resultData.Length() ) + { + err = iNotifierMessage.Write( EBTNotifSrvReplySlot, resultData ); + } + iNotifierMessage.Complete( err ); + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + +// --------------------------------------------------------------------------- +// Ask the user to allow incoming pairing. +// --------------------------------------------------------------------------- +// +void CBTNotifPairNotifier::StartAcceptPairingQueryL() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + PrepareNotificationL( TBluetoothDialogParams::EQuery, EIncomingPairing ); + iState = EIncomingPairingAcceptconfirm; + // if rejected, the client message is completed in CompleteAcceptPairingQueryL + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// The user was asked to accept an incoming pairing. Process and proceed. +// --------------------------------------------------------------------------- +// +void CBTNotifPairNotifier::CompleteAcceptPairingQueryL( TInt aError, TBool aResult ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + TInt err = aError; + if( !err ) + { + // const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote); + // TBool proceed = iParent.ConnectionTracker().UpdateBlockingHistoryL(&dev->Device(),aResult); + if( aResult ) + { + // User accepted, continue to show pairing query. + StartPairingUserInputL(); + if( iDialogNumeric.Length() ) + { + err = iNotification->SetData( + TBluetoothDeviceDialog::EAdditionalDesc, iDialogNumeric ); + } + } + else + { + err = KErrCancel; + // if( proceed ) + // { + // //ask to block the device. + // LaunchBlockingQueryL(); + // } + } + } + if( err ) + { + // The user denied the connection, or something else prevented completion. + CompletePairingNotifierL( err, EFalse, KNullDesC8 ); + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// Parse the parameters of a request for pairing. +// --------------------------------------------------------------------------- +// +void CBTNotifPairNotifier::ParseNotifierReqParamsL() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + // Reset to make sure all vars contain initial values. + iLocallyInitiated = EFalse; + iDialogNumeric.Zero(); + iDialog = TBluetoothDialogParams::EInvalidDialog; + iDialogResource = ENoResource; + iRemote = TBTDevAddr(); + iMinPinLength = -1; + + TInt uid = iNotifierMessage.Int0(); + // Reset for other pairing modes than PIN code. + // Determine the notifier type by the length of the parameter buffer + if( uid == KBTManPinNotifierUid.iUid || uid == KBTPinCodeEntryNotifierUid.iUid ) + { + if ( uid == KBTManPinNotifierUid.iUid ) + { + ParseLegacyPinCodeReqParamsL( iLocallyInitiated, iMinPinLength, iRemote ); + } + else + { + ParsePinCodeReqParamsL( iLocallyInitiated, iMinPinLength, iRemote ); + } + iDialog = TBluetoothDialogParams::EInput; + iDialogResource = EPinInput; + } + else if( uid == KBTNumericComparisonNotifierUid.iUid ) + { + ParseNumericCompReqParamsL( iLocallyInitiated, iDialogNumeric, iRemote ); + iDialog = TBluetoothDialogParams::EQuery; + iDialogResource = ENumericComparison; + } + else if( uid == KBTPasskeyDisplayNotifierUid.iUid ) + { + ParsePasskeyDisplayReqParamsL( iLocallyInitiated, iDialogNumeric, iRemote ); + iDialog = TBluetoothDialogParams::EQuery; + iDialogResource = EPasskeyDisplay; + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// Parse the parameters of a request for pairing using pin query. +// --------------------------------------------------------------------------- +// +void CBTNotifPairNotifier::ParseLegacyPinCodeReqParamsL( TBool& aLocallyInitiated, + TInt& aMinPinLength, TBTDevAddr& aAddr ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + TBTPasskeyNotifierParams params; + TPckgC paramsPckg( params ); + paramsPckg.Set( iParams ); + aLocallyInitiated = paramsPckg().iLocallyInitiated; + aMinPinLength = paramsPckg().iPasskeyMinLength; + aAddr = paramsPckg().iBDAddr; + iCurrentDeviceName = paramsPckg().iName; + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// Parse the parameters of a request for pairing using pin query. +// --------------------------------------------------------------------------- +// +void CBTNotifPairNotifier::ParsePinCodeReqParamsL( TBool& aLocallyInitiated, + TInt& aMinPinLength, TBTDevAddr& aAddr ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + TBTPinCodeEntryNotifierParams params; + TPckgC paramsPckg( params ); + paramsPckg.Set( iParams ); + aLocallyInitiated = paramsPckg().LocallyInitiated(); + aMinPinLength = paramsPckg().PinCodeMinLength(); + aAddr = paramsPckg().DeviceAddress(); + iCurrentDeviceName = paramsPckg().DeviceName(); + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// Parse the parameters of a request for pairing using numeric comparison. +// --------------------------------------------------------------------------- +// +void CBTNotifPairNotifier::ParseNumericCompReqParamsL( TBool& aLocallyInitiated, + TDes& aNumVal, TBTDevAddr& aAddr ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + TBTNumericComparisonParams params; + TPckgC paramsPckg( params ); + paramsPckg.Set( iParams ); + aLocallyInitiated = paramsPckg().LocallyInitiated(); + TBTNumericComparisonParams::TComparisonScenario scenario = + paramsPckg().ComparisonScenario(); + aNumVal.Format( KNumCompFormat, paramsPckg().NumericalValue() ); + aAddr = paramsPckg().DeviceAddress(); + iCurrentDeviceName = paramsPckg().DeviceName(); + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// Parse the parameters of a request for pairing using passkey display. +// --------------------------------------------------------------------------- +// +void CBTNotifPairNotifier::ParsePasskeyDisplayReqParamsL( TBool& aLocallyInitiated, + TDes& aNumVal, TBTDevAddr& aAddr ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + TBTPasskeyDisplayParams params; + TPckgC paramsPckg( params ); + paramsPckg.Set( iParams ); + aLocallyInitiated = paramsPckg().LocallyInitiated(); + aNumVal.Format( KPassKeyFormat, paramsPckg().NumericalValue() ); + aAddr = paramsPckg().DeviceAddress(); + iCurrentDeviceName = paramsPckg().DeviceName(); + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// Get and configure a notification. +// --------------------------------------------------------------------------- +// +void CBTNotifPairNotifier::PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType, + TBTDialogResourceId aResourceId ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + iNotification = + iParent.ConnectionTracker().NotificationManager()->GetNotification(); + User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory + iNotification->SetObserver( this ); + iNotification->SetNotificationType( aType, aResourceId ); + TInt err = iNotification->SetData( TBluetoothDeviceDialog::EDeviceName, iCurrentDeviceName ); + NOTIF_NOTHANDLED( !err ) + TBTDeviceName name; + iRemote.GetReadable(name); + err = iNotification->SetData( TBluetoothDialogParams::EAddress, name ); + NOTIF_NOTHANDLED( !err ) + const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote); + TInt classofdevice = 0; + if(dev) + { + if(dev->Device().IsValidDeviceClass()) + { + classofdevice = dev->Device().DeviceClass().DeviceClass(); + } + } + err = iNotification->SetData( (TInt) TBluetoothDeviceDialog::EDeviceClass, + classofdevice ); + iParent.ConnectionTracker().NotificationManager()->QueueNotificationL( iNotification); + NOTIF_NOTHANDLED( !err ) + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// The notification is finished, handle the result. +// --------------------------------------------------------------------------- +// +void CBTNotifPairNotifier::NotificationClosedL( TInt aError, const TDesC8& aData ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); + // Read the result. + TPckgC result( EFalse ); + result.Set( aData.Ptr(), result.Length() ); // Read the part containing the result + // Set a pointer descriptor to capture the remaining data, if any. + TPtrC8 dataPtr( aData.Mid( result.Length() ) ); + if ( iState == EIncomingPairingAcceptconfirm ) + { + CompleteAcceptPairingQueryL(aError, result()); + } + else + { + CompletePairingNotifierL( aError, result(), dataPtr ); + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + +// --------------------------------------------------------------------------- +// Ask the user if he/she wants to block future connection requests. +// --------------------------------------------------------------------------- +// +void CBTNotifPairNotifier::LaunchBlockingQueryL() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + TBTDialogResourceId resourceId = EBlockUnpairedDevice; + const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote); + if(dev->Device().IsValidPaired() && dev->Device().IsPaired() && + dev->Device().LinkKeyType() != ELinkKeyUnauthenticatedUpgradable ) + { + resourceId = EBlockPairedDevice; + } + PrepareNotificationL( TBluetoothDialogParams::EQuery, resourceId ); + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + + + + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/src/btnotifserver.cpp --- a/bluetoothengine/btnotif/btnotifsrv/src/btnotifserver.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifserver.cpp Mon May 17 11:06:23 2010 +0300 @@ -1,24 +1,19 @@ /* -* ============================================================================ -* Name : btnotifserver.cpp -* Part of : bluetoothengine / btnotif -* Description : Server class for handling commands from clients, and the +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Server class for handling commands from clients, and the * central class in btnotif thread. * -* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* Nokia Corporation -* ============================================================================ -* Template version: 4.1 */ #include "btnotifserver.h" @@ -117,20 +112,18 @@ // void CBTNotifServer::AsyncConstructL() { + // The server class owns this registry object and provides it + // as a singleton in the whole server process. + // Server itself does not handle any registry events. + // Classes that want to receive these events must register + // observers via CBtDevRepository interface. + iDevRep = CBtDevRepository::NewL(); + iNotificationMgr = CBTNotificationManager::NewL( this ); iSettingsTracker = CBTNotifSettingsTracker::NewL( this ); - if( iSettingsTracker->GetPowerState() == EBTPowerOn ) - { - iConnectionTracker = CBTNotifConnectionTracker::NewL( this ); - } - iNotificationMgr = CBTNotificationManager::NewL( this ); - + iConnectionTracker = CBTNotifConnectionTracker::NewL( this ); iTimer = CDeltaTimer::NewL(CActive::EPriorityLow); TCallBack shutdownCb( ShutdownTimeout, this ); iShutdownTimerEntry.Set( shutdownCb ); - // The server class does not handle any registry events. - // Classes that want to receive these events must register - // via observer interface. - iDevRep = CBtDevRepository::NewL(); } // --------------------------------------------------------------------------- @@ -178,16 +171,6 @@ // void CBTNotifServer::HandlePowerStateChangeL( TBTPowerStateValue aState ) { - if( aState && !iConnectionTracker ) - { - // only construct tracker if it is not available yet - iConnectionTracker = CBTNotifConnectionTracker::NewL( this ); - } - else - { - delete iConnectionTracker; - iConnectionTracker = NULL; - } CheckIdle( aState ); } @@ -239,72 +222,6 @@ } // --------------------------------------------------------------------------- -// Searches for a client message from a message handle and completes it. -// --------------------------------------------------------------------------- -// -TInt CBTNotifServer::CompleteMessage( TInt aHandle, TInt aReason, const TDesC8& aReply ) - { - TInt err = KErrNotFound; - iSessionIter.SetToFirst(); - CBTNotifSession* session = NULL; - while( ( session = (CBTNotifSession*) iSessionIter++ ) != NULL ) - { - err = session->CompleteMessage( aHandle, aReason, aReply ); - if( err != KErrNotFound ) - { - // Found the correct session, and message, and completed it. - break; - } - } - return err; - } - - -// --------------------------------------------------------------------------- -// Searches for a client message from a message handle and returns it. -// --------------------------------------------------------------------------- -// -const RMessage2* CBTNotifServer::FindMessageFromHandle( TInt aHandle ) - { - const RMessage2* message = NULL; - iSessionIter.SetToFirst(); - CBTNotifSession* session = NULL; - while( ( session = (CBTNotifSession*) iSessionIter++ ) != NULL ) - { - message = session->FindMessageFromHandle( aHandle ); - if( message ) - { - // Found the correct session and message to return. - break; - } - } - return message; - } - - -// --------------------------------------------------------------------------- -// Searches for a client message from a message handle and returns it. -// --------------------------------------------------------------------------- -// -const RMessage2* CBTNotifServer::FindMessageFromUid( TInt aUid ) - { - const RMessage2* message = NULL; - iSessionIter.SetToFirst(); - CBTNotifSession* session = NULL; - while( ( session = (CBTNotifSession*) iSessionIter++ ) != NULL ) - { - message = session->FindMessageFromUid( aUid ); - if( message ) - { - // Found the correct session and message to return. - break; - } - } - return message; - } - - -// --------------------------------------------------------------------------- // From class CPolicyServer. // Create a new session object. // --------------------------------------------------------------------------- diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/src/btnotifsession.cpp --- a/bluetoothengine/btnotif/btnotifsrv/src/btnotifsession.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifsession.cpp Mon May 17 11:06:23 2010 +0300 @@ -1,27 +1,25 @@ /* -* ============================================================================ -* Name : btnotifsession.cpp -* Part of : bluetoothengine / btnotif -* Description : Session class for handling commands from clients. +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". * -* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* Initial Contributors: +* Nokia Corporation - initial contribution. * -* Initial Contributors: -* Nokia Corporation - initial contribution. +* Contributors: * -* Contributors: -* Nokia Corporation -* ============================================================================ -* Template version: 4.1 +* Description: Session class for handling commands from clients. +* */ #include "btnotifsession.h" #include +#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS +#include +#endif #include "btnotifclientserver.h" #include "btnotifsettingstracker.h" #include "btnotifconnectiontracker.h" @@ -81,12 +79,8 @@ // CBTNotifSession::~CBTNotifSession() { - for( TInt i = 0; i < iMessageQ.Count(); i++ ) - { - // Complete all outstanding messages with error code - iMessageQ[i].Complete( KErrSessionClosed ); - } - iMessageQ.Close(); // Cleans up all message objects. + // clients must complete the message they are responsible for + // we do not complete any message here Server()->RemoveSession(); } @@ -97,59 +91,71 @@ // void CBTNotifSession::ServiceL( const RMessage2& aMessage ) { + CBTNotifConnectionTracker* connTracker = Server()->ConnectionTracker(); TInt opCode = aMessage.Function(); - if ( opCode == EBTNotifCancelNotifier || - opCode == EBTNotifStartSyncNotifier || - opCode == EBTNotifStartAsyncNotifier || - opCode == EBTNotifUpdateNotifier ) - { - TInt uid = aMessage.Int0(); - if( uid == KDeviceSelectionNotifierUid.iUid ) - { - // Note for implementers: - // message queue is not used in this notifier handling (due - // to its drawbacks for exception handlings in various situations). - // implementations using message queue will be migrated step - // by step. - - TRAPD( err, { - CBTNotifDeviceSelector& selector = Server()->DeviceSelectorL(); - selector.DispatchNotifierMessageL( aMessage ); } - ); + TInt uid = aMessage.Int0(); + TInt err( KErrNotReady ); + switch(opCode){ + case EBTNotifCancelNotifier: + case EBTNotifStartSyncNotifier: + case EBTNotifStartAsyncNotifier: + case EBTNotifUpdateNotifier: + if( uid == KDeviceSelectionNotifierUid.iUid ) + { + TRAP( err, { + CBTNotifDeviceSelector& selector = Server()->DeviceSelectorL(); + selector.DispatchNotifierMessageL( aMessage ); } + ); + if ( err ) + { + aMessage.Complete( err ); + } + // deviceselector takes the ownership of aMessage. + } + else + { + // PIN/ SSP pairing notifiers from BT stack: + // ***** Note for implementers: + // message queue is not used for this notifier handling. + if ( uid == KBTManAuthNotifierUid.iUid || + uid == KBTManPinNotifierUid.iUid || + uid == KBTPinCodeEntryNotifierUid.iUid || + uid == KBTNumericComparisonNotifierUid.iUid || + uid == KBTPasskeyDisplayNotifierUid.iUid || + uid == KBTUserConfirmationNotifierUid.iUid ) + { + if( connTracker ) + { + // Pass it to the connection tracker. + TRAP( err, + connTracker->HandlePairingNotifierRequestL( aMessage ) ); + } + if ( err ) + { + // tracker not available, can't do this now. + aMessage.Complete( err ); + } + } + } + break; + case EBTNotifPairDevice: + case EBTNotifCancelPairDevice: + // Pairing requests from clients: + if ( connTracker ) + { + TRAP( err, connTracker->HandleBondingRequestL( aMessage ) ); + } if ( err ) { - aMessage.Complete( err ); + // tracker not available, can't do this now. + aMessage.Complete( err ); } - // deviceselector takes the ownership of aMessage. - return; - } - } - - // Messages are completed by message handlers, not here. - // Queue the message already so that handlers can find it from the queue. - iMessageQ.AppendL( aMessage ); - // The position is assumed to not change during the execution of this function. - TInt handle = aMessage.Handle(); // Store the handle for de-queueing - TRAPD( err, DispatchMessageL( aMessage ) ); - if( err || ( aMessage.IsNull() && FindMessageFromHandle( handle ) ) ) - { - // If the message has been completed by now (handle is null and the message - // still in the queue), we remove it again from the queue. Otherwise it - // will be completed by the handling handler when it has handled the handling. - for( TInt i = 0; i < iMessageQ.Count(); i++ ) - { - // This may be replaced by RArray::Find with appropriate key - if( iMessageQ[i].Handle() == handle ) - { - iMessageQ.Remove( i ); - } - } - } - if( err && !aMessage.IsNull() ) - { - aMessage.Complete( err ); - } + break; + default: + aMessage.Complete( KErrNotSupported ); + break; } +} // --------------------------------------------------------------------------- @@ -162,143 +168,3 @@ Server()->AddSession(); } -// --------------------------------------------------------------------------- -// Complete a client message from a message handle with given data. -// If a zero-length descriptor is passed, no data will be written back. -// --------------------------------------------------------------------------- -// -TInt CBTNotifSession::CompleteMessage( TInt aHandle, TInt aReason, const TDesC8& aReply ) - { - TInt err = KErrNotFound; - // This may be replaced by RArray::Find with appropriate key - for( TInt i = 0; i < iMessageQ.Count(); i++ ) - { - if( iMessageQ[i].Handle() == aHandle ) - { - err = KErrNone; - if( aReply.Length() ) - { - // For now, assume a fixed index for the result. - // Change this if a the client can pass more arguments! - // ToDo: replace with constant! - err = iMessageQ[i].Write( EBTNotifSrvReplySlot, aReply ); - // Should the result be passed back to the calller, - // or used to complete the message? - } - iMessageQ[i].Complete( aReason ); - iMessageQ.Remove( i ); - break; - } - } - return err; - } - - -// --------------------------------------------------------------------------- -// Find a client message from an RMessage2 handle. -// --------------------------------------------------------------------------- -// -const RMessage2* CBTNotifSession::FindMessageFromHandle( TInt aHandle ) const - { - // This may be replaced by RArray::Find with appropriate key - for( TInt i = 0; i < iMessageQ.Count(); i++ ) - { - if( iMessageQ[i].Handle() == aHandle ) - { - return &iMessageQ[i]; - } - } - return NULL; - } - - -// --------------------------------------------------------------------------- -// Process a client message. -// The processing here relies on RNotifier backend server for queueing -// notifiers on the same channel. Therefore pairing (SSP and legacy) and -// authorization notifiers arrive in order, not simultaneously, even if -// they use arrive on different session instances. -// --------------------------------------------------------------------------- -// -void CBTNotifSession::DispatchMessageL( const RMessage2& aMessage ) - { - BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aMessage.Function() ); - CBTNotifSettingsTracker* settTracker = Server()->SettingsTracker(); - CBTNotifConnectionTracker* connTracker = Server()->ConnectionTracker(); - LeaveIfNullL( settTracker, KErrNotReady ); - TInt opcode = aMessage.Function(); - if( opcode < EBTNotifMinValue ) - { - User::Leave( KErrArgument ); - } - switch( opcode ) - { - case EBTNotifCancelNotifier: - case EBTNotifStartSyncNotifier: - case EBTNotifStartAsyncNotifier: - case EBTNotifUpdateNotifier: - { - // All these messages get the same treatment: forward - // to settings and connection tracker, who will deal with it appropriately. - // First the settings tracker handles the message. - settTracker->DispatchNotifierMessageL( aMessage ); - if( connTracker && !aMessage.IsNull() ) - { - // Pass it on to the connection tracker, if it hasn't been completed yet. - connTracker->DispatchNotifierMessageL( aMessage ); - } - else - { - // Power is off, can't do this now. - LeaveIfNullL( connTracker, KErrNotReady ); - } - if( opcode != EBTNotifStartAsyncNotifier && !aMessage.IsNull() ) - { - // Nobody has yet completed the message, and it is a synchronous - // one so we'll do it here to allow the notifier to keep on going. - aMessage.Complete( KErrNone ); - } - } - break; - case EBTEngPrepareDiscovery: - { - // This is functionality only related to existing connections. - // Can't do when power is off though. - LeaveIfNullL( connTracker, KErrNotReady ); - //connTracker->HandlePairingRequestL( aMessage ); - } - break; - case EBTEngPairDevice: - case EBTEngCancelPairDevice: - { - // This is functionality only related to connections. - // Can't do when power is off though. - LeaveIfNullL( connTracker, KErrNotReady ); - connTracker->HandleBondingRequestL( aMessage ); - } - break; - default: - // Communicate result back. - User::Leave( KErrNotSupported ); - break; - } - BOstraceFunctionExit1( DUMMY_DEVLIST, this ); - } - - -// --------------------------------------------------------------------------- -// Find a client message from an RNotifier UID. -// --------------------------------------------------------------------------- -// -const RMessage2* CBTNotifSession::FindMessageFromUid( TInt aUid ) const - { - // This may be replaced by RArray::Find with appropriate key - for( TInt i = 0; i < iMessageQ.Count(); i++ ) - { - if( iMessageQ[i].Int0() == aUid ) - { - return &iMessageQ[i]; - } - } - return NULL; - } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifsrv/src/btnotifsettingstracker.cpp --- a/bluetoothengine/btnotif/btnotifsrv/src/btnotifsettingstracker.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifsettingstracker.cpp Mon May 17 11:06:23 2010 +0300 @@ -1,23 +1,19 @@ /* -* ============================================================================ -* Name : btnotifsettingstracker.cpp -* Part of : BTProximity / BTProximity -* Description : Class for tracking Bluetooth settings, and also for handling notes unrelated to specific connection. +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". * -* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* Initial Contributors: +* Nokia Corporation - initial contribution. * -* Initial Contributors: -* Nokia Corporation - initial contribution. +* Contributors: * -* Contributors: -* Nokia Corporation -* ============================================================================ -* Template version: 4.1 +* Description: Class for tracking Bluetooth settings, and also for +* handling notes unrelated to specific connection. +* */ #include "btnotifsettingstracker.h" @@ -134,7 +130,8 @@ { iNotification->SetObserver( this ); iNotification->SetNotificationType( TBluetoothDeviceDialog::ENote, EVisibilityTimeout ); - iServer->NotificationManager()->QueueNotification( iNotification ); + TRAP_IGNORE( + iServer->NotificationManager()->QueueNotificationL( iNotification ) ); } } iVisibilityMode = aState; diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifwrapper/inc/btnotifwrapper.h --- a/bluetoothengine/btnotif/btnotifwrapper/inc/btnotifwrapper.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifwrapper/inc/btnotifwrapper.h Mon May 17 11:06:23 2010 +0300 @@ -241,7 +241,7 @@ * Buffer containing a copy of the notifier parameters, for async notifiers. * Own. */ - HBufC8* iParamsBuf; + RBuf8 iParamsBuf; /** * Modifiable pointer descriptor for getting the response back. @@ -252,7 +252,7 @@ * Buffer for receiving the response from the BT notifier server. * Own. */ - HBufC8* iResponseBuf; + RBuf8 iResponseBuf; /** * Active object helper class. diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifwrapper/src/btnotifwrapper.cpp --- a/bluetoothengine/btnotif/btnotifwrapper/src/btnotifwrapper.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifwrapper/src/btnotifwrapper.cpp Mon May 17 11:06:23 2010 +0300 @@ -165,17 +165,14 @@ // returning from this call. We do it on the heap, so we do not permanently // consume memory for the buffer. - iParamsBuf = HBufC8::NewL( aBuffer.Size() ); - *iParamsBuf = aBuffer; - + iParamsBuf.CreateL( aBuffer ); TInt len = aMessage.GetDesMaxLength( aReplySlot ); - iResponseBuf = HBufC8::NewL( len ); - // Copy in the response, to get the right buffer size. - iResponsePtr.Set( iResponseBuf->Des() ); - aMessage.ReadL( aReplySlot, iResponsePtr ); + + iResponseBuf.CreateL( len ); + aMessage.ReadL( aReplySlot, iResponseBuf ); iBTNotif.StartNotifierAndGetResponse( iActive->RequestStatus(), - iUid, *iParamsBuf, iResponsePtr ); + iUid, iParamsBuf, iResponseBuf ); iActive->GoActive(); // record the request iReplySlot = aReplySlot; @@ -199,10 +196,8 @@ iMessage.Complete( KErrCancel ); } iReplySlot = 0; - delete iParamsBuf; - iParamsBuf = NULL; - delete iResponseBuf; - iResponseBuf = NULL; + iParamsBuf.Close(); + iResponseBuf.Close(); } // --------------------------------------------------------------------------- @@ -259,22 +254,14 @@ if( !iMessage.IsNull() ) { TInt err( aStatus ); - if( !aStatus ) + if( !err ) { - // for testing: - //TPckgBuf response; - //response.Copy( *iResponseBuf ); - //response().BDAddr(); - err = iMessage.Write( iReplySlot, *iResponseBuf ); + err = iMessage.Write( iReplySlot, iResponseBuf ); } iMessage.Complete( err ); } // Clean up after usage. iBTNotif.Close(); - delete iParamsBuf; - iParamsBuf = NULL; - delete iResponseBuf; - iResponseBuf = NULL; delete iActive; iActive = NULL; } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/btnotifwrapper/src/btnotifwrapperproxy.cpp --- a/bluetoothengine/btnotif/btnotifwrapper/src/btnotifwrapperproxy.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/btnotifwrapper/src/btnotifwrapperproxy.cpp Mon May 17 11:06:23 2010 +0300 @@ -80,9 +80,13 @@ CreateAndAppendNotifierLC( *notifiers, KBTNumericComparisonNotifierUid, KBTAuthChannel ); CreateAndAppendNotifierLC( *notifiers, KBTPasskeyDisplayNotifierUid, KBTAuthChannel ); + // todo: add + // KBTUserConfirmationNotifierUid for incoming JW dedicated bonding. + CreateAndAppendNotifierLC( *notifiers, KDeviceSelectionNotifierUid, KBTDiscoveryChannel ); /* + * todo: * Other notifiers to be migrated: * * existing stack notifiers: diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/group/bld.inf --- a/bluetoothengine/btnotif/group/bld.inf Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/group/bld.inf Mon May 17 11:06:23 2010 +0300 @@ -1,5 +1,5 @@ /* -* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" @@ -24,6 +24,7 @@ PRJ_EXPORTS ../rom/btnotif.iby CORE_MW_LAYER_IBY_EXPORT_PATH(btnotif.iby) +../inc/bluetoothdevicedialogs.h MW_LAYER_PLATFORM_EXPORT_PATH(btservices/bluetoothdevicedialogs.h) PRJ_MMPFILES btnotifsrv.mmp @@ -32,7 +33,7 @@ PRJ_TESTMMPFILES //../btnotifsrv/tsrc/btnotifsrvtest/group/btnotifsrvtest.mmp -../btnotifsrv/tsrc/btnotifsrvtest/group/btnotifserversessiontest.mmp -../btnotifwrapper/tsrc/btnotifwrappertest/group/btnotifwrappertest.mmp +//../btnotifsrv/tsrc/btnotifsrvtest/group/btnotifserversessiontest.mmp +//../btnotifwrapper/tsrc/btnotifwrappertest/group/btnotifwrappertest.mmp PRJ_TESTEXPORTS diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/group/btnotifsrv.mmp --- a/bluetoothengine/btnotif/group/btnotifsrv.mmp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/group/btnotifsrv.mmp Mon May 17 11:06:23 2010 +0300 @@ -34,12 +34,15 @@ SOURCE btnotifserver.cpp SOURCE btnotifsession.cpp SOURCE btnotifconnectiontracker.cpp -SOURCE btnotifconnection.cpp -SOURCE btnotifpairinghelper.cpp SOURCE btnotifsettingstracker.cpp SOURCE btnotificationmanager.cpp SOURCE bluetoothnotification.cpp -SOURCE btnotifdeviceselector.cpp +SOURCE btnotifdeviceselector.cpp +SOURCE btnotifpairnotifier.cpp +SOURCE btnotifbasepairinghandler.cpp +SOURCE btnotifincomingpairinghandler.cpp +SOURCE btnotifoutgoingpairinghandler.cpp +SOURCE btnotifpairingmanager.cpp USERINCLUDE ../btnotifsrv/inc ../inc diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/inc/bluetoothdevicedialogs.h --- a/bluetoothengine/btnotif/inc/bluetoothdevicedialogs.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/inc/bluetoothdevicedialogs.h Mon May 17 11:06:23 2010 +0300 @@ -62,7 +62,9 @@ ENote, EQuery, EInput, + EMoreDevice, EDeviceSearch, + ESend, EGlobalNotif }; diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btnotif/inc/btnotifclientserver.h --- a/bluetoothengine/btnotif/inc/btnotifclientserver.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btnotif/inc/btnotifclientserver.h Mon May 17 11:06:23 2010 +0300 @@ -49,10 +49,9 @@ EBTNotifStartAsyncNotifier, EBTNotifCancelNotifier, EBTNotifUpdateNotifier, - // Commands moved from BTEngine server. - EBTEngPrepareDiscovery = 43, - EBTEngPairDevice, - EBTEngCancelPairDevice, + EBTNotifPrepareDiscovery = 43, + EBTNotifPairDevice, + EBTNotifCancelPairDevice, }; /** diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btsac/btrcc/inc/btrccAbsoluteVolumeLevelController.h --- a/bluetoothengine/btsac/btrcc/inc/btrccAbsoluteVolumeLevelController.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btsac/btrcc/inc/btrccAbsoluteVolumeLevelController.h Mon May 17 11:06:23 2010 +0300 @@ -87,7 +87,7 @@ void AdjustRemoteVolume(TInt aVolume); - TInt GetPhoneVolume(TInt &aVol); + TInt RoundRemoteVolume(TInt aPrevPhVol); public: // New methods @@ -121,6 +121,8 @@ TUint iNumRemotes; // not used, but needed for the remote controlling API. TInt iRetryCounter; + + TInt iStep; }; #endif // BTRCCABSOLUTEVOLUMELEVELCONTROLLER_H diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btsac/btrcc/inc/btrccLegacyVolumeLevelController.h --- a/bluetoothengine/btsac/btrcc/inc/btrccLegacyVolumeLevelController.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btsac/btrcc/inc/btrccLegacyVolumeLevelController.h Mon May 17 11:06:23 2010 +0300 @@ -97,7 +97,7 @@ private: // From CBTRCCVolumeLevelControllerBase void AdjustRemoteVolume(TInt aVolume); - TInt GetPhoneVolume(TInt &aVol); + void ScalePhoneVolume(TInt& aVolume); private: // From MRemConCoreApiControllerObserver TInt MrccacoResponse(); diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btsac/btrcc/inc/btrccLinker.h --- a/bluetoothengine/btsac/btrcc/inc/btrccLinker.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btsac/btrcc/inc/btrccLinker.h Mon May 17 11:06:23 2010 +0300 @@ -319,6 +319,7 @@ CBTRCCVolumeLevelControllerBase* iVolController; CBTRCCVolumeLevelControllerBase* iAbsoluteVolController; + CBTRCCVolumeLevelControllerBase* iLegacyVolController; TInt iRegisterVolumeChangeNotificationCounter;//Counter for re-register for remote volume control notification }; diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btsac/btrcc/inc/btrccVolumeLevelControllerBase.h --- a/bluetoothengine/btsac/btrcc/inc/btrccVolumeLevelControllerBase.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btsac/btrcc/inc/btrccVolumeLevelControllerBase.h Mon May 17 11:06:23 2010 +0300 @@ -92,6 +92,8 @@ TInt GetLocalMaxVolume(); TInt GetCurrentLocalVolume(); + + TInt GetCurrentRemoteVolume(); void AccessoryChangedVolume(TInt aVolumeInPhoneScale); @@ -106,18 +108,18 @@ virtual void RegisterVolumeChangeNotification(); private: - void SetPhoneVolume(); + void SetPhoneVolume(TInt aRemoteVol); + TInt GetPhoneVolume(TInt &aVol); private: // New methods /** * To be implemented by the specialization class. */ - virtual void AdjustRemoteVolume(TInt aVolume) = 0; - - protected: - virtual TInt GetPhoneVolume(TInt &aVol); - + virtual void AdjustRemoteVolume(TInt aVolume) = 0; + virtual TInt RoundRemoteVolume(TInt aPrevPhVol); + virtual void ScalePhoneVolume(TInt& aVolume); + private: // Data RProperty iVolLevelProperty; // owned RProperty iVolKeyEventProperty; // owned diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btsac/btrcc/src/btrccAbsoluteVolumeLevelController.cpp --- a/bluetoothengine/btsac/btrcc/src/btrccAbsoluteVolumeLevelController.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btsac/btrcc/src/btrccAbsoluteVolumeLevelController.cpp Mon May 17 11:06:23 2010 +0300 @@ -28,6 +28,7 @@ const TInt KAbsoluteVolumeLevelSetServiceId = 0x02; const TInt KMaxRetries = 3; +const TInt KDefaultStep = 1000; // MODULE DATA STRUCTURES @@ -53,7 +54,7 @@ // ----------------------------------------------------------------------------- // CBTRCCAbsoluteVolumeLevelController::CBTRCCAbsoluteVolumeLevelController(MBTRCCVolumeControllerObserver& aObserver) -: CBTRCCVolumeLevelControllerBase(aObserver) +: CBTRCCVolumeLevelControllerBase(aObserver), iStep(KDefaultStep) { } @@ -153,13 +154,48 @@ } // ----------------------------------------------------------------------------- -// CBTRCCAbsoluteVolumeLevelController::GetPhoneVolume +// CBTRCCAbsoluteVolumeLevelController::RoundRemoteVolume // ----------------------------------------------------------------------------- // -TInt CBTRCCAbsoluteVolumeLevelController::GetPhoneVolume(TInt &aVol) +TInt CBTRCCAbsoluteVolumeLevelController::RoundRemoteVolume(TInt aPrevPhVol) { TRACE_FUNC - return CBTRCCVolumeLevelControllerBase::GetPhoneVolume(aVol); + TInt phoneVol = GetCurrentLocalVolume(); + TInt remoteVol = GetCurrentRemoteVolume(); + TRACE_INFO((_L("Volume to be rounded %d"), remoteVol)) + // Update step + if( phoneVol != -1 && aPrevPhVol != -1 ) + { + TInt step = Abs( phoneVol - aPrevPhVol ); + if( step ) + { + TRACE_INFO((_L("Step %d"), step)) + // Only update step value if it is not equal to zero + iStep = step; + } + } + if( remoteVol >= 0 && remoteVol <= iLocalMaxVolume ) + { + TInt lowLimit = 0; + TInt highLimit = 0; + + for( TInt i = 0 ; highLimit < iLocalMaxVolume ; i++ ) + { + lowLimit = i*iStep; + highLimit = (i+1)*iStep; + // Find the correct low and high value pair in which volume + // belongs. + if( remoteVol >= lowLimit && remoteVol <= highLimit ) + { + break; + } + } + TInt diff1 = Abs( remoteVol - lowLimit ); + TInt diff2 = Abs( remoteVol - highLimit ); + remoteVol = diff1 <= diff2 ? lowLimit : highLimit; + } + TRACE_INFO((_L("Rounded volume %d"), remoteVol)) + return remoteVol; } // ----------------------------------------------------------------------------- diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btsac/btrcc/src/btrccLegacyVolumeLevelController.cpp --- a/bluetoothengine/btsac/btrcc/src/btrccLegacyVolumeLevelController.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btsac/btrcc/src/btrccLegacyVolumeLevelController.cpp Mon May 17 11:06:23 2010 +0300 @@ -247,23 +247,21 @@ } // ----------------------------------------------------------------------------- -// CBTRCCLegacyVolumeLevelController::GetPhoneVolume +// CBTRCCLegacyVolumeLevelController::ScalePhoneVolume // ----------------------------------------------------------------------------- // -TInt CBTRCCLegacyVolumeLevelController::GetPhoneVolume(TInt &aVol) +void CBTRCCLegacyVolumeLevelController::ScalePhoneVolume(TInt &aVolume) { - TRACE_FUNC - TInt err = CBTRCCVolumeLevelControllerBase::GetPhoneVolume(aVol); - + TRACE_FUNC // Converts volume level scale used in DevSound Audio (0 - 10000) into 0 - KVolumeScaleMax. - if( aVol <= 0 ) + if( aVolume <= 0 ) { // 0 level and -1 (no stream) don't need adjustment. - return err; + return; } TReal tgt; - TReal src(aVol); + TReal src(aVolume); TReal maxScale(KVolumeScaleMax); TReal maxDevSound(iLocalMaxVolume); TReal scale = maxScale/maxDevSound; @@ -275,9 +273,8 @@ // values have to be upgraded to level 1. tgt = 1; } - TRACE_INFO((_L("Volume scaled: original %d, scaled %d"), aVol, TInt(tgt))) - aVol = TInt(tgt); - return err; + TRACE_INFO((_L("Volume scaled: original %d, scaled %d"), aVolume, TInt(tgt))) + aVolume = TInt(tgt); } // ----------------------------------------------------------------------------- diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btsac/btrcc/src/btrccLinker.cpp --- a/bluetoothengine/btsac/btrcc/src/btrccLinker.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btsac/btrcc/src/btrccLinker.cpp Mon May 17 11:06:23 2010 +0300 @@ -25,6 +25,7 @@ #include #include #include "btaudioremconpskeys.h" +#include "btrccLegacyVolumeLevelController.h" #include "btrccAbsoluteVolumeLevelController.h" #include "btrccLinker.h" #include "btrccplayerstarter.h" @@ -86,6 +87,14 @@ if (iAccObserver.IsAvrcpVolCTSupported()) { iAbsoluteVolController = CBTRCCAbsoluteVolumeLevelController::NewL(*iInterfaceSelector, *this); + TRACE_INFO((_L("CBTRCCLinker::ConstructL, absolute volume controller created."))) + + // If also legacy is configured into use, prepare to use it with legacy devices. + if(iAccObserver.IsAvrcpLegacyVolCTSupported()) + { + iLegacyVolController = CBTRCCLegacyVolumeLevelController::NewL(*iInterfaceSelector, *this); + TRACE_INFO((_L("CBTRCCLinker::ConstructL, legacy volume controller created."))) + } } else { @@ -125,6 +134,7 @@ User::RequestComplete(iClientRequest, KErrAbort); delete iAbsoluteVolController; + delete iLegacyVolController; delete iPlayerStarter; Cancel(); iStateArray.ResetAndDestroy(); @@ -432,7 +442,7 @@ if (iAccObserver.IsAvrcpVolCTSupported()) { // Choose based on SDP result whether to create - // absolute controller or not. + // absolute controller or legacy controller. if(!iVolController) { if (iAccObserver.IsAbsoluteVolumeSupported(iRemoteAddr)) @@ -440,10 +450,10 @@ iVolController = iAbsoluteVolController; TRACE_INFO(_L("Absolute volume supported, taking it into use.")) } - else - { - TRACE_INFO(_L("No absolute volume supported, so no volume control.")) - } + else + { + iVolController = iLegacyVolController; // iLegacyVolController may be NULL, depends on the configuration. + } } } if (iVolController) diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btsac/btrcc/src/btrccVolumeLevelControllerBase.cpp --- a/bluetoothengine/btsac/btrcc/src/btrccVolumeLevelControllerBase.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btsac/btrcc/src/btrccVolumeLevelControllerBase.cpp Mon May 17 11:06:23 2010 +0300 @@ -82,6 +82,7 @@ iBtrccActive->GoActive(); (void) GetPhoneVolume(iPhoneVolume); + ScalePhoneVolume(iPhoneVolume); if( iPhoneVolume > -1) { DoStart( iPhoneVolume ); @@ -152,10 +153,13 @@ iRemoteVolume = aVolumeInPhoneScale; TInt vol; TInt err = GetPhoneVolume(vol); + ScalePhoneVolume(iPhoneVolume); if(!err) { + TInt prevPhVol = iPhoneVolume; iPhoneVolume = vol; - SetPhoneVolume(); + TInt remoteVol = RoundRemoteVolume(prevPhVol); + SetPhoneVolume(remoteVol); } } @@ -163,24 +167,18 @@ // CBTRCCVolumeLevelControllerBase::SetPhoneVolume // ----------------------------------------------------------------------------- // -void CBTRCCVolumeLevelControllerBase::SetPhoneVolume() +void CBTRCCVolumeLevelControllerBase::SetPhoneVolume(TInt aRemoteVol) { TRACE_FUNC - TRACE_INFO((_L("iRemoteVolume = %d, iPhoneVolume = %d"), iRemoteVolume, iPhoneVolume)) - if (iRemoteVolume != iPhoneVolume) + TRACE_INFO((_L("Remote Volume = %d, iPhoneVolume = %d"), aRemoteVol, iPhoneVolume)) + TInt err( KErrNotFound ); + if (aRemoteVol != iPhoneVolume) { - TInt event = (iRemoteVolume > iPhoneVolume) ? KPSVolumeUpClicked : KPSVolumeDownClicked; - TInt err = iVolKeyEventProperty.Set(event); - if (err) - { - TRACE_ERROR((_L("Set KMediaKeysVolumeKeyEvent err %d"), err)); - } - iState = ESetPhoneVolume; + TInt event = (aRemoteVol > iPhoneVolume) ? KPSVolumeUpClicked : KPSVolumeDownClicked; + err = iVolKeyEventProperty.Set(event); + TRACE_INFO((_L("Set KMediaKeysVolumeKeyEvent click %d err %d"), event, err)); } - else - { - iState = ESubscribePhoneVolume; - } + iState = err ? ESubscribePhoneVolume : ESetPhoneVolume; } // ----------------------------------------------------------------------------- @@ -205,6 +203,36 @@ } // ----------------------------------------------------------------------------- +// CBTRCCVolumeLevelControllerBase::GetCurrentRemoteVolume +// ----------------------------------------------------------------------------- +// +TInt CBTRCCVolumeLevelControllerBase::GetCurrentRemoteVolume() + { + return iRemoteVolume; + } + +// ----------------------------------------------------------------------------- +// CBTRCCVolumeLevelControllerBase::RoundRemoteVolume +// ----------------------------------------------------------------------------- +// +TInt CBTRCCVolumeLevelControllerBase::RoundRemoteVolume(TInt /*aPrevPhVol*/) + { + TRACE_FUNC + // default implementation + return iRemoteVolume; + } + +// ----------------------------------------------------------------------------- +// CBTRCCVolumeLevelControllerBase::ScalePhoneVolume +// ----------------------------------------------------------------------------- +// +void CBTRCCVolumeLevelControllerBase::ScalePhoneVolume(TInt& /*aVolume*/) + { + TRACE_FUNC + // default implementation + } + +// ----------------------------------------------------------------------------- // CBTRCCVolumeLevelControllerBase::RequestCompletedL // ----------------------------------------------------------------------------- // @@ -213,7 +241,9 @@ TRACE_FUNC if(aActive.ServiceId() == KVolumeChangeListenerServiceId) { + TInt prevPhVol = iPhoneVolume; TInt err = GetPhoneVolume(iPhoneVolume); + ScalePhoneVolume(iPhoneVolume); if(!err && !aErr && iPhoneVolume > -1) { @@ -224,7 +254,8 @@ AdjustRemoteVolume(iPhoneVolume); break; case ESetPhoneVolume: - SetPhoneVolume(); + TInt remoteVol = RoundRemoteVolume(prevPhVol); + SetPhoneVolume(remoteVol); break; } } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btserviceutil/bwins/btserviceutilu.def --- a/bluetoothengine/btserviceutil/bwins/btserviceutilu.def Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btserviceutil/bwins/btserviceutilu.def Mon May 17 11:06:23 2010 +0300 @@ -30,4 +30,6 @@ ?NewL@CBtDevRepository@@SAPAV1@XZ @ 29 NONAME ; class CBtDevRepository * CBtDevRepository::NewL(void) ??1CBtSimpleActive@@UAE@XZ @ 30 NONAME ; CBtSimpleActive::~CBtSimpleActive(void) ?Device@CBtDevRepository@@QBEPBVCBtDevExtension@@ABVTBTDevAddr@@@Z @ 31 NONAME ; class CBtDevExtension const * CBtDevRepository::Device(class TBTDevAddr const &) const + ?ReInitialize@CBtDevRepository@@QAEXXZ @ 32 NONAME ; void CBtDevRepository::ReInitialize(void) + ?IsHeadset@CBtDevExtension@@SAHABVTBTDeviceClass@@@Z @ 33 NONAME ; int CBtDevExtension::IsHeadset(class TBTDeviceClass const &) diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btserviceutil/eabi/btserviceutilu.def --- a/bluetoothengine/btserviceutil/eabi/btserviceutilu.def Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btserviceutil/eabi/btserviceutilu.def Mon May 17 11:06:23 2010 +0300 @@ -34,4 +34,10 @@ _ZNK16CBtDevRepository10AllDevicesEv @ 33 NONAME _ZNK16CBtDevRepository13IsInitializedEv @ 34 NONAME _ZNK16CBtDevRepository6DeviceERK10TBTDevAddr @ 35 NONAME + _ZNK15CBtDevExtension23ServiceConnectionStatusEv @ 36 NONAME + _ZN16CBtDevRepository12ReInitializeEv @ 37 NONAME + _ZN15CBtDevExtension17IsJustWorksBondedERK17TBTNamelessDevice @ 38 NONAME + _ZN15CBtDevExtension17IsUserAwareBondedERK17TBTNamelessDevice @ 39 NONAME + _ZN15CBtDevExtension8IsBondedERK17TBTNamelessDevice @ 40 NONAME + _ZN15CBtDevExtension9IsHeadsetERK14TBTDeviceClass @ 41 NONAME diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btserviceutil/export/btdevextension.h --- a/bluetoothengine/btserviceutil/export/btdevextension.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btserviceutil/export/btdevextension.h Mon May 17 11:06:23 2010 +0300 @@ -116,6 +116,15 @@ IMPORT_C static TBool IsUserAwareBonded( const TBTNamelessDevice &dev ); /** + * Guesses if the given device is a headset. + * + * @param the Class of Device of the device of which the type is + * determined. + * @return ETrue if it is probably a headset. EFalse otherwise. + */ + IMPORT_C static TBool IsHeadset( const TBTDeviceClass &aCod ); + + /** * Returns the display name of this device for end users. * @return the friendly name of the device if it is available; else, the device * name if it is available; otherwise, the BDADDR seperated with ":". diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btserviceutil/export/btdevrepository.h --- a/bluetoothengine/btserviceutil/export/btdevrepository.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btserviceutil/export/btdevrepository.h Mon May 17 11:06:23 2010 +0300 @@ -49,7 +49,7 @@ * registry update events. * */ - virtual void RepositoryInitialiazed() = 0; + virtual void RepositoryInitialized() = 0; /** * Callback to notify that a device has been deleted from BT registry. @@ -57,14 +57,14 @@ * * @param aAddr the bd_addr of the deleted device */ - virtual void BtDeviceDeleted( const TBTDevAddr& aAddr ) = 0; + virtual void DeletedFromRegistry( const TBTDevAddr& aAddr ) = 0; /** * Callback to notify that the device has been added to BT registry. * * @param aDevice the device that has been added to registry */ - virtual void BtDeviceAdded( const CBtDevExtension& aDevice ) = 0; + virtual void AddedToRegistry( const CBtDevExtension& aDevice ) = 0; /** * Callback to notify that the property of a device in BT registry has been @@ -77,8 +77,20 @@ * TBTNamelessDevice::TBTDeviceSet for the meanings of the bits * in this parameter. */ - virtual void BtDeviceChangedInRegistry( - const CBtDevExtension& aDevice, TUint aSimilarity ) = 0; + virtual void ChangedInRegistry( + const CBtDevExtension& aDevice, TUint aSimilarity ) = 0; + + /** + * Callback to notify that the status of service (limited to + * services maintained in btengsrv scope) connections with + * a device has changed. + * + * @param aDevice the device to which the status change refers + * @param aConnected ETrue if at least one service is currently connected. + * EFalse if no service is currently connected. + */ + virtual void ServiceConnectionChanged( + const CBtDevExtension& aDevice, TBool aConnected ) = 0; }; /** @@ -136,6 +148,16 @@ */ IMPORT_C const CBtDevExtension* Device( const TBTDevAddr& aAddr ) const; + /** + * Forces the repository to initialize its data store. + * At Initialization completion, corresponding callback will be invoked. + * Initialization completion means the repository has retieved all + * Bluetooth devices from BT registry, and it is subscribing to + * registry update events. + * + */ + IMPORT_C void ReInitialize(); + private: /** diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btserviceutil/inc/btdevrepositoryimpl.h --- a/bluetoothengine/btserviceutil/inc/btdevrepositoryimpl.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btserviceutil/inc/btdevrepositoryimpl.h Mon May 17 11:06:23 2010 +0300 @@ -86,6 +86,16 @@ const CBtDevExtension* Device( const TBTDevAddr& aAddr ) const; /** + * Forces the repository to initialize its data store. + * At Initialization completion, corresponding callback will be invoked. + * Initialization completion means the repository has retieved all + * Bluetooth devices from BT registry, and it is subscribing to + * registry update events. + * + */ + void ReInitialize(); + + /** * Returns the service (limited to services managed in bteng scope) * level connection status of the specified device. * diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btserviceutil/src/btdevextension.cpp --- a/bluetoothengine/btserviceutil/src/btdevextension.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btserviceutil/src/btdevextension.cpp Mon May 17 11:06:23 2010 +0300 @@ -90,7 +90,7 @@ // IsBonded // --------------------------------------------------------------------------- // -TBool CBtDevExtension::IsBonded( const TBTNamelessDevice &dev ) +EXPORT_C TBool CBtDevExtension::IsBonded( const TBTNamelessDevice &dev ) { // IsValidPaired tells if the paired bit of dev is valid // and IsPaired tells if the device is paired or not: @@ -105,7 +105,7 @@ // IsJustWorksBonded // --------------------------------------------------------------------------- // -TBool CBtDevExtension::IsJustWorksBonded( const TBTNamelessDevice &dev ) +EXPORT_C TBool CBtDevExtension::IsJustWorksBonded( const TBTNamelessDevice &dev ) { return IsBonded( dev ) && dev.LinkKeyType() == ELinkKeyUnauthenticatedNonUpgradable; @@ -115,7 +115,7 @@ // IsUserAwareBonded // --------------------------------------------------------------------------- // -TBool CBtDevExtension::IsUserAwareBonded( const TBTNamelessDevice &dev ) +EXPORT_C TBool CBtDevExtension::IsUserAwareBonded( const TBTNamelessDevice &dev ) { if ( IsJustWorksBonded( dev ) ) { @@ -130,6 +130,25 @@ return IsBonded( dev ); } +// --------------------------------------------------------------------------- +// IsHeadset +// --------------------------------------------------------------------------- +// +EXPORT_C TBool CBtDevExtension::IsHeadset( const TBTDeviceClass &aCod ) + { + if ( ( aCod.MajorServiceClass() & EMajorServiceAudioService ) && + ( aCod.MajorDeviceClass() & EMajorDeviceAudioDevice ) ) + { + if (aCod.MinorDeviceClass() == EMinorDeviceAVHandsfree || + aCod.MinorDeviceClass() == EMinorDeviceAVCarAudio) + { + // This is the typical CoD setting used by carkits: + return false; + } + return true; + } + return false; + } // --------------------------------------------------------------------------- // @@ -173,7 +192,7 @@ // ServiceConnectionStatus() // --------------------------------------------------------------------------- // -TBTEngConnectionStatus CBtDevExtension::ServiceConnectionStatus() const +EXPORT_C TBTEngConnectionStatus CBtDevExtension::ServiceConnectionStatus() const { return iServiceStatus; } @@ -219,8 +238,6 @@ iServiceStatus = aStatus; } - - // --------------------------------------------------------------------------- // UpdateL() // --------------------------------------------------------------------------- diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btserviceutil/src/btdevrepository.cpp --- a/bluetoothengine/btserviceutil/src/btdevrepository.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btserviceutil/src/btdevrepository.cpp Mon May 17 11:06:23 2010 +0300 @@ -107,3 +107,12 @@ { return iImpl->Device( aAddr ); } + +// --------------------------------------------------------------------------- +// Device +// --------------------------------------------------------------------------- +// +EXPORT_C void CBtDevRepository::ReInitialize() + { + return iImpl->ReInitialize(); + } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btserviceutil/src/btdevrepositoryimpl.cpp --- a/bluetoothengine/btserviceutil/src/btdevrepositoryimpl.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btserviceutil/src/btdevrepositoryimpl.cpp Mon May 17 11:06:23 2010 +0300 @@ -174,6 +174,25 @@ } // --------------------------------------------------------------------------- +// ReInitialize +// --------------------------------------------------------------------------- +// +void CBtDevRepositoryImpl::ReInitialize() + { + iInitialized = EFalse; + if ( !iRegistryActive->IsActive() ) + { + CreateRemoteDeviceView(); + } + else + { + // This counter-increasing + // will force to re-create a registry view later. + ++iNotHandledRegEventCounter; + } + } + +// --------------------------------------------------------------------------- // From class MBtSimpleActiveObserver. // Checks if there is an authentication result. // --------------------------------------------------------------------------- @@ -258,10 +277,22 @@ TInt pos = iDevices.Find( aAddr, MatchDeviceAddress ); if ( pos > -1 ) { + TBTEngConnectionStatus old = iDevices[pos]->ServiceConnectionStatus(); TBTEngConnectionStatus status = EBTEngNotConnected; // error returned from the call is treated as not connected. (void) iBtengConn->IsConnected( aAddr, status ); iDevices[pos]->SetServiceConnectionStatus( status ); + + if ( old != status && + ( status == EBTEngConnected || + status == EBTEngNotConnected ) ) + { + for ( TInt i = 0; i < iObservers.Count(); ++i ) + { + iObservers[i]->ServiceConnectionChanged( + *(iDevices[pos]), status == EBTEngConnected ); + } + } } } @@ -356,7 +387,7 @@ } for ( TInt i = 0; i < iObservers.Count(); ++i ) { - iObservers[i]->RepositoryInitialiazed(); + iObservers[i]->RepositoryInitialized(); } } } @@ -395,9 +426,9 @@ devsFromReg.Remove( pos ); if ( iInitialized && changed ) { - for ( TInt i = 0; i < iObservers.Count(); ++i ) + for ( TInt counter = 0; counter < iObservers.Count(); ++counter ) { - iObservers[i]->BtDeviceChangedInRegistry( *iDevices[i], similarity ); + iObservers[counter]->ChangedInRegistry( *iDevices[i], similarity ); } } } @@ -410,16 +441,16 @@ iDevices.Remove( i ); if ( iInitialized ) { - for ( TInt i = 0; i < iObservers.Count(); ++i ) + for ( TInt counter = 0; counter < iObservers.Count(); ++counter ) { - iObservers[i]->BtDeviceDeleted( addr ); + iObservers[counter]->DeletedFromRegistry( addr ); } } } } // Remaining devices in iRegRespRemoteDevices are new devices: - for ( TInt i = 0; i < devsFromReg.Count() ; i++ ) + for ( TInt i = devsFromReg.Count()- 1; i > -1 ; --i ) { CBtDevExtension* devExt = CBtDevExtension::NewLC( devsFromReg[i] ); iDevices.AppendL( devExt ); @@ -427,9 +458,9 @@ devsFromReg.Remove( i ); if ( iInitialized ) { - for ( TInt i = 0; i < iObservers.Count(); ++i ) + for ( TInt counter = 0; counter < iObservers.Count(); ++counter ) { - iObservers[i]->BtDeviceAdded( *iDevices[ iDevices.Count() - 1 ] ); + iObservers[counter]->AddedToRegistry( *devExt ); } } } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btcpplugin/btcpplugin.cpp --- a/bluetoothengine/btui/btcpplugin/btcpplugin.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btcpplugin/btcpplugin.cpp Mon May 17 11:06:23 2010 +0300 @@ -17,7 +17,7 @@ #include -#include "BtCpPlugin.h" +#include "btcpplugin.h" #include "btcpuimainview.h" #include "btcpuisettingitem.h" diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btcpplugin/btcpplugin.pro --- a/bluetoothengine/btui/btcpplugin/btcpplugin.pro Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btcpplugin/btcpplugin.pro Mon May 17 11:06:23 2010 +0300 @@ -34,12 +34,15 @@ btcpuibaseview.h \ btcpuimainview.h \ btcpuisearchview.h \ - btcpuisettingitem.h + btcpuideviceview.h \ + btcpuisettingitem.h \ + btuiviewutil.h SOURCES += btcpplugin.cpp \ btcpuibaseview.cpp \ btcpuimainview.cpp \ btcpuisearchview.cpp \ + btcpuideviceview.cpp \ btcpuisettingitem.cpp symbian: { diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btcpplugin/btcpplugin.qrc --- a/bluetoothengine/btui/btcpplugin/btcpplugin.qrc Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btcpplugin/btcpplugin.qrc Mon May 17 11:06:23 2010 +0300 @@ -22,5 +22,6 @@ docml/bt-main-view.docml docml/bt-search-view.docml + docml/bt-device-view.docml diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btcpplugin/btcpuibaseview.cpp --- a/bluetoothengine/btui/btcpplugin/btcpuibaseview.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btcpplugin/btcpuibaseview.cpp Mon May 17 11:06:23 2010 +0300 @@ -21,15 +21,19 @@ */ #include "btcpuibaseview.h" -#include +#include /*! Constructor. */ -BtCpUiBaseView::BtCpUiBaseView( BtuiModel &model, QGraphicsItem *parent ) - :CpBaseSettingView( 0 , parent ),mModel(model) +BtCpUiBaseView::BtCpUiBaseView( + BtSettingModel &settingModel, + BtDeviceModel &deviceModel, + QGraphicsItem *parent ) + :CpBaseSettingView( 0 , parent ), + mSettingModel( &settingModel ), + mDeviceModel( &deviceModel ) { - } /*! diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btcpplugin/btcpuibaseview.h --- a/bluetoothengine/btui/btcpplugin/btcpuibaseview.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btcpplugin/btcpuibaseview.h Mon May 17 11:06:23 2010 +0300 @@ -26,7 +26,8 @@ #include #include #include -#include +#include +#include /*! \class BtUiBaseView @@ -42,19 +43,29 @@ virtual ~BtCpUiBaseView(); virtual void activateView( const QVariant& value, int cmdId ) = 0; virtual void deactivateView() = 0; - + virtual void switchToPreviousView() = 0; + signals: -protected: - explicit BtCpUiBaseView( BtuiModel &model, QGraphicsItem *parent = 0); +protected: + explicit BtCpUiBaseView( + BtSettingModel &settingModel, + BtDeviceModel &deviceModel, + QGraphicsItem *parent = 0); + virtual void setSoftkeyBack() = 0; - virtual void switchToPreviousView() = 0; + + BtSettingModel &getSettingModel(); + BtDeviceModel &getDeviceModel(); protected: - //Does not own this model. - BtuiModel &mModel; - + // do not owned + BtSettingModel *mSettingModel; + + //do not owned + BtDeviceModel *mDeviceModel; + QGraphicsItem *mParent; int mPreviousViewId; diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btcpplugin/btcpuideviceview.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/btcpuideviceview.cpp Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,473 @@ +/* + * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0"" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ + +#include "btcpuideviceview.h" +#include "btuiviewutil.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "btcpuimainview.h" +#include +#include +#include + +// docml to load +const char* BTUI_DEVICEVIEW_DOCML = ":/docml/bt-device-view.docml"; + + +BtCpUiDeviceView::BtCpUiDeviceView( + BtSettingModel &settingModel, + BtDeviceModel &deviceModel, + QGraphicsItem *parent) : + BtCpUiBaseView(settingModel,deviceModel,parent), + mPairStatus(false), mConnectStatus(false), mConnectable(false), mAbstractDelegate(0) +{ + mDeviceIndex = QModelIndex();//is it needed to initialize mIndex??? + + mMainView = (BtCpUiMainView *) parent; + + mMainWindow = hbInstance->allMainWindows().first(); + + mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this); + BTUI_ASSERT_X(mSoftKeyBackAction, "BtCpUiBaseView::BtCpUiBaseView", "can't create back action"); + + // read view info from docml file + + // Create view for the application. + // Set the name for the view. The name should be same as the view's + // name in docml. + setObjectName("bt_device_view"); + + QObjectList objectList; + objectList.append(this); + // Pass the view to documentloader. Document loader uses this view + // when docml is parsed, instead of creating new view. + mLoader = new HbDocumentLoader(); + mLoader->setObjectTree(objectList); + + bool ret = false; + + bool ok = false; + mLoader->load( BTUI_DEVICEVIEW_DOCML, &ok ); + // Exit if the file format is invalid + BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file" ); + + // Set title for the control panel + // ToDo: check if deprecated API + setTitle("Control Panel"); + + // assign automatically created widgets to local variables + + mGroupBox = 0; + mGroupBox = qobject_cast( mLoader->findWidget( "groupBox_deviceView" ) ); + BTUI_ASSERT_X( mGroupBox != 0, "bt-device-view", "Device groupbox not found" ); + + mDeviceIcon=0; + //can't use qobject_cast since HbIcon is not derived from QObject! + mDeviceIcon = qobject_cast( mLoader->findWidget( "deviceIcon" ) ); + BTUI_ASSERT_X( mDeviceIcon != 0, "bt-device-view", "Device Icon not found" ); + + mDeviceName=0; + mDeviceName = qobject_cast( mLoader->findWidget( "deviceName" ) ); + BTUI_ASSERT_X( mDeviceName != 0, "bt-device-view", "Device Name not found" ); + ret = connect(mDeviceName, SIGNAL(editingFinished ()), this, SLOT(changeBtDeviceName())); + + mDeviceCategory=0; + mDeviceCategory = qobject_cast( mLoader->findWidget( "deviceCategory" ) ); + BTUI_ASSERT_X( mDeviceCategory != 0, "bt-device-view", "Device Category not found" ); + + mDeviceStatus=0; + mDeviceStatus = qobject_cast( mLoader->findWidget( "deviceStatus" ) ); + BTUI_ASSERT_X( mDeviceStatus != 0, "bt-device-view", "Device status not found" ); + + mPair_Unpair=0; + mPair_Unpair = qobject_cast( mLoader->findWidget( "pushButton_0" ) ); + BTUI_ASSERT_X( mPair_Unpair != 0, "bt-device-view", "pair/unpair button not found" ); + ret = connect(mPair_Unpair, SIGNAL(clicked()), this, SLOT(pairUnpair())); + BTUI_ASSERT_X( ret, "BtCpUiDeviceView::BtCpUiDeviceView", "can't connect pair button" ); + + mConnect_Disconnect=0; + mConnect_Disconnect = qobject_cast( mLoader->findWidget( "pushButton_1" ) ); + BTUI_ASSERT_X( mConnect_Disconnect != 0, "bt-device-view", "connect/disconnect button not found" ); + ret = connect(mConnect_Disconnect, SIGNAL(clicked()), this, SLOT(connectDisconnect())); + BTUI_ASSERT_X( ret, "BtCpUiDeviceView::BtCpUiDeviceView", "can't connect disconnect button" ); + + mDeviceSetting = 0; + mDeviceSetting = qobject_cast( mLoader->findWidget( "pushButton_2" ) ); + BTUI_ASSERT_X( mDeviceSetting != 0, "bt-device-view", "settings button not found" ); + + // read landscape orientation section from docml file if needed + // mOrientation = ((BTUIViewManager*)parent)->orientation(); + mOrientation = Qt::Vertical; + if (mOrientation == Qt::Horizontal) { + mLoader->load(BTUI_DEVICEVIEW_DOCML, "landscape", &ok); + BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: landscape section problem" ); + } + +} + +BtCpUiDeviceView::~BtCpUiDeviceView() +{ + setNavigationAction(0); + delete mSoftKeyBackAction; + if(mAbstractDelegate) + { + delete mAbstractDelegate; + mAbstractDelegate = 0; + } +} + + +void BtCpUiDeviceView::setSoftkeyBack() +{ + if (navigationAction() != mSoftKeyBackAction) { + setNavigationAction(mSoftKeyBackAction); + connect( mSoftKeyBackAction, SIGNAL(triggered()), this, SLOT(switchToPreviousView()) ); + } +} + +void BtCpUiDeviceView::switchToPreviousView() +{ + BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView"); + mMainView->switchToPreviousView(); +} + +void BtCpUiDeviceView::activateView( const QVariant& value, int cmdId ) +{ + Q_UNUSED(cmdId); + + setSoftkeyBack(); + + QModelIndex index = value.value(); + mDeviceBdAddr = (mDeviceModel->data(index, BtDeviceModel::ReadableBdaddrRole)); + + //activate view is called when device is selected + clearViewData(); + updateDeviceData(); + + bool ret(false); + ret=connect(mDeviceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), + this, SLOT(updateDeviceData())); + BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::activateView", "dataChanged() connect failed"); +} + +void BtCpUiDeviceView::deactivateView() +{ +} + +void BtCpUiDeviceView::clearViewData() +{ + mDeviceIcon->clear(); + mDeviceCategory->clear(); + mDeviceStatus->clear(); + + mPairStatus = false; + mConnectStatus = false; + mConnectable = false; +} + +void BtCpUiDeviceView::updateDeviceData() +{ + QModelIndex localIndex = mSettingModel->index( BtSettingModel::LocalBtNameRow, 0); + QString localName = (mSettingModel->data(localIndex,BtSettingModel::settingDisplayRole)).toString(); + QString groupBoxTitle (tr("Bluetooth-")); + mGroupBox->setHeading(groupBoxTitle.append(localName)); + //Get the QModelIndex of the device using the device BDAddres + QModelIndex start = mDeviceModel->index(0,0); + QModelIndexList indexList = mDeviceModel->match(start,BtDeviceModel::ReadableBdaddrRole, mDeviceBdAddr); + mDeviceIndex = indexList.at(0); + + //populate device view with device data fetched from UiModel + QString deviceName = (mDeviceModel->data(mDeviceIndex, + BtDeviceModel::NameAliasRole)).toString(); + mDeviceName->setPlainText(deviceName); + + int cod = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::CoDRole)).toInt(); + + int majorRole = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::MajorPropertyRole)).toInt(); + int minorRole = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::MinorPropertyRole)).toInt(); + + setDeviceCategory(cod, majorRole, minorRole); + setDeviceStatus(majorRole); + setTextAndVisibilityOfButtons(); +} + +void BtCpUiDeviceView::setDeviceCategory(int cod,int majorRole, int minorRole) +{ + //TODO: change the hardcoded numeric value to enumerations + if (cod) + { + if (majorRole & 0x00020000) + { + //this is a phone + mDeviceCategory->setPlainText(tr("Phone")); + } + else if (majorRole & 0x00010000) + { + //this is a computer + mDeviceCategory->setPlainText(tr("Computer")); + + } + else if (majorRole & 0x00080000) + { + //this is a A/V device + //int minorRole = (mDeviceModel->data(mIndex,BtDeviceModel::MinorPropertyRole)).toInt(); + if ( minorRole & 0x00000002) + { + //this is a Headset, it is possible to connect + mConnectable = true; + mDeviceCategory->setPlainText(tr("Headset")); + } + } + else + { + mDeviceCategory->setPlainText(tr("Uncategorized Dev")); + } + + } + + +} +void BtCpUiDeviceView::setDeviceStatus(int majorRole) +{ + //TODO: change the hardcoded numeric value to enumerations + QString deviceStatus; + if (majorRole & 0x00000001) + { + deviceStatus = deviceStatus.append(tr("Paired")); + mPairStatus = true; + } + else + { + mPairStatus = false; + } + + if ((majorRole & 0x00000020)&& (mConnectable)) + { + //if the device is connected and it is a headset NOTE! two phone can be paired but not be connected + deviceStatus = deviceStatus.append(tr(", connected")); + mConnectStatus = true; + } + else + { + mConnectStatus = false; + } + mDeviceStatus->setPlainText(deviceStatus); + + + +} + +void BtCpUiDeviceView::setTextAndVisibilityOfButtons() +{ + if (mPairStatus) + { + mPair_Unpair->setText(tr("Unpair")); + } + else + { + mPair_Unpair->setText(tr("Pair")); + } + + if (mConnectable) + { + if (mConnectStatus) + { + mConnect_Disconnect->setText(tr("Disconnect")); + } + else + { + mConnect_Disconnect->setText(tr("Connect")); + } + + } + else + { + //it is not possible to connect, set the button invisible + mConnect_Disconnect->setVisible(false); + } + + mDeviceSetting->setVisible(false); + +} + +void BtCpUiDeviceView::changeBtDeviceName() +{ + /* + if (!mAbstractDelegate) + { + mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::DeviceName, mModel); + connect( mAbstractDelegate, SIGNAL(commandCompleted(int,QVariant)), this, SLOT(btNameDelegateCompleted(int,QVariant)) ); + mAbstractDelegate->exec(mDeviceNameEdit->text ()); + } + */ + +} + +void BtCpUiDeviceView::pairUnpair() +{ + if (mPairStatus) + { + //if the device is paired, call unpairDevice() when the button is tabbed + unpairDevice(); + } + else + { + //if the device is unpaired, call pairDevice() when the button is tabbed + pairDevice(); + + } + + +} + +void BtCpUiDeviceView::connectDisconnect() +{ + if (mConnectStatus) + { + //if the device is connected, call disconnectDevice() when the button is tabbed + disconnectDevice(); + } + else + { + //if the device is disconnected, call connectDevice() when the button is tabbed + connectDevice(); + + } +} + +void BtCpUiDeviceView::pairDevice() +{ + if (!mAbstractDelegate)//if there is no other delegate running + { + QVariant params; + params.setValue(mDeviceIndex); + mAbstractDelegate = BtDelegateFactory::newDelegate( + BtDelegate::Pair, mSettingModel, mDeviceModel); + connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(pairDelegateCompleted(int)) ); + mAbstractDelegate->exec(params); + } + +} + +void BtCpUiDeviceView::pairDelegateCompleted(int status) +{ + Q_UNUSED(status); + //TODO: handle the error here + if (mAbstractDelegate) + { + disconnect(mAbstractDelegate); + delete mAbstractDelegate; + mAbstractDelegate = 0; + } +} + +void BtCpUiDeviceView::unpairDevice() +{ + if (!mAbstractDelegate)//if there is no other delegate running + { + QVariant params; + params.setValue(mDeviceIndex); + mAbstractDelegate = BtDelegateFactory::newDelegate( + BtDelegate::Unpair, mSettingModel, mDeviceModel); + connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(unpairDelegateCompleted(int)) ); + mAbstractDelegate->exec(params); + } + + +} + +void BtCpUiDeviceView::unpairDelegateCompleted(int status) +{ + Q_UNUSED(status); + //TODO: handle the error here + if (mAbstractDelegate) + { + disconnect(mAbstractDelegate); + delete mAbstractDelegate; + mAbstractDelegate = 0; + } +} + +void BtCpUiDeviceView::connectDevice() +{ + + + if (!mAbstractDelegate)//if there is no other delegate running + { + QVariant params; + params.setValue(mDeviceIndex); + mAbstractDelegate = BtDelegateFactory::newDelegate( + BtDelegate::Connect, mSettingModel, mDeviceModel); + connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(connectDelegateCompleted(int)) ); + mAbstractDelegate->exec(params); + } + + +} + +void BtCpUiDeviceView::connectDelegateCompleted(int status) +{ + Q_UNUSED(status); + if (mAbstractDelegate) + { + disconnect(mAbstractDelegate); + delete mAbstractDelegate; + mAbstractDelegate = 0; + } + + +} + +void BtCpUiDeviceView::disconnectDevice() +{ + if (!mAbstractDelegate)//if there is no other delegate running + { + QVariant params; + params.setValue(mDeviceIndex); + mAbstractDelegate = BtDelegateFactory::newDelegate( + BtDelegate::Disconnect, mSettingModel, mDeviceModel); + connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(disconnectDelegateCompleted(int)) ); + mAbstractDelegate->exec(params); + } + +} + +void BtCpUiDeviceView::disconnectDelegateCompleted(int status) +{ + Q_UNUSED(status); + if (mAbstractDelegate) + { + disconnect(mAbstractDelegate); + delete mAbstractDelegate; + mAbstractDelegate = 0; + } + + +} + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btcpplugin/btcpuideviceview.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/btcpuideviceview.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0"" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ + +#ifndef BTCPUIDEVICEVIEW_H +#define BTCPUIDEVICEVIEW_H + +#include +#include +#include +#include "btcpuibaseview.h" + +class HbGroupBox; +class HbLabel; +class HbTextEdit; +class HbPushButton; +class HbIcon; +class HbDocumentLoader; +class HbListView; +class HbDataFormModel; +class HbDataFormModelItem; +class CpSettingFormItemData; +class BtAbstractDelegate; + + +class BtCpUiDeviceView : public BtCpUiBaseView +{ + Q_OBJECT + +public: + explicit BtCpUiDeviceView( + BtSettingModel &settingModel, + BtDeviceModel &deviceModel, + QGraphicsItem *parent = 0); + virtual ~BtCpUiDeviceView(); + virtual void activateView( const QVariant& value, int cmdId ); + virtual void deactivateView(); + virtual void setSoftkeyBack(); + +public slots: + + virtual void switchToPreviousView(); + void updateDeviceData(); + void changeBtDeviceName(); + void pairUnpair(); + void connectDisconnect(); + void pairDelegateCompleted(int status); + void unpairDelegateCompleted(int status); + void connectDelegateCompleted(int status); + void disconnectDelegateCompleted(int status); + +private: + void clearViewData(); + void pairDevice(); + void unpairDevice(); + void connectDevice(); + void disconnectDevice(); + void setDeviceCategory(int cod, int majorRole, int minorRole);//cod:class of device + void setDeviceStatus(int majorRole); + void setTextAndVisibilityOfButtons(); + +private: + HbDocumentLoader *mLoader; + HbGroupBox *mGroupBox; + HbLabel *mDeviceIcon; + HbTextEdit *mDeviceName; + HbLabel *mDeviceCategory; + HbLabel *mDeviceStatus; + + HbPushButton *mPair_Unpair; + HbPushButton *mConnect_Disconnect; + HbPushButton *mDeviceSetting; + + + // data structures for switching between views + bool mEventFilterInstalled; + int mAutoCmdId; + Qt::Orientation mOrientation; + + HbMainWindow* mMainWindow; + BtCpUiBaseView* mMainView; + //BtCpUiBaseView* mDeviceView; + HbAction *mSoftKeyBackAction; + + QModelIndex mDeviceIndex; + QVariant mDeviceBdAddr; + + //true -> device is paired; false -> device is unpaired + bool mPairStatus; + + //true-> device is connected; false -> device is disconnected + bool mConnectStatus; + + //true -> device is connectable + //e.g. not possible to connect to a phone, but possible to connect to a headset + bool mConnectable; + + BtAbstractDelegate* mAbstractDelegate; + + +}; + +#endif diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btcpplugin/btcpuimainview.cpp --- a/bluetoothengine/btui/btcpplugin/btcpuimainview.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btcpplugin/btcpuimainview.cpp Mon May 17 11:06:23 2010 +0300 @@ -1,5 +1,5 @@ /* -* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" @@ -16,13 +16,14 @@ */ #include "btcpuimainview.h" +#include "btuiviewutil.h" #include #include #include -//#include "btuiviewutil.h" #include #include #include +#include #include #include #include @@ -33,6 +34,7 @@ #include #include #include "btcpuisearchview.h" +#include "btcpuideviceview.h" #include #include #include @@ -47,8 +49,12 @@ has been generated using Application Designer. */ -BtCpUiMainView::BtCpUiMainView( BtuiModel &model, QGraphicsItem *parent ) - : BtCpUiBaseView( model, parent ), mAbstractDelegate(0) +BtCpUiMainView::BtCpUiMainView( + BtSettingModel &settingModel, + BtDeviceModel &deviceModel, + QGraphicsItem *parent ) + : BtCpUiBaseView( settingModel, deviceModel, parent ), + mAbstractDelegate(0), mMainFilterModel(0) { bool ret(false); @@ -99,9 +105,12 @@ BTUI_ASSERT_X( mVisibilityMode != 0, "bt-main-view", "visibility combobox not found" ); mDeviceList=0; - mDeviceList = qobject_cast( mLoader->findWidget( "gridView" ) ); + mDeviceList = qobject_cast( mLoader->findWidget( "listView" ) ); BTUI_ASSERT_X( mDeviceList != 0, "bt-main-view", "Device List (grid view) not found" ); + ret = connect(mDeviceList, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex))); + BTUI_ASSERT_X( ret, "bt-search-view", "deviceSelected can't connect" ); + // listen for orientation changes ret = connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(changeOrientation(Qt::Orientation))); @@ -113,18 +122,28 @@ ret = connect(discoverAction, SIGNAL(triggered()), this, SLOT(goToDiscoveryView())); BTUI_ASSERT_X( ret, "bt-main-view", "orientation toggle can't connect" ); + //*********************Testing device view START****************************// + HbAction *removePairedDevices = static_cast( mLoader->findObject( "removePairedDevices" ) ); + BTUI_ASSERT_X( removePairedDevices, "bt-main-view", "remove action missing" ); + //ret = connect(removePairedDevices, SIGNAL(triggered()), this, SLOT(goToDeviceView())); + //BTUI_ASSERT_X( ret, "bt-main-view", "orientation toggle can't connect" ); + + + + //*********************Testing device view END****************************// + // load menu HbMenu *optionsMenu = qobject_cast(mLoader->findWidget("viewMenu")); BTUI_ASSERT_X( optionsMenu != 0, "bt-main-view", "Options menu not found" ); this->setMenu(optionsMenu); // update display when setting data changed - ret = connect(&mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), + ret = connect(mSettingModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(updateSettingItems(QModelIndex,QModelIndex))); BTUI_ASSERT_X( ret, "BtCpUiMainView::BtCpUiMainView", "can't connect dataChanged" ); - QModelIndex top = mModel.index( BtuiModel::LocalSettingRow, BtuiModel::BluetoothNameCol ); - QModelIndex bottom = mModel.index( BtuiModel::LocalSettingRow, BtuiModel::VisibilityCol ); + QModelIndex top = mSettingModel->index( BtSettingModel::LocalBtNameRow, 0 ); + QModelIndex bottom = mSettingModel->index( BtSettingModel::AllowedInOfflineRow, 0 ); // update name, power and visibility rows updateSettingItems( top, bottom ); @@ -135,7 +154,18 @@ createViews(); mCurrentView = this; mCurrentViewId = MainView; + + mMainFilterModel = new BtuiModelSortFilter(this); + + mMainFilterModel->setSourceModel( mDeviceModel ); + // filter to match only InRegistry devices + mMainFilterModel->addDeviceMajorFilter( + BtDeviceModel::InRegistry, + BtuiModelSortFilter::AtLeastMatch); + mDeviceList->setModel(mMainFilterModel); + + } /*! @@ -144,10 +174,14 @@ BtCpUiMainView::~BtCpUiMainView() { delete mLoader; // Also deletes all widgets that it constructed. + mMainWindow->removeView(mSearchView); delete mSearchView; - if (mAbstractDelegate) - { + + mMainWindow->removeView(mDeviceView); + delete mDeviceView; + + if (mAbstractDelegate) { delete mAbstractDelegate; } } @@ -159,7 +193,7 @@ { Q_UNUSED(value); Q_UNUSED(cmdId); - + } /*! @@ -180,6 +214,14 @@ changeView( SearchView, false, 0 ); } +void BtCpUiMainView::goToDeviceView(const QModelIndex& modelIndex) +{ + //the QModelIndex of the selected device should be given as parameter here + QVariant params; + params.setValue(modelIndex); + changeView( DeviceView, false, 0, params ); +} + Qt::Orientation BtCpUiMainView::orientation() { return mOrientation; @@ -189,7 +231,8 @@ { //Error handling has to be done. if (!mAbstractDelegate) { - mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::DeviceName, mModel); + mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::DeviceName, + mSettingModel, mDeviceModel); connect( mAbstractDelegate, SIGNAL(commandCompleted(int,QVariant)), this, SLOT(btNameDelegateCompleted(int,QVariant)) ); mAbstractDelegate->exec(mDeviceNameEdit->text ()); } @@ -202,9 +245,10 @@ { //Should we notify user this as Error...? HbNotificationDialog::launchDialog(hbTrId("Error")); - QModelIndex index = mModel.index( BtuiModel::LocalSettingRow, BtuiModel::BluetoothNameCol ); + QModelIndex index = mSettingModel->index( BtSettingModel::LocalBtNameRow,0 ); - mDeviceNameEdit->setText( mModel.data(index,BtuiModel::settingDisplay).toString() ); + mDeviceNameEdit->setText( mSettingModel->data( + index,BtSettingModel::settingDisplayRole).toString() ); } @@ -238,7 +282,8 @@ } //Error handling has to be done. if (!mAbstractDelegate) { - mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::Visibility, mModel); + mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::Visibility, + mSettingModel, mDeviceModel); connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(visibilityDelegateCompleted(int)) ); mAbstractDelegate->exec(list); } @@ -254,14 +299,14 @@ //Should we notify this error to user..? HbNotificationDialog::launchDialog(hbTrId("Error")); - QModelIndex index = mModel.index( BtuiModel::LocalSettingRow, BtuiModel::VisibilityCol ); + QModelIndex index = mSettingModel->index( BtSettingModel::VisibilityRow, 0 ); ret = disconnect(mVisibilityMode, SIGNAL(currentIndexChanged (int)), this, SLOT(visibilityChanged (int))); BTUI_ASSERT_X( ret, "BtCpUiMainView::setPrevVisibilityMode", "can't disconnect signal" ); - mVisibilityMode->setCurrentIndex ( visibilityModeToIndex((VisibilityMode) - mModel.data(index,BtuiModel::SettingValue).toInt()) ); + mVisibilityMode->setCurrentIndex ( visibilityModeToIndex((VisibilityMode) + mSettingModel->data(index,BtSettingModel::SettingValueRole).toInt()) ); //Handle Visibility Change User Interaction ret = connect(mVisibilityMode, SIGNAL(currentIndexChanged (int)), @@ -315,32 +360,31 @@ } /*! - Slot for receiving notification of data changes from the model. + Slot for receiving notification of local setting changes from the model. Identify the setting changed and update the corresponding UI item. */ void BtCpUiMainView::updateSettingItems(const QModelIndex &topLeft, const QModelIndex &bottomRight) { // update only the part of the view specified by the model's row(s) - - for (int i=topLeft.column(); i <= bottomRight.column(); i++) { - QModelIndex index = mModel.index( BtuiModel::LocalSettingRow, i); + for (int i=topLeft.row(); i <= bottomRight.row(); i++) { + QModelIndex index = mSettingModel->index( i, 0); // Distinguish which setting value is changed. switch ( i ) { - case BtuiModel::BluetoothNameCol : - mDeviceNameEdit->setText( mModel.data(index,BtuiModel::settingDisplay).toString() ); + case BtSettingModel::LocalBtNameRow : + mDeviceNameEdit->setText( + mSettingModel->data(index,BtSettingModel::settingDisplayRole).toString() ); break; - case BtuiModel::PowerStateCol: - mPowerButton->setText( mModel.data(index,BtuiModel::settingDisplay).toString() ); + case BtSettingModel::PowerStateRow: + mPowerButton->setText( mSettingModel->data(index, + BtSettingModel::settingDisplayRole).toString() ); break; - case BtuiModel::VisibilityCol: + case BtSettingModel::VisibilityRow: mVisibilityMode->setCurrentIndex ( visibilityModeToIndex((VisibilityMode) - mModel.data(index,BtuiModel::SettingValue).toInt()) ); + mSettingModel->data(index,BtSettingModel::SettingValueRole).toInt()) ); break; } - } - - + } } /*! @@ -350,11 +394,12 @@ void BtCpUiMainView::changePowerState() { - QModelIndex index = mModel.index(BtuiModel::LocalSettingRow, BtuiModel::PowerStateCol); - QVariant powerState = mModel.data(index, Qt::EditRole); + QModelIndex index = mSettingModel->index(BtSettingModel::PowerStateRow, 0); + QVariant powerState = mSettingModel->data(index, Qt::EditRole); if (!mAbstractDelegate)//if there is no other delegate running { - mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::ManagePower, mModel); + mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::ManagePower, + mSettingModel, mDeviceModel ); connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(powerDelegateCompleted(int)) ); mAbstractDelegate->exec(powerState); } @@ -432,9 +477,11 @@ { Qt::Orientation orientation = mMainWindow->orientation(); // Create other views - mSearchView = new BtCpUiSearchView( mModel, this ); + mSearchView = new BtCpUiSearchView( *mSettingModel, *mDeviceModel, this ); mMainWindow->addView(mSearchView); - mDeviceView = 0; // ToDo: add this later + + mDeviceView = new BtCpUiDeviceView( *mSettingModel, *mDeviceModel, this ); + mMainWindow->addView(mDeviceView); mCurrentView = this; mCurrentViewId = MainView; @@ -482,6 +529,16 @@ } +void BtCpUiMainView::deviceSelected(const QModelIndex& modelIndex) +{ + QModelIndex index = mMainFilterModel->mapToSource(modelIndex); + + QVariant params; + params.setValue(index); + + changeView( DeviceView, false, 0, params ); +} + BtCpUiBaseView * BtCpUiMainView::idToView(int targetViewId) { switch (targetViewId) { @@ -502,13 +559,13 @@ */ void BtCpUiMainView::switchToPreviousViewReally() { - // jump to previous view of current view. - if( (mCurrentViewId >= 0) && (mCurrentViewId < LastView)) { - changeView( mPreviousViewIds[mCurrentViewId], true, 0 ); - } - else { - BTUI_ASSERT_X(false, "BtCpUiMainView::switchToPreviousViewReally", "invalid view id"); - } +// // jump to previous view of current view. +// if( (mCurrentViewId >= 0) && (mCurrentViewId < LastView)) { +// changeView( mPreviousViewIds[mCurrentViewId], true, 0 ); +// } +// else { +// BTUI_ASSERT_X(false, "BtCpUiMainView::switchToPreviousViewReally", "invalid view id"); +// } } @@ -517,8 +574,19 @@ } +/*! + Jump to previous view. This function is used when back button is pressed. + semantics slightly different than in other views, since this is called by other + views when a view switch is needed + */ void BtCpUiMainView::switchToPreviousView() { - + // jump to previous view of current view. + if( (mCurrentViewId >= 0) && (mCurrentViewId < LastView)) { + changeView( mPreviousViewIds[mCurrentViewId], true, 0 ); + } + else { + BTUI_ASSERT_X(false, "BtCpUiMainView::switchToPreviousView", "invalid view id"); + } } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btcpplugin/btcpuimainview.h --- a/bluetoothengine/btui/btcpplugin/btcpuimainview.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btcpplugin/btcpuimainview.h Mon May 17 11:06:23 2010 +0300 @@ -20,7 +20,7 @@ #include "btcpuibaseview.h" #include -#include +#include class HbLabel; class HbLineEdit; @@ -30,20 +30,23 @@ class HbDocumentLoader; class HbGridView; class BtAbstractDelegate; - +class HbListView; class BtCpUiMainView : public BtCpUiBaseView { Q_OBJECT public: - enum ViewIndex { - MainView, - SearchView, - DeviceView, - LastView - }; - explicit BtCpUiMainView( BtuiModel &model, QGraphicsItem *parent = 0 ); +// enum ViewIndex { +// MainView, +// SearchView, +// DeviceView, +// LastView +// }; + explicit BtCpUiMainView( + BtSettingModel &settingModel, + BtDeviceModel &deviceModel, + QGraphicsItem *parent = 0 ); ~BtCpUiMainView(); // from view manager void createViews(); @@ -60,9 +63,11 @@ void changeOrientation( Qt::Orientation orientation ); void itemActivated(QModelIndex index); void changePowerState(); + void updateSettingItems(const QModelIndex &topLeft, const QModelIndex &bottomRight); - + void deviceSelected(const QModelIndex& modelIndex); void goToDiscoveryView(); + void goToDeviceView(const QModelIndex& modelIndex); // from view manager void changeView(int targetViewId, bool fromBackButton, int cmdId, const QVariant& value = 0 ); @@ -95,8 +100,7 @@ HbLineEdit *mDeviceNameEdit; HbPushButton *mPowerButton; HbComboBox *mVisibilityMode; - QStringListModel *mVisiListModel; - HbGridView *mDeviceList; + HbListView *mDeviceList; // data structures for switching between views bool mEventFilterInstalled; @@ -115,6 +119,7 @@ //poiter to abstract delegate, and it is instantiated at runtime BtAbstractDelegate* mAbstractDelegate; + BtuiModelSortFilter *mMainFilterModel; }; #endif // BTCPUIMAINVIEW_H diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btcpplugin/btcpuisearchview.cpp --- a/bluetoothengine/btui/btcpplugin/btcpuisearchview.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btcpplugin/btcpuisearchview.cpp Mon May 17 11:06:23 2010 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0"" @@ -16,55 +16,36 @@ */ #include "btcpuisearchview.h" +#include "btuiviewutil.h" #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include "btcpuimainview.h" +#include "btdelegatefactory.h" +#include "btabstractdelegate.h" // docml to load const char* BTUI_SEARCHVIEW_DOCML = ":/docml/bt-search-view.docml"; -BtCpUiSearchView::BtCpUiSearchView(BtuiModel &model, QGraphicsItem *parent) : - BtCpUiBaseView(model,parent) -/*{ - mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this); - BTUI_ASSERT_X(mSoftKeyBackAction, "BtCpUiBaseView::BtCpUiBaseView", "can't create back action"); - - QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout( Qt::Vertical, this ); - // create button - HbPushButton *button = new HbPushButton(this); - button->setText("Press Me"); - button->setMaximumSize(150,50); - mainLayout->addItem(button); - -// (void) connect(button, SIGNAL(clicked()), this, SLOT(changePowerState())); +BtCpUiSearchView::BtCpUiSearchView( + BtSettingModel &settingModel, + BtDeviceModel &deviceModel, + QGraphicsItem *parent) : + BtCpUiBaseView(settingModel,deviceModel, parent), mAbstractDelegate(0), mBtuiModelSortFilter(0) +{ + bool ret(false); - setLayout(mainLayout); - - // create dummy options menu - HbMenu *optionsMenu = new HbMenu(); - HbAction *openGadgetGallery = optionsMenu->addAction("Open Device Gallery"); -// connect(openGadgetGallery, SIGNAL(triggered()), this, SLOT(openGadgetGalleryView())); - HbAction *openNewMainView = optionsMenu->addAction("Open new Main View"); -// connect(openNewMainView, SIGNAL(triggered()), this, SLOT(openNewMainView())); - setMenu(optionsMenu); - -}*/ - -{ - //bool ret(false); - - mSearchView = this; mMainView = (BtCpUiMainView *) parent; mMainWindow = hbInstance->allMainWindows().first(); @@ -72,10 +53,6 @@ mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this); BTUI_ASSERT_X(mSoftKeyBackAction, "BtCpUiBaseView::BtCpUiBaseView", "can't create back action"); - - // read view info from docml file - - // Create view for the application. // Set the name for the view. The name should be same as the view's // name in docml. @@ -87,7 +64,8 @@ // when docml is parsed, instead of creating new view. mLoader = new HbDocumentLoader(); mLoader->setObjectTree(objectList); - + + // read view info from docml file bool ok = false; mLoader->load( BTUI_SEARCHVIEW_DOCML, &ok ); // Exit if the file format is invalid @@ -104,80 +82,133 @@ mDeviceIcon = qobject_cast( mLoader->findWidget( "icon" ) ); BTUI_ASSERT_X( mDeviceIcon != 0, "bt-search-view", "Device Icon not found" ); - mDeviceName=0; - mDeviceName = qobject_cast( mLoader->findWidget( "label_found_devices" ) ); - BTUI_ASSERT_X( mDeviceName != 0, "bt-search-view", "Device Name not found" ); - + mLabelFoundDevices=0; + mLabelFoundDevices = qobject_cast( mLoader->findWidget( "label_found_devices" ) ); + BTUI_ASSERT_X( mLabelFoundDevices != 0, "bt-search-view", "Found Devices not found" ); + mLabelFoundDevices->setPlainText(hbTrId("txt_bt_subhead_bluetooth_found_devices")); + + mLabelSearching=0; + mLabelSearching = qobject_cast( mLoader->findWidget( "label_searching" ) ); + BTUI_ASSERT_X( mLabelSearching != 0, "bt-search-view", "Searching not found" ); + mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_searching")); + mDeviceList=0; mDeviceList = qobject_cast( mLoader->findWidget( "deviceList" ) ); BTUI_ASSERT_X( mDeviceList != 0, "bt-search-view", "Device List not found" ); -// // set model to list view -// mDeviceList->setModel( mFilterProxy ); -// // define settings for list view -// mDeviceList->setSelectionMode(HbAbstractItemView::SingleSelection); -// // set prototype item for list view -// BtUiDevListGridItem *item = new BtUiDevListGridItem( mDeviceList ); -// mDeviceList->setItemPrototype(item); -// // connect to list view pressed signal -// ret = connect( mDeviceList, SIGNAL(pressed(QModelIndex)),this, SLOT(itemActivated(QModelIndex)) ); -// BTUI_ASSERT_X( ret, "bt-search-view", "device list can't connect" ); + mDeviceList->setSelectionMode( HbAbstractItemView::SingleSelection ); // read landscape orientation section from docml file if needed -// mOrientation = ((BTUIViewManager*)parent)->orientation(); - mOrientation = Qt::Vertical; + mOrientation = mMainWindow->orientation(); + if (mOrientation == Qt::Horizontal) { - mLoader->load(BTUI_SEARCHVIEW_DOCML, "landscape", &ok); + mLoader->load(BTUI_SEARCHVIEW_DOCML, "landscape_ui", &ok); BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: landscape section problem" ); + } else { + mLoader->load(BTUI_SEARCHVIEW_DOCML, "portrait_ui", &ok); + BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: portrait section problem" ); } + // listen for orientation changes + ret = connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)), + this, SLOT(changeOrientation(Qt::Orientation))); + BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView()", "connect orientationChanged() failed"); // load tool bar actions - HbAction *viewByAction = static_cast( mLoader->findObject( "viewByAction" ) ); - BTUI_ASSERT_X( viewByAction, "bt-search-view", "view by action missing" ); + mViewBy = static_cast( mLoader->findObject( "viewByAction" ) ); + BTUI_ASSERT_X( mViewBy, "bt-search-view", "view by action missing" ); +// TODO - Need to implement the View by // ret = connect(viewByAction, SIGNAL(triggered()), this, SLOT(noOp())); // BTUI_ASSERT_X( ret, "bt-search-view", "viewByAction can't connect" ); - HbAction *stopAction = static_cast( mLoader->findObject( "stopAction" ) ); - BTUI_ASSERT_X( stopAction, "bt-search-view", "view by action missing" ); -// ret = connect(stopAction, SIGNAL(triggered()), this, SLOT(noOp())); -// BTUI_ASSERT_X( ret, "bt-search-view", "stopAction can't connect" ); - - HbAction *retryAction = static_cast( mLoader->findObject( "retryAction" ) ); - BTUI_ASSERT_X( retryAction, "bt-search-view", "view by action missing" ); -// ret = connect(retryAction, SIGNAL(triggered()), this, SLOT(noOp())); -// BTUI_ASSERT_X( ret, "bt-search-view", "retryAction can't connect" ); - + mStop = static_cast( mLoader->findObject( "stopAction" ) ); + BTUI_ASSERT_X( mStop, "bt-search-view", "stopAction missing" ); + ret = connect(mStop, SIGNAL(triggered()), this, SLOT(stopSearching())); + BTUI_ASSERT_X( ret, "bt-search-view", "stopAction can't connect" ); + mStop->setEnabled(true); + + mRetry = static_cast( mLoader->findObject( "retryAction" ) ); + BTUI_ASSERT_X( mRetry, "bt-search-view", "retryAction missing" ); + ret = connect(mRetry, SIGNAL(triggered()), this, SLOT(retrySearch())); + BTUI_ASSERT_X( ret, "bt-search-view", "retryAction can't connect" ); + // Disable for initial search + mRetry->setEnabled(false); // load menu HbMenu *optionsMenu = qobject_cast(mLoader->findWidget("viewMenu")); BTUI_ASSERT_X( optionsMenu != 0, "bt-search-view", "Options menu not found" ); - this->setMenu(optionsMenu); - + this->setMenu(optionsMenu); + + mExit = static_cast( mLoader->findObject( "exitAction" ) ); + BTUI_ASSERT_X( mExit, "bt-search-view", "exitAction missing" ); + mExit->setText(hbTrId("txt_common_opt_exit")); - // update display when setting data changed -// ret = connect(mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), -// this, SLOT(updateSettingItems(QModelIndex,QModelIndex))); -// BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "can't connect dataChanged" ); + mConnect = static_cast( mLoader->findObject( "connectAction" ) ); + BTUI_ASSERT_X( mConnect, "bt-search-view", "connectAction missing" ); + mConnect->setText(hbTrId("txt_bt_menu_connect")); -// QModelIndex top = mModel->index( Btuim::LocalDeviceName, KDefaultColumn ); -// QModelIndex bottom = mModel->index( Btuim::Visibility, KDefaultColumn ); -// // update name, power and visibility rows -// updateSettingItems( top, bottom ); - - + ret = connect(mDeviceList, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex))); + BTUI_ASSERT_X( ret, "bt-search-view", "deviceSelected can't connect" ); } BtCpUiSearchView::~BtCpUiSearchView() { setNavigationAction(0); delete mSoftKeyBackAction; + + if(mAbstractDelegate) { + delete mAbstractDelegate; + mAbstractDelegate = 0; + } + + if(mBtuiModelSortFilter) { + delete mBtuiModelSortFilter; + mBtuiModelSortFilter = 0; + } +} + +void BtCpUiSearchView::changeOrientation( Qt::Orientation orientation ) +{ + bool ok = false; + mOrientation = orientation; + if( orientation == Qt::Vertical ) { + // load "portrait" section + mLoader->load( BTUI_SEARCHVIEW_DOCML, "portrait_ui", &ok ); + BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: portrait section problem" ); + } else { + // load "landscape" section + mLoader->load( BTUI_SEARCHVIEW_DOCML, "landscape_ui", &ok ); + BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: landscape section problem" ); + } } -void BtCpUiSearchView::deviceSelected(const QModelIndex& modelIndex) +void BtCpUiSearchView::stopSearching() { - int row = modelIndex.row(); + // Stop delegate + + // Change label and buttons to reflect status + mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_search_done")); + mRetry->setEnabled(true); + mStop->setEnabled(false); + + // Stop delegate + mAbstractDelegate->cancel(); +} + +void BtCpUiSearchView::retrySearch() +{ + // Retry delegate + + // Change label and buttons to reflect status + mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_searching")); + mRetry->setEnabled(false); + mStop->setEnabled(true); + + // Make use of the delegate and start the search. + mAbstractDelegate->cancel(); + mDeviceList->setModel(mBtuiModelSortFilter); + mAbstractDelegate->exec(QVariant()); } void BtCpUiSearchView::setSoftkeyBack() @@ -191,15 +222,7 @@ void BtCpUiSearchView::switchToPreviousView() { BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView"); - // jump to previous view of current view. - mSearchView->deactivateView(); - - // set the new current view - mMainWindow->setCurrentView( mMainView ); - - // do preparation or some actions when new view is activated - mMainView->activateView( 0, 0 ); - + mMainView->switchToPreviousView(); } void BtCpUiSearchView::activateView( const QVariant& value, int cmdId ) @@ -208,8 +231,55 @@ Q_UNUSED(cmdId); setSoftkeyBack(); + + bool ret(false); + + if(!mAbstractDelegate) { + // Create the inquiry delegate. + mAbstractDelegate = BtDelegateFactory::newDelegate( + BtDelegate::Inquiry, mSettingModel, mDeviceModel ); + } + + // Connect to the signal from the BtDelegateInquiry for completion of the search request + ret = connect(mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(searchDelegateCompleted(int))); + BTUI_ASSERT_X( ret, "bt-search-view", "searchDelegateCompleted can't connect" ); + + // Connect to the signal from the BtuiModel when the search has been completed. + ret = connect(mDeviceModel, SIGNAL(deviceSearchCompleted(int)), this, SLOT(deviceSearchCompleted(int))); + BTUI_ASSERT_X( ret, "bt-search-view", "deviceSearchCompleted can't connect" ); + + if(!mBtuiModelSortFilter) { + mBtuiModelSortFilter = new BtuiModelSortFilter(this); + } + mBtuiModelSortFilter->setSourceModel(mDeviceModel); + mBtuiModelSortFilter->addDeviceMajorFilter(BtDeviceModel::InRange, BtuiModelSortFilter::AtLeastMatch); + mDeviceList->setModel(mBtuiModelSortFilter); + + // Make use of the delegate and start the search. + mAbstractDelegate->exec(QVariant()); } void BtCpUiSearchView::deactivateView() { } + +void BtCpUiSearchView::searchDelegateCompleted(int error) +{ + //TODO - handle error. + Q_UNUSED(error); +} + +void BtCpUiSearchView::deviceSearchCompleted(int error) +{ + //TODO - handle error. + Q_UNUSED(error); + mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_search_done")); + mRetry->setEnabled(true); + mStop->setEnabled(false); +} + +void BtCpUiSearchView::deviceSelected(const QModelIndex& modelIndex) +{ + QModelIndex index = mBtuiModelSortFilter->mapToSource(modelIndex); + static_cast(mMainView)->goToDeviceView(index); +} diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btcpplugin/btcpuisearchview.h --- a/bluetoothengine/btui/btcpplugin/btcpuisearchview.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btcpplugin/btcpuisearchview.h Mon May 17 11:06:23 2010 +0300 @@ -22,36 +22,43 @@ #include #include #include "btcpuibaseview.h" +#include "btuimodelsortfilter.h" class HbLabel; class HbPushButton; class HbIcon; class HbDocumentLoader; class HbListView; -class HbDataFormModel; -class HbDataFormModelItem; -class CpSettingFormItemData; - +class BtAbstractDelegate; class BtCpUiSearchView : public BtCpUiBaseView { Q_OBJECT public: - explicit BtCpUiSearchView(BtuiModel &model, QGraphicsItem *parent = 0); + explicit BtCpUiSearchView( + BtSettingModel &settingModel, + BtDeviceModel &deviceModel, + QGraphicsItem *parent = 0); virtual ~BtCpUiSearchView(); virtual void activateView( const QVariant& value, int cmdId ); virtual void deactivateView(); virtual void setSoftkeyBack(); public slots: + virtual void switchToPreviousView(); + void changeOrientation( Qt::Orientation orientation ); + void stopSearching(); + void retrySearch(); + void searchDelegateCompleted(int error); + void deviceSearchCompleted(int error); void deviceSelected(const QModelIndex& modelIndex); - virtual void switchToPreviousView(); private: HbDocumentLoader *mLoader; HbLabel *mDeviceIcon; - HbLabel *mDeviceName; + HbLabel *mLabelFoundDevices; + HbLabel *mLabelSearching; HbListView *mDeviceList; // data structures for switching between views @@ -59,17 +66,22 @@ int mAutoCmdId; Qt::Orientation mOrientation; - HbMainWindow* mMainWindow; - BtCpUiBaseView* mMainView; - BtCpUiBaseView* mSearchView; - HbAction *mSoftKeyBackAction; -// CpCustomLabelViewItem* mLabelItem; -// CpCustomListViewItem* mListItem; - HbToolBar* mToolBar; - HbAction* mViewBy; - HbAction* mStop; - HbAction* mRetry; - HbDataFormModel* mModel; + HbMainWindow* mMainWindow; + BtCpUiBaseView* mMainView; + BtCpUiBaseView* mDeviceView; + HbAction * mSoftKeyBackAction; + HbToolBar* mToolBar; + HbAction* mViewBy; + HbAction* mStop; + HbAction* mRetry; + HbAction* mExit; + HbAction* mConnect; + + //pointer to abstract delegate, and it is instantiated at runtime + BtAbstractDelegate* mAbstractDelegate; + QModelIndex* mParentIndex; + int mNumOfRows; + BtuiModelSortFilter* mBtuiModelSortFilter; }; #endif// BTCPUISEARCHVIEW_H diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btcpplugin/btcpuisettingitem.cpp --- a/bluetoothengine/btui/btcpplugin/btcpuisettingitem.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btcpplugin/btcpuisettingitem.cpp Mon May 17 11:06:23 2010 +0300 @@ -40,11 +40,12 @@ void BtCpUiSettingItem::onLaunchView() { - mModel = new BtuiModel(); + mSettingModel = new BtSettingModel(this); + mDeviceModel = new BtDeviceModel(this); mMainWindow = hbInstance->allMainWindows().first(); - mBtMainView = new BtCpUiMainView(*mModel); + mBtMainView = new BtCpUiMainView(*mSettingModel, *mDeviceModel); mCpView = mMainWindow->currentView(); @@ -59,8 +60,6 @@ { mBtMainView->deactivateView(); mMainWindow->setCurrentView(mCpView); - delete mBtMainView; - delete mModel; } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btcpplugin/btcpuisettingitem.h --- a/bluetoothengine/btui/btcpplugin/btcpuisettingitem.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btcpplugin/btcpuisettingitem.h Mon May 17 11:06:23 2010 +0300 @@ -19,7 +19,8 @@ #define BTCPUISETTINGITEM_H #include -#include +#include +#include #include "btcpuimainview.h" @@ -45,7 +46,8 @@ BtCpUiMainView *mBtMainView; //Owns this model. - BtuiModel *mModel; + BtSettingModel *mSettingModel; + BtDeviceModel *mDeviceModel; HbView *mCpView; diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btcpplugin/btuiviewutil.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/btuiviewutil.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,34 @@ +/* +* ============================================================================ +* Name : btuiviewutil.h +* Description : utilities in the view for some often used functions, +* +* Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BTUIVIEWUTIL_H +#define BTUIVIEWUTIL_H + +enum ViewIndex { + MainView, + SearchView, + DeviceView, + LastView +}; + + + +#endif // BTUIVIEWUTIL_H diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btcpplugin/docml/bt-device-view.docml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/docml/bt-device-view.docml Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,145 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btcpplugin/docml/bt-main-view.docml --- a/bluetoothengine/btui/btcpplugin/docml/bt-main-view.docml Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btcpplugin/docml/bt-main-view.docml Mon May 17 11:06:23 2010 +0300 @@ -35,11 +35,6 @@ - - - - - @@ -108,9 +103,14 @@ + + + + + - + @@ -133,9 +133,17 @@ + + + + + + + + @@ -152,36 +160,25 @@ - - - - - + - - - -
- - - - - - + + + @@ -195,15 +192,12 @@ - - -
- +
diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btcpplugin/docml/bt-search-view.docml --- a/bluetoothengine/btui/btcpplugin/docml/bt-search-view.docml Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btcpplugin/docml/bt-search-view.docml Mon May 17 11:06:23 2010 +0300 @@ -1,5 +1,5 @@ - + @@ -21,7 +21,7 @@ - + @@ -33,8 +33,8 @@ + - @@ -56,17 +56,20 @@ - + - - - + + + - + + + + @@ -76,32 +79,33 @@ - - + +
- - - - - - - - - - - - - - - -
- + + + + + + + + + + + + + + + + + +
diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btui.pro --- a/bluetoothengine/btui/btui.pro Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btui.pro Mon May 17 11:06:23 2010 +0300 @@ -26,7 +26,8 @@ CONFIG += ordered symbian: { - + SYMBIAN_PLATFORMS = WINSCW \ + ARMV5 BLD_INF_RULES.prj_exports += \ "$${LITERAL_HASH}include" \ "rom/btui.iby CORE_MW_LAYER_IBY_EXPORT_PATH(btui.iby)" diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btabstractdelegate.cpp --- a/bluetoothengine/btui/btuidelegate/btabstractdelegate.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btuidelegate/btabstractdelegate.cpp Mon May 17 11:06:23 2010 +0300 @@ -17,13 +17,15 @@ #include "btabstractdelegate.h" -#include "btuimodel.h" +#include +#include /*! Constructor. */ -BtAbstractDelegate::BtAbstractDelegate( BtuiModel& model, QObject *parent ) - : QObject( parent ), mModel(model) +BtAbstractDelegate::BtAbstractDelegate( BtSettingModel *settingModel, + BtDeviceModel *deviceModel, QObject *parent ) + : QObject( parent ), mSettingModel(settingModel),mDeviceModel(deviceModel) { } @@ -34,7 +36,18 @@ { } -BtuiModel &BtAbstractDelegate::model() +BtSettingModel *BtAbstractDelegate::getSettingModel() +{ + return mSettingModel; +} + +BtDeviceModel *BtAbstractDelegate::getDeviceModel() { - return mModel; + return mDeviceModel; } + +void BtAbstractDelegate::cancel() +{ + +} + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btabstractdelegate.h --- a/bluetoothengine/btui/btuidelegate/btabstractdelegate.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btuidelegate/btabstractdelegate.h Mon May 17 11:06:23 2010 +0300 @@ -20,8 +20,10 @@ #include #include +#include -class BtuiModel; +class BtSettingModel; +class BtDeviceModel; #ifdef BUILD_BTUIDELEGATE #define BTUIDELEGATE_IMEXPORT Q_DECL_EXPORT @@ -42,27 +44,35 @@ Q_OBJECT public: - explicit BtAbstractDelegate( BtuiModel& model, QObject *parent = 0 ); + explicit BtAbstractDelegate( BtSettingModel* settingModel, + BtDeviceModel* deviceModel, QObject *parent = 0 ); virtual ~BtAbstractDelegate(); virtual void exec( const QVariant ¶ms ) = 0; + virtual void cancel(); + signals: void commandCompleted(int status, QVariant params = QVariant() ); protected: - BtuiModel &model(); + BtSettingModel *getSettingModel(); + BtDeviceModel *getDeviceModel(); public slots: private: - BtuiModel& mModel; - + // pointer to models. do not own. + BtSettingModel *mSettingModel; + BtDeviceModel *mDeviceModel; + Q_DISABLE_COPY(BtAbstractDelegate) }; +Q_DECLARE_METATYPE(QModelIndex) + #endif // BTABSTRACTDELEGATE_H diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegateInquiry.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegateInquiry.cpp Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "btdelegateinquiry.h" +#include +#include +#include + + +BtDelegateInquiry::BtDelegateInquiry( + BtSettingModel* settingModel, + BtDeviceModel* deviceModel, QObject* parent ) + :BtAbstractDelegate( settingModel, deviceModel, parent ) +{ +} + +BtDelegateInquiry::~BtDelegateInquiry() +{ + +} + +void BtDelegateInquiry::exec( const QVariant& params ) +{ + Q_UNUSED(params); + + bool err = getDeviceModel()->searchDevice(); + if (!err) { + // TODO - Verify the error code to be used. + // Complete command with error + emit commandCompleted(KErrNotSupported); + return; + } + + emit commandCompleted(KErrNone); +} + +void BtDelegateInquiry::cancel() +{ + getDeviceModel()->cancelSearchDevice(); +} diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegateInquiry.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegateInquiry.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef BTDELEGATEINQUIRY_H_ +#define BTDELEGATEINQUIRY_H_ + +#include +#include +#include "btabstractdelegate.h" + +class BtuiModel; + + +class BtDelegateInquiry : public BtAbstractDelegate +{ + Q_OBJECT + +public: + explicit BtDelegateInquiry( + BtSettingModel* settingModel, + BtDeviceModel* deviceModel, + QObject* parent = 0 ); + + virtual ~BtDelegateInquiry(); + + virtual void exec( const QVariant ¶ms ); + + virtual void cancel(); + +private: +}; + +#endif /* BTDELEGATEINQUIRY_H_ */ diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegateconnect.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegateconnect.cpp Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,113 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "btdelegateconnect.h" +#include +#include +#include +#include + +BtDelegateConnect::BtDelegateConnect( + BtSettingModel* settingModel, + BtDeviceModel* deviceModel, QObject *parent) : + BtAbstractDelegate(settingModel, deviceModel, parent), mBtengConnMan(0) +{ + +} + +BtDelegateConnect::~BtDelegateConnect() +{ + delete mBtengConnMan; +} + +void BtDelegateConnect::exec( const QVariant ¶ms ) +{ + int error = KErrNone; + QModelIndex index = params.value(); + + mdeviceName = getDeviceModel()->data(index,BtDeviceModel::NameAliasRole).toString(); + + QString strBtAddr = getDeviceModel()->data(index, + BtDeviceModel::ReadableBdaddrRole).toString(); + int cod = getDeviceModel()->data(index,BtDeviceModel::CoDRole).toInt(); + + if ( ! mBtengConnMan ){ + TRAP_IGNORE( mBtengConnMan = CBTEngConnMan::NewL(this) ); + } + Q_CHECK_PTR( mBtengConnMan ); + + TBTDeviceClass btEngDeviceClass(cod); + TPtrC ptrName(reinterpret_cast(strBtAddr.constData())); + + RBuf16 btName; + error = btName.Create(ptrName.Length()); + + if(error == KErrNone) { + btName.Copy(ptrName); + mBtEngddr.SetReadable(btName); + error = mBtengConnMan->Connect(mBtEngddr, btEngDeviceClass); + btName.Close(); + } + + + if(error) { + emitCommandComplete(error); + } + +} + +void BtDelegateConnect::ConnectComplete( TBTDevAddr& aAddr, TInt aErr, + RBTDevAddrArray* aConflicts ) +{ + Q_UNUSED(aAddr); + Q_UNUSED(aConflicts); + emitCommandComplete(aErr); +} + +void BtDelegateConnect::DisconnectComplete( TBTDevAddr& aAddr, TInt aErr ) +{ + Q_UNUSED(aAddr); + Q_UNUSED(aErr); +} + +void BtDelegateConnect::PairingComplete( TBTDevAddr& aAddr, TInt aErr ) +{ + Q_UNUSED(aAddr); + Q_UNUSED(aErr); +} + +void BtDelegateConnect::cancel() +{ + mBtengConnMan->CancelConnect(mBtEngddr); +} + +void BtDelegateConnect::emitCommandComplete(int error) +{ + QString str(hbTrId("Connected to %1")); + QString err(hbTrId("Connecting with %1 Failed")); + + if(error != KErrNone) { + HbNotificationDialog::launchDialog(err.arg(mdeviceName)); + } + else { + HbNotificationDialog::launchDialog(str.arg(mdeviceName)); + } + + emit commandCompleted(error); +} + + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegateconnect.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegateconnect.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTDELEGATECONNECT_H_ +#define BTDELEGATECONNECT_H_ + +#include +#include +#include "btabstractdelegate.h" + +class BtuiModel; + +/*! + \class BtDelegateConnect + \brief the base class for handling Bluetooth Connection. + */ +class BtDelegateConnect : public BtAbstractDelegate, + public MBTEngConnObserver +{ + Q_OBJECT + +public: + explicit BtDelegateConnect( + BtSettingModel* settingModel, + BtDeviceModel* deviceModel, + QObject *parent = 0 ); + + virtual ~BtDelegateConnect(); + + virtual void exec( const QVariant ¶ms ); + + virtual void cancel(); + +public slots: + +protected: + //From MBTEngConnObserver + virtual void ConnectComplete( TBTDevAddr& aAddr, TInt aErr, + RBTDevAddrArray* aConflicts ); + virtual void DisconnectComplete( TBTDevAddr& aAddr, TInt aErr ); + virtual void PairingComplete( TBTDevAddr& aAddr, TInt aErr ); + + void emitCommandComplete(int error); + +private: + + CBTEngConnMan *mBtengConnMan; + + TBTDevAddr mBtEngddr; + + QString mdeviceName; + + Q_DISABLE_COPY(BtDelegateConnect) + +}; + + +#endif /* BTDELEGATECONNECT_H_ */ diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegateconsts.h --- a/bluetoothengine/btui/btuidelegate/btdelegateconsts.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btuidelegate/btdelegateconsts.h Mon May 17 11:06:23 2010 +0300 @@ -28,6 +28,11 @@ ManagePower, DeviceName, Visibility, + Inquiry, + Connect, + Pair, + Disconnect, + Unpair, }; } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegatedevname.cpp --- a/bluetoothengine/btui/btuidelegate/btdelegatedevname.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btuidelegate/btdelegatedevname.cpp Mon May 17 11:06:23 2010 +0300 @@ -16,12 +16,12 @@ */ #include "btdelegatedevname.h" -#include "btuimodel.h" +#include #include #include -BtDelegateDevName::BtDelegateDevName( BtuiModel& model, QObject *parent ) : - BtAbstractDelegate( model, parent ) +BtDelegateDevName::BtDelegateDevName(QObject *parent ) : + BtAbstractDelegate( NULL, NULL, parent ) { TRAP_IGNORE( mBtEngSettings = CBTEngSettings::NewL() ); Q_CHECK_PTR( mBtEngSettings ); diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegatedevname.h --- a/bluetoothengine/btui/btuidelegate/btdelegatedevname.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btuidelegate/btdelegatedevname.h Mon May 17 11:06:23 2010 +0300 @@ -33,7 +33,7 @@ Q_OBJECT public: - explicit BtDelegateDevName( BtuiModel& model, QObject *parent = 0 ); + explicit BtDelegateDevName( QObject *parent = 0 ); virtual ~BtDelegateDevName(); diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegatedevsecurity.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegatedevsecurity.cpp Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,110 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include + +#include "btdelegatedevsecurity.h" +#include +#include +#include + +BtDelegateDevSecurity::BtDelegateDevSecurity( + BtSettingModel* settingModel, + BtDeviceModel* deviceModel, + QObject *parent) : + BtAbstractDelegate(settingModel, deviceModel, parent), mBtEngDevMan(0) +{ + +} + +BtDelegateDevSecurity::~BtDelegateDevSecurity() +{ + delete mBtEngDevMan; +} + + +void BtDelegateDevSecurity::exec( const QVariant ¶ms ) +{ + int error = KErrNone; + QModelIndex index = params.value(); + + QString strBtAddr = getDeviceModel()->data(index, + BtDeviceModel::ReadableBdaddrRole).toString(); + + mdeviceName = getDeviceModel()->data(index,BtDeviceModel::NameAliasRole).toString(); + + TBTDevAddr symaddr; + TBuf buffer(strBtAddr.utf16()); + symaddr.SetReadable( buffer ); + + CBTDevice *symBtDevice = 0; + TRAP( error, { + symBtDevice = CBTDevice::NewL( symaddr ); + if( !mBtEngDevMan) { + mBtEngDevMan = CBTEngDevMan::NewL( this ); + } + }); + + if ( !error ) { + symBtDevice->SetPaired(EFalse); + // deleting link key for executing unpair is safe as no + // link key shall exist if the device has been unpaired. + symBtDevice->DeleteLinkKey(); + error = mBtEngDevMan->ModifyDevice( *symBtDevice ); + } + delete symBtDevice; + + if ( error ) { + emitCommandComplete(error); + } +} + +void BtDelegateDevSecurity::cancel() +{ + +} + +void BtDelegateDevSecurity::HandleDevManComplete( TInt aErr ) +{ + emitCommandComplete(aErr); +} + +void BtDelegateDevSecurity::HandleGetDevicesComplete( TInt aErr, CBTDeviceArray* aDeviceArray ) +{ + Q_UNUSED(aErr); + Q_UNUSED(aDeviceArray); +} + +void BtDelegateDevSecurity::emitCommandComplete(int error) +{ + QString str(hbTrId("Unpaired to %1")); + QString err(hbTrId("Unpairing with %1 Failed")); + + if(error != KErrNone) { + HbNotificationDialog::launchDialog(err.arg(mdeviceName)); + } + else { + HbNotificationDialog::launchDialog(str.arg(mdeviceName)); + } + + emit commandCompleted(error); +} + + + + + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegatedevsecurity.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegatedevsecurity.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTDELEGATEDEVSECURITY_H +#define BTDELEGATEDEVSECURITY_H + +#include +#include +#include +#include "btabstractdelegate.h" + +class BtuiModel; + +/*! + \class BtDelegateDisconnect + \brief the base class for Disconnecting Bluetooth Connection. + */ +class BtDelegateDevSecurity : public BtAbstractDelegate, + public MBTEngDevManObserver +{ + Q_OBJECT + +public: + explicit BtDelegateDevSecurity( + BtSettingModel* settingModel, + BtDeviceModel* deviceModel, + QObject *parent = 0 ); + + virtual ~BtDelegateDevSecurity(); + + virtual void exec( const QVariant ¶ms ); + + virtual void cancel(); + +public slots: + +protected: + //From MBTEngDevManObserver + virtual void HandleDevManComplete( TInt aErr ); + virtual void HandleGetDevicesComplete( TInt aErr, CBTDeviceArray* aDeviceArray ); + + void emitCommandComplete(int error); + +private: + + CBTEngDevMan *mBtEngDevMan; + + QString mdeviceName; + + Q_DISABLE_COPY(BtDelegateDevSecurity) + +}; + + +#endif /* BTDELEGATEDEVSECURITY_H */ diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegatedisconnect.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegatedisconnect.cpp Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,109 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +#include "btdelegatedisconnect.h" +#include +#include +#include +#include + +BtDelegateDisconnect::BtDelegateDisconnect( + BtSettingModel* settingModel, + BtDeviceModel* deviceModel, QObject *parent) : + BtAbstractDelegate(settingModel, deviceModel, parent), mBtengConnMan(0) +{ + +} + +BtDelegateDisconnect::~BtDelegateDisconnect() +{ + delete mBtengConnMan; +} + +void BtDelegateDisconnect::exec( const QVariant ¶ms ) +{ + int error = KErrNone; + QModelIndex index = params.value(); + + mdeviceName = getDeviceModel()->data(index,BtDeviceModel::NameAliasRole).toString(); + + QString strBtAddr = getDeviceModel()->data(index,BtDeviceModel::ReadableBdaddrRole).toString(); + + if ( ! mBtengConnMan ){ + TRAP_IGNORE( mBtengConnMan = CBTEngConnMan::NewL(this) ); + } + Q_CHECK_PTR( mBtengConnMan ); + + TPtrC ptrName(reinterpret_cast(strBtAddr.constData())); + + RBuf16 btName; + error = btName.Create(ptrName.Length()); + + if(error == KErrNone) { + btName.Copy(ptrName); + mBtEngddr.SetReadable(btName); + error = mBtengConnMan->Disconnect(mBtEngddr, EBTDiscGraceful); + btName.Close(); + } + + + if(error) { + emitCommandComplete(error); + } + +} + +void BtDelegateDisconnect::ConnectComplete( TBTDevAddr& aAddr, TInt aErr, + RBTDevAddrArray* aConflicts ) +{ + Q_UNUSED(aAddr); + Q_UNUSED(aConflicts); + Q_UNUSED(aErr); +} + +void BtDelegateDisconnect::DisconnectComplete( TBTDevAddr& aAddr, TInt aErr ) +{ + Q_UNUSED(aAddr); + emitCommandComplete(aErr); +} + +void BtDelegateDisconnect::PairingComplete( TBTDevAddr& aAddr, TInt aErr ) +{ + Q_UNUSED(aAddr); + Q_UNUSED(aErr); +} + +void BtDelegateDisconnect::cancel() +{ + +} + +void BtDelegateDisconnect::emitCommandComplete(int error) +{ + QString str(hbTrId("Disconnected to %1")); + QString err(hbTrId("Disconnecting with %1 Failed")); + + if(error != KErrNone) { + HbNotificationDialog::launchDialog(err.arg(mdeviceName)); + } + else { + HbNotificationDialog::launchDialog(str.arg(mdeviceName)); + } + + emit commandCompleted(error); +} + + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegatedisconnect.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegatedisconnect.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTDELEGATEDISCONNECT_H +#define BTDELEGATEDISCONNECT_H + +#include +#include +#include "btabstractdelegate.h" + +class BtuiModel; + +/*! + \class BtDelegateDisconnect + \brief the base class for Disconnecting Bluetooth Connection. + */ +class BtDelegateDisconnect : public BtAbstractDelegate, + public MBTEngConnObserver +{ + Q_OBJECT + +public: + explicit BtDelegateDisconnect( + BtSettingModel* settingModel, + BtDeviceModel* deviceModel, QObject *parent = 0 ); + + virtual ~BtDelegateDisconnect(); + + virtual void exec( const QVariant ¶ms ); + + virtual void cancel(); + +public slots: + +protected: + //From MBTEngConnObserver + virtual void ConnectComplete( TBTDevAddr& aAddr, TInt aErr, + RBTDevAddrArray* aConflicts ); + virtual void DisconnectComplete( TBTDevAddr& aAddr, TInt aErr ); + virtual void PairingComplete( TBTDevAddr& aAddr, TInt aErr ); + + void emitCommandComplete(int error); + +private: + + CBTEngConnMan *mBtengConnMan; + + TBTDevAddr mBtEngddr; + + QString mdeviceName; + + Q_DISABLE_COPY(BtDelegateDisconnect) + +}; + + + +#endif /* BTDELEGATEDISCONNECT_H */ diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegatefactory.cpp --- a/bluetoothengine/btui/btuidelegate/btdelegatefactory.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btuidelegate/btdelegatefactory.cpp Mon May 17 11:06:23 2010 +0300 @@ -17,25 +17,43 @@ #include "btdelegatefactory.h" +#include +#include #include "btdelegatepower.h" -#include "btuimodel.h" #include "btdelegatedevname.h" #include "btdelegatevisibility.h" - +#include "btdelegateinquiry.h" +#include "btdelegateconnect.h" +#include "btdelegatepair.h" +#include "btdelegatedisconnect.h" +#include "btdelegatedevsecurity.h" /*! Constructor. */ BtAbstractDelegate * BtDelegateFactory::newDelegate( - BtDelegate::Command cmd, BtuiModel& model, QObject *parent ) + BtDelegate::Command cmd, + BtSettingModel* settingModel, + BtDeviceModel* deviceModel, + QObject *parent ) { switch ( cmd ) { case BtDelegate::ManagePower: - return new BtDelegatePower( model, parent ); + return new BtDelegatePower( settingModel, deviceModel, parent ); case BtDelegate::DeviceName: - return new BtDelegateDevName( model, parent ); + return new BtDelegateDevName( parent ); case BtDelegate::Visibility: - return new BtDelegateVisibility( model, parent ); + return new BtDelegateVisibility( parent ); + case BtDelegate::Inquiry: + return new BtDelegateInquiry( settingModel, deviceModel, parent ); + case BtDelegate::Connect: + return new BtDelegateConnect( settingModel, deviceModel, parent ); + case BtDelegate::Pair: + return new BtDelegatePair( settingModel, deviceModel, parent ); + case BtDelegate::Disconnect: + return new BtDelegateDisconnect( settingModel, deviceModel, parent ); + case BtDelegate::Unpair: + return new BtDelegateDevSecurity( settingModel, deviceModel, parent ); } return 0; } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegatefactory.h --- a/bluetoothengine/btui/btuidelegate/btdelegatefactory.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btuidelegate/btdelegatefactory.h Mon May 17 11:06:23 2010 +0300 @@ -22,7 +22,8 @@ #include "btdelegateconsts.h" class BtAbstractDelegate; -class BtuiModel; +class BtSettingModel; +class BtDeviceModel; #ifdef BUILD_BTUIDELEGATE #define BTUIDELEGATE_IMEXPORT Q_DECL_EXPORT @@ -41,7 +42,10 @@ public: static BtAbstractDelegate *newDelegate( - BtDelegate::Command cmd, BtuiModel& model, QObject *parent = 0 ); + BtDelegate::Command cmd, + BtSettingModel* settingModel, + BtDeviceModel* deviceModel, + QObject *parent = 0 ); }; diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegatepair.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegatepair.cpp Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,150 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "btdelegatepair.h" +#include "btuiutil.h" + +#include +#include +#include +#include +#include +#include +#include + +// docml to load +const char* BTUI_PAIR_WAIT_DOCML = ":/docml/pairwaitingdialog.docml"; + +BtDelegatePair::BtDelegatePair( + BtSettingModel* settingModel, + BtDeviceModel* deviceModel, + QObject *parent) : + BtAbstractDelegate(settingModel, deviceModel, parent), mBtengConnMan(0) +{ + mLoader = new HbDocumentLoader(); +} + +BtDelegatePair::~BtDelegatePair() +{ + delete mBtengConnMan; + delete mLoader; +} + +void BtDelegatePair::exec( const QVariant ¶ms ) +{ + int error = KErrNone; + QModelIndex index = params.value(); + + mdeviceName = getDeviceModel()->data(index,BtDeviceModel::NameAliasRole).toString(); + + QString strBtAddr = getDeviceModel()->data(index,BtDeviceModel::ReadableBdaddrRole).toString(); + int cod = getDeviceModel()->data(index,BtDeviceModel::CoDRole).toInt(); + + if ( ! mBtengConnMan ){ + TRAP( error, mBtengConnMan = CBTEngConnMan::NewL(this) ); + } + + if ( !error ) { + TBTDevAddr btEngddr; + addrReadbleStringToSymbian( strBtAddr, btEngddr ); + TBTDeviceClass btEngDeviceClass(cod); + error = mBtengConnMan->PairDevice(btEngddr, btEngDeviceClass); + launchWaitDialog(); + } + + if(error) { + emitCommandComplete(error); + } + +} + +void BtDelegatePair::launchWaitDialog() +{ + QString headingText(hbTrId("Pairing with %1")); + HbLabel *heading; + HbProgressBar* progressBar; + + bool ok = false; + mLoader->load( BTUI_PAIR_WAIT_DOCML, &ok ); + // Exit if the file format is invalid + BTUI_ASSERT_X( ok, "BTUI_PAIR_WAIT_DOCML", "Invalid docml file" ); + + mWaitDialog = qobject_cast( mLoader->findWidget( "dialog" ) ); + BTUI_ASSERT_X( mWaitDialog != 0, "BTUI_PAIR_WAIT_DOCML", "dialog not found" ); + + heading = qobject_cast( mLoader->findWidget( "heading" ) ); + BTUI_ASSERT_X( heading != 0, "BTUI_PAIR_WAIT_DOCML", "heading not found" ); + + progressBar = qobject_cast( mLoader->findWidget( "progressBar" ) ); + BTUI_ASSERT_X( progressBar != 0, "BTUI_PAIR_WAIT_DOCML", "progressBar not found" ); + progressBar->setRange(0,0); + + heading->setPlainText(headingText.arg(mdeviceName)); + + mWaitDialog->setDismissPolicy(HbPopup::NoDismiss); + mWaitDialog->setTimeout(HbPopup::NoTimeout); + + mWaitDialog->show(); +} + +void BtDelegatePair::ConnectComplete( TBTDevAddr& aAddr, TInt aErr, + RBTDevAddrArray* aConflicts ) +{ + Q_UNUSED(aAddr); + Q_UNUSED(aErr); + Q_UNUSED(aConflicts); + +} + +void BtDelegatePair::DisconnectComplete( TBTDevAddr& aAddr, TInt aErr ) +{ + Q_UNUSED(aAddr); + Q_UNUSED(aErr); +} + +void BtDelegatePair::PairingComplete( TBTDevAddr& aAddr, TInt aErr ) +{ + Q_UNUSED(aAddr); + + mWaitDialog->close(); + emitCommandComplete(aErr); +} + +void BtDelegatePair::emitCommandComplete(int error) +{ + QString str(hbTrId("Paired to %1")); + QString err(hbTrId("Pairing with %1 Failed")); + + if(error != KErrNone) { + HbNotificationDialog::launchDialog(err.arg(mdeviceName)); + } + else { + HbNotificationDialog::launchDialog(str.arg(mdeviceName)); + } + + emit commandCompleted(error); +} + +void BtDelegatePair::cancel() +{ + if ( mBtengConnMan ) { + mBtengConnMan->CancelPairDevice(); + } +} + + + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegatepair.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegatepair.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTDELEGATEPAIR_H +#define BTDELEGATEPAIR_H + +#include +#include +#include +#include +#include "btabstractdelegate.h" + +class BtuiModel; + +/*! + \class BtDelegatePair + \brief the base class for handling Bluetooth Pair functionality. + */ +class BtDelegatePair : public BtAbstractDelegate, + public MBTEngConnObserver +{ + Q_OBJECT + +public: + explicit BtDelegatePair( + BtSettingModel* settingModel, + BtDeviceModel* deviceModel, QObject *parent = 0 ); + + virtual ~BtDelegatePair(); + + virtual void exec( const QVariant ¶ms ); + + virtual void cancel(); + +public slots: + +protected: + //From MBTEngConnObserver + virtual void ConnectComplete( TBTDevAddr& aAddr, TInt aErr, + RBTDevAddrArray* aConflicts ); + virtual void DisconnectComplete( TBTDevAddr& aAddr, TInt aErr ); + virtual void PairingComplete( TBTDevAddr& aAddr, TInt aErr ); + +private: + void launchWaitDialog(); + void emitCommandComplete(int error); + +private: + + CBTEngConnMan *mBtengConnMan; + HbDialog *mWaitDialog; + QString mdeviceName; + + HbDocumentLoader *mLoader; + + Q_DISABLE_COPY(BtDelegatePair) + +}; + +#endif /* BTDELEGATEPAIR_H */ diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegatepower.cpp --- a/bluetoothengine/btui/btuidelegate/btdelegatepower.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btuidelegate/btdelegatepower.cpp Mon May 17 11:06:23 2010 +0300 @@ -17,7 +17,8 @@ #include "btdelegatepower.h" -#include "btuimodel.h" +#include +#include #include #include #include @@ -25,8 +26,10 @@ /*! Constructor. */ -BtDelegatePower::BtDelegatePower( BtuiModel& model, QObject *parent ) - : BtAbstractDelegate( model, parent ) +BtDelegatePower::BtDelegatePower( + BtSettingModel* settingModel, + BtDeviceModel* deviceModel, QObject *parent ) + : BtAbstractDelegate( settingModel, deviceModel, parent ) { TRAP_IGNORE( mBtengSettings = CBTEngSettings::NewL(this) ); Q_CHECK_PTR( mBtengSettings ); @@ -67,12 +70,14 @@ if (enabledInOffline){ //if (1){ // BT is allowed to be enabled in offline mode, show query. - HbMessageBox::question( tr("Turn Bluetooth on in offline mode?"),this, SLOT(btOnQuestionClose(HbAction*))); + HbMessageBox::question( tr("Turn Bluetooth on in offline mode?"),this, + SLOT(btOnQuestionClose(HbAction*))); } else{ //if BT is not allowed to be enabled in offline mode, show message and complete - HbMessageBox::warning(tr("Bluetooth not allowed to be turned on in offline mode"),this, SLOT(btOnWarningClose())); + HbMessageBox::warning(tr("Bluetooth not allowed to be turned on in offline mode"),this, + SLOT(btOnWarningClose())); } } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegatepower.h --- a/bluetoothengine/btui/btuidelegate/btdelegatepower.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btuidelegate/btdelegatepower.h Mon May 17 11:06:23 2010 +0300 @@ -36,7 +36,9 @@ Q_OBJECT public: - explicit BtDelegatePower( BtuiModel& model, QObject *parent = 0 ); + explicit BtDelegatePower( + BtSettingModel* settingModel, + BtDeviceModel* deviceModel, QObject *parent = 0 ); virtual ~BtDelegatePower(); diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegatevisibility.cpp --- a/bluetoothengine/btui/btuidelegate/btdelegatevisibility.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btuidelegate/btdelegatevisibility.cpp Mon May 17 11:06:23 2010 +0300 @@ -17,7 +17,8 @@ #include "btdelegatevisibility.h" -#include "btuimodel.h" +#include +#include #include #include "btqtconstants.h" #include @@ -27,8 +28,9 @@ /*! Constructor. */ -BtDelegateVisibility::BtDelegateVisibility( BtuiModel& model, QObject *parent ) - : BtAbstractDelegate( model, parent ) +BtDelegateVisibility::BtDelegateVisibility( + QObject *parent ) + : BtAbstractDelegate( NULL, NULL, parent ) { TRAP_IGNORE( mBtengSettings = CBTEngSettings::NewL(this) ); Q_CHECK_PTR( mBtengSettings ); diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btdelegatevisibility.h --- a/bluetoothengine/btui/btuidelegate/btdelegatevisibility.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btuidelegate/btdelegatevisibility.h Mon May 17 11:06:23 2010 +0300 @@ -35,7 +35,7 @@ Q_OBJECT public: - explicit BtDelegateVisibility( BtuiModel& model, QObject *parent = 0 ); + explicit BtDelegateVisibility( QObject *parent = 0 ); virtual ~BtDelegateVisibility(); diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btuidelegate.pro --- a/bluetoothengine/btui/btuidelegate/btuidelegate.pro Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btuidelegate/btuidelegate.pro Mon May 17 11:06:23 2010 +0300 @@ -21,6 +21,8 @@ INCLUDEPATH += . \ ../inc +RESOURCES += btuidelegate.qrc + CONFIG += qt \ hb \ dll @@ -29,13 +31,23 @@ btdelegatefactory.h \ btabstractdelegate.h \ btdelegatevisibility.h \ - btdelegatedevname.h + btdelegatedevname.h \ + btdelegateinquiry.h \ + btdelegateconnect.h \ + btdelegatepair.h \ + btdelegatedisconnect.h \ + btdelegatedevsecurity.h SOURCES += btdelegatepower.cpp \ btdelegatefactory.cpp \ btabstractdelegate.cpp \ btdelegatevisibility.cpp \ - btdelegatedevname.cpp + btdelegatedevname.cpp \ + btdelegateinquiry.cpp \ + btdelegateconnect.cpp \ + btdelegatepair.cpp \ + btdelegatedisconnect.cpp \ + btdelegatedevsecurity.cpp symbian: { SYMBIAN_PLATFORMS = WINSCW \ @@ -56,6 +68,7 @@ -lbtengdevman \ -lbtengconnman \ -lcentralrepository \ - -lflogger + -lflogger \ + -lbtuimodel //MMP_RULES -= EXPORTUNFROZEN } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/btuidelegate.qrc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btuidelegate.qrc Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,5 @@ + + + docml/pairwaitingdialog.docml + + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuidelegate/docml/pairwaitingdialog.docml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/docml/pairwaitingdialog.docml Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuimodel/activewrapper.cpp --- a/bluetoothengine/btui/btuimodel/activewrapper.cpp Wed May 05 09:56:48 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +0,0 @@ -/* -* ============================================================================ -* Name : btuimsettings_p.cpp -* Part of : BluetoothUI / bluetoothuimodel *** Info from the SWAD -* Description : Implements the data source settings class used by BluetoothUiDataModel. -* -* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* Nokia Corporation -* ============================================================================ -* Template version: 4.1 -*/ - -#include "activewrapper.h" - -/*! - Constructor. - */ -ActiveWrapper::ActiveWrapper( int id, int priority, QObject *parent ) -: QObject( parent ){ - d = new ActiveWrapperPrivate( this, id, priority ); -} - -/*! - Destructor. - */ -ActiveWrapper::~ActiveWrapper(){ - delete d; -} - -int ActiveWrapper::getRequestId(){ - return d->mRequestId; -} - -void ActiveWrapper::setRequestId( int reqId ){ - d->mRequestId = reqId; -} - - -void ActiveWrapper::setActive() { - d->SetActive(); -} - -void ActiveWrapper::cancel(){ - d->Cancel(); -} - -bool ActiveWrapper::isActive(){ - return (bool) d->IsActive(); -} - -void ActiveWrapper::emitRequestCompleted( int status, int id ) { - emit requestCompleted( status, id ); -} - -void ActiveWrapper::emitCancelRequest( int id ) { - emit cancelRequest( id ); -} - -inline void ActiveWrapper::emitError( int status, int id ) { - emit error( status, id ); -} - -/*! - Constructor. - */ -ActiveWrapperPrivate::ActiveWrapperPrivate( - ActiveWrapper *parent, int id, int priority ) -: CActive( (TInt) priority ), - q( parent ), - mRequestId( id ) { - CActiveScheduler::Add( this ); -} - -/*! - Destructor. - */ -ActiveWrapperPrivate::~ActiveWrapperPrivate() { - Cancel(); -} - -/*! - \reimp - Called by the active scheduler when the request has been cancelled. - */ -void ActiveWrapperPrivate::RunL() { - q->emitRequestCompleted( iStatus.Int(), mRequestId ); -} - -/*! - \reimp - Called by Cancel() when the request is outstanding. - */ -void ActiveWrapperPrivate::DoCancel() { - q->emitCancelRequest( mRequestId ); -} - -/*! - \reimp - Called by the active scheduler when an error in RunL has occurred. - */ -TInt ActiveWrapperPrivate::RunError( TInt error ) { - q->emitRequestCompleted( error, mRequestId ); - return KErrNone; -} diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuimodel/activewrapper.h --- a/bluetoothengine/btui/btuimodel/activewrapper.h Wed May 05 09:56:48 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -/* -* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* -* Description: -* -*/ - - -#ifndef ACTIVEWRAPPER_H -#define ACTIVEWRAPPER_H - -#include -#include - -class ActiveWrapperPrivate; - -/*! - \class ActiveWrapper - \brief Helper class for using active objects in Qt classes. - - ActiveWrapper is a helper class for using active objects - from any Qt class. It wraps a CActive-derived class in an interface - that uses Qt's signal-slot mechanism for communicating status changes - of the active object. - - \\sa bluetoothuimodel - */ -class ActiveWrapper : public QObject -{ - Q_OBJECT - friend class ActiveWrapperPrivate; - -public: - explicit ActiveWrapper( int id, - int priority = CActive::EPriorityStandard, QObject *parent = NULL ); - ~ActiveWrapper(); - - int getRequestId(); - void setRequestId(int reqId); - void setActive(); - void cancel(); - bool isActive(); - -signals: - void requestCompleted( int status, int id ); - void cancelRequest( int id ); - void error( int status, int id ); - -private: - void emitRequestCompleted( int status, int id ); - void emitCancelRequest( int id ); - void emitError( int status, int id ); - -private: - ActiveWrapperPrivate *d; - -}; - - -/*! - \class ActiveWrapperPrivate - \brief Private class of ActiveWrapper, for using active objects in Qt classes. - - ActiveWrapperPrivate is a helper class for using active objects - from any Qt class. It derives from CActive and allows other classes to use - it for passing to asynchronous function calls through its RequestStatus method. - - \\sa bluetoothuimodel - */ -class ActiveWrapperPrivate : public CActive -{ - friend class ActiveWrapper; - -public: - explicit ActiveWrapperPrivate( ActiveWrapper *parent, int id, int priority ); - ~ActiveWrapperPrivate(); - -private: - virtual void RunL(); - virtual void DoCancel(); - virtual TInt RunError( TInt error ); - -private: - ActiveWrapper *q; - int mRequestId; -}; - -#endif // ACTIVEWRAPPER_H diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuimodel/btdevicedata.cpp --- a/bluetoothengine/btui/btuimodel/btdevicedata.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btuimodel/btdevicedata.cpp Mon May 17 11:06:23 2010 +0300 @@ -15,24 +15,67 @@ * */ +#include "btdevicedata.h" +#include +#include +#include "btuiutil.h" +#include "btqtconstants.h" -#include "btdevicedata.h" +class DevTypeIconMapping { +public: + int majorDevClass; // major device class value from CoD + int minorDevClass; // minor device class value from CoD + int majorProperty; // one of major properties defined in BtDeviceModel + int minorProperty; // one of minor properties defined in BtDeviceModel + char* connectedIcon; // the icon name for connected device + char* unconnectedIcon; // the icon name for not connected device. +}; + +// mapping table from major and minor Device Classes to device types and icons +// which are specifically defined in btapplication namespace. +// (Note audio device mapping is not in this table due to its complex logic) +static const DevTypeIconMapping DeviceTypeIconMappingTable[] = +{ +{EMajorDeviceComputer, 0, BtDeviceModel::Computer, 0, + ":/icons/qgn_prop_bt_computer_connect.svg", ":/icons/qgn_prop_bt_computer.svg" }, +{EMajorDevicePhone, 0, BtDeviceModel::Phone, 0, + ":/icons/qgn_prop_bt_phone_connect.svg", ":/icons/qgn_prop_bt_phone.svg"}, +{EMajorDeviceLanAccessPoint, 0, BtDeviceModel::LANAccessDev, 0, + ":/icons/qgn_prop_bt_misc.svg", ":/icons/qgn_prop_bt_misc.svg" }, +{EMajorDevicePeripheral, EMinorDevicePeripheralKeyboard, + BtDeviceModel::Peripheral, BtDeviceModel::Keyboard, + ":/icons/qgn_prop_bt_keyboard_connect.svg", ":/icons/qgn_prop_bt_keyboard.svg"}, +{EMajorDevicePeripheral, EMinorDevicePeripheralPointer, + BtDeviceModel::Peripheral, BtDeviceModel::Mouse, + ":/icons/qgn_prop_bt_mouse_connect.svg", ":/icons/qgn_prop_bt_mouse.svg"}, +{EMajorDeviceImaging, 0, BtDeviceModel::ImagingDev, 0, + ":/icons/qgn_prop_bt_printer_connect.svg", ":/icons/qgn_prop_bt_printer.svg"}, +{EMajorDeviceWearable, 0, BtDeviceModel::WearableDev, 0, + ":/icons/qgn_prop_bt_misc.svg", ":/icons/qgn_prop_bt_misc.svg"}, +{EMajorDeviceToy, 0, BtDeviceModel::Toy, 0, + ":/icons/qgn_prop_bt_misc.svg", ":/icons/qgn_prop_bt_misc.svg"}, +}; + +static const int DeviceTypeIconMappingTableSize = + sizeof( DeviceTypeIconMappingTable ) / sizeof( DevTypeIconMapping ); /*! Constructor. */ -BtDeviceData::BtDeviceData( - const QSharedPointer &data, - QObject *parent) - : QObject( parent ), mData( data ), mBtengConnMan(0) +BtDeviceData::BtDeviceData( BtDeviceModel& model, QObject *parent ) + : QObject( parent ), mModel( model ), mDiscover( 0 ) { + mDeviceRepo = 0; + isSearchingDevice = false; TRAP_IGNORE({ - mBtengConnMan = CBTEngConnMan::NewL( this ); - mDeviceRepo = CBtDevRepository::NewL( ); + mDeviceRepo = CBtDevRepository::NewL(); }); + Q_CHECK_PTR( mDeviceRepo ); + TRAP_IGNORE( mDeviceRepo->AddObserverL( this ) ); - Q_CHECK_PTR( mBtengConnMan ); - Q_CHECK_PTR( mDeviceRepo ); + if ( mDeviceRepo->IsInitialized() ) { + initializeDataStore(); + } } /*! @@ -40,37 +83,441 @@ */ BtDeviceData::~BtDeviceData() { - delete mBtengConnMan; delete mDeviceRepo; + delete mDiscover; +} + + +/*! + Tells whether the given column is in the range of the setting list. + + \param row the row number to be checked + \param col the column number to be checked + + \return true if the given row and column are valid; false otherwise. +*/ +bool BtDeviceData::isValid( int row, int column) const +{ + return row >= 0 && row < mData.count() && column == 0; +} + +/*! + \return the total amount of rows. + +*/ +int BtDeviceData::rowCount() const +{ + return mData.count(); +} + +/*! + \return the total amount of columns. + +*/ +int BtDeviceData::columnCount() const +{ + return 1; +} + +/*! + Gets the value within a data item. + \param val contains the value at return. + \param row the row number which the value is from + \param col the column number which the value is from + \param role the role idenfier of the value. + */ +void BtDeviceData::data(QVariant& val, int row, int col, int role ) const +{ + if ( isValid( row, col ) ) { + val = mData.at( row ).value( role ); + } + else { + val = QVariant( QVariant::Invalid ); + } +} + +/*! + Gets the whole item data at the specified column + \param row the row number of the item data to be returned + \param col the column number of the item data to be returned + \return the item data + */ +BtuiModelDataItem BtDeviceData::itemData( int row, int col ) const +{ + if ( isValid( row, col ) ) { + return mData.at( row ); + } + return BtuiModelDataItem(); +} + + +/*! + Requests the model to searching Bluetooth devices. + \return true if the request is accepted; false otherwise + */ +bool BtDeviceData::searchDevice() +{ + int err ( 0 ); + removeTransientDevices(); + if ( !mDiscover ) { + TRAP(err, mDiscover = CAdvanceDevDiscoverer::NewL( *mDeviceRepo, *this) ); + } + if ( !err ) { + TRAP(err, mDiscover->DiscoverDeviceL() ); + } + isSearchingDevice = true; + return err == 0; +} + +/*! + Cancels a possible outstanding device search request. + */ +void BtDeviceData::cancelSearchDevice() +{ + if ( mDiscover ) { + isSearchingDevice = false; + mDiscover->CancelDiscovery(); + } } -void BtDeviceData::ConnectComplete( TBTDevAddr& addr, TInt err, - RBTDevAddrArray* conflicts ) +/*! + Removes transient (not-in-registry) devices + (added as the result of device search). + */ +void BtDeviceData::removeTransientDevices() +{ + // clear in-range property for all device items in this model. + int cnt = mData.count(); + for ( int i = mData.count() - 1; i > -1; --i) + { + const BtuiModelDataItem& qtdev = mData.at(i); + if(isDeviceInRange(qtdev)) { + if(isDeviceInRegistry(qtdev)) { + // we cannot remove this device as it is in registry. + // remove it in-range property. + setMajorProperty(mData[i], BtDeviceModel::InRange, false); + updateRssi(mData[i], RssiInvalid); + mModel.emitDataChanged( i, 0, this ); + } + else { + // this device is not in-registry. Delete it from local + // store. + mModel.beginRemoveRows(QModelIndex(), i, i); + mData.removeAt( i ); + mModel.endRemoveRows(); + } + } + } +} + +/*! + callback from repository. + re-initialize our store. + */ +void BtDeviceData::RepositoryInitialized() +{ + initializeDataStore(); +} + +/*! + callback from repository. + update our store. + */ +void BtDeviceData::DeletedFromRegistry( const TBTDevAddr& addr ) { - Q_UNUSED( addr ); - Q_UNUSED( err ); - Q_UNUSED( conflicts ); + int i = indexOf( addr ); + if ( i > -1 ) { + if ( isSearchingDevice && isDeviceInRange( mData.at(i) ) ) { + // device searching is ongoing, and it is in-range. we can not + // remore it from model now. + // clear-registry related properties, so that + // we get a chance to clean it after device searching later. + setMajorProperty(mData[i], BtDeviceModel::RegistryProperties, false); + mModel.emitDataChanged( i, 0, this ); + } + else { + mModel.beginRemoveRows(QModelIndex(), i, i); + mData.removeAt( i ); + mModel.endRemoveRows(); + } + } +} + +/*! + callback from repository. + update our store. + */ +void BtDeviceData::AddedToRegistry( const CBtDevExtension& dev ) +{ + ChangedInRegistry( dev, 0 ); +} + +/*! + callback from repository. + update our store. + */ +void BtDeviceData::ChangedInRegistry( + const CBtDevExtension& dev, TUint similarity ) +{ + int i = indexOf( dev.Addr() ); + if ( i == -1 ) { + BtuiModelDataItem devData; + if ( !isSearchingDevice ) { + // Rssi is only available at device inquiry stage. + // We initialize this property to an invalid value + updateRssi(devData, RssiInvalid); + } + // add device-in-registry property: + setMajorProperty(devData, BtDeviceModel::InRegistry, true); + updateDeviceProperty(devData, dev, 0 ); + mModel.beginInsertRows( QModelIndex(), mData.count(), mData.count() ); + mData.append( devData ); + mModel.endInsertRows(); + } + else { + updateDeviceProperty(mData[i], dev, similarity ); + setMajorProperty(mData[i], BtDeviceModel::InRegistry, true); + mModel.emitDataChanged( i, 0, this ); + } } -void BtDeviceData::DisconnectComplete( TBTDevAddr& addr, TInt err ) +/*! + callback from repository. + update our store. + */ +void BtDeviceData::ServiceConnectionChanged( + const CBtDevExtension& dev, TBool connected ) { - Q_UNUSED( addr ); - Q_UNUSED( err ); + int i = indexOf( dev.Addr() ); + if ( i > -1 ) { + int preconn = BtDeviceModel::Connected + & mData[i][BtDeviceModel::MajorPropertyRole].toInt(); + // we only update and signal if connection status is really + // changed: + if ( ( preconn != 0 && !connected ) + || ( preconn == 0 && connected ) ) { + setMajorProperty(mData[i], BtDeviceModel::Connected, connected ); + mModel.emitDataChanged( i, 0, this ); + } + } + // it is impossible that a device has connected but it is not in + // our local store according to current bteng services. + // need to take more care in future when this becomes possible. } -void BtDeviceData::BtDeviceDeleted( const TBTDevAddr& addr ) +/*! + callback from device search. + update our store. + */ +void BtDeviceData::HandleNextDiscoveryResultL( + const TInquirySockAddr& inqAddr, const TDesC& name ) { - Q_UNUSED( addr ); + int pos = indexOf( inqAddr.BTAddr() ); + const CBtDevExtension* dev = mDeviceRepo->Device( inqAddr.BTAddr() ); + + //RssiRole + int rssi( RssiInvalid ); // initialize to an invalid value. + if( inqAddr.ResultFlags() & TInquirySockAddr::ERssiValid ) { + rssi = inqAddr.Rssi(); + } + + if ( pos == -1 ) { + BtuiModelDataItem devData; + setMajorProperty(devData, BtDeviceModel::InRange, true); + updateRssi(devData, rssi); + CBtDevExtension* devExt(NULL); + TRAP_IGNORE( { + devExt = CBtDevExtension::NewLC( inqAddr, name ); + CleanupStack::Pop(); }); + updateDeviceProperty(devData, *devExt, 0); + delete devExt; + mModel.beginInsertRows( QModelIndex(), mData.count(), mData.count() ); + mData.append( devData ); + mModel.endInsertRows(); + } + else { + setMajorProperty(mData[pos], BtDeviceModel::InRange, true); + updateRssi(mData[pos], rssi); + mModel.emitDataChanged( pos, 0, this ); + } +} + +/*! + callback from device search. + inform client. + */ +void BtDeviceData::HandleDiscoveryCompleted( TInt error ) +{ + isSearchingDevice = false; + mModel.emitdeviceSearchCompleted( (int) error ); +} + +void BtDeviceData::initializeDataStore() + { + // it is possible that we are searching devices. + // We use a simple but not-so-efficient method to update the model. + + // If the device store is not empty, we clear + // registry property from these devices first. + for (int i = 0; i < mData.count(); ++i) { + setMajorProperty(mData[i], BtDeviceModel::RegistryProperties, false); + } + if ( mData.count() ) { + // need to update view because we have changed device properties. + QModelIndex top = mModel.createIndex(0, 0, this); + QModelIndex bottom = mModel.createIndex(mData.count() - 1, 0, this); + mModel.emitDataChanged( top, bottom ); + } + + const RDevExtensionArray& devs = mDeviceRepo->AllDevices(); + for (int i = 0; i < devs.Count(); ++i) { + int pos = indexOf( devs[i]->Addr() ); + if ( pos > -1 ) { + // add device-in-registry property: + setMajorProperty(mData[pos], BtDeviceModel::InRegistry, true); + updateDeviceProperty(mData[pos], *(devs[i]), 0); + mModel.emitDataChanged( pos, 0, this ); + } + else { + BtuiModelDataItem devData; + // add device-in-registry property: + setMajorProperty(devData, BtDeviceModel::InRegistry, true); + updateDeviceProperty(devData, *( devs[i] ), 0 ); + mModel.beginInsertRows(QModelIndex(), mData.count(), mData.count() ); + mData.append( devData ); + mModel.endInsertRows(); + } + } } -void BtDeviceData::BtDeviceAdded( const CBTDevice& device ) +void BtDeviceData::updateDeviceProperty(BtuiModelDataItem& qtdev, + const CBtDevExtension& dev, TUint similarity ) { - Q_UNUSED( device ); + // similarity is not used currently. + // It is possible to gain better performance + // with this info to avoid re-manipulate + // unchanged properties. + Q_UNUSED(similarity); + + //DevDisplayNameRole + QString str = QString::fromUtf16( + dev.Alias().Ptr(), dev.Alias().Length() ); + qtdev[BtDeviceModel::NameAliasRole] = QVariant( str ); + + //DevAddrReadableRole + addrSymbianToReadbleString( str, dev.Addr() ); + qtdev[BtDeviceModel::ReadableBdaddrRole] = QVariant( str ); + + //LastUsedTimeRole + TDateTime symDt = dev.Device().Used().DateTime(); + QDate date( symDt.Year(), symDt.Month(), symDt.Day() ); + QTime time( symDt.Hour(), symDt.Minute(), symDt.MicroSecond() / 1000 ); + QDateTime qdt(date, time); + qtdev[BtDeviceModel::LastUsedTimeRole] = QVariant(qdt); + + // set paired status: + setMajorProperty(qtdev, BtDeviceModel::Bonded, isBonded( dev.Device() )); + + // set blocked status: + setMajorProperty(qtdev, BtDeviceModel::Blocked, + dev.Device().GlobalSecurity().Banned() ); + // set trusted status: + setMajorProperty(qtdev, BtDeviceModel::Trusted, + dev.Device().GlobalSecurity().NoAuthorise() ); + + //CoDRole + //MinorPropertyRole + int cod = static_cast( dev.Device().DeviceClass().DeviceClass() ); + qtdev[BtDeviceModel::CoDRole] = QVariant(cod); + + // Initially, clear CoD related properties: + int majorProperty = qtdev[BtDeviceModel::MajorPropertyRole].toInt() & + ~BtDeviceModel::CodProperties; + + int minorProperty = BtDeviceModel::NullProperty; + + // device type must be mapped according to CoD: + int majorDevCls = dev.Device().DeviceClass().MajorDeviceClass(); + int minorDevCls = dev.Device().DeviceClass().MinorDeviceClass(); + + int i; + for (i = 0; i < DeviceTypeIconMappingTableSize; ++i ) { + if ( DeviceTypeIconMappingTable[i].majorDevClass == majorDevCls && + ( DeviceTypeIconMappingTable[i].minorDevClass == 0 || + DeviceTypeIconMappingTable[i].minorDevClass == minorDevCls ) ) { + // device classes match a item in table, get the mapping: + majorProperty |= DeviceTypeIconMappingTable[i].majorProperty; + minorProperty |= DeviceTypeIconMappingTable[i].minorProperty; + break; + } + } + + // AV device mapping are not defined in the table, do mapping here if no device + // type mapped so far: + if ( i == DeviceTypeIconMappingTableSize) { + // audio device, carkit, headset or speaker: + if( ( majorDevCls == EMajorDeviceAV) + || (dev.Device().DeviceClass().MajorServiceClass() == EMajorServiceRendering + && majorDevCls != EMajorDeviceImaging) ) { + + majorProperty |= BtDeviceModel::AVDev; + + if( minorDevCls == EMinorDeviceAVCarAudio ) { + // carkit: + minorProperty |= BtDeviceModel::Carkit; + } + else { + // headset: + minorProperty |= BtDeviceModel::Headset; + } + } + } + + qtdev[BtDeviceModel::MajorPropertyRole] = QVariant( majorProperty ); + qtdev[BtDeviceModel::MinorPropertyRole] = QVariant( minorProperty ); } -void BtDeviceData::BtDeviceChanged( const CBTDevice& device, TUint similarity ) +int BtDeviceData::indexOf( const TBTDevAddr& addr ) const { - Q_UNUSED( device ); - Q_UNUSED( similarity ); + QString addrStr; + addrSymbianToReadbleString( addrStr, addr ); + for (int i = 0; i < mData.count(); ++i ) { + if ( mData.at( i ).value( BtDeviceModel::ReadableBdaddrRole ) + == addrStr ) { + return i; + } + } + return -1; } +void BtDeviceData::updateRssi(BtuiModelDataItem& qtdev, int rssi ) + { + qtdev[BtDeviceModel::RssiRole] = QVariant( rssi ); + } + +/*! + Add the specified major property to the device if addto is true. + Otherwise the property is removed from the device. + */ +void BtDeviceData::setMajorProperty( + BtuiModelDataItem& qtdev, int prop, bool addto) +{ + if ( addto ) { + qtdev[BtDeviceModel::MajorPropertyRole] = + QVariant( qtdev[BtDeviceModel::MajorPropertyRole].toInt() | prop); + } + else { + qtdev[BtDeviceModel::MajorPropertyRole] = + QVariant( qtdev[BtDeviceModel::MajorPropertyRole].toInt() & ~prop); + } +} + +bool BtDeviceData::isDeviceInRange( const BtuiModelDataItem& qtdev ) +{ + return BtDeviceModel::InRange & qtdev[BtDeviceModel::MajorPropertyRole].toInt(); +} + +bool BtDeviceData::isDeviceInRegistry( const BtuiModelDataItem& qtdev ) +{ + return BtDeviceModel::InRegistry & qtdev[BtDeviceModel::MajorPropertyRole].toInt(); +} diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuimodel/btdevicedata.h --- a/bluetoothengine/btui/btuimodel/btdevicedata.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btuimodel/btdevicedata.h Mon May 17 11:06:23 2010 +0300 @@ -18,63 +18,104 @@ #ifndef BTDEVICEDATA_H #define BTDEVICEDATA_H -#include +#include "btuimodeltypes.h" +#include + #include -#include #include -#include "btuimodel.h" +#include + + +class CAdvanceDevDiscoverer; /*! \class BtDeviceData - \brief class for handling local Bluetooth setting updates. + \brief class for providing remote device data. BtDeviceData class is responsible for providing the latest information - regarding the properties of remote devices and the connection status. + regarding the properties of remote devices. \\sa bluetoothuimodel */ class BtDeviceData : public QObject, - public MBTEngConnObserver, - public MBtDevRepositoryObserver + public MBtDevRepositoryObserver, + public MDevDiscoveryObserver { Q_OBJECT public: - BtDeviceData( - const QSharedPointer &data, - QObject *parent = 0 - ); + explicit BtDeviceData( BtDeviceModel& model, QObject *parent = 0 ); virtual ~BtDeviceData(); -private: - // from MBTEngConnObserver + bool isValid( int row, int col ) const; + + int rowCount() const; + + int columnCount() const; + + void data(QVariant& val, int row, int col, int role ) const; - void ConnectComplete( TBTDevAddr& addr, TInt err, - RBTDevAddrArray* conflicts ); - - void DisconnectComplete( TBTDevAddr& addr, TInt err ); + BtuiModelDataItem itemData( int row, int col ) const; + + bool searchDevice(); + void cancelSearchDevice(); + + void removeTransientDevices(); + +private: // From MBtDeviceRepositoryObserver - void BtDeviceDeleted( const TBTDevAddr& addr ); + void RepositoryInitialized(); + + void DeletedFromRegistry( const TBTDevAddr& addr ); + + void AddedToRegistry( const CBtDevExtension& dev ); + + void ChangedInRegistry( const CBtDevExtension& dev, TUint similarity ); - void BtDeviceAdded( const CBTDevice& device ); + void ServiceConnectionChanged( + const CBtDevExtension& dev, TBool connected ); - void BtDeviceChanged( const CBTDevice& device, TUint similarity ); + // from MDevDiscoveryObserver + void HandleNextDiscoveryResultL( + const TInquirySockAddr& inqAddr, const TDesC& name ); + + void HandleDiscoveryCompleted( TInt error ); public slots: //void activeRequestCompleted( int status, int id ); private: + void initializeDataStore(); + + void updateDeviceProperty(BtuiModelDataItem& qtdev, + const CBtDevExtension& dev, TUint similarity ); + + int indexOf( const TBTDevAddr& addr ) const; + + void updateRssi(BtuiModelDataItem& qtdev, int rssi ); + + void setMajorProperty( BtuiModelDataItem& qtdev, int prop, bool addto); + + bool isDeviceInRange( const BtuiModelDataItem& qtdev ); + + bool isDeviceInRegistry( const BtuiModelDataItem& qtdev ); + private: - QSharedPointer mData; + + BtuiModelDataSource mData; - CBTEngConnMan *mBtengConnMan; + BtDeviceModel& mModel; CBtDevRepository* mDeviceRepo; + CAdvanceDevDiscoverer* mDiscover; + + bool isSearchingDevice; + Q_DISABLE_COPY(BtDeviceData) }; diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuimodel/btdevicemodel.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuimodel/btdevicemodel.cpp Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,149 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include +#include "btdevicedata.h" + +/*! + This Constructor creates new instances of model data structure. + */ +BtDeviceModel::BtDeviceModel( QObject *parent ) + : QAbstractItemModel( parent ) +{ + mDeviceData = QSharedPointer( new BtDeviceData( *this ) ); +} + +/*! + This Constructor shares the instances of model data structure with the + given model. + */ +BtDeviceModel::BtDeviceModel( const BtDeviceModel &model, QObject *parent ) + : QAbstractItemModel( parent ) +{ + mDeviceData = model.mDeviceData; +} + +/*! + Destructor. + */ +BtDeviceModel::~BtDeviceModel() +{ +} + +/*! + Requests the model to searching Bluetooth devices. + \return true if the request is accepted; false otherwise + */ +bool BtDeviceModel::searchDevice() +{ + return mDeviceData->searchDevice(); +} + +/*! + Cancels a possible outstanding device search request. + */ +void BtDeviceModel::cancelSearchDevice() +{ + mDeviceData->cancelSearchDevice(); +} + +/*! + Removes transient (not-in-registry) devices + which were added as the result of device search. + */ +void BtDeviceModel::removeTransientDevices() +{ + mDeviceData->removeTransientDevices(); +} + +/*! + \reimp + */ +QModelIndex BtDeviceModel::index( int row, int column, const QModelIndex &parent ) const +{ + Q_UNUSED( parent ); + if ( mDeviceData->isValid( row, column ) ) { + return createIndex( row, column, mDeviceData.data() ); + } + // invalid row and column: + return QModelIndex(); +} + +/*! + \reimp + */ +QModelIndex BtDeviceModel::parent( const QModelIndex &child ) const +{ + Q_UNUSED( child ); + // root level, no parent. + return QModelIndex(); +} + +/*! + \reimp + */ +int BtDeviceModel::rowCount( const QModelIndex &parent ) const +{ + Q_UNUSED( parent ); + return mDeviceData->rowCount(); +} + +/*! + \reimp + */ +int BtDeviceModel::columnCount( const QModelIndex &parent ) const +{ + Q_UNUSED( parent ); + return mDeviceData->columnCount(); +} + +/*! + \reimp + */ +QVariant BtDeviceModel::data( const QModelIndex &index, int role ) const +{ + QVariant val( QVariant::Invalid ); + mDeviceData.data()->data( val, index.row(), index.column(), role ); + return val; +} + +QMap BtDeviceModel::itemData( const QModelIndex & index ) const +{ + return mDeviceData.data()->itemData( index.row(), index.column() ); +} + +/*! + emits dataChanged signal. + */ +void BtDeviceModel::emitDataChanged( int row, int column, void *parent ) +{ + QModelIndex idx = createIndex( row, column, parent ); + emit dataChanged( idx, idx ); +} + +void BtDeviceModel::emitDataChanged(const QModelIndex &top, const QModelIndex &bottom ) + { + emit dataChanged( top, bottom ); + } + +/*! + emits deviceSearchCompleted signal. + */ +void BtDeviceModel::emitdeviceSearchCompleted( int error ) +{ + emit deviceSearchCompleted( error ); +} diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuimodel/btlocalsetting.cpp --- a/bluetoothengine/btui/btuimodel/btlocalsetting.cpp Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btuimodel/btlocalsetting.cpp Mon May 17 11:06:23 2010 +0300 @@ -31,8 +31,8 @@ /*! Constructor. */ -BtLocalSetting::BtLocalSetting( BtuiModel& model, QObject *parent ) - : QObject( parent ), mModel(model), mLocalDeviceWatcher(0) +BtLocalSetting::BtLocalSetting( BtSettingModel& model, QObject *parent ) + : QObject( parent), mModel( model ), mLocalDeviceWatcher(0) { int err( 0 ); if (!err ) { @@ -50,7 +50,7 @@ Q_CHECK_PTR( mBtengSetting ); Q_CHECK_PTR( mLocalDeviceWatcher ); - for ( int i = 0; i < BtuiModel::LocalSettingColCount; ++i ) { + for ( int i = 0; i < BtSettingModel::LocalSettingRowCount; ++i ) { // Initialize the list with empty values. mData.append( BtuiModelDataItem() ); } @@ -90,58 +90,91 @@ } -bool BtLocalSetting::isValid( int column) const +/*! + Tells whether the given column is in the range of the setting list. + + \param row the row number to be checked + \param col the column number to be checked + + \return true if the given row and column are valid; false otherwise. +*/ +bool BtLocalSetting::isValid( int row, int column) const { - return column < mData.count(); + return row >= 0 && row < mData.count() && column == 0; } -int BtLocalSetting::itemCount() const +/*! + \return the total amount of rows. + +*/ +int BtLocalSetting::rowCount() const { return mData.count(); } -void BtLocalSetting::data(QVariant& val, int col, int role ) const +/*! + \return the total amount of columns. + +*/ +int BtLocalSetting::columnCount() const { - if ( isValid( col ) ) { - val = mData.at( col ).value( role ); + return 1; +} + +/*! + Gets the value within a data item. + \param val contains the value at return. + \param row the row number which the value is from + \param col the column number which the value is from + \param role the role idenfier of the value. + */ +void BtLocalSetting::data(QVariant& val, int row, int col, int role ) const +{ + if ( isValid( row, col ) ) { + val = mData.at( row ).value( role ); } else { val = QVariant( QVariant::Invalid ); } } -BtuiModelDataItem BtLocalSetting::itemData( int col ) const +/*! + Gets the whole item data at the specified column + \param row the row number of the item data to be returned + \param col the column number of the item data to be returned + \return the item data + */ +BtuiModelDataItem BtLocalSetting::itemData( int row, int col ) const { - if ( isValid( col ) ) { - return mData.at( col ); + if ( isValid( row, col ) ) { + return mData.at( row ); } return BtuiModelDataItem(); } - /*! Provides notification of changes in the power state of the Bluetooth hardware. - @param state EBTPowerOff if the BT hardware has been turned off, + \param state EBTPowerOff if the BT hardware has been turned off, EBTPowerOn if it has been turned on. */ void BtLocalSetting::PowerStateChanged( TBTPowerStateValue state ) { setPowerSetting( state ); - emit settingDataChanged( BtuiModel::LocalSettingRow, BtuiModel::PowerStateCol, this ); + mModel.emitDataChanged( BtSettingModel::PowerStateRow, 0, this ); } /*! Provides notification of changes in the discoverability mode of the Bluetooth hardware. - @param state EBTDiscModeHidden if the BT hardware is in hidden mode, + \param state EBTDiscModeHidden if the BT hardware is in hidden mode, EBTDiscModeGeneral if it is in visible mode. */ void BtLocalSetting::VisibilityModeChanged( TBTVisibilityMode state ) { setVisibilityMode( state ); - emit settingDataChanged( BtuiModel::LocalSettingRow, BtuiModel::VisibilityCol, this ); + mModel.emitDataChanged( BtSettingModel::VisibilityRow, 0, this ); } void BtLocalSetting::RequestCompletedL( CBtSimpleActive* active, TInt status ) { @@ -176,11 +209,11 @@ { // To-do: the data structure initialization is not impled yet in the model BtuiModelDataItem& item = - mData[ BtuiModel::BluetoothNameCol ]; + mData[ BtSettingModel::LocalBtNameRow ]; if ( item.isEmpty() ) { // Initialize with additional information on the setting - item[ BtuiModel::SettingIdentity ] = QVariant( tr( "Local Bluetooth name" ) ); + item[ BtSettingModel::SettingNameRole ] = QVariant( tr( "Local Bluetooth name" ) ); } bool setByUser = !name.isEmpty(); @@ -189,15 +222,15 @@ // Bluetooth name has been set by the user. // The flag is set to true if the name has been set. // requirement does not - //nitem[ BtuiModel::SettingValueParam ] = QVariant( setByUser ); + //nitem[ BtSettingModel::SettingValueParamRole ] = QVariant( setByUser ); QString resolvedName( name ); if ( resolvedName.isEmpty() ) { // We get the default name as suggestion for the user to set. getNameFromRegistry( resolvedName ); } - item[ BtuiModel::settingDisplay ] = QVariant( resolvedName ); - item[ BtuiModel::SettingValue ] = QVariant( resolvedName ); + item[ BtSettingModel::settingDisplayRole ] = QVariant( resolvedName ); + item[ BtSettingModel::SettingValueRole ] = QVariant( resolvedName ); } /*! @@ -206,40 +239,40 @@ void BtLocalSetting::setPowerSetting( TBTPowerStateValue state ) { BtuiModelDataItem& item = - mData[ BtuiModel::PowerStateCol ]; + mData[ BtSettingModel::PowerStateRow ]; if ( item.isEmpty() ) { // Initialize with additional information on the setting - item[ BtuiModel::SettingIdentity ] = QVariant( tr( "Bluetooth power" ) ); + item[ BtSettingModel::SettingNameRole ] = QVariant( tr( "Bluetooth power" ) ); } bool powerOn = ( state == EBTPowerOn ); - item[ BtuiModel::settingDisplay ] = + item[ BtSettingModel::settingDisplayRole ] = powerOn ? QVariant( tr( "On" ) ) : QVariant( tr( "Off" ) ); - item[ BtuiModel::SettingValue ] = QVariant( powerOn ); + item[ BtSettingModel::SettingValueRole ] = QVariant( powerOn ); } void BtLocalSetting::setVisibilityMode( TBTVisibilityMode state ) { - BtuiModelDataItem& item = mData[ BtuiModel::VisibilityCol ]; + BtuiModelDataItem& item = mData[ BtSettingModel::VisibilityRow ]; if ( item.isEmpty() ) { - item[ BtuiModel::SettingIdentity ] = QVariant( tr( "Phone visibility" ) ); + item[ BtSettingModel::SettingNameRole ] = QVariant( tr( "Phone visibility" ) ); } if ( state == EBTVisibilityModeHidden ) { - item [ BtuiModel::settingDisplay ] = QVariant( tr( "Hidden" ) ); + item [ BtSettingModel::settingDisplayRole ] = QVariant( tr( "Hidden" ) ); } else if ( state == EBTVisibilityModeGeneral ) { - item [ BtuiModel::settingDisplay ] = QVariant( tr( "Visible" ) ); + item [ BtSettingModel::settingDisplayRole ] = QVariant( tr( "Visible" ) ); } else { - item [ BtuiModel::settingDisplay ] = QVariant( tr( "Temporarily visible" ) ); + item [ BtSettingModel::settingDisplayRole ] = QVariant( tr( "Temporarily visible" ) ); } - item [ BtuiModel::SettingValue ] = QVariant( QtVisibilityMode(state) ); + item [ BtSettingModel::SettingValueRole ] = QVariant( QtVisibilityMode(state) ); } /*! diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuimodel/btlocalsetting.h --- a/bluetoothengine/btui/btuimodel/btlocalsetting.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btuimodel/btlocalsetting.h Mon May 17 11:06:23 2010 +0300 @@ -24,14 +24,13 @@ #ifndef BTLOCALSETTING_H #define BTLOCALSETTING_H -#include +#include "btsettingmodel.h" + #include #include #include #include -#include "btuimodel.h" - /*! \class BtuimSettings \brief class for handling local Bluetooth setting updates. @@ -48,21 +47,19 @@ Q_OBJECT public: - explicit BtLocalSetting( BtuiModel& model, QObject *parent = 0 ); + explicit BtLocalSetting( BtSettingModel& model, QObject *parent = 0 ); virtual ~BtLocalSetting(); - bool isValid( int col) const; + bool isValid( int row, int col ) const; - int itemCount() const; - - void data(QVariant& val, int col, int role ) const; + int rowCount() const; - BtuiModelDataItem itemData( int col ) const; - -signals: - - void settingDataChanged( int row, int column, void *parent ); + int columnCount() const; + + void data(QVariant& val, int row, int col, int role ) const; + + BtuiModelDataItem itemData( int row, int col ) const; private: // from MBTEngSettingsObserver @@ -79,7 +76,6 @@ void HandleError( CBtSimpleActive* active, TInt error ); - public slots: //void activeRequestCompleted( int status, int id ); @@ -97,9 +93,10 @@ void getNameFromRegistry( QString &name ); private: + BtuiModelDataSource mData; - BtuiModel& mModel; + BtSettingModel& mModel; CBTEngSettings *mBtengSetting; diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuimodel/btsettingmodel.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuimodel/btsettingmodel.cpp Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,116 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include +#include "btlocalsetting.h" +#include "bluetoothuitrace.h" + +/*! + This Constructor creates new instances of model data structure. + */ +BtSettingModel::BtSettingModel( QObject *parent ) + : QAbstractItemModel( parent ) +{ + mLocalSetting = QSharedPointer( new BtLocalSetting( *this ) ); +} + +/*! + This Constructor shares the instances of model data structure with the + given model. + */ +BtSettingModel::BtSettingModel( const BtSettingModel &model, QObject *parent ) + : QAbstractItemModel( parent ) +{ + mLocalSetting = model.mLocalSetting; +} + +/*! + Destructor. + */ +BtSettingModel::~BtSettingModel() +{ +} + +/*! + \reimp + */ +QModelIndex BtSettingModel::index( int row, int column, const QModelIndex &parent ) const +{ + Q_UNUSED( parent ); + if ( mLocalSetting->isValid( row, column ) ) { + return createIndex( row, column, mLocalSetting.data() ); + } + // invalid row and column: + return QModelIndex(); +} + +/*! + \reimp + */ +QModelIndex BtSettingModel::parent( const QModelIndex &child ) const +{ + Q_UNUSED( child ); + // root level, no parent. + return QModelIndex(); +} + +/*! + \reimp + */ +int BtSettingModel::rowCount( const QModelIndex &parent ) const +{ + Q_UNUSED( parent ); + return mLocalSetting->rowCount(); +} + +/*! + \reimp + */ +int BtSettingModel::columnCount( const QModelIndex &parent ) const +{ + Q_UNUSED( parent ); + return mLocalSetting->columnCount(); +} + +/*! + \reimp + */ +QVariant BtSettingModel::data( const QModelIndex &index, int role ) const +{ + QVariant val( QVariant::Invalid ); + mLocalSetting.data()->data( val, index.row(), index.column(), role ); + return val; +} + +QMap BtSettingModel::itemData( const QModelIndex & index ) const +{ + return mLocalSetting.data()->itemData( index.row(), index.column() ); +} + +/*! + emits dataChanged signal. + */ +void BtSettingModel::emitDataChanged( int row, int column, void *parent ) +{ + QModelIndex idx = createIndex( row, column, parent ); + emit dataChanged( idx, idx ); +} + +void BtSettingModel::emitDataChanged(const QModelIndex &top, const QModelIndex &bottom ) + { + emit dataChanged( top, bottom ); + } diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuimodel/btuimodel.cpp --- a/bluetoothengine/btui/btuimodel/btuimodel.cpp Wed May 05 09:56:48 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,138 +0,0 @@ -/* -* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* -* Description: -* -*/ - -#include "btuimodel.h" -#include "btlocalsetting.h" - -/*! - This Constructor creates new instances of model data structure. - */ -BtuiModel::BtuiModel( QObject *parent ) - : QAbstractItemModel( parent ) -{ - mLocalSetting = QSharedPointer( new BtLocalSetting( *this ) ); - bool b = connect( mLocalSetting.data(), SIGNAL(settingDataChanged(int,int,void*)), this, SLOT(btDataChanged(int,int,void*))); - Q_ASSERT( b ); -} - -/*! - This Constructor shares the instances of model data structure with the - given model. - */ -BtuiModel::BtuiModel( const BtuiModel &model, QObject *parent ) - : QAbstractItemModel( parent ) -{ - mLocalSetting = model.mLocalSetting; - bool b = connect( mLocalSetting.data(), SIGNAL(settingDataChanged(int,int,void*)), this, SLOT(btDataChanged(int,int,void*))); - Q_ASSERT( b ); -} - -/*! - Destructor. - */ -BtuiModel::~BtuiModel() -{ -} - -/*! - \reimp - */ -QModelIndex BtuiModel::index( int row, int column, const QModelIndex &parent ) const -{ - Q_UNUSED( parent ); - if ( row == LocalSettingRow - && mLocalSetting->isValid( column ) ) { - // local setting data: - return createIndex( row, column, mLocalSetting.data() ); - } - else if ( row == RemoteDeviceRow ) { - - } - // invalid row and column: - return QModelIndex(); -} - -/*! - \reimp - */ -QModelIndex BtuiModel::parent( const QModelIndex &child ) const -{ - Q_UNUSED( child ); - // root level, no parent. - return QModelIndex(); -} - -/*! - \reimp - */ -int BtuiModel::rowCount( const QModelIndex &parent ) const -{ - Q_UNUSED( parent ); - return ModelRowCount; -} - -/*! - \reimp - */ -int BtuiModel::columnCount( const QModelIndex &parent ) const -{ - if ( parent.row() == LocalSettingRow - && mLocalSetting->isValid( parent.column() ) ) { - // local setting data: - return mLocalSetting->itemCount(); - } - else if ( parent.row() == RemoteDeviceRow ) { - } - return 0; -} - -/*! - \reimp - */ -QVariant BtuiModel::data( const QModelIndex &index, int role ) const -{ - QVariant val( QVariant::Invalid ); - if ( index.row() == LocalSettingRow ) { - mLocalSetting.data()->data( val, index.column(), role ); - } - else if ( index.row() == RemoteDeviceRow ) { - } - return val; -} - -QMap BtuiModel::itemData( const QModelIndex & index ) const -{ - if ( index.row() == LocalSettingRow ) { - mLocalSetting.data()->itemData( index.column() ); - } - else if ( index.row() == RemoteDeviceRow ) { - } - return QMap(); -} - -/*! - Slot for receiving notification of changes from the data source. - Forward the notification using dataChanged signal. - */ -void BtuiModel::btDataChanged( int row, int column, void *parent ) -{ - (void) parent; - QModelIndex idx = createIndex( row, column, parent ); - emit dataChanged( idx, idx ); -} - - diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuimodel/btuimodel.h --- a/bluetoothengine/btui/btuimodel/btuimodel.h Wed May 05 09:56:48 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,152 +0,0 @@ -/* -* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* -* Description: -* -*/ - -#ifndef BTUIMODEL_H -#define BTUIMODEL_H - - -#include -#include -#include - -class BtLocalSetting; -class BtDeviceStore; - -// A data item in this model. For example, power state item consists -// of the information regarding the current Bluetooth power state. -typedef QMap< int, QVariant > BtuiModelDataItem; - -// A category of the model data for specific group -typedef QList< BtuiModelDataItem > BtuiModelDataSource; - -#ifdef BUILD_BTUIMODEL -#define BTUIMODEL_IMEXPORT Q_DECL_EXPORT -#else -#define BTUIMODEL_IMEXPORT Q_DECL_IMPORT -#endif - -/*! - \class BtuiModel - \brief The data model provided to Bluetooth UIs in QT - - BtuiModel provides APIs for accessing certain BT data, such as local Bluetooth - settings and the properties of remote BT devices. In addition, signals from this - model are provided for being informed of data update. - - This model is in two dimension (2 rows * n columns), i.e., - - row 0 (BT local setting) - col 0 (local device name) - col 1 (power state) - ... - row 1 (remote devices) - col 0 ( a remote device) - col 1 ( another device) - ... - - The data in this model is non-modifiable from the user interface (except device - search may add a number of in-range devices temporarily) , - determined by the characteristics of Bluetooth, the underline BT software - services and the BT application requirements. - - Whenever feasible, the detailed description should contain a simple - example code example: - \code - // ... - \endcode - - \sa \link model-view-programming.html Model/View Programming\endlink - */ - -class BTUIMODEL_IMEXPORT BtuiModel : public QAbstractItemModel -{ - Q_OBJECT - Q_ENUMS( RowId LocalSettingCol LocalSettingDataRole ) - -public: - - /** - * The parent row identifier of data model. Data in this model is grouped into - * two categories: the local Bluetooth settings and the remote device - * database. The data of each category is stored in multiple - * rows of a specified row. - */ - enum RowId { - LocalSettingRow = 0, - RemoteDeviceRow = 1, - ModelRowCount = 2 - }; - //Q_DECLARE_FLAGS(Rows, BtuiModelRow) - - /** - * child row identifiers of the local setting row - */ - enum LocalSettingCol { - BluetoothNameCol = 0, - PowerStateCol , - VisibilityCol, - SapModeCol, - AllowedInOfflineCol, - LocalSettingColCount, - }; - //Q_DECLARE_FLAGS(BtuiModelLocalSettings, BtuiModelLocalSettingColumn) - - /** - * Data roles that the items in the local setting row - */ - enum LocalSettingDataRole { - SettingIdentity = Qt::WhatsThisRole, - settingDisplay = Qt::DisplayRole, - SettingValue = Qt::EditRole, - SettingValueParam = Qt::UserRole + 1, // e.g., temp visibility time - }; - -public: - - explicit BtuiModel( QObject *parent = 0 ); - - explicit BtuiModel( const BtuiModel &model, QObject *parent = 0 ); - - virtual ~BtuiModel(); - - // from QAbstractItemModel - virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const; - - virtual QModelIndex parent( const QModelIndex &child ) const; - - virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const; - - virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const; - - virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; - - virtual QMap itemData( const QModelIndex & index ) const; - -public slots: - - void btDataChanged(int row, int column, void *parent ); - -private: - QSharedPointer mLocalSetting; -}; - -//Q_DECLARE_OPERATORS_FOR_FLAGS(BtuiModel::Rows) - -Q_DECLARE_METATYPE(BtuiModelDataItem) -Q_DECLARE_METATYPE(BtuiModelDataSource) - -#endif // BTUIMODEL_H diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuimodel/btuimodel.pro --- a/bluetoothengine/btui/btuimodel/btuimodel.pro Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/btuimodel/btuimodel.pro Mon May 17 11:06:23 2010 +0300 @@ -26,20 +26,22 @@ CONFIG += qt \ hb \ dll - HEADERS += btdevicedata.h \ btlocalsetting.h \ - btuimodel.h \ - activewrapper.h + ../inc/btsettingmodel.h \ + ../inc/btdevicemodel.h \ + ../inc/btuimodelsortfilter.h \ + ../inc/btuiutil.h + SOURCES += btdevicedata.cpp \ btlocalsetting.cpp \ - btuimodel.cpp \ - activewrapper.cpp + btsettingmodel.cpp \ + btdevicemodel.cpp \ + btuimodelsortfilter.cpp symbian: { SYMBIAN_PLATFORMS = WINSCW \ ARMV5 - BLD_INF_RULES.prj_exports += "btuimodel.h |../inc/btuimodel.h" TARGET.EPOCALLOWDLLDATA = 1 TARGET.UID3 = 0x2002434F diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuimodel/btuimodelsortfilter.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuimodel/btuimodelsortfilter.cpp Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,166 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include +#include + +/*! + Constructor. + */ +BtuiModelSortFilter::BtuiModelSortFilter( QObject *parent ) + : QSortFilterProxyModel( parent ) +{ + setDynamicSortFilter( true ); +} + +/*! + Destructor. + */ +BtuiModelSortFilter::~BtuiModelSortFilter() +{ +} + +/*! + Replace current filter values for filtering on major device class with + the specified. This Model will not reset itself for performance reason, + the caller shall call reset after all filters have been set. + */ +void BtuiModelSortFilter::setDeviceMajorFilter( int filter, FilterMode mode ) +{ + mFilters.clear(); + addDeviceMajorFilter( filter, mode ); +} + +/*! + Add the specified filter value for filtering on major device class + if the specified filter doesn't exist when this function is called. + This Model will not reset itself for performance reason, + the caller shall call reset after all filters have been set. + */ +void BtuiModelSortFilter::addDeviceMajorFilter( int filter, FilterMode mode ) +{ + FilterItem f(filter, mode); + if ( mFilters.indexOf(f) == -1 ) { + mFilters.append( f ); + } +} + +/*! + Clear the specified filter value for filtering on major device class from this model. + This Model will not reset itself for performance reason, + the caller shall call reset after all filters have been set. + */ +void BtuiModelSortFilter::clearDeviceMajorFilter( int filter, FilterMode mode ) +{ + FilterItem f(filter, mode); + int i = mFilters.indexOf(f); + if ( i > -1 ) { + mFilters.removeAt( i ); + } +} + +/*! + clear all filters for filtering on major device class. + This Model will not reset itself for performance reason, + the caller shall call reset after all filters have been set. + */ +void BtuiModelSortFilter::clearDeviceMajorFilters() +{ + // model reset is needed if there are filters : + bool shReset = ( mFilters.size() > 0 ); + + if ( shReset ) { + reset(); + } + mFilters.clear(); +} + +/*! + return true if the specified filter exists; return false otherwise. + */ +bool BtuiModelSortFilter::hasFilter( int filter, FilterMode mode ) +{ + FilterItem f(filter, mode); + return mFilters.indexOf(f) > -1 ; +} + +/*! + \reimp + */ +bool BtuiModelSortFilter::filterAcceptsRow( + int sourceRow, const QModelIndex &sourceParent) const +{ + bool accepted (false ); + // Get the device name from the model + QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); + + // the row shall pass all filters: + for (int i = 0; i < mFilters.size(); i++ ) { + if ( mFilters.at(i).mFilter == BtDeviceModel::NullProperty ) { + accepted = true; // There is no filter, we accept all + } + else { + int majorProperty = + sourceModel()->data(index, BtDeviceModel::MajorPropertyRole).toInt(); + switch (mFilters.at(i).mMode) { + case ExactMatch: + // Accept if the match is spot-on + accepted = majorProperty == mFilters.at(i).mFilter ; + break; + case AtLeastMatch: + // accept if it matches all specified filters: + accepted = ( mFilters.at(i).mFilter == + ( majorProperty & mFilters.at(i).mFilter ) ); + break; + case RoughMatch: + // Accept if it matches one of specified filters: + accepted = (majorProperty & mFilters.at(i).mFilter) != 0; + break; + case Exclusive: + // Accept if this is not one that we want to filter out + accepted = (majorProperty & mFilters.at(i).mFilter) == 0; + break; + default: + accepted = false; + } + } + } + if (accepted) { + // emit signal to inform a row has been accepted by fitler, + // currently this is only needed by search view + emit const_cast(this)->deviceAcceptedByFilter( sourceRow ); + } + return accepted; +} + +/*! + \reimp + */ +bool BtuiModelSortFilter::lessThan( + const QModelIndex &left, const QModelIndex &right) const +{ + Q_UNUSED( left ); + Q_UNUSED( right ); + if (sortRole() == BtDeviceModel::NameAliasRole || + sortRole() == BtDeviceModel::LastUsedTimeRole || + sortRole() == BtDeviceModel::RssiRole) { + // base class provides sorting for these types already: + return QSortFilterProxyModel::lessThan(left, right); + } + // no custom sort supported yet. + return true; +} diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/btuimodel/btuimodelutil.h --- a/bluetoothengine/btui/btuimodel/btuimodelutil.h Wed May 05 09:56:48 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,174 +0,0 @@ -/* -* ============================================================================ -* Name : btuimutil.h -* Part of : BluetoothUI / bluetoothuimodel *** Info from the SWAD -* Description : utilities in the model for some often used functions, -* e.g. conversions between Qt and Symbian types. -* -* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* Nokia Corporation -* ============================================================================ -* Template version: 4.2 -*/ - -#ifndef BTUIMODELUTIL_H -#define BTUIMODELUTIL_H - -#include -#include - -_LIT(KDefaultBTDevName, "Bluetooth Device" ); - -/*! - Converts a QString which contains a BT device address in readable format to - Symbian native TBTDevAddr type. - */ -inline void addrReadbleStringToSymbian( const QString &readable, TBTDevAddr &addr) -{ - TBuf buffer(readable.utf16()); - addr.SetReadable( buffer ); -} - -/*! - Converts a Symbian native TBTDevAddr to - QString which contains the BT device address in readable format. - */ -inline void addrSymbianToReadbleString( QString &readable, const TBTDevAddr &addr) -{ - TBuf buffer; - addr.GetReadable( buffer ); - readable = QString::fromUtf16( buffer.Ptr(), buffer.Length() ); -} - -/*! - Decide the device name to display from the device information, and - converts the name if necessary. If the device doesn't have a valid name, - the given default name will be used. -*/ -inline void getDeviceDisplayName( QString& dispName, const CBTDevice& device , - const TDesC& defaultName ) -{ - // friendly name is preferred if available - if( device.IsValidFriendlyName() && device.FriendlyName().Length()){ - dispName = QString::fromUtf16( - device.FriendlyName().Ptr(), device.FriendlyName().Length() ); - } - // next preferred is actual device name - else if( device.IsValidDeviceName() && device.DeviceName().Length() ) { - dispName = QString::fromUtf8( - (char*) device.DeviceName().Ptr(), device.DeviceName().Length() ); - } - else { - // finally, use default name if nothing else is available - dispName = QString::fromUtf16( - defaultName.Ptr(), defaultName.Length() ); - } -} - -/*! - Decide the device name to display from the device information, and - converts the name if necessary. If the device doesn't have a valid name, - the given default name will be used. -*/ -inline void getDeviceDisplayName( QString& dispName, const CBTDevice& device ) -{ - getDeviceDisplayName( dispName, device, KDefaultBTDevName ); -} - - -/*! - Guess if the given Class of Device indicates an Audio/Video device (headset and carkit) - or not. - Computer device supporting audio is not considered as AV device. -*/ -inline bool isAVDevice( const TBTDeviceClass &cod ) -{ - int majorDevCls = cod.MajorDeviceClass(); - int minorDevCls = cod.MinorDeviceClass(); - return ( ( majorDevCls == EMajorDeviceAV ) - || ( cod.MajorServiceClass() == EMajorServiceRendering - && majorDevCls != EMajorDeviceImaging ) ); -} - -/*! - Guess if the given Class of Device indicates an input device (keyboard and mouse) - or not. -*/ -inline bool isHIDDevice( const TBTDeviceClass &cod ) -{ - int majorDevCls = cod.MajorDeviceClass(); - int minorDevCls = cod.MinorDeviceClass(); - return ( ( majorDevCls == EMajorDevicePeripheral ) && - ( minorDevCls == EMinorDevicePeripheralKeyboard || - minorDevCls == EMinorDevicePeripheralPointer ) ); -} - -/*! - Tells if the given device has been paired. -*/ -inline bool isPaired( const CBTDevice &dev ) -{ - return dev.IsValidPaired() && dev.IsPaired() && - dev.LinkKeyType() != ELinkKeyUnauthenticatedUpgradable; -} - -/*! - Tells if the given device supports file transfer. -*/ -inline bool supportsFileTransfer( const TBTDeviceClass &cod ) -{ - int majorDevCls = cod.MajorDeviceClass(); - return ( majorDevCls == EMajorDevicePhone - || majorDevCls == EMajorDeviceComputer ); -} - -/*! - Tells if the given device is currently connected. -*/ -inline bool isConnected( CBTEngConnMan &btConnMan, - const TBTDevAddr &addr ) -{ - TBTEngConnectionStatus connectStatus( EBTEngNotConnected ); - btConnMan.IsConnected( addr, connectStatus ); - return connectStatus == EBTEngConnected; -} - -/*! - Tells if the given device is currently connected. -*/ -inline bool isConnected( CBTEngConnMan &btConnMan, - const CBTDevice &dev ) -{ - return isConnected( btConnMan, dev.BDAddr() ); -} - -/*! - Tells if the given device is connectible with services managed by bteng. -*/ -inline bool isConnectible( CBTEngConnMan &btConnMan, - const TBTDeviceClass &devClass ) -{ - TBool connectible( false ); - btConnMan.IsConnectable( devClass, connectible ); - return connectible; -} - -/*! - Tells if the given device is connectible with services managed by bteng. -*/ -inline bool isConnectible( CBTEngConnMan &btConnMan, - const CBTDevice &dev ) -{ - return isConnectible( btConnMan, dev.DeviceClass() ); -} -#endif // BTUIMODELUTIL_H diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/bwins/btuidelegateu.def --- a/bluetoothengine/btui/bwins/btuidelegateu.def Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/bwins/btuidelegateu.def Mon May 17 11:06:23 2010 +0300 @@ -1,17 +1,19 @@ EXPORTS - ?staticMetaObject@BtAbstractDelegate@@2UQMetaObject@@B @ 1 NONAME ; struct QMetaObject const BtAbstractDelegate::staticMetaObject - ?qt_metacall@BtAbstractDelegate@@UAEHW4Call@QMetaObject@@HPAPAX@Z @ 2 NONAME ; int BtAbstractDelegate::qt_metacall(enum QMetaObject::Call, int, void * *) - ?newDelegate@BtDelegateFactory@@SAPAVBtAbstractDelegate@@W4Command@BtDelegate@@AAVBtuiModel@@PAVQObject@@@Z @ 3 NONAME ; class BtAbstractDelegate * BtDelegateFactory::newDelegate(enum BtDelegate::Command, class BtuiModel &, class QObject *) - ??_EBtAbstractDelegate@@UAE@I@Z @ 4 NONAME ; BtAbstractDelegate::~BtAbstractDelegate(unsigned int) - ??1BtAbstractDelegate@@UAE@XZ @ 5 NONAME ; BtAbstractDelegate::~BtAbstractDelegate(void) - ?metaObject@BtAbstractDelegate@@UBEPBUQMetaObject@@XZ @ 6 NONAME ; struct QMetaObject const * BtAbstractDelegate::metaObject(void) const - ?tr@BtAbstractDelegate@@SA?AVQString@@PBD0H@Z @ 7 NONAME ; class QString BtAbstractDelegate::tr(char const *, char const *, int) - ?commandCompleted@BtAbstractDelegate@@IAEXHVQVariant@@@Z @ 8 NONAME ; void BtAbstractDelegate::commandCompleted(int, class QVariant) - ?tr@BtAbstractDelegate@@SA?AVQString@@PBD0@Z @ 9 NONAME ; class QString BtAbstractDelegate::tr(char const *, char const *) - ??0BtAbstractDelegate@@QAE@AAVBtuiModel@@PAVQObject@@@Z @ 10 NONAME ; BtAbstractDelegate::BtAbstractDelegate(class BtuiModel &, class QObject *) - ?getStaticMetaObject@BtAbstractDelegate@@SAABUQMetaObject@@XZ @ 11 NONAME ; struct QMetaObject const & BtAbstractDelegate::getStaticMetaObject(void) - ?qt_metacast@BtAbstractDelegate@@UAEPAXPBD@Z @ 12 NONAME ; void * BtAbstractDelegate::qt_metacast(char const *) - ?model@BtAbstractDelegate@@IAEAAVBtuiModel@@XZ @ 13 NONAME ; class BtuiModel & BtAbstractDelegate::model(void) + ?qt_metacall@BtAbstractDelegate@@UAEHW4Call@QMetaObject@@HPAPAX@Z @ 1 NONAME ; int BtAbstractDelegate::qt_metacall(enum QMetaObject::Call, int, void * *) + ??1BtAbstractDelegate@@UAE@XZ @ 2 NONAME ; BtAbstractDelegate::~BtAbstractDelegate(void) + ?metaObject@BtAbstractDelegate@@UBEPBUQMetaObject@@XZ @ 3 NONAME ; struct QMetaObject const * BtAbstractDelegate::metaObject(void) const + ?tr@BtAbstractDelegate@@SA?AVQString@@PBD0H@Z @ 4 NONAME ; class QString BtAbstractDelegate::tr(char const *, char const *, int) + ?newDelegate@BtDelegateFactory@@SAPAVBtAbstractDelegate@@W4Command@BtDelegate@@PAVBtSettingModel@@PAVBtDeviceModel@@PAVQObject@@@Z @ 5 NONAME ; class BtAbstractDelegate * BtDelegateFactory::newDelegate(enum BtDelegate::Command, class BtSettingModel *, class BtDeviceModel *, class QObject *) + ?tr@BtAbstractDelegate@@SA?AVQString@@PBD0@Z @ 6 NONAME ; class QString BtAbstractDelegate::tr(char const *, char const *) + ?qt_metacast@BtAbstractDelegate@@UAEPAXPBD@Z @ 7 NONAME ; void * BtAbstractDelegate::qt_metacast(char const *) + ?getStaticMetaObject@BtAbstractDelegate@@SAABUQMetaObject@@XZ @ 8 NONAME ; struct QMetaObject const & BtAbstractDelegate::getStaticMetaObject(void) + ??0BtAbstractDelegate@@QAE@PAVBtSettingModel@@PAVBtDeviceModel@@PAVQObject@@@Z @ 9 NONAME ; BtAbstractDelegate::BtAbstractDelegate(class BtSettingModel *, class BtDeviceModel *, class QObject *) + ?staticMetaObject@BtAbstractDelegate@@2UQMetaObject@@B @ 10 NONAME ; struct QMetaObject const BtAbstractDelegate::staticMetaObject + ??_EBtAbstractDelegate@@UAE@I@Z @ 11 NONAME ; BtAbstractDelegate::~BtAbstractDelegate(unsigned int) + ?commandCompleted@BtAbstractDelegate@@IAEXHVQVariant@@@Z @ 12 NONAME ; void BtAbstractDelegate::commandCompleted(int, class QVariant) + ?cancel@BtAbstractDelegate@@UAEXXZ @ 13 NONAME ; void BtAbstractDelegate::cancel(void) ?trUtf8@BtAbstractDelegate@@SA?AVQString@@PBD0@Z @ 14 NONAME ; class QString BtAbstractDelegate::trUtf8(char const *, char const *) - ?trUtf8@BtAbstractDelegate@@SA?AVQString@@PBD0H@Z @ 15 NONAME ; class QString BtAbstractDelegate::trUtf8(char const *, char const *, int) + ?getSettingModel@BtAbstractDelegate@@IAEPAVBtSettingModel@@XZ @ 15 NONAME ; class BtSettingModel * BtAbstractDelegate::getSettingModel(void) + ?getDeviceModel@BtAbstractDelegate@@IAEPAVBtDeviceModel@@XZ @ 16 NONAME ; class BtDeviceModel * BtAbstractDelegate::getDeviceModel(void) + ?trUtf8@BtAbstractDelegate@@SA?AVQString@@PBD0H@Z @ 17 NONAME ; class QString BtAbstractDelegate::trUtf8(char const *, char const *, int) diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/bwins/btuimodelu.def --- a/bluetoothengine/btui/bwins/btuimodelu.def Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/bwins/btuimodelu.def Mon May 17 11:06:23 2010 +0300 @@ -1,22 +1,69 @@ EXPORTS - ??0BtuiModel@@QAE@PAVQObject@@@Z @ 1 NONAME ; BtuiModel::BtuiModel(class QObject *) - ?tr@BtuiModel@@SA?AVQString@@PBD0@Z @ 2 NONAME ; class QString BtuiModel::tr(char const *, char const *) - ?qt_metacall@BtuiModel@@UAEHW4Call@QMetaObject@@HPAPAX@Z @ 3 NONAME ; int BtuiModel::qt_metacall(enum QMetaObject::Call, int, void * *) - ?itemData@BtuiModel@@UBE?AV?$QMap@HVQVariant@@@@ABVQModelIndex@@@Z @ 4 NONAME ; class QMap BtuiModel::itemData(class QModelIndex const &) const - ?qt_metacast@BtuiModel@@UAEPAXPBD@Z @ 5 NONAME ; void * BtuiModel::qt_metacast(char const *) - ?getStaticMetaObject@BtuiModel@@SAABUQMetaObject@@XZ @ 6 NONAME ; struct QMetaObject const & BtuiModel::getStaticMetaObject(void) - ??1BtuiModel@@UAE@XZ @ 7 NONAME ; BtuiModel::~BtuiModel(void) - ?parent@BtuiModel@@UBE?AVQModelIndex@@ABV2@@Z @ 8 NONAME ; class QModelIndex BtuiModel::parent(class QModelIndex const &) const - ?btDataChanged@BtuiModel@@QAEXHHPAX@Z @ 9 NONAME ; void BtuiModel::btDataChanged(int, int, void *) - ?trUtf8@BtuiModel@@SA?AVQString@@PBD0@Z @ 10 NONAME ; class QString BtuiModel::trUtf8(char const *, char const *) - ?metaObject@BtuiModel@@UBEPBUQMetaObject@@XZ @ 11 NONAME ; struct QMetaObject const * BtuiModel::metaObject(void) const - ?data@BtuiModel@@UBE?AVQVariant@@ABVQModelIndex@@H@Z @ 12 NONAME ; class QVariant BtuiModel::data(class QModelIndex const &, int) const - ?columnCount@BtuiModel@@UBEHABVQModelIndex@@@Z @ 13 NONAME ; int BtuiModel::columnCount(class QModelIndex const &) const - ??_EBtuiModel@@UAE@I@Z @ 14 NONAME ; BtuiModel::~BtuiModel(unsigned int) - ?trUtf8@BtuiModel@@SA?AVQString@@PBD0H@Z @ 15 NONAME ; class QString BtuiModel::trUtf8(char const *, char const *, int) - ?index@BtuiModel@@UBE?AVQModelIndex@@HHABV2@@Z @ 16 NONAME ; class QModelIndex BtuiModel::index(int, int, class QModelIndex const &) const - ?staticMetaObject@BtuiModel@@2UQMetaObject@@B @ 17 NONAME ; struct QMetaObject const BtuiModel::staticMetaObject - ??0BtuiModel@@QAE@ABV0@PAVQObject@@@Z @ 18 NONAME ; BtuiModel::BtuiModel(class BtuiModel const &, class QObject *) - ?rowCount@BtuiModel@@UBEHABVQModelIndex@@@Z @ 19 NONAME ; int BtuiModel::rowCount(class QModelIndex const &) const - ?tr@BtuiModel@@SA?AVQString@@PBD0H@Z @ 20 NONAME ; class QString BtuiModel::tr(char const *, char const *, int) + ?deviceSearchCompleted@BtDeviceModel@@IAEXH@Z @ 1 NONAME ; void BtDeviceModel::deviceSearchCompleted(int) + ?cancelSearchDevice@BtDeviceModel@@QAEXXZ @ 2 NONAME ; void BtDeviceModel::cancelSearchDevice(void) + ??0BtSettingModel@@QAE@PAVQObject@@@Z @ 3 NONAME ; BtSettingModel::BtSettingModel(class QObject *) + ??1BtDeviceModel@@UAE@XZ @ 4 NONAME ; BtDeviceModel::~BtDeviceModel(void) + ?emitdeviceSearchCompleted@BtDeviceModel@@AAEXH@Z @ 5 NONAME ; void BtDeviceModel::emitdeviceSearchCompleted(int) + ?tr@BtDeviceModel@@SA?AVQString@@PBD0H@Z @ 6 NONAME ; class QString BtDeviceModel::tr(char const *, char const *, int) + ?qt_metacast@BtDeviceModel@@UAEPAXPBD@Z @ 7 NONAME ; void * BtDeviceModel::qt_metacast(char const *) + ?index@BtDeviceModel@@UBE?AVQModelIndex@@HHABV2@@Z @ 8 NONAME ; class QModelIndex BtDeviceModel::index(int, int, class QModelIndex const &) const + ?rowCount@BtSettingModel@@UBEHABVQModelIndex@@@Z @ 9 NONAME ; int BtSettingModel::rowCount(class QModelIndex const &) const + ?emitDataChanged@BtSettingModel@@AAEXHHPAX@Z @ 10 NONAME ; void BtSettingModel::emitDataChanged(int, int, void *) + ??1BtSettingModel@@UAE@XZ @ 11 NONAME ; BtSettingModel::~BtSettingModel(void) + ??0BtSettingModel@@QAE@ABV0@PAVQObject@@@Z @ 12 NONAME ; BtSettingModel::BtSettingModel(class BtSettingModel const &, class QObject *) + ?searchDevice@BtDeviceModel@@QAE_NXZ @ 13 NONAME ; bool BtDeviceModel::searchDevice(void) + ?parent@BtSettingModel@@UBE?AVQModelIndex@@ABV2@@Z @ 14 NONAME ; class QModelIndex BtSettingModel::parent(class QModelIndex const &) const + ?trUtf8@BtSettingModel@@SA?AVQString@@PBD0@Z @ 15 NONAME ; class QString BtSettingModel::trUtf8(char const *, char const *) + ??_EBtSettingModel@@UAE@I@Z @ 16 NONAME ; BtSettingModel::~BtSettingModel(unsigned int) + ?emitDataChanged@BtSettingModel@@AAEXABVQModelIndex@@0@Z @ 17 NONAME ; void BtSettingModel::emitDataChanged(class QModelIndex const &, class QModelIndex const &) + ?rowCount@BtDeviceModel@@UBEHABVQModelIndex@@@Z @ 18 NONAME ; int BtDeviceModel::rowCount(class QModelIndex const &) const + ?metaObject@BtSettingModel@@UBEPBUQMetaObject@@XZ @ 19 NONAME ; struct QMetaObject const * BtSettingModel::metaObject(void) const + ?itemData@BtDeviceModel@@UBE?AV?$QMap@HVQVariant@@@@ABVQModelIndex@@@Z @ 20 NONAME ; class QMap BtDeviceModel::itemData(class QModelIndex const &) const + ?staticMetaObject@BtDeviceModel@@2UQMetaObject@@B @ 21 NONAME ; struct QMetaObject const BtDeviceModel::staticMetaObject + ?parent@BtDeviceModel@@UBE?AVQModelIndex@@ABV2@@Z @ 22 NONAME ; class QModelIndex BtDeviceModel::parent(class QModelIndex const &) const + ?itemData@BtSettingModel@@UBE?AV?$QMap@HVQVariant@@@@ABVQModelIndex@@@Z @ 23 NONAME ; class QMap BtSettingModel::itemData(class QModelIndex const &) const + ?tr@BtSettingModel@@SA?AVQString@@PBD0@Z @ 24 NONAME ; class QString BtSettingModel::tr(char const *, char const *) + ??0BtDeviceModel@@QAE@PAVQObject@@@Z @ 25 NONAME ; BtDeviceModel::BtDeviceModel(class QObject *) + ?tr@BtDeviceModel@@SA?AVQString@@PBD0@Z @ 26 NONAME ; class QString BtDeviceModel::tr(char const *, char const *) + ?qt_metacast@BtSettingModel@@UAEPAXPBD@Z @ 27 NONAME ; void * BtSettingModel::qt_metacast(char const *) + ?getStaticMetaObject@BtSettingModel@@SAABUQMetaObject@@XZ @ 28 NONAME ; struct QMetaObject const & BtSettingModel::getStaticMetaObject(void) + ??0BtDeviceModel@@QAE@ABV0@PAVQObject@@@Z @ 29 NONAME ; BtDeviceModel::BtDeviceModel(class BtDeviceModel const &, class QObject *) + ?emitDataChanged@BtDeviceModel@@AAEXHHPAX@Z @ 30 NONAME ; void BtDeviceModel::emitDataChanged(int, int, void *) + ?staticMetaObject@BtSettingModel@@2UQMetaObject@@B @ 31 NONAME ; struct QMetaObject const BtSettingModel::staticMetaObject + ?data@BtSettingModel@@UBE?AVQVariant@@ABVQModelIndex@@H@Z @ 32 NONAME ; class QVariant BtSettingModel::data(class QModelIndex const &, int) const + ?columnCount@BtSettingModel@@UBEHABVQModelIndex@@@Z @ 33 NONAME ; int BtSettingModel::columnCount(class QModelIndex const &) const + ?removeTransientDevices@BtDeviceModel@@QAEXXZ @ 34 NONAME ; void BtDeviceModel::removeTransientDevices(void) + ?qt_metacall@BtDeviceModel@@UAEHW4Call@QMetaObject@@HPAPAX@Z @ 35 NONAME ; int BtDeviceModel::qt_metacall(enum QMetaObject::Call, int, void * *) + ?trUtf8@BtDeviceModel@@SA?AVQString@@PBD0@Z @ 36 NONAME ; class QString BtDeviceModel::trUtf8(char const *, char const *) + ??_EBtDeviceModel@@UAE@I@Z @ 37 NONAME ; BtDeviceModel::~BtDeviceModel(unsigned int) + ?index@BtSettingModel@@UBE?AVQModelIndex@@HHABV2@@Z @ 38 NONAME ; class QModelIndex BtSettingModel::index(int, int, class QModelIndex const &) const + ?qt_metacall@BtSettingModel@@UAEHW4Call@QMetaObject@@HPAPAX@Z @ 39 NONAME ; int BtSettingModel::qt_metacall(enum QMetaObject::Call, int, void * *) + ?metaObject@BtDeviceModel@@UBEPBUQMetaObject@@XZ @ 40 NONAME ; struct QMetaObject const * BtDeviceModel::metaObject(void) const + ?trUtf8@BtSettingModel@@SA?AVQString@@PBD0H@Z @ 41 NONAME ; class QString BtSettingModel::trUtf8(char const *, char const *, int) + ?columnCount@BtDeviceModel@@UBEHABVQModelIndex@@@Z @ 42 NONAME ; int BtDeviceModel::columnCount(class QModelIndex const &) const + ?tr@BtSettingModel@@SA?AVQString@@PBD0H@Z @ 43 NONAME ; class QString BtSettingModel::tr(char const *, char const *, int) + ?data@BtDeviceModel@@UBE?AVQVariant@@ABVQModelIndex@@H@Z @ 44 NONAME ; class QVariant BtDeviceModel::data(class QModelIndex const &, int) const + ?getStaticMetaObject@BtDeviceModel@@SAABUQMetaObject@@XZ @ 45 NONAME ; struct QMetaObject const & BtDeviceModel::getStaticMetaObject(void) + ?emitDataChanged@BtDeviceModel@@AAEXABVQModelIndex@@0@Z @ 46 NONAME ; void BtDeviceModel::emitDataChanged(class QModelIndex const &, class QModelIndex const &) + ?trUtf8@BtDeviceModel@@SA?AVQString@@PBD0H@Z @ 47 NONAME ; class QString BtDeviceModel::trUtf8(char const *, char const *, int) + ?setDeviceMajorFilter@BtuiModelSortFilter@@QAEXHW4FilterMode@1@@Z @ 48 NONAME ; void BtuiModelSortFilter::setDeviceMajorFilter(int, enum BtuiModelSortFilter::FilterMode) + ?metaObject@BtuiModelSortFilter@@UBEPBUQMetaObject@@XZ @ 49 NONAME ; struct QMetaObject const * BtuiModelSortFilter::metaObject(void) const + ?hasFilter@BtuiModelSortFilter@@QAE_NHW4FilterMode@1@@Z @ 50 NONAME ; bool BtuiModelSortFilter::hasFilter(int, enum BtuiModelSortFilter::FilterMode) + ?staticMetaObject@BtuiModelSortFilter@@2UQMetaObject@@B @ 51 NONAME ; struct QMetaObject const BtuiModelSortFilter::staticMetaObject + ?qt_metacast@BtuiModelSortFilter@@UAEPAXPBD@Z @ 52 NONAME ; void * BtuiModelSortFilter::qt_metacast(char const *) + ?trUtf8@BtuiModelSortFilter@@SA?AVQString@@PBD0@Z @ 53 NONAME ; class QString BtuiModelSortFilter::trUtf8(char const *, char const *) + ??0BtuiModelSortFilter@@QAE@PAVQObject@@@Z @ 54 NONAME ; BtuiModelSortFilter::BtuiModelSortFilter(class QObject *) + ?lessThan@BtuiModelSortFilter@@MBE_NABVQModelIndex@@0@Z @ 55 NONAME ; bool BtuiModelSortFilter::lessThan(class QModelIndex const &, class QModelIndex const &) const + ??1BtuiModelSortFilter@@UAE@XZ @ 56 NONAME ; BtuiModelSortFilter::~BtuiModelSortFilter(void) + ??_EBtuiModelSortFilter@@UAE@I@Z @ 57 NONAME ; BtuiModelSortFilter::~BtuiModelSortFilter(unsigned int) + ?deviceAcceptedByFilter@BtuiModelSortFilter@@IAEXH@Z @ 58 NONAME ; void BtuiModelSortFilter::deviceAcceptedByFilter(int) + ?filterAcceptsRow@BtuiModelSortFilter@@MBE_NHABVQModelIndex@@@Z @ 59 NONAME ; bool BtuiModelSortFilter::filterAcceptsRow(int, class QModelIndex const &) const + ?clearDeviceMajorFilter@BtuiModelSortFilter@@QAEXHW4FilterMode@1@@Z @ 60 NONAME ; void BtuiModelSortFilter::clearDeviceMajorFilter(int, enum BtuiModelSortFilter::FilterMode) + ?tr@BtuiModelSortFilter@@SA?AVQString@@PBD0@Z @ 61 NONAME ; class QString BtuiModelSortFilter::tr(char const *, char const *) + ?addDeviceMajorFilter@BtuiModelSortFilter@@QAEXHW4FilterMode@1@@Z @ 62 NONAME ; void BtuiModelSortFilter::addDeviceMajorFilter(int, enum BtuiModelSortFilter::FilterMode) + ?qt_metacall@BtuiModelSortFilter@@UAEHW4Call@QMetaObject@@HPAPAX@Z @ 63 NONAME ; int BtuiModelSortFilter::qt_metacall(enum QMetaObject::Call, int, void * *) + ?trUtf8@BtuiModelSortFilter@@SA?AVQString@@PBD0H@Z @ 64 NONAME ; class QString BtuiModelSortFilter::trUtf8(char const *, char const *, int) + ?tr@BtuiModelSortFilter@@SA?AVQString@@PBD0H@Z @ 65 NONAME ; class QString BtuiModelSortFilter::tr(char const *, char const *, int) + ?getStaticMetaObject@BtuiModelSortFilter@@SAABUQMetaObject@@XZ @ 66 NONAME ; struct QMetaObject const & BtuiModelSortFilter::getStaticMetaObject(void) + ?clearDeviceMajorFilters@BtuiModelSortFilter@@QAEXXZ @ 67 NONAME ; void BtuiModelSortFilter::clearDeviceMajorFilters(void) diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/eabi/btuidelegateu.def --- a/bluetoothengine/btui/eabi/btuidelegateu.def Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/eabi/btuidelegateu.def Mon May 17 11:06:23 2010 +0300 @@ -1,16 +1,18 @@ EXPORTS - _ZN17BtDelegateFactory11newDelegateEN10BtDelegate7CommandER9BtuiModelP7QObject @ 1 NONAME + _ZN17BtDelegateFactory11newDelegateEN10BtDelegate7CommandEP14BtSettingModelP13BtDeviceModelP7QObject @ 1 NONAME _ZN18BtAbstractDelegate11qt_metacallEN11QMetaObject4CallEiPPv @ 2 NONAME _ZN18BtAbstractDelegate11qt_metacastEPKc @ 3 NONAME - _ZN18BtAbstractDelegate16commandCompletedEi8QVariant @ 4 NONAME - _ZN18BtAbstractDelegate16staticMetaObjectE @ 5 NONAME DATA 16 - _ZN18BtAbstractDelegate19getStaticMetaObjectEv @ 6 NONAME - _ZN18BtAbstractDelegate5modelEv @ 7 NONAME - _ZN18BtAbstractDelegateC2ER9BtuiModelP7QObject @ 8 NONAME - _ZN18BtAbstractDelegateD0Ev @ 9 NONAME - _ZN18BtAbstractDelegateD1Ev @ 10 NONAME - _ZN18BtAbstractDelegateD2Ev @ 11 NONAME - _ZNK18BtAbstractDelegate10metaObjectEv @ 12 NONAME - _ZTI18BtAbstractDelegate @ 13 NONAME - _ZTV18BtAbstractDelegate @ 14 NONAME + _ZN18BtAbstractDelegate14getDeviceModelEv @ 4 NONAME + _ZN18BtAbstractDelegate15getSettingModelEv @ 5 NONAME + _ZN18BtAbstractDelegate16commandCompletedEi8QVariant @ 6 NONAME + _ZN18BtAbstractDelegate16staticMetaObjectE @ 7 NONAME DATA 16 + _ZN18BtAbstractDelegate19getStaticMetaObjectEv @ 8 NONAME + _ZN18BtAbstractDelegate6cancelEv @ 9 NONAME + _ZN18BtAbstractDelegateC2EP14BtSettingModelP13BtDeviceModelP7QObject @ 10 NONAME + _ZN18BtAbstractDelegateD0Ev @ 11 NONAME + _ZN18BtAbstractDelegateD1Ev @ 12 NONAME + _ZN18BtAbstractDelegateD2Ev @ 13 NONAME + _ZNK18BtAbstractDelegate10metaObjectEv @ 14 NONAME + _ZTI18BtAbstractDelegate @ 15 NONAME + _ZTV18BtAbstractDelegate @ 16 NONAME diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/eabi/btuimodelu.def --- a/bluetoothengine/btui/eabi/btuimodelu.def Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/eabi/btuimodelu.def Mon May 17 11:06:23 2010 +0300 @@ -1,23 +1,71 @@ EXPORTS - _ZN9BtuiModel11qt_metacallEN11QMetaObject4CallEiPPv @ 1 NONAME - _ZN9BtuiModel11qt_metacastEPKc @ 2 NONAME - _ZN9BtuiModel13btDataChangedEiiPv @ 3 NONAME - _ZN9BtuiModel16staticMetaObjectE @ 4 NONAME DATA 16 - _ZN9BtuiModel19getStaticMetaObjectEv @ 5 NONAME - _ZN9BtuiModelC1EP7QObject @ 6 NONAME - _ZN9BtuiModelC1ERKS_P7QObject @ 7 NONAME - _ZN9BtuiModelC2EP7QObject @ 8 NONAME - _ZN9BtuiModelC2ERKS_P7QObject @ 9 NONAME - _ZN9BtuiModelD0Ev @ 10 NONAME - _ZN9BtuiModelD1Ev @ 11 NONAME - _ZN9BtuiModelD2Ev @ 12 NONAME - _ZNK9BtuiModel10metaObjectEv @ 13 NONAME - _ZNK9BtuiModel11columnCountERK11QModelIndex @ 14 NONAME - _ZNK9BtuiModel4dataERK11QModelIndexi @ 15 NONAME - _ZNK9BtuiModel5indexEiiRK11QModelIndex @ 16 NONAME - _ZNK9BtuiModel6parentERK11QModelIndex @ 17 NONAME - _ZNK9BtuiModel8itemDataERK11QModelIndex @ 18 NONAME - _ZNK9BtuiModel8rowCountERK11QModelIndex @ 19 NONAME - _ZTI9BtuiModel @ 20 NONAME - _ZTV9BtuiModel @ 21 NONAME + _ZN13BtDeviceModel11qt_metacallEN11QMetaObject4CallEiPPv @ 1 NONAME + _ZN13BtDeviceModel11qt_metacastEPKc @ 2 NONAME + _ZN13BtDeviceModel12searchDeviceEv @ 3 NONAME + _ZN13BtDeviceModel15emitDataChangedERK11QModelIndexS2_ @ 4 NONAME + _ZN13BtDeviceModel15emitDataChangedEiiPv @ 5 NONAME + _ZN13BtDeviceModel16staticMetaObjectE @ 6 NONAME DATA 16 + _ZN13BtDeviceModel18cancelSearchDeviceEv @ 7 NONAME + _ZN13BtDeviceModel19getStaticMetaObjectEv @ 8 NONAME + _ZN13BtDeviceModel21deviceSearchCompletedEi @ 9 NONAME + _ZN13BtDeviceModel22removeTransientDevicesEv @ 10 NONAME + _ZN13BtDeviceModel25emitdeviceSearchCompletedEi @ 11 NONAME + _ZN13BtDeviceModelC1EP7QObject @ 12 NONAME + _ZN13BtDeviceModelC1ERKS_P7QObject @ 13 NONAME + _ZN13BtDeviceModelC2EP7QObject @ 14 NONAME + _ZN13BtDeviceModelC2ERKS_P7QObject @ 15 NONAME + _ZN13BtDeviceModelD0Ev @ 16 NONAME + _ZN13BtDeviceModelD1Ev @ 17 NONAME + _ZN13BtDeviceModelD2Ev @ 18 NONAME + _ZN14BtSettingModel11qt_metacallEN11QMetaObject4CallEiPPv @ 19 NONAME + _ZN14BtSettingModel11qt_metacastEPKc @ 20 NONAME + _ZN14BtSettingModel15emitDataChangedERK11QModelIndexS2_ @ 21 NONAME + _ZN14BtSettingModel15emitDataChangedEiiPv @ 22 NONAME + _ZN14BtSettingModel16staticMetaObjectE @ 23 NONAME DATA 16 + _ZN14BtSettingModel19getStaticMetaObjectEv @ 24 NONAME + _ZN14BtSettingModelC1EP7QObject @ 25 NONAME + _ZN14BtSettingModelC1ERKS_P7QObject @ 26 NONAME + _ZN14BtSettingModelC2EP7QObject @ 27 NONAME + _ZN14BtSettingModelC2ERKS_P7QObject @ 28 NONAME + _ZN14BtSettingModelD0Ev @ 29 NONAME + _ZN14BtSettingModelD1Ev @ 30 NONAME + _ZN14BtSettingModelD2Ev @ 31 NONAME + _ZNK13BtDeviceModel10metaObjectEv @ 32 NONAME + _ZNK13BtDeviceModel11columnCountERK11QModelIndex @ 33 NONAME + _ZNK13BtDeviceModel4dataERK11QModelIndexi @ 34 NONAME + _ZNK13BtDeviceModel5indexEiiRK11QModelIndex @ 35 NONAME + _ZNK13BtDeviceModel6parentERK11QModelIndex @ 36 NONAME + _ZNK13BtDeviceModel8itemDataERK11QModelIndex @ 37 NONAME + _ZNK13BtDeviceModel8rowCountERK11QModelIndex @ 38 NONAME + _ZNK14BtSettingModel10metaObjectEv @ 39 NONAME + _ZNK14BtSettingModel11columnCountERK11QModelIndex @ 40 NONAME + _ZNK14BtSettingModel4dataERK11QModelIndexi @ 41 NONAME + _ZNK14BtSettingModel5indexEiiRK11QModelIndex @ 42 NONAME + _ZNK14BtSettingModel6parentERK11QModelIndex @ 43 NONAME + _ZNK14BtSettingModel8itemDataERK11QModelIndex @ 44 NONAME + _ZNK14BtSettingModel8rowCountERK11QModelIndex @ 45 NONAME + _ZTI13BtDeviceModel @ 46 NONAME + _ZTI14BtSettingModel @ 47 NONAME + _ZTV13BtDeviceModel @ 48 NONAME + _ZTV14BtSettingModel @ 49 NONAME + _ZN19BtuiModelSortFilter11qt_metacallEN11QMetaObject4CallEiPPv @ 50 NONAME + _ZN19BtuiModelSortFilter11qt_metacastEPKc @ 51 NONAME + _ZN19BtuiModelSortFilter16staticMetaObjectE @ 52 NONAME DATA 16 + _ZN19BtuiModelSortFilter19getStaticMetaObjectEv @ 53 NONAME + _ZN19BtuiModelSortFilter20addDeviceMajorFilterEiNS_10FilterModeE @ 54 NONAME + _ZN19BtuiModelSortFilter20setDeviceMajorFilterEiNS_10FilterModeE @ 55 NONAME + _ZN19BtuiModelSortFilter22clearDeviceMajorFilterEiNS_10FilterModeE @ 56 NONAME + _ZN19BtuiModelSortFilter22deviceAcceptedByFilterEi @ 57 NONAME + _ZN19BtuiModelSortFilter23clearDeviceMajorFiltersEv @ 58 NONAME + _ZN19BtuiModelSortFilter9hasFilterEiNS_10FilterModeE @ 59 NONAME + _ZN19BtuiModelSortFilterC1EP7QObject @ 60 NONAME + _ZN19BtuiModelSortFilterC2EP7QObject @ 61 NONAME + _ZN19BtuiModelSortFilterD0Ev @ 62 NONAME + _ZN19BtuiModelSortFilterD1Ev @ 63 NONAME + _ZN19BtuiModelSortFilterD2Ev @ 64 NONAME + _ZNK19BtuiModelSortFilter10metaObjectEv @ 65 NONAME + _ZNK19BtuiModelSortFilter16filterAcceptsRowEiRK11QModelIndex @ 66 NONAME + _ZNK19BtuiModelSortFilter8lessThanERK11QModelIndexS2_ @ 67 NONAME + _ZTI19BtuiModelSortFilter @ 68 NONAME + _ZTV19BtuiModelSortFilter @ 69 NONAME diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/inc/btdevicemodel.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/inc/btdevicemodel.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,174 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTDEVICEMODEL_H +#define BTDEVICEMODEL_H + +#include +#include +#include +#include + +class BtDeviceData; + +/*! + \class BtDeviceModel + \brief The data model provided to Bluetooth UIs in QT + + BtDeviceModel provides APIs for accessing the data of remote devices. + In addition, signals from this + model are provided for being informed of data update. + + This model is in one dimension (n rows * 1 columns), i.e., + + row 0 ( a remote device) + row 1 ( another device) + ... + + The data in this model is non-modifiable from the user interface (except device + search may add a number of in-range devices temporarily) , + determined by the characteristics of Bluetooth, the underline BT software + services and the BT application requirements. + + Whenever feasible, the detailed description should contain a simple + example code example: + \code + // ... + \endcode + + \sa \link model-view-programming.html Model/View Programming\endlink + */ + +class BTUIMODEL_IMEXPORT BtDeviceModel : public QAbstractItemModel +{ + Q_OBJECT + Q_ENUMS( DevDataRole DevMajorProperty AVDevMinorProperty PeripheralMinorProperty ) + +public: + + // the roles for catogerizing Bluetooth device properties + enum DevDataRole { + NameAliasRole = Qt::DisplayRole, // QVariant::String, the name showing in UI + ReadableBdaddrRole = Qt::UserRole, // QString, the readable format of a BD_ADDR (BT Device address) + LastUsedTimeRole, // QDateTime + RssiRole, // QVariant::Int + MajorPropertyRole, // QVariant::Int, bits of DevMajorProperty + MinorPropertyRole, // QVariant::Int, bits according to an item from DevMajorProperty + CoDRole, // QVariant::Int, the value of Class of Device + }; + + /* + * Major device property values. + */ + enum DevMajorProperty { + NullProperty = 0x00000000, // device without any specific filter. + Bonded = 0x00000001, // device is in registry and bonded with phone + Blocked = 0x00000002, // device is in registry and blocked by user + RecentlyUsed = 0x00000004, // device is in registry and was used in last 30 days. + Trusted = 0x00000008, // device is in registry and authorized by user. + InRegistry = 0x00000010, // device exists in registry. + + Connected = 0x00000020, // device is currently connected to one or more + // services managed by Bluetooth Engine. + Connectable = 0x00000040, // device is connectable to one or more + // services managed by Bluetooth Engine. + InRange = 0x00000100, // device is in range + + // bits re-defined according to Class of Device: + Computer = 0x00010000, // a computer + Phone = 0x00020000, // a phone + LANAccessDev = 0x00040000, // a LAN access point + AVDev = 0x00080000, // an A/V device + Peripheral = 0x00100000, // a peripheral + ImagingDev = 0x00200000, // an imaging device + WearableDev = 0x00400000, // a wearable device + Toy = 0x00800000, // a toy + HealthDev = 0x01000000, // a health device + UncategorizedDev = 0x02000000, // a generic device that is uncategorized + + // all properties derived from BT registry + RegistryProperties = Bonded | + Blocked | RecentlyUsed | Trusted | InRegistry, + + // all properties derived from CoD + CodProperties = Computer | Phone | LANAccessDev | + AVDev | Peripheral | ImagingDev | WearableDev | + Toy | HealthDev | UncategorizedDev, + }; + + /* + * Minor device filters for major property \code AVDev \endcode + */ + enum AVDevMinorProperty { + Carkit = 0x00000001, + Headset = 0x00000002, + }; + + /* + * Minor device filters for major property \code Peripheral \endcode + */ + enum PeripheralMinorProperty { + Mouse = 0x00000001, + Keyboard = 0x00000002, + }; + +public: + + explicit BtDeviceModel( QObject *parent = 0 ); + + explicit BtDeviceModel( const BtDeviceModel &model, QObject *parent = 0 ); + + virtual ~BtDeviceModel(); + + bool searchDevice(); + + void cancelSearchDevice(); + + void removeTransientDevices(); + + // from QAbstractItemModel + virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const; + + virtual QModelIndex parent( const QModelIndex &child ) const; + + virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const; + + virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const; + + virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; + + virtual QMap itemData( const QModelIndex & index ) const; + +signals: + + void deviceSearchCompleted(int error); + +private: + + void emitDataChanged(int row, int column, void *parent ); + + void emitDataChanged(const QModelIndex &top, const QModelIndex &bottom ); + + void emitdeviceSearchCompleted(int error); + +private: + QSharedPointer mDeviceData; + + friend class BtDeviceData; +}; + +#endif // BTUIMODEL_H diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/inc/btqtconstants.h --- a/bluetoothengine/btui/inc/btqtconstants.h Wed May 05 09:56:48 2010 +0300 +++ b/bluetoothengine/btui/inc/btqtconstants.h Mon May 17 11:06:23 2010 +0300 @@ -21,6 +21,17 @@ #include +// RSSI value range: -127dB ~ +20dB +const int RssiMinRange = -127; + +//const int RssiMaxRange = 20; // maybe useful in the future + +const int RssiMediumStrength = -75; + +const int RssiHighStrength = -46; + +const int RssiInvalid = RssiMinRange - 1; + enum VisibilityMode { BtHidden = 0x10, // using a different number space than TBTVisibilityMode BtVisible, diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/inc/btsettingmodel.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/inc/btsettingmodel.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,112 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTSETTINGMODEL_H +#define BTSETTINGMODEL_H + +#include +#include +#include +#include + +class BtLocalSetting; + +/*! + \class BtSettingModel + \brief The data model provided to Bluetooth UIs in QT + + BtSettingModel provides APIs for accessing BT local Bluetooth + settings. In addition, signals from this + model are provided for being informed of data update. + + This model is in one dimension (n rows * 1 column), i.e., + + row 0 (local device name) + row 1 (power state) + ... + + The data in this model is non-modifiable from the user interface, + determined by the characteristics of Bluetooth, the underline BT software + services and the BT application requirements. + */ + +class BTUIMODEL_IMEXPORT BtSettingModel : public QAbstractItemModel +{ + Q_OBJECT + Q_ENUMS( LocalSettingRowId LocalSettingDataRole ) + +public: + + //Q_DECLARE_FLAGS(Rows, BtSettingModelRow) + + /** + * child row identifiers of the local setting row + */ + enum LocalSettingRowId { + LocalBtNameRow = 0, + PowerStateRow , + VisibilityRow, + SimAccessProfileRow, + AllowedInOfflineRow, + LocalSettingRowCount, + }; + //Q_DECLARE_FLAGS(BtSettingModelLocalSettings, BtSettingModelLocalSettingColumn) + + /** + * Data roles of the items in the local setting row + */ + enum LocalSettingDataRole { + SettingNameRole = Qt::WhatsThisRole, + settingDisplayRole = Qt::DisplayRole, + SettingValueRole = Qt::EditRole, + SettingValueParamRole = Qt::UserRole + 1, // e.g., temp visibility time + }; + +public: + + explicit BtSettingModel( QObject *parent = 0 ); + + explicit BtSettingModel( const BtSettingModel &model, QObject *parent = 0 ); + + virtual ~BtSettingModel(); + + // from QAbstractItemModel + virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const; + + virtual QModelIndex parent( const QModelIndex &child ) const; + + virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const; + + virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const; + + virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; + + virtual QMap itemData( const QModelIndex & index ) const; + +private: + + void emitDataChanged(int row, int column, void *parent ); + + void emitDataChanged(const QModelIndex &top, const QModelIndex &bottom ); + +private: + QSharedPointer mLocalSetting; + + friend class BtLocalSetting; +}; + +#endif diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/inc/btuimodelsortfilter.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/inc/btuimodelsortfilter.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,82 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTUIMODELSORTFILTER_H +#define BTUIMODELSORTFILTER_H + +#include +#include + +/*! + \class BtuiModelSortFilter + \brief the class handling sorting and filtering Bluetooth devices. + + BtuiModelSortFilter handles filtering/sorting a list of Bluetooth devices. + + \\sa bluetoothuimodel + */ +class BTUIMODEL_IMEXPORT BtuiModelSortFilter : public QSortFilterProxyModel +{ + Q_OBJECT + +public: + + // matching mechanism applied for filters defined in Btuim::DeviceListFilter + enum FilterMode { + ExactMatch, // The filter value of the device must equal to the specified filters + AtLeastMatch, // The filter value of the device must contains + // all the specified filters at least. + RoughMatch, // match at least one of the specified filters + Exclusive, // not match any of the specified filters + }; + + explicit BtuiModelSortFilter( QObject *parent = 0 ); + virtual ~BtuiModelSortFilter(); + + void setDeviceMajorFilter( int filter, FilterMode mode ); + void addDeviceMajorFilter( int filter, FilterMode mode ); + void clearDeviceMajorFilter( int filter, FilterMode mode ); + void clearDeviceMajorFilters(); + + bool hasFilter( int filter, FilterMode mode ); + +signals: + void deviceAcceptedByFilter(int sourceRow); + +protected: + + bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; + bool lessThan(const QModelIndex &left, const QModelIndex &right) const; + +private: + class FilterItem { + public: + int mFilter; + FilterMode mMode; + FilterItem(int filter, FilterMode mode ) { + mFilter = filter; mMode = mode; + } + bool operator== ( const FilterItem & other ) const { + return mFilter == other.mFilter && mMode == other.mMode; + } + }; + +private: + QList mFilters; +}; + +#endif // BTUIMODELSORTFILTER_H diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/inc/btuimodeltypes.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/inc/btuimodeltypes.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTUIMODELTYPES_H +#define BTUIMODELTYPES_H + +#include +#include +#include +#include + +// A data item in this model DLL. For example, power state item consists +// of the information regarding the current Bluetooth power state. +typedef QMap< int, QVariant > BtuiModelDataItem; + +// A category of the model data for specific group +typedef QList< BtuiModelDataItem > BtuiModelDataSource; + +Q_DECLARE_METATYPE(BtuiModelDataItem) +Q_DECLARE_METATYPE(BtuiModelDataSource) + +#ifdef BUILD_BTUIMODEL +#define BTUIMODEL_IMEXPORT Q_DECL_EXPORT +#else +#define BTUIMODEL_IMEXPORT Q_DECL_IMPORT +#endif + + +#endif // BTUIMODELTYPES_H diff -r df7a93ede42e -r a0ea99b6fa53 bluetoothengine/btui/inc/btuiutil.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/inc/btuiutil.h Mon May 17 11:06:23 2010 +0300 @@ -0,0 +1,123 @@ +/* +* ============================================================================ +* Name : btuiutil.h +* Part of : BluetoothUI / bluetoothuimodel *** Info from the SWAD +* Description : utilities in the model for some often used functions, +* e.g. conversions between Qt and Symbian types. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BTUIUTIL_H +#define BTUIUTIL_H + +#include +#include + +/*! + Converts a QString which contains a BT device address in readable format to + Symbian native TBTDevAddr type. + */ +inline void addrReadbleStringToSymbian( const QString &readable, TBTDevAddr &addr) +{ + TBuf buffer(readable.utf16()); + addr.SetReadable( buffer ); +} + +/*! + Converts a Symbian native TBTDevAddr to + QString which contains the BT device address in readable format. + */ +inline void addrSymbianToReadbleString( QString &readable, const TBTDevAddr &addr) +{ + TBuf buffer; + addr.GetReadable( buffer ); + readable = QString::fromUtf16( buffer.Ptr(), buffer.Length() ); +} + +/*! + Decide the device name to display from the device information, and + converts the name if necessary. If the device doesn't have a valid name, + the given default name will be used. +*/ +inline void getDeviceDisplayName( QString& dispName, const CBTDevice& device , + const TDesC& defaultName ) +{ + // friendly name is preferred if available + if( device.IsValidFriendlyName() && device.FriendlyName().Length()){ + dispName = QString::fromUtf16( + device.FriendlyName().Ptr(), device.FriendlyName().Length() ); + } + // next preferred is actual device name + else if( device.IsValidDeviceName() && device.DeviceName().Length() ) { + dispName = QString::fromUtf8( + (char*) device.DeviceName().Ptr(), device.DeviceName().Length() ); + } + else { + // finally, use default name if nothing else is available + dispName = QString::fromUtf16( + defaultName.Ptr(), defaultName.Length() ); + } +} + +/*! + Guess if the given Class of Device indicates an Audio/Video device (headset and carkit) + or not. + Computer device supporting audio is not considered as AV device. +*/ +inline bool isAVDevice( const TBTDeviceClass &cod ) +{ + int majorDevCls = cod.MajorDeviceClass(); + int minorDevCls = cod.MinorDeviceClass(); + return ( ( majorDevCls == EMajorDeviceAV ) + || ( cod.MajorServiceClass() == EMajorServiceRendering + && majorDevCls != EMajorDeviceImaging ) ); +} + +/*! + Guess if the given Class of Device indicates an input device (keyboard and mouse) + or not. +*/ +inline bool isHIDDevice( const TBTDeviceClass &cod ) +{ + int majorDevCls = cod.MajorDeviceClass(); + int minorDevCls = cod.MinorDeviceClass(); + return ( ( majorDevCls == EMajorDevicePeripheral ) && + ( minorDevCls == EMinorDevicePeripheralKeyboard || + minorDevCls == EMinorDevicePeripheralPointer ) ); +} + +/*! + Tells if the given device is bonded. +*/ +inline bool isBonded( const CBTDevice &dev ) +{ + // todo: this has not addresses Just Works pairing mode yet. + return dev.IsValidPaired() && dev.IsPaired() && + dev.LinkKeyType() != ELinkKeyUnauthenticatedUpgradable; +} + +/*! + Tells if the given device supports file transfer. +*/ +inline bool supportsFileTransfer( const TBTDeviceClass &cod ) +{ + int majorDevCls = cod.MajorDeviceClass(); + return ( majorDevCls == EMajorDevicePhone + || majorDevCls == EMajorDeviceComputer ); +} + +#endif // BTUIMODELUTIL_H diff -r df7a93ede42e -r a0ea99b6fa53 btservices_plat/bluetooth_local_variation_api/inc/btengdomaincrkeys.h --- a/btservices_plat/bluetooth_local_variation_api/inc/btengdomaincrkeys.h Wed May 05 09:56:48 2010 +0300 +++ b/btservices_plat/bluetooth_local_variation_api/inc/btengdomaincrkeys.h Mon May 17 11:06:23 2010 +0300 @@ -137,7 +137,7 @@ * Indicates if supports remote volume control over AVRCP Controller. * * Possible integer values: - * 0 supported + * 0 not supported * 1 supported * * Default value: 1 @@ -151,14 +151,29 @@ EBTAvrcpVolCTSupported }; +/** + * CenRep key for storing Bluetooth feature settings. + * Indicates if supports legacy remote volume control over AVRCP Controller. + * + * Possible integer values: + * 0 not supported + * 1 supported + * + * Default value: 0 + */ +const TUint32 KBTAvrcpLegacyVolCTLV = 0x00000008; + +/** Enumeration for remote volume control AVRCP Controller support */ +enum TBTAvrcpLegacyVolCTSupported + { + EBTAvrcpLegacyVolCTNotSupported = 0, + EBTAvrcpLegacyVolCTSupported + }; /** * CenRep key for default folder for file receiving. * Indicates where receving files will be saved. - * Possible integer values: - * 0 supported - * 1 supported * * Default value: Received files\\ */ diff -r df7a93ede42e -r a0ea99b6fa53 cbsatplugin/atmisccmdplugin/src/atmisccmdplugin.cpp --- a/cbsatplugin/atmisccmdplugin/src/atmisccmdplugin.cpp Wed May 05 09:56:48 2010 +0300 +++ b/cbsatplugin/atmisccmdplugin/src/atmisccmdplugin.cpp Mon May 17 11:06:23 2010 +0300 @@ -28,7 +28,7 @@ #include "atmisccmdpluginconsts.h" #include "debug.h" -#include // Additional RMobilePhone error code +#include // Additional RMobilePhone error code // +CME error code diff -r df7a93ede42e -r a0ea99b6fa53 cbsatplugin/atmisccmdplugin/src/cpincommandhandler.cpp --- a/cbsatplugin/atmisccmdplugin/src/cpincommandhandler.cpp Wed May 05 09:56:48 2010 +0300 +++ b/cbsatplugin/atmisccmdplugin/src/cpincommandhandler.cpp Mon May 17 11:06:23 2010 +0300 @@ -18,7 +18,7 @@ #include "cpincommandhandler.h" #include // define AO wrapper -#include // Additional RMobilePhone error code +#include // Additional RMobilePhone error code #include "debug.h"