idlefw/plugins/devicestatus/src/aicugmcnpublisher.cpp
changeset 0 79c6a41cd166
child 8 d0529222e3f0
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     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:  Closed user group (CUG) publisher.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aidevstaplgres.rsg>
       
    20 #include <StringLoader.h>
       
    21 #include "aicugmcnpublisher.h"
       
    22 #include "aicontentobserver.h"
       
    23 #include "ainetworkinfolistener.h"
       
    24 
       
    25 // ======== MEMBER FUNCTIONS ========
       
    26 
       
    27 CAiCUGMCNPublisher::CAiCUGMCNPublisher()
       
    28     {
       
    29     }
       
    30 
       
    31 
       
    32 void CAiCUGMCNPublisher::ConstructL()
       
    33     {
       
    34     iListener = CAiNetworkInfoListener::InstanceL();
       
    35     User::LeaveIfError( iSSSettings.Open() );
       
    36     
       
    37     // Initialize the periodic timer.
       
    38     iPeriodic = CPeriodic::NewL( CActive::EPriorityStandard );
       
    39     }
       
    40 
       
    41 
       
    42 CAiCUGMCNPublisher* CAiCUGMCNPublisher::NewL()
       
    43     {
       
    44     CAiCUGMCNPublisher* self = new( ELeave ) CAiCUGMCNPublisher;
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL();
       
    47     CleanupStack::Pop( );
       
    48     //CleanupStack::Pop( self );
       
    49     return self;
       
    50     }
       
    51 
       
    52 
       
    53 CAiCUGMCNPublisher::~CAiCUGMCNPublisher()
       
    54     {
       
    55     if( iPeriodic )
       
    56             {
       
    57             iPeriodic->Cancel();
       
    58             delete iPeriodic;
       
    59             }
       
    60     if( iListener )
       
    61             {
       
    62             iListener->RemoveObserver( *this );
       
    63             iListener->Release();
       
    64             }
       
    65     //Cancel listenning CUG changes.
       
    66     iSSSettings.CancelAll( *this );
       
    67     iSSSettings.Close();
       
    68     
       
    69     delete iCUG;
       
    70     delete iMCN;
       
    71     }
       
    72 
       
    73 TInt CAiCUGMCNPublisher::PeriodicTimerCallBack(TAny* aAny)
       
    74 	{
       
    75 	CAiCUGMCNPublisher* self = static_cast<CAiCUGMCNPublisher*>( aAny );
       
    76   
       
    77 	if( self )
       
    78 	        {
       
    79 	        self->DoAnimation();
       
    80 	        }
       
    81 
       
    82 	    return KErrNone;
       
    83 	}
       
    84 
       
    85 void CAiCUGMCNPublisher::DoAnimation()
       
    86 	{
       
    87 	if ( iAnimationDone )
       
    88 		{
       
    89 		PublishCUG();
       
    90 		iPeriodic->Cancel();
       
    91 		}
       
    92 	else
       
    93 		{
       
    94 		iAnimationDone = ETrue;
       
    95 		PublishMCN();
       
    96 		}
       
    97 
       
    98 	}
       
    99 
       
   100 
       
   101 void CAiCUGMCNPublisher::ResumeL()
       
   102     {
       
   103     iListener->AddObserverL( *this );
       
   104     
       
   105 	//Start listening CUG changes.
       
   106     TInt err = iSSSettings.Register( ESSSettingsCug, *this );
       
   107 
       
   108     if( err == KErrNotSupported ||
       
   109         err == KErrAlreadyExists  )
       
   110         {
       
   111         //CUG not supported, or already registered
       
   112         err = KErrNone;
       
   113         }
       
   114 
       
   115     User::LeaveIfError( err );
       
   116     }
       
   117 
       
   118 
       
   119 void CAiCUGMCNPublisher::Subscribe( MAiContentObserver& aObserver, 
       
   120 							        MAiPropertyExtension& aExtension,
       
   121                                     MAiPublishPrioritizer& /*aPrioritizer*/,
       
   122                                     MAiPublisherBroadcaster& /*aBroadcaster*/ )
       
   123     {
       
   124     iContentObserver = &aObserver;
       
   125     iExtension = &aExtension;
       
   126     }
       
   127 
       
   128 
       
   129 void CAiCUGMCNPublisher::RefreshL( TBool /*aClean*/ )
       
   130     {
       
   131 	//Get current CUG value and publish it.
       
   132     TInt value;
       
   133     if ( iSSSettings.Get( ESSSettingsCug, value ) != KErrNone )
       
   134         {
       
   135         value = ESSSettingsCugDefault;
       
   136         }
       
   137 
       
   138     UpdateCUGMCNIndicatorL( value );
       
   139     }
       
   140 
       
   141 
       
   142 void CAiCUGMCNPublisher::PhoneSettingChanged( TSSSettingsSetting aSetting, 
       
   143 											TInt aNewValue )
       
   144     {
       
   145     if( aSetting == ESSSettingsCug )
       
   146         {
       
   147         TRAP_IGNORE( UpdateCUGMCNIndicatorL( aNewValue ) );
       
   148         }
       
   149     }
       
   150 
       
   151 void CAiCUGMCNPublisher::UpdateCUGMCNIndicatorL( TInt aValue )
       
   152     {
       
   153 	//Check if the CUG is valid...
       
   154     if( iSSSettings.IsValueValidCugIndex( aValue ) )
       
   155         {
       
   156 		//...and then read CUG indicator format from resource file and publish 
       
   157 		// content as a text.
       
   158         if (iCUG)
       
   159         	{
       
   160         	delete iCUG;
       
   161         	iCUG = NULL;
       
   162         	}
       
   163         iCUG = StringLoader::LoadL( 
       
   164         						R_ACTIVEIDLE_CUG_INDICATOR_FORMAT, 
       
   165         						aValue );
       
   166         						
       
   167 		Animate();
       
   168         }
       
   169     else
       
   170         {            
       
   171 		//CUG is not valid, call clean.
       
   172 		if ( iCUG )
       
   173 			{
       
   174 			iContentObserver->Clean( *iExtension, 
       
   175         					EAiDeviceStatusContentCUGMCNIndicator, 
       
   176         					0 );
       
   177 			iCUG = NULL;
       
   178 			}
       
   179         }
       
   180     }
       
   181 
       
   182 void CAiCUGMCNPublisher::HandleNetworkInfoChange( 
       
   183 						const MNWMessageObserver::TNWMessages& aMessage, 
       
   184 						const TNWInfo& aInfo,
       
   185 						const TBool /*aShowOpInd*/ )
       
   186     {
       
   187 	//If MSN message was received, publish it.
       
   188     if ( aMessage == MNWMessageObserver::ENWMessageCurrentCellInfoMessage )
       
   189         {
       
   190         if ( aInfo.iMCNIndicatorType == ENWMCNIndicatorTypeActive )
       
   191             {
       
   192             TPtrC msg = aInfo.iMCNName;
       
   193             if (iMCN)
       
   194             	{
       
   195             	delete iMCN;
       
   196             	iMCN = NULL;
       
   197             	}
       
   198             	
       
   199             TRAP_IGNORE(iMCN = msg.AllocL());
       
   200 			Animate();
       
   201             }
       
   202         else if ( aInfo.iMCNIndicatorType == ENWMCNIndicatorTypeNone )
       
   203             {
       
   204 			if ( iMCN )
       
   205 				{
       
   206 				//MCN is not valid, call clean.
       
   207 				iContentObserver->Clean( *iExtension, 
       
   208 								EAiDeviceStatusContentCUGMCNIndicator,
       
   209 			            		0 );
       
   210 				iMCN = NULL;
       
   211 				}
       
   212             }
       
   213         }
       
   214     }
       
   215 
       
   216 
       
   217 TBool CAiCUGMCNPublisher::RefreshL( TInt aContentId, TBool aClean )
       
   218 	{
       
   219     if( ( aContentId == EAiDeviceStatusContentCUGMCNIndicator ) 
       
   220     		|| ( aContentId == EAiDeviceStatusContentNetworkIdentity ) )
       
   221         {
       
   222    	    RefreshL( aClean );
       
   223    	    return ETrue;
       
   224     	}
       
   225     	
       
   226     return EFalse;
       
   227 	}
       
   228 
       
   229 void CAiCUGMCNPublisher::Animate()
       
   230 	{
       
   231 	if ( iCUG && iMCN )
       
   232 		{
       
   233 		if ( !iPeriodic->IsActive() )
       
   234 			{
       
   235 			iAnimationDone = EFalse;
       
   236 			PublishCUG();
       
   237 			iPeriodic->Start( KAnimDelay, KAnimDelay, TCallBack( PeriodicTimerCallBack, this ) );
       
   238 			}
       
   239 		}
       
   240 	else
       
   241 		{
       
   242 		if ( iCUG )
       
   243 			{
       
   244 			PublishCUG();
       
   245 			}
       
   246 		else if ( iMCN )
       
   247 			{
       
   248 			PublishMCN();
       
   249 			}
       
   250 		}
       
   251 	}
       
   252 
       
   253 void CAiCUGMCNPublisher::PublishCUG()
       
   254 	{
       
   255 	iContentObserver->Publish( *iExtension, 
       
   256 			        	EAiDeviceStatusContentCUGMCNIndicator, 
       
   257 			        	*iCUG, 
       
   258 			        	0 );
       
   259 	}
       
   260 
       
   261 void CAiCUGMCNPublisher::PublishMCN()
       
   262 	{
       
   263 	iContentObserver->Publish( *iExtension, 
       
   264 						EAiDeviceStatusContentCUGMCNIndicator, 
       
   265 		            	*iMCN, 
       
   266 		            	0 );
       
   267 	}
       
   268