|
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 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: CLandmarkCmdGetCategories class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <epos_cposlmoperation.h> |
|
20 #include <epos_cposlandmarksearch.h> |
|
21 #include "clandmarkcmdgetcategories.h" |
|
22 #include "mlandmarkobserver.h" |
|
23 #include "clandmarkmanagehandlers.h" |
|
24 #include "clandmarkfilter.h" |
|
25 #include "clandmarkmanageobjects.h" |
|
26 |
|
27 // ============================ MEMBER FUNCTIONS =============================== |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CLandmarkCmdGetCategories::NewL( MLandmarkObserver* aObserver, CLandmarkManageObjects* aManageObjects ) |
|
31 // Two-phased constructor. |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CLandmarkCmdGetCategories* CLandmarkCmdGetCategories::NewL( |
|
35 MLandmarkObserver* aObserver, CLandmarkManageObjects* aManageObjects ) |
|
36 { |
|
37 CLandmarkCmdGetCategories* self = CLandmarkCmdGetCategories::NewLC ( |
|
38 aObserver, aManageObjects ); |
|
39 CleanupStack::Pop ( self ); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CLandmarkCmdGetCategories::NewLC( MLandmarkObserver* aObserver, CLandmarkManageObjects* aManageObjects ) |
|
45 // Two-phased constructor. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CLandmarkCmdGetCategories* CLandmarkCmdGetCategories::NewLC( |
|
49 MLandmarkObserver* aObserver, CLandmarkManageObjects* aManageObjects ) |
|
50 { |
|
51 CLandmarkCmdGetCategories* self = new (ELeave) CLandmarkCmdGetCategories(aObserver,aManageObjects); |
|
52 CleanupStack::PushL ( self ); |
|
53 return self; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CLandmarkCmdGetCategories::CLandmarkCmdGetCategories( MLandmarkObserver* aObserver, CLandmarkManageObjects* aManageObjects ) |
|
58 // C++ default constructor can NOT contain any code, that might leave. |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CLandmarkCmdGetCategories::CLandmarkCmdGetCategories( |
|
62 MLandmarkObserver* aObserver, CLandmarkManageObjects* aManageObjects ) |
|
63 { |
|
64 iObserver = aObserver; |
|
65 iManageObjects = aManageObjects; |
|
66 CActiveScheduler::Add ( this ); |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CLandmarkCmdGetCategories::~CLandmarkCmdGetCategories() |
|
71 // Destructor. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 CLandmarkCmdGetCategories::~CLandmarkCmdGetCategories( ) |
|
75 { |
|
76 Cancel ( ); |
|
77 delete iSearchOperation; |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CLandmarkCmdGetCategories::StartL( CLandmarkHandler* aHandle, TInt32 aTransactionId, CLandmarkFilter* aFilter ) |
|
82 // Start asynchronous operation. |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 void CLandmarkCmdGetCategories::StartL( CLandmarkHandler* aHandle, |
|
86 TInt32 aTransactionId, CLandmarkFilter& aFilter ) |
|
87 { |
|
88 iHandle = aHandle; |
|
89 iTransactionId = aTransactionId; |
|
90 CPosLandmarkSearch* search = iHandle->LandmarkSearchHandle ( ); |
|
91 search->SetMaxNumOfMatches (aFilter.MaximumMatches ( ) ); |
|
92 iSearchOperation = search->StartCategorySearchL (aFilter.Criteria ( ), |
|
93 aFilter.CatSortPref ( ), aFilter.PreviousMatches ( ) ); |
|
94 NextStep ( ); |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CLandmarkCmdGetCategories::NextStep() |
|
99 // Execute the next step. |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 void CLandmarkCmdGetCategories::NextStep( ) |
|
103 { |
|
104 iSearchOperation->NextStep (iStatus, iProgress ); |
|
105 SetActive ( ); |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CLandmarkCmdGetCategories::RunL() |
|
110 // Notify Observer on completion of the asynchronous call. |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 void CLandmarkCmdGetCategories::RunL( ) |
|
114 { |
|
115 if ( iStatus == KPosLmOperationNotComplete ) |
|
116 { |
|
117 NextStep ( ); |
|
118 } |
|
119 else |
|
120 { |
|
121 User::LeaveIfError (iStatus.Int ( ) ); |
|
122 CPosLmItemIterator* iterator= NULL; |
|
123 CPosLandmarkDatabase* db = iHandle->LandmarkDatabaseHandle ( ); |
|
124 TPtrC dbUri; |
|
125 iHandle->GetDatabaseUri (dbUri ); |
|
126 CPosLandmarkSearch* search = iHandle->LandmarkSearchHandle ( ); |
|
127 iterator = search->MatchIteratorL ( ); |
|
128 CleanupStack::PushL (iterator ); |
|
129 TRAP_IGNORE(iObserver->HandleCategoryItemsL(iterator,iTransactionId,KErrNone,dbUri)); |
|
130 CleanupStack::Pop (iterator ); |
|
131 //set active garbage collector |
|
132 if ( !iManageObjects->IsActive() ) |
|
133 { |
|
134 iManageObjects->Start ( ); |
|
135 } |
|
136 } |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CLandmarkCmdGetCategories::DoCancel() |
|
141 // Cancel asynchronous call. |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 void CLandmarkCmdGetCategories::DoCancel( ) |
|
145 { |
|
146 if ( iSearchOperation ) |
|
147 { |
|
148 delete iSearchOperation; |
|
149 iSearchOperation = NULL; |
|
150 } |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CLandmarkCmdGetCategories::RunError( TInt aError ) |
|
155 // This functions handles a leave occurring in the request completion event handler. |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 TInt CLandmarkCmdGetCategories::RunError( TInt aError ) |
|
159 { |
|
160 TRAP_IGNORE(iObserver->HandleCategoryItemsL(NULL,iTransactionId,aError,KNullDesC)); |
|
161 if ( !iManageObjects->IsActive() ) |
|
162 { |
|
163 iManageObjects->Start ( ); |
|
164 } |
|
165 return KErrNone; |
|
166 } |
|
167 //end of file |