|
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: The virtual phonebook commit contacts operation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CCommitContactsOperation.h" |
|
20 #include "CContactStore.h" |
|
21 #include "CContact.h" |
|
22 |
|
23 |
|
24 #include <MVPbkBatchOperationObserver.h> |
|
25 |
|
26 #include <cntdef.h> |
|
27 #include <cntdb.h> |
|
28 |
|
29 namespace VPbkCntModel { |
|
30 |
|
31 const TInt KStepSize = 1; |
|
32 |
|
33 |
|
34 CCommitContactsOperation::CCommitContactsOperation( |
|
35 CContactStore& aContactStore, |
|
36 MVPbkBatchOperationObserver& aObserver ) : |
|
37 CActive( CActive::EPriorityIdle ), |
|
38 iContactStore( aContactStore ), |
|
39 iObserver( aObserver ), |
|
40 iState( ECommit ) |
|
41 { |
|
42 CActiveScheduler::Add( this ); |
|
43 } |
|
44 |
|
45 inline void CCommitContactsOperation::ConstructL( const TArray<CContact*>& |
|
46 aContacts ) |
|
47 { |
|
48 const TInt count = aContacts.Count(); |
|
49 for ( TInt i = 0; i < count; ++i ) |
|
50 { |
|
51 iContacts.Append( aContacts[i] ); |
|
52 } |
|
53 } |
|
54 |
|
55 CCommitContactsOperation* CCommitContactsOperation::NewL( |
|
56 CContactStore& aContactStore, |
|
57 const TArray<CContact*> aContacts, |
|
58 MVPbkBatchOperationObserver& aObserver ) |
|
59 { |
|
60 CCommitContactsOperation* self = new ( ELeave ) CCommitContactsOperation |
|
61 ( aContactStore, aObserver ); |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL( aContacts ); |
|
64 CleanupStack::Pop( self ); |
|
65 return self; |
|
66 } |
|
67 |
|
68 CCommitContactsOperation::~CCommitContactsOperation() |
|
69 { |
|
70 Cancel(); |
|
71 iContacts.Reset(); |
|
72 } |
|
73 |
|
74 void CCommitContactsOperation::RunL() |
|
75 { |
|
76 NextStepL(); |
|
77 } |
|
78 |
|
79 TInt CCommitContactsOperation::RunError( TInt aError ) |
|
80 { |
|
81 if ( iObserver.StepFailed( *this, KStepSize, aError ) ) |
|
82 { |
|
83 IssueRequest(); |
|
84 } |
|
85 return KErrNone; |
|
86 } |
|
87 |
|
88 void CCommitContactsOperation::DoCancel() |
|
89 { |
|
90 // Do nothing |
|
91 } |
|
92 |
|
93 void CCommitContactsOperation::NextStepL() |
|
94 { |
|
95 if (iContacts.Count() > 0) |
|
96 { |
|
97 CContact* contact = iContacts[0]; |
|
98 iContacts.Remove( 0 ); |
|
99 contact->CommitL( *this ); |
|
100 } |
|
101 else |
|
102 { |
|
103 iObserver.OperationComplete( *this ); |
|
104 } |
|
105 } |
|
106 |
|
107 void CCommitContactsOperation::IssueRequest() |
|
108 { |
|
109 if ( !IsActive() ) |
|
110 { |
|
111 TRequestStatus* status = &iStatus; |
|
112 User::RequestComplete( status, KErrNone ); |
|
113 SetActive(); |
|
114 } |
|
115 } |
|
116 |
|
117 void CCommitContactsOperation::StartL() |
|
118 { |
|
119 IssueRequest(); |
|
120 } |
|
121 |
|
122 void CCommitContactsOperation::Cancel() |
|
123 { |
|
124 CActive::Cancel(); |
|
125 } |
|
126 |
|
127 void CCommitContactsOperation::ContactOperationCompleted |
|
128 ( TContactOpResult /* aResult */ ) |
|
129 { |
|
130 iObserver.StepComplete( *this, KStepSize ); |
|
131 IssueRequest(); |
|
132 } |
|
133 |
|
134 void CCommitContactsOperation::ContactOperationFailed |
|
135 ( TContactOp /* aOpCode */, |
|
136 TInt aErrorCode, |
|
137 TBool /* aErrorNotified */ ) |
|
138 { |
|
139 if ( iObserver.StepFailed( *this, KStepSize, aErrorCode ) ) |
|
140 { |
|
141 // Continue only if ETrue is returned. Otherwise this operation might |
|
142 // be already deleted. |
|
143 IssueRequest(); |
|
144 } |
|
145 } |
|
146 |
|
147 } // namespace VPbkCntModel |
|
148 //End of file |