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 "CLmkIconOperation.h" |
|
27 #include <EPos_CPosLmCategoryManager.h> |
|
28 #include "LmkConsts.h" |
|
29 #include <lmkerrors.h> |
|
30 |
|
31 #if defined(_DEBUG) |
|
32 // CONSTANTS |
|
33 /// Unnamed namespace for local definitions |
|
34 namespace { |
|
35 |
|
36 _LIT( KPanicMsg, "CLmkIconOperation" ); |
|
37 |
|
38 void Panic( TPanicCode aReason ) |
|
39 { |
|
40 User::Panic( KPanicMsg, aReason ); |
|
41 } |
|
42 } // namespace |
|
43 #endif |
|
44 // ============================ MEMBER FUNCTIONS =============================== |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CLmkIconOperation::CLmkIconOperation |
|
48 // C++ constructor can NOT contain any code, that |
|
49 // might leave. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CLmkIconOperation::CLmkIconOperation( |
|
53 CPosLandmarkDatabase& aDb, |
|
54 TLmkItemType aItemsType, |
|
55 TInt aIconIndex ) |
|
56 : iDb( aDb ), |
|
57 iIconIndex( aIconIndex ) |
|
58 { |
|
59 // Set method pointer: |
|
60 if ( aItemsType == ELmkItemTypeLandmark ) |
|
61 { |
|
62 iStepMethodL = &CLmkIconOperation::DoLandmarkStepL; |
|
63 } |
|
64 else |
|
65 { |
|
66 __ASSERT_DEBUG( aItemsType == ELmkItemTypeCategory, |
|
67 Panic( KLmkPanicUnknownItemType ) ); |
|
68 iStepMethodL = &CLmkIconOperation::DoCategoryStepL; |
|
69 } |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CLmkIconOperation::ConstructL |
|
74 // Symbian 2nd phase constructor can leave. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 void CLmkIconOperation::ConstructL( |
|
78 const RArray<TPosLmItemId>& aIdArray, |
|
79 TLmkItemType aItemsType, |
|
80 const TDesC& aMbmFileName ) |
|
81 { |
|
82 TInt count = aIdArray.Count(); |
|
83 for ( TInt i( 0 ); i < count; ++i ) |
|
84 { |
|
85 User::LeaveIfError( iIdArray.Append( aIdArray[i] ) ); |
|
86 } |
|
87 |
|
88 if ( aItemsType == ELmkItemTypeCategory ) |
|
89 { |
|
90 iCategoryMgr = CPosLmCategoryManager::NewL( iDb ); |
|
91 } |
|
92 iMbmFileName = aMbmFileName.AllocL(); |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CLmkIconOperation::NewL |
|
97 // Two-phased constructor. |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 CLmkIconOperation* CLmkIconOperation::NewL( |
|
101 CPosLandmarkDatabase& aDb, |
|
102 const RArray<TPosLmItemId>& aIdArray, |
|
103 TLmkItemType aItemsType, |
|
104 const TDesC& aMbmFileName, |
|
105 TInt aIconIndex ) |
|
106 { |
|
107 CLmkIconOperation* self = new ( ELeave ) CLmkIconOperation( aDb, |
|
108 aItemsType, |
|
109 aIconIndex ); |
|
110 |
|
111 CleanupStack::PushL( self ); |
|
112 self->ConstructL( aIdArray, aItemsType, aMbmFileName ); |
|
113 CleanupStack::Pop(); |
|
114 |
|
115 return self; |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CLmkIconOperation::~CLmkIconOperation |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 CLmkIconOperation::~CLmkIconOperation() |
|
123 { |
|
124 iIdArray.Close(); |
|
125 delete iCategoryMgr; |
|
126 delete iMbmFileName; |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CLmkIconOperation::NextStep |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 void CLmkIconOperation::NextStep( TRequestStatus& aStatus, TReal32& aProgress ) |
|
134 { |
|
135 aStatus = KRequestPending; |
|
136 aProgress = 0; |
|
137 |
|
138 TInt count = iIdArray.Count(); |
|
139 // Index should be smaller than count if NextStep called properly: |
|
140 __ASSERT_DEBUG( iCurrentIndex < count, Panic( KLmkPanicIllegalMethodCall ) ); |
|
141 |
|
142 TInt result( KErrNone ); |
|
143 |
|
144 // Do one step: |
|
145 if ( iCurrentIndex < count ) |
|
146 { |
|
147 TRAP( result, ( this->*iStepMethodL )( iIdArray[iCurrentIndex++] ) ); |
|
148 } |
|
149 |
|
150 // Check result: |
|
151 if ( result != KErrNone || iCurrentIndex == count ) |
|
152 { |
|
153 --iCurrentIndex; |
|
154 aProgress = 1; |
|
155 } |
|
156 else |
|
157 { |
|
158 result = KPosLmOperationNotComplete; |
|
159 // Neither divider nor dividend can be zero in this if-branch: |
|
160 __ASSERT_DEBUG( ( iCurrentIndex > 0 ) && ( count > 0 ), |
|
161 Panic( KLmkPanicMathError ) ); |
|
162 aProgress = static_cast<TReal32>( iCurrentIndex ) / count; |
|
163 } |
|
164 TRequestStatus* status = &aStatus; |
|
165 User::RequestComplete( status, result ); |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CLmkIconOperation::ExecuteL |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 void CLmkIconOperation::ExecuteL() |
|
173 { |
|
174 // We never use asynchronous methods in synchronous way and therefore |
|
175 // don't need to support this method |
|
176 User::Leave( KErrNotSupported ); |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CLmkIconOperation::DoLandmarkStepL |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 void CLmkIconOperation::DoLandmarkStepL( TPosLmItemId aId ) |
|
184 { |
|
185 |
|
186 CPosLandmark* landmark = iDb.ReadLandmarkLC( aId ); |
|
187 landmark->SetIconL( *iMbmFileName, iIconIndex, KLmkDefaultId+1 ); |
|
188 iDb.UpdateLandmarkL( *landmark ); |
|
189 CleanupStack::PopAndDestroy(); // landmark |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CLmkIconOperation::DoCategoryStepL |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 void CLmkIconOperation::DoCategoryStepL( TPosLmItemId aId ) |
|
197 { |
|
198 |
|
199 CPosLandmarkCategory* category = |
|
200 iCategoryMgr->ReadCategoryLC( aId ); |
|
201 category->SetIconL( *iMbmFileName, iIconIndex, KCategoryDefaultId+1); |
|
202 iCategoryMgr->UpdateCategoryL( *category ); |
|
203 CleanupStack::PopAndDestroy(); // category |
|
204 } |
|
205 |
|
206 // End of File |
|