phonebookui/pbkcommonui/src/cntkeygrabber.cpp
changeset 71 7cc7d74059f9
parent 59 a642906a277a
equal deleted inserted replaced
65:ae724a111993 71:7cc7d74059f9
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "cntkeygrabber.h"
    18 #include "cntkeygrabber.h"
    19 
    19 
    20 #include <logsservices.h>
       
    21 #include <hbmainwindow.h>
    20 #include <hbmainwindow.h>
    22 #include <xqaiwrequest.h>
    21 #include <xqaiwrequest.h>
    23 #include <xqaiwdecl.h>
    22 #include <xqaiwdecl.h>
    24 #include <xqappmgr.h>
    23 #include <xqappmgr.h>
    25 #include <QCoreApplication>
    24 #include <QCoreApplication>
    26 #include <QKeyEvent>
    25 #include <QKeyEvent>
    27 
    26 #include <xqserviceutil.h>
       
    27 #include <xqkeycapture.h>
    28 /*!
    28 /*!
    29     Key press event handler for default actions when pressing either send or end key.
    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
    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 
    31     can be overwritten to have view-specific functionality by installing an additional 
    32     event filter for the main window.
    32     event filter for the main window.
    34     See CntGroupActionsView for an example.
    34     See CntGroupActionsView for an example.
    35 */
    35 */
    36 CntKeyGrabber::CntKeyGrabber(HbMainWindow *window, QObject *parent) :
    36 CntKeyGrabber::CntKeyGrabber(HbMainWindow *window, QObject *parent) :
    37     QObject(parent),
    37     QObject(parent),
    38     mMainWindow(window),
    38     mMainWindow(window),
    39     mRequest(NULL)
    39     mRequest(NULL),
       
    40     mKeyCapture(NULL)
    40 {
    41 {
    41     mMainWindow->installEventFilter(this);
    42     mMainWindow->installEventFilter(this);
       
    43     mKeyCapture = new XqKeyCapture();
    42 }
    44 }
    43 
    45 
    44 /*!
    46 /*!
    45     Destructor
    47     Destructor
    46 */
    48 */
    47 CntKeyGrabber::~CntKeyGrabber()
    49 CntKeyGrabber::~CntKeyGrabber()
    48 {
    50 {
    49     delete mRequest;
    51     delete mRequest;
       
    52     if ( mKeyCapture )
       
    53     {
       
    54         mKeyCapture->cancelCaptureKey(Qt::Key_Yes);
       
    55     }
       
    56     delete mKeyCapture;
       
    57     mKeyCapture = NULL;
    50 }
    58 }
    51 
    59 
    52 /*!
    60 /*!
    53     Listens to events coming to the QObject obj (in this case HbMainWindow instance) and
    61     Listens to events coming to the QObject obj (in this case HbMainWindow instance) and
    54     grabs/handles the necessary ones.
    62     grabs/handles the necessary ones.
    57     \param event QEvent that happened (key press, mouse press etc...)
    65     \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)
    66     \return bool true if the event was handled (and thus it wont be passed on anymore)
    59 */
    67 */
    60 bool CntKeyGrabber::eventFilter(QObject *obj, QEvent *event)
    68 bool CntKeyGrabber::eventFilter(QObject *obj, QEvent *event)
    61 {
    69 {
    62     if (event->type() == QEvent::KeyPress && obj == mMainWindow)
    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)
    63     {
    79     {
    64         QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
    80         QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
    65         
    81         
    66         if (keyEvent->key() == Qt::Key_No )
    82         if (keyEvent->key() == Qt::Key_No )
    67         {
    83         {
    83             
    99             
    84             if (mRequest)
   100             if (mRequest)
    85             {
   101             {
    86                 QList<QVariant> args;
   102                 QList<QVariant> args;
    87                 QVariantMap map;
   103                 QVariantMap map;
    88                 map.insert(XQLOGS_VIEW_INDEX, QVariant(int(LogsServices::ViewAll)));
   104                 map.insert(XQLOGS_VIEW_INDEX, QVariant(int(XQService::LogsViewAll)));
    89                 map.insert(XQLOGS_SHOW_DIALPAD, QVariant(true));
   105                 map.insert(XQLOGS_SHOW_DIALPAD, QVariant(true));
    90                 map.insert(XQLOGS_DIALPAD_TEXT, QVariant(QString()));
   106                 map.insert(XQLOGS_DIALPAD_TEXT, QVariant(QString()));
    91                 args.append(QVariant(map));
   107                 args.append(QVariant(map));
    92                 mRequest->setArguments(args);
   108                 mRequest->setArguments(args);
    93                 mRequest->send();
   109                 mRequest->send();