messagingappbase/ncnlist/src/CNcnUI.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:   Methods for CNcnUI class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CNcnUI.h"
       
    22 #include    "NcnModelBase.h"
       
    23 #include    "NcnHandlerAudio.h"
       
    24 #include    "CNcnClass0Viewer.h"
       
    25 #include    "NcnSNNotifier.h"
       
    26 #include    "NcnSubscriber.h"
       
    27 
       
    28 #include    <f32file.h>                             // For TParse
       
    29 #include    <data_caging_path_literals.hrh>         // For literals
       
    30 #include    <stringresourcereader.h>                // For CStringResourceReader
       
    31 #include    <StringLoader.h>                        // For StringLoader
       
    32 #include    <AknUtils.h>                            // For AknTextUtils
       
    33 #include    <AknGlobalNote.h>                       // For CAknGlobalNote
       
    34 #include    <viewcli.h>                             // For CVwsSessionWrapper
       
    35 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    36 #include    <viewclipartner.h>
       
    37 #endif
       
    38 #include    <e32property.h>                         // For RProperty
       
    39 #include    <BTSapDomainPSKeys.h>                   // For KPSUidBluetoothSapConnectionState
       
    40 #include    <activeidle2domainpskeys.h>
       
    41 #include    <coreapplicationuisdomainpskeys.h>
       
    42 
       
    43 #include    <Ncnlist.rsg>                           // New Contacts Note resource
       
    44 
       
    45 // ================= LOCAL CONSTANTS =======================
       
    46 namespace
       
    47     {
       
    48     _LIT( KNcnResourceFileName,"z:ncnlist.rsc" );
       
    49     
       
    50     const TInt KNcnDeliveryResourceBufLen = 128;
       
    51     const TInt KNcnDeliveryTextBufLen = 256;
       
    52     
       
    53     const TUid KMCEAppUid = { 0x100058C5 };
       
    54     const TUid KMCEViewUid = { 0x02 };
       
    55     }
       
    56 
       
    57 // ================= MEMBER FUNCTIONS =======================
       
    58 
       
    59 // ----------------------------------------------------
       
    60 //  CNcnUI::CNcnUI
       
    61 // ----------------------------------------------------
       
    62 //
       
    63 CNcnUI::CNcnUI( CNcnModelBase& aModel ) :
       
    64     iNcnModel( aModel ),
       
    65     iIdleState( EFalse ),
       
    66     iBootPhase( EFalse ),
       
    67     iSAPConnected( EFalse )
       
    68     //iVisualNotificationsAllowed( ETrue ),
       
    69     //iAudioNotificationsAllowed( ETrue )
       
    70     {
       
    71     // empty
       
    72     }
       
    73 
       
    74 // ----------------------------------------------------
       
    75 //  CNcnUI::ConstructL
       
    76 // ----------------------------------------------------
       
    77 //
       
    78 void CNcnUI::ConstructL()
       
    79     {
       
    80     iAudioHandler = CNcnHandlerAudio::NewL( &iNcnModel );
       
    81     iClass0Viewer = CNcnClass0Viewer::NewL( iNcnModel.MsvSessionHandler() );
       
    82     iNotifier = CNcnSNNotifier::NewL();
       
    83         
       
    84     // initialize and subscribe SAP connection subscriber
       
    85     iSAPSubscriber = CNcnSubscriber::NewL( *this,
       
    86         KPSUidBluetoothSapConnectionState,
       
    87         KBTSapConnectionState );
       
    88     iSAPSubscriber->Subscribe();
       
    89     
       
    90     // set SAP connection status
       
    91     iSAPConnected = SAPConnected();
       
    92     }
       
    93     
       
    94 // ----------------------------------------------------
       
    95 //  CNcnUI::NewL
       
    96 // ----------------------------------------------------
       
    97 //
       
    98 CNcnUI* CNcnUI::NewL( CNcnModelBase& aModel )
       
    99     {
       
   100     CNcnUI* self = new (ELeave) CNcnUI( aModel );
       
   101     
       
   102     CleanupStack::PushL( self );
       
   103     self->ConstructL();
       
   104     CleanupStack::Pop( self );
       
   105     
       
   106     return self;
       
   107     }
       
   108 
       
   109 // ----------------------------------------------------
       
   110 //  CNcnUI::~CNcnUI
       
   111 // ----------------------------------------------------
       
   112 //
       
   113 CNcnUI::~CNcnUI()
       
   114     {
       
   115     delete iSAPSubscriber;
       
   116     delete iNotifier;
       
   117     delete iClass0Viewer;
       
   118     delete iAudioHandler;    
       
   119     }
       
   120 
       
   121 // ----------------------------------------------------
       
   122 //  CNcnUI::ShowMessageL
       
   123 // ----------------------------------------------------
       
   124 //    
       
   125 void CNcnUI::ShowMessageL( const TMsvEntry& aEntry )
       
   126     {
       
   127     // use class0 viewer for immidiate display
       
   128     iClass0Viewer->ShowClass0SmsL( aEntry );
       
   129     }
       
   130 
       
   131 // ----------------------------------------------------
       
   132 //  CNcnUI::OpenMessageL
       
   133 // ----------------------------------------------------
       
   134 //    
       
   135 void CNcnUI::OpenMessageL( const TMsvEntry& aEntry )
       
   136     {
       
   137     TVwsViewId messagingCentreInboxView( KMCEAppUid, KMCEViewUid );
       
   138     TUid uid = TUid::Uid( aEntry.Id() );
       
   139     
       
   140     // Create view wrapper object and launch MCE application
       
   141     CVwsSessionWrapper* viewCli = CVwsSessionWrapper::NewLC();    
       
   142     viewCli->CreateActivateViewEvent( 
       
   143         messagingCentreInboxView, uid, KNullDesC8() );
       
   144     CleanupStack::PopAndDestroy( viewCli );
       
   145     
       
   146     iNcnModel.NotifyPublishAndSubscribe(
       
   147         KPSUidAiInformation, // Idle status category
       
   148         KActiveIdleState,
       
   149         EPSAiBackground );// ActiveIdle to background
       
   150     }
       
   151 
       
   152 // ----------------------------------------------------
       
   153 //  CNcnUI::ShowDeliveryNoteL
       
   154 // ----------------------------------------------------
       
   155 //    
       
   156 void CNcnUI::ShowDeliveryNoteL( const TMsvEntry& aEntry )
       
   157     {
       
   158 	TParse *fp = new(ELeave) TParse();
       
   159 	fp->Set( KNcnResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL );
       
   160 	CleanupStack::PushL( fp );
       
   161 
       
   162     TFileName myFileName( fp->FullName() );
       
   163     CStringResourceReader* reader = CStringResourceReader::NewL( myFileName );
       
   164     CleanupStack::PushL( reader );
       
   165 
       
   166     TBuf<KNcnDeliveryResourceBufLen> deliveredText =
       
   167         reader->ReadResourceString( R_NCN_DELIVERED_NOTE_TEXT );
       
   168 
       
   169     TBuf<KNcnDeliveryTextBufLen> theWholeString;
       
   170 
       
   171     StringLoader::Format( theWholeString, deliveredText, -1, aEntry.iDetails );
       
   172     AknTextUtils::DisplayTextLanguageSpecificNumberConversion(
       
   173         theWholeString );
       
   174 
       
   175     CAknGlobalNote * note = CAknGlobalNote::NewL();
       
   176 
       
   177     CleanupStack::PushL( note );
       
   178     note->ShowNoteL( EAknGlobalInformationNote, theWholeString );
       
   179     CleanupStack::PopAndDestroy( 3 );
       
   180     }
       
   181 
       
   182 // ----------------------------------------------------
       
   183 //  CNcnUI::PlayMessageAlertToneL
       
   184 // ----------------------------------------------------
       
   185 //    
       
   186 void CNcnUI::PlayMessageAlertToneL()
       
   187     {
       
   188     if( AudioNotificationsAllowed() )
       
   189         {
       
   190         iAudioHandler->PlayAlertToneL( CNcnModelBase::EIndexUnreadMessages );    
       
   191         }    
       
   192     }
       
   193     
       
   194 // ----------------------------------------------------
       
   195 //  CNcnUI::PlayMessageAlertTone
       
   196 // ----------------------------------------------------
       
   197 //    
       
   198 void CNcnUI::PlayMessageAlertTone()
       
   199     {
       
   200     TRAP_IGNORE( PlayMessageAlertToneL() );
       
   201     }
       
   202 
       
   203 // ----------------------------------------------------
       
   204 //  CNcnUI::PlayEMailAlertToneL
       
   205 // ----------------------------------------------------
       
   206 //    
       
   207 void CNcnUI::PlayEMailAlertToneL()
       
   208     {
       
   209     if( AudioNotificationsAllowed() )
       
   210         {
       
   211         iAudioHandler->PlayAlertToneL( CNcnModelBase::EIndexNewEmails );
       
   212         }    
       
   213     }
       
   214     
       
   215 // ----------------------------------------------------
       
   216 //  CNcnUI::PlayEMailAlertTone
       
   217 // ----------------------------------------------------
       
   218 //    
       
   219 void CNcnUI::PlayEMailAlertTone()
       
   220     {
       
   221     TRAP_IGNORE( PlayEMailAlertToneL() );
       
   222     }
       
   223 
       
   224 // ----------------------------------------------------
       
   225 //  CNcnUI::PlayEMailAlertTone
       
   226 // ----------------------------------------------------
       
   227 //
       
   228 void CNcnUI::AbortAlertTonePlayback()
       
   229     {
       
   230     iAudioHandler->StopMsgReceivedTonePlaying();
       
   231     }
       
   232     
       
   233 // ----------------------------------------------------
       
   234 //  CNcnUI::FlashDisplay
       
   235 // ----------------------------------------------------
       
   236 //    
       
   237 void CNcnUI::FlashDisplay()
       
   238     {
       
   239     // only flash display if notifications are allowed
       
   240     if( VisualNotificationsAllowed() )
       
   241         {
       
   242         // try to set the P&S property
       
   243         TInt err = RProperty::Set(
       
   244             KPSUidCoreApplicationUIs,
       
   245             KLightsControl,
       
   246             ELightsOn );
       
   247         
       
   248         // only set it back if setting succeeded in first place
       
   249         if( err == KErrNone )
       
   250             {
       
   251             RProperty::Set(
       
   252                 KPSUidCoreApplicationUIs,
       
   253                 KLightsControl,
       
   254                 ELightsOff );
       
   255             }
       
   256         }
       
   257     }
       
   258 
       
   259 // ----------------------------------------------------
       
   260 //  CNcnUI::SetIdleState
       
   261 // ----------------------------------------------------
       
   262 //    
       
   263 void CNcnUI::SetIdleState( TBool aIdleState )
       
   264     {
       
   265     // update idle state if changed
       
   266     if( iIdleState != aIdleState )
       
   267         {
       
   268         iIdleState = aIdleState;
       
   269         iNotifier->IdleState( iIdleState );       
       
   270         }    
       
   271     }
       
   272 
       
   273 // ----------------------------------------------------
       
   274 //  CNcnUI::IdleState
       
   275 // ----------------------------------------------------
       
   276 //    
       
   277 TBool CNcnUI::IdleState()
       
   278     {
       
   279     return iIdleState;
       
   280     }
       
   281 
       
   282 // ----------------------------------------------------
       
   283 //  CNcnUI::SetBootPhase
       
   284 // ----------------------------------------------------
       
   285 //    
       
   286 void CNcnUI::SetBootPhase( TBool aBootPhase )
       
   287     {
       
   288     iBootPhase = aBootPhase;
       
   289     }
       
   290     
       
   291 // ----------------------------------------------------
       
   292 //  CNcnUI::BootPhase
       
   293 // ----------------------------------------------------
       
   294 //
       
   295 TBool CNcnUI::BootPhase()
       
   296     {
       
   297     return iBootPhase;
       
   298     }
       
   299     
       
   300 // ----------------------------------------------------
       
   301 //  CNcnUI::UpdateSoftNotification
       
   302 // ----------------------------------------------------
       
   303 //    
       
   304 void CNcnUI::UpdateSoftNotification(
       
   305     MNcnNotifier::TNcnNotificationType aNotification,
       
   306     TUint aAmount )
       
   307     {
       
   308     // only update notification if visual notifications are allowed
       
   309     if( VisualNotificationsAllowed() )
       
   310         {  
       
   311         // update SN notification
       
   312         iNotifier->NewItems( aNotification, aAmount );
       
   313         }
       
   314     }    
       
   315     
       
   316 // ----------------------------------------------------
       
   317 //  CNcnUI::VisualNotificationsAllowed
       
   318 // ----------------------------------------------------
       
   319 //    
       
   320 TBool CNcnUI::VisualNotificationsAllowed()
       
   321     {
       
   322     // visual notifications are not allowed
       
   323     // when SAP is connected
       
   324     return !iSAPConnected;
       
   325     }
       
   326     
       
   327 // ----------------------------------------------------
       
   328 //  CNcnUI::AudioNotificationsAllowed
       
   329 // ----------------------------------------------------
       
   330 //    
       
   331 TBool CNcnUI::AudioNotificationsAllowed()
       
   332     {
       
   333     // audio notifications are not allowed when SAP
       
   334     // is connected or during boot phase
       
   335     return ( !iSAPConnected && !iBootPhase );
       
   336     }   
       
   337 
       
   338 // ----------------------------------------------------
       
   339 //  CNcnUI::HandlePropertyChangedL
       
   340 // ----------------------------------------------------
       
   341 //    
       
   342 void CNcnUI::HandlePropertyChangedL( const TUid& aCategory, TInt aKey )
       
   343     {
       
   344     // SAP connection state changed
       
   345     if( aCategory == KPSUidBluetoothSapConnectionState &&
       
   346         aKey == KBTSapConnectionState )
       
   347         {
       
   348         // update SAP connection status
       
   349         iSAPConnected = SAPConnected();
       
   350         
       
   351         //Clear notes if we have changed to connected or we are connecting
       
   352         //TSW bug ID PRIA-6HTCCK
       
   353         if(iSAPConnected == TRUE)
       
   354 	        {
       
   355         	NCN_RDEBUG( _L( "CNcnUI::SAP is connected. clear all soft notifications!" ) );
       
   356 			iNotifier->NewItems(MNcnNotifier::ENcnMessagesNotification,0);
       
   357 			iNotifier->NewItems(MNcnNotifier::ENcnAudioMessagesNotification,0);
       
   358 			iNotifier->NewItems(MNcnNotifier::ENcnEmailNotification,0);
       
   359 			iNotifier->NewItems(MNcnNotifier::ENcnVoiceMailNotification,0);
       
   360 			iNotifier->NewItems(MNcnNotifier::ENcnVoiceMailOnLine1Notification,0);
       
   361 			iNotifier->NewItems(MNcnNotifier::ENcnVoiceMailOnLine2Notification,0);
       
   362 			iNotifier->NewItems(MNcnNotifier::ENcnMissedCallsNotification,0);
       
   363 	        }
       
   364         }
       
   365     }
       
   366     
       
   367 // ----------------------------------------------------
       
   368 //  CNcnUI::SAPConnected
       
   369 // ----------------------------------------------------
       
   370 //    
       
   371 TBool CNcnUI::SAPConnected()
       
   372     {
       
   373     // default to false
       
   374     TBool ret = EFalse;            
       
   375 
       
   376     // get SAP connection state
       
   377     TInt state = 0;
       
   378     TInt err = RProperty::Get(
       
   379         KPSUidBluetoothSapConnectionState,
       
   380         KBTSapConnectionState,
       
   381         state );
       
   382     
       
   383     if( err == KErrNone )
       
   384         {
       
   385         NCN_RDEBUG_INT( _L( "CNcnUI::SAPConnected - SAP connection = %d" ), state );
       
   386         
       
   387         // if SAP is connecting or connected, return ETrue
       
   388         if( state == EBTSapConnecting || state == EBTSapConnected )
       
   389             {
       
   390             NCN_RDEBUG( _L( "CNcnUI::SAPConnected - SAP connected" ) );
       
   391             ret = ETrue;
       
   392             }
       
   393         else
       
   394             {
       
   395             NCN_RDEBUG( _L( "CNcnUI::SAPConnected - SAP not connected" ) );
       
   396             }
       
   397         }
       
   398     else
       
   399         {
       
   400         NCN_RDEBUG_INT( _L( "CNcnUI::SAPConnected - Could not read SAP connection value, err = %d" ), err );
       
   401         }
       
   402     
       
   403     return ret;
       
   404     }    
       
   405 
       
   406 //  End of File