telutils/dialpad/src/dialpadvoicemailboxeventfilter.cpp
branchRCL_3
changeset 20 987c9837762f
parent 19 7d48bed6ce0c
child 21 0a6dd2dc9970
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
     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: 
       
    15 *
       
    16 */
       
    17 #include <QTimer>
       
    18 #include <QKeyEvent>
       
    19 #include <hblineedit.h>
       
    20 #include <hbstringutil.h>
       
    21 #include "dialpadvoicemailboxeventfilter.h"
       
    22 #include "dialpadsymbianwrapper.h"
       
    23 #include "dialpad.h"
       
    24 #include "qtphonesrvlog.h"
       
    25 
       
    26 #ifdef Q_OS_SYMBIAN
       
    27 #include <xqservicerequest.h>
       
    28 #include <xqserviceutil.h>
       
    29 #endif //Q_OS_SYMBIAN
       
    30 
       
    31 const QString VmbxCharacter("1");
       
    32 
       
    33 DialpadVoiceMailboxEventFilter::DialpadVoiceMailboxEventFilter(Dialpad* dialpad, QObject* parent) :
       
    34     DialpadMailboxEventFilterBase(dialpad, parent)
       
    35 {
       
    36 }
       
    37 
       
    38 DialpadVoiceMailboxEventFilter::~DialpadVoiceMailboxEventFilter()
       
    39 {
       
    40 }
       
    41 
       
    42 bool DialpadVoiceMailboxEventFilter::eventFilter(QObject *watched, QEvent *event)
       
    43 {
       
    44     Q_UNUSED(watched)
       
    45     bool keyEventEaten(false);
       
    46     
       
    47     if (event->type() == QEvent::KeyPress) {
       
    48         QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
       
    49         if (checkIfSendEventAndConsumeEvent(keyEvent->key(), event->type())) {
       
    50             keyEventEaten = true;
       
    51         } else if ((isLongKeyPressSupported(keyEvent->key())) &&
       
    52                 !(mDialpad->editor().text().length() >= 1)) {
       
    53             //Check that there is only one item in dialpad, if there is more than one
       
    54             //do not handle long key press.
       
    55             mLongPressTimer->stop();
       
    56             mLongPressTimer->start(DialpadLongKeyPressTimeOut);
       
    57         }
       
    58     } else if (event->type() == QEvent::KeyRelease) {
       
    59         QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
       
    60         if (checkIfSendEventAndConsumeEvent(keyEvent->key(), event->type())) {
       
    61             keyEventEaten = true;
       
    62         } else if (isLongKeyPressSupported(keyEvent->key())){
       
    63             mLongPressTimer->stop();
       
    64         }
       
    65     }
       
    66 
       
    67     return keyEventEaten;
       
    68 }
       
    69 
       
    70 void DialpadVoiceMailboxEventFilter::handleLongKeyPress()
       
    71 {
       
    72     PHONE_TRACE;
       
    73     switch(mKeyEvent) {
       
    74     case Qt::Key_1:{
       
    75        handleMailboxOperation();
       
    76        break;
       
    77        }
       
    78    default:
       
    79        // Do nothing.
       
    80        break;
       
    81     }
       
    82 
       
    83     // Reset key code.
       
    84     mKeyEvent = NULL;
       
    85 }
       
    86 
       
    87 bool DialpadVoiceMailboxEventFilter::handleCallButtonPress()
       
    88 {
       
    89     PHONE_TRACE;
       
    90     bool callButtonhandled(false);
       
    91     if (!mDialpad->editor().text().isEmpty()) {
       
    92 #ifdef Q_OS_SYMBIAN
       
    93         // check if editor has '1' character if does then
       
    94         // get MailboxNumber.
       
    95         QString editorContent = HbStringUtil::convertDigitsTo(
       
    96             mDialpad->editor().text(), WesternDigit);
       
    97         if (VmbxCharacter==editorContent) {
       
    98             handleMailboxOperation();
       
    99             callButtonhandled = true;
       
   100         }
       
   101 #endif //Q_OS_SYMBIAN
       
   102     }
       
   103     return callButtonhandled;
       
   104 }
       
   105 
       
   106 void DialpadVoiceMailboxEventFilter::handleMailboxOperation()
       
   107 {
       
   108     PHONE_TRACE;
       
   109     QString mailboxNumber;
       
   110     int error = mSymbianWrapper->getMailboxNumber(mailboxNumber);
       
   111     // If here is no vmbx number and dialpad must start vmbx number definition procedures.
       
   112     if (DialpadErrorNone != error || mailboxNumber.length() == 0) {
       
   113         mDialpad->closeDialpad();
       
   114         // If define mailbox query was interupted than reopen dialpad.
       
   115         error = mSymbianWrapper->defineMailboxNumber(mailboxNumber);
       
   116         if (DialpadErrorCancel == error) {
       
   117             mDialpad->openDialpad();
       
   118         }
       
   119     }
       
   120     // Valid vmbx number found or defined and there vmbx didnt
       
   121     // return error values then create a call.
       
   122     if ((DialpadErrorNone == error) &&
       
   123         (mailboxNumber.length() != 0)) {
       
   124         createCall(mailboxNumber);
       
   125         clearEditor();
       
   126         mDialpad->openDialpad();
       
   127     }
       
   128 }