camerauis/cameraxui/cxui/src/cxuivideoprecaptureview.cpp
changeset 48 42ba2d16bf40
parent 37 64817133cd1d
child 56 01e205c615b9
--- a/camerauis/cameraxui/cxui/src/cxuivideoprecaptureview.cpp	Tue Jul 06 14:04:02 2010 +0300
+++ b/camerauis/cameraxui/cxui/src/cxuivideoprecaptureview.cpp	Wed Aug 18 09:37:18 2010 +0300
@@ -15,9 +15,10 @@
 *
 */
 
-#include <e32keys.h>
+
 
 #include <QApplication>
+#include <QGraphicsLayout>
 
 #include <hbmainwindow.h>
 #include <hbaction.h>
@@ -45,12 +46,17 @@
 #include "cxuizoomslider.h"
 #include "cxuicapturekeyhandler.h"
 #include "cxuidocumentloader.h"
+#include "cxuiserviceprovider.h"
+
+#ifdef Q_OS_SYMBIAN
 #include "OstTraceDefinitions.h"
+
 #ifdef OST_TRACE_COMPILER_IN_USE
 #include "cxuivideoprecaptureviewTraces.h"
 #endif
-#include "cxuiserviceprovider.h"
 
+#include <e32keys.h>
+#endif  //Q_OS_SYMBIAN
 
 using namespace Cxe;
 using namespace CxUiLayout;
@@ -64,6 +70,7 @@
 
     //!@todo Localization?
     static const char* VIDEO_TIME_FORMAT = "%02d:%02d";
+    const int POSTCAPTURE_ON = -1;
 }
 
 
@@ -72,8 +79,7 @@
     mElapsedTimer(this),
     mTimeElapsed(0),
     mTimeRemaining(0),
-    mElapsedTimeText(NULL),
-    mRemainingTimeText(NULL),
+    mVideoTimeText(NULL),
     mRecordingIcon(NULL),
     mGoToStillAction(NULL),
     mToolbarIdle(NULL),
@@ -95,6 +101,13 @@
     CX_DEBUG_EXIT_FUNCTION();
 }
 
+/*!
+ * Construct-method handles initialisation tasks for this class.
+ * @param mainwindow
+ * @param engine
+ * @param documentLoader
+ * @param keyHandler
+ */
 void CxuiVideoPrecaptureView::construct(HbMainWindow *mainwindow, CxeEngine *engine,
                                         CxuiDocumentLoader *documentLoader,
                                         CxuiCaptureKeyHandler *keyHandler,
@@ -108,15 +121,13 @@
     mVideoCaptureControl = &(engine->videoCaptureControl());
 
     connect(&mElapsedTimer, SIGNAL(timeout()), this, SLOT(updateTimeLabels()));
-    connect(mVideoCaptureControl, SIGNAL(snapshotReady(CxeError::Id, const QImage&, const QString&)),
-            this, SLOT(handleSnapshot(CxeError::Id)));
     connect(mVideoCaptureControl, SIGNAL(stateChanged(CxeVideoCaptureControl::State, CxeError::Id)),
             this, SLOT(handleVideoStateChanged(CxeVideoCaptureControl::State,CxeError::Id)));
-    connect(&(mEngine->settings()), SIGNAL(sceneChanged(CxeScene&)),
-            this, SLOT(handleSceneChanged(CxeScene&)));
     connect(mVideoCaptureControl, SIGNAL(remainingTimeChanged()),
             this, SLOT(updateTimeLabels()));
 
+    mEngine->settings().listenForSetting(CxeSettingIds::VIDEO_SCENE, this, SLOT(handleSceneChanged(const QVariant&)));
+
     mPauseTimer.setSingleShot(true);
     connect(&mPauseTimer, SIGNAL(timeout()), this, SLOT(stop()));
     mPauseTimer.setInterval(CXUI_PAUSE_TIMEOUT);
@@ -133,34 +144,105 @@
 
 }
 
