2
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB
|
|
3 |
*
|
|
4 |
* All rights reserved.
|
|
5 |
* This component and the accompanying materials are made available
|
|
6 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
7 |
* which accompanies this distribution, and is available
|
|
8 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
9 |
*
|
|
10 |
* Initial Contributors:
|
|
11 |
* EmbedDev AB - initial contribution.
|
|
12 |
*
|
|
13 |
* Contributors:
|
|
14 |
*
|
|
15 |
* Description:
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
#include "PodcastListView.h"
|
|
20 |
#include "Podcast.hrh"
|
|
21 |
#include "PodcastAppUi.h"
|
|
22 |
#include "constants.h"
|
|
23 |
#include <podcast.rsg>
|
|
24 |
#include <aknlists.h>
|
|
25 |
#include <aknviewappui.h>
|
|
26 |
#include <aknnotedialog.h>
|
|
27 |
#include <aknsbasicbackgroundcontrolcontext.h>
|
|
28 |
#include <akntabgrp.h>
|
|
29 |
#include <akntoolbarextension.h>
|
|
30 |
#include <aknquerydialog.h>
|
|
31 |
#include <barsread.h>
|
|
32 |
|
|
33 |
const TInt KDefaultGran = 5;
|
|
34 |
|
|
35 |
CPodcastListContainer::CPodcastListContainer()
|
|
36 |
{
|
|
37 |
}
|
|
38 |
|
|
39 |
void CPodcastListContainer::SetKeyEventListener(MKeyEventListener *aKeyEventListener)
|
|
40 |
{
|
|
41 |
iKeyEventListener = aKeyEventListener;
|
|
42 |
}
|
|
43 |
|
|
44 |
TKeyResponse CPodcastListContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
|
|
45 |
{
|
|
46 |
TKeyResponse response = iListbox->OfferKeyEventL(aKeyEvent, aType);
|
|
47 |
if (iKeyEventListener)
|
|
48 |
iKeyEventListener->OfferKeyEventL(aKeyEvent, aType);
|
|
49 |
|
|
50 |
return response;
|
|
51 |
}
|
|
52 |
|
|
53 |
void CPodcastListContainer::ConstructL( const TRect& aRect, TInt aListboxFlags )
|
|
54 |
{
|
|
55 |
CreateWindowL();
|
|
56 |
|
|
57 |
iBgContext =
|
|
58 |
CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain,
|
|
59 |
aRect,
|
|
60 |
ETrue );
|
|
61 |
|
|
62 |
// Set the windows size
|
|
63 |
SetRect( aRect );
|
|
64 |
iListbox =static_cast<CEikFormattedCellListBox*>( new (ELeave) CAknDoubleLargeStyleListBox);
|
|
65 |
iListbox->ConstructL(this, aListboxFlags);
|
|
66 |
iListbox->SetMopParent( this );
|
|
67 |
iListbox->SetContainerWindowL(*this);
|
|
68 |
iListbox->CreateScrollBarFrameL(ETrue);
|
|
69 |
iListbox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto, CEikScrollBarFrame::EAuto );
|
|
70 |
|
|
71 |
iListbox->ItemDrawer()->FormattedCellData()->EnableMarqueeL( ETrue );
|
|
72 |
|
|
73 |
iListbox->SetSize(aRect.Size());
|
|
74 |
iListbox->MakeVisible(ETrue);
|
|
75 |
MakeVisible(EFalse);
|
|
76 |
|
|
77 |
// Activate the window, which makes it ready to be drawn
|
|
78 |
ActivateL();
|
|
79 |
}
|
|
80 |
|
|
81 |
TInt CPodcastListContainer::CountComponentControls() const
|
|
82 |
{
|
|
83 |
return 1; // return number of controls inside this container
|
|
84 |
}
|
|
85 |
|
|
86 |
CCoeControl* CPodcastListContainer::ComponentControl(TInt aIndex) const
|
|
87 |
{
|
|
88 |
switch ( aIndex )
|
|
89 |
{
|
|
90 |
case 0:
|
|
91 |
return iListbox;
|
|
92 |
default:
|
|
93 |
return NULL;
|
|
94 |
}
|
|
95 |
}
|
|
96 |
|
|
97 |
void CPodcastListContainer::HandleResourceChange(TInt aType)
|
|
98 |
{
|
|
99 |
switch( aType )
|
|
100 |
{
|
|
101 |
case KEikDynamicLayoutVariantSwitch:
|
|
102 |
SetRect(iEikonEnv->EikAppUi()->ClientRect());
|
|
103 |
break;
|
|
104 |
}
|
|
105 |
}
|
|
106 |
|
|
107 |
void CPodcastListContainer::ScrollToVisible() {
|
|
108 |
if (iListbox != NULL) {
|
|
109 |
iListbox->ScrollToMakeItemVisible(iListbox->CurrentItemIndex());
|
|
110 |
}
|
|
111 |
}
|
|
112 |
void CPodcastListContainer::SizeChanged()
|
|
113 |
{
|
|
114 |
DP2("CPodcastListContainer::SizeChanged(), width=%d, height=%d",Size().iWidth, Size().iHeight);
|
|
115 |
if(iListbox != NULL)
|
|
116 |
{
|
|
117 |
iListbox->SetSize(Size());
|
|
118 |
}
|
|
119 |
}
|
|
120 |
|
|
121 |
CEikFormattedCellListBox* CPodcastListContainer::Listbox()
|
|
122 |
{
|
|
123 |
return iListbox;
|
|
124 |
}
|
|
125 |
|
|
126 |
|
|
127 |
CPodcastListContainer::~CPodcastListContainer()
|
|
128 |
{
|
|
129 |
delete iListbox;
|
|
130 |
delete iBgContext;
|
|
131 |
}
|
|
132 |
|
|
133 |
|
|
134 |
void CPodcastListContainer::Draw(const TRect& aRect) const
|
|
135 |
{
|
|
136 |
CWindowGc& gc = SystemGc();
|
|
137 |
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
|
|
138 |
MAknsControlContext* cc = AknsDrawUtils::ControlContext(this);
|
|
139 |
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
|
|
140 |
AknsDrawUtils::Background(skin, cc, (CCoeControl*) this, gc, aRect);
|
|
141 |
}
|
|
142 |
|
|
143 |
|
|
144 |
TTypeUid::Ptr CPodcastListContainer::MopSupplyObject( TTypeUid aId )
|
|
145 |
{
|
|
146 |
if (iBgContext )
|
|
147 |
{
|
|
148 |
return MAknsControlContext::SupplyMopObject( aId, iBgContext );
|
|
149 |
}
|
|
150 |
return CCoeControl::MopSupplyObject(aId);
|
|
151 |
}
|
|
152 |
|
|
153 |
void CPodcastListContainer::HandlePointerEventL(const TPointerEvent& aPointerEvent)
|
|
154 |
{
|
|
155 |
if (iPointerListener)
|
|
156 |
iPointerListener->PointerEventL(aPointerEvent);
|
|
157 |
|
|
158 |
// Call base class HandlePointerEventL()
|
|
159 |
CCoeControl::HandlePointerEventL(aPointerEvent);
|
|
160 |
}
|
|
161 |
|
|
162 |
|
|
163 |
void CPodcastListContainer::SetPointerListener(MPointerListener *aPointerListener)
|
|
164 |
{
|
|
165 |
iPointerListener = aPointerListener;
|
|
166 |
}
|
|
167 |
|
|
168 |
|
|
169 |
CPodcastListView::CPodcastListView()
|
|
170 |
{
|
|
171 |
}
|
|
172 |
|
|
173 |
void CPodcastListView::ConstructL()
|
|
174 |
{
|
|
175 |
DP("CPodcastListView::ConstructL BEGIN");
|
|
176 |
iListContainer = new (ELeave) CPodcastListContainer;
|
|
177 |
iListContainer->ConstructL(ClientRect(), iListboxFlags);
|
|
178 |
iListContainer->SetMopParent(this);
|
|
179 |
iListContainer->ActivateL();
|
|
180 |
iItemArray = new (ELeave)CDesCArrayFlat(KDefaultGran);
|
|
181 |
iListContainer->Listbox()->Model()->SetItemTextArray(iItemArray);
|
|
182 |
iListContainer->Listbox()->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray);
|
|
183 |
|
|
184 |
if (Toolbar()) {
|
|
185 |
iToolbar = Toolbar();
|
|
186 |
iToolbar->SetToolbarObserver(this);
|
|
187 |
}
|
|
188 |
|
|
189 |
iLongTapDetector = CAknLongTapDetector::NewL(this);
|
|
190 |
iListContainer->SetPointerListener(this);
|
|
191 |
iListContainer->SetKeyEventListener(this);
|
|
192 |
DP("CPodcastListView::ConstructL END");
|
|
193 |
}
|
|
194 |
|
|
195 |
void CPodcastListView::HandleViewRectChange()
|
|
196 |
{
|
|
197 |
if ( iListContainer )
|
|
198 |
{
|
|
199 |
iListContainer->SetRect( ClientRect() );
|
|
200 |
}
|
|
201 |
}
|
|
202 |
|
|
203 |
void CPodcastListView::HandleStatusPaneSizeChange()
|
|
204 |
{
|
|
205 |
DP2("CPodcastListView::HandleStatusPaneSizeChange(), width=%d, height=%d", ClientRect().Width(), ClientRect().Height());
|
|
206 |
|
|
207 |
if ( iListContainer )
|
|
208 |
{
|
|
209 |
iListContainer->SetRect( ClientRect() );
|
|
210 |
}
|
|
211 |
|
|
212 |
}
|
|
213 |
|
|
214 |
|
|
215 |
CPodcastListView::~CPodcastListView()
|
|
216 |
{
|
|
217 |
if(iListContainer)
|
|
218 |
{
|
|
219 |
AppUi()->RemoveFromStack(iListContainer);
|
|
220 |
delete iListContainer;
|
|
221 |
}
|
|
222 |
|
|
223 |
delete iItemArray;
|
|
224 |
delete iLongTapDetector;
|
|
225 |
iItemIdArray.Close();
|
|
226 |
}
|
|
227 |
|
|
228 |
|
|
229 |
void CPodcastListView::DoActivateL(const TVwsViewId& /*aPrevViewId */,
|
|
230 |
TUid /*aCustomMessageId */,
|
|
231 |
const TDesC8& /* aCustomMessage */)
|
|
232 |
{
|
|
233 |
DP("CPodcastListView::DoActivateL() BEGIN");
|
|
234 |
|
|
235 |
if(iListContainer)
|
|
236 |
{
|
|
237 |
iListContainer->SetSize(ClientRect().Size());
|
|
238 |
iListContainer->SetMopParent(this);
|
|
239 |
|
|
240 |
AppUi()->AddToStackL(*this, iListContainer);
|
|
241 |
iListContainer->MakeVisible(ETrue);
|
|
242 |
UpdateListboxItemsL();
|
|
243 |
iListContainer->DrawNow();
|
|
244 |
}
|
|
245 |
DP("CPodcastListView::DoActivateL() END");
|
|
246 |
|
|
247 |
}
|
|
248 |
|
|
249 |
void CPodcastListView::DoDeactivate()
|
|
250 |
{
|
|
251 |
DP("CPodcastListView::DoDeactivate() BEGIN");
|
|
252 |
if ( iListContainer )
|
|
253 |
{
|
|
254 |
AppUi()->RemoveFromViewStack( *this, iListContainer);
|
|
255 |
iListContainer->MakeVisible(EFalse);
|
|
256 |
}
|
|
257 |
DP("CPodcastListView::DoDeactivate() END");
|
|
258 |
}
|
|
259 |
|
|
260 |
/**
|
|
261 |
* Command handling function intended for overriding by sub classes.
|
|
262 |
* Default implementation is empty.
|
|
263 |
* @param aCommand ID of the command to respond to.
|
|
264 |
*/
|
|
265 |
void CPodcastListView::HandleCommandL(TInt aCommand)
|
|
266 |
{
|
|
267 |
DP1("CPodcastListView::HandleCommandL=%d", aCommand);
|
|
268 |
switch(aCommand)
|
|
269 |
{
|
|
270 |
case EAknSoftkeyExit:
|
|
271 |
case EEikCmdExit:
|
|
272 |
{
|
|
273 |
AppUi()->Exit();
|
|
274 |
break;
|
|
275 |
}
|
|
276 |
case EAknSoftkeyBack:
|
|
277 |
{
|
|
278 |
AppUi()->ActivateViewL(iPreviousView);
|
|
279 |
if (iPreviousView.iViewUid == KUidPodcastFeedViewID) {
|
|
280 |
((CPodcastAppUi*)AppUi())->SetActiveTab(KTabIdFeeds);
|
|
281 |
}
|
|
282 |
}break;
|
|
283 |
case EPodcastSettings:
|
|
284 |
AppUi()->ActivateLocalViewL(KUidPodcastSettingsViewID);
|
|
285 |
break;
|
|
286 |
case EPodcastAbout:
|
|
287 |
RunAboutDialogL();
|
|
288 |
break;
|
|
289 |
default:
|
|
290 |
AppUi()->HandleCommandL(aCommand);
|
|
291 |
}
|
|
292 |
}
|
|
293 |
|
|
294 |
|
|
295 |
void CPodcastListView::RunAboutDialogL()
|
|
296 |
{
|
|
297 |
CAknNoteDialog* dlg = new(ELeave) CAknNoteDialog();
|
|
298 |
dlg->ExecuteLD(R_DLG_ABOUT);
|
|
299 |
}
|
|
300 |
|
|
301 |
void CPodcastListView::SetEmptyTextL(TInt aResourceId)
|
|
302 |
{
|
|
303 |
HBufC* emptyText = iEikonEnv->AllocReadResourceLC(aResourceId);
|
|
304 |
iListContainer->Listbox()->View()->SetListEmptyTextL(*emptyText);
|
|
305 |
CleanupStack::PopAndDestroy(emptyText);
|
|
306 |
}
|
|
307 |
|
|
308 |
void CPodcastListView::ShowOkMessage(TDesC &aText)
|
|
309 |
{
|
|
310 |
CAknNoteDialog* dlg= new(ELeave) CAknNoteDialog();
|
|
311 |
CleanupStack::PushL(dlg);
|
|
312 |
dlg->SetTextL(aText);
|
|
313 |
CleanupStack::Pop(dlg);
|
|
314 |
dlg->ExecuteLD(R_MESSAGEDLG_OK);
|
|
315 |
}
|
|
316 |
|
|
317 |
void CPodcastListView::ShowErrorMessage(TDesC &aText)
|
|
318 |
{
|
|
319 |
CAknNoteDialog* dlg= new(ELeave) CAknNoteDialog();
|
|
320 |
CleanupStack::PushL(dlg);
|
|
321 |
dlg->SetTextL(aText);
|
|
322 |
CleanupStack::Pop(dlg);
|
|
323 |
dlg->ExecuteLD(R_ERRORDLG_OK);
|
|
324 |
}
|
|
325 |
|
|
326 |
TInt CPodcastListView::ShowQueryMessage(TDesC &aText)
|
|
327 |
{
|
|
328 |
CAknQueryDialog* dlg= new(ELeave) CAknQueryDialog();
|
|
329 |
|
|
330 |
CleanupStack::PushL(dlg);
|
|
331 |
dlg->SetPromptL(aText);
|
|
332 |
CleanupStack::Pop(dlg);
|
|
333 |
return dlg->ExecuteLD(R_QUERYDLG);
|
|
334 |
}
|
|
335 |
|
|
336 |
void CPodcastListView::CloseToolbarExtension()
|
|
337 |
{
|
|
338 |
CAknToolbar* toolbar = Toolbar();
|
|
339 |
if (toolbar) {
|
|
340 |
CAknToolbarExtension* toolbarExtension = toolbar->ToolbarExtension();
|
|
341 |
if (toolbarExtension) {
|
|
342 |
toolbarExtension->SetShown( EFalse );
|
|
343 |
}
|
|
344 |
}
|
|
345 |
}
|
|
346 |
|
|
347 |
void CPodcastListView::PointerEventL(const TPointerEvent& aPointerEvent)
|
|
348 |
{
|
|
349 |
//DP1("CPodcastListView::PointerEventL, iType=%d", aPointerEvent.iType);
|
|
350 |
// Pass the pointer event to Long tap detector component
|
|
351 |
iLongTapDetector->PointerEventL(aPointerEvent);
|
|
352 |
}
|
|
353 |
|
|
354 |
|
|
355 |
void CPodcastListView::HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& /* aPenEventScreenLocation */)
|
|
356 |
{
|
|
357 |
DP("CPodcastListView::HandleLongTapEventL BEGIN");
|
|
358 |
if(iStylusPopupMenu)
|
|
359 |
{
|
|
360 |
iStylusPopupMenu->ShowMenu();
|
|
361 |
iStylusPopupMenu->SetPosition(aPenEventLocation);
|
|
362 |
}
|
|
363 |
DP("CPodcastListView::HandleLongTapEventL END");
|
|
364 |
}
|
|
365 |
|
|
366 |
|
|
367 |
void CPodcastListView::DynInitToolbarL (TInt /*aResourceId*/, CAknToolbar * /*aToolbar*/)
|
|
368 |
{
|
|
369 |
DP("CPodcastListView::DynInitToolbarL");
|
|
370 |
UpdateToolbar();
|
|
371 |
}
|
|
372 |
|
|
373 |
|
|
374 |
void CPodcastListView::OfferToolbarEventL(TInt aCommand)
|
|
375 |
{
|
|
376 |
HandleCommandL(aCommand);
|
|
377 |
}
|
|
378 |
|
|
379 |
void CPodcastListView::ShowWaitDialogL(TDesC &aWaitText)
|
|
380 |
{
|
|
381 |
DP("CPodcastListView::ShowWaitDialogL BEGIN");
|
|
382 |
|
|
383 |
if (iWaitDialog) {
|
|
384 |
User::Leave(KErrInUse);
|
|
385 |
}
|
|
386 |
|
|
387 |
iWaitDialog=new(ELeave) CAknWaitDialog(reinterpret_cast<CEikDialog**>(&iWaitDialog), EFalse);
|
|
388 |
iWaitDialog->SetCallback(this);
|
|
389 |
iWaitDialog->ExecuteLD(R_WAITDLG);
|
|
390 |
iWaitDialog->SetTextL(aWaitText);
|
|
391 |
DP("CPodcastListView::ShowWaitDialogL END");
|
|
392 |
}
|
|
393 |
|
|
394 |
TKeyResponse CPodcastListView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
|
|
395 |
{
|
|
396 |
if (aType==EEventKey)
|
|
397 |
{
|
|
398 |
switch (aKeyEvent.iCode)
|
|
399 |
{
|
|
400 |
case EKeyRightArrow:
|
|
401 |
((CPodcastAppUi*)AppUi())->TabRight();
|
|
402 |
return EKeyWasConsumed;
|
|
403 |
case EKeyLeftArrow:
|
|
404 |
((CPodcastAppUi*)AppUi())->TabLeft();
|
|
405 |
return EKeyWasConsumed;
|
|
406 |
}
|
|
407 |
}
|
|
408 |
return EKeyWasNotConsumed;
|
|
409 |
}
|
|
410 |
|