37
|
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 CLandmarksCategoriesView class
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
#include <aknViewAppUi.h>
|
|
22 |
#include <eikmenup.h>
|
|
23 |
#include <AknQueryDialog.h>
|
|
24 |
|
|
25 |
#include <EPos_CPosLandmarkCategory.h>
|
|
26 |
|
|
27 |
#include "LmRefApp.hrh"
|
|
28 |
#include <lmrefapp.rsg>
|
|
29 |
#include "LandmarksCategoriesView.h"
|
|
30 |
#include "LandmarksCategoriesContainer.h"
|
|
31 |
#include "LandmarksApplicationEngine.h"
|
|
32 |
|
|
33 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
34 |
|
|
35 |
// -----------------------------------------------------------------------------
|
|
36 |
// -----------------------------------------------------------------------------
|
|
37 |
//
|
|
38 |
CLandmarksCategoriesView::CLandmarksCategoriesView(
|
|
39 |
CLandmarksApplicationEngine* aEngine)
|
|
40 |
: iEngine(aEngine)
|
|
41 |
{
|
|
42 |
// No implementation required
|
|
43 |
}
|
|
44 |
|
|
45 |
// -----------------------------------------------------------------------------
|
|
46 |
// -----------------------------------------------------------------------------
|
|
47 |
//
|
|
48 |
void CLandmarksCategoriesView::ConstructL()
|
|
49 |
{
|
|
50 |
BaseConstructL(R_LMREFAPP_CATEGORIES_VIEW);
|
|
51 |
}
|
|
52 |
|
|
53 |
// -----------------------------------------------------------------------------
|
|
54 |
// -----------------------------------------------------------------------------
|
|
55 |
//
|
|
56 |
CLandmarksCategoriesView* CLandmarksCategoriesView::NewLC(
|
|
57 |
CLandmarksApplicationEngine* aEngine)
|
|
58 |
{
|
|
59 |
CLandmarksCategoriesView* self =
|
|
60 |
new (ELeave) CLandmarksCategoriesView(aEngine);
|
|
61 |
CleanupStack::PushL(self);
|
|
62 |
self->ConstructL();
|
|
63 |
return self;
|
|
64 |
}
|
|
65 |
|
|
66 |
// -----------------------------------------------------------------------------
|
|
67 |
// -----------------------------------------------------------------------------
|
|
68 |
//
|
|
69 |
CLandmarksCategoriesView::~CLandmarksCategoriesView()
|
|
70 |
{
|
|
71 |
delete iContainer;
|
|
72 |
|
|
73 |
// This object is responsible for deleting the application engine instance.
|
|
74 |
delete iEngine;
|
|
75 |
}
|
|
76 |
|
|
77 |
// -----------------------------------------------------------------------------
|
|
78 |
// -----------------------------------------------------------------------------
|
|
79 |
//
|
|
80 |
TUid CLandmarksCategoriesView::Id() const
|
|
81 |
{
|
|
82 |
return TUid::Uid(ELandmarksCategoriesViewId);
|
|
83 |
}
|
|
84 |
|
|
85 |
// -----------------------------------------------------------------------------
|
|
86 |
// -----------------------------------------------------------------------------
|
|
87 |
//
|
|
88 |
void CLandmarksCategoriesView::HandleCommandL(TInt aCommand)
|
|
89 |
{
|
|
90 |
switch (aCommand)
|
|
91 |
{
|
|
92 |
case ELandmarksDelete:
|
|
93 |
iContainer->DeleteCategoryL();
|
|
94 |
break;
|
|
95 |
|
|
96 |
case ELandmarksRename:
|
|
97 |
RenameCategoryL();
|
|
98 |
break;
|
|
99 |
|
|
100 |
case ELandmarksAddCategory:
|
|
101 |
AddCategoryL();
|
|
102 |
break;
|
|
103 |
|
|
104 |
default:
|
|
105 |
AppUi()->HandleCommandL(aCommand);
|
|
106 |
break;
|
|
107 |
}
|
|
108 |
}
|
|
109 |
|
|
110 |
// -----------------------------------------------------------------------------
|
|
111 |
// -----------------------------------------------------------------------------
|
|
112 |
//
|
|
113 |
void CLandmarksCategoriesView::DoActivateL(
|
|
114 |
const TVwsViewId& /*aPrevViewId*/,
|
|
115 |
TUid /*aCustomMessageId*/,
|
|
116 |
const TDesC8& /*aCustomMessage*/)
|
|
117 |
{
|
|
118 |
if (!iContainer)
|
|
119 |
{
|
|
120 |
iContainer = new (ELeave) CLandmarksCategoriesContainer(
|
|
121 |
*this, *iEngine, *(MenuBar()));
|
|
122 |
iContainer->SetMopParent(this);
|
|
123 |
iContainer->ConstructL(ClientRect());
|
|
124 |
}
|
|
125 |
|
|
126 |
// Enable receiving of keyboard events.
|
|
127 |
AppUi()->AddToStackL(*this, iContainer);
|
|
128 |
|
|
129 |
// Make view visible.
|
|
130 |
iContainer->MakeVisible(ETrue);
|
|
131 |
|
|
132 |
// Notify that this view is active.
|
|
133 |
TBool isActive = ETrue;
|
|
134 |
iEngine->NotifyViewActivated(Id(), isActive);
|
|
135 |
}
|
|
136 |
|
|
137 |
// -----------------------------------------------------------------------------
|
|
138 |
// -----------------------------------------------------------------------------
|
|
139 |
//
|
|
140 |
void CLandmarksCategoriesView::DoDeactivate()
|
|
141 |
{
|
|
142 |
// Hide view.
|
|
143 |
iContainer->MakeVisible(EFalse);
|
|
144 |
|
|
145 |
// Notify that this view is inactive.
|
|
146 |
TBool isActive = EFalse;
|
|
147 |
iEngine->NotifyViewActivated(Id(), isActive);
|
|
148 |
|
|
149 |
// Disable receiving keyboard events.
|
|
150 |
AppUi()->RemoveFromStack(iContainer);
|
|
151 |
}
|
|
152 |
|
|
153 |
// -----------------------------------------------------------------------------
|
|
154 |
// -----------------------------------------------------------------------------
|
|
155 |
//
|
|
156 |
void CLandmarksCategoriesView::HandleResourceChange( TInt aType )
|
|
157 |
{
|
|
158 |
if ( iContainer )
|
|
159 |
{
|
|
160 |
iContainer->HandleResourceChange( aType );
|
|
161 |
}
|
|
162 |
}
|
|
163 |
|
|
164 |
// -----------------------------------------------------------------------------
|
|
165 |
// -----------------------------------------------------------------------------
|
|
166 |
//
|
|
167 |
void CLandmarksCategoriesView::DynInitMenuPaneL(
|
|
168 |
TInt aResourceId,
|
|
169 |
CEikMenuPane* aMenuPane)
|
|
170 |
{
|
|
171 |
CAknView::DynInitMenuPaneL(aResourceId, aMenuPane);
|
|
172 |
if (aResourceId == R_LMREFAPP_CATEGORIES_MENU)
|
|
173 |
{
|
|
174 |
// If none or a global cat. is selected we need to hide some commands.
|
|
175 |
TBool dimmed =
|
|
176 |
!iContainer->IsItemSelected() || iContainer->IsGlobalL();
|
|
177 |
aMenuPane->SetItemDimmed(ELandmarksDelete, dimmed);
|
|
178 |
aMenuPane->SetItemDimmed(ELandmarksRename, dimmed);
|
|
179 |
}
|
|
180 |
}
|
|
181 |
|
|
182 |
// -----------------------------------------------------------------------------
|
|
183 |
// -----------------------------------------------------------------------------
|
|
184 |
//
|
|
185 |
void CLandmarksCategoriesView::AddCategoryL()
|
|
186 |
{
|
|
187 |
// Create and initialize dialog
|
|
188 |
TBuf<KPosLmMaxCategoryNameLength> categoryName;
|
|
189 |
CAknTextQueryDialog* queryDialog = CAknTextQueryDialog::NewL(categoryName);
|
|
190 |
queryDialog->SetMaxLength(KPosLmMaxCategoryNameLength);
|
|
191 |
CleanupStack::PushL(queryDialog);
|
|
192 |
|
|
193 |
// Create and set title
|
|
194 |
HBufC* title =
|
|
195 |
iCoeEnv->AllocReadResourceAsDes16LC(R_LMREFAPP_NEW_CATEGORY);
|
|
196 |
queryDialog->SetPromptL(*title);
|
|
197 |
CleanupStack::PopAndDestroy(title);
|
|
198 |
|
|
199 |
// Launch dialog
|
|
200 |
TBool dialogDismissed = queryDialog->ExecuteLD(R_LMREFAPP_RENAME_QUERY);
|
|
201 |
CleanupStack::Pop(queryDialog);
|
|
202 |
if (dialogDismissed)
|
|
203 |
{
|
|
204 |
// Create and add a new category with user defined name.
|
|
205 |
CPosLandmarkCategory* newCategory = CPosLandmarkCategory::NewLC();
|
|
206 |
newCategory->SetCategoryNameL(categoryName);
|
|
207 |
iEngine->AddCategoryL(*newCategory);
|
|
208 |
CleanupStack::PopAndDestroy(newCategory);
|
|
209 |
}
|
|
210 |
}
|
|
211 |
|
|
212 |
// -----------------------------------------------------------------------------
|
|
213 |
// -----------------------------------------------------------------------------
|
|
214 |
//
|
|
215 |
void CLandmarksCategoriesView::RenameCategoryL()
|
|
216 |
{
|
|
217 |
// Fetch existing category name
|
|
218 |
CPosLandmarkCategory* category =
|
|
219 |
iEngine->CategoryLC(iContainer->CurrentCategoryId());
|
|
220 |
TPtrC categoryName;
|
|
221 |
category->GetCategoryName(categoryName);
|
|
222 |
TBuf<KPosLmMaxCategoryNameLength> newCategoryName;
|
|
223 |
newCategoryName.Insert(0, categoryName);
|
|
224 |
|
|
225 |
// Create and initialize dialog
|
|
226 |
CAknTextQueryDialog* queryDialog =
|
|
227 |
CAknTextQueryDialog::NewL(newCategoryName);
|
|
228 |
queryDialog->SetMaxLength(KPosLmMaxCategoryNameLength);
|
|
229 |
CleanupStack::PushL(queryDialog);
|
|
230 |
|
|
231 |
// Create and set title
|
|
232 |
HBufC* title =
|
|
233 |
iCoeEnv->AllocReadResourceAsDes16LC(R_LMREFAPP_CATEGORY_NAME);
|
|
234 |
queryDialog->SetPromptL(*title);
|
|
235 |
CleanupStack::PopAndDestroy(title);
|
|
236 |
|
|
237 |
// Launch dialog
|
|
238 |
TBool dialogAccepted = queryDialog->ExecuteLD(R_LMREFAPP_RENAME_QUERY);
|
|
239 |
CleanupStack::Pop(queryDialog);
|
|
240 |
if (dialogAccepted)
|
|
241 |
{
|
|
242 |
// Update category name
|
|
243 |
category->SetCategoryNameL(newCategoryName);
|
|
244 |
iEngine->UpdateCategoryL(*category);
|
|
245 |
}
|
|
246 |
|
|
247 |
CleanupStack::PopAndDestroy(category);
|
|
248 |
}
|
|
249 |
|
|
250 |
|