+/*!
+ * Loads widgets that are needed right from the start.
+ */
 void CxuiVideoPrecaptureView::loadDefaultWidgets()
 {
     CX_DEBUG_ENTER_FUNCTION();
-    CX_DEBUG_ASSERT(mDocumentLoader);
+    CX_ASSERT_ALWAYS(mDocumentLoader);
 
     // get pointers to ui components from the layout data
     QGraphicsWidget *widget = NULL;
     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_VIEWFINDER);
     mViewfinder = qobject_cast<HbTransparentWindow *> (widget);
-    CX_DEBUG_ASSERT(mViewfinder);
-
-    widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_QUALITY_ICON);
-    mQualityIcon = qobject_cast<HbLabel *> (widget);
-    CX_DEBUG_ASSERT(mQualityIcon);
+    CX_ASSERT_ALWAYS(mViewfinder);
 
-    widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_INDICATOR_CONTAINER_TOP);
-    mIndicators = qobject_cast<HbWidget *>(widget);
-    CX_DEBUG_ASSERT(mIndicators);
-    // Create background graphics for indicator container
-    createWidgetBackgroundGraphic(mIndicators, TRANSPARENT_BACKGROUND_GRAPHIC);
+    reloadIndicatorWidgets();
 
     CX_DEBUG_EXIT_FUNCTION();
 }
 
+/*!
+ * Loads default indicators from docml and modifies the visibility
+ * according to current settings.
+ */
+void CxuiVideoPrecaptureView::reloadIndicatorWidgets()
+{
+    CX_DEBUG_ENTER_FUNCTION();
+    CX_ASSERT_ALWAYS(mDocumentLoader);
+
+    bool ok = false;
+    mDocumentLoader->load(VIDEO_1ST_XML, VIDEO_PRE_CAPTURE_INDICATORS_SECTION, &ok);
+    CX_ASSERT_ALWAYS(ok);
+
+    QGraphicsWidget *widget = NULL;
+    widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_QUALITY_ICON);
+    mQualityIcon = qobject_cast<HbLabel *> (widget);
+    CX_ASSERT_ALWAYS(mQualityIcon);
+
+    widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_VIDEOAUDIOMUTE_INDICATOR_ICON);
+    HbLabel *videoaudiomuteIndicatorIcon = qobject_cast<HbLabel *>(widget);
+    CX_ASSERT_ALWAYS(videoaudiomuteIndicatorIcon);
+
+    widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_STABILITY_INDICATOR_ICON);
+    HbLabel *videoStabilityIndicatorIcon = qobject_cast<HbLabel *>(widget);
+    CX_ASSERT_ALWAYS(videoStabilityIndicatorIcon);
+
+    widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_INDICATOR_CONTAINER_TOP);
+    mIndicators = qobject_cast<HbWidget *>(widget);
+    CX_ASSERT_ALWAYS(mIndicators);
+
+    QGraphicsLayout *layout = mIndicators->layout();
+    QGraphicsLayoutItem *graphicsLayoutItem = NULL;
+    QGraphicsItem *graphicsItem = NULL;
+    QString key = "";
+    int currentSettingValue = -1;
+    bool isSettingOff = false;
+    // Go through the items in the layout to check whether they should be
+    // shown or not in the indicator pane. Start from the last towards
+    // the first, so that removing items from between works correctly.
+    for (int i = layout->count() - 1; i >= 0; i--) {
+        graphicsLayoutItem = layout->itemAt(i);
+        isSettingOff = false;
+        if (graphicsLayoutItem) {
+            graphicsItem = graphicsLayoutItem->graphicsItem();
+            currentSettingValue = -1;
+            if (graphicsItem == videoaudiomuteIndicatorIcon) {
+                key = CxeSettingIds::VIDEO_MUTE_SETTING;
+                currentSettingValue = mEngine->settings().get(key, currentSettingValue);
+                // video mute implementation does not use
+                // enum for on/off values but instead
+                // 0 for off and 1 for on.
+                if (currentSettingValue == 0) {
+                    isSettingOff = true;
+                }
+            } else if (graphicsItem == videoStabilityIndicatorIcon) {
+                // remove video stability indicator.
+                isSettingOff = true;
+            }
+            if (isSettingOff) {
+                layout->removeAt(i);
+            }
+        }
+    }
+
+    // Create background graphics for indicator container
+    createWidgetBackgroundGraphic(mIndicators, TRANSPARENT_BACKGROUND_GRAPHIC);
+
+    mIndicators->setVisible(true);
+
+    CX_DEBUG_EXIT_FUNCTION();
+}
+
+/*!
+ * Loads widgets that are not part of the default section in layouts xml.
+ * Widgets are created at the time they are first loaded.
+ */
 void CxuiVideoPrecaptureView::loadWidgets()
 {
     CX_DEBUG_ENTER_FUNCTION();
-    CX_DEBUG_ASSERT(mDocumentLoader);
+    CX_ASSERT_ALWAYS(mDocumentLoader);
 
     if (mWidgetsLoaded) {
         CX_DEBUG(("Widgets already loaded"));
@@ -176,17 +258,17 @@
 
     // load widgets section (creates the widgets)
     mDocumentLoader->load(VIDEO_1ST_XML, VIDEO_PRE_CAPTURE_WIDGETS_SECTION, &ok);
-    Q_ASSERT_X(ok, "camerax ui", "error in xml file parsing");
+    CX_ASSERT_ALWAYS(ok);
     if (CxuiServiceProvider::isCameraEmbedded()) {
         mDocumentLoader->load(VIDEO_1ST_XML, VIDEO_PRE_CAPTURE_EMBEDDED_SECTION, &ok);
     } else {
         mDocumentLoader->load(VIDEO_1ST_XML, VIDEO_PRE_CAPTURE_STANDALONE_SECTION, &ok);
     }
-    Q_ASSERT_X(ok, "camerax ui", "error in xml file parsing");
+    CX_ASSERT_ALWAYS(ok);
     // get needed pointers to some of the widgets
     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_ZOOM_SLIDER);
     mSlider = qobject_cast<CxuiZoomSlider *> (widget);
-    CX_DEBUG_ASSERT(mSlider);
+    CX_ASSERT_ALWAYS(mSlider);
 
     //Let's add a plus and minus buttons to the slider
     mSlider->addZoomButtons();
@@ -201,9 +283,9 @@
 
     mToolbar = mToolbarIdle;
 
-    CX_DEBUG_ASSERT(mToolbarIdle);
-    CX_DEBUG_ASSERT(mToolbarRec);
-    CX_DEBUG_ASSERT(mToolbarPaused);
+    CX_ASSERT_ALWAYS(mToolbarIdle);
+    CX_ASSERT_ALWAYS(mToolbarRec);
+    CX_ASSERT_ALWAYS(mToolbarPaused);
 
     hideControls();
 
@@ -240,20 +322,16 @@
     HbWidget *indicatorContainer;
     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_INDICATOR_CONTAINER_BOTTOM);
     indicatorContainer = qobject_cast<HbWidget *>(widget);
