camerauis/cameraxui/cxui/src/cxuiserviceprovider.cpp
branchRCL_3
changeset 24 bac7acad7cb3
parent 23 61bc0f252b2b
child 25 2c87b2808fd7
equal deleted inserted replaced
23:61bc0f252b2b 24:bac7acad7cb3
     1 /*
       
     2  * Copyright (c) 2009-2010 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:
       
    15  *
       
    16  */
       
    17 
       
    18 #include <QApplication>
       
    19 
       
    20 #include "cxutils.h"
       
    21 #include "cxeengine.h"
       
    22 #include "cxecameradevicecontrol.h"
       
    23 #include "cxestillcapturecontrol.h"
       
    24 #include "cxevideocapturecontrol.h"
       
    25 
       
    26 #include "cxuiserviceprovider.h"
       
    27 #include "cxesettings.h"
       
    28 
       
    29 #include <xqaiwdecl.h>
       
    30 
       
    31 CxuiServiceProvider* CxuiServiceProvider::mInstance = NULL;
       
    32 
       
    33 CxuiServiceProvider::CxuiServiceProvider(CxeEngine *engine)
       
    34 :
       
    35     XQServiceProvider("cxui." + XQI_CAMERA_CAPTURE),
       
    36     mRequestIndex(-1),
       
    37     mEngine(engine),
       
    38     mRequestedMode(Cxe::ImageMode),
       
    39     mCameraIndex(0),
       
    40     mQuality(0),
       
    41     mAllowModeSwitching(true),
       
    42     mAllowQualityChange(true),
       
    43     mAllowCameraSwitching(true)
       
    44 {
       
    45     CX_DEBUG_ENTER_FUNCTION();
       
    46     publishAll();
       
    47     CX_DEBUG_EXIT_FUNCTION();
       
    48 }
       
    49 
       
    50 CxuiServiceProvider::~CxuiServiceProvider()
       
    51 {
       
    52     CX_DEBUG_ENTER_FUNCTION();
       
    53     if (mRequestIndex != -1) {
       
    54         CX_DEBUG(("Request still active..."));
       
    55         // Complete request now, this will return error to client
       
    56         completeRequest(mRequestIndex, QString());
       
    57     }
       
    58     CX_DEBUG_EXIT_FUNCTION();
       
    59 }
       
    60 
       
    61 /*!
       
    62  * Creates singleton instance of service provider.
       
    63  */
       
    64 void CxuiServiceProvider::create(CxeEngine* engine)
       
    65 {
       
    66     if (mInstance == NULL) {
       
    67         mInstance = new CxuiServiceProvider(engine);
       
    68     }
       
    69 }
       
    70 
       
    71 /*!
       
    72  * Returns singleton instance of service provider.
       
    73  *
       
    74  */
       
    75 CxuiServiceProvider* CxuiServiceProvider::instance()
       
    76 {
       
    77     return mInstance;
       
    78 }
       
    79 
       
    80 /*!
       
    81  * Deletes singleton instance of service provider.
       
    82  */
       
    83 void CxuiServiceProvider::destroy()
       
    84 {
       
    85     delete mInstance;
       
    86     mInstance = NULL;
       
    87 }
       
    88 
       
    89 /*!
       
    90  * Returns true if camera is started by another application.
       
    91  *
       
    92  * "Embedded" in camera means that the camera is started as a service
       
    93  * by another application using QtHighway. It doesn't necessarily
       
    94  * mean that camera is actually embedded (=window groups chained). The
       
    95  * distinction between embedded and non-embedded service is not relevant on
       
    96  * camera side, it's more meaningful to the client app.
       
    97  *
       
    98  */
       
    99 bool CxuiServiceProvider::isCameraEmbedded()
       
   100 {
       
   101     return mInstance != NULL;
       
   102 }
       
   103 
       
   104 /*!
       
   105  *
       
   106  */
       
   107 Cxe::CameraMode CxuiServiceProvider::requestedMode()
       
   108 {
       
   109     return mRequestedMode;
       
   110 }
       
   111 
       
   112 /*!
       
   113  *
       
   114  */
       
   115 bool CxuiServiceProvider::allowModeSwitching()
       
   116 {
       
   117     return mAllowModeSwitching;
       
   118 }
       
   119 
       
   120 /*!
       
   121  *
       
   122  */
       
   123 bool CxuiServiceProvider::allowQualityChange()
       
   124 {
       
   125     return mAllowQualityChange;
       
   126 }
       
   127 
       
   128 /*!
       
   129  *
       
   130  */
       
   131 bool CxuiServiceProvider::allowCameraSwitching()
       
   132 {
       
   133     return mAllowCameraSwitching;
       
   134 }
       
   135 
       
   136 /*!
       
   137  *
       
   138  */
       
   139 void CxuiServiceProvider::sendFilenameToClientAndExit(QString filename)
       
   140 {
       
   141     CX_DEBUG_ENTER_FUNCTION();
       
   142 
       
   143     if (mRequestIndex == -1) {
       
   144         CX_DEBUG(("CxuiServiceProvider: no request in progress"));
       
   145         QCoreApplication::instance()->quit();
       
   146         CX_DEBUG_EXIT_FUNCTION();
       
   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)
       
   164 {
       
   165     CX_DEBUG_ENTER_FUNCTION();
       
   166 
       
   167     if (mRequestIndex != -1) {
       
   168         // only one request can be active at once
       
   169         CX_DEBUG(("Request already active, ignoring"));
       
   170         CX_DEBUG_EXIT_FUNCTION();
       
   171         return;
       
   172     }
       
   173 
       
   174     // read options from map
       
   175     if (!readParameters(parameters)) {
       
   176         CX_DEBUG_EXIT_FUNCTION();
       
   177         return;
       
   178     }
       
   179 
       
   180     if (mCameraIndex < 0 || mCameraIndex > 1) {
       
   181         CX_DEBUG(("Invalid camera index"));
       
   182         CX_DEBUG_EXIT_FUNCTION();
       
   183         return;
       
   184     }
       
   185 
       
   186     mRequestIndex = setCurrentRequestAsync();
       
   187 
       
   188     mEngine->cameraDeviceControl().switchCamera(static_cast<Cxe::CameraIndex> (mCameraIndex));
       
   189 
       
   190 
       
   191     if (mode == 0) {
       
   192         CX_DEBUG(("Image capture requested"));
       
   193         mRequestedMode = Cxe::ImageMode;
       
   194     }
       
   195     else {
       
   196         CX_DEBUG(("Video capture requested"));
       
   197         mRequestedMode = Cxe::VideoMode;
       
   198     }
       
   199 
       
   200     if (mQuality == 1) {
       
   201         // set image quality to lowest
       
   202         int imageQualityIndex = mEngine->stillCaptureControl().supportedImageQualities().size() - 1;
       
   203         CX_DEBUG(("Setting image quality to lowest, index=%d", imageQualityIndex));
       
   204         mEngine->settings().set(CxeSettingIds::IMAGE_QUALITY, imageQualityIndex);
       
   205 
       
   206         // set video quality to lowest
       
   207         int videoQualityIndex = mEngine->videoCaptureControl().supportedVideoQualities().size() - 1;
       
   208         CX_DEBUG(("Setting video quality to lowest, index=%d", videoQualityIndex));
       
   209         mEngine->settings().set(CxeSettingIds::VIDEO_QUALITY, videoQualityIndex);
       
   210     } else if (mQuality == 2) {
       
   211         // set image quality to highest
       
   212         CX_DEBUG(("Setting image quality to highest, index=0"));
       
   213         mEngine->settings().set(CxeSettingIds::IMAGE_QUALITY, 0);
       
   214 
       
   215         // set video quality to highest
       
   216         CX_DEBUG(("Setting video quality to highest, index=0"));
       
   217         mEngine->settings().set(CxeSettingIds::VIDEO_QUALITY, 0);
       
   218     }
       
   219 
       
   220     mEngine->initMode(mRequestedMode);
       
   221 
       
   222 
       
   223 
       
   224     CX_DEBUG_EXIT_FUNCTION();
       
   225 }
       
   226 
       
   227 bool CxuiServiceProvider::readParameters(const QVariantMap& parameters)
       
   228 {
       
   229 
       
   230     CX_DEBUG_ENTER_FUNCTION();
       
   231     CX_DEBUG(("Reading parameters"));
       
   232     bool ok;
       
   233     mCameraIndex = parameters[XQCAMERA_INDEX].toInt(&ok);
       
   234     if (!ok) {
       
   235         CX_DEBUG(("Error reading parameter %s", XQCAMERA_INDEX.latin1()));
       
   236         CX_DEBUG_EXIT_FUNCTION();
       
   237         return false;
       
   238     }
       
   239     mQuality = parameters[XQCAMERA_QUALITY].toInt(&ok);
       
   240     if (!ok) {
       
   241         CX_DEBUG(("Error reading parameter %s", XQCAMERA_QUALITY.latin1()));
       
   242         CX_DEBUG_EXIT_FUNCTION();
       
   243         return false;
       
   244     }
       
   245 
       
   246     // ignore possible errors on these parameters. default values will be false
       
   247     mAllowModeSwitching = parameters[XQCAMERA_MODE_SWITCH].toBool();
       
   248     mAllowQualityChange = parameters[XQCAMERA_QUALITY_CHANGE].toBool();
       
   249     mAllowCameraSwitching = parameters[XQCAMERA_INDEX_SWITCH].toBool();
       
   250 
       
   251     CX_DEBUG_EXIT_FUNCTION();
       
   252     return true;
       
   253 }
       
   254