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