78
|
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: Phone UI's Qt view private.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
#include <hbinstance.h>
|
|
18 |
#include <hbaction.h>
|
|
19 |
#include <hbvolumesliderpopup.h>
|
|
20 |
#include <hbnamespace.h>
|
|
21 |
#include <bubblemanager2.h>
|
|
22 |
#include <hblineedit.h>
|
|
23 |
#include <hbmenu.h>
|
|
24 |
|
|
25 |
#include <xqserviceutil.h>
|
|
26 |
#include <xqkeycapture.h>
|
|
27 |
#include <dialpad.h>
|
|
28 |
#include <dialpadkeyhandler.h>
|
|
29 |
#include "phoneuiqtview.h"
|
|
30 |
#include "phoneuiqtview_p.h"
|
|
31 |
#include "qtphonelog.h"
|
|
32 |
|
|
33 |
PhoneUIQtViewPrivate::PhoneUIQtViewPrivate(
|
|
34 |
HbMainWindow &window, PhoneUIQtView &parent) :
|
|
35 |
QObject(&parent),
|
|
36 |
m_parent(parent),
|
|
37 |
m_window(window),
|
|
38 |
m_bubbleManager(new BubbleManager(&m_parent)),
|
|
39 |
m_volumeSlider (0),
|
|
40 |
m_volumeCommandId(0),
|
|
41 |
m_backAction(0),
|
|
42 |
m_dialpad(0),
|
|
43 |
m_keyCapture(0),
|
|
44 |
m_networkInfo(new QSystemNetworkInfo(this)),
|
|
45 |
m_dialpadKeyHandler(0),
|
|
46 |
m_restrictedMode(false),
|
|
47 |
m_optionsMenu(0)
|
|
48 |
{
|
|
49 |
PHONE_TRACE
|
|
50 |
// Set network name
|
|
51 |
connect(m_networkInfo, SIGNAL(
|
|
52 |
networkNameChanged(QSystemNetworkInfo::NetworkMode,QString)),
|
|
53 |
this, SLOT(
|
|
54 |
networkNameChanged(QSystemNetworkInfo::NetworkMode, QString)));
|
|
55 |
|
|
56 |
// Capturing long press of end key
|
|
57 |
m_keyCapture = new XQKeyCapture();
|
|
58 |
|
|
59 |
// Dialpad
|
|
60 |
m_dialpad = new Dialpad(m_window);
|
|
61 |
m_dialpad->setCallButtonEnabled(false);
|
|
62 |
m_dialpad->setTapOutsideDismiss(true);
|
|
63 |
connect(m_dialpad,SIGNAL(aboutToClose()),this,
|
|
64 |
SLOT(dialpadClosed()));
|
|
65 |
|
|
66 |
// Set event filter
|
|
67 |
m_window.installEventFilter(this);
|
|
68 |
|
|
69 |
connect(&m_window,SIGNAL(orientationChanged(Qt::Orientation)),
|
|
70 |
this,SLOT(setDialpadPosition(Qt::Orientation)));
|
|
71 |
|
|
72 |
connect(&m_window,SIGNAL(orientationChanged(Qt::Orientation)),
|
|
73 |
m_bubbleManager,SLOT(handleOrientationChange(Qt::Orientation)));
|
|
74 |
|
|
75 |
m_bubbleManager->handleOrientationChange(m_window.orientation());
|
|
76 |
|
|
77 |
// change exit softkey to back button
|
|
78 |
m_backAction = new HbAction(Hb::BackNaviAction, this);
|
|
79 |
connect(m_backAction, SIGNAL(triggered()), this, SLOT(backButtonClicked()));
|
|
80 |
|
|
81 |
}
|
|
82 |
|
|
83 |
PhoneUIQtViewPrivate::~PhoneUIQtViewPrivate()
|
|
84 |
{
|
|
85 |
foreach (QList<HbAction *> actions, m_bubbleActionMap) {
|
|
86 |
qDeleteAll(actions);
|
|
87 |
}
|
|
88 |
|
|
89 |
qDeleteAll(m_participantListActions);
|
|
90 |
qDeleteAll(m_expandActionMap);
|
|
91 |
m_window.removeEventFilter(this);
|
|
92 |
delete m_keyCapture;
|
|
93 |
delete m_volumeSlider;
|
|
94 |
delete m_dialpad;
|
|
95 |
delete m_optionsMenu;
|
|
96 |
}
|
|
97 |
|
|
98 |
QString PhoneUIQtViewPrivate::networkName()
|
|
99 |
{
|
|
100 |
QString networkName = m_networkInfo->networkName(QSystemNetworkInfo::WcdmaMode);
|
|
101 |
if(networkName.isEmpty()) {
|
|
102 |
networkName = m_networkInfo->networkName(QSystemNetworkInfo::GsmMode);
|
|
103 |
}
|
|
104 |
return networkName;
|
|
105 |
}
|
|
106 |
|
|
107 |
void PhoneUIQtViewPrivate::addBubbleCommand (
|
|
108 |
int bubbleId,
|
|
109 |
HbAction* action )
|
|
110 |
{
|
|
111 |
PHONE_TRACE
|
|
112 |
m_bubbleManager->addAction(bubbleId, action);
|
|
113 |
|
|
114 |
QList<int> bubbles = m_bubbleActionMap.keys();
|
|
115 |
bool found(false);
|
|
116 |
|
|
117 |
for ( int i=0; i<bubbles.size(); ++i ) {
|
|
118 |
if (bubbleId==bubbles[i]){
|
|
119 |
connect(action, SIGNAL(triggered()), this, SLOT(actionTriggerred()));
|
|
120 |
m_bubbleActionMap[bubbleId].append(action);
|
|
121 |
found = true;
|
|
122 |
}
|
|
123 |
}
|
|
124 |
|
|
125 |
if (!found) {
|
|
126 |
connect(action, SIGNAL(triggered()), this, SLOT(actionTriggerred()));
|
|
127 |
QList<HbAction *> actionList;
|
|
128 |
actionList.append(action);
|
|
129 |
m_bubbleActionMap.insert(bubbleId,actionList);
|
|
130 |
}
|
|
131 |
}
|
|
132 |
|
|
133 |
void PhoneUIQtViewPrivate::addParticipantListAction(
|
|
134 |
int commandId,
|
|
135 |
const QString& text,
|
|
136 |
const HbIcon& icon)
|
|
137 |
{
|
|
138 |
PHONE_TRACE
|
|
139 |
QScopedPointer<HbAction> action(new HbAction());
|
|
140 |
action->setText(text);
|
|
141 |
action->setIcon(icon);
|
|
142 |
action->setProperty("command", commandId);
|
|
143 |
m_bubbleManager->addParticipantListAction(action.data());
|
|
144 |
|
|
145 |
connect(action.data(), SIGNAL(triggered()), this, SLOT(actionTriggerred()));
|
|
146 |
m_participantListActions.append(action.take());
|
|
147 |
}
|
|
148 |
|
|
149 |
void PhoneUIQtViewPrivate::clearParticipantListActions()
|
|
150 |
{
|
|
151 |
PHONE_TRACE
|
|
152 |
m_bubbleManager->clearParticipantListActions();
|
|
153 |
qDeleteAll(m_participantListActions);
|
|
154 |
m_participantListActions.clear();
|
|
155 |
}
|
|
156 |
|
|
157 |
void PhoneUIQtViewPrivate::clearBubbleCommands (int bubbleId)
|
|
158 |
{
|
|
159 |
PHONE_TRACE
|
|
160 |
m_bubbleManager->clearActions(bubbleId);
|
|
161 |
qDeleteAll(m_bubbleActionMap.take(bubbleId));
|
|
162 |
}
|
|
163 |
|
|
164 |
int PhoneUIQtViewPrivate::volumeSliderValue()
|
|
165 |
{
|
|
166 |
if (m_volumeSlider) {
|
|
167 |
return m_volumeSlider->value ();
|
|
168 |
} else {
|
|
169 |
return -1;
|
|
170 |
}
|
|
171 |
}
|
|
172 |
|
|
173 |
void PhoneUIQtViewPrivate::removeVolumeSlider()
|
|
174 |
{
|
|
175 |
if (m_volumeSlider) {
|
|
176 |
if (m_volumeSlider->isVisible()) {
|
|
177 |
m_volumeSlider->hide();
|
|
178 |
}
|
|
179 |
m_volumeSlider->deleteLater();
|
|
180 |
m_volumeSlider = 0;
|
|
181 |
}
|
|
182 |
}
|
|
183 |
|
|
184 |
void PhoneUIQtViewPrivate::setVolumeSliderValue (
|
|
185 |
int value, int commandId, int maxVolumeValue, int minVolumeValue)
|
|
186 |
{
|
|
187 |
PHONE_TRACE
|
|
188 |
m_volumeCommandId = commandId;
|
|
189 |
|
|
190 |
if (!m_volumeSlider) {
|
|
191 |
m_volumeSlider = new HbVolumeSliderPopup();
|
|
192 |
m_volumeSlider->setDismissPolicy(HbDialog::TapOutside);
|
|
193 |
m_volumeSlider->setTimeout(10000); // TODO: 10 seconds for now, replace with correct value when spec is ready and says what it is
|
|
194 |
connect(m_volumeSlider, SIGNAL(valueChanged(int)), this, SLOT(volumeSliderChanged(int)));
|
|
195 |
connect(m_volumeSlider, SIGNAL(aboutToClose()), this, SLOT(removeVolumeSlider()));
|
|
196 |
}
|
|
197 |
|
|
198 |
|
|
199 |
if (m_volumeSlider->minimum() != minVolumeValue ||
|
|
200 |
m_volumeSlider->maximum() != maxVolumeValue ) {
|
|
201 |
m_volumeSlider->setRange(minVolumeValue, maxVolumeValue);
|
|
202 |
}
|
|
203 |
|
|
204 |
if (value != m_volumeSlider->value()) {
|
|
205 |
m_volumeSlider->setValue(value);
|
|
206 |
}
|
|
207 |
|
|
208 |
|
|
209 |
if (false == m_volumeSlider->isVisible()) {
|
|
210 |
m_volumeSlider->show();
|
|
211 |
}
|
|
212 |
}
|
|
213 |
|
|
214 |
void PhoneUIQtViewPrivate::volumeSliderChanged(int value)
|
|
215 |
{
|
|
216 |
Q_UNUSED (value);
|
|
217 |
emit m_parent.command(m_volumeCommandId);
|
|
218 |
}
|
|
219 |
|
|
220 |
void PhoneUIQtViewPrivate::setExpandAction(int bubbleId, int commandId)
|
|
221 |
{
|
|
222 |
PHONE_TRACE
|
|
223 |
removeExpandAction(bubbleId);
|
|
224 |
|
|
225 |
QScopedPointer<HbAction> action(new HbAction());
|
|
226 |
action->setProperty("command", commandId);
|
|
227 |
m_bubbleManager->setExpandAction(bubbleId, action.data());
|
|
228 |
|
|
229 |
connect(action.data(), SIGNAL(triggered()), this, SLOT(actionTriggerred()));
|
|
230 |
|
|
231 |
m_expandActionMap.insert(bubbleId, action.take());
|
|
232 |
}
|
|
233 |
|
|
234 |
void PhoneUIQtViewPrivate::removeExpandAction(int bubbleId)
|
|
235 |
{
|
|
236 |
PHONE_TRACE
|
|
237 |
if (m_expandActionMap.contains(bubbleId)) {
|
|
238 |
m_bubbleManager->setExpandAction(bubbleId, 0);
|
|
239 |
delete m_expandActionMap.take(bubbleId);
|
|
240 |
}
|
|
241 |
}
|
|
242 |
|
|
243 |
void PhoneUIQtViewPrivate::showDialpad()
|
|
244 |
{
|
|
245 |
if (false == m_dialpad->isVisible()) {
|
|
246 |
setDialpadPosition(m_window.orientation());
|
|
247 |
m_dialpad->openDialpad();
|
|
248 |
}
|
|
249 |
}
|
|
250 |
|
|
251 |
void PhoneUIQtViewPrivate::hideDialpad()
|
|
252 |
{
|
|
253 |
if (true == m_dialpad->isVisible())
|
|
254 |
m_dialpad->closeDialpad();
|
|
255 |
}
|
|
256 |
|
|
257 |
void PhoneUIQtViewPrivate::replaceActions(
|
|
258 |
HbWidget &widget, const QList<HbAction *> &actions) const
|
|
259 |
{
|
|
260 |
|
|
261 |
// Memorize old actions, so that widget doenst flash while updating
|
|
262 |
QList<QAction*> oldActions = widget.actions();
|
|
263 |
|
|
264 |
// Add new toolbar actions
|
|
265 |
foreach (HbAction *newAction, actions) {
|
|
266 |
newAction->setParent(&widget); // Transfer ownership
|
|
267 |
connect(newAction, SIGNAL(triggered()), this, SLOT(actionTriggerred()));
|
|
268 |
widget.addAction(newAction);
|
|
269 |
}
|
|
270 |
|
|
271 |
// Remove and delete old actions
|
|
272 |
foreach (QAction *oldAction, oldActions) {
|
|
273 |
widget.removeAction(oldAction);
|
|
274 |
delete oldAction;
|
|
275 |
}
|
|
276 |
|
|
277 |
}
|
|
278 |
|
|
279 |
void PhoneUIQtViewPrivate::captureKey(Qt::Key key, bool capture)
|
|
280 |
{
|
|
281 |
if (capture) {
|
|
282 |
if (!m_keyCaptures.contains(key)) {
|
|
283 |
m_keyCapture->captureLongKey(key);
|
|
284 |
m_keyCapture->captureKey(key);
|
|
285 |
m_keyCaptures.append(key);
|
|
286 |
}
|
|
287 |
} else {
|
|
288 |
if (m_keyCaptures.contains(key)) {
|
|
289 |
m_keyCapture->cancelCaptureKey(key);
|
|
290 |
m_keyCapture->cancelCaptureLongKey(key);
|
|
291 |
m_keyCaptures.removeOne(key);
|
|
292 |
}
|
|
293 |
}
|
|
294 |
}
|
|
295 |
|
|
296 |
void PhoneUIQtViewPrivate::backButtonClicked()
|
|
297 |
{
|
|
298 |
XQServiceUtil::toBackground(true);
|
|
299 |
}
|
|
300 |
|
|
301 |
void PhoneUIQtViewPrivate::onEditorContentChanged()
|
|
302 |
{
|
|
303 |
m_dialpad->setCallButtonEnabled(
|
|
304 |
m_dialpad->editor().text().length());
|
|
305 |
}
|
|
306 |
|
|
307 |
void PhoneUIQtViewPrivate::dialpadClosed()
|
|
308 |
{
|
|
309 |
emit m_parent.dialpadIsAboutToClose();
|
|
310 |
}
|
|
311 |
|
|
312 |
bool PhoneUIQtViewPrivate::eventFilter(QObject *watched, QEvent * event)
|
|
313 |
{
|
|
314 |
Q_UNUSED(watched);
|
|
315 |
PHONE_TRACE2(":event type", event->type());
|
|
316 |
|
|
317 |
// Allow send key only when there is callbutton enabled or no text in input field
|
|
318 |
bool sendKeyAllowed = m_dialpad->isCallButtonEnabled() ||
|
|
319 |
(m_dialpad->editor().text().length() == 0);
|
|
320 |
|
|
321 |
if(event->type() == QEvent::KeyPress) {
|
|
322 |
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
|
|
323 |
PHONE_DEBUG2("PhoneUIQtView::eventFilter pressed key:", keyEvent->key());
|
|
324 |
PHONE_DEBUG2("PhoneUIQtView::eventFilter isAutoRepeat:", keyEvent->isAutoRepeat());
|
|
325 |
if ( (keyEvent->key() != Qt::Key_Yes && keyEvent->key() != Qt::Key_Enter) ||
|
|
326 |
sendKeyAllowed) {
|
|
327 |
emit m_parent.keyPressed(keyEvent);
|
|
328 |
keyEvent->accept();
|
|
329 |
}
|
|
330 |
|
|
331 |
return false;
|
|
332 |
} else if(event->type() == QEvent::KeyRelease) {
|
|
333 |
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
|
|
334 |
PHONE_DEBUG2("PhoneUIQtView::eventFilter released key:", keyEvent->key());
|
|
335 |
if ( (keyEvent->key() != Qt::Key_Yes && keyEvent->key() != Qt::Key_Enter) ||
|
|
336 |
sendKeyAllowed) {
|
|
337 |
emit m_parent.keyReleased(keyEvent);
|
|
338 |
keyEvent->accept();
|
|
339 |
}
|
|
340 |
return false;
|
|
341 |
} else if (event->type() == QEvent::WindowActivate){
|
|
342 |
PHONE_DEBUG("PhoneUIQtView::eventFilter WindowActivate");
|
|
343 |
emit m_parent.windowActivated();
|
|
344 |
return false;
|
|
345 |
} else if (event->type() == QEvent::WindowDeactivate){
|
|
346 |
PHONE_DEBUG("PhoneUIQtView::eventFilter WindowDeactivate");
|
|
347 |
emit m_parent.windowDeactivated();
|
|
348 |
return false;
|
|
349 |
}else{
|
|
350 |
return false;
|
|
351 |
}
|
|
352 |
}
|
|
353 |
|
|
354 |
void PhoneUIQtViewPrivate::setDialpadPosition(Qt::Orientation orientation)
|
|
355 |
{
|
|
356 |
PHONE_TRACE
|
|
357 |
QRectF screenRect(m_window.layoutRect());
|
|
358 |
|
|
359 |
if (orientation == Qt::Horizontal) {
|
|
360 |
// dialpad takes half of the screen
|
|
361 |
m_dialpad->setPos(QPointF(screenRect.width()/2,
|
|
362 |
m_parent.scenePos().y()));
|
|
363 |
m_dialpad->setPreferredSize(screenRect.width()/2,
|
|
364 |
(screenRect.height()-m_parent.scenePos().y()));
|
|
365 |
} else {
|
|
366 |
// dialpad takes 65% of the screen height
|
|
367 |
qreal screenHeight = screenRect.height();
|
|
368 |
m_dialpad->setPos(QPointF(0,
|
|
369 |
screenHeight/2.25));
|
|
370 |
m_dialpad->setPreferredSize(screenRect.width(),
|
|
371 |
screenHeight-screenHeight/2.25);
|
|
372 |
}
|
|
373 |
}
|
|
374 |
|
|
375 |
void PhoneUIQtViewPrivate::setBackButtonVisible(bool visible)
|
|
376 |
{
|
|
377 |
if (!m_restrictedMode) {
|
|
378 |
m_backAction->setEnabled(visible);
|
|
379 |
}
|
|
380 |
}
|
|
381 |
|
|
382 |
void PhoneUIQtViewPrivate::setRestrictedMode(bool restrictedMode)
|
|
383 |
{
|
|
384 |
PHONE_TRACE
|
|
385 |
m_restrictedMode = restrictedMode;
|
|
386 |
m_backAction->setEnabled(!restrictedMode);
|
|
387 |
m_dialpad->setCallButtonEnabled(false);
|
|
388 |
m_dialpad->editor().setText(""); // Clead dialpad
|
|
389 |
if (m_restrictedMode) {
|
|
390 |
delete m_dialpadKeyHandler;
|
|
391 |
m_dialpadKeyHandler = 0;
|
|
392 |
m_dialpadKeyHandler = new DialpadKeyHandler(
|
|
393 |
m_dialpad, DialpadKeyHandler::EmergencyCall, this);
|
|
394 |
disconnect(&m_dialpad->editor(),SIGNAL(contentsChanged()),
|
|
395 |
this, SLOT(onEditorContentChanged())); // Let emergency handler do updating
|
|
396 |
} else {
|
|
397 |
delete m_dialpadKeyHandler;
|
|
398 |
m_dialpadKeyHandler = 0;
|
|
399 |
// enable key sequence handling during a call
|
|
400 |
m_dialpadKeyHandler = new DialpadKeyHandler(
|
|
401 |
m_dialpad, DialpadKeyHandler::KeySequence, this);
|
|
402 |
connect(&m_dialpad->editor(),SIGNAL(contentsChanged()),
|
|
403 |
SLOT(onEditorContentChanged())); // Update our self
|
|
404 |
}
|
|
405 |
|
|
406 |
}
|
|
407 |
|
|
408 |
void PhoneUIQtViewPrivate::networkNameChanged(
|
|
409 |
QSystemNetworkInfo::NetworkMode mode, const QString &netName)
|
|
410 |
{
|
|
411 |
if((mode == QSystemNetworkInfo::GsmMode) ||
|
|
412 |
(mode == QSystemNetworkInfo::WcdmaMode)) {
|
|
413 |
m_parent.setTitle(netName);
|
|
414 |
}
|
|
415 |
}
|
|
416 |
|
|
417 |
|
|
418 |
void PhoneUIQtViewPrivate::actionTriggerred()
|
|
419 |
{
|
|
420 |
if (sender()->property("command").isValid()) {
|
|
421 |
emit m_parent.command(sender()->property("command").toInt());
|
|
422 |
} else {
|
|
423 |
PHONE_TRACE1(": No command found!")
|
|
424 |
}
|
|
425 |
}
|