wvuing/wvuiave/AppSrc/CCAGroupUtils.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:  Group handling utilities
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //INCLUDES
       
    20 #include    "ImpsCSPAllErrors.h"
       
    21 #include    "CCAGroupUtils.h"
       
    22 
       
    23 #include    "chatngclient.hrh"
       
    24 #include    "ChatDefinitions.h"
       
    25 #include    "CAExternalInterface.h"
       
    26 #include    "CCAAppUi.h"
       
    27 
       
    28 #include    "ChatDebugPrint.h"
       
    29 #include    "CCAGroupPropertiesDialog.h"
       
    30 #include    "IMNoteMapper.h"
       
    31 #include    "IMDialogUtils.h"
       
    32 #include    "StringLoader.h"
       
    33 #include    "CCAStatusPaneHandler.h"
       
    34 #include    "CCAChatInfoArray.h"
       
    35 #include    "CAArrayUtils.h"
       
    36 #include    "CCAUISessionManager.h"
       
    37 #include    "IMUtils.h"
       
    38 #include    "CAUtils.h"
       
    39 #include    "CCAApp.h"
       
    40 #include    "CCAVariantFactory.h"
       
    41 #include    "CCAContactSelectionDialog.h"
       
    42 #include    "CCAUINGUtils.h"
       
    43 #include    "CCAPCUtils.h"
       
    44 
       
    45 #include    "MCAConversationMessage.h"
       
    46 #include	"MCAProcessManager.h"
       
    47 #include    "MCAGroupPC.h"
       
    48 #include 	"MCAGroupUtilsPC.h"
       
    49 
       
    50 
       
    51 #include    <chatNG.rsg>
       
    52 #include    <chatNG.mbg>
       
    53 #include    <impsgroupprops.h>
       
    54 #include    <aknnotewrappers.h>
       
    55 #include    <aknlists.h>
       
    56 #include    <bautils.h>
       
    57 
       
    58 // The Settings have been moved to Cenrep (also retained in the Resource file),
       
    59 // so the enums for keys and central repository header is added here
       
    60 #include 	"VariantKeys.h"
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CCAGroupUtils::CCAGroupUtils
       
    64 // C++ default constructor can NOT contain any code, that
       
    65 // might leave.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CCAGroupUtils::CCAGroupUtils( MCAViewSwitcher& aViewSwitcher )
       
    69         : iViewSwitcher( aViewSwitcher ),
       
    70         iCurrState( ESGCNone ),
       
    71         iPrevState( ESGCNone ),
       
    72         iScreenNamePtr( NULL, 0 )
       
    73     {
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CCAGroupUtils::NewL
       
    78 // Two-phased constructor.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CCAGroupUtils* CCAGroupUtils::NewLC( MCAViewSwitcher& aViewSwitcher )
       
    82     {
       
    83     CCAGroupUtils* temp = new( ELeave )CCAGroupUtils( aViewSwitcher );
       
    84     CleanupStack::PushL( temp );
       
    85     temp->ConstructL();
       
    86     return temp;
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CCAGroupUtils::ResolveInviteConflictL
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void CCAGroupUtils::ResolveInviteConflictL( const TDesC& aGroup,
       
    94                                             CDesCArray& aArray )
       
    95     {
       
    96 
       
    97 
       
    98 
       
    99 
       
   100 
       
   101     // get the banned and all user list  from pc
       
   102     TInt countInvite( aArray.MdcaCount() );
       
   103 
       
   104     if ( !countInvite )
       
   105         {
       
   106         //no possible conflicts
       
   107         return;
       
   108         }
       
   109 
       
   110     iAppUi->ShowWaitDialogLC( R_QTN_GEN_CHAT_NOTE_PROCESSING, ETrue );
       
   111 
       
   112     TInt err( KErrNone );
       
   113 
       
   114 
       
   115     CDesCArray* banned = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   116     CleanupStack::PushL( banned );
       
   117 
       
   118     // Check server capabilities for group reject list
       
   119     if ( iAppUi->UISessionManager().IsSupported( CCAUISessionManager::EGroupRejectList ) )
       
   120         {
       
   121         // If supported, fetch list
       
   122         err = iGroupUtilsPC->GetRejectListL( *banned, aGroup );
       
   123         }
       
   124 
       
   125 
       
   126     if ( err == ECSPInsufficientGroupPrivileges )
       
   127         {
       
   128         //not enough group rights
       
   129         CleanupStack::PopAndDestroy( 2 ); // banned, wait
       
   130         return;
       
   131         }
       
   132 
       
   133     User::LeaveIfError( err );
       
   134 
       
   135     if ( banned->MdcaCount() == 0 )
       
   136         {
       
   137         //no possible conflict , nothing to do, just cleanup
       
   138         CleanupStack::PopAndDestroy( 2 ); // banned, wait
       
   139         return;
       
   140         }
       
   141 
       
   142 
       
   143     CDesCArray* userList = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   144     CleanupStack::PushL( userList );
       
   145     CDesCArray* screenNames  = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   146     CleanupStack::PushL( screenNames );
       
   147     CDesCArray* moders = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   148     CleanupStack::PushL( moders );
       
   149     CDesCArray* admins = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   150     CleanupStack::PushL( admins );
       
   151 
       
   152     err = iGroupUtilsPC->GetMembersL( *userList,
       
   153                                       *screenNames,
       
   154                                       *moders,
       
   155                                       *admins, aGroup );
       
   156     User::LeaveIfError( err );
       
   157 
       
   158     CDesCArray* newBanned = CAArrayUtils::CloneArrayLC( *banned );
       
   159     CDesCArray* newUserlist = CAArrayUtils::CloneArrayLC( *userList );
       
   160 
       
   161     TInt bannedCount( banned->MdcaCount() );
       
   162     TInt pos( KErrNotFound );
       
   163     TInt userlistInUse = userList->MdcaCount();
       
   164 
       
   165     for ( TInt i( 0 ); i < bannedCount; i++ )
       
   166         {
       
   167         pos = CAUtils::NeutralFind( aArray, banned->MdcaPoint( i ) );
       
   168         if ( pos != KErrNotFound )
       
   169             {
       
   170             //we have a conflict to resolve
       
   171             HBufC* prompt = StringLoader::LoadLC( R_QTN_CHAT_INVITE_REMOVE_BANNED,
       
   172                                                   iGroupUtilsPC->GetIdentificationL( banned->MdcaPoint( i ) ) );
       
   173 
       
   174             TInt ret( IMDialogUtils::DisplayQueryDialogL( R_GENERIC_YES_NO_CONFIRMATION_QUERY,
       
   175                                                           *prompt ) );
       
   176             CleanupStack::PopAndDestroy( prompt );
       
   177 
       
   178             if ( ( ret == EAknSoftkeyOk ) || ( ret == EAknSoftkeyYes )  )
       
   179                 {
       
   180                 //lets remove from the banned list
       
   181                 newBanned->Delete( i );
       
   182                 if ( userlistInUse )
       
   183                     {
       
   184                     newUserlist->AppendL( banned->MdcaPoint( i ) );
       
   185                     }
       
   186                 }
       
   187             else
       
   188                 {
       
   189                 //lets removed from the invitation list
       
   190                 aArray.Delete( pos );
       
   191                 }
       
   192             }
       
   193         }
       
   194 
       
   195     if ( newBanned->MdcaCount() != bannedCount )
       
   196         {
       
   197         //we need to update group props
       
   198         CDesCArray* newAdminlist = CAArrayUtils::CloneArrayLC( *admins );
       
   199         iGroupUtilsPC->UpdateGroupMembersL(
       
   200             aGroup,
       
   201             *admins, *newAdminlist,
       
   202             *userList, *newUserlist,
       
   203             *banned, *newBanned );
       
   204         CleanupStack::PopAndDestroy( newAdminlist );
       
   205         }
       
   206 
       
   207     // newUserlist , newBanned, admins, moders, screenNames
       
   208     CleanupStack::PopAndDestroy( 8 ); // banned, userlist, wait
       
   209     }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CCAGroupUtils::~CCAGroupUtils
       
   213 // Destructor
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 CCAGroupUtils::~CCAGroupUtils()
       
   217     {
       
   218     delete iGroupId;
       
   219     delete iAsyncCb;
       
   220     delete iJoinGroupId;
       
   221 
       
   222     if ( iWait.IsStarted() )
       
   223         {
       
   224         iWait.AsyncStop();
       
   225         }
       
   226 
       
   227     delete iAsyncGroupId;
       
   228     delete iAsyncScreenName;
       
   229     }
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CCAGroupUtils::ConstructL
       
   233 // Symbian 2nd phase constructor can leave.
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 void CCAGroupUtils::ConstructL()
       
   237     {
       
   238     iAppUi = static_cast<CCAAppUi*>( CEikonEnv::Static()->AppUi() );
       
   239     iGroupPC = iAppUi->GetProcessManager().GetGroupInterface();
       
   240     iGroupUtilsPC = iAppUi->GetProcessManager().GetGroupUtilsInterface() ;
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // CCAGroupUtils::EditChatGroupPropertiesL
       
   245 // (other items were commented in a header).
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 TInt CCAGroupUtils::EditChatGroupPropertiesL( const TDesC& aGroupId )
       
   249     {
       
   250 
       
   251 
       
   252     CHAT_DP_FUNC_ENTER( "EditChatGroupPropertiesL" );
       
   253 
       
   254     TBool areItemsEdited( EFalse );
       
   255 
       
   256     // create lists
       
   257     CDesCArray* userList = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   258     CleanupStack::PushL( userList );
       
   259     CDesCArray* screenNames  = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   260     CleanupStack::PushL( screenNames );
       
   261     CDesCArray* moders = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   262     CleanupStack::PushL( moders );
       
   263     CDesCArray* admins = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   264     CleanupStack::PushL( admins );
       
   265     CDesCArray* rejected = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   266     CleanupStack::PushL( rejected );
       
   267 
       
   268     TInt err( KErrNone );
       
   269     iAppUi->ShowWaitDialogL( R_QTN_GEN_CHAT_NOTE_PROCESSING, ETrue );
       
   270 
       
   271 
       
   272     TRAPD( leave, err = iGroupUtilsPC->GetGroupDataL( aGroupId, *userList, *screenNames,
       
   273                                                       *moders, *admins, *rejected ) );
       
   274 
       
   275     iAppUi->DismissWaitDialogL( leave );
       
   276 
       
   277     if ( err != KErrNone )
       
   278         {
       
   279         IMNoteMapper::ShowNoteL( err );
       
   280         CleanupStack::PopAndDestroy( 5, userList ); // rejected, admins,
       
   281         // moders, screenNames, userList
       
   282         return EAknSoftkeyCancel;
       
   283         }
       
   284 
       
   285     iGroupUtilsPC->MoveOwnIdToFirstL( *admins );
       
   286 
       
   287     // store the original arrays
       
   288     // (we'll ignore screennames and moderators)
       
   289     CDesCArray* oldUserList = CAArrayUtils::CloneArrayLC( *userList );
       
   290     CDesCArray* oldAdmins = CAArrayUtils::CloneArrayLC( *admins );
       
   291     CDesCArray* oldRejected = CAArrayUtils::CloneArrayLC( *rejected );
       
   292 
       
   293 
       
   294     // construct the groupproperties dialog
       
   295     CCAGroupPropertiesDialog* groupPropDialog =
       
   296         new( ELeave )CCAGroupPropertiesDialog(
       
   297         *iViewSwitcher.CAStatusPane(),
       
   298         ETrue,
       
   299         *userList,
       
   300         *admins,
       
   301         *rejected,
       
   302         aGroupId,
       
   303         areItemsEdited );
       
   304 
       
   305     CleanupStack::PushL( groupPropDialog );
       
   306     groupPropDialog->ConstructL( R_CHATCLIENT_MENUBAR_CHAT_PROPERTIES_VIEW );
       
   307 
       
   308     // launch the dialog
       
   309     CleanupStack::Pop( groupPropDialog );
       
   310     TInt result( groupPropDialog->ExecuteLD( R_CHATCLIENT_GROUPPROPERTIES_DLG ) );
       
   311     CHAT_DP( D_CHAT_LIT(
       
   312                  "CCAGroupUtils::EditChatGroupPropertiesL areItemsEdited: %d" ),
       
   313              areItemsEdited );
       
   314 
       
   315     if ( ( result == EAknSoftkeyDone || result == EAknSoftkeyYes ) && areItemsEdited )
       
   316         {
       
   317         // Display wait note. Move this to utils side.
       
   318         iAppUi->ShowWaitDialogL( R_QTN_GEN_NOTE_SAVING, ETrue );
       
   319 
       
   320         // Update properties
       
   321         TInt err( KErrNone );
       
   322 
       
   323         TRAP( leave, err = iGroupUtilsPC->ProcessEditedGroupPropertiesL(
       
   324                                aGroupId, *oldAdmins, *admins, *oldUserList, *userList,
       
   325                                *oldRejected, *rejected ) );
       
   326 
       
   327         iAppUi->DismissWaitDialogL( leave );
       
   328         if ( err != KErrNone )
       
   329             {
       
   330             IMNoteMapper::ShowNoteL( err );
       
   331             CleanupStack::PopAndDestroy( 8, userList );
       
   332             return EAknSoftkeyCancel;
       
   333             }
       
   334         }
       
   335     else if ( result == EAknSoftkeyExit )
       
   336         {
       
   337         CEikonEnv::Static()->EikAppUi()->HandleCommandL( EChatClientCmdExit );
       
   338         }
       
   339 
       
   340     CleanupStack::PopAndDestroy( 8, userList );
       
   341     CHAT_DP_FUNC_DONE( "EditChatGroupPropertiesL" );
       
   342     return result;
       
   343     }
       
   344 
       
   345 // utilsside_complete
       
   346 // -----------------------------------------------------------------------------
       
   347 // CCAGroupUtils::AskScreenNameL
       
   348 // (other items were commented in a header).
       
   349 // -----------------------------------------------------------------------------
       
   350 //
       
   351 TInt CCAGroupUtils::AskScreenNameL( TDes& aScreenName )
       
   352     {
       
   353     // don't call this directly, call ScreenNameQueryL instead
       
   354 
       
   355     // make sure we're not capturing
       
   356     TBool wasCapturing = iAppUi->AreEventsCaptured();
       
   357     iAppUi->ReleaseCapturingL();
       
   358 
       
   359     // ask for the screenname
       
   360     TInt result = IMDialogUtils::DisplayTextQueryDialogL( aScreenName,
       
   361                                                           R_CHATCLIENT_CLIST_SN_PROMPT,
       
   362                                                           R_CHATCLIENT_CLIST_SN_QUERY,
       
   363                                                           ETrue // T9
       
   364                                                         );
       
   365 
       
   366     if ( wasCapturing )
       
   367         {
       
   368         // restore capturing
       
   369         iAppUi->CaptureEventsL();
       
   370         }
       
   371 
       
   372     return result;
       
   373     }
       
   374 // pcside_partially ..impact has to be analysed
       
   375 
       
   376 
       
   377 // -----------------------------------------------------------------------------
       
   378 // CCAGroupUtils::CreateNewChatL
       
   379 // (other items were commented in a header).
       
   380 // -----------------------------------------------------------------------------
       
   381 //
       
   382 HBufC* CCAGroupUtils::CreateNewChatL( TInt aResourceId, const TUid aViewId,
       
   383                                       TBool aContactFound, TEnumsPC::TListSelectionType aSelType,
       
   384                                       TInt aSelectedListIndex   )
       
   385     {
       
   386     CHAT_DP_FUNC_ENTER( "CreateNewChatL" );
       
   387 
       
   388     if ( !iAppUi->UISessionManager().IsLoggedIn() )
       
   389         {
       
   390         iAppUi->UISessionManager().LoginL( MCAUiLoginCmdCB::ELogin );
       
   391         if ( !iAppUi->UISessionManager().IsLoggedIn() )
       
   392             {
       
   393             // Still not logged in
       
   394             // Can't continue
       
   395             return NULL;
       
   396             }
       
   397         }
       
   398 
       
   399     if ( IMUtils::IntResourceValueL( RSC_CHAT_VARIATION_SIMPLE_GROUP_CREATION ) )
       
   400         {
       
   401         // simplified new school group creation
       
   402         CHAT_DP_FUNC_DONE( "CreateNewChatL" );
       
   403         return CreateNewChatSimpleL( aResourceId, aViewId , aContactFound, aSelType, /*aOnlineContacts*/ aSelectedListIndex );
       
   404         }
       
   405     else
       
   406         {
       
   407         // normal old school group creation
       
   408         CHAT_DP_FUNC_DONE( "CreateNewChatL" );
       
   409         return CreateNewChatNormalL( aResourceId, aViewId );
       
   410         }
       
   411     }
       
   412 //pcside_partially
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 // CCAGroupUtils::CreateNewChatNormalL
       
   416 // (other items were commented in a header).
       
   417 // -----------------------------------------------------------------------------
       
   418 //
       
   419 HBufC* CCAGroupUtils::CreateNewChatNormalL(
       
   420     TInt aResourceId,
       
   421     const TUid aViewId )
       
   422     {
       
   423     CHAT_DP_FUNC_ENTER( "CreateNewChatNormalL" );
       
   424 
       
   425     TBool areItemsEdited( EFalse );
       
   426 
       
   427     // create lists
       
   428     CDesCArray* userList = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   429     CleanupStack::PushL( userList );
       
   430     CDesCArray* admins = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   431     CleanupStack::PushL( admins );
       
   432     CDesCArray* rejected = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   433     CleanupStack::PushL( rejected );
       
   434 
       
   435     // add own wvid to admins list
       
   436     // Use new function for this
       
   437 
       
   438 
       
   439     iGroupUtilsPC->MoveOwnIdToFirstL( *admins );
       
   440 
       
   441     // note: groupprops must be at the top of the cleanupstack
       
   442     // so that we can get them out before call to creategroupl
       
   443     CImpsCommonGroupProps* groupProps = CImpsCommonGroupProps::NewL();
       
   444     CleanupStack::PushL( groupProps );
       
   445     CImpsPrivateGroupProps* privateProps = CImpsPrivateGroupProps::NewL();
       
   446     CleanupStack::PushL( privateProps );
       
   447 
       
   448     CImpsCommonGroupProps* newGroupProps = CImpsCommonGroupProps::NewL();
       
   449     CleanupStack::PushL( newGroupProps );
       
   450     CImpsPrivateGroupProps* newPrivateProps = CImpsPrivateGroupProps::NewL();
       
   451     CleanupStack::PushL( newPrivateProps );
       
   452 
       
   453     // construct and launch the groupproperties dialog
       
   454     CCAGroupPropertiesDialog* groupPropDialog =
       
   455         new( ELeave )CCAGroupPropertiesDialog(
       
   456         *iViewSwitcher.CAStatusPane(),
       
   457         /**groupProps, *privateProps, *newGroupProps, *newPrivateProps,*/
       
   458 
       
   459         EFalse,
       
   460         *userList, *admins, *rejected,
       
   461         KNullDesC,
       
   462         areItemsEdited );
       
   463 
       
   464     CleanupStack::PushL( groupPropDialog );
       
   465     groupPropDialog->ConstructL( R_CHATCLIENT_MENUBAR_CHAT_PROPERTIES_VIEW );
       
   466     CleanupStack::Pop( groupPropDialog );
       
   467     TInt result( groupPropDialog->ExecuteLD(
       
   468                      R_CHATCLIENT_GROUPPROPERTIES_DLG ) );
       
   469     CHAT_DP( D_CHAT_LIT(
       
   470                  "CCAGroupUtils::CreateNewChatNormalL areItemsEdited: %d" ),
       
   471              areItemsEdited );
       
   472 
       
   473     HBufC* groupId = NULL;
       
   474 
       
   475     if ( result == EAknSoftkeyDone || result == EAknSoftkeyYes )
       
   476         {
       
   477         CCAUINGUtils::SetTitleL( aResourceId, aViewId );
       
   478 
       
   479         // ask screenname query before creation, or re-use alias
       
   480         TBool joinGroup( EFalse );
       
   481 
       
   482         // fetch the default or recently used screen name pointer
       
   483         iScreenNamePtr.Set( iAppUi->ScreenNamePtr()->Des() );
       
   484         TInt ret = ScreenNameQueryL( iScreenNamePtr );
       
   485 
       
   486         if ( ret == EAknSoftkeyDone || ret == EAknSoftkeyOk )
       
   487             {
       
   488             CDesCArray* noteTexts = new( ELeave ) CDesCArrayFlat(
       
   489                 KArrayGranularity );
       
   490             CleanupStack::PushL( noteTexts );
       
   491             noteTexts->AppendL( newGroupProps->GroupName() );
       
   492             noteTexts->AppendL( iScreenNamePtr );
       
   493             HBufC* waitMsg = StringLoader::LoadLC(
       
   494                                  RSC_CHAT_JOIN_WAIT, *noteTexts );
       
   495             iAppUi->ShowWaitDialogL( *waitMsg, ETrue );
       
   496             CleanupStack::PopAndDestroy( 2, noteTexts ); // waitMsg, noteTexts
       
   497             joinGroup = ETrue;
       
   498             }
       
   499         else
       
   500             {
       
   501             iAppUi->ShowWaitDialogL( R_QTN_GEN_CHAT_NOTE_PROCESSING, ETrue );
       
   502             }
       
   503 
       
   504         // check the autodeletion variation flag
       
   505         if ( IMUtils::IntResourceValueL( RSC_CHAT_VARIATION_GROUP_AUTODELETE ) )
       
   506             {
       
   507             newGroupProps->SetAutoDelete( EImpsPropYes );
       
   508             }
       
   509 
       
   510         // CreateGroupL takes the ownership of the properties
       
   511         CleanupStack::Pop( 2, newGroupProps ); // newPrivateProps, newGroupProps
       
   512         CleanupStack::PopAndDestroy( 2, groupProps ); // privateProps, groupProps
       
   513 
       
   514         TInt error( 0 );
       
   515         TBool whisperingAllowed =
       
   516             IMUtils::IntResourceValueL(
       
   517                 RSC_CHAT_VARIATION_GROUP_WHISPER ) == 1;
       
   518         TRAPD( err, groupId = iGroupUtilsPC->CreateGroupSimpleL( iScreenNamePtr,
       
   519                                                                  joinGroup,
       
   520                                                                  whisperingAllowed,
       
   521                                                                  error ) );
       
   522 
       
   523         // if CreateGroupL returns NULL, it couldn't create the group
       
   524         if ( groupId )
       
   525             {
       
   526             // Delete old one. No need to store it.
       
   527             // Cannot put groupId to CleanupStack because if PushL leaves then
       
   528             // wait note would be shown forever
       
   529             delete iGroupId;
       
   530             iGroupId = groupId;
       
   531             }
       
   532 
       
   533         CHAT_DP( D_CHAT_LIT(
       
   534                      "CCAGroupUtils::CreateNewChatNormalL()  iGroupInterface->CreateGroupL() error = %d, err = %d" ),
       
   535                  error, err );
       
   536 
       
   537         if ( err == KErrNone && error == KErrNone && groupId )
       
   538             {
       
   539             TRAPD( leave, iGroupUtilsPC->AddGroupMembersL( *groupId, *admins, *userList, *rejected ) );
       
   540             iAppUi->DismissWaitDialogL( leave );
       
   541 
       
   542             if ( joinGroup )
       
   543                 {
       
   544                 // switch to joined group (ETrue = ask invite query)
       
   545                 SwitchToJoinedGroupL( EFalse, *groupId, NULL, ETrue );
       
   546                 }
       
   547             }
       
   548         // Engine couldn't find a unique group id
       
   549         else if ( err == KErrNone && error == KErrNone && ! groupId )
       
   550             {
       
   551             // Imps_ERROR_BASE - 10000 is an unknown error
       
   552             // ("server error") to note mapper
       
   553             iAppUi->DismissWaitDialogL( Imps_ERROR_BASE - 10000 );
       
   554             }
       
   555         else
       
   556             {
       
   557             iAppUi->DismissWaitDialogL( err );
       
   558             if ( error == ECSPAccepted )
       
   559                 {
       
   560                 CCAUINGUtils::HandlePartialSuccessL();
       
   561                 }
       
   562             else
       
   563                 {
       
   564                 IMNoteMapper::ShowNoteL( error );
       
   565                 if ( error == ECSPMaxNumberOfGroupsForUser ||
       
   566                      error == ECSPMaxNumberOfGroupsForServer )
       
   567                     {
       
   568                     DisplayCreatedChatRoomsListL();
       
   569                     }
       
   570                 }
       
   571             }
       
   572         }
       
   573     else
       
   574         {
       
   575         // user cancelled the creation
       
   576         CleanupStack::PopAndDestroy( 4, groupProps ); //newPrivateProps,
       
   577         // newGroupProps, privateProps, groupProps
       
   578         CCAUINGUtils::SetTitleL( aResourceId, aViewId );
       
   579         if ( result == EAknSoftkeyExit )
       
   580             {
       
   581             CEikonEnv::Static()->EikAppUi()->HandleCommandL(
       
   582                 EChatClientCmdExit );
       
   583             }
       
   584         }
       
   585     CleanupStack::PopAndDestroy( 3, userList ); // rejected, admins, userList
       
   586 
       
   587     if ( groupId )
       
   588         {
       
   589         // groupId points to iGroupId and the ownership is
       
   590         // passed to calling function so we can't delete the iGroupId
       
   591         iGroupId = NULL;
       
   592         }
       
   593     // no leaving code allowed between (iGroupId = NULL;) and (return groupId;)
       
   594     CHAT_DP_FUNC_DONE( "CreateNewChatNormalL" );
       
   595 
       
   596     return groupId;
       
   597     }
       
   598 
       
   599 // -----------------------------------------------------------------------------
       
   600 // CCAGroupUtils::CreateNewChatSimpleL
       
   601 // (other items were commented in a header).
       
   602 // -----------------------------------------------------------------------------
       
   603 //
       
   604 HBufC* CCAGroupUtils::CreateNewChatSimpleL( TInt /* aResourceId */,
       
   605                                             const TUid /* aViewId */, TBool aContactFound,
       
   606                                             TEnumsPC::TListSelectionType aSelType,
       
   607                                             TInt aSelectedListIndex )
       
   608     {
       
   609     CHAT_DP_FUNC_ENTER( "CreateNewChatSimpleL" );
       
   610 
       
   611     CDesCArray* inviteList = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   612     CleanupStack::PushL( inviteList );
       
   613 
       
   614     HBufC* groupId = NULL;
       
   615     HBufC* groupName = HBufC::NewLC( KMaxChatGroupLenght );
       
   616     HBufC* inviteMsg = HBufC::NewLC( KInviteMessageMaxLength );
       
   617     TPtr chatGroupName( groupName->Des() );
       
   618     TPtr chatInvite( inviteMsg->Des() );
       
   619     TPtr screenName( iAppUi->ScreenNamePtr()->Des() );
       
   620     TBool inviteSupported( iAppUi->UISessionManager().IsSupported( CCAUISessionManager::EInvite ) );
       
   621 
       
   622 
       
   623 
       
   624     TInt result = EAknSoftkeyOk;
       
   625     TInt inviteError = KErrNone;
       
   626 
       
   627     // number of online friends
       
   628     //TInt onlineCount = 0;
       
   629 
       
   630     iCurrState = ESGCInviteContacts;
       
   631     iPrevState = ESGCNone;
       
   632 
       
   633     TBool exitFSM = EFalse;
       
   634 
       
   635     //   MAKE SURE EACH STATE HAS CLEANUPSTACK BALANCED UPON EXIT
       
   636     //   This means: DO NOT CleanupStack::Push in one state, and
       
   637     //   Pop/PopAndDestroy in the other. This also means to do Pop/PopAndDestroy
       
   638     //   before a state transition inside a state.
       
   639 
       
   640     // handle simplified group creation within a finite state machine
       
   641     // construction
       
   642 
       
   643 
       
   644 
       
   645     while ( ! exitFSM )
       
   646         {
       
   647         switch ( iCurrState )
       
   648             {
       
   649                 // BEGIN state: choosing the contacts to be invited
       
   650             case ESGCInviteContacts :
       
   651                 {
       
   652                 // we only ask for invite if invite function is supported
       
   653                 result = EAknSoftkeyOk;
       
   654 
       
   655 
       
   656                 if ( aContactFound  )
       
   657                     {
       
   658 
       
   659 
       
   660                     // We have online friends, so show the multiselection view
       
   661                     CCAAppUi* appUi = static_cast<CCAAppUi*>(
       
   662                                           CCoeEnv::Static()->AppUi() );
       
   663 
       
   664 
       
   665                     MCASkinVariant* skinVar = static_cast<CCAApp*>(
       
   666                                                   appUi->Application() )->VariantFactory()->SkinVariantL();
       
   667                     CDesCArrayFlat* selectedContacts =
       
   668                         new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   669                     CleanupStack::PushL( selectedContacts );
       
   670 
       
   671                     // Show selection dialog
       
   672 
       
   673                     TBool isSelected( EFalse );
       
   674                     // show selection dialog
       
   675 
       
   676                     isSelected = CCAContactSelectionDialog::ShowDialogL(
       
   677                                      *selectedContacts,
       
   678                                      *appUi->GetProcessManager().GetArrayInterface(),
       
   679                                      *skinVar,
       
   680                                      *appUi->GetProcessManager().GetSettingsInterface(),
       
   681                                      appUi->MbmFullPath(),
       
   682                                      aSelType,
       
   683                                      R_CONTACT_SELECTION_DIALOG,
       
   684                                      *iViewSwitcher.CAStatusPane(),
       
   685                                      NULL,
       
   686                                      TEnumsPC::EFilterNotDefined,
       
   687                                      TEnumsPC::EFilterNotDefined,
       
   688                                      EFalse,
       
   689                                      aSelectedListIndex
       
   690                                      , &exitFSM );
       
   691                     if ( exitFSM )
       
   692                         {
       
   693                         CleanupStack::PopAndDestroy();
       
   694                         break;
       
   695                         }
       
   696 
       
   697                     if ( isSelected )
       
   698                         {
       
   699                         // code merge 14 Nov, 2006
       
   700                         // Get rid of contacts with duplicate ids
       
   701                         CCAPCUtils::RemoveDuplicateWVIds( *selectedContacts );
       
   702                         // Populate "real" invite list
       
   703                         TInt inviteCount( selectedContacts->MdcaCount() );
       
   704 
       
   705                         for ( TInt i = 0; i < inviteCount; ++i )
       
   706                             {
       
   707 
       
   708                             TPtrC wvid( selectedContacts->MdcaPoint( i ) );
       
   709 
       
   710                             inviteList->AppendL( wvid );
       
   711                             }
       
   712 
       
   713                         // Continue creation if user selected invitees
       
   714                         if ( inviteList->Count() > 0 )
       
   715                             {
       
   716                             result = EAknSoftkeyOk;
       
   717                             }
       
   718                         else
       
   719                             {
       
   720                             result = EAknSoftkeyCancel;
       
   721                             }
       
   722 
       
   723 
       
   724                         }
       
   725                     else
       
   726                         {
       
   727                         result = EAknSoftkeyCancel;
       
   728                         }
       
   729 
       
   730                     CleanupStack::PopAndDestroy(); // selectedContacts.Close()
       
   731                     }
       
   732 
       
   733 
       
   734                 StateChange( result, KErrNone, ESGCGroupName );
       
   735                 break;
       
   736                 }
       
   737 
       
   738             // ask the group name
       
   739             case ESGCGroupName :
       
   740                 {
       
   741                 if ( aSelType == TEnumsPC::ESingleListMultiSelect )
       
   742                     {
       
   743                     MCAMainViewArrayPC* mainViewArrayPC =
       
   744                         iAppUi->GetProcessManager().GetArrayInterface();
       
   745                     chatGroupName = mainViewArrayPC->DisplayName( aSelectedListIndex );
       
   746                     }
       
   747                 iGroupUtilsPC->GetDefaultGroupNameL( chatGroupName, aSelType );
       
   748                 // since the user didn't cancel, ask the group name
       
   749                 result = IMDialogUtils::DisplayTextQueryDialogL( chatGroupName,
       
   750                                                                  R_CHATCLIENT_CHATLIST_CREATE_GROUP_NAME,
       
   751                                                                  R_CHATCLIENT_CHATLIST_CREATE_GROUP_NAME_QUERY,
       
   752                                                                  ETrue // T9
       
   753                                                                );
       
   754 
       
   755                 StateChange( result, KErrNone, ESGCInviteMessage );
       
   756                 break;
       
   757                 }
       
   758 
       
   759             // ask the invitation message
       
   760             case ESGCInviteMessage :
       
   761                 {
       
   762                 if ( inviteList->Count() > 0 )
       
   763                     {
       
   764                     // the user didn't cancel, so ask the invitation message
       
   765                     result = IMDialogUtils::DisplayTextQueryDialogL(
       
   766                                  chatInvite,
       
   767                                  R_CHAT_INVITE_MSG_DQ,
       
   768                                  R_CHAT_INVITE_MESSAGE_QUERY,
       
   769                                  ETrue // T9
       
   770                              );
       
   771 
       
   772                     StateChange( result, KErrNone, ESGCScreenName );
       
   773                     }
       
   774                 else
       
   775                     {
       
   776                     // nobody in invite list, force state change
       
   777                     StateChange( EAknSoftkeyOk, KErrNone, ESGCScreenName );
       
   778                     }
       
   779                 break;
       
   780                 }
       
   781 
       
   782             // ask the screen name (or use alias)
       
   783             case ESGCScreenName :
       
   784                 {
       
   785                 result = ScreenNameQueryL( screenName );
       
   786                 StateChange( result, KErrNone, ESGCCreateGroup );
       
   787                 break;
       
   788                 }
       
   789 
       
   790             // do the actual creation, sending of invitations,
       
   791             // and joining to the group
       
   792             case ESGCCreateGroup :
       
   793                 {
       
   794                 // finalize chat group creation and join it, then send all the
       
   795                 // invitations
       
   796                 // put up the wait note
       
   797                 // wait note is dismissed by the last state
       
   798                 HBufC* waitMsg = StringLoader::LoadLC(
       
   799                                      R_CHAT_CREATING_CHAT_GROUP );
       
   800                 iAppUi->ShowWaitDialogL( *waitMsg, ETrue );
       
   801                 CleanupStack::PopAndDestroy(); // waitMsg
       
   802 
       
   803                 TInt err;
       
   804                 TInt error = 0;
       
   805                 TRAP( err, groupId = iGroupUtilsPC->CreateGroupL( screenName, chatGroupName, error ) );
       
   806 
       
   807 
       
   808                 // CreateGroupL leaves with KErrDiskFull under low flash
       
   809                 // memory conditions (below critical level, 128 kB)
       
   810                 // stop group creation here in that case
       
   811                 if ( err == KErrDiskFull )
       
   812                     {
       
   813                     // Use StateChange to advance to error state
       
   814                     StateChange( EAknSoftkeyOk, err, ESGCNone );
       
   815                     break;
       
   816                     }
       
   817 
       
   818                 // if CreateGroupL returns NULL, it couldn't create the group
       
   819                 if ( groupId )
       
   820                     {
       
   821                     // Delete old one. No need to store it.
       
   822                     // Cannot put groupId to CleanupStack because if PushL leaves then
       
   823                     // wait note would be shown forever
       
   824                     delete iGroupId;
       
   825                     iGroupId = groupId;
       
   826                     }
       
   827 
       
   828                 // note, the ESGCDoJoin state and ESGCError states dismiss the
       
   829                 // wait note.  ESGCDoSendInvite makes a new wait note, and it
       
   830                 // gets dismissed upon successful state change to ESGCDoJoin
       
   831 
       
   832                 // error contains the actual nw error now
       
   833                 StateChange( EAknSoftkeyOk, error, ESGCDoSendInvite );
       
   834                 break;
       
   835                 }
       
   836 
       
   837             // send the invitation(s),
       
   838             case ESGCDoSendInvite :
       
   839                 {
       
   840                 TInt retval = KErrNone;
       
   841 
       
   842                 if ( inviteList->MdcaCount() > 0 )
       
   843                     {
       
   844                     // we have invitations, so send them
       
   845 
       
   846                     // Show wait-note. Error state dismisses it.
       
   847                     iAppUi->ShowWaitDialogL( inviteList->MdcaCount() > 1 ?
       
   848                                              R_QTN_CHAT_INVITE_SENDING_MANY : R_QTN_CHAT_INVITE_SENDING,
       
   849                                              ETrue );
       
   850 
       
   851                     // Send invitation
       
   852                     TRAP( retval, iGroupUtilsPC->SendInvitationsL( *inviteList, *groupId, *inviteMsg ); );
       
   853                     }
       
   854 
       
   855                 // Ignore these errors at least for now and continue group creation.
       
   856                 // UI CR coming for 3.1
       
   857                 if ( retval == ECSPPartiallySuccessful || retval == ECSPCannotDeliver
       
   858                      || retval == ECSPRecipientBlockedSender )
       
   859                     {
       
   860                     inviteError = retval;
       
   861                     retval = KErrNone;
       
   862                     }
       
   863 
       
   864                 StateChange( EAknSoftkeyOk, retval, ESGCDoJoin );
       
   865                 break;
       
   866                 }
       
   867 
       
   868             // and joining to the group
       
   869             case ESGCDoJoin:
       
   870                 {
       
   871                 // join to group (groupId contains ID), then
       
   872                 // switch to joined group
       
   873                 TInt leave;
       
   874                 TInt err = KErrNone;
       
   875                 TRAP( leave, err = iGroupUtilsPC->JoinGroupL( *groupId, screenName, ETrue, ETrue ) );
       
   876 
       
   877                 // Get rid of wait-note. It's either
       
   878                 // "Creating chat group" or "Sending invitation"
       
   879                 // at this point
       
   880                 iAppUi->DismissWaitDialogL( err );
       
   881 
       
   882                 // If there was an error in sending invitation show error note
       
   883                 // at this point right before view switching
       
   884                 if ( inviteError != KErrNone &&  inviteError != ECSPRecipientBlockedSender )
       
   885                     {
       
   886                     IMNoteMapper::ShowNoteL( inviteError );
       
   887                     }
       
   888                 if ( inviteError == ECSPRecipientBlockedSender )
       
   889                     {
       
   890                     TInt inviteeCount = inviteList->MdcaCount();
       
   891                     for ( TInt cnt = 0; cnt < inviteeCount; cnt++ )
       
   892                         {
       
   893                         IMNoteMapper::ShowNoteL( inviteError,
       
   894                                                  CCAPCUtils::DisplayId( inviteList->MdcaPoint( cnt )  ) );
       
   895                         }
       
   896                     }
       
   897                 // screen name cannot be in use since we just created the group...
       
   898                 switch ( err )
       
   899                     {
       
   900                     case ECSPSuccessful:    // flowthrough
       
   901                     case KErrNone:
       
   902                         {
       
   903                         // ok, switch to joined group
       
   904                         SwitchToJoinedGroupL( EFalse, *groupId );
       
   905                         break;
       
   906                         }
       
   907 
       
   908                     default:
       
   909                         {
       
   910                         // will force state change to error state
       
   911                         StateChange( EAknSoftkeyOk, err, ESGCDoJoin );
       
   912                         break;
       
   913                         }
       
   914                     }
       
   915 
       
   916                 // final state, all done.
       
   917                 exitFSM = ETrue;
       
   918                 break;
       
   919                 }
       
   920 
       
   921             // got some network or other error during the process
       
   922             // not all states will end up here. only ESGCCreateGroup and
       
   923             // ESGCInviteAndJoin.
       
   924             case ESGCError :
       
   925                 {
       
   926                 // safe to call even without a wait dialog active
       
   927                 iAppUi->DismissWaitDialogL( iNwError );
       
   928 
       
   929                 // must be the last
       
   930                 exitFSM = ETrue;
       
   931 
       
   932                 if ( iNwError == ECSPMaxNumberOfGroupsForUser ||
       
   933                      iNwError == ECSPMaxNumberOfGroupsForServer )
       
   934                     {
       
   935                     if ( DisplayCreatedChatRoomsListL() == EAknSoftkeyOk )
       
   936                         {
       
   937                         exitFSM = EFalse; // Continue creation.
       
   938                         StateChange( EAknSoftkeyOk, KErrNone, ESGCCreateGroup );
       
   939                         }
       
   940                     }
       
   941                 break;
       
   942                 }
       
   943 
       
   944             // cancel group creation query
       
   945             case ESGCQueryCancel :
       
   946                 {
       
   947                 result = IMDialogUtils::DisplayQueryDialogL(
       
   948                              R_CHAT_GENERIC_CANCEL_CONFIRMATION_QUERY,
       
   949                              R_QTN_CHAT_CANCEL_GROUP_CREATION );
       
   950 
       
   951                 if ( ( result == EAknSoftkeyOk ) ||
       
   952                         ( result == EAknSoftkeyYes ) )
       
   953                     {
       
   954                     // user really wants to cancel, so
       
   955                     // let's get out of here
       
   956                     exitFSM = ETrue;
       
   957                     }
       
   958                 else if( !result )
       
   959                 	{
       
   960                 	if( !iAppUi->GetIsFSWExitFlag() )
       
   961                 		{
       
   962                 	    StateChange( EAknSoftkeyOk, KErrNone, iPrevState );
       
   963                 		}
       
   964                 	else
       
   965                 		{
       
   966                 		exitFSM = ETrue;
       
   967                 		}
       
   968                 	}
       
   969                 else
       
   970                     {
       
   971                     // user cancelled the cancel query, so go back to the state
       
   972                     // we were in
       
   973                     iCurrState = iPrevState;
       
   974                     }
       
   975                 break;
       
   976                 }
       
   977 
       
   978             default :
       
   979                 {
       
   980                 // WRONG state, leave
       
   981                 User::Leave( KErrArgument );
       
   982                 break;
       
   983                 }
       
   984             }
       
   985         }
       
   986 
       
   987     iCurrState = ESGCNone;
       
   988     iPrevState = ESGCNone;
       
   989 
       
   990     // if the user cancels in any step, we end up here
       
   991     // and do cleanup. also, if we're successful
       
   992     CleanupStack::PopAndDestroy( inviteMsg );
       
   993     CleanupStack::PopAndDestroy( groupName );
       
   994     CleanupStack::PopAndDestroy( inviteList );
       
   995 
       
   996     CHAT_DP_FUNC_DONE( "CreateNewChatSimpleL" );
       
   997     return NULL;
       
   998     }
       
   999 // pcside_completely
       
  1000 
       
  1001 // pcside_completely
       
  1002 // -----------------------------------------------------------------------------
       
  1003 // CCAGroupUtils::ScreenNameQueryL
       
  1004 // (other items were commented in a header).
       
  1005 // -----------------------------------------------------------------------------
       
  1006 //
       
  1007 TInt CCAGroupUtils::ScreenNameQueryL( TDes& aScreenName )
       
  1008     {
       
  1009     TInt askScreenName = IMUtils::IntResourceValueL(
       
  1010                              RSC_CHAT_VARIATION_SCREENNAME_QUERY );
       
  1011 
       
  1012     TInt result = 0;
       
  1013 
       
  1014 
       
  1015     iGroupUtilsPC->ScreenNameQueryL( aScreenName );
       
  1016 
       
  1017     if ( ! askScreenName )
       
  1018         {
       
  1019         // assume as accepted as the query dialog is not to be shown
       
  1020         result = EAknSoftkeyOk;
       
  1021         }
       
  1022     else
       
  1023         {
       
  1024         result = AskScreenNameL( aScreenName );
       
  1025         }
       
  1026 
       
  1027     return result;
       
  1028     }
       
  1029 
       
  1030 // -----------------------------------------------------------------------------
       
  1031 // CCAGroupUtils::PrepareToSwitchBackL
       
  1032 // (other items were commented in a header).
       
  1033 // -----------------------------------------------------------------------------
       
  1034 //
       
  1035 void CCAGroupUtils::PrepareToSwitchBackL( const TDesC& aGroupID,
       
  1036                                           TUid aPrevView,
       
  1037                                           TUid aNextView )
       
  1038     {
       
  1039     TUid messageID;
       
  1040 
       
  1041     HBufC8* myMessage = NULL;
       
  1042 
       
  1043     TCADnlChatViewBuf chatMsgBuf;
       
  1044     TCADnlConvViewBuf convMsgBuf;
       
  1045 
       
  1046 
       
  1047     TCADnlChatView dnlChatView;
       
  1048     if ( aPrevView == KUidChatView )
       
  1049         {
       
  1050         TBool foundGroup = iGroupUtilsPC->FindGroup( aGroupID );
       
  1051 
       
  1052         dnlChatView.iGroupId =
       
  1053             aGroupID.Left( dnlChatView.iGroupId.MaxLength() );
       
  1054         dnlChatView.iIsForwarded = EFalse;
       
  1055         dnlChatView.iInviteQuery = EFalse;
       
  1056         if ( foundGroup )
       
  1057             {
       
  1058             dnlChatView.iGroupName = iGroupUtilsPC->GetEngineDefaultGroupName( aGroupID );
       
  1059             }
       
  1060 
       
  1061         chatMsgBuf = dnlChatView;
       
  1062         messageID = KUidChatViewMsgId;
       
  1063         myMessage = chatMsgBuf.AllocLC();
       
  1064         }
       
  1065     else // aPrevView == KUidConversationsView
       
  1066         {
       
  1067         TCADnlConvView dnlConView;
       
  1068         dnlConView.iWVID = aGroupID;
       
  1069         dnlConView.iIsForwarded = EFalse;
       
  1070         dnlConView.iSAPChanged = EFalse;
       
  1071         dnlConView.iSwitchTab = EFalse;
       
  1072 
       
  1073         convMsgBuf = dnlConView;
       
  1074         messageID = KUidConvViewMsgId;
       
  1075         myMessage = convMsgBuf.AllocLC();
       
  1076         }
       
  1077 
       
  1078 
       
  1079     CleanupStack::Pop( myMessage );
       
  1080 
       
  1081     //myMessage ownership is taken by RegisterSwitchBack
       
  1082     iAppUi->RegisterSwitchBack( aPrevView, messageID, myMessage, aNextView );
       
  1083     }
       
  1084 
       
  1085 // -----------------------------------------------------------------------------
       
  1086 // CCAGroupUtils::StateChange
       
  1087 // (other items were commented in a header).
       
  1088 // -----------------------------------------------------------------------------
       
  1089 //
       
  1090 void CCAGroupUtils::StateChange( TInt aAknResult, TInt aErrorCode,
       
  1091                                  TSGCState aNewState )
       
  1092     {
       
  1093     iPrevState = iCurrState;
       
  1094 
       
  1095     if ( aErrorCode != KErrNone )
       
  1096         {
       
  1097         // got an error, go to error state and handle it
       
  1098         iCurrState = ESGCError;
       
  1099         iNwError = aErrorCode;
       
  1100         return;
       
  1101         }
       
  1102 
       
  1103     // new state for FSM, changes FSM state
       
  1104     if ( ( aAknResult != EAknSoftkeyOk ) && ( aAknResult != EAknSoftkeyYes )
       
  1105          && ( aAknResult != EAknSoftkeyDone ) )
       
  1106         {
       
  1107         // user cancelled the query in a step, verify
       
  1108         // with a query
       
  1109         iCurrState = ESGCQueryCancel;
       
  1110         }
       
  1111     else
       
  1112         {
       
  1113         // user didn't cancel, so move to a new state
       
  1114         iCurrState = aNewState;
       
  1115         }
       
  1116     }
       
  1117 
       
  1118 // Callback for asynchronous joining to the group
       
  1119 // after the login has been completed
       
  1120 TInt JoinGroupCallBack( TAny* aPtr )
       
  1121     {
       
  1122     return static_cast< CCAGroupUtils* >( aPtr )->DoAsyncJoin();
       
  1123     }
       
  1124 
       
  1125 // -----------------------------------------------------------------------------
       
  1126 // CCAGroupUtils::DoAsyncJoin
       
  1127 // (other items were commented in a header).
       
  1128 // -----------------------------------------------------------------------------
       
  1129 //
       
  1130 TInt CCAGroupUtils::DoAsyncJoin()
       
  1131     {
       
  1132     CHAT_DP_FUNC_ENTER( "JoinGroupCallBack" );
       
  1133 
       
  1134     TRAP( iAsyncLeave, iErr = JoinGroupL(
       
  1135                                   EFalse,
       
  1136                                   *iAsyncGroupId,
       
  1137                                   *iAsyncScreenName,
       
  1138                                   iAsyncFwdMessage ) );
       
  1139 
       
  1140     CHAT_DP_FUNC_DONE( "JoinGroupCallBack" );
       
  1141 
       
  1142     // don't call again
       
  1143     return EFalse;
       
  1144     }
       
  1145 
       
  1146 // utilsside_complete
       
  1147 // -----------------------------------------------------------------------------
       
  1148 // CCAGroupUtils::JoinGroupL
       
  1149 // (other items were commented in a header).
       
  1150 // -----------------------------------------------------------------------------
       
  1151 //
       
  1152 TInt CCAGroupUtils::JoinGroupL( const TBool aFromFwd,
       
  1153                                 const TDesC& aGroupId,
       
  1154                                 const TDesC& aScreenName /*= KNullDesC*/,
       
  1155                                 const MCAConversationMessage* aFwdMessage /*= NULL*/,
       
  1156                                 TJoinMode aJoinMode /*= EStoredId*/ )
       
  1157     {
       
  1158     CHAT_DP_FUNC_ENTER( "JoinGroupL" );
       
  1159     if( iJoinGroupId )
       
  1160         {
       
  1161         delete iJoinGroupId;   
       
  1162         iJoinGroupId = NULL;
       
  1163         }
       
  1164     iJoinGroupId = aGroupId.Alloc();
       
  1165     // Create copy of the forwarded message.
       
  1166     // This method does not copy again the message if it's the one we have
       
  1167     // already copied. aFwdMessage should not be used after this copy
       
  1168     // operation, since it's not assured to stay in memory until we need it.
       
  1169     // Use 'message' instead.
       
  1170     iAppUi->SetForwardMessageL( aFwdMessage );
       
  1171     const MCAConversationMessage* message = iAppUi->ForwardMessage();
       
  1172 
       
  1173     if ( !iAppUi->UISessionManager().IsLoggedIn() )
       
  1174         {
       
  1175         // not logged in, try to log in
       
  1176         iAppUi->UISessionManager().LoginL( MCAUiLoginCmdCB::ELogin );
       
  1177 
       
  1178         TInt err( KErrNone );
       
  1179 
       
  1180         if ( iAppUi->UISessionManager().IsLoggedIn() )
       
  1181             {
       
  1182             // start the joining when we have time, i.e.
       
  1183             // when the ongoing login "background tasks" have been
       
  1184             // finished
       
  1185 
       
  1186             // prevent keypresses from being handled, otherwise we might crash
       
  1187             // because of view change in between everything or something like
       
  1188             // that
       
  1189             CHAT_DP_TXT(
       
  1190                 "CCAGroupUtils::JoinGroupL - Start capturing key events" );
       
  1191             iAppUi->CaptureEventsL();
       
  1192 
       
  1193             iAsyncGroupId = aGroupId.AllocL();
       
  1194             iAsyncScreenName = aScreenName.AllocL();
       
  1195             iAsyncFwdMessage = message;
       
  1196 
       
  1197             CAsyncCallBack* temp = new ( ELeave ) CAsyncCallBack(
       
  1198                 TCallBack( JoinGroupCallBack, this ),
       
  1199                 CActive::EPriorityIdle );
       
  1200 
       
  1201             delete iAsyncCb;
       
  1202             iAsyncCb = temp;
       
  1203 
       
  1204             // let it rock
       
  1205             iAsyncCb->CallBack();
       
  1206 
       
  1207             // wait for the request to stop
       
  1208             if ( !iWait.IsStarted() )
       
  1209                 {
       
  1210                 iWait.Start();  // CSI: 10 # iWait is not an active object
       
  1211                 }
       
  1212 
       
  1213             err = iErr;
       
  1214 
       
  1215             CHAT_DP_TXT(
       
  1216                 "CCAGroupUtils::JoinGroupL - JoinGroupCallBack finished" );
       
  1217 
       
  1218             // leave with stuff the JoinGroupL left with,
       
  1219             // but return the stuff it returned...
       
  1220             User::LeaveIfError( iAsyncLeave );
       
  1221 
       
  1222             iAppUi->ReleaseCapturingL();
       
  1223             CHAT_DP_TXT( "CCAGroupUtils::JoinGroupL - Released capturing" );
       
  1224             }
       
  1225 
       
  1226         return err;
       
  1227         }
       
  1228 
       
  1229     if ( !iAppUi->UISessionManager().IsSupported( CCAUISessionManager::EGroup ) )
       
  1230         {
       
  1231         // groups not supported, show note
       
  1232         IMDialogUtils::DisplayNoteDialogL( R_CHAT_ERROR_NOT_SUP_FUNCTIONS );
       
  1233         return KErrNotSupported;
       
  1234         }
       
  1235 
       
  1236     CHAT_DP_TXT( "CCAGroupUtils::JoinGroupL - Beginning to join to the group" );
       
  1237 
       
  1238     TBool isGroupJoined( EFalse );
       
  1239     TBool isFavourite( EFalse );
       
  1240 
       
  1241     iGroupUtilsPC->CreateOrJoinGroupL( aGroupId, isGroupJoined, isFavourite );
       
  1242 
       
  1243 
       
  1244 
       
  1245     // we know whether group exists or not by this time..
       
  1246 
       
  1247 
       
  1248     TInt err( KErrNone );
       
  1249     if ( isGroupJoined )
       
  1250         {
       
  1251         // if it's already joined, not much to do
       
  1252         SwitchToJoinedGroupL( aFromFwd, aGroupId, message );
       
  1253         }
       
  1254     else
       
  1255         {
       
  1256         TInt result( 0 );
       
  1257         HBufC* screenName = NULL;
       
  1258 
       
  1259         // Select correct screen name:
       
  1260 
       
  1261         if ( aScreenName.Length() > 0 )
       
  1262             {
       
  1263             // if the screen name query has already been done
       
  1264             screenName = aScreenName.AllocLC();
       
  1265             result = EAknSoftkeyOk;
       
  1266             }
       
  1267         else
       
  1268             {
       
  1269             // fetch the last used or default screen name
       
  1270             TPtr screenNamePtr( iAppUi->ScreenNamePtr()->Des() );
       
  1271 
       
  1272             // confirm the screen name
       
  1273             result = ScreenNameQueryL( screenNamePtr );
       
  1274             screenName = screenNamePtr.AllocLC();
       
  1275             }
       
  1276 
       
  1277 
       
  1278         if ( ( result == EAknSoftkeyOk ) || ( result == EAknSoftkeyDone )  )
       
  1279             {
       
  1280             // screen name ok
       
  1281             CDesCArray* noteTexts =
       
  1282                 new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
  1283             CleanupStack::PushL( noteTexts );
       
  1284 
       
  1285             const TDesC& groupName = iGroupUtilsPC->GetEngineDefaultGroupName( aGroupId );
       
  1286             if ( groupName.Length() == 0 )
       
  1287                 {
       
  1288                 // no group name, use Group ID
       
  1289                 noteTexts->AppendL( CCAPCUtils::DisplayId( aGroupId ) );
       
  1290                 }
       
  1291             else
       
  1292                 {
       
  1293                 noteTexts->AppendL( groupName );
       
  1294                 }
       
  1295             noteTexts->AppendL( *screenName );
       
  1296             HBufC* waitMsg = StringLoader::LoadLC( RSC_CHAT_JOIN_WAIT, *noteTexts );
       
  1297 
       
  1298             iAppUi->ShowWaitDialogL( *waitMsg, ETrue );
       
  1299 
       
  1300             TRAPD( leave, err = iGroupUtilsPC->JoinGroupL( aGroupId,
       
  1301                                                            *screenName, ETrue, isFavourite ) );
       
  1302 
       
  1303             iAppUi->DismissWaitDialogL( leave );
       
  1304             if (err == EOperationCancelled)
       
  1305                 {
       
  1306                 if( iJoinGroupId )
       
  1307                     {
       
  1308                     delete iJoinGroupId;   
       
  1309                     iJoinGroupId = NULL;
       
  1310                     }
       
  1311                 CleanupStack::PopAndDestroy( 2);// waitMsg, noteTexts
       
  1312                 CleanupStack::PopAndDestroy( screenName );                                   
       
  1313                 return err;
       
  1314                 }
       
  1315 
       
  1316             CHAT_DP( D_CHAT_LIT( "CCAGroupUtils - JoinGroupL returned %d" ),
       
  1317                      err );
       
  1318 
       
  1319             switch ( err )
       
  1320                 {
       
  1321                 case ECSPSuccessful:    // flowthrough
       
  1322                 case KErrNone:
       
  1323                     {
       
  1324                     if ( iGroupUtilsPC->GetEngineDefaultGroupName( aGroupId ).Length() == 0 )
       
  1325                         {
       
  1326                         iGroupUtilsPC->SetGroupNameL( aGroupId );
       
  1327                         }
       
  1328 
       
  1329                     //Switch to joined group
       
  1330                     SwitchToJoinedGroupL( aFromFwd, aGroupId, message );
       
  1331                     break;
       
  1332                     }
       
  1333                 case ECSPInvalidParameter:  // flowthrough
       
  1334                 case ECSPGroupDoesNotExist:
       
  1335                     {
       
  1336                     // the user might have manually entered a bogus group id
       
  1337 
       
  1338                     iGroupUtilsPC->DeleteFailedGroupL( aGroupId, EFalse );
       
  1339                     if ( aJoinMode == EManualId )
       
  1340                         {
       
  1341                         // This way error can be recognized in note mapper
       
  1342                         err += Imps_ERROR_BASE;
       
  1343                         }
       
  1344 
       
  1345                     IMNoteMapper::ShowNoteL( err );
       
  1346 
       
  1347                     if ( aJoinMode == EManualId )
       
  1348                         {
       
  1349                         // Map back to original error code
       
  1350                         err -= Imps_ERROR_BASE;
       
  1351                         }
       
  1352                     break;
       
  1353                     }
       
  1354                 case ECSPScreennameInUse:
       
  1355                     {
       
  1356                     IMNoteMapper::ShowNoteL( err );
       
  1357                     // Screen name was already in use, using KNullDesC
       
  1358                     // as screen name so that method understands to ask
       
  1359                     // screen name again
       
  1360                     err = JoinGroupL( aFromFwd, aGroupId, KNullDesC, message );
       
  1361                     break;
       
  1362                     }
       
  1363                 default:
       
  1364                     {
       
  1365 
       
  1366                     iGroupUtilsPC->DeleteFailedGroupL( aGroupId, EFalse );
       
  1367                     IMNoteMapper::ShowNoteL( err );
       
  1368                     break;
       
  1369                     }
       
  1370                 }
       
  1371 
       
  1372             CleanupStack::PopAndDestroy( 2 ); // waitMsg, noteTexts
       
  1373             }
       
  1374         else
       
  1375             {
       
  1376             // screen name not ok
       
  1377             iGroupUtilsPC->DeleteFailedGroupL( aGroupId, EFalse );
       
  1378 
       
  1379             err = EOperationCancelled;
       
  1380             }
       
  1381 
       
  1382         CleanupStack::PopAndDestroy( screenName );
       
  1383         }
       
  1384         if( iJoinGroupId )
       
  1385             {
       
  1386             delete iJoinGroupId;   
       
  1387             iJoinGroupId = NULL;
       
  1388             }
       
  1389     return err;
       
  1390     }
       
  1391 
       
  1392 
       
  1393 // -----------------------------------------------------------------------------
       
  1394 // CCAGroupUtils::SwitchToJoinedGroupL
       
  1395 // (other items were commented in a header).
       
  1396 // -----------------------------------------------------------------------------
       
  1397 //
       
  1398 void CCAGroupUtils::SwitchToJoinedGroupL( const TBool aFromFwd,
       
  1399                                           const TDesC& aGroupID,
       
  1400                                           const MCAConversationMessage* aFwdMessage /*= Null*/,
       
  1401                                           TBool aInviteQuery /*= EFalse*/ )
       
  1402     {
       
  1403     CHAT_DP_FUNC_ENTER( "SwitchToJoinedGroupL" );
       
  1404 
       
  1405 
       
  1406 
       
  1407     TCADnlChatViewBuf viewBuf;
       
  1408 
       
  1409     TInt err = iGroupUtilsPC->SwitchToJoinedGroupL( aGroupID, viewBuf , aFwdMessage, aInviteQuery );
       
  1410 
       
  1411 
       
  1412     if ( err != KErrNone )
       
  1413         {
       
  1414         CCAUINGUtils::DisplayErrorNoteL( err );
       
  1415         return;
       
  1416         }
       
  1417 
       
  1418     if ( aFromFwd )
       
  1419         {
       
  1420         //if the join group is called from conversation view's fwdtogroup option
       
  1421         //then the viewSwitcher neednt save the last view
       
  1422         //and when u give back key it neednt move to the last view of conversation
       
  1423         //hence we use ActivateLocalViewL
       
  1424         iAppUi->ActivateLocalViewL( KUidChatView, KUidChatViewMsgId, viewBuf );
       
  1425         }
       
  1426     else
       
  1427         {
       
  1428         iViewSwitcher.SwitchViewL( KUidChatView, KUidChatViewMsgId, viewBuf );
       
  1429         }
       
  1430     }
       
  1431 
       
  1432 
       
  1433 // -----------------------------------------------------------------------------
       
  1434 // CCAGroupUtils::DisplayCreatedChatRoomsListL
       
  1435 // (other items were commented in a header).
       
  1436 // -----------------------------------------------------------------------------
       
  1437 //
       
  1438 TInt CCAGroupUtils::DisplayCreatedChatRoomsListL()
       
  1439     {
       
  1440 
       
  1441 
       
  1442     CArrayFixFlat<TInt>* indexArray =
       
  1443         new ( ELeave ) CArrayFixFlat<TInt>( KArrayGranularity );
       
  1444     CleanupStack::PushL( indexArray );
       
  1445 
       
  1446     CDesCArray* groupIds = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
  1447     CleanupStack::PushL( groupIds );
       
  1448 
       
  1449     CDesCArray* tempArray = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
  1450     CleanupStack::PushL( tempArray );
       
  1451 
       
  1452 
       
  1453 
       
  1454     TInt err = iGroupUtilsPC->GetCreatedChatRoomListL( *tempArray, *groupIds );
       
  1455 
       
  1456     TInt result( IMDialogUtils::DisplayListQueryDialogL( indexArray, tempArray,
       
  1457                                                          R_CHAT_CREATED_GROUPS_QUERY ) );
       
  1458 
       
  1459     CleanupStack::PopAndDestroy( tempArray );
       
  1460 
       
  1461     if ( result == EAknSoftkeyOk )
       
  1462         {
       
  1463         iAppUi->ShowWaitDialogLC( R_QTN_GEN_CHAT_NOTE_PROCESSING );
       
  1464 
       
  1465         TInt error( KErrNone );
       
  1466         TInt selectionCount( indexArray->Count() );
       
  1467         for ( TInt i( 0 ); ( i < selectionCount ) && ( error == KErrNone ); i++ )
       
  1468             {
       
  1469             TPtrC groupId( groupIds->MdcaPoint( indexArray->At( i ) ) );
       
  1470             iGroupUtilsPC->DeleteChatGroupFromNetworkL( groupId, ETrue );
       
  1471             }
       
  1472 
       
  1473         CleanupStack::Pop( 1 ); // wait dialog
       
  1474         iAppUi->DismissWaitDialogL( error );
       
  1475         }
       
  1476     else
       
  1477         {
       
  1478         HBufC* errorText = StringLoader::LoadLC( R_QTN_CHAT_GROUP_CREATION_CANCELLED );
       
  1479         IMDialogUtils::DisplayErrorNoteL( *errorText );
       
  1480         CleanupStack::PopAndDestroy( errorText );
       
  1481         }
       
  1482     CleanupStack::PopAndDestroy( 2, indexArray ); // groupIds, indexArray
       
  1483     return result;
       
  1484     }
       
  1485 
       
  1486 // pcside_partially
       
  1487 
       
  1488 // -----------------------------------------------------------------------------
       
  1489 // CCAGroupUtils::DisplayChatInfoL
       
  1490 // (other items were commented in a header).
       
  1491 // -----------------------------------------------------------------------------
       
  1492 //
       
  1493 void CCAGroupUtils::DisplayChatInfoL( const TDesC& aGroupId )
       
  1494     {
       
  1495     //Let's activate wait dialog
       
  1496     iAppUi->ShowWaitDialogLC( R_QTN_GEN_CHAT_NOTE_PROCESSING, ETrue );
       
  1497 
       
  1498 
       
  1499 
       
  1500     // create listbox and popuplist
       
  1501     CAknSingleHeadingPopupMenuStyleListBox* listBox = new ( ELeave )
       
  1502     CAknSingleHeadingPopupMenuStyleListBox();
       
  1503     CleanupStack::PushL( listBox );
       
  1504 
       
  1505     CAknPopupList* popUpList = CAknPopupList::NewL( listBox,
       
  1506                                                     R_AVKON_SOFTKEYS_OK_EMPTY, AknPopupLayouts::EMenuWindow );
       
  1507     CleanupStack::PushL( popUpList );
       
  1508 
       
  1509     //Constructing popuplist
       
  1510     listBox->ConstructL( popUpList,
       
  1511                          CEikListBox::ELeftDownInViewRect | CEikListBox::EDisableHighlight );
       
  1512     listBox->CreateScrollBarFrameL( ETrue );
       
  1513     listBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
  1514         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
  1515 
       
  1516     TInt err = KErrNone;
       
  1517     CCAChatInfoArray* itemArray = NULL;
       
  1518 
       
  1519     TRAP( err, itemArray = iGroupUtilsPC->GetChatInfoArrayL( aGroupId ) );
       
  1520 
       
  1521     if ( !itemArray ) //NOTE: dismiss dialog error could be wrong, check completely
       
  1522         {
       
  1523 
       
  1524         CleanupStack::PopAndDestroy( 2,  listBox );	// listBox, popUpList
       
  1525         iAppUi->DismissWaitDialogL( err );
       
  1526         CleanupStack::Pop( 1 ); // wait dialog
       
  1527 
       
  1528         return;
       
  1529         }
       
  1530 
       
  1531     CleanupStack::PushL( itemArray );
       
  1532 
       
  1533     // set the item array as listbox model
       
  1534     CTextListBoxModel* model = listBox->Model();
       
  1535     CleanupStack::Pop( itemArray );
       
  1536     model->SetItemTextArray( itemArray );
       
  1537     model->SetOwnershipType( ELbmOwnsItemArray );
       
  1538 
       
  1539     // set the title
       
  1540     HBufC* prompt = StringLoader::LoadLC(
       
  1541                         R_CHATLIST_VIEW_INFO_TITLE,
       
  1542                         iGroupUtilsPC->GetEngineDefaultGroupName( aGroupId ) );
       
  1543 
       
  1544     popUpList->SetTitleL( *prompt );
       
  1545     CleanupStack::PopAndDestroy( prompt );
       
  1546 
       
  1547 
       
  1548     // hide the waitnote and execute the popuplist
       
  1549     iAppUi->DismissWaitDialogL( KErrNone );
       
  1550 
       
  1551     popUpList->ExecuteLD();
       
  1552     CleanupStack::Pop( popUpList );
       
  1553 
       
  1554     CleanupStack::PopAndDestroy( );	// listBox
       
  1555 
       
  1556     CleanupStack::Pop( 1 ); // wait dialog
       
  1557     }
       
  1558 
       
  1559 
       
  1560 
       
  1561 
       
  1562 
       
  1563 // -----------------------------------------------------------------------------
       
  1564 // CCAGroupUtils::IsJoinedToGroup
       
  1565 // (other items were commented in a header).
       
  1566 // -----------------------------------------------------------------------------
       
  1567 //
       
  1568 TBool CCAGroupUtils::IsJoinedToGroup( const TDesC& aGroupId )
       
  1569     {
       
  1570     return iGroupUtilsPC->IsJoined( aGroupId );
       
  1571     }
       
  1572 // -----------------------------------------------------------------------------
       
  1573 // CCAGroupUtils::IsOwnGroup
       
  1574 // (other items were commented in a header).
       
  1575 // -----------------------------------------------------------------------------
       
  1576 //
       
  1577 TBool CCAGroupUtils::IsOwnGroup( const TDesC& aGroupId ) const
       
  1578     {
       
  1579     return iGroupUtilsPC->IsOwnGroup( aGroupId );
       
  1580     }
       
  1581 
       
  1582 // -----------------------------------------------------------------------------
       
  1583 // CCAGroupUtils::IsFavouriteChatGroup
       
  1584 // (other items were commented in a header).
       
  1585 // -----------------------------------------------------------------------------
       
  1586 //
       
  1587 TBool CCAGroupUtils::IsFavouriteChatGroup( const TDesC& aGroupId )
       
  1588     {
       
  1589     return iGroupUtilsPC->IsFavouriteChatGroup( aGroupId );
       
  1590     }
       
  1591 
       
  1592 // -----------------------------------------------------------------------------
       
  1593 // CCAGroupUtils::IsOwnGroup
       
  1594 // (other items were commented in a header).
       
  1595 // -----------------------------------------------------------------------------
       
  1596 //
       
  1597 void CCAGroupUtils::SaveAsFavouriteL( const TDesC& aGroupId )
       
  1598     {
       
  1599 
       
  1600     iAppUi->ShowWaitDialogL( R_QTN_GEN_NOTE_SAVING );
       
  1601 
       
  1602     TRAPD( err, iGroupUtilsPC->SaveAsFavouriteL( aGroupId ) );
       
  1603 
       
  1604     iAppUi->DismissWaitDialogL( err );
       
  1605     }
       
  1606 
       
  1607 // -----------------------------------------------------------------------------
       
  1608 // CCAGroupUtils::FindGroup
       
  1609 // (other items were commented in a header).
       
  1610 // -----------------------------------------------------------------------------
       
  1611 //
       
  1612 TBool CCAGroupUtils::FindGroup( const TDesC& aGroupId ) const
       
  1613     {
       
  1614     return iGroupUtilsPC->FindGroup( aGroupId );
       
  1615     }
       
  1616 
       
  1617 // -----------------------------------------------------------------------------
       
  1618 // CCAGroupUtils::GetGroupName
       
  1619 // (other items were commented in a header).
       
  1620 // -----------------------------------------------------------------------------
       
  1621 //
       
  1622 TPtrC CCAGroupUtils::GetGroupName( const TDesC& aGroupId ) const
       
  1623     {
       
  1624     return iGroupUtilsPC->GetEngineDefaultGroupName( aGroupId );
       
  1625     }
       
  1626 
       
  1627 // -----------------------------------------------------------------------------
       
  1628 // CCAGroupUtils::DeleteGroupL
       
  1629 // (other items were commented in a header).
       
  1630 // -----------------------------------------------------------------------------
       
  1631 //
       
  1632 TInt CCAGroupUtils::DeleteGroupL( const TDesC& aGroupId )
       
  1633     {
       
  1634 
       
  1635     TInt retVal( KErrNone );
       
  1636 
       
  1637     HBufC* groupName = iGroupUtilsPC->GetEngineDefaultGroupName( aGroupId ).AllocLC();
       
  1638 
       
  1639     HBufC* prompt = StringLoader::LoadLC( R_DELETE_CHATGROUP_PROMPT,
       
  1640                                           *groupName );
       
  1641 
       
  1642     // Show confirmation
       
  1643 
       
  1644     TInt ret( IMDialogUtils::DisplayQueryDialogL( R_GENERIC_YES_NO_CONFIRMATION_QUERY,
       
  1645                                                   *prompt ) );
       
  1646     CleanupStack::PopAndDestroy( prompt );
       
  1647 
       
  1648     CleanupStack::PopAndDestroy( groupName );
       
  1649 
       
  1650     if ( ( ret == EAknSoftkeyOk ) || ( ret == EAknSoftkeyYes ) )
       
  1651         {
       
  1652         // if group is own and deletion is allowed
       
  1653         // and autodeletion is not used => delete also from network
       
  1654 
       
  1655         // if group is own and deletion is allowed
       
  1656         // and autodeletion is not used => delete also from network
       
  1657         TBool deleteFromNetwork( IsOwnGroup( aGroupId ) &&
       
  1658                                  IMUtils::IntResourceValueL( RSC_CHAT_VARIATION_ALLOW_EDIT_GROUP_PROPERTIES )
       
  1659                                  && !IMUtils::IntResourceValueL( RSC_CHAT_VARIATION_GROUP_AUTODELETE ) );
       
  1660 
       
  1661         iAppUi->ShowWaitDialogL( R_QTN_FLDR_DELETING_WAIT_NOTE );
       
  1662         TRAPD( err, retVal = iGroupUtilsPC->DeleteGroupL( aGroupId, deleteFromNetwork ) );
       
  1663         iAppUi->DismissWaitDialogL( err );
       
  1664 
       
  1665         if ( retVal != KErrNone )
       
  1666             {
       
  1667             IMNoteMapper::ShowNoteL( retVal );
       
  1668             }
       
  1669         }
       
  1670     return ret;
       
  1671     }
       
  1672 
       
  1673 // ---------------------------------------------------------
       
  1674 // CCAGroupUtils::GetParticipantsL()
       
  1675 // ---------------------------------------------------------
       
  1676 //
       
  1677 void CCAGroupUtils::GetParticipantsL( CDesCArray& aParticipantList,
       
  1678                                       const TDesC& aGroupID ) const
       
  1679     {
       
  1680     iGroupUtilsPC->GetParticipantsL( aParticipantList, aGroupID );
       
  1681     }
       
  1682 // -----------------------------------------------------------------------------
       
  1683 // CCAGroupUtils::LeaveGroupL
       
  1684 // (other items were commented in a header).
       
  1685 // -----------------------------------------------------------------------------
       
  1686 //
       
  1687 TInt CCAGroupUtils::LeaveGroupL( const TDesC& aGroupId )
       
  1688     {
       
  1689 
       
  1690     iAppUi->ShowWaitDialogL( R_QTN_CHAT_GROUP_LEAVING );
       
  1691 
       
  1692 
       
  1693     TRAPD( err, iGroupUtilsPC->LeaveGroupL( aGroupId ) );
       
  1694 
       
  1695     iAppUi->DismissWaitDialogL( err );
       
  1696 
       
  1697     if ( err )
       
  1698         {
       
  1699         CActiveScheduler::Current()->Error( err );
       
  1700         }
       
  1701 
       
  1702     return KErrNone;
       
  1703     }
       
  1704 
       
  1705 // ---------------------------------------------------------
       
  1706 // CCASingleListContainer::DisplayJoinedMembersL()
       
  1707 // Displays joined members
       
  1708 // (other items were commented in a header).
       
  1709 // ---------------------------------------------------------
       
  1710 //
       
  1711 void CCAGroupUtils::DisplayJoinedMembersL( const TDesC& aGroupId )
       
  1712     {
       
  1713     CDesCArray* joinedMembers = new( ELeave )CDesCArrayFlat(
       
  1714         KArrayGranularity );
       
  1715     CleanupStack::PushL( joinedMembers );
       
  1716 
       
  1717     iGroupUtilsPC->GetParticipantsL( *joinedMembers, aGroupId );
       
  1718 
       
  1719     joinedMembers->Sort( ECmpCollated );
       
  1720 
       
  1721     IMDialogUtils::DisplayPopupListL( joinedMembers,
       
  1722                                       R_CHATVIEW_SHOW_PART_PROMPT, ELbmDoesNotOwnItemArray );
       
  1723 
       
  1724     CleanupStack::PopAndDestroy( joinedMembers );
       
  1725     }
       
  1726 
       
  1727 // -----------------------------------------------------------------------------
       
  1728 // CCAGroupUtils::IsAdmin
       
  1729 // (other items were commented in a header).
       
  1730 // -----------------------------------------------------------------------------
       
  1731 //
       
  1732 TBool CCAGroupUtils::IsAdmin( const TDesC& aGroupId ) const
       
  1733     {
       
  1734     return iGroupUtilsPC->IsAdmin( aGroupId );
       
  1735     }
       
  1736 TPtrC CCAGroupUtils::GetJoinGroupID()
       
  1737     {
       
  1738     if ( iJoinGroupId )
       
  1739         {
       
  1740         return iJoinGroupId->Des(); ;    
       
  1741         }
       
  1742     else
       
  1743         {
       
  1744         return KEmptyDesC();       
       
  1745         }    
       
  1746     }