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