|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include <hblistview.h> |
|
18 #include <hbmenu.h> |
|
19 #include <hbaction.h> |
|
20 #include <QPixmap> |
|
21 #include <QTimer> |
|
22 |
|
23 #include "irabstractviewmanager.h" |
|
24 #include "irapplication.h" |
|
25 #include "irqisdsclient.h" |
|
26 #include "irplaycontroller.h" |
|
27 #include "irhistoryview.h" |
|
28 #include "irqisdsdatastructure.h" |
|
29 #include "irhistorymodel.h" |
|
30 #include "irqsonghistoryinfo.h" |
|
31 #include "irqnetworkcontroller.h" |
|
32 #include "irqutility.h" |
|
33 #include "irqenums.h" |
|
34 #include "irqfavoritesdb.h" |
|
35 |
|
36 const int KBitmapSize = 59; |
|
37 |
|
38 // public functions |
|
39 |
|
40 /* |
|
41 * Description : constructor |
|
42 */ |
|
43 IRHistoryView::IRHistoryView(IRApplication *aApplication, TIRViewId aViewId) : |
|
44 IrAbstractListViewBase(aApplication, aViewId), iClearHistoryAction(NULL), |
|
45 iLogoPreset(NULL) |
|
46 { |
|
47 |
|
48 iModel = new IRHistoryModel(this); |
|
49 iListView->setModel(iModel); |
|
50 iListView->setCurrentIndex(iModel->index(0)); |
|
51 |
|
52 iClearHistoryAction = new HbAction(hbTrId("txt_irad_opt_clear_station_history"), menu()); |
|
53 iSongHistoryAction = new HbAction(hbTrId("txt_irad_opt_recently_played_songs"), menu()); |
|
54 menu()->insertAction(iOpenWebAddressAction, iSongHistoryAction); |
|
55 |
|
56 iConvertTimer = new QTimer(this); |
|
57 iConvertTimer->setInterval(10); |
|
58 |
|
59 connect(iClearHistoryAction, SIGNAL(triggered()), this, SLOT(clearAllList())); |
|
60 connect(iNetworkController, SIGNAL(networkRequestNotified(IRQNetworkEvent)), |
|
61 this, SLOT(networkRequestNotified(IRQNetworkEvent))); |
|
62 connect(iModel, SIGNAL(modelChanged()), this, SLOT(modelChanged())); |
|
63 connect(iSongHistoryAction, SIGNAL(triggered()), this, SLOT(gotoSongHistory())); |
|
64 connect(iConvertTimer, SIGNAL(timeout()), this, SLOT(convertAnother())); |
|
65 } |
|
66 |
|
67 void IRHistoryView::gotoSongHistory() |
|
68 { |
|
69 getViewManager()->activateView(EIRView_SongHistoryView); |
|
70 } |
|
71 |
|
72 /* |
|
73 * Description : destructor |
|
74 */ |
|
75 IRHistoryView::~IRHistoryView() |
|
76 { |
|
77 delete iLogoPreset; |
|
78 iLogoPreset = NULL; |
|
79 } |
|
80 |
|
81 /* |
|
82 * Description : virtual functions from base class IRBaseView. |
|
83 * handle view commands |
|
84 * |
|
85 * see also : IRBaseView::handleCommand |
|
86 */ |
|
87 TIRHandleResult IRHistoryView::handleCommand(TIRViewCommand aCommand, |
|
88 TIRViewCommandReason aReason) |
|
89 { |
|
90 Q_UNUSED(aReason); |
|
91 TIRHandleResult ret = IrAbstractListViewBase::handleCommand(aCommand, aReason); |
|
92 int leftCount = 0; |
|
93 |
|
94 switch (aCommand) |
|
95 { |
|
96 case EIR_ViewCommand_ACTIVATED: |
|
97 connect(iIsdsClient, SIGNAL(presetResponse(IRQPreset *)), |
|
98 this, SLOT(presetResponse(IRQPreset *))); |
|
99 connect(iIsdsClient, SIGNAL(operationException(IRQError)), |
|
100 this, SLOT(operationException(IRQError))); |
|
101 connect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset* )), |
|
102 this, SLOT(presetLogoDownload(IRQPreset* ))); |
|
103 connect(iIsdsClient, SIGNAL(presetLogoDownloadError()), |
|
104 this, SLOT(presetLogoDownloadError())); |
|
105 |
|
106 showHistory(); |
|
107 ret = EIR_NoDefault; |
|
108 break; |
|
109 |
|
110 case EIR_ViewCommand_DEACTIVATE: |
|
111 |
|
112 iModel->clearAndDestroyLogos(); |
|
113 iConvertTimer->stop(); |
|
114 iIsdsClient->isdsLogoDownCancelTransaction(); |
|
115 |
|
116 //iIconIndexArray must be cleared, because timer call back convertAnother() might be |
|
117 //called after view is deactivated. In that case, iModel->getImgURL(aIndex); will crash |
|
118 iIconIndexArray.clear(); |
|
119 |
|
120 disconnect(iIsdsClient, SIGNAL(presetResponse(IRQPreset *)), |
|
121 this, SLOT(presetResponse(IRQPreset *))); |
|
122 disconnect(iIsdsClient, SIGNAL(operationException(IRQError)), |
|
123 this, SLOT(operationException(IRQError))); |
|
124 disconnect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset*)), |
|
125 this, SLOT(presetLogoDownload(IRQPreset* ))); |
|
126 disconnect(iIsdsClient, SIGNAL(presetLogoDownloadError()), |
|
127 this, SLOT(presetLogoDownloadError())); |
|
128 ret = EIR_NoDefault; |
|
129 break; |
|
130 |
|
131 case EIR_ViewCommand_EffectFinished: |
|
132 /* when the effect is finished, we start showing the logos */ |
|
133 leftCount = iIconIndexArray.count(); |
|
134 if( leftCount > 0 ) |
|
135 { |
|
136 iConvertTimer->start(); |
|
137 } |
|
138 break; |
|
139 |
|
140 default: |
|
141 break; |
|
142 } |
|
143 |
|
144 return ret; |
|
145 } |
|
146 |
|
147 // slots functions |
|
148 |
|
149 /* |
|
150 * Description : slot function when an item in a list is clicked. |
|
151 * issue a listen request to isds client |
|
152 * Parameters : aItem : pointer to the clicked item. |
|
153 */ |
|
154 void IRHistoryView::handleItemSelected() |
|
155 { |
|
156 int index = iListView->currentIndex().row(); |
|
157 IRQSongHistoryInfo *hisInfo = iModel->getHistoryInfo(index); |
|
158 if (NULL == hisInfo) |
|
159 { |
|
160 return; |
|
161 } |
|
162 |
|
163 if (hisInfo->getChannelType()) |
|
164 { |
|
165 // channel from isds server, get this preset |
|
166 iPlayController->createBufferingDialog(this, SLOT(cancelRequest())); |
|
167 iIsdsClient->isdsListenRequest(hisInfo->getChannelId(), true); |
|
168 } |
|
169 else |
|
170 { |
|
171 // user defined channel |
|
172 IRQChannelServerURL server; |
|
173 server.bitrate = hisInfo->getBitrate(); |
|
174 server.url = hisInfo->getStreamUrl(); |
|
175 server.serverName = hisInfo->getChannelName(); |
|
176 IRQPreset preset; |
|
177 preset.insertChannelServer(server); |
|
178 preset.name = hisInfo->getChannelName(); |
|
179 preset.description = hisInfo->getChannelDesc(); |
|
180 preset.shortDesc = hisInfo->getChannelDesc(); |
|
181 preset.type = 0; |
|
182 preset.uniqID = 0; |
|
183 preset.presetId = 0; |
|
184 |
|
185 iPlayController->connectToChannel(&preset,EIRQHistoryAdhoc); |
|
186 } |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // IRHistoryView::presetResponse() |
|
191 // gets the preset from isds client and play |
|
192 //--------------------------------------------------------------------------- |
|
193 void IRHistoryView::presetResponse(IRQPreset *aPreset) |
|
194 { |
|
195 iPlayController->connectToChannel(aPreset,EIRQHistoryIsds); |
|
196 } |
|
197 |
|
198 void IRHistoryView::operationException(IRQError aError) |
|
199 { |
|
200 Q_UNUSED(aError); |
|
201 iPlayController->closeBufferingDialog(); |
|
202 |
|
203 popupNote(hbTrId("txt_irad_info_failed_to_connect"), HbMessageBox::MessageTypeWarning); |
|
204 } |
|
205 |
|
206 void IRHistoryView::networkRequestNotified(IRQNetworkEvent aEvent) |
|
207 { |
|
208 if (getViewManager()->currentView() != this) |
|
209 { |
|
210 return; |
|
211 } |
|
212 |
|
213 switch (aEvent) |
|
214 { |
|
215 case EIRQNetworkConnectionEstablished: |
|
216 iApplication->closeConnectingDialog(); |
|
217 |
|
218 if (EIR_UseNetwork_SelectItem == getUseNetworkReason()) |
|
219 { |
|
220 handleItemSelected(); |
|
221 } |
|
222 |
|
223 setUseNetworkReason(EIR_UseNetwork_NoReason); |
|
224 break; |
|
225 |
|
226 default: |
|
227 setCheckedAction(); |
|
228 break; |
|
229 } |
|
230 } |
|
231 |
|
232 void IRHistoryView::cancelRequest() |
|
233 { |
|
234 iIsdsClient->isdsCancelRequest(); |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // IRHistoryView::showHistory() |
|
239 // gets the List which was stored earlier |
|
240 //--------------------------------------------------------------------------- |
|
241 void IRHistoryView::showHistory() |
|
242 { |
|
243 if (iModel->checkHistoryUpdate()) |
|
244 { |
|
245 iListView->reset(); |
|
246 iListView->setCurrentIndex(iModel->index(0)); |
|
247 |
|
248 //because we get all the history refreshed, so clear the icon array. |
|
249 iIconIndexArray.clear(); |
|
250 |
|
251 //initialize the iconindices |
|
252 for (int i = 0; i < iModel->rowCount(); ++i) |
|
253 { |
|
254 if (iModel->getImageUrl(i) != "") |
|
255 { |
|
256 iIconIndexArray.append(i); |
|
257 } |
|
258 } |
|
259 } |
|
260 } |
|
261 |
|
262 // --------------------------------------------------------------------------- |
|
263 // IRHistoryView::clearAllList() |
|
264 // gets the List which was stored earlier |
|
265 //--------------------------------------------------------------------------- |
|
266 void IRHistoryView::clearAllList() |
|
267 { |
|
268 iIconIndexArray.clear(); |
|
269 iModel->clearAllList(); |
|
270 iConvertTimer->stop(); |
|
271 iIsdsClient->isdsLogoDownCancelTransaction(); |
|
272 iListView->reset(); |
|
273 updateView(); |
|
274 } |
|
275 |
|
276 void IRHistoryView::prepareMenu() |
|
277 { |
|
278 HbMenu *viewMenu = menu(); |
|
279 |
|
280 viewMenu->removeAction(iClearHistoryAction); |
|
281 if (iModel->rowCount() > 0) |
|
282 { |
|
283 viewMenu->insertAction(iOpenWebAddressAction, iClearHistoryAction); |
|
284 } |
|
285 } |
|
286 |
|
287 void IRHistoryView::startConvert(int aIndex) |
|
288 { |
|
289 QString url = iModel->getImageUrl(aIndex); |
|
290 |
|
291 IRQPreset tempPreset; |
|
292 tempPreset.imgUrl = url; |
|
293 tempPreset.type = IRQPreset::EIsds; |
|
294 iIsdsClient->isdsLogoDownSendRequest(&tempPreset, 0, KBitmapSize, KBitmapSize); |
|
295 } |
|
296 |
|
297 //if the logo is downloaded ok |
|
298 void IRHistoryView::presetLogoDownload(IRQPreset* aPreset) |
|
299 { |
|
300 if (NULL == aPreset) |
|
301 { |
|
302 presetLogoDownloadError(); |
|
303 return; |
|
304 } |
|
305 |
|
306 |
|
307 delete iLogoPreset; |
|
308 iLogoPreset = aPreset; |
|
309 |
|
310 if (iLogoPreset->logoData != KNullDesC8) |
|
311 { |
|
312 const unsigned char * logoData = iLogoPreset->logoData.Ptr(); |
|
313 QPixmap tempMap; |
|
314 bool ret = tempMap.loadFromData(logoData,iLogoPreset->logoData.Length()); |
|
315 if( ret ) |
|
316 { |
|
317 QIcon convertIcon(tempMap); |
|
318 HbIcon *hbIcon = new HbIcon(convertIcon); |
|
319 int index = iIconIndexArray[0]; |
|
320 iModel->setLogo(hbIcon, index); |
|
321 iIconIndexArray.removeAt(0); |
|
322 int leftCount = iIconIndexArray.count(); |
|
323 if( leftCount > 0 ) |
|
324 { |
|
325 iConvertTimer->start(); |
|
326 } |
|
327 return; |
|
328 } |
|
329 } |
|
330 |
|
331 presetLogoDownloadError(); |
|
332 } |
|
333 |
|
334 |
|
335 |
|
336 //if the logo download fails |
|
337 void IRHistoryView::presetLogoDownloadError() |
|
338 { |
|
339 // if the logo download fails, try to download the next |
|
340 iIconIndexArray.removeAt(0); |
|
341 int leftCount = 0; |
|
342 leftCount = iIconIndexArray.count(); |
|
343 if( leftCount > 0 ) |
|
344 { |
|
345 iConvertTimer->start(); |
|
346 } |
|
347 } |
|
348 |
|
349 void IRHistoryView::convertAnother() |
|
350 { |
|
351 iConvertTimer->stop(); |
|
352 int leftCount = iIconIndexArray.count(); |
|
353 |
|
354 if (0 != leftCount) |
|
355 { |
|
356 startConvert(iIconIndexArray[0]); |
|
357 } |
|
358 } |
|
359 |
|
360 void IRHistoryView::modelChanged() |
|
361 { |
|
362 QString headingStr = hbTrId("Station History") + " (" + QString::number(iModel->rowCount()) + ")"; |
|
363 setHeadingText(headingStr); |
|
364 } |
|
365 |
|
366 |
|
367 void IRHistoryView::addContextAction() |
|
368 { |
|
369 QModelIndex current = iListView->currentIndex(); |
|
370 IRQSongHistoryInfo * currentInfo = iModel->getHistoryInfo(current.row()); |
|
371 IRQPreset preset; |
|
372 convertStationHistory2Preset(*currentInfo, preset); |
|
373 int retValue = iFavorites->addPreset(preset); |
|
374 |
|
375 switch (retValue) |
|
376 { |
|
377 case EIRQErrorNone: |
|
378 popupNote(hbTrId("txt_irad_menu_add_to_favorite"), HbMessageBox::MessageTypeInformation); |
|
379 |
|
380 break; |
|
381 |
|
382 case EIRQErrorOutOfMemory: |
|
383 popupNote(hbTrId("txt_irad_info_can_not_add_more"), HbMessageBox::MessageTypeInformation); |
|
384 break; |
|
385 |
|
386 case EIRQErrorAlreadyExist: |
|
387 popupNote(hbTrId("txt_irad_info_favorite_updated"), HbMessageBox::MessageTypeInformation); |
|
388 break; |
|
389 |
|
390 default: |
|
391 break; |
|
392 } |
|
393 } |
|
394 |
|
395 void IRHistoryView::deleteContextAction() |
|
396 { |
|
397 int current = iListView->currentIndex().row(); |
|
398 bool ret = iModel->deleteOneItem(current); |
|
399 if( !ret ) |
|
400 { |
|
401 popupNote(hbTrId("txt_irad_info_operation_failed"), HbMessageBox::MessageTypeWarning); |
|
402 } |
|
403 } |
|
404 |
|
405 |
|
406 |
|
407 void IRHistoryView::listViewLongPressed(HbAbstractViewItem *aItem, const QPointF& aCoords) |
|
408 { |
|
409 Q_UNUSED(aItem); |
|
410 HbMenu *contextMenu = 0; |
|
411 HbAction *action = 0; |
|
412 |
|
413 contextMenu = new HbMenu(); |
|
414 action = contextMenu->addAction(QString(hbTrId("txt_irad_menu_add_to_favorite"))); |
|
415 action->setObjectName("add"); |
|
416 action = contextMenu->addAction(QString(hbTrId("txt_common_menu_delete"))); |
|
417 action->setObjectName("delete"); |
|
418 action = contextMenu->exec(aCoords); |
|
419 |
|
420 if( action ) |
|
421 { |
|
422 QString objectName = action->objectName(); |
|
423 if ( objectName == "add" ) |
|
424 { |
|
425 addContextAction(); |
|
426 } |
|
427 else if( objectName == "delete") |
|
428 { |
|
429 deleteContextAction(); |
|
430 } |
|
431 } |
|
432 } |
|
433 |
|
434 void IRHistoryView::convertStationHistory2Preset(const IRQSongHistoryInfo& aHistoryInfo, IRQPreset& aPreset) |
|
435 { |
|
436 IRQChannelServerURL url; |
|
437 url.url = aHistoryInfo.getStreamUrl(); |
|
438 url.bitrate = aHistoryInfo.getBitrate(); |
|
439 aPreset.name = aHistoryInfo.getChannelName(); |
|
440 aPreset.insertChannelServer(url); |
|
441 aPreset.type = aHistoryInfo.getChannelType(); |
|
442 aPreset.presetId = aHistoryInfo.getChannelId(); |
|
443 aPreset.shortDesc = aHistoryInfo.getChannelDesc(); |
|
444 aPreset.imgUrl = aHistoryInfo.getImageUrl(); |
|
445 aPreset.description = aHistoryInfo.getChannelDesc(); |
|
446 aPreset.musicStoreStatus = aHistoryInfo.getMusicStoreStatus(); |
|
447 } |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |