messagingappbase/ncnlist/src/NcnModelBase.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2004 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:   Implements the class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    <msgsimscnumberdetector.h>
       
    22 #include    <featmgr.h>
       
    23 #include    <bldvariant.hrh>
       
    24 #include    <messagingvariant.hrh>
       
    25 #include    <MNcnNotification.h>
       
    26 #include	<messaginginternalcrkeys.h>
       
    27 #include    <startupdomainpskeys.h>
       
    28 
       
    29 #include    "NcnDebug.h"
       
    30 #include    "NcnSNNotifier.h"
       
    31 #include    "NcnMsvSessionObserverBase.h"
       
    32 #include    "NcnCRHandler.h"
       
    33 
       
    34 #include    "CVoiceMailManager.h"
       
    35 #include    "NcnOutboxObserver.h"
       
    36 #include	"MNcnNotificationObserver.h"
       
    37 #include    "CNcnNotifApiObserver.h"
       
    38 #include    "NcnHandlerAudio.h"
       
    39 #include    "NcnModelBase.h"
       
    40 #include    "CNcnMsvSessionHandler.h"
       
    41 #include    "CNcnUI.h"
       
    42 #include    "CNcnNotifier.h"
       
    43 
       
    44 #include    "NcnPublishAndSubscribeObserver.h"
       
    45 #include	"CNcnMsgWaitingManager.h"
       
    46 
       
    47 // ================= MEMBER FUNCTIONS =======================
       
    48 
       
    49 // C++ default constructor can NOT contain any code that
       
    50 // might leave.
       
    51 //
       
    52 CNcnModelBase::CNcnModelBase()  :
       
    53     CActive( EPriorityStandard ), iVoiceMailManager(NULL),
       
    54     iMsgSimOperation( NULL ), iSmsInitialisationPhase( 0 ), 
       
    55     iNcnStatusBits( 0 ), iNcnFeatureFlags( 0 )
       
    56     {
       
    57 	CActiveScheduler::Add( this );
       
    58     }
       
    59 
       
    60 // Symbian OS default constructor can leave.
       
    61 
       
    62 void CNcnModelBase::ConstructL()
       
    63     {
       
    64     // instantiate Msv session handler
       
    65     iMsvSessionHandler = CNcnMsvSessionHandler::NewL();
       
    66     
       
    67     // Set bootstate active
       
    68     iNcnStatusBits |= KNcnBootPhase;
       
    69 
       
    70     // Get available features from feature manager
       
    71     FeatureManager::InitializeLibL();
       
    72     
       
    73     //Is offline mode supported?
       
    74     iNcnFeatureFlags = FeatureManager::FeatureSupported( KFeatureIdOfflineMode );
       
    75 
       
    76     //Is automatic opening of the received sms/mms enabled?
       
    77     //Received SMS/MMS is opened automatically during active call if the sender
       
    78     //is the same as the caller
       
    79     FeatureManager::FeatureSupported( KFeatureIdSendFileInCall ) ? iNcnFeatureFlags |= KNcnSendFileInCall : 0;
       
    80     
       
    81     //Is Audio messaging feature enabled?
       
    82     FeatureManager::FeatureSupported( KFeatureIdAudioMessaging ) ? iNcnFeatureFlags |= KNcnAudioMessaging : 0;
       
    83 
       
    84 	FetchInitialSimSupportStateL();
       
    85     
       
    86     // instantiate ncn ui    
       
    87     iNcnUI = CNcnUI::NewL( *this );
       
    88     
       
    89     // we're in boot phase, inform UI
       
    90     iNcnUI->SetBootPhase( ETrue );
       
    91     
       
    92     // insantiate ncn notifier with UI
       
    93     iNcnNotifier = CNcnNotifier::NewL( *iNcnUI, *this );
       
    94 
       
    95 	// Create MsgWaitingManager which manages indicators
       
    96 	// and message counts
       
    97 	iMsgWaitingManager = CNcnMsgWaitingManager::NewL( *this );
       
    98 
       
    99 	//Connect to CR keys
       
   100 	CreateCRConnectionL();
       
   101 
       
   102 	// Check if SIM service center number should be read 
       
   103 	// in boot
       
   104 	CheckIfSimSCShouldBeRead();			
       
   105 
       
   106 	// Create publish and subscribe observer to receive events
       
   107     NCN_RDEBUG( _L("CNcnModelBase::ConstructL - Constructing CNcnPublishAndSubscribeObserver") );
       
   108 	iNcnPublishAndSubscribeObserver = CNcnPublishAndSubscribeObserver::NewL( this );
       
   109 
       
   110 	//Create a manager for voice mail messages
       
   111 	iVoiceMailManager = CVoiceMailManager::NewL( *this );
       
   112 	
       
   113 	// Create MsvSession observer to receive message and email events
       
   114 	// It takes the voice mail manager as a reference so it can
       
   115 	// notify it directly when new voice mail messages are received
       
   116     NCN_RDEBUG( _L("CNcnModelBase::ConstructL - Constructing CNcnMsvSessionObserverBase") ); 
       
   117     iNcnMsvSessionObserver = CNcnMsvSessionObserverBase::NewL( this, *iVoiceMailManager );         
       
   118 
       
   119     // Check if Service Centres should be fetched
       
   120     CheckIfSimSCOperationRequired();
       
   121     
       
   122     // Create outbox observer
       
   123     NCN_RDEBUG( _L("CNcnModelBase::ConstructL - Constructing CNcnOutboxObserver") );
       
   124     iNcnOutboxObserver = CNcnOutboxObserver::NewL( this );
       
   125 
       
   126     // Create NCN Notification API observer(ECOM API)
       
   127     RImplInfoPtrArray implInfoArray;
       
   128     CleanupClosePushL( implInfoArray );
       
   129     REComSession::ListImplementationsL( KNcnNotificationInterfaceUid,
       
   130                                         implInfoArray );
       
   131     if ( implInfoArray.Count() > 0 )
       
   132         {
       
   133         NCN_RDEBUG( _L("CNcnModelBase::ConstructL - Creating CNcnNotifApiObserver") );
       
   134         iNcnNotificationObserver = CNcnNotifApiObserver::NewL( *this );
       
   135         }
       
   136     else
       
   137         {
       
   138         NCN_RDEBUG( _L("CNcnModelBase::ConstructL - ERROR! CNcnNotifApiObserver ECOM Plug-in not found!") );      
       
   139         }
       
   140     CleanupStack::PopAndDestroy(); // implInfoArray                                                                           
       
   141     
       
   142     // start the session handler
       
   143     iMsvSessionHandler->StartSessionHandlerL();
       
   144     
       
   145     // Reset the boot phase bit.
       
   146     iNcnStatusBits &= ~KNcnBootPhase;
       
   147     
       
   148     // we're finished with boot phase, inform UI
       
   149     iNcnUI->SetBootPhase( EFalse );
       
   150     }
       
   151 
       
   152 // Destructor
       
   153 CNcnModelBase::~CNcnModelBase()
       
   154     {
       
   155     FeatureManager::UnInitializeLib();
       
   156 
       
   157     Cancel();
       
   158     // Free allocated resources.
       
   159     
       
   160     delete iNcnOutboxObserver;    
       
   161 	delete iNcnCRHandler;
       
   162 	delete iNcnPublishAndSubscribeObserver;
       
   163     delete iNcnMsvSessionObserver;
       
   164     delete iMsgSimOperation;
       
   165     delete iNcnNotificationObserver;          
       
   166     delete iVoiceMailManager;
       
   167         
       
   168     delete iNcnNotifier;
       
   169     delete iNcnUI;
       
   170     
       
   171     delete iMsvSessionHandler;
       
   172     
       
   173     delete iMsgWaitingManager;
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------
       
   177 // CNcnModel::SetIdleStateL
       
   178 // Informs the soft notification about the current phone idle state status.
       
   179 // ---------------------------------------------------------
       
   180 //
       
   181 void CNcnModelBase::SetIdleState( const TBool aCurrentState )
       
   182     {
       
   183     // delegate to UI
       
   184     iNcnUI->SetIdleState( aCurrentState );
       
   185     }
       
   186 // ---------------------------------------------------------
       
   187 // CNcnModel::NotifyPublishAndSubscribe
       
   188 // ---------------------------------------------------------
       
   189 //
       
   190 void CNcnModelBase::NotifyPublishAndSubscribe(
       
   191     const TUid&     aVariable,
       
   192     const TInt      aState )
       
   193     {
       
   194     iNcnPublishAndSubscribeObserver->NotifyPublishAndSubscribe( KUidSystemCategory, aVariable.iUid, aState );
       
   195     }
       
   196     
       
   197 // ---------------------------------------------------------
       
   198 // CNcnModel::NotifyPublishAndSubscribe
       
   199 // ---------------------------------------------------------
       
   200 //
       
   201 void CNcnModelBase::NotifyPublishAndSubscribe(
       
   202     const TUid&     aCategory,
       
   203     const TUid&     aVariable,
       
   204     const TInt      aState )
       
   205     {
       
   206     iNcnPublishAndSubscribeObserver->NotifyPublishAndSubscribe( aCategory, aVariable.iUid, aState );
       
   207     }
       
   208     
       
   209 // ---------------------------------------------------------
       
   210 // CNcnModel::NotifyPublishAndSubscribe
       
   211 // ---------------------------------------------------------
       
   212 //
       
   213 void CNcnModelBase::NotifyPublishAndSubscribe(
       
   214     const TUid&     aCategory,
       
   215     const TUint     aVariable,
       
   216     const TInt      aState )
       
   217     {
       
   218     iNcnPublishAndSubscribeObserver->NotifyPublishAndSubscribe( aCategory, aVariable, aState );
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------
       
   222 // CNcnModel::SmsServicePresent
       
   223 // ---------------------------------------------------------
       
   224 //
       
   225 void CNcnModelBase::SmsServicePresent( const TBool aSmsServicePresent )
       
   226     {
       
   227     aSmsServicePresent ?
       
   228         ( iNcnStatusBits |= KNcnSmsServicePresent ) :
       
   229         ( iNcnStatusBits &= ~KNcnSmsServicePresent );
       
   230 
       
   231     // Check here if we should fetch the sms service center number
       
   232     // from the sim card.
       
   233     CheckIfSimSCOperationRequired();
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------
       
   237 // CNcnModelBase::DoCancel
       
   238 // ---------------------------------------------------------
       
   239 //
       
   240 void CNcnModelBase::DoCancel()
       
   241     {
       
   242     // Destroy the outstanding request (delete the active object).
       
   243     delete iMsgSimOperation;
       
   244     iMsgSimOperation = NULL;
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------
       
   248 // CNcnModelBase::RunL
       
   249 // ---------------------------------------------------------
       
   250 //
       
   251 void CNcnModelBase::RunL()
       
   252     {
       
   253     NCN_RDEBUG_INT(_L("CNcnModelBase::RunL(): SC operation completed with status:%d" ), iStatus.Int() );
       
   254 
       
   255     if ( IsSupported( KNcnIdSimCard ))
       
   256         {
       
   257         // Now we have performed the SIM sc fetching so we can close the shared data session...
       
   258 	    iNcnCRHandler->SetSmumFlag( 2 ); // Initialisation complete
       
   259 		delete iMsgSimOperation;
       
   260         iMsgSimOperation = NULL;
       
   261         }
       
   262     }
       
   263 
       
   264 // ---------------------------------------------------------
       
   265 // CNcnModelBase::StopMsgReceivedTonePlaying
       
   266 // ---------------------------------------------------------
       
   267 //
       
   268 void CNcnModelBase::StopMsgReceivedTonePlaying()
       
   269     {
       
   270     iNcnUI->AbortAlertTonePlayback();
       
   271     }
       
   272 
       
   273 // ---------------------------------------------------------
       
   274 // CNcnModelBase::MsgReceivedTonePlaying
       
   275 // ---------------------------------------------------------
       
   276 //
       
   277 void CNcnModelBase::MsgReceivedTonePlaying( TUint aAlertTonePlaying )
       
   278     {
       
   279     if( iNcnCRHandler )
       
   280         {
       
   281         iNcnCRHandler->MsgReceivedTonePlaying( aAlertTonePlaying );
       
   282         }    
       
   283     }
       
   284 
       
   285 // ---------------------------------------------------------
       
   286 // CNcnModelBase::IsSupported
       
   287 // ---------------------------------------------------------
       
   288 //
       
   289 TBool CNcnModelBase::IsSupported( TUint aFeature ) const
       
   290     {
       
   291     return iNcnFeatureFlags & aFeature;
       
   292     }
       
   293 
       
   294 // ---------------------------------------------------------
       
   295 // CNcnModelBase::AddLocalVariationSupport
       
   296 // ---------------------------------------------------------
       
   297 //
       
   298 void CNcnModelBase::AddLocalVariationSupport( TUint aFeature )
       
   299     {
       
   300     iNcnFeatureFlags |= aFeature;
       
   301     }
       
   302 
       
   303 // ---------------------------------------------------------
       
   304 // CNcnModelBase::NotifyOfflineSenderL
       
   305 // ---------------------------------------------------------
       
   306 //
       
   307 void CNcnModelBase::NotifyOfflineSenderL( const TInt& aNetworkBars )
       
   308     {
       
   309     NCN_RDEBUG_INT(_L("CNcnModelBase::NotifyOfflineSenderL(): aNetworkBars:%d" ), aNetworkBars );
       
   310     iNcnOutboxObserver->InformOutboxSenderL( aNetworkBars );
       
   311     }
       
   312 
       
   313 // ---------------------------------------------------------
       
   314 // CNcnModelBase::GetCRString
       
   315 // ---------------------------------------------------------
       
   316 //
       
   317 TInt CNcnModelBase::GetCRString(
       
   318     const TUid&     aUid,
       
   319     const TUint32   aKey,
       
   320     TDes&           aString ) const
       
   321     {
       
   322     // Fetch value from shared data
       
   323     return iNcnCRHandler->GetString( aUid, aKey, aString );
       
   324     }
       
   325 
       
   326 // ---------------------------------------------------------
       
   327 // CNcnModelBase::GetPSString
       
   328 // ---------------------------------------------------------
       
   329 //
       
   330 TInt CNcnModelBase::GetPSString(
       
   331     const TUid&     aUid,
       
   332     const TUint32   aKey,
       
   333     TDes&           aString ) const
       
   334     {
       
   335     // Fetch value from shared data
       
   336     return iNcnCRHandler->GetPSString( aUid, aKey, aString );
       
   337     }
       
   338 
       
   339 // ---------------------------------------------------------
       
   340 // CNcnModelBase::GetCRInteger
       
   341 // ---------------------------------------------------------
       
   342 //
       
   343 TInt CNcnModelBase::GetCRInteger(
       
   344     const TUid&     aUid,
       
   345     const TUint32   aKey,
       
   346     TInt&           aValue) const
       
   347     {
       
   348     // Fetch value from shared data
       
   349     return iNcnCRHandler->GetCRInt( aUid, aKey, aValue );
       
   350     }
       
   351 
       
   352 // ---------------------------------------------------------
       
   353 // CNcnModelBase::SetCRInt
       
   354 // ---------------------------------------------------------
       
   355 //
       
   356 TInt CNcnModelBase::SetCRInt( const TUid& aUid,
       
   357                         const TUint32& aKey, 
       
   358                         TInt& aValue ) const
       
   359     {
       
   360     return iNcnCRHandler->SetCRInt( aUid, aKey, aValue );
       
   361     }
       
   362                         
       
   363 // ---------------------------------------------------------
       
   364 // CNcnModel::PlayAlertTone
       
   365 // ---------------------------------------------------------
       
   366 //
       
   367 TInt CNcnModelBase::PlayAlertToneL( const TUint aAlertTone ) const
       
   368     {
       
   369     if( aAlertTone == CNcnModelBase::EIndexNewEmails )
       
   370         {
       
   371         iNcnUI->PlayEMailAlertTone();
       
   372         }
       
   373     else
       
   374         {
       
   375         iNcnUI->PlayMessageAlertTone();        
       
   376         }
       
   377         
       
   378     return KErrNone;
       
   379     }
       
   380 
       
   381 // ---------------------------------------------------------
       
   382 // CNcnModelBase::SetSimSupported
       
   383 // ---------------------------------------------------------
       
   384 //
       
   385 void CNcnModelBase::SetSimSupported( const TBool aSimSupported )
       
   386     {
       
   387     NCN_RDEBUG_INT(_L("CNcnModelBase::SetSimSupported:%d" ), aSimSupported );
       
   388 
       
   389     if ( aSimSupported )
       
   390         {
       
   391         iNcnFeatureFlags |= KNcnIdSimCard;
       
   392         }
       
   393     else
       
   394         {
       
   395         iNcnFeatureFlags &= ~KNcnIdSimCard;
       
   396         }
       
   397     }
       
   398 
       
   399 // ---------------------------------------------------------
       
   400 // CNcnModelBase::IsSIMPresent
       
   401 // ---------------------------------------------------------
       
   402 //
       
   403 TBool CNcnModelBase::IsSIMPresent()
       
   404 	{
       
   405 	TInt status = KErrNone;
       
   406 	TInt value = 0;
       
   407 	
       
   408 	status = RProperty::Get ( KPSUidStartup, KPSSimStatus, value );
       
   409     NCN_RDEBUG_INT2(_L("CNcnModelBase::IsSIMPresent! status %d, value %d" ), status, value );
       
   410     
       
   411 	if ( status == KErrNone && value != ESimNotPresent )
       
   412         {
       
   413         NCN_RDEBUG(_L("SIM present") );
       
   414 		return TRUE;
       
   415         }
       
   416     else
       
   417     	{
       
   418     	NCN_RDEBUG(_L("SIM not present") );
       
   419     	return FALSE;
       
   420     	}
       
   421 	}
       
   422 		
       
   423 // ---------------------------------------------------------
       
   424 // CNcnModelBase::NotificationObserver
       
   425 // ---------------------------------------------------------
       
   426 //
       
   427 MNcnNotificationObserver& CNcnModelBase::NotificationObserver()
       
   428     {
       
   429     __ASSERT_DEBUG( iNcnNotificationObserver, User::Invariant() );
       
   430     return *iNcnNotificationObserver;
       
   431     }
       
   432     
       
   433 // ---------------------------------------------------------
       
   434 // CNcnModelBase::FetchInitialSimSupportStateL
       
   435 // ---------------------------------------------------------
       
   436 //
       
   437 void CNcnModelBase::FetchInitialSimSupportStateL()
       
   438 	{
       
   439 	TInt state = 0;
       
   440 
       
   441     RProperty::Get ( KPSUidStartup, KPSSimStatus, state );
       
   442     
       
   443 	if ( state != KErrUnknown )
       
   444         {
       
   445 		SetSimSupported( ETrue );
       
   446         SetSimSupported(
       
   447             ( state == ESimNotSupported ) ? EFalse : ETrue );
       
   448         }
       
   449 	}
       
   450 
       
   451 // ---------------------------------------------------------
       
   452 // CNcnModelBase::MsvSessionHandler
       
   453 // ---------------------------------------------------------
       
   454 //
       
   455 CNcnMsvSessionHandler& CNcnModelBase::MsvSessionHandler()
       
   456     {
       
   457     __ASSERT_DEBUG( iMsvSessionHandler, User::Invariant() );
       
   458     return *iMsvSessionHandler;
       
   459     }
       
   460     
       
   461 // ---------------------------------------------------------
       
   462 // CNcnModelBase::NcnUI
       
   463 // ---------------------------------------------------------
       
   464 //
       
   465 MNcnUI& CNcnModelBase::NcnUI()
       
   466     {
       
   467     __ASSERT_DEBUG( iNcnUI, User::Invariant() );
       
   468     return *iNcnUI;
       
   469     }
       
   470 
       
   471 // ---------------------------------------------------------
       
   472 // CNcnModelBase::NcnNotifier
       
   473 // ---------------------------------------------------------
       
   474 //    
       
   475 MNcnNotifier& CNcnModelBase::NcnNotifier()
       
   476     {
       
   477     __ASSERT_DEBUG( iNcnNotifier, User::Invariant() );
       
   478     return *iNcnNotifier;
       
   479     }
       
   480 
       
   481 // ---------------------------------------------------------
       
   482 // CNcnModelBase::NcnNotifier
       
   483 // ---------------------------------------------------------
       
   484 //    
       
   485 MNcnMsgWaitingManager& CNcnModelBase::MsgWaitingManager()
       
   486 	{
       
   487     __ASSERT_DEBUG( iMsgWaitingManager, User::Invariant() );
       
   488 	return *iMsgWaitingManager;		
       
   489 	}
       
   490 
       
   491 // ---------------------------------------------------------
       
   492 // CNcnModelBase::VoiceMailManager
       
   493 // ---------------------------------------------------------
       
   494 //    
       
   495 CVoiceMailManager& CNcnModelBase::VoiceMailManager()
       
   496 	{
       
   497     __ASSERT_DEBUG( iVoiceMailManager, User::Invariant() );
       
   498 	return *iVoiceMailManager;		
       
   499 	}
       
   500 
       
   501 // ---------------------------------------------------------
       
   502 // CNcnModelBase::CheckIfSimSCShouldBeRead
       
   503 // ---------------------------------------------------------
       
   504 //    
       
   505 void CNcnModelBase::CheckIfSimSCShouldBeRead()
       
   506 	{
       
   507 	TInt value = 0;
       
   508 	TInt ret = GetCRInteger( KCRUidMuiuVariation, KMuiuSmsFeatures, value );
       
   509 	NCN_RDEBUG_INT(_L("CNcnModelBase::CheckIfSimSCShouldBeRead: GetCRInteger returned %d" ), ret );			
       
   510 	if( ret == KErrNone && ( value & KSmsFeatureIdCheckSimAlways ) )
       
   511 		{
       
   512 		iNcnStatusBits |= KNcnReadSimSc;
       
   513 		}
       
   514 		
       
   515 	NCN_RDEBUG_INT(_L("CNcnModelBase::CheckIfSimSCShouldBeRead: reading SMS SC from SIM %d" ), ( iNcnStatusBits & KNcnReadSimSc ) ? ETrue : EFalse );		
       
   516 	}
       
   517     
       
   518 //  End of File