|
1 /* |
|
2 * Copyright (c) 2005-2006 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: CLandmarkCmdGetLandmarks class |
|
15 * |
|
16 */ |
|
17 #include <EPos_CPosLmOperation.h> |
|
18 #include <EPos_CPosLandmarkSearch.h> |
|
19 #include <EPos_CPosLandmarkDatabase.h> |
|
20 #include <EPos_CPosLandmarkEncoder.h> |
|
21 #include <EPos_CPosLandmarkParser.h> |
|
22 #include <f32file.h> |
|
23 #include "clandmarkoperation.h" |
|
24 #include "mlandmarkobserver.h" |
|
25 #include "clandmarkmanagehandlers.h" |
|
26 #include "clandmarkmanageobjects.h" |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CLandmarkOperation::NewL( MLandmarkObserver* aObserver, CLandmarkManageObjects* aManageObjects ) |
|
32 // Two-phased constructor. |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CLandmarkOperation* CLandmarkOperation::NewL( |
|
36 MLandmarkObserver* aObserver, CLandmarkManageObjects* aManageObjects) |
|
37 { |
|
38 CLandmarkOperation* self = |
|
39 CLandmarkOperation::NewLC(aObserver, aManageObjects); |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CLandmarkOperation::NewLC( MLandmarkObserver* aObserver, CLandmarkManageObjects* aManageObjects ) |
|
46 // Two-phased constructor. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 CLandmarkOperation* CLandmarkOperation::NewLC( |
|
50 MLandmarkObserver* aObserver, CLandmarkManageObjects* aManageObjects) |
|
51 { |
|
52 CLandmarkOperation* self = |
|
53 new (ELeave) CLandmarkOperation(aObserver, |
|
54 aManageObjects); |
|
55 CleanupStack::PushL(self); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CLandmarkOperation::CLandmarkOperation( MLandmarkObserver* aObserver, CLandmarkManageObjects* aManageObjects ) |
|
61 // C++ default constructor can NOT contain any code, that might leave. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CLandmarkOperation::CLandmarkOperation( |
|
65 MLandmarkObserver* aObserver, CLandmarkManageObjects* aManageObjects) : |
|
66 CActive(EPriorityNormal), iObserver(aObserver), iManageObjects( |
|
67 aManageObjects) |
|
68 { |
|
69 CActiveScheduler::Add(this); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CLandmarkOperation::~CLandmarkOperation() |
|
74 // Destructor. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CLandmarkOperation::~CLandmarkOperation() |
|
78 { |
|
79 Cancel(); |
|
80 delete iOperation; |
|
81 delete iExportBuffer; |
|
82 delete iEncoder; |
|
83 delete iParser; |
|
84 delete iDestinationFile; |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CLandmarkOperation::StartL( CLandmarkHandler* aHandle, TInt32 aTransactionId, CLandmarkFilter* aFilter ) |
|
89 // Start asynchronous operation. |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 void CLandmarkOperation::LinkL(TInt32 aTransactionId, |
|
93 TPosLmItemId aCategoryId, RArray<TPosLmItemId>& aLandmarkIdArray, |
|
94 CPosLmCategoryManager* aCategoryManager) |
|
95 { |
|
96 iOperationType = EOrganise; |
|
97 iTransactionId = aTransactionId; |
|
98 iOperation = aCategoryManager->AddCategoryToLandmarksL(aCategoryId, |
|
99 aLandmarkIdArray); |
|
100 NextStep(); |
|
101 } |
|
102 |
|
103 void CLandmarkOperation::UnLinkL(TInt32 aTransactionId, |
|
104 TPosLmItemId aCategoryId, RArray<TPosLmItemId>& aLandmarkIdArray, |
|
105 CPosLmCategoryManager* aCategoryManager) |
|
106 { |
|
107 iOperationType = EOrganise; |
|
108 iTransactionId = aTransactionId; |
|
109 iOperation = aCategoryManager->RemoveCategoryFromLandmarksL( |
|
110 aCategoryId, aLandmarkIdArray); |
|
111 NextStep(); |
|
112 } |
|
113 |
|
114 void CLandmarkOperation::ImportL(TInt32 aTransactionId, CLandmarkHandler* aHandle, |
|
115 CPosLandmarkParser& aLandmarkParser) |
|
116 { |
|
117 iHandle = aHandle; |
|
118 iOperationType = EImport; |
|
119 iTransactionId = aTransactionId; |
|
120 iParser = &aLandmarkParser; |
|
121 CPosLandmarkDatabase* db = iHandle->LandmarkDatabaseHandle(); |
|
122 iOperation = db->ImportLandmarksL(aLandmarkParser, |
|
123 CPosLandmarkDatabase::EDefaultOptions); |
|
124 NextStep(); |
|
125 } |
|
126 |
|
127 void CLandmarkOperation::ExportL(TInt32 aTransactionId, CPosLandmarkDatabase* aDatabase, |
|
128 CPosLandmarkEncoder& aLandmarkEncoder, |
|
129 const RArray<TPosLmItemId>& aLandmarkIdArray, |
|
130 const TDesC& aDestinationFile) |
|
131 { |
|
132 iOperationType = EExport; |
|
133 iTransactionId = aTransactionId; |
|
134 iEncoder = &aLandmarkEncoder; |
|
135 iDestinationFile= aDestinationFile.AllocL(); |
|
136 iExportBuffer = iEncoder->SetUseOutputBufferL(); |
|
137 iOperation = aDatabase->ExportLandmarksL(aLandmarkEncoder,aLandmarkIdArray, |
|
138 CPosLandmarkDatabase::EIncludeCategories); |
|
139 NextStep(); |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CLandmarkOperation::NextStep() |
|
144 // Execute the next step. |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 void CLandmarkOperation::NextStep() |
|
148 { |
|
149 iOperation->NextStep(iStatus, iProgress); |
|
150 SetActive(); |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CLandmarkOperation::RunL() |
|
155 // Notify Observer on completion of the asynchronous call. |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 void CLandmarkOperation::RunL() |
|
159 { |
|
160 if (iStatus == KPosLmOperationNotComplete) |
|
161 { |
|
162 NextStep(); |
|
163 } |
|
164 else |
|
165 { |
|
166 if( iOperationType == EImport) |
|
167 { |
|
168 CPosLmItemIterator* iterator= NULL; |
|
169 CPosLandmarkDatabase* db = iHandle->LandmarkDatabaseHandle ( ); |
|
170 iterator = db->ImportedLandmarksIteratorL(iOperation); |
|
171 CleanupStack::PushL (iterator ); |
|
172 TRAP_IGNORE(iObserver->HandleLandmarkItemsL(iterator,iTransactionId,KErrNone,iHandle)); |
|
173 CleanupStack::Pop (iterator ); |
|
174 } |
|
175 else if( iOperationType == EExport) |
|
176 { |
|
177 ExecuteAndDeleteLD (iEncoder->FinalizeEncodingL ( ) ); |
|
178 //Write to file |
|
179 RFs fs; |
|
180 User::LeaveIfError(fs.Connect()); |
|
181 CleanupClosePushL(fs); |
|
182 RFile file; |
|
183 CleanupClosePushL(file); |
|
184 User::LeaveIfError(file.Create(fs, *iDestinationFile, |
|
185 EFileShareExclusive | EFileStreamText | EFileWrite)); |
|
186 TInt size = iExportBuffer->Size(); |
|
187 for( TInt i = 0; i < size; ++i ) |
|
188 { |
|
189 file.Write(i,iExportBuffer->Ptr(i)); |
|
190 } |
|
191 CleanupStack::PopAndDestroy(&file); |
|
192 CleanupStack::PopAndDestroy(&fs); |
|
193 TRAP_IGNORE(iObserver->HandleItemsL(iTransactionId,iStatus.Int ( ))); |
|
194 } |
|
195 else |
|
196 { |
|
197 TRAP_IGNORE(iObserver->HandleItemsL(iTransactionId,iStatus.Int ( ))); |
|
198 } |
|
199 //set active garbage collector |
|
200 if (!iManageObjects->IsActive()) |
|
201 { |
|
202 iManageObjects->Start(); |
|
203 } |
|
204 } |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CLandmarkOperation::DoCancel() |
|
209 // Cancel asynchronous call. |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 void CLandmarkOperation::DoCancel() |
|
213 { |
|
214 if (iOperation) |
|
215 { |
|
216 delete iOperation; |
|
217 iOperation = NULL; |
|
218 } |
|
219 } |
|
220 |
|
221 TInt CLandmarkOperation::RunError( TInt aError ) |
|
222 { |
|
223 if( iOperationType == EImport) |
|
224 { |
|
225 TRAP_IGNORE(iObserver->HandleLandmarkItemsL(NULL,iTransactionId,aError,NULL)); |
|
226 } |
|
227 else |
|
228 { |
|
229 TRAP_IGNORE(iObserver->HandleItemsL(iTransactionId,aError)); |
|
230 } |
|
231 if ( !iManageObjects->IsActive() ) |
|
232 { |
|
233 iManageObjects->Start ( ); |
|
234 } |
|
235 return KErrNone; |
|
236 } |
|
237 //end of file |
|
238 |
|
239 |