35
|
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: Music Player secondary collection abstract data model. This is
|
|
15 |
* primarily used to support Mediawall in Collection View. This
|
|
16 |
* model represents the list containing album songs.
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
|
|
20 |
#include <hbnamespace.h>
|
|
21 |
|
|
22 |
#include "mpcollectiontbonelistdatamodel.h"
|
|
23 |
#include "mpmpxcollectiondata.h"
|
36
|
24 |
#include "mpplaybackdata.h"
|
35
|
25 |
#include "mptrace.h"
|
|
26 |
|
|
27 |
/*!
|
|
28 |
\class MpCollectionTBoneListDataModel
|
|
29 |
\brief Music Player collection data model.
|
|
30 |
|
|
31 |
Secondary collection data model implements the interface specified by
|
|
32 |
QAbstractListModel, which defines the standard interface that item models
|
|
33 |
must use to be able to interoperate with other components in the model/view
|
|
34 |
architecture.
|
|
35 |
|
|
36 |
Every item of data that can be accessed via a model has an associated model
|
|
37 |
index.
|
|
38 |
|
|
39 |
Each item has a number of data elements associated with it and they can be
|
|
40 |
retrieved by specifying a role (see Qt::ItemDataRole) to the model's data
|
|
41 |
returned by itemData() function.
|
|
42 |
|
|
43 |
MpCollectionTBoneListDataModel is primarily used to support Mediawall in
|
|
44 |
Collection View. This model represents the list containing album songs.
|
|
45 |
|
|
46 |
\sa QAbstractListModel
|
|
47 |
*/
|
|
48 |
|
|
49 |
/*!
|
|
50 |
\fn void albumDataChanged()
|
|
51 |
|
|
52 |
This signal is specific to views with TBone. This signal is emitted when
|
36
|
53 |
there's a change in album data. This is an indication that the container
|
|
54 |
should re-fetch the album content. Currently, the only operation that can
|
|
55 |
trigger this is the delete operation.
|
|
56 |
*/
|
|
57 |
|
|
58 |
/*!
|
|
59 |
\fn void albumDataAvailable()
|
|
60 |
|
|
61 |
This signal is specific to views with TBone. This signal is emitted when
|
|
62 |
a new data set is available for the list section of the TBone. This is
|
|
63 |
triggered as a result of container re-fetching the album content.
|
|
64 |
|
|
65 |
\sa albumDataChanged
|
35
|
66 |
*/
|
|
67 |
|
|
68 |
/*!
|
|
69 |
Constructs the collection data model.
|
|
70 |
*/
|
36
|
71 |
MpCollectionTBoneListDataModel::MpCollectionTBoneListDataModel( MpMpxCollectionData *collectionData,
|
|
72 |
MpPlaybackData *playbackData, QObject *parent )
|
|
73 |
: QAbstractListModel( parent ),
|
|
74 |
mCollectionData( collectionData ),
|
|
75 |
mPlaybackData( playbackData ),
|
37
|
76 |
mRowCount( 0 ),
|
|
77 |
mCurrentSongId( 0 ),
|
|
78 |
mPlaybackActive( false )
|
35
|
79 |
{
|
|
80 |
TX_ENTRY
|
|
81 |
connect( mCollectionData, SIGNAL(refreshAlbumSongs()),
|
|
82 |
this, SLOT(refreshModel()) );
|
|
83 |
connect( mCollectionData, SIGNAL(albumDataChanged()),
|
|
84 |
this, SIGNAL(albumDataChanged()) );
|
36
|
85 |
|
|
86 |
if ( mPlaybackData ) {
|
|
87 |
connect( mPlaybackData, SIGNAL(playbackInfoChanged()),
|
|
88 |
this, SLOT(updateSong()));
|
|
89 |
|
|
90 |
connect( mPlaybackData, SIGNAL(playbackStateChanged()),
|
|
91 |
this, SLOT(updatePlaybackState()));
|
|
92 |
mPlaybackActive = mPlaybackData->playbackState() != MpPlaybackData::NotPlaying;
|
|
93 |
}
|
|
94 |
|
35
|
95 |
TX_EXIT
|
|
96 |
}
|
|
97 |
|
|
98 |
/*!
|
|
99 |
Destructs the collection data model.
|
|
100 |
*/
|
|
101 |
MpCollectionTBoneListDataModel::~MpCollectionTBoneListDataModel()
|
|
102 |
{
|
|
103 |
TX_LOG
|
|
104 |
}
|
|
105 |
|
|
106 |
/*!
|
|
107 |
Returns the number of rows under the given \a parent.
|
|
108 |
|
|
109 |
\reimp
|
|
110 |
*/
|
|
111 |
int MpCollectionTBoneListDataModel::rowCount( const QModelIndex &parent ) const
|
|
112 |
{
|
|
113 |
TX_LOG
|
|
114 |
Q_UNUSED(parent);
|
|
115 |
return mRowCount;
|
|
116 |
}
|
|
117 |
|
|
118 |
/*!
|
|
119 |
Returns the data stored for the item referred to by the \a index.
|
|
120 |
|
|
121 |
\reimp
|
|
122 |
*/
|
|
123 |
QVariant MpCollectionTBoneListDataModel::data(const QModelIndex &index, int role) const
|
|
124 |
{
|
|
125 |
TX_ENTRY
|
|
126 |
QVariant returnValue = QVariant();
|
|
127 |
if ( !index.isValid() ) {
|
|
128 |
return returnValue;
|
|
129 |
}
|
|
130 |
|
|
131 |
int row = index.row();
|
|
132 |
TX_LOG_ARGS("index=" << row << ", role=" << role);
|
|
133 |
if ( role == Qt::DisplayRole ) {
|
|
134 |
// Fetch the primary text, which is the title, if available.
|
|
135 |
QString songTitle = mCollectionData->albumSongData(row, MpMpxCollectionData::Title);
|
|
136 |
if ( !songTitle.isEmpty() ) {
|
|
137 |
returnValue = songTitle;
|
|
138 |
}
|
|
139 |
else {
|
|
140 |
returnValue = hbTrId("txt_mus_other_unknown4");
|
|
141 |
}
|
|
142 |
}
|
36
|
143 |
else if ( role == Qt::DecorationRole ) {
|
37
|
144 |
if ( mPlaybackActive
|
|
145 |
&& mPlaybackData->id() == mCollectionData->albumSongId( row ) ) {
|
36
|
146 |
QList<QVariant> iconList;
|
|
147 |
iconList << QVariant(); //primary icon is not used.
|
37
|
148 |
|
|
149 |
iconList << HbIcon("qtg_small_speaker");
|
36
|
150 |
returnValue = iconList;
|
|
151 |
}
|
|
152 |
}
|
35
|
153 |
TX_EXIT
|
|
154 |
return returnValue;
|
|
155 |
}
|
|
156 |
|
|
157 |
/*!
|
|
158 |
Slot to be called when data has changed and model needs to be refreshed
|
|
159 |
to reflect the new data.
|
|
160 |
*/
|
|
161 |
void MpCollectionTBoneListDataModel::refreshModel()
|
|
162 |
{
|
|
163 |
TX_ENTRY
|
|
164 |
mRowCount = mCollectionData->albumSongsCount();
|
|
165 |
reset();
|
36
|
166 |
emit albumDataAvailable();
|
35
|
167 |
TX_EXIT
|
|
168 |
}
|
|
169 |
|
36
|
170 |
/*!
|
|
171 |
Slot to be called when playing song status has changed.
|
|
172 |
*/
|
|
173 |
void MpCollectionTBoneListDataModel::updateSong()
|
|
174 |
{
|
|
175 |
TX_ENTRY
|
|
176 |
int newSongId = mPlaybackData->id();
|
|
177 |
|
|
178 |
if ( mCurrentSongId && newSongId != mCurrentSongId) {
|
|
179 |
//Attempt to remove old song icon.
|
37
|
180 |
QModelIndex oldSongIndex;
|
|
181 |
oldSongIndex = index( mCollectionData->albumSongIndex( mCurrentSongId ) );
|
|
182 |
if ( oldSongIndex.isValid() ) {
|
|
183 |
emit dataChanged( oldSongIndex, oldSongIndex );
|
36
|
184 |
}
|
|
185 |
}
|
|
186 |
|
|
187 |
//Attempt to update current song data and state.
|
|
188 |
QModelIndex songIndex;
|
|
189 |
songIndex = index( mCollectionData->albumSongIndex( newSongId ) );
|
|
190 |
if ( songIndex.isValid() ) {
|
|
191 |
emit dataChanged( songIndex, songIndex );
|
|
192 |
}
|
|
193 |
mCurrentSongId = newSongId;
|
|
194 |
TX_EXIT
|
|
195 |
}
|
|
196 |
|
|
197 |
/*!
|
|
198 |
Slot to be called when playback state has changed.
|
|
199 |
*/
|
|
200 |
void MpCollectionTBoneListDataModel::updatePlaybackState()
|
|
201 |
{
|
|
202 |
//This logic is to account for when song plays the very first time, we get
|
|
203 |
//media before playback is active.
|
|
204 |
bool playbackWasActive = mPlaybackActive;
|
|
205 |
mPlaybackActive = mPlaybackData->playbackState() != MpPlaybackData::NotPlaying;
|
|
206 |
if ( mPlaybackActive && !playbackWasActive ) {
|
|
207 |
updateSong();
|
|
208 |
}
|
|
209 |
}
|
|
210 |
|
|
211 |
|
|
212 |
//EOF
|
|
213 |
|
|
214 |
|