qtmobileextensions/src/keycapture/targetwrapper.cpp
changeset 26 3d09643def13
parent 19 46686fb6258c
child 27 6bfad47013df
equal deleted inserted replaced
24:9d760f716ca8 26:3d09643def13
    46     initMapping();
    46     initMapping();
    47 }
    47 }
    48 
    48 
    49 TargetWrapper::~TargetWrapper()
    49 TargetWrapper::~TargetWrapper()
    50 {
    50 {
    51     delete selector;
    51     cleanup();
    52 }
    52 }
    53 
    53 
    54 void TargetWrapper::close(XQKeyCapture::CapturingFlags flags)
    54 void TargetWrapper::close(XQKeyCapture::CapturingFlags flags)
    55 {
    55 {
    56     captureFlags &= ~flags;
    56     captureFlags &= ~flags;
    64 }
    64 }
    65 
    65 
    66 void TargetWrapper::reset()
    66 void TargetWrapper::reset()
    67 {
    67 {
    68     try {
    68     try {
    69         delete selector;
    69         cleanup();
    70     
    70     
    71         QT_TRAP_THROWING(selector = CRemConInterfaceSelector::NewL());
    71         QT_TRAP_THROWING(selector = CRemConInterfaceSelector::NewL());
    72         
    72         
    73         if (captureFlags & XQKeyCapture::CaptureBasic) {
    73         if (captureFlags & XQKeyCapture::CaptureBasic) {
    74             QT_TRAP_THROWING(target = CRemConCoreApiTarget::NewL(*selector, *this));
    74             QT_TRAP_THROWING(target = CRemConCoreApiTarget::NewL(*selector, *this));
    85     } catch (const std::exception &e) {
    85     } catch (const std::exception &e) {
    86         delete selector;
    86         delete selector;
    87         selector = 0;
    87         selector = 0;
    88         target = 0;
    88         target = 0;
    89         targetEx = 0;
    89         targetEx = 0;
       
    90         delete handler;
    90         handler = 0;
    91         handler = 0;
       
    92         delete handlerEx;
    91         handlerEx = 0;
    93         handlerEx = 0;
    92         qDebug() << "TargetWrapper::init - exception: " << e.what();
    94         qDebug() << "TargetWrapper::init - exception: " << e.what();
    93         throw;
    95         throw;
    94     }    
    96     }    
    95 }
    97 }
   104         return Qt::Key_unknown;
   106         return Qt::Key_unknown;
   105     }
   107     }
   106     
   108     
   107 }
   109 }
   108 
   110 
       
   111 /*
       
   112  * Function for cleaning up selector and handlers, targets are handled via selector
       
   113  */
       
   114 void TargetWrapper::cleanup()
       
   115 {
       
   116     delete handler;
       
   117     handler = 0;
       
   118     delete handlerEx;
       
   119     handlerEx = 0;
       
   120     delete selector;
       
   121     selector = 0;
       
   122 }
       
   123 
   109 void TargetWrapper::MrccatoCommand(TRemConCoreApiOperationId aOperationId, TRemConCoreApiButtonAction aButtonAct)
   124 void TargetWrapper::MrccatoCommand(TRemConCoreApiOperationId aOperationId, TRemConCoreApiButtonAction aButtonAct)
   110 {
   125 {
   111     Qt::Key key = mapKey(aOperationId); 
   126     if (target) {
   112 
   127         Qt::Key key = mapKey(aOperationId); 
   113     switch (aButtonAct) {
   128         switch (aButtonAct) {
   114         case ERemConCoreApiButtonPress:
   129             case ERemConCoreApiButtonPress:
   115             TX_LOG_ARGS("ERemConCoreApiButtonPress");
   130                 TX_LOG_ARGS("ERemConCoreApiButtonPress");
   116             sendKey(QEvent::KeyPress, key, Qt::NoModifier, aOperationId);
   131                 sendKey(QEvent::KeyPress, key, Qt::NoModifier, aOperationId);
   117             break;
   132                 break;
   118         case ERemConCoreApiButtonRelease:
   133             case ERemConCoreApiButtonRelease:
   119             TX_LOG_ARGS("ERemConCoreApiButtonRelease");
   134                 TX_LOG_ARGS("ERemConCoreApiButtonRelease");
   120             sendKey(QEvent::KeyRelease, key, Qt::NoModifier, aOperationId);
   135                 sendKey(QEvent::KeyRelease, key, Qt::NoModifier, aOperationId);
   121             break;
   136                 break;
   122         case ERemConCoreApiButtonClick:
   137             case ERemConCoreApiButtonClick:
   123             TX_LOG_ARGS("ERemConCoreApiButtonClick");
   138                 TX_LOG_ARGS("ERemConCoreApiButtonClick");
   124             sendKey(QEvent::KeyPress, key, Qt::NoModifier, aOperationId);
   139                 sendKey(QEvent::KeyPress, key, Qt::NoModifier, aOperationId);
   125             sendKey(QEvent::KeyRelease, key, Qt::NoModifier, aOperationId);
   140                 sendKey(QEvent::KeyRelease, key, Qt::NoModifier, aOperationId);
   126             break;
   141                 break;
   127         default:
   142             default:
   128             return;
   143                 return;
   129     }
   144         }
   130 
   145     } else {
   131     handler->CompleteAnyKey(aOperationId);
   146         qWarning() << "target in MrccatoCommand was not initialized";
       
   147     }
       
   148     
       
   149     if (handler) {
       
   150         handler->CompleteAnyKey(aOperationId);
       
   151     } else {
       
   152         qWarning() << "handler in MrccatoCommand was not initialized";
       
   153     }
   132 }
   154 }
   133 
   155 
   134 void TargetWrapper::AnswerCall()
   156 void TargetWrapper::AnswerCall()
   135 {
   157 {
   136     sendKey(QEvent::KeyPress, Qt::Key_Call, Qt::NoModifier);
   158     if (targetEx) {
   137     sendKey(QEvent::KeyRelease, Qt::Key_Call, Qt::NoModifier);
   159         sendKey(QEvent::KeyPress, Qt::Key_Call, Qt::NoModifier);
   138     handlerEx->CompleteAnyKey(0);
   160         sendKey(QEvent::KeyRelease, Qt::Key_Call, Qt::NoModifier);
       
   161     } else {
       
   162         qWarning() << "targetEx in AnswerCall was not initialized";
       
   163     }
       
   164     if (handlerEx) { 
       
   165         handlerEx->CompleteAnyKey(0);
       
   166     } else {
       
   167         qWarning() << "handlerEx in AnswerCall was not initialized";
       
   168     }
   139 }
   169 }
   140 
   170 
   141 void TargetWrapper::EndCall()
   171 void TargetWrapper::EndCall()
   142 {
   172 {
   143     sendKey(QEvent::KeyPress, Qt::Key_Hangup, Qt::NoModifier);
   173     if (targetEx) {
   144     sendKey(QEvent::KeyRelease, Qt::Key_Hangup, Qt::NoModifier);
   174         sendKey(QEvent::KeyPress, Qt::Key_Hangup, Qt::NoModifier);
   145     handlerEx->CompleteAnyKey(0);
   175         sendKey(QEvent::KeyRelease, Qt::Key_Hangup, Qt::NoModifier);
       
   176     } else {
       
   177         qWarning() << "targetEx in EndCall was not initialized";
       
   178     }
       
   179     if (handlerEx) {
       
   180         handlerEx->CompleteAnyKey(0);
       
   181     } else {
       
   182         qWarning() << "handlerEx in EndCall was not initialized";
       
   183     }
   146 }
   184 }
   147 
   185 
   148 void TargetWrapper::AnswerEndCall()
   186 void TargetWrapper::AnswerEndCall()
   149 {
   187 {
   150     sendKey(QEvent::KeyPress, Qt::Key_Hangup, Qt::NoModifier);  //TODO: Qt::Key_ToggleCallHangup
   188     if (targetEx) {
   151     sendKey(QEvent::KeyRelease, Qt::Key_Hangup, Qt::NoModifier); 
   189         sendKey(QEvent::KeyPress, Qt::Key_Hangup, Qt::NoModifier);  //TODO: Qt::Key_ToggleCallHangup
   152     handlerEx->CompleteAnyKey(0);
   190         sendKey(QEvent::KeyRelease, Qt::Key_Hangup, Qt::NoModifier); 
       
   191     } else {
       
   192         qWarning() << "targetEx in AnswerEndCall was not initialized";
       
   193     }    
       
   194     if (handlerEx) {
       
   195         handlerEx->CompleteAnyKey(0);
       
   196     } else {
       
   197         qWarning() << "handlerEx in AnswerEndCall was not initialized";
       
   198     }
   153 }
   199 }
   154 
   200 
   155 void TargetWrapper::VoiceDial( const TBool aActivate )
   201 void TargetWrapper::VoiceDial( const TBool aActivate )
   156 {
   202 {
   157     Q_UNUSED(aActivate)
   203     Q_UNUSED(aActivate)
   199             event = new QKeyEvent(eventType, key, modFlags);
   245             event = new QKeyEvent(eventType, key, modFlags);
   200         }
   246         }
   201         
   247         
   202         if (event){
   248         if (event){
   203             QApplication::sendEvent(widget, event);
   249             QApplication::sendEvent(widget, event);
   204             qDebug("sending key event!");
       
   205             delete event;
   250             delete event;
   206         }
   251         }
   207     }
   252     }
   208 }
   253 }
   209 
   254 
   210 QWidget *TargetWrapper::getTargetWidget()
   255 QWidget *TargetWrapper::getTargetWidget()
   211 {
   256 {
   212     QWidget *widget;
   257     QWidget *widget;
   213     widget = QWidget::keyboardGrabber();
   258     widget = QWidget::keyboardGrabber();
   214     
       
   215     if (!widget) {
   259     if (!widget) {
   216         widget = QApplication::focusWidget();
   260         widget = QApplication::focusWidget();
   217     }
   261     }
   218     
       
   219     if (!widget) {
   262     if (!widget) {
   220         if (QApplication::activePopupWidget()) {
   263         if (QApplication::activePopupWidget()) {
   221             widget = QApplication::activePopupWidget()->focusWidget();
   264             widget = QApplication::activePopupWidget()->focusWidget();
   222             if (!widget) {
   265             if (!widget) {
   223                 widget = QApplication::activePopupWidget();
   266                 widget = QApplication::activePopupWidget();
   224             }
   267             }
   225         }
   268         }
   226     }
   269     }
   227 
       
   228     return widget;
   270     return widget;
   229 }
   271 }
   230 
   272 
   231 
   273 
   232 
   274