|
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 #include "btdelegatedisconnect.h" |
|
18 #include <QModelIndex> |
|
19 #include <btsettingmodel.h> |
|
20 #include <btdevicemodel.h> |
|
21 #include <hbnotificationdialog.h> |
|
22 |
|
23 BtDelegateDisconnect::BtDelegateDisconnect( |
|
24 BtSettingModel* settingModel, |
|
25 BtDeviceModel* deviceModel, QObject *parent) : |
|
26 BtAbstractDelegate(settingModel, deviceModel, parent), mBtengConnMan(0) |
|
27 { |
|
28 |
|
29 } |
|
30 |
|
31 BtDelegateDisconnect::~BtDelegateDisconnect() |
|
32 { |
|
33 delete mBtengConnMan; |
|
34 } |
|
35 |
|
36 void BtDelegateDisconnect::exec( const QVariant ¶ms ) |
|
37 { |
|
38 int error = KErrNone; |
|
39 QModelIndex index = params.value<QModelIndex>(); |
|
40 |
|
41 mdeviceName = getDeviceModel()->data(index,BtDeviceModel::NameAliasRole).toString(); |
|
42 |
|
43 QString strBtAddr = getDeviceModel()->data(index,BtDeviceModel::ReadableBdaddrRole).toString(); |
|
44 |
|
45 if ( ! mBtengConnMan ){ |
|
46 TRAP_IGNORE( mBtengConnMan = CBTEngConnMan::NewL(this) ); |
|
47 } |
|
48 Q_CHECK_PTR( mBtengConnMan ); |
|
49 |
|
50 TPtrC ptrName(reinterpret_cast<const TText*>(strBtAddr.constData())); |
|
51 |
|
52 RBuf16 btName; |
|
53 error = btName.Create(ptrName.Length()); |
|
54 |
|
55 if(error == KErrNone) { |
|
56 btName.Copy(ptrName); |
|
57 mBtEngddr.SetReadable(btName); |
|
58 error = mBtengConnMan->Disconnect(mBtEngddr, EBTDiscGraceful); |
|
59 btName.Close(); |
|
60 } |
|
61 |
|
62 |
|
63 if(error) { |
|
64 emitCommandComplete(error); |
|
65 } |
|
66 |
|
67 } |
|
68 |
|
69 void BtDelegateDisconnect::ConnectComplete( TBTDevAddr& aAddr, TInt aErr, |
|
70 RBTDevAddrArray* aConflicts ) |
|
71 { |
|
72 Q_UNUSED(aAddr); |
|
73 Q_UNUSED(aConflicts); |
|
74 Q_UNUSED(aErr); |
|
75 } |
|
76 |
|
77 void BtDelegateDisconnect::DisconnectComplete( TBTDevAddr& aAddr, TInt aErr ) |
|
78 { |
|
79 Q_UNUSED(aAddr); |
|
80 emitCommandComplete(aErr); |
|
81 } |
|
82 |
|
83 void BtDelegateDisconnect::PairingComplete( TBTDevAddr& aAddr, TInt aErr ) |
|
84 { |
|
85 Q_UNUSED(aAddr); |
|
86 Q_UNUSED(aErr); |
|
87 } |
|
88 |
|
89 void BtDelegateDisconnect::cancel() |
|
90 { |
|
91 |
|
92 } |
|
93 |
|
94 void BtDelegateDisconnect::emitCommandComplete(int error) |
|
95 { |
|
96 QString str(hbTrId("Disconnected to %1")); |
|
97 QString err(hbTrId("Disconnecting with %1 Failed")); |
|
98 |
|
99 if(error != KErrNone) { |
|
100 HbNotificationDialog::launchDialog(err.arg(mdeviceName)); |
|
101 } |
|
102 else { |
|
103 HbNotificationDialog::launchDialog(str.arg(mdeviceName)); |
|
104 } |
|
105 |
|
106 emit commandCompleted(error); |
|
107 } |
|
108 |
|
109 |