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