34 by MpCollectionContainer. It provides a layout and widgets for the |
38 by MpCollectionContainer. It provides a layout and widgets for the |
35 'Albums' view. |
39 'Albums' view. |
36 |
40 |
37 This container handles the following contexts: |
41 This container handles the following contexts: |
38 \li ECollectionContextAlbums |
42 \li ECollectionContextAlbums |
39 \li ECollectionContextAlbumSongs |
43 \li ECollectionContextAlbumsTBone |
40 |
44 |
41 \sa MpCollectionContainer |
45 \sa MpCollectionContainer |
42 */ |
46 */ |
43 |
47 |
44 /*! |
48 /*! |
45 Constructs the collection container. |
49 Constructs the collection container. |
46 */ |
50 */ |
47 MpCollectionContainerAlbums::MpCollectionContainerAlbums( HbDocumentLoader *loader, QGraphicsItem *parent ) |
51 MpCollectionContainerAlbums::MpCollectionContainerAlbums( HbDocumentLoader *loader, QGraphicsItem *parent ) |
48 : MpCollectionListContainer(loader, parent), |
52 : MpCollectionListContainer(loader, parent), |
49 mInfoBar(0) |
53 mInfoBar(0), |
|
54 mTBone(0), |
|
55 mTBoneListModel(0), |
|
56 mCurrentAlbumIndex(0) |
50 { |
57 { |
51 TX_LOG |
58 TX_LOG |
|
59 mCollectionContext = ECollectionContextAlbums; |
52 } |
60 } |
53 |
61 |
54 /*! |
62 /*! |
55 Destructs the collection container. |
63 Destructs the collection container. |
56 */ |
64 */ |
57 MpCollectionContainerAlbums::~MpCollectionContainerAlbums() |
65 MpCollectionContainerAlbums::~MpCollectionContainerAlbums() |
58 { |
66 { |
59 TX_ENTRY |
67 TX_ENTRY |
60 delete mInfoBar; |
68 delete mInfoBar; |
|
69 delete mTBone; |
61 delete mList; |
70 delete mList; |
|
71 delete mTBoneListModel; |
|
72 TX_EXIT |
|
73 } |
|
74 |
|
75 /*! |
|
76 Sets the data model for the container. |
|
77 */ |
|
78 void MpCollectionContainerAlbums::setDataModel( MpCollectionDataModel *dataModel ) |
|
79 { |
|
80 TX_ENTRY |
|
81 MpCollectionContainer::setDataModel(dataModel); |
|
82 if ( mCollectionContext == ECollectionContextAlbums ) { |
|
83 if ( mList ) { |
|
84 mList->setModel(dataModel); |
|
85 if ( mCollectionData->count() ) { |
|
86 mList->scrollTo( dataModel->index(mCurrentAlbumIndex, 0) ); |
|
87 } |
|
88 } |
|
89 } |
|
90 else if ( mCollectionContext == ECollectionContextAlbumsTBone ) { |
|
91 if ( mTBone ) { |
|
92 mTBone->setModel(dataModel); |
|
93 mTBone->scrollTo( dataModel->index(mCurrentAlbumIndex, 0) ); |
|
94 if ( mTBoneListModel == 0 ) { |
|
95 mTBoneListModel = new MpCollectionTBoneListDataModel(mCollectionData); |
|
96 connect( mTBoneListModel, SIGNAL(albumDataChanged()), this, SLOT(albumDataChanged()) ); |
|
97 } |
|
98 mList->setModel(mTBoneListModel); |
|
99 if ( !mCollectionData->setCurrentAlbum(mCurrentAlbumIndex) ) { |
|
100 emit findAlbumSongs(mCurrentAlbumIndex); |
|
101 } |
|
102 } |
|
103 } |
62 TX_EXIT |
104 TX_EXIT |
63 } |
105 } |
64 |
106 |
65 /*! |
107 /*! |
66 Slot to be called when an item is selected by the user. |
108 Slot to be called when an item is selected by the user. |
67 */ |
109 */ |
68 void MpCollectionContainerAlbums::itemActivated( const QModelIndex &index ) |
110 void MpCollectionContainerAlbums::itemActivated( const QModelIndex &index ) |
69 { |
111 { |
70 int row = index.row(); |
112 if ( mCollectionContext == ECollectionContextAlbums ) { |
71 TX_ENTRY_ARGS("index=" << row); |
113 mCurrentAlbumIndex = index.row(); |
72 |
114 TX_ENTRY_ARGS("mCurrentAlbumIndex=" << mCurrentAlbumIndex); |
73 mAlbum = mCollectionData->itemData(row, MpMpxCollectionData::Title); |
115 MpCollectionListContainer::itemActivated(index); |
74 if ( mAlbum.isEmpty() ) { |
116 } |
75 mAlbum = hbTrId("txt_mus_dblist_val_unknown3"); |
117 else if ( mCollectionContext == ECollectionContextAlbumsTBone ) { |
76 } |
118 int row = index.row(); |
77 |
119 TX_ENTRY_ARGS("index=" << row); |
78 mArtist = mCollectionData->itemData(row, MpMpxCollectionData::Artist); |
120 if ( mViewMode == MpCommon::FetchView ) { |
79 if ( mArtist.isEmpty() ) { |
121 MpCollectionListContainer::itemActivated(index); |
80 mArtist = hbTrId("txt_mus_subtitle_unknown"); |
122 } |
81 } |
123 else { |
82 |
124 emit playAlbumSongs(mCurrentAlbumIndex, row); |
83 MpCollectionListContainer::itemActivated(index); |
125 } |
|
126 } |
|
127 TX_EXIT |
|
128 } |
|
129 |
|
130 /*! |
|
131 Slot to be called when scrolling ends in media wall and an album is centered. |
|
132 */ |
|
133 void MpCollectionContainerAlbums::albumCentered() |
|
134 { |
|
135 TX_ENTRY |
|
136 QModelIndex index = mTBone->currentIndex(); |
|
137 if ( mCurrentAlbumIndex != index.row() ) { |
|
138 // Prevent reloading if user just moves the center album a little |
|
139 // and the same album re-centers. |
|
140 mCurrentAlbumIndex = index.row(); |
|
141 TX_LOG_ARGS("mCurrentAlbumIndex=" << mCurrentAlbumIndex); |
|
142 if ( !mCollectionData->setCurrentAlbum(mCurrentAlbumIndex) ) { |
|
143 emit findAlbumSongs(mCurrentAlbumIndex); |
|
144 } |
|
145 } |
|
146 TX_EXIT |
|
147 } |
|
148 |
|
149 /*! |
|
150 Slot to be called data model has new data. |
|
151 Two cases: |
|
152 1) User deleted an album. |
|
153 2) User deleted last song in an album. |
|
154 */ |
|
155 void MpCollectionContainerAlbums::dataReloaded() |
|
156 { |
|
157 TX_ENTRY |
|
158 if ( mCollectionContext == ECollectionContextAlbumsTBone ) { |
|
159 if ( mCurrentAlbumIndex > 0 ) { |
|
160 --mCurrentAlbumIndex; |
|
161 } |
|
162 mTBone->scrollTo( mDataModel->index(mCurrentAlbumIndex, 0) ); |
|
163 if ( !mCollectionData->setCurrentAlbum(mCurrentAlbumIndex) ) { |
|
164 emit findAlbumSongs(mCurrentAlbumIndex); |
|
165 } |
|
166 } |
|
167 else { |
|
168 MpCollectionListContainer::dataReloaded(); |
|
169 } |
|
170 TX_EXIT |
|
171 } |
|
172 |
|
173 /*! |
|
174 Slot to be called data model has new data. |
|
175 User has deleted one of the songs from TBone list. |
|
176 */ |
|
177 void MpCollectionContainerAlbums::albumDataChanged() |
|
178 { |
|
179 TX_ENTRY |
|
180 emit findAlbumSongs(mCurrentAlbumIndex); |
84 TX_EXIT |
181 TX_EXIT |
85 } |
182 } |
86 |
183 |
87 /*! |
184 /*! |
88 Sets up the container by organizing widgets according to its layout. |
185 Sets up the container by organizing widgets according to its layout. |
109 } |
206 } |
110 if ( mInfoBar ) { |
207 if ( mInfoBar ) { |
111 delete mInfoBar; |
208 delete mInfoBar; |
112 mInfoBar = 0; |
209 mInfoBar = 0; |
113 } |
210 } |
114 } |
211 if ( mTBone ) { |
115 else if ( mCollectionContext == ECollectionContextAlbumSongs ) { |
212 delete mTBone; |
116 mDocumentLoader->load(QString(":/docml/musiccollection.docml"), "albumSongs", &ok); |
213 mTBone = 0; |
117 if ( !ok ) { |
214 } |
118 TX_LOG_ARGS("Error: invalid xml file."); |
215 } |
119 Q_ASSERT_X(ok, "MpCollectionContainerAlbums::setupContainer", "invalid xml file"); |
216 else if ( mCollectionContext == ECollectionContextAlbumsTBone ) { |
120 } |
|
121 |
|
122 widget = mDocumentLoader->findWidget(QString("albumSongsDetail")); |
|
123 mInfoBar = qobject_cast<HbGroupBox*>(widget); |
|
124 |
|
125 QString details; |
|
126 if ( mViewMode == MpCommon::FetchView ) { |
217 if ( mViewMode == MpCommon::FetchView ) { |
127 details = "Select a song"; |
218 mDocumentLoader->load(QString(":/docml/musiccollection.docml"), "albumTBoneFetcher", &ok); |
|
219 if ( !ok ) { |
|
220 TX_LOG_ARGS("Error: invalid xml file."); |
|
221 Q_ASSERT_X(ok, "MpCollectionContainerAlbums::setupContainer", "invalid xml file"); |
|
222 } |
|
223 widget = mDocumentLoader->findWidget(QString("albumTBoneDetail")); |
|
224 mInfoBar = qobject_cast<HbGroupBox*>(widget); |
|
225 mInfoBar->setHeading( hbTrId("txt_mus_subtitle_select_a_song") ); |
128 } |
226 } |
129 else { |
227 else { |
130 details = mArtist; |
228 mDocumentLoader->load(QString(":/docml/musiccollection.docml"), "albumTBone", &ok); |
131 details.append(" : "); |
229 if ( !ok ) { |
132 details.append(mAlbum); |
230 TX_LOG_ARGS("Error: invalid xml file."); |
133 } |
231 Q_ASSERT_X(ok, "MpCollectionContainerAlbums::setupContainer", "invalid xml file"); |
134 mInfoBar->setHeading(details); |
232 } |
|
233 } |
|
234 widget = mDocumentLoader->findWidget(QString("albumWall")); |
|
235 mTBone = qobject_cast<HgMediawall*>(widget); |
|
236 HbIcon defaultIcon( "qtg_large_music_album" ); |
|
237 defaultIcon.setSize(mTBone->itemSize()); |
|
238 mTBone->setDefaultImage( defaultIcon.pixmap().toImage() ); |
|
239 mTBone->setTitleFontSpec( HbFontSpec(HbFontSpec::Primary) ); |
|
240 mTBone->setDescriptionFontSpec( HbFontSpec(HbFontSpec::Secondary) ); |
|
241 mTBone->setScrollBarPolicy( HgWidget::ScrollBarAlwaysOff ); |
|
242 mTBone->enableReflections(true); |
|
243 connect( mTBone, SIGNAL(scrollingEnded()), this, SLOT(albumCentered()) ); |
135 } |
244 } |
136 } |
245 } |
137 else { |
246 else { |
|
247 // Must delete widgets when last song is deleted and view is reloaded. |
138 if ( mInfoBar ) { |
248 if ( mInfoBar ) { |
139 // When last song in an album is deleted and album list is reloaded |
|
140 delete mInfoBar; |
249 delete mInfoBar; |
141 mInfoBar = 0; |
250 mInfoBar = 0; |
142 } |
251 } |
|
252 if ( mTBone ) { |
|
253 delete mTBone; |
|
254 mTBone = 0; |
|
255 } |
143 // Call empty list from base class |
256 // Call empty list from base class |
144 setupEmptyListContainer(); |
257 setupEmptyListContainer(); |
145 } |
258 } |
146 TX_EXIT |
259 TX_EXIT |
147 } |
260 } |