camerauis/cameraxui/cxui/src/cxuiselftimer.cpp
changeset 43 0e652f8f1fbd
parent 28 3075d9b614e6
child 45 24fd82631616
equal deleted inserted replaced
28:3075d9b614e6 43:0e652f8f1fbd
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    16 */
    16 */
    17 #include <QGraphicsWidget>
    17 #include <QGraphicsWidget>
    18 #include <hblabel.h>
    18 #include <hblabel.h>
    19 #include <hbpushbutton.h>
    19 #include <hbpushbutton.h>
    20 
    20 
       
    21 #ifdef Q_OS_SYMBIAN
       
    22 #include <ProfileEngineSDKCRKeys.h>
       
    23 #endif
       
    24 
    21 #include "cxuiselftimer.h"
    25 #include "cxuiselftimer.h"
    22 #include "cxutils.h"
    26 #include "cxutils.h"
    23 #include "cxuienums.h"
    27 #include "cxuienums.h"
    24 #include "cxuidocumentloader.h"
    28 #include "cxuidocumentloader.h"
    25 #include "cxesettings.h"
    29 #include "cxesettings.h"
    35     CxuiSelfTimer class handles the selftimer countdown and updates widgets
    39     CxuiSelfTimer class handles the selftimer countdown and updates widgets
    36     accordingly.
    40     accordingly.
    37 */
    41 */
    38 
    42 
    39 // constants
    43 // constants
       
    44 
    40 const int CONTINUOUS_POSTCAPTURE    = -1;
    45 const int CONTINUOUS_POSTCAPTURE    = -1;
    41 const int UNKNOWN                   = -99;
    46 const int UNKNOWN                   = -99;
       
    47 
       
    48 const static QString SELFTIMER_SOUND = "z:\\system\\sounds\\digital\\selftimer.wav";
    42 
    49 
    43 CxuiSelfTimer::CxuiSelfTimer(CxeSettings &settings)
    50 CxuiSelfTimer::CxuiSelfTimer(CxeSettings &settings)
    44 :  mDelay(-1),
    51 :  mDelay(-1),
    45    mCounter(0),
    52    mCounter(0),
    46    mTimer(this),
    53    mTimer(this),
    47    mOldPostCaptureTimeOut(UNKNOWN),
    54    mOldPostCaptureTimeOut(UNKNOWN),
    48    mWidgetContainer(NULL),
    55    mWidgetContainer(NULL),
    49    mTimerLabel(NULL),
    56    mTimerLabel(NULL),
    50    mCancelButton(NULL),
    57    mCancelButton(NULL),
    51    mStartButton(NULL),
    58    mStartButton(NULL),
    52    mSettings(settings)
    59    mSettings(settings),
       
    60    mSound(SELFTIMER_SOUND),
       
    61    mUseSound(true)
    53 {
    62 {
    54     CX_DEBUG_ENTER_FUNCTION();
    63     CX_DEBUG_ENTER_FUNCTION();
    55 
    64 
    56     connect(&mTimer, SIGNAL(timeout()), this, SLOT(timeout()));
    65     connect(&mTimer, SIGNAL(timeout()), this, SLOT(timeout()));
    57     mTimer.setSingleShot(false);
    66     mTimer.setSingleShot(false);
       
    67 
       
    68     // connect to capture sound signal in order to monitor
       
    69     // warning tone changes
       
    70     connect(&mSettings,
       
    71             SIGNAL(settingValueChanged(long int, unsigned long int, QVariant)),
       
    72             this, SLOT(enableSound(long int, unsigned long int, QVariant)));
       
    73 
       
    74     // get initial warning tone value from profile
       
    75     QVariant value(0);
       
    76 
       
    77 #ifdef Q_OS_SYMBIAN
       
    78     // get current profile setting for using camerasound
       
    79     // camera sound follows warning tone setting
       
    80     unsigned long int key = KProEngActiveWarningTones;
       
    81     long int uid = KCRUidProfileEngine.iUid;
       
    82     mSettings.get(uid, key, Cxe::Repository, value);
       
    83 #endif
       
    84 
       
    85     // possible values are:
       
    86     // 0 -> warning tones off
       
    87     // 1 -> warning tones on
       
    88     mUseSound = (value.toInt() == 1);
       
    89     CX_DEBUG(("Warning tones enabled [%d]", value.toInt()));
    58 
    90 
    59     CX_DEBUG_EXIT_FUNCTION();
    91     CX_DEBUG_EXIT_FUNCTION();
    60 }
    92 }
    61 
    93 
    62 CxuiSelfTimer::~CxuiSelfTimer()
    94 CxuiSelfTimer::~CxuiSelfTimer()
   122 bool CxuiSelfTimer::isOngoing()
   154 bool CxuiSelfTimer::isOngoing()
   123 {
   155 {
   124     return mTimer.isActive();
   156     return mTimer.isActive();
   125 }
   157 }
   126 
   158 
       
   159 /*!
       
   160    Returns current timeout value of selftimer.
       
   161  */
       
   162 int CxuiSelfTimer::getTimeout() const
       
   163 {
       
   164     return mDelay;
       
   165 }
       
   166 
   127 /*! Slot for canceling the selftimer.
   167 /*! Slot for canceling the selftimer.
   128     Disables selftimer, sets back the postcapturetimeout if it
   168     Disables selftimer, sets back the postcapturetimeout if it
   129     has been changed by selftimer and emits signal to notify interested
   169     has been changed by selftimer and emits signal to notify interested
   130     parties that cancel has been called.
   170     parties that cancel has been called.
   131 
   171 
   171     // Update now to have better looking user experience,
   211     // Update now to have better looking user experience,
   172     // especially when counter elapses: "0" is updated before emitting event,
   212     // especially when counter elapses: "0" is updated before emitting event,
   173     // so the UI seems to update smoother.
   213     // so the UI seems to update smoother.
   174     updateWidgets();
   214     updateWidgets();
   175 
   215 
       
   216     playSound();
       
   217 
   176     // Check if timer ran out
   218     // Check if timer ran out
   177     if (mCounter >= mDelay) {
   219     if (mCounter >= mDelay) {
   178         mTimer.stop();
   220         mTimer.stop();
       
   221         mSound.stop();
       
   222         hideWidgets();
   179         emit timerFinished();
   223         emit timerFinished();
   180     }
   224     }
   181 
   225 
   182     CX_DEBUG_EXIT_FUNCTION();
   226     CX_DEBUG_EXIT_FUNCTION();
   183 }
   227 }
   184 
   228 
   185 /*!
   229 /*!
   186     Slot for resetting the selftimer countdown. Countdown is stopped,
   230  * Play selftimer sound.
   187     and set back to starting value. Start button is set enabled.
   231  */
   188 
   232 void CxuiSelfTimer::playSound()
   189  */
   233 {
   190 void CxuiSelfTimer::reset()
   234     CX_DEBUG_ENTER_FUNCTION();
   191 {
   235 
   192     CX_DEBUG_ENTER_FUNCTION();
   236     // play sounds only if warning tones are enabled
   193     reset(true);
   237     if (mUseSound) {
       
   238         CX_DEBUG(("play"));
       
   239 
       
   240         int timeLeft = mDelay - mCounter;
       
   241 
       
   242         if (timeLeft <= 3) {
       
   243             // play as fast as we can
       
   244             if (mSound.isFinished()) {
       
   245                 mSound.setLoops(-1);
       
   246                 mSound.play();
       
   247             }
       
   248         } else if (timeLeft <= 10) {
       
   249             // play every second
       
   250             mSound.setLoops(1);
       
   251             mSound.play();
       
   252         } else {
       
   253             // play once every two seconds
       
   254             if (mCounter%2) {
       
   255                 mSound.setLoops(1);
       
   256                 mSound.play();
       
   257             }
       
   258         }
       
   259     }
       
   260 
   194     CX_DEBUG_EXIT_FUNCTION();
   261     CX_DEBUG_EXIT_FUNCTION();
   195 }
   262 }
   196 
   263 
   197 /*!
   264 /*!
   198      Slot for starting the countdown. Show postcapture setting is set to
   265      Slot for starting the countdown. Show postcapture setting is set to
   219         mStartButton->setEnabled(false);
   286         mStartButton->setEnabled(false);
   220     }
   287     }
   221 
   288 
   222     // start countdown
   289     // start countdown
   223     mCounter = 0;
   290     mCounter = 0;
       
   291     playSound();
   224     mTimer.start(1000); // 1000 milliseconds == 1 second
   292     mTimer.start(1000); // 1000 milliseconds == 1 second
   225 
   293 
   226     CX_DEBUG_EXIT_FUNCTION();
   294     CX_DEBUG_EXIT_FUNCTION();
   227 }
   295 }
   228 
   296 
   260  */
   328  */
   261 void CxuiSelfTimer::reset(bool update)
   329 void CxuiSelfTimer::reset(bool update)
   262 {
   330 {
   263     // Stop timer and reset counter.
   331     // Stop timer and reset counter.
   264     mTimer.stop();
   332     mTimer.stop();
       
   333     mSound.stop();
   265     mCounter = 0;
   334     mCounter = 0;
   266 
   335 
   267     // Set start buttonback to enabled.
   336     // Set start buttonback to enabled.
   268     if (mStartButton) {
   337     if (mStartButton) {
   269         mStartButton->setEnabled(true);
   338         mStartButton->setEnabled(true);
   318 {
   387 {
   319     if (mWidgetContainer){
   388     if (mWidgetContainer){
   320         mWidgetContainer->hide();
   389         mWidgetContainer->hide();
   321     }
   390     }
   322 
   391 
   323 
   392 }
   324 
   393 
   325 }
   394 /*!
       
   395  * Enables or disables the selftimer sound.
       
   396  * \param uid UID of the changed setting
       
   397  * \param key Key of the changed setting
       
   398  * \param value New setting value
       
   399  */
       
   400 void CxuiSelfTimer::enableSound(long int uid, unsigned long int key, QVariant value)
       
   401 {
       
   402 #ifdef Q_OS_SYMBIAN
       
   403     // selftimer is only interested in warning tones
       
   404     if (uid == KCRUidProfileEngine.iUid && key == KProEngActiveWarningTones) {
       
   405         CX_DEBUG_IN_FUNCTION();
       
   406         // possible values are:
       
   407         // 0 -> warning tones off
       
   408         // 1 -> warning tones on
       
   409         mUseSound = (value.toInt() == 1);
       
   410     }
       
   411 #else
       
   412     Q_UNUSED(uid);
       
   413     Q_UNUSED(key);
       
   414     Q_UNUSED(value);
       
   415 #endif
       
   416 }
       
   417