Start/ | End/ | |||
True | False | - | Line | Source |
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 <QRegExp> | |||
19 | #include <QStringList> | |||
20 | #include <QFileInfo> | |||
21 | #include <QDateTime> | |||
22 | #include <QTime> | |||
23 | #include <QDate> | |||
24 | ||||
25 | #include <mpxplaybackutility.h> | |||
26 | #include <mpxmedia.h> | |||
27 | #include <mpxmediageneraldefs.h> | |||
28 | #include <mpxmediamusicdefs.h> | |||
29 | #include <mpxcommandgeneraldefs.h> | |||
30 | #include <mpxplaybackmessage.h> | |||
31 | #include <mpxmessagegeneraldefs.h> | |||
32 | #include <mpxplaybackmessagedefs.h> | |||
33 | #include <mpxmediaaudiodefs.h> | |||
34 | #include <mpxmediadrmdefs.h> | |||
35 | ||||
36 | #include "mpmpxdetailsframeworkwrapper_p.h" | |||
37 | #include "mpmpxdetailsframeworkwrapper.h" | |||
38 | #include "mpcommondefs.h" | |||
39 | #include "mptrace.h" | |||
40 | #include "mpsongdata.h" | |||
41 | ||||
42 | /*! | |||
43 | \class MpMpxDetailsFrameworkWrapperPrivate | |||
44 | \brief Wrapper for mpx framework utilities - private implementation. | |||
45 | ||||
46 | This is a private implementation of the mpx framework wrapper utilties interface. | |||
47 | */ | |||
48 | ||||
49 | /*! | |||
50 | \internal | |||
51 | */ | |||
Top | ||||
45 | 45 | 52 | MpMpxDetailsFrameworkWrapperPrivate::MpMpxDetailsFrameworkWrapperPrivate( MpMpxDetailsFrameworkWrapper *qq ) | |
53 | : q_ptr( qq ), | |||
54 | iSongData(0), | |||
55 | iPlaybackUtility(0) | |||
56 | { | |||
57 | TX_LOG | |||
58 | } | |||
59 | ||||
60 | /*! | |||
61 | \internal | |||
62 | */ | |||
Top | ||||
44 | 44 | 63 | MpMpxDetailsFrameworkWrapperPrivate::~MpMpxDetailsFrameworkWrapperPrivate() | |
64 | { | |||
65 | TX_ENTRY | |||
66 | ||||
44 | 0 | - | 67 | if ( iPlaybackUtility ) |
68 | { | |||
44 | 44 | 69 | TRAP_IGNORE(iPlaybackUtility->RemoveObserverL( *this )); | |
0 | - | 69 | catch (XLeaveException & l) | |
0 | - | 69 | catch (...) | |
70 | iPlaybackUtility->Close(); | |||
71 | iPlaybackUtility = NULL; | |||
72 | //do not delete pointer data | |||
73 | } | |||
74 | ||||
75 | delete iSongData; | |||
76 | iSongData=NULL; | |||
77 | ||||
78 | TX_EXIT | |||
79 | } | |||
80 | ||||
81 | /*! | |||
82 | \initialize wrapper | |||
83 | */ | |||
Top | ||||
45 | 45 | 84 | void MpMpxDetailsFrameworkWrapperPrivate::init( TUid hostUid ) | |
85 | { | |||
86 | mHostUid = hostUid; | |||
45 | 45 | 87 | TRAPD(err, DoInitL()); | |
0 | - | 87 | catch (XLeaveException & l) | |
0 | - | 87 | catch (...) | |
0 | 45 | - | 88 | if ( err != KErrNone ) { |
89 | TX_LOG_ARGS("Error: " << err << "; should never get here."); | |||
90 | } | |||
91 | } | |||
92 | ||||
93 | /*! | |||
94 | \internal | |||
95 | */ | |||
Top | ||||
45 | 45 | 96 | void MpMpxDetailsFrameworkWrapperPrivate::DoInitL() | |
97 | { | |||
98 | TX_ENTRY | |||
99 | ||||
100 | iPlaybackUtility = MMPXPlaybackUtility::UtilityL( mHostUid ); | |||
101 | iPlaybackUtility->AddObserverL( *this ); | |||
102 | iSongData = new MpSongData(); | |||
103 | User::LeaveIfNull(iSongData); | |||
104 | ||||
105 | TX_EXIT | |||
106 | } | |||
107 | ||||
108 | ||||
109 | /*! | |||
110 | \internal | |||
111 | */ | |||
Top | ||||
1 | 1 | 112 | void MpMpxDetailsFrameworkWrapperPrivate::HandlePlaybackMessage( | |
113 | CMPXMessage *aMessage, | |||
114 | TInt aError ) | |||
115 | { | |||
116 | Q_UNUSED( aMessage ); | |||
117 | Q_UNUSED( aError ); | |||
118 | } | |||
119 | ||||
120 | /*! | |||
121 | \internal | |||
122 | */ | |||
Top | ||||
1 | 1 | 123 | void MpMpxDetailsFrameworkWrapperPrivate::HandlePropertyL( TMPXPlaybackProperty /*aProperty*/, TInt /*aValue*/, TInt /*aError*/ ) | |
124 | { | |||
125 | TX_LOG | |||
126 | } | |||
127 | ||||
128 | /*! | |||
129 | \internal | |||
130 | */ | |||
Top | ||||
1 | 1 | 131 | void MpMpxDetailsFrameworkWrapperPrivate::HandleSubPlayerNamesL( TUid /*aPlayer*/, const MDesCArray */*aSubPlayers*/, TBool /*aComplete*/, TInt /*aError*/ ) | |
132 | { | |||
133 | TX_LOG | |||
134 | } | |||
135 | ||||
136 | /*! | |||
137 | \internal | |||
138 | */ | |||
Top | ||||
38 | 37 | 139 | void MpMpxDetailsFrameworkWrapperPrivate::HandleMediaL( | |
140 | const CMPXMedia& aProperties, | |||
141 | TInt aError ) | |||
142 | { | |||
143 | TX_ENTRY | |||
144 | ||||
1 | 37 | 145 | if ( KErrNone != aError ){ | |
146 | // TODO: Hkn: Add a proper trace macro and trace | |||
147 | TX_EXIT | |||
1 | 148 | return; | ||
149 | } | |||
150 | ||||
151 | bool changed = false; | |||
35 | 2 | 152 | if ( aProperties.IsSupported( KMPXMediaGeneralTitle ) ) { | |
153 | changed |= iSongData->setTitle( | |||
154 | QString::fromUtf16( | |||
155 | aProperties.ValueText( KMPXMediaGeneralTitle ).Ptr(), | |||
156 | aProperties.ValueText( KMPXMediaGeneralTitle ).Length() ) ); | |||
157 | } else { | |||
158 | changed |= iSongData->setTitle( QString() ); | |||
159 | } | |||
160 | ||||
35 | 2 | 161 | if ( aProperties.IsSupported( KMPXMediaMusicArtist ) ) { | |
162 | changed |= iSongData->setArtist( | |||
163 | QString::fromUtf16( | |||
164 | aProperties.ValueText( KMPXMediaMusicArtist ).Ptr(), | |||
165 | aProperties.ValueText( KMPXMediaMusicArtist ).Length() ) ); | |||
166 | } else { | |||
167 | changed |= iSongData->setArtist( QString() ); | |||
168 | } | |||
169 | ||||
35 | 2 | 170 | if ( aProperties.IsSupported( KMPXMediaMusicAlbum ) ) { | |
171 | changed |= iSongData->setAlbum( | |||
172 | QString::fromUtf16( | |||
173 | aProperties.ValueText( KMPXMediaMusicAlbum ).Ptr(), | |||
174 | aProperties.ValueText( KMPXMediaMusicAlbum ).Length() ) ); | |||
175 | } else { | |||
176 | changed |= iSongData->setAlbum( QString() ); | |||
177 | } | |||
35 | 2 | 178 | if ( changed ) { | |
179 | iSongData->commitPlaybackInfo( ); | |||
180 | } | |||
181 | ||||
182 | // call back will be called when Album art is retrieved | |||
36 | 1 | 183 | if ( aProperties.IsSupported( TMPXAttribute( KMPXMediaMusicAlbumArtFileName ) ) ) { | |
184 | iSongData->setAlbumArtUri( | |||
185 | QString::fromUtf16( | |||
186 | aProperties.ValueText(KMPXMediaMusicAlbumArtFileName).Ptr(), | |||
187 | aProperties.ValueText(KMPXMediaMusicAlbumArtFileName).Length() ) ); | |||
188 | } else { | |||
189 | iSongData->setAlbumArtUri( QString() ); | |||
190 | } | |||
191 | ||||
192 | // all following will be for song details | |||
193 | changed = false; | |||
36 | 1 | 194 | if ( aProperties.IsSupported( TMPXAttribute( KMPXMediaGeneralUri ) ) ) { | |
195 | QString fullName = QString::fromUtf16( | |||
196 | aProperties.ValueText( KMPXMediaGeneralUri ).Ptr(), | |||
197 | aProperties.ValueText( KMPXMediaGeneralUri ).Length() ); | |||
198 | ||||
199 | TX_LOG_ARGS( "File name with path: " << fullName ); | |||
200 | // get size & last modifed information from file system | |||
201 | QFileInfo info( fullName ); | |||
202 | changed |= iSongData->setSize( info.size() ); | |||
203 | ||||
204 | QDateTime lastModified = info.lastModified(); | |||
205 | QDate date = lastModified.date(); | |||
206 | int day = date.day(); | |||
207 | int month = date.month(); | |||
208 | int year = date.year(); | |||
209 | QTime time = lastModified.time(); | |||
210 | int sec = time.second(); | |||
211 | int min = time.minute(); | |||
212 | int hr = time.hour(); | |||
213 | ||||
214 | ||||
215 | QString lastModifiedStr("%1.%2.%3 %4:%5:%6"); | |||
216 | lastModifiedStr = lastModifiedStr.arg( day ).arg( month ).arg( year ).arg( hr ).arg( min ).arg( sec ); | |||
217 | changed |= iSongData->setModified( lastModifiedStr ); | |||
218 | ||||
219 | ||||
220 | // get file name without suffix | |||
221 | QString file; | |||
222 | QRegExp rx("(.+)\\..+"); | |||
223 | QString str = info.fileName(); | |||
224 | TX_LOG_ARGS( "File name with suffix = " << str ); | |||
225 | ||||
226 | int pos = rx.indexIn( str ); | |||
0 | 36 | - | 227 | if( pos > -1 ) { |
228 | file = rx.cap( 1 ); | |||
229 | TX_LOG_ARGS( "File = " << file ); | |||
230 | } | |||
231 | ||||
232 | changed |= iSongData->setFileName( file ); | |||
233 | } else { | |||
234 | changed |= iSongData->setFileName( QString() ); | |||
235 | } | |||
236 | ||||
35 | 2 | 237 | if ( aProperties.IsSupported( TMPXAttribute( KMPXMediaMusicComposer ) ) ) { | |
238 | TX_LOG_ARGS( "Composer is supported " ); | |||
239 | changed |= iSongData->setComposer( | |||
240 | QString::fromUtf16( | |||
241 | aProperties.ValueText( KMPXMediaMusicComposer ).Ptr(), | |||
242 | aProperties.ValueText( KMPXMediaMusicComposer ).Length() ) ); | |||
243 | } else { | |||
244 | changed |= iSongData->setComposer( QString() ); | |||
245 | } | |||
246 | ||||
35 | 2 | 247 | if ( aProperties.IsSupported( TMPXAttribute( KMPXMediaMusicYear ) ) ) { | |
248 | TInt64 yearInMicroSeconds = aProperties.ValueTObjectL<TInt64>( KMPXMediaMusicYear ); | |||
249 | TX_LOG_ARGS( "year = " << yearInMicroSeconds ); | |||
250 | TTime yearTime( yearInMicroSeconds ); | |||
251 | changed |= iSongData->setYear( yearTime.DateTime().Year() ); | |||
252 | } else { | |||
253 | // to clear previous result | |||
254 | changed |= iSongData->setYear( -1 ); | |||
255 | } | |||
256 | ||||
35 | 2 | 257 | if ( aProperties.IsSupported( TMPXAttribute( KMPXMediaMusicAlbumTrack ) ) ) { | |
258 | changed |= iSongData->setAlbumTrack( | |||
259 | QString::fromUtf16( | |||
260 | aProperties.ValueText( KMPXMediaMusicAlbumTrack ).Ptr(), | |||
261 | aProperties.ValueText( KMPXMediaMusicAlbumTrack ).Length() ) ); | |||
262 | } else { | |||
263 | changed |= iSongData->setAlbumTrack( QString() ); | |||
264 | } | |||
265 | ||||
35 | 2 | 266 | if ( aProperties.IsSupported( TMPXAttribute( KMPXMediaMusicGenre ) ) ) { | |
267 | changed |= iSongData->setGenre( | |||
268 | QString::fromUtf16( | |||
269 | aProperties.ValueText( KMPXMediaMusicGenre ).Ptr(), | |||
270 | aProperties.ValueText( KMPXMediaMusicGenre ).Length() ) ); | |||
271 | } else { | |||
272 | changed |= iSongData->setGenre( QString() ); | |||
273 | } | |||
274 | ||||
8 | 29 | 275 | if ( aProperties.IsSupported( TMPXAttribute( KMPXMediaGeneralMimeType ) ) ) { | |
276 | QString type = QString::fromUtf16( | |||
277 | aProperties.ValueText( KMPXMediaGeneralMimeType ).Ptr(), | |||
278 | aProperties.ValueText( KMPXMediaGeneralMimeType ).Length() ); | |||
279 | QString regularExpression(".+/(.+)"); | |||
280 | QRegExp rx(regularExpression); | |||
281 | QString mimeType; | |||
282 | ||||
283 | int pos = rx.indexIn( type ); | |||
0 | 8 | - | 284 | if( pos > -1 ) { |
285 | mimeType = rx.cap( 1 ); | |||
286 | mimeType = mimeType.toUpper(); | |||
287 | TX_LOG_ARGS( "MIME type =" << mimeType ); | |||
288 | } | |||
289 | ||||
290 | changed |= iSongData->setMimeType( mimeType ); | |||
291 | } else { | |||
292 | changed |= iSongData->setMimeType( QString() ); | |||
293 | } | |||
294 | ||||
2 | 35 | 295 | if ( aProperties.IsSupported( TMPXAttribute( KMPXMediaGeneralDuration ) ) ) { | |
296 | TInt duration( aProperties.ValueTObjectL<TInt>( KMPXMediaGeneralDuration ) ); | |||
297 | changed |= iSongData->setDuration( duration / 1000 ); | |||
298 | } else { | |||
299 | changed |= iSongData->setDuration( -1 ); | |||
300 | } | |||
301 | ||||
1 | 36 | 302 | if ( aProperties.IsSupported( TMPXAttribute( KMPXMediaAudioBitrate ) ) ) { | |
303 | TInt bitRate( aProperties.ValueTObjectL<TInt>( KMPXMediaAudioBitrate ) ); | |||
304 | changed |= iSongData->setBitRate( bitRate ); | |||
305 | } else { | |||
306 | changed |= iSongData->setBitRate( -1 ); | |||
307 | } | |||
308 | ||||
3 | 34 | 309 | if ( aProperties.IsSupported( TMPXAttribute( KMPXMediaAudioSamplerate ) ) ) { | |
310 | TInt sampleRate( aProperties.ValueTObjectL<TInt>( KMPXMediaAudioSamplerate ) ); | |||
311 | changed |= iSongData->setSampleRate( sampleRate ); | |||
312 | } else { | |||
313 | changed |= iSongData->setSampleRate( -1 ); | |||
314 | } | |||
315 | ||||
316 | ||||
1 | 36 | 317 | if ( aProperties.IsSupported( TMPXAttribute( KMPXMediaGeneralCopyright ) ) ) { | |
318 | changed |= iSongData->setCopyright( | |||
319 | QString::fromUtf16( | |||
320 | aProperties.ValueText( KMPXMediaGeneralCopyright ).Ptr(), | |||
321 | aProperties.ValueText( KMPXMediaGeneralCopyright ).Length() ) ); | |||
322 | } else { | |||
323 | changed |= iSongData->setCopyright( QString() ); | |||
324 | } | |||
325 | ||||
1 | 36 | 326 | if ( aProperties.IsSupported( TMPXAttribute( KMPXMediaMusicURL ) ) ) { | |
327 | changed |= iSongData->setMusicURL( | |||
328 | QString::fromUtf16( | |||
329 | aProperties.ValueText( KMPXMediaMusicURL ).Ptr(), | |||
330 | aProperties.ValueText( KMPXMediaMusicURL ).Length() ) ); | |||
331 | } else { | |||
332 | changed |= iSongData->setMusicURL( QString() ); | |||
333 | } | |||
334 | ||||
0 | 37 | - | 335 | if ( aProperties.IsSupported( TMPXAttribute( KMPXMediaDrmProtected ) ) ) { |
336 | TX_LOG_ARGS( "DRM is supported." ); | |||
337 | changed |= iSongData->setDrmProtected( aProperties.ValueTObjectL<TBool>( KMPXMediaDrmProtected ) ); | |||
338 | } else { | |||
339 | changed |= iSongData->setDrmProtected( false ); | |||
340 | } | |||
341 | ||||
37 | 0 | - | 342 | if ( changed ) { |
343 | iSongData->commitSongDetailInfo( ); | |||
344 | } | |||
345 | TX_EXIT | |||
346 | } | |||
347 | ||||
348 | /*! | |||
349 | return song data | |||
350 | */ | |||
Top | ||||
461 | 0 | 351 | MpSongData *MpMpxDetailsFrameworkWrapperPrivate::songData() | |
352 | { | |||
353 | TX_LOG | |||
461 | 354 | return iSongData; | ||
355 | } | |||
356 | ||||
357 | /*! | |||
358 | \internal | |||
359 | */ | |||
Top | ||||
1 | 1 | 360 | void MpMpxDetailsFrameworkWrapperPrivate::retrieveSong() | |
361 | { | |||
362 | TX_ENTRY | |||
1 | 1 | 363 | TRAP_IGNORE( doRetrieveSongL() ); | |
0 | - | 363 | catch (XLeaveException & l) | |
0 | - | 363 | catch (...) | |
364 | TX_EXIT | |||
365 | } | |||
366 | ||||
367 | /*! | |||
368 | \internal | |||
369 | */ | |||
Top | ||||
1 | 1 | 370 | void MpMpxDetailsFrameworkWrapperPrivate::doRetrieveSongL() | |
371 | { | |||
372 | TX_ENTRY | |||
373 | MMPXSource *mediaSrc = iPlaybackUtility->Source(); | |||
374 | User::LeaveIfNull( mediaSrc ); | |||
375 | RArray<TMPXAttribute> requestedAttr; | |||
376 | CleanupClosePushL( requestedAttr ); | |||
377 | requestedAttr.AppendL( TMPXAttribute( KMPXMediaGeneralTitle ) ); | |||
378 | requestedAttr.AppendL( TMPXAttribute( KMPXMediaMusicArtist ) ); | |||
379 | requestedAttr.AppendL( TMPXAttribute( KMPXMediaMusicAlbum ) ); | |||
380 | requestedAttr.AppendL( TMPXAttribute( KMPXMediaGeneralUri ) ); | |||
381 | requestedAttr.AppendL( TMPXAttribute( KMPXMediaMusicAlbumArtFileName ) ); | |||
382 | ||||
383 | requestedAttr.AppendL( TMPXAttribute( KMPXMediaMusicAlbumTrack ) ); | |||
384 | requestedAttr.AppendL( TMPXAttribute( KMPXMediaMusicComposer ) ); | |||
385 | requestedAttr.AppendL( TMPXAttribute( KMPXMediaMusicYear ) ); | |||
386 | requestedAttr.AppendL( TMPXAttribute( KMPXMediaMusicGenre ) ); | |||
387 | ||||
388 | requestedAttr.AppendL( TMPXAttribute( KMPXMediaGeneralMimeType ) ); | |||
389 | requestedAttr.AppendL( TMPXAttribute( KMPXMediaGeneralDuration ) ); | |||
390 | requestedAttr.AppendL( TMPXAttribute( KMPXMediaAudioBitrate ) ); | |||
391 | requestedAttr.AppendL( TMPXAttribute( KMPXMediaAudioSamplerate ) ); | |||
392 | requestedAttr.AppendL( TMPXAttribute( KMPXMediaGeneralCopyright ) ); | |||
393 | requestedAttr.AppendL( TMPXAttribute( KMPXMediaMusicURL ) ); | |||
394 | requestedAttr.AppendL( TMPXAttribute( KMPXMediaDrmProtected ) ); | |||
395 | ||||
396 | mediaSrc->MediaL( requestedAttr.Array(), *this ); | |||
397 | CleanupStack::PopAndDestroy( &requestedAttr ); | |||
398 | TX_EXIT | |||
399 | } | |||
***TER 82% (56/68) of SOURCE FILE mpmpxdetailsframeworkwrapper_p.cpp |