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