author | hgs |
Fri, 15 Oct 2010 16:26:27 +0300 | |
changeset 57 | 21be958eb3ce |
parent 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 |
#ifndef RADIOSTATIONMODEL_H_ |
|
19 |
#define RADIOSTATIONMODEL_H_ |
|
20 |
||
21 |
// System includes |
|
22 |
#include <QAbstractListModel> |
|
34 | 23 |
#include <QScopedPointer> |
24 | 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 |
||
34 | 43 |
namespace FindCriteria |
44 |
{ |
|
45 |
enum Criteria |
|
46 |
{ |
|
47 |
OnlySavedStations, |
|
48 |
IncludeManualStation |
|
49 |
}; |
|
50 |
} |
|
51 |
||
24 | 52 |
// Class declaration |
53 |
class UI_ENGINE_DLL_EXPORT RadioStationModel : public QAbstractListModel |
|
54 |
{ |
|
55 |
Q_OBJECT |
|
34 | 56 |
Q_DECLARE_PRIVATE_D( d_ptr.data(), RadioStationModel ) |
24 | 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 |
*/ |
|
51 | 90 |
void setIcons( const QIcon& favoriteIcon, const QIcon& nonFavoriteIcon, const QIcon& nowPlayingIcon ); |
24 | 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 |
/*! |
|
34 | 109 |
* Finds a station by frequency |
24 | 110 |
*/ |
34 | 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; |
|
24 | 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 |
/*! |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
131 |
* 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
|
132 |
*/ |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
133 |
bool contains( const uint frequency ) const; |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
134 |
|
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
135 |
/*! |
24 | 136 |
* Functions to remove stations |
137 |
*/ |
|
138 |
void removeByFrequency( uint frequency ); |
|
139 |
void removeByPresetIndex( int presetIndex ); |
|
140 |
void removeStation( const RadioStation& station ); |
|
54 | 141 |
void removeByModelIndices( QModelIndexList& indices, bool removeFavorites = false ); |
24 | 142 |
|
143 |
/** |
|
144 |
* Removes all stations |
|
145 |
*/ |
|
146 |
enum RemoveMode{ RemoveAll, RemoveLocalStations, RemoveFavorites }; |
|
147 |
void removeAll( RemoveMode mode = RemoveAll ); |
|
148 |
||
149 |
/*! |
|
150 |
* Functions to add and save stations |
|
151 |
*/ |
|
152 |
void addStation( const RadioStation& station ); |
|
153 |
void saveStation( RadioStation& station ); |
|
154 |
||
155 |
/*! |
|
156 |
* Function to check the number of favorite stations |
|
157 |
*/ |
|
158 |
int favoriteCount(); |
|
159 |
||
160 |
/*! |
|
47 | 161 |
* Function to check the number of local stations |
162 |
*/ |
|
163 |
int localCount(); |
|
164 |
||
165 |
/*! |
|
24 | 166 |
* Convenience functions to change common settings |
167 |
*/ |
|
168 |
void setFavoriteByFrequency( uint frequency, bool favorite ); |
|
169 |
void setFavoriteByPreset( int presetIndex, bool favorite ); |
|
170 |
void renameStation( int presetIndex, const QString& name ); |
|
171 |
void setFavorites( const QModelIndexList& favorites ); |
|
172 |
||
173 |
/*! |
|
174 |
* Functions to init and access the currently tuned station |
|
175 |
*/ |
|
176 |
RadioStation& currentStation(); |
|
177 |
const RadioStation& currentStation() const; |
|
178 |
||
179 |
/*! |
|
180 |
* Sets the model detail level |
|
181 |
*/ |
|
182 |
void setDetail( Detail level ); |
|
183 |
||
184 |
/*! |
|
185 |
* Returns a list of radio stations in the given frequency range |
|
186 |
*/ |
|
187 |
QList<RadioStation> stationsInRange( uint minFrequency, uint maxFrequency ); |
|
188 |
||
189 |
/*! |
|
190 |
* Returns the model index corresponding to the given frequency |
|
191 |
*/ |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
192 |
int indexFromFrequency( uint frequency ); |
24 | 193 |
|
57 | 194 |
Q_SIGNALS: |
24 | 195 |
|
196 |
void stationDataChanged( const RadioStation& station ); |
|
197 |
void radioTextReceived( const RadioStation& station ); |
|
198 |
void dynamicPsChanged( const RadioStation& station ); |
|
199 |
void favoriteChanged( const RadioStation& station ); |
|
57 | 200 |
void stationsRemoved( const QList<uint>& frequencies ); |
24 | 201 |
|
57 | 202 |
private Q_SLOTS: |
24 | 203 |
|
204 |
/*! |
|
205 |
* Timer timeout slot to indicate that the dynamic PS check has ended |
|
206 |
*/ |
|
207 |
void dynamicPsCheckEnded(); |
|
208 |
||
57 | 209 |
/*! |
210 |
* Clears the radiotext from a station after its timeout has passed |
|
211 |
*/ |
|
212 |
void clearRadiotext( int id ); |
|
213 |
||
214 |
/*! |
|
215 |
* Handles the end of RT plus check |
|
216 |
*/ |
|
217 |
void rtPlusCheckEnd(); |
|
218 |
||
24 | 219 |
private: |
220 |
||
221 |
// New functions |
|
222 |
||
223 |
/*! |
|
224 |
* Checks the given station and emits signals based on what member variables had been changed |
|
225 |
* since the last save or reset. |
|
226 |
*/ |
|
227 |
void emitChangeSignals( const RadioStation& station, RadioStation::Change flags ); |
|
228 |
||
229 |
void emitDataChanged( const RadioStation& station ); |
|
230 |
||
231 |
/*! |
|
232 |
* Finds an unused preset index |
|
233 |
*/ |
|
234 |
int findUnusedPresetIndex(); |
|
235 |
||
236 |
private: // data |
|
237 |
||
238 |
/** |
|
239 |
* Unmodifiable pointer to the private implementation |
|
240 |
*/ |
|
34 | 241 |
const QScopedPointer<RadioStationModelPrivate> d_ptr; |
24 | 242 |
|
243 |
}; |
|
244 |
||
245 |
Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStationModel::Detail ) |
|
246 |
||
247 |
#endif // RADIOSTATIONMODEL_H_ |