camerauis/cameraxui/cxengine/src/cxesoundplayersymbian.cpp
changeset 37 64817133cd1d
parent 19 d9aefe59d544
child 45 24fd82631616
--- a/camerauis/cameraxui/cxengine/src/cxesoundplayersymbian.cpp	Wed Jun 23 17:59:54 2010 +0300
+++ b/camerauis/cameraxui/cxengine/src/cxesoundplayersymbian.cpp	Tue Jul 06 14:04:02 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"
@@ -16,12 +16,14 @@
 */
 #include <cxesoundplayersymbian.h>
 #include <AudioPreference.h>
+#include <ProfileEngineSDKCRKeys.h>
 #include "cxutils.h"
 #include "cxecameradevicecontrolsymbian.h"
 #include "cxestate.h"
+#include "cxesettings.h"
+
 
 const TUint KCxeAudioPriority = KAudioPriorityCameraTone;
-//const TUint KCxeAudioPriority = KAudioPriorityVideoRecording;
 
 _LIT(KCxeCaptureSound,    "z:\\system\\sounds\\digital\\capture.wav");
 _LIT(KCxeVideoStartSound, "z:\\system\\sounds\\digital\\videoStart.wav");
@@ -29,13 +31,25 @@
 _LIT(KCxeAutoFocusSound,  "z:\\system\\sounds\\digital\\autoFocus.wav");
 
 
-CxeSoundPlayerSymbian::CxeSoundPlayerSymbian(CaptureSound soundId) :
+CxeSoundPlayerSymbian::CxeSoundPlayerSymbian(CaptureSound soundId,
+    CxeSettings &settings) :
     CxeStateMachine("CxeSoundPlayerSymbian"),
     mAudioPlayer(NULL),
-    mSoundId(soundId)
+    mSoundId(soundId),
+    mUseSound(true),
+    mCaptureSoundForced(false),
+    mSettings(settings)
 {
     CX_DEBUG_ENTER_FUNCTION();
 
+    checkCaptureSoundSettings();
+
+    // connect to setting changed signal in order to monitor
+    // profile warning tone changes
+    connect(&mSettings,
+            SIGNAL(settingValueChanged(long int, unsigned long int, QVariant)),
+            this, SLOT(enableSound(long int, unsigned long int, QVariant)));
+
     qRegisterMetaType<CxeSoundPlayerSymbian::State>();
     initializeStates();
 
@@ -52,6 +66,11 @@
     CX_DEBUG_EXIT_FUNCTION();
 }
 
+/*!
+ * Plays the current sound file if soundplayer is in correct state. Once
+ * playing is finished or there is an error playComplete signal is emitted.
+ * \sa playComplete()
+ */
 void CxeSoundPlayerSymbian::play()
 {
     CX_DEBUG_ENTER_FUNCTION();
@@ -59,15 +78,25 @@
 
     // Only play the capture sound if CMdaAudioPlayerUtility is initialised
     if (state() == Ready) {
-        //! @todo: Define & implement what to do, when sound is already playing.
-        // Important for sequence mode.
-        setState(Playing);
-        mAudioPlayer->Play();
+
+        if (mUseSound) {
+            //! @todo: Define & implement what to do, when sound is already playing.
+            // Important for sequence mode.
+            setState(Playing);
+            mAudioPlayer->Play();
+        } else {
+            CX_DEBUG(("CxeSoundPlayerSymbian::play capture sounds turned off"));
+
+            // sounds are off and we don't play the sound,
+            // act as the sound has been played
+            emit playComplete(KErrNone);
+        }
+
     } else if( state() == NotReady ) {
         // Here sound loading has failed.
         // Emit signal with error code.
         emit playComplete(KErrNotReady);
-    } 
+    }
 
     CX_DEBUG_EXIT_FUNCTION();
 }
@@ -131,9 +160,10 @@
             delete mAudioPlayer;
             mAudioPlayer = 0;
         }
-        TRAP( error, mAudioPlayer =
-                      CMdaAudioPlayerUtility::NewFilePlayerL(*filename, *this, KCxeAudioPriority,
-                                                        TMdaPriorityPreference(KAudioPrefCamera)) );
+        TRAP(error, mAudioPlayer =
+             CMdaAudioPlayerUtility::NewFilePlayerL(*filename,
+                                                    *this, KCxeAudioPriority,
+                                                    TMdaPriorityPreference(KAudioPrefCamera)));
         if (!error) {
             setState(Opening);
         } else {
@@ -145,16 +175,25 @@
 }
 
 
-void CxeSoundPlayerSymbian::handleStateChanged(int /*newStateId*/, CxeError::Id /*error*/)
+void CxeSoundPlayerSymbian::handleStateChanged(int newStateId, CxeError::Id error)
 {
+    Q_UNUSED(newStateId);
+    Q_UNUSED(error);
     // No implementation needed, because state is not visible outside of this class
 }
 
+/*!
+ * Returns the current sound player state.
+ * \return Current state
+ */
 CxeSoundPlayerSymbian::State CxeSoundPlayerSymbian::state() const
 {
     return static_cast<State>(stateId());
 }
 
+/*!
+ * Initialize CxeStateMachine.
+ */
 void CxeSoundPlayerSymbian::initializeStates()
 {
     // addState(id, name, allowed next states)
@@ -165,3 +204,75 @@
 
     setInitialState(NotReady);
 }
+
+/*!
+ * Enables or disables the capture sound. If capture sound is forced to
+ * be always on, then the capture sound cannot be disabled.
+ *
+ * \param uid UID of the changed setting
+ * \param key Key of the changed setting
+ * \param value New setting value
+ */
+void CxeSoundPlayerSymbian::enableSound(long int uid, unsigned long int key, QVariant value)
+{
+
+    // 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
+        bool warningTonesEnabled = (value.toInt() == 1);
+
+        // update sound
+        mUseSound = mCaptureSoundForced || warningTonesEnabled;
+    }
+
+    CX_DEBUG(("CxeSoundPlayerSymbian::enableSound <> Use sound [%d]",
+               mUseSound));
+}
+
+/*!
+ * Checks the initial capture sound settings based on profile warning tones
+ * and whether the capture sound is forced to be always on. Connects settings
+ * signal for capture sounds changes to enableCaptureSound slot.
+ *
+ * \sa enableCaptureSound()
+ */
+void CxeSoundPlayerSymbian::checkCaptureSoundSettings()
+{
+
+    CX_DEBUG_ENTER_FUNCTION();
+
+    QVariant value(0);
+
+    // 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);
+
+    // possible values are:
+    // 0 -> warning tones off
+    // 1 -> warning tones on
+    bool warningTonesEnabled = (value.toInt() == 1);
+    CX_DEBUG(("Warning tones enabled [%d]", value.toInt()));
+
+    // check whether capture sound is forced or not
+    int forced = 0;
+    mSettings.get(CxeSettingIds::CAPTURE_SOUND_ALWAYS_ON, forced);
+    // 0 -> capture sound not forced
+    // 1 -> capture sound forced on
+    mCaptureSoundForced = (forced == 1);
+    CX_DEBUG(("Capture sound forced [%d]", forced));
+
+    // use sound if forced on or warningtones are enabled
+    mUseSound = mCaptureSoundForced || warningTonesEnabled;
+    CX_DEBUG(("Use sound [%d]", mUseSound));
+
+    CX_DEBUG_EXIT_FUNCTION();
+}
+
+
+// end of file
+