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 |
// User includes
|
|
19 |
#include "radiohistoryitem.h"
|
|
20 |
#include "radiohistoryitem_p.h"
|
|
21 |
|
|
22 |
/**
|
|
23 |
* Static shared data instance that is used by all default-constructed RadioStation instances
|
|
24 |
*/
|
|
25 |
Q_GLOBAL_STATIC( RadioHistoryItemPrivate, shared_null )
|
|
26 |
|
|
27 |
|
|
28 |
/*!
|
|
29 |
*
|
|
30 |
*/
|
|
31 |
RadioHistoryItem::RadioHistoryItem() :
|
|
32 |
QObject( 0 )
|
|
33 |
{
|
|
34 |
mData = shared_null();
|
|
35 |
mData->ref.ref();
|
|
36 |
}
|
|
37 |
|
|
38 |
/*!
|
|
39 |
*
|
|
40 |
*/
|
|
41 |
RadioHistoryItem::RadioHistoryItem( const QString& artist, const QString& title ) :
|
|
42 |
QObject( 0 )
|
|
43 |
{
|
|
44 |
mData = new RadioHistoryItemPrivate( artist, title );
|
|
45 |
}
|
|
46 |
|
|
47 |
/*!
|
|
48 |
*
|
|
49 |
*/
|
|
50 |
RadioHistoryItem::RadioHistoryItem( const RadioHistoryItem& other ) :
|
|
51 |
QObject( 0 )
|
|
52 |
{
|
|
53 |
mData = other.mData;
|
|
54 |
mData->ref.ref();
|
|
55 |
}
|
|
56 |
|
|
57 |
/*!
|
|
58 |
*
|
|
59 |
*/
|
|
60 |
RadioHistoryItem::~RadioHistoryItem()
|
|
61 |
{
|
|
62 |
decrementReferenceCount();
|
|
63 |
}
|
|
64 |
|
|
65 |
/*!
|
|
66 |
*
|
|
67 |
*/
|
|
68 |
RadioHistoryItem& RadioHistoryItem::operator=( const RadioHistoryItem& other )
|
|
69 |
{
|
|
70 |
qAtomicAssign( mData, other.mData );
|
|
71 |
return *this;
|
|
72 |
}
|
|
73 |
|
|
74 |
/*!
|
|
75 |
*
|
|
76 |
*/
|
|
77 |
bool RadioHistoryItem::isValid() const
|
|
78 |
{
|
|
79 |
return id() != 0 && !title().isEmpty();
|
|
80 |
}
|
|
81 |
|
|
82 |
/*!
|
|
83 |
*
|
|
84 |
*/
|
|
85 |
void RadioHistoryItem::reset()
|
|
86 |
{
|
|
87 |
decrementReferenceCount();
|
|
88 |
mData = shared_null();
|
|
89 |
mData->ref.ref();
|
|
90 |
}
|
|
91 |
|
|
92 |
/*!
|
|
93 |
*
|
|
94 |
*/
|
|
95 |
int RadioHistoryItem::id() const
|
|
96 |
{
|
|
97 |
return mData->mId;
|
|
98 |
}
|
|
99 |
|
|
100 |
/*!
|
|
101 |
*
|
|
102 |
*/
|
|
103 |
QString RadioHistoryItem::artist() const
|
|
104 |
{
|
|
105 |
return mData->mArtist;
|
|
106 |
}
|
|
107 |
|
|
108 |
/*!
|
|
109 |
*
|
|
110 |
*/
|
|
111 |
void RadioHistoryItem::setArtist( const QString& artist )
|
|
112 |
{
|
|
113 |
if ( artist.compare( mData->mArtist ) != 0 ) {
|
|
114 |
detach();
|
|
115 |
mData->mArtist = artist;
|
|
116 |
}
|
|
117 |
}
|
|
118 |
|
|
119 |
/*!
|
|
120 |
*
|
|
121 |
*/
|
|
122 |
QString RadioHistoryItem::title() const
|
|
123 |
{
|
|
124 |
return mData->mTitle;
|
|
125 |
}
|
|
126 |
|
|
127 |
/*!
|
|
128 |
*
|
|
129 |
*/
|
|
130 |
void RadioHistoryItem::setTitle( const QString& title )
|
|
131 |
{
|
|
132 |
if ( title.compare( mData->mTitle ) != 0 ) {
|
|
133 |
detach();
|
|
134 |
mData->mTitle = title;
|
|
135 |
}
|
|
136 |
}
|
|
137 |
|
|
138 |
/*!
|
|
139 |
*
|
|
140 |
*/
|
|
141 |
QString RadioHistoryItem::station() const
|
|
142 |
{
|
|
143 |
return mData->mStation;
|
|
144 |
}
|
|
145 |
|
|
146 |
/*!
|
|
147 |
*
|
|
148 |
*/
|
|
149 |
void RadioHistoryItem::setStation( const QString& station )
|
|
150 |
{
|
|
151 |
if ( station.compare( mData->mStation ) != 0 ) {
|
|
152 |
detach();
|
|
153 |
mData->mStation = station;
|
|
154 |
}
|
|
155 |
}
|
|
156 |
|
|
157 |
/*!
|
|
158 |
*
|
|
159 |
*/
|
|
160 |
uint RadioHistoryItem::frequency() const
|
|
161 |
{
|
|
162 |
return mData->mFrequency;
|
|
163 |
}
|
|
164 |
|
|
165 |
/*!
|
|
166 |
*
|
|
167 |
*/
|
|
168 |
void RadioHistoryItem::setFrequency( uint frequency )
|
|
169 |
{
|
|
170 |
if ( frequency != mData->mFrequency ) {
|
|
171 |
detach();
|
|
172 |
mData->mFrequency = frequency;
|
|
173 |
}
|
|
174 |
}
|
|
175 |
|
|
176 |
/*!
|
|
177 |
*
|
|
178 |
*/
|
|
179 |
QString RadioHistoryItem::time() const
|
|
180 |
{
|
|
181 |
return mData->mTime.toString();
|
|
182 |
}
|
|
183 |
|
|
184 |
/*!
|
|
185 |
*
|
|
186 |
*/
|
|
187 |
void RadioHistoryItem::setCurrentTime()
|
|
188 |
{
|
|
189 |
detach();
|
|
190 |
mData->mTime.currentDateTime();
|
|
191 |
}
|
|
192 |
|
|
193 |
|
|
194 |
/*!
|
|
195 |
*
|
|
196 |
*/
|
|
197 |
bool RadioHistoryItem::isTagged() const
|
|
198 |
{
|
|
199 |
return mData->mTagged;
|
|
200 |
}
|
|
201 |
|
|
202 |
/*!
|
|
203 |
*
|
|
204 |
*/
|
|
205 |
bool RadioHistoryItem::isRecognizedByRds() const
|
|
206 |
{
|
|
207 |
return mData->mFromRds;
|
|
208 |
}
|
|
209 |
|
|
210 |
/**
|
|
211 |
* Decrements the reference count of the implicitly shared data.
|
|
212 |
*/
|
|
213 |
void RadioHistoryItem::decrementReferenceCount()
|
|
214 |
{
|
|
215 |
if ( !mData->ref.deref() ) {
|
|
216 |
delete mData;
|
|
217 |
mData = 0;
|
|
218 |
}
|
|
219 |
}
|
|
220 |
|
|
221 |
/**
|
|
222 |
* Detach from the implicitly shared data
|
|
223 |
*/
|
|
224 |
void RadioHistoryItem::detach()
|
|
225 |
{
|
|
226 |
if ( !isDetached() ) {
|
|
227 |
RadioHistoryItemPrivate* newData = new RadioHistoryItemPrivate( *mData );
|
|
228 |
|
|
229 |
decrementReferenceCount();
|
|
230 |
|
|
231 |
newData->ref = 1;
|
|
232 |
mData = newData;
|
|
233 |
}
|
|
234 |
}
|
|
235 |
|
|
236 |
/**
|
|
237 |
* Checks if the class is detached from implicitly shared data
|
|
238 |
*/
|
|
239 |
bool RadioHistoryItem::isDetached() const
|
|
240 |
{
|
|
241 |
return mData->ref == 1;
|
|
242 |
}
|