|
1 /* |
|
2 * Copyright (c) 2002-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 "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: A contact operation for deleting multiple contacts |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CDeleteContactsOperation.h" |
|
22 |
|
23 #include <MVPbkBatchOperationObserver.h> |
|
24 #include "CContactStore.h" |
|
25 #include "CRemoteStore.h" |
|
26 #include "VPbkSimStoreError.h" |
|
27 |
|
28 namespace VPbkSimStore { |
|
29 |
|
30 // CONSTANTS |
|
31 |
|
32 // Contacts are delete one contact at a time |
|
33 const TInt KStepSize = 1; |
|
34 |
|
35 // ============================= LOCAL FUNCTIONS =============================== |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // SendStepFailed |
|
39 // Send step failed event to given observer. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 inline TBool SendStepFailed( CDeleteContactsOperation& aOperation, TInt aError, |
|
43 MVPbkBatchOperationObserver& aObserver ) |
|
44 { |
|
45 return aObserver.StepFailed( aOperation, KStepSize, aError ); |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // SendStepComplete |
|
50 // Send step completed event to given observer. |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 inline void SendStepComplete( CDeleteContactsOperation& aOperation, |
|
54 MVPbkBatchOperationObserver& aObserver ) |
|
55 { |
|
56 aObserver.StepComplete( aOperation, KStepSize ); |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // SendOperationComplete |
|
61 // Send operation completed event to given observer. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 inline void SendOperationComplete( CDeleteContactsOperation& aOperation, |
|
65 MVPbkBatchOperationObserver& aObserver ) |
|
66 { |
|
67 aObserver.OperationComplete( aOperation ); |
|
68 } |
|
69 |
|
70 // ============================ MEMBER FUNCTIONS =============================== |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CDeleteContactsOperation::CDeleteContactsOperation |
|
74 // C++ default constructor can NOT contain any code, that |
|
75 // might leave. |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 CDeleteContactsOperation::CDeleteContactsOperation( CContactStore& aStore, |
|
79 MVPbkBatchOperationObserver& aObserver ) |
|
80 : iStore( aStore ), |
|
81 iObserver( aObserver ) |
|
82 { |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CDeleteContactsOperation::ConstructL |
|
87 // Symbian 2nd phase constructor can leave. |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 void CDeleteContactsOperation::ConstructL( |
|
91 const TArray<TInt>& aSimIndexes ) |
|
92 { |
|
93 const TInt count = aSimIndexes.Count(); |
|
94 for ( TInt i = 0; i < count; ++i ) |
|
95 { |
|
96 iSimIndexes.AppendIntL( aSimIndexes[i] ); |
|
97 } |
|
98 |
|
99 __ASSERT_DEBUG( iSimIndexes.Count() > 0, |
|
100 VPbkSimStore::Panic( VPbkSimStore::EZeroIndexesInDeleteOperation ) ); |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CDeleteContactsOperation::NewL |
|
105 // Two-phased constructor. |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 CDeleteContactsOperation* CDeleteContactsOperation::NewL( |
|
109 CContactStore& aStore, MVPbkBatchOperationObserver& aObserver, |
|
110 const TArray<TInt>& aSimIndexes ) |
|
111 { |
|
112 CDeleteContactsOperation* self = |
|
113 new( ELeave ) CDeleteContactsOperation( aStore, aObserver ); |
|
114 CleanupStack::PushL( self ); |
|
115 self->ConstructL( aSimIndexes ); |
|
116 CleanupStack::Pop( self ); |
|
117 return self; |
|
118 } |
|
119 |
|
120 // Destructor |
|
121 CDeleteContactsOperation::~CDeleteContactsOperation() |
|
122 { |
|
123 Cancel(); |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CDeleteContactsOperation::StartL |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 void CDeleteContactsOperation::StartL() |
|
131 { |
|
132 // Open store because the operation must listen to store events. |
|
133 iStore.OpenL( *this ); |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CDeleteContactsOperation::Cancel |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 void CDeleteContactsOperation::Cancel() |
|
141 { |
|
142 delete iSimOperation; |
|
143 iSimOperation = NULL; |
|
144 iStore.Close( *this ); |
|
145 iSimIndexes.Close(); |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CDeleteContactsOperation::ContactEventComplete |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 void CDeleteContactsOperation::ContactEventComplete( TEvent /*aEvent*/, |
|
153 CVPbkSimContact* /*aContact*/ ) |
|
154 { |
|
155 // All the contacts have been deleted. Complete operation. |
|
156 SendOperationComplete( *this, iObserver ); |
|
157 } |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // CDeleteContactsOperation::ContactEventError |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 void CDeleteContactsOperation::ContactEventError( TEvent /*aEvent*/, |
|
164 CVPbkSimContact* /*aContact*/, TInt aError ) |
|
165 { |
|
166 // An error happened, the operatio can not continue. |
|
167 CompleteWithError( aError ); |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CDeleteContactsOperation::ContactEventError |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 void CDeleteContactsOperation::StoreReady(MVPbkContactStore& /*aContactStore*/) |
|
175 { |
|
176 TRAPD( res, iSimOperation = iStore.NativeStore().DeleteL( |
|
177 iSimIndexes, *this ) ); |
|
178 if ( res != KErrNone ) |
|
179 { |
|
180 CompleteWithError( res ); |
|
181 } |
|
182 } |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CDeleteContactsOperation::ContactEventError |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 void CDeleteContactsOperation::StoreUnavailable( |
|
189 MVPbkContactStore& /*aContactStore*/, |
|
190 TInt aReason) |
|
191 { |
|
192 CompleteWithError( aReason ); |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CDeleteContactsOperation::ContactEventError |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 void CDeleteContactsOperation::HandleStoreEventL( |
|
200 MVPbkContactStore& /*aContactStore*/, |
|
201 TVPbkContactStoreEvent aStoreEvent) |
|
202 { |
|
203 if ( aStoreEvent.iEventType == TVPbkContactStoreEvent::EContactDeleted ) |
|
204 { |
|
205 SendStepComplete( *this, iObserver ); |
|
206 } |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CDeleteContactsOperation::CompleteWithError |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 void CDeleteContactsOperation::CompleteWithError( TInt aError ) |
|
214 { |
|
215 // Delete the async operation so that it doesn't send events after error |
|
216 delete iSimOperation; |
|
217 iSimOperation = NULL; |
|
218 // Close store so that the operation doesn't get store events after error. |
|
219 iStore.Close( *this ); |
|
220 // Send error code to client. |
|
221 if ( SendStepFailed( *this, aError, iObserver ) ) |
|
222 { |
|
223 // If client does continue call OperationComplete() for it. |
|
224 SendOperationComplete( *this, iObserver ); |
|
225 } |
|
226 } |
|
227 } // namespace VPbkSimStore |
|
228 // End of File |