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: Framework wraper - Private. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <mpxplaybackutility.h> |
|
19 #include <mpxmedia.h> |
|
20 #include <mpxmediageneraldefs.h> |
|
21 #include <mpxmediamusicdefs.h> |
|
22 #include <mpxcommandgeneraldefs.h> |
|
23 #include <mpxplaybackmessage.h> |
|
24 #include <mpxmessagegeneraldefs.h> |
|
25 #include <mpxplaybackmessagedefs.h> |
|
26 |
|
27 #include "mpmpxdetailsframeworkwrapper_p.h" |
|
28 #include "mpmpxdetailsframeworkwrapper.h" |
|
29 #include "mpcommondefs.h" |
|
30 #include "mptrace.h" |
|
31 #include "mpsongdata.h" |
|
32 |
|
33 /*! |
|
34 \class MpMpxDetailsFrameworkWrapperPrivate |
|
35 \brief Wrapper for mpx framework utilities - private implementation. |
|
36 |
|
37 This is a private implementation of the mpx framework wrapper utilties interface. |
|
38 */ |
|
39 |
|
40 /*! |
|
41 \internal |
|
42 */ |
|
43 MpMpxDetailsFrameworkWrapperPrivate::MpMpxDetailsFrameworkWrapperPrivate( MpMpxDetailsFrameworkWrapper *qq ) |
|
44 : q_ptr( qq ), |
|
45 iSongData(0), |
|
46 iPlaybackUtility(0) |
|
47 { |
|
48 TX_ENTRY |
|
49 // TODO: Who will call the destructor if it throws ? |
|
50 QT_TRAP_THROWING( constructProviderL() ); |
|
51 TX_EXIT |
|
52 } |
|
53 |
|
54 /*! |
|
55 \internal |
|
56 */ |
|
57 MpMpxDetailsFrameworkWrapperPrivate::~MpMpxDetailsFrameworkWrapperPrivate() |
|
58 { |
|
59 TX_ENTRY |
|
60 // TODO: Hkn: Trace the leave on debug, remove any TRAP_IGNORE s |
|
61 TRAP_IGNORE( destructProviderL() ); |
|
62 TX_EXIT |
|
63 } |
|
64 |
|
65 /*! |
|
66 \internal |
|
67 \ TODO: Hkn: rename |
|
68 */ |
|
69 void MpMpxDetailsFrameworkWrapperPrivate::constructProviderL() |
|
70 { |
|
71 TX_ENTRY |
|
72 iPlaybackUtility = MMPXPlaybackUtility::UtilityL( |
|
73 TUid::Uid( MpCommon::KMusicPlayerUid ) ); |
|
74 iPlaybackUtility->AddObserverL( *this ); |
|
75 |
|
76 iSongData = new MpSongData(); |
|
77 User::LeaveIfNull(iSongData); |
|
78 |
|
79 TX_EXIT |
|
80 } |
|
81 |
|
82 /*! |
|
83 \internal |
|
84 */ |
|
85 void MpMpxDetailsFrameworkWrapperPrivate::destructProviderL() |
|
86 { |
|
87 TX_ENTRY |
|
88 if ( iPlaybackUtility ) |
|
89 { |
|
90 iPlaybackUtility->RemoveObserverL( *this ); |
|
91 iPlaybackUtility->Close(); |
|
92 iPlaybackUtility = NULL; |
|
93 //do not delete pointer data |
|
94 } |
|
95 |
|
96 delete iSongData; |
|
97 iSongData=NULL; |
|
98 TX_EXIT |
|
99 } |
|
100 |
|
101 /*! |
|
102 \internal |
|
103 */ |
|
104 void MpMpxDetailsFrameworkWrapperPrivate::HandlePlaybackMessage( |
|
105 CMPXMessage *aMessage, |
|
106 TInt aError ) |
|
107 { |
|
108 Q_UNUSED( aMessage ); |
|
109 Q_UNUSED( aError ); |
|
110 } |
|
111 |
|
112 /*! |
|
113 \internal |
|
114 */ |
|
115 void MpMpxDetailsFrameworkWrapperPrivate::HandlePropertyL( TMPXPlaybackProperty /*aProperty*/, TInt /*aValue*/, TInt /*aError*/ ) |
|
116 { |
|
117 TX_LOG |
|
118 } |
|
119 |
|
120 /*! |
|
121 \internal |
|
122 */ |
|
123 void MpMpxDetailsFrameworkWrapperPrivate::HandleSubPlayerNamesL( TUid /*aPlayer*/, const MDesCArray */*aSubPlayers*/, TBool /*aComplete*/, TInt /*aError*/ ) |
|
124 { |
|
125 TX_LOG |
|
126 } |
|
127 |
|
128 /*! |
|
129 \internal |
|
130 */ |
|
131 void MpMpxDetailsFrameworkWrapperPrivate::HandleMediaL( |
|
132 const CMPXMedia& aProperties, |
|
133 TInt aError ) |
|
134 { |
|
135 TX_ENTRY |
|
136 |
|
137 if ( KErrNone != aError ){ |
|
138 // TODO: Hkn: Add a proper trace macro and trace |
|
139 TX_EXIT |
|
140 return; |
|
141 } |
|
142 |
|
143 bool changed = false; |
|
144 if ( aProperties.IsSupported( KMPXMediaGeneralTitle ) ) { |
|
145 changed |= iSongData->setTitle( |
|
146 QString::fromUtf16( |
|
147 aProperties.ValueText( KMPXMediaGeneralTitle ).Ptr(), |
|
148 aProperties.ValueText( KMPXMediaGeneralTitle ).Length() ) ); |
|
149 } else { |
|
150 changed |= iSongData->setTitle( QString() ); |
|
151 } |
|
152 |
|
153 if ( aProperties.IsSupported( KMPXMediaMusicArtist ) ) { |
|
154 changed |= iSongData->setArtist( |
|
155 QString::fromUtf16( |
|
156 aProperties.ValueText( KMPXMediaMusicArtist ).Ptr(), |
|
157 aProperties.ValueText( KMPXMediaMusicArtist ).Length() ) ); |
|
158 } else { |
|
159 changed |= iSongData->setArtist( QString() ); |
|
160 } |
|
161 |
|
162 if ( aProperties.IsSupported( KMPXMediaMusicAlbum ) ) { |
|
163 changed |= iSongData->setAlbum( |
|
164 QString::fromUtf16( |
|
165 aProperties.ValueText( KMPXMediaMusicAlbum ).Ptr(), |
|
166 aProperties.ValueText( KMPXMediaMusicAlbum ).Length() ) ); |
|
167 } else { |
|
168 changed |= iSongData->setAlbum( QString() ); |
|
169 } |
|
170 if ( changed ) { |
|
171 iSongData->commitPlaybackInfo( ); |
|
172 } |
|
173 |
|
174 // call back will be called when Album art is retrieved |
|
175 if ( aProperties.IsSupported( TMPXAttribute( KMPXMediaMusicAlbumArtFileName ) ) ) { |
|
176 iSongData->setAlbumArtUri( |
|
177 QString::fromUtf16( |
|
178 aProperties.ValueText(KMPXMediaMusicAlbumArtFileName).Ptr(), |
|
179 aProperties.ValueText(KMPXMediaMusicAlbumArtFileName).Length())); |
|
180 } else { |
|
181 iSongData->setAlbumArtUri( QString() ); |
|
182 } |
|
183 |
|
184 // all following will be for song details |
|
185 changed = false; |
|
186 if ( aProperties.IsSupported( KMPXMediaGeneralComment ) ) { |
|
187 TX_LOG_ARGS( "Comment is supported " ); |
|
188 changed |= iSongData->setComment( |
|
189 QString::fromUtf16( |
|
190 aProperties.ValueText( KMPXMediaGeneralComment ).Ptr(), |
|
191 aProperties.ValueText( KMPXMediaGeneralComment ).Length() ) ); |
|
192 } else { |
|
193 changed |= iSongData->setComment( QString() ); |
|
194 } |
|
195 |
|
196 if ( aProperties.IsSupported( TMPXAttribute( KMPXMediaMusicComposer ) ) ) { |
|
197 TX_LOG_ARGS( "Composer is supported " ); |
|
198 changed |= iSongData->setComposer( |
|
199 QString::fromUtf16( |
|
200 aProperties.ValueText( KMPXMediaMusicComposer ).Ptr(), |
|
201 aProperties.ValueText( KMPXMediaMusicComposer ).Length())); |
|
202 } else { |
|
203 changed |= iSongData->setComposer( QString() ); |
|
204 } |
|
205 |
|
206 if ( aProperties.IsSupported( TMPXAttribute( KMPXMediaMusicYear ) ) ) { |
|
207 TInt64 yearInMicroSeconds = aProperties.ValueTObjectL<TInt64>( KMPXMediaMusicYear ); |
|
208 TTime yearTime( yearInMicroSeconds ); |
|
209 changed |= iSongData->setYear( yearTime.DateTime().Year() ); |
|
210 } else { |
|
211 // to clear previous result |
|
212 changed |= iSongData->setYear( -1 ); |
|
213 } |
|
214 |
|
215 if ( aProperties.IsSupported( TMPXAttribute( KMPXMediaMusicAlbumTrack ) ) ) { |
|
216 changed |= iSongData->setAlbumTrack( |
|
217 QString::fromUtf16( |
|
218 aProperties.ValueText( KMPXMediaMusicAlbumTrack ).Ptr(), |
|
219 aProperties.ValueText( KMPXMediaMusicAlbumTrack ).Length())); |
|
220 } else { |
|
221 changed |= iSongData->setAlbumTrack( QString() ); |
|
222 } |
|
223 |
|
224 if ( aProperties.IsSupported( TMPXAttribute( KMPXMediaMusicGenre ) ) ) { |
|
225 changed |= iSongData->setGenre( |
|
226 QString::fromUtf16( |
|
227 aProperties.ValueText( KMPXMediaMusicGenre ).Ptr(), |
|
228 aProperties.ValueText( KMPXMediaMusicGenre ).Length())); |
|
229 } else { |
|
230 changed |= iSongData->setGenre( QString() ); |
|
231 } |
|
232 |
|
233 if ( changed ) { |
|
234 iSongData->commitSongDetailInfo( ); |
|
235 } |
|
236 TX_EXIT |
|
237 } |
|
238 |
|
239 /*! |
|
240 return song data |
|
241 */ |
|
242 MpSongData *MpMpxDetailsFrameworkWrapperPrivate::songData() |
|
243 { |
|
244 TX_LOG |
|
245 return iSongData; |
|
246 } |
|
247 |
|
248 /*! |
|
249 \internal |
|
250 */ |
|
251 void MpMpxDetailsFrameworkWrapperPrivate::retrieveSong() |
|
252 { |
|
253 TX_ENTRY |
|
254 TRAP_IGNORE( doRetrieveSongL() ); |
|
255 TX_EXIT |
|
256 } |
|
257 |
|
258 /*! |
|
259 \internal |
|
260 */ |
|
261 void MpMpxDetailsFrameworkWrapperPrivate::doRetrieveSongL() |
|
262 { |
|
263 TX_ENTRY |
|
264 MMPXSource *mediaSrc = iPlaybackUtility->Source(); |
|
265 User::LeaveIfNull( mediaSrc ); |
|
266 RArray<TMPXAttribute> requestedAttr; |
|
267 CleanupClosePushL( requestedAttr ); |
|
268 requestedAttr.AppendL( TMPXAttribute( KMPXMediaGeneralTitle ) ); |
|
269 requestedAttr.AppendL( TMPXAttribute( KMPXMediaMusicArtist ) ); |
|
270 requestedAttr.AppendL( TMPXAttribute( KMPXMediaMusicAlbum ) ); |
|
271 requestedAttr.AppendL( TMPXAttribute( KMPXMediaGeneralUri ) ); |
|
272 requestedAttr.AppendL( TMPXAttribute( KMPXMediaMusicAlbumArtFileName ) ); |
|
273 requestedAttr.AppendL( TMPXAttribute( KMPXMediaGeneralComment ) ); |
|
274 |
|
275 requestedAttr.AppendL( TMPXAttribute( KMPXMediaMusicAlbumTrack ) ); |
|
276 requestedAttr.AppendL( TMPXAttribute( KMPXMediaMusicComposer ) ); |
|
277 requestedAttr.AppendL( TMPXAttribute( KMPXMediaMusicYear ) ); |
|
278 requestedAttr.AppendL( TMPXAttribute( KMPXMediaMusicGenre ) ); |
|
279 |
|
280 mediaSrc->MediaL( requestedAttr.Array(), *this ); |
|
281 CleanupStack::PopAndDestroy( &requestedAttr ); |
|
282 TX_EXIT |
|
283 } |
|