18 #include <hbtoolbar.h> |
18 #include <hbtoolbar.h> |
19 #include <hbaction.h> |
19 #include <hbaction.h> |
20 #include <hbmenu.h> |
20 #include <hbmenu.h> |
21 #include <hbgroupbox.h> |
21 #include <hbgroupbox.h> |
22 #include <hbselectiondialog.h> |
22 #include <hbselectiondialog.h> |
23 #include <QPixmap> |
|
24 #include <QTimer> |
|
25 #include <HbInputDialog> |
23 #include <HbInputDialog> |
26 #include <hbscrollbar.h> |
24 #include <hbscrollbar.h> |
27 #include <HbLineEdit> |
25 #include <HbLineEdit> |
28 |
26 |
29 #include "irviewmanager.h" |
27 #include "irviewmanager.h" |
38 #include "irqisdsdatastructure.h" |
36 #include "irqisdsdatastructure.h" |
39 #include "irqutility.h" |
37 #include "irqutility.h" |
40 #include "iruidefines.h" |
38 #include "iruidefines.h" |
41 #include "irstationshare.h" |
39 #include "irstationshare.h" |
42 #include "irstationdetailsview.h" |
40 #include "irstationdetailsview.h" |
43 const int KBitmapSize = 59; |
|
44 |
41 |
45 const QString KActionShareName("Share"); |
42 const QString KActionShareName("Share"); |
46 const QString KActionDeleteName("Delete"); |
43 const QString KActionDeleteName("Delete"); |
47 const QString KActionRenameName("Rename"); |
44 const QString KActionRenameName("Rename"); |
48 const QString KActionDetailsName("Details"); |
45 const QString KActionDetailsName("Details"); |
55 */ |
52 */ |
56 IRFavoritesView::IRFavoritesView(IRApplication *aApplication, TIRViewId aViewId) |
53 IRFavoritesView::IRFavoritesView(IRApplication *aApplication, TIRViewId aViewId) |
57 : IrAbstractListViewBase(aApplication, aViewId), |
54 : IrAbstractListViewBase(aApplication, aViewId), |
58 iStationShare(NULL), |
55 iStationShare(NULL), |
59 iMultiDeleteDialog(NULL), |
56 iMultiDeleteDialog(NULL), |
60 iMultiDeleteAction(NULL), |
57 iMultiDeleteAction(NULL) |
61 iLogoPreset(NULL) |
|
62 { |
58 { |
63 setFlag(EViewFlag_ClearStackWhenActivate|EViewFlag_StickyViewEnabled); |
59 setFlag(EViewFlag_ClearStackWhenActivate|EViewFlag_StickyViewEnabled); |
64 |
60 iLoader.load(ABSTRACT_LIST_VIEW_BASE_LAYOUT_FILENAME, ABSTRACT_LIST_VIEW_BASE_ADD_TOOLBAR_SECTION); |
65 initToolBar(); |
61 |
66 iModel = new IRFavoritesModel(iFavorites, this); |
62 iModel = new IRFavoritesModel(iFavorites, this); |
67 iListView->setModel(iModel); |
63 iListView->setModel(iModel); |
68 |
64 |
69 iConvertTimer = new QTimer(this); |
|
70 iConvertTimer->setInterval(10); |
|
71 |
|
72 connect(iModel, SIGNAL(modelChanged()), this, SLOT(modelChanged())); |
65 connect(iModel, SIGNAL(modelChanged()), this, SLOT(modelChanged())); |
73 connect(iNetworkController, SIGNAL(networkRequestNotified(IRQNetworkEvent)), |
66 connect(iNetworkController, SIGNAL(networkRequestNotified(IRQNetworkEvent)), |
74 this, SLOT(networkRequestNotified(IRQNetworkEvent))); |
67 this, SLOT(networkRequestNotified(IRQNetworkEvent))); |
75 connect(iConvertTimer, SIGNAL(timeout()), this, SLOT(convertAnother())); |
|
76 |
|
77 } |
68 } |
78 |
69 |
79 /* |
70 /* |
80 * Description : destructor |
71 * Description : destructor |
81 */ |
72 */ |
82 IRFavoritesView::~IRFavoritesView() |
73 IRFavoritesView::~IRFavoritesView() |
83 { |
74 { |
84 delete iLogoPreset; |
|
85 iLogoPreset = NULL; |
|
86 |
|
87 delete iMultiDeleteDialog; |
75 delete iMultiDeleteDialog; |
88 iMultiDeleteDialog = NULL; |
76 iMultiDeleteDialog = NULL; |
89 |
77 |
90 delete iStationShare; |
78 delete iStationShare; |
91 iStationShare = NULL; |
79 iStationShare = NULL; |
94 TIRHandleResult IRFavoritesView::handleCommand(TIRViewCommand aCommand, TIRViewCommandReason aReason) |
82 TIRHandleResult IRFavoritesView::handleCommand(TIRViewCommand aCommand, TIRViewCommandReason aReason) |
95 { |
83 { |
96 Q_UNUSED(aReason); |
84 Q_UNUSED(aReason); |
97 |
85 |
98 TIRHandleResult ret = IrAbstractListViewBase::handleCommand(aCommand, aReason); |
86 TIRHandleResult ret = IrAbstractListViewBase::handleCommand(aCommand, aReason); |
99 int leftCount = 0; |
|
100 |
87 |
101 switch (aCommand) |
88 switch (aCommand) |
102 { |
89 { |
103 case EIR_ViewCommand_TOBEACTIVATED: |
90 case EIR_ViewCommand_TOBEACTIVATED: |
104 iModel->checkFavoritesUpdate(); |
91 iModel->checkFavoritesUpdate(); |
105 ret = EIR_NoDefault; |
92 ret = EIR_NoDefault; |
106 break; |
93 break; |
107 |
94 |
108 case EIR_ViewCommand_ACTIVATED: |
95 case EIR_ViewCommand_ACTIVATED: |
109 connect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset* )), |
96 iModel->startDownloadingLogo(); |
110 this, SLOT(presetLogoDownload(IRQPreset* ))); |
|
111 connect(iIsdsClient, SIGNAL(presetLogoDownloadError()), |
|
112 this, SLOT(presetLogoDownloadError())); |
|
113 |
|
114 leftCount = iIconIndexArray.count(); |
|
115 if( leftCount > 0 ) |
|
116 { |
|
117 iConvertTimer->start(); |
|
118 } |
|
119 |
|
120 getViewManager()->saveScreenShot(); |
97 getViewManager()->saveScreenShot(); |
121 ret = EIR_NoDefault; |
98 ret = EIR_NoDefault; |
122 break; |
99 break; |
123 |
100 |
124 case EIR_ViewCommand_DEACTIVATE: |
101 case EIR_ViewCommand_DEACTIVATE: |
125 |
102 |
126 iModel->clearAndDestroyLogos(); |
103 iModel->clearAndDestroyLogos(); |
127 iConvertTimer->stop(); |
104 iModel->stopDownloadingLogo(); |
128 iIsdsClient->isdsLogoDownCancelTransaction(); |
|
129 //iIconIndexArray must be cleared, because timer call back convertAnother() might be |
|
130 //called after view is deactivated. In that case, iModel->getImgURL(aIndex); will crash |
|
131 iIconIndexArray.clear(); |
|
132 |
|
133 disconnect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset*)), |
|
134 this, SLOT(presetLogoDownload(IRQPreset* ))); |
|
135 disconnect(iIsdsClient, SIGNAL(presetLogoDownloadError()), |
|
136 this, SLOT(presetLogoDownloadError())); |
|
137 |
|
138 ret = EIR_NoDefault; |
105 ret = EIR_NoDefault; |
139 break; |
106 break; |
140 |
107 |
141 default: |
108 default: |
142 break; |
109 break; |
256 { |
223 { |
257 viewMenu->insertAction(settingAction, iMultiDeleteAction); |
224 viewMenu->insertAction(settingAction, iMultiDeleteAction); |
258 } |
225 } |
259 } |
226 } |
260 |
227 |
261 void IRFavoritesView::startConvert(int aIndex) |
|
262 { |
|
263 QString url = iModel->getImgUrl(aIndex); |
|
264 |
|
265 IRQPreset tempPreset; |
|
266 tempPreset.imgUrl = url; |
|
267 tempPreset.type = IRQPreset::EIsds; |
|
268 |
|
269 iIsdsClient->isdsLogoDownSendRequest(&tempPreset, 0, KBitmapSize, KBitmapSize); |
|
270 } |
|
271 |
|
272 //if the logo is downloaded ok |
|
273 void IRFavoritesView::presetLogoDownload(IRQPreset* aPreset) |
|
274 { |
|
275 if (NULL == aPreset) |
|
276 { |
|
277 presetLogoDownloadError(); |
|
278 return; |
|
279 } |
|
280 |
|
281 delete iLogoPreset; |
|
282 iLogoPreset = aPreset; |
|
283 |
|
284 if (iLogoPreset->logoData.size() > 0) |
|
285 { |
|
286 QPixmap tempMap; |
|
287 bool ret = tempMap.loadFromData((const unsigned char*)iLogoPreset->logoData.constData(), iLogoPreset->logoData.size()); |
|
288 if( ret ) |
|
289 { |
|
290 QIcon convertIcon(tempMap); |
|
291 HbIcon *hbIcon = new HbIcon(convertIcon); |
|
292 int index = iIconIndexArray[0]; |
|
293 iModel->setLogo(hbIcon, index); |
|
294 iIconIndexArray.removeAt(0); |
|
295 int leftCount = iIconIndexArray.count(); |
|
296 if( leftCount > 0 ) |
|
297 { |
|
298 iConvertTimer->start(); |
|
299 } |
|
300 return; |
|
301 } |
|
302 } |
|
303 |
|
304 presetLogoDownloadError(); |
|
305 } |
|
306 |
|
307 //if the logo download fails |
|
308 void IRFavoritesView::presetLogoDownloadError() |
|
309 { |
|
310 iIconIndexArray.removeAt(0); |
|
311 int leftCount = 0; |
|
312 leftCount = iIconIndexArray.count(); |
|
313 if( leftCount > 0 ) |
|
314 { |
|
315 iConvertTimer->start(); |
|
316 } |
|
317 } |
|
318 |
|
319 void IRFavoritesView::convertAnother() |
|
320 { |
|
321 iConvertTimer->stop(); |
|
322 int leftCount = iIconIndexArray.count(); |
|
323 |
|
324 if (0 != leftCount) |
|
325 { |
|
326 startConvert(iIconIndexArray[0]); |
|
327 } |
|
328 } |
|
329 |
|
330 void IRFavoritesView::modelChanged() |
228 void IRFavoritesView::modelChanged() |
331 { |
229 { |
332 #ifdef SUBTITLE_STR_BY_LOCID |
230 #ifdef SUBTITLE_STR_BY_LOCID |
333 QString headingStr = hbTrId("txt_irad_subtitle_favorites") + " (" + QString::number(iModel->rowCount()) + ")"; |
231 QString headingStr = hbTrId("txt_irad_subtitle_favorites") + " (" + QString::number(iModel->rowCount()) + ")"; |
334 #else |
232 #else |
335 QString headingStr = hbTrId("Favorites") + " (" + QString::number(iModel->rowCount()) + ")"; |
233 QString headingStr = hbTrId("Favorites") + " (" + QString::number(iModel->rowCount()) + ")"; |
336 #endif |
234 #endif |
337 setHeadingText(headingStr); |
235 setHeadingText(headingStr); |
338 updateIconIndexArray(); |
|
339 |
236 |
340 iListView->reset(); |
237 iListView->reset(); |
341 iListView->setCurrentIndex(iModel->index(0)); |
238 iListView->setCurrentIndex(iModel->index(0)); |
342 iListView->verticalScrollBar()->setValue(0.0); |
239 iListView->verticalScrollBar()->setValue(0.0); |
343 } |
240 } |
347 if (iMultiDeleteDialog->actions().at(0) == aAction) |
244 if (iMultiDeleteDialog->actions().at(0) == aAction) |
348 { |
245 { |
349 QModelIndexList selectedIndexes = iMultiDeleteDialog->selectedModelIndexes(); |
246 QModelIndexList selectedIndexes = iMultiDeleteDialog->selectedModelIndexes(); |
350 if (!selectedIndexes.empty()) |
247 if (!selectedIndexes.empty()) |
351 { |
248 { |
352 if (!iIconIndexArray.empty()) |
|
353 { |
|
354 iIsdsClient->isdsLogoDownCancelTransaction(); |
|
355 iConvertTimer->stop(); |
|
356 } |
|
357 |
|
358 if(!iModel->deleteMultiFavorites(selectedIndexes)) |
249 if(!iModel->deleteMultiFavorites(selectedIndexes)) |
359 { |
250 { |
360 #ifdef SUBTITLE_STR_BY_LOCID |
251 #ifdef SUBTITLE_STR_BY_LOCID |
361 popupNote(hbTrId("txt_irad_info_operation_failed"), HbMessageBox::MessageTypeWarning); |
252 popupNote(hbTrId("txt_irad_info_operation_failed"), HbMessageBox::MessageTypeWarning); |
362 #else |
253 #else |
363 popupNote(hbTrId("Operation failed"), HbMessageBox::MessageTypeWarning); |
254 popupNote(hbTrId("Operation failed"), HbMessageBox::MessageTypeWarning); |
364 #endif |
255 #endif |
365 } |
256 } |
366 |
257 |
367 updateIconIndexArray(); |
|
368 #ifdef SUBTITLE_STR_BY_LOCID |
258 #ifdef SUBTITLE_STR_BY_LOCID |
369 QString headingStr = hbTrId("txt_irad_subtitle_favorites") + " (" + QString::number(iModel->rowCount()) + ")"; |
259 QString headingStr = hbTrId("txt_irad_subtitle_favorites") + " (" + QString::number(iModel->rowCount()) + ")"; |
370 #else |
260 #else |
371 QString headingStr = hbTrId("Favorites") + " (" + QString::number(iModel->rowCount()) + ")"; |
261 QString headingStr = hbTrId("Favorites") + " (" + QString::number(iModel->rowCount()) + ")"; |
372 #endif |
262 #endif |
373 setHeadingText(headingStr); |
263 setHeadingText(headingStr); |
374 |
|
375 if (!iIconIndexArray.empty()) |
|
376 { |
|
377 iConvertTimer->start(); |
|
378 } |
|
379 } |
264 } |
380 } |
265 } |
381 } |
266 } |
382 |
267 |
383 void IRFavoritesView::actionClicked(HbAction *aAction) |
268 void IRFavoritesView::actionClicked(HbAction *aAction) |
461 iStationShare = new IRStationShare(); |
346 iStationShare = new IRStationShare(); |
462 } |
347 } |
463 iStationShare->shareStations(*iModel->getPreset(current)); |
348 iStationShare->shareStations(*iModel->getPreset(current)); |
464 } |
349 } |
465 |
350 |
466 void IRFavoritesView::updateIconIndexArray() |
|
467 { |
|
468 iIconIndexArray.clear(); |
|
469 |
|
470 for (int i = 0; i < iModel->rowCount(); ++i) |
|
471 { |
|
472 if (iModel->getImgUrl(i) != "" |
|
473 && !iModel->isLogoReady(i)) |
|
474 { |
|
475 iIconIndexArray.append(i); |
|
476 } |
|
477 } |
|
478 } |
|
479 |
|
480 void IRFavoritesView::renameContextAction() |
351 void IRFavoritesView::renameContextAction() |
481 { |
352 { |
482 int current = iListView->currentIndex().row(); |
353 int current = iListView->currentIndex().row(); |
483 IRQPreset *preset = iModel->getPreset(current); |
354 IRQPreset *preset = iModel->getPreset(current); |
484 |
355 |
487 dlg->setPromptText(hbTrId("txt_common_menu_rename_item")); |
358 dlg->setPromptText(hbTrId("txt_common_menu_rename_item")); |
488 #else |
359 #else |
489 dlg->setPromptText(hbTrId("Rename")); |
360 dlg->setPromptText(hbTrId("Rename")); |
490 #endif |
361 #endif |
491 HbLineEdit* lineEdit = dlg->lineEdit(); |
362 HbLineEdit* lineEdit = dlg->lineEdit(); |
492 lineEdit->setMaxLength(256); |
363 lineEdit->setMaxLength(KMaxLineEditLength); |
493 dlg->setInputMode(HbInputDialog::TextInput); |
364 dlg->setInputMode(HbInputDialog::TextInput); |
494 dlg->setValue(preset->name); |
365 dlg->setValue(preset->nickName); |
495 dlg->setAttribute(Qt::WA_DeleteOnClose); |
366 dlg->setAttribute(Qt::WA_DeleteOnClose); |
496 dlg->open(this, SLOT(renameConfirmed(HbAction*))); |
367 dlg->open(this, SLOT(renameConfirmed(HbAction*))); |
497 } |
368 } |
498 |
369 |
499 void IRFavoritesView::detailsContextAction() |
370 void IRFavoritesView::detailsContextAction() |
507 getViewManager()->activateView(EIRView_StationDetailsView); |
378 getViewManager()->activateView(EIRView_StationDetailsView); |
508 } |
379 } |
509 |
380 |
510 void IRFavoritesView::deleteContextAction() |
381 void IRFavoritesView::deleteContextAction() |
511 { |
382 { |
512 if (!iIconIndexArray.empty()) |
|
513 { |
|
514 iIsdsClient->isdsLogoDownCancelTransaction(); |
|
515 iConvertTimer->stop(); |
|
516 } |
|
517 |
|
518 int current = iListView->currentIndex().row(); |
383 int current = iListView->currentIndex().row(); |
519 if (iModel->deleteOneFavorite(current)) |
384 if (iModel->deleteOneFavorite(current)) |
520 { |
385 { |
521 updateIconIndexArray(); |
|
522 #ifdef SUBTITLE_STR_BY_LOCID |
386 #ifdef SUBTITLE_STR_BY_LOCID |
523 QString headingStr = hbTrId("txt_irad_subtitle_favorites") + " (" + QString::number(iModel->rowCount()) + ")"; |
387 QString headingStr = hbTrId("txt_irad_subtitle_favorites") + " (" + QString::number(iModel->rowCount()) + ")"; |
524 #else |
388 #else |
525 QString headingStr = hbTrId("Favorites") + " (" + QString::number(iModel->rowCount()) + ")"; |
389 QString headingStr = hbTrId("Favorites") + " (" + QString::number(iModel->rowCount()) + ")"; |
526 #endif |
390 #endif |
531 #ifdef SUBTITLE_STR_BY_LOCID |
395 #ifdef SUBTITLE_STR_BY_LOCID |
532 popupNote(hbTrId("txt_irad_info_operation_failed"), HbMessageBox::MessageTypeWarning); |
396 popupNote(hbTrId("txt_irad_info_operation_failed"), HbMessageBox::MessageTypeWarning); |
533 #else |
397 #else |
534 popupNote(hbTrId("Operation failed"), HbMessageBox::MessageTypeWarning); |
398 popupNote(hbTrId("Operation failed"), HbMessageBox::MessageTypeWarning); |
535 #endif |
399 #endif |
536 } |
400 } |
537 |
|
538 if (!iIconIndexArray.empty()) |
|
539 { |
|
540 iConvertTimer->start(); |
|
541 } |
|
542 } |
401 } |
543 |
402 |
544 void IRFavoritesView::renameConfirmed(HbAction *aAction) |
403 void IRFavoritesView::renameConfirmed(HbAction *aAction) |
545 { |
404 { |
546 HbInputDialog *dialog = static_cast<HbInputDialog*>(sender()); |
405 HbInputDialog *dialog = static_cast<HbInputDialog*>(sender()); |
586 } |
445 } |
587 } |
446 } |
588 } |
447 } |
589 } |
448 } |
590 |
449 |
591 void IRFavoritesView::initToolBar() |
|
592 { |
|
593 //add HbActions to the toolbar, the HbActions have been created in IrAbstractListViewBase |
|
594 HbToolBar *viewToolBar = toolBar(); |
|
595 viewToolBar->addAction(iGenresAction); |
|
596 viewToolBar->addAction(iCollectionsAction); |
|
597 viewToolBar->addAction(iFavoritesAction); |
|
598 viewToolBar->addAction(iSearchAction); |
|
599 } |
|
600 |
|
601 void IRFavoritesView::popupDeleteContextConfirmMessageBox() |
450 void IRFavoritesView::popupDeleteContextConfirmMessageBox() |
602 { |
451 { |
603 #ifdef SUBTITLE_STR_BY_LOCID |
452 #ifdef SUBTITLE_STR_BY_LOCID |
604 HbMessageBox::question(hbTrId("txt_irad_info_delete_station"), this, SLOT(deleteContext(HbAction*)), HbMessageBox::Ok | HbMessageBox::Cancel); |
453 HbMessageBox::question(hbTrId("txt_irad_info_delete_station"), this, SLOT(deleteContext(HbAction*)), HbMessageBox::Ok | HbMessageBox::Cancel); |
605 #else |
454 #else |