usbengines/usbotgwatcher/src/cusbindicatornotifier.cpp
changeset 0 1e05558e2206
child 1 705ec7b86991
equal deleted inserted replaced
-1:000000000000 0:1e05558e2206
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Blink/show Usb indicator notifier implementation
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <AknSmallIndicator.h>
       
    20 #include <avkon.hrh>
       
    21 #include <usbuinotif.h>
       
    22 
       
    23 #include "cusbindicatornotifier.h"
       
    24 #include "cusbnotifier.h"
       
    25 #include "definitions.h"
       
    26 
       
    27 #include "debug.h"
       
    28 #include "panic.h"
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // Two-phased constructor.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CUsbIndicatorNotifier* CUsbIndicatorNotifier::NewL(CUsbNotifManager* aNotifManager)
       
    37     {
       
    38     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::NewL" ));
       
    39 
       
    40     CUsbIndicatorNotifier* self = new (ELeave) CUsbIndicatorNotifier(aNotifManager);
       
    41     CleanupStack::PushL(self);
       
    42     self->ConstructL();
       
    43     CleanupStack::Pop(self);
       
    44     return self;
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // Destructor
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CUsbIndicatorNotifier::~CUsbIndicatorNotifier()
       
    52     {
       
    53     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::~CUsbIndicatorNotifier" ) );
       
    54         
       
    55     Close();
       
    56     delete iIconBlinkingTimer;
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // Show/hide static icon of the indicator. 
       
    61 // If the indicator is blinking, stop blinking it and show/hide the static 
       
    62 // form of the indicator.
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 void CUsbIndicatorNotifier::ShowIndicatorL(TBool aVisible)
       
    66     {
       
    67     FTRACE( FPrint (_L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::ShowIndicator, aVisible=%d" ), aVisible));
       
    68 
       
    69     iIconBlinkingTimer->Cancel();
       
    70 
       
    71     SetIndicatorStateL(aVisible ? EAknIndicatorStateOn : EAknIndicatorStateOff);    
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // From CUsbNotifier
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CUsbIndicatorNotifier::ShowL()
       
    79     {
       
    80     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::ShowL" ));
       
    81 
       
    82     // Will be canceled if active in After()
       
    83     iIconBlinkingTimer->After(0);
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // From CUsbNotifier
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 void CUsbIndicatorNotifier::Close()
       
    91     {
       
    92     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::Close" ) );
       
    93     
       
    94     iIconBlinkingTimer->Cancel();
       
    95     TRAP_IGNORE( ShowIndicatorL(EFalse) );
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // From MUsbTimerObserver
       
   100 // ---------------------------------------------------------------------------
       
   101 // 
       
   102 void CUsbIndicatorNotifier::TimerElapsedL(TUsbTimerId aTimerId)
       
   103     {
       
   104     switch (aTimerId)
       
   105         {
       
   106         case EIconBlinkingTimer:
       
   107             {
       
   108             SetIndicatorStateL(iIndicatorState ? EAknIndicatorStateOn : EAknIndicatorStateOff);    
       
   109 
       
   110             iIndicatorState = (iIndicatorState == EAknIndicatorStateOn
       
   111                                     ? EAknIndicatorStateOff : EAknIndicatorStateOn);
       
   112 
       
   113             // Will be canceled if active in After()
       
   114             iIconBlinkingTimer->After(KUsbIndicatorBlinkingInterval);
       
   115             break;
       
   116             }
       
   117         default:
       
   118             {
       
   119             FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::TimerElapsedL - Unknown timer" ) );
       
   120             
       
   121             Panic(EWrongTimerId);
       
   122             }
       
   123         }
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // C++ constructor
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 CUsbIndicatorNotifier::CUsbIndicatorNotifier(CUsbNotifManager* aNotifManager) :
       
   131     CUsbNotifier(aNotifManager, KUsbUiNotifOtgIndicator, NULL)
       
   132     {
       
   133     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::CUsbIndicatorNotifier" ) );
       
   134 
       
   135     //To be changed to EAknIndicatorStateAnimate and remove iIconBlinkingTimer
       
   136     //when AVKON implements animation form of usb indicator.
       
   137     iIndicatorState = EAknIndicatorStateOn;
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // Second-phase constructor
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 void CUsbIndicatorNotifier::ConstructL()
       
   145     {
       
   146     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::ConstructL" ) );
       
   147 
       
   148     iIconBlinkingTimer = CUsbTimer::NewL(this, EIconBlinkingTimer);
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // Set USB indicator On or Off
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CUsbIndicatorNotifier::SetIndicatorStateL(const TInt aState)
       
   156     {
       
   157     FTRACE( FPrint (_L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::SetIndicatorStateL - aState=%d" ), aState));
       
   158 
       
   159     CAknSmallIndicator* indicator = CAknSmallIndicator::NewLC(TUid::Uid(EAknIndicatorUSBConnection));
       
   160     indicator->SetIndicatorStateL( aState );
       
   161     CleanupStack::PopAndDestroy( indicator ); //indicator    
       
   162     }
       
   163 
       
   164 // End of file