|
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 <logsservices.h> |
|
21 #include <hbmainwindow.h> |
|
22 #include <xqaiwrequest.h> |
|
23 #include <xqaiwdecl.h> |
|
24 #include <xqappmgr.h> |
|
25 #include <QCoreApplication> |
|
26 #include <QKeyEvent> |
|
27 |
|
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), |
|
39 mRequest(NULL) |
|
40 { |
|
41 mMainWindow->installEventFilter(this); |
|
42 } |
|
43 |
|
44 /*! |
|
45 Destructor |
|
46 */ |
|
47 CntKeyGrabber::~CntKeyGrabber() |
|
48 { |
|
49 delete mRequest; |
|
50 } |
|
51 |
|
52 /*! |
|
53 Listens to events coming to the QObject obj (in this case HbMainWindow instance) and |
|
54 grabs/handles the necessary ones. |
|
55 |
|
56 \param obj QObject to which the event was sent to |
|
57 \param event QEvent that happened (key press, mouse press etc...) |
|
58 \return bool true if the event was handled (and thus it wont be passed on anymore) |
|
59 */ |
|
60 bool CntKeyGrabber::eventFilter(QObject *obj, QEvent *event) |
|
61 { |
|
62 if (event->type() == QEvent::KeyPress && obj == mMainWindow) |
|
63 { |
|
64 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); |
|
65 |
|
66 if (keyEvent->key() == Qt::Key_No ) |
|
67 { |
|
68 qApp->exit(); |
|
69 |
|
70 return true; |
|
71 } |
|
72 else if (keyEvent->key() == Qt::Key_Yes) |
|
73 { |
|
74 XQApplicationManager appManager; |
|
75 |
|
76 if (mRequest) |
|
77 { |
|
78 delete mRequest; |
|
79 mRequest = NULL; |
|
80 } |
|
81 |
|
82 mRequest = appManager.create(XQI_LOGS_VIEW, XQOP_LOGS_SHOW, false); |
|
83 |
|
84 if (mRequest) |
|
85 { |
|
86 QList<QVariant> args; |
|
87 QVariantMap map; |
|
88 map.insert(XQLOGS_VIEW_INDEX, QVariant(int(LogsServices::ViewAll))); |
|
89 map.insert(XQLOGS_SHOW_DIALPAD, QVariant(true)); |
|
90 map.insert(XQLOGS_DIALPAD_TEXT, QVariant(QString())); |
|
91 args.append(QVariant(map)); |
|
92 mRequest->setArguments(args); |
|
93 mRequest->send(); |
|
94 } |
|
95 |
|
96 return true; |
|
97 } |
|
98 } |
|
99 |
|
100 return QObject::eventFilter(obj, event); |
|
101 } |