|
1 /* |
|
2 * Copyright (c) 2004-2005 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: |
|
15 * Implements the CLandmarksLmCategoriesModel class |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include <eikenv.h> |
|
22 #include <gulicon.h> |
|
23 #include <AknIconArray.h> |
|
24 #include <avkon.mbg> |
|
25 |
|
26 #include <EPos_CPosLandmarkCategory.h> |
|
27 |
|
28 #include "LandmarksUtils.h" |
|
29 #include "LandmarksCommonData.h" |
|
30 #include "LandmarksLmCategoriesModel.h" |
|
31 #include "LandmarksApplicationEngine.h" |
|
32 |
|
33 |
|
34 _LIT(KItemFormat, "\t%S"); |
|
35 |
|
36 // ============================ MEMBER FUNCTIONS =============================== |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CLandmarksLmCategoriesModel::CLandmarksLmCategoriesModel( |
|
42 RArray<TPosLmItemId>& aMarkedCategories) |
|
43 : iMarkedCategoryIds(aMarkedCategories) |
|
44 { |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 void CLandmarksLmCategoriesModel::ConstructL(CLandmarksApplicationEngine& aEngine) |
|
51 { |
|
52 iCategories = aEngine.CategoriesL(); |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CLandmarksLmCategoriesModel* CLandmarksLmCategoriesModel::NewL( |
|
59 CLandmarksApplicationEngine& aEngine, |
|
60 RArray<TPosLmItemId>& aMarkedCategories) |
|
61 { |
|
62 CLandmarksLmCategoriesModel* self = new (ELeave) |
|
63 CLandmarksLmCategoriesModel(aMarkedCategories); |
|
64 CleanupStack::PushL(self); |
|
65 self->ConstructL(aEngine); |
|
66 CleanupStack::Pop(self); |
|
67 return self; |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 CLandmarksLmCategoriesModel::~CLandmarksLmCategoriesModel() |
|
74 { |
|
75 if (iCategories) |
|
76 { |
|
77 iCategories->ResetAndDestroy(); |
|
78 delete iCategories; |
|
79 } |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 void CLandmarksLmCategoriesModel::SelectCategoriesL( |
|
86 CArrayFixFlat<TInt>& aSelectedIndexes) |
|
87 { |
|
88 // clear current list of selected categories |
|
89 iMarkedCategoryIds.Reset(); |
|
90 |
|
91 for (TInt i = 0; i < aSelectedIndexes.Count(); i++) |
|
92 { |
|
93 TInt categoryIndex = aSelectedIndexes[i]; |
|
94 |
|
95 // Fetch the id of the selected item. |
|
96 __ASSERT_ALWAYS((categoryIndex >= 0) && (categoryIndex < iCategories->Count()), |
|
97 LandmarksUtils::Panic(KErrGeneral)); |
|
98 TPosLmItemId selectedCategoryId = (*iCategories)[categoryIndex]->CategoryId(); |
|
99 |
|
100 User::LeaveIfError(iMarkedCategoryIds.Append(selectedCategoryId)); |
|
101 } |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 CArrayFixFlat<TInt>* CLandmarksLmCategoriesModel::SelectedCategoriesL() |
|
108 { |
|
109 CArrayFixFlat<TInt>* selectedItems = new (ELeave) CArrayFixFlat<TInt>(KGranularity); |
|
110 CleanupStack::PushL(selectedItems); |
|
111 |
|
112 for (TInt i = 0; i < iCategories->Count(); i++) |
|
113 { |
|
114 TPosLmItemId categoryId = (*iCategories)[i]->CategoryId(); |
|
115 |
|
116 TInt index = iMarkedCategoryIds.Find(categoryId); |
|
117 if (KErrNotFound != index) |
|
118 { |
|
119 selectedItems->AppendL(i); |
|
120 } |
|
121 } |
|
122 |
|
123 CleanupStack::Pop(selectedItems); |
|
124 return selectedItems; |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 CDesCArray* CLandmarksLmCategoriesModel::FormattedCategoryNamesL() |
|
131 { |
|
132 // Granularity is set to be 8. |
|
133 CDesCArrayFlat* listItems = new (ELeave) CDesCArrayFlat(KGranularity); |
|
134 CleanupStack::PushL(listItems); |
|
135 |
|
136 for (TInt i = 0; i < iCategories->Count(); i++) |
|
137 { |
|
138 // Create buffer that will contain the name and mark status. 3 extra |
|
139 // chars for tab and icon index. |
|
140 const TInt KExtraChars = 3; |
|
141 TPtrC categoryName; |
|
142 User::LeaveIfError((*iCategories)[i]->GetCategoryName(categoryName)); |
|
143 HBufC* formattedCategoryName = HBufC::NewLC(categoryName.Length() + KExtraChars); |
|
144 |
|
145 // format string with category |
|
146 formattedCategoryName->Des().Format(KItemFormat, &categoryName); |
|
147 |
|
148 listItems->AppendL(*formattedCategoryName); |
|
149 CleanupStack::PopAndDestroy(formattedCategoryName); |
|
150 } |
|
151 |
|
152 CleanupStack::Pop(listItems); |
|
153 |
|
154 iListItems = listItems; |
|
155 return iListItems; |
|
156 } |
|
157 |
|
158 |