24 #include <hgwidgets.h> |
24 #include <hgwidgets.h> |
25 |
25 |
26 |
26 |
27 #include "mpcollectiondatamodel.h" |
27 #include "mpcollectiondatamodel.h" |
28 #include "mpcollectionalbumartmanager.h" |
28 #include "mpcollectionalbumartmanager.h" |
|
29 #include "mpplaybackdata.h" |
29 #include "mpmpxcollectiondata.h" |
30 #include "mpmpxcollectiondata.h" |
30 #include "mptrace.h" |
31 #include "mptrace.h" |
31 |
32 |
32 /*! |
33 /*! |
33 \class MpCollectionDataModel |
34 \class MpCollectionDataModel |
65 */ |
66 */ |
66 |
67 |
67 /*! |
68 /*! |
68 Constructs the collection data model. |
69 Constructs the collection data model. |
69 */ |
70 */ |
70 MpCollectionDataModel::MpCollectionDataModel( MpMpxCollectionData *data, QObject *parent ) |
71 MpCollectionDataModel::MpCollectionDataModel( MpMpxCollectionData *data, MpPlaybackData *playbackData, QObject *parent ) |
71 : QAbstractListModel( parent ), |
72 : QAbstractListModel(parent), |
72 mCollectionData( data ), |
73 mCollectionData(data), |
73 mRowCount( 0 ), |
74 mPlaybackData(playbackData), |
74 mAlbumIndexOffset( 0 ), |
75 mRowCount(0), |
75 mHiddenItemIndex( -1 ) |
76 mAlbumIndexOffset(0), |
|
77 mHiddenItemIndex(-1), |
|
78 mCollectionLayout(ECollectionListView) |
76 { |
79 { |
77 TX_ENTRY |
80 TX_ENTRY |
78 connect( mCollectionData, SIGNAL(contextChanged(TCollectionContext)), this, SLOT(setContext(TCollectionContext)) ); |
81 connect( mCollectionData, SIGNAL(contextChanged(TCollectionContext)), this, SLOT(setContext(TCollectionContext)) ); |
79 connect( mCollectionData, SIGNAL(dataChanged()), this, SLOT(reloadData()) ); |
82 connect( mCollectionData, SIGNAL(dataChanged()), this, SLOT(reloadData()) ); |
|
83 connect( mCollectionData, SIGNAL(dataChanged(int, int)), this, SLOT(reloadData(int, int)) ); |
80 mAlbumArtManager = new MpCollectionAlbumArtManager(mCollectionData); |
84 mAlbumArtManager = new MpCollectionAlbumArtManager(mCollectionData); |
81 connect( mAlbumArtManager, SIGNAL(albumArtReady(int)), this, SLOT(updateAlbumArt(int)) ); |
85 connect( mAlbumArtManager, SIGNAL(albumArtReady(int)), this, SLOT(updateAlbumArt(int)) ); |
|
86 |
|
87 if ( mPlaybackData ) { |
|
88 connect( mPlaybackData, SIGNAL(fileCorrupted(int)), |
|
89 this, SLOT(fileCorrupted(int)) ); |
|
90 } |
82 TX_EXIT |
91 TX_EXIT |
83 } |
92 } |
84 |
93 |
85 /*! |
94 /*! |
86 Destructs the collection data model. |
95 Destructs the collection data model. |
141 primaryText = mCollectionData->itemData(row, MpMpxCollectionData::Title); |
150 primaryText = mCollectionData->itemData(row, MpMpxCollectionData::Title); |
142 if ( !primaryText.isEmpty() ) { |
151 if ( !primaryText.isEmpty() ) { |
143 display << primaryText; |
152 display << primaryText; |
144 } |
153 } |
145 else { |
154 else { |
146 display << hbTrId("txt_mus_other_unknown4"); |
155 switch ( context ) { |
|
156 case ECollectionContextArtists: |
|
157 display << hbTrId("txt_mus_list_unknown"); |
|
158 break; |
|
159 case ECollectionContextArtistAlbums: |
|
160 case ECollectionContextAlbums: |
|
161 display << hbTrId("txt_mus_dblist_unknown"); |
|
162 break; |
|
163 case ECollectionContextAlbumsTBone: |
|
164 case ECollectionContextArtistAlbumsTBone: |
|
165 display << hbTrId("txt_mus_other_unknown8"); |
|
166 break; |
|
167 default: |
|
168 // Otherwise the primary text should be the Song Title or File Name |
|
169 // but can not be empty, if so there is an error. |
|
170 TX_LOG_ARGS("Error: Song title empty."); |
|
171 break; |
|
172 } |
147 } |
173 } |
148 break; |
174 break; |
149 case ECollectionContextAlbumsMediaWall: |
175 case ECollectionContextAlbumsMediaWall: |
150 primaryText = mCollectionData->itemData(row, MpMpxCollectionData::Artist); |
176 primaryText = mCollectionData->itemData(row, MpMpxCollectionData::Artist); |
151 if ( !primaryText.isEmpty() ) { |
177 if ( !primaryText.isEmpty() ) { |
152 display << primaryText; |
178 display << primaryText; |
153 } |
179 } |
154 else { |
180 else { |
155 display << hbTrId("txt_mus_other_unknown4"); |
181 display << hbTrId("txt_mus_other_unknown2"); |
156 } |
182 } |
157 break; |
183 break; |
158 default: |
184 default: |
159 break; |
185 break; |
160 } |
186 } |
169 secondaryText = mCollectionData->itemData(row, MpMpxCollectionData::Artist); |
195 secondaryText = mCollectionData->itemData(row, MpMpxCollectionData::Artist); |
170 if ( !secondaryText.isEmpty() ) { |
196 if ( !secondaryText.isEmpty() ) { |
171 display << secondaryText; |
197 display << secondaryText; |
172 } |
198 } |
173 else { |
199 else { |
174 display << hbTrId("txt_mus_other_unknown3"); |
200 switch ( context ) { |
|
201 case ECollectionContextAllSongs: |
|
202 case ECollectionContextPlaylistSongs: |
|
203 if ( mCollectionLayout == ECollectionSelectionDialog ) { |
|
204 display << hbTrId("txt_mus_dblist_val_unknown4"); |
|
205 } |
|
206 else if ( mCollectionLayout == ECollectionArrangeSongsDialog ) { |
|
207 display << hbTrId("txt_mus_other_unknown9"); |
|
208 } |
|
209 else { |
|
210 display << hbTrId("txt_mus_dblist_val_unknown"); |
|
211 } |
|
212 break; |
|
213 case ECollectionContextAlbums: |
|
214 display << hbTrId("txt_mus_dblist_val_unknown2"); |
|
215 break; |
|
216 case ECollectionContextAlbumsTBone: |
|
217 display << hbTrId("txt_mus_other_unknown5"); |
|
218 break; |
|
219 } |
175 } |
220 } |
176 break; |
221 break; |
177 case ECollectionContextArtistAlbumsTBone: |
222 case ECollectionContextArtistAlbumsTBone: |
178 secondaryText = mCollectionData->collectionTitle(); |
223 secondaryText = mCollectionData->collectionTitle(); |
179 if ( !secondaryText.isEmpty() ) { |
224 if ( !secondaryText.isEmpty() ) { |
180 display << secondaryText; |
225 display << secondaryText; |
181 } |
226 } |
182 else { |
227 else { |
183 display << hbTrId("txt_mus_other_unknown3"); |
228 display << hbTrId("txt_mus_other_unknown5"); |
184 } |
229 } |
185 break; |
230 break; |
186 case ECollectionContextArtistAllSongs: |
231 case ECollectionContextArtistAllSongs: |
187 secondaryText = mCollectionData->itemData(row, MpMpxCollectionData::Album); |
232 secondaryText = mCollectionData->itemData(row, MpMpxCollectionData::Album); |
188 if ( !secondaryText.isEmpty() ) { |
233 if ( !secondaryText.isEmpty() ) { |
189 display << secondaryText; |
234 display << secondaryText; |
190 } |
235 } |
191 else { |
236 else { |
192 display << hbTrId("txt_mus_other_unknown4"); |
237 display << hbTrId("txt_mus_dblist_val_unknown3"); |
193 } |
238 } |
194 break; |
239 break; |
195 case ECollectionContextAlbumsMediaWall: |
240 case ECollectionContextAlbumsMediaWall: |
196 secondaryText = mCollectionData->itemData(row, MpMpxCollectionData::Title); |
241 secondaryText = mCollectionData->itemData(row, MpMpxCollectionData::Title); |
197 if ( !secondaryText.isEmpty() ) { |
242 if ( !secondaryText.isEmpty() ) { |
198 display << secondaryText; |
243 display << secondaryText; |
199 } |
244 } |
200 else { |
245 else { |
201 display << hbTrId("txt_mus_other_unknown3"); |
246 display << hbTrId("txt_mus_other_unknown1"); |
202 } |
247 } |
203 break; |
248 break; |
204 default: |
249 default: |
205 break; |
250 break; |
206 } |
251 } |
219 returnValue = HbIcon( "qtg_small_sound" ); |
264 returnValue = HbIcon( "qtg_small_sound" ); |
220 } |
265 } |
221 else { |
266 else { |
222 returnValue = mAlbumArtManager->albumArt( row ); |
267 returnValue = mAlbumArtManager->albumArt( row ); |
223 } |
268 } |
|
269 break; |
|
270 case ECollectionContextAllSongs: |
|
271 case ECollectionContextArtistAllSongs: |
|
272 case ECollectionContextPlaylistSongs: |
|
273 if( mCollectionData->hasItemProperty(row, MpMpxCollectionData::Corrupted) ){ |
|
274 QList<QVariant> iconList; |
|
275 iconList << QVariant(); |
|
276 iconList << HbIcon("qtg_mono_corrupted"); |
|
277 returnValue = iconList; |
|
278 } |
|
279 else if ( mCollectionData->hasItemProperty(row, MpMpxCollectionData::DrmExpired) ) { |
|
280 QList<QVariant> iconList; |
|
281 iconList << QVariant(); |
|
282 iconList << HbIcon("qtg_small_drm_rights_expired"); |
|
283 returnValue = iconList; |
|
284 } |
|
285 break; |
|
286 default: |
224 break; |
287 break; |
225 } |
288 } |
226 } |
289 } |
227 else if ( role == Hb::IndexFeedbackRole ) { |
290 else if ( role == Hb::IndexFeedbackRole ) { |
228 QString feedbackIndex; |
291 QString feedbackIndex; |
370 Returns pointer to MpMpxCollectionData, which is the collection data. |
433 Returns pointer to MpMpxCollectionData, which is the collection data. |
371 */ |
434 */ |
372 MpMpxCollectionData *MpCollectionDataModel::collectionData() |
435 MpMpxCollectionData *MpCollectionDataModel::collectionData() |
373 { |
436 { |
374 return mCollectionData; |
437 return mCollectionData; |
|
438 } |
|
439 |
|
440 /*! |
|
441 Sets the layout where the collection is being displayed. |
|
442 */ |
|
443 void MpCollectionDataModel::setLayout(TCollectionLayout layout) |
|
444 { |
|
445 mCollectionLayout = layout; |
375 } |
446 } |
376 |
447 |
377 /*! |
448 /*! |
378 Slot to be called when collection context is changed. |
449 Slot to be called when collection context is changed. |
379 */ |
450 */ |
417 { |
488 { |
418 TX_ENTRY_ARGS("index=" << index); |
489 TX_ENTRY_ARGS("index=" << index); |
419 |
490 |
420 index -= mAlbumIndexOffset; |
491 index -= mAlbumIndexOffset; |
421 if ( index >= 0 && index < mRowCount ) { |
492 if ( index >= 0 && index < mRowCount ) { |
422 QModelIndex modelIndex = QAbstractItemModel::createIndex(index, 0); |
493 emit dataChanged(this->index(index, 0), this->index(index, 0)); |
423 emit dataChanged(modelIndex, modelIndex); |
|
424 } |
494 } |
425 TX_EXIT |
495 TX_EXIT |
426 } |
496 } |
427 |
497 |
428 /*! |
498 /*! |
460 reset(); |
530 reset(); |
461 emit dataReloaded(); |
531 emit dataReloaded(); |
462 TX_EXIT |
532 TX_EXIT |
463 } |
533 } |
464 |
534 |
|
535 /*! |
|
536 Slot to be called when data has changed (same context) and model needs to reload |
|
537 the data in the specified range. |
|
538 */ |
|
539 void MpCollectionDataModel::reloadData( int fromIndex, int toIndex ) |
|
540 { |
|
541 TX_ENTRY_ARGS("fromIndex=" << fromIndex << ", toIndex=" << toIndex); |
|
542 emit dataChanged(this->index(fromIndex,0), this->index(toIndex,0)); |
|
543 TX_EXIT |
|
544 } |
|
545 |
|
546 /*! |
|
547 Slot to be called when a song is marked as corrupted |
|
548 */ |
|
549 void MpCollectionDataModel::fileCorrupted(int songId) |
|
550 { |
|
551 TX_ENTRY |
|
552 QModelIndex corruptedSongIndex; |
|
553 QList<int> indexList = mCollectionData->songIndex( songId ); |
|
554 for (int i = 0; i < indexList.count(); i++){ |
|
555 corruptedSongIndex = index( indexList.at(i) ); |
|
556 if ( corruptedSongIndex.isValid() && (!(mCollectionData->hasItemProperty(corruptedSongIndex.row(), |
|
557 MpMpxCollectionData::Corrupted)))) { |
|
558 |
|
559 mCollectionData->setCorruptValue(corruptedSongIndex, false); |
|
560 emit dataChanged( corruptedSongIndex, corruptedSongIndex ); |
|
561 } |
|
562 } |
|
563 TX_EXIT |
|
564 } |
|
565 |
|
566 |