servicewidget/servicewidgetdatapublisher/src/cservicewidgetservicemanager.cpp
changeset 0 5e5d6b214f4f
child 12 36d367c62acb
equal deleted inserted replaced
-1:000000000000 0:5e5d6b214f4f
       
     1 /*
       
     2 * Copyright (c) 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:  service manager for a specific service
       
    15  *                
       
    16  *
       
    17 */
       
    18 
       
    19  
       
    20 #include "cservicewidgetservicemanager.h"
       
    21 
       
    22 #include "cservicewidgetcontentpublisher.h"
       
    23 #include "cservicewidgetbrandhandler.h"
       
    24 #include "cservicewidgetmessagehandler.h"
       
    25 #include "cservicewidgetcchhandler.h"
       
    26 #include "cservicewidgetpresencehandler.h"
       
    27 #include "cservicewidgettimer.h"
       
    28 #include "servicewidgetcpglobals.h"
       
    29 #include "servicewidgetutils.h"
       
    30 #include "swpdebugtrace.h"
       
    31 #include <eikenv.h>
       
    32 #include <servicewidgetpluginres.rsg>
       
    33 #include <cchtypes.h>
       
    34 
       
    35 #include <cvimpstsettingsstore.h>
       
    36 #include <imcvlauncher.h>
       
    37 #include <xSPViewServices.h>
       
    38 #include <eikappui.h>
       
    39 
       
    40 #include <spsettings.h> 
       
    41 #include <spentry.h>
       
    42 #include <spproperty.h>
       
    43 
       
    44 #include <s32mem.h> //For Stream writing
       
    45 //---------------------------------------------------------------------------
       
    46 // CServiceWidgetServiceManager::NewL
       
    47 // ---------------------------------------------------------------------------
       
    48 // 
       
    49 CServiceWidgetServiceManager* CServiceWidgetServiceManager::NewL(TUint32 aServiceId,
       
    50 																 CServiceWidgetContentPublisher& aContentPublisher,
       
    51 																 MVIMPSTSettingsStore& aSettingStore )
       
    52     {
       
    53     TRACE_SWP(TXT("CServiceWidgetServiceManager::NewL() start") );
       
    54     CServiceWidgetServiceManager* self = new( ELeave )CServiceWidgetServiceManager( aServiceId, aContentPublisher , aSettingStore);
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL();
       
    57     CleanupStack::Pop( self );
       
    58     TRACE_SWP(TXT("CServiceWidgetServiceManager::NewL() end") );
       
    59     return self;
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // CServiceWidgetServiceManager::CServiceWidgetServiceManager
       
    64 // ---------------------------------------------------------------------------
       
    65 // 
       
    66 CServiceWidgetServiceManager::CServiceWidgetServiceManager(TUint32 aServiceId,
       
    67 														   CServiceWidgetContentPublisher& aContentPublisher,
       
    68 														   MVIMPSTSettingsStore& aSettingStore )
       
    69 	:iServiceId( aServiceId ),
       
    70 	iContentPublisher( aContentPublisher ),
       
    71 	iSettingStore( aSettingStore ),
       
    72 	iExecuteOperation( ESWAUnknown )
       
    73    {
       
    74    TRACE_SWP(TXT("CServiceWidgetServiceManager::CServiceWidgetServiceManager() start") );
       
    75    TRACE_SWP(TXT("CServiceWidgetServiceManager::CServiceWidgetServiceManager() start") );
       
    76    }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CServiceWidgetServiceManager::ConstructL
       
    80 // ---------------------------------------------------------------------------
       
    81 // 
       
    82 void CServiceWidgetServiceManager::ConstructL()
       
    83     {
       
    84 	TRACE_SWP(TXT("CServiceWidgetServiceManager::ConstructL() start") );
       
    85 	CSPSettings* settings = CSPSettings::NewLC(); 
       
    86 	// read service name    
       
    87 	CSPEntry* entry = CSPEntry::NewLC();
       
    88 	settings->FindEntryL( iServiceId, *entry ) ;
       
    89 	// set the service name to presence cache updater
       
    90     iServiceName = entry->GetServiceName().AllocL() ;
       
    91 	CleanupStack::PopAndDestroy(2); // entry,settings
       
    92 	
       
    93 	iBrandHandler = CServiceWidgetBrandHandler::NewL(iServiceId);
       
    94 	TRACE_SWP(TXT("CServiceWidgetServiceManager::ConstructL() end") );
       
    95     }
       
    96 // ---------------------------------------------------------------------------
       
    97 // CServiceWidgetServiceManager::ActivateWidgetL
       
    98 // ---------------------------------------------------------------------------
       
    99 // 
       
   100 void CServiceWidgetServiceManager::ActivateWidgetL(TDesC& aInstId)
       
   101     {
       
   102     TRACE_SWP(TXT("CServiceWidgetServiceManager::ActivateWidget() start") );
       
   103     iEnv = CEikonEnv::Static();
       
   104     //CCH handler initialize
       
   105     iCchHandler =  CServiceWidgetCchHandler::NewL( iServiceId, *this );
       
   106     TRACE_SWP(TXT("CServiceWidgetServiceManager::ActivateWidget() iBrandHandler created") );
       
   107     iServiceState = iCchHandler->ParseGetServiceState();
       
   108     iServiceviewId = iCchHandler->GetServiceViewIdL( iServiceTabUid );
       
   109     CreateHandlersL();
       
   110     //Initialize instance id of corresponding widget
       
   111     iInstId = aInstId.AllocL();
       
   112     iExecuteOperation = ESWALaunchServiceTab;
       
   113     
       
   114     TRACE_SWP(TXT("CServiceWidgetServiceManager::ActivateWidget() end") );
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // CServiceWidgetServiceManager::DeactivateWidgetL
       
   119 // ---------------------------------------------------------------------------
       
   120 // 
       
   121 void CServiceWidgetServiceManager::DeactivateWidgetL(TDesC& aInstId)
       
   122     {
       
   123     TRACE_SWP(TXT("CServiceWidgetServiceManager::DeactivateWidgetL() start") );
       
   124     
       
   125     iContentPublisher.RemoveWidgetDataL(*iServiceName,aInstId );
       
   126     
       
   127     delete iMessageHandler;
       
   128     iMessageHandler = NULL;
       
   129     
       
   130     if( iPresenceHandler)
       
   131         {
       
   132         iPresenceHandler->ReleaseConnectionL() ;  
       
   133         delete iPresenceHandler ;
       
   134         iPresenceHandler = NULL;
       
   135         }
       
   136     if( iWidgetTimer )
       
   137         {
       
   138         iWidgetTimer->StopListening();
       
   139         delete iWidgetTimer;
       
   140         iWidgetTimer = NULL;
       
   141         }
       
   142     
       
   143     delete iCchHandler;
       
   144     iCchHandler = NULL;
       
   145     
       
   146     delete iInstId;
       
   147     iInstId = NULL;
       
   148     
       
   149     iIsWidgetSuspended = EFalse;
       
   150     iExecuteOperation = ESWAUnknown;
       
   151     TRACE_SWP(TXT("CServiceWidgetServiceManager::DeactivateWidgetL() end") );
       
   152     }
       
   153 // ---------------------------------------------------------------------------
       
   154 // CServiceWidgetServiceManager::WidgetSuspended
       
   155 // ---------------------------------------------------------------------------
       
   156 // 
       
   157 void CServiceWidgetServiceManager::WidgetSuspended( TBool aIsWidgetSuspended )
       
   158     {
       
   159     iIsWidgetSuspended  = aIsWidgetSuspended;
       
   160     }
       
   161 // ---------------------------------------------------------------------------
       
   162 // CServiceWidgetServiceManager::~CServiceWidgetServiceManager
       
   163 // ---------------------------------------------------------------------------
       
   164 // 
       
   165 CServiceWidgetServiceManager::~CServiceWidgetServiceManager()
       
   166     {
       
   167     TRACE_SWP(TXT("CServiceWidgetServiceManager::~CServiceWidgetServiceManager() start") );
       
   168     delete iMessageHandler;
       
   169     if( iPresenceHandler)
       
   170 		{
       
   171 		TRAP_IGNORE( iPresenceHandler->ReleaseConnectionL() );	
       
   172 		delete iPresenceHandler ;
       
   173 		iPresenceHandler = NULL;
       
   174 		}
       
   175 	delete iCchHandler;
       
   176 	
       
   177 	delete iServiceName;
       
   178 	
       
   179     if( iWidgetTimer )
       
   180 	    {
       
   181 	    iWidgetTimer->StopListening();
       
   182 	    delete iWidgetTimer;
       
   183         }
       
   184     delete iBrandHandler;
       
   185     
       
   186     delete iInstId;
       
   187     
       
   188     TRACE_SWP(TXT("CServiceWidgetServiceManager::~CServiceWidgetServiceManager() end") );
       
   189    	}
       
   190   // ---------------------------------------------------------------------------
       
   191 // CServiceWidgetServiceManager::UpdateContentsL
       
   192 // ----------------------------------------------------------------------------
       
   193 // 
       
   194 void CServiceWidgetServiceManager::UpdateContentsL()
       
   195     {
       
   196     TRACE_SWP(TXT("CServiceWidgetServiceManager::UpdateContentsL() start") );
       
   197     if( !iIsWidgetSuspended )
       
   198         {
       
   199         SetCurrentTextDataL(); // to set the data in box 2 and 4 : Own id and new message or invite or presence
       
   200         }
       
   201    	TRACE_SWP(TXT("CServiceWidgetServiceManager::UpdateContentsL() end") );
       
   202     }
       
   203  
       
   204  // ---------------------------------------------------------------------------
       
   205 // CServiceWidgetServiceManager::SetCurrentTextDataL
       
   206 // ----------------------------------------------------------------------------
       
   207 // 
       
   208 void CServiceWidgetServiceManager::SetCurrentTextDataL()
       
   209     {
       
   210     TRACE_SWP(TXT("CServiceWidgetServiceManager::SetCurrentTextDataL() start") );
       
   211     iServiceState = iCchHandler->ParseGetServiceState();
       
   212 
       
   213     TWSPresenceStatus showIcon = EWSLast;
       
   214     iExecuteOperation = ESWALaunchServiceTab;
       
   215 
       
   216     TBuf<KIMWCP_FIRSTTEXT_SIZE> firstText( KNullDesC );
       
   217     TBuf<KIMWCP_SECONDTEXT_SIZE> SecondText( KNullDesC);
       
   218     
       
   219     TRACE_SWP(TXT("CServiceWidgetServiceManager::SetCurrentTextDataL() service is complete") );
       
   220     // service configured correctly
       
   221     TPtrC serviceName = iServiceName->Left( KIMWCP_FIRSTTEXT_SIZE );
       
   222     TPtrC ownUser = ServiceWidgetUtils::DisplayId( iCchHandler->OwnUserIdL().Left( KIMWCP_FIRSTTEXT_SIZE  ) );
       
   223     switch( iServiceState )
       
   224         {
       
   225         case ESWSNetworkConnecting:
       
   226             {
       
   227             TRACE_SWP(TXT("CServiceWidgetServiceManager::SetCurrentTextDataL() Connecting") );
       
   228             firstText.Append(ownUser);
       
   229             HBufC* str = ServiceWidgetUtils::LoadResourceLC( R_QTN_SERVTAB_WIDGET_CONNECTING,iEnv );
       
   230             if( str )
       
   231                 {
       
   232                 SecondText.Append( *str );
       
   233                 CleanupStack::PopAndDestroy(str); //str	
       
   234                 }
       
   235             break;	
       
   236             }
       
   237         case ESWSUpdatingContacts:
       
   238         case ESWSRegistered:
       
   239             {
       
   240             TRACE_SWP(TXT("CServiceWidgetServiceManager::SetCurrentTextDataL() Enabled") );
       
   241             firstText.Append(ownUser );
       
   242             TWServiceOperationId operationId = EWSOperationUnknown;
       
   243             HBufC* tempValue = NULL;
       
   244             if( iPresenceHandler )
       
   245                 {
       
   246                 // presence service supported 
       
   247                 // take the ongoing operation
       
   248                 showIcon = iPresenceHandler->GetOwnStatus();
       
   249                 operationId = iPresenceHandler->GetOngoingOperationId();	
       
   250                 if( operationId != EWSOperationComplete )
       
   251                     {
       
   252                     // fetching is on going
       
   253                     tempValue = ServiceWidgetUtils::LoadResourceLC(R_QTN_SERVTAB_WIDGET_UPDATING ,iEnv );
       
   254                     }
       
   255                 }
       
   256             if( !tempValue)
       
   257                 {
       
   258                 // second row data is empty ,read it
       
   259                 tempValue = GetSecondRowDataLC();	
       
   260                 }
       
   261             if( tempValue )
       
   262                 {
       
   263                 TPtrC tempValuePtr( tempValue->Des() ); 
       
   264                 SecondText.Append( tempValuePtr );
       
   265                 CleanupStack::PopAndDestroy(tempValue); // tempValue	
       
   266                 }
       
   267             break;	
       
   268             }
       
   269         case ESWSNetworkDisConnecting:
       
   270             {
       
   271             TRACE_SWP(TXT("CServiceWidgetServiceManager::SetCurrentTextDataL() Disconnecting") );
       
   272             firstText.Append(ownUser );
       
   273             HBufC* str = ServiceWidgetUtils::LoadResourceLC( R_QTN_SERVTAB_WIDGET_LOGGINGOUT ,iEnv);
       
   274             if( str )
       
   275                 {
       
   276                 SecondText.Append( *str );
       
   277                 CleanupStack::PopAndDestroy(str); //str	
       
   278                 }
       
   279             break;	
       
   280             }
       
   281         case ESWSWaitingForNetwork:
       
   282             {
       
   283             TRACE_SWP(TXT("CServiceWidgetServiceManager::SetCurrentTextDataL() Waiting for connection") );
       
   284             // waiting for network connection mostly for service which has ALR support
       
   285             firstText.Append(ownUser );
       
   286             HBufC* str = ServiceWidgetUtils::LoadResourceLC( R_QTN_SERVTAB_WIDGET_WAITING ,iEnv);
       
   287             if( str )
       
   288                 {
       
   289                 SecondText.Append( *str );
       
   290                 CleanupStack::PopAndDestroy(str); //str	
       
   291                 }
       
   292             break;
       
   293             }
       
   294         case ESWSNotRegistered:
       
   295         default :
       
   296             {
       
   297             TRACE_SWP(TXT("CServiceWidgetServiceManager::SetCurrentTextDataL() ECCHDisabled ||  default ") );
       
   298             firstText.Append(serviceName );
       
   299             HBufC* str = ServiceWidgetUtils::LoadResourceLC( R_QTN_SERVTAB_WIDGET_LOGIN ,iEnv );
       
   300             if( str )
       
   301                 {
       
   302                 SecondText.Append( *str );
       
   303                 CleanupStack::PopAndDestroy(str); //str	
       
   304                 }
       
   305             iExecuteOperation = ESWALaunchSTAutoLogin;
       
   306             TInt isSuccessfullLogin = KErrNone;
       
   307             iSettingStore.GetL(iServiceId, EServiceSuccessfullLogin, isSuccessfullLogin );
       
   308             if( isSuccessfullLogin )
       
   309                 {
       
   310                 iExecuteOperation = ESWAStartLogin;
       
   311                 }
       
   312             break;	
       
   313             }
       
   314         }
       
   315 //Data to publish service Icon
       
   316     TInt sericonbitmapHandle = 0 ;
       
   317     TInt sericonmaskHandle  = 0 ;
       
   318     iBrandHandler->GetStatusBitmapL( EWSServiceIcon, sericonbitmapHandle, sericonmaskHandle ) ;
       
   319     //data to publish presence icon
       
   320     TInt bitmapHandle = 0;
       
   321     TInt maskHandle = 0 ;
       
   322     iBrandHandler->GetStatusBitmapL( showIcon, bitmapHandle, maskHandle ) ;
       
   323     // publish the data to widget
       
   324     iContentPublisher.PublishDataWithActionL( *iServiceName,
       
   325                                               *iInstId,
       
   326                                                firstText, 
       
   327                                                SecondText,
       
   328                                                bitmapHandle, 
       
   329                                                maskHandle,
       
   330                                                sericonbitmapHandle, 
       
   331                                                sericonmaskHandle
       
   332     );
       
   333     TRACE_SWP(TXT("CServiceWidgetServiceManager::SetCurrentTextDataL() end") );
       
   334     }
       
   335   
       
   336 // ---------------------------------------------------------------------------
       
   337 // CServiceWidgetServiceManager::GetSecondRowDataLC
       
   338 // ---------------------------------------------------------------------------
       
   339 // 
       
   340 HBufC* CServiceWidgetServiceManager::GetSecondRowDataLC()  
       
   341 	{
       
   342 	TRACE_SWP(TXT("CServiceWidgetServiceManager::GetSecondRowDataLC() start ") );
       
   343 	HBufC* text = HBufC::NewLC(KIMWCP_SECONDTEXT_SIZE);
       
   344 	TPtr textPtr( text->Des() );
       
   345 	TInt unreadCount = 0;
       
   346 	TInt inviteCount = 0;
       
   347 	HBufC* str = NULL;
       
   348 	
       
   349 	if( iMessageHandler)
       
   350 		{
       
   351 		TRACE_SWP(TXT("CServiceWidgetServiceManager::GetSecondRowDataLC() iMessageHandler  ") );
       
   352 		unreadCount = iMessageHandler->GetUnreadMessageCountL();
       
   353 		}
       
   354 	if( iPresenceHandler)
       
   355 		{
       
   356 		TRACE_SWP(TXT("CServiceWidgetServiceManager::GetSecondRowDataLC() iPresenceHandler  ") );
       
   357 		inviteCount = iPresenceHandler->GetInviteCounts();
       
   358 		}
       
   359 	if( ( static_cast<TIMWidgetContentPriority>( iPriority ) == EIMNewMessage) 
       
   360 		&& unreadCount ) // match the priority
       
   361 		{
       
   362 		TRACE_SWP(TXT("CServiceWidgetServiceManager::GetSecondRowDataLC() unreadCount %d  "), unreadCount );
       
   363 		if( iMessageHandler->IsSingleMessageSender() )
       
   364 			{
       
   365 			// single sender launch conversation view 
       
   366 			iExecuteOperation = ESWALaunchConverView ;	
       
   367 			}
       
   368 		if( unreadCount == 1 )
       
   369 			{
       
   370 			// exactly one message show singular form
       
   371 			str = ServiceWidgetUtils::LoadResourceLC( R_QTN_SERVTAB_WIDGET_ONENEWMSG , iEnv);	
       
   372 			}
       
   373 		else
       
   374 			{
       
   375 			//  more than one message show plural form
       
   376 			str = ServiceWidgetUtils::LoadResourceLC( R_QTN_SERVTAB_WIDGET_NEWMSGS, unreadCount, iEnv );		
       
   377 			}
       
   378 		if( str )
       
   379 			{
       
   380 			textPtr.Append( *str );
       
   381 			CleanupStack::PopAndDestroy(str); //str	
       
   382 			}
       
   383        	}
       
   384      else if( ( static_cast<TIMWidgetContentPriority>( ++iPriority ) == EIMFriendInvite ) 
       
   385      	&& inviteCount )
       
   386 		 // match the priority
       
   387 		{
       
   388 		TRACE_SWP(TXT("CServiceWidgetServiceManager::GetSecondRowDataLC() inviteCount %d  "), inviteCount );
       
   389 		if( inviteCount == 1 )
       
   390 			{
       
   391 			// exactly one request show singular form
       
   392 			str = ServiceWidgetUtils::LoadResourceLC( R_QTN_SERVTAB_WIDGET_ONEPENDREQ ,iEnv );	
       
   393 			}
       
   394 		else
       
   395 			{
       
   396 			//  more than one request show plural form
       
   397 			str = ServiceWidgetUtils::LoadResourceLC( R_QTN_SERVTAB_WIDGET_PENDREQ, inviteCount, iEnv );		
       
   398 			}
       
   399 		if( str )
       
   400 			{
       
   401 			textPtr.Append( *str );
       
   402 			CleanupStack::PopAndDestroy(str); //str	
       
   403 			}
       
   404 		} 
       
   405   	else if( iPresenceHandler )// this is next priority
       
   406 		{
       
   407 		TRACE_SWP(TXT("CServiceWidgetServiceManager::GetSecondRowDataLC() iPresenceHandler ") );
       
   408 		TInt totalCount = iPresenceHandler->AllBuddyCount();
       
   409 		TInt onlineCount = iPresenceHandler->OnlineBuddyCount();
       
   410 		TRACE_SWP(TXT("CServiceWidgetServiceManager::GetSecondRowDataLC() totalCount %d "), totalCount);
       
   411 		TRACE_SWP(TXT("CServiceWidgetServiceManager::GetSecondRowDataLC() onlineCount %d "), onlineCount);	
       
   412 		// array to append online / totlal counts
       
   413 		CArrayFix<TInt>* intArray = new ( ELeave ) CArrayFixFlat<TInt>( 2 );
       
   414 		CleanupStack::PushL( intArray );
       
   415 		intArray->AppendL( onlineCount );
       
   416 		intArray->AppendL( totalCount );
       
   417 		str = ServiceWidgetUtils::LoadResourceLC( R_QTN_SERVTAB_WIDGET_ONLINESTATUS, *intArray , iEnv );
       
   418 		if( str )
       
   419 			{
       
   420 			textPtr.Append( *str );
       
   421 			CleanupStack::PopAndDestroy(str); //str	
       
   422 			}
       
   423 		CleanupStack::PopAndDestroy(intArray); //intArray	
       
   424 		}
       
   425 	else
       
   426 		{
       
   427 		// nothing to show in online case ,show "You are online"
       
   428 		str = ServiceWidgetUtils::LoadResourceLC( R_QTN_SERVTAB_WIDGET_AVAILABLE ,iEnv );	
       
   429 		if( str )
       
   430 			{
       
   431 			textPtr.Append( *str );
       
   432 			CleanupStack::PopAndDestroy(str); //str	
       
   433 			}
       
   434 		}
       
   435 	ResetPriority(); // reset to high again
       
   436 	TRACE_SWP(TXT("CServiceWidgetServiceManager::GetSecondRowDataLC() end ") );
       
   437 	return text; // ownership to caller
       
   438 	}
       
   439    	
       
   440 // ---------------------------------------------------------------------------
       
   441 // CServiceWidgetServiceManager::HandleNewMessageL
       
   442 // ---------------------------------------------------------------------------
       
   443 // 
       
   444 void CServiceWidgetServiceManager::HandleNewMessageL(const TDesC& aSenderId ,const TDesC& aMessageText)  
       
   445 	{
       
   446 	TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleNewMessageL() start ") );
       
   447 	if( !iIsWidgetSuspended )
       
   448 	    {
       
   449 	    TBuf<KIMWCP_FIRSTTEXT_SIZE> firstText;
       
   450 	    TBuf<KIMWCP_SECONDTEXT_SIZE> secondText;
       
   451 	    TBuf<KIMWCP_ADD_DATA_SIZE> additionalData( KNullDesC);
       
   452 	    HBufC* str = ServiceWidgetUtils::LoadResourceLC( R_QTN_SERVTAB_WIDGET_FRIEND, 
       
   453 	            ServiceWidgetUtils::DisplayId( aSenderId ),
       
   454 	            iEnv  );
       
   455 	    if( str )
       
   456 	        {
       
   457 	        TPtr strPtr( str->Des() );
       
   458 	        firstText.Append( strPtr.Left( KIMWCP_FIRSTTEXT_SIZE ) );
       
   459 	        CleanupStack::PopAndDestroy(str); //str	
       
   460 	        }
       
   461 	    secondText.Append( aMessageText.Left( KIMWCP_SECONDTEXT_SIZE ) );
       
   462 
       
   463 	    additionalData.Append( aSenderId.Left( KIMWCP_ADD_DATA_SIZE ) ) ;
       
   464 	    
       
   465 	    //Data to be published for service icon
       
   466 	    TInt sericonbitmapHandle = 0 ;
       
   467 	    TInt sericonmaskHandle  = 0 ;
       
   468 	    iBrandHandler->GetStatusBitmapL( EWSServiceIcon, sericonbitmapHandle, sericonmaskHandle ) ;
       
   469 	    
       
   470 	    TInt bitmapHandle = 0;
       
   471 	    TInt maskHandle = 0 ;
       
   472 	    iBrandHandler->GetStatusBitmapL( EWSNewMessage, bitmapHandle, maskHandle ) ;
       
   473 	    // publish the new message icon with all other data  
       
   474 	    iContentPublisher.PublishDataWithActionL( *iServiceName,
       
   475 	                                               *iInstId,
       
   476                                                     firstText,
       
   477                                                     secondText ,
       
   478                                                     bitmapHandle,
       
   479                                                     maskHandle,
       
   480                                                     sericonbitmapHandle, 
       
   481                                                     sericonmaskHandle
       
   482                                                     );
       
   483 	     iExecuteOperation = ESWALaunchConverView;
       
   484          if( iWidgetTimer )
       
   485 	        {
       
   486 	        TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleNewMessageL() timer started ") );
       
   487 	        iWidgetTimer->StopListening();
       
   488 	        iWidgetTimer->StartListening( KTimerInterval );	
       
   489 	        }
       
   490 	    }
       
   491 	TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleNewMessageL() end ") );
       
   492 	}
       
   493   
       
   494   // ---------------------------------------------------------------------------
       
   495 // CServiceWidgetServiceManager::HandleAddRequestL
       
   496 // ---------------------------------------------------------------------------
       
   497 // 
       
   498 void CServiceWidgetServiceManager::HandleAddRequestL(const TDesC& aRequesterId )     
       
   499 	{
       
   500 	TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleAddRequestL() start ") );
       
   501 	if( !iIsWidgetSuspended )
       
   502 	    {
       
   503 	    TBuf<KIMWCP_FIRSTTEXT_SIZE> firstText;
       
   504 	    TBuf<KIMWCP_SECONDTEXT_SIZE> secondText;
       
   505 
       
   506 	    HBufC* str = ServiceWidgetUtils::LoadResourceLC( R_QTN_SERVTAB_WIDGET_INVITE ,iEnv );  
       
   507 	    if( str )
       
   508 	        {
       
   509 	        TPtr strPtr( str->Des() );
       
   510 	        firstText.Append( strPtr.Left( KIMWCP_FIRSTTEXT_SIZE ) );
       
   511 	        CleanupStack::PopAndDestroy(str); //str    
       
   512 	        }
       
   513 	    secondText.Append( ServiceWidgetUtils::DisplayId( aRequesterId ).Left( KIMWCP_SECONDTEXT_SIZE ) );
       
   514 	    // publish the last icon which is empty 
       
   515 	    TBuf<KIMWCP_ADD_DATA_SIZE> additionalData( KNullDesC);
       
   516 	    //Data to be published for service icon
       
   517 	    TInt sericonbitmapHandle = 0 ;
       
   518 	    TInt sericonmaskHandle  = 0 ;
       
   519 	    iBrandHandler->GetStatusBitmapL( EWSServiceIcon, sericonbitmapHandle, sericonmaskHandle ) ;
       
   520 	    
       
   521 	    TInt bitmapHandle = 0;
       
   522 	    TInt maskHandle = 0 ;
       
   523 	    iBrandHandler->GetStatusBitmapL( EWSLast, bitmapHandle, maskHandle ) ;
       
   524         //Publish all data
       
   525 	    iContentPublisher.PublishDataWithActionL(*iServiceName,
       
   526 	                                             *iInstId,
       
   527                                                 firstText,
       
   528                                                 secondText,
       
   529                                                 bitmapHandle,
       
   530                                                 maskHandle,
       
   531                                                 sericonbitmapHandle, 
       
   532                                                 sericonmaskHandle
       
   533                                             );
       
   534 	    iExecuteOperation = ESWALaunchServiceTab;
       
   535 	    if( iWidgetTimer )
       
   536 	        {
       
   537 	        TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleAddRequestL() timer started ") );
       
   538 	        iWidgetTimer->StopListening();
       
   539 	        iWidgetTimer->StartListening( KTimerInterval );	
       
   540 	        }
       
   541 	    }
       
   542     TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleAddRequestL() start ") );
       
   543 	}
       
   544 	
       
   545 // ---------------------------------------------------------------------------
       
   546 // CServiceWidgetServiceManager::HandleCountChangedL
       
   547 // ---------------------------------------------------------------------------
       
   548 // 
       
   549 void CServiceWidgetServiceManager::HandleCountChangedL()  
       
   550 	{
       
   551 	TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleCountChangedL() start ") );
       
   552 	UpdateContentsL(); // set new data
       
   553 	TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleCountChangedL() end ") );
       
   554 	}
       
   555 
       
   556 // ---------------------------------------------------------------------------
       
   557 // CServiceWidgetServiceManager::HandleChangeL
       
   558 // ---------------------------------------------------------------------------
       
   559 // 
       
   560 void CServiceWidgetServiceManager::HandleChangeL()  
       
   561 	{
       
   562 	TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleChangeL() start ") );
       
   563 	UpdateContentsL(); // new data	
       
   564 	TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleChangeL() end ") );  
       
   565 	}
       
   566 
       
   567 // ---------------------------------------------------------------------------
       
   568 // CServiceWidgetServiceManager::HandleBuddyPresenceChangeL
       
   569 // ---------------------------------------------------------------------------
       
   570 // 
       
   571 void CServiceWidgetServiceManager::HandleBuddyPresenceChangeL(const TDesC& aBuddyId, 
       
   572                                                             TWSPresenceStatus aStatus,
       
   573                                                             const TDesC& aStatusText )  
       
   574     {
       
   575     TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleBuddyPresenceChangeL() start ") );
       
   576     if( !iIsWidgetSuspended )
       
   577         {
       
   578         TBuf<KIMWCP_FIRSTTEXT_SIZE> firstText;
       
   579         TBuf<KIMWCP_SECONDTEXT_SIZE> secondText;
       
   580         HBufC* str = ServiceWidgetUtils::LoadResourceLC( R_QTN_SERVTAB_WIDGET_FRIEND, 
       
   581                                                        ServiceWidgetUtils::DisplayId( aBuddyId ),
       
   582                                                            iEnv  );
       
   583         if( str )
       
   584             {
       
   585             TPtr strPtr( str->Des() );
       
   586             firstText.Append( strPtr.Left( KIMWCP_FIRSTTEXT_SIZE ) );
       
   587             CleanupStack::PopAndDestroy(str); //str    
       
   588             }
       
   589         HBufC* statusText = NULL;
       
   590         HBufC* status = NULL;
       
   591         if( aStatusText.Length() )
       
   592             {
       
   593             statusText = ServiceWidgetUtils::LoadResourceLC( R_QTN_SERVTAB_WIDGET_STATUS, 
       
   594                     ServiceWidgetUtils::DisplayId( aStatusText ),
       
   595                     iEnv  );
       
   596             }
       
   597         else
       
   598             { 
       
   599             TInt statusResId = R_QTN_SERVTAB_WIDGET_OFFLINE;
       
   600             switch( aStatus )
       
   601                 {
       
   602                 case EWSOnline:
       
   603                     {
       
   604                     statusResId = R_QTN_SERVTAB_WIDGET_ONLINE;
       
   605                     break;
       
   606                     }
       
   607                 case EWSAway:
       
   608                     {
       
   609                     statusResId = R_QTN_SERVTAB_WIDGET_AWAY;
       
   610                     break;
       
   611                     }
       
   612                 case EWSbusy:
       
   613                     {
       
   614                     statusResId = R_QTN_SERVTAB_WIDGET_BUSY;
       
   615                     break;
       
   616                     }
       
   617 
       
   618                 case EWSDoNotDisturb:
       
   619                     {
       
   620                     statusResId = R_QTN_SERVTAB_WIDGET_DND;
       
   621                     break;
       
   622                     }
       
   623                 case EWSOnPhone:
       
   624                     {
       
   625                     statusResId = R_QTN_SERVTAB_WIDGET_ONTHEPHONE;
       
   626                     break;
       
   627                     }
       
   628                 case EWSOffline:
       
   629                 default:
       
   630                     {
       
   631                     statusResId = R_QTN_SERVTAB_WIDGET_OFFLINE;
       
   632                     }
       
   633                 }
       
   634             status = ServiceWidgetUtils::LoadResourceLC( statusResId, iEnv  ); 
       
   635             if( status )
       
   636                 {
       
   637                 statusText = ServiceWidgetUtils::LoadResourceLC( R_QTN_SERVTAB_WIDGET_STATUS,
       
   638                         *status,
       
   639                         iEnv  );
       
   640                 }
       
   641             }
       
   642         if( statusText )
       
   643             {
       
   644             TPtr statusTextPtr( statusText->Des() );
       
   645             secondText.Append( statusTextPtr.Left( KIMWCP_SECONDTEXT_SIZE ) );
       
   646             CleanupStack::PopAndDestroy(); //statusText
       
   647             if( status )
       
   648                 {
       
   649                 CleanupStack::PopAndDestroy(status); //status 
       
   650                 }
       
   651              
       
   652             }
       
   653         //Data to be published for service Icon
       
   654         TInt sericonbitmapHandle = 0 ;
       
   655         TInt sericonmaskHandle  = 0 ;
       
   656         iBrandHandler->GetStatusBitmapL( EWSServiceIcon, sericonbitmapHandle, sericonmaskHandle ) ;
       
   657         //////////////////////////////////////////
       
   658         TInt bitmapHandle = 0;
       
   659         TInt maskHandle = 0 ;
       
   660         iBrandHandler->GetStatusBitmapL( aStatus, bitmapHandle, maskHandle ) ;
       
   661         TBuf<KIMWCP_ADD_DATA_SIZE> additionalData( KNullDesC);
       
   662         iContentPublisher.PublishDataWithActionL(*iServiceName,
       
   663                                                  *iInstId,
       
   664                                                 firstText, 
       
   665                                                 secondText,
       
   666                                                 bitmapHandle,
       
   667                                                 maskHandle,
       
   668                                                 sericonbitmapHandle, 
       
   669                                                 sericonmaskHandle
       
   670                                                 );
       
   671         iExecuteOperation = ESWALaunchServiceTab;
       
   672         if( iWidgetTimer )
       
   673             {
       
   674             TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleBuddyPresenceChangeL() timer started ") );
       
   675             iWidgetTimer->StopListening();
       
   676             iWidgetTimer->StartListening( KTimerInterval ); 
       
   677             }
       
   678         }
       
   679     TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleBuddyPresenceChangeL() end ") );  
       
   680   }
       
   681 
       
   682 // ---------------------------------------------------------------------------
       
   683 // CServiceWidgetServiceManager::HandleOwnStatusChangeL
       
   684 // ---------------------------------------------------------------------------
       
   685 // 
       
   686 void CServiceWidgetServiceManager::HandleOwnStatusChangeL( TWSPresenceStatus /*aStatus*/ )  
       
   687 	{
       
   688 	TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleOwnStatusChangeL() start ") );
       
   689 	UpdateContentsL();
       
   690 	TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleOwnStatusChangeL() end ") );
       
   691 	}
       
   692 // ---------------------------------------------------------------------------
       
   693 // CServiceWidgetServiceManager::HandleServiceStatusChangedL
       
   694 // ---------------------------------------------------------------------------
       
   695 // 
       
   696 void CServiceWidgetServiceManager::HandleServiceStatusChangedL( TSWSTRegistrationState aState ) 
       
   697 	{
       
   698 	TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleServiceStatusChangedL() start ") );
       
   699 	iServiceState = aState ;
       
   700 	CreateHandlersL();
       
   701 	UpdateContentsL();	
       
   702 	TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleServiceStatusChangedL() end ") );
       
   703 	}
       
   704 
       
   705 // ---------------------------------------------------------------------------
       
   706 // CServiceWidgetServiceManager::HandleTimerExpiredL
       
   707 // ---------------------------------------------------------------------------
       
   708 // 
       
   709 void CServiceWidgetServiceManager::HandleTimerExpiredL() 
       
   710 	{
       
   711 	TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleTimerExpiredL() start ") );
       
   712 	UpdateContentsL(); // once timer expired show the current data based on availabity
       
   713 	TRACE_SWP(TXT("CServiceWidgetServiceManager::HandleTimerExpiredL() end ") );	
       
   714 	}
       
   715 
       
   716 // ---------------------------------------------------------------------------
       
   717 // CServiceWidgetServiceManager::CreateHandlersL
       
   718 // ---------------------------------------------------------------------------
       
   719 // 
       
   720 void CServiceWidgetServiceManager::CreateHandlersL() 
       
   721 	{
       
   722 	TRACE_SWP(TXT("CServiceWidgetServiceManager::CreateHandlersL() start ") );
       
   723 	if( iServiceState == ESWSRegistered  || iServiceState == ESWSUpdatingContacts )
       
   724 		{
       
   725 		TRACE_SWP(TXT("CServiceWidgetServiceManager::CreateHandlersL() ECCHEnabled ") );
       
   726 		// once logged in create all interfaces
       
   727 		// please note this is boot blugin so keep lesser memory use
       
   728 		if( !iPresenceHandler && iCchHandler->IsSubServiceSupported( ECCHPresenceSub ) )
       
   729 			{
       
   730 			TPtrC ownId = iCchHandler->OwnUserIdL();
       
   731 			iPresenceHandler = CServiceWidgetPresenceHandler::NewL(*this,*iServiceName,ownId );
       
   732 			iPresenceHandler->GetConnectedSessionL( iCchHandler->XimpAdaptationUidL(), iServiceId );
       
   733 			TRACE_SWP(TXT("CServiceWidgetServiceManager::CreateHandlersL() iPresenceHandler cretaed ") );	
       
   734 			}
       
   735 		if( !iMessageHandler && iCchHandler->IsSubServiceSupported( ECCHIMSub ) )
       
   736 			{
       
   737 			TPtrC ownId = iCchHandler->OwnUserIdL();
       
   738 			iMessageHandler = CServiceWidgetMessageHandler::NewL( *this, iServiceId, ownId);
       
   739 			TRACE_SWP(TXT("CServiceWidgetServiceManager::CreateHandlersL() iMessageHandler created ") );	
       
   740 			}
       
   741 		if( !iWidgetTimer && ( iPresenceHandler || iMessageHandler  ) )
       
   742 			{
       
   743 			// create the timer only if required
       
   744 			iWidgetTimer =  CServiceWidgetTimer::NewL(*this) ;
       
   745 		    TRACE_SWP(TXT("CServiceWidgetServiceManager::CreateHandlersL() iWidgetTimer created ") );
       
   746 		 	}
       
   747 		}
       
   748 	else if( iServiceState == ESWSNotRegistered )
       
   749 		{
       
   750 		TRACE_SWP(TXT("CServiceWidgetServiceManager::CreateHandlersL() ECCHDisabled ") );
       
   751 		// once disconnecting off delete all interfaces
       
   752 		if( iWidgetTimer )
       
   753 			{
       
   754 			delete iWidgetTimer;
       
   755 			iWidgetTimer = NULL;
       
   756 			TRACE_SWP(TXT("CServiceWidgetServiceManager::CreateHandlersL() iWidgetTimer deleted ") );	
       
   757 			}
       
   758 		if(iMessageHandler  )
       
   759 			{
       
   760 			delete iMessageHandler;
       
   761 			iMessageHandler = NULL;	
       
   762 			TRACE_SWP(TXT("CServiceWidgetServiceManager::CreateHandlersL() iMessageHandler deleted ") );
       
   763 			}
       
   764 		if( iPresenceHandler)
       
   765 			{
       
   766 			iPresenceHandler->ReleaseConnectionL();	
       
   767 			delete iPresenceHandler ;
       
   768 			iPresenceHandler = NULL;
       
   769 			TRACE_SWP(TXT("CServiceWidgetServiceManager::CreateHandlersL() iPresenceHandler deleted ") );
       
   770 			}
       
   771 	   	}
       
   772 	TRACE_SWP(TXT("CServiceWidgetServiceManager::CreateHandlersL() end ") );
       
   773 	}
       
   774 
       
   775 // ---------------------------------------------------------------------------
       
   776 // CServiceWidgetServiceManager::ServiceId
       
   777 // ---------------------------------------------------------------------------
       
   778 // 
       
   779 TInt CServiceWidgetServiceManager::ServiceId()
       
   780 {
       
   781 TRACE_SWP(TXT("CServiceWidgetServiceManager::ServiceId() Manager") );
       
   782 return iServiceId;
       
   783 }
       
   784 
       
   785 // ---------------------------------------------------------------------------
       
   786 // CServiceWidgetServiceManager::ServiceName
       
   787 // ---------------------------------------------------------------------------
       
   788 // 
       
   789 const TDesC& CServiceWidgetServiceManager::ServiceName()
       
   790 {
       
   791 TRACE_SWP(TXT("CServiceWidgetServiceManager::ServiceName() Manager") );
       
   792 return *iServiceName;
       
   793 }
       
   794 // ---------------------------------------------------------------------------
       
   795 // CServiceWidgetServiceManager::UnregisterWidgetL
       
   796 // ---------------------------------------------------------------------------
       
   797 // 
       
   798 void CServiceWidgetServiceManager::UnregisterWidgetL()
       
   799     {
       
   800     TRACE_SWP(TXT("CServiceWidgetServiceManager::UnregisterWidgetL() Manager") );
       
   801     
       
   802     iContentPublisher.UnregisterWidgetL(*iServiceName);
       
   803     }
       
   804 
       
   805 // ---------------------------------------------------------------------------
       
   806 // CServiceWidgetServiceManager::RegisterWidgetL
       
   807 // ---------------------------------------------------------------------------
       
   808 // 
       
   809 void CServiceWidgetServiceManager::RegisterWidgetL()
       
   810     {
       
   811     TRACE_SWP(TXT("CServiceWidgetServiceManager::RegisterWidgetL() Manager") );
       
   812     TInt bitmapHandle = 0 ;
       
   813     TInt maskHandle  = 0 ;
       
   814     iBrandHandler->GetStatusBitmapL( EWSServiceIcon, bitmapHandle, maskHandle ) ;
       
   815     iContentPublisher.RegisterWidgetL(*iServiceName,bitmapHandle, maskHandle);
       
   816     }
       
   817 
       
   818 // ---------------------------------------------------------------------------
       
   819 // CServiceWidgetServiceManager::ExecuteActionL
       
   820 // ---------------------------------------------------------------------------
       
   821 // 
       
   822 void CServiceWidgetServiceManager::ExecuteActionL()
       
   823     {
       
   824     TRACE_SWP(TXT("CServiceWidgetServiceManager::ExecuteActionL() Manager") );
       
   825     switch( iExecuteOperation )
       
   826         {
       
   827         case ESWALaunchServiceTab:
       
   828             {
       
   829             RxSPViewServices viewServices;
       
   830             TInt err = viewServices.Activate(  iServiceTabUid, 
       
   831                     iServiceviewId ) ; 
       
   832             TRACE_SWP(TXT("CServiceWidgetServiceManager::ExecuteActionL() Activate = %d"), err), 
       
   833             User::LeaveIfError( err );
       
   834             
       
   835             break;
       
   836             }
       
   837         case ESWALaunchConverView:
       
   838             {
       
   839             if( iMessageHandler && iEnv )
       
   840                 {
       
   841                 TRACE_SWP(TXT("CServiceWidgetServiceManager::ExecuteActionL() launch cv") );
       
   842                 TVwsViewId activeViewId;
       
   843                 CCoeAppUi* appui = iEnv->AppUi();
       
   844                 appui->GetActiveViewId( activeViewId );
       
   845                 IMCVLauncher::LaunchImConversationViewL(activeViewId,
       
   846                                                         iServiceId,
       
   847                                                         iMessageHandler->GetUnreadSenderId() ) ;
       
   848                 }
       
   849             break;
       
   850             }
       
   851         case ESWALaunchSTAutoLogin :
       
   852             {
       
   853             /* 
       
   854              * First pack version number followed by service id.
       
   855              * PhoneBook first read till EEnd and then it goes to service tab
       
   856              * get the custom info in this call CVIMPSTUiTabbedView::DoActivateViewL
       
   857              * aCustomMessageId is CPbk2ViewState::Uid()
       
   858              * In service tab (tabbedview) we need to unpack dataPtr in similar reverse pattern
       
   859              *
       
   860             */
       
   861             HBufC8* data = HBufC8::NewLC( 20 );
       
   862                         TPtr8 dataPtr( data->Des() );
       
   863              RDesWriteStream stream( dataPtr );
       
   864              stream.PushL();
       
   865              stream.WriteInt8L(1);   // version number
       
   866              stream.WriteInt8L( 0 ); //EEnd
       
   867              stream.WriteInt32L( iServiceId ); //Service Id
       
   868              stream.CommitL();
       
   869                        
       
   870             RxSPViewServices viewServices;
       
   871             TInt err = viewServices.Activate(  iServiceTabUid, 
       
   872                                             iServiceviewId , dataPtr );
       
   873             TRACE_SWP(TXT("CServiceWidgetServiceManager::ExecuteActionL() Activate = %d"), err), 
       
   874             User::LeaveIfError( err );
       
   875             CleanupStack::PopAndDestroy(); 
       
   876             CleanupStack::PopAndDestroy( data );// data
       
   877             break;
       
   878             }
       
   879         case ESWAStartLogin:
       
   880             {
       
   881             iCchHandler->EnableServiceL();
       
   882             break;
       
   883             }
       
   884         default :
       
   885             {
       
   886             // do nothing
       
   887             }
       
   888         } // end of switch
       
   889     
       
   890   }//End ExecuteActionL
       
   891 // End of File