camerauis/cameraxui/cxui/src/cxuisettingsinfo.cpp
branchRCL_3
changeset 53 61bc0f252b2b
equal deleted inserted replaced
50:f54ad444594d 53:61bc0f252b2b
       
     1 /*
       
     2 * Copyright (c) 2009 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 <QSize>
       
    19 #include <QMetaType>
       
    20 #include <QVariant>
       
    21 #include <hbparameterlengthlimiter.h>
       
    22 
       
    23 #include "cxutils.h"
       
    24 #include "cxuienums.h"
       
    25 #include "cxeengine.h"
       
    26 #include "cxesettings.h"
       
    27 #include "cxenamespace.h"
       
    28 #include "cxuisettingsinfo.h"
       
    29 #include "cxequalitydetails.h"
       
    30 #include "cxestillcapturecontrol.h"
       
    31 #include "cxevideocapturecontrol.h"
       
    32 #include "cxecameradevicecontrol.h"
       
    33 #include "cxuisettingradiobuttonlist.h"
       
    34 #include "cxuisettingxmlreader.h"
       
    35 
       
    36 using namespace Cxe;
       
    37 using namespace CxUiSettings;
       
    38 
       
    39 namespace
       
    40 {
       
    41     const QSize KResVGA = QSize(640, 480);
       
    42     const QSize KResHD = QSize(1280, 720);
       
    43     const QSize KResWideVGA = QSize(864, 480);
       
    44     const QSize KResSharing = QSize(176,144);
       
    45 }
       
    46 
       
    47 RadioButtonListParams& RadioButtonListParams::operator=(const RadioButtonListParams& other)
       
    48 {
       
    49     CX_DEBUG_ENTER_FUNCTION();
       
    50     // Protect against self-assignment
       
    51     if (this != &other)
       
    52         {
       
    53         mHeading = other.mHeading;
       
    54         mSettingId = other.mSettingId;
       
    55         mHeadingIcon = other.mHeadingIcon;
       
    56         mSettingPairList = other.mSettingPairList;
       
    57         mPreview = other.mPreview;
       
    58         mListboxType = other.mListboxType;
       
    59         }
       
    60     CX_DEBUG_EXIT_FUNCTION();
       
    61     return *this;
       
    62 }
       
    63 
       
    64 SliderParams& SliderParams::operator=(const SliderParams& other)
       
    65 {
       
    66     CX_DEBUG_ENTER_FUNCTION();
       
    67     // Protect against self-assignment
       
    68     if (this != &other)
       
    69         {
       
    70         mHeading = other.mHeading;
       
    71         mSettingId = other.mSettingId;
       
    72         mHeadingIcon = other.mHeadingIcon;
       
    73         mSettingStrings = other.mSettingStrings;
       
    74         mRange = other.mRange;
       
    75         mMinorStep = other.mMinorStep;
       
    76         mMajorStep = other.mMajorStep;
       
    77         }
       
    78     CX_DEBUG_EXIT_FUNCTION();
       
    79     return *this;
       
    80 }
       
    81 
       
    82 
       
    83 /*!
       
    84 * CxuiSettingsInfo::CxuiSettingsInfo
       
    85 */
       
    86 CxuiSettingsInfo::CxuiSettingsInfo(CxeEngine *engine)
       
    87     : mMode(-1), mEngine(engine)
       
    88 {
       
    89     CX_DEBUG_ENTER_FUNCTION();
       
    90     CX_ASSERT_ALWAYS(engine);
       
    91 
       
    92     mXmlReader = new CxuiSettingXmlReader();
       
    93     CX_DEBUG_EXIT_FUNCTION();
       
    94 }
       
    95 
       
    96 /*!
       
    97 * CxuiSettingsInfo::~CxuiSettingsInfo
       
    98 */
       
    99 CxuiSettingsInfo::~CxuiSettingsInfo()
       
   100 {
       
   101     CX_DEBUG_ENTER_FUNCTION();
       
   102 
       
   103     delete mXmlReader;
       
   104 
       
   105     CX_DEBUG_EXIT_FUNCTION();
       
   106 }
       
   107 
       
   108 
       
   109 /*!
       
   110 * Fetches the settings content for radio button list
       
   111 * @param key specifies the settings key
       
   112 * @param settings on return contains all the data required for radiobutton list
       
   113 * @return Was the setting supported or not
       
   114 */
       
   115 bool CxuiSettingsInfo::getSettingsContent(const QString &key,
       
   116                                           RadioButtonListParams &settings)
       
   117 {
       
   118     CX_DEBUG_ENTER_FUNCTION();
       
   119 
       
   120     // Check that right content is loaded. Load now if not.
       
   121     checkMode();
       
   122 
       
   123     bool found(false);
       
   124 
       
   125     if (key == CxeSettingIds::IMAGE_QUALITY ||
       
   126         key == CxeSettingIds::VIDEO_QUALITY) {
       
   127         handleQualitySettings(key, settings);
       
   128         found = true;
       
   129     } else {
       
   130         // load settings from xml loader
       
   131         if (mXmlReader) {
       
   132             settings = mXmlReader->getListSettingInfo(key, found);
       
   133         }
       
   134     }
       
   135 
       
   136     CX_DEBUG_EXIT_FUNCTION();
       
   137     return found;
       
   138 }
       
   139 
       
   140 
       
   141 
       
   142 /*!
       
   143 * Fetches the settings content for slider
       
   144 * @Param key specifies the settings key
       
   145 * @param settings on return contains all the data required for slider
       
   146 */
       
   147 bool CxuiSettingsInfo::getSettingsContent(const QString &key,
       
   148                                           SliderParams &settings)
       
   149 {
       
   150     CX_DEBUG_ENTER_FUNCTION();
       
   151 
       
   152     // Check that right content is loaded. Load now if not.
       
   153     checkMode();
       
   154 
       
   155     bool found(false);
       
   156 
       
   157     if (mXmlReader) {
       
   158         settings = mXmlReader->getSliderSettingInfo(key, found);
       
   159     }
       
   160 
       
   161     CX_DEBUG_EXIT_FUNCTION();
       
   162     return found;
       
   163 }
       
   164 
       
   165 
       
   166 
       
   167 
       
   168 
       
   169 /*!
       
   170 * Helper function to prepare image/video quality settings list
       
   171 */
       
   172 void CxuiSettingsInfo::handleQualitySettings(const QString &key,
       
   173                                              CxUiSettings::RadioButtonListParams &settings)
       
   174 {
       
   175     CX_DEBUG_ENTER_FUNCTION();
       
   176 
       
   177     settings.mSettingId = key;
       
   178     settings.mPreview = false;
       
   179     settings.mListboxType = CxuiSettingRadioButtonList::TwoLine;
       
   180 
       
   181     if (key == CxeSettingIds::IMAGE_QUALITY) {
       
   182         settings.mHeading = hbTrId("txt_cam_title_image_quality");
       
   183         getImageQualitySettings(settings);
       
   184     } else {
       
   185         settings.mHeading = hbTrId("txt_cam_title_video_quality");
       
   186         getVideoQualitySettings(settings);
       
   187     }
       
   188 
       
   189     CX_DEBUG_EXIT_FUNCTION();
       
   190 
       
   191 }
       
   192 
       
   193 
       
   194 
       
   195 /*!
       
   196 * Prepares Image quality settings.
       
   197 */
       
   198 void CxuiSettingsInfo::getImageQualitySettings(RadioButtonListParams &settings)
       
   199 {
       
   200     CX_DEBUG_ENTER_FUNCTION();
       
   201 
       
   202     settings.mSettingPairList.clear();
       
   203 
       
   204     QList<CxeImageDetails> list =
       
   205                 mEngine->stillCaptureControl().supportedImageQualities();
       
   206 
       
   207     int index = 0;
       
   208 
       
   209     // get the localized possible strings for each image quality setting
       
   210     QString vga = "txt_cam_dblist_vga";
       
   211     QString normal = "txt_cam_dblist_ln_mpix";
       
   212     QString imagesLeft = "txt_cam_dblist_hd_720p_val_ln_images_left";
       
   213     QString widescreen = "txt_cam_dblist_ln_mpix_widescreen";
       
   214 
       
   215     foreach(CxeImageDetails quality, list) {
       
   216         // mapping the right value for each quality
       
   217 
       
   218         QString settingString;
       
   219         QString qualityIcon = "";
       
   220         qreal pxCount = quality.mMpxCount.toDouble();
       
   221 
       
   222         if (quality.mWidth == KResVGA.width() && quality.mHeight == KResVGA.height()) {
       
   223             settingString.append(hbTrId(vga.toAscii().constData()));
       
   224             settingString.append(" ");
       
   225         }
       
   226 
       
   227         if (quality.mAspectRatio == Cxe::AspectRatio16to9) {
       
   228              settingString.append(hbTrId(widescreen.toAscii().constData()).arg(pxCount,0,'g',3));
       
   229         } else {
       
   230             settingString.append(hbTrId(normal.toAscii().constData()).arg(pxCount,0,'g',3));
       
   231         }
       
   232 
       
   233         settingString.append(NEW_LINE_CHAR);
       
   234         settingString.append(HbParameterLengthLimiter(imagesLeft.toAscii().constData(), quality.mPossibleImages));
       
   235         CX_DEBUG(( "Image quality setting string: %s", settingString.toAscii().constData()));
       
   236 
       
   237         if (quality.mMpxCount == "12") {
       
   238             qualityIcon = "qtg_mono_12mp";
       
   239         } else if (quality.mMpxCount == "9") {
       
   240             qualityIcon = "qtg_mono_9mp";
       
   241         } else if (quality.mMpxCount == "3") {
       
   242             qualityIcon = "qtg_mono_3mp";
       
   243         } else if (quality.mMpxCount == "1.2") {
       
   244             qualityIcon = "qtg_mono_1_3mp";
       
   245         } else if (quality.mMpxCount == "0.3") {
       
   246             qualityIcon = "qtg_mono_0_3mp";
       
   247         }
       
   248 
       
   249         SettingItem setting;
       
   250         setting.mItem = settingString;
       
   251         setting.mValue = index;
       
   252         setting.mIcon = qualityIcon;
       
   253         settings.mSettingPairList.append(setting);
       
   254 
       
   255         index++;
       
   256     }
       
   257 
       
   258     CX_DEBUG_EXIT_FUNCTION();
       
   259 }
       
   260 
       
   261 
       
   262 
       
   263 /*!
       
   264 * Prepares video quality settings.
       
   265 */
       
   266 void CxuiSettingsInfo::getVideoQualitySettings(RadioButtonListParams &settings)
       
   267 {
       
   268     CX_DEBUG_ENTER_FUNCTION();
       
   269 
       
   270     settings.mSettingPairList.clear();
       
   271 
       
   272     QList<CxeVideoDetails> list =
       
   273                 mEngine->videoCaptureControl().supportedVideoQualities();
       
   274 
       
   275     int index = 0;
       
   276 
       
   277     // get the localized possible strings for each video quality setting
       
   278     QString timeleft = hbTrId("txt_cam_dblist_hd_720p_val_ln_recording_time_left");
       
   279     QString hdString = hbTrId("txt_cam_dblist_hd_720p_169_widescreen");
       
   280     QString vga = hbTrId("txt_cam_dblist_vga_43");
       
   281     QString wideVga = hbTrId("txt_cam_dblist_vga_169_widescreen"); //VGA 16:9 widescreen
       
   282     QString sharing = hbTrId("txt_cam_dblist_qcif_sharing");
       
   283 
       
   284     foreach(CxeVideoDetails quality, list) {
       
   285         // mapping the right value for each quality
       
   286 
       
   287         QString settingString = "";
       
   288         QString time = "";
       
   289         QString qualityIcon = "";
       
   290 
       
   291         if (quality.mWidth == KResHD.width() &&
       
   292             quality.mHeight == KResHD.height()) {
       
   293             settingString.append(hdString);
       
   294             qualityIcon = "qtg_mono_hd";
       
   295         } else if (quality.mWidth == KResVGA.width() &&
       
   296                    quality.mHeight == KResVGA.height()) {
       
   297             settingString.append(vga);
       
   298             qualityIcon = "qtg_mono_vga";
       
   299         } else if (quality.mWidth == KResSharing.width() &&
       
   300                    quality.mHeight == KResSharing.height()){
       
   301             settingString.append(sharing);
       
   302             qualityIcon = "qtg_mono_qcif";
       
   303         } else if (quality.mWidth == KResWideVGA.width() &&
       
   304                   quality.mHeight == KResWideVGA.height()) {
       
   305             settingString.append(wideVga);
       
   306             qualityIcon = "qtg_mono_vga_wide";
       
   307         }
       
   308 
       
   309         settingString.append(NEW_LINE_CHAR);
       
   310         time.sprintf("%02d:%02d", quality.mRemainingTime / 60, quality.mRemainingTime % 60);
       
   311         settingString.append(timeleft.arg(time));
       
   312 
       
   313 
       
   314 
       
   315         CX_DEBUG(( "video quality setting string: %s", settingString.toAscii().constData()));
       
   316         SettingItem setting;
       
   317         setting.mItem = settingString;
       
   318         setting.mValue = index;
       
   319         setting.mIcon = qualityIcon;
       
   320         settings.mSettingPairList.append(setting);
       
   321 
       
   322         index++;
       
   323     }
       
   324 
       
   325     CX_DEBUG_EXIT_FUNCTION();
       
   326 }
       
   327 
       
   328 /*!
       
   329 * Check that the right content for current mode is loaded.
       
   330 *
       
   331 * UI gets "settings changed" / "scene changed" events quite
       
   332 * early when switching mode (image / video). We cannot rely
       
   333 * on CxeCameraDeviceControl::initModeComplete signal since
       
   334 * that would be coming too late. (We would be using setting XML
       
   335 * for the old mode, and setting keys/values/icons would not
       
   336 * be found.) Better check this whenever UI requests for
       
   337 * content for a setting, and reload the XML when needed.
       
   338 * @see CxuiSettingsInfo::getSettingsContent(const QString &, RadioButtonListParams &)
       
   339 * @see CxuiSettingsInfo::getSettingsContent(const QString &, SliderParams &)
       
   340 * @see CxeCameraDeviceControl::initModeComplete(CxeError::Id)
       
   341 */
       
   342 void CxuiSettingsInfo::checkMode()
       
   343 {
       
   344     CX_DEBUG_ENTER_FUNCTION();
       
   345 
       
   346     int oldMode = mMode;
       
   347     mMode = mEngine->cameraDeviceControl().mode();
       
   348     if (mMode != oldMode) {
       
   349         // Select the setting XML file based on mode.
       
   350         QString sourceXml(mEngine->cameraDeviceControl().mode() == Cxe::ImageMode
       
   351                          ? CxUiSettings::IMAGE_SETTING_MAPPING_FILE
       
   352                          : CxUiSettings::VIDEO_SETTING_MAPPING_FILE);
       
   353 
       
   354         mXmlReader->setXmlSource(sourceXml);
       
   355     }
       
   356 
       
   357     CX_DEBUG_EXIT_FUNCTION();
       
   358 }
       
   359 
       
   360 
       
   361 // end of file