author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 22:59:08 +0300 | |
branch | RCL_3 |
changeset 46 | 5146369cfdc9 |
parent 26 | 5d0ec8b709be |
permissions | -rw-r--r-- |
5 | 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: CLandmarkManageHandlers class implementation |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
23
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
19 |
#include <EPos_CPosLandmarkDatabase.h> |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
20 |
#include <EPos_CPosLmCategoryManager.h> |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
21 |
#include <EPos_CPosLandmarkSearch.h> |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
22 |
#include <EPos_TPosLmDatabaseSettings.h> |
5 | 23 |
#include "clandmarkmanagehandlers.h" |
24 |
||
25 |
//class CLandmarkManageHandlers |
|
26 |
// ============================ MEMBER FUNCTIONS =============================== |
|
27 |
||
28 |
// ----------------------------------------------------------------------------- |
|
29 |
// CLandmarkManageHandlers::NewL() |
|
30 |
// Two-phased constructor. |
|
31 |
// ----------------------------------------------------------------------------- |
|
32 |
// |
|
33 |
CLandmarkManageHandlers* CLandmarkManageHandlers::NewL( ) |
|
34 |
{ |
|
35 |
CLandmarkManageHandlers* self = new (ELeave) CLandmarkManageHandlers(); |
|
36 |
return self; |
|
37 |
} |
|
38 |
||
39 |
// ----------------------------------------------------------------------------- |
|
40 |
// CLandmarkManageHandlers::CLandmarkManageHandlers() |
|
41 |
// C++ default constructor can NOT contain any code, that might leave. |
|
42 |
// ----------------------------------------------------------------------------- |
|
43 |
// |
|
44 |
CLandmarkManageHandlers::CLandmarkManageHandlers( ) |
|
45 |
{ |
|
46 |
} |
|
47 |
||
48 |
// ----------------------------------------------------------------------------- |
|
49 |
// CLandmarkManageHandlers::~CLandmarkManageHandlers() |
|
50 |
// Destructor. |
|
51 |
// ----------------------------------------------------------------------------- |
|
52 |
// |
|
53 |
CLandmarkManageHandlers::~CLandmarkManageHandlers( ) |
|
54 |
{ |
|
26
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
55 |
TInt count = iHandlers.Count(); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
56 |
for (TInt i = 0; i < count; i++) |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
57 |
{ |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
58 |
if (!iHandlers[i]->DecRef()) |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
59 |
{ |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
60 |
delete iHandlers[i]; |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
61 |
} |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
62 |
} |
5 | 63 |
iHandlers.Close(); |
64 |
} |
|
65 |
||
66 |
// ----------------------------------------------------------------------------- |
|
67 |
// CLandmarkManageHandlers::CloseHandler( CLandmarkHandler* aHandler ) |
|
68 |
// Closes the passed CLandmarkHandler handle and removes it from the array. |
|
69 |
// ----------------------------------------------------------------------------- |
|
70 |
// |
|
71 |
void CLandmarkManageHandlers::CloseHandler( CLandmarkHandler* aHandler ) |
|
72 |
{ |
|
73 |
TInt index = iHandlers.Find (aHandler ); |
|
74 |
if ( index != KErrNotFound ) |
|
75 |
{ |
|
26
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
76 |
if (!iHandlers[index]->DecRef()) |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
77 |
{ |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
78 |
delete iHandlers[index]; |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
79 |
} |
5 | 80 |
iHandlers[index] = NULL; |
81 |
iHandlers.Remove (index ); |
|
82 |
} |
|
83 |
} |
|
84 |
// ----------------------------------------------------------------------------- |
|
85 |
// CLandmarkManageHandlers::CreateHandlerL(TDesC & aDatabaseUri) |
|
86 |
// Creates and Returns the handle of CLandmarkHandler instance. |
|
87 |
// ----------------------------------------------------------------------------- |
|
88 |
// |
|
89 |
CLandmarkHandler* CLandmarkManageHandlers::CreateHandlerL( |
|
90 |
const TDesC& aDatabaseUri ) |
|
91 |
{ |
|
92 |
//create a database handle and append to the array. |
|
93 |
CLandmarkHandler* handler = CLandmarkHandler::CreateL (aDatabaseUri ); |
|
94 |
CleanupStack::PushL (handler ); |
|
95 |
iHandlers.AppendL (handler ); |
|
96 |
CleanupStack::Pop (handler ); |
|
97 |
//if there is no default handler then set default as device default |
|
98 |
if( !iDefaultHandler && aDatabaseUri == KNullDesC ) |
|
99 |
{ |
|
100 |
iDefaultHandler = handler; |
|
101 |
} |
|
102 |
return handler; |
|
103 |
} |
|
104 |
||
105 |
// ----------------------------------------------------------------------------- |
|
106 |
// CLandmarkManageHandlers::GetHandlerL(TDesC & aDatabaseUri) |
|
107 |
// Returns the handle of CLandmarkHandler instance. |
|
108 |
// ----------------------------------------------------------------------------- |
|
109 |
// |
|
110 |
CLandmarkHandler* CLandmarkManageHandlers::GetHandlerL(const TDesC& aDatabaseUri ) |
|
111 |
{ |
|
112 |
_LIT(KDriveSeparatorSymbol, ":"); |
|
113 |
_LIT(KDefaultDriveLocal, "c"); |
|
114 |
_LIT(KProtocolSeparatorLocal, "://"); |
|
115 |
_LIT(KLocalProtocolString, "file"); |
|
116 |
||
117 |
CLandmarkHandler* handler= NULL; |
|
118 |
//if aDatabaseUri is KNullDesC then return the default handler |
|
119 |
if ( aDatabaseUri == KNullDesC ) |
|
120 |
{ |
|
121 |
if ( iDefaultHandler ) |
|
122 |
{ |
|
123 |
iDefaultHandler->InitL ( ); |
|
124 |
} |
|
125 |
handler = iDefaultHandler; |
|
126 |
} |
|
127 |
//else compare the passed URI with the stored handle's URI |
|
128 |
else |
|
129 |
{ |
|
130 |
//Simple parsing. Have to implement better parsing |
|
131 |
TBuf<KPosLmDatabaseName> dbName; |
|
132 |
TInt offset = aDatabaseUri.Find (KProtocolSeparatorLocal ); |
|
133 |
if ( KErrNotFound == offset ) |
|
134 |
{ |
|
135 |
dbName.Copy (KLocalProtocolString ); |
|
136 |
dbName.Append (KProtocolSeparatorLocal ); |
|
137 |
} |
|
138 |
if ( aDatabaseUri.Find (KDriveSeparatorSymbol )<= offset ) |
|
139 |
{ |
|
140 |
dbName.Append (KDefaultDriveLocal ); |
|
141 |
dbName.Append (KDriveSeparatorSymbol ); |
|
142 |
} |
|
143 |
//Check for Length < KPosLmDatabaseName |
|
144 |
if ( (aDatabaseUri.Length() + dbName.Length()) > KPosLmDatabaseName ) |
|
145 |
{ |
|
146 |
User::Leave ( KErrBadName ); |
|
147 |
} |
|
148 |
//create the complete db uri |
|
149 |
dbName.Append (aDatabaseUri ); |
|
150 |
//normalize to lower |
|
151 |
dbName.LowerCase ( ); |
|
152 |
TInt count = iHandlers.Count ( ); |
|
153 |
TPtrC dbUri; |
|
154 |
while ( count ) |
|
155 |
{ |
|
156 |
//Retrieve the handles from end |
|
157 |
handler = iHandlers[--count]; |
|
158 |
handler->GetDatabaseUri (dbUri ); |
|
159 |
if ( dbUri == dbName ) |
|
160 |
{ |
|
161 |
handler->InitL ( ); |
|
162 |
break; |
|
163 |
} |
|
164 |
//if no handle found then NULL |
|
165 |
handler = NULL; |
|
166 |
} |
|
167 |
} |
|
168 |
return handler; |
|
169 |
} |
|
170 |
||
171 |
// ----------------------------------------------------------------------------- |
|
172 |
// CLandmarkManageHandlers::SetDefaultHandler(CLandmarkHandler* aHandler) |
|
173 |
// Sets the default handler. |
|
174 |
// ----------------------------------------------------------------------------- |
|
175 |
// |
|
176 |
void CLandmarkManageHandlers::SetDefaultHandler( CLandmarkHandler* aHandler ) |
|
177 |
{ |
|
178 |
iDefaultHandler = aHandler; |
|
179 |
} |
|
180 |
||
181 |
//Class CLandmarkHandler |
|
182 |
// ============================ MEMBER FUNCTIONS =============================== |
|
183 |
||
184 |
// ----------------------------------------------------------------------------- |
|
185 |
// CLandmarkHandler::CreateL( TDesC & aDatabaseUri ) |
|
186 |
// Two-phased constructor. |
|
187 |
// ----------------------------------------------------------------------------- |
|
188 |
// |
|
189 |
CLandmarkHandler* CLandmarkHandler::CreateL( const TDesC& aDatabaseUri ) |
|
190 |
{ |
|
191 |
CLandmarkHandler* self = new (ELeave) CLandmarkHandler(); |
|
192 |
CleanupStack::PushL ( self ); |
|
193 |
self->ConstructL (aDatabaseUri ); |
|
194 |
CleanupStack::Pop ( self ); |
|
195 |
return self; |
|
196 |
} |
|
197 |
||
198 |
// ----------------------------------------------------------------------------- |
|
199 |
// CLandmarkHandler::ConstructL( TDesC & aDatabaseUri ) |
|
200 |
// Symbian 2nd phase constructor can leave. |
|
201 |
// ----------------------------------------------------------------------------- |
|
202 |
// |
|
203 |
void CLandmarkHandler::ConstructL( const TDesC& aDatabaseUri ) |
|
204 |
{ |
|
205 |
//Open default database or the database requested depending on paramater aDatabaseUri |
|
206 |
if ( aDatabaseUri != KNullDesC ) |
|
207 |
{ |
|
208 |
iLandmarkDatabaseHandle = CPosLandmarkDatabase::OpenL (aDatabaseUri ); |
|
209 |
} |
|
210 |
else |
|
211 |
{ |
|
212 |
iLandmarkDatabaseHandle = CPosLandmarkDatabase::OpenL ( ); |
|
213 |
} |
|
214 |
iDatabaseUri = iLandmarkDatabaseHandle->DatabaseUriLC ( ); |
|
215 |
CleanupStack::Pop (iDatabaseUri ); |
|
216 |
//Normalize to lower |
|
217 |
iDatabaseUri->Des().LowerCase ( ); |
|
218 |
//initialize the database for further opertaions on the database. |
|
219 |
ExecuteAndDeleteLD (iLandmarkDatabaseHandle->InitializeL ( ) ); |
|
220 |
//Create other handles with respect to the open database |
|
221 |
iLmCategoryManagerHandle = CPosLmCategoryManager::NewL (*iLandmarkDatabaseHandle ); |
|
222 |
iLandmarkSearchHandle = CPosLandmarkSearch::NewL (*iLandmarkDatabaseHandle ); |
|
26
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
223 |
IncRef(); |
5 | 224 |
} |
225 |
||
226 |
// ----------------------------------------------------------------------------- |
|
227 |
// CLandmarkHandler::CLandmarkHandler() |
|
228 |
// C++ default constructor can NOT contain any code, that might leave. |
|
229 |
// ----------------------------------------------------------------------------- |
|
230 |
// |
|
231 |
CLandmarkHandler::CLandmarkHandler( ) |
|
232 |
{ |
|
233 |
} |
|
234 |
||
235 |
// ----------------------------------------------------------------------------- |
|
236 |
// CLandmarkHandler::~CLandmarkHandler() |
|
237 |
// Destructor. |
|
238 |
// ----------------------------------------------------------------------------- |
|
239 |
// |
|
240 |
CLandmarkHandler::~CLandmarkHandler( ) |
|
241 |
{ |
|
242 |
delete iLandmarkSearchHandle; |
|
243 |
delete iLmCategoryManagerHandle; |
|
244 |
delete iLandmarkDatabaseHandle; |
|
245 |
delete iDatabaseUri; |
|
246 |
} |
|
247 |
||
248 |
// ----------------------------------------------------------------------------- |
|
249 |
// CLandmarkHandler::InitL() |
|
250 |
// Initialize the databse if required. |
|
251 |
// ----------------------------------------------------------------------------- |
|
252 |
// |
|
253 |
void CLandmarkHandler::InitL( ) |
|
254 |
{ |
|
255 |
if (iLandmarkDatabaseHandle->IsInitializingNeeded ( ) ) |
|
256 |
{ |
|
257 |
//Initialize the database for further opertaions on the database. |
|
258 |
ExecuteAndDeleteLD (iLandmarkDatabaseHandle->InitializeL ( ) ); |
|
259 |
} |
|
260 |
} |
|
261 |
||
262 |
// End of File |