23 #include "PodcastApp.h" |
23 #include "PodcastApp.h" |
24 #include "Constants.h" |
24 #include "Constants.h" |
25 #include "imagehandler.h" |
25 #include "imagehandler.h" |
26 #include "PodcastShowsView.h" |
26 #include "PodcastShowsView.h" |
27 |
27 |
28 #include <akntitle.h> |
|
29 #include <podcast.rsg> |
28 #include <podcast.rsg> |
30 #include <podcast.mbg> |
29 #include <podcast.mbg> |
31 #include <gulicon.h> |
30 #include <gulicon.h> |
32 #include <barsread.h> |
31 #include <barsread.h> |
33 #include <aknnotedialog.h> |
32 #include <aknnotedialog.h> |
34 #include <aknmessagequerydialog.h> |
33 #include <aknmessagequerydialog.h> |
35 #include "Podcast.hrh" |
|
36 |
34 |
37 #define KMaxMessageLength 200 |
35 #define KMaxMessageLength 200 |
38 |
36 |
39 #define KPodcastImageWidth 160 |
|
40 #define KPodcastImageHeight 120 |
|
41 #define KPodcastDialogOffset 2 |
|
42 |
|
43 #define KOneHundredPercent 100 |
|
44 |
|
45 const TInt KSizeBufLen = 64; |
|
46 const TInt KDefaultGran = 5; |
|
47 _LIT(KSizeDownloadingOf, "%.1f/%.1f MB"); |
|
48 _LIT(KShowsSizeFormatS60, "%.1f MB"); |
|
49 |
|
50 _LIT(KShowFormat, "%d\t%S\t%S %S\t"); |
|
51 _LIT(KShowErrorFormat, "%d\t%S\t%S\t"); |
|
52 _LIT(KShowQueueFormat, "%d\t%S\t%S%S\t"); |
|
53 |
|
54 |
|
55 // these must correspond with TShowsIconIndex |
|
56 |
|
57 const TUint KShowIconArrayIds[] = |
|
58 { |
|
59 EMbmPodcastAudio, |
|
60 EMbmPodcastAudio_mask, |
|
61 EMbmPodcastAudio_new, |
|
62 EMbmPodcastAudio_new_mask, |
|
63 EMbmPodcastAudio_queued, |
|
64 EMbmPodcastAudio_queued_mask, |
|
65 EMbmPodcastAudio_downloading, |
|
66 EMbmPodcastAudio_downloading_mask, |
|
67 EMbmPodcastAudio_downloaded, |
|
68 EMbmPodcastAudio_downloaded_mask, |
|
69 EMbmPodcastAudio_downloaded_new, |
|
70 EMbmPodcastAudio_downloaded_new_mask, |
|
71 EMbmPodcastAudio_failed, |
|
72 EMbmPodcastAudio_failed_mask, |
|
73 EMbmPodcastAudio_suspended, |
|
74 EMbmPodcastAudio_suspended_mask, |
|
75 0, |
|
76 0 |
|
77 }; |
|
78 |
37 |
79 CPodcastQueueView* CPodcastQueueView::NewL(CPodcastModel& aPodcastModel) |
38 CPodcastQueueView* CPodcastQueueView::NewL(CPodcastModel& aPodcastModel) |
80 { |
39 { |
81 CPodcastQueueView* self = CPodcastQueueView::NewLC(aPodcastModel); |
40 CPodcastQueueView* self = CPodcastQueueView::NewLC(aPodcastModel); |
82 CleanupStack::Pop(self); |
41 CleanupStack::Pop(self); |
90 self->ConstructL(); |
49 self->ConstructL(); |
91 return self; |
50 return self; |
92 } |
51 } |
93 |
52 |
94 CPodcastQueueView::CPodcastQueueView(CPodcastModel& aPodcastModel) : |
53 CPodcastQueueView::CPodcastQueueView(CPodcastModel& aPodcastModel) : |
95 iPodcastModel(aPodcastModel) |
54 CPodcastShowsView(aPodcastModel) |
96 { |
55 { |
97 } |
56 } |
98 |
57 |
99 void CPodcastQueueView::ConstructL() |
58 void CPodcastQueueView::ConstructL() |
100 { |
59 { |
101 BaseConstructL(R_PODCAST_QUEUEVIEW); |
60 BaseConstructL(R_PODCAST_QUEUEVIEW); |
102 CPodcastListView::ConstructL(); |
61 CPodcastListView::ConstructL(); |
103 CArrayPtr< CGulIcon>* icons = new(ELeave) CArrayPtrFlat< CGulIcon>(1); |
62 |
104 CleanupStack::PushL(icons); |
63 CreateIconsL(); |
105 TInt pos = 0; |
64 |
106 while (KShowIconArrayIds[pos] > 0) |
|
107 { |
|
108 // Load the bitmap for play icon |
|
109 CFbsBitmap* bitmap= NULL;//iEikonEnv->CreateBitmapL( _L("*"), KIconArrayIds[pos]); |
|
110 CFbsBitmap* mask= NULL;////iEikonEnv->CreateBitmapL( _L("*"), KIconArrayIds[pos+1] ); |
|
111 AknIconUtils::CreateIconL(bitmap, |
|
112 mask, |
|
113 iEikonEnv->EikAppUi()->Application()->BitmapStoreName(), |
|
114 KShowIconArrayIds[pos], |
|
115 KShowIconArrayIds[pos+1]); |
|
116 CleanupStack::PushL(bitmap); |
|
117 // Load the mask for play icon |
|
118 CleanupStack::PushL(mask); |
|
119 // Append the play icon to icon array |
|
120 icons->AppendL(CGulIcon::NewL(bitmap, mask) ); |
|
121 CleanupStack::Pop(2); // bitmap, mask |
|
122 pos+=2; |
|
123 } |
|
124 iListContainer->Listbox()->ItemDrawer()->FormattedCellData()->SetIconArrayL(icons); |
|
125 CleanupStack::Pop(icons); // icons |
|
126 iListContainer->Listbox()->SetListBoxObserver(this); |
65 iListContainer->Listbox()->SetListBoxObserver(this); |
127 |
66 |
128 iPodcastModel.FeedEngine().AddObserver(this); |
67 iPodcastModel.FeedEngine().AddObserver(this); |
129 iPodcastModel.ShowEngine().AddObserver(this); |
68 iPodcastModel.ShowEngine().AddObserver(this); |
130 |
69 |
|
70 |
|
71 // no popup options apply to S^1 |
|
72 #ifndef SYMBIAN1_UI |
131 iStylusPopupMenu = CAknStylusPopUpMenu::NewL( this , TPoint(0,0)); |
73 iStylusPopupMenu = CAknStylusPopUpMenu::NewL( this , TPoint(0,0)); |
132 TResourceReader reader; |
74 TResourceReader reader; |
133 iCoeEnv->CreateResourceReaderLC(reader,R_QUEUEVIEW_POPUP_MENU); |
75 iCoeEnv->CreateResourceReaderLC(reader,R_QUEUEVIEW_POPUP_MENU); |
134 iStylusPopupMenu->ConstructFromResourceL(reader); |
76 iStylusPopupMenu->ConstructFromResourceL(reader); |
135 CleanupStack::PopAndDestroy(); |
77 CleanupStack::PopAndDestroy(); |
|
78 #endif |
136 SetEmptyTextL(R_PODCAST_EMPTY_QUEUE); |
79 SetEmptyTextL(R_PODCAST_EMPTY_QUEUE); |
137 } |
80 } |
138 |
81 |
139 TKeyResponse CPodcastQueueView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
82 TKeyResponse CPodcastQueueView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
140 { |
83 { |
198 TUid aCustomMessageId, const TDesC8& aCustomMessage) |
126 TUid aCustomMessageId, const TDesC8& aCustomMessage) |
199 { |
127 { |
200 DP("CPodcastQueueView::DoActivateL BEGIN"); |
128 DP("CPodcastQueueView::DoActivateL BEGIN"); |
201 |
129 |
202 CPodcastListView::DoActivateL(aPrevViewId, aCustomMessageId, aCustomMessage); |
130 CPodcastListView::DoActivateL(aPrevViewId, aCustomMessageId, aCustomMessage); |
203 iPreviousView = TVwsViewId(KUidPodcast, KUidPodcastFeedViewID); |
131 iPreviousView = aPrevViewId; |
204 |
132 |
205 UpdateFeedUpdateStateL(); |
133 UpdateFeedUpdateStateL(); |
206 UpdateToolbar(); |
134 UpdateToolbar(); |
207 DP("CPodcastQueueView::DoActivateL END"); |
135 DP("CPodcastQueueView::DoActivateL END"); |
208 } |
136 } |
209 |
137 |
210 void CPodcastQueueView::DoDeactivate() |
138 void CPodcastQueueView::DoDeactivate() |
211 { |
139 { |
212 CPodcastListView::DoDeactivate(); |
140 CPodcastListView::DoDeactivate(); |
213 } |
|
214 |
|
215 // Engine callback when new shows are available |
|
216 void CPodcastQueueView::ShowListUpdatedL() |
|
217 { |
|
218 UpdateListboxItemsL(); |
|
219 } |
|
220 |
|
221 void CPodcastQueueView::ShowDownloadUpdatedL(TInt aBytesOfCurrentDownload, TInt /*aBytesTotal*/) |
|
222 { |
|
223 if (!iListContainer->IsVisible()) |
|
224 { |
|
225 return; |
|
226 } |
|
227 |
|
228 CShowInfo *info = iPodcastModel.ShowEngine().ShowDownloading(); |
|
229 if (info) |
|
230 { |
|
231 UpdateShowItemL(info->Uid(), aBytesOfCurrentDownload); |
|
232 } |
|
233 } |
|
234 |
|
235 void CPodcastQueueView::ShowDownloadFinishedL(TUint /*aShowUid*/, TInt aError) |
|
236 { |
|
237 if (iListContainer->IsVisible()) |
|
238 { |
|
239 |
|
240 iProgressAdded = EFalse; |
|
241 |
|
242 iPodcastModel.GetShowsDownloadingL(); |
|
243 UpdateListboxItemsL(); |
|
244 UpdateToolbar(); |
|
245 |
|
246 switch(aError) |
|
247 { |
|
248 case KErrCouldNotConnect: |
|
249 { |
|
250 TBuf<KMaxMessageLength> message; |
|
251 iEikonEnv->ReadResourceL(message, R_PODCAST_CONNECTION_ERROR); |
|
252 ShowErrorMessage(message); |
|
253 } |
|
254 break; |
|
255 default: // Do nothing |
|
256 break; |
|
257 } |
|
258 } |
|
259 } |
|
260 |
|
261 |
|
262 void CPodcastQueueView::FeedDownloadStartedL(TFeedState /*aState*/, TUint aFeedUid) |
|
263 { |
|
264 // TODO make use of the fact that we know that the feed download is |
|
265 // started instead of checking feed engine states in UpdateFeedUpdateStateL. |
|
266 if (iPodcastModel.ActiveFeedInfo() != NULL |
|
267 && iPodcastModel.ActiveFeedInfo()->Uid() == aFeedUid) |
|
268 { |
|
269 UpdateFeedUpdateStateL(); |
|
270 UpdateToolbar(); |
|
271 } |
|
272 } |
|
273 |
|
274 void CPodcastQueueView::FeedDownloadFinishedL(TFeedState /*aState*/, TUint aFeedUid, TInt /*aError*/) |
|
275 { |
|
276 DP("CPodcastQueueView::FeedDownloadFinishedL BEGIN"); |
|
277 // TODO make use of the fact that we know that the feed download is |
|
278 // finished instead of checking feed engine states in UpdateFeedUpdateStateL. |
|
279 if (iPodcastModel.ActiveFeedInfo() != NULL |
|
280 && iPodcastModel.ActiveFeedInfo()->Uid() == aFeedUid) |
|
281 { |
|
282 UpdateFeedUpdateStateL(); |
|
283 } |
|
284 DP("CPodcastQueueView::FeedDownloadFinishedL END"); |
|
285 } |
141 } |
286 |
142 |
287 void CPodcastQueueView::HandleListBoxEventL(CEikListBox* /*aListBox*/, |
143 void CPodcastQueueView::HandleListBoxEventL(CEikListBox* /*aListBox*/, |
288 TListBoxEvent aEventType) |
144 TListBoxEvent aEventType) |
289 { |
145 { |
299 default: |
155 default: |
300 break; |
156 break; |
301 } |
157 } |
302 UpdateToolbar(); |
158 UpdateToolbar(); |
303 } |
159 } |
304 |
|
305 void CPodcastQueueView::GetShowIcons(CShowInfo* aShowInfo, TInt& aIconIndex) |
|
306 { |
|
307 TBool dlStop = iPodcastModel.SettingsEngine().DownloadSuspended(); |
|
308 |
|
309 switch (aShowInfo->DownloadState()) |
|
310 { |
|
311 case EDownloaded: |
|
312 if (aShowInfo->PlayState() == ENeverPlayed) { |
|
313 aIconIndex = EDownloadedNewShowIcon; |
|
314 } else { |
|
315 aIconIndex = EDownloadedShowIcon; |
|
316 } |
|
317 break; |
|
318 case ENotDownloaded: |
|
319 if (aShowInfo->PlayState() == ENeverPlayed) { |
|
320 aIconIndex = ENewShowIcon; |
|
321 } else { |
|
322 aIconIndex = EShowIcon; |
|
323 } |
|
324 break; |
|
325 case EQueued: |
|
326 aIconIndex = dlStop ? ESuspendedShowIcon : EQuedShowIcon; |
|
327 break; |
|
328 case EDownloading: |
|
329 aIconIndex = dlStop ? ESuspendedShowIcon : EDownloadingShowIcon; |
|
330 break; |
|
331 case EFailedDownload: |
|
332 aIconIndex = EFailedShowIcon; |
|
333 break; |
|
334 } |
|
335 } |
|
336 |
|
337 void CPodcastQueueView::UpdateFeedUpdateStateL() |
|
338 { |
|
339 TBool listboxDimmed = EFalse; |
|
340 |
|
341 if (iPodcastModel.FeedEngine().ClientState() != EIdle && iPodcastModel.ActiveFeedInfo() |
|
342 != NULL && iPodcastModel.FeedEngine().ActiveClientUid() == iPodcastModel.ActiveFeedInfo()->Uid()) |
|
343 { |
|
344 listboxDimmed = ETrue; |
|
345 } |
|
346 |
|
347 if ((iListContainer->Listbox()->IsDimmed() && !listboxDimmed) || (!iListContainer->Listbox()->IsDimmed() && listboxDimmed)) |
|
348 { |
|
349 iListContainer->Listbox()->SetDimmed(listboxDimmed); |
|
350 } |
|
351 UpdateListboxItemsL(); |
|
352 UpdateToolbar(); |
|
353 } |
|
354 |
|
355 void CPodcastQueueView::FormatShowInfoListBoxItemL(CShowInfo& aShowInfo, TInt aSizeDownloaded) |
|
356 { |
|
357 TBuf<32> infoSize; |
|
358 TInt iconIndex = 0; |
|
359 TBuf<KMaxShortDateFormatSpec*2> showDate; |
|
360 GetShowIcons(&aShowInfo, iconIndex); |
|
361 |
|
362 if(aSizeDownloaded > 0) |
|
363 { |
|
364 if (aShowInfo.ShowSize() > 0) |
|
365 { |
|
366 infoSize.Format(KSizeDownloadingOf(), ((float) aSizeDownloaded / (float) KSizeMb), |
|
367 ((float)aShowInfo.ShowSize() / (float)KSizeMb)); |
|
368 } |
|
369 else |
|
370 { |
|
371 infoSize.Format(KShowsSizeFormatS60(), (float)aSizeDownloaded / (float)KSizeMb); |
|
372 } |
|
373 } |
|
374 else if (aShowInfo.ShowSize() > 0) |
|
375 { |
|
376 infoSize.Format(KShowsSizeFormatS60(), (float)aShowInfo.ShowSize() / (float)KSizeMb); |
|
377 } |
|
378 else { |
|
379 infoSize = KNullDesC(); |
|
380 } |
|
381 |
|
382 if (aShowInfo.PubDate().Int64() == 0) |
|
383 { |
|
384 showDate = KNullDesC(); |
|
385 } |
|
386 else |
|
387 { |
|
388 aShowInfo.PubDate().FormatL(showDate, KDateFormatShort()); |
|
389 } |
|
390 |
|
391 if(aShowInfo.LastError() != KErrNone) |
|
392 { |
|
393 TBuf<KSizeBufLen> errorBuffer; |
|
394 iEikonEnv->GetErrorText(errorBuffer, aShowInfo.LastError()); |
|
395 iListboxFormatbuffer.Format(KShowErrorFormat(), iconIndex, &aShowInfo.Title(), &errorBuffer); |
|
396 } |
|
397 else |
|
398 { |
|
399 if (infoSize.Length() > 0) { |
|
400 infoSize.Insert(0,_L(", ")); |
|
401 } |
|
402 |
|
403 iListboxFormatbuffer.Format(KShowQueueFormat(), iconIndex, &aShowInfo.Title(), &showDate, &infoSize); |
|
404 } |
|
405 } |
|
406 |
|
407 void CPodcastQueueView::UpdateShowItemDataL(CShowInfo* aShowInfo,TInt aIndex, TInt aSizeDownloaded) |
|
408 { |
|
409 FormatShowInfoListBoxItemL(*aShowInfo, aSizeDownloaded); |
|
410 iItemArray->Delete(aIndex); |
|
411 if(aIndex>= iItemArray->MdcaCount()) |
|
412 { |
|
413 iItemArray->AppendL(iListboxFormatbuffer); |
|
414 } |
|
415 else |
|
416 { |
|
417 iItemArray->InsertL(aIndex, iListboxFormatbuffer); |
|
418 } |
|
419 } |
|
420 |
|
421 void CPodcastQueueView::UpdateShowItemL(TUint aUid, TInt aSizeDownloaded) |
|
422 { |
|
423 RShowInfoArray& array = iPodcastModel.ActiveShowList(); |
|
424 |
|
425 for (int i=0;i<array.Count();i++) { |
|
426 if (array[i]->Uid() == aUid) { |
|
427 UpdateShowItemDataL(array[i], i, aSizeDownloaded); |
|
428 if (iListContainer->Listbox()->TopItemIndex() <= i && |
|
429 iListContainer->Listbox()->BottomItemIndex() >= i) { |
|
430 iListContainer->Listbox()->DrawItem(i); |
|
431 } |
|
432 } |
|
433 } |
|
434 } |
|
435 |
160 |
436 void CPodcastQueueView::UpdateListboxItemsL() |
161 void CPodcastQueueView::UpdateListboxItemsL() |
437 { |
162 { |
438 if (iListContainer->IsVisible()) |
163 if (iListContainer->IsVisible()) |
439 { |
164 { |
515 case EPodcastRemoveAllDownloads: |
240 case EPodcastRemoveAllDownloads: |
516 { |
241 { |
517 TBuf<KMaxMessageLength> msg; |
242 TBuf<KMaxMessageLength> msg; |
518 iEikonEnv->ReadResourceL(msg, R_CLEAR_QUERY); |
243 iEikonEnv->ReadResourceL(msg, R_CLEAR_QUERY); |
519 |
244 |
520 if(ShowQueryMessage(msg)) |
245 if(ShowQueryMessageL(msg)) |
521 { |
246 { |
522 iPodcastModel.ShowEngine().RemoveAllDownloads(); |
247 iPodcastModel.ShowEngine().RemoveAllDownloadsL(); |
523 UpdateListboxItemsL(); |
248 UpdateListboxItemsL(); |
524 } |
249 } |
525 } |
250 } |
526 break; |
251 break; |
527 case EPodcastRemoveDownload: |
252 case EPodcastRemoveDownload: |
528 { |
253 { |
529 TInt index = iListContainer->Listbox()->CurrentItemIndex(); |
254 TInt index = iListContainer->Listbox()->CurrentItemIndex(); |
530 if (index >= 0 && index < iPodcastModel.ActiveShowList().Count()) |
255 if (index >= 0 && index < iPodcastModel.ActiveShowList().Count()) |
531 { |
256 { |
532 if (iPodcastModel.ShowEngine().RemoveDownloadL(iPodcastModel.ActiveShowList()[index]->Uid())) |
257 TRAP_IGNORE(iPodcastModel.ShowEngine().RemoveDownloadL(iPodcastModel.ActiveShowList()[index]->Uid())); |
533 { |
|
534 iItemArray->Delete(index); |
|
535 iItemIdArray.Remove(index); |
|
536 iListContainer->Listbox()->HandleItemRemovalL(); |
|
537 iListContainer->Listbox()->SetCurrentItemIndex(index - 1 > 0 ? index - 1 : 0); |
|
538 iListContainer->Listbox()->DrawNow(); |
|
539 |
|
540 delete iPodcastModel.ActiveShowList()[index]; |
|
541 iPodcastModel.ActiveShowList().Remove(index); |
|
542 } |
|
543 } |
258 } |
544 } |
259 } |
545 break; |
260 break; |
546 case EPodcastSuspendDownloads: |
261 case EPodcastSuspendDownloads: |
547 { |
262 { |
582 } |
298 } |
583 toolbar->HideItem(EPodcastRemoveAllDownloads, EFalse, ETrue); |
299 toolbar->HideItem(EPodcastRemoveAllDownloads, EFalse, ETrue); |
584 toolbar->SetItemDimmed(EPodcastRemoveAllDownloads, itemCnt == 0, ETrue); |
300 toolbar->SetItemDimmed(EPodcastRemoveAllDownloads, itemCnt == 0, ETrue); |
585 toolbar->HideItem(EPodcastSuspendDownloads,iPodcastModel.SettingsEngine().DownloadSuspended(), ETrue); |
301 toolbar->HideItem(EPodcastSuspendDownloads,iPodcastModel.SettingsEngine().DownloadSuspended(), ETrue); |
586 toolbar->HideItem(EPodcastResumeDownloads,!iPodcastModel.SettingsEngine().DownloadSuspended(), ETrue); |
302 toolbar->HideItem(EPodcastResumeDownloads,!iPodcastModel.SettingsEngine().DownloadSuspended(), ETrue); |
587 #ifdef SYMBIAN1_UI |
|
588 toolbar->HideItem(EPodcastRemoveDownload, EFalse, ETrue); |
|
589 toolbar->SetItemDimmed(EPodcastRemoveDownload, itemCnt == 0, ETrue); |
303 toolbar->SetItemDimmed(EPodcastRemoveDownload, itemCnt == 0, ETrue); |
590 #endif |
|
591 } |
304 } |
592 } |
305 } |
593 |
|
594 void CPodcastQueueView::DownloadQueueUpdatedL(TInt /*aDownloadingShows*/, TInt /*aQueuedShows*/) |
|
595 { |
|
596 } |
|
597 |
|
598 void CPodcastQueueView::FeedUpdateAllCompleteL(TFeedState /*aState*/) |
|
599 { |
|
600 UpdateListboxItemsL(); |
|
601 UpdateToolbar(); |
|
602 } |
|