author | Pat Downey <patd@symbian.org> |
Wed, 23 Jun 2010 17:20:24 +0100 | |
changeset 29 | 29ba091146f4 |
parent 28 | 075425b8d9a4 |
child 32 | 189d20c34778 |
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 |
#ifndef RADIOSTATIONMODEL_H_ |
|
19 |
#define RADIOSTATIONMODEL_H_ |
|
20 |
||
21 |
// System includes |
|
22 |
#include <QAbstractListModel> |
|
23 |
#include <QMap> |
|
24 |
||
25 |
// User includes |
|
26 |
#include "radio_global.h" |
|
27 |
#include "radiouiengineexport.h" |
|
28 |
#include "radiostation.h" |
|
29 |
||
30 |
// Forward declarations |
|
31 |
class RadioStationModelPrivate; |
|
32 |
class RadioPresetStorage; |
|
33 |
class RadioStationHandlerIf; |
|
34 |
class RadioEngineWrapper; |
|
35 |
class RadioStation; |
|
36 |
class RadioUiEnginePrivate; |
|
37 |
class QIcon; |
|
38 |
||
39 |
// Constants |
|
40 |
typedef QMap<uint,RadioStation> Stations; |
|
41 |
||
42 |
// Class declaration |
|
43 |
class UI_ENGINE_DLL_EXPORT RadioStationModel : public QAbstractListModel |
|
44 |
{ |
|
45 |
Q_OBJECT |
|
46 |
Q_DECLARE_PRIVATE_D( d_ptr, RadioStationModel ) |
|
47 |
Q_DISABLE_COPY( RadioStationModel ) |
|
48 |
||
49 |
public: |
|
50 |
||
51 |
enum DetailFlag |
|
52 |
{ |
|
53 |
Minimal = 1 << 0, |
|
54 |
ShowIcons = 1 << 1, |
|
55 |
ShowGenre = 1 << 2 |
|
56 |
}; |
|
57 |
Q_DECLARE_FLAGS( Detail, DetailFlag ) |
|
58 |
||
59 |
explicit RadioStationModel( RadioUiEnginePrivate& uiEngine ); |
|
60 |
||
61 |
~RadioStationModel(); |
|
62 |
||
63 |
// from base class QAbstractListModel |
|
64 |
||
65 |
Qt::ItemFlags flags ( const QModelIndex& index ) const; |
|
66 |
int rowCount( const QModelIndex& parent = QModelIndex() ) const; |
|
67 |
QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const; |
|
68 |
bool setData( const QModelIndex& index, const QVariant& value, int role = Qt::EditRole ); |
|
69 |
||
70 |
// New functions |
|
71 |
||
72 |
/*! |
|
73 |
* Called by the engine to initialize the list with given amount of presets |
|
74 |
*/ |
|
75 |
void initialize( RadioPresetStorage* storage, RadioEngineWrapper* wrapper ); |
|
76 |
||
77 |
/*! |
|
78 |
* Sets the icons to be used in the lists |
|
79 |
*/ |
|
80 |
void setIcons( const QIcon& favoriteIcon, const QIcon& nowPlayingIcon ); |
|
81 |
||
82 |
/*! |
|
83 |
* Returns a reference to the station handler interface |
|
84 |
*/ |
|
85 |
RadioStationHandlerIf& stationHandlerIf(); |
|
86 |
||
87 |
/*! |
|
88 |
* Returns a reference to the underlying QList so that it can be easily looped |
|
89 |
*/ |
|
90 |
const Stations& list() const; |
|
91 |
||
92 |
/*! |
|
93 |
* Returns the station at the given index. |
|
94 |
* The station is returned by value, but it is cheap because it is implicitly shared |
|
95 |
*/ |
|
96 |
RadioStation stationAt( int index ) const; |
|
97 |
||
98 |
/*! |
|
99 |
* Functions to find stations by frequency |
|
100 |
*/ |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
101 |
bool findFrequency( uint frequency, RadioStation& station ) const; |
24 | 102 |
|
103 |
/*! |
|
104 |
* Functions to find stations by preset index |
|
105 |
*/ |
|
106 |
int findPresetIndex( int presetIndex ); |
|
107 |
int findPresetIndex( int presetIndex, RadioStation& station ); |
|
108 |
||
109 |
/*! |
|
110 |
* Finds the closest station from the given frequency |
|
111 |
*/ |
|
112 |
RadioStation findClosest( const uint frequency, StationSkip::Mode mode ); |
|
113 |
||
114 |
/*! |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
115 |
* Checks if the model contains the given frequency |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
116 |
*/ |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
117 |
bool contains( const uint frequency ) const; |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
118 |
|
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
119 |
/*! |
24 | 120 |
* Functions to remove stations |
121 |
*/ |
|
122 |
void removeByFrequency( uint frequency ); |
|
123 |
void removeByPresetIndex( int presetIndex ); |
|
124 |
void removeStation( const RadioStation& station ); |
|
125 |
||
126 |
/** |
|
127 |
* Removes all stations |
|
128 |
*/ |
|
129 |
enum RemoveMode{ RemoveAll, RemoveLocalStations, RemoveFavorites }; |
|
130 |
void removeAll( RemoveMode mode = RemoveAll ); |
|
131 |
||
132 |
/*! |
|
133 |
* Functions to add and save stations |
|
134 |
*/ |
|
135 |
void addStation( const RadioStation& station ); |
|
136 |
void saveStation( RadioStation& station ); |
|
137 |
||
138 |
/*! |
|
139 |
* Function to check the number of favorite stations |
|
140 |
*/ |
|
141 |
int favoriteCount(); |
|
142 |
||
143 |
/*! |
|
144 |
* Convenience functions to change common settings |
|
145 |
*/ |
|
146 |
void setFavoriteByFrequency( uint frequency, bool favorite ); |
|
147 |
void setFavoriteByPreset( int presetIndex, bool favorite ); |
|
148 |
void renameStation( int presetIndex, const QString& name ); |
|
149 |
void setFavorites( const QModelIndexList& favorites ); |
|
150 |
||
151 |
/*! |
|
152 |
* Functions to init and access the currently tuned station |
|
153 |
*/ |
|
154 |
RadioStation& currentStation(); |
|
155 |
const RadioStation& currentStation() const; |
|
156 |
||
157 |
/*! |
|
158 |
* Sets the model detail level |
|
159 |
*/ |
|
160 |
void setDetail( Detail level ); |
|
161 |
||
162 |
/*! |
|
163 |
* Returns a list of radio stations in the given frequency range |
|
164 |
*/ |
|
165 |
QList<RadioStation> stationsInRange( uint minFrequency, uint maxFrequency ); |
|
166 |
||
167 |
/*! |
|
168 |
* Returns the model index corresponding to the given frequency |
|
169 |
*/ |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
170 |
int indexFromFrequency( uint frequency ); |
24 | 171 |
|
172 |
signals: |
|
173 |
||
174 |
void stationDataChanged( const RadioStation& station ); |
|
175 |
void radioTextReceived( const RadioStation& station ); |
|
176 |
void dynamicPsChanged( const RadioStation& station ); |
|
177 |
void favoriteChanged( const RadioStation& station ); |
|
178 |
||
179 |
private slots: |
|
180 |
||
181 |
/*! |
|
182 |
* Timer timeout slot to indicate that the dynamic PS check has ended |
|
183 |
*/ |
|
184 |
void dynamicPsCheckEnded(); |
|
185 |
||
186 |
private: |
|
187 |
||
188 |
// New functions |
|
189 |
||
190 |
/*! |
|
191 |
* Checks the given station and emits signals based on what member variables had been changed |
|
192 |
* since the last save or reset. |
|
193 |
*/ |
|
194 |
void emitChangeSignals( const RadioStation& station, RadioStation::Change flags ); |
|
195 |
||
196 |
void emitDataChanged( const RadioStation& station ); |
|
197 |
||
198 |
/*! |
|
199 |
* Finds an unused preset index |
|
200 |
*/ |
|
201 |
int findUnusedPresetIndex(); |
|
202 |
||
203 |
/** |
|
204 |
* Used by the RDS data setters to find the correct station where the data is set |
|
205 |
* First tries the currentStation variable and if the frequency doesn't match, finds the right one |
|
206 |
*/ |
|
207 |
RadioStation findCurrentStation( uint frequency ); |
|
208 |
||
209 |
private: // data |
|
210 |
||
211 |
/** |
|
212 |
* Unmodifiable pointer to the private implementation |
|
213 |
*/ |
|
214 |
RadioStationModelPrivate* const d_ptr; |
|
215 |
||
216 |
}; |
|
217 |
||
218 |
Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStationModel::Detail ) |
|
219 |
||
220 |
#endif // RADIOSTATIONMODEL_H_ |