imstutils/imconversationview/imcvuiengine/src/cimcvengine.cpp
changeset 15 81eeb8c83ce5
parent 0 5e5d6b214f4f
equal deleted inserted replaced
0:5e5d6b214f4f 15:81eeb8c83ce5
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  engine class
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "cimcvengine.h"
       
    20 
       
    21 #include "cimcvenginechatcontainer.h"
       
    22 #include "cimcvenginemessagehandler.h"
       
    23 #include "cimcvenginemessagecreator.h"
       
    24 #include <e32base.h>
       
    25 #include <badesca.h>
       
    26 #include <e32property.h>
       
    27 //ximp includes
       
    28 #include <ximpclient.h>
       
    29 #include <ximpcontext.h>
       
    30 #include <ximpobjectfactory.h>
       
    31 #include <ximpidentity.h>
       
    32 #include <ximpstatus.h>
       
    33 #include <ximpcontextstateevent.h>
       
    34 #include <ximprequestcompleteevent.h>
       
    35 #include <ximpcontextstate.h>
       
    36 #include <ximpobjectfactory.h>
       
    37 #include <ximpidentity.h>
       
    38 #include <ximpstatus.h>
       
    39 
       
    40 // local includes
       
    41 #include "cimcvenginecontextobserver.h"
       
    42 #include "cimcvenginechatcontainer.h"
       
    43 #include "imcvlogger.h"
       
    44 #include "imcvuiliterals.h"
       
    45 //settings
       
    46 #include <spsettings.h>
       
    47 #include <spentry.h>
       
    48 #include <spproperty.h>
       
    49 
       
    50 #include "cimcvengineopenchats.h"
       
    51 #include "cimcvenginecchhandler.h"
       
    52 #include "conversations.h"
       
    53 
       
    54 #include <imconnectionproviderconsts.h>
       
    55 //branding related header files
       
    56 #include <mbsaccess.h>
       
    57 #include <mbselement.h>
       
    58 #include <cbsfactory.h>
       
    59 #include <utf.h>
       
    60 #include <gulicon.h>
       
    61 
       
    62 #define KMAX_SMILEY_COUNT 20
       
    63 
       
    64 // ================= MEMBER FUNCTIONS =======================
       
    65 
       
    66 // Two-phased constructor.
       
    67  CIMCVEngine* CIMCVEngine::NewL(TInt aServiceId, MIMCVEngineMessageCreator& aMessageCreater, 
       
    68         CBSFactory& aBrandingFactory )
       
    69     {
       
    70    	IM_CV_LOGS(TXT("CIMCVAppView::CIMCVEngine::NewL() start") );
       
    71     CIMCVEngine* self = new ( ELeave ) CIMCVEngine(aServiceId,aBrandingFactory);
       
    72 
       
    73     CleanupStack::PushL( self );
       
    74     self->ConstructL(aMessageCreater );
       
    75     CleanupStack::Pop( self );
       
    76     IM_CV_LOGS(TXT("CIMCVAppView::CIMCVEngine::NewL() end") );
       
    77     return self;
       
    78     }
       
    79 
       
    80 
       
    81 // ---------------------------------------------------------
       
    82 // CIMCVEngine::~CIMCVEngine()
       
    83 // Note the destruction order of objects.
       
    84 // ---------------------------------------------------------
       
    85 //
       
    86  CIMCVEngine::~CIMCVEngine()
       
    87     {
       
    88 	IM_CV_LOGS(TXT("CIMCVEngine destructor START") );
       
    89     if( iWait.IsStarted() )  
       
    90 	    {
       
    91 	    iWait.AsyncStop();  
       
    92 	    }
       
    93     Cancel();
       
    94     delete iCCHHandler;
       
    95     iAcceptedEventTypes.Reset();
       
    96 	iAcceptedEventTypes.Close();
       
    97 	
       
    98 	delete iOwnUserId;
       
    99 	delete iServiceName;
       
   100 	delete iBrandId;
       
   101 
       
   102 	if(iPresenceContext)
       
   103 		{
       
   104 		iPresenceContext->UnregisterObserver( *iContextEventObserver );
       
   105 		delete 	iPresenceContext;
       
   106 		iPresenceContext = NULL;
       
   107 		}
       
   108 	if(iClient)
       
   109 		{
       
   110 		delete iClient;	
       
   111 		iClient = NULL;
       
   112 		}
       
   113 	if(iContextEventObserver)
       
   114 		{
       
   115 		iContextEventObserver->UnRegisterObserver(iMessageHandler);
       
   116 		delete iContextEventObserver;
       
   117 		iContextEventObserver = NULL;	
       
   118 		}
       
   119 	if(iMessageHandler)
       
   120 		{
       
   121 		delete iMessageHandler;
       
   122 		iMessageHandler = NULL;
       
   123 		}
       
   124 	delete iChatInterface;
       
   125 
       
   126 	if( iBrandingAccess  )
       
   127 	    {
       
   128 	    iBrandingAccess->Close();
       
   129 	    iBrandingAccess = NULL;
       
   130 	    }
       
   131 	IM_CV_LOGS(TXT("CIMCVEngine destructor END") );
       
   132 
       
   133 #if 0
       
   134 	if( iSmileyArrayOwned )
       
   135 	    {
       
   136 		IM_CV_LOGS(TXT("CIMCVEngine::deleting icon STRING array owned") );
       
   137 	    iSmileyArray.ResetAndDestroy();
       
   138 	    }
       
   139 	IM_CV_LOGS(TXT("CIMCVEngine::RESETTING icon STRING array ") );
       
   140 	iSmileyArray.Reset();
       
   141 	
       
   142 	if( iSmileyDlgIconArrayOwned )
       
   143 	    {
       
   144 		IM_CV_LOGS(TXT("CIMCVEngine::deleting icon array owned") );
       
   145 	    iSmileyDlgIconArray.ResetAndDestroy();
       
   146 	    }
       
   147 	IM_CV_LOGS(TXT("CIMCVEngine::deleting icon array ") );	
       
   148 	iSmileyDlgIconArray.Reset();
       
   149 #endif	
       
   150 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::SendMessageL() start") );
       
   151 
       
   152 	}
       
   153 
       
   154 // ---------------------------------------------------------
       
   155 // CIMCVEngine::CIMCVEngine()
       
   156 // C++ default constructor can NOT contain any code, that
       
   157 // might leave.
       
   158 // ---------------------------------------------------------
       
   159 //
       
   160 CIMCVEngine::CIMCVEngine(TInt aServiceId,CBSFactory& aBrandingFactory) :
       
   161 CActive( CActive::EPriorityStandard ),
       
   162 iServiceId( aServiceId ),
       
   163 iBrandingFactory( aBrandingFactory ),
       
   164 iSmileyArrayOwned( ETrue ),
       
   165 iSmileyDlgIconArrayOwned( ETrue )
       
   166     {
       
   167     iOwnUserId = NULL;
       
   168     CActiveScheduler::Add( this );
       
   169     }
       
   170 // ---------------------------------------------------------
       
   171 // CIMCVEngine::ConstructL()
       
   172 // Symbian OS default constructor can leave.
       
   173 // ---------------------------------------------------------
       
   174 //
       
   175 void CIMCVEngine::ConstructL(MIMCVEngineMessageCreator& aMessageCreater)
       
   176     {
       
   177     IM_CV_LOGS(TXT("CIMCVAppView::CIMCVEngine::ConstructL()	start") );   
       
   178     iClient = MXIMPClient::NewClientL();
       
   179 	//Create new sink to receive ximp context events
       
   180 	iContextEventObserver = CIMCVEngineContextObserver::NewL();
       
   181 	
       
   182 	iChatInterface = CIMCVEngineChatContainer::NewL( iServiceId );
       
   183 	//Read the logged in status from CCH True/False
       
   184     TBool isCchEnebled = EFalse;
       
   185 	iCCHHandler = CIMCVEngineCchHandler::NewL(iServiceId, *this);
       
   186 	isCchEnebled = iCCHHandler->IsServiceLoggedIn();
       
   187 	
       
   188 	// Read User Id from CCH
       
   189 	iOwnUserId = HBufC::NewL(KMAXUSERIDLENGTH);
       
   190 	TPtr owndataPtr =  iOwnUserId->Des();	
       
   191 	GetUserIdL(owndataPtr ) ;
       
   192 	
       
   193 	//Read Servicename from CCH
       
   194     iServiceName = HBufC::NewL(KMAXUSERIDLENGTH);
       
   195 	TPtr srvNamePtr( iServiceName->Des() );	
       
   196 	GetServiceNameL( iServiceId, srvNamePtr );   
       
   197     
       
   198 	//Read the service state from CCH
       
   199     TCCHSubserviceState serviceState = ECCHUninitialized;    
       
   200     TInt error = iCCHHandler->GetServiceState( 
       
   201         			serviceState ); 
       
   202   
       
   203 	if ( ECCHEnabled == serviceState || isCchEnebled )
       
   204 		{
       
   205 		// register this to prsence context  
       
   206 		LoginL();
       
   207 		}
       
   208 	// Read the BrandId from SPsettings
       
   209 	iBrandId = HBufC8::NewL( KVIMPSTUISPSMaxPropertyLength );
       
   210 	TPtr8 brandidPtr(iBrandId->Des());
       
   211 	GetBrandIdL( iServiceId, brandidPtr );	
       
   212     
       
   213 	//Read BrandLanguage id from SPsettings
       
   214     iLanguageId = PropertyBrandLanguageL(iServiceId);    
       
   215 	
       
   216     ConstructBrandL();
       
   217     
       
   218 	if ( ECCHEnabled == serviceState || isCchEnebled )
       
   219 		{
       
   220 		iMessageHandler = CIMCVEngineMessageHandler::NewL( *iChatInterface, 
       
   221                                                         aMessageCreater,
       
   222                                                         iPresenceContext, 
       
   223 														iServiceId, 
       
   224 														owndataPtr );
       
   225 		}
       
   226 	else
       
   227 		{
       
   228 		iMessageHandler = CIMCVEngineMessageHandler::NewL( *iChatInterface, 
       
   229                                                             aMessageCreater, 
       
   230                                                             NULL, 
       
   231                                                             iServiceId, 
       
   232                                                             owndataPtr );
       
   233 			
       
   234 		}		
       
   235 														
       
   236 	iContextEventObserver->RegisterObserver(iMessageHandler);	
       
   237    	IM_CV_LOGS(TXT("CIMCVAppView::CIMCVEngine::ConstructL()	end") );
       
   238     }
       
   239 
       
   240 // ---------------------------------------------------------
       
   241 // CIMCVEngine::ConstructBrandL()
       
   242 // ---------------------------------------------------------
       
   243 //
       
   244 void CIMCVEngine::ConstructBrandL()
       
   245     {
       
   246     if(iBrandingAccess)
       
   247         {
       
   248         iBrandingAccess->Close();
       
   249         iBrandingAccess = NULL;
       
   250         }
       
   251     iBrandingAccess = iBrandingFactory.CreateAccessL( GetBrandId(), (TLanguage)GetLanguageId() );
       
   252     if(iBrandingAccess)
       
   253         {
       
   254         TInt totalCount = iBrandingAccess->GetIntL(KSmileycount);
       
   255         
       
   256         // Restricting the maximum number of smileys to KMAX_SMILEY_COUNT.
       
   257         if( totalCount > KMAX_SMILEY_COUNT )
       
   258             totalCount = KMAX_SMILEY_COUNT;
       
   259         HBufC* allSmileyString = iBrandingAccess->GetTextL(KSmileytext);
       
   260         CleanupStack::PushL(allSmileyString);   
       
   261         allSmileyString->Des().Delete(0, 1);
       
   262         allSmileyString->Des().Delete(((allSmileyString->Length())-1), 2);
       
   263         ParseAllSmileyStringL(totalCount, *allSmileyString);
       
   264         CleanupStack::PopAndDestroy(allSmileyString);
       
   265 
       
   266         TInt iconCount = iSmileyArray.Count();
       
   267         CGulIcon* icon = NULL;
       
   268         CFbsBitmap* bitmap = NULL;
       
   269         CFbsBitmap* mask = NULL; 
       
   270         HBufC* iconString = NULL;
       
   271         TInt err = KErrNotFound;
       
   272         for( TInt index = 0; index< iconCount; index++ )
       
   273             {
       
   274             iconString = iSmileyArray[index];
       
   275             TPtrC iconStringPtr = iconString->Des();          
       
   276             TBuf8<16> aUtf8; //            
       
   277             CnvUtfConverter::ConvertFromUnicodeToUtf8(aUtf8, iconStringPtr);            
       
   278             iBrandingAccess->GetBitmapL(aUtf8, bitmap, mask );
       
   279 			CleanupStack::PushL( bitmap );
       
   280 			CleanupStack::PushL( mask );
       
   281             icon = CGulIcon::NewL( bitmap, mask ); 
       
   282 			CleanupStack::Pop( 2 ); // bitmap ,mask
       
   283 		     
       
   284             err = iSmileyDlgIconArray.Append( icon );        
       
   285 			   
       
   286             if( err < 0)
       
   287                 {
       
   288                 delete icon;
       
   289                 icon = NULL;
       
   290                 }
       
   291             }
       
   292         }
       
   293      }
       
   294 
       
   295 // ---------------------------------------------------------
       
   296 // CIMCVEngine::GetSmileStringArray()
       
   297 // ---------------------------------------------------------
       
   298 //
       
   299 EXPORT_C RPointerArray<HBufC> CIMCVEngine::GetSmileStringArray()
       
   300     {   
       
   301     iSmileyArrayOwned = EFalse;
       
   302     return iSmileyArray;// ownership transfered
       
   303     }
       
   304 
       
   305 // ---------------------------------------------------------
       
   306 // CIMCVEngine::ParseAllSmileyStringL()
       
   307 // ---------------------------------------------------------
       
   308 //
       
   309 EXPORT_C RPointerArray<CGulIcon> CIMCVEngine::GetSmileyIconArray( )
       
   310     {
       
   311     iSmileyDlgIconArrayOwned = EFalse;
       
   312     return iSmileyDlgIconArray; // ownership transfered
       
   313     }
       
   314 // ---------------------------------------------------------
       
   315 // CIMCVEngine::ParseAllSmileyStringL()
       
   316 // ---------------------------------------------------------
       
   317 //
       
   318 void CIMCVEngine::ParseAllSmileyStringL(TInt aTotalCount , const TDesC& aAllSmileyString)
       
   319     {       
       
   320     TInt location = KErrNotFound;
       
   321     HBufC* string = aAllSmileyString.AllocLC();
       
   322     TPtr mainBufferPtr = string->Des();
       
   323     //make sure everything is fresh
       
   324     iSmileyArray.ResetAndDestroy();
       
   325     for(TInt i=0; i<aTotalCount; i++)
       
   326         {        
       
   327         location = mainBufferPtr.Locate(' ');
       
   328         if(location != KErrNotFound )
       
   329             {
       
   330             TPtrC smileStringPtr = mainBufferPtr.Left(location);
       
   331             HBufC* smileString = smileStringPtr.AllocL();
       
   332             iSmileyArray.Append(smileString);
       
   333             mainBufferPtr.Delete(0,location+1);
       
   334             }
       
   335         if( i == (aTotalCount -1 ))
       
   336             {
       
   337             //for last string
       
   338             HBufC* smileString = mainBufferPtr.AllocL();
       
   339             iSmileyArray.Append(smileString);
       
   340             }      
       
   341         } 
       
   342     CleanupStack::PopAndDestroy(string);   
       
   343     }
       
   344 
       
   345 // ---------------------------------------------------------
       
   346 // CIMCVEngine::ParseAllSmileyStringL()
       
   347 // ---------------------------------------------------------
       
   348 //
       
   349 EXPORT_C CGulIcon* CIMCVEngine::GetPresenceIconL(const TDesC8& aIconid)
       
   350     {
       
   351     CFbsBitmap* bitmap = NULL;
       
   352     CFbsBitmap* mask = NULL;
       
   353     CGulIcon* icon = NULL;
       
   354     iBrandingAccess->GetBitmapL(aIconid, bitmap, mask );
       
   355 	CleanupStack::PushL( bitmap );
       
   356 	CleanupStack::PushL( mask );
       
   357 	icon = CGulIcon::NewL( bitmap, mask ); 
       
   358 	CleanupStack::Pop( 2 ); // bitmap ,mask
       
   359     return icon;
       
   360     }
       
   361 // ---------------------------------------------------------
       
   362 // CIMCVEngine::CreateConnectionL()
       
   363 // ---------------------------------------------------------
       
   364 //
       
   365 void CIMCVEngine::CreateConnectionL() 
       
   366 	{
       
   367 	iPresenceContext = iClient->NewPresenceContextLC();
       
   368 	// ignore code scanner warning, it gives panic
       
   369 	CleanupStack::Pop();// because of LC method
       
   370 	// Read the ximpfw adaptation uid from SPsettings
       
   371 	TInt protocolUidValue = iCCHHandler->GetAdapterUidL(); ;	
       
   372 	// filter the event from ximpfw ,interested only login and request complete
       
   373 	iAcceptedEventTypes.Reset();
       
   374 	iAcceptedEventTypes.AppendL( MXIMPRequestCompleteEvent::KInterfaceId );
       
   375 	iAcceptedEventTypes.AppendL( MXIMPContextStateEvent::KInterfaceId );	
       
   376 		
       
   377 	TArray< TInt32 > eventFilterArray = iAcceptedEventTypes.Array();
       
   378 	// register this to prsence context   
       
   379 	iPresenceContext->RegisterObserverL( *iContextEventObserver, &eventFilterArray );
       
   380 	TUid protocolUid =TUid::Uid( protocolUidValue );
       
   381 	iContextEventObserver->GetConnectedSessionL(*iPresenceContext,iServiceId, protocolUid );
       
   382 	}
       
   383 // ---------------------------------------------------------
       
   384 // CIMCVEngine::ChatInterface()
       
   385 // ---------------------------------------------------------
       
   386 //
       
   387 EXPORT_C MIMCVEngineChatInterface& CIMCVEngine::ChatInterface() const
       
   388     {
       
   389     return *iChatInterface;
       
   390     }
       
   391 
       
   392 // ---------------------------------------------------------
       
   393 // CIMCVEngine::ChatInterface()
       
   394 // ---------------------------------------------------------
       
   395 //
       
   396 EXPORT_C MIMCVEngineMessageHandler& CIMCVEngine::MessageHandler() const
       
   397     {
       
   398     return *iMessageHandler;
       
   399     }
       
   400 
       
   401 // ---------------------------------------------------------
       
   402 // CIMCVEngine::ReadyForShutdown()
       
   403 // ---------------------------------------------------------
       
   404 //
       
   405 EXPORT_C TBool CIMCVEngine::ReadyForShutdown()
       
   406     {
       
   407     return !iContextEventObserver->IsLoggedIn();
       
   408     }
       
   409    
       
   410 // ---------------------------------------------------------
       
   411 // CIMCVEngine::IsLoggedIn()
       
   412 // ---------------------------------------------------------
       
   413 //
       
   414 EXPORT_C TBool CIMCVEngine::IsLoggedIn() const
       
   415 	{
       
   416     return iContextEventObserver->IsLoggedIn();	
       
   417     }
       
   418 
       
   419 // ---------------------------------------------------------
       
   420 // CIMCVEngine::GetLoggedInUserId()
       
   421 // ---------------------------------------------------------
       
   422 //
       
   423 EXPORT_C const TDesC& CIMCVEngine::GetLoggedInUserId() 
       
   424 	{
       
   425 	if(iOwnUserId)
       
   426 		{
       
   427 		return *iOwnUserId;
       
   428 		}
       
   429 	return KNullDesC;
       
   430 	}	
       
   431 // ---------------------------------------------------------
       
   432 // CIMCVEngine::ReleaseConnectionL()
       
   433 // ---------------------------------------------------------
       
   434 //
       
   435 EXPORT_C void CIMCVEngine::ReleaseConnectionL() 
       
   436 	{
       
   437 	if (iPresenceContext)
       
   438 	    {
       
   439 	    iContextEventObserver->ReleaseConnectionL(*iPresenceContext);
       
   440 	    }
       
   441 	}
       
   442 	
       
   443 // ---------------------------------------------------------
       
   444 // CIMCVEngine::DeleteContextL()
       
   445 // ---------------------------------------------------------
       
   446 //
       
   447 void CIMCVEngine::DeleteContextL() 
       
   448 	{
       
   449 	if(iPresenceContext)
       
   450 		{
       
   451 		iPresenceContext->UnregisterObserver( *iContextEventObserver );
       
   452 		delete 	iPresenceContext;
       
   453 		iPresenceContext = NULL;
       
   454 
       
   455 		}
       
   456 
       
   457 	}
       
   458 
       
   459 // ---------------------------------------------------------
       
   460 // CIMCVEngine::CreateContextL()
       
   461 // ---------------------------------------------------------
       
   462 //
       
   463 void CIMCVEngine::CreateContextL() 
       
   464 	{
       
   465 	if(!iPresenceContext)
       
   466 		{
       
   467 		CreateConnectionL();
       
   468 		iMessageHandler->ResetContextL(iPresenceContext); 
       
   469 		}
       
   470 	}
       
   471 // ---------------------------------------------------------
       
   472 // CIMCVEngine::GetLoggedInUserId()
       
   473 // ---------------------------------------------------------
       
   474 //
       
   475 EXPORT_C const TDesC8& CIMCVEngine::GetBrandId() 
       
   476     {
       
   477     if(iBrandId)
       
   478         {
       
   479         return *iBrandId;
       
   480         }
       
   481     return KNullDesC8;
       
   482     }   
       
   483 // ---------------------------------------------------------
       
   484 // CIMCVEngine::GetLoggedInUserId()
       
   485 // ---------------------------------------------------------
       
   486 //
       
   487 EXPORT_C TInt CIMCVEngine::GetLanguageId() 
       
   488     {
       
   489     return iLanguageId;
       
   490     }   
       
   491 
       
   492 
       
   493 // ---------------------------------------------------------
       
   494 // CIMCVEngine::CCHHandler()
       
   495 // ---------------------------------------------------------
       
   496 //
       
   497 EXPORT_C MIMCVEngineCchHandler& CIMCVEngine::CCHHandler() 
       
   498     {
       
   499     return *iCCHHandler;     
       
   500     } 
       
   501 
       
   502 // ---------------------------------------------------------
       
   503 // CIMCVEngine::ServiceName()
       
   504 // ---------------------------------------------------------
       
   505 //
       
   506 EXPORT_C const TDesC& CIMCVEngine::ServiceName() 
       
   507     {
       
   508     return *iServiceName;     
       
   509     } 
       
   510     
       
   511 
       
   512 // ---------------------------------------------------------
       
   513 // CIMCVEngine::GetLoggedInUserId()
       
   514 // ---------------------------------------------------------
       
   515 //
       
   516 
       
   517 EXPORT_C MIMCVEngineOpenChats& CIMCVEngine::OpenChats() 
       
   518 	{
       
   519 	return  iMessageHandler->OpenChats();
       
   520 	}
       
   521 
       
   522 
       
   523 // ---------------------------------------------------------
       
   524 // CIMCVEngine::GetServiceId()
       
   525 // ---------------------------------------------------------
       
   526 //
       
   527 EXPORT_C TInt CIMCVEngine::GetServiceId() 
       
   528 	{	
       
   529 	return iServiceId;
       
   530 	}
       
   531 		
       
   532 // ---------------------------------------------------------------------------
       
   533 // CIMCVEngine::GetServiceNameL()
       
   534 // ---------------------------------------------------------------------------
       
   535 //
       
   536 void CIMCVEngine::GetServiceNameL( 
       
   537     TUint32 aServiceId, TDes& aServiceName )
       
   538     {
       
   539     
       
   540     CSPSettings* settings = CSPSettings::NewLC();
       
   541     CSPEntry* entry = CSPEntry::NewLC();
       
   542     TRAPD( err, settings->FindEntryL( aServiceId, *entry ) );
       
   543     if ( !err )
       
   544         {
       
   545         aServiceName = entry->GetServiceName();
       
   546         }
       
   547     
       
   548     CleanupStack::PopAndDestroy( 2 );    
       
   549     }
       
   550     
       
   551     
       
   552 
       
   553 
       
   554 // ---------------------------------------------------------------------------
       
   555 // CIMCVEngine::GetBrandIdL()
       
   556 // ---------------------------------------------------------------------------
       
   557 //
       
   558 void CIMCVEngine::GetBrandIdL( 
       
   559     TUint32 aServiceId, TDes8& aBrandId )
       
   560     {
       
   561     HBufC* ret = HBufC::NewL( KVIMPSTUISPSMaxPropertyLength );
       
   562     CleanupStack::PushL( ret );
       
   563     TPtr retPtr( ret->Des() );
       
   564     
       
   565     CSPSettings* settings = CSPSettings::NewLC();
       
   566     CSPProperty* property = CSPProperty::NewLC();
       
   567     settings->FindPropertyL( aServiceId,
       
   568                                 EPropertyBrandId,
       
   569                                 *property );    
       
   570     if ( property )
       
   571         {
       
   572         property->GetValue( retPtr );
       
   573         aBrandId.Copy( retPtr );
       
   574         }
       
   575     CleanupStack::PopAndDestroy( 3 );  //property,settings,ret             
       
   576     }    
       
   577 
       
   578 
       
   579 
       
   580 // ---------------------------------------------------------------------------
       
   581 // CIMCVEngine::PropertyBrandLanguageL()
       
   582 // ---------------------------------------------------------------------------
       
   583 //
       
   584 TLanguage CIMCVEngine::PropertyBrandLanguageL( 
       
   585     TUint32 aServiceId ) 
       
   586     {
       
   587     
       
   588     // default to english
       
   589     TInt brandLanguage = ELangInternationalEnglish; 
       
   590     CSPSettings* settings = CSPSettings::NewLC();
       
   591     CSPProperty* property = CSPProperty::NewLC();
       
   592     settings->FindPropertyL( aServiceId,
       
   593                                 EPropertyBrandLanguage,
       
   594                                 *property );    
       
   595     if ( property )
       
   596         {
       
   597         property->GetValue( brandLanguage );
       
   598         }
       
   599     CleanupStack::PopAndDestroy( 2 ); // property,settings 
       
   600 
       
   601     return ((TLanguage) (brandLanguage) );
       
   602     }
       
   603 
       
   604 
       
   605 
       
   606 // ---------------------------------------------------------------------------
       
   607 // CIMCVEngine::PropertySettingsIdL()
       
   608 // ---------------------------------------------------------------------------
       
   609 //
       
   610 TInt CIMCVEngine::PropertySettingsIdL( 
       
   611     TUint32 aServiceId ) 
       
   612     {
       
   613     
       
   614     // default to english
       
   615     TInt settingsId = 0; 
       
   616     CSPSettings* settings = CSPSettings::NewLC();
       
   617     CSPProperty* property = CSPProperty::NewLC();
       
   618     settings->FindPropertyL( aServiceId,
       
   619                                 ESubPropertyIMSettingsId,
       
   620                                 *property );    
       
   621     if ( property )
       
   622         {
       
   623         property->GetValue( settingsId );
       
   624         }
       
   625     CleanupStack::PopAndDestroy( 2 );  // property,settings 
       
   626 
       
   627     return (settingsId);
       
   628     }
       
   629 
       
   630 
       
   631 // ---------------------------------------------------------------------------
       
   632 // CIMCVEngine::ResolveServiceStateL()
       
   633 // ---------------------------------------------------------------------------
       
   634 //
       
   635 EXPORT_C void CIMCVEngine::ResolveServiceStateL()
       
   636 	{
       
   637 	
       
   638 	if ((!IsLoggedIn()) && (iCCHHandler->IsServiceLoggedIn()))
       
   639 		{
       
   640 		IM_CV_LOGS(TXT("CIMCVEngine::ResolveServiceState() NOT LOGGED IN") );
       
   641 		iChatInterface->CloseAllContainers();
       
   642 		CreateContextL();	
       
   643 		}
       
   644 		
       
   645 	}
       
   646 // ---------------------------------------------------------------------------
       
   647 // CIMCVEngine::GetUserIdL()
       
   648 // ---------------------------------------------------------------------------
       
   649 //
       
   650 void CIMCVEngine::GetUserIdL(TPtr& aUserId ) 
       
   651     {
       
   652 	
       
   653 	HBufC* userId = iCCHHandler->GetUserIdL();
       
   654 	
       
   655 	if(userId)
       
   656 	    {
       
   657 	    TPtr userIdPtr( userId->Des() );
       
   658 
       
   659 	    aUserId.Copy( userIdPtr );
       
   660 	    }
       
   661 	delete userId;
       
   662 	
       
   663     }
       
   664 
       
   665 
       
   666 // ---------------------------------------------------------------------------
       
   667 // CIMCVEngine::LoginL()
       
   668 // ---------------------------------------------------------------------------
       
   669 //    
       
   670 EXPORT_C TInt CIMCVEngine::LoginL()
       
   671 	{
       
   672 	if (!IsLoggedIn())
       
   673 	    {	
       
   674 	    iState = ELogin;	
       
   675 	    IssueRequest();	
       
   676 	    // ignore codescanner warning ignored.
       
   677 	    if( !iWait.IsStarted() )  
       
   678 	        {
       
   679 	        // Code scanner warning "active object called without checking 
       
   680 	        // whether it is active or cancelling it first" ignored because
       
   681 	        // CActiveSchedulerWait is not an active object
       
   682 	        iWait.Start(); // CSI: 10 # See above
       
   683 	        }
       
   684 
       
   685 	    if ( EOperationInComplete == iState )	        
       
   686 	        {
       
   687 	        return KErrGeneral;				
       
   688 	        }
       
   689 	    }
       
   690 	return KErrNone;
       
   691 	}
       
   692 
       
   693 
       
   694 // --------------------------------------------------------------------------
       
   695 // CIMCVEngine::RunL
       
   696 // --------------------------------------------------------------------------
       
   697 //
       
   698 void CIMCVEngine::RunL()
       
   699     {
       
   700     switch( iState )
       
   701         {
       
   702         case ELogin:
       
   703             {
       
   704             //cch is not logged in
       
   705             if (!iCCHHandler->IsServiceLoggedIn())
       
   706 	            {
       
   707 				TInt error = iCCHHandler->EnableService();
       
   708 	            if (KErrNone != error)
       
   709 		            {
       
   710 					iState = EOperationInComplete; 	
       
   711 					IssueRequest();	            	
       
   712 		            }
       
   713 				else
       
   714 					{
       
   715 					iCCHHandler->RegisterObserver(this);	
       
   716 					}		            		            	
       
   717 	            }
       
   718 			else
       
   719 				{
       
   720 				//cch logged in but the ximp context is not logged in
       
   721 				if (!IsLoggedIn())
       
   722 					{
       
   723 					TRAPD(err,CreateConnectionL());
       
   724 					if(KErrNone == err )
       
   725 					    {
       
   726 					    iState = EOperationComplete;
       
   727 					    }
       
   728 					else
       
   729 					    {
       
   730 					    iState = EOperationInComplete;
       
   731 					    }
       
   732 					IssueRequest();	
       
   733 					}
       
   734 				}	            
       
   735             break;
       
   736             }
       
   737         
       
   738         case EOperationInComplete:
       
   739         	{
       
   740         	iCCHHandler->UnRegisterObserver();
       
   741         	if( iWait.IsStarted() )  
       
   742 		        {
       
   743 		        iWait.AsyncStop();  
       
   744 		        }
       
   745         	break;	
       
   746         	}
       
   747         	
       
   748         case EOperationComplete:
       
   749         	{
       
   750         	iCCHHandler->UnRegisterObserver();
       
   751         	if( iWait.IsStarted() )  
       
   752 		        {
       
   753 		        iWait.AsyncStop();  
       
   754 		        }
       
   755         	break;	
       
   756         	}
       
   757         	        	
       
   758         default:
       
   759             {
       
   760             // Do nothing
       
   761             break;
       
   762             }
       
   763         }
       
   764     }
       
   765 
       
   766 // --------------------------------------------------------------------------
       
   767 // CIMCVEngine::DoCancel
       
   768 // --------------------------------------------------------------------------
       
   769 //
       
   770 void CIMCVEngine::DoCancel()
       
   771     {
       
   772     }
       
   773 
       
   774 // --------------------------------------------------------------------------
       
   775 // CIMCVEngine::RunError
       
   776 // --------------------------------------------------------------------------
       
   777 //
       
   778 TInt CIMCVEngine::RunError( TInt /*aError*/ )
       
   779     {    
       
   780     return KErrNone;
       
   781     }
       
   782 	
       
   783 
       
   784 // --------------------------------------------------------------------------
       
   785 // CIMCVEngine::IssueRequest
       
   786 // --------------------------------------------------------------------------
       
   787 //
       
   788 void CIMCVEngine::IssueRequest()
       
   789     {
       
   790     if (IsActive())
       
   791 	    {
       
   792 	    Cancel();	
       
   793 	    }
       
   794 
       
   795     TRequestStatus* status = &iStatus;
       
   796     User::RequestComplete( status, KErrNone );
       
   797     SetActive();
       
   798     }
       
   799 
       
   800 
       
   801 // --------------------------------------------------------------------------
       
   802 // CIMCVEngine::ServiceStatusChanged
       
   803 // --------------------------------------------------------------------------
       
   804 //
       
   805 void CIMCVEngine::ServiceStatusChanged( TInt /*aServiceId*/,     								   
       
   806 	                                 TServiceState aServiceStatus )
       
   807 	{
       
   808 	
       
   809 	switch(aServiceStatus)
       
   810 		{
       
   811 		case MIMCVEngineCCHObserver::ENotLoggedIn:			
       
   812 			{
       
   813 			iState = EOperationInComplete;
       
   814 			IssueRequest();
       
   815 			break;	
       
   816 			}
       
   817 		case MIMCVEngineCCHObserver::EConnecting:
       
   818 			{
       
   819 			//Nothing to be done
       
   820 			break;	
       
   821 			}
       
   822 		case MIMCVEngineCCHObserver::ELogin:
       
   823 			{
       
   824 			iState = EOperationComplete;
       
   825 			IssueRequest();
       
   826 			break;	
       
   827 			}		
       
   828 		case MIMCVEngineCCHObserver::EDisconnecting:
       
   829 			{
       
   830 			//nothing to be done
       
   831 			break;	
       
   832 			}
       
   833 		
       
   834 		default:
       
   835 			{
       
   836 			break;	
       
   837 			}	
       
   838 		}
       
   839 	}
       
   840 // --------------------------------------------------------------------------
       
   841 // CIMCVEngine::CloseAllOpenChatsL
       
   842 // --------------------------------------------------------------------------
       
   843 //
       
   844 void CIMCVEngine::CloseAllOpenChatsL()
       
   845     {
       
   846 	IM_CV_LOGS(TXT("CIMCVEngine::CloseAllOpenChatsL() ***************************** START") );
       
   847     iMessageHandler->CloseAllConversationL();
       
   848 	IM_CV_LOGS(TXT("CIMCVEngine::CloseAllOpenChatsL() ***************************** END") );
       
   849     }
       
   850 	                                      
       
   851 //  End of File