IMPSengine/imapi/src/imclientimpl.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004 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: mplementation of the IM Client interface (imclient.h)
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "imclientimpl.h"
       
    22 #include "apiutils.h"
       
    23 #include "imerrors.h"
       
    24 #include "imconnectionimpl.h"
       
    25 #include "cntdbreader.h"
       
    26 
       
    27 
       
    28 // CONSTANTS
       
    29 const TInt KDetailedListGranularity = 5;
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CImClient::CImClient
       
    35 // C++ default constructor can NOT contain any code, that
       
    36 // might leave.
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CImClient::CImClient( CImConnectionImpl& aImConnection )
       
    40         :   iImConnection( aImConnection )
       
    41     {
       
    42 #ifdef _DEBUG
       
    43     CImApiLogger::Log( _L( "CImClient: Construction" ) );
       
    44 #endif
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CImClient::ConstructL
       
    49 // Symbian 2nd phase constructor can leave.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 void CImClient::ConstructL()
       
    53     {
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CImClient::NewL
       
    58 // Two-phased constructor.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CImClient* CImClient::NewL( CImConnectionImpl& aImConnection )
       
    62     {
       
    63     CImClient* self = new( ELeave ) CImClient( aImConnection );
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL();
       
    66     CleanupStack::Pop();
       
    67     return self;
       
    68     }
       
    69 
       
    70 
       
    71 // Destructor
       
    72 CImClient::~CImClient()
       
    73     {
       
    74 
       
    75 #ifdef _DEBUG
       
    76     CImApiLogger::Log( _L( "CImClient: Destruction" ) );
       
    77 #endif
       
    78 
       
    79 
       
    80     // This should be already empty
       
    81     __ASSERT_DEBUG( iOutstandingOpIds.Count() == 0,
       
    82                     User::Panic( KTxtImOpenApiPanic, EListNotEmpty ) );
       
    83 
       
    84     iOutstandingOpIds.Close();
       
    85 
       
    86     }
       
    87 
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CImClient::RegisterL
       
    91 // Starts the registration sequence
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CImClient::RegisterObserverL( MImObserver* aObserver )
       
    95     {
       
    96 
       
    97 #ifdef _DEBUG
       
    98     CImApiLogger::Log( _L( "CImClient: RegisterL" ) );
       
    99 #endif
       
   100 
       
   101     if ( iClientObserver )
       
   102         {
       
   103         User::Leave( KImApiErrAlreadyRegistered );
       
   104         }
       
   105 
       
   106     iImClient.RegisterL(
       
   107         ImpsEngine(),
       
   108         ImpsImHandler(),
       
   109         NULL,
       
   110         iImConnection.ApplicationId(),
       
   111         ETrue );
       
   112 
       
   113     iImClient.RegisterErrorObserverL( ImpsErrorHandler() );
       
   114 
       
   115     iClientObserver = aObserver;
       
   116 
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CImClient::UnregisterL
       
   121 // Unregisters the client from the WV engine
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void CImClient::UnregisterObserver()
       
   125     {
       
   126 #ifdef _DEBUG
       
   127     CImApiLogger::Log( _L( "CImClient: UnregisterL" ) );
       
   128 #endif
       
   129 
       
   130     // Clear the pointers to the client
       
   131     iClientObserver = NULL;
       
   132 
       
   133     // Unregister from Imps engine
       
   134     iImClient.Unregister();
       
   135     TInt err;
       
   136     TRAP( err, iImClient.UnregisterErrorObserverL() );
       
   137     }
       
   138 
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CImClient::SendPToPMessageL
       
   142 //
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 TInt CImClient::SendPToPMessageL( const TContactItemId& aContactItem,
       
   146                                   const TDesC16&        aContent )
       
   147     {
       
   148 #ifdef _DEBUG
       
   149     CImApiLogger::Log( _L( "CImClient: Sending PToP text Message (ContactID)" ) );
       
   150 #endif
       
   151     // Check the observer
       
   152     if ( !iClientObserver )
       
   153         {
       
   154         User::Leave( KImApiErrNotRegistered );
       
   155         }
       
   156     // Get the user IDs from the contact DB
       
   157     CDesCArraySeg* userIds = new( ELeave ) CDesCArraySeg( 1 );
       
   158     CleanupStack::PushL( userIds );
       
   159     iImConnection.ContactDBReader().GetWVIdL( aContactItem, *userIds );
       
   160 
       
   161     // check the userIds
       
   162     if ( userIds->Count() == 0 )
       
   163         {
       
   164         // no valid user to send
       
   165         CleanupStack::PopAndDestroy(); // >> userIds
       
   166         User::Leave( KImApiErrInvalidContactId );
       
   167         }
       
   168 
       
   169 #ifdef _DEBUG
       
   170     for ( TInt i( 0 ); i < userIds->MdcaCount(); ++i )
       
   171         {
       
   172         TPtrC	tmp = ( *userIds )[i];
       
   173         CImApiLogger::Log( _L( "    User ID: %S" ), &tmp );
       
   174         }
       
   175 #endif
       
   176 
       
   177     TInt opId( DoSendMessageL( *userIds, aContent ) );
       
   178     CleanupStack::PopAndDestroy(); // >> userIds
       
   179     return opId;
       
   180 
       
   181     }
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CImClient::SendPToPMessageL
       
   185 //
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 TInt CImClient::SendPToPMessageL( const CContactIdArray&   aContactIds,
       
   189                                   const TDesC16&           aContent )
       
   190 
       
   191     {
       
   192 #ifdef _DEBUG
       
   193     CImApiLogger::Log( _L( "CImClient: Sending PToP text Message (ContactID)" ) );
       
   194 #endif
       
   195     // Check the observer
       
   196     if ( !iClientObserver )
       
   197         {
       
   198         User::Leave( KImApiErrNotRegistered );
       
   199         }
       
   200 
       
   201     // Get the user IDs from the contact DB
       
   202     CDesCArraySeg* userIds = new( ELeave ) CDesCArraySeg( 1 );
       
   203     CleanupStack::PushL( userIds );
       
   204     iImConnection.ContactDBReader().ReadWVIdsL( aContactIds, *userIds );
       
   205 
       
   206     // check the userIds
       
   207     if ( userIds->Count() == 0 )
       
   208         {
       
   209         // no valid user to send
       
   210         CleanupStack::PopAndDestroy(); // >> userIds
       
   211         User::Leave( KImApiErrInvalidContactId );
       
   212         }
       
   213 
       
   214 #ifdef _DEBUG
       
   215     for ( TInt i( 0 ); i < userIds->MdcaCount(); ++i )
       
   216         {
       
   217         TPtrC	tmp = ( *userIds )[i];
       
   218         CImApiLogger::Log( _L( "    User ID: %S" ), &tmp );
       
   219         }
       
   220 #endif
       
   221 
       
   222     TInt opId( DoSendMessageL( *userIds, aContent ) );
       
   223     CleanupStack::PopAndDestroy(); // >> userIds
       
   224     return opId;
       
   225 
       
   226     }
       
   227 
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CImClient::SendPToPMessageL
       
   231 //
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 TInt CImClient::SendPToPMessageL( const TDesC&      aUserId,
       
   235                                   const TDesC16&    aContent )
       
   236     {
       
   237 #ifdef _DEBUG
       
   238     CImApiLogger::Log( _L( "CImClient: Sending PToP text Message (UserID)" ) );
       
   239     CImApiLogger::Log( _L( "    User ID: %S" ), &aUserId );
       
   240 #endif
       
   241 
       
   242     // Check the observer
       
   243     if ( !iClientObserver )
       
   244         {
       
   245         User::Leave( KImApiErrNotRegistered );
       
   246         }
       
   247 
       
   248     // Sanity checking
       
   249     if ( aUserId.Length() == 0  ) // empty user ID
       
   250         {
       
   251         User::Leave( KImApiErrInvalidUserId );
       
   252         }
       
   253 
       
   254     CDesCArraySeg* userIds = new( ELeave ) CDesCArraySeg( 1 );
       
   255     CleanupStack::PushL( userIds );
       
   256     userIds->AppendL( aUserId );
       
   257 
       
   258     TInt opId( DoSendMessageL( *userIds, aContent ) );
       
   259     CleanupStack::PopAndDestroy(); // >> userIds
       
   260     return opId;
       
   261     }
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // CImClient::SendPToPMessageL
       
   265 //
       
   266 // -----------------------------------------------------------------------------
       
   267 //
       
   268 TInt CImClient::SendPToPMessageL( const MDesCArray& aUserIds,
       
   269                                   const TDesC16&    aContent )
       
   270     {
       
   271 #ifdef _DEBUG
       
   272     CImApiLogger::Log( _L( "CImClient: Sending PToP text Message (UserID)" ) );
       
   273 
       
   274     for ( TInt i( 0 ); i < aUserIds.MdcaCount(); ++i )
       
   275         {
       
   276         TPtrC	tmp = aUserIds.MdcaPoint( i );
       
   277         CImApiLogger::Log( _L( "    User ID: %S" ), &tmp );
       
   278         }
       
   279 #endif
       
   280 
       
   281     // Check the observer
       
   282     if ( !iClientObserver )
       
   283         {
       
   284         User::Leave( KImApiErrNotRegistered );
       
   285         }
       
   286 
       
   287     // sanity checking
       
   288     if ( aUserIds.MdcaCount() == 0 ) // empty list
       
   289         {
       
   290         User::Leave( KImApiErrInvalidUserId );
       
   291         }
       
   292     else if ( ( aUserIds.MdcaCount() == 1 ) &&
       
   293               ( aUserIds.MdcaPoint( 0 ).Length() == 0 ) ) // empty user ID
       
   294         {
       
   295         User::Leave( KImApiErrInvalidUserId );
       
   296         }
       
   297 
       
   298     TInt opId( DoSendMessageL( aUserIds, aContent ) );
       
   299     return opId;
       
   300     }
       
   301 
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // CImClient::SendPToPMessageL
       
   305 //
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 TInt CImClient::SendPToPMessageL( const CContactIdArray& /*aContactIds*/,
       
   309                                   const TDesC&           /*aContentType*/,
       
   310                                   const TDesC8&          /*aContent*/ )
       
   311     {
       
   312     User::Leave( KErrNotSupported );
       
   313     return KErrNone;
       
   314     }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // CImClient::SendPToPMessageL
       
   318 //
       
   319 // -----------------------------------------------------------------------------
       
   320 //
       
   321 TInt CImClient::SendPToPMessageL( const MDesCArray& /*aUserIds*/,
       
   322                                   const TDesC&      /*aContentType*/,
       
   323                                   const TDesC8&     /*aContent*/ )
       
   324     {
       
   325     User::Leave( KErrNotSupported );
       
   326     return KErrNone;
       
   327     }
       
   328 
       
   329 // -----------------------------------------------------------------------------
       
   330 // CImClient::HandleNewTextMessageL
       
   331 //
       
   332 // -----------------------------------------------------------------------------
       
   333 //
       
   334 void CImClient::HandleNewTextMessageL( TInt              /*aOpId*/,
       
   335                                        const TDesC&      /*aMessageId*/,
       
   336                                        const TDesC&      aSender,
       
   337                                        const TDesC&      /*aGroupId*/,
       
   338                                        const MDesCArray& /*aRecipients*/,
       
   339                                        const MDesCArray& /*aScreenNames*/,
       
   340                                        const TDesC&      aText,
       
   341                                        TImpsCspIdentifier& /*aCspId*/ )
       
   342     {
       
   343 #ifdef _DEBUG
       
   344     CImApiLogger::Log(
       
   345         _L( "CImClient: HandleNewTextMessageL" ) );
       
   346 #endif
       
   347     _LIT( KMessageType, "text/plain" );
       
   348 
       
   349     if ( iClientObserver )
       
   350         {
       
   351         iClientObserver->HandleNewPToPMessageL(
       
   352             KErrNone,
       
   353             KNullContactId ,
       
   354             aSender,
       
   355             KMessageType,
       
   356             aText );
       
   357         }
       
   358     }
       
   359 
       
   360 // -----------------------------------------------------------------------------
       
   361 // CImClient::HandleSendCompleteL
       
   362 //
       
   363 // -----------------------------------------------------------------------------
       
   364 //
       
   365 void CImClient::HandleSendCompleteL(
       
   366     TInt  aOpId,
       
   367     TBool /*aDeliveryReportOrdered*/,
       
   368     TImpsCspIdentifier& /*aCspId*/ )
       
   369     {
       
   370 #ifdef _DEBUG
       
   371     CImApiLogger::Log( _L( "CImClient: HandleSendCompleteL" ) );
       
   372 #endif
       
   373 
       
   374 
       
   375     RemoveOpId( aOpId );
       
   376 
       
   377     if ( iClientObserver )
       
   378         {
       
   379         iClientObserver->HandleMessageSentL(
       
   380             aOpId,
       
   381             KErrNone );
       
   382         }
       
   383     }
       
   384 
       
   385 
       
   386 
       
   387 
       
   388 // -----------------------------------------------------------------------------
       
   389 // CImClient::HandleNewContentMessageL
       
   390 //
       
   391 // -----------------------------------------------------------------------------
       
   392 //
       
   393 void CImClient::HandleNewContentMessageL(
       
   394     TInt /*aOpId*/,
       
   395     const TDesC& /*aMessageId*/,
       
   396     const TDesC& /*aSender*/,
       
   397     const TDesC& /*aGroupId*/,
       
   398     const MDesCArray& /*aRecipients*/,
       
   399     const MDesCArray& /*aScreenNames*/,
       
   400     const TDesC& /*aContentType*/,
       
   401     const TDesC8& /*aContent*/,
       
   402     TImpsCspIdentifier& /*aCspId*/ )
       
   403     {
       
   404     }
       
   405 
       
   406 // -----------------------------------------------------------------------------
       
   407 // CImClient::HandleDeliveryReportL
       
   408 //
       
   409 // -----------------------------------------------------------------------------
       
   410 //
       
   411 void CImClient::HandleDeliveryReportL(
       
   412     const TDesC& /*aMessageId*/,
       
   413     TInt /*aResult*/,
       
   414     const TDesC* /*aDescription*/,
       
   415     TImpsCspIdentifier& /*aCspId*/ )
       
   416     {
       
   417     }
       
   418 
       
   419 // -----------------------------------------------------------------------------
       
   420 // CImClient::HandleErrorL
       
   421 //
       
   422 // -----------------------------------------------------------------------------
       
   423 //
       
   424 void CImClient::HandleErrorL( TInt                 aStatus,
       
   425                               TInt                 aOpId,
       
   426                               const TDesC*         /*aDescription*/,
       
   427                               const CImpsDetailed* aDetailedRes,
       
   428                               TImpsCspIdentifier&  /*aCspId*/ )
       
   429     {
       
   430 #ifdef _DEBUG
       
   431     CImApiLogger::Log( _L( "CImClient: IM error received: %d" ), aStatus );
       
   432 #endif
       
   433 
       
   434     CImClientDetailedErrorImpl* detailedResult = NULL;
       
   435 
       
   436     if ( aDetailedRes )
       
   437         {
       
   438         detailedResult = CImClientDetailedErrorImpl::NewL( aDetailedRes );
       
   439         CleanupStack::PushL( detailedResult ); // << detailedResult
       
   440         }
       
   441 
       
   442     if ( iClientObserver )
       
   443         {
       
   444         TInt err;
       
   445         TRAP( err, iClientObserver->HandleSendErrorL(
       
   446                   aOpId,
       
   447                   iImConnection.ConvertImpsEngineErrorCode( aStatus ),
       
   448                   detailedResult ) );
       
   449         }
       
   450 
       
   451 
       
   452     // Delete the OpID from the list
       
   453     RemoveOpId( aOpId );
       
   454     if ( detailedResult )
       
   455         {
       
   456         CleanupStack::PopAndDestroy(); // >> detailedResult
       
   457         }
       
   458 
       
   459     }
       
   460 
       
   461 // -----------------------------------------------------------------------------
       
   462 // CImClient::DoSendMessageL
       
   463 //
       
   464 // -----------------------------------------------------------------------------
       
   465 //
       
   466 TInt CImClient::DoSendMessageL( const MDesCArray&    aUserIds,
       
   467                                 const TDesC&         aContent )
       
   468     {
       
   469 
       
   470     TInt opId( 0 );
       
   471 
       
   472     TRAPD( err, opId = iImClient.SendTextMessageL( NULL,
       
   473                                                    &aUserIds,
       
   474                                                    NULL,
       
   475                                                    NULL,
       
   476                                                    aContent,
       
   477                                                    EFalse /*No delivery report*/ ) );
       
   478 
       
   479     if ( err != KErrNone )
       
   480         {
       
   481         // Failed to send
       
   482         User::Leave ( KImApiGeneralError );
       
   483         }
       
   484 
       
   485     // Put the OpID to the Outstanding OpIds list
       
   486     iOutstandingOpIds.Append( opId );
       
   487 
       
   488     return opId;
       
   489     }
       
   490 
       
   491 // -----------------------------------------------------------------------------
       
   492 // CImClient::RemoveOpId
       
   493 //
       
   494 // -----------------------------------------------------------------------------
       
   495 //
       
   496 void CImClient::RemoveOpId( TInt aOpId )
       
   497     {
       
   498     TInt index = iOutstandingOpIds.Find( aOpId );
       
   499 
       
   500     // OpID is not found from the list there is a problem somewhere
       
   501     __ASSERT_DEBUG( ( index != KErrNotFound ),
       
   502                     User::Panic( KTxtImOpenApiPanic, EListCorrupted ) );
       
   503 
       
   504     iOutstandingOpIds.Remove( index );
       
   505     }
       
   506 
       
   507 
       
   508 // -----------------------------------------------------------------------------
       
   509 // CImClient::ImpsImHandler
       
   510 //
       
   511 // -----------------------------------------------------------------------------
       
   512 //
       
   513 MImpsImHandler2* CImClient::ImpsImHandler()
       
   514     {
       
   515     return this;
       
   516     }
       
   517 
       
   518 // -----------------------------------------------------------------------------
       
   519 // CImClient::ImpsErrorHandler
       
   520 //
       
   521 // -----------------------------------------------------------------------------
       
   522 //
       
   523 MImpsErrorHandler2& CImClient::ImpsErrorHandler()
       
   524     {
       
   525     return *this;
       
   526     }
       
   527 
       
   528 // -----------------------------------------------------------------------------
       
   529 // CImClient::ImpsEngine
       
   530 //
       
   531 // -----------------------------------------------------------------------------
       
   532 //
       
   533 RImpsEng& CImClient::ImpsEngine()
       
   534     {
       
   535     return iImConnection.ImpsEngine();
       
   536     }
       
   537 
       
   538 
       
   539 // -----------------------------------------------------------------------------
       
   540 // CImClient::ClientObserver
       
   541 //
       
   542 // -----------------------------------------------------------------------------
       
   543 //
       
   544 MImObserver* CImClient::ClientObserver()
       
   545     {
       
   546     return iClientObserver;
       
   547     }
       
   548 
       
   549 
       
   550 //////////////////////////////////////////////////////////////////////////
       
   551 // TDetailedResultItem
       
   552 
       
   553 // -----------------------------------------------------------------------------
       
   554 // TDetailedResultItem::TDetailedResultItem
       
   555 //
       
   556 // -----------------------------------------------------------------------------
       
   557 //
       
   558 TDetailedResultItem::TDetailedResultItem()
       
   559     {
       
   560     }
       
   561 
       
   562 // -----------------------------------------------------------------------------
       
   563 // TDetailedResultItem::TDetailedResultItem
       
   564 //
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 TDetailedResultItem::~TDetailedResultItem()
       
   568     {
       
   569     }
       
   570 
       
   571 // -----------------------------------------------------------------------------
       
   572 // TDetailedResultItem::SetErrorCode
       
   573 //
       
   574 // -----------------------------------------------------------------------------
       
   575 //
       
   576 void TDetailedResultItem::SetErrorCode( TInt aErroCode )
       
   577     {
       
   578     iErrorCode = aErroCode;
       
   579     }
       
   580 
       
   581 // -----------------------------------------------------------------------------
       
   582 // TDetailedResultItem::ErrorCode
       
   583 //
       
   584 // -----------------------------------------------------------------------------
       
   585 //
       
   586 TInt TDetailedResultItem::ErrorCode() const
       
   587     {
       
   588     return iErrorCode;
       
   589     }
       
   590 
       
   591 // -----------------------------------------------------------------------------
       
   592 // TDetailedResultItem::SetUserId
       
   593 //
       
   594 // -----------------------------------------------------------------------------
       
   595 //
       
   596 void TDetailedResultItem::SetUserId( TDesC& aUserId )
       
   597     {
       
   598     iUserId.Set( aUserId );
       
   599     }
       
   600 
       
   601 // -----------------------------------------------------------------------------
       
   602 // TDetailedResultItem::UserId
       
   603 //
       
   604 // -----------------------------------------------------------------------------
       
   605 //
       
   606 const TDesC& TDetailedResultItem::UserId() const
       
   607     {
       
   608     return iUserId;
       
   609     }
       
   610 
       
   611 
       
   612 //////////////////////////////////////////////////////////////////////////
       
   613 // CImClientDetailedErrorImpl
       
   614 //////////////////////////////////////////////////////////////////////////
       
   615 
       
   616 // -----------------------------------------------------------------------------
       
   617 // CImClientDetailedErrorImpl::CImClientDetailedErrorImpl
       
   618 //
       
   619 // -----------------------------------------------------------------------------
       
   620 //
       
   621 CImClientDetailedErrorImpl::CImClientDetailedErrorImpl()
       
   622     {
       
   623     }
       
   624 
       
   625 // -----------------------------------------------------------------------------
       
   626 // CImClientDetailedErrorImpl::CImClientDetailedErrorImpl
       
   627 //
       
   628 // -----------------------------------------------------------------------------
       
   629 //
       
   630 void CImClientDetailedErrorImpl::ConstructL(
       
   631     const CImpsDetailed* aImpsDetailed )
       
   632     {
       
   633     iDetailedList = new( ELeave ) CArrayFixFlat<TDetailedResultItem>(
       
   634         KDetailedListGranularity );
       
   635     DoInitL( aImpsDetailed );
       
   636     }
       
   637 
       
   638 // -----------------------------------------------------------------------------
       
   639 // CImClientDetailedErrorImpl::CImClientDetailedErrorImpl
       
   640 //
       
   641 // -----------------------------------------------------------------------------
       
   642 //
       
   643 CImClientDetailedErrorImpl* CImClientDetailedErrorImpl::NewL(
       
   644     const CImpsDetailed* aImpsDetailed )
       
   645     {
       
   646     CImClientDetailedErrorImpl* self = new( ELeave ) CImClientDetailedErrorImpl();
       
   647     CleanupStack::PushL( self );
       
   648     self->ConstructL( aImpsDetailed );
       
   649     CleanupStack::Pop();
       
   650     return self;
       
   651     }
       
   652 
       
   653 // -----------------------------------------------------------------------------
       
   654 // CImClientDetailedErrorImpl::~CImClientDetailedErrorImpl
       
   655 //
       
   656 // -----------------------------------------------------------------------------
       
   657 //
       
   658 CImClientDetailedErrorImpl::~CImClientDetailedErrorImpl()
       
   659     {
       
   660     delete iDetailedList;
       
   661     }
       
   662 
       
   663 // -----------------------------------------------------------------------------
       
   664 // CImClientDetailedErrorImpl::Count
       
   665 //
       
   666 // -----------------------------------------------------------------------------
       
   667 //
       
   668 TInt CImClientDetailedErrorImpl::Count()
       
   669     {
       
   670     return iDetailedList->Count();
       
   671     }
       
   672 
       
   673 // -----------------------------------------------------------------------------
       
   674 // CImClientDetailedErrorImpl::UserId
       
   675 //
       
   676 // -----------------------------------------------------------------------------
       
   677 //
       
   678 const TDesC& CImClientDetailedErrorImpl::UserId( TInt aIndex )
       
   679     {
       
   680     // out-of-bounds will panic: E32USER-CBase 21
       
   681     return iDetailedList->At( aIndex ).UserId();
       
   682     }
       
   683 
       
   684 // -----------------------------------------------------------------------------
       
   685 // CImClientDetailedErrorImpl::ErrorCode
       
   686 //
       
   687 // -----------------------------------------------------------------------------
       
   688 //
       
   689 TInt CImClientDetailedErrorImpl::ErrorCode( TInt aIndex )
       
   690     {
       
   691     // out-of-bounds will panic: E32USER-CBase 21
       
   692     return iDetailedList->At( aIndex ).ErrorCode();
       
   693     }
       
   694 
       
   695 // -----------------------------------------------------------------------------
       
   696 // CImClientDetailedErrorImpl::DoInitL
       
   697 // Initializes the detailed list from the ImpsDetailed
       
   698 // -----------------------------------------------------------------------------
       
   699 //
       
   700 void CImClientDetailedErrorImpl::DoInitL( const CImpsDetailed* aImpsDetailed )
       
   701     {
       
   702     TInt detailedCount = aImpsDetailed->Count();
       
   703     for ( TInt i( 0 ); i < detailedCount; ++i )
       
   704         {
       
   705         // Get all the failed user IDs
       
   706         // and make a list of those IDs
       
   707         CPtrC16Array* userIds = aImpsDetailed->At( i )->UserIds();
       
   708         if ( userIds )
       
   709             {
       
   710             TInt userCount = userIds->Count();
       
   711             for ( TInt j( 0 ); j < userCount; ++j )
       
   712                 {
       
   713                 TDetailedResultItem resultItem;
       
   714                 resultItem.SetUserId( userIds->At( j ) );
       
   715                 resultItem.SetErrorCode( ConvertWVErrorCode(
       
   716                                              aImpsDetailed->At( i )->Code() ) );
       
   717                 iDetailedList->AppendL( resultItem );
       
   718                 }
       
   719             }
       
   720         }
       
   721     }
       
   722 
       
   723 
       
   724 // -----------------------------------------------------------------------------
       
   725 // CImClientDetailedErrorImpl::ConvertWVErrorCode
       
   726 // Converts the WV error code to an API error code
       
   727 // -----------------------------------------------------------------------------
       
   728 //
       
   729 TInt CImClientDetailedErrorImpl::ConvertWVErrorCode( TInt aErrorCode )
       
   730     {
       
   731     // Do not try to convert KErrNone
       
   732     if ( aErrorCode == KErrNone )
       
   733         {
       
   734         return KErrNone;
       
   735         }
       
   736 
       
   737     TInt returnValue;
       
   738     switch ( aErrorCode )
       
   739         {
       
   740         case 531: // Recipient does not exist
       
   741             returnValue = KImApiErrInvalidUserId;
       
   742             break;
       
   743         case 532: //Recipient user blocked the sender
       
   744             returnValue = KImApiErrSenderBlocked;
       
   745             break;
       
   746 
       
   747         case 533: // Recipient user is not logged in
       
   748             returnValue = KImApiErrRecipientNotLogged;
       
   749             break;
       
   750 
       
   751         default:
       
   752             returnValue = KImApiGeneralError;
       
   753             break;
       
   754 
       
   755         }
       
   756     return returnValue;
       
   757     }
       
   758 //  End of File