telutils/dialpad/src/dialpadvideomailboxeventfilter.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 "dialpadvideomailboxeventfilter.h"
       
    22 #include "dialpadsymbianwrapper.h"
       
    23 #include "dialpad.h"
       
    24 #include "qtphonesrvlog.h"
       
    25 
       
    26 #ifdef Q_OS_SYMBIAN
       
    27 #include <xqserviceutil.h>
       
    28 #endif //Q_OS_SYMBIAN
       
    29 
       
    30 #include <xqsettingsmanager.h>
       
    31 #include <xqsettingskey.h>
       
    32 #include <voicemailboxdomaincrkeys.h>
       
    33 
       
    34 
       
    35 const QString VideoVmbxCharacter("2");
       
    36 
       
    37 DialpadVideoMailboxEventFilter::DialpadVideoMailboxEventFilter(Dialpad* dialpad, QObject* parent) :
       
    38     DialpadMailboxEventFilterBase(dialpad, parent)
       
    39 {
       
    40 }
       
    41 
       
    42 DialpadVideoMailboxEventFilter::~DialpadVideoMailboxEventFilter()
       
    43 {
       
    44 }
       
    45 
       
    46 bool DialpadVideoMailboxEventFilter::eventFilter(QObject *watched, QEvent *event)
       
    47 {
       
    48     Q_UNUSED(watched)
       
    49     bool keyEventEaten(false);
       
    50         
       
    51     if (event->type() == QEvent::KeyPress) {
       
    52         QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
       
    53         if (checkIfSendEventAndConsumeEvent(keyEvent->key(), event->type())) {
       
    54             keyEventEaten = true;
       
    55         } else if ((isLongKeyPressSupported(keyEvent->key())) &&
       
    56                 !(mDialpad->editor().text().length() >= 1)) {
       
    57             //Check that there is only one item in dialpad, if there is more than one
       
    58             //do not handle long key press.
       
    59             mLongPressTimer->stop();
       
    60             mLongPressTimer->start(DialpadLongKeyPressTimeOut);
       
    61         }
       
    62     } else if (event->type() == QEvent::KeyRelease) {
       
    63         QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
       
    64         if (checkIfSendEventAndConsumeEvent(keyEvent->key(), event->type())) {
       
    65             keyEventEaten = true;
       
    66         } else if (isLongKeyPressSupported(keyEvent->key())){
       
    67             mLongPressTimer->stop();
       
    68         }
       
    69     }
       
    70 
       
    71     return keyEventEaten;
       
    72 }
       
    73 
       
    74 void DialpadVideoMailboxEventFilter::handleLongKeyPress()
       
    75 {
       
    76     PHONE_TRACE;
       
    77     switch(mKeyEvent) {
       
    78     case Qt::Key_2:{
       
    79        handleMailboxOperation();
       
    80        break;
       
    81        }
       
    82    default:
       
    83        // Do nothing.
       
    84        break;
       
    85     }
       
    86 
       
    87     // Reset key code.
       
    88     mKeyEvent = NULL;
       
    89 }
       
    90 
       
    91 bool DialpadVideoMailboxEventFilter::handleCallButtonPress()
       
    92 {
       
    93     PHONE_TRACE;
       
    94     bool callButtonhandled(false);
       
    95     if (!mDialpad->editor().text().isEmpty()) {
       
    96 #ifdef Q_OS_SYMBIAN
       
    97         // check if editor has '2' character if does then
       
    98         // get MailboxNumber.
       
    99         QString editorContent = HbStringUtil::convertDigitsTo(
       
   100             mDialpad->editor().text(), WesternDigit);
       
   101         if (VideoVmbxCharacter==editorContent) {
       
   102             handleMailboxOperation();
       
   103             callButtonhandled = true;
       
   104         }
       
   105 #endif //Q_OS_SYMBIAN
       
   106     }
       
   107     return callButtonhandled;
       
   108 }
       
   109 
       
   110 void DialpadVideoMailboxEventFilter::handleMailboxOperation()
       
   111 {
       
   112     PHONE_TRACE;
       
   113     
       
   114     if (isVideoMbxSupported()) {
       
   115         QString mailboxNumber;
       
   116         int error = mSymbianWrapper->getVideoMailboxNumber(mailboxNumber);
       
   117         // If here is no vmbx number and dialpad must start vmbx number definition procedures.
       
   118         if (DialpadErrorNone != error || mailboxNumber.length() == 0) {
       
   119             mDialpad->closeDialpad();
       
   120             // If define mailbox query was interupted than reopen dialpad.
       
   121             error = mSymbianWrapper->defineVideoMailboxNumber(mailboxNumber);
       
   122             if (DialpadErrorCancel == error) {
       
   123                 mDialpad->openDialpad();
       
   124             }
       
   125         }
       
   126     
       
   127         // Valid vmbx number found or defined and there vmbx didnt
       
   128         // return error values then create a call.
       
   129         if ((DialpadErrorNone == error) &&
       
   130             (mailboxNumber.length() != 0)) {
       
   131             createCall(mailboxNumber, true);
       
   132             clearEditor();
       
   133             mDialpad->openDialpad();
       
   134         }
       
   135     }
       
   136 }
       
   137 
       
   138 bool DialpadVideoMailboxEventFilter::isVideoMbxSupported()
       
   139 {
       
   140     XQSettingsKey key(XQSettingsKey::TargetCentralRepository,
       
   141         KCRUidVideoMailbox.iUid,
       
   142         KVideoMbxSupport);
       
   143     XQSettingsManager settingsMgr;
       
   144     
       
   145     int ret = settingsMgr.readItemValue(key, XQSettingsManager::TypeInt).toInt();
       
   146     PHONE_TRACE2("Video mbx support:", ret);
       
   147     return ret;
       
   148 }
       
   149