equal
deleted
inserted
replaced
13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 #include <hbicon.h> |
17 #include <hbicon.h> |
18 #include <QBrush> |
|
19 |
18 |
20 #include "irqfavoritesdb.h" |
19 #include "irqfavoritesdb.h" |
21 #include "irqisdsdatastructure.h" |
20 #include "irqisdsdatastructure.h" |
22 #include "iruidefines.h" |
|
23 #include "irfavoritesmodel.h" |
21 #include "irfavoritesmodel.h" |
24 |
22 |
25 IRFavoritesModel::IRFavoritesModel(IRQFavoritesDB *aFavoritesDb, QObject *aParent) |
23 IRFavoritesModel::IRFavoritesModel(IRQFavoritesDB *aFavoritesDb, QObject *aParent) |
26 : QAbstractListModel(aParent), iFavoritesDb(aFavoritesDb), |
24 : QAbstractListModel(aParent), iFavoritesDb(aFavoritesDb), |
27 iPresetsList(NULL) |
25 iPresetsList(NULL) |
29 if (aFavoritesDb) |
27 if (aFavoritesDb) |
30 { |
28 { |
31 iPresetsList = aFavoritesDb->getPresets(); |
29 iPresetsList = aFavoritesDb->getPresets(); |
32 } |
30 } |
33 |
31 |
34 iStationLogo = new HbIcon(":/stationlist/icon_stationdefault.png"); |
32 iStationLogo = new HbIcon("qtg_large_internet_radio"); |
35 } |
33 } |
36 |
34 |
37 IRFavoritesModel::~IRFavoritesModel() |
35 IRFavoritesModel::~IRFavoritesModel() |
38 { |
36 { |
39 delete iStationLogo; |
37 delete iStationLogo; |
51 return NULL; |
49 return NULL; |
52 } |
50 } |
53 |
51 |
54 QString IRFavoritesModel::getImgUrl(int aIndex) const |
52 QString IRFavoritesModel::getImgUrl(int aIndex) const |
55 { |
53 { |
56 if( aIndex<0 || aIndex >=iPresetsList->count() ) |
54 if ( aIndex<0 || aIndex >=iPresetsList->count() ) |
57 { |
55 { |
58 return ""; |
56 return ""; |
59 } |
57 } |
60 return iPresetsList->at(aIndex)->imgUrl; |
58 return iPresetsList->at(aIndex)->imgUrl; |
61 } |
59 } |
72 return 0; |
70 return 0; |
73 } |
71 } |
74 |
72 |
75 void IRFavoritesModel::setLogo(HbIcon *aIcon, int aIndex) |
73 void IRFavoritesModel::setLogo(HbIcon *aIcon, int aIndex) |
76 { |
74 { |
|
75 int elementCountNeedToAdd = aIndex + 1 - iLogos.size(); |
|
76 while (elementCountNeedToAdd > 0) |
|
77 { |
|
78 iLogos.append(NULL); |
|
79 elementCountNeedToAdd--; |
|
80 } |
77 iLogos[aIndex] = aIcon; |
81 iLogos[aIndex] = aIcon; |
78 emit dataChanged(index(aIndex), index(aIndex)); |
82 emit dataChanged(index(aIndex), index(aIndex)); |
79 } |
83 } |
80 |
84 |
81 QVariant IRFavoritesModel::data(const QModelIndex &aIndex, int aRole) const |
85 QVariant IRFavoritesModel::data(const QModelIndex &aIndex, int aRole) const |
93 if (aRole == Qt::DisplayRole) |
97 if (aRole == Qt::DisplayRole) |
94 { |
98 { |
95 QVariantList list; |
99 QVariantList list; |
96 int row = aIndex.row(); |
100 int row = aIndex.row(); |
97 |
101 |
98 QString primaryText = QString::number(row+1) + ". " + iPresetsList->at(row)->name; |
102 QString primaryText = iPresetsList->at(row)->name; |
99 list.append(primaryText); |
103 list.append(primaryText); |
100 QString secondaryText = iPresetsList->at(row)->shortDesc; |
104 QString secondaryText = iPresetsList->at(row)->shortDesc; |
101 |
105 |
102 // fix bug #9888,if left descriptions as blank, |
106 // fix bug #9888,if left descriptions as blank, |
103 // only one line displays in favorites view |
107 // only one line displays in favorites view |
107 } |
111 } |
108 |
112 |
109 list.append(secondaryText); |
113 list.append(secondaryText); |
110 return list; |
114 return list; |
111 } |
115 } |
112 else if( aRole == Qt::DecorationRole) |
116 else if ( aRole == Qt::DecorationRole) |
113 { |
117 { |
114 QVariantList list; |
118 QVariantList list; |
115 int row = aIndex.row(); |
119 int row = aIndex.row(); |
116 const HbIcon *icon = iLogos.value(row); |
120 if(row < iLogos.size()) |
117 if (icon) |
121 { |
118 { |
122 const HbIcon *icon = iLogos[row]; |
119 list.append(*icon); |
123 if (icon) |
120 } |
124 { |
121 else |
125 list.append(*icon); |
122 { |
126 } |
|
127 else |
|
128 { |
|
129 list.append(*iStationLogo); |
|
130 } |
|
131 } |
|
132 else |
|
133 { |
123 list.append(*iStationLogo); |
134 list.append(*iStationLogo); |
124 } |
135 } |
125 |
|
126 return list; |
136 return list; |
127 } |
137 } |
128 else if (aRole == Qt::BackgroundRole) |
|
129 { |
|
130 if (aIndex.row() % 2 == 0) |
|
131 { |
|
132 return QBrush(KListEvenRowColor); |
|
133 } |
|
134 else |
|
135 { |
|
136 return QBrush(KListOddRowColor); |
|
137 } |
|
138 } |
|
139 |
|
140 return QVariant(); |
138 return QVariant(); |
141 } |
139 } |
142 |
140 |
143 bool IRFavoritesModel::checkFavoritesUpdate() |
141 bool IRFavoritesModel::checkFavoritesUpdate() |
144 { |
142 { |
149 return true; |
147 return true; |
150 } |
148 } |
151 |
149 |
152 void IRFavoritesModel::clearAndDestroyLogos() |
150 void IRFavoritesModel::clearAndDestroyLogos() |
153 { |
151 { |
154 for (QMap<int, HbIcon*>::iterator it = iLogos.begin(); it != iLogos.end(); ++it) |
152 int size = iLogos.size(); |
155 { |
153 for (int i = 0; i < size; i ++) |
156 delete it.value(); |
154 { |
157 } |
155 delete iLogos[i]; |
158 |
156 iLogos[i] = NULL; |
|
157 } |
159 iLogos.clear(); |
158 iLogos.clear(); |
160 } |
159 } |
161 |
160 |
162 void IRFavoritesModel::clearFavoriteDB() |
161 void IRFavoritesModel::clearFavoriteDB() |
163 { |
162 { |
195 iPresetsList = NULL; |
194 iPresetsList = NULL; |
196 } |
195 } |
197 |
196 |
198 bool IRFavoritesModel::deleteOneFavorite(int aIndex) |
197 bool IRFavoritesModel::deleteOneFavorite(int aIndex) |
199 { |
198 { |
200 if( aIndex < 0 || aIndex >= iPresetsList->size()) |
199 if ( aIndex < 0 || aIndex >= iPresetsList->size()) |
201 { |
200 { |
202 return false; |
201 return false; |
203 } |
202 } |
204 |
203 |
205 IRQPreset *preset = iPresetsList->at(aIndex); |
204 IRQPreset *preset = iPresetsList->at(aIndex); |
206 int ret = iFavoritesDb->deletePreset(preset->uniqID); |
205 int ret = iFavoritesDb->deletePreset(preset->uniqID); |
207 |
206 if ( 0 != ret ) |
208 |
|
209 if( 0 != ret ) |
|
210 { |
207 { |
211 return false; |
208 return false; |
212 } |
209 } |
213 |
210 |
214 beginRemoveRows(QModelIndex(), aIndex, aIndex); |
211 beginRemoveRows(QModelIndex(), aIndex, aIndex); |
215 iPresetsList->removeAt(aIndex); |
212 iPresetsList->removeAt(aIndex); |
|
213 |
|
214 if (aIndex<iLogos.size()) |
|
215 { |
|
216 delete iLogos[aIndex]; |
|
217 iLogos[aIndex] = NULL; |
|
218 } |
|
219 iLogos.removeAt(aIndex); |
216 endRemoveRows(); |
220 endRemoveRows(); |
217 emit modelChanged(); |
221 emit modelChanged(); |
218 return true; |
222 return true; |
219 } |
223 } |
220 |
224 |