|
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 RADIOSTATION_H_ |
|
19 #define RADIOSTATION_H_ |
|
20 |
|
21 // System includes |
|
22 #include <qstring> |
|
23 #include <qmetatype> |
|
24 #include <qobject> |
|
25 |
|
26 // User includes |
|
27 #include "radiouiengineexport.h" |
|
28 #include "radio_global.h" |
|
29 // Constants |
|
30 const int KLastCallSignCharCode = 25; |
|
31 const uint KThreeLetterCallSignCount = 72; |
|
32 const uint KKxxxCallSignPiFirst = 0x1000; |
|
33 const uint KWxxxCallSignPiFirst = 0x54A8; |
|
34 const uint KWxxxCallSignPiLast = 0x994F; |
|
35 const uint KxxxCallSignPiFirst = 0x9950; |
|
36 const uint KxxxCallSignPiLast = 0x99B9; |
|
37 |
|
38 // Forward declarations |
|
39 class RadioStationPrivate; |
|
40 |
|
41 // Class declaration |
|
42 |
|
43 /*! |
|
44 * RadioStation is a data container that holds all information of a radio station. |
|
45 * It is implicitly shared to make it cheap to copy and pass around as a signal parameter. |
|
46 * It uses the "shared null" idiom to initialize empty instances quickly and efficiently. |
|
47 * |
|
48 * Note! It is derived from QObject even though architecturally it shouldn't be. |
|
49 * It is done only to satisfy the WINSCW build which doesn't export the destructor in UREL |
|
50 * build. This causes mismatching def files and annoying warnings. Deriving from QObject fixes this |
|
51 */ |
|
52 class UI_ENGINE_DLL_EXPORT RadioStation : public QObject |
|
53 { |
|
54 friend class RadioStationModel; |
|
55 friend class RadioStationModelPrivate; |
|
56 friend class TestRadioUiEngine; |
|
57 friend class TestRadioPresetStorage; |
|
58 |
|
59 public: |
|
60 |
|
61 /** |
|
62 * Flags to indicate how the RadioStation has changed since last save or reset. |
|
63 * Declared to use QFlags<> to ease flag usage and to enforce type safety |
|
64 */ |
|
65 enum ChangeFlag |
|
66 { |
|
67 NoChange = 0 |
|
68 ,PersistentDataChanged = 1 << 0 |
|
69 ,NameChanged = 1 << 1 |
|
70 ,FavoriteChanged = 1 << 2 |
|
71 ,GenreChanged = 1 << 3 |
|
72 ,UrlChanged = 1 << 4 |
|
73 ,TypeChanged = 1 << 5 |
|
74 ,PiCodeChanged = 1 << 6 |
|
75 ,PsTypeChanged = 1 << 7 |
|
76 ,RadioTextChanged = 1 << 8 |
|
77 ,DynamicPsChanged = 1 << 9 |
|
78 }; |
|
79 Q_DECLARE_FLAGS( Change, ChangeFlag ) |
|
80 |
|
81 /** |
|
82 * Flags ot indicate station type. |
|
83 * Declared to use QFlags<> to ease flag usage and to enforce type safety |
|
84 */ |
|
85 enum TypeFlag |
|
86 { |
|
87 Favorite = 1 << 0, |
|
88 LocalStation = 1 << 1, |
|
89 PreDefined = 1 << 2, |
|
90 Temporary = 1 << 3 |
|
91 }; |
|
92 Q_DECLARE_FLAGS( Type, TypeFlag ) |
|
93 |
|
94 /** |
|
95 * Flag to indiate whether or not station uses dynamic PS and if the check has been performed |
|
96 * Declared to use QFlags<> to ease flag usage and to enforce type safety |
|
97 */ |
|
98 enum PsTypeFlag |
|
99 { |
|
100 Unknown, |
|
101 Dynamic, |
|
102 Static |
|
103 }; |
|
104 Q_DECLARE_FLAGS( PsType, PsTypeFlag ) |
|
105 |
|
106 /** |
|
107 * Magical values used as preset indexes to signify certain conditions. |
|
108 * NotFound means that a find function could not find a station |
|
109 * Invalid means that the station instance has not been initialized |
|
110 */ |
|
111 enum PresetFlag { NotFound = -1, Invalid = -100, SharedNull = -200 }; |
|
112 |
|
113 /** |
|
114 * Static convenience function to parse a frequency |
|
115 */ |
|
116 static QString parseFrequency( uint frequency ); |
|
117 |
|
118 RadioStation(); |
|
119 RadioStation( const RadioStation& other ); |
|
120 |
|
121 ~RadioStation(); |
|
122 |
|
123 RadioStation& operator=( const RadioStation& other ); |
|
124 |
|
125 private: |
|
126 |
|
127 explicit RadioStation( int presetIndex, uint frequency ); |
|
128 |
|
129 void reset(); |
|
130 void setChangeFlags( Change flags ); |
|
131 |
|
132 // Setters for persistent data |
|
133 void setPresetIndex( int presetIndex ); |
|
134 void setFrequency( uint frequency ); |
|
135 void setName( const QString& name ); |
|
136 void setGenre( const int genre ); |
|
137 void setUrl( const QString& url ); |
|
138 bool setPiCode( int piCode, RadioRegion::Region region ); |
|
139 |
|
140 // Setters for non-persistent data |
|
141 void setPsType( PsType psType ); |
|
142 void setRadioText( const QString& radioText ); |
|
143 void setRadioTextPlus( const int rtPlusClass, const QString& rtPlusItem ); |
|
144 void setDynamicPsText( const QString& dynamicPsText ); |
|
145 |
|
146 public: // Getters and setters |
|
147 |
|
148 // Setters & Getters for persistent data |
|
149 |
|
150 bool isValid() const; |
|
151 |
|
152 QString name() const; |
|
153 void setUserDefinedName( const QString& name ); |
|
154 bool isRenamed() const; |
|
155 |
|
156 int genre() const; |
|
157 |
|
158 QString frequencyMhz() const; |
|
159 uint frequency() const; |
|
160 int presetIndex() const; |
|
161 |
|
162 void setFavorite( bool favorite ); |
|
163 bool isFavorite() const; |
|
164 |
|
165 QString url() const; |
|
166 |
|
167 bool hasPiCode() const; |
|
168 bool hasRds() const; |
|
169 |
|
170 void setType( RadioStation::Type type ); |
|
171 void unsetType( RadioStation::Type type ); |
|
172 bool isType( RadioStation::Type type ) const; |
|
173 |
|
174 // Getters for non-persistent data |
|
175 |
|
176 PsType psType() const; |
|
177 QString radioText() const; |
|
178 QString dynamicPsText() const; |
|
179 Change changeFlags() const; |
|
180 bool hasDataChanged( Change flags ) const; |
|
181 bool hasChanged() const; |
|
182 void resetChangeFlags(); |
|
183 |
|
184 private: |
|
185 |
|
186 /** |
|
187 * Decrements the reference count of the implicitly shared data. |
|
188 * Data is deleted if no instance uses it anymore. |
|
189 */ |
|
190 void decrementReferenceCount(); |
|
191 |
|
192 // Methods for converting PI code into call sign |
|
193 QString piCodeToCallSign( uint programmeIdentification ); |
|
194 QString iterateCallSign( int piBase, int programmeIdentification ); |
|
195 QString callSignString( uint programmeIdentification ); |
|
196 char callSignChar( uint decimalValue ); |
|
197 |
|
198 private: // data |
|
199 |
|
200 /** |
|
201 * Pointer to the implicitly shared private implementation |
|
202 * Own. |
|
203 */ |
|
204 class RadioStationPrivate* mData; |
|
205 |
|
206 public: |
|
207 |
|
208 /** |
|
209 * Detach from the implicitly shared data |
|
210 */ |
|
211 void detach(); |
|
212 |
|
213 /** |
|
214 * Checks if the class is detached from implicitly shared data |
|
215 * Required by many QT convenience functions for implicitly shared classes |
|
216 */ |
|
217 bool isDetached() const; |
|
218 |
|
219 typedef RadioStationPrivate* DataPtr; |
|
220 inline DataPtr &data_ptr() { return mData; } |
|
221 |
|
222 }; |
|
223 |
|
224 Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStation::Change ) |
|
225 Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStation::Type ) |
|
226 |
|
227 Q_DECLARE_TYPEINFO( RadioStation, Q_MOVABLE_TYPE ); // Can be moved around in memory by containers if necessary |
|
228 Q_DECLARE_SHARED( RadioStation ) // Uses implicit sharing |
|
229 Q_DECLARE_METATYPE( RadioStation ) // To be usable in a QVariant |
|
230 |
|
231 #endif // RADIOSTATION_H_ |