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