31
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <QModelIndex>
|
|
19 |
|
42
|
20 |
#include "btqtconstants.h"
|
31
|
21 |
#include "btdelegatedevsecurity.h"
|
|
22 |
#include <btsettingmodel.h>
|
|
23 |
#include <btdevicemodel.h>
|
42
|
24 |
#include <btdelegatefactory.h>
|
31
|
25 |
#include <hbnotificationdialog.h>
|
|
26 |
|
|
27 |
BtDelegateDevSecurity::BtDelegateDevSecurity(
|
|
28 |
BtSettingModel* settingModel,
|
|
29 |
BtDeviceModel* deviceModel,
|
|
30 |
QObject *parent) :
|
42
|
31 |
BtAbstractDelegate(settingModel, deviceModel, parent), mBtEngDevMan(0), mBtengConnMan(0), mDisconnectDelegate(0)
|
31
|
32 |
{
|
|
33 |
|
|
34 |
}
|
|
35 |
|
|
36 |
BtDelegateDevSecurity::~BtDelegateDevSecurity()
|
|
37 |
{
|
|
38 |
delete mBtEngDevMan;
|
42
|
39 |
delete mBtengConnMan;
|
|
40 |
delete mDisconnectDelegate;
|
31
|
41 |
}
|
|
42 |
|
|
43 |
|
|
44 |
void BtDelegateDevSecurity::exec( const QVariant ¶ms )
|
|
45 |
{
|
|
46 |
int error = KErrNone;
|
|
47 |
QModelIndex index = params.value<QModelIndex>();
|
|
48 |
|
|
49 |
QString strBtAddr = getDeviceModel()->data(index,
|
|
50 |
BtDeviceModel::ReadableBdaddrRole).toString();
|
|
51 |
|
|
52 |
mdeviceName = getDeviceModel()->data(index,BtDeviceModel::NameAliasRole).toString();
|
|
53 |
|
|
54 |
TBTDevAddr symaddr;
|
|
55 |
TBuf<KBTDevAddrSize * 2> buffer(strBtAddr.utf16());
|
|
56 |
symaddr.SetReadable( buffer );
|
42
|
57 |
|
|
58 |
// Disconnect if paired device was connected
|
|
59 |
if ( ! mBtengConnMan ){
|
|
60 |
TRAP( error, mBtengConnMan = CBTEngConnMan::NewL(this) );
|
|
61 |
}
|
|
62 |
TBTEngConnectionStatus connstatus;
|
|
63 |
if ( !error && mBtengConnMan->IsConnected(symaddr, connstatus ) == KErrNone) {
|
|
64 |
if ( connstatus == EBTEngConnected) {
|
|
65 |
if (! mDisconnectDelegate){
|
|
66 |
mDisconnectDelegate = BtDelegateFactory::newDelegate(
|
|
67 |
BtDelegate::Disconnect, getSettingModel(), getDeviceModel());
|
|
68 |
connect( mDisconnectDelegate, SIGNAL(commandCompleted(int)), this, SLOT(disconnectDelegateCompleted(int)) );
|
|
69 |
|
|
70 |
}
|
|
71 |
QList<QVariant>list;
|
|
72 |
QVariant paramFirst;
|
|
73 |
paramFirst.setValue(index);
|
|
74 |
QVariant paramSecond;
|
|
75 |
DisconnectOption discoOpt = ServiceLevel;
|
|
76 |
paramSecond.setValue((int)discoOpt);
|
|
77 |
list.append(paramFirst);
|
|
78 |
list.append(paramSecond);
|
|
79 |
QVariant paramsList;
|
|
80 |
paramsList.setValue(list);
|
|
81 |
mDisconnectDelegate->exec(paramsList);
|
|
82 |
}
|
|
83 |
}
|
31
|
84 |
|
42
|
85 |
// Set device as unpaired
|
31
|
86 |
CBTDevice *symBtDevice = 0;
|
|
87 |
TRAP( error, {
|
|
88 |
symBtDevice = CBTDevice::NewL( symaddr );
|
|
89 |
if( !mBtEngDevMan) {
|
|
90 |
mBtEngDevMan = CBTEngDevMan::NewL( this );
|
|
91 |
}
|
|
92 |
});
|
|
93 |
|
|
94 |
if ( !error ) {
|
|
95 |
symBtDevice->SetPaired(EFalse);
|
|
96 |
// deleting link key for executing unpair is safe as no
|
|
97 |
// link key shall exist if the device has been unpaired.
|
|
98 |
symBtDevice->DeleteLinkKey();
|
|
99 |
error = mBtEngDevMan->ModifyDevice( *symBtDevice );
|
|
100 |
}
|
|
101 |
delete symBtDevice;
|
|
102 |
|
|
103 |
if ( error ) {
|
|
104 |
emitCommandComplete(error);
|
|
105 |
}
|
|
106 |
}
|
|
107 |
|
|
108 |
void BtDelegateDevSecurity::cancel()
|
|
109 |
{
|
|
110 |
|
|
111 |
}
|
|
112 |
|
42
|
113 |
void BtDelegateDevSecurity::disconnectDelegateCompleted( int err )
|
|
114 |
{
|
|
115 |
Q_UNUSED(err);
|
|
116 |
}
|
|
117 |
|
31
|
118 |
void BtDelegateDevSecurity::HandleDevManComplete( TInt aErr )
|
|
119 |
{
|
|
120 |
emitCommandComplete(aErr);
|
|
121 |
}
|
|
122 |
|
|
123 |
void BtDelegateDevSecurity::HandleGetDevicesComplete( TInt aErr, CBTDeviceArray* aDeviceArray )
|
|
124 |
{
|
|
125 |
Q_UNUSED(aErr);
|
|
126 |
Q_UNUSED(aDeviceArray);
|
|
127 |
}
|
|
128 |
|
|
129 |
void BtDelegateDevSecurity::emitCommandComplete(int error)
|
|
130 |
{
|
42
|
131 |
// no dialogs here since stack provides "unpaired to %1" dialog
|
|
132 |
// and failures are not reported
|
31
|
133 |
|
42
|
134 |
emit commandCompleted(error);
|
|
135 |
}
|
31
|
136 |
|
42
|
137 |
void BtDelegateDevSecurity::ConnectComplete( TBTDevAddr& aAddr, TInt aErr,
|
|
138 |
RBTDevAddrArray* aConflicts )
|
|
139 |
{
|
|
140 |
Q_UNUSED(aAddr);
|
|
141 |
Q_UNUSED(aErr);
|
|
142 |
Q_UNUSED(aConflicts);
|
|
143 |
}
|
|
144 |
|
|
145 |
void BtDelegateDevSecurity::DisconnectComplete( TBTDevAddr& aAddr, TInt aErr )
|
|
146 |
{
|
|
147 |
Q_UNUSED(aAddr);
|
|
148 |
Q_UNUSED(aErr);
|
31
|
149 |
}
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|