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: |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <QStringList> |
|
20 |
|
21 // User includes |
|
22 #include "radiohistorymodel.h" |
|
23 #include "radiohistorymodel_p.h" |
|
24 #include "radiouiengine.h" |
|
25 #include "radiohistoryitem.h" |
|
26 #include "radiostation.h" |
|
27 #include "radiouiengine.h" |
|
28 #include "radio_global.h" |
|
29 #include "radiologger.h" |
|
30 |
|
31 /*! |
|
32 * |
|
33 */ |
|
34 RadioHistoryModel::RadioHistoryModel( RadioUiEngine& uiEngine ) : |
|
35 QAbstractListModel( &uiEngine ), |
|
36 d_ptr( new RadioHistoryModelPrivate( this, uiEngine ) ) |
|
37 { |
|
38 connectAndTest( &uiEngine, SIGNAL(tunedToFrequency(uint,int)), |
|
39 this, SLOT(resetCurrentSong()) ); |
|
40 connectAndTest( &uiEngine, SIGNAL(seekingStarted(int)), |
|
41 this, SLOT(resetCurrentSong()) ); |
|
42 |
|
43 Q_D( RadioHistoryModel ); |
|
44 d->connectToDatabase(); |
|
45 } |
|
46 |
|
47 /*! |
|
48 * |
|
49 */ |
|
50 RadioHistoryModel::~RadioHistoryModel() |
|
51 { |
|
52 Q_D( RadioHistoryModel ); |
|
53 delete d_ptr; |
|
54 } |
|
55 |
|
56 /*! |
|
57 * \reimp |
|
58 */ |
|
59 int RadioHistoryModel::rowCount( const QModelIndex& parent ) const |
|
60 { |
|
61 Q_UNUSED( parent ); |
|
62 Q_D( const RadioHistoryModel ); |
|
63 return d->rowCount(); |
|
64 } |
|
65 |
|
66 /*! |
|
67 * \reimp |
|
68 */ |
|
69 QVariant RadioHistoryModel::data( const QModelIndex& index, int role ) const |
|
70 { |
|
71 if ( !index.isValid() ) { |
|
72 return QVariant(); |
|
73 } |
|
74 |
|
75 Q_D( const RadioHistoryModel ); |
|
76 return d->data( index.row(), role ); |
|
77 } |
|
78 |
|
79 /*! |
|
80 * Public slot |
|
81 */ |
|
82 void RadioHistoryModel::resetCurrentSong() |
|
83 { |
|
84 Q_D( RadioHistoryModel ); |
|
85 d->mTopItemIsPlaying = false; |
|
86 emit currentSongReset(); |
|
87 } |
|
88 |
|
89 /*! |
|
90 * Public slot |
|
91 */ |
|
92 void RadioHistoryModel::removeAll() |
|
93 { |
|
94 Q_D( RadioHistoryModel ); |
|
95 d->removeAll(); |
|
96 } |
|
97 |
|
98 /*! |
|
99 * Sets the icons to be used in the list |
|
100 */ |
|
101 void RadioHistoryModel::setIcons( const QIcon& nonTaggedIcon, const QIcon& taggedIcon ) |
|
102 { |
|
103 Q_D( RadioHistoryModel ); |
|
104 d->mNonTaggedIcon = nonTaggedIcon; |
|
105 d->mTaggedIcon = taggedIcon; |
|
106 } |
|
107 |
|
108 /*! |
|
109 * |
|
110 */ |
|
111 bool RadioHistoryModel::isCurrentSongRecognized() const |
|
112 { |
|
113 Q_D( const RadioHistoryModel ); |
|
114 return d->mTopItemIsPlaying; |
|
115 } |
|
116 |
|
117 /*! |
|
118 * |
|
119 */ |
|
120 void RadioHistoryModel::setShowDetails( bool showDetails ) |
|
121 { |
|
122 Q_D( RadioHistoryModel ); |
|
123 d->mShowDetails = showDetails; |
|
124 reset(); |
|
125 } |
|
126 |
|
127 /*! |
|
128 * |
|
129 */ |
|
130 void RadioHistoryModel::setShowTagged( bool showTagged ) |
|
131 { |
|
132 Q_D( RadioHistoryModel ); |
|
133 d->setViewMode( showTagged ? RadioHistoryModelPrivate::ShowTagged : RadioHistoryModelPrivate::ShowAll ); |
|
134 } |
|
135 |
|
136 /*! |
|
137 * |
|
138 */ |
|
139 void RadioHistoryModel::toggleTagging( const RadioHistoryItem& item, const int row ) |
|
140 { |
|
141 Q_D( RadioHistoryModel ); |
|
142 d->toggleTagging( item, row ); |
|
143 } |
|
144 |
|
145 /*! |
|
146 * |
|
147 */ |
|
148 RadioHistoryItem RadioHistoryModel::itemAtIndex( const QModelIndex& index ) const |
|
149 { |
|
150 Q_D( const RadioHistoryModel ); |
|
151 return d->itemAtIndex( index ); |
|
152 } |
|
153 |
|
154 /*! |
|
155 * |
|
156 */ |
|
157 void RadioHistoryModel::addItem( const QString& artist, const QString& title, const RadioStation& station ) |
|
158 { |
|
159 Q_D( RadioHistoryModel ); |
|
160 d->addItem( artist, title, station ); |
|
161 } |
|
162 |
|
163 /*! |
|
164 * |
|
165 */ |
|
166 void RadioHistoryModel::clearRadioTextPlus() |
|
167 { |
|
168 Q_D( RadioHistoryModel ); |
|
169 d->mRtItemHolder = ""; |
|
170 resetCurrentSong(); |
|
171 } |
|
172 |
|
173 /*! |
|
174 * |
|
175 */ |
|
176 void RadioHistoryModel::addRadioTextPlus( int rtClass, const QString& rtItem, const RadioStation& station ) |
|
177 { |
|
178 if ( rtClass == RtPlus::Dummy || rtClass == RtPlus::Artist || rtClass == RtPlus::Title ) { |
|
179 Q_D( RadioHistoryModel ); |
|
180 if ( d->mRtItemClass == -1 ) { |
|
181 d->mRtItemClass = rtClass; |
|
182 d->mRtItemHolder = rtItem; |
|
183 } else { |
|
184 // Received: Artist - Title |
|
185 if ( d->mRtItemClass == RtPlus::Artist && rtClass == RtPlus::Title ) { |
|
186 addItem( d->mRtItemHolder, rtItem, station ); |
|
187 |
|
188 // Received: Title - Artist |
|
189 } else if ( rtClass == RtPlus::Artist && d->mRtItemClass == RtPlus::Title ) { |
|
190 addItem( rtItem, d->mRtItemHolder, station ); |
|
191 |
|
192 // Received: Dummy - Title |
|
193 } else if ( d->mRtItemClass == RtPlus::Dummy && rtClass == RtPlus::Title ) { |
|
194 addItem( "", rtItem, station ); |
|
195 |
|
196 // Received: Title - Dummy |
|
197 } else if ( rtClass == RtPlus::Dummy && d->mRtItemClass == RtPlus::Title ) { |
|
198 addItem( "", d->mRtItemHolder, station ); |
|
199 } |
|
200 |
|
201 d->mRtItemHolder = ""; |
|
202 d->mRtItemClass = -1; |
|
203 } |
|
204 } |
|
205 } |
|
206 |
|
207 /*! |
|
208 * |
|
209 */ |
|
210 void RadioHistoryModel::reportChangedData( int start, int end ) |
|
211 { |
|
212 if ( end == -1 ) { |
|
213 end = start; |
|
214 } |
|
215 const QModelIndex startIndex = index( start, 0, QModelIndex() ); |
|
216 const QModelIndex endIndex = index( end, 0, QModelIndex() ); |
|
217 emit dataChanged( startIndex, endIndex ); |
|
218 } |
|
219 |
|
220 /*! |
|
221 * |
|
222 */ |
|
223 void RadioHistoryModel::emitItemAdded() |
|
224 { |
|
225 emit itemAdded(); |
|
226 } |
|