17 #include <QPixmap> |
17 #include <QPixmap> |
18 #include <hblistview.h> |
18 #include <hblistview.h> |
19 #include <hbaction.h> |
19 #include <hbaction.h> |
20 #include <QTimer> |
20 #include <QTimer> |
21 #include <hbscrollbar.h> |
21 #include <hbscrollbar.h> |
|
22 #include <hgwidgets/hgcacheproxymodel.h> |
22 |
23 |
23 #include "irviewmanager.h" |
24 #include "irviewmanager.h" |
24 #include "irstationsview.h" |
25 #include "irstationsview.h" |
25 #include "irapplication.h" |
26 #include "irapplication.h" |
26 #include "irplaycontroller.h" |
27 #include "irplaycontroller.h" |
27 #include "irqisdsclient.h" |
28 #include "irqisdsclient.h" |
28 #include "irqenums.h" |
29 #include "irqenums.h" |
29 #include "irqutility.h" |
30 #include "irqutility.h" |
30 #include "irchannelmodel.h" |
31 #include "irchanneldataprovider.h" |
31 #include "irqisdsdatastructure.h" |
32 #include "irqisdsdatastructure.h" |
32 #include "irqnetworkcontroller.h" |
33 #include "irqnetworkcontroller.h" |
33 |
34 |
34 const int KBitmapSize = 59; |
35 |
35 const uint KConnectTimeOut = 15000; //if the connecting take more than 15 seconds, we will show a pop up |
36 const uint KConnectTimeOut = 15000; //if the connecting take more than 15 seconds, we will show a pop up |
36 |
37 |
37 // public functions |
38 // public functions |
38 |
39 |
39 /* |
40 /* |
40 * Description : constructor |
41 * Description : constructor |
41 */ |
42 */ |
42 IRStationsView::IRStationsView(IRApplication* aApplication, TIRViewId aViewId) |
43 IRStationsView::IRStationsView(IRApplication* aApplication, TIRViewId aViewId) |
43 : IrAbstractListViewBase(aApplication, aViewId), |
44 : IrAbstractListViewBase(aApplication, aViewId), |
44 iLogoPreset(NULL), iPreset(NULL), |
45 iPreset(NULL), |
45 iLastSelectitem(0) |
46 iLastSelectitem(0) |
46 { |
47 { |
47 //this view won't be starting view, don't need lazy init |
48 |
48 IrAbstractListViewBase::lazyInit(); |
49 iDataProvider = new IRChannelDataProvider(this); |
49 setInitCompleted(true); |
50 HgCacheProxyModel *model = new HgCacheProxyModel(this); |
50 |
51 model->setDataProvider(iDataProvider, KCacheSize, KCacheThreshold); |
51 iIconIndexArray.clear(); |
52 iListView->setModel(model); |
52 iChannelModel = new IrChannelModel(this); |
|
53 iListView->setModel(iChannelModel); |
|
54 |
|
55 |
53 |
56 iConnectTimer = new QTimer(this); |
54 iConnectTimer = new QTimer(this); |
57 iConnectTimer->setInterval(KConnectTimeOut); |
55 iConnectTimer->setInterval(KConnectTimeOut); |
58 |
56 |
59 iConvertTimer = new QTimer(this); |
57 connect(iDataProvider, SIGNAL(dataAvailable()), this, SLOT(dataChanged())); |
60 iConvertTimer->setInterval(10); |
|
61 |
|
62 connect(iChannelModel, SIGNAL(dataAvailable()), this, SLOT(dataChanged())); |
|
63 connect(iNetworkController, SIGNAL(networkRequestNotified(IRQNetworkEvent)), |
58 connect(iNetworkController, SIGNAL(networkRequestNotified(IRQNetworkEvent)), |
64 this, SLOT(networkRequestNotified(IRQNetworkEvent))); |
59 this, SLOT(networkRequestNotified(IRQNetworkEvent))); |
65 connect(iConnectTimer, SIGNAL(timeout()), this, SLOT(connectTimeOut())); |
60 connect(iConnectTimer, SIGNAL(timeout()), this, SLOT(connectTimeOut())); |
66 connect(iConvertTimer, SIGNAL(timeout()), this, SLOT(convertAnother())); |
|
67 } |
61 } |
68 |
62 |
69 /* |
63 /* |
70 * Description : destructor |
64 * Description : destructor |
71 */ |
65 */ |
72 IRStationsView::~IRStationsView() |
66 IRStationsView::~IRStationsView() |
73 { |
67 { |
74 delete iPreset; |
68 delete iPreset; |
75 iPreset = NULL; |
69 iPreset = NULL; |
76 |
|
77 delete iLogoPreset; |
|
78 iLogoPreset = NULL; |
|
79 } |
70 } |
80 |
71 |
81 void IRStationsView::loadCategoryStations(int aIndex, const QString &aHeadingText) |
72 void IRStationsView::loadCategoryStations(int aIndex, const QString &aHeadingText) |
82 { |
73 { |
83 connectToIsdsClient(); |
74 connectToIsdsClient(); |
110 * EIR_NoDefault : caller doesn't do default handling |
101 * EIR_NoDefault : caller doesn't do default handling |
111 */ |
102 */ |
112 TIRHandleResult IRStationsView::handleCommand(TIRViewCommand aCommand, TIRViewCommandReason aReason) |
103 TIRHandleResult IRStationsView::handleCommand(TIRViewCommand aCommand, TIRViewCommandReason aReason) |
113 { |
104 { |
114 TIRHandleResult ret = IrAbstractListViewBase::handleCommand(aCommand, aReason); |
105 TIRHandleResult ret = IrAbstractListViewBase::handleCommand(aCommand, aReason); |
115 int leftCount = 0; |
|
116 |
106 |
117 switch (aCommand) |
107 switch (aCommand) |
118 { |
108 { |
119 case EIR_ViewCommand_ACTIVATED: |
109 case EIR_ViewCommand_ACTIVATED: |
120 connect(iIsdsClient, SIGNAL(presetResponse(IRQPreset *)), |
110 connect(iIsdsClient, SIGNAL(presetResponse(IRQPreset *)), |
121 this, SLOT(presetResponse(IRQPreset *))); |
111 this, SLOT(presetResponse(IRQPreset *))); |
122 connect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset* )), |
112 |
123 this, SLOT(presetLogoDownload(IRQPreset* ))); |
113 iDataProvider->activate(); |
124 connect(iIsdsClient, SIGNAL(presetLogoDownloadError()), |
114 |
125 this, SLOT(presetLogoDownloadError())); |
|
126 |
|
127 leftCount = iIconIndexArray.count(); |
|
128 if( leftCount > 0 ) |
|
129 { |
|
130 iConvertTimer->start(); |
|
131 } |
|
132 ret = EIR_NoDefault; |
115 ret = EIR_NoDefault; |
133 break; |
116 break; |
134 |
117 |
135 case EIR_ViewCommand_DEACTIVATE: |
118 case EIR_ViewCommand_DEACTIVATE: |
136 if (aReason == EIR_ViewCommandReason_Back) |
119 iConnectTimer->stop(); |
137 { |
120 iDataProvider->deactivate(); |
138 cleanupResource(); |
|
139 } |
|
140 |
|
141 iConnectTimer->stop(); |
|
142 iConvertTimer->stop(); |
|
143 iIsdsClient->isdsLogoDownCancelTransaction(); |
|
144 |
121 |
145 disconnect(iIsdsClient, SIGNAL(presetResponse(IRQPreset *)), |
122 disconnect(iIsdsClient, SIGNAL(presetResponse(IRQPreset *)), |
146 this, SLOT(presetResponse(IRQPreset *))); |
123 this, SLOT(presetResponse(IRQPreset *))); |
147 disconnect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset*)), |
|
148 this, SLOT(presetLogoDownload(IRQPreset* ))); |
|
149 disconnect(iIsdsClient, SIGNAL(presetLogoDownloadError()), |
|
150 this, SLOT(presetLogoDownloadError())); |
|
151 ret = EIR_NoDefault; |
124 ret = EIR_NoDefault; |
152 break; |
125 break; |
153 |
126 |
154 default: |
127 default: |
155 break; |
128 break; |
211 void IRStationsView::dataChanged() |
184 void IRStationsView::dataChanged() |
212 { |
185 { |
213 iConnectTimer->stop(); |
186 iConnectTimer->stop(); |
214 |
187 |
215 disconnectIsdsClient(); |
188 disconnectIsdsClient(); |
216 cleanupResource(); |
|
217 |
189 |
218 iListView->reset(); |
190 iListView->reset(); |
219 iListView->setCurrentIndex(iChannelModel->index(iLastSelectitem)); |
191 iListView->setCurrentIndex(iDataProvider->index(iLastSelectitem, 0)); |
220 iListView->scrollTo(iChannelModel->index(iLastSelectitem)); |
192 iListView->scrollTo(iDataProvider->index(iLastSelectitem, 0)); |
221 qreal value = 0.0; |
193 qreal value = 0.0; |
222 if (iListView->model()->rowCount() > 0) |
194 if (iListView->model()->rowCount() > 0) |
223 { |
195 { |
224 value = iLastSelectitem / iListView->model()->rowCount(); |
196 value = iLastSelectitem / iListView->model()->rowCount(); |
225 } |
197 } |
226 iListView->verticalScrollBar()->setValue(value); |
198 iListView->verticalScrollBar()->setValue(value); |
227 |
|
228 //initialize the iconindices |
|
229 for (int i = 0; i < iChannelModel->rowCount(); ++i) |
|
230 { |
|
231 if (iChannelModel->imageUrl(i) != "") |
|
232 { |
|
233 iIconIndexArray.append(i); |
|
234 } |
|
235 } |
|
236 |
199 |
237 getViewManager()->activateView(this); |
200 getViewManager()->activateView(this); |
238 iApplication->stopLoadingAnimation(); |
201 iApplication->stopLoadingAnimation(); |
239 } |
202 } |
240 |
203 |
303 iIsdsClient->isdsCancelRequest(); |
266 iIsdsClient->isdsCancelRequest(); |
304 disconnectIsdsClient(); |
267 disconnectIsdsClient(); |
305 iApplication->stopLoadingAnimation(); |
268 iApplication->stopLoadingAnimation(); |
306 } |
269 } |
307 |
270 |
308 void IRStationsView::startConvert(int aIndex) |
|
309 { |
|
310 QString url = iChannelModel->imageUrl(aIndex); |
|
311 |
|
312 IRQPreset tempPreset; |
|
313 tempPreset.imgUrl = url; |
|
314 tempPreset.type = IRQPreset::EIsds; |
|
315 |
|
316 iIsdsClient->isdsLogoDownSendRequest(&tempPreset, 0, KBitmapSize, KBitmapSize); |
|
317 } |
|
318 |
|
319 |
|
320 //if the logo is downloaded ok |
|
321 void IRStationsView::presetLogoDownload(IRQPreset* aPreset) |
|
322 { |
|
323 if( NULL == aPreset ) |
|
324 { |
|
325 presetLogoDownloadError(); |
|
326 return; |
|
327 } |
|
328 |
|
329 |
|
330 delete iLogoPreset; |
|
331 iLogoPreset = aPreset; |
|
332 |
|
333 if (iLogoPreset->logoData != KNullDesC8) |
|
334 { |
|
335 QPixmap tempMap; |
|
336 const unsigned char * logoData = iLogoPreset->logoData.Ptr(); |
|
337 bool ret = tempMap.loadFromData(logoData, iLogoPreset->logoData.Length()); |
|
338 QIcon convertIcon(tempMap); |
|
339 |
|
340 if( ret ) |
|
341 { |
|
342 HbIcon *hbIcon = new HbIcon(convertIcon); |
|
343 int index = iIconIndexArray[0]; |
|
344 iChannelModel->setLogo(hbIcon, index); |
|
345 iIconIndexArray.removeAt(0); |
|
346 int leftCount = iIconIndexArray.count(); |
|
347 if( leftCount > 0 ) |
|
348 { |
|
349 iConvertTimer->start(); |
|
350 } |
|
351 return; |
|
352 } |
|
353 } |
|
354 |
|
355 presetLogoDownloadError(); |
|
356 } |
|
357 |
|
358 //if the logo download fails |
|
359 void IRStationsView::presetLogoDownloadError() |
|
360 { |
|
361 // if the logo download fails, try to download the next |
|
362 iIconIndexArray.removeAt(0); |
|
363 int leftCount = iIconIndexArray.count(); |
|
364 if( leftCount > 0 ) |
|
365 { |
|
366 iConvertTimer->start(); |
|
367 } |
|
368 } |
|
369 |
|
370 void IRStationsView::cleanupResource() |
|
371 { |
|
372 iIconIndexArray.clear(); |
|
373 |
|
374 //destroy icons in time to save memory |
|
375 iChannelModel->clearAndDestroyLogos(); |
|
376 } |
|
377 |
|
378 void IRStationsView::networkRequestNotified(IRQNetworkEvent aEvent) |
271 void IRStationsView::networkRequestNotified(IRQNetworkEvent aEvent) |
379 { |
272 { |
380 if (getViewManager()->currentView() != this) |
273 if (getViewManager()->currentView() != this) |
381 { |
274 { |
382 return; |
275 return; |
406 } |
294 } |
407 |
295 |
408 void IRStationsView::connectToIsdsClient() |
296 void IRStationsView::connectToIsdsClient() |
409 { |
297 { |
410 connect(iIsdsClient, SIGNAL(channelItemsChanged(QList<IRQChannelItem *> *)), |
298 connect(iIsdsClient, SIGNAL(channelItemsChanged(QList<IRQChannelItem *> *)), |
411 iChannelModel, SLOT(updateData(QList<IRQChannelItem *> *))); |
299 iDataProvider, SLOT(updateData(QList<IRQChannelItem *> *))); |
412 |
300 |
413 connect(iIsdsClient, SIGNAL(operationException(IRQError)), |
301 connect(iIsdsClient, SIGNAL(operationException(IRQError)), |
414 this, SLOT(operationException(IRQError))); |
302 this, SLOT(operationException(IRQError))); |
415 } |
303 } |
416 |
304 |
417 void IRStationsView::disconnectIsdsClient() |
305 void IRStationsView::disconnectIsdsClient() |
418 { |
306 { |
419 disconnect(iIsdsClient, SIGNAL(channelItemsChanged(QList<IRQChannelItem *> *)), |
307 disconnect(iIsdsClient, SIGNAL(channelItemsChanged(QList<IRQChannelItem *> *)), |
420 iChannelModel, SLOT(updateData(QList<IRQChannelItem *> *))); |
308 iDataProvider, SLOT(updateData(QList<IRQChannelItem *> *))); |
421 |
309 |
422 disconnect(iIsdsClient, SIGNAL(operationException(IRQError)), |
310 disconnect(iIsdsClient, SIGNAL(operationException(IRQError)), |
423 this, SLOT(operationException(IRQError))); |
311 this, SLOT(operationException(IRQError))); |
424 } |
|
425 |
|
426 void IRStationsView::convertAnother() |
|
427 { |
|
428 iConvertTimer->stop(); |
|
429 int leftCount = iIconIndexArray.count(); |
|
430 |
|
431 if(0 != leftCount) |
|
432 { |
|
433 startConvert(iIconIndexArray[0]); |
|
434 } |
|
435 } |
312 } |
436 |
313 |
437 void IRStationsView::connectTimeOut() |
314 void IRStationsView::connectTimeOut() |
438 { |
315 { |
439 iConnectTimer->stop(); |
316 iConnectTimer->stop(); |