16 */ |
16 */ |
17 #include <hblistview.h> |
17 #include <hblistview.h> |
18 #include <hbmenu.h> |
18 #include <hbmenu.h> |
19 #include <hbaction.h> |
19 #include <hbaction.h> |
20 #include <hbnotificationdialog.h> |
20 #include <hbnotificationdialog.h> |
21 #include <QPixmap> |
|
22 #include <QTimer> |
|
23 |
21 |
24 #include "irviewmanager.h" |
22 #include "irviewmanager.h" |
25 #include "irapplication.h" |
23 #include "irapplication.h" |
26 #include "irqisdsclient.h" |
24 #include "irqisdsclient.h" |
27 #include "irplaycontroller.h" |
25 #include "irplaycontroller.h" |
28 #include "irhistoryview.h" |
26 #include "irhistoryview.h" |
29 #include "irqisdsdatastructure.h" |
27 #include "irqisdsdatastructure.h" |
30 #include "irhistorymodel.h" |
28 #include "irhistorymodel.h" |
31 #include "irqsonghistoryinfo.h" |
|
32 #include "irqnetworkcontroller.h" |
29 #include "irqnetworkcontroller.h" |
33 #include "irqutility.h" |
|
34 #include "irqenums.h" |
30 #include "irqenums.h" |
35 #include "irqfavoritesdb.h" |
31 #include "irqfavoritesdb.h" |
36 #include "irstationdetailsview.h" |
32 #include "irstationdetailsview.h" |
37 #include "iruidefines.h" |
33 #include "iruidefines.h" |
38 |
34 |
39 |
35 |
40 const int KBitmapSize = 59; |
|
41 const QString KActionAddName("Add"); |
36 const QString KActionAddName("Add"); |
42 const QString KActionDeleteName("Delete"); |
37 const QString KActionDeleteName("Delete"); |
43 const QString KActionDetailsName("Details"); |
38 const QString KActionDetailsName("Details"); |
44 |
39 |
45 // public functions |
40 // public functions |
46 |
41 |
47 /* |
42 /* |
48 * Description : constructor |
43 * Description : constructor |
49 */ |
44 */ |
50 IRHistoryView::IRHistoryView(IRApplication *aApplication, TIRViewId aViewId) : |
45 IRHistoryView::IRHistoryView(IRApplication *aApplication, TIRViewId aViewId) : |
51 IrAbstractListViewBase(aApplication, aViewId), iClearHistoryAction(NULL), |
46 IrAbstractListViewBase(aApplication, aViewId), iClearHistoryAction(NULL) |
52 iLogoPreset(NULL) |
|
53 { |
47 { |
54 iModel = new IRHistoryModel(this); |
48 iModel = new IRHistoryModel(this); |
55 iListView->setModel(iModel); |
49 iListView->setModel(iModel); |
56 iListView->setCurrentIndex(iModel->index(0)); |
50 iListView->setCurrentIndex(iModel->index(0)); |
57 |
51 |
59 iClearHistoryAction = new HbAction(hbTrId("txt_irad_opt_clear_list"), menu()); |
53 iClearHistoryAction = new HbAction(hbTrId("txt_irad_opt_clear_list"), menu()); |
60 #else |
54 #else |
61 iClearHistoryAction = new HbAction(hbTrId("Clear list"), menu()); |
55 iClearHistoryAction = new HbAction(hbTrId("Clear list"), menu()); |
62 #endif |
56 #endif |
63 |
57 |
64 iConvertTimer = new QTimer(this); |
|
65 iConvertTimer->setInterval(10); |
|
66 |
|
67 connect(iClearHistoryAction, SIGNAL(triggered()), this, SLOT(popupClearHistoryConfirmMessageBox())); |
58 connect(iClearHistoryAction, SIGNAL(triggered()), this, SLOT(popupClearHistoryConfirmMessageBox())); |
68 connect(iNetworkController, SIGNAL(networkRequestNotified(IRQNetworkEvent)), |
59 connect(iNetworkController, SIGNAL(networkRequestNotified(IRQNetworkEvent)), |
69 this, SLOT(networkRequestNotified(IRQNetworkEvent))); |
60 this, SLOT(networkRequestNotified(IRQNetworkEvent))); |
70 connect(iModel, SIGNAL(modelChanged()), this, SLOT(modelChanged())); |
61 connect(iModel, SIGNAL(modelChanged()), this, SLOT(modelChanged())); |
71 connect(iConvertTimer, SIGNAL(timeout()), this, SLOT(convertAnother())); |
|
72 } |
62 } |
73 void IRHistoryView::popupClearHistoryConfirmMessageBox() |
63 void IRHistoryView::popupClearHistoryConfirmMessageBox() |
74 { |
64 { |
75 #ifdef SUBTITLE_STR_BY_LOCID |
65 #ifdef SUBTITLE_STR_BY_LOCID |
76 HbMessageBox::question(hbTrId("txt_irad_info_clear_station_list"), this, SLOT(clearAllList(HbAction*)), HbMessageBox::Ok | HbMessageBox::Cancel); |
66 HbMessageBox::question(hbTrId("txt_irad_info_clear_station_list"), this, SLOT(clearAllList(HbAction*)), HbMessageBox::Ok | HbMessageBox::Cancel); |
96 TIRHandleResult IRHistoryView::handleCommand(TIRViewCommand aCommand, |
84 TIRHandleResult IRHistoryView::handleCommand(TIRViewCommand aCommand, |
97 TIRViewCommandReason aReason) |
85 TIRViewCommandReason aReason) |
98 { |
86 { |
99 Q_UNUSED(aReason); |
87 Q_UNUSED(aReason); |
100 TIRHandleResult ret = IrAbstractListViewBase::handleCommand(aCommand, aReason); |
88 TIRHandleResult ret = IrAbstractListViewBase::handleCommand(aCommand, aReason); |
101 int leftCount = 0; |
|
102 |
89 |
103 switch (aCommand) |
90 switch (aCommand) |
104 { |
91 { |
105 |
92 |
106 case EIR_ViewCommand_TOBEACTIVATED: |
93 case EIR_ViewCommand_TOBEACTIVATED: |
107 showHistory(); |
94 showHistory(); |
108 ret = EIR_NoDefault; |
95 ret = EIR_NoDefault; |
109 break; |
96 break; |
110 |
97 |
111 case EIR_ViewCommand_ACTIVATED: |
98 case EIR_ViewCommand_ACTIVATED: |
112 connect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset* )), |
99 iModel->startDownloadingLogo(); |
113 this, SLOT(presetLogoDownload(IRQPreset* ))); |
|
114 connect(iIsdsClient, SIGNAL(presetLogoDownloadError()), |
|
115 this, SLOT(presetLogoDownloadError())); |
|
116 |
|
117 leftCount = iIconIndexArray.count(); |
|
118 if( leftCount > 0 ) |
|
119 { |
|
120 iConvertTimer->start(); |
|
121 } |
|
122 ret = EIR_NoDefault; |
100 ret = EIR_NoDefault; |
123 break; |
101 break; |
124 |
102 |
125 case EIR_ViewCommand_DEACTIVATE: |
103 case EIR_ViewCommand_DEACTIVATE: |
126 |
104 iModel->stopDownloadingLogo(); |
127 iModel->clearAndDestroyLogos(); |
|
128 iConvertTimer->stop(); |
|
129 iIsdsClient->isdsLogoDownCancelTransaction(); |
|
130 |
|
131 //iIconIndexArray must be cleared, because timer call back convertAnother() might be |
|
132 //called after view is deactivated. In that case, iModel->getImgURL(aIndex); will crash |
|
133 iIconIndexArray.clear(); |
|
134 |
|
135 disconnect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset*)), |
|
136 this, SLOT(presetLogoDownload(IRQPreset* ))); |
|
137 disconnect(iIsdsClient, SIGNAL(presetLogoDownloadError()), |
|
138 this, SLOT(presetLogoDownloadError())); |
|
139 ret = EIR_NoDefault; |
105 ret = EIR_NoDefault; |
140 break; |
106 break; |
141 |
107 |
142 default: |
108 default: |
143 break; |
109 break; |
154 * Parameters : aItem : pointer to the clicked item. |
120 * Parameters : aItem : pointer to the clicked item. |
155 */ |
121 */ |
156 void IRHistoryView::handleItemSelected() |
122 void IRHistoryView::handleItemSelected() |
157 { |
123 { |
158 int index = iListView->currentIndex().row(); |
124 int index = iListView->currentIndex().row(); |
159 IRQSongHistoryInfo *hisInfo = iModel->getHistoryInfo(index); |
125 IRQPreset *preset = iModel->getHistoryInfo(index); |
160 if (NULL == hisInfo) |
126 if (NULL == preset) |
161 { |
127 { |
162 return; |
128 return; |
163 } |
129 } |
164 |
130 |
165 IRQPreset preset; |
131 if (preset->type) |
166 convertStationHistory2Preset(*hisInfo, preset); |
|
167 |
|
168 if (hisInfo->getChannelType()) |
|
169 { |
132 { |
170 // channel from isds server |
133 // channel from isds server |
171 iPlayController->connectToChannel(&preset, EIRQHistoryIsds); |
134 iPlayController->connectToChannel(preset, EIRQHistoryIsds); |
172 } |
135 } |
173 else |
136 else |
174 { |
137 { |
175 // user defined channel |
138 // user defined channel |
176 iPlayController->connectToChannel(&preset,EIRQHistoryAdhoc); |
139 iPlayController->connectToChannel(preset,EIRQHistoryAdhoc); |
177 } |
140 } |
178 } |
141 } |
179 |
142 |
180 #ifdef HS_WIDGET_ENABLED |
143 #ifdef HS_WIDGET_ENABLED |
181 void IRHistoryView::itemAboutToBeSelected(bool &aNeedNetwork) |
144 void IRHistoryView::itemAboutToBeSelected(bool &aNeedNetwork) |
182 { |
145 { |
183 aNeedNetwork = true; |
146 aNeedNetwork = true; |
184 |
147 |
185 int index = iListView->currentIndex().row(); |
148 int index = iListView->currentIndex().row(); |
186 iPlayController->setConnectingStationName(iModel->getHistoryInfo(index)->getChannelName()); |
149 iPlayController->setConnectingStationName(iModel->getHistoryInfo(index)->nickName); |
187 } |
150 } |
188 #endif |
151 #endif |
189 |
152 |
190 void IRHistoryView::networkRequestNotified(IRQNetworkEvent aEvent) |
153 void IRHistoryView::networkRequestNotified(IRQNetworkEvent aEvent) |
191 { |
154 { |
218 void IRHistoryView::showHistory() |
181 void IRHistoryView::showHistory() |
219 { |
182 { |
220 if (iModel->checkHistoryUpdate()) |
183 if (iModel->checkHistoryUpdate()) |
221 { |
184 { |
222 iListView->reset(); |
185 iListView->reset(); |
223 iListView->setCurrentIndex(iModel->index(0)); |
186 iListView->setCurrentIndex(iModel->index(0)); |
224 |
|
225 //because we get all the history refreshed, so clear the icon array. |
|
226 iIconIndexArray.clear(); |
|
227 |
|
228 //initialize the iconindices |
|
229 for (int i = 0; i < iModel->rowCount(); ++i) |
|
230 { |
|
231 if (iModel->getImageUrl(i) != "") |
|
232 { |
|
233 iIconIndexArray.append(i); |
|
234 } |
|
235 } |
|
236 } |
187 } |
237 } |
188 } |
238 |
189 |
239 // --------------------------------------------------------------------------- |
190 // --------------------------------------------------------------------------- |
240 // IRHistoryView::clearAllList() |
191 // IRHistoryView::clearAllList() |
267 if (iModel->rowCount() > 0) |
215 if (iModel->rowCount() > 0) |
268 { |
216 { |
269 viewMenu->insertAction(settingAction, iClearHistoryAction); |
217 viewMenu->insertAction(settingAction, iClearHistoryAction); |
270 } |
218 } |
271 } |
219 } |
272 |
|
273 void IRHistoryView::startConvert(int aIndex) |
|
274 { |
|
275 QString url = iModel->getImageUrl(aIndex); |
|
276 |
|
277 IRQPreset tempPreset; |
|
278 tempPreset.imgUrl = url; |
|
279 tempPreset.type = IRQPreset::EIsds; |
|
280 iIsdsClient->isdsLogoDownSendRequest(&tempPreset, 0, KBitmapSize, KBitmapSize); |
|
281 } |
|
282 |
|
283 //if the logo is downloaded ok |
|
284 void IRHistoryView::presetLogoDownload(IRQPreset* aPreset) |
|
285 { |
|
286 if (NULL == aPreset) |
|
287 { |
|
288 presetLogoDownloadError(); |
|
289 return; |
|
290 } |
|
291 |
|
292 |
|
293 delete iLogoPreset; |
|
294 iLogoPreset = aPreset; |
|
295 |
|
296 if (iLogoPreset->logoData.size() > 0) |
|
297 { |
|
298 QPixmap tempMap; |
|
299 bool ret = tempMap.loadFromData((const unsigned char*)iLogoPreset->logoData.constData(), iLogoPreset->logoData.size()); |
|
300 if( ret ) |
|
301 { |
|
302 QIcon convertIcon(tempMap); |
|
303 HbIcon *hbIcon = new HbIcon(convertIcon); |
|
304 int index = iIconIndexArray[0]; |
|
305 iModel->setLogo(hbIcon, index); |
|
306 iIconIndexArray.removeAt(0); |
|
307 int leftCount = iIconIndexArray.count(); |
|
308 if( leftCount > 0 ) |
|
309 { |
|
310 iConvertTimer->start(); |
|
311 } |
|
312 return; |
|
313 } |
|
314 } |
|
315 |
|
316 presetLogoDownloadError(); |
|
317 } |
|
318 |
|
319 |
|
320 |
|
321 //if the logo download fails |
|
322 void IRHistoryView::presetLogoDownloadError() |
|
323 { |
|
324 // if the logo download fails, try to download the next |
|
325 iIconIndexArray.removeAt(0); |
|
326 int leftCount = 0; |
|
327 leftCount = iIconIndexArray.count(); |
|
328 if( leftCount > 0 ) |
|
329 { |
|
330 iConvertTimer->start(); |
|
331 } |
|
332 } |
|
333 |
|
334 void IRHistoryView::convertAnother() |
|
335 { |
|
336 iConvertTimer->stop(); |
|
337 int leftCount = iIconIndexArray.count(); |
|
338 |
|
339 if (0 != leftCount) |
|
340 { |
|
341 startConvert(iIconIndexArray[0]); |
|
342 } |
|
343 } |
|
344 |
220 |
345 void IRHistoryView::modelChanged() |
221 void IRHistoryView::modelChanged() |
346 { |
222 { |
347 #ifdef SUBTITLE_STR_BY_LOCID |
223 #ifdef SUBTITLE_STR_BY_LOCID |
348 QString headingStr = hbTrId("txt_irad_subtitle_recently_played_stations") + " (" + QString::number(iModel->rowCount()) + ")"; |
224 QString headingStr = hbTrId("txt_irad_subtitle_recently_played_stations") + " (" + QString::number(iModel->rowCount()) + ")"; |
374 } |
250 } |
375 |
251 |
376 void IRHistoryView::addContextAction() |
252 void IRHistoryView::addContextAction() |
377 { |
253 { |
378 QModelIndex current = iListView->currentIndex(); |
254 QModelIndex current = iListView->currentIndex(); |
379 IRQSongHistoryInfo * currentInfo = iModel->getHistoryInfo(current.row()); |
255 IRQPreset * preset = iModel->getHistoryInfo(current.row()); |
380 IRQPreset preset; |
256 int retValue = iFavorites->addPreset(*preset); |
381 convertStationHistory2Preset(*currentInfo, preset); |
|
382 int retValue = iFavorites->addPreset(preset); |
|
383 |
257 |
384 HbNotificationDialog *add2FavNote = new HbNotificationDialog(); |
258 HbNotificationDialog *add2FavNote = new HbNotificationDialog(); |
385 add2FavNote->setModal(true); |
259 add2FavNote->setModal(true); |
386 add2FavNote->setTimeout(HbPopup::ConfirmationNoteTimeout); |
260 add2FavNote->setTimeout(HbPopup::ConfirmationNoteTimeout); |
387 add2FavNote->setAttribute(Qt::WA_DeleteOnClose); |
261 add2FavNote->setAttribute(Qt::WA_DeleteOnClose); |
425 } |
299 } |
426 |
300 |
427 void IRHistoryView::deleteContextAction() |
301 void IRHistoryView::deleteContextAction() |
428 { |
302 { |
429 int current = iListView->currentIndex().row(); |
303 int current = iListView->currentIndex().row(); |
430 bool ret = iModel->deleteOneItem(current); |
304 bool ret = iModel->deleteHistory(current); |
431 if( !ret ) |
305 if( !ret ) |
432 { |
306 { |
433 #ifdef SUBTITLE_STR_BY_LOCID |
307 #ifdef SUBTITLE_STR_BY_LOCID |
434 popupNote(hbTrId("txt_irad_info_operation_failed"), HbMessageBox::MessageTypeWarning); |
308 popupNote(hbTrId("txt_irad_info_operation_failed"), HbMessageBox::MessageTypeWarning); |
435 #else |
309 #else |
438 } |
312 } |
439 } |
313 } |
440 void IRHistoryView::detailsContextAction() |
314 void IRHistoryView::detailsContextAction() |
441 { |
315 { |
442 int selectedItemIndex = iListView->currentIndex().row(); |
316 int selectedItemIndex = iListView->currentIndex().row(); |
443 IRQSongHistoryInfo *channelDetailInfo = iModel->getHistoryInfo(selectedItemIndex); |
317 IRQPreset *channelPreset = iModel->getHistoryInfo(selectedItemIndex); |
444 |
|
445 IRQPreset channelPreset; |
|
446 convertStationHistory2Preset(*channelDetailInfo, channelPreset); |
|
447 |
318 |
448 IRStationDetailsView *stationDetailsView = static_cast<IRStationDetailsView*>(getViewManager()->getView(EIRView_StationDetailsView, true)); |
319 IRStationDetailsView *stationDetailsView = static_cast<IRStationDetailsView*>(getViewManager()->getView(EIRView_StationDetailsView, true)); |
449 stationDetailsView->setDetails(&channelPreset); |
320 stationDetailsView->setDetails(channelPreset); |
450 |
321 |
451 getViewManager()->activateView(EIRView_StationDetailsView); |
322 getViewManager()->activateView(EIRView_StationDetailsView); |
452 } |
323 } |
453 |
324 |
454 void IRHistoryView::listViewLongPressed(HbAbstractViewItem *aItem, const QPointF& aCoords) |
325 void IRHistoryView::listViewLongPressed(HbAbstractViewItem *aItem, const QPointF& aCoords) |
482 |
353 |
483 contextMenu->setPreferredPos(aCoords); |
354 contextMenu->setPreferredPos(aCoords); |
484 contextMenu->open(); |
355 contextMenu->open(); |
485 } |
356 } |
486 |
357 |
487 void IRHistoryView::convertStationHistory2Preset(const IRQSongHistoryInfo& aHistoryInfo, IRQPreset& aPreset) |
358 |
488 { |
359 |
489 IRQChannelServerURL url; |
360 |
490 url.serverName = aHistoryInfo.getChannelName(); |
361 |
491 url.url = aHistoryInfo.getStreamUrl(); |
362 |
492 url.bitrate = aHistoryInfo.getBitrate(); |
|
493 aPreset.name = aHistoryInfo.getChannelName(); |
|
494 aPreset.insertChannelServer(url); |
|
495 aPreset.type = aHistoryInfo.getChannelType(); |
|
496 aPreset.presetId = aHistoryInfo.getChannelId(); |
|
497 aPreset.shortDesc = aHistoryInfo.getChannelDesc(); |
|
498 aPreset.imgUrl = aHistoryInfo.getImageUrl(); |
|
499 aPreset.genreName = aHistoryInfo.getGenreName(); |
|
500 aPreset.countryName = aHistoryInfo.getCountryName(); |
|
501 aPreset.languageName = aHistoryInfo.getLanguageName(); |
|
502 aPreset.description = aHistoryInfo.getChannelDesc(); |
|
503 aPreset.musicStoreStatus = aHistoryInfo.getMusicStoreStatus(); |
|
504 } |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|