|
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: Delegate class for setting visibility mode |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "btdelegatevisibility.h" |
|
20 #include <btsettingmodel.h> |
|
21 #include <btdevicemodel.h> |
|
22 #include <bluetoothuitrace.h> |
|
23 #include "btqtconstants.h" |
|
24 #include <btengsettings.h> |
|
25 |
|
26 const int MAX_TEMPORARY_VISIBILITY = 60; // minutes, this value comes from the UI spec |
|
27 |
|
28 /*! |
|
29 Constructor. |
|
30 */ |
|
31 BtDelegateVisibility::BtDelegateVisibility( |
|
32 QObject *parent ) |
|
33 : BtAbstractDelegate( NULL, NULL, parent ) |
|
34 { |
|
35 TRAP_IGNORE( mBtengSettings = CBTEngSettings::NewL(this) ); |
|
36 Q_CHECK_PTR( mBtengSettings ); |
|
37 mActiveHandling = false; |
|
38 } |
|
39 |
|
40 /*! |
|
41 Destructor. |
|
42 */ |
|
43 BtDelegateVisibility::~BtDelegateVisibility() |
|
44 { |
|
45 delete mBtengSettings; |
|
46 } |
|
47 /*! |
|
48 * executes visibility delegate functionality, ie. calls CBTEngSettings to set the visibility mode; |
|
49 * when operation completes, emits commandCompleted signal |
|
50 * Parameters: Qlist<QVariant> where first item is VisibilityMode integer specifying operation; |
|
51 * for BtTemporary a 2nd parameter is give which signifies the number of minutes to stay visible. |
|
52 */ |
|
53 void BtDelegateVisibility::exec( const QVariant ¶ms ) |
|
54 { |
|
55 int minutes, err = 0; |
|
56 |
|
57 if (mActiveHandling) { |
|
58 // complete command with error |
|
59 emit commandCompleted(KErrInUse); |
|
60 return; |
|
61 } |
|
62 mActiveHandling = true; |
|
63 |
|
64 // read 1st parameter |
|
65 BTUI_ASSERT_X(params.toList().at(0).isValid(), "BtDelegateVisibility::exec", "invalid parameter"); |
|
66 VisibilityMode btQtMode = (VisibilityMode)params.toList().at(0).toInt(); |
|
67 mOperation = BtEngVisibilityMode(btQtMode); |
|
68 |
|
69 // verify that we are setting visibility to a new value, otherwise we won't get a callback |
|
70 TBTVisibilityMode visibilityMode( EBTVisibilityModeNoScans ); |
|
71 err = mBtengSettings->GetVisibilityMode( visibilityMode ); |
|
72 if (err) { |
|
73 mActiveHandling = false; |
|
74 emit commandCompleted(err); |
|
75 return; |
|
76 } |
|
77 if (visibilityMode == mOperation) { |
|
78 mActiveHandling = false; |
|
79 emit commandCompleted(KErrNone); |
|
80 return; |
|
81 } |
|
82 |
|
83 switch (mOperation) { |
|
84 case EBTVisibilityModeGeneral : |
|
85 err = mBtengSettings->SetVisibilityMode(mOperation, 0); |
|
86 break; |
|
87 case EBTVisibilityModeHidden: |
|
88 err = mBtengSettings->SetVisibilityMode(mOperation, 0); |
|
89 break; |
|
90 case EBTVisibilityModeTemporary: |
|
91 BTUI_ASSERT_X(params.toList().at(1).isValid(), "BtDelegateVisibility::exec", "invalid time parameter"); |
|
92 minutes = params.toList().at(1).toInt(); |
|
93 BTUI_ASSERT_X(((minutes >= 0 ) && (minutes <= MAX_TEMPORARY_VISIBILITY)), |
|
94 "BtDelegateVisibility::exec", "invalid time parameter"); |
|
95 err = mBtengSettings->SetVisibilityMode(mOperation, minutes); |
|
96 break; |
|
97 default: |
|
98 // error |
|
99 BTUI_ASSERT_X(false, "BtDelegateVisibility::exec", "invalid parameter"); |
|
100 } |
|
101 if (err) { |
|
102 // complete command with error |
|
103 mActiveHandling = false; |
|
104 emit commandCompleted(err); |
|
105 } |
|
106 } |
|
107 |
|
108 void BtDelegateVisibility::PowerStateChanged( TBTPowerStateValue aState ) |
|
109 { |
|
110 Q_UNUSED( aState ); |
|
111 } |
|
112 |
|
113 /*! |
|
114 * callback from BtEngine |
|
115 * emits command complete with either: |
|
116 * 1) KErrUnknown if something went wrong, or |
|
117 * 2) KErrNone if everything ok |
|
118 */ |
|
119 void BtDelegateVisibility::VisibilityModeChanged( TBTVisibilityMode aState ) |
|
120 { |
|
121 if (mActiveHandling) { |
|
122 //Error handling has to be done, if value is not set properly. |
|
123 mActiveHandling = false; |
|
124 if (mOperation == aState) { |
|
125 emit commandCompleted(KErrNone); |
|
126 } |
|
127 else { |
|
128 emit commandCompleted(KErrUnknown); |
|
129 } |
|
130 } |
|
131 } |