messagingappbase/ncnlist/src/NcnMsvSessionObserverBase.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 NcnMsvSessionObserverBase class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    <msvids.h>                      // Entry Ids
       
    22 #include    <MuiuMsvUiServiceUtilities.h>   // Messaging utilites
       
    23 #include	<PSVariables.h>
       
    24 #include	<mmsconst.h>					// KUidMsgSubTypeMmsAudioMsg
       
    25 
       
    26 #include    "NcnDebug.h"
       
    27 #include    "NcnMsvSessionObserverBase.h"
       
    28 #include    "NcnModelBase.h"
       
    29 #include    "NcnHandlerAudio.h"
       
    30 #include    "CNcnMsvSessionHandler.h"
       
    31 
       
    32 // CONSTANTS
       
    33 
       
    34 const TInt KNcnSMSInitRetryCount  = 20;
       
    35 const TTimeIntervalMicroSeconds32 KNcnSMSInitMaxSleepTime  = 2000000; // 2 seconds
       
    36 
       
    37 // ================= MEMBER FUNCTIONS =======================
       
    38 
       
    39 // C++ default constructor can NOT contain any code that
       
    40 // might leave.
       
    41 //
       
    42 CNcnMsvSessionObserverBase::CNcnMsvSessionObserverBase( 
       
    43     CNcnModelBase* aModel ) : 
       
    44     iModel( aModel )
       
    45     {
       
    46     // empty
       
    47     }
       
    48 
       
    49 // Symbian OS default constructor can leave.
       
    50 void CNcnMsvSessionObserverBase::ConstructL()
       
    51     {
       
    52     // add msv session handler observer
       
    53     iModel->MsvSessionHandler().AddObserverL( this );
       
    54     }
       
    55 
       
    56 // Destructor
       
    57 CNcnMsvSessionObserverBase::~CNcnMsvSessionObserverBase()
       
    58     {
       
    59     if( iModel )
       
    60         {
       
    61         // remove msv session handler observer
       
    62         iModel->MsvSessionHandler().RemoveObserver( this );
       
    63         }
       
    64     
       
    65     // deletate to session close handler
       
    66     TRAP_IGNORE( HandleMsvSessionClosedL() );
       
    67     }
       
    68 
       
    69 
       
    70 // ---------------------------------------------------------
       
    71 // NcnMsvSessionObserverBase::HandleMsvSessionReadyL
       
    72 // ---------------------------------------------------------
       
    73 //
       
    74 void CNcnMsvSessionObserverBase::HandleMsvSessionReadyL(
       
    75     CMsvSession& aMsvSession )
       
    76     {
       
    77     // check if there is sms service present in the device.
       
    78     CMsvEntrySelection* sel = NULL;
       
    79     TInt err;
       
    80     TTimeIntervalMicroSeconds32 waitTime = 100000; // 0,1 s
       
    81     
       
    82     for( int i = 0; i < KNcnSMSInitRetryCount; ++i )
       
    83 	    {
       
    84 	    TRAP( err, sel = MsvUiServiceUtilities::GetListOfAccountsWithMTML( 
       
    85 				aMsvSession, KNcnSmsUid, ETrue ) );
       
    86 		NCN_RDEBUG_INT( _L("CNcnMsvSessionObserverBase::HandleMsvSessionReadyL: MsvUiServiceUtilities::GetListOfAccountsWithMTML returned %d"), err );
       
    87 		if( err != KErrNone )		
       
    88 			{
       
    89 		    if( sel )
       
    90 		    	{
       
    91 		    	sel->Reset();
       
    92 		    	delete sel;
       
    93 		    	sel = NULL;
       
    94 		    	}			
       
    95 			NCN_RDEBUG_INT( _L("CNcnMsvSessionObserverBase::HandleMsvSessionReadyL: waiting #%d"), i + 1 );			
       
    96 			NCN_RDEBUG_INT( _L("CNcnMsvSessionObserverBase::HandleMsvSessionReadyL: Waiting %d microseconds"), waitTime.Int() );			
       
    97 			User::After( waitTime ); // CSI: 92 # We must use sleep here before we try to read sms status next time
       
    98             if( waitTime < KNcnSMSInitMaxSleepTime )
       
    99                 {
       
   100 			    waitTime = waitTime.Int() * 2;
       
   101                 }
       
   102             else                
       
   103                 {
       
   104                 waitTime = KNcnSMSInitMaxSleepTime;
       
   105                 }
       
   106 			NCN_RDEBUG( _L("CNcnMsvSessionObserverBase::HandleMsvSessionReadyL: Waiting for timer... DONE") );			
       
   107 			}
       
   108 		else
       
   109 			{
       
   110 			// SMS status successfully read
       
   111 			break; 				
       
   112 			}			
       
   113 	    }
       
   114 	
       
   115     // set sms service status to the model
       
   116     if( sel )
       
   117 	    {
       
   118 		NCN_RDEBUG_INT( _L("CNcnMsvSessionObserverBase::HandleMsvSessionReadyL: %d entries found"), sel->Count() );	    
       
   119 	    iModel->SmsServicePresent( sel->Count() != 0 );
       
   120 	    delete sel;
       
   121 	    sel = NULL;
       
   122 	    }
       
   123 	else 
       
   124 		{
       
   125 		NCN_RDEBUG( _L("CNcnMsvSessionObserverBase::HandleMsvSessionReadyL: 0 entries found") );		
       
   126 		iModel->SmsServicePresent( EFalse );					
       
   127 		}
       
   128     
       
   129     // get inbox folder
       
   130     iInboxFolder = 	
       
   131     	CMsvEntry::NewL( 
       
   132 			aMsvSession,
       
   133 			KMsvGlobalInBoxIndexEntryId,
       
   134 			TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByDateReverse, ETrue ) );        
       
   135     iInboxFolder->AddObserverL( *this );     
       
   136     
       
   137     NCN_RDEBUG( _L("CNcnMsvSessionObserverBase::HandleMsvSessionReadyL: DONE") );
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------
       
   141 // NcnMsvSessionObserverBase::HandleMsvSessionClosedL
       
   142 // ---------------------------------------------------------
       
   143 //    
       
   144 void CNcnMsvSessionObserverBase::HandleMsvSessionClosedL()
       
   145     {
       
   146     NCN_RDEBUG( _L("CNcnMsvSessionObserverBase::HandleMsvSessionClosedL >>") );
       
   147     if( iInboxFolder ) 
       
   148         {
       
   149         iInboxFolder->RemoveObserver( *this );
       
   150         delete iInboxFolder;
       
   151         iInboxFolder = NULL;
       
   152         }
       
   153     NCN_RDEBUG( _L("CNcnMsvSessionObserverBase::HandleMsvSessionClosedL <<") );
       
   154     }    
       
   155     
       
   156 // End of file