qtmobileextensions/src/keycapture/targetwrapper.cpp
changeset 27 6bfad47013df
parent 26 3d09643def13
equal deleted inserted replaced
26:3d09643def13 27:6bfad47013df
    63     reset();
    63     reset();
    64 }
    64 }
    65 
    65 
    66 void TargetWrapper::reset()
    66 void TargetWrapper::reset()
    67 {
    67 {
       
    68     TX_ENTRY
    68     try {
    69     try {
    69         cleanup();
    70         cleanup();
    70     
    71     
    71         QT_TRAP_THROWING(selector = CRemConInterfaceSelector::NewL());
    72         QT_TRAP_THROWING(selector = CRemConInterfaceSelector::NewL());
    72         
    73         
    91         handler = 0;
    92         handler = 0;
    92         delete handlerEx;
    93         delete handlerEx;
    93         handlerEx = 0;
    94         handlerEx = 0;
    94         qDebug() << "TargetWrapper::init - exception: " << e.what();
    95         qDebug() << "TargetWrapper::init - exception: " << e.what();
    95         throw;
    96         throw;
    96     }    
    97     }
       
    98     TX_EXIT
    97 }
    99 }
    98 
   100 
    99 Qt::Key TargetWrapper::mapKey(TRemConCoreApiOperationId aOperationId)
   101 Qt::Key TargetWrapper::mapKey(TRemConCoreApiOperationId aOperationId)
   100 {
   102 {
       
   103     TX_ENTRY
   101     Qt::Key key = keyMapping.value(aOperationId);
   104     Qt::Key key = keyMapping.value(aOperationId);
   102     
   105     
   103     if (key != Qt::Key())
   106     if (key == Qt::Key()) {
   104         return key;
   107         key = Qt::Key_unknown;
   105     else {
   108     }
   106         return Qt::Key_unknown;
   109     TX_EXIT
   107     }
   110     return key;
   108     
       
   109 }
   111 }
   110 
   112 
   111 /*
   113 /*
   112  * Function for cleaning up selector and handlers, targets are handled via selector
   114  * Function for cleaning up selector and handlers, targets are handled via selector
   113  */
   115  */
   114 void TargetWrapper::cleanup()
   116 void TargetWrapper::cleanup()
   115 {
   117 {
       
   118     TX_ENTRY
   116     delete handler;
   119     delete handler;
   117     handler = 0;
   120     handler = 0;
   118     delete handlerEx;
   121     delete handlerEx;
   119     handlerEx = 0;
   122     handlerEx = 0;
   120     delete selector;
   123     delete selector;
   121     selector = 0;
   124     selector = 0;
       
   125     TX_EXIT
   122 }
   126 }
   123 
   127 
   124 void TargetWrapper::MrccatoCommand(TRemConCoreApiOperationId aOperationId, TRemConCoreApiButtonAction aButtonAct)
   128 void TargetWrapper::MrccatoCommand(TRemConCoreApiOperationId aOperationId, TRemConCoreApiButtonAction aButtonAct)
   125 {
   129 {
       
   130     TX_ENTRY
   126     if (target) {
   131     if (target) {
   127         Qt::Key key = mapKey(aOperationId); 
   132         Qt::Key key = mapKey(aOperationId); 
   128         switch (aButtonAct) {
   133         switch (aButtonAct) {
   129             case ERemConCoreApiButtonPress:
   134             case ERemConCoreApiButtonPress:
   130                 TX_LOG_ARGS("ERemConCoreApiButtonPress");
   135                 TX_LOG_ARGS("ERemConCoreApiButtonPress");
   138                 TX_LOG_ARGS("ERemConCoreApiButtonClick");
   143                 TX_LOG_ARGS("ERemConCoreApiButtonClick");
   139                 sendKey(QEvent::KeyPress, key, Qt::NoModifier, aOperationId);
   144                 sendKey(QEvent::KeyPress, key, Qt::NoModifier, aOperationId);
   140                 sendKey(QEvent::KeyRelease, key, Qt::NoModifier, aOperationId);
   145                 sendKey(QEvent::KeyRelease, key, Qt::NoModifier, aOperationId);
   141                 break;
   146                 break;
   142             default:
   147             default:
       
   148                 TX_EXIT
   143                 return;
   149                 return;
   144         }
   150         }
   145     } else {
   151     } else {
   146         qWarning() << "target in MrccatoCommand was not initialized";
   152         qWarning() << "target in MrccatoCommand was not initialized";
   147     }
   153     }
   149     if (handler) {
   155     if (handler) {
   150         handler->CompleteAnyKey(aOperationId);
   156         handler->CompleteAnyKey(aOperationId);
   151     } else {
   157     } else {
   152         qWarning() << "handler in MrccatoCommand was not initialized";
   158         qWarning() << "handler in MrccatoCommand was not initialized";
   153     }
   159     }
       
   160     TX_EXIT
   154 }
   161 }
   155 
   162 
   156 void TargetWrapper::AnswerCall()
   163 void TargetWrapper::AnswerCall()
   157 {
   164 {
       
   165     TX_ENTRY
   158     if (targetEx) {
   166     if (targetEx) {
   159         sendKey(QEvent::KeyPress, Qt::Key_Call, Qt::NoModifier);
   167         sendKey(QEvent::KeyPress, Qt::Key_Call, Qt::NoModifier);
   160         sendKey(QEvent::KeyRelease, Qt::Key_Call, Qt::NoModifier);
   168         sendKey(QEvent::KeyRelease, Qt::Key_Call, Qt::NoModifier);
   161     } else {
   169     } else {
   162         qWarning() << "targetEx in AnswerCall was not initialized";
   170         qWarning() << "targetEx in AnswerCall was not initialized";
   164     if (handlerEx) { 
   172     if (handlerEx) { 
   165         handlerEx->CompleteAnyKey(0);
   173         handlerEx->CompleteAnyKey(0);
   166     } else {
   174     } else {
   167         qWarning() << "handlerEx in AnswerCall was not initialized";
   175         qWarning() << "handlerEx in AnswerCall was not initialized";
   168     }
   176     }
       
   177     TX_EXIT
   169 }
   178 }
   170 
   179 
   171 void TargetWrapper::EndCall()
   180 void TargetWrapper::EndCall()
   172 {
   181 {
       
   182     TX_ENTRY
   173     if (targetEx) {
   183     if (targetEx) {
   174         sendKey(QEvent::KeyPress, Qt::Key_Hangup, Qt::NoModifier);
   184         sendKey(QEvent::KeyPress, Qt::Key_Hangup, Qt::NoModifier);
   175         sendKey(QEvent::KeyRelease, Qt::Key_Hangup, Qt::NoModifier);
   185         sendKey(QEvent::KeyRelease, Qt::Key_Hangup, Qt::NoModifier);
   176     } else {
   186     } else {
   177         qWarning() << "targetEx in EndCall was not initialized";
   187         qWarning() << "targetEx in EndCall was not initialized";
   179     if (handlerEx) {
   189     if (handlerEx) {
   180         handlerEx->CompleteAnyKey(0);
   190         handlerEx->CompleteAnyKey(0);
   181     } else {
   191     } else {
   182         qWarning() << "handlerEx in EndCall was not initialized";
   192         qWarning() << "handlerEx in EndCall was not initialized";
   183     }
   193     }
       
   194     TX_EXIT
   184 }
   195 }
   185 
   196 
   186 void TargetWrapper::AnswerEndCall()
   197 void TargetWrapper::AnswerEndCall()
   187 {
   198 {
       
   199     TX_ENTRY
   188     if (targetEx) {
   200     if (targetEx) {
   189         sendKey(QEvent::KeyPress, Qt::Key_Hangup, Qt::NoModifier);  //TODO: Qt::Key_ToggleCallHangup
   201         sendKey(QEvent::KeyPress, Qt::Key_Hangup, Qt::NoModifier);  //TODO: Qt::Key_ToggleCallHangup
   190         sendKey(QEvent::KeyRelease, Qt::Key_Hangup, Qt::NoModifier); 
   202         sendKey(QEvent::KeyRelease, Qt::Key_Hangup, Qt::NoModifier); 
   191     } else {
   203     } else {
   192         qWarning() << "targetEx in AnswerEndCall was not initialized";
   204         qWarning() << "targetEx in AnswerEndCall was not initialized";
   194     if (handlerEx) {
   206     if (handlerEx) {
   195         handlerEx->CompleteAnyKey(0);
   207         handlerEx->CompleteAnyKey(0);
   196     } else {
   208     } else {
   197         qWarning() << "handlerEx in AnswerEndCall was not initialized";
   209         qWarning() << "handlerEx in AnswerEndCall was not initialized";
   198     }
   210     }
       
   211     TX_EXIT    
   199 }
   212 }
   200 
   213 
   201 void TargetWrapper::VoiceDial( const TBool aActivate )
   214 void TargetWrapper::VoiceDial( const TBool aActivate )
   202 {
   215 {
       
   216     TX_ENTRY
   203     Q_UNUSED(aActivate)
   217     Q_UNUSED(aActivate)
       
   218     TX_EXIT
   204 }
   219 }
   205 
   220 
   206 void TargetWrapper::LastNumberRedial()
   221 void TargetWrapper::LastNumberRedial()
   207 {
   222 {
       
   223     TX_ENTRY
       
   224     TX_EXIT
   208 }
   225 }
   209 
   226 
   210 void TargetWrapper::DialCall( const TDesC8& aTelNumber )
   227 void TargetWrapper::DialCall( const TDesC8& aTelNumber )
   211 {
   228 {
       
   229     TX_ENTRY
   212     Q_UNUSED(aTelNumber)
   230     Q_UNUSED(aTelNumber)
       
   231     TX_EXIT
   213 }
   232 }
   214 
   233 
   215 void TargetWrapper::MultipartyCalling( const TDesC8& aData )
   234 void TargetWrapper::MultipartyCalling( const TDesC8& aData )
   216 {
   235 {
       
   236     TX_ENTRY
   217     Q_UNUSED(aData)
   237     Q_UNUSED(aData)
       
   238     TX_EXIT
   218 }
   239 }
   219 
   240 
   220 void TargetWrapper::GenerateDTMF( const TChar aChar )
   241 void TargetWrapper::GenerateDTMF( const TChar aChar )
   221 {
   242 {
       
   243     TX_ENTRY
   222     Q_UNUSED(aChar)
   244     Q_UNUSED(aChar)
       
   245     TX_EXIT
   223 }
   246 }
   224 
   247 
   225 void TargetWrapper::SpeedDial( const TInt aIndex )    
   248 void TargetWrapper::SpeedDial( const TInt aIndex )    
   226 {
   249 {
       
   250     TX_ENTRY
   227     Q_UNUSED(aIndex)
   251     Q_UNUSED(aIndex)
       
   252     TX_EXIT
   228 }
   253 }
   229 
   254 
   230 void TargetWrapper::sendKey(QEvent::Type eventType, Qt::Key key, Qt::KeyboardModifiers modFlags, 
   255 void TargetWrapper::sendKey(QEvent::Type eventType, Qt::Key key, Qt::KeyboardModifiers modFlags, 
   231                     TRemConCoreApiOperationId aOperationId)
   256                     TRemConCoreApiOperationId aOperationId)
   232 {
   257 {
       
   258     TX_ENTRY
   233     QWidget *widget = getTargetWidget();
   259     QWidget *widget = getTargetWidget();
   234     if (widget) {
   260     if (widget) {
   235         QKeyEvent *event = NULL;
   261         QKeyEvent *event = NULL;
   236         if (captureFlags & XQKeyCapture::CaptureEnableRemoteExtEvents){
   262         if (captureFlags & XQKeyCapture::CaptureEnableRemoteExtEvents){
   237             if (eventType == QEvent::KeyPress){
   263             if (eventType == QEvent::KeyPress){
   243             }
   269             }
   244         } else {
   270         } else {
   245             event = new QKeyEvent(eventType, key, modFlags);
   271             event = new QKeyEvent(eventType, key, modFlags);
   246         }
   272         }
   247         
   273         
   248         if (event){
   274         if (event) {
       
   275             TX_LOG_ARGS("Sending event: " << event->key() << ", " << event->modifiers() << "[" << event->nativeScanCode() << ", " << event->nativeVirtualKey() << ", " << event->nativeModifiers() << "]");
   249             QApplication::sendEvent(widget, event);
   276             QApplication::sendEvent(widget, event);
       
   277             TX_LOG_ARGS("Event sent: " << event->key());
   250             delete event;
   278             delete event;
   251         }
   279         }
   252     }
   280     }
       
   281     TX_EXIT
   253 }
   282 }
   254 
   283 
   255 QWidget *TargetWrapper::getTargetWidget()
   284 QWidget *TargetWrapper::getTargetWidget()
   256 {
   285 {
       
   286     TX_ENTRY
   257     QWidget *widget;
   287     QWidget *widget;
   258     widget = QWidget::keyboardGrabber();
   288     widget = QWidget::keyboardGrabber();
   259     if (!widget) {
   289     if (!widget) {
   260         widget = QApplication::focusWidget();
   290         widget = QApplication::focusWidget();
   261     }
   291     }
   265             if (!widget) {
   295             if (!widget) {
   266                 widget = QApplication::activePopupWidget();
   296                 widget = QApplication::activePopupWidget();
   267             }
   297             }
   268         }
   298         }
   269     }
   299     }
       
   300     TX_EXIT
   270     return widget;
   301     return widget;
   271 }
   302 }
   272 
   303 
   273 
   304 
   274 
   305 
   275 void TargetWrapper::initMapping()
   306 void TargetWrapper::initMapping()
   276 {
   307 {
       
   308     TX_ENTRY
   277     keyMapping.insert(ERemConCoreApiSelect, Qt::Key_Select);
   309     keyMapping.insert(ERemConCoreApiSelect, Qt::Key_Select);
   278     keyMapping.insert(ERemConCoreApiUp, Qt::Key_Up);
   310     keyMapping.insert(ERemConCoreApiUp, Qt::Key_Up);
   279     keyMapping.insert(ERemConCoreApiDown, Qt::Key_Down);
   311     keyMapping.insert(ERemConCoreApiDown, Qt::Key_Down);
   280     keyMapping.insert(ERemConCoreApiLeft, Qt::Key_Left); // Qt::Key_Direction_L
   312     keyMapping.insert(ERemConCoreApiLeft, Qt::Key_Left); // Qt::Key_Direction_L
   281     keyMapping.insert(ERemConCoreApiRight, Qt::Key_Right); // Qt::Key_Direction_R
   313     keyMapping.insert(ERemConCoreApiRight, Qt::Key_Right); // Qt::Key_Direction_R
   335     keyMapping.insert(ERemConCoreApiF2, Qt::Key_F2);
   367     keyMapping.insert(ERemConCoreApiF2, Qt::Key_F2);
   336     keyMapping.insert(ERemConCoreApiF3, Qt::Key_F3);
   368     keyMapping.insert(ERemConCoreApiF3, Qt::Key_F3);
   337     keyMapping.insert(ERemConCoreApiF4, Qt::Key_F4);
   369     keyMapping.insert(ERemConCoreApiF4, Qt::Key_F4);
   338     keyMapping.insert(ERemConCoreApiF5, Qt::Key_F5);
   370     keyMapping.insert(ERemConCoreApiF5, Qt::Key_F5);
   339     keyMapping.insert(ENop, Qt::Key_unknown);
   371     keyMapping.insert(ENop, Qt::Key_unknown);
   340 }
   372     TX_EXIT
       
   373 }