--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/phonebookui/pbkcommonui/src/cntkeygrabber.cpp Thu Aug 05 14:31:09 2010 +0300
@@ -0,0 +1,101 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+#include "cntkeygrabber.h"
+
+#include <logsservices.h>
+#include <hbmainwindow.h>
+#include <xqaiwrequest.h>
+#include <xqaiwdecl.h>
+#include <xqappmgr.h>
+#include <QCoreApplication>
+#include <QKeyEvent>
+
+/*!
+ Key press event handler for default actions when pressing either send or end key.
+ End key closes the application and send key opens dialer. Default functionality
+ can be overwritten to have view-specific functionality by installing an additional
+ event filter for the main window.
+
+ See CntGroupActionsView for an example.
+*/
+CntKeyGrabber::CntKeyGrabber(HbMainWindow *window, QObject *parent) :
+ QObject(parent),
+ mMainWindow(window),
+ mRequest(NULL)
+{
+ mMainWindow->installEventFilter(this);
+}
+
+/*!
+ Destructor
+*/
+CntKeyGrabber::~CntKeyGrabber()
+{
+ delete mRequest;
+}
+
+/*!
+ Listens to events coming to the QObject obj (in this case HbMainWindow instance) and
+ grabs/handles the necessary ones.
+
+ \param obj QObject to which the event was sent to
+ \param event QEvent that happened (key press, mouse press etc...)
+ \return bool true if the event was handled (and thus it wont be passed on anymore)
+*/
+bool CntKeyGrabber::eventFilter(QObject *obj, QEvent *event)
+{
+ if (event->type() == QEvent::KeyPress && obj == mMainWindow)
+ {
+ QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
+
+ if (keyEvent->key() == Qt::Key_No )
+ {
+ qApp->exit();
+
+ return true;
+ }
+ else if (keyEvent->key() == Qt::Key_Yes)
+ {
+ XQApplicationManager appManager;
+
+ if (mRequest)
+ {
+ delete mRequest;
+ mRequest = NULL;
+ }
+
+ mRequest = appManager.create(XQI_LOGS_VIEW, XQOP_LOGS_SHOW, false);
+
+ if (mRequest)
+ {
+ QList<QVariant> args;
+ QVariantMap map;
+ map.insert(XQLOGS_VIEW_INDEX, QVariant(int(LogsServices::ViewAll)));
+ map.insert(XQLOGS_SHOW_DIALPAD, QVariant(true));
+ map.insert(XQLOGS_DIALPAD_TEXT, QVariant(QString()));
+ args.append(QVariant(map));
+ mRequest->setArguments(args);
+ mRequest->send();
+ }
+
+ return true;
+ }
+ }
+
+ return QObject::eventFilter(obj, event);
+}