|
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: CLandmarkCategoryIterable class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <epos_cposlandmarkcategory.h> |
|
20 #include <epos_cposlandmarkdatabase.h> |
|
21 #include <epos_cposlmcategorymanager.h> |
|
22 #include <epos_cposlmitemiterator.h> |
|
23 #include "clandmarkcategoryiterable.h" |
|
24 #include "landmarkliwparams.hrh" |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // CLandmarkCategoryIterable::NewL() |
|
30 // Two-phased constructor. |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CLandmarkCategoryIterable* CLandmarkCategoryIterable::NewL( CPosLmItemIterator* aIterator, |
|
34 const TDesC& aDatabaseUri ) |
|
35 { |
|
36 CLandmarkCategoryIterable* self = new (ELeave) CLandmarkCategoryIterable(aIterator); |
|
37 CleanupStack::PushL(self); |
|
38 self->ConstructL(aDatabaseUri); |
|
39 CleanupStack::Pop(self); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CLandmarkCategoryIterable::ConstructL( const TDesC & aDatabaseUri ) |
|
45 // Symbian 2nd phase constructor can leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 void CLandmarkCategoryIterable::ConstructL( const TDesC& aDatabaseUri ) |
|
49 { |
|
50 iDatabase = CPosLandmarkDatabase::OpenL(aDatabaseUri); |
|
51 if ( iDatabase->IsInitializingNeeded() ) |
|
52 { |
|
53 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
54 } |
|
55 iCategoryManager = CPosLmCategoryManager::NewL(*iDatabase); |
|
56 } |
|
57 |
|
58 // CLandmarkCategoryIterable::CLandmarkCategoryIterable( CPosLmItemIterator* aIterator ) |
|
59 // C++ default constructor can NOT contain any code, that might leave. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CLandmarkCategoryIterable::CLandmarkCategoryIterable( CPosLmItemIterator* aIterator ) |
|
63 : iIterator(aIterator) |
|
64 { |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CLandmarkCategoryIterable::~CLandmarkCategoryIterable() |
|
69 // Destructor. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CLandmarkCategoryIterable::~CLandmarkCategoryIterable() |
|
73 { |
|
74 delete iIterator; |
|
75 delete iLandmarkCategory; |
|
76 delete iCategoryManager; |
|
77 delete iDatabase; |
|
78 delete iCategoryId; |
|
79 delete iGlobalCategoryId; |
|
80 ReleaseLandmarkResources(); |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CLandmarkCategoryIterable::Reset() |
|
85 // Resets the iterator. NextL has to be called to retrieve the first item. |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 void CLandmarkCategoryIterable::Reset() |
|
89 { |
|
90 iIterator->Reset(); |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CLandmarkCategoryIterable::NextL( TLiwVariant& aEntry ) |
|
95 // retrievs the next item in the list. |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 TBool CLandmarkCategoryIterable::NextL( TLiwVariant& aEntry ) |
|
99 { |
|
100 if ( iLandmarkCategory ) |
|
101 { |
|
102 delete iLandmarkCategory; |
|
103 iLandmarkCategory = NULL; |
|
104 delete iCategoryId; |
|
105 iCategoryId = NULL; |
|
106 delete iGlobalCategoryId; |
|
107 iGlobalCategoryId = NULL; |
|
108 } |
|
109 TPosLmItemId categoryId = iIterator->NextL(); |
|
110 if ( KPosLmNullItemId == categoryId ) |
|
111 { |
|
112 return EFalse; |
|
113 } |
|
114 TPtrC categoryName; |
|
115 TPtrC iconFileName; |
|
116 TInt iconIndex; |
|
117 TInt iconMaskIndex; |
|
118 CLiwMap* categoryMap = CLiwDefaultMap::NewL(); |
|
119 CleanupClosePushL(*categoryMap); |
|
120 iLandmarkCategory = iCategoryManager->ReadCategoryLC(categoryId); |
|
121 CleanupStack::Pop(iLandmarkCategory); |
|
122 |
|
123 iCategoryId = HBufC::NewL(KMaxIDStringLength); |
|
124 iCategoryId->Des().Num(categoryId,EDecimal); |
|
125 categoryMap->InsertL(KId,TLiwVariant(iCategoryId)); |
|
126 |
|
127 if ( iLandmarkCategory->GetCategoryName(categoryName) == KErrNone ) |
|
128 { |
|
129 categoryMap->InsertL(KCategoryName,TLiwVariant(categoryName)); |
|
130 } |
|
131 TPosLmGlobalCategory globalCategory = iLandmarkCategory->GlobalCategory(); |
|
132 if ( KPosLmNullGlobalCategory != globalCategory ) |
|
133 { |
|
134 iGlobalCategoryId = HBufC::NewL(KMaxIDStringLength); |
|
135 iGlobalCategoryId->Des().Num(globalCategory,EDecimal); |
|
136 categoryMap->InsertL(KGlobalCategory,TLiwVariant(iGlobalCategoryId)); |
|
137 } |
|
138 if ( iLandmarkCategory->GetIcon(iconFileName,iconIndex,iconMaskIndex) == KErrNone ) |
|
139 { |
|
140 categoryMap->InsertL(KIconFile,TLiwVariant(iconFileName)); |
|
141 categoryMap->InsertL(KIconIndex,TLiwVariant((TInt32)iconIndex)); |
|
142 categoryMap->InsertL(KIconMaskIndex,TLiwVariant((TInt32)iconMaskIndex)); |
|
143 } |
|
144 aEntry.SetL(categoryMap); |
|
145 CleanupStack::PopAndDestroy(categoryMap); |
|
146 return ETrue; |
|
147 } |
|
148 |
|
149 //end of file |