|
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 QString RadioHistoryItem::artist() const |
|
78 { |
|
79 return mData->mArtist; |
|
80 } |
|
81 |
|
82 /*! |
|
83 * |
|
84 */ |
|
85 void RadioHistoryItem::setArtist( const QString& artist ) |
|
86 { |
|
87 if ( artist.compare( mData->mArtist ) != 0 ) { |
|
88 detach(); |
|
89 mData->mArtist = artist; |
|
90 } |
|
91 } |
|
92 |
|
93 /*! |
|
94 * |
|
95 */ |
|
96 QString RadioHistoryItem::title() const |
|
97 { |
|
98 return mData->mTitle; |
|
99 } |
|
100 |
|
101 /*! |
|
102 * |
|
103 */ |
|
104 void RadioHistoryItem::setTitle( const QString& title ) |
|
105 { |
|
106 if ( title.compare( mData->mTitle ) != 0 ) { |
|
107 detach(); |
|
108 mData->mTitle = title; |
|
109 } |
|
110 } |
|
111 |
|
112 /*! |
|
113 * |
|
114 */ |
|
115 QString RadioHistoryItem::station() const |
|
116 { |
|
117 return mData->mStation; |
|
118 } |
|
119 |
|
120 /*! |
|
121 * |
|
122 */ |
|
123 void RadioHistoryItem::setStation( const QString& station ) |
|
124 { |
|
125 if ( station.compare( mData->mStation ) != 0 ) { |
|
126 detach(); |
|
127 mData->mStation = station; |
|
128 } |
|
129 } |
|
130 |
|
131 /*! |
|
132 * |
|
133 */ |
|
134 uint RadioHistoryItem::frequency() const |
|
135 { |
|
136 return mData->mFrequency; |
|
137 } |
|
138 |
|
139 /*! |
|
140 * |
|
141 */ |
|
142 void RadioHistoryItem::setFrequency( uint frequency ) |
|
143 { |
|
144 if ( frequency != mData->mFrequency ) { |
|
145 detach(); |
|
146 mData->mFrequency = frequency; |
|
147 } |
|
148 } |
|
149 |
|
150 /*! |
|
151 * |
|
152 */ |
|
153 QString RadioHistoryItem::time() const |
|
154 { |
|
155 return mData->mTime.toString(); |
|
156 } |
|
157 |
|
158 /*! |
|
159 * |
|
160 */ |
|
161 void RadioHistoryItem::setCurrentTime() |
|
162 { |
|
163 detach(); |
|
164 mData->mTime.currentDateTime(); |
|
165 } |
|
166 |
|
167 |
|
168 /*! |
|
169 * |
|
170 */ |
|
171 bool RadioHistoryItem::isFavorite() const |
|
172 { |
|
173 return mData->mFavorite; |
|
174 } |
|
175 |
|
176 /*! |
|
177 * |
|
178 */ |
|
179 void RadioHistoryItem::setFavorite() |
|
180 { |
|
181 if ( !mData->mFavorite ) { |
|
182 detach(); |
|
183 mData->mFavorite = true; |
|
184 } |
|
185 } |
|
186 |
|
187 /*! |
|
188 * |
|
189 */ |
|
190 void RadioHistoryItem::increasePlayCount() |
|
191 { |
|
192 detach(); |
|
193 ++mData->mPlayCount; |
|
194 } |
|
195 |
|
196 /*! |
|
197 * |
|
198 */ |
|
199 int RadioHistoryItem::playCount() const |
|
200 { |
|
201 return mData->mPlayCount; |
|
202 } |
|
203 |
|
204 /** |
|
205 * Decrements the reference count of the implicitly shared data. |
|
206 */ |
|
207 void RadioHistoryItem::decrementReferenceCount() |
|
208 { |
|
209 if ( !mData->ref.deref() ) { |
|
210 delete mData; |
|
211 mData = 0; |
|
212 } |
|
213 } |
|
214 |
|
215 /** |
|
216 * Detach from the implicitly shared data |
|
217 */ |
|
218 void RadioHistoryItem::detach() |
|
219 { |
|
220 if ( !isDetached() ) { |
|
221 RadioHistoryItemPrivate* newData = new RadioHistoryItemPrivate( *mData ); |
|
222 |
|
223 decrementReferenceCount(); |
|
224 |
|
225 newData->ref = 1; |
|
226 mData = newData; |
|
227 } |
|
228 } |
|
229 |
|
230 /** |
|
231 * Checks if the class is detached from implicitly shared data |
|
232 */ |
|
233 bool RadioHistoryItem::isDetached() const |
|
234 { |
|
235 return mData->ref == 1; |
|
236 } |