telutils/dialpad/src/dialpadbluetootheventfilter.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 "dialpadbluetootheventfilter.h"
       
    21 #include "dialpad.h"
       
    22 #include "qtphonesrvlog.h"
       
    23 
       
    24 #ifdef Q_OS_SYMBIAN
       
    25 #include <xqservicerequest.h>
       
    26 #endif //Q_OS_SYMBIAN
       
    27 
       
    28 const int DialpadLongKeyPressTimeOut(1000);
       
    29 const QString BluetoothCharacter("*");
       
    30 
       
    31 DialpadBluetoothEventFilter::DialpadBluetoothEventFilter(Dialpad* dialpad, QObject* parent) :
       
    32     QObject(parent), mDialpad(dialpad)
       
    33 {
       
    34     PHONE_TRACE;
       
    35     mLongPressTimer = new QTimer(this);
       
    36     mLongPressTimer->setSingleShot(true);
       
    37     connect(mLongPressTimer,SIGNAL(timeout()), this, SLOT(toggleBluetooth()));
       
    38 }
       
    39 
       
    40 DialpadBluetoothEventFilter::~DialpadBluetoothEventFilter()
       
    41 {
       
    42 }
       
    43 
       
    44 bool DialpadBluetoothEventFilter::eventFilter(QObject *watched, QEvent *event)
       
    45 {
       
    46     Q_UNUSED(watched)
       
    47             
       
    48     if (event->type() == QEvent::KeyPress) {
       
    49         QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
       
    50         if (keyEvent->key() == Qt::Key_Asterisk && 
       
    51             !(mDialpad->editor().text().length() >= 1)) {
       
    52             //Check that there is only one item in dialpad, if there is more than one
       
    53             //do not handle long key press.
       
    54             mLongPressTimer->stop();
       
    55             mLongPressTimer->start(DialpadLongKeyPressTimeOut);
       
    56         }
       
    57     } else if (event->type() == QEvent::KeyRelease) {
       
    58             mLongPressTimer->stop();
       
    59     }
       
    60 
       
    61     // Don't consume the key
       
    62     return false;
       
    63 }
       
    64 
       
    65 void DialpadBluetoothEventFilter::toggleBluetooth()
       
    66 {
       
    67     PHONE_TRACE;
       
    68     mDialpad->editor().setText(QString(""));
       
    69 #ifdef Q_OS_SYMBIAN
       
    70     XQServiceRequest snd("com.nokia.services.btservices.ToggleBluetooth","toggleBluetooth()", false);
       
    71     QVariant retValue;
       
    72     snd.send(retValue);
       
    73 #endif // Q_OS_SYMBIAN
       
    74 }