uifw/AvKon/src/AknInfoPopupNoteController.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2005, 2006 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:  Implementation of CAknInfoPopupNoteController class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include <AknPictographInterface.h>
       
    23 
       
    24 #include <AknsDrawUtils.h>
       
    25 #include <AknsFrameBackgroundControlContext.h>
       
    26 #include <eiklabel.h>
       
    27 #include <gulicon.h>
       
    28 
       
    29 #include <eikdef.h>
       
    30 #include <coeaui.h>
       
    31 
       
    32 #include <e32base.h>
       
    33 #include <aknappui.h>
       
    34 #include <aknsoundsystem.h>
       
    35 
       
    36 #include "akntextcontrol.h"
       
    37 
       
    38 #include "AknInfoPopupNoteController.h"
       
    39 #include "AknInfoPopupNote.h"
       
    40 
       
    41 
       
    42 // CONSTANTS
       
    43 const TInt KInfoPopupNoteTimeDelayBeforeShow = 1000000;  // 1 seconds
       
    44 const TInt KInfoPopupNoteTimeInView          = 10000000; // 10 seconds
       
    45 const TInt KFromMillisecToMicrosecMultiplier = 1000;
       
    46 const TInt KObserverArrayGranularity         = 1;
       
    47 
       
    48 
       
    49 // ============================ MEMBER FUNCTIONS ===============================
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CAknInfoPopupNoteController
       
    53 //
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CAknInfoPopupNoteController::CAknInfoPopupNoteController()
       
    57     : CTimer( 0 ),
       
    58     iState( CAknInfoPopupNoteController::EHidden ),
       
    59     iObservers( KObserverArrayGranularity ),
       
    60     iTimeDelayBeforeShow( KInfoPopupNoteTimeDelayBeforeShow ),
       
    61     iTimeInView( KInfoPopupNoteTimeInView ),
       
    62     iTone( ENoTone )
       
    63     {
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // ConstructL
       
    68 //
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 void CAknInfoPopupNoteController::ConstructL()
       
    72     {
       
    73     iPopup = CAknInfoPopupNote::NewL( *this );
       
    74     CTimer::ConstructL();
       
    75     CActiveScheduler::Add( this );
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // NewL
       
    80 //
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 EXPORT_C CAknInfoPopupNoteController* CAknInfoPopupNoteController::NewL()
       
    84     {
       
    85     CAknInfoPopupNoteController* self = new( ELeave ) CAknInfoPopupNoteController();
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL();
       
    88     CleanupStack::Pop();
       
    89     return self;
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // ~CAknInfoPopupNoteController
       
    94 //
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 CAknInfoPopupNoteController::~CAknInfoPopupNoteController()
       
    98     {
       
    99     Cancel();
       
   100     if ( iPopup )
       
   101         {
       
   102         delete iPopup;
       
   103         }
       
   104     iObservers.Reset();
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // SetShowTime
       
   109 //
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 EXPORT_C void CAknInfoPopupNoteController::SetTimeDelayBeforeShow( TInt aMilliSeconds )
       
   113     {
       
   114     if ( aMilliSeconds >= 0 )
       
   115         {
       
   116         iTimeDelayBeforeShow = KFromMillisecToMicrosecMultiplier * aMilliSeconds;
       
   117         }
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // SetHideTime
       
   122 //
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 EXPORT_C void CAknInfoPopupNoteController::SetTimePopupInView( TInt aMilliSeconds )
       
   126     {
       
   127     iTimeInView = KFromMillisecToMicrosecMultiplier * aMilliSeconds;
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // SetTextL
       
   132 //
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 EXPORT_C void CAknInfoPopupNoteController::SetTextL( const TDesC& aText )
       
   136     {
       
   137     iPopup->SetTextL( aText );
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // ShowInfoPopupNote
       
   142 //
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 EXPORT_C void CAknInfoPopupNoteController::ShowInfoPopupNote()
       
   146     {
       
   147     // cancel the timer and hide the popup, this also sets initial state
       
   148     Cancel();
       
   149     
       
   150     if(iPopup->IsVisible())
       
   151     {
       
   152     	return;
       
   153     }
       
   154 
       
   155     if ( iPopup->GetText() == KNullDesC() )  // if text isn't set before at all
       
   156         {
       
   157         return;
       
   158         }
       
   159 
       
   160     // set up timer to wait default of one second before showing the popup
       
   161     iState = CAknInfoPopupNoteController::EWaitingToShow;
       
   162     After( TTimeIntervalMicroSeconds32( iTimeDelayBeforeShow ) );
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // HideInfoPopupNote
       
   167 //
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 EXPORT_C void CAknInfoPopupNoteController::HideInfoPopupNote()
       
   171     {
       
   172     if ( iTimeInView > 0)
       
   173         {
       
   174         Cancel();
       
   175         
       
   176         // If the button from which info popup note was launched,
       
   177         // has keyrepeat timer, the previous Cancel() -call won't
       
   178         // cause DoCancel() call. TSW Error RYPA-7DYCCY.
       
   179         if( iPopup->IsVisible() ) 
       
   180 	        {
       
   181 	        DoCancel();
       
   182 	        }
       
   183 	        
       
   184         __ASSERT_ALWAYS( !iPopup->IsVisible(), 
       
   185             User::Panic(_L("Info popup note assert"), KErrUnknown));
       
   186         }        
       
   187     else
       
   188         {
       
   189         iState = CAknInfoPopupNoteController::EHidden;
       
   190         iPopup->Hide();
       
   191         Cancel();
       
   192         }
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // AddObserverL
       
   197 //
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 EXPORT_C void CAknInfoPopupNoteController::AddObserverL(
       
   201         const MAknInfoPopupNoteObserver& aObserver )
       
   202     {
       
   203     iObservers.InsertInAddressOrderL( &aObserver );
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // RemoveObserver
       
   208 //
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 EXPORT_C void CAknInfoPopupNoteController::RemoveObserver(
       
   212         const MAknInfoPopupNoteObserver& aObserver )
       
   213     {
       
   214     TInt index = iObservers.FindInAddressOrder( &aObserver );
       
   215     if ( index != KErrNotFound )
       
   216         {
       
   217         iObservers.Remove( index );
       
   218         }
       
   219     }
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // SetPositionAndAlignment
       
   223 //
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 EXPORT_C void CAknInfoPopupNoteController::SetPositionAndAlignment(
       
   227         const TPoint& aPosition, const TGulAlignmentValue& aAlignment )
       
   228     {
       
   229     iPopup->SetPositionAndAlignment( aPosition, aAlignment );
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // SetPositionByHighlight
       
   234 //
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 EXPORT_C void CAknInfoPopupNoteController::SetPositionByHighlight(
       
   238         const TRect& aHighlightRect )
       
   239     {
       
   240     iPopup->SetPositionByHighlight( aHighlightRect );
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // RestoreDefaultPosition
       
   245 //
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 EXPORT_C void CAknInfoPopupNoteController::RestoreDefaultPosition()
       
   249     {
       
   250     iPopup->RestoreDefaultPosition();
       
   251     }
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // SetTooltipModeL
       
   255 //
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 EXPORT_C void CAknInfoPopupNoteController::SetTooltipModeL(
       
   259         const TBool aTooltipMode )
       
   260     {
       
   261     iPopup->SetTooltipModeL( aTooltipMode );
       
   262     }
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // HideWhenAppFaded
       
   266 //
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 
       
   270 EXPORT_C void CAknInfoPopupNoteController::HideWhenAppFaded( const TBool aHide )
       
   271     {
       
   272     iPopup->HideWhenAppFaded( aHide );
       
   273     }
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // NotifyObservers
       
   277 //
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 void CAknInfoPopupNoteController::NotifyObservers(
       
   281         MAknInfoPopupNoteObserver::TAknInfoPopupNoteEvent aEvent )
       
   282     {
       
   283     for ( TInt i = 0; i < iObservers.Count(); ++i )
       
   284         {
       
   285         iObservers[i]->HandleInfoPopupNoteEvent( this, aEvent );
       
   286         }
       
   287     }
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // CAknInfoPopupNoteController::SetTone
       
   291 // Set the tone to be played
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 EXPORT_C void CAknInfoPopupNoteController::SetTone( const TTone& aTone )
       
   295     {
       
   296     iTone = aTone;
       
   297     }
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // RunL
       
   301 //
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 void CAknInfoPopupNoteController::RunL()
       
   305     {
       
   306     switch ( iState )
       
   307         {
       
   308         case CAknInfoPopupNoteController::EWaitingToShow:
       
   309             iState = CAknInfoPopupNoteController::EShowing;
       
   310             PlayTone();
       
   311             iPopup->ShowL();
       
   312             if ( iTimeInView > 0 )
       
   313                 {
       
   314                 After( TTimeIntervalMicroSeconds32( iTimeInView ) );    
       
   315                 }
       
   316             break;
       
   317 
       
   318         case CAknInfoPopupNoteController::EShowing:
       
   319             iState = CAknInfoPopupNoteController::EHidden;
       
   320             iPopup->Hide();
       
   321             break;
       
   322 
       
   323         default:
       
   324             User::Panic( _L( "Info popup note" ), KErrUnknown );
       
   325         }
       
   326     }
       
   327 
       
   328 // -----------------------------------------------------------------------------
       
   329 // CAknInfoPopupNoteController::PlayTone
       
   330 // Play the tone
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 void CAknInfoPopupNoteController::PlayTone()
       
   334     {
       
   335     if ( ( iTone != ENoTone ) && ( CEikonEnv::Static()->AppUi() ) )
       
   336         {
       
   337         iAvkonAppUiBase->KeySounds()->PlaySound( iTone );
       
   338         }
       
   339     }
       
   340 
       
   341 // -----------------------------------------------------------------------------
       
   342 // CAknInfoPopupNoteController::DoCancel
       
   343 // Implements cancellation of asynchronous operation.
       
   344 // -----------------------------------------------------------------------------
       
   345 //
       
   346 void CAknInfoPopupNoteController::DoCancel()
       
   347     {
       
   348     CTimer::DoCancel();
       
   349     iState = CAknInfoPopupNoteController::EHidden;
       
   350     iPopup->Hide();
       
   351     }
       
   352 
       
   353 //  End of File