| Start/ | End/ | |||
| True | False | - | Line | Source |
| 1 | /* | |||
| 2 | * =========================================================================== | |||
| 3 | * Name : cvimpstcmdprocessselectedcontact.cpp | |||
| 4 | * Part of : IMUiServiceTab/vimpstcmdprocess | |||
| 5 | * Description : | |||
| 6 | * Version : %version: 12 % | |||
| 7 | * | |||
| 8 | * Copyright © 2008 Nokia. All rights reserved. | |||
| 9 | * This material, including documentation and any related computer | |||
| 10 | * programs, is protected by copyright controlled by Nokia. All | |||
| 11 | * rights are reserved. Copying, including reproducing, storing, | |||
| 12 | * adapting or translating, any or all of this material requires the | |||
| 13 | * prior written consent of Nokia. This material also contains | |||
| 14 | * confidential information which may not be disclosed to others | |||
| 15 | * without the prior written consent of Nokia. | |||
| 16 | * ============================================================================ | |||
| 17 | */ | |||
| 18 | ||||
| 19 | //include files | |||
| 20 | #include "cvimpstcmdprocessselectedcontact.h" | |||
| 21 | ||||
| 22 | #include <MVPbkStoreContact.h> | |||
| 23 | #include <MVPbkFieldType.h> | |||
| 24 | #include <MVPbkContactFieldTextData.h> | |||
| 25 | #include <MVPbkContactFieldUriData.h> | |||
| 26 | ||||
| 27 | #include "vimpstcmd.hrh" | |||
| 28 | #include "mvimpstcmdobserver.h" | |||
| 29 | #include "vimpstdebugprint.h" | |||
| 30 | ||||
| 31 | #include <e32def.h> | |||
| 32 | #include <mvpbkcontactlinkarray.h> | |||
| 33 | #include "mvimpstengine.h" | |||
| 34 | ||||
| 35 | #include "mvimpststorageserviceview.h" | |||
| 36 | #include "cvimpststoragemanagerfactory.h" | |||
| 37 | #include "mvimpstenginecontactmgmtextention.h" | |||
| 38 | #include "tvimpstconsts.h" | |||
| 39 | #include "mvimpstenginesubservice.h" | |||
| 40 | #include "mvimpstenginepresencesubservice.h" | |||
| 41 | ||||
| 42 | // Constants | |||
| 43 | _LIT( KListNameAllBuddy ,"buddylist" ); | |||
| 44 | ||||
| 45 | // -------------------------------------------------------------------------- | |||
| 46 | // CVIMPSTCmdProcessSelectedContact::CVIMPSTCmdProcessSelectedContact | |||
| 47 | // -------------------------------------------------------------------------- | |||
| 48 | // | |||
| 8 | 8 | 49 | CVIMPSTCmdProcessSelectedContact::CVIMPSTCmdProcessSelectedContact( const TInt aCommandId , | |
| 50 | TVPbkSelectedData& aSelectedEntries, | |||
| 51 | MVIMPSTEngine& aEngine ): | |||
| 52 | iCommandId( aCommandId ), | |||
| 53 | iSelectedEntries( aSelectedEntries ), | |||
| 54 | iEngine(aEngine) | |||
| 55 | { | |||
| 56 | } | |||
| 57 | ||||
| 58 | // -------------------------------------------------------------------------- | |||
| 59 | // CVIMPSTCmdProcessSelectedContact::~CVIMPSTCmdProcessSelectedContact | |||
| 60 | // -------------------------------------------------------------------------- | |||
| 61 | // | |||
| 8 | 8 | 62 | CVIMPSTCmdProcessSelectedContact::~CVIMPSTCmdProcessSelectedContact() | |
| 63 | { | |||
| 64 | ||||
| 65 | } | |||
| 66 | ||||
| 67 | // -------------------------------------------------------------------------- | |||
| 68 | // CVIMPSTCmdProcessSelectedContact::NewL | |||
| 69 | // -------------------------------------------------------------------------- | |||
| 70 | // | |||
| 8 | 0 | 71 | CVIMPSTCmdProcessSelectedContact* CVIMPSTCmdProcessSelectedContact::NewL( const TInt aCommandId, | |
| 72 | TVPbkSelectedData& aSelectedEntries, | |||
| 73 | MVIMPSTEngine& aEngine ) | |||
| 74 | { | |||
| 75 | CVIMPSTCmdProcessSelectedContact* self = new (ELeave ) CVIMPSTCmdProcessSelectedContact( aCommandId ,aSelectedEntries, aEngine); | |||
| 76 | self->ConstructL(); //use contsurctL if necessary | |||
| 8 | 77 | return self; | ||
| 78 | } | |||
| 79 | // -------------------------------------------------------------------------- | |||
| 80 | // CVIMPSTCmdProcessSelectedContact::ConstructL | |||
| 81 | // -------------------------------------------------------------------------- | |||
| 82 | // | |||
| 8 | 8 | 83 | void CVIMPSTCmdProcessSelectedContact::ConstructL() | |
| 84 | { | |||
| 85 | iError = KErrNone; | |||
| 86 | } | |||
| 87 | ||||
| 88 | // -------------------------------------------------------------------------- | |||
| 89 | // CVIMPSTCmdProcessSelectedContact::ExecuteLD | |||
| 90 | // -------------------------------------------------------------------------- | |||
| 91 | // | |||
| 8 | 8 | 92 | void CVIMPSTCmdProcessSelectedContact::ExecuteLD() | |
| 93 | { | |||
| 94 | CHAT_DP_FUNC_ENTER("CVIMPSTCmdProcessSelectedContact::ExecuteLD"); | |||
| 95 | //push to the cleanupstack | |||
| 96 | CleanupStack::PushL( this ); | |||
| 97 | MVIMPSTStorageServiceView* storage = CVIMPSTStorageManagerFactory::ContactListInterfaceL( iEngine.ServiceId() ) ; | |||
| 8 | 0 | - | 98 | if(storage) |
| 99 | { | |||
| 100 | TBool localStore = storage->IsLocalStore(); | |||
| 101 | //retrieve contact from links | |||
| 102 | TPtrC8 pacledLinks = iSelectedEntries.iPackedLinks->Des(); | |||
| 103 | TInt count = storage->RetriveLinkXSPIdsL( pacledLinks ); | |||
| 0 | 8 | - | 104 | if( !count ) |
| 105 | { | |||
| 106 | iError = KErrGeneral; | |||
| 107 | } | |||
| 108 | if( (iCommandId == ECmdProcessSelectedContactNew || | |||
| 109 | iCommandId == ECmdProcessSelectedContactExist )&& | |||
| 4 | 4 | 110 | iError == KErrNone ) | |
| 111 | { | |||
| 112 | MVIMPSTEngineExtentionFeatures* contactFeature = iEngine.ExtentionFeatures(TVIMPSTEnums::EContactManagement); | |||
| 113 | MVIMPSTEngineSubService* presenceService = iEngine.SubService(TVIMPSTEnums::EPresence); | |||
| 12 | 4 | 114 | for(TInt index = 0; index < count; index++ ) | |
| 115 | { | |||
| 116 | TPtrC xspIdPtr = storage->GetRetrieveXSPIdL( index ); // xspId is owned here | |||
| 12 | 0 | - | 117 | if( localStore ) |
| 118 | { | |||
| 119 | iError = KErrNone; | |||
| 12 | 0 | - | 120 | if( xspIdPtr.Length() ) |
| 121 | { | |||
| 4 | 8 | 122 | if( IsContactBlocked( xspIdPtr ) ) | |
| 123 | { | |||
| 124 | iError = EErrExistInBlockList; | |||
| 125 | } | |||
| 4 | 4 | 126 | else if( storage->FindContactByUserId( xspIdPtr ) ) | |
| 127 | { | |||
| 128 | iError = EErrExistInContactList; | |||
| 129 | } | |||
| 4 | 0 | - | 130 | else if( contactFeature ) |
| 131 | { | |||
| 132 | // add to server and store if sucess | |||
| 133 | MVIMPSTEngineContactMgmtExtention& contactMgr = | |||
| 134 | MVIMPSTEngineContactMgmtExtention::Cast (*contactFeature); | |||
| 135 | iError = contactMgr.AddServerContactL( KListNameAllBuddy, xspIdPtr ,KNullDesC ); | |||
| 136 | } | |||
| 137 | } | |||
| 0 | 12 | - | 138 | if(KErrNone == iError ) |
| 139 | { | |||
| 140 | iError = storage->CreateNewContactFromRetrivedIdL( index ); | |||
| 141 | } | |||
| 6 | 6 | 142 | else if( iCommandId == ECmdProcessSelectedContactNew ) | |
| 143 | { | |||
| 144 | // delete the contact which got created in phonebook but failed to add in servicetab | |||
| 145 | storage->DeleteNewContactFromRetrivedIdL( index ); | |||
| 146 | } | |||
| 147 | } | |||
| 0 | 0 | - | 148 | else if( xspIdPtr.Length() ) |
| 149 | { | |||
| 150 | // xspId ownership is transfered to iXSPList | |||
| 151 | iSelectedEntries.iXSPList.AppendL( xspIdPtr.AllocL() ); | |||
| 152 | } | |||
| 153 | } | |||
| 154 | } | |||
| 155 | else if( ( iCommandId == ECmdProcessAcceptedContactNew || | |||
| 156 | iCommandId == ECmdProcessAcceptedContactExist )&& | |||
| 4 | 0 | - | 157 | iError == KErrNone )// for accepted contact |
| 158 | { | |||
| 159 | // just add and return | |||
| 160 | // contact is already added in storage in RetrieveContactL | |||
| 161 | // if sucess ,storage will take ownership else we need to delete contact | |||
| 162 | iError = storage->CreateNewContactFromRetrivedIdL( 0 ); // for accepting invitation take the first contact which is retirved | |||
| 2 | 2 | 163 | if( iError != KErrNone && iCommandId == ECmdProcessAcceptedContactNew ) | |
| 164 | { | |||
| 165 | // delete the contact which got created in phonebook but failed to add in servicetab | |||
| 166 | storage->DeleteNewContactFromRetrivedIdL( 0 ); | |||
| 167 | } | |||
| 168 | } | |||
| 0 | 8 | - | 169 | if( !localStore ) |
| 170 | { | |||
| 171 | // in case of server we have a selection dialog | |||
| 172 | // so this error does not matter | |||
| 173 | // set to 0 | |||
| 174 | iError = KErrNone; | |||
| 175 | } | |||
| 176 | } | |||
| 177 | else | |||
| 178 | { | |||
| 179 | iError = KErrGeneral; | |||
| 180 | } | |||
| 4 | 4 | 181 | if(iObserver) | |
| 182 | { | |||
| 183 | iObserver->CommandFinishedL(*this); | |||
| 184 | } | |||
| 185 | CHAT_DP_FUNC_ENTER("CVIMPSTCmdProcessSelectedContact:: CommandFinished"); | |||
| 186 | CleanupStack::PopAndDestroy(); | |||
| 187 | CHAT_DP_FUNC_DONE("CVIMPSTCmdProcessSelectedContact::ExecuteLD"); | |||
| 188 | } | |||
| 189 | ||||
| 190 | ||||
| 191 | // -------------------------------------------------------------------------- | |||
| 192 | // CVIMPSTCmdProcessSelectedContact::AddObserver | |||
| 193 | // -------------------------------------------------------------------------- | |||
| 194 | // | |||
| 4 | 4 | 195 | void CVIMPSTCmdProcessSelectedContact::AddObserver( MVIMPSTCmdObserver& aObserver ) | |
| 196 | { | |||
| 197 | // store the observer to notify the command completion | |||
| 198 | iObserver = &aObserver; | |||
| 199 | } | |||
| 200 | ||||
| 201 | ||||
| 202 | // -------------------------------------------------------------------------- | |||
| 203 | // CVIMPSTCmdProcessSelectedContact::CommandId | |||
| 204 | // -------------------------------------------------------------------------- | |||
| 205 | // | |||
| 8 | 0 | 206 | TInt CVIMPSTCmdProcessSelectedContact::CommandId() const | |
| 207 | { | |||
| 8 | 208 | return iCommandId; | ||
| 209 | } | |||
| 210 | ||||
| 211 | // -------------------------------------------------------------------------- | |||
| 212 | // CVIMPSTCmdProcessSelectedContact::Result | |||
| 213 | // -------------------------------------------------------------------------- | |||
| 214 | // | |||
| 4 | 0 | 215 | TInt CVIMPSTCmdProcessSelectedContact::Result() const | |
| 216 | { | |||
| 217 | //return valid data regd the command operation | |||
| 4 | 218 | return iError; | ||
| 219 | } | |||
| 220 | ||||
| 221 | // -------------------------------------------------------------------------- | |||
| 222 | // CVIMPSTCmdProcessSelectedContact::Result | |||
| 223 | // -------------------------------------------------------------------------- | |||
| 224 | // | |||
| 225 | // -------------------------------------------------------------------------- | |||
| 226 | // CVIMPSTCmdProcessSelectedContact::IsContactBlocked | |||
| 227 | // -------------------------------------------------------------------------- | |||
| 12 | 0 | 228 | TBool CVIMPSTCmdProcessSelectedContact::IsContactBlocked(const TDesC& aUserId) | |
| 229 | { | |||
| 230 | MVIMPSTEngineSubService* subService = | |||
| 231 | (iEngine.SubService(TVIMPSTEnums::EPresence)); | |||
| 12 | 0 | - | 232 | if(subService) |
| 233 | { | |||
| 234 | MVIMPSTEnginePresenceSubService& presence = | |||
| 235 | MVIMPSTEnginePresenceSubService::Cast (*subService); | |||
| 236 | ||||
| 237 | RPointerArray<HBufC> *blockedlist = presence .GetBlockedList(); | |||
| 238 | ||||
| 12 | 0 | - | 239 | if(blockedlist) |
| 240 | { | |||
| 12 | 8 | 241 | for(TInt i=0; i<blockedlist->Count(); ++i) | |
| 242 | { | |||
| 4 | 8 | 243 | if(0 == aUserId.CompareC((*blockedlist)[i]->Des())) | |
| 244 | { | |||
| 4 | 245 | return ETrue; | ||
| 246 | } | |||
| 247 | } | |||
| 248 | } | |||
| 249 | } | |||
| 8 | 250 | return EFalse; | ||
| 251 | } | |||
| 252 | // End of File | |||
| ***TER 78% (42/54) of SOURCE FILE cvimpstcmdprocessselectedcontact.cpp | ||||