-    CX_DEBUG_ASSERT(indicatorContainer);
+    CX_ASSERT_ALWAYS(indicatorContainer);
     createWidgetBackgroundGraphic(indicatorContainer, TRANSPARENT_BACKGROUND_GRAPHIC);
 
-    widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_ELAPSED_TIME_LABEL);
-    mElapsedTimeText = qobject_cast<HbLabel *> (widget);
-    CX_DEBUG_ASSERT(mElapsedTimeText);
-
-    widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_REMAINING_TIME_LABEL);
-    mRemainingTimeText = qobject_cast<HbLabel *> (widget);
-    CX_DEBUG_ASSERT(mRemainingTimeText);
+    widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_VIDEO_TIME_LABEL);
+    mVideoTimeText = qobject_cast<HbLabel *> (widget);
+    CX_ASSERT_ALWAYS(mVideoTimeText);
 
     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_RECORDING_ICON);
     mRecordingIcon = qobject_cast<HbLabel *> (widget);
-    CX_DEBUG_ASSERT(mRecordingIcon);
+    CX_ASSERT_ALWAYS(mRecordingIcon);
 
     mWidgetsLoaded = true;
 
@@ -268,9 +346,10 @@
 
 
     // Update toolbar scene mode icon.
-    QString sceneId;
-    if (mEngine->settings().get(CxeSettingIds::SCENE_ID, sceneId) == CxeError::None) {
-        updateSceneIcon(sceneId);
+    try {
+        updateSceneIcon(mEngine->settings().get<QString>(CxeSettingIds::VIDEO_SCENE));
+    } catch (CxeException &e) {
+        // ignore error
     }
 
     // Initialize the video time counters.
@@ -345,6 +424,7 @@
     }
 }
 
