29 #include <QUrl> |
29 #include <QUrl> |
30 #include <QSslError> |
30 #include <QSslError> |
31 #include <QDir> |
31 #include <QDir> |
32 #include <QCoreApplication> |
32 #include <QCoreApplication> |
33 |
33 |
|
34 #include <thumbnailmanager_qt.h> |
|
35 #include <thumbnaildata.h> |
|
36 #include <thumbnailobjectsource.h> |
|
37 |
34 #include "mpdetailssharedialog.h" |
38 #include "mpdetailssharedialog.h" |
35 #include "mptrace.h" |
39 #include "mptrace.h" |
36 |
40 |
|
41 const int KUndefined = -1; |
37 const int KRecommendationCount = 2; |
42 const int KRecommendationCount = 2; |
38 |
43 |
39 MpQueryManager::MpQueryManager() |
44 MpQueryManager::MpQueryManager() |
|
45 : mManager(0), |
|
46 mDownloadManager(0), |
|
47 mThumbnailManager(0) |
40 |
48 |
41 { |
49 { |
42 TX_ENTRY |
50 TX_ENTRY |
43 |
51 |
44 QString privatePathQt( QCoreApplication::applicationDirPath() ); |
52 QString privatePathQt( QCoreApplication::applicationDirPath() ); |
58 |
66 |
59 mManager = new QNetworkAccessManager( this ); |
67 mManager = new QNetworkAccessManager( this ); |
60 |
68 |
61 mDownloadManager = new QNetworkAccessManager( this ); |
69 mDownloadManager = new QNetworkAccessManager( this ); |
62 connect( mDownloadManager, SIGNAL( finished( QNetworkReply * ) ), this, SLOT( DownloadFinished( QNetworkReply * ) ) ); |
70 connect( mDownloadManager, SIGNAL( finished( QNetworkReply * ) ), this, SLOT( DownloadFinished( QNetworkReply * ) ) ); |
|
71 |
|
72 mThumbnailManager = new ThumbnailManager( this ); |
|
73 mThumbnailManager->setQualityPreference( ThumbnailManager::OptimizeForQuality ); |
|
74 mThumbnailManager->setThumbnailSize( ThumbnailManager::ThumbnailSmall ); |
|
75 QObject::connect( mThumbnailManager, SIGNAL( thumbnailReady( QPixmap , void * , int , int ) ), |
|
76 this, SLOT( thumbnailReady( QPixmap , void * , int , int ) ) ); |
|
77 // TODO: Use the album art in provided by 10.1 wk16 platform. Current one is in the binary |
|
78 mDefaultRecommendationAlbumArt = QPixmap( ":/mpdetailsviewicons/qtg_large_music_album.svg" ); |
63 |
79 |
64 TX_EXIT |
80 TX_EXIT |
65 } |
81 } |
66 |
82 |
67 MpQueryManager::~MpQueryManager() |
83 MpQueryManager::~MpQueryManager() |
183 TX_LOG |
200 TX_LOG |
184 return mRecommendationAlbumArtsMap; |
201 return mRecommendationAlbumArtsMap; |
185 } |
202 } |
186 |
203 |
187 /*! |
204 /*! |
188 Return the number of ready album arts |
|
189 */ |
|
190 int &MpQueryManager::albumArtsReadyCount() |
|
191 { |
|
192 TX_LOG |
|
193 return mAlbumArtsReadyCount; |
|
194 } |
|
195 |
|
196 /*! |
|
197 Insert one uri & pixmap item into map |
205 Insert one uri & pixmap item into map |
198 */ |
206 */ |
199 void MpQueryManager::insertMapItem( const QString &uri, const QPixmap &pixmap ) |
207 void MpQueryManager::insertMapItem( const QString &uri, const QPixmap &pixmap ) |
200 { |
208 { |
201 TX_ENTRY_ARGS( "Map Item URI: " << uri ); |
209 TX_ENTRY_ARGS( "Map Item URI: " << uri ); |
267 |
275 |
268 // If file writing went OK, emit a signal with the real filename |
276 // If file writing went OK, emit a signal with the real filename |
269 // If it failed, use empty filename (since file was removed in any case) |
277 // If it failed, use empty filename (since file was removed in any case) |
270 if ( ret ) |
278 if ( ret ) |
271 { |
279 { |
272 emit setAlbumArt( mRecommendationAlbumArtsLink.at( mDownloadedAlbumArts), |
280 setAlbumArtUri( mRecommendationAlbumArtsLink.at( mDownloadedAlbumArts), |
273 mRecommendationAlbumArtsName.at( mDownloadedAlbumArts ) ); |
281 mRecommendationAlbumArtsName.at( mDownloadedAlbumArts ) ); |
274 } |
282 } |
275 else |
283 else |
276 { |
284 { |
277 emit setAlbumArt( mRecommendationAlbumArtsLink.at( mDownloadedAlbumArts), "" ); |
285 setAlbumArtUri(mRecommendationAlbumArtsLink.at( mDownloadedAlbumArts), ""); |
278 } |
286 } |
279 } |
287 } |
280 else |
288 else |
281 { |
289 { |
282 TX_LOG_ARGS( "Downloading album art failed!" ); |
290 TX_LOG_ARGS( "Downloading album art failed!" ); |
470 } |
478 } |
471 TX_EXIT |
479 TX_EXIT |
472 return str.left( str.length() - 1 ); |
480 return str.left( str.length() - 1 ); |
473 } |
481 } |
474 |
482 |
|
483 /*! |
|
484 Sets recommendation album art |
|
485 */ |
|
486 void MpQueryManager::setAlbumArtUri( const QString &albumArtUri, const QString &albumArtName ) |
|
487 { |
|
488 TX_ENTRY_ARGS( "albumArtUri = " << albumArtUri ) |
|
489 TX_LOG_ARGS( "albumArtName = " << albumArtName ) |
|
490 if ( !albumArtUri.isEmpty() && !albumArtName.isEmpty() ) { |
|
491 int id = mThumbnailManager->getThumbnail( albumArtName, reinterpret_cast<void *>( const_cast<QString *>( &albumArtUri ) ) ); |
|
492 if ( id == KUndefined ) { |
|
493 // Request failed. Set default album art. |
|
494 insertMapItem( albumArtUri, mDefaultRecommendationAlbumArt ); |
|
495 } |
|
496 } |
|
497 else { |
|
498 // No album art uri. Set default album art. |
|
499 insertMapItem( albumArtUri, mDefaultRecommendationAlbumArt ); |
|
500 } |
|
501 TX_EXIT |
|
502 } |
|
503 |
|
504 /*! |
|
505 Slot to handle the recommendation album art |
|
506 */ |
|
507 void MpQueryManager::thumbnailReady( |
|
508 const QPixmap& pixmap, |
|
509 void *data, |
|
510 int /*id*/, |
|
511 int error ) |
|
512 { |
|
513 TX_ENTRY |
|
514 // TODO: Hkn: use qobject_cast |
|
515 QString uri = *( reinterpret_cast<QString *>( data ) ); |
|
516 TX_LOG_ARGS( "Uri: " << uri ); |
|
517 |
|
518 if ( error == 0 ) { |
|
519 TX_LOG_ARGS( "album art link: " << uri ); |
|
520 insertMapItem( uri, pixmap ); |
|
521 } else { |
|
522 insertMapItem( uri, mDefaultRecommendationAlbumArt ); |
|
523 } |
|
524 if(++mAlbumArtsReadyCount == KRecommendationCount) { |
|
525 emit recommendationAlbumArtsReady(); |
|
526 } |
|
527 TX_EXIT |
|
528 } |