usbengines/usbotgwatcher/src/cusbindicatornotifier.cpp
branchRCL_3
changeset 80 e02eb84a14d2
parent 79 25fce757be94
--- a/usbengines/usbotgwatcher/src/cusbindicatornotifier.cpp	Tue Aug 31 16:13:57 2010 +0300
+++ b/usbengines/usbotgwatcher/src/cusbindicatornotifier.cpp	Wed Sep 01 12:20:49 2010 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (c) 2009 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"
@@ -15,8 +15,9 @@
  *
  */
 
+#include <AknSmallIndicator.h>
+#include <avkon.hrh>
 #include <usbuinotif.h>
-#include <hb/hbcore/hbindicatorsymbian.h>
 
 #include "cusbindicatornotifier.h"
 #include "cusbstate.h"
@@ -61,8 +62,6 @@
 
     // Unsubscribe from otg watcher states change notifications
     TRAP_IGNORE(iOtgWatcher.UnsubscribeL(*this));
-
-    delete iUsbConnectingIndicator; 
     }
 
 // ---------------------------------------------------------------------------
@@ -71,10 +70,14 @@
 //
 CUsbIndicatorNotifier::CUsbIndicatorNotifier(CUsbNotifManager& aNotifManager,
         CUsbOtgWatcher& aOtgWatcher) :
-        iOtgWatcher(aOtgWatcher)
+    CUsbNotifier(aNotifManager, KUsbUiNotifOtgIndicator, NULL), iOtgWatcher(
+            aOtgWatcher)
     {
     LOG_FUNC
-    
+
+    //To be changed to EAknIndicatorStateAnimate and remove iIconBlinkingTimer
+    //when AVKON implements animation form of usb indicator.
+    iIndicatorState = EAknIndicatorStateOn;
     }
 
 // ---------------------------------------------------------------------------
@@ -85,21 +88,54 @@
     {
     LOG_FUNC
 
-    iUsbConnectingIndicator = CHbIndicatorSymbian::NewL();
-    
     // Subscribe for VBus change notifications
     iOtgWatcher.VBusObserver()->SubscribeL(*this);
 
     // Subscribe for otg watcher states change notifications
     iOtgWatcher.SubscribeL(*this);
 
-    iConnectingIndicatorOn = EFalse;
+    // check here for condition to set usb indicator
+    SetIndicatorL();
+    }
 
-    // check here for condition to set usb indicator
-    SetIndicator();
-   
+// ---------------------------------------------------------------------------
+// Show/hide static icon of the indicator. 
+// If the indicator is blinking, stop blinking it and show/hide the static 
+// form of the indicator.
+// ---------------------------------------------------------------------------
+//
+void CUsbIndicatorNotifier::ShowStaticL(TBool aVisible)
+    {
+    LOG_FUNC
+
+    LOG1("aVisible = %d" , aVisible);
+
+    SetIndicatorStateL(aVisible
+                                ? EAknIndicatorStateOn
+                                   : EAknIndicatorStateOff);
     }
 
+// ---------------------------------------------------------------------------
+// 
+// ---------------------------------------------------------------------------
+//
+void CUsbIndicatorNotifier::BlinkL()
+    {
+    LOG_FUNC
+
+    SetIndicatorStateL( EAknIndicatorStateAnimate );
+    }
+
+// ---------------------------------------------------------------------------
+// From base class CUsbNotifier
+// ---------------------------------------------------------------------------
+//
+void CUsbIndicatorNotifier::ShowL()
+    {
+    LOG_FUNC
+
+    ShowStaticL(ETrue);
+    }
 
 // ---------------------------------------------------------------------------
 // From CUsbNotifier
@@ -109,56 +145,31 @@
     {
     LOG_FUNC
 
-    ToggleConnectingIndicator( EFalse );
+    TRAP_IGNORE( ShowStaticL(EFalse) );
     }
 
 // ---------------------------------------------------------------------------
 // Set USB indicator On or Off
 // ---------------------------------------------------------------------------
 //
