5
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 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 the License "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: Implementation of the delete contact observer functionality.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
//User Includes
|
|
20 |
#include "deletecontactobserver.h"
|
|
21 |
#include "contactcallback.h"
|
|
22 |
|
|
23 |
//System Includes
|
|
24 |
#include <cvpbkcontactmanager.h>// for iContactManager
|
|
25 |
#include <mvpbkcontactstore.h>// for iContactStore
|
|
26 |
#include <mvpbkstorecontact.h>// used in many function to get the store contact
|
|
27 |
#include <mvpbkcontactoperationbase.h>//for observer
|
|
28 |
#include <mvpbkcontactlink.h>//for param in ContactsSaved()
|
|
29 |
#include <mvpbkcontactstoreproperties.h>//for getting store uri in StoreReady()
|
|
30 |
|
|
31 |
//-------------------------------------------------------------------------------------
|
|
32 |
// Static method to create instance of delete contact observer.
|
|
33 |
//-------------------------------------------------------------------------------------
|
|
34 |
|
|
35 |
CDeleteContactObserver* CDeleteContactObserver::NewL( CContactService* aContactService,
|
|
36 |
MVPbkContactStore* aContactStore,
|
|
37 |
RPointerArray<TDesC8>& aContactIdArray,
|
|
38 |
TInt aTransId,
|
|
39 |
MContactCallback* aCallback )
|
|
40 |
{
|
|
41 |
|
|
42 |
CDeleteContactObserver* self = new( ELeave ) CDeleteContactObserver( );
|
|
43 |
CleanupStack::PushL(self);
|
|
44 |
self->ConstructL(aContactService, aContactStore,
|
|
45 |
aContactIdArray, aTransId, aCallback );
|
|
46 |
CleanupStack::Pop(self);
|
|
47 |
return self;
|
|
48 |
}
|
|
49 |
|
|
50 |
|
|
51 |
//Constructor
|
|
52 |
|
|
53 |
CDeleteContactObserver::CDeleteContactObserver()
|
|
54 |
{
|
|
55 |
|
|
56 |
}
|
|
57 |
|
|
58 |
//second-phase constructor
|
|
59 |
void CDeleteContactObserver::ConstructL( CContactService* aContactService,
|
|
60 |
MVPbkContactStore* aContactStore,
|
|
61 |
RPointerArray<TDesC8>& aContactIdArray,
|
|
62 |
TInt aTransId,
|
|
63 |
MContactCallback* aCallback )
|
|
64 |
{
|
|
65 |
iContactService= aContactService;
|
|
66 |
iContactStore = aContactStore;
|
|
67 |
iTransId = aTransId;
|
|
68 |
iCallback = aCallback;
|
|
69 |
|
|
70 |
iContactLinkArray = CVPbkContactLinkArray::NewL();
|
|
71 |
|
|
72 |
ConvertContactIdsToLinkArrayL( aContactIdArray );
|
|
73 |
iOp = NULL;
|
|
74 |
|
|
75 |
}
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
//Destructor.
|
|
80 |
|
|
81 |
CDeleteContactObserver::~CDeleteContactObserver()
|
|
82 |
{
|
|
83 |
TInt count = iLinkArrayToDelete.Count();
|
|
84 |
if( count )
|
|
85 |
{
|
|
86 |
for(TInt index = 0; index < count; index++)
|
|
87 |
{
|
|
88 |
delete iLinkArrayToDelete[index];
|
|
89 |
}
|
|
90 |
}
|
|
91 |
iLinkArrayToDelete.Reset();
|
|
92 |
if(iContactLinkArray)
|
|
93 |
{
|
|
94 |
iContactLinkArray->Reset();
|
|
95 |
delete iContactLinkArray;
|
|
96 |
iContactLinkArray = NULL;
|
|
97 |
}
|
|
98 |
if( iContactStore )
|
|
99 |
{
|
|
100 |
iContactStore->Close(*this);
|
|
101 |
}
|
|
102 |
if(iOp)
|
|
103 |
{
|
|
104 |
delete iOp;
|
|
105 |
}
|
|
106 |
}
|
|
107 |
|
|
108 |
/*
|
|
109 |
-------------------------------------------------------------------------------------
|
|
110 |
CDeleteContactObserver::Cancel()
|
|
111 |
Description : Cancel implementation relevant to DeleteObserver
|
|
112 |
Return values : KErrorNone on Success and KErrGeneral on Failure
|
|
113 |
-------------------------------------------------------------------------------------
|
|
114 |
*/
|
|
115 |
|
|
116 |
void CDeleteContactObserver::Cancel()
|
|
117 |
{
|
|
118 |
iCallback->HandleReturnValue(EOpCancel, KErrNone, iTransId);
|
|
119 |
delete this;
|
|
120 |
}
|
|
121 |
|
|
122 |
//Get MVPbkContactLinkArray from the dynamic array, which is having contact ids.
|
|
123 |
|
|
124 |
void CDeleteContactObserver::ConvertContactIdsToLinkArrayL( RPointerArray<TDesC8>& aContactIdArray )
|
|
125 |
{
|
|
126 |
|
|
127 |
TInt contactIdCount = aContactIdArray.Count();
|
|
128 |
if((contactIdCount) && !(*aContactIdArray[0]).Compare(KNullDesC8))
|
|
129 |
{
|
|
130 |
User::Leave(KErrArgument);
|
|
131 |
}
|
|
132 |
|
|
133 |
for(TInt index = 0; index < contactIdCount; index++)
|
|
134 |
{
|
|
135 |
//get the id from the contact id array
|
|
136 |
TPtrC8 contactId = *aContactIdArray[index];
|
|
137 |
|
|
138 |
//construct link using contact mngr's CreateLinksLC
|
|
139 |
MVPbkContactLinkArray* tmpLinkArray = (&(iContactService->GetContactManager()))->CreateLinksLC(contactId);
|
|
140 |
|
|
141 |
iLinkArrayToDelete.AppendL(tmpLinkArray);
|
|
142 |
|
|
143 |
iContactLinkArray->AppendL(const_cast<MVPbkContactLink*> (&(tmpLinkArray->At(0))) );
|
|
144 |
|
|
145 |
CleanupStack::Pop(); //tmpLinkArray
|
|
146 |
}
|
|
147 |
|
|
148 |
}
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
//Deletes the list of contacts from the contact store.
|
|
153 |
void CDeleteContactObserver::DoDeleteL()
|
|
154 |
{
|
|
155 |
CVPbkContactManager* contactManager = &(iContactService->GetContactManager());
|
|
156 |
MVPbkContactOperationBase* iOp = contactManager ->DeleteContactsL( *iContactLinkArray, *this );
|
|
157 |
}
|
|
158 |
|
|
159 |
|
|
160 |
void CDeleteContactObserver::StepComplete( MVPbkContactOperationBase& /*aOperation*/,
|
|
161 |
TInt /*aStepSize*/ )
|
|
162 |
{
|
|
163 |
//Ignore this...as it enters OperationComplete once it is done
|
|
164 |
}
|
|
165 |
|
|
166 |
//deletion failed
|
|
167 |
TBool CDeleteContactObserver::StepFailed( MVPbkContactOperationBase& aOperation,
|
|
168 |
TInt /*aStepSize*/ , TInt aError )
|
|
169 |
{
|
|
170 |
delete &aOperation;
|
|
171 |
//&aOperation = NULL;
|
|
172 |
iContactService->RequestComplete(iTransId);
|
|
173 |
iCallback->HandleReturnValue(EOpError, aError, iTransId);
|
|
174 |
|
|
175 |
delete this;
|
|
176 |
|
|
177 |
return EFalse;
|
|
178 |
}
|
|
179 |
|
|
180 |
//successfully deleted.
|
|
181 |
void CDeleteContactObserver::OperationComplete( MVPbkContactOperationBase& aOperation )
|
|
182 |
{
|
|
183 |
delete &aOperation;
|
|
184 |
//&aOperation = NULL;
|
|
185 |
iContactService->RequestComplete(iTransId);
|
|
186 |
iCallback->HandleReturnValue(EOpComplete, KErrNone, iTransId);
|
|
187 |
delete this;
|
|
188 |
}
|
|
189 |
|
|
190 |
|
|
191 |
//Enters this method when OpenL() is successfull.
|
|
192 |
void CDeleteContactObserver::StoreReady( MVPbkContactStore& aContactStore )
|
|
193 |
{
|
|
194 |
iContactStore = &aContactStore;
|
|
195 |
|
|
196 |
if(!iContactLinkArray)
|
|
197 |
{
|
|
198 |
iContactService->RequestComplete(iTransId);
|
|
199 |
iCallback->HandleReturnValue(EOpComplete, KErrNotFound, iTransId );
|
|
200 |
delete this;
|
|
201 |
}
|
|
202 |
|
|
203 |
TRAPD(error, DoDeleteL());
|
|
204 |
|
|
205 |
if(error != KErrNone)
|
|
206 |
{
|
|
207 |
iContactService->RequestComplete(iTransId);
|
|
208 |
iCallback->HandleReturnValue(EOpComplete, error, iTransId);
|
|
209 |
delete this;
|
|
210 |
}
|
|
211 |
|
|
212 |
}
|
|
213 |
|
|
214 |
//Store open failed
|
|
215 |
void CDeleteContactObserver::StoreUnavailable( MVPbkContactStore& /*aContactStore*/, TInt aReason )
|
|
216 |
{
|
|
217 |
iContactService->RequestComplete(iTransId);
|
|
218 |
iCallback->HandleReturnValue(EOpError, aReason, iTransId);
|
|
219 |
delete this;
|
|
220 |
}
|
|
221 |
|
|
222 |
void CDeleteContactObserver::HandleStoreEventL( MVPbkContactStore& /*aContactStore*/, TVPbkContactStoreEvent /*aStoreEvent*/ )
|
|
223 |
{
|
|
224 |
//do nothing here
|
|
225 |
}
|
|
226 |
|