diff -r c826656d6714 -r 7e18d488ac5f camerauis/cameraxui/cxui/src/cxuiapplicationframeworkmonitorprivate.cpp --- a/camerauis/cameraxui/cxui/src/cxuiapplicationframeworkmonitorprivate.cpp Fri Aug 06 10:03:37 2010 +0300 +++ b/camerauis/cameraxui/cxui/src/cxuiapplicationframeworkmonitorprivate.cpp Mon Aug 23 13:50:05 2010 +0300 @@ -32,6 +32,7 @@ #include #include #include +#include #include #endif // Q_OS_SYMBIAN @@ -42,6 +43,9 @@ #include "cxesettings.h" #include "cxuiapplicationframeworkmonitorprivate.h" +namespace{ + const int CXUI_USB_MODE_CHECK_TIMER_DELAY = 1000; // 1 second +} #ifdef Q_OS_SYMBIAN namespace @@ -110,6 +114,7 @@ mKeyLockState(EKeyguardNotActive), mBatteryStatus(EBatteryStatusUnknown), mUsbPersonality(0), + mUsbModeCheckTimer(this), mEventLog(NULL), #endif // Q_OS_SYMBIAN mState(CxuiApplicationFrameworkMonitor::ForegroundOwned) @@ -120,6 +125,10 @@ mWindowGroupName = windowGroupName(mWsSession, mWindowGroupId); mEventLog = new CxuiEventLog("CxuiApplicationFrameworkMonitorPrivate"); init(); + mUsbModeCheckTimer.setSingleShot(true); + mUsbModeCheckTimer.setInterval(CXUI_USB_MODE_CHECK_TIMER_DELAY); + connect(&mUsbModeCheckTimer, SIGNAL(timeout()), + this, SLOT(usbModeCheckTimerCallback())); #endif // Q_OS_SYMBIAN CX_DEBUG_EXIT_FUNCTION(); } @@ -234,7 +243,20 @@ // Check if mass memory mode activity changed. if (wasUsbMassMemoryModeActive != isUsbMassMemoryModeActive()) { - emit q->usbMassMemoryModeToggled(isUsbMassMemoryModeActive()); + + // If the massmemory mode switched from on to off, + // the signal is emitted immediately. + // If the switch is from off to on, we need to use a timer + // as a workaround because plugging in the USB charger + // sends a mass memory mode change event. + if (wasUsbMassMemoryModeActive) { + emit q->usbMassMemoryModeToggled(isUsbMassMemoryModeActive()); + } else { + // (Re)starting the timer + mUsbModeCheckTimer.stop(); + mUsbModeCheckTimer.start(); + } + } } } @@ -243,6 +265,23 @@ } /*! +* Callback function for the timer used to seperate USB charging +* from USB mass memory mode +*/ +void CxuiApplicationFrameworkMonitorPrivate::usbModeCheckTimerCallback() +{ + CX_DEBUG_ENTER_FUNCTION(); + + // if the device is still in mass memory mode after the timer has finished, + // the device really is in massmemory mode and not plugged into the charger + if (isUsbMassMemoryModeActive()){ + emit q->usbMassMemoryModeToggled(isUsbMassMemoryModeActive()); + } + + CX_DEBUG_EXIT_FUNCTION(); +} + +/*! * Set initial values. */ void CxuiApplicationFrameworkMonitorPrivate::init()