+
 /**
 * Get if postcapture view should be shown or not.
 * Postcapture view may be shown for a predefined time or
@@ -361,9 +441,9 @@
 
     // Read the value from settings. Ignoring reading error.
     // On error (missing settings) default to "postcapture on".
-    int showPostcapture(-1);
+    int showPostcapture(POSTCAPTURE_ON);
     if(mEngine) {
-        mEngine->settings().get(CxeSettingIds::VIDEO_SHOWCAPTURED, showPostcapture);
+        showPostcapture = mEngine->settings().get<int>(CxeSettingIds::VIDEO_SHOWCAPTURED, POSTCAPTURE_ON);
     }
 
     CX_DEBUG_EXIT_FUNCTION();
@@ -391,7 +471,7 @@
 
             if (mDocumentLoader) {
                 QObject *obj = mDocumentLoader->findObject(iconObjectName);
-                CX_DEBUG_ASSERT(obj);
+                CX_ASSERT_ALWAYS(obj);
                 qobject_cast<HbAction *>(obj)->setIcon(HbIcon(icon));
             }
         } else {
@@ -410,9 +490,8 @@
 
     if (mQualityIcon && mEngine) {
         QString icon = "";
-        int currentValue = -1;
 
-        mEngine->settings().get(CxeSettingIds::VIDEO_QUALITY, currentValue);
+        int currentValue = mEngine->settings().get<int>(CxeSettingIds::VIDEO_QUALITY, -1);
         icon = getSettingItemIcon(CxeSettingIds::VIDEO_QUALITY, currentValue);
 
         mQualityIcon->setIcon(HbIcon(icon));
@@ -421,13 +500,6 @@
     CX_DEBUG_EXIT_FUNCTION();
 }
 
-void CxuiVideoPrecaptureView::handleSnapshot(CxeError::Id /*error*/)
-{
-    CX_DEBUG_ENTER_FUNCTION();
-
-    CX_DEBUG_EXIT_FUNCTION();
-}
-
 void CxuiVideoPrecaptureView::record()
 {
     CX_DEBUG_ENTER_FUNCTION();
@@ -436,7 +508,9 @@
     mVideoCaptureControl->remainingTime(time);
 
     if (time) {
-        mMenu = takeMenu();
+        if (!mMenu){ // Only take out menu, if we have not already done it
+            mMenu = takeMenu();
+        }
         mVideoCaptureControl->record();
     } else {
         emit errorEncountered(CxeError::DiskFull);
@@ -556,13 +630,12 @@
 void CxuiVideoPrecaptureView::goToStill()
 {
     CX_DEBUG_ENTER_FUNCTION();
-    OstTrace0( camerax_performance, DUP1_CXUIVIDEOPRECAPTUREVIEW_GOTOSTILL, "msg: e_CX_GO_TO_STILL_MODE 1" );
+    OstTrace0( camerax_performance, CXUIVIDEOPRECAPTUREVIEW_GOTOSTILL, "msg: e_CX_GO_TO_STILL_MODE 1" );
 
     hideControls();
     mEngine->initMode(ImageMode);
     emit changeToPrecaptureView();
 
-    OstTrace0( camerax_performance, DUP2_CXUIVIDEOPRECAPTUREVIEW_GOTOSTILL, "msg: e_CX_GO_TO_STILL_MODE 0" );
     CX_DEBUG_EXIT_FUNCTION();
 }
 
@@ -573,7 +646,7 @@
 {
     CX_DEBUG_IN_FUNCTION();
 
-    if (!mRemainingTimeText || !mElapsedTimeText) {
+    if (!mVideoTimeText) {
         // Section not loaded yet. Skip update until created.
         CX_DEBUG(("CxuiVideoPrecaptureView: video time labels not loaded yet!"));
         CX_DEBUG_EXIT_FUNCTION();
@@ -606,8 +679,7 @@
             break;
     }
 
-    setVideoTime(mRemainingTimeText, mTimeRemaining);
-    setVideoTime(mElapsedTimeText, mTimeElapsed);
+    setVideoTime(mVideoTimeText, mTimeElapsed, mTimeRemaining);
 
     CX_DEBUG_EXIT_FUNCTION();
 }
@@ -630,23 +702,28 @@
 /*!
 * Helper method for formatting video time to requested label.
 * @param label Text label to show the time.
-* @param time Time in seconds to be formatted to the label text.
+* @param elapsedTime Elapsed time in seconds to be formatted to the label text.
+* @param remainingTime Remaining time in seconds to be formatted to the label text.
 */
-void CxuiVideoPrecaptureView::setVideoTime(HbLabel* label, int time)
+void CxuiVideoPrecaptureView::setVideoTime(HbLabel* label,
+                                           int elapsedTime,
+                                           int remainingTime)
 {
     // Convert time (seconds) into mm:ss
     // HbExtendedLocale wraps minutes at 60 so we can't use that.
     // We need to show times over 1 hour, e.g. "90:00".
-    QString timeString;
-    timeString.sprintf(VIDEO_TIME_FORMAT, time/60, time%60);
-    label->setPlainText(timeString);
+    QString elapsed, remaining;
+    elapsed.sprintf(VIDEO_TIME_FORMAT, elapsedTime/60, elapsedTime%60);
+    remaining.sprintf(VIDEO_TIME_FORMAT, remainingTime/60, remainingTime%60);
+
+    label->setPlainText(hbTrId("txt_cam_info_redorcding_time").arg(elapsed).arg(remaining));
 }
 
 bool CxuiVideoPrecaptureView::getElapsedTime()
 {
     CX_DEBUG_ENTER_FUNCTION();
 
-    TBool status = mVideoCaptureControl->elapsedTime(mTimeElapsed);
+    bool status = mVideoCaptureControl->elapsedTime(mTimeElapsed);
     CX_DEBUG(("Elapsed time: %d", mTimeElapsed));
     CX_DEBUG(("status: %d", status));
 
@@ -705,6 +782,7 @@
         if (mDocumentLoader){
             mDocumentLoader->load(VIDEO_1ST_XML, VIDEO_PRE_CAPTURE_RECORDING);
         }
+
         mElapsedTimer.start(CXUI_ELAPSED_TIME_TIMEOUT);
         disableFeedback();
 
@@ -758,8 +836,7 @@
         // don't change anything
         break;
     default:
-        // in any other state, just hide the controls
-        setRecordingItemsVisibility(false);
+        // don't change anything
         break;
     }
 
@@ -863,6 +940,10 @@
 
             // update video remaining time counter when video quality is changed
             updateTimeLabels();
+        } else if (key == CxeSettingIds::GEOTAGGING) {
+            reloadIndicatorWidgets();
+        } else if (key == CxeSettingIds::VIDEO_MUTE_SETTING) {
+            reloadIndicatorWidgets();
         }
     }
 
@@ -873,36 +954,18 @@
 * Handle scene mode change.
 * @param scene The new active scene mode.
 */
-void CxuiVideoPrecaptureView::handleSceneChanged(CxeScene &scene)
+void CxuiVideoPrecaptureView::handleSceneChanged(const QVariant &scene)
 {
     CX_DEBUG_ENTER_FUNCTION();
     // Ignore if not in video mode.
     if (mEngine->mode() == Cxe::VideoMode) {
         // Update toolbar scene mode icon.
-        updateSceneIcon(scene[CxeSettingIds::SCENE_ID].toString());
+        updateSceneIcon(scene.toString());
     }
 
     CX_DEBUG_EXIT_FUNCTION();
 }
 
-
-
-/*!
-    Sets the visibility of recording icon and elapsed time text.
-    \param visible True if widgets are to be shown, false if not.
-*/
-void CxuiVideoPrecaptureView::setRecordingItemsVisibility(bool visible) {
-
-    if (mRecordingIcon) {
-        mRecordingIcon->setVisible(visible);
-        mRecordingIcon->setOpacity(1.0f);
-    }
-
-    if (mElapsedTimeText) {
-        mElapsedTimeText->setVisible(visible);
-    }
-}
-
 /*!
  * Overridden eventFilter() to restart the pause timer.
  */