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