imstutils/imconversationview/imcvuiengine/src/cimcvenginefactory.cpp
branchRCL_3
changeset 28 3104fc151679
parent 27 2b7283837edb
child 29 9a48e301e94b
equal deleted inserted replaced
27:2b7283837edb 28:3104fc151679
     1 /*
       
     2 * Copyright (c) 2008-2009 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 engine factory implementation
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "cimcvenginefactory.h"
       
    20 
       
    21 #include "mimcvenginefactory.h"
       
    22 #include "cimcvengine.h"
       
    23 #include "imcvuiliterals.h"
       
    24 #include <spsettings.h>
       
    25 #include <spentry.h>
       
    26 #include <spproperty.h>
       
    27 #include <spdefinitions.h>
       
    28 #include <MVPbkContactLink.h>
       
    29 #include "mimcvenginemessagecreator.h"
       
    30 #include <cbsfactory.h>
       
    31 #include "cimcvenginemessagecreator.h"
       
    32 #include <spnotifychange.h>
       
    33 #include "mimcvngineservicechangeobserver.h"
       
    34 #include <apgtask.h>
       
    35 #include <w32std.h>
       
    36 #include "imcvuiparams.h"
       
    37 #include "mimcvenginemessagehandler.h"
       
    38 #include "mimcvenginechatinterface.h"
       
    39 
       
    40 // ================= MEMBER FUNCTIONS =======================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CIMCVEngineFactory::InstanceL
       
    44 // Create an instance of the ximp manager
       
    45 // behaving as singleton object already created then return same instance.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 EXPORT_C MIMCVEngineFactory* CIMCVEngineFactory::InstanceL()
       
    49     {
       
    50     CIMCVEngineFactory* singleton;
       
    51     singleton = static_cast<CIMCVEngineFactory*> (Dll::Tls());
       
    52     if( !singleton )
       
    53         {
       
    54         singleton = CIMCVEngineFactory::NewLC();
       
    55         User::LeaveIfError( Dll::SetTls( static_cast<TAny*> (singleton ) ));
       
    56         CleanupStack::Pop(singleton);
       
    57         }
       
    58     return (MIMCVEngineFactory*)singleton;
       
    59     }
       
    60     
       
    61 // -----------------------------------------------------------------------------
       
    62 // CIMCVEngineFactory::Release
       
    63 // Release the singelton
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 EXPORT_C void CIMCVEngineFactory::Release()
       
    67     {
       
    68     CIMCVEngineFactory* singleton;
       
    69     singleton = static_cast<CIMCVEngineFactory*>(Dll::Tls());
       
    70     if( singleton )
       
    71         {
       
    72         delete singleton;
       
    73         Dll::SetTls( NULL ) ;
       
    74         }
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CIMCVEngineFactory::NewLC
       
    79 // Object creation using two phase construction
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CIMCVEngineFactory* CIMCVEngineFactory::NewLC()
       
    83     {
       
    84     CIMCVEngineFactory* self = new (ELeave) CIMCVEngineFactory();
       
    85     CleanupStack::PushL( self );
       
    86     self->ConstructL();
       
    87     return self;
       
    88     }
       
    89     
       
    90 // -----------------------------------------------------------------------------
       
    91 // CIMCVEngineFactory::ConstructL
       
    92 // Symbian OS default constructor can leave.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CIMCVEngineFactory::ConstructL()
       
    96     {
       
    97     iMessageCreator = CIMCVEngineMessageCreator::NewL();
       
    98     iBrandingFactory = CBSFactory::NewL( KDefaultBrandIdForBrand, KAppIdForBrand );
       
    99     __ASSERT_ALWAYS((iBrandingFactory != NULL),User::Leave(KErrArgument));
       
   100     ReadAndCreateAllValidServiceL();
       
   101     //register for service table notifications
       
   102     RArray<TUint> serviceIds;
       
   103     CleanupClosePushL( serviceIds );
       
   104     iSpNotifyChange = CSPNotifyChange::NewL( *this );    
       
   105     iSpNotifyChange->NotifyChangeL( serviceIds );
       
   106     CleanupStack::PopAndDestroy( &serviceIds ) ; 
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------
       
   110 // CIMCVEngineFactory::CIMCVEngineFactory
       
   111 // ---------------------------------------------------------  
       
   112 CIMCVEngineFactory::CIMCVEngineFactory():
       
   113     iActiveChatIndex( KErrNotFound )
       
   114 	{
       
   115 		
       
   116 	}
       
   117 
       
   118 // ---------------------------------------------------------
       
   119 // CIMCVEngineFactory::~CIMCVEngineFactory
       
   120 // ---------------------------------------------------------   
       
   121 CIMCVEngineFactory::~CIMCVEngineFactory()
       
   122     {
       
   123     delete iSpNotifyChange;
       
   124     //delete all the create engine instances
       
   125     //delete iBrandingFactory;
       
   126     iServiceEngines.ResetAndDestroy();
       
   127     iServiceEngines.Close();
       
   128     delete iMessageCreator;
       
   129     delete iBrandingFactory;
       
   130     }
       
   131 // ---------------------------------------------------------
       
   132 // CIMCVEngineFactory::ReadAndCreateAllValidServiceL
       
   133 // ---------------------------------------------------------   
       
   134 void CIMCVEngineFactory::ReadAndCreateAllValidServiceL()
       
   135     {
       
   136     CSPSettings* settings = CSPSettings::NewLC();
       
   137     
       
   138     RArray<TServiceId> services;
       
   139     CleanupClosePushL( services );
       
   140     settings->FindServiceIdsL( services );
       
   141     const TInt serviceCount = services.Count();
       
   142     
       
   143     for ( TInt i( 0 ); i < serviceCount; i++ )
       
   144         {
       
   145         TInt serviceId = services[ i ];
       
   146         TUint32 refContactUid = ContactViewUidL(*settings , serviceId );
       
   147         if ( TUid::Uid( refContactUid ) == 
       
   148              TUid::Uid( 0x20012423 ) 
       
   149              || TUid::Uid( refContactUid ) == 
       
   150              TUid::Uid( 0x20007B6D )
       
   151              || TUid::Uid( refContactUid ) == 
       
   152              TUid::Uid( 0x2002B334 ) )
       
   153             {
       
   154             if( CheckValidIMServiceL(*settings , serviceId  ) )
       
   155                 {
       
   156                 CreateServiceEngineL( serviceId );
       
   157                 }
       
   158             }
       
   159         }
       
   160     CleanupStack::PopAndDestroy( &services );
       
   161     CleanupStack::PopAndDestroy( settings );
       
   162     }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // CIMCVEngineFactory::ContactViewUidL()
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 TUint32 CIMCVEngineFactory::ContactViewUidL(CSPSettings& aSettings, TUint32 aServiceId )
       
   169     {
       
   170     TInt contactViewUid = KErrNotFound;
       
   171     CSPProperty* property = CSPProperty::NewLC();
       
   172     TInt err = aSettings.FindPropertyL( aServiceId,
       
   173                                 EPropertyContactViewPluginId,
       
   174                                 *property );    
       
   175     if ( KErrNone == err )
       
   176         {
       
   177         property->GetValue( contactViewUid );
       
   178         }
       
   179     CleanupStack::PopAndDestroy( property );      
       
   180     return contactViewUid;
       
   181     }    
       
   182 //-----------------------------------------------------------------------------
       
   183 // CIMCVEngineFactory::CheckValidIMServiceL
       
   184 // ( Other items commented in header )
       
   185 //----------------------------------------------------------------------------- 
       
   186 TBool CIMCVEngineFactory::CheckValidIMServiceL(CSPSettings& aSettings , TInt aServiceId) 
       
   187     {   
       
   188     //check whether it has IMSubservice    
       
   189     TBool ret = ETrue;
       
   190     CSPProperty* property = CSPProperty::NewLC();
       
   191     TInt err = aSettings.FindPropertyL( aServiceId,
       
   192                                 ESubPropertyIMEnabled,
       
   193                                 *property );    
       
   194     if ( err )
       
   195         {
       
   196         ret = EFalse;
       
   197         }
       
   198     CleanupStack::PopAndDestroy( property );
       
   199     return ret;      
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // CIMCVEngineFactory::CreateServiceEngineL()
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 void CIMCVEngineFactory::CreateServiceEngineL( TInt aServiceId )
       
   207     {
       
   208     TInt count = iServiceEngines.Count();
       
   209     CIMCVEngine* engine = NULL;
       
   210     for(int i=0 ; i<count ; i++)
       
   211         {
       
   212         if(iServiceEngines[i]->GetServiceId() == aServiceId)
       
   213             {
       
   214             engine = iServiceEngines[i];
       
   215             break;
       
   216             }
       
   217         }
       
   218     if( !engine )
       
   219         {
       
   220         engine = CIMCVEngine::NewL( aServiceId , *iMessageCreator, *iBrandingFactory );
       
   221 		CleanupStack::PushL(engine);
       
   222         iServiceEngines.AppendL(engine);
       
   223 		CleanupStack::Pop(engine);
       
   224         }
       
   225     }           
       
   226 // ---------------------------------------------------------------------------
       
   227 // CIMCVEngineFactory::GetServiceEngine()
       
   228 // ---------------------------------------------------------------------------
       
   229 //
       
   230 CIMCVEngine& CIMCVEngineFactory::GetServiceEngineL( TInt aServiceId )
       
   231     {
       
   232     TInt count = iServiceEngines.Count();
       
   233     CIMCVEngine* engine = NULL;
       
   234     for(int i=0 ; i<count ; i++)
       
   235         {
       
   236         if(iServiceEngines[i]->GetServiceId() == aServiceId)
       
   237             {
       
   238             engine = iServiceEngines[i];
       
   239             break;
       
   240             }
       
   241         }
       
   242     if( !engine )
       
   243         {
       
   244         engine = CIMCVEngine::NewL( aServiceId , *iMessageCreator, *iBrandingFactory );
       
   245 		CleanupStack::PushL(engine);
       
   246         iServiceEngines.AppendL(engine);
       
   247         CleanupStack::Pop(engine);
       
   248         engine->OpenChats().RegisterObserver( this );
       
   249         engine->MessageHandler().SetObserver( this );
       
   250         engine->ChatInterface().RegisterChatListObserver( this );
       
   251 	    }
       
   252     return *engine;
       
   253     }			
       
   254 // ---------------------------------------------------------------------------
       
   255 // CIMCVEngineFactory::ReleaseServiceEngine()
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 void CIMCVEngineFactory::ReleaseServiceEngine( TInt aServiceId )
       
   259     {
       
   260     TInt count = iServiceEngines.Count();
       
   261     for(int i=0 ; i<count ; i++)
       
   262         {
       
   263         if(iServiceEngines[i]->GetServiceId() == aServiceId )
       
   264             {
       
   265             CIMCVEngine* engine = iServiceEngines[i];
       
   266             iServiceEngines.Remove( i );
       
   267             delete engine;
       
   268             engine = NULL;
       
   269             iServiceEngines.Compress();
       
   270             break;
       
   271             }
       
   272         }
       
   273     }    
       
   274 // -----------------------------------------------------------------------------
       
   275 // CIMCVEngineFactory: GetDisplayNameL
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 TPtrC CIMCVEngineFactory::GetDisplayNameL(TInt aIndex) const
       
   279     {
       
   280     TInt count = iServiceEngines.Count();
       
   281     for( TInt i=0; i<count; i++ )
       
   282         {
       
   283         MIMCVEngineOpenChats& openChat = iServiceEngines[i]->OpenChats();
       
   284         TInt openChatCount = openChat.Count();
       
   285         if( aIndex < openChatCount )
       
   286             {
       
   287             return openChat.GetDisplayNameL( aIndex );
       
   288             }
       
   289         else
       
   290             {
       
   291             aIndex = aIndex - openChatCount;
       
   292             }
       
   293         }
       
   294     return KNullDesC();
       
   295     }
       
   296     
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CIMCVEngineFactory: GetTargetIdL
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 const TDesC& CIMCVEngineFactory::GetTargetIdL(TInt aIndex) const
       
   303     {
       
   304     TInt count = iServiceEngines.Count();
       
   305     for( TInt i=0; i<count; i++ )
       
   306         {
       
   307         MIMCVEngineOpenChats& openChat = iServiceEngines[i]->OpenChats();
       
   308         TInt openChatCount = openChat.Count();
       
   309         if( aIndex < openChatCount )
       
   310             {
       
   311             return openChat.GetTargetIdL( aIndex );
       
   312             }
       
   313         else
       
   314             {
       
   315             aIndex = aIndex - openChatCount;
       
   316             }
       
   317         }
       
   318     return KNullDesC;   
       
   319     }
       
   320 
       
   321 
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // CIMCVEngineFactory: FindIndexL
       
   325 // -----------------------------------------------------------------------------
       
   326 //
       
   327 TInt CIMCVEngineFactory::FindIndexL(const TDesC& aItem )
       
   328     {
       
   329     TInt index = KErrNotFound;
       
   330     TInt validIndex = 0;
       
   331     TInt count = iServiceEngines.Count();
       
   332     for( TInt i=0; i<count; i++ )
       
   333         {
       
   334         MIMCVEngineOpenChats& openChat = iServiceEngines[i]->OpenChats();
       
   335         TInt openChatCount = openChat.Count();
       
   336         index = openChat.FindIndexL( aItem ) ;
       
   337         if( index != KErrNotFound )
       
   338             {
       
   339             validIndex = validIndex + index;
       
   340             break;
       
   341             }
       
   342         else
       
   343             {
       
   344             validIndex = openChatCount;
       
   345             }
       
   346         }
       
   347     return validIndex; 
       
   348     }
       
   349     
       
   350 // -----------------------------------------------------------------------------
       
   351 // CIMCVEngineFactory: Count
       
   352 // -----------------------------------------------------------------------------
       
   353 //
       
   354 TInt CIMCVEngineFactory::Count() const
       
   355     {
       
   356     TInt chatCount = 0;
       
   357     TInt count = iServiceEngines.Count();
       
   358     for( TInt i=0; i<count; i++ )
       
   359         {
       
   360         MIMCVEngineOpenChats& openChat = iServiceEngines[i]->OpenChats();
       
   361         chatCount = chatCount + openChat.Count();
       
   362         }
       
   363     return chatCount;
       
   364     }
       
   365 
       
   366 
       
   367 // -----------------------------------------------------------------------------
       
   368 // CIMCVEngineFactory: SetActiveItemL
       
   369 // -----------------------------------------------------------------------------
       
   370 //
       
   371 void CIMCVEngineFactory::SetActiveItemL( const TInt aIndex )
       
   372     {
       
   373     iActiveChatIndex = aIndex;
       
   374     }
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // CIMCVEngineFactory: GetActiveItem
       
   378 // -----------------------------------------------------------------------------
       
   379 //
       
   380 const TDesC& CIMCVEngineFactory::GetActiveItemL() const
       
   381     {
       
   382     TInt index = iActiveChatIndex ;
       
   383     TInt count = iServiceEngines.Count();
       
   384     for( TInt i=0; i<count; i++ )
       
   385         {
       
   386         MIMCVEngineOpenChats& openChat = iServiceEngines[i]->OpenChats();
       
   387         TInt openChatCount = openChat.Count();
       
   388         if( index < openChatCount )
       
   389             {
       
   390             return openChat.GetTargetIdL( index ); 
       
   391             }
       
   392         else
       
   393             {
       
   394             index = index - openChatCount;
       
   395             }
       
   396         }
       
   397     return KNullDesC;
       
   398     }
       
   399 
       
   400 // -----------------------------------------------------------------------------
       
   401 // CIMCVEngineFactory: GetServiceEngines
       
   402 // -----------------------------------------------------------------------------
       
   403 //
       
   404 RPointerArray<CIMCVEngine>&  CIMCVEngineFactory::GetServiceEngines()
       
   405     {
       
   406     return iServiceEngines;
       
   407     }
       
   408 // -----------------------------------------------------------------------------
       
   409 // CIMCVEngineFactory: GetActiveServiceId
       
   410 // -----------------------------------------------------------------------------
       
   411 //
       
   412 TInt CIMCVEngineFactory::GetActiveServiceId() 
       
   413     {
       
   414     TInt index = iActiveChatIndex;
       
   415     TInt count = iServiceEngines.Count();
       
   416     for( TInt i=0; i<count; i++ )
       
   417         {
       
   418         MIMCVEngineOpenChats& openChat = iServiceEngines[i]->OpenChats();
       
   419         TInt openChatCount = openChat.Count();
       
   420         if( index < openChatCount )
       
   421             {
       
   422             return iServiceEngines[i]->GetServiceId();
       
   423             }
       
   424         else
       
   425             {
       
   426             index = index - openChatCount;
       
   427             }
       
   428         }
       
   429     return KErrNotFound;
       
   430     }
       
   431 
       
   432 // -----------------------------------------------------------------------------
       
   433 // CIMCVEngineFactory: IsMsgPendingL
       
   434 // -----------------------------------------------------------------------------
       
   435 //
       
   436 TBool CIMCVEngineFactory::IsMsgPendingL( const TInt aIndex ) const
       
   437     {
       
   438     TInt index = aIndex;
       
   439     TInt count = iServiceEngines.Count();
       
   440     for( TInt i=0; i<count; i++ )
       
   441         {
       
   442         MIMCVEngineOpenChats& openChat = iServiceEngines[i]->OpenChats();
       
   443         TInt openChatCount = openChat.Count();
       
   444         if( index < openChatCount )
       
   445             {
       
   446             openChat.IsMsgPendingL( index );
       
   447             }
       
   448         else
       
   449             {
       
   450             index = index - openChatCount;
       
   451             }
       
   452         }
       
   453     return EFalse;          
       
   454     }
       
   455 
       
   456 // -----------------------------------------------------------------------------
       
   457 // CIMCVEngineFactory: ResetL
       
   458 // -----------------------------------------------------------------------------
       
   459 //
       
   460 void CIMCVEngineFactory::ResetL()
       
   461     {
       
   462     TInt count = iServiceEngines.Count();
       
   463     for( TInt i=0; i<count; i++ )
       
   464         {
       
   465         iServiceEngines[i]->OpenChats().ResetL();
       
   466         }
       
   467     iActiveServiceId = KErrNotFound;
       
   468     }   
       
   469 // -----------------------------------------------------------------------------
       
   470 // CIMCVEngineFactory: RegisterOpenChatObserver
       
   471 // -----------------------------------------------------------------------------
       
   472 //
       
   473 void CIMCVEngineFactory::RegisterOpenChatObserver(MIMCVEngineOpenChatsObserver* aChatObserver)
       
   474     {
       
   475     iChatObserver = aChatObserver;
       
   476     TInt count = iServiceEngines.Count();
       
   477     for( TInt i=0; i<count; i++ )
       
   478         {
       
   479         iServiceEngines[i]->OpenChats().RegisterObserver( this );
       
   480         }
       
   481     }
       
   482 
       
   483 // -----------------------------------------------------------------------------
       
   484 // CIMCVEngineFactory: UnRegisterOpenChatObserver
       
   485 // -----------------------------------------------------------------------------
       
   486 //
       
   487 void CIMCVEngineFactory::UnRegisterOpenChatObserver()
       
   488     {
       
   489     iChatObserver = NULL;
       
   490     TInt count = iServiceEngines.Count();
       
   491     for( TInt i=0; i<count; i++ )
       
   492         {
       
   493         iServiceEngines[i]->OpenChats().UnRegisterObserver();
       
   494         }
       
   495     }
       
   496 
       
   497 
       
   498 // ---------------------------------------------------------    
       
   499 // CIMCVEngineFactory::HandleChangeL
       
   500 // (other items were commented in a header).
       
   501 // ---------------------------------------------------------
       
   502 //
       
   503 void CIMCVEngineFactory::HandleChangeL(TInt aServiceId, TInt aIndex, TOpenChatsEventType aChangeType) 
       
   504     {
       
   505     if( iChatObserver )
       
   506         {
       
   507         TInt validIndex = KErrNotFound;
       
   508         MIMCVEngineOpenChats& openChat = GetServiceEngineL( aServiceId ).OpenChats();
       
   509         TInt chatCount = openChat.Count();
       
   510         if( aIndex < chatCount && aIndex>=0 )
       
   511             {
       
   512             validIndex = FindIndexL( openChat.GetTargetIdL( aIndex ) );
       
   513             }
       
   514         if(validIndex >=0 )
       
   515             {
       
   516             iChatObserver->HandleChangeL( aServiceId, validIndex, aChangeType );
       
   517             }
       
   518         }
       
   519     }       
       
   520     
       
   521 // ---------------------------------------------------------
       
   522 // CIMCVEngineFactory::SetStatusMsgL()
       
   523 // (other items were commented in a header).
       
   524 // ---------------------------------------------------------
       
   525 //
       
   526 void CIMCVEngineFactory::SetStatusMsgL(TInt aServiceId, TInt aIndex,const TDesC & aMsg)
       
   527     {
       
   528     if( iChatObserver )
       
   529         {
       
   530         TInt validIndex = KErrNotFound;
       
   531         MIMCVEngineOpenChats& openChat = GetServiceEngineL( aServiceId ).OpenChats();
       
   532         TInt chatCount = openChat.Count();
       
   533         if( aIndex < chatCount && aIndex>=0 )
       
   534             {
       
   535             validIndex = FindIndexL( openChat.GetTargetIdL( aIndex ) );
       
   536             }
       
   537         if( validIndex >= 0 )
       
   538             {
       
   539             iChatObserver->SetStatusMsgL( aServiceId, validIndex, aMsg );
       
   540             }
       
   541         }
       
   542     }
       
   543 // ---------------------------------------------------------------------------
       
   544 // CIMCVEngineFactory::RegisterServiceObserver()
       
   545 // ---------------------------------------------------------------------------
       
   546 //
       
   547 void CIMCVEngineFactory::RegisterServiceObserver(MIMCVEngineServiceChangeObserver* aServiceObserver)  
       
   548     {
       
   549     iServiceChangeObserver = aServiceObserver;
       
   550     TInt count = iServiceEngines.Count();
       
   551     for( TInt i=0; i<count; i++ )
       
   552         {
       
   553         iServiceEngines[i]->ChatInterface().RegisterChatListObserver( this );
       
   554         iServiceEngines[i]->MessageHandler().SetObserver( this );
       
   555         }
       
   556     }
       
   557 // ---------------------------------------------------------------------------
       
   558 // CIMCVEngineFactory::UnRegisterServiceObserver()
       
   559 // ---------------------------------------------------------------------------
       
   560 //
       
   561 void CIMCVEngineFactory::UnRegisterServiceObserver()
       
   562     {
       
   563     iServiceChangeObserver = NULL;
       
   564     TInt count = iServiceEngines.Count();
       
   565     for( TInt i=0; i<count; i++ )
       
   566         {
       
   567         iServiceEngines[i]->ChatInterface().UnregisterChatListObserver( this );
       
   568         iServiceEngines[i]->MessageHandler().RemoveObserver();
       
   569         }
       
   570     }
       
   571        
       
   572 //////////////////////////////////////////////////////////////
       
   573 // ---------------------------------------------------------------------------
       
   574 // CIMCVEngineFactory::HandleNotifyChange()
       
   575 // ---------------------------------------------------------------------------
       
   576 //
       
   577 void CIMCVEngineFactory::HandleNotifyChange(
       
   578     TServiceId aServiceId )
       
   579     {
       
   580     TRAP_IGNORE( DoHandleServiceChangeL(aServiceId ) );
       
   581     }
       
   582 
       
   583 // ---------------------------------------------------------------------------
       
   584 // CIMCVEngineFactory::DoHandleServiceChangeL()
       
   585 // ---------------------------------------------------------------------------
       
   586 //
       
   587 void CIMCVEngineFactory::DoHandleServiceChangeL( TInt aServiceId )
       
   588     {
       
   589     // check service Id exist intable
       
   590     CSPSettings* settings = CSPSettings::NewLC();
       
   591     RArray<TServiceId> services;
       
   592     CleanupClosePushL( services );
       
   593     settings->FindServiceIdsL( services );
       
   594     const TInt serviceCount = services.Count();
       
   595     TBool serviceExist = EFalse;
       
   596     for ( TInt i( 0 ); i < serviceCount; i++ )
       
   597         {
       
   598         TInt serviceId = services[ i ];
       
   599         TUint32 refContactUid = ContactViewUidL(*settings , serviceId );
       
   600         if ( TUid::Uid( refContactUid ) == 
       
   601         TUid::Uid( 0x20012423 ) 
       
   602         || TUid::Uid( refContactUid ) == 
       
   603         TUid::Uid( 0x20007B6D )
       
   604         || TUid::Uid( refContactUid ) == 
       
   605             TUid::Uid( 0x2002B334 ) )
       
   606             {
       
   607             if( aServiceId == serviceId   )
       
   608                 {
       
   609                 serviceExist = ETrue;
       
   610                 }
       
   611             }
       
   612         }
       
   613     CleanupStack::PopAndDestroy( &services );
       
   614    
       
   615     // if service does not exist delete the engine if created
       
   616     if( !serviceExist )
       
   617         {
       
   618         // delete if already created
       
   619         TInt count = iServiceEngines.Count();
       
   620         for( TInt i=0; i<count; i++ )
       
   621             {
       
   622             if( iServiceEngines[i]->GetServiceId() == aServiceId )
       
   623                 {
       
   624                 if( iServiceChangeObserver )
       
   625                     {
       
   626                     // this will delete the new branding icosn for smile etc.
       
   627                     iServiceChangeObserver->HandleServiceDeletedL( aServiceId );
       
   628                     }
       
   629                 CIMCVEngine* engine = iServiceEngines[i];
       
   630                 engine->OpenChats().UnRegisterObserver();
       
   631                 engine->MessageHandler().RemoveObserver();
       
   632                 engine->ChatInterface().UnregisterChatListObserver( this );
       
   633                 
       
   634                 iServiceEngines.Remove(i);
       
   635                 delete engine;
       
   636                 engine = NULL;
       
   637                 iServiceEngines.Compress();
       
   638                 break;
       
   639                 }
       
   640             }
       
   641         if( !iServiceEngines.Count() )
       
   642             {
       
   643             ShutDownConversationviewL();
       
   644             }
       
   645         }
       
   646     else
       
   647         {
       
   648         // service exist check whether we have service engine or not 
       
   649         // create if we dont have
       
   650         TBool newService = ETrue;
       
   651         TInt count = iServiceEngines.Count();
       
   652         for( TInt i=0; i<count; i++ )
       
   653             {
       
   654             if( iServiceEngines[i]->GetServiceId() == aServiceId )
       
   655                 {
       
   656                 newService = EFalse;
       
   657                 break;
       
   658                 }
       
   659             }
       
   660         if ( newService && CheckValidIMServiceL( *settings, aServiceId ) )
       
   661             {
       
   662             // create if NULL and return
       
   663             GetServiceEngineL( aServiceId );
       
   664             if( iServiceChangeObserver )
       
   665                 {
       
   666                 // this will create the new branding icosn for smile etc.
       
   667                 iServiceChangeObserver->HandleNewServiceL( aServiceId );
       
   668                 }
       
   669             }
       
   670         }
       
   671     CleanupStack::PopAndDestroy( settings );
       
   672     }
       
   673 
       
   674 // ---------------------------------------------------------------------------
       
   675 // CIMCVEngineFactory::HandleError()
       
   676 // ---------------------------------------------------------------------------
       
   677 //
       
   678 void CIMCVEngineFactory::HandleError( TInt /*aError*/ )
       
   679     {
       
   680     }  
       
   681  // ---------------------------------------------------------------------------
       
   682 // CIMCVEngineFactory::ShutDownConversationviewL()
       
   683 // ---------------------------------------------------------------------------
       
   684 //
       
   685 void CIMCVEngineFactory::ShutDownConversationviewL()
       
   686     {
       
   687     // Kills cv if running
       
   688     RWsSession ws;
       
   689     User::LeaveIfError( ws.Connect() );
       
   690     CleanupClosePushL( ws );
       
   691     TApaTaskList list( ws );
       
   692     TApaTask task( list.FindApp( KConversationViewAppUid ) );
       
   693     if ( task.Exists() )
       
   694         {
       
   695         task.EndTask();
       
   696         }
       
   697     CleanupStack::PopAndDestroy( &ws ); // ws
       
   698     }
       
   699 // -----------------------------------------------------------------------------
       
   700 // CIMCVEngineFactory::HandlePresenceChangedL
       
   701 // (other items were commented in a header).
       
   702 // -----------------------------------------------------------------------------
       
   703 //
       
   704 void CIMCVEngineFactory::HandlePresenceChangedL(TInt aServiceId, const TDesC& aBuddyId )
       
   705     {
       
   706     if( iServiceChangeObserver )
       
   707         {
       
   708         // this will create the new branding icosn for smile etc.
       
   709         iServiceChangeObserver->HandlePresenceChangedL( aServiceId , aBuddyId );
       
   710         }
       
   711     }
       
   712 // ---------------------------------------------------------
       
   713 // CIMCVEngineFactory::HandleOperationCompletdL
       
   714 // Handles operation completion
       
   715 // ---------------------------------------------------------
       
   716 //
       
   717 void CIMCVEngineFactory::HandleOperationCompletdL(TInt aServiceId , MIMCVEngineMessage::TMessagerType aType , TInt aResult )
       
   718     {
       
   719     if( iServiceChangeObserver )
       
   720         {
       
   721         // this will create the new branding icosn for smile etc.
       
   722         iServiceChangeObserver->HandleOperationCompletdL( aServiceId , aType, aResult );
       
   723         }
       
   724     }
       
   725 
       
   726 
       
   727 // -----------------------------------------------------------------------------
       
   728 // CIMCVEngineFactory::HandleConnectionTerminatedL
       
   729 // (other items were commented in a header).
       
   730 // -----------------------------------------------------------------------------
       
   731 //
       
   732 void CIMCVEngineFactory::HandleConnectionEventL( TInt aServiceId, TIMCVConnectionState aState, TInt aReason )
       
   733     {
       
   734     if( iServiceChangeObserver )
       
   735           {
       
   736           // this will create the new branding icosn for smile etc.
       
   737           iServiceChangeObserver->HandleConnectionEventL( aServiceId , aState, aReason );
       
   738           }
       
   739     }
       
   740 
       
   741 // -----------------------------------------------------------------------------
       
   742 // CIMCVEngineFactory: HandleChatListEvent
       
   743 // -----------------------------------------------------------------------------
       
   744 //
       
   745 void CIMCVEngineFactory::HandleChatListEvent(TInt aServiceId, TChatListEventType aEvent, 
       
   746                                     MIMCVEngineMessageReadInterface* aContainerInfo
       
   747                                      ) 
       
   748     {
       
   749     if( iServiceChangeObserver )
       
   750        {
       
   751        // this will create the new branding icosn for smile etc.
       
   752        iServiceChangeObserver->HandleChatListEvent( aServiceId , aEvent, aContainerInfo );
       
   753        }
       
   754     }
       
   755 //  End of File