29
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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: BtDeviceDialogWidget class implementation.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "btdevicedialognotifwidget.h"
|
|
20 |
#include "btdevicedialogplugintrace.h"
|
|
21 |
#include <bluetoothdevicedialogs.h>
|
|
22 |
#include <hbaction.h>
|
|
23 |
#include <hbdialog.h>
|
|
24 |
#include "btdevicedialogpluginerrors.h"
|
|
25 |
|
|
26 |
/*!
|
|
27 |
class Constructor
|
|
28 |
*/
|
|
29 |
BtDeviceDialogNotifWidget::BtDeviceDialogNotifWidget( const QVariantMap ¶meters )
|
|
30 |
{
|
|
31 |
TRACE_ENTRY
|
|
32 |
// set properties
|
|
33 |
mLastError = NoError;
|
|
34 |
mShowEventReceived = false;
|
|
35 |
resetProperties();
|
|
36 |
constructQueryDialog(parameters);
|
|
37 |
TRACE_EXIT
|
|
38 |
}
|
|
39 |
|
|
40 |
/*!
|
|
41 |
Set parameters, implementation of interface
|
|
42 |
Invoked when HbDeviceDialog::update calls.
|
|
43 |
*/
|
|
44 |
bool BtDeviceDialogNotifWidget::setDeviceDialogParameters(
|
|
45 |
const QVariantMap ¶meters)
|
|
46 |
{
|
|
47 |
TRACE_ENTRY
|
|
48 |
mLastError = NoError;
|
|
49 |
processParam(parameters);
|
|
50 |
TRACE_EXIT
|
|
51 |
return true;
|
|
52 |
}
|
|
53 |
|
|
54 |
/*!
|
|
55 |
Get error, implementation of interface
|
|
56 |
*/
|
|
57 |
int BtDeviceDialogNotifWidget::deviceDialogError() const
|
|
58 |
{
|
|
59 |
TRACE_ENTRY
|
|
60 |
TRACE_EXIT
|
|
61 |
return mLastError;
|
|
62 |
}
|
|
63 |
|
|
64 |
/*!
|
|
65 |
Close notification, implementation of interface
|
|
66 |
*/
|
|
67 |
void BtDeviceDialogNotifWidget::closeDeviceDialog(bool byClient)
|
|
68 |
{
|
|
69 |
TRACE_ENTRY
|
|
70 |
Q_UNUSED(byClient);
|
|
71 |
// Closed by client or internally by server -> no action to be transmitted.
|
|
72 |
mSendAction = false;
|
|
73 |
close();
|
|
74 |
// If show event has been received, close is signalled from hide event. If not,
|
|
75 |
// hide event does not come and close is signalled from here.
|
|
76 |
if (!mShowEventReceived) {
|
|
77 |
emit deviceDialogClosed();
|
|
78 |
}
|
|
79 |
TRACE_EXIT
|
|
80 |
}
|
|
81 |
|
|
82 |
/*!
|
|
83 |
Return display widget, implementation of interface
|
|
84 |
*/
|
|
85 |
HbDialog *BtDeviceDialogNotifWidget::deviceDialogWidget() const
|
|
86 |
{
|
|
87 |
TRACE_ENTRY
|
|
88 |
TRACE_EXIT
|
|
89 |
return const_cast<BtDeviceDialogNotifWidget*>(this);
|
|
90 |
}
|
|
91 |
|
|
92 |
/*!
|
|
93 |
Construct display widget
|
|
94 |
*/
|
|
95 |
bool BtDeviceDialogNotifWidget::constructQueryDialog(const QVariantMap ¶meters)
|
|
96 |
{
|
|
97 |
TRACE_ENTRY
|
|
98 |
// analyze the parameters to compose the properties of the message box widget
|
|
99 |
processParam(parameters);
|
|
100 |
|
|
101 |
TRACE_EXIT
|
|
102 |
return true;
|
|
103 |
}
|
|
104 |
|
|
105 |
/*!
|
|
106 |
Take parameter values and generate relevant property of this widget
|
|
107 |
*/
|
|
108 |
void BtDeviceDialogNotifWidget::processParam(const QVariantMap ¶meters)
|
|
109 |
{
|
|
110 |
TRACE_ENTRY
|
|
111 |
QString keyStr, prompt;
|
|
112 |
keyStr.setNum( TBluetoothDialogParams::EResource );
|
|
113 |
// Validate if the resource item exists.
|
|
114 |
QVariantMap::const_iterator i = parameters.constFind( keyStr );
|
|
115 |
// item of ResourceId is not found, can't continue.
|
|
116 |
if ( i == parameters.constEnd() ) {
|
|
117 |
mLastError = UnknownDeviceDialogError;
|
|
118 |
return;
|
|
119 |
}
|
|
120 |
|
|
121 |
QVariant param = parameters.value( keyStr );
|
|
122 |
int key = param.toInt();
|
|
123 |
switch ( key ) {
|
|
124 |
// Note dialogs
|
|
125 |
case EPairingSuccess:
|
|
126 |
prompt = QString( tr( "Pairing with %1 complete" ) );
|
|
127 |
break;
|
|
128 |
case EPairingFailure:
|
|
129 |
prompt = QString( tr( "Unable to pair with %1" ) );
|
|
130 |
break;
|
|
131 |
case EVisibilityTimeout:
|
|
132 |
prompt = QString( tr( "Phone is not detectable in searches made by other devices" ) );
|
|
133 |
break;
|
|
134 |
default:
|
|
135 |
mLastError = ParameterError;
|
|
136 |
break;
|
|
137 |
}
|
|
138 |
// Could use QChar with ReplacementCharacter?
|
|
139 |
int repls = prompt.count( QString( "%" ) );
|
|
140 |
if ( repls > 0 ) {
|
|
141 |
QVariant name = parameters.value( QString::number( TBluetoothDeviceDialog::EDeviceName ) );
|
|
142 |
prompt = prompt.arg( name.toString() );
|
|
143 |
}
|
|
144 |
// set property value to this dialog widget
|
|
145 |
HbNotificationDialog::setTitle( prompt );
|
|
146 |
TRACE_EXIT
|
|
147 |
}
|
|
148 |
|
|
149 |
/*!
|
|
150 |
Reset properties to default values
|
|
151 |
*/
|
|
152 |
void BtDeviceDialogNotifWidget::resetProperties()
|
|
153 |
{
|
|
154 |
TRACE_ENTRY
|
|
155 |
mSendAction = true;
|
|
156 |
TRACE_EXIT
|
|
157 |
return;
|
|
158 |
}
|
|
159 |
|
|
160 |
/*!
|
|
161 |
Widget is about to hide. Closing effect has ended.
|
|
162 |
*/
|
|
163 |
void BtDeviceDialogNotifWidget::hideEvent(QHideEvent *event)
|
|
164 |
{
|
|
165 |
HbNotificationDialog::hideEvent(event);
|
|
166 |
emit deviceDialogClosed();
|
|
167 |
}
|
|
168 |
|
|
169 |
/*!
|
|
170 |
Widget is about to show
|
|
171 |
*/
|
|
172 |
void BtDeviceDialogNotifWidget::showEvent(QShowEvent *event)
|
|
173 |
{
|
|
174 |
HbNotificationDialog::showEvent(event);
|
|
175 |
mShowEventReceived = true;
|
|
176 |
}
|