31 #include "irfavoritesmodel.h" |
34 #include "irfavoritesmodel.h" |
32 #include "irqenums.h" |
35 #include "irqenums.h" |
33 #include "irqisdsdatastructure.h" |
36 #include "irqisdsdatastructure.h" |
34 #include "irqutility.h" |
37 #include "irqutility.h" |
35 #include "iruidefines.h" |
38 #include "iruidefines.h" |
36 |
39 #include "irstationshare.h" |
|
40 #include "irstationdetailsview.h" |
37 const int KBitmapSize = 59; |
41 const int KBitmapSize = 59; |
38 |
42 |
39 const QString KActionShareName("Share"); |
43 const QString KActionShareName("Share"); |
40 const QString KActionDeleteName("Delete"); |
44 const QString KActionDeleteName("Delete"); |
41 const QString KActionRenameName("Rename"); |
45 const QString KActionRenameName("Rename"); |
42 const QString KActionDetailsName("Details"); |
46 const QString KActionDetailsName("Details"); |
|
47 |
43 |
48 |
44 // public functions |
49 // public functions |
45 |
50 |
46 /* |
51 /* |
47 * Description : constructor |
52 * Description : constructor |
48 */ |
53 */ |
49 IRFavoritesView::IRFavoritesView(IRApplication *aApplication, TIRViewId aViewId) |
54 IRFavoritesView::IRFavoritesView(IRApplication *aApplication, TIRViewId aViewId) |
50 : IrAbstractListViewBase(aApplication, aViewId), |
55 : IrAbstractListViewBase(aApplication, aViewId), |
51 iClearFavoriteAction(NULL),iLogoPreset(NULL) |
56 iStationShare(NULL), |
|
57 iMultiDeleteDialog(NULL), |
|
58 iMultiDeleteAction(NULL), |
|
59 iLogoPreset(NULL) |
52 { |
60 { |
53 setFlag(EViewFlag_ClearStackWhenActivate); |
61 setFlag(EViewFlag_ClearStackWhenActivate|EViewFlag_StickyViewEnabled); |
54 |
62 |
55 //if this view is not starting view, finish all initialization in constructor |
63 //if this view is not starting view, finish all initialization in constructor |
56 if (getViewManager()->views().count() > 0) |
64 if (getViewManager()->views().count() > 0) |
57 { |
65 { |
58 normalInit(); |
66 normalInit(); |
80 TIRHandleResult ret = IrAbstractListViewBase::handleCommand(aCommand, aReason); |
94 TIRHandleResult ret = IrAbstractListViewBase::handleCommand(aCommand, aReason); |
81 int leftCount = 0; |
95 int leftCount = 0; |
82 |
96 |
83 switch (aCommand) |
97 switch (aCommand) |
84 { |
98 { |
|
99 case EIR_ViewCommand_TOBEACTIVATED: |
|
100 iModel->checkFavoritesUpdate(); |
|
101 ret = EIR_NoDefault; |
|
102 break; |
|
103 |
85 case EIR_ViewCommand_ACTIVATED: |
104 case EIR_ViewCommand_ACTIVATED: |
86 connect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset* )), |
105 connect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset* )), |
87 this, SLOT(presetLogoDownload(IRQPreset* ))); |
106 this, SLOT(presetLogoDownload(IRQPreset* ))); |
88 connect(iIsdsClient, SIGNAL(presetLogoDownloadError()), |
107 connect(iIsdsClient, SIGNAL(presetLogoDownloadError()), |
89 this, SLOT(presetLogoDownloadError())); |
108 this, SLOT(presetLogoDownloadError())); |
90 |
109 |
91 iModel->checkFavoritesUpdate(); |
|
92 |
|
93 leftCount = iIconIndexArray.count(); |
110 leftCount = iIconIndexArray.count(); |
94 if( leftCount > 0 ) |
111 if( leftCount > 0 ) |
95 { |
112 { |
96 iConvertTimer->start(); |
113 iConvertTimer->start(); |
97 } |
114 } |
|
115 |
|
116 getViewManager()->saveScreenShot(); |
98 ret = EIR_NoDefault; |
117 ret = EIR_NoDefault; |
99 break; |
118 break; |
100 |
119 |
101 case EIR_ViewCommand_DEACTIVATE: |
120 case EIR_ViewCommand_DEACTIVATE: |
102 |
121 |
173 } |
202 } |
174 } |
203 } |
175 } |
204 } |
176 |
205 |
177 // --------------------------------------------------------------------------- |
206 // --------------------------------------------------------------------------- |
178 // IRFavoritesView::clearAllList() |
207 // IRFavoritesView::deleteFavorites() |
179 //--------------------------------------------------------------------------- |
208 //--------------------------------------------------------------------------- |
180 void IRFavoritesView::clearAllFavorites() |
209 void IRFavoritesView::deleteFavorites() |
181 { |
210 { |
182 iIconIndexArray.clear(); |
211 if (NULL == iMultiDeleteDialog) |
183 iModel->clearFavoriteDB(); |
212 { |
184 iIsdsClient->isdsLogoDownCancelTransaction(); |
213 iMultiDeleteDialog = new HbSelectionDialog; |
185 iConvertTimer->stop(); |
214 iMultiDeleteDialog->setSelectionMode(HbAbstractItemView::MultiSelection); |
|
215 |
|
216 HbGroupBox * header = new HbGroupBox; |
|
217 #ifdef SUBTITLE_STR_BY_LOCID |
|
218 header->setHeading(hbTrId("txt_irad_subtitle_select_items_to_delete")); |
|
219 #else |
|
220 header->setHeading(hbTrId("Select items to delete")); |
|
221 #endif |
|
222 iMultiDeleteDialog->setHeadingWidget(header); |
|
223 |
|
224 |
|
225 QList<QAction *> oriActions = iMultiDeleteDialog->actions(); |
|
226 for(int i = 0; i< oriActions.count(); i++) |
|
227 { |
|
228 iMultiDeleteDialog->removeAction(oriActions.at(i)); |
|
229 delete oriActions.at(i); |
|
230 } |
|
231 |
|
232 #ifdef SUBTITLE_STR_BY_LOCID |
|
233 iMultiDeleteDialog->addAction(new HbAction(hbTrId("txt_common_button_delete"))); |
|
234 iMultiDeleteDialog->addAction(new HbAction(hbTrId("txt_common_button_cancel"))); |
|
235 #else |
|
236 iMultiDeleteDialog->addAction(new HbAction(hbTrId("Delete"))); |
|
237 iMultiDeleteDialog->addAction(new HbAction(hbTrId("Cancel"))); |
|
238 #endif |
|
239 } |
|
240 |
|
241 iMultiDeleteDialog->setModel(iModel); |
|
242 iMultiDeleteDialog->open(this,SLOT(deleteDialogClosed(HbAction*))); |
186 } |
243 } |
187 |
244 |
188 void IRFavoritesView::networkRequestNotified(IRQNetworkEvent aEvent) |
245 void IRFavoritesView::networkRequestNotified(IRQNetworkEvent aEvent) |
189 { |
246 { |
190 if (getViewManager()->currentView() != this) |
247 if (getViewManager()->currentView() != this) |
193 } |
250 } |
194 |
251 |
195 switch (aEvent) |
252 switch (aEvent) |
196 { |
253 { |
197 case EIRQNetworkConnectionEstablished: |
254 case EIRQNetworkConnectionEstablished: |
198 iApplication->closeConnectingDialog(); |
|
199 if (EIR_UseNetwork_SelectItem == getUseNetworkReason()) |
255 if (EIR_UseNetwork_SelectItem == getUseNetworkReason()) |
200 { |
256 { |
201 handleItemSelected(); |
257 handleItemSelected(); |
202 } |
258 } |
203 |
|
204 setUseNetworkReason(EIR_UseNetwork_NoReason); |
|
205 break; |
259 break; |
206 |
260 |
207 default: |
261 default: |
208 setCheckedAction(); |
262 setCheckedAction(); |
209 break; |
263 break; |
210 } |
264 } |
|
265 |
|
266 setUseNetworkReason(EIR_UseNetwork_NoReason); |
211 } |
267 } |
212 |
268 |
213 void IRFavoritesView::prepareMenu() |
269 void IRFavoritesView::prepareMenu() |
214 { |
270 { |
215 if (NULL == iClearFavoriteAction) |
271 if (NULL == iMultiDeleteAction) |
216 { |
272 { |
217 iClearFavoriteAction = new HbAction(hbTrId("txt_irad_opt_clear_favorites"), menu()); |
273 #ifdef SUBTITLE_STR_BY_LOCID |
218 connect(iClearFavoriteAction, SIGNAL(triggered()), this, SLOT(clearAllFavorites())); |
274 iMultiDeleteAction = new HbAction(hbTrId("txt_irad_opt_delete_stations"), menu()); |
219 } |
275 #else |
220 |
276 iMultiDeleteAction = new HbAction(hbTrId("Delete stations"), menu()); |
|
277 #endif |
|
278 connect(iMultiDeleteAction, SIGNAL(triggered()), this, SLOT(deleteFavorites())); |
|
279 } |
|
280 |
221 HbMenu *viewMenu = menu(); |
281 HbMenu *viewMenu = menu(); |
222 |
282 |
223 viewMenu->removeAction(iClearFavoriteAction); |
283 viewMenu->removeAction(iMultiDeleteAction); |
224 |
284 |
225 HbAction * settingAction = qobject_cast<HbAction *>(iLoader.findObject(SETTINGS_ACTION)); |
285 HbAction * settingAction = qobject_cast<HbAction *>(iLoader.findObject(SETTINGS_ACTION)); |
226 |
286 |
227 if (iModel->rowCount() > 0) |
287 if (iModel->rowCount() > 0) |
228 { |
288 { |
229 viewMenu->insertAction(settingAction, iClearFavoriteAction); |
289 viewMenu->insertAction(settingAction, iMultiDeleteAction); |
230 } |
290 } |
231 } |
291 } |
232 |
292 |
233 void IRFavoritesView::startConvert(int aIndex) |
293 void IRFavoritesView::startConvert(int aIndex) |
234 { |
294 { |
300 } |
360 } |
301 } |
361 } |
302 |
362 |
303 void IRFavoritesView::modelChanged() |
363 void IRFavoritesView::modelChanged() |
304 { |
364 { |
305 QString headingStr = QString::number(iModel->rowCount()) + QString(" ") + hbTrId("txt_irad_subtitle_stations"); |
365 #ifdef SUBTITLE_STR_BY_LOCID |
|
366 QString headingStr = hbTrId("txt_irad_subtitle_favorites") + " (" + QString::number(iModel->rowCount()) + ")"; |
|
367 #else |
|
368 QString headingStr = hbTrId("Favorites") + " (" + QString::number(iModel->rowCount()) + ")"; |
|
369 #endif |
306 setHeadingText(headingStr); |
370 setHeadingText(headingStr); |
307 iIconIndexArray.clear(); |
371 updateIconIndexArray(); |
308 |
|
309 for (int i = 0; i < iModel->rowCount(); ++i) |
|
310 { |
|
311 if (iModel->getImgUrl(i) != "") |
|
312 { |
|
313 iIconIndexArray.append(i); |
|
314 } |
|
315 } |
|
316 |
372 |
317 iListView->reset(); |
373 iListView->reset(); |
318 iListView->setCurrentIndex(iModel->index(0)); |
374 iListView->setCurrentIndex(iModel->index(0)); |
|
375 } |
|
376 |
|
377 void IRFavoritesView::deleteDialogClosed(HbAction *aAction) |
|
378 { |
|
379 if (iMultiDeleteDialog->actions().at(0) == aAction) |
|
380 { |
|
381 QModelIndexList selectedIndexes = iMultiDeleteDialog->selectedModelIndexes(); |
|
382 if (!selectedIndexes.empty()) |
|
383 { |
|
384 if (!iIconIndexArray.empty()) |
|
385 { |
|
386 iIsdsClient->isdsLogoDownCancelTransaction(); |
|
387 iConvertTimer->stop(); |
|
388 } |
|
389 |
|
390 if(!iModel->deleteMultiFavorites(selectedIndexes)) |
|
391 { |
|
392 #ifdef SUBTITLE_STR_BY_LOCID |
|
393 popupNote(hbTrId("txt_irad_info_operation_failed"), HbMessageBox::MessageTypeWarning); |
|
394 #else |
|
395 popupNote(hbTrId("Operation failed"), HbMessageBox::MessageTypeWarning); |
|
396 #endif |
|
397 } |
|
398 |
|
399 updateIconIndexArray(); |
|
400 #ifdef SUBTITLE_STR_BY_LOCID |
|
401 QString headingStr = hbTrId("txt_irad_subtitle_favorites") + " (" + QString::number(iModel->rowCount()) + ")"; |
|
402 #else |
|
403 QString headingStr = hbTrId("Favorites") + " (" + QString::number(iModel->rowCount()) + ")"; |
|
404 #endif |
|
405 setHeadingText(headingStr); |
|
406 |
|
407 if (!iIconIndexArray.empty()) |
|
408 { |
|
409 iConvertTimer->start(); |
|
410 } |
|
411 } |
|
412 } |
|
413 iMultiDeleteDialog->setModel(NULL); |
319 } |
414 } |
320 |
415 |
321 void IRFavoritesView::actionClicked(HbAction *aAction) |
416 void IRFavoritesView::actionClicked(HbAction *aAction) |
322 { |
417 { |
323 if ( aAction ) |
418 if ( aAction ) |
360 |
455 |
361 HbMenu *contextMenu = new HbMenu(); |
456 HbMenu *contextMenu = new HbMenu(); |
362 contextMenu->setAttribute(Qt::WA_DeleteOnClose); |
457 contextMenu->setAttribute(Qt::WA_DeleteOnClose); |
363 connect(contextMenu, SIGNAL(triggered(HbAction*)), this, SLOT(actionClicked(HbAction*))); |
458 connect(contextMenu, SIGNAL(triggered(HbAction*)), this, SLOT(actionClicked(HbAction*))); |
364 |
459 |
365 action = contextMenu->addAction(hbTrId("txt_irad_opt_share_station")); |
460 #ifdef SUBTITLE_STR_BY_LOCID |
|
461 action = contextMenu->addAction(hbTrId("txt_irad_opt_share")); |
|
462 #else |
|
463 action = contextMenu->addAction(hbTrId("Share")); |
|
464 #endif |
366 action->setObjectName(KActionShareName); |
465 action->setObjectName(KActionShareName); |
|
466 #ifdef SUBTITLE_STR_BY_LOCID |
367 action = contextMenu->addAction(hbTrId("txt_common_menu_delete")); |
467 action = contextMenu->addAction(hbTrId("txt_common_menu_delete")); |
|
468 #else |
|
469 action = contextMenu->addAction(hbTrId("Delete")); |
|
470 #endif |
368 action->setObjectName(KActionDeleteName); |
471 action->setObjectName(KActionDeleteName); |
|
472 #ifdef SUBTITLE_STR_BY_LOCID |
369 action = contextMenu->addAction(hbTrId("txt_common_menu_rename_item")); |
473 action = contextMenu->addAction(hbTrId("txt_common_menu_rename_item")); |
|
474 #else |
|
475 action = contextMenu->addAction(hbTrId("Rename")); |
|
476 #endif |
370 action->setObjectName(KActionRenameName); |
477 action->setObjectName(KActionRenameName); |
|
478 #ifdef SUBTITLE_STR_BY_LOCID |
371 action = contextMenu->addAction(hbTrId("txt_common_menu_details")); |
479 action = contextMenu->addAction(hbTrId("txt_common_menu_details")); |
|
480 #else |
|
481 action = contextMenu->addAction(hbTrId("Details")); |
|
482 #endif |
372 action->setObjectName(KActionDetailsName); |
483 action->setObjectName(KActionDetailsName); |
373 |
484 |
374 contextMenu->open(); |
485 contextMenu->open(); |
375 } |
486 } |
376 |
487 |
377 void IRFavoritesView::shareContextAction() |
488 void IRFavoritesView::shareContextAction() |
378 { |
489 { |
379 |
490 int current = iListView->currentIndex().row(); |
|
491 |
|
492 if (NULL == iStationShare) |
|
493 { |
|
494 iStationShare = new IRStationShare(); |
|
495 } |
|
496 iStationShare->shareStations(*iModel->getPreset(current)); |
|
497 } |
|
498 |
|
499 void IRFavoritesView::updateIconIndexArray() |
|
500 { |
|
501 iIconIndexArray.clear(); |
|
502 |
|
503 for (int i = 0; i < iModel->rowCount(); ++i) |
|
504 { |
|
505 if (iModel->getImgUrl(i) != "" |
|
506 && !iModel->isLogoReady(i)) |
|
507 { |
|
508 iIconIndexArray.append(i); |
|
509 } |
|
510 } |
380 } |
511 } |
381 |
512 |
382 void IRFavoritesView::renameContextAction() |
513 void IRFavoritesView::renameContextAction() |
383 { |
514 { |
384 |
515 int current = iListView->currentIndex().row(); |
|
516 IRQPreset *preset = iModel->getPreset(current); |
|
517 #ifdef SUBTITLE_STR_BY_LOCID |
|
518 HbInputDialog::getText(hbTrId("txt_common_menu_rename_item"), this, SLOT(renameConfirmed(HbAction*)), preset->name); |
|
519 #else |
|
520 HbInputDialog::getText(hbTrId("Rename"), this, SLOT(renameConfirmed(HbAction*)), preset->name); |
|
521 #endif |
385 } |
522 } |
386 |
523 |
387 void IRFavoritesView::detailsContextAction() |
524 void IRFavoritesView::detailsContextAction() |
388 { |
525 { |
389 |
526 int selectedItemIndex = iListView->currentIndex().row(); |
|
527 IRQPreset *channelPreset = iModel->getPreset(selectedItemIndex); |
|
528 |
|
529 IRStationDetailsView *stationDetailsView = static_cast<IRStationDetailsView*>(getViewManager()->getView(EIRView_StationDetailsView, true)); |
|
530 stationDetailsView->setDetails(channelPreset); |
|
531 |
|
532 getViewManager()->activateView(EIRView_StationDetailsView); |
390 } |
533 } |
391 |
534 |
392 void IRFavoritesView::deleteContextAction() |
535 void IRFavoritesView::deleteContextAction() |
393 { |
536 { |
394 int current = iListView->currentIndex().row(); |
537 if (!iIconIndexArray.empty()) |
395 bool ret = iModel->deleteOneFavorite(current); |
538 { |
396 if ( !ret ) |
539 iIsdsClient->isdsLogoDownCancelTransaction(); |
397 { |
540 iConvertTimer->stop(); |
398 popupNote(hbTrId("txt_irad_info_operation_failed"), HbMessageBox::MessageTypeWarning); |
541 } |
399 } |
542 |
|
543 int current = iListView->currentIndex().row(); |
|
544 if (iModel->deleteOneFavorite(current)) |
|
545 { |
|
546 updateIconIndexArray(); |
|
547 #ifdef SUBTITLE_STR_BY_LOCID |
|
548 QString headingStr = hbTrId("txt_irad_subtitle_favorites") + " (" + QString::number(iModel->rowCount()) + ")"; |
|
549 #else |
|
550 QString headingStr = hbTrId("Favorites") + " (" + QString::number(iModel->rowCount()) + ")"; |
|
551 #endif |
|
552 setHeadingText(headingStr); |
|
553 } |
|
554 else |
|
555 { |
|
556 #ifdef SUBTITLE_STR_BY_LOCID |
|
557 popupNote(hbTrId("txt_irad_info_operation_failed"), HbMessageBox::MessageTypeWarning); |
|
558 #else |
|
559 popupNote(hbTrId("Operation failed"), HbMessageBox::MessageTypeWarning); |
|
560 #endif |
|
561 } |
|
562 |
|
563 if (!iIconIndexArray.empty()) |
|
564 { |
|
565 iConvertTimer->start(); |
|
566 } |
|
567 } |
|
568 |
|
569 void IRFavoritesView::renameConfirmed(HbAction *aAction) |
|
570 { |
|
571 HbInputDialog *dialog = static_cast<HbInputDialog*>(sender()); |
|
572 if (dialog) |
|
573 { |
|
574 if (aAction == dialog->actions().at(0)) |
|
575 { |
|
576 int current = iListView->currentIndex().row(); |
|
577 IRQPreset *preset = iModel->getPreset(current); |
|
578 |
|
579 QString newName = dialog->value().toString().trimmed(); |
|
580 if (newName.isEmpty()) |
|
581 { |
|
582 #ifdef SUBTITLE_STR_BY_LOCID |
|
583 newName = hbTrId("txt_irad_info_unnamed_station"); |
|
584 #else |
|
585 newName = hbTrId("Unnamed station"); |
|
586 #endif |
|
587 } |
|
588 |
|
589 if (newName == preset->name) |
|
590 { |
|
591 return; |
|
592 } |
|
593 |
|
594 int ret = iFavorites->renamePreset(*preset, newName); |
|
595 switch (ret) |
|
596 { |
|
597 case EIRQErrorNotFound: |
|
598 //popup note : not found |
|
599 break; |
|
600 |
|
601 case EIRQErrorAlreadyExist: |
|
602 //popup note : already exists |
|
603 break; |
|
604 |
|
605 case EIRQErrorNone: |
|
606 iModel->updateFavoriteName(current, newName); |
|
607 break; |
|
608 |
|
609 default: |
|
610 break; |
|
611 } |
|
612 } |
|
613 } |
400 } |
614 } |
401 |
615 |
402 void IRFavoritesView::initToolBar() |
616 void IRFavoritesView::initToolBar() |
403 { |
617 { |
404 //add HbActions to the toolbar, the HbActions have been created in IrAbstractListViewBase |
618 //add HbActions to the toolbar, the HbActions have been created in IrAbstractListViewBase |