wvuing/wvuiave/AppSrc/CCAInviteEditor.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:  Editor for invites
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include	"CCAInviteEditor.h"		// header for this .cpp.
       
    21 #include	"IMDialogUtils.h"
       
    22 #include	"ChatDefinitions.h"
       
    23 #include    "CCAApp.h"
       
    24 #include    "CCAAppUi.h"
       
    25 #include	"CCAVariantFactory.h"
       
    26 #include    "ChatDebugPrint.h"
       
    27 #include    "IMPSBuildDefinitions.h"
       
    28 #include    "CCAContactSelectionDialog.h"
       
    29 #include    "MCAInviteConflictResolver.h"
       
    30 #include    "MCASettingsPC.h"
       
    31 #include    "MCAMainViewArrayPC.h"
       
    32 #include    "MCAProcessManager.h"
       
    33 #include    "MCAInviteEditorPC.h"
       
    34 #include    "MCAServerContactsArrayPC.h"
       
    35 #include 	"ImpsCSPAllErrors.h"
       
    36 #include 	"CCAPCUtils.h"
       
    37 
       
    38 #include	<eikenv.h>
       
    39 #include	<chatNG.rsg>
       
    40 #include    <stringloader.h>
       
    41 
       
    42 // The Settings have been moved to Cenrep (also retained in the Resource file),
       
    43 // so the enums for keys and central repository header is added here
       
    44 #include 	"VariantKeys.h"
       
    45 
       
    46 // ================= MEMBER FUNCTIONS =======================
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CCAInviteEditor::NewL
       
    50 // Two-phased constructor.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CCAInviteEditor* CCAInviteEditor::NewL( const TDesC& aGroup )
       
    54     {
       
    55     CCAInviteEditor* self = new ( ELeave ) CCAInviteEditor( );
       
    56 
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL( aGroup );
       
    59     CleanupStack::Pop( self );
       
    60 
       
    61     return self;
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CCAInviteEditor::NewLC
       
    66 // Two-phased constructor.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CCAInviteEditor* CCAInviteEditor::NewLC( const TDesC& aGroup )
       
    70     {
       
    71     CCAInviteEditor* self = new ( ELeave ) CCAInviteEditor( );
       
    72 
       
    73     CleanupStack::PushL( self );
       
    74     self->ConstructL( aGroup );
       
    75     return self;
       
    76     }
       
    77 
       
    78 // Destructor
       
    79 CCAInviteEditor::~CCAInviteEditor()
       
    80     {
       
    81     delete iGroupID;
       
    82     delete iInviteEditorPC;
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CCAInviteEditor::CreateAndSendInvitation
       
    87 // (other items were commented in a header).
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 TBool CCAInviteEditor::CreateAndSendInvitation( MCAInviteConflictResolver& aResolver,
       
    91                                                 const TDesC& aReceiver )
       
    92     {
       
    93     TRAPD( err, CreateAndSendInvitationL( aResolver, aReceiver ) );
       
    94 
       
    95     if ( err != KErrNone )
       
    96         {
       
    97         TRAPD( ign, ShowErrorNoteL() );
       
    98 
       
    99         if ( ign )
       
   100             {
       
   101             // propagate system errors to current active scheduler,
       
   102             CActiveScheduler::Current()->Error( ign );
       
   103             }
       
   104         }
       
   105 
       
   106     return ( err == KErrNone );
       
   107     }
       
   108 
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CCAInviteEditor::PopulateInviteListL
       
   112 // (other items were commented in a header).
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void CCAInviteEditor::PopulateInviteListL( CDesCArray& aInviteList,
       
   116                                            const MCAServerContactsArrayPC& aRawOnlineList,
       
   117                                            const CArrayFixFlat<TInt>& aSelectionArray )
       
   118     {
       
   119     iInviteEditorPC->PopulateInviteListL( aInviteList,
       
   120                                           aRawOnlineList,
       
   121                                           aSelectionArray );
       
   122 
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CCAInviteEditor::QueryInviteMessageL
       
   127 // (other items were commented in a header).
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 HBufC* CCAInviteEditor::QueryInviteMessageL()
       
   131     {
       
   132     HBufC* message = HBufC::NewLC( KInviteMessageMaxLength );
       
   133     TPtr messagePtr( message->Des() );
       
   134 
       
   135     if ( !IMDialogUtils::DisplayTextQueryDialogL( messagePtr,
       
   136                                                   R_CHAT_INVITE_MSG_DQ, R_CHAT_INVITE_MESSAGE_QUERY,
       
   137                                                   ETrue /* T9 */,
       
   138                                                   EFalse, // Show LSK only when needed
       
   139                                                   IMDialogUtils::ESend
       
   140                                                 ) )
       
   141         {
       
   142         CleanupStack::PopAndDestroy( message );
       
   143         return NULL;
       
   144         }
       
   145     else
       
   146         {
       
   147         CleanupStack::Pop( message );
       
   148         return message;
       
   149         }
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CCAInviteEditor::ShowErrorNoteL
       
   154 // (other items were commented in a header).
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 void CCAInviteEditor::ShowErrorNoteL()
       
   158     {
       
   159     HBufC* prompt = CEikonEnv::Static()->AllocReadResourceLC(
       
   160                         R_CHAT_INVITE_SEND_ERROR );
       
   161     IMDialogUtils::DisplayErrorNoteL( *prompt );
       
   162     CleanupStack::PopAndDestroy( prompt );
       
   163     }
       
   164 
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // C++ default constructor can NOT contain any code, that
       
   168 // might leave.
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 CCAInviteEditor::CCAInviteEditor(  )
       
   172     {
       
   173     }
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // CCAInviteEditor::ConstructL
       
   177 // Symbian 2nd phase constructor can leave.
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 void CCAInviteEditor::ConstructL( const TDesC& aGroup )
       
   181     {
       
   182     iGroupID = aGroup.AllocL();
       
   183     CCAAppUi* appUi = static_cast<CCAAppUi*>( CCoeEnv::Static()->AppUi() );
       
   184     iInviteEditorPC = appUi->GetProcessManager().CreateInviteEditorPCL();
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CCAInviteEditor::CreateAndSendInvitationL
       
   189 // (other items were commented in a header).
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 void CCAInviteEditor::CreateAndSendInvitationL( MCAInviteConflictResolver& aResolver,
       
   193                                                 const TDesC& aReceiver
       
   194                                               )
       
   195     {
       
   196 
       
   197     CDesCArray* inviteList = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   198     CleanupStack::PushL( inviteList );
       
   199 
       
   200 
       
   201     if ( aReceiver.Length() == 0 )
       
   202         {
       
   203         CCAAppUi* appUi = static_cast<CCAAppUi*>( CCoeEnv::Static()->AppUi() );
       
   204         CDesCArray* selectedContacts = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   205         CleanupStack::PushL( selectedContacts );
       
   206         MCASkinVariant* skinVar = static_cast<CCAApp*>( appUi->Application() )
       
   207                                   ->VariantFactory()->SkinVariantL();
       
   208 
       
   209 
       
   210         MCASettingsPC* settingsPC = appUi->GetProcessManager().GetSettingsInterface();
       
   211         MCAMainViewArrayPC* mainViewArrayPC = appUi->GetProcessManager().GetArrayInterface();
       
   212         if ( ! CCAContactSelectionDialog::ShowDialogL( *selectedContacts,
       
   213                                                        *mainViewArrayPC,
       
   214                                                        *skinVar, *settingsPC,
       
   215                                                        appUi->MbmFullPath(),
       
   216                                                        TEnumsPC::EMultiSelect,
       
   217                                                        R_CONTACT_SELECTION_DIALOG,
       
   218                                                        *appUi->CAStatusPane(),
       
   219                                                        NULL ) )
       
   220             {
       
   221             // no contacts
       
   222             CleanupStack::PopAndDestroy( 2 ); // selectedContacts.Close(), inviteList
       
   223             return;
       
   224             }
       
   225 
       
   226         // handle selected contacts (if any)
       
   227         TInt count( selectedContacts->MdcaCount() );
       
   228         CHAT_DP( D_CHAT_LIT( "selection count %d" ), count );
       
   229         for ( TInt i( 0 ); i < count; ++i )
       
   230             {
       
   231 
       
   232             TPtrC wvid( selectedContacts->MdcaPoint( i ) );
       
   233 
       
   234             CHAT_DP( D_CHAT_LIT( "..adding %S to invite list" ), &wvid );
       
   235             // Prevent duplicates and don't add if user canceled offline notification
       
   236             TInt pos( KErrNone );
       
   237             if ( inviteList->Find( wvid, pos ) != KErrNone )
       
   238                 {
       
   239                 inviteList->AppendL( wvid );
       
   240                 }
       
   241             }
       
   242 
       
   243         CleanupStack::PopAndDestroy(); // selectedContacts.Close()
       
   244         }
       
   245     else
       
   246         {
       
   247         inviteList->AppendL( aReceiver );
       
   248         }
       
   249 
       
   250     // If user selected something, then proceed...
       
   251     if ( inviteList->MdcaCount() > 0 )
       
   252         {
       
   253         // Ask for invite message
       
   254         HBufC* message = QueryInviteMessageL();
       
   255 
       
   256         if ( message )
       
   257             {
       
   258             CleanupStack::PushL( message );
       
   259 
       
   260             // Resolve invite conflicts
       
   261             aResolver.ResolveInviteConflictL( *iGroupID, *inviteList );
       
   262 
       
   263             TInt inviteeCount = inviteList->MdcaCount();
       
   264             if ( inviteeCount > 0 )
       
   265                 {
       
   266                 // Create invitation
       
   267                 // Show wait-note
       
   268                 CCAAppUi* appUi =
       
   269                     static_cast< CCAAppUi* >( CCoeEnv::Static()->AppUi() );
       
   270 
       
   271                 // Show wait-note. Error state dismisses it.
       
   272                 appUi->ShowWaitDialogL( inviteList->MdcaCount() > 1 ?
       
   273                                         R_QTN_CHAT_INVITE_SENDING_MANY : R_QTN_CHAT_INVITE_SENDING,
       
   274                                         ETrue );
       
   275                 // Send invitation
       
   276                 TRAPD( retval, iInviteEditorPC->SendInvitationL( *inviteList,
       
   277                                                                  *iGroupID,
       
   278                                                                  *message ) );
       
   279 
       
   280                 CleanupStack::PopAndDestroy( message );
       
   281                 // Get rid of wait-note
       
   282                 if ( retval == ECSPRecipientBlockedSender )
       
   283                     {
       
   284                     for ( TInt cnt = 0; cnt < inviteeCount; cnt++ )
       
   285                         {
       
   286                         appUi->DismissWaitDialogL( retval, EFalse,
       
   287                                                    CCAPCUtils::DisplayId( inviteList->MdcaPoint( cnt ) ) );
       
   288                         }
       
   289                     }
       
   290                 else
       
   291                     {
       
   292                     appUi->DismissWaitDialogL( retval );
       
   293                     }
       
   294 
       
   295                 }
       
   296             else
       
   297                 {
       
   298                 CleanupStack::PopAndDestroy( message );
       
   299                 }
       
   300 
       
   301             }
       
   302         else
       
   303             {
       
   304             // User cancelled invite message query,
       
   305             // return to contact selection view
       
   306             CleanupStack::PopAndDestroy( inviteList );
       
   307             return;
       
   308             }
       
   309         }
       
   310     CleanupStack::PopAndDestroy( inviteList );
       
   311 
       
   312     }
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 // CCAInviteEditor::GetOnlineFriendsLC
       
   316 // (other items were commented in a header).
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 MCAServerContactsArrayPC* CCAInviteEditor::GetOnlineFriendsLC()
       
   320     {
       
   321     MCAServerContactsArrayPC* pairsArray = iInviteEditorPC->GetOnlineFriendsLC( KIconTabulator );
       
   322     return pairsArray;
       
   323     }
       
   324 
       
   325 //  End of File
       
   326