51 model, indicates that the item with \a containerId , \a itemId is to |
51 model, indicates that the item with \a containerId , \a itemId is to |
52 be moved from \a itemOrdinal to \a newOrdinal. |
52 be moved from \a itemOrdinal to \a newOrdinal. |
53 */ |
53 */ |
54 |
54 |
55 /*! |
55 /*! |
|
56 \fn void dataReloaded() |
|
57 |
|
58 This signal is emitted when there has been a changed in the data represented |
|
59 by this model. This signal is emitted so that the view owning this model can |
|
60 refresh the view. This can happen after operations like delete and several |
|
61 playlist related operations (save, rearrange, remove). |
|
62 */ |
|
63 |
|
64 /*! |
56 Constructs the collection data model. |
65 Constructs the collection data model. |
57 */ |
66 */ |
58 MpCollectionDataModel::MpCollectionDataModel( MpMpxCollectionData *data, QObject *parent ) |
67 MpCollectionDataModel::MpCollectionDataModel( MpMpxCollectionData *data, QObject *parent ) |
59 : QAbstractListModel(parent), |
68 : QAbstractListModel(parent), |
60 mCollectionData(data), |
69 mCollectionData(data), |
61 mRowCount(0) |
70 mRowCount(0), |
|
71 mAlbumIndexOffset(0) |
62 { |
72 { |
63 TX_ENTRY |
73 TX_ENTRY |
|
74 connect( mCollectionData, SIGNAL(contextChanged(TCollectionContext)), this, SLOT(setContext(TCollectionContext)) ); |
|
75 connect( mCollectionData, SIGNAL(dataChanged()), this, SLOT(reloadData()) ); |
64 mAlbumArtManager = new MpCollectionAlbumArtManager(mCollectionData); |
76 mAlbumArtManager = new MpCollectionAlbumArtManager(mCollectionData); |
65 connect( mAlbumArtManager, SIGNAL(albumArtReady(int)), this, SLOT(updateAlbumArt(int)) ); |
77 connect( mAlbumArtManager, SIGNAL(albumArtReady(int)), this, SLOT(updateAlbumArt(int)) ); |
66 TX_EXIT |
78 TX_EXIT |
67 } |
79 } |
68 |
80 |
103 QVariant returnValue = QVariant(); |
115 QVariant returnValue = QVariant(); |
104 if ( !index.isValid() ) { |
116 if ( !index.isValid() ) { |
105 return returnValue; |
117 return returnValue; |
106 } |
118 } |
107 |
119 |
108 int row = index.row(); |
120 int row = index.row() + mAlbumIndexOffset; |
109 TX_LOG_ARGS("index=" << row << ", role=" << role); |
121 TX_LOG_ARGS("index=" << row << ", role=" << role); |
110 TCollectionContext context = mCollectionData->context(); |
122 TCollectionContext context = mCollectionData->context(); |
111 if ( role == Qt::DisplayRole ) { |
123 if ( role == Qt::DisplayRole ) { |
112 QStringList display; |
124 QStringList display; |
113 // Fetch the primary text, which is the title, if available. |
125 // Fetch the primary text, which is the title, if available. |
114 QString primaryText; |
126 QString primaryText; |
115 primaryText = mCollectionData->itemData(row, MpMpxCollectionData::Title); |
127 switch ( context ) { |
116 if ( !primaryText.isEmpty() ) { |
128 case ECollectionContextAllSongs: |
117 display << primaryText; |
129 case ECollectionContextArtists: |
|
130 case ECollectionContextAlbums: |
|
131 case ECollectionContextArtistAlbums: |
|
132 case ECollectionContextPlaylists: |
|
133 case ECollectionContextPlaylistSongs: |
|
134 case ECollectionContextAlbumsTBone: |
|
135 case ECollectionContextArtistAlbumsTBone: |
|
136 case ECollectionContextArtistAllSongs: |
|
137 primaryText = mCollectionData->itemData(row, MpMpxCollectionData::Title); |
|
138 if ( !primaryText.isEmpty() ) { |
|
139 display << primaryText; |
|
140 } |
|
141 else { |
|
142 display << hbTrId("txt_mus_other_unknown4"); |
|
143 } |
|
144 break; |
|
145 case ECollectionContextAlbumsMediaWall: |
|
146 primaryText = mCollectionData->itemData(row, MpMpxCollectionData::Artist); |
|
147 if ( !primaryText.isEmpty() ) { |
|
148 display << primaryText; |
|
149 } |
|
150 else { |
|
151 display << hbTrId("txt_mus_other_unknown4"); |
|
152 } |
|
153 break; |
|
154 default: |
|
155 break; |
118 } |
156 } |
119 else { |
157 |
120 display << hbTrId("txt_mus_other_unknown4"); |
|
121 } |
|
122 |
|
123 // Fetch the secondary text, which depends on the current context, if available. |
158 // Fetch the secondary text, which depends on the current context, if available. |
124 QString secondaryText; |
159 QString secondaryText; |
125 switch ( context ) { |
160 switch ( context ) { |
126 case ECollectionContextAllSongs: |
161 case ECollectionContextAllSongs: |
127 case ECollectionContextAlbums: |
162 case ECollectionContextAlbums: |
128 case ECollectionContextPlaylistSongs: |
163 case ECollectionContextPlaylistSongs: |
|
164 case ECollectionContextAlbumsTBone: |
129 secondaryText = mCollectionData->itemData(row, MpMpxCollectionData::Artist); |
165 secondaryText = mCollectionData->itemData(row, MpMpxCollectionData::Artist); |
130 if ( !secondaryText.isEmpty() ) { |
166 if ( !secondaryText.isEmpty() ) { |
131 display << secondaryText; |
167 display << secondaryText; |
132 } |
168 } |
133 else { |
169 else { |
134 display << hbTrId("txt_mus_other_unknown3"); |
170 display << hbTrId("txt_mus_other_unknown3"); |
135 } |
171 } |
136 break; |
172 break; |
137 case ECollectionContextArtistSongs: |
173 case ECollectionContextArtistAlbumsTBone: |
|
174 secondaryText = mCollectionData->collectionTitle(); |
|
175 if ( !secondaryText.isEmpty() ) { |
|
176 display << secondaryText; |
|
177 } |
|
178 else { |
|
179 display << hbTrId("txt_mus_other_unknown3"); |
|
180 } |
|
181 break; |
|
182 case ECollectionContextArtistAllSongs: |
138 secondaryText = mCollectionData->itemData(row, MpMpxCollectionData::Album); |
183 secondaryText = mCollectionData->itemData(row, MpMpxCollectionData::Album); |
139 if ( !secondaryText.isEmpty() ) { |
184 if ( !secondaryText.isEmpty() ) { |
140 display << secondaryText; |
185 display << secondaryText; |
141 } |
186 } |
142 else { |
187 else { |
143 display << hbTrId("txt_mus_other_unknown4"); |
188 display << hbTrId("txt_mus_other_unknown4"); |
144 } |
189 } |
145 break; |
190 break; |
|
191 case ECollectionContextAlbumsMediaWall: |
|
192 secondaryText = mCollectionData->itemData(row, MpMpxCollectionData::Title); |
|
193 if ( !secondaryText.isEmpty() ) { |
|
194 display << secondaryText; |
|
195 } |
|
196 else { |
|
197 display << hbTrId("txt_mus_other_unknown3"); |
|
198 } |
|
199 break; |
146 default: |
200 default: |
147 break; |
201 break; |
148 } |
202 } |
149 returnValue = display; |
203 returnValue = display; |
150 } |
204 } |
151 else if ( role == Qt::DecorationRole ) { |
205 else if ( role == Qt::DecorationRole ) { |
152 switch ( context ) { |
206 switch ( context ) { |
153 case ECollectionContextAlbums: |
207 case ECollectionContextAlbums: |
|
208 case ECollectionContextAlbumsMediaWall: |
|
209 case ECollectionContextArtistAlbumsTBone: |
|
210 case ECollectionContextAlbumsTBone: |
|
211 returnValue = mAlbumArtManager->albumArt( row ) ; |
|
212 break; |
154 case ECollectionContextArtistAlbums: |
213 case ECollectionContextArtistAlbums: |
155 const QIcon *icon = mAlbumArtManager->albumArt(row); |
214 if ( row == 0 ) { |
156 QVariant iconVariant(QVariant::Icon, icon); |
215 returnValue = HbIcon( "qtg_small_sound" ); |
157 returnValue = iconVariant; |
216 } |
|
217 else { |
|
218 returnValue = mAlbumArtManager->albumArt( row ); |
|
219 } |
158 break; |
220 break; |
159 } |
221 } |
160 } |
222 } |
161 else if ( role == Hb::IndexFeedbackRole ) { |
223 else if ( role == Hb::IndexFeedbackRole ) { |
162 QString feedbackIndex; |
224 QString feedbackIndex; |
163 feedbackIndex = mCollectionData->itemData(row, MpMpxCollectionData::Title); |
225 switch ( context ) { |
|
226 case ECollectionContextAllSongs: |
|
227 case ECollectionContextArtists: |
|
228 case ECollectionContextAlbums: |
|
229 case ECollectionContextArtistAlbums: |
|
230 case ECollectionContextPlaylists: |
|
231 case ECollectionContextPlaylistSongs: |
|
232 case ECollectionContextAlbumsTBone: |
|
233 case ECollectionContextArtistAlbumsTBone: |
|
234 case ECollectionContextArtistAllSongs: |
|
235 feedbackIndex = mCollectionData->itemData(row, MpMpxCollectionData::Title); |
|
236 break; |
|
237 case ECollectionContextAlbumsMediaWall: |
|
238 feedbackIndex = mCollectionData->itemData(row, MpMpxCollectionData::Artist); |
|
239 break; |
|
240 default: |
|
241 break; |
|
242 } |
164 returnValue = feedbackIndex; |
243 returnValue = feedbackIndex; |
165 } |
244 } |
166 TX_EXIT |
245 TX_EXIT |
167 return returnValue; |
246 return returnValue; |
168 } |
247 } |
274 { |
353 { |
275 return mCollectionData; |
354 return mCollectionData; |
276 } |
355 } |
277 |
356 |
278 /*! |
357 /*! |
|
358 Slot to be called when collection context is changed. |
|
359 */ |
|
360 void MpCollectionDataModel::setContext( TCollectionContext context ) |
|
361 { |
|
362 TX_ENTRY_ARGS( "context=" << context ); |
|
363 // Reset the album index offset for navigation |
|
364 mAlbumIndexOffset = 0; |
|
365 switch ( context ) { |
|
366 case ECollectionContextArtistAlbums: |
|
367 case ECollectionContextAlbums: |
|
368 mAlbumArtManager->setThumbnailSize( MpCommon::ListThumb ); |
|
369 mAlbumArtManager->enableDefaultArt( true ); |
|
370 break; |
|
371 case ECollectionContextArtistAlbumsTBone: |
|
372 if ( mCollectionData->count() > 1 ) { |
|
373 // Selected artist has more than 1 album and therefore the |
|
374 // artist's "All songs" exist. Since we don't show artist's |
|
375 // "All songs" in TBone, we need to set an offset. |
|
376 mAlbumIndexOffset = 1; |
|
377 } |
|
378 //intentional fallthrough |
|
379 case ECollectionContextAlbumsTBone: |
|
380 mAlbumArtManager->setThumbnailSize( MpCommon::TBoneThumb ); |
|
381 mAlbumArtManager->enableDefaultArt( false ); |
|
382 break; |
|
383 case ECollectionContextAlbumsMediaWall: |
|
384 mAlbumArtManager->setThumbnailSize( MpCommon::MediaWallThumb ); |
|
385 mAlbumArtManager->enableDefaultArt( false ); |
|
386 break; |
|
387 default: |
|
388 break; |
|
389 } |
|
390 TX_EXIT |
|
391 } |
|
392 |
|
393 /*! |
279 Slot to be called when album art for the \a index needs to be updated. |
394 Slot to be called when album art for the \a index needs to be updated. |
280 */ |
395 */ |
281 void MpCollectionDataModel::updateAlbumArt( int index ) |
396 void MpCollectionDataModel::updateAlbumArt( int index ) |
282 { |
397 { |
283 TX_ENTRY_ARGS("index=" << index); |
398 TX_ENTRY_ARGS("index=" << index); |
|
399 |
|
400 index -= mAlbumIndexOffset; |
284 if ( index >= 0 && index < mRowCount ) { |
401 if ( index >= 0 && index < mRowCount ) { |
285 QModelIndex modelIndex = QAbstractItemModel::createIndex(index, 0); |
402 QModelIndex modelIndex = QAbstractItemModel::createIndex(index, 0); |
286 emit dataChanged(modelIndex, modelIndex); |
403 emit dataChanged(modelIndex, modelIndex); |
287 } |
404 } |
288 TX_EXIT |
405 TX_EXIT |
298 // Cancel all outstanding album art request first, then reset the model. |
415 // Cancel all outstanding album art request first, then reset the model. |
299 mAlbumArtManager->cancel(); |
416 mAlbumArtManager->cancel(); |
300 mRowCount = mCollectionData->count(); |
417 mRowCount = mCollectionData->count(); |
301 |
418 |
302 TCollectionContext context = mCollectionData->context(); |
419 TCollectionContext context = mCollectionData->context(); |
303 if ( context == ECollectionContextAlbums || ECollectionContextArtistAlbums ) { |
420 if ( context == ECollectionContextAlbums || |
|
421 context == ECollectionContextArtistAlbums || |
|
422 context == ECollectionContextAlbumsMediaWall ) { |
304 // Before providing the new data to the view (list, grid, etc.), we want |
423 // Before providing the new data to the view (list, grid, etc.), we want |
305 // to make sure that we have enough album arts for the first screen. |
424 // to make sure that we have enough album arts for the first screen. |
306 mAlbumArtManager->cacheFirstScreen(); |
425 mAlbumArtManager->cacheFirstScreen(); |
307 } |
426 } |
308 reset(); |
427 reset(); |
309 TX_EXIT |
428 TX_EXIT |
310 } |
429 } |
311 |
430 |
|
431 /*! |
|
432 Slot to be called when data has changed (same context) and model needs to reload |
|
433 the data. |
|
434 */ |
|
435 void MpCollectionDataModel::reloadData() |
|
436 { |
|
437 TX_ENTRY |
|
438 mAlbumArtManager->cancel(); |
|
439 mRowCount = mCollectionData->count(); |
|
440 reset(); |
|
441 emit dataReloaded(); |
|
442 TX_EXIT |
|
443 } |
|
444 |