telutils/dialpad/src/dialpadinternaleventfilter.cpp
changeset 48 78df25012fda
equal deleted inserted replaced
46:2fa1fa551b0b 48:78df25012fda
       
     1 /*!
       
     2 * Copyright (c) 2009 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: Dialpad keypad
       
    15 *
       
    16 */
       
    17 #include "dialpadinternaleventfilter.h"
       
    18 #include "qtphonesrvlog.h"
       
    19 
       
    20 #include <hbdevicenotificationdialog.h>
       
    21 #include <QDebug>
       
    22 #include <QKeyEvent>
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <APGTASK.H>
       
    26 #include <coemain.h>
       
    27 #include <apgcli.h>
       
    28 #include <apacmdln.h>
       
    29 
       
    30 const int DialpadLongKeyPressTimeOut(1000);
       
    31 
       
    32 DialpadInternalEventFilter::DialpadInternalEventFilter() :
       
    33     QObject(),
       
    34     mKey(0)
       
    35 {
       
    36     PHONE_TRACE;
       
    37     mLongPressTimer = new QTimer(this);
       
    38     mLongPressTimer->setSingleShot(true);
       
    39     connect(mLongPressTimer,SIGNAL(timeout()), this, SLOT(togglePhoneUi()));
       
    40 }
       
    41 
       
    42 DialpadInternalEventFilter::~DialpadInternalEventFilter()
       
    43 {
       
    44 }
       
    45 
       
    46 bool DialpadInternalEventFilter::eventFilter(QObject *watched, QEvent *event)
       
    47 {
       
    48     Q_UNUSED(watched)
       
    49             
       
    50     if (event->type() == QEvent::KeyPress) {
       
    51         QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
       
    52         if (keyEvent->key() == Qt::Key_8 ||  keyEvent->key() == Qt::Key_9) {
       
    53             mKey = keyEvent->key();
       
    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 DialpadInternalEventFilter::togglePhoneUi()
       
    66 {
       
    67     if(mKey == Qt::Key_8) {
       
    68         start();
       
    69     }
       
    70     if(mKey == Qt::Key_9) {
       
    71         shutdown();
       
    72     } 
       
    73 }
       
    74 
       
    75 void DialpadInternalEventFilter::shutdown()
       
    76 {
       
    77     HbDeviceNotificationDialog notificationDialog;
       
    78     QString text = "Shutting down phoneui.exe";
       
    79     notificationDialog.setText(text);
       
    80     notificationDialog.show();
       
    81 
       
    82     
       
    83     qDebug() << "Shutting down phoneui.exe";
       
    84     
       
    85     const TUid KPhoneAppUid = {0x100058B3};
       
    86     TApaTaskList taskList(CCoeEnv::Static()->WsSession());
       
    87     TApaTask task = taskList.FindApp(KPhoneAppUid);
       
    88     
       
    89     if (task.Exists()){
       
    90         task.EndTask(); // Ends the task
       
    91     }    
       
    92 }
       
    93 
       
    94 void DialpadInternalEventFilter::start()
       
    95 {
       
    96 
       
    97     HbDeviceNotificationDialog notificationDialog;
       
    98     QString text = "Starting phoneui.exe";
       
    99     notificationDialog.setText(text);
       
   100     notificationDialog.show();
       
   101     
       
   102     TThreadId app_threadid;
       
   103     CApaCommandLine* cmdLine; 
       
   104     cmdLine=CApaCommandLine::NewLC();
       
   105     cmdLine->SetExecutableNameL(_L("phoneui.exe"));
       
   106     cmdLine->SetCommandL( EApaCommandRun );
       
   107     RApaLsSession ls;
       
   108     User::LeaveIfError(ls.Connect());
       
   109     TInt err=ls.StartApp(*cmdLine,app_threadid);
       
   110     ls.Close();
       
   111     CleanupStack::PopAndDestroy(); // cmdLine
       
   112 }