-void CUsbIndicatorNotifier::ToggleConnectingIndicator(TBool aEnable)
+void CUsbIndicatorNotifier::SetIndicatorStateL(const TInt aState)
     {
-    LOG1( "toggle connecting indicator = %d" , aEnable);
-    
-    TBool success = ETrue;
-    
-    if (aEnable && !iConnectingIndicatorOn)
-        {
-        success = iUsbConnectingIndicator->Activate(KUsbConnectingIndicator);   
-        LOG1( "calling CHbIndicatorSymbian::Activate(), returned %d", success);   
-        if (success)
-            {
-            iConnectingIndicatorOn = ETrue;
-            }  
-                   
-        }
-   
-    if (!aEnable && iConnectingIndicatorOn)
-        {
-        success = iUsbConnectingIndicator->Deactivate(KUsbConnectingIndicator); 
-        if (success)
-            {
-            iConnectingIndicatorOn = EFalse;
-            }  
-        LOG1( "calling CHbIndicatorSymbian::Deactivate(), returned %d", success);                  
-        }   
-        
-    // if success became false loading the indicator failed, log the error    
-    if (!success)
-        {
-        TInt error = iUsbConnectingIndicator->Error();
-        LOG1( "indicator error is %d", error);       
-        }         
+
+    LOG1( "USB indicator State = %d" , aState);
+
+    CAknSmallIndicator* indicator = CAknSmallIndicator::NewLC(TUid::Uid(
+            EAknIndicatorUSBConnection));
+    indicator->SetIndicatorStateL(aState);
+    CleanupStack::PopAndDestroy(indicator); //indicator    
     }
-       
+
 // ---------------------------------------------------------------------------
 // 
 // ---------------------------------------------------------------------------
 //
 void CUsbIndicatorNotifier::OtgWatcherStateChangedL(TUsbStateIds aState)
     {
-     LOG_FUNC
-    SetIndicator();
+    SetIndicatorL();
     }
 
 // ---------------------------------------------------------------------------
@@ -167,8 +178,7 @@
 //
 void CUsbIndicatorNotifier::VBusDownL()
     {
-     LOG_FUNC
-    SetIndicator();
+    SetIndicatorL();
     }
 
 // ---------------------------------------------------------------------------
@@ -177,8 +187,7 @@
 //
 void CUsbIndicatorNotifier::VBusUpL()
     {
-     LOG_FUNC
-    SetIndicator();
+    SetIndicatorL();
     }
 
 // ---------------------------------------------------------------------------
@@ -187,7 +196,6 @@
 //  
 void CUsbIndicatorNotifier::VBusObserverErrorL(TInt aError)
     {
-    LOG_FUNC
     // do nothing
     }
 
@@ -195,9 +203,8 @@
 // 
 // ---------------------------------------------------------------------------
 //  
-void CUsbIndicatorNotifier::SetIndicator()
+void CUsbIndicatorNotifier::SetIndicatorL()
     {
-    LOG_FUNC
     if (!(iOtgWatcher.IsDeviceA()) || iOtgWatcher.CurrentHostState()->Id() == EUsbStateHostAPeripheral)
         {
         // if B or peripheral, than other party (usbwatcher) takes care of usb indicator
@@ -205,16 +212,22 @@
         return;
         }
 
-    // if VBus up and we are not host -> show connecting indicator
+    // if VBus Up and we are host -> show indicator
     if ((iOtgWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp)
+            && (iOtgWatcher.CurrentHostState()->Id() == EUsbStateHostAHost))
+        {
+        ShowStaticL(ETrue);
+        }
+    // if VBus up and we are not host -> Blink indicator
+    else if ((iOtgWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp)
             && (iOtgWatcher.CurrentHostState()->Id() != EUsbStateHostAHost))
         {
-        ToggleConnectingIndicator( ETrue );
+        BlinkL();
         }
     else
     // Otherwise do not show indicator
         {
-        ToggleConnectingIndicator( EFalse );
+        ShowStaticL(EFalse);
         }
     }