50
|
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 <QtGui>
|
|
19 |
#include <QGraphicsLinearLayout>
|
|
20 |
#include <QUrl>
|
|
21 |
#include <HbAction>
|
|
22 |
#include <HbLabel>
|
|
23 |
#include <HbMainWindow>
|
|
24 |
#include <HbPushButton>
|
|
25 |
#include <HbLineEdit>
|
|
26 |
#include <HbNotificationDialog>
|
|
27 |
#include <HbCheckBox>
|
|
28 |
#include <hbinputeditorinterface.h>
|
|
29 |
#include <xqservicerequest.h>
|
|
30 |
#include <xqappmgr.h>
|
|
31 |
#include "urischemeservicetestappview.h"
|
|
32 |
|
|
33 |
const int KMultitapTimeInMs = 800;
|
|
34 |
const int KNumOfTelMultitapCharacters = 4;
|
|
35 |
const int KNumOfCtiMultitapCharacters = 2;
|
|
36 |
const QString KTelUriSchemePrefix = "tel:";
|
|
37 |
const QString KCtiUriSchemePrefix = "cti:";
|
|
38 |
|
|
39 |
UriSchemeServiceTestAppView::UriSchemeServiceTestAppView(
|
|
40 |
HbMainWindow& mainWindow )
|
|
41 |
:
|
|
42 |
m_mainWindow(mainWindow),
|
|
43 |
m_lineEdit(NULL),
|
|
44 |
m_telUriCheckBox(NULL),
|
|
45 |
m_ctiUriCheckBox(NULL),
|
|
46 |
m_uriLabel(NULL),
|
|
47 |
m_multitapIndex(0),
|
|
48 |
m_multitapCount(0)
|
|
49 |
{
|
|
50 |
setTitle("URI Scheme Test App");
|
|
51 |
|
|
52 |
m_extraChar.insert(Qt::Key_Comma, ',');
|
|
53 |
m_extraChar.insert(Qt::Key_Slash, '/');
|
|
54 |
m_extraChar.insert(Qt::Key_Asterisk, '*');
|
|
55 |
m_extraChar.insert(Qt::Key_NumberSign, '#');
|
|
56 |
m_extraChar.insert(Qt::Key_P, 'p');
|
|
57 |
m_extraChar.insert(Qt::Key_W, 'w');
|
|
58 |
|
|
59 |
QGraphicsLinearLayout *mainLayout =
|
|
60 |
new QGraphicsLinearLayout(Qt::Vertical, this);
|
|
61 |
|
|
62 |
// create URI scheme selection check boxes
|
|
63 |
m_telUriCheckBox = new HbCheckBox(this);
|
|
64 |
m_telUriCheckBox->setText("TEL URI Scheme");
|
|
65 |
m_telUriCheckBox->setChecked(true);
|
|
66 |
connect(
|
|
67 |
m_telUriCheckBox, SIGNAL(stateChanged(int)),
|
|
68 |
this, SLOT(setupTelUriConfiguration(int)));
|
|
69 |
mainLayout->addItem(m_telUriCheckBox);
|
|
70 |
m_ctiUriCheckBox = new HbCheckBox(this);
|
|
71 |
m_ctiUriCheckBox->setText("CTI URI Scheme");
|
|
72 |
connect(
|
|
73 |
m_ctiUriCheckBox, SIGNAL(stateChanged(int)),
|
|
74 |
this, SLOT(setupCtiUriConfiguration(int)));
|
|
75 |
mainLayout->addItem(m_ctiUriCheckBox);
|
|
76 |
|
|
77 |
// create URI input field
|
|
78 |
QGraphicsLinearLayout *uriEditLayout =
|
|
79 |
new QGraphicsLinearLayout(Qt::Horizontal);
|
|
80 |
m_uriLabel = new HbLabel(this);
|
|
81 |
uriEditLayout->addItem(m_uriLabel);
|
|
82 |
m_lineEdit = new HbLineEdit(this);
|
|
83 |
HbEditorInterface editorInterface(m_lineEdit);
|
|
84 |
editorInterface.setMode(HbInputModeNumeric);
|
|
85 |
HbAction *specialInputAction = new HbAction(QString("INP"), this);
|
|
86 |
editorInterface.addAction(specialInputAction);
|
|
87 |
connect(
|
|
88 |
specialInputAction, SIGNAL(triggered(bool)),
|
|
89 |
this, SLOT(inputSpecialCharacter(bool)));
|
|
90 |
m_lineEdit->setInputMethodHints(
|
|
91 |
Qt::ImhPreferNumbers|Qt::ImhNoPredictiveText);
|
|
92 |
uriEditLayout->addItem(m_lineEdit);
|
|
93 |
mainLayout->addItem(uriEditLayout);
|
|
94 |
|
|
95 |
// create Call & Clear buttons
|
|
96 |
HbPushButton *callButton = new HbPushButton(this);
|
|
97 |
callButton->setText("Call");
|
|
98 |
mainLayout->addItem(callButton);
|
|
99 |
connect(
|
|
100 |
callButton, SIGNAL(clicked(bool)),
|
|
101 |
this, SLOT(makeCall(bool)));
|
|
102 |
HbPushButton *clearButton = new HbPushButton(this);
|
|
103 |
clearButton->setText("Clear");
|
|
104 |
mainLayout->addItem(clearButton);
|
|
105 |
connect(
|
|
106 |
clearButton, SIGNAL(clicked(bool)),
|
|
107 |
this, SLOT(clearInputField(bool)));
|
|
108 |
|
|
109 |
setLayout(mainLayout);
|
|
110 |
|
|
111 |
setupTelUriConfiguration(Qt::Checked);
|
|
112 |
}
|
|
113 |
|
|
114 |
|
|
115 |
UriSchemeServiceTestAppView::~UriSchemeServiceTestAppView()
|
|
116 |
{
|
|
117 |
|
|
118 |
}
|
|
119 |
|
|
120 |
|
|
121 |
void UriSchemeServiceTestAppView::makeCall(bool checked)
|
|
122 |
{
|
|
123 |
Q_UNUSED(checked)
|
|
124 |
|
|
125 |
QString uriToCall = "";
|
|
126 |
uriToCall += m_uriLabel->plainText();
|
|
127 |
uriToCall += m_lineEdit->text();
|
|
128 |
QUrl callUri(uriToCall);
|
|
129 |
|
|
130 |
HbNotificationDialog *notifDialog = new HbNotificationDialog();
|
|
131 |
notifDialog->setDismissPolicy(HbPopup::TapAnywhere);
|
|
132 |
notifDialog->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
133 |
|
|
134 |
XQApplicationManager aiwManager;
|
|
135 |
QScopedPointer<XQAiwRequest> request(aiwManager.create(callUri));
|
|
136 |
if (request) {
|
|
137 |
request->setSynchronous(true);
|
|
138 |
request->setEmbedded(false);
|
|
139 |
request->setBackground(true);
|
|
140 |
|
|
141 |
QList<QVariant> args;
|
|
142 |
args << callUri.toString();
|
|
143 |
request->setArguments(args);
|
|
144 |
|
|
145 |
QVariant uriHandled = false;
|
|
146 |
bool requestOk = request->send(uriHandled);
|
|
147 |
if (uriHandled.toBool()) {
|
|
148 |
notifDialog->setText("URI call accepted");
|
|
149 |
} else {
|
|
150 |
/* URI is not handled in the following cases:
|
|
151 |
* 1. URI is invalid or not supported and parsing has failed.
|
|
152 |
* 2. User has canceled the call request.
|
|
153 |
* 3. Phone has rejected call request with parsed phone number.*/
|
|
154 |
notifDialog->setText("URI call rejected");
|
|
155 |
}
|
|
156 |
} else {
|
|
157 |
notifDialog->setText("Unknown scheme");
|
|
158 |
}
|
|
159 |
notifDialog->show();
|
|
160 |
}
|
|
161 |
|
|
162 |
|
|
163 |
void UriSchemeServiceTestAppView::clearInputField(bool checked)
|
|
164 |
{
|
|
165 |
Q_UNUSED(checked)
|
|
166 |
|
|
167 |
m_lineEdit->setText("");
|
|
168 |
}
|
|
169 |
|
|
170 |
|
|
171 |
void UriSchemeServiceTestAppView::inputSpecialCharacter(bool checked)
|
|
172 |
{
|
|
173 |
Q_UNUSED(checked)
|
|
174 |
|
|
175 |
QString textBeforeTapCharInsertion = m_lineEdit->text();
|
|
176 |
|
|
177 |
QString tapCharacter = "";
|
|
178 |
if (m_multitapTimer.elapsed() <= KMultitapTimeInMs) {
|
|
179 |
m_multitapIndex = ++m_multitapIndex % m_multitapCount;
|
|
180 |
textBeforeTapCharInsertion.chop(1);
|
|
181 |
} else {
|
|
182 |
m_multitapIndex = 0;
|
|
183 |
}
|
|
184 |
|
|
185 |
int key = m_multitapCharacters.at(m_multitapIndex);
|
|
186 |
tapCharacter = m_extraChar.value(key);
|
|
187 |
|
|
188 |
QString textAfterTapCharInsertion =
|
|
189 |
textBeforeTapCharInsertion + tapCharacter;
|
|
190 |
m_lineEdit->setText(textAfterTapCharInsertion);
|
|
191 |
|
|
192 |
m_multitapTimer.start();
|
|
193 |
}
|
|
194 |
|
|
195 |
|
|
196 |
void UriSchemeServiceTestAppView::setupTelUriConfiguration(int state)
|
|
197 |
{
|
|
198 |
if (Qt::Checked == state) {
|
|
199 |
m_uriLabel->setPlainText(KTelUriSchemePrefix);
|
|
200 |
|
|
201 |
disconnect(
|
|
202 |
m_ctiUriCheckBox, SIGNAL(stateChanged(int)),
|
|
203 |
this, SLOT(setupCtiUriConfiguration(int)));
|
|
204 |
m_ctiUriCheckBox->setChecked(false);
|
|
205 |
connect(
|
|
206 |
m_ctiUriCheckBox, SIGNAL(stateChanged(int)),
|
|
207 |
this, SLOT(setupCtiUriConfiguration(int)));
|
|
208 |
|
|
209 |
m_multitapIndex = 0;
|
|
210 |
m_multitapCount = KNumOfTelMultitapCharacters;
|
|
211 |
m_multitapCharacters.clear();
|
|
212 |
m_multitapCharacters.append(Qt::Key_Asterisk);
|
|
213 |
m_multitapCharacters.append(Qt::Key_NumberSign);
|
|
214 |
m_multitapCharacters.append(Qt::Key_P);
|
|
215 |
m_multitapCharacters.append(Qt::Key_W);
|
|
216 |
} else {
|
|
217 |
m_uriLabel->setPlainText("");
|
|
218 |
}
|
|
219 |
}
|
|
220 |
|
|
221 |
|
|
222 |
void UriSchemeServiceTestAppView::setupCtiUriConfiguration(int state)
|
|
223 |
{
|
|
224 |
if (Qt::Checked == state) {
|
|
225 |
m_uriLabel->setPlainText(KCtiUriSchemePrefix);
|
|
226 |
|
|
227 |
disconnect(
|
|
228 |
m_telUriCheckBox, SIGNAL(stateChanged(int)),
|
|
229 |
this, SLOT(setupTelUriConfiguration(int)));
|
|
230 |
m_telUriCheckBox->setChecked(false);
|
|
231 |
connect(
|
|
232 |
m_telUriCheckBox, SIGNAL(stateChanged(int)),
|
|
233 |
this, SLOT(setupTelUriConfiguration(int)));
|
|
234 |
|
|
235 |
m_multitapIndex = 0;
|
|
236 |
m_multitapCount = KNumOfCtiMultitapCharacters;
|
|
237 |
m_multitapCharacters.clear();
|
|
238 |
m_multitapCharacters.append(Qt::Key_Comma);
|
|
239 |
m_multitapCharacters.append(Qt::Key_Slash);
|
|
240 |
} else {
|
|
241 |
m_uriLabel->setPlainText("");
|
|
242 |
}
|
|
243 |
}
|