wvuing/wvuiprocess/Src/CCAGlobalNotificationObserverPC.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Global interface for the UI to get notifications when theres a
       
    15 *				 change in contact, list, invite, settings, conversation, group etc
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "MCAContactListModel.h"
       
    21 #include "MCAChatInterface.h"
       
    22 #include "MCAInvite.h"
       
    23 #include "MCASettings.h"
       
    24 #include "TStorageManagerGlobals.h"
       
    25 #include "MCAContactList.h"
       
    26 #include "MCAStoredContact.h"
       
    27 #include "MCAStoredContacts.h"
       
    28 #include "CCAStorageManagerFactory.h"
       
    29 #include "MCAMessage.h"
       
    30 #include "MCAMessageUtils.h"
       
    31 #include "MCAUiGlobalNotificationObserverPC.h"
       
    32 #include "CCAGlobalNotificationObserverPC.h"
       
    33 #include "MCAMessageErrorInformer.h"
       
    34 #include "MCAContactLists.h"
       
    35 #include "capresencemanager.h"
       
    36 
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CCAGlobalNotificationObserverPC::CCAGlobalNotificationObserverPC
       
    42 // -----------------------------------------------------------------------------
       
    43 
       
    44 CCAGlobalNotificationObserverPC::CCAGlobalNotificationObserverPC(
       
    45     MCAContactListModel& aContactListModel,
       
    46     MCAChatInterface& aChatInterface,
       
    47     MCAInvite& aInviteInterface,
       
    48     MCASettings& aSettingsInterface,
       
    49     const MCAMessageUtils& aMessageUtils )
       
    50         : iContactListModel( aContactListModel ),
       
    51         iChatInterface( aChatInterface ),
       
    52         iInviteInterface( aInviteInterface ),
       
    53         iSettingsInterface( aSettingsInterface ),
       
    54         iMessageUtils( aMessageUtils )
       
    55     {
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CCAGlobalNotificationObserverPC::NewL
       
    60 // -----------------------------------------------------------------------------
       
    61 
       
    62 CCAGlobalNotificationObserverPC* CCAGlobalNotificationObserverPC::NewL(
       
    63     MCAContactListModel& aContactListModel,
       
    64     MCAChatInterface& aChatInterface,
       
    65     MCAInvite& aInviteObserver,
       
    66     MCASettings& aSettingsInterface,
       
    67     const MCAMessageUtils& aMessageUtils )
       
    68     {
       
    69     CCAGlobalNotificationObserverPC* self
       
    70     = new ( ELeave ) CCAGlobalNotificationObserverPC(
       
    71         aContactListModel,
       
    72         aChatInterface,
       
    73         aInviteObserver,
       
    74         aSettingsInterface,
       
    75         aMessageUtils );
       
    76     CleanupStack::PushL( self );
       
    77     self->ConstructL();
       
    78     CleanupStack::Pop( self );
       
    79     return self;
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CCAGlobalNotificationObserverPC::ConstructL
       
    84 // -----------------------------------------------------------------------------
       
    85 void CCAGlobalNotificationObserverPC::ConstructL()
       
    86     {
       
    87     iContactInterface = CCAStorageManagerFactory::ContactListInterfaceL();
       
    88     iContactInterface->AddObserverL( this );// listen these events..
       
    89     iInviteInterface.AddInviteObserver( this );
       
    90     iSettingsInterface.AddObserverL( this );  //register with engine
       
    91 
       
    92     // Register this as chat observer
       
    93     iChatInterface.RegisterChatObserver( this );
       
    94 
       
    95     iMessageUtils.MessageErrorInformer().RegisterObserver( this );
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CCAGlobalNotificationObserverPC::~CCAGlobalNotificationObserverPC
       
   100 // -----------------------------------------------------------------------------
       
   101 CCAGlobalNotificationObserverPC::~CCAGlobalNotificationObserverPC()
       
   102     {
       
   103     iGlobalNotificationObservers.ResetAndDestroy();
       
   104     iGlobalNotificationObservers.Close();
       
   105     if ( iContactInterface )
       
   106         {
       
   107         iContactInterface->RemoveObserver( this );
       
   108         }
       
   109     iInviteInterface.RemoveInviteObserver( this );
       
   110     iSettingsInterface.RemoveObserver( this );
       
   111     iChatInterface.UnregisterChatObserver( this );
       
   112     iMessageUtils.MessageErrorInformer().UnregisterObserver( this );
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CCAGlobalNotificationObserverPC::HandleContactDelete
       
   117 // MCAStoredContactsObserver implementation
       
   118 // -----------------------------------------------------------------------------
       
   119 
       
   120 void CCAGlobalNotificationObserverPC::HandleContactDelete( const TDesC& aContactId )
       
   121     {
       
   122     for ( TInt index = 0; index < iGlobalNotificationObservers.Count(); index++ )
       
   123         {
       
   124         iGlobalNotificationObservers[index]->HandleDelete( aContactId, TEnumsPC::EContactItem );
       
   125         }
       
   126 
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CCAGlobalNotificationObserverPC::HandleAddition
       
   131 // MCAStoredContactsObserver implementation
       
   132 // -----------------------------------------------------------------------------
       
   133 
       
   134 void CCAGlobalNotificationObserverPC::HandleAddition( MCAContactList& /*aList*/, MCAStoredContact& /*aContact*/ )
       
   135     {
       
   136     for ( TInt index = 0; index < iGlobalNotificationObservers.Count(); index++ )
       
   137         {
       
   138         iGlobalNotificationObservers[index]->HandleAddition( TEnumsPC::EContactItem );
       
   139         }
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CCAGlobalNotificationObserverPC::HandleChange
       
   144 // MCAStoredContactsObserver implementation
       
   145 // -----------------------------------------------------------------------------
       
   146 
       
   147 void CCAGlobalNotificationObserverPC::HandleChange( MCAContactList* aList, MCAStoredContact* /*aContact*/,
       
   148                                                     TStorageManagerGlobals::TCAObserverEventType aEventType,
       
   149                                                     TBool /*aUserIdChanged */ )
       
   150     {
       
   151     // we need to handle the change here..from storage manager...
       
   152     TEnumsPC::TChange eventtype = TEnumsPC::EUnknownEvent;
       
   153     TInt error( KErrNone );
       
   154     switch ( aEventType )
       
   155         {
       
   156         case TStorageManagerGlobals::EStorageEventPreChange:
       
   157             {
       
   158             // ignore the pre-change events
       
   159             return;
       
   160             }
       
   161         case TStorageManagerGlobals::EStorageEventListDelete:
       
   162         case TStorageManagerGlobals::EStorageEventMultipleChanges:
       
   163             {
       
   164             TInt index = iContactListModel.IndexOfList( aList, EFalse, ETrue );
       
   165 
       
   166             eventtype = aEventType == TStorageManagerGlobals::EStorageEventListDelete
       
   167                         ? TEnumsPC::EDelete : TEnumsPC::EMultipleChanges;
       
   168 
       
   169             for ( TInt index = 0; index < iGlobalNotificationObservers.Count(); index++ )
       
   170                 {
       
   171                 iGlobalNotificationObservers[index]->HandleChange(
       
   172                     TEnumsPC::EContactListItem,	eventtype );
       
   173                 }
       
   174 
       
   175             break;
       
   176             }
       
   177         case TStorageManagerGlobals::EStorageEventPostChange:
       
   178             {
       
   179             // call back the UI with HandleChange here....
       
   180             for ( TInt index = 0; index < iGlobalNotificationObservers.Count(); index++ )
       
   181                 {
       
   182                 iGlobalNotificationObservers[index]->HandleChange(
       
   183                     TEnumsPC::EContactItem, TEnumsPC::EChanged );
       
   184                 }
       
   185             break;
       
   186             }
       
   187         case TStorageManagerGlobals::EStorageEventListAddition:
       
   188         case TStorageManagerGlobals::EStorageEventListChanged:
       
   189             {
       
   190             eventtype = aEventType == TStorageManagerGlobals::EStorageEventListAddition
       
   191                         ? TEnumsPC::EAddition : TEnumsPC::EChanged;
       
   192             for ( TInt index = 0; index < iGlobalNotificationObservers.Count(); index++ )
       
   193                 {
       
   194                 iGlobalNotificationObservers[index]->HandleChange(
       
   195                     TEnumsPC::EContactListItem, eventtype );
       
   196                 }
       
   197             break;
       
   198             }
       
   199         default:
       
   200             {
       
   201             break;
       
   202             }
       
   203         }
       
   204 
       
   205     if ( error )
       
   206         {
       
   207         CActiveScheduler::Current()->Error( error );
       
   208         }
       
   209 
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------
       
   213 // CCAGlobalNotificationObserverPC::HandleSettingsChangeL
       
   214 // @see MCASettingsObserver
       
   215 // ---------------------------------------------------------
       
   216 
       
   217 void CCAGlobalNotificationObserverPC::HandleSettingsChangeL( TInt aChangedSettingEnum )
       
   218     {
       
   219 
       
   220     for ( TInt index = 0; index < iGlobalNotificationObservers.Count(); index++ )
       
   221         {
       
   222         TEnumsPC::TCASettingValues settings = ConvertToSettingsEnumsPC( aChangedSettingEnum );
       
   223         iGlobalNotificationObservers[index]->HandleSettingsChangeL( settings );
       
   224         }
       
   225 
       
   226     }
       
   227 // --------------------------------------------------------------------
       
   228 // CCAGlobalNotificationObserverPC::ConvertToSettingsEnumsPC
       
   229 // (other items were commented in a header).
       
   230 // --------------------------------------------------------------------
       
   231 //
       
   232 TEnumsPC::TCASettingValues CCAGlobalNotificationObserverPC::ConvertToSettingsEnumsPC(
       
   233     TInt aStatus )
       
   234     {
       
   235     MCASettings::TCASettingFlags engineFlags = ( MCASettings::TCASettingFlags )aStatus;
       
   236 
       
   237     TEnumsPC::TCASettingValues setValue = TEnumsPC::EUnknownValue;
       
   238 
       
   239     // Map status to setting item
       
   240     switch ( engineFlags )
       
   241         {
       
   242         case MCASettings::EDefaultScreenNameInUse :
       
   243             {
       
   244             setValue =  TEnumsPC::EDefaultScreenNameInUse;
       
   245             break;
       
   246             }
       
   247         case MCASettings::EAutomaticPresenceUpdate :
       
   248             {
       
   249             setValue =  TEnumsPC::EAutomaticPresenceUpdate;
       
   250             break;
       
   251             }
       
   252 
       
   253         case MCASettings::EShowOffline :
       
   254             {
       
   255             setValue =  TEnumsPC::EShowOffline;
       
   256             break;
       
   257             }
       
   258         case MCASettings::EShowTimeStamps :
       
   259             {
       
   260             setValue =  TEnumsPC::EShowTimeStamps;
       
   261             break;
       
   262             }
       
   263         default:
       
   264             {
       
   265             break;
       
   266             }
       
   267         }
       
   268     return setValue ;
       
   269     }
       
   270 
       
   271 // ---------------------------------------------------------
       
   272 // CCAGlobalNotificationObserverPC::HandleInvitation()
       
   273 // (other items were commented in a header).
       
   274 // ---------------------------------------------------------
       
   275 //
       
   276 void CCAGlobalNotificationObserverPC::HandleInvitationEventL(
       
   277     TInviteEventType aEvent, const MCAInvitation* aInvitation )
       
   278     {
       
   279     TEnumsPC::TInviteType inviteType = TEnumsPC::EInviteUnknown;
       
   280     switch ( aEvent )
       
   281         {
       
   282         case MCAInviteObserver::ENewInvite:
       
   283             {
       
   284             inviteType = TEnumsPC::ENewInvite;
       
   285             break;
       
   286             }
       
   287         case MCAInviteObserver::EInviteCancel: // Flowthrough
       
   288         case MCAInviteObserver::EInviteExpired:
       
   289             {
       
   290             inviteType = TEnumsPC::EInviteCancelOrExpired;
       
   291             break;
       
   292             }
       
   293 
       
   294         case MCAInviteObserver::EInviteRead:
       
   295             {
       
   296             inviteType = TEnumsPC::EInviteRead;
       
   297             break;
       
   298             }
       
   299         default:
       
   300             {
       
   301             inviteType = TEnumsPC::EInviteUnknown;
       
   302             break;
       
   303             }
       
   304         }
       
   305     for ( TInt index = 0; index < iGlobalNotificationObservers.Count(); index++ )
       
   306         {
       
   307         if ( aInvitation )
       
   308             {
       
   309             iGlobalNotificationObservers[index]->HandleInvitationEventL(
       
   310                 inviteType,
       
   311                 iContactInterface->Identification( aInvitation->UserID() ) ,
       
   312                 aInvitation->Message() );
       
   313             }
       
   314 
       
   315         else
       
   316             {
       
   317             iGlobalNotificationObservers[index]->HandleInvitationEventL(
       
   318                 inviteType,
       
   319                 KNullDesC(), KNullDesC() );
       
   320             }
       
   321         }
       
   322 
       
   323     }
       
   324 
       
   325 // ---------------------------------------------------------
       
   326 // CCAGlobalNotificationObserverPC::HandleInvitationResponse()
       
   327 // (other items were commented in a header).
       
   328 // ---------------------------------------------------------
       
   329 //
       
   330 void CCAGlobalNotificationObserverPC::HandleInvitationResponse(
       
   331     TBool aAcceptance,
       
   332     const TDesC& aUserId,
       
   333     const TDesC& aGroupName,
       
   334     const TDesC& aResponse )
       
   335     {
       
   336     for ( TInt index = 0; index < iGlobalNotificationObservers.Count(); index++ )
       
   337         {
       
   338         iGlobalNotificationObservers[index]->HandleInvitationResponse( aAcceptance,
       
   339                                                                        aUserId,
       
   340                                                                        aGroupName,
       
   341                                                                        aResponse );
       
   342         }
       
   343     }
       
   344 
       
   345 // ---------------------------------------------------------
       
   346 // CCAGlobalNotificationObserverPC::MCAGlobalNotificationObserverPCL()
       
   347 // (other items were commented in a header).
       
   348 // ---------------------------------------------------------
       
   349 //
       
   350 void CCAGlobalNotificationObserverPC::AddGlobalObserverL(
       
   351     MCAUiGlobalNotificationObserverPC* aGlobalObserver )
       
   352     {
       
   353     ASSERT( aGlobalObserver );
       
   354 
       
   355     TInt status( iGlobalNotificationObservers.Append( aGlobalObserver ) );
       
   356     User::LeaveIfError( status );
       
   357     }
       
   358 
       
   359 // ---------------------------------------------------------
       
   360 // CCAGlobalNotificationObserverPC::RemoveGlobalObserver()
       
   361 // (other items were commented in a header).
       
   362 // ---------------------------------------------------------
       
   363 //
       
   364 void CCAGlobalNotificationObserverPC::RemoveGlobalObserver(
       
   365     MCAUiGlobalNotificationObserverPC* aGlobalObserver )
       
   366     {
       
   367     ASSERT( aGlobalObserver );
       
   368 
       
   369     const TInt status( iGlobalNotificationObservers.Find( aGlobalObserver ) );
       
   370     if ( status != KErrNotFound )
       
   371         {
       
   372         iGlobalNotificationObservers.Remove( status );
       
   373         iGlobalNotificationObservers.Compress();
       
   374         }
       
   375     }
       
   376 
       
   377 
       
   378 // -----------------------------------------------------------------------------
       
   379 // CCAGlobalNotificationObserverPC: HandleChatEvent
       
   380 // -----------------------------------------------------------------------------
       
   381 //
       
   382 void CCAGlobalNotificationObserverPC::HandleChatEvent( TChatEventType aEvent,
       
   383                                                        MCAMessage* aMessage /*= NULL*/ )
       
   384     {
       
   385 
       
   386     TEnumsPC::TChatEventType aEventType = TEnumsPC::EEventNotSpecified;
       
   387     TEnumsPC::TMessagerType aMsgrType = TEnumsPC::EMessageOther;
       
   388     TEnumsPC::TMessageType aMsgType = TEnumsPC::EMessageInvalid;
       
   389 
       
   390     const TDesC& wvid( GetWvId( aMessage ) );
       
   391     const TDesC& msgText( aMessage ? aMessage->Text() : KNullDesC );
       
   392     const TPtrC& identification( aMessage ?
       
   393                                  iContactInterface->Identification( wvid ) : KNullDesC() );
       
   394 
       
   395     switch ( aEvent )
       
   396         {
       
   397         case EGroupListChanged:
       
   398             {
       
   399             aEventType = TEnumsPC::EGroupListChanged;
       
   400             break;
       
   401             }
       
   402         case EChatListChanged:
       
   403             {
       
   404             aEventType = TEnumsPC::EChatListChanged;
       
   405             break;
       
   406             }
       
   407         case ESendListChanged:
       
   408             {
       
   409             aEventType = TEnumsPC::ESendListChanged;
       
   410             break;
       
   411             }
       
   412         case EUnreadCountChanged:
       
   413             {
       
   414             aEventType = TEnumsPC::EUnreadCountChanged;
       
   415             break;
       
   416             }
       
   417         case EMemoryLow:
       
   418             {
       
   419             aEventType = TEnumsPC::EMemoryLow;
       
   420             break;
       
   421             }
       
   422         default:
       
   423             {
       
   424             break;
       
   425             }
       
   426 
       
   427         }
       
   428 
       
   429     if ( aMessage )
       
   430         {
       
   431 
       
   432         switch ( aMessage->MessagerType() )
       
   433             {
       
   434             case MCAMessage::EMessageSent:
       
   435                 {
       
   436                 aMsgrType = TEnumsPC::EMessageSent;
       
   437                 break;
       
   438                 }
       
   439             case MCAMessage::EMessageReceived:
       
   440                 {
       
   441                 aMsgrType = TEnumsPC::EMessageReceived;
       
   442                 break;
       
   443                 }
       
   444             default:
       
   445                 {
       
   446                 break;
       
   447                 }
       
   448 
       
   449             }
       
   450 
       
   451 
       
   452         switch ( aMessage->MessageType() )
       
   453             {
       
   454             case MCAMessage::EMessagePTOP:
       
   455                 {
       
   456                 aMsgType = TEnumsPC::EMessagePTOP;
       
   457                 break;
       
   458                 }
       
   459             case MCAMessage::EMessageWhisper:
       
   460                 {
       
   461                 aMsgType = TEnumsPC::EMessageWhisper;
       
   462                 break;
       
   463                 }
       
   464 
       
   465             case MCAMessage::EMessageGroup:
       
   466                 {
       
   467                 aMsgType = TEnumsPC::EMessageGroup;
       
   468                 break;
       
   469                 }
       
   470             case MCAMessage::EMessageSystem:
       
   471                 {
       
   472                 aMsgType = TEnumsPC::EMessageSystem;
       
   473                 break;
       
   474                 }
       
   475             default:
       
   476                 {
       
   477                 break;
       
   478                 }
       
   479 
       
   480             }
       
   481 
       
   482         }
       
   483 
       
   484     for ( TInt index = 0; index < iGlobalNotificationObservers.Count(); index++ )
       
   485         {
       
   486         iGlobalNotificationObservers[index]->HandleChatEvent(
       
   487             aEventType,
       
   488             wvid ,
       
   489             identification,
       
   490             msgText,
       
   491             aMsgrType,
       
   492             aMsgType );
       
   493         }
       
   494     }
       
   495 
       
   496 // -----------------------------------------------------------------------------
       
   497 // CCAAppUi::HandleMessageError
       
   498 // (other items were commented in a header).
       
   499 // -----------------------------------------------------------------------------
       
   500 //
       
   501 void CCAGlobalNotificationObserverPC::HandleMessageError( TInt aError, MCAMessage* aMessage )
       
   502     {
       
   503     for ( TInt index = 0; index < iGlobalNotificationObservers.Count(); index++ )
       
   504         {
       
   505         iGlobalNotificationObservers[index]->HandleMessageError(
       
   506             aError,
       
   507             aMessage->Text() );
       
   508         }
       
   509     }
       
   510 
       
   511 
       
   512 // -----------------------------------------------------------------------------
       
   513 // CCAGlobalNotificationObserverPC::GetWvId
       
   514 // (other items were commented in a header).
       
   515 // -----------------------------------------------------------------------------
       
   516 //
       
   517 const TDesC& CCAGlobalNotificationObserverPC::GetWvId( MCAMessage* aMessage )
       
   518     {
       
   519     if ( aMessage )
       
   520         {
       
   521 
       
   522         if ( aMessage->MessageType() == MCAMessage::EMessagePTOP )
       
   523             {
       
   524             return aMessage->Sender();
       
   525             }
       
   526         else
       
   527             {
       
   528             return aMessage->Target();
       
   529             }
       
   530         }
       
   531 
       
   532     return KNullDesC;
       
   533     }
       
   534 // -----------------------------------------------------------------------------
       
   535 // CCAGlobalNotificationObserverPC::IsContactListsSyncDoneL()
       
   536 // (other items were commented in a header).
       
   537 // -----------------------------------------------------------------------------
       
   538 //
       
   539 TBool CCAGlobalNotificationObserverPC::IsContactListsSyncDoneL()
       
   540     {
       
   541 
       
   542     MCAContactLists* contactLists =
       
   543         CAPresenceManager::InstanceL()->ContactLists();
       
   544     if ( !contactLists )
       
   545         {
       
   546         // not logged in yet, so sync state is ok
       
   547         return ETrue;
       
   548         }
       
   549     return contactLists->IsSyncDone();
       
   550     }
       
   551 
       
   552 // -----------------------------------------------------------------------------
       
   553 // CCAGlobalNotificationObserverPC::StoredContactsIsAllSynchronised
       
   554 // (other items were commented in a header).
       
   555 // -----------------------------------------------------------------------------
       
   556 //
       
   557 TBool CCAGlobalNotificationObserverPC::StoredContactsIsAllSynchronised( TBool& aFailed )
       
   558     {
       
   559     return iContactInterface->IsAllSynchronised( aFailed );
       
   560     }
       
   561 
       
   562 // -----------------------------------------------------------------------------
       
   563 // CCAGlobalNotificationObserverPC::IsValidListInterface
       
   564 // (other items were commented in a header).
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 TBool CCAGlobalNotificationObserverPC::IsValidStoredContactsInterface()
       
   568     {
       
   569     if ( iContactInterface )
       
   570         {
       
   571         return ETrue;
       
   572         }
       
   573     else
       
   574         {
       
   575         return EFalse;
       
   576         }
       
   577     }
       
   578 
       
   579 // -----------------------------------------------------------------------------
       
   580 // CCAGlobalNotificationObserverPC::IsValidListInterfaceL
       
   581 // (other items were commented in a header).
       
   582 // -----------------------------------------------------------------------------
       
   583 //
       
   584 TBool CCAGlobalNotificationObserverPC::IsValidListInterfaceL()
       
   585     {
       
   586     MCAContactLists* contactLists =
       
   587         CAPresenceManager::InstanceL()->ContactLists();
       
   588     if ( contactLists )
       
   589         {
       
   590         return ETrue;
       
   591         }
       
   592     else
       
   593         {
       
   594         return EFalse;
       
   595         }
       
   596     }
       
   597 
       
   598 //end of file
       
   599