13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include <hbicon.h> |
18 #include <HbIcon> |
|
19 #include <QTimer> |
19 |
20 |
20 #include "irchannelmodel.h" |
21 #include "irchannelmodel.h" |
21 #include "irqisdsdatastructure.h" |
22 #include "irqisdsdatastructure.h" |
22 #include "irsearchresultdb.h" |
23 #include "irsearchresultdb.h" |
|
24 #include "irqisdsclient.h" |
|
25 #include "irlogoprovider.h" |
23 |
26 |
24 IrChannelModel::IrChannelModel(QObject *aParent): QAbstractListModel(aParent) |
27 IrChannelModel::IrChannelModel(QObject *aParent): QAbstractListModel(aParent) |
25 , iChannelList(NULL),iDB(NULL) |
28 , iChannelList(NULL),iDB(NULL) |
26 { |
29 { |
27 iStationLogo = new HbIcon("qtg_large_internet_radio"); |
30 iIsdsClient = IRQIsdsClient::openInstance(); |
|
31 iLogoProvider = new IRLogoProvider(iIsdsClient); |
|
32 |
|
33 iTimer = new QTimer; |
|
34 iTimer->setInterval(10); |
|
35 connect(iTimer, SIGNAL(timeout()), this, SLOT(downloadNextLogo())); |
|
36 |
|
37 iStationLogo = new HbIcon("qtg_large_internet_radio"); |
|
38 |
|
39 if( NULL == iDB ) |
|
40 { |
|
41 iDB = new IRSearchResultDB(); |
|
42 } |
28 } |
43 } |
29 |
44 |
30 IrChannelModel::~IrChannelModel() |
45 IrChannelModel::~IrChannelModel() |
31 { |
46 { |
32 clearAndDestroyItems(); |
47 clearAndDestroyItems(); |
117 { |
130 { |
118 return QVariant(); |
131 return QVariant(); |
119 } |
132 } |
120 } |
133 } |
121 |
134 |
122 void IrChannelModel::updateData(QList<IRQChannelItem*> *aPushItemsList) |
135 void IrChannelModel::updateData(QList<IRQChannelItem*> *aPushItemsList, bool bInit) |
123 { |
136 { |
124 if (iChannelList != aPushItemsList) |
137 if (iChannelList != aPushItemsList) |
125 { |
138 { |
126 clearAndDestroyItems(); |
139 clearAndDestroyItems(); |
127 iChannelList = aPushItemsList; |
140 iChannelList = aPushItemsList; |
128 } |
141 } |
|
142 if(false == bInit) |
|
143 { |
|
144 save2Cache(); |
|
145 |
|
146 } |
129 |
147 |
130 clearAndDestroyLogos(); |
148 clearAndDestroyLogos(); |
131 |
149 |
|
150 updateIconIndexArray(); |
|
151 |
132 emit dataAvailable(); |
152 emit dataAvailable(); |
133 } |
153 } |
134 |
154 |
135 void IrChannelModel::initWithCache() |
155 void IrChannelModel::initWithCache() |
136 { |
156 { |
137 if( NULL == iDB ) |
157 updateData(iDB->getCahcedChannelList(), true); |
138 { |
|
139 iDB = new IRSearchResultDB(); |
|
140 } |
|
141 |
|
142 QList<IRQChannelItem*> *channelList = iDB->getCahcedChannelList(); |
|
143 |
|
144 if( NULL == channelList ) |
|
145 { |
|
146 //some error happens |
|
147 return; |
|
148 } |
|
149 |
|
150 clearAndDestroyItems(); |
|
151 clearAndDestroyLogos(); |
|
152 iChannelList = channelList; |
|
153 } |
158 } |
154 |
159 |
155 void IrChannelModel::save2Cache() |
160 void IrChannelModel::save2Cache() |
156 { |
161 { |
157 if( NULL == iChannelList ) |
162 if( NULL == iChannelList ) |
176 void IrChannelModel::cleanupDatabase() |
181 void IrChannelModel::cleanupDatabase() |
177 { |
182 { |
178 clearAndDestroyItems(); |
183 clearAndDestroyItems(); |
179 clearAndDestroyLogos(); |
184 clearAndDestroyLogos(); |
180 iDB->clearCache(); |
185 iDB->clearCache(); |
181 |
186 iIconIndexArray.clear(); |
|
187 |
182 emit dataAvailable(); |
188 emit dataAvailable(); |
183 } |
189 } |
184 |
190 |
185 void IrChannelModel::clearAndDestroyLogos() |
191 void IrChannelModel::clearAndDestroyLogos() |
186 { |
192 { |
202 } |
208 } |
203 delete iChannelList; |
209 delete iChannelList; |
204 iChannelList = NULL; |
210 iChannelList = NULL; |
205 } |
211 } |
206 } |
212 } |
|
213 |
|
214 void IrChannelModel::startDownloadingLogo() |
|
215 { |
|
216 iLogoProvider->activate(this, SLOT(logoData(const QByteArray&))); |
|
217 iTimer->start(); |
|
218 } |
|
219 |
|
220 void IrChannelModel::stopDownloadingLogo() |
|
221 { |
|
222 iIsdsClient->isdsLogoDownCancelTransaction(); |
|
223 iTimer->stop(); |
|
224 iLogoProvider->deactivate(); |
|
225 } |
|
226 |
|
227 void IrChannelModel::downloadNextLogo() |
|
228 { |
|
229 iTimer->stop(); |
|
230 int leftCount = iIconIndexArray.count(); |
|
231 |
|
232 if (0 != leftCount) |
|
233 { |
|
234 int row = iIconIndexArray[0]; |
|
235 IRQPreset preset; |
|
236 preset.name = iChannelList->at(row)->channelName; |
|
237 preset.shortDesc = iChannelList->at(row)->shortDescription; |
|
238 preset.type = IRQPreset::EIsds; |
|
239 preset.presetId = iChannelList->at(row)->channelID; |
|
240 preset.imgUrl = iChannelList->at(row)->imageURL; |
|
241 iLogoProvider->getLogo(&preset); |
|
242 } |
|
243 } |
|
244 |
|
245 void IrChannelModel::logoData(const QByteArray &aLogoData) |
|
246 { |
|
247 if (aLogoData.size() > 0) |
|
248 { |
|
249 QPixmap tempMap; |
|
250 bool ret = tempMap.loadFromData((const unsigned char*)aLogoData.constData(), aLogoData.size()); |
|
251 if( ret ) |
|
252 { |
|
253 QIcon convertIcon(tempMap); |
|
254 HbIcon *hbIcon = new HbIcon(convertIcon); |
|
255 int index = iIconIndexArray[0]; |
|
256 setLogo(hbIcon, index); |
|
257 } |
|
258 } |
|
259 |
|
260 iIconIndexArray.removeAt(0); |
|
261 int leftCount = iIconIndexArray.count(); |
|
262 if( leftCount > 0 ) |
|
263 { |
|
264 iTimer->start(); |
|
265 } |
|
266 } |
|
267 |
|
268 void IrChannelModel::updateIconIndexArray() |
|
269 { |
|
270 iIconIndexArray.clear(); |
|
271 |
|
272 for (int i = 0; i < rowCount(); ++i) |
|
273 { |
|
274 if (iChannelList->at(i)->imageURL != "" && !iLogos.contains(i)) |
|
275 { |
|
276 iIconIndexArray.append(i); |
|
277 } |
|
278 } |
|
279 |
|
280 if (iIconIndexArray.size() > 0) |
|
281 { |
|
282 startDownloadingLogo(); |
|
283 } |
|
284 } |