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