|
1 /* |
|
2 * Copyright (c) 2002 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: LandmarksUi Content File - |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 // INCLUDE FILES |
|
26 #include "CLmkAddToCatOperation.h" |
|
27 #include "CLmkAOOperation.h" |
|
28 #include <EPos_CPosLmCategoryManager.h> |
|
29 #include <EPos_CPosLmOperation.h> |
|
30 #include <lmkerrors.h> |
|
31 |
|
32 #if defined(_DEBUG) |
|
33 // CONSTANTS |
|
34 /// Unnamed namespace for local definitions |
|
35 namespace { |
|
36 |
|
37 _LIT( KPanicMsg, "CLmkAddToCatOperation" ); |
|
38 |
|
39 void Panic( TPanicCode aReason ) |
|
40 { |
|
41 User::Panic( KPanicMsg, aReason ); |
|
42 } |
|
43 } // namespace |
|
44 #endif |
|
45 // ============================ MEMBER FUNCTIONS =============================== |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CLmkAddToCatOperation::CLmkAddToCatOperation |
|
49 // C++ constructor can NOT contain any code, that |
|
50 // might leave. |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CLmkAddToCatOperation::CLmkAddToCatOperation( |
|
54 CPosLmCategoryManager& aCategoryMgr ) |
|
55 : iCategoryMgr( aCategoryMgr ) |
|
56 { |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CLmkAddToCatOperation::ConstructL |
|
61 // Symbian 2nd phase constructor can leave. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 void CLmkAddToCatOperation::ConstructL( |
|
65 const RArray<TPosLmItemId>& aLandmarkIdArray, |
|
66 const RArray<TPosLmItemId>& aCategoryIdArray ) |
|
67 { |
|
68 TInt lmCount = aLandmarkIdArray.Count(); |
|
69 for ( TInt i( 0 ); i < lmCount; ++i ) |
|
70 { |
|
71 User::LeaveIfError( iLmIdArray.Append( aLandmarkIdArray[i] ) ); |
|
72 } |
|
73 TInt catCount = aCategoryIdArray.Count(); |
|
74 for ( TInt k( 0 ); k < catCount; ++k ) |
|
75 { |
|
76 User::LeaveIfError( iCatIdArray.Append( aCategoryIdArray[k] ) ); |
|
77 } |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CLmkAddToCatOperation::NewL |
|
82 // Two-phased constructor. |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 CLmkAddToCatOperation* CLmkAddToCatOperation::NewL( |
|
86 CPosLmCategoryManager& aCategoryMgr, |
|
87 const RArray<TPosLmItemId>& aLandmarkIdArray, |
|
88 const RArray<TPosLmItemId>& aCategoryIdArray ) |
|
89 { |
|
90 CLmkAddToCatOperation* self = |
|
91 new ( ELeave ) CLmkAddToCatOperation( aCategoryMgr ); |
|
92 |
|
93 CleanupStack::PushL( self ); |
|
94 self->ConstructL( aLandmarkIdArray, aCategoryIdArray ); |
|
95 CleanupStack::Pop(); |
|
96 |
|
97 return self; |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CLmkAddToCatOperation::NewL |
|
102 // Two-phased constructor. |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 CLmkAddToCatOperation* CLmkAddToCatOperation::NewL( |
|
106 CPosLmCategoryManager& aCategoryMgr, |
|
107 TPosLmItemId aLandmarkId, |
|
108 const RArray<TPosLmItemId>& aCategoryIdArray ) |
|
109 { |
|
110 CLmkAddToCatOperation* self = |
|
111 new ( ELeave ) CLmkAddToCatOperation( aCategoryMgr ); |
|
112 |
|
113 CleanupStack::PushL( self ); |
|
114 // For users of this class we provide two NewL interfaces but internally |
|
115 // we create an array also in case of just one landmark item. |
|
116 RArray<TPosLmItemId> tmpArray = RArray<TPosLmItemId>( 1 ); |
|
117 CleanupClosePushL( tmpArray ); |
|
118 User::LeaveIfError( tmpArray.Append( aLandmarkId ) ); |
|
119 self->ConstructL( tmpArray, aCategoryIdArray ); |
|
120 CleanupStack::PopAndDestroy(); // tmpArray |
|
121 CleanupStack::Pop(); |
|
122 |
|
123 return self; |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CLmkAddToCatOperation::~CLmkAddToCatOperation |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 CLmkAddToCatOperation::~CLmkAddToCatOperation() |
|
131 { |
|
132 if (iStatus) |
|
133 { |
|
134 if (*iStatus == KRequestPending ) |
|
135 { |
|
136 User::RequestComplete( iStatus, KErrCancel ); |
|
137 } |
|
138 } |
|
139 iLmIdArray.Close(); |
|
140 iCatIdArray.Close(); |
|
141 delete iAddOperation; |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CLmkAddToCatOperation::NextStep |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 void CLmkAddToCatOperation::NextStep( TRequestStatus& aStatus, |
|
149 TReal32& aProgress ) |
|
150 { |
|
151 aStatus = KRequestPending; |
|
152 iStatus = &aStatus; |
|
153 iProgress = &aProgress; |
|
154 |
|
155 TInt count = iCatIdArray.Count(); |
|
156 // Index should be smaller than count if NextStep called properly: |
|
157 __ASSERT_DEBUG( iCurrentIndex < count, Panic( KLmkPanicIllegalMethodCall ) ); |
|
158 |
|
159 TInt err( KErrNone ); |
|
160 |
|
161 // Do one step: |
|
162 if ( iCurrentIndex < count ) |
|
163 { |
|
164 TRAP( err, DoAddToCatStepL( iCatIdArray[iCurrentIndex++] ) ); |
|
165 } |
|
166 |
|
167 if ( err != KErrNone ) |
|
168 { // error occurred already when preparing for asynch. operation |
|
169 --iCurrentIndex; |
|
170 *iProgress = 1; |
|
171 User::RequestComplete( iStatus, err ); |
|
172 } |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CLmkAddToCatOperation::ExecuteL |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 void CLmkAddToCatOperation::ExecuteL() |
|
180 { |
|
181 // We never use asynchronous methods in synchronous way and therefore |
|
182 // don't need to support this method |
|
183 User::Leave( KErrNotSupported ); |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CLmkAddToCatOperation::HandleOperationL |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 void CLmkAddToCatOperation::HandleOperationL( |
|
191 TOperationTypes /*aType*/, |
|
192 TReal32 /*aProgress*/, |
|
193 TInt aStatus ) |
|
194 { |
|
195 // Operation (adding one category to landmarks) finished: |
|
196 delete iAddOperation; |
|
197 iAddOperation = NULL; |
|
198 |
|
199 TInt result( KErrNone ); |
|
200 TInt count = iCatIdArray.Count(); |
|
201 |
|
202 // Check result: |
|
203 if ( aStatus != KErrNone || iCurrentIndex == count ) |
|
204 { |
|
205 *iProgress = 1; |
|
206 result = aStatus; |
|
207 } |
|
208 else |
|
209 { |
|
210 result = KPosLmOperationNotComplete; |
|
211 // Neither divider nor dividend can be zero in this if-branch: |
|
212 __ASSERT_DEBUG( ( iCurrentIndex > 0 ) && ( count > 0 ), |
|
213 Panic( KLmkPanicMathError ) ); |
|
214 *iProgress = static_cast<TReal32>( iCurrentIndex ) / count; |
|
215 } |
|
216 User::RequestComplete( iStatus, result ); |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CLmkAddToCatOperation::DoAddToCatStepL |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void CLmkAddToCatOperation::DoAddToCatStepL( TPosLmItemId aCategoryId ) |
|
224 { |
|
225 CPosLmOperation* operation = |
|
226 iCategoryMgr.AddCategoryToLandmarksL( aCategoryId, |
|
227 iLmIdArray ); |
|
228 |
|
229 __ASSERT_DEBUG( !iAddOperation, Panic( KLmkPanicAlreadyActive ) ); |
|
230 |
|
231 iAddOperation = |
|
232 CLmkAOOperation::NewL( operation, |
|
233 *this, |
|
234 MLmkAOOperationObserver::EAddToCategory, |
|
235 EFalse ); |
|
236 iAddOperation->StartOperation(); |
|
237 } |
|
238 |
|
239 // End of File |