camerauis/cameraxui/cxui/src/cxuiselftimer.cpp
changeset 43 0e652f8f1fbd
parent 28 3075d9b614e6
child 45 24fd82631616
--- a/camerauis/cameraxui/cxui/src/cxuiselftimer.cpp	Thu May 13 21:30:19 2010 +0300
+++ b/camerauis/cameraxui/cxui/src/cxuiselftimer.cpp	Thu Jul 15 01:55:05 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -18,6 +18,10 @@
 #include <hblabel.h>
 #include <hbpushbutton.h>
 
+#ifdef Q_OS_SYMBIAN
+#include <ProfileEngineSDKCRKeys.h>
+#endif
+
 #include "cxuiselftimer.h"
 #include "cxutils.h"
 #include "cxuienums.h"
@@ -37,9 +41,12 @@
 */
 
 // constants
+
 const int CONTINUOUS_POSTCAPTURE    = -1;
 const int UNKNOWN                   = -99;
 
+const static QString SELFTIMER_SOUND = "z:\\system\\sounds\\digital\\selftimer.wav";
+
 CxuiSelfTimer::CxuiSelfTimer(CxeSettings &settings)
 :  mDelay(-1),
    mCounter(0),
@@ -49,13 +56,38 @@
    mTimerLabel(NULL),
    mCancelButton(NULL),
    mStartButton(NULL),
-   mSettings(settings)
+   mSettings(settings),
+   mSound(SELFTIMER_SOUND),
+   mUseSound(true)
 {
     CX_DEBUG_ENTER_FUNCTION();
 
     connect(&mTimer, SIGNAL(timeout()), this, SLOT(timeout()));
     mTimer.setSingleShot(false);
 
+    // connect to capture sound signal in order to monitor
+    // warning tone changes
+    connect(&mSettings,
+            SIGNAL(settingValueChanged(long int, unsigned long int, QVariant)),
+            this, SLOT(enableSound(long int, unsigned long int, QVariant)));
+
+    // get initial warning tone value from profile
+    QVariant value(0);
+
+#ifdef Q_OS_SYMBIAN
+    // get current profile setting for using camerasound
+    // camera sound follows warning tone setting
+    unsigned long int key = KProEngActiveWarningTones;
+    long int uid = KCRUidProfileEngine.iUid;
+    mSettings.get(uid, key, Cxe::Repository, value);
+#endif
+
+    // possible values are:
+    // 0 -> warning tones off
+    // 1 -> warning tones on
+    mUseSound = (value.toInt() == 1);
+    CX_DEBUG(("Warning tones enabled [%d]", value.toInt()));
+
     CX_DEBUG_EXIT_FUNCTION();
 }
 
@@ -124,6 +156,14 @@
     return mTimer.isActive();
 }
 
+/*!
+   Returns current timeout value of selftimer.
+ */
+int CxuiSelfTimer::getTimeout() const
+{
+    return mDelay;
+}
+
 /*! Slot for canceling the selftimer.
     Disables selftimer, sets back the postcapturetimeout if it
     has been changed by selftimer and emits signal to notify interested
@@ -173,9 +213,13 @@
     // so the UI seems to update smoother.
     updateWidgets();
 
+    playSound();
+
     // Check if timer ran out
     if (mCounter >= mDelay) {
         mTimer.stop();
+        mSound.stop();
+        hideWidgets();
         emit timerFinished();
     }
 
@@ -183,14 +227,37 @@
 }
 
 /*!
-    Slot for resetting the selftimer countdown. Countdown is stopped,
-    and set back to starting value. Start button is set enabled.
-
+ * Play selftimer sound.
  */
-void CxuiSelfTimer::reset()
+void CxuiSelfTimer::playSound()
 {
     CX_DEBUG_ENTER_FUNCTION();
-    reset(true);
+
+    // play sounds only if warning tones are enabled
+    if (mUseSound) {
+        CX_DEBUG(("play"));
+
+        int timeLeft = mDelay - mCounter;
+
+        if (timeLeft <= 3) {
+            // play as fast as we can
+            if (mSound.isFinished()) {
+                mSound.setLoops(-1);
+                mSound.play();
+            }
+        } else if (timeLeft <= 10) {
+            // play every second
+            mSound.setLoops(1);
+            mSound.play();
+        } else {
+            // play once every two seconds
+            if (mCounter%2) {
+                mSound.setLoops(1);
+                mSound.play();
+            }
+        }
+    }
+
     CX_DEBUG_EXIT_FUNCTION();
 }
 
@@ -221,6 +288,7 @@
 
     // start countdown
     mCounter = 0;
+    playSound();
     mTimer.start(1000); // 1000 milliseconds == 1 second
 
     CX_DEBUG_EXIT_FUNCTION();
@@ -262,6 +330,7 @@
 {
     // Stop timer and reset counter.
     mTimer.stop();
+    mSound.stop();
     mCounter = 0;
 
     // Set start buttonback to enabled.
@@ -320,6 +389,29 @@
         mWidgetContainer->hide();
     }
 
-
+}
 
+/*!
+ * Enables or disables the selftimer sound.
+ * \param uid UID of the changed setting
+ * \param key Key of the changed setting
+ * \param value New setting value
+ */
+void CxuiSelfTimer::enableSound(long int uid, unsigned long int key, QVariant value)
+{
+#ifdef Q_OS_SYMBIAN
+    // selftimer is only interested in warning tones
+    if (uid == KCRUidProfileEngine.iUid && key == KProEngActiveWarningTones) {
+        CX_DEBUG_IN_FUNCTION();
+        // possible values are:
+        // 0 -> warning tones off
+        // 1 -> warning tones on
+        mUseSound = (value.toInt() == 1);
+    }
+#else
+    Q_UNUSED(uid);
+    Q_UNUSED(key);
+    Q_UNUSED(value);
+#endif
 }
+