qtmobileextensions/src/keycapture/keycapture_s60_p.cpp
branchRCL_3
changeset 10 cd2778e5acfe
parent 9 5d007b20cfd0
child 11 19a54be74e5e
equal deleted inserted replaced
9:5d007b20cfd0 10:cd2778e5acfe
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  *
       
     5  * This program is free software: you can redistribute it and/or modify
       
     6  * it under the terms of the GNU Lesser General Public License as published by
       
     7  * the Free Software Foundation, version 2.1 of the License.
       
     8  * 
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU Lesser General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU Lesser General Public License
       
    15  * along with this program.  If not, 
       
    16  * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17  *
       
    18  * Description:
       
    19  *
       
    20  */
       
    21 
       
    22 #include "keycapture_s60_p.h"
       
    23 #include "capturerequest_s60.h"
       
    24 
       
    25 #include "keymapper.h"
       
    26 
       
    27 #include <w32std.h>
       
    28 #include <coemain.h> 
       
    29 #include <eikenv.h> 
       
    30 
       
    31 #include "targetwrapper.h"
       
    32 #include "txlogger.h"
       
    33 
       
    34 #ifdef _XQKEYCAPTURE_UNITTEST_
       
    35     #include "tsrc\mytestwindowgroup.h"
       
    36 #endif
       
    37 
       
    38 int KeyCapturePrivate::mRemoteEventType_KeyPress = 0;
       
    39 int KeyCapturePrivate::mRemoteEventType_KeyRelease = 0;
       
    40 
       
    41 KeyCapturePrivate::KeyCapturePrivate() :
       
    42     mLastError(KErrNone), mLastErrorString(QString("OK")),
       
    43 #ifndef _XQKEYCAPTURE_UNITTEST_
       
    44         mWindowGroup( CEikonEnv::Static()->RootWin()), 
       
    45 #else
       
    46         mWindowGroup( *MyTestWindowGroup::Instance()),
       
    47 #endif
       
    48         mRequestsList(new QList<CaptureRequest*> ()),
       
    49         mMapper(new QKeyMapper()),
       
    50         tgWrapper(new TargetWrapper())
       
    51 {
       
    52 
       
    53 }
       
    54 
       
    55 KeyCapturePrivate::~KeyCapturePrivate()
       
    56 {
       
    57     if (mRequestsList){
       
    58         qDeleteAll(mRequestsList->begin(), mRequestsList->end());
       
    59         mRequestsList->clear();
       
    60     }
       
    61     delete mRequestsList;
       
    62     delete mMapper;
       
    63     delete tgWrapper;
       
    64 }
       
    65 
       
    66 bool KeyCapturePrivate::doCapture(TUint aKey,
       
    67         Qt::KeyboardModifiers aModifiersMask,
       
    68         Qt::KeyboardModifiers aModifier,
       
    69         CaptureRequest::CaptureRequestType aType,
       
    70         XQKeyCapture::LongFlags aLongType)
       
    71 {
       
    72     int err = mLastError;
       
    73     CaptureRequest *req = new CaptureRequest(aKey, aModifiersMask, aModifier,
       
    74             aType, aLongType, &mWindowGroup);
       
    75     mLastError = req->request();
       
    76     mRequestsList->append(req);
       
    77     if (err != mLastError)
       
    78         regenerateError();
       
    79 
       
    80     return errorId() == KErrNone;
       
    81 }
       
    82 
       
    83 bool KeyCapturePrivate::doCancelCapture(TUint aKey,
       
    84         Qt::KeyboardModifiers aModifiersMask,
       
    85         Qt::KeyboardModifiers aModifier, 
       
    86         CaptureRequest::CaptureRequestType aType,
       
    87         XQKeyCapture::LongFlags aLongType)
       
    88 {
       
    89     int err = mLastError;
       
    90 
       
    91     for (int i(0), size(mRequestsList->count()); i < size; i++) {
       
    92         CaptureRequest *request = mRequestsList->at(i);
       
    93         if (request && request->matches(aKey, aModifiersMask, aModifier, aType,
       
    94                 aLongType)) {
       
    95             mLastError = request->cancel();
       
    96             mRequestsList->removeAt(i);
       
    97             delete request;
       
    98             break;
       
    99         }
       
   100     }
       
   101 
       
   102     if (err != mLastError)
       
   103         regenerateError();
       
   104 
       
   105     return errorId() == KErrNone;
       
   106 }
       
   107 
       
   108 QString KeyCapturePrivate::errorString() const
       
   109 {
       
   110     return mLastErrorString;
       
   111 }
       
   112 
       
   113 int KeyCapturePrivate::errorId() const
       
   114 {
       
   115     return mLastError;
       
   116 }
       
   117 
       
   118 void KeyCapturePrivate::regenerateError()
       
   119 {
       
   120     if (mLastError != KErrNone) {
       
   121         mLastErrorString = QString("ERROR: %1").arg(mLastError);
       
   122     } else {
       
   123         mLastErrorString = QString("OK");
       
   124     }
       
   125 }
       
   126 
       
   127 bool KeyCapturePrivate::initRemote(XQKeyCapture::CapturingFlags flags)
       
   128 {
       
   129     int err;
       
   130     QT_TRYCATCH_ERROR(err, tgWrapper->init(flags));
       
   131     mLastError = err;
       
   132     if (err != mLastError)
       
   133         regenerateError();
       
   134 
       
   135     return errorId() == KErrNone;
       
   136 }
       
   137 
       
   138 bool KeyCapturePrivate::closeRemote(XQKeyCapture::CapturingFlags flags)
       
   139 {
       
   140     int err;
       
   141     QT_TRYCATCH_ERROR(err, tgWrapper->close(flags));
       
   142     mLastError = err;
       
   143     if (err != mLastError)
       
   144         regenerateError();
       
   145 
       
   146     return errorId() == KErrNone;
       
   147 }