camerauis/cameraxui/cxui/src/cxuiserviceprovider.cpp
changeset 58 ddba9caa7f32
parent 46 c826656d6714
equal deleted inserted replaced
55:0da2a5b56583 58:ddba9caa7f32
    28 
    28 
    29 #include <xqaiwdecl.h>
    29 #include <xqaiwdecl.h>
    30 
    30 
    31 CxuiServiceProvider* CxuiServiceProvider::mInstance = NULL;
    31 CxuiServiceProvider* CxuiServiceProvider::mInstance = NULL;
    32 
    32 
       
    33 /*!
       
    34  * Constructor.
       
    35  */
    33 CxuiServiceProvider::CxuiServiceProvider(CxeEngine *engine)
    36 CxuiServiceProvider::CxuiServiceProvider(CxeEngine *engine)
    34 :
    37 :
    35     XQServiceProvider("cxui." + XQI_CAMERA_CAPTURE),
    38     XQServiceProvider("cxui." + XQI_CAMERA_CAPTURE),
    36     mRequestIndex(-1),
    39     mRequestIndex(-1),
    37     mEngine(engine),
    40     mEngine(engine),
    38     mRequestedMode(Cxe::ImageMode),
    41     mRequestedMode(Cxe::ImageMode),
    39     mCameraIndex(0),
    42     mCameraIndex(0),
    40     mQuality(0),
    43     mQuality(0),
    41     mAllowModeSwitching(true),
    44     mAllowModeSwitching(true),
    42     mAllowQualityChange(true),
    45     mAllowQualityChange(true),
    43     mAllowCameraSwitching(true)
    46     mAllowCameraSwitching(true),
       
    47     mWindowTitle("")
    44 {
    48 {
    45     CX_DEBUG_ENTER_FUNCTION();
    49     CX_DEBUG_ENTER_FUNCTION();
    46     publishAll();
    50     publishAll();
    47     CX_DEBUG_EXIT_FUNCTION();
    51     CX_DEBUG_EXIT_FUNCTION();
    48 }
    52 }
    49 
    53 
       
    54 /*!
       
    55  * Destructor.
       
    56  */
    50 CxuiServiceProvider::~CxuiServiceProvider()
    57 CxuiServiceProvider::~CxuiServiceProvider()
    51 {
    58 {
    52     CX_DEBUG_ENTER_FUNCTION();
    59     CX_DEBUG_ENTER_FUNCTION();
    53     if (mRequestIndex != -1) {
    60     if (mRequestIndex != -1) {
    54         CX_DEBUG(("Request still active..."));
    61         CX_DEBUG(("Request still active..."));
   100 {
   107 {
   101     return mInstance != NULL;
   108     return mInstance != NULL;
   102 }
   109 }
   103 
   110 
   104 /*!
   111 /*!
   105  *
   112  * Returns camera mode requested by client.
   106  */
   113  */
   107 Cxe::CameraMode CxuiServiceProvider::requestedMode()
   114 Cxe::CameraMode CxuiServiceProvider::requestedMode() const
   108 {
   115 {
   109     return mRequestedMode;
   116     return mRequestedMode;
   110 }
   117 }
   111 
   118 
   112 /*!
   119 /*!
   113  *
   120  * Returns boolean to indicate whether client app allows camera mode switching.
   114  */
   121  */
   115 bool CxuiServiceProvider::allowModeSwitching()
   122 bool CxuiServiceProvider::allowModeSwitching() const
   116 {
   123 {
   117     return mAllowModeSwitching;
   124     return mAllowModeSwitching;
   118 }
   125 }
   119 
   126 
   120 /*!
   127 /*!
   121  *
   128  * Returns boolean to indicate whether client app allows image/video quality to be
   122  */
   129  * changed.
   123 bool CxuiServiceProvider::allowQualityChange()
   130  */
       
   131 bool CxuiServiceProvider::allowQualityChange() const
   124 {
   132 {
   125     return mAllowQualityChange;
   133     return mAllowQualityChange;
   126 }
   134 }
   127 
   135 
   128 /*!
   136 /*!
   129  *
   137  * Returns boolean to indicate whether client app allows switching
   130  */
   138  * between primary and secondary camera.
   131 bool CxuiServiceProvider::allowCameraSwitching()
   139  */
       
   140 bool CxuiServiceProvider::allowCameraSwitching() const
   132 {
   141 {
   133     return mAllowCameraSwitching;
   142     return mAllowCameraSwitching;
   134 }
   143 }
   135 
   144 
   136 /*!
   145 /*!
   137  *
   146  * Returns window title provided by client application.
   138  */
   147  */
   139 void CxuiServiceProvider::sendFilenameToClientAndExit(QString filename)
   148 QString CxuiServiceProvider::windowTitle() const
   140 {
   149 {
   141     CX_DEBUG_ENTER_FUNCTION();
   150     return mWindowTitle;
   142 
   151 }
   143     if (mRequestIndex == -1) {
   152 
   144         CX_DEBUG(("CxuiServiceProvider: no request in progress"));
   153 /*!
   145         QCoreApplication::instance()->quit();
   154  * Function that is called when request arrives. Sets up camera to requested state.
   146         CX_DEBUG_EXIT_FUNCTION();
   155  */
   147         return;
       
   148     }
       
   149 
       
   150     connect(this, SIGNAL(returnValueDelivered()), QCoreApplication::instance(), SLOT(quit()));
       
   151 
       
   152     CX_DEBUG(("CxuiServiceProvider: completing request"));
       
   153     if (!completeRequest(mRequestIndex, QVariant(filename))) {
       
   154         // if request completion fails call quit immediately because signal is not coming
       
   155         CX_DEBUG(("completeRequest() failed, quitting now"));
       
   156         QCoreApplication::instance()->quit();
       
   157     }
       
   158     mRequestIndex = -1;
       
   159 
       
   160     CX_DEBUG_EXIT_FUNCTION();
       
   161 }
       
   162 
       
   163 void CxuiServiceProvider::capture(int mode, const QVariantMap &parameters)
   156 void CxuiServiceProvider::capture(int mode, const QVariantMap &parameters)
   164 {
   157 {
   165     CX_DEBUG_ENTER_FUNCTION();
   158     CX_DEBUG_ENTER_FUNCTION();
   166 
   159 
   167     if (mRequestIndex != -1) {
   160     if (mRequestIndex != -1) {
   181         CX_DEBUG(("Invalid camera index"));
   174         CX_DEBUG(("Invalid camera index"));
   182         CX_DEBUG_EXIT_FUNCTION();
   175         CX_DEBUG_EXIT_FUNCTION();
   183         return;
   176         return;
   184     }
   177     }
   185 
   178 
       
   179     CX_DEBUG(("Getting request info"));
       
   180     XQRequestInfo info = requestInfo();
       
   181 
       
   182     QString windowTitle = info.info(XQINFO_KEY_WINDOW_TITLE).toString();
       
   183     if (!windowTitle.isNull() && !windowTitle.isEmpty()) {
       
   184         CX_DEBUG(("Got window title=%s", qPrintable(windowTitle)));
       
   185         mWindowTitle = windowTitle;
       
   186     }
   186     mRequestIndex = setCurrentRequestAsync();
   187     mRequestIndex = setCurrentRequestAsync();
   187 
   188 
   188     mEngine->cameraDeviceControl().switchCamera(static_cast<Cxe::CameraIndex> (mCameraIndex));
   189     mEngine->cameraDeviceControl().switchCamera(static_cast<Cxe::CameraIndex> (mCameraIndex));
   189 
   190 
   190 
   191 
   217         mEngine->settings().set(CxeSettingIds::VIDEO_QUALITY, 0);
   218         mEngine->settings().set(CxeSettingIds::VIDEO_QUALITY, 0);
   218     }
   219     }
   219 
   220 
   220     mEngine->initMode(mRequestedMode);
   221     mEngine->initMode(mRequestedMode);
   221 
   222 
   222 
   223     CX_DEBUG_EXIT_FUNCTION();
   223 
   224 }
   224     CX_DEBUG_EXIT_FUNCTION();
   225 
   225 }
   226 /*!
   226 
   227  * Sends filename of captured image/video to client and exits camera app.
       
   228  */
       
   229 void CxuiServiceProvider::sendFilenameToClientAndExit(QString filename)
       
   230 {
       
   231     CX_DEBUG_ENTER_FUNCTION();
       
   232 
       
   233     if (mRequestIndex == -1) {
       
   234         CX_DEBUG(("CxuiServiceProvider: no request in progress"));
       
   235         QCoreApplication::instance()->quit();
       
   236         CX_DEBUG_EXIT_FUNCTION();
       
   237         return;
       
   238     }
       
   239 
       
   240     connect(this, SIGNAL(returnValueDelivered()), QCoreApplication::instance(), SLOT(quit()));
       
   241 
       
   242     CX_DEBUG(("CxuiServiceProvider: completing request"));
       
   243     if (!completeRequest(mRequestIndex, QVariant(filename))) {
       
   244         // if request completion fails call quit immediately because signal is not coming
       
   245         CX_DEBUG(("completeRequest() failed, quitting now"));
       
   246         QCoreApplication::instance()->quit();
       
   247     }
       
   248     mRequestIndex = -1;
       
   249 
       
   250     CX_DEBUG_EXIT_FUNCTION();
       
   251 }
       
   252 
       
   253 /*!
       
   254  * Helper function to read request parameters.
       
   255  */
   227 bool CxuiServiceProvider::readParameters(const QVariantMap& parameters)
   256 bool CxuiServiceProvider::readParameters(const QVariantMap& parameters)
   228 {
   257 {
   229 
   258 
   230     CX_DEBUG_ENTER_FUNCTION();
   259     CX_DEBUG_ENTER_FUNCTION();
   231     CX_DEBUG(("Reading parameters"));
   260     CX_DEBUG(("Reading parameters"));