|
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 |
|
18 #include <hbicon.h> |
|
19 #include <QBrush> |
|
20 |
|
21 #include "irchannelmodel.h" |
|
22 #include "irqisdsdatastructure.h" |
|
23 #include "iruidefines.h" |
|
24 |
|
25 IrChannelModel::IrChannelModel(QObject *aParent): QAbstractListModel(aParent) |
|
26 , iChannelList(NULL) |
|
27 { |
|
28 QIcon icon(":/stationlist/icon_stationdefault.png"); |
|
29 iStationLogo = new HbIcon(icon); |
|
30 } |
|
31 |
|
32 IrChannelModel::~IrChannelModel() |
|
33 { |
|
34 clearAndDestroyItems(); |
|
35 |
|
36 delete iStationLogo; |
|
37 iStationLogo = NULL; |
|
38 |
|
39 clearAndDestroyLogos(); |
|
40 } |
|
41 |
|
42 int IrChannelModel::rowCount(const QModelIndex &aParent) const |
|
43 { |
|
44 Q_UNUSED(aParent); |
|
45 int count = 0; |
|
46 |
|
47 if(iChannelList) |
|
48 { |
|
49 count = iChannelList->count(); |
|
50 } |
|
51 return count; |
|
52 } |
|
53 |
|
54 QString IrChannelModel::imageUrl(int aRow) |
|
55 { |
|
56 if (iChannelList) |
|
57 { |
|
58 return iChannelList->at(aRow)->imageURL; |
|
59 } |
|
60 else |
|
61 { |
|
62 return ""; |
|
63 } |
|
64 } |
|
65 |
|
66 void IrChannelModel::setLogo(HbIcon *aIcon, int aIndex) |
|
67 { |
|
68 iLogos[aIndex] = aIcon; |
|
69 emit dataChanged(index(aIndex), index(aIndex)); |
|
70 } |
|
71 |
|
72 QVariant IrChannelModel::data(const QModelIndex &aIndex, int aRole) const |
|
73 { |
|
74 if (!aIndex.isValid()) |
|
75 return QVariant(); |
|
76 |
|
77 if (aIndex.row() >= iChannelList->count()) |
|
78 return QVariant(); |
|
79 |
|
80 if (aRole == Qt::DisplayRole) |
|
81 { |
|
82 QVariantList list; |
|
83 int row = aIndex.row(); |
|
84 |
|
85 list.append(iChannelList->at(row)->channelName); |
|
86 // fix bug #9888,if left descriptions as blank, only one line appears |
|
87 QString tempDes = iChannelList->at(row)->shortDescription; |
|
88 if( 0 == tempDes.length() ) |
|
89 { |
|
90 tempDes = " "; |
|
91 } |
|
92 list.append(tempDes); |
|
93 |
|
94 return list; |
|
95 } |
|
96 else if (aRole == Qt::DecorationRole) |
|
97 { |
|
98 QVariantList list; |
|
99 int row = aIndex.row(); |
|
100 const HbIcon *icon = iLogos.value(row); |
|
101 if (icon) |
|
102 { |
|
103 list.append(*icon); |
|
104 } |
|
105 else |
|
106 { |
|
107 list.append(*iStationLogo); |
|
108 } |
|
109 |
|
110 return list; |
|
111 } |
|
112 else if (aRole == Qt::BackgroundRole) |
|
113 { |
|
114 if (aIndex.row() % 2 == 0) |
|
115 { |
|
116 return QBrush(KListEvenRowColor); |
|
117 } |
|
118 else |
|
119 { |
|
120 return QBrush(KListOddRowColor); |
|
121 } |
|
122 } |
|
123 else |
|
124 { |
|
125 return QVariant(); |
|
126 } |
|
127 } |
|
128 |
|
129 void IrChannelModel::updateData(QList<IRQChannelItem*> *aPushItemsList) |
|
130 { |
|
131 if (iChannelList != aPushItemsList) |
|
132 { |
|
133 clearAndDestroyItems(); |
|
134 iChannelList = aPushItemsList; |
|
135 } |
|
136 |
|
137 clearAndDestroyLogos(); |
|
138 |
|
139 emit dataAvailable(); |
|
140 } |
|
141 |
|
142 void IrChannelModel::clearAndDestroyLogos() |
|
143 { |
|
144 for (QMap<int, HbIcon*>::iterator it = iLogos.begin(); it != iLogos.end(); ++it) |
|
145 { |
|
146 delete it.value(); |
|
147 } |
|
148 |
|
149 iLogos.clear(); |
|
150 } |
|
151 |
|
152 void IrChannelModel::clearAndDestroyItems() |
|
153 { |
|
154 if (iChannelList) |
|
155 { |
|
156 for (QList<IRQChannelItem*>::iterator it = iChannelList->begin(); it != iChannelList->end(); ++it) |
|
157 { |
|
158 delete *it; |
|
159 } |
|
160 delete iChannelList; |
|
161 iChannelList = NULL; |
|
162 } |
|
163 } |