wvuing/wvcommandutils/Src/CCAContactEditCmd.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:  This component is for contact editing
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // ============================ HEADER FILES ===============================
       
    21 //  INCLUDE FILES
       
    22 #include    "CCAContactEditCmd.h"
       
    23 #include    "MCAProcessManager.h"
       
    24 #include	"TEnumsPC.h"
       
    25 #include	"ImpsCSPAllErrors.h"
       
    26 #include 	"IMNoteMapper.h"
       
    27 #include 	"IMDialogUtils.h"
       
    28 
       
    29 #include	<chatNG.rsg>
       
    30 
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // Destructor
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CCAContactEditCmd::~CCAContactEditCmd()
       
    39     {
       
    40 
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // C++ constructor
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CCAContactEditCmd::CCAContactEditCmd(
       
    48     MCAUiContactEditCmdCB& aUiContactEditCmdCB,
       
    49     MCAContactEditPC & aCCAContactEditPC )
       
    50         :
       
    51         iUiContactEditCmdCB( aUiContactEditCmdCB ),
       
    52         iCCAContactEditPC( static_cast <CCAContactEditPC&>( aCCAContactEditPC ) )
       
    53     {
       
    54 
       
    55     }
       
    56 
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CCAContactEditCmd::NewL
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CCAContactEditCmd* CCAContactEditCmd::NewL( MCAProcessManager& aProcessManager,
       
    63                                             MCAUiContactEditCmdCB& aUiContactEditCmdCB )
       
    64     {
       
    65     CCAContactEditCmd* self = CCAContactEditCmd::NewLC( aProcessManager ,
       
    66                                                         aUiContactEditCmdCB );
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }
       
    70 
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CCAContactEditCmd::NewLC
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CCAContactEditCmd* CCAContactEditCmd::NewLC( MCAProcessManager& aProcessManager,
       
    77                                              MCAUiContactEditCmdCB& aUiContactEditCmdCB )
       
    78     {
       
    79     CCAContactEditCmd* self = new( ELeave ) CCAContactEditCmd(
       
    80         aUiContactEditCmdCB,
       
    81         *aProcessManager.GetContactEditInterface() );
       
    82     CleanupStack::PushL( self );
       
    83     return self;
       
    84     }
       
    85 
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CCAContactEditCmd::SetObserver
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 void CCAContactEditCmd::SetObserver( MCACommandObserver& /*aObserver*/ )
       
    92     {
       
    93 
       
    94     }
       
    95 
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CCAContactEditCmd::CancelCommand
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void CCAContactEditCmd::CancelCommand()
       
   102     {
       
   103 
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CCAContactEditCmd::ExecuteCommandL
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 void CCAContactEditCmd::ExecuteCommandL()
       
   111     {
       
   112     MCAUiContactEditCmdCB::TContactEditParams params;
       
   113 
       
   114     iUiContactEditCmdCB.GetParameters( params );
       
   115 
       
   116     switch ( params.iContactEditOperation )
       
   117         {
       
   118         case MCAUiContactEditCmdCB::TContactEditParams::ELoadContactDetails :
       
   119             {
       
   120             LoadCCAContactDetailsL( params ) ;
       
   121             break;
       
   122             }
       
   123 
       
   124         case MCAUiContactEditCmdCB::TContactEditParams::EAddContact :
       
   125             {
       
   126             SaveCCAContactDetailsL( params ) ;
       
   127             break;
       
   128             }
       
   129         case MCAUiContactEditCmdCB::TContactEditParams::EUpdateContact :
       
   130             {
       
   131             SaveCCAContactDetailsL( params ) ;
       
   132             break;
       
   133             }
       
   134         case MCAUiContactEditCmdCB::TContactEditParams::EMoveContact :
       
   135             {
       
   136             MoveContactL( params ) ;
       
   137             break;
       
   138             }
       
   139 
       
   140         default:
       
   141             {
       
   142             break;
       
   143             }
       
   144         }
       
   145 
       
   146     iUiContactEditCmdCB.SetParameters( params );
       
   147 
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CCAContactEditCmd::IsAsynchronous
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 TBool CCAContactEditCmd::IsAsynchronous()
       
   155     {
       
   156     return ETrue;
       
   157     }
       
   158 
       
   159 
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CCAContactEditCmd::LoadCCAContactDetails
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 void CCAContactEditCmd::LoadCCAContactDetailsL(
       
   166     MCAUiContactEditCmdCB::TContactEditParams &aParams )
       
   167     {
       
   168 
       
   169     iCCAContactEditPC.GetContactDetailsL(
       
   170         aParams.iAliasEnabled,
       
   171         aParams.iNicknameEnabled,
       
   172         aParams.iOwnData,
       
   173         aParams.iOrigId,
       
   174         aParams.iAlias,
       
   175         aParams.iNickname,
       
   176         aParams.iUserId,
       
   177         aParams.iIdentification );
       
   178 
       
   179 
       
   180     }
       
   181 
       
   182 
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // CCAContactEditCmd::SaveCCAContactDetails
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 void CCAContactEditCmd::SaveCCAContactDetailsL
       
   189 ( MCAUiContactEditCmdCB::TContactEditParams &aParams )
       
   190     {
       
   191 
       
   192     aParams.iContactEditOperationError = KErrNone ;
       
   193 
       
   194     if ( aParams.iNewContact )
       
   195         {
       
   196         aParams.iContactEditOperationError =
       
   197             iCCAContactEditPC.AddContactL( *aParams.iListId,
       
   198                                            *aParams.iUserId,
       
   199                                            *aParams.iNickname,
       
   200                                            *aParams.iAlias );
       
   201         }
       
   202     else
       
   203         {
       
   204         aParams.iContactEditOperationError =
       
   205             iCCAContactEditPC.UpdateContactL( *aParams.iListId,
       
   206                                               *aParams.iUserId,
       
   207                                               *aParams.iNickname );
       
   208         }
       
   209 
       
   210     switch ( aParams.iContactEditOperationError )
       
   211         {
       
   212         case KErrNone:
       
   213             {
       
   214             TInt noteId( aParams.iNewContact ?
       
   215                          R_QTN_CHAT_CONTACT_ADD_NOTE : R_QTN_CHAT_CNOTE_SAVED );
       
   216             // find the contact in storage
       
   217             // If the wvid was edited, the contact is different and we
       
   218             // must search it from the storage
       
   219             iCCAContactEditPC.SetContactL( *aParams.iListId, *aParams.iUserId ) ;
       
   220 
       
   221                 {
       
   222                 // check nickname
       
   223                 HBufC* newNick =
       
   224                     iCCAContactEditPC.GetCurrentContactNickname().AllocL();
       
   225 
       
   226                 if ( newNick )
       
   227                     {
       
   228                     // contact found and it has a nickname
       
   229                     CleanupStack::PushL( newNick );
       
   230                     TPtrC newNickPtr( newNick->Des() );
       
   231 
       
   232                     // compare it to the one we tried to add
       
   233                     if ( newNickPtr.CompareC( *aParams.iNickname ) != 0
       
   234                          && aParams.iNicknameEnabled )
       
   235                         {
       
   236                         // nickname was changed
       
   237                         noteId = R_QTN_CHAT_SERVER_ALTERED_NICK;
       
   238                         }
       
   239                     CleanupStack::PopAndDestroy( newNick );
       
   240                     }
       
   241                 }
       
   242             IMDialogUtils::DisplayConfirmationNoteL( noteId );
       
   243 
       
   244             break;
       
   245             }
       
   246 
       
   247         case ECSPPartiallySuccessful:
       
   248             {
       
   249             // show the detailed error codes
       
   250             const RPointerArray<MCAPresenceError>& errorArray =
       
   251                 iCCAContactEditPC.LastContactEditOperationResultL();
       
   252 
       
   253             TInt count( errorArray.Count() );
       
   254 
       
   255 
       
   256             //for partially successful.
       
   257 
       
   258             if ( count == 0 )
       
   259                 {
       
   260                 IMNoteMapper::ShowNoteL( ECSPUnknownUserId, *aParams.iUserId );
       
   261                 }
       
   262 
       
   263             for ( TInt i( 0 ); i < count; i++ )
       
   264                 {
       
   265                 TInt error = errorArray[ i ]->ErrorCode();
       
   266                 const TDesC& userId = errorArray[i]->UserId();
       
   267                 if ( userId.Length() > 0 )
       
   268                     {
       
   269                     IMNoteMapper::ShowNoteL( error, userId );
       
   270                     }
       
   271                 }
       
   272             break;
       
   273             }
       
   274         default:
       
   275             {
       
   276             break;
       
   277             }
       
   278         }
       
   279 
       
   280     }
       
   281 
       
   282 
       
   283 // -----------------------------------------------------------------------------
       
   284 // CCAContactEditCmd::MoveContactL
       
   285 // -----------------------------------------------------------------------------
       
   286 //
       
   287 
       
   288 void CCAContactEditCmd::MoveContactL(
       
   289     MCAUiContactEditCmdCB::TContactEditParams &aParams )
       
   290     {
       
   291 
       
   292 
       
   293 
       
   294     // make a copy of ids so that instances are
       
   295     // valid when storage contacts disappear
       
   296     HBufC* userId = iCCAContactEditPC.GetCurrentContactUserId().AllocLC();
       
   297     HBufC* nickName = iCCAContactEditPC.GetCurrentContactNickname().AllocLC();
       
   298 
       
   299     // We have to remove first, because some servers
       
   300     // don't support same nicknames on different lists.
       
   301     // Yes, nicknames.
       
   302     aParams.iContactEditOperationError = iCCAContactEditPC.RemoveContactL(
       
   303                                              *aParams.iListId,
       
   304                                              *userId ) ;
       
   305     if ( aParams.iContactEditOperationError == KErrNone )
       
   306         {
       
   307 
       
   308         aParams.iContactEditOperationError = iCCAContactEditPC.AddContactL(
       
   309                                                  *aParams.iUserId,
       
   310                                                  *userId,
       
   311                                                  *nickName,
       
   312                                                  KNullDesC() );
       
   313         if ( aParams.iContactEditOperationError != KErrNone )
       
   314             {
       
   315             // adding failed, rollback
       
   316             // we can ignore the return value, because in this case
       
   317             // we will show the error from previous AddContactL
       
   318             iCCAContactEditPC.AddContactL( *aParams.iListId,
       
   319                                            *userId,
       
   320                                            *nickName,
       
   321                                            KNullDesC() );
       
   322             }
       
   323         }
       
   324 
       
   325     CleanupStack::PopAndDestroy( 2, userId ); // nickName, userId
       
   326 
       
   327     }
       
   328 
       
   329