54
|
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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "cntkeygrabber.h"
|
|
19 |
|
|
20 |
#include <hbmainwindow.h>
|
|
21 |
#include <xqaiwrequest.h>
|
|
22 |
#include <xqaiwdecl.h>
|
|
23 |
#include <xqappmgr.h>
|
|
24 |
#include <QCoreApplication>
|
|
25 |
#include <QKeyEvent>
|
66
|
26 |
#include <xqserviceutil.h>
|
|
27 |
#include <xqkeycapture.h>
|
54
|
28 |
/*!
|
|
29 |
Key press event handler for default actions when pressing either send or end key.
|
|
30 |
End key closes the application and send key opens dialer. Default functionality
|
|
31 |
can be overwritten to have view-specific functionality by installing an additional
|
|
32 |
event filter for the main window.
|
|
33 |
|
|
34 |
See CntGroupActionsView for an example.
|
|
35 |
*/
|
|
36 |
CntKeyGrabber::CntKeyGrabber(HbMainWindow *window, QObject *parent) :
|
|
37 |
QObject(parent),
|
|
38 |
mMainWindow(window),
|
66
|
39 |
mRequest(NULL),
|
|
40 |
mKeyCapture(NULL)
|
54
|
41 |
{
|
|
42 |
mMainWindow->installEventFilter(this);
|
73
|
43 |
mKeyCapture = new XQKeyCapture();
|
54
|
44 |
}
|
|
45 |
|
|
46 |
/*!
|
|
47 |
Destructor
|
|
48 |
*/
|
|
49 |
CntKeyGrabber::~CntKeyGrabber()
|
|
50 |
{
|
|
51 |
delete mRequest;
|
66
|
52 |
if ( mKeyCapture )
|
|
53 |
{
|
|
54 |
mKeyCapture->cancelCaptureKey(Qt::Key_Yes);
|
|
55 |
}
|
|
56 |
delete mKeyCapture;
|
|
57 |
mKeyCapture = NULL;
|
54
|
58 |
}
|
|
59 |
|
|
60 |
/*!
|
|
61 |
Listens to events coming to the QObject obj (in this case HbMainWindow instance) and
|
|
62 |
grabs/handles the necessary ones.
|
|
63 |
|
|
64 |
\param obj QObject to which the event was sent to
|
|
65 |
\param event QEvent that happened (key press, mouse press etc...)
|
|
66 |
\return bool true if the event was handled (and thus it wont be passed on anymore)
|
|
67 |
*/
|
|
68 |
bool CntKeyGrabber::eventFilter(QObject *obj, QEvent *event)
|
|
69 |
{
|
66
|
70 |
if ( event->type() == QEvent::ApplicationActivate )
|
|
71 |
{
|
|
72 |
mKeyCapture->captureKey( Qt::Key_Yes );
|
|
73 |
}
|
|
74 |
else if ( event->type() == QEvent::ApplicationDeactivate )
|
|
75 |
{
|
|
76 |
mKeyCapture->cancelCaptureKey( Qt::Key_Yes );
|
|
77 |
}
|
|
78 |
else if (event->type() == QEvent::KeyPress && obj == mMainWindow)
|
54
|
79 |
{
|
|
80 |
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
|
|
81 |
|
|
82 |
if (keyEvent->key() == Qt::Key_No )
|
|
83 |
{
|
|
84 |
qApp->exit();
|
|
85 |
|
|
86 |
return true;
|
|
87 |
}
|
|
88 |
else if (keyEvent->key() == Qt::Key_Yes)
|
|
89 |
{
|
|
90 |
XQApplicationManager appManager;
|
|
91 |
|
|
92 |
if (mRequest)
|
|
93 |
{
|
|
94 |
delete mRequest;
|
|
95 |
mRequest = NULL;
|
|
96 |
}
|
|
97 |
|
|
98 |
mRequest = appManager.create(XQI_LOGS_VIEW, XQOP_LOGS_SHOW, false);
|
|
99 |
|
|
100 |
if (mRequest)
|
|
101 |
{
|
|
102 |
QList<QVariant> args;
|
|
103 |
QVariantMap map;
|
66
|
104 |
map.insert(XQLOGS_VIEW_INDEX, QVariant(int(XQService::LogsViewAll)));
|
54
|
105 |
map.insert(XQLOGS_SHOW_DIALPAD, QVariant(true));
|
|
106 |
map.insert(XQLOGS_DIALPAD_TEXT, QVariant(QString()));
|
|
107 |
args.append(QVariant(map));
|
|
108 |
mRequest->setArguments(args);
|
|
109 |
mRequest->send();
|
|
110 |
}
|
|
111 |
|
|
112 |
return true;
|
|
113 |
}
|
|
114 |
}
|
|
115 |
|
|
116 |
return QObject::eventFilter(obj, event);
|
|
117 |
}
|