|
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: Metadata of song for details view - private implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <QString> |
|
20 #include <QPixmap> |
|
21 #include <QPainter> |
|
22 #include <QBuffer> |
|
23 #include <QPixmap> |
|
24 #include <QTime> |
|
25 #include <QIcon> |
|
26 #include <QFile> |
|
27 #include <QRegExp> |
|
28 #include <QFileInfo> |
|
29 #include <QDateTime> |
|
30 #include <QDate> |
|
31 #include <HbExtendedLocale> |
|
32 #include <hbi18ndef.h> |
|
33 #include <HbStringUtil> |
|
34 |
|
35 #include <hbicon.h> |
|
36 |
|
37 #include <mpxmedia.h> |
|
38 #include <mpxmediacontainerdefs.h> |
|
39 #include <mpxmediaarray.h> |
|
40 #include <mpxmediageneraldefs.h> |
|
41 #include <mpxmediamusicdefs.h> |
|
42 #include <mpxmediaaudiodefs.h> |
|
43 #include <mpxmediadrmdefs.h> |
|
44 #include <thumbnailmanager_qt.h> |
|
45 |
|
46 #include "mpsongdata_p.h" |
|
47 #include "mptrace.h" |
|
48 |
|
49 const int KUndefined = -1; |
|
50 |
|
51 /*! |
|
52 \class MpSongDataPrivate |
|
53 \brief Music Player song metadata - private implementation. |
|
54 |
|
55 Song data provide access to song metadata. |
|
56 */ |
|
57 |
|
58 /*! |
|
59 Constructs a new MpSongDataPrivate. |
|
60 */ |
|
61 MpSongDataPrivate::MpSongDataPrivate( MpSongData *wrapper, ThumbnailManager *thumbnailManager ) |
|
62 : q_ptr( wrapper ), |
|
63 mThumbnailManager(thumbnailManager), |
|
64 mReqId( KUndefined ), |
|
65 mAlbumArt() |
|
66 { |
|
67 TX_ENTRY |
|
68 mDefaultAlbumArt = new HbIcon( "qtg_large_album_art" ); |
|
69 TX_EXIT |
|
70 } |
|
71 |
|
72 /*! |
|
73 Constructs a new MpSongDataPrivate. |
|
74 */ |
|
75 MpSongDataPrivate::~MpSongDataPrivate() |
|
76 { |
|
77 TX_ENTRY |
|
78 removeAlbumArtFile(); // TODO Remove when base64 is working |
|
79 TX_EXIT |
|
80 } |
|
81 |
|
82 /*! |
|
83 Returns the song title. |
|
84 */ |
|
85 QString MpSongDataPrivate::title() const |
|
86 { |
|
87 TX_LOG |
|
88 return mTitle; |
|
89 } |
|
90 |
|
91 /*! |
|
92 Returns the song album. |
|
93 */ |
|
94 QString MpSongDataPrivate::album() const |
|
95 { |
|
96 TX_LOG |
|
97 return mAlbum; |
|
98 } |
|
99 |
|
100 /*! |
|
101 Returns the song artist. |
|
102 */ |
|
103 QString MpSongDataPrivate::artist() const |
|
104 { |
|
105 TX_LOG |
|
106 return mArtist; |
|
107 } |
|
108 |
|
109 /*! |
|
110 Returns the comment. |
|
111 */ |
|
112 QString MpSongDataPrivate::comment() const |
|
113 { |
|
114 TX_LOG |
|
115 return mComment; |
|
116 } |
|
117 |
|
118 /*! |
|
119 Returns the song album art on \a icon. |
|
120 */ |
|
121 void MpSongDataPrivate::albumArt( HbIcon& icon ) const |
|
122 { |
|
123 TX_ENTRY |
|
124 if ( !mAlbumArt || mAlbumArt->isNull() ) { |
|
125 TX_LOG_ARGS( "Album art is NULL." ); |
|
126 icon = HbIcon(); |
|
127 } else { |
|
128 TX_LOG_ARGS( "Album art is not NULL." ); |
|
129 icon = *mAlbumArt ; |
|
130 } |
|
131 TX_EXIT |
|
132 } |
|
133 |
|
134 /*! |
|
135 Returns the release date. |
|
136 */ |
|
137 QString MpSongDataPrivate::year() const |
|
138 { |
|
139 TX_LOG |
|
140 return mYear; |
|
141 } |
|
142 |
|
143 /*! |
|
144 Returns the song genre. |
|
145 */ |
|
146 QString MpSongDataPrivate::genre() const |
|
147 { |
|
148 TX_LOG |
|
149 return mGenre; |
|
150 } |
|
151 |
|
152 /*! |
|
153 Returns the song composer. |
|
154 */ |
|
155 QString MpSongDataPrivate::composer() const |
|
156 { |
|
157 TX_LOG |
|
158 return mComposer; |
|
159 } |
|
160 |
|
161 /*! |
|
162 Returns the album track. |
|
163 */ |
|
164 QString MpSongDataPrivate::albumTrack() const |
|
165 { |
|
166 TX_LOG |
|
167 return mAlbumTrack; |
|
168 } |
|
169 |
|
170 /*! |
|
171 Returns link |
|
172 */ |
|
173 QString MpSongDataPrivate::link() const |
|
174 { |
|
175 TX_LOG |
|
176 return mLink; |
|
177 } |
|
178 |
|
179 /*! |
|
180 Returns the file name |
|
181 */ |
|
182 QString MpSongDataPrivate::fileName() const |
|
183 { |
|
184 TX_LOG |
|
185 return mFileName; |
|
186 } |
|
187 |
|
188 /*! |
|
189 Returns the MIME type |
|
190 */ |
|
191 QString MpSongDataPrivate::mimeType() const |
|
192 { |
|
193 TX_LOG |
|
194 return mMimeType; |
|
195 } |
|
196 |
|
197 /*! |
|
198 Returns the duration |
|
199 */ |
|
200 QString MpSongDataPrivate::duration() const |
|
201 { |
|
202 TX_LOG |
|
203 return mDuration; |
|
204 } |
|
205 |
|
206 /*! |
|
207 Returns the bit rate |
|
208 */ |
|
209 QString MpSongDataPrivate::bitRate() const |
|
210 { |
|
211 TX_LOG |
|
212 return mBitRate; |
|
213 } |
|
214 |
|
215 /*! |
|
216 Returns the sampling rate |
|
217 */ |
|
218 QString MpSongDataPrivate::sampleRate() const |
|
219 { |
|
220 TX_LOG |
|
221 return mSampleRate; |
|
222 } |
|
223 |
|
224 /*! |
|
225 Returns the size |
|
226 */ |
|
227 QString MpSongDataPrivate::size() const |
|
228 { |
|
229 TX_LOG |
|
230 return mSize; |
|
231 } |
|
232 |
|
233 /*! |
|
234 Returns the modified time |
|
235 */ |
|
236 QString MpSongDataPrivate::modified() const |
|
237 { |
|
238 TX_LOG |
|
239 return mModified; |
|
240 } |
|
241 |
|
242 /*! |
|
243 Returns the copyright |
|
244 */ |
|
245 QString MpSongDataPrivate::copyright() const |
|
246 { |
|
247 TX_LOG |
|
248 return mCopyright; |
|
249 } |
|
250 |
|
251 /*! |
|
252 Returns the music URL |
|
253 */ |
|
254 QString MpSongDataPrivate::musicURL() const |
|
255 { |
|
256 TX_LOG |
|
257 return mMusicURL; |
|
258 } |
|
259 |
|
260 /*! |
|
261 Returns whether the song is protected |
|
262 */ |
|
263 bool MpSongDataPrivate::isDrmProtected() const |
|
264 { |
|
265 TX_LOG |
|
266 return mDrmProtected; |
|
267 } |
|
268 |
|
269 /*! |
|
270 Retrieve the album art in base64 encoding suitable for inline HTML display for sharing player. |
|
271 */ |
|
272 QString MpSongDataPrivate::albumArtBase64() const |
|
273 { |
|
274 /* |
|
275 // Converts the current album art icon to a base64 string, and return the string. |
|
276 TX_LOG |
|
277 if ( mAlbumArt->isNull() ) { |
|
278 TX_ENTRY_ARGS( "MpSongDataPrivate: album art isNull" ) |
|
279 return "nullimgcraptoberemoved"; |
|
280 } |
|
281 TX_ENTRY_ARGS("MpSongDataPrivate: album art exists"); |
|
282 QByteArray array; |
|
283 QBuffer buffer( &array ); |
|
284 buffer.open( QIODevice::WriteOnly ); |
|
285 mAlbumArt->pixmap().save( &buffer, "PNG" ); // writes pixmap into bytes in PNG format |
|
286 buffer.close(); |
|
287 QString result = array.toBase64().constData(); |
|
288 TX_ENTRY_ARGS("MpSongDataPrivate: album art base64 length: " << result.length()); |
|
289 return result; |
|
290 */ |
|
291 // TODO: this is temporary solution until base64 defect in QT is fixed. |
|
292 TX_LOG |
|
293 QByteArray array; |
|
294 |
|
295 // Remove old album art in case new one cannot be written. |
|
296 removeAlbumArtFile(); |
|
297 |
|
298 QString sTimeStamp = QTime::currentTime().toString( "hhmmsszzz" ); |
|
299 QString sTempFileLocation = QString( "e:\\album_art_%1.png" ).arg( sTimeStamp ); |
|
300 |
|
301 ( ( MpSongDataPrivate* ) this )->mTempAlbumArt = sTempFileLocation; |
|
302 TX_LOG_ARGS( "Create album art file " << mTempAlbumArt ); |
|
303 |
|
304 QFile file( mTempAlbumArt ); |
|
305 if ( !file.open( QIODevice::WriteOnly ) ) { |
|
306 return QString(""); |
|
307 } |
|
308 if ( mAlbumArt && !mAlbumArt->isNull() && !mAlbumArt->qicon().isNull() ) |
|
309 { |
|
310 QPixmap p = mAlbumArt->qicon().pixmap( QSize( 74, 74 ), QIcon::Normal, QIcon::Off ); |
|
311 p.save( &file, "PNG" ); |
|
312 //mAlbumArt->pixmap().save( &file, "PNG" ); // writes pixmap into bytes in PNG format |
|
313 } |
|
314 file.close(); |
|
315 return mTempAlbumArt; |
|
316 } |
|
317 |
|
318 /*! |
|
319 Delete temporary album art file. |
|
320 */ |
|
321 void MpSongDataPrivate::removeAlbumArtFile() const |
|
322 { |
|
323 TX_ENTRY |
|
324 if ( !mTempAlbumArt.isEmpty() ) |
|
325 { |
|
326 TX_LOG_ARGS( "Remove album art file " << mTempAlbumArt ); |
|
327 QFile::remove( mTempAlbumArt ); |
|
328 ( ( MpSongDataPrivate* ) this )->mTempAlbumArt = ""; |
|
329 } |
|
330 else |
|
331 { |
|
332 TX_LOG_ARGS( "Album art filename is empty" ); |
|
333 } |
|
334 TX_EXIT |
|
335 } |
|
336 |
|
337 /*! |
|
338 Sets the \a link |
|
339 */ |
|
340 void MpSongDataPrivate::setLink( const QString &link ) |
|
341 { |
|
342 TX_ENTRY_ARGS( "Link =" << link ) |
|
343 mLink = link; |
|
344 TX_EXIT |
|
345 } |
|
346 |
|
347 /*! |
|
348 \internal |
|
349 New data from MPX collection. |
|
350 */ |
|
351 void MpSongDataPrivate::setMpxMedia( const CMPXMedia& aMedia ) |
|
352 { |
|
353 TX_ENTRY |
|
354 TRAPD(err, DoSetMpxMediaL(aMedia)); |
|
355 if ( err != KErrNone ) { |
|
356 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
357 } |
|
358 TX_EXIT |
|
359 } |
|
360 |
|
361 /*! |
|
362 Returns the reserved length. |
|
363 */ |
|
364 int MpSongDataPrivate::reservedLength() const |
|
365 { |
|
366 return mLink.length() + mTitle.length() + mArtist.length(); |
|
367 } |
|
368 |
|
369 /*! |
|
370 Handles the album art thumbnail. |
|
371 */ |
|
372 void MpSongDataPrivate::thumbnailReady( QPixmap pixmap, void *data, int id, int error ) |
|
373 { |
|
374 TX_ENTRY |
|
375 Q_UNUSED( data ); |
|
376 if ( error == 0 && mReqId == id ) { |
|
377 QIcon qicon; |
|
378 QPixmap mCompositePixmap; |
|
379 mReqId = KUndefined; |
|
380 |
|
381 mCompositePixmap = QPixmap( 360, 360 ); |
|
382 mCompositePixmap.fill( Qt::transparent ); |
|
383 QPainter painter(&mCompositePixmap); |
|
384 painter.setCompositionMode(QPainter::CompositionMode_Clear); |
|
385 painter.setCompositionMode(QPainter::CompositionMode_SourceOver); |
|
386 painter.fillRect(mCompositePixmap.rect(), Qt::transparent); |
|
387 painter.drawPixmap(QRect(0, 0,360,360), pixmap); |
|
388 |
|
389 if ( !mCompositePixmap.isNull() ) { |
|
390 qicon = QIcon( mCompositePixmap ); |
|
391 } |
|
392 else { |
|
393 qicon = QIcon( pixmap ); |
|
394 } |
|
395 |
|
396 if ( mAlbumArt == mDefaultAlbumArt ) { |
|
397 TX_LOG_ARGS( "Album art is default album art." ) |
|
398 delete mAlbumArt; |
|
399 mAlbumArt = new HbIcon(qicon); |
|
400 mDefaultAlbumArt = new HbIcon( "qtg_large_album_art" ); |
|
401 } else { |
|
402 TX_LOG_ARGS( "Album art is NOT default album art." ) |
|
403 delete mAlbumArt; |
|
404 mAlbumArt = new HbIcon(qicon); |
|
405 } |
|
406 |
|
407 emit q_ptr->albumArtReady(); |
|
408 } |
|
409 else { |
|
410 mReqId = KUndefined; |
|
411 mAlbumArt = mDefaultAlbumArt; |
|
412 emit q_ptr->albumArtReady(); |
|
413 } |
|
414 |
|
415 TX_EXIT |
|
416 } |
|
417 |
|
418 /*! |
|
419 \internal |
|
420 */ |
|
421 void MpSongDataPrivate::DoSetMpxMediaL( const CMPXMedia& aMedia ) |
|
422 { |
|
423 TX_ENTRY |
|
424 bool changed = false; |
|
425 if ( aMedia.IsSupported( KMPXMediaGeneralTitle ) ) { |
|
426 changed |= setTitle( |
|
427 QString::fromUtf16( |
|
428 aMedia.ValueText( KMPXMediaGeneralTitle ).Ptr(), |
|
429 aMedia.ValueText( KMPXMediaGeneralTitle ).Length() ) ); |
|
430 } else { |
|
431 changed |= setTitle( QString() ); |
|
432 } |
|
433 |
|
434 if ( aMedia.IsSupported( KMPXMediaMusicArtist ) ) { |
|
435 changed |= setArtist( |
|
436 QString::fromUtf16( |
|
437 aMedia.ValueText( KMPXMediaMusicArtist ).Ptr(), |
|
438 aMedia.ValueText( KMPXMediaMusicArtist ).Length() ) ); |
|
439 } else { |
|
440 changed |= setArtist( QString() ); |
|
441 } |
|
442 |
|
443 if ( aMedia.IsSupported( KMPXMediaMusicAlbum ) ) { |
|
444 changed |= setAlbum( |
|
445 QString::fromUtf16( |
|
446 aMedia.ValueText( KMPXMediaMusicAlbum ).Ptr(), |
|
447 aMedia.ValueText( KMPXMediaMusicAlbum ).Length() ) ); |
|
448 } else { |
|
449 changed |= setAlbum( QString() ); |
|
450 } |
|
451 if ( changed ) { |
|
452 emit q_ptr->playbackInfoChanged(); |
|
453 } |
|
454 |
|
455 // call back will be called when Album art is retrieved |
|
456 if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaMusicAlbumArtFileName ) ) ) { |
|
457 setAlbumArtUri( |
|
458 QString::fromUtf16( |
|
459 aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Ptr(), |
|
460 aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Length() ) ); |
|
461 } else { |
|
462 setAlbumArtUri( QString() ); |
|
463 } |
|
464 |
|
465 // all following will be for song details |
|
466 changed = false; |
|
467 if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaGeneralUri ) ) ) { |
|
468 QString fullName = QString::fromUtf16( |
|
469 aMedia.ValueText( KMPXMediaGeneralUri ).Ptr(), |
|
470 aMedia.ValueText( KMPXMediaGeneralUri ).Length() ); |
|
471 |
|
472 TX_LOG_ARGS( "File name with path: " << fullName ); |
|
473 // get size & last modifed information from file system |
|
474 QFileInfo info( fullName ); |
|
475 changed |= setSize( info.size() ); |
|
476 |
|
477 // Localization of timestamp is somewhat complex operation: |
|
478 // 1. Localize the date and time parts separately |
|
479 // 2. Concatenate the resulting localized strings |
|
480 // 3. Finally, convert all of the digits in resulting single string |
|
481 // to their localized versions (not all scripts have same numerals |
|
482 // as latin/arabic) |
|
483 QDateTime lastModified = info.lastModified(); |
|
484 QDate date( lastModified.date() ); |
|
485 QTime time( lastModified.time() ); |
|
486 |
|
487 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
488 |
|
489 QString dateStr = locale.format( date, r_qtn_date_usual_with_zero ); |
|
490 QString timeStr = locale.format( time, r_qtn_time_long_with_zero ); |
|
491 QString timestampStr( dateStr + " " + timeStr ); |
|
492 TX_LOG_ARGS( "Timestamp before corrections: " << timestampStr ); |
|
493 QString convertedTimestampStr( HbStringUtil::convertDigits(timestampStr) ); |
|
494 |
|
495 changed |= setModified( convertedTimestampStr ); |
|
496 |
|
497 |
|
498 // get file name without suffix |
|
499 QString file; |
|
500 QRegExp rx("(.+)\\..+"); |
|
501 QString str = info.fileName(); |
|
502 TX_LOG_ARGS( "File name with suffix = " << str ); |
|
503 |
|
504 int pos = rx.indexIn( str ); |
|
505 if( pos > -1 ) { |
|
506 file = rx.cap( 1 ); |
|
507 TX_LOG_ARGS( "File = " << file ); |
|
508 } |
|
509 |
|
510 changed |= setFileName( file ); |
|
511 } else { |
|
512 changed |= setFileName( QString() ); |
|
513 } |
|
514 |
|
515 if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaMusicComposer ) ) ) { |
|
516 TX_LOG_ARGS( "Composer is supported " ); |
|
517 changed |= setComposer( |
|
518 QString::fromUtf16( |
|
519 aMedia.ValueText( KMPXMediaMusicComposer ).Ptr(), |
|
520 aMedia.ValueText( KMPXMediaMusicComposer ).Length() ) ); |
|
521 } else { |
|
522 changed |= setComposer( QString() ); |
|
523 } |
|
524 |
|
525 if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaMusicYear ) ) ) { |
|
526 TInt64 yearInMicroSeconds = aMedia.ValueTObjectL<TInt64>( KMPXMediaMusicYear ); |
|
527 TX_LOG_ARGS( "year = " << yearInMicroSeconds ); |
|
528 TTime yearTime( yearInMicroSeconds ); |
|
529 changed |= setYear( yearTime.DateTime().Year() ); |
|
530 } else { |
|
531 // to clear previous result |
|
532 changed |= setYear( -1 ); |
|
533 } |
|
534 |
|
535 if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaMusicAlbumTrack ) ) ) { |
|
536 changed |= setAlbumTrack( |
|
537 QString::fromUtf16( |
|
538 aMedia.ValueText( KMPXMediaMusicAlbumTrack ).Ptr(), |
|
539 aMedia.ValueText( KMPXMediaMusicAlbumTrack ).Length() ) ); |
|
540 } else { |
|
541 changed |= setAlbumTrack( QString() ); |
|
542 } |
|
543 |
|
544 if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaMusicGenre ) ) ) { |
|
545 changed |= setGenre( |
|
546 QString::fromUtf16( |
|
547 aMedia.ValueText( KMPXMediaMusicGenre ).Ptr(), |
|
548 aMedia.ValueText( KMPXMediaMusicGenre ).Length() ) ); |
|
549 } else { |
|
550 changed |= setGenre( QString() ); |
|
551 } |
|
552 |
|
553 if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaGeneralMimeType ) ) ) { |
|
554 QString type = QString::fromUtf16( |
|
555 aMedia.ValueText( KMPXMediaGeneralMimeType ).Ptr(), |
|
556 aMedia.ValueText( KMPXMediaGeneralMimeType ).Length() ); |
|
557 QString regularExpression(".+/(.+)"); |
|
558 QRegExp rx(regularExpression); |
|
559 QString mimeType; |
|
560 |
|
561 int pos = rx.indexIn( type ); |
|
562 if( pos > -1 ) { |
|
563 mimeType = rx.cap( 1 ); |
|
564 mimeType = mimeType.toUpper(); |
|
565 TX_LOG_ARGS( "MIME type =" << mimeType ); |
|
566 } |
|
567 |
|
568 changed |= setMimeType( mimeType ); |
|
569 } else { |
|
570 changed |= setMimeType( QString() ); |
|
571 } |
|
572 |
|
573 if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaGeneralDuration ) ) ) { |
|
574 TInt duration( aMedia.ValueTObjectL<TInt>( KMPXMediaGeneralDuration ) ); |
|
575 changed |= setDuration( duration / 1000 ); |
|
576 } else { |
|
577 changed |= setDuration( -1 ); |
|
578 } |
|
579 |
|
580 if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaAudioBitrate ) ) ) { |
|
581 TInt bitRate( aMedia.ValueTObjectL<TInt>( KMPXMediaAudioBitrate ) ); |
|
582 changed |= setBitRate( bitRate ); |
|
583 } else { |
|
584 changed |= setBitRate( -1 ); |
|
585 } |
|
586 |
|
587 if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaAudioSamplerate ) ) ) { |
|
588 TInt sampleRate( aMedia.ValueTObjectL<TInt>( KMPXMediaAudioSamplerate ) ); |
|
589 changed |= setSampleRate( sampleRate ); |
|
590 } else { |
|
591 changed |= setSampleRate( -1 ); |
|
592 } |
|
593 |
|
594 |
|
595 if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaGeneralCopyright ) ) ) { |
|
596 changed |= setCopyright( |
|
597 QString::fromUtf16( |
|
598 aMedia.ValueText( KMPXMediaGeneralCopyright ).Ptr(), |
|
599 aMedia.ValueText( KMPXMediaGeneralCopyright ).Length() ) ); |
|
600 } else { |
|
601 changed |= setCopyright( QString() ); |
|
602 } |
|
603 |
|
604 if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaMusicURL ) ) ) { |
|
605 changed |= setMusicURL( |
|
606 QString::fromUtf16( |
|
607 aMedia.ValueText( KMPXMediaMusicURL ).Ptr(), |
|
608 aMedia.ValueText( KMPXMediaMusicURL ).Length() ) ); |
|
609 } else { |
|
610 changed |= setMusicURL( QString() ); |
|
611 } |
|
612 |
|
613 if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaDrmProtected ) ) ) { |
|
614 TX_LOG_ARGS( "DRM is supported." ); |
|
615 changed |= setDrmProtected( aMedia.ValueTObjectL<TBool>( KMPXMediaDrmProtected ) ); |
|
616 } else { |
|
617 changed |= setDrmProtected( false ); |
|
618 } |
|
619 |
|
620 if ( changed ) { |
|
621 emit q_ptr->songDetailInfoChanged(); |
|
622 } |
|
623 TX_EXIT |
|
624 } |
|
625 |
|
626 /*! |
|
627 Sets the song \a title, returns true if the value is new. |
|
628 */ |
|
629 bool MpSongDataPrivate::setTitle( const QString &title ) |
|
630 { |
|
631 TX_ENTRY_ARGS( "title =" << title ) |
|
632 bool change = false; |
|
633 if ( title != mTitle ) { |
|
634 change = true; |
|
635 mTitle = title; |
|
636 } |
|
637 TX_EXIT |
|
638 return change; |
|
639 } |
|
640 |
|
641 /*! |
|
642 Sets the song \a album, returns true if the value is new. |
|
643 */ |
|
644 bool MpSongDataPrivate::setAlbum( const QString &album ) |
|
645 { |
|
646 TX_ENTRY_ARGS( "album =" << album ) |
|
647 bool change = false; |
|
648 if ( album != mAlbum ) { |
|
649 change = true; |
|
650 mAlbum = album; |
|
651 } |
|
652 TX_EXIT |
|
653 return change; |
|
654 } |
|
655 |
|
656 /*! |
|
657 Sets the song \a artist, returns true if the value is new. |
|
658 */ |
|
659 bool MpSongDataPrivate::setArtist( const QString &artist ) |
|
660 { |
|
661 TX_ENTRY_ARGS( "artist =" << artist ) |
|
662 bool change = false; |
|
663 if ( artist != mArtist ) { |
|
664 change = true; |
|
665 mArtist = artist; |
|
666 } |
|
667 TX_EXIT |
|
668 return change; |
|
669 } |
|
670 |
|
671 /*! |
|
672 Sets the song \a comment, returns true if the value is new. |
|
673 */ |
|
674 bool MpSongDataPrivate::setComment( const QString &comment) |
|
675 { |
|
676 TX_ENTRY_ARGS( "comment =" << comment ) |
|
677 bool change = false; |
|
678 if ( comment != mComment ) { |
|
679 change = true; |
|
680 mComment = comment; |
|
681 } |
|
682 TX_EXIT |
|
683 return change; |
|
684 } |
|
685 |
|
686 /*! |
|
687 Sets the song \a composer, returns true if the value is new. |
|
688 */ |
|
689 bool MpSongDataPrivate::setComposer( const QString &composer ) |
|
690 { |
|
691 TX_ENTRY_ARGS( "composer =" << composer ) |
|
692 bool change = false; |
|
693 if ( composer != mComposer ) { |
|
694 change = true; |
|
695 mComposer = composer; |
|
696 } |
|
697 TX_EXIT |
|
698 return change; |
|
699 } |
|
700 |
|
701 /*! |
|
702 Sets the song \a genre, returns true if the value is new. |
|
703 */ |
|
704 bool MpSongDataPrivate::setGenre( const QString &genre ) |
|
705 { |
|
706 TX_ENTRY_ARGS( "genre =" << genre ) |
|
707 bool change = false; |
|
708 if ( genre != mGenre ) { |
|
709 change = true; |
|
710 mGenre = genre; |
|
711 } |
|
712 TX_EXIT |
|
713 return change; |
|
714 } |
|
715 |
|
716 /*! |
|
717 Sets the song \a date, returns true if the value is new. |
|
718 */ |
|
719 bool MpSongDataPrivate::setYear( int year ) |
|
720 { |
|
721 TX_ENTRY_ARGS( "year =" << year ) |
|
722 bool change = false; |
|
723 if ( QString::number(year) != mYear ) { |
|
724 change = true; |
|
725 if ( year >= 0 && year < 9999 ) { |
|
726 mYear = QString::number(year); |
|
727 } else { |
|
728 mYear = QString(); |
|
729 } |
|
730 } |
|
731 TX_EXIT |
|
732 return change; |
|
733 } |
|
734 |
|
735 /*! |
|
736 Sets the \a album track, returns true if the value is new. |
|
737 */ |
|
738 bool MpSongDataPrivate::setAlbumTrack( const QString &track ) |
|
739 { |
|
740 TX_ENTRY_ARGS( "track =" << track ) |
|
741 bool change = false; |
|
742 if ( track != mAlbumTrack ) { |
|
743 change = true; |
|
744 mAlbumTrack = track; |
|
745 } |
|
746 TX_EXIT |
|
747 return change; |
|
748 } |
|
749 |
|
750 /*! |
|
751 Sets the song \a albumArtUri. |
|
752 */ |
|
753 void MpSongDataPrivate::setAlbumArtUri( const QString &albumArtUri) |
|
754 { |
|
755 TX_ENTRY_ARGS( "albumArtUri = " << albumArtUri ) |
|
756 if ( !albumArtUri.isEmpty() ) { |
|
757 TX_LOG_ARGS( "There is album art" ); |
|
758 bool ok = true; |
|
759 if ( mReqId != KUndefined ) { |
|
760 // There is already an outstanding request. Cancel it first. |
|
761 bool ok = mThumbnailManager->cancelRequest( mReqId ); |
|
762 } |
|
763 if ( ok ) { |
|
764 mReqId = mThumbnailManager->getThumbnail( albumArtUri ); |
|
765 if ( mReqId == KUndefined ) { |
|
766 // Request failed. Set default album art. |
|
767 mAlbumArt = mDefaultAlbumArt; |
|
768 emit q_ptr->albumArtReady(); |
|
769 } |
|
770 } |
|
771 } |
|
772 else { |
|
773 // No album art uri. Set default album art. |
|
774 TX_LOG_ARGS( "There is No album art" ); |
|
775 mAlbumArt = mDefaultAlbumArt; |
|
776 emit q_ptr->albumArtReady(); |
|
777 } |
|
778 TX_EXIT |
|
779 } |
|
780 |
|
781 /*! |
|
782 Sets the \a file name |
|
783 */ |
|
784 bool MpSongDataPrivate::setFileName( const QString &fileName ) |
|
785 { |
|
786 TX_ENTRY_ARGS( "File name =" << fileName ) |
|
787 bool change = false; |
|
788 if ( fileName != mFileName ) { |
|
789 change = true; |
|
790 mFileName = fileName; |
|
791 } |
|
792 TX_EXIT |
|
793 return change; |
|
794 } |
|
795 |
|
796 /*! |
|
797 Sets the \a MIME type |
|
798 */ |
|
799 bool MpSongDataPrivate::setMimeType( const QString &mimeType ) |
|
800 { |
|
801 TX_ENTRY_ARGS( "Mime =" << mimeType ) |
|
802 bool change = false; |
|
803 if ( mimeType != mMimeType ) { |
|
804 change = true; |
|
805 mMimeType = mimeType; |
|
806 } |
|
807 TX_EXIT |
|
808 return change; |
|
809 } |
|
810 |
|
811 /*! |
|
812 Sets the \a duration |
|
813 */ |
|
814 bool MpSongDataPrivate::setDuration( int duration ) |
|
815 { |
|
816 TX_ENTRY_ARGS( "Duration =" << duration ) |
|
817 bool change = false; |
|
818 QString timeFormatOne("%1:%2:%3"); |
|
819 QString timeFormatTwo("%1:%2"); |
|
820 if ( QString::number( duration ) != mDuration ) { |
|
821 change = true; |
|
822 if ( duration >= 3600 ) { |
|
823 // more than one hours |
|
824 QString hourStr, minStr, secStr; |
|
825 int hour = duration / 3600; |
|
826 int min = duration % 3600 / 60; |
|
827 int sec = duration % 3600 % 60; |
|
828 |
|
829 hourStr = hour >= 10 ? QString::number( hour ) : QString::number( hour ).prepend( "0" ); |
|
830 minStr = min >= 10 ? QString::number( min ) : QString::number( min ).prepend( "0" ); |
|
831 secStr = sec >= 10 ? QString::number( sec ) : QString::number( sec ).prepend( "0" ); |
|
832 mDuration = timeFormatOne.arg( hourStr ).arg( minStr ).arg( secStr ); |
|
833 } else if ( duration >= 60 && duration < 3600 ) { |
|
834 // more than one min && less than one hour |
|
835 QString minStr, secStr; |
|
836 int min = duration / 60; |
|
837 int sec = duration % 60; |
|
838 |
|
839 minStr = min >= 10 ? QString::number( min ) : QString::number( min ).prepend( "0" ); |
|
840 secStr = sec >= 10 ? QString::number( sec ) : QString::number( sec ).prepend( "0" ); |
|
841 mDuration = timeFormatTwo.arg( minStr ).arg( secStr ); |
|
842 } else if ( duration > 0 && duration < 60 ) { |
|
843 QString secStr; |
|
844 secStr = duration >= 10 ? QString::number( duration ) : QString::number( duration ).prepend( "0" ); |
|
845 mDuration = secStr; |
|
846 } else { |
|
847 mDuration = QString(); |
|
848 } |
|
849 } |
|
850 TX_EXIT |
|
851 return change; |
|
852 } |
|
853 |
|
854 /*! |
|
855 Sets bit rate |
|
856 */ |
|
857 bool MpSongDataPrivate::setBitRate( int bitRate) |
|
858 { |
|
859 TX_ENTRY_ARGS( "Bit rate =" << bitRate ) |
|
860 bool change = false; |
|
861 if ( QString::number( bitRate ) != mBitRate ) { |
|
862 change = true; |
|
863 if ( bitRate > 0 ) { |
|
864 mBitRate = QString::number( bitRate / 1000 ); |
|
865 } else { |
|
866 mBitRate = QString(); |
|
867 } |
|
868 } |
|
869 TX_EXIT |
|
870 return change; |
|
871 } |
|
872 |
|
873 /*! |
|
874 Sets sample rate |
|
875 */ |
|
876 bool MpSongDataPrivate::setSampleRate( int sampleRate ) |
|
877 { |
|
878 TX_ENTRY_ARGS( "Sample rate =" << sampleRate ) |
|
879 bool change = false; |
|
880 if ( QString::number( sampleRate ) != mSampleRate ) { |
|
881 change = true; |
|
882 if ( sampleRate > 0 ) { |
|
883 mSampleRate = QString::number( sampleRate ); |
|
884 } else { |
|
885 mSampleRate = QString(); |
|
886 } |
|
887 } |
|
888 TX_EXIT |
|
889 return change; |
|
890 } |
|
891 |
|
892 /*! |
|
893 Sets the \a size |
|
894 */ |
|
895 bool MpSongDataPrivate::setSize( int size ) |
|
896 { |
|
897 TX_ENTRY_ARGS( "Size =" << size ) |
|
898 bool change = false; |
|
899 if ( QString::number( size ) != mSize ) { |
|
900 change = true; |
|
901 mSize = QString::number( size ); // in bytes |
|
902 } |
|
903 TX_EXIT |
|
904 return change; |
|
905 } |
|
906 |
|
907 /*! |
|
908 Sets the \a modification information |
|
909 */ |
|
910 bool MpSongDataPrivate::setModified( const QString &modified ) |
|
911 { |
|
912 TX_ENTRY_ARGS( "Modified =" << modified ) |
|
913 bool change = false; |
|
914 if ( modified != mModified ) { |
|
915 change = true; |
|
916 mModified = modified; |
|
917 } |
|
918 TX_EXIT |
|
919 return change; |
|
920 } |
|
921 |
|
922 /*! |
|
923 Sets the \a copyright information |
|
924 */ |
|
925 bool MpSongDataPrivate::setCopyright( const QString ©right ) |
|
926 { |
|
927 TX_ENTRY_ARGS( "Copyright =" << copyright ) |
|
928 bool change = false; |
|
929 if ( copyright != mCopyright ) { |
|
930 change = true; |
|
931 mCopyright = copyright; |
|
932 } |
|
933 TX_EXIT |
|
934 return change; |
|
935 } |
|
936 |
|
937 /*! |
|
938 Sets the \a music URL |
|
939 */ |
|
940 bool MpSongDataPrivate::setMusicURL( const QString &musicURL ) |
|
941 { |
|
942 TX_ENTRY_ARGS( "Music URL =" << musicURL ) |
|
943 bool change = false; |
|
944 if ( musicURL != mMusicURL ) { |
|
945 change = true; |
|
946 |
|
947 // Make sure URL contains the correct protocol definition (HTTP). |
|
948 if ( (musicURL.length() > 0) && |
|
949 (musicURL.indexOf( "://", 0, Qt::CaseInsensitive ) == -1) ) { |
|
950 mMusicURL = "http://" + musicURL; |
|
951 TX_LOG_ARGS("Changed music url to " << mMusicURL); |
|
952 } |
|
953 else { |
|
954 mMusicURL = musicURL; |
|
955 TX_LOG_ARGS("Music url unchanged: " << mMusicURL); |
|
956 } |
|
957 } |
|
958 TX_EXIT |
|
959 return change; |
|
960 } |
|
961 |
|
962 /*! |
|
963 Set whether the song is DRM protected |
|
964 */ |
|
965 bool MpSongDataPrivate::setDrmProtected( bool drmProtected ) |
|
966 { |
|
967 TX_ENTRY_ARGS( "DRM protected =" << drmProtected ) |
|
968 bool change = false; |
|
969 if ( drmProtected != mDrmProtected ) { |
|
970 change = true; |
|
971 mDrmProtected = drmProtected; |
|
972 } |
|
973 TX_EXIT |
|
974 return change; |
|
975 } |
|
976 |