|
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" |
|
24 #include "mptrace.h" |
|
25 |
|
26 /*! |
|
27 \class MpCollectionTBoneListDataModel |
|
28 \brief Music Player collection data model. |
|
29 |
|
30 Secondary collection data model implements the interface specified by |
|
31 QAbstractListModel, which defines the standard interface that item models |
|
32 must use to be able to interoperate with other components in the model/view |
|
33 architecture. |
|
34 |
|
35 Every item of data that can be accessed via a model has an associated model |
|
36 index. |
|
37 |
|
38 Each item has a number of data elements associated with it and they can be |
|
39 retrieved by specifying a role (see Qt::ItemDataRole) to the model's data |
|
40 returned by itemData() function. |
|
41 |
|
42 MpCollectionTBoneListDataModel is primarily used to support Mediawall in |
|
43 Collection View. This model represents the list containing album songs. |
|
44 |
|
45 \sa QAbstractListModel |
|
46 */ |
|
47 |
|
48 /*! |
|
49 \fn void albumDataChanged() |
|
50 |
|
51 This signal is specific to views with TBone. This signal is emitted when |
|
52 a new data set is available for the list section of the TBone. Currently, |
|
53 the only operation that can trigger this is the delete operation. |
|
54 */ |
|
55 |
|
56 /*! |
|
57 Constructs the collection data model. |
|
58 */ |
|
59 MpCollectionTBoneListDataModel::MpCollectionTBoneListDataModel( MpMpxCollectionData *data, QObject *parent ) |
|
60 : QAbstractListModel(parent), |
|
61 mCollectionData(data), |
|
62 mRowCount(0) |
|
63 { |
|
64 TX_ENTRY |
|
65 connect( mCollectionData, SIGNAL(refreshAlbumSongs()), |
|
66 this, SLOT(refreshModel()) ); |
|
67 connect( mCollectionData, SIGNAL(albumDataChanged()), |
|
68 this, SIGNAL(albumDataChanged()) ); |
|
69 TX_EXIT |
|
70 } |
|
71 |
|
72 /*! |
|
73 Destructs the collection data model. |
|
74 */ |
|
75 MpCollectionTBoneListDataModel::~MpCollectionTBoneListDataModel() |
|
76 { |
|
77 TX_LOG |
|
78 } |
|
79 |
|
80 /*! |
|
81 Returns the number of rows under the given \a parent. |
|
82 |
|
83 \reimp |
|
84 */ |
|
85 int MpCollectionTBoneListDataModel::rowCount( const QModelIndex &parent ) const |
|
86 { |
|
87 TX_LOG |
|
88 Q_UNUSED(parent); |
|
89 return mRowCount; |
|
90 } |
|
91 |
|
92 /*! |
|
93 Returns the data stored for the item referred to by the \a index. |
|
94 |
|
95 \reimp |
|
96 */ |
|
97 QVariant MpCollectionTBoneListDataModel::data(const QModelIndex &index, int role) const |
|
98 { |
|
99 TX_ENTRY |
|
100 QVariant returnValue = QVariant(); |
|
101 if ( !index.isValid() ) { |
|
102 return returnValue; |
|
103 } |
|
104 |
|
105 int row = index.row(); |
|
106 TX_LOG_ARGS("index=" << row << ", role=" << role); |
|
107 if ( role == Qt::DisplayRole ) { |
|
108 // Fetch the primary text, which is the title, if available. |
|
109 QString songTitle = mCollectionData->albumSongData(row, MpMpxCollectionData::Title); |
|
110 if ( !songTitle.isEmpty() ) { |
|
111 returnValue = songTitle; |
|
112 } |
|
113 else { |
|
114 returnValue = hbTrId("txt_mus_other_unknown4"); |
|
115 } |
|
116 } |
|
117 TX_EXIT |
|
118 return returnValue; |
|
119 } |
|
120 |
|
121 /*! |
|
122 Slot to be called when data has changed and model needs to be refreshed |
|
123 to reflect the new data. |
|
124 */ |
|
125 void MpCollectionTBoneListDataModel::refreshModel() |
|
126 { |
|
127 TX_ENTRY |
|
128 mRowCount = mCollectionData->albumSongsCount(); |
|
129 reset(); |
|
130 TX_EXIT |
|
131 } |
|
132 |