wvuing/wvuiprocess/Src/ccagrouppc.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:  Implementation for PC Group Interface
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "ccagrouppc.h"
       
    22 #include "MCAStoredGroups.h"
       
    23 #include "CCAStorageManagerFactory.h"
       
    24 #include "mcagroupobserverpc.h"
       
    25 #include "CCAEngine.h"
       
    26 #include "MCAChatInterface.h"
       
    27 #include "mcamessageswriteinterface.h"
       
    28 #include "mcamessagecontainerinfo.h"
       
    29 #include "MCAStoredGroup.h"
       
    30 #include "MCAMessage.h"
       
    31 #include "MCAStoredContacts.h"
       
    32 #include "MCAGroupEventObserverPC.h"
       
    33 #include "MCAGroupOperations.h"
       
    34 #include "MCAGroupManagerInterface.h"
       
    35 #include "MCAExtendedStoredGroup.h"
       
    36 #include "MCAMessageUtils.h"
       
    37 #include "MCAMessageErrorInformer.h"
       
    38 #include "MCAMessageCreator.h"
       
    39 #include "CAUtils.h"
       
    40 #include "CCAServerContactsArrayPC.h"
       
    41 #include "CAPresenceManager.h"
       
    42 #include "MCAPresence.h"
       
    43 
       
    44 
       
    45 
       
    46 
       
    47 // ============================ MEMBER FUNCTIONS ===============================
       
    48 
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CCAGroupPC: Constructor
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CCAGroupPC::CCAGroupPC( MCAGroupManagerInterface* aGroupInterface,
       
    55                         MCAChatInterface& aChatInterface,
       
    56                         const MCAMessageUtils& aMessageUtils  )
       
    57         : iGroupInterface( aGroupInterface ),
       
    58         iChatInterface( aChatInterface ),
       
    59         iMessageUtils( aMessageUtils )
       
    60 
       
    61     {
       
    62     }
       
    63 
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CCAGroupPC: NewL
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CCAGroupPC* CCAGroupPC::NewL( MCAGroupManagerInterface* aGroupInterface,
       
    70                               MCAChatInterface& aChatInterface,
       
    71                               const MCAMessageUtils& aMessageUtils )
       
    72     {
       
    73     CCAGroupPC* self = new ( ELeave ) CCAGroupPC( aGroupInterface,
       
    74                                                   aChatInterface, aMessageUtils );
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     CleanupStack::Pop( self );
       
    78     return self;
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CCAGroupPC: ConstructL
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void CCAGroupPC::ConstructL(  )
       
    86     {
       
    87     iStoredGroups = CCAStorageManagerFactory::GroupListInterfaceL();
       
    88     iStoredContacts = CCAStorageManagerFactory::ContactListInterfaceL();
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CCAGroupPC: Destructor
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 CCAGroupPC::~CCAGroupPC()
       
    96     {
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CCAGroupPC: RegisterGroupObserver
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CCAGroupPC::RegisterGroupObserver( MCAGroupObserverPC*  aGroupObserverPC )
       
   104     {
       
   105     ASSERT( aGroupObserverPC );
       
   106     iGroupObserverPC = aGroupObserverPC;
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CCAGroupPC: UnRegisterGroupObserver
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void CCAGroupPC::UnRegisterGroupObserver()
       
   114     {
       
   115     iGroupObserverPC = NULL;
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CCAGroupPC: SetGroupEventObserverL
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 void CCAGroupPC::SetGroupEventObserverL( MCAGroupEventObserverPC* aGroupEventObserverPC,
       
   123                                          const TDesC& aGroupId )
       
   124     {
       
   125     iGroupEventObserverPC = aGroupEventObserverPC;
       
   126 
       
   127     if ( !iGroupInterface )
       
   128         {
       
   129         return;
       
   130         }
       
   131 
       
   132     // Register this as chat observer
       
   133     if ( iGroupEventObserverPC )
       
   134         {
       
   135         iGroupInterface->SetGroupEventObserverL( aGroupId, this );
       
   136         }
       
   137     else
       
   138         {
       
   139         iGroupInterface->SetGroupEventObserverL( aGroupId, NULL );
       
   140         }
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CCAGroupPC: ActiveGroupId
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 const TDesC& CCAGroupPC::ActiveGroupId()
       
   148     {
       
   149     return iReadInterface->TargetId().Target();
       
   150     }
       
   151 
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CCAGroupPC: ScreenName
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 const TDesC& CCAGroupPC::ScreenName() const
       
   158     {
       
   159 
       
   160     if ( iReadInterface )
       
   161         {
       
   162         return iReadInterface->TargetId().ScreenName();
       
   163         }
       
   164 
       
   165 
       
   166     // Fix warning: #940-D: missing return statement at end of non-void function
       
   167     else
       
   168         {
       
   169         return KNullDesC();
       
   170         }
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CCAGroupPC: IsLoggingOn
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 TBool CCAGroupPC::IsLoggingOn() const
       
   178     {
       
   179     return iReadInterface->IsLoggingOn();
       
   180     }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CCAGroupPC: EndLoggingL
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 void CCAGroupPC::EndLoggingL()
       
   187     {
       
   188     iReadInterface->EndLoggingL();
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // CCAGroupPC: SaveChatL
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 void CCAGroupPC::SaveChatL( const TDesC& aLogFilename )
       
   196     {
       
   197     iReadInterface->StartLoggingL( aLogFilename );
       
   198 
       
   199     if ( iReadInterface->IsLoggingOn() )
       
   200         {
       
   201         iReadInterface->EndLoggingL();
       
   202         }
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CCAGroupPC: GetPropertiesL
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 TInt CCAGroupPC::GetPropertiesL( TBool& aIsGroupProps )
       
   210     {
       
   211     if ( !iGrOps )
       
   212         {
       
   213         return KErrGeneral;
       
   214         }
       
   215 
       
   216     TInt err( KErrNone );
       
   217     err = iGrOps->GetPropertiesL( iGroupProps, iPrivateProps );
       
   218     if ( iGroupProps )
       
   219         {
       
   220         aIsGroupProps = ETrue;
       
   221         }
       
   222     else
       
   223         {
       
   224         aIsGroupProps = EFalse;
       
   225         }
       
   226     return err;
       
   227 
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CCAGroupPC: GroupName
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 TPtrC CCAGroupPC::GroupName( ) const
       
   235     {
       
   236     if ( !iGroupProps )
       
   237         {
       
   238         return KNullDesC();
       
   239         }
       
   240     return iGroupProps->GroupName();
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // CCAGroupPC: IsPrivateAllowed
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 TEnumsPC::TImpsPropertyBoolPC CCAGroupPC::IsPrivateAllowed()
       
   248     {
       
   249     return ConvertTImpsPropertyBoolToTEnumsPC( iGroupProps->IsPrivateAllowed() );
       
   250     }
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CCAGroupPC: IsOpen
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 TEnumsPC::TImpsPropertyBoolPC CCAGroupPC::IsOpen()
       
   257     {
       
   258     return ConvertTImpsPropertyBoolToTEnumsPC( iGroupProps->IsOpen() );
       
   259     }
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // CCAGroupPC::ConvertTImpsPropertyBoolToTEnumsPC
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 TEnumsPC::TImpsPropertyBoolPC CCAGroupPC::ConvertTImpsPropertyBoolToTEnumsPC
       
   266 ( TImpsPropertyBool aEventSource )
       
   267     {
       
   268 
       
   269     switch ( aEventSource )
       
   270         {
       
   271         case EImpsPropUndef:
       
   272             {
       
   273             return TEnumsPC::EImpsPropUndef;
       
   274             }
       
   275         case EImpsPropNo:
       
   276             {
       
   277             return TEnumsPC::EImpsPropNo;
       
   278             }
       
   279         case EImpsPropYes:
       
   280             {
       
   281             return TEnumsPC::EImpsPropYes;
       
   282             }
       
   283 
       
   284         default:
       
   285             {
       
   286             return TEnumsPC::EImpsPropUndef;
       
   287             }
       
   288         }
       
   289     }
       
   290 
       
   291 
       
   292 // ---------------------------------------------------------
       
   293 // CCAGroupPC::GroupCount
       
   294 // (other items were commented in a header).
       
   295 // ---------------------------------------------------------
       
   296 //
       
   297 TInt CCAGroupPC::GroupCount( TBool aOnlyVisible ) const
       
   298     {
       
   299     return iStoredGroups->GroupCount( aOnlyVisible );
       
   300     }
       
   301 
       
   302 
       
   303 // ---------------------------------------------------------
       
   304 // CCAGroupPC::ContactCount
       
   305 // (other items were commented in a header).
       
   306 // ---------------------------------------------------------
       
   307 //
       
   308 TInt CCAGroupPC::ContactCount( TBool aSkipOfflineContacts ) const
       
   309     {
       
   310     return iStoredContacts->ContactCount( aSkipOfflineContacts );
       
   311     }
       
   312 
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 // CCAGroupPC: InitialiseResourcesL
       
   316 // -----------------------------------------------------------------------------
       
   317 //
       
   318 void CCAGroupPC::InitialiseResourcesL( const TDesC& aGroupId )
       
   319     {
       
   320     //can be used as data member if used many times
       
   321     if ( iGroupId )
       
   322         {
       
   323         delete iGroupId ;
       
   324         iGroupId = NULL;
       
   325         }
       
   326     iGroupId = aGroupId.AllocL();
       
   327 
       
   328     // resolve message read interface
       
   329     //read/write interface can be done in ctor after complete refactoring
       
   330     iReadInterface =
       
   331         &( iChatInterface.MessageReadInterfaceL( KNullDesC, KNullDesC, *iGroupId ) );
       
   332     iWriteInterface =
       
   333         &( iChatInterface.MessageWriteInterfaceL( KNullDesC, KNullDesC ) );
       
   334 
       
   335     iStoredGroup = iStoredGroups->FindGroup( *iGroupId );
       
   336     if ( iGroupInterface )
       
   337         {
       
   338         iGrOps = iGroupInterface->GroupOperationsL( *iGroupId );
       
   339         }
       
   340     // Register this as chat observer
       
   341     iChatInterface.RegisterChatObserver( this );
       
   342     //register this as message error observer
       
   343     iMessageUtils.MessageErrorInformer().RegisterObserver( this );
       
   344     }
       
   345 
       
   346 // -----------------------------------------------------------------------------
       
   347 // CCAGroupPC: ReleaseResources
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 void CCAGroupPC::ReleaseResources()
       
   351     {
       
   352     iChatInterface.UnregisterChatObserver( this );
       
   353     iMessageUtils.MessageErrorInformer().UnregisterObserver( this );
       
   354 
       
   355     delete iGroupId;
       
   356     iGroupId = NULL;
       
   357     }
       
   358 
       
   359 // -----------------------------------------------------------------------------
       
   360 // CCAGroupPC: ReadInterface
       
   361 // -----------------------------------------------------------------------------
       
   362 //
       
   363 MCAMessagesReadInterface& CCAGroupPC::ReadInterfaceL() const
       
   364     {
       
   365     if ( !iReadInterface )
       
   366         {
       
   367         User::Leave( KErrGeneral );
       
   368         }
       
   369     return *iReadInterface;
       
   370     }
       
   371 
       
   372 // -----------------------------------------------------------------------------
       
   373 // CCAGroupPC: WriteInterface
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 MCAMessagesWriteInterface& CCAGroupPC::WriteInterfaceL() const
       
   377     {
       
   378     if ( !iWriteInterface )
       
   379         {
       
   380         User::Leave( KErrGeneral );
       
   381         }
       
   382     return *iWriteInterface;
       
   383     }
       
   384 
       
   385 // -----------------------------------------------------------------------------
       
   386 // CCAGroupPC: HandleChatEvent
       
   387 // -----------------------------------------------------------------------------
       
   388 //
       
   389 void CCAGroupPC::HandleChatEvent( TChatEventType aEvent, MCAMessage* aMessage )
       
   390     {
       
   391 
       
   392     if ( aEvent == EUnreadCountChanged && aMessage )
       
   393         {
       
   394         if ( aMessage->MessageType() != MCAMessage::EMessagePTOP )
       
   395             {
       
   396             // don't show flasher if this isn't p2p message
       
   397             // or if there's no container (this view isn't active)
       
   398             return;
       
   399             }
       
   400 
       
   401         const TDesC& wvid( aMessage->Sender() );
       
   402 
       
   403         // nickname or wv-less contact id
       
   404 
       
   405         if ( iGroupObserverPC && iStoredContacts )
       
   406             {
       
   407             iGroupObserverPC->HandleChatEvent( wvid ,
       
   408                                                iStoredContacts->Identification( wvid ) ) ;
       
   409             }
       
   410         }
       
   411     }
       
   412 
       
   413 // ---------------------------------------------------------
       
   414 // CCAGroupPC::HandleGroupLeft
       
   415 // (other items were commented in a header).
       
   416 // ---------------------------------------------------------
       
   417 //
       
   418 void CCAGroupPC::HandleGroupLeft( TInt aReason )
       
   419     {
       
   420     if ( iGroupEventObserverPC )
       
   421         {
       
   422         iGroupEventObserverPC->HandleGroupLeft( aReason );
       
   423         }
       
   424     }
       
   425 
       
   426 // ---------------------------------------------------------
       
   427 // CCAGroupPC::HandleGroupPropertiesChanged()
       
   428 // (other items were commented in a header).
       
   429 // ---------------------------------------------------------
       
   430 //
       
   431 void CCAGroupPC::HandleGroupPropertiesChanged()
       
   432     {
       
   433     if ( iGroupEventObserverPC )
       
   434         {
       
   435         iGroupEventObserverPC->HandleGroupPropertiesChanged( );
       
   436         }
       
   437 
       
   438     }
       
   439 
       
   440 // ---------------------------------------------------------
       
   441 // CCAGroupPC::HandleMessageError()
       
   442 // (other items were commented in a header).
       
   443 // ---------------------------------------------------------
       
   444 //
       
   445 void CCAGroupPC::HandleMessageError( TInt aError, MCAMessage* aMessage )
       
   446     {
       
   447     TPtrC nick( KNullDesC );
       
   448 
       
   449     if ( !iGroupObserverPC )
       
   450         {
       
   451         return;
       
   452         }
       
   453 
       
   454     if ( aMessage )
       
   455         {
       
   456         if ( aMessage->ContentType() == MCAMessage::EContentPicture )
       
   457             {
       
   458             iGroupObserverPC->HandleMessageError( aError );
       
   459 
       
   460             return;
       
   461             }
       
   462 
       
   463         nick.Set( iStoredContacts->Identification( aMessage->Recipient() ) );
       
   464         }
       
   465 
       
   466     iGroupObserverPC->HandleMessageError( aError, nick );
       
   467     }
       
   468 
       
   469 
       
   470 // -----------------------------------------------------------------------------
       
   471 // CCAGroupPC: SendMessageL
       
   472 // -----------------------------------------------------------------------------
       
   473 //
       
   474 void CCAGroupPC::SendMessageL( const TDesC& aMessageBuffer,
       
   475                                CDesCArrayFlat& aRecipients )
       
   476     {
       
   477 
       
   478     MCAMessageCreator& creator = iMessageUtils.MessageCreator();
       
   479 
       
   480     const MCAMessageContainerInfo& info = iReadInterface->TargetId();
       
   481 
       
   482     MCAMessageCreator::SMessageData data =
       
   483         {
       
   484         KMessageDataVersion,
       
   485         0,
       
   486         KNullDesC,
       
   487         KNullDesC,
       
   488         info.ScreenName(), // Sender
       
   489         info.Target(), // Recipient
       
   490         NULL,
       
   491         &aRecipients,
       
   492         aMessageBuffer,
       
   493         KNullDesC8,
       
   494         KNullDesC8,
       
   495         MCAMessage::EMessageSent
       
   496         };
       
   497 
       
   498     iWriteInterface->AppendL( creator.CreateMessageL( data ) );
       
   499     }
       
   500 
       
   501 
       
   502 // -----------------------------------------------------------------------------
       
   503 // CCAGroupPC: SetActiveGroupChatL
       
   504 // -----------------------------------------------------------------------------
       
   505 //
       
   506 void CCAGroupPC::SetActiveGroupChatL( const TDesC& aGroupId )
       
   507     {
       
   508     if ( iGroupId )
       
   509         {
       
   510         delete iGroupId;
       
   511 
       
   512         iGroupId = NULL;
       
   513         }
       
   514 
       
   515 
       
   516     iGroupId = aGroupId.AllocL();
       
   517 
       
   518     iReadInterface =
       
   519         &( iChatInterface.MessageReadInterfaceL( KNullDesC, KNullDesC, *iGroupId ) );
       
   520 
       
   521     iStoredGroup = iStoredGroups->FindGroup( *iGroupId );
       
   522 
       
   523     iGrOps = iGroupInterface->GroupOperationsL( *iGroupId );
       
   524 
       
   525 
       
   526     if ( !iGroupId )
       
   527         {
       
   528         iGroupId = KNullDesC().AllocL();
       
   529         }
       
   530 
       
   531     }
       
   532 
       
   533 // -----------------------------------------------------------------------------
       
   534 // CCAGroupPC::GetGroupPairArrayLC
       
   535 // -----------------------------------------------------------------------------
       
   536 //
       
   537 MCAServerContactsArrayPC* CCAGroupPC::GetGroupPairArrayLC()
       
   538     {
       
   539     RPointerArray<MCAStoredGroup> groupList;
       
   540 
       
   541     CDesCArray* groupNames = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   542     CleanupStack::PushL( groupNames );
       
   543     CDesCArray* groupIds = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   544     CleanupStack::PushL( groupIds );
       
   545 
       
   546     CleanupClosePushL( groupList );
       
   547     iStoredGroups->PopulateGroupsListL( groupList );
       
   548 
       
   549     TInt count( groupList.Count() );
       
   550     for ( TInt index( 0 ); index < count; index++ )
       
   551         {
       
   552         if ( 0 != groupList[ index ]->GroupId().CompareC( *iGroupId ) )
       
   553             {
       
   554             // other than current group
       
   555             groupNames->AppendL( groupList[ index ]->GroupName() );
       
   556             groupIds->AppendL( groupList[ index ]->GroupId() );
       
   557             }
       
   558         }
       
   559     //Codescanner warning ignored
       
   560     CleanupStack::PopAndDestroy(); // groupList.Close()
       
   561     //Codescanner warning ignored
       
   562     CleanupStack::Pop( 2, groupNames );  //groupIds,groupNames
       
   563 
       
   564     CCAServerContactsArrayPC* pairsArray =
       
   565         CCAServerContactsArrayPC::NewL( groupNames, groupIds, KNullDesC );
       
   566 
       
   567     //Not owned. Transfer ownership of pairsArray to the caller.
       
   568     //since we return as MCAServerContactsArrayPC object sliciing will happen
       
   569     //so its better to push the original data onto stack
       
   570     CleanupStack::PushL( pairsArray );
       
   571 
       
   572     return pairsArray;
       
   573     }
       
   574 
       
   575 
       
   576 // -----------------------------------------------------------------------------
       
   577 // CCAGroupPC::IsActiveGroupChat
       
   578 // -----------------------------------------------------------------------------
       
   579 //
       
   580 TBool CCAGroupPC::IsActiveGroupChat( const TDesC& aGroupId )
       
   581 
       
   582     {
       
   583     TBool retValue = EFalse;
       
   584 
       
   585     if ( iGroupId )
       
   586         {
       
   587         if ( !CAUtils::NeutralCompare( aGroupId, *iGroupId ) )
       
   588             {
       
   589             retValue = ETrue;
       
   590             }
       
   591         }
       
   592 
       
   593     return  retValue;
       
   594     }
       
   595 
       
   596 
       
   597 //-----------------------------------------------------------
       
   598 //CCAGroupPC::MessageCount
       
   599 //-----------------------------------------------------------
       
   600 TInt CCAGroupPC::MessageCount()
       
   601     {
       
   602     if ( iReadInterface )
       
   603         {
       
   604         return iReadInterface->MessageCount();
       
   605         }
       
   606 
       
   607     return 0;
       
   608 
       
   609     }
       
   610 
       
   611 // End of File
       
   612