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