mpviewplugins/mpdetailsviewplugin/src/mpdetailsview.cpp
changeset 20 82baf59ce8dd
child 22 ecf06a08d4d9
equal deleted inserted replaced
19:4e84c994a771 20:82baf59ce8dd
       
     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: Music Player details view.
       
    15 *
       
    16 */
       
    17 #include <qgraphicswebview>
       
    18 #include <qwebsettings>
       
    19 #include <QGraphicsWidget>
       
    20 #include <QGraphicsLayoutItem>
       
    21 #include <QUrl>
       
    22 #include <QSslError>
       
    23 #include <QDomElement>
       
    24 #include <QWebPage>
       
    25 #include <QWebFrame>
       
    26 #include <QList>
       
    27 #include <QFile>
       
    28 #include <QTranslator>
       
    29 #include <QLocale>
       
    30 #include <QGraphicsLinearLayout>
       
    31 
       
    32 #include <thumbnailmanager_qt.h>
       
    33 #include <thumbnaildata.h>
       
    34 #include <thumbnailobjectsource.h>
       
    35 
       
    36 #include <hbinstance.h>
       
    37 #include <hbmainwindow.h>
       
    38 #include <hbaction.h>
       
    39 #include <hblabel.h>
       
    40 #include <hbgroupbox.h>
       
    41 #include <hbdocumentloader.h>
       
    42 #include <hbwidget.h>
       
    43 #include <hbpushbutton.h>
       
    44 #include <hbpopup.h>
       
    45 #include <hbdialog.h>
       
    46 #include <hblistwidget.h>
       
    47 #include <hblistwidgetitem.h>
       
    48 
       
    49 #include "mpdetailsview.h"
       
    50 #include "mpcommondefs.h"
       
    51 #include "mpmpxdetailsframeworkwrapper.h"
       
    52 #include "mpsongdata.h"
       
    53 #include "mptrace.h"
       
    54 
       
    55 const int KUndefined = -1;
       
    56 const int KRecommendationNum = 2;
       
    57 
       
    58 /*!
       
    59  Constructor
       
    60  */
       
    61 MpDetailsView::MpDetailsView()
       
    62     : mSongData( 0 ),
       
    63       mFrameworkWrapper( 0 ),
       
    64       mActivated( false ),
       
    65       mWindow( 0 ),
       
    66       mSoftKeyBack( 0 ),
       
    67       mSongText( NULL ),
       
    68       mAlbumText( NULL ),
       
    69       mArtistText( NULL ),
       
    70       mAlbumArt( NULL ),
       
    71       mDocumentLoader( NULL ),
       
    72       mDownloadedAlbumArts( 0 ),
       
    73       mAlbumArtsReadyCount( 0 ),
       
    74       mMpTranslator( 0 ),
       
    75       mCommonTranslator( 0 )
       
    76 {
       
    77     TX_ENTRY
       
    78     bool widgetsOk = false;
       
    79     HbMainWindow *mainWindow = hbInstance->allMainWindows()[0];
       
    80     mDocumentLoader = new HbDocumentLoader();
       
    81 
       
    82     if ( mDocumentLoader ) {
       
    83             mDocumentLoader->load( QString(":/detailsviewdocml/detailsview.docml"), &widgetsOk );
       
    84         }
       
    85     if ( widgetsOk ) {
       
    86         QGraphicsWidget *widget; 
       
    87         
       
    88         widget = mDocumentLoader->findWidget( QString("content") );
       
    89         mContainer = qobject_cast<HbWidget *>(widget);
       
    90         if ( mContainer ) {
       
    91             setWidget( mContainer );
       
    92         }
       
    93         
       
    94      widget = mDocumentLoader->findWidget( QString("shareButton") );
       
    95      mShareButton = qobject_cast<HbPushButton *>(widget);         
       
    96         
       
    97      widget = mDocumentLoader->findWidget( QString("songText") );
       
    98      mSongText = qobject_cast<HbLabel *>(widget);
       
    99     
       
   100      widget = mDocumentLoader->findWidget( QString("artistText") );
       
   101      mArtistText = qobject_cast<HbLabel *>(widget);
       
   102     
       
   103      widget = mDocumentLoader->findWidget( QString("albumText") );
       
   104      mAlbumText = qobject_cast<HbLabel *>(widget);
       
   105 
       
   106      widget = mDocumentLoader->findWidget( QString("albumArt") );
       
   107      mAlbumArt = qobject_cast<HbLabel *>(widget);
       
   108         
       
   109      widget = mDocumentLoader->findWidget( QString("songDetailsGroupBox") );
       
   110      mSongDetailsGroupBox = qobject_cast<HbGroupBox *>(widget);
       
   111         
       
   112      widget = mDocumentLoader->findWidget( QString("inspireMeGroupBox") );
       
   113      mInspireMeGroupBox = qobject_cast<HbGroupBox *>(widget);
       
   114     }
       
   115     else {
       
   116         TX_LOG_ARGS( "Error: invalid detailsview.docml" );
       
   117     }
       
   118     TX_EXIT
       
   119 }
       
   120 
       
   121 /*!
       
   122  Destructs the details view.
       
   123  */
       
   124 MpDetailsView::~MpDetailsView()
       
   125 {
       
   126     TX_ENTRY    
       
   127     if ( mFrameworkWrapper ) {
       
   128         delete mFrameworkWrapper;
       
   129     }
       
   130     if ( mSoftKeyBack ) {
       
   131         delete mSoftKeyBack;
       
   132     }
       
   133     if ( mDocumentLoader ) {
       
   134         delete mDocumentLoader;
       
   135     }
       
   136     if ( mManager ) {
       
   137         mManager->deleteLater();
       
   138     }
       
   139     if ( mDownloadManager ) {
       
   140         mDownloadManager->deleteLater();
       
   141     }    
       
   142     if( mThumbnailManager ) {
       
   143         delete mThumbnailManager;
       
   144     }
       
   145     delete mMpTranslator;
       
   146     delete mCommonTranslator;
       
   147     TX_EXIT
       
   148 }
       
   149 
       
   150 /*!
       
   151  Initializes the details view. Allocates all resources needed by the view.
       
   152  */
       
   153 void MpDetailsView::initializeView()
       
   154 {
       
   155     TX_ENTRY    
       
   156     
       
   157     //Load musicplayer and common translators
       
   158         QString lang = QLocale::system().name();
       
   159         QString path = QString( "z:/resource/qt/translations/" );
       
   160         bool translatorLoaded = false;
       
   161 
       
   162         mMpTranslator = new QTranslator( this );
       
   163         translatorLoaded = mMpTranslator->load( path + "musicplayer_" + lang );
       
   164         TX_LOG_ARGS( "Loading translator ok=" << translatorLoaded );
       
   165         if ( translatorLoaded ) {
       
   166             qApp->installTranslator( mMpTranslator );
       
   167         }
       
   168 
       
   169         mCommonTranslator = new QTranslator( this );
       
   170         translatorLoaded = mCommonTranslator->load( path + "common_" + lang );
       
   171         TX_LOG_ARGS( "Loading common translator ok=" << translatorLoaded );
       
   172         if ( translatorLoaded ) {
       
   173             qApp->installTranslator( mCommonTranslator );
       
   174         }
       
   175         
       
   176     mWindow = mainWindow();
       
   177     mSoftKeyBack = new HbAction( Hb::BackAction, this );    
       
   178     mFrameworkWrapper = new MpMpxDetailsFrameworkWrapper( );
       
   179     mSongData = mFrameworkWrapper->songData();
       
   180     
       
   181     mCompositePixmap = QPixmap( 150, 150 );
       
   182     
       
   183     mDetailList = new HbListWidget( mSongDetailsGroupBox );
       
   184     mButton = new HbPushButton( tr( "More recommendations" ) );
       
   185     mSongDetailsGroupBox->setCollapsable( true );
       
   186     mSongDetailsGroupBox->setHeading( tr("Song details") );
       
   187     mSongDetailsGroupBox->setContentWidget( mDetailList );
       
   188     mSongDetailsGroupBox->setCollapsed( true );
       
   189 
       
   190     mLayout = new QGraphicsLinearLayout( Qt::Vertical );
       
   191     mInspireMe = new HbWidget( mInspireMeGroupBox );
       
   192     mInspireList = new HbListWidget();
       
   193     mInspireMeGroupBox->setCollapsable( true );   
       
   194     mInspireMeGroupBox->setHeading( tr("Inspire me") );
       
   195     mInspireMeGroupBox->setContentWidget( mInspireMe ); 
       
   196     
       
   197 
       
   198     mManager = new QNetworkAccessManager( this );
       
   199     connect( mManager, SIGNAL( finished( QNetworkReply * ) ), this, SLOT( retrieveInformationFinished( QNetworkReply * ) ) );
       
   200     
       
   201     mDownloadManager = new QNetworkAccessManager( this );
       
   202     connect( mDownloadManager, SIGNAL( finished( QNetworkReply * ) ), this, SLOT( DownloadFinished( QNetworkReply * ) ) );
       
   203     
       
   204     mRecommendationAlbumArtsName << "C:\\Data\\albumOne.png" << "C:\\Data\\albumTwo.png"; 
       
   205     
       
   206     mThumbnailManager = new ThumbnailManager( this );
       
   207     mThumbnailManager->setQualityPreference( ThumbnailManager::OptimizeForQuality );
       
   208     mThumbnailManager->setThumbnailSize( ThumbnailManager::ThumbnailSmall );
       
   209     QObject::connect( mThumbnailManager, SIGNAL( thumbnailReady( QPixmap , void * , int , int ) ),
       
   210             this, SLOT( thumbnailReady( QPixmap , void * , int , int  ) ) );
       
   211     mDefaultRecommendationAlbumArt = QPixmap( ":/detailsviewicons/defaultalbumart.png" );
       
   212     
       
   213     setTitle( tr("Music") );
       
   214     // TODO: might need later
       
   215     setupMenu();
       
   216       
       
   217     connect( mSoftKeyBack, SIGNAL( triggered() ), this, SLOT( back() ) );
       
   218     connect( mShareButton, SIGNAL( clicked() ), this, SLOT( share() ) );    
       
   219     connect( mSongData, SIGNAL( albumArtReady() ), this, SLOT( albumArtChanged() ) ); 
       
   220     connect( mSongData, SIGNAL( playbackInfoChanged() ), this, SLOT( playbackInfoChanged() ) );
       
   221     connect( mSongData, SIGNAL( songDetailInfoChanged() ), this, SLOT( songDetailInfoChanged() ) ); 
       
   222     connect( mSongDetailsGroupBox, SIGNAL( toggled( bool ) ), this, SLOT( toggleInspireMeGroupBox( bool ) ) );
       
   223     connect( mInspireMeGroupBox, SIGNAL( toggled( bool ) ), this, SLOT( toggleDetailsGroupBox( bool ) ) );
       
   224     TX_EXIT
       
   225 }
       
   226 
       
   227 /*!
       
   228  Activates the details view.
       
   229  */
       
   230 void MpDetailsView::activateView()
       
   231 {
       
   232     TX_ENTRY    
       
   233     setNavigationAction( mSoftKeyBack );
       
   234     mFrameworkWrapper->retrieveSong();
       
   235         
       
   236     mActivated = true;
       
   237     TX_EXIT
       
   238 }
       
   239 
       
   240 /*!
       
   241  Deactivates the details view.
       
   242  */
       
   243 void MpDetailsView::deactivateView()
       
   244 {
       
   245     TX_ENTRY    
       
   246     setNavigationAction( 0 );
       
   247     mActivated = false;    
       
   248     TX_EXIT
       
   249 }
       
   250 
       
   251 /*!
       
   252  Setup the menu.
       
   253  */
       
   254 void MpDetailsView::setupMenu()
       
   255 {
       
   256     TX_ENTRY
       
   257 
       
   258     TX_EXIT
       
   259 }
       
   260 
       
   261 /*!
       
   262  Slot to handle back command from softkey.
       
   263 
       
   264  \reimp
       
   265  */
       
   266 void MpDetailsView::back()
       
   267 {
       
   268     TX_ENTRY  
       
   269     emit command( MpCommon::ActivatePlaybackView );
       
   270     TX_EXIT
       
   271 }
       
   272 
       
   273 /*!
       
   274  Slot to be called when share button is clicked
       
   275  */
       
   276 void MpDetailsView::share()
       
   277 {
       
   278     TX_ENTRY  
       
   279     TX_EXIT    
       
   280 }
       
   281 
       
   282 /*!
       
   283  Slot to handle Album art changed.
       
   284  */
       
   285 void MpDetailsView::albumArtChanged( )
       
   286 {    
       
   287     TX_ENTRY
       
   288     QPixmap pixmap;
       
   289     QIcon qicon;
       
   290     mSongData->albumArt( pixmap );
       
   291     composeAlbumCover( pixmap );
       
   292     if ( !mCompositePixmap.isNull() )
       
   293         qicon = QIcon( mCompositePixmap );
       
   294     else
       
   295         qicon = QIcon( pixmap );
       
   296     HbIcon icon( qicon );  
       
   297     mAlbumArt->setIcon( icon );
       
   298     TX_EXIT
       
   299 }
       
   300 
       
   301 void MpDetailsView::loadSharePlayer()
       
   302 {
       
   303     TX_ENTRY       
       
   304     TX_EXIT    
       
   305 }
       
   306 
       
   307 
       
   308 /*!
       
   309  Slot to call when widget is loaded
       
   310  */
       
   311 void MpDetailsView::webViewLoaded( bool ok )
       
   312 {
       
   313     TX_ENTRY    
       
   314     if ( ok ) {
       
   315         TX_LOG_ARGS( "Loading web page successfully." );
       
   316 
       
   317     } else {
       
   318         TX_LOG_ARGS( "Loading web page failed!" );
       
   319     }
       
   320     TX_EXIT    
       
   321 }
       
   322 
       
   323 
       
   324 /*!
       
   325  Compose the album art.
       
   326  */
       
   327 void MpDetailsView::composeAlbumCover( QPixmap albumart )
       
   328 {
       
   329     TX_ENTRY
       
   330     mCompositePixmap.fill( Qt::transparent );
       
   331     QPainter painter( &mCompositePixmap );
       
   332     painter.setCompositionMode( QPainter::CompositionMode_Clear );
       
   333     painter.setCompositionMode( QPainter::CompositionMode_SourceOver );
       
   334     painter.fillRect( mCompositePixmap.rect(), Qt::transparent );
       
   335     painter.drawPixmap( QRect( 0, 0, 150, 150 ), albumart );
       
   336     TX_EXIT
       
   337 }
       
   338 
       
   339 /*!
       
   340  Make a key & value pair string for querying
       
   341  */
       
   342 QString MpDetailsView::keyValues( QStringList keys, QStringList values ) const
       
   343 {
       
   344     TX_ENTRY
       
   345     QString str;
       
   346     if ( keys.length() != values.length() ) {
       
   347         TX_LOG_ARGS( "Error: keys length is not equal to values length" ); 
       
   348     } else {
       
   349         for ( int i = 0; i < keys.length(); i++ ) {
       
   350             QString tValue = values.at( i );
       
   351             if ( 0 != tValue.length() )
       
   352             {
       
   353                 str += keys.at( i ) + "=" + values.at( i ) + "&";
       
   354             }
       
   355         }
       
   356     }
       
   357     TX_EXIT
       
   358     return str.left( str.length() - 1 );
       
   359 }
       
   360 
       
   361 /*!
       
   362  Find the most suitable link based on Atom response from Ovi music server
       
   363  */
       
   364 void MpDetailsView::handleParsedXML()
       
   365 {
       
   366     TX_ENTRY
       
   367     QDomElement rootElement = mDomDocument.documentElement();
       
   368     
       
   369     if ( rootElement.attribute( "type" ) == tr( "search" ) ) {
       
   370         TX_LOG_ARGS( "URI response" )
       
   371         QString result;
       
   372         QDomElement entry = rootElement.firstChildElement( "entry" );
       
   373         while ( !entry.isNull() )
       
   374         {
       
   375             if ( entry.attribute( "type" ) == tr( "musictrack" ) ) {
       
   376                 QDomElement link = entry.firstChildElement( "link" );
       
   377                 while ( !link.isNull() )
       
   378                 {
       
   379                     if ( link.attribute( "rel" ) == tr( "alternate" )
       
   380                         && link.attribute( "type" ) == tr( "text/html" ) ) {
       
   381                         result = link.attribute( "href" );
       
   382                     }
       
   383                     link = link.nextSiblingElement( "link" );
       
   384                 }
       
   385             }
       
   386             entry = entry.nextSiblingElement( "entry" );
       
   387         }  
       
   388         
       
   389         mSongData->setLink( result );
       
   390     } else if ( rootElement.attribute( "type" ) == tr( "recommendedTracks" ) ) {
       
   391         TX_LOG_ARGS( "Recommendation response" )
       
   392         QDomElement entry = rootElement.firstChildElement( "entry" );
       
   393         QNetworkReply *reply;
       
   394         int count = 0;
       
   395         while ( !entry.isNull() && count < KRecommendationNum )
       
   396         {
       
   397             if ( entry.attribute( "type" ) == tr( "musictrack" ) ) {
       
   398                 QDomElement link = entry.firstChildElement( "link" );
       
   399                 while ( !link.isNull() )
       
   400                 {
       
   401                     if ( link.attribute( "title" ) == tr( "albumart100" ) ) {
       
   402                         mRecommendationAlbumArtsLink.append( link.attribute( "href" ) );
       
   403                         break;
       
   404                     } else {
       
   405                         link = link.nextSiblingElement( "link" );
       
   406                     }                    
       
   407                 }
       
   408                 QDomElement metadata = entry.firstChildElement( "metadata" );
       
   409                 mRecommendationSongs.append( metadata.firstChildElement( "name" ).text() );
       
   410                 mRecommendationArtists.append( metadata.firstChildElement( "primaryartist" ).text() );
       
   411                 count++;
       
   412             }
       
   413             entry = entry.nextSiblingElement( "entry" );
       
   414         }          
       
   415         
       
   416         for (int i = 0; i < KRecommendationNum; i++ ) {
       
   417             TX_LOG_ARGS( "song name: " << mRecommendationSongs.at(i) );
       
   418             TX_LOG_ARGS( "Artist name: " << mRecommendationArtists.at(i) );
       
   419             TX_LOG_ARGS( "Album art link: " << mRecommendationAlbumArtsLink.at(i) );
       
   420             
       
   421             if ( mRecommendationAlbumArtsLink.at( i ).contains( "http", Qt::CaseInsensitive ) ) {
       
   422                 reply = mDownloadManager->get( QNetworkRequest( QUrl( mRecommendationAlbumArtsLink.at(i) ) ) );
       
   423                 mReplys.append( reply );
       
   424                 connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), this, SLOT( retrieveInformationNetworkError( QNetworkReply::NetworkError ) ) );
       
   425                 connect( reply, SIGNAL( sslErrors( QList<QSslError> ) ), this, SLOT( retrieveInformationSslErrors( QList<QSslError> ) ) );
       
   426             }             
       
   427         }
       
   428     } else {
       
   429         TX_LOG_ARGS( "Not supported response" )
       
   430     }
       
   431     TX_EXIT
       
   432 }
       
   433 
       
   434 /*!
       
   435  Sets recommendation album art
       
   436 */
       
   437 void MpDetailsView::setAlbumArtUri( const QString &albumArtUri, const QString &albumArtName )
       
   438 {
       
   439     TX_ENTRY_ARGS( "albumArtUri = " << albumArtUri )
       
   440     TX_LOG_ARGS( "albumArtName = " << albumArtName )
       
   441     if ( !albumArtUri.isEmpty() ) {
       
   442         int id = mThumbnailManager->getThumbnail( albumArtName, reinterpret_cast<void *>( const_cast<QString *>( &albumArtUri ) ) );
       
   443         if ( id == KUndefined ) {
       
   444             // Request failed. Set default album art.
       
   445             mRecommendationAlbumArtsMap.insert( albumArtUri, mDefaultRecommendationAlbumArt );
       
   446             recommendationAlbumArtReady();
       
   447         }
       
   448     }
       
   449     else {
       
   450         // No album art uri. Set default album art.
       
   451         mRecommendationAlbumArtsMap.insert( albumArtUri, mDefaultRecommendationAlbumArt );
       
   452         recommendationAlbumArtReady();
       
   453     }
       
   454     TX_EXIT
       
   455 }
       
   456 
       
   457 /*!
       
   458  Render inspireme groupbox after album arts downloaded
       
   459  */
       
   460 void MpDetailsView::RenderInspireMeGroupBox() 
       
   461 {
       
   462     TX_ENTRY
       
   463     for ( int i = 0; i < KRecommendationNum; i++ ) {
       
   464        HbListWidgetItem  *item = new HbListWidgetItem();       
       
   465        HbIcon icon( QIcon( mRecommendationAlbumArtsMap.value( mRecommendationAlbumArtsLink.at( i ) ) ) );
       
   466        item->setIcon( icon );
       
   467        item->setText( mRecommendationSongs.at( i ) );
       
   468        item->setSecondaryText( mRecommendationArtists.at( i ) );
       
   469 
       
   470        mInspireList->addItem( item );       
       
   471     }
       
   472     
       
   473     // TODO: HbListWidget has some problem to return the correct height, hard code to 180 for now.
       
   474     TX_LOG_ARGS( "height = " << mInspireList->geometry().height() );
       
   475     TX_LOG_ARGS( "height2 = " << mInspireList->size().height() );
       
   476     mInspireList->setMinimumHeight( 180 );
       
   477     mInspireList->setMaximumHeight( 180 );    
       
   478     
       
   479     mLayout->addItem( mInspireList );
       
   480     mButton->show();
       
   481     mLayout->addItem( mButton );
       
   482     mInspireMe->setLayout( mLayout );
       
   483     
       
   484     TX_EXIT
       
   485 }
       
   486 
       
   487 void MpDetailsView::recommendationAlbumArtReady()
       
   488 {   
       
   489     TX_ENTRY_ARGS( "mAlbumArtsReadyCount = " << mAlbumArtsReadyCount )
       
   490     mAlbumArtsReadyCount++;
       
   491     if ( mAlbumArtsReadyCount == KRecommendationNum ) {
       
   492         RenderInspireMeGroupBox();
       
   493     }
       
   494     TX_EXIT
       
   495 }
       
   496 
       
   497 
       
   498 /*!
       
   499  Slot to handle basic song information
       
   500  */
       
   501 void MpDetailsView::playbackInfoChanged()
       
   502 {
       
   503     TX_ENTRY
       
   504     mSongText->setPlainText( mSongData->title() );
       
   505     mAlbumText->setPlainText( mSongData->album() );
       
   506     mArtistText->setPlainText( mSongData->artist() );
       
   507     
       
   508     // Clear information & Remove album arts downloaded previously when song changes
       
   509     TX_LOG_ARGS( "Reply count = " << mReplys.count() );
       
   510     for ( int i = 0; i < mReplys.count(); i++ ) {
       
   511         QNetworkReply *reply = mReplys.at( i );
       
   512         if ( reply != NULL ) {
       
   513             TX_LOG_ARGS( "Reply index : " << i );
       
   514             reply->close();
       
   515             delete reply;
       
   516             reply = NULL;
       
   517         }   
       
   518     }
       
   519     mReplys.clear();
       
   520     
       
   521     mDownloadedAlbumArts = 0;
       
   522     mAlbumArtsReadyCount = 0;
       
   523     mInspireList->clear();
       
   524     for ( int i = 0; i < KRecommendationNum; i++) {
       
   525         mRecommendationSongs.clear();
       
   526         mRecommendationArtists.clear();
       
   527         mRecommendationAlbumArtsLink.clear();
       
   528         mRecommendationAlbumArtsMap.clear();
       
   529         
       
   530         QFile file( mRecommendationAlbumArtsName.at( i ) );        
       
   531         if ( file.exists() ) {
       
   532             if ( file.remove() ) {
       
   533                 TX_LOG_ARGS( "File removed - " << file.fileName() );
       
   534             }
       
   535             else {
       
   536                 TX_LOG_ARGS( "Cannot remove file - " << file.fileName() );
       
   537             }
       
   538         } else {
       
   539             TX_LOG_ARGS( "File doesn't exist - " << file.fileName() );
       
   540         }
       
   541     }
       
   542     mButton->hide();
       
   543         
       
   544     // TODO: country information handling, MCC
       
   545     QString queryURI("http://api.music.ovi.com/1.0/ru/?");
       
   546     constructRequest( queryURI );
       
   547     TX_LOG_ARGS( "queryURI : " << queryURI );
       
   548     retrieveInformation( queryURI );
       
   549     
       
   550     QString queryRecommendation("http://api.music.ovi.com/1.0/gb/releases/recommend/?");
       
   551     constructRequest( queryRecommendation );
       
   552     TX_LOG_ARGS( "queryRecommendation : " << queryRecommendation );
       
   553     retrieveInformation( queryRecommendation );
       
   554     
       
   555     loadSharePlayer();
       
   556     TX_EXIT
       
   557 }
       
   558 
       
   559 /*!
       
   560  Slot to handle detail song information
       
   561  */
       
   562 void MpDetailsView::songDetailInfoChanged()
       
   563 {
       
   564     TX_ENTRY
       
   565     mDetailList->clear();
       
   566     
       
   567     HbListWidgetItem *item = new HbListWidgetItem();  
       
   568     item->setText( tr( "Track" ) );
       
   569     item->setSecondaryText( mSongData->albumTrack() );
       
   570     mDetailList->addItem( item );
       
   571     
       
   572     item = new HbListWidgetItem();
       
   573     item->setText( tr( "Composer" ) );
       
   574     item->setSecondaryText( mSongData->composer() );
       
   575     mDetailList->addItem( item );
       
   576 
       
   577     item = new HbListWidgetItem();
       
   578     item->setText( tr( "Year" ) );
       
   579     item->setSecondaryText( mSongData->year() );
       
   580     mDetailList->addItem( item );
       
   581     
       
   582     item = new HbListWidgetItem();
       
   583     item->setText( tr( "Genre" ) );
       
   584     item->setSecondaryText( mSongData->genre() );
       
   585     mDetailList->addItem( item );
       
   586 
       
   587     item = new HbListWidgetItem();
       
   588     item->setText( tr( "Comment" ) );
       
   589     item->setSecondaryText( mSongData->comment() );
       
   590     mDetailList->addItem( item );    
       
   591     TX_EXIT
       
   592 }
       
   593 
       
   594 /*!
       
   595  Slot to handle details groupbox toggling
       
   596  */
       
   597 void MpDetailsView::toggleDetailsGroupBox(bool /*state*/)
       
   598 {
       
   599     TX_ENTRY
       
   600     if ( !mInspireMeGroupBox->isCollapsed() ) {
       
   601         mSongDetailsGroupBox->setCollapsed( true );
       
   602     }
       
   603     TX_EXIT
       
   604 }
       
   605 
       
   606 /*!
       
   607  Slot to handle inspire me groupbox toggling
       
   608  */
       
   609 void MpDetailsView::toggleInspireMeGroupBox(bool /*state*/)
       
   610 {
       
   611     TX_ENTRY
       
   612     if ( !mSongDetailsGroupBox->isCollapsed() ) {
       
   613         mInspireMeGroupBox->setCollapsed( true );
       
   614     }
       
   615     TX_EXIT
       
   616 }
       
   617 
       
   618 /*!
       
   619  Construct the query for fetching URI & recommendations
       
   620  */
       
   621 void MpDetailsView::constructRequest( QString &uri )
       
   622 {
       
   623     TX_ENTRY_ARGS( "uri =" << uri)
       
   624     
       
   625     QStringList keys;
       
   626     keys << tr("artist") << tr("albumtitle") << tr("tracktitle") << tr("orderby");
       
   627     
       
   628     // TODO: need to clarify which crition to use for sort, currently hard code to "relevancy"
       
   629     // order can be relevancy, alltimedownloads, streetreleasedate, sortname, recentdownloads
       
   630     QStringList values;
       
   631     values << mSongData->artist() << mSongData->album()
       
   632             << mSongData->title() << QString(tr("relevancy"));
       
   633     TX_LOG_ARGS( "Artist: " << mSongData->artist() ); 
       
   634     TX_LOG_ARGS( "Album: " << mSongData->album() );
       
   635     TX_LOG_ARGS( "Title: " << mSongData->title() );
       
   636     
       
   637     uri += keyValues( keys, values );
       
   638 
       
   639     QUrl url(uri);
       
   640     uri = url.toEncoded();
       
   641     TX_EXIT
       
   642 }
       
   643 
       
   644 /*!
       
   645  Get Atom response from Ovi server based on query
       
   646  */
       
   647 void MpDetailsView::retrieveInformation( const QString &urlEncoded )
       
   648 {
       
   649     TX_ENTRY_ARGS( "urlEconded = " << urlEncoded)
       
   650     QNetworkReply *reply = mManager->get( QNetworkRequest( QUrl( urlEncoded ) ) );
       
   651     mReplys.append( reply );
       
   652     
       
   653     connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), this, SLOT( retrieveInformationNetworkError( QNetworkReply::NetworkError ) ) );
       
   654     connect( reply, SIGNAL( sslErrors( QList<QSslError> ) ), this, SLOT( retrieveInformationSslErrors( QList<QSslError> ) ) );
       
   655     TX_EXIT
       
   656 }
       
   657 
       
   658 
       
   659 /*!
       
   660  Slot to call when getting response
       
   661  */
       
   662 void MpDetailsView::retrieveInformationFinished( QNetworkReply* reply )
       
   663 {
       
   664     TX_ENTRY
       
   665     QString errorStr;
       
   666     int errorLine;
       
   667     int errorColumn;
       
   668     bool parsingSuccess;
       
   669     
       
   670     if ( reply->error() == QNetworkReply::NoError )
       
   671     {
       
   672         parsingSuccess = mDomDocument.setContent( reply, true, &errorStr, &errorLine, &errorColumn );
       
   673         if ( parsingSuccess ) {
       
   674             handleParsedXML();  //CodeScanner throws a warning mis-interpreting the trailing 'L' to be a leaving function.
       
   675         } else {
       
   676             // TODO: agree on error handling            
       
   677             TX_LOG_ARGS( "XML parsing error" );
       
   678         }
       
   679     }
       
   680     else
       
   681     {
       
   682     // TODO: agree on error handling
       
   683         TX_LOG_ARGS( "Network error in retrieving Information" );
       
   684     }
       
   685     TX_EXIT
       
   686 }
       
   687 
       
   688 /*!
       
   689  Slot to call when there is network error
       
   690  */
       
   691 void MpDetailsView::retrieveInformationNetworkError( QNetworkReply::NetworkError /*error*/ )
       
   692 {
       
   693     // TODO: agree on error handling
       
   694     TX_ENTRY_ARGS( "Network error for retrieving Information" );
       
   695     TX_EXIT
       
   696 }
       
   697 
       
   698 /*!
       
   699  Slot to call when there is ssl error
       
   700  */
       
   701 void MpDetailsView::retrieveInformationSslErrors( const QList<QSslError> &/*error*/ )
       
   702 {   
       
   703     // TODO: agree on error handling
       
   704     TX_ENTRY_ARGS( "SSL error for retrieving Information" );
       
   705     TX_EXIT
       
   706 }
       
   707 
       
   708 /*!
       
   709  Slot to call when downloading finished
       
   710  */
       
   711 void MpDetailsView::DownloadFinished( QNetworkReply* reply )
       
   712 {
       
   713     TX_ENTRY_ARGS( "mDownloadedAlbumArts = " << mDownloadedAlbumArts );
       
   714     if ( reply->error() == QNetworkReply::NoError )
       
   715     {
       
   716         QString fileName = mRecommendationAlbumArtsName.at( mDownloadedAlbumArts );
       
   717         TX_LOG_ARGS( "File name: " << fileName );
       
   718         QFile file(fileName);
       
   719 
       
   720         if ( fileName.isEmpty() ) {
       
   721             TX_LOG_ARGS( "Only store two album arts" );
       
   722         } else {
       
   723             if ( !file.open( QIODevice::ReadWrite ) ) {
       
   724                 TX_LOG_ARGS( "Unable to open file" );
       
   725             } else {
       
   726                 file.write( reply->readAll() );
       
   727                 file.flush();
       
   728                 file.close();
       
   729                 setAlbumArtUri( mRecommendationAlbumArtsLink.at( mDownloadedAlbumArts ), 
       
   730                                 mRecommendationAlbumArtsName.at( mDownloadedAlbumArts ) );
       
   731             }
       
   732         }
       
   733     }
       
   734     else
       
   735     {
       
   736         TX_LOG_ARGS( "Downloading album art failed!" );
       
   737     }
       
   738     
       
   739     mDownloadedAlbumArts++;
       
   740     TX_EXIT
       
   741 }
       
   742 
       
   743 /*!
       
   744  Slot to handle the recommendation album art 
       
   745 */
       
   746 void MpDetailsView::thumbnailReady(
       
   747         const QPixmap& pixmap,
       
   748         void *data,
       
   749         int /*id*/,
       
   750         int error  )
       
   751 {
       
   752     TX_ENTRY
       
   753     QString uri = *( reinterpret_cast<QString *>( data ) );
       
   754     TX_LOG_ARGS( "Uri: " << uri );
       
   755     
       
   756     if ( error == 0 ) {
       
   757         TX_LOG_ARGS( "album art link: " << uri );
       
   758         mRecommendationAlbumArtsMap.insert( uri, pixmap );
       
   759         recommendationAlbumArtReady();
       
   760     }
       
   761     else {
       
   762         mRecommendationAlbumArtsMap.insert( uri, mDefaultRecommendationAlbumArt );
       
   763         recommendationAlbumArtReady();
       
   764     }
       
   765 
       
   766     TX_EXIT
       
   767 }
       
   768 
       
   769 
       
   770 /*!
       
   771  Slot to add context to javascript
       
   772  */
       
   773 void MpDetailsView::addContext()
       
   774 {
       
   775     TX_ENTRY
       
   776     TX_EXIT
       
   777 }
       
   778 
       
   779 /*!
       
   780  Slot to close widget
       
   781  */
       
   782 void MpDetailsView::close()
       
   783 {
       
   784     TX_ENTRY
       
   785     TX_EXIT
       
   786 }
       
   787