/*!
 \internal
 */
void MpLightMonitorPrivate::init()
{
    TX_ENTRY
    TRAPD(err, DoInitL());
    if ( err != KErrNone ) {
        TX_LOG_ARGS("Error: " << err << "; should never get here.");
    }
    TX_EXIT
}
void KeyCaptureTestApp::addTextLine(QString aText)
{
    TX_ENTRY
    TX_LOG_ARGS( QString("aText=%1").arg(aText));
	if ( !aText.endsWith("\n"))
		aText = aText + "\n";
	QString msg = mTextArea->toPlainText();
	msg = aText + msg;
	mTextArea->setPlainText(msg);
	TX_EXIT
}
/*!
 Returns the data stored for the item referred to by the \a index.

 \reimp
 */
QVariant MpCollectionTBoneListDataModel::data(const QModelIndex &index, int role) const
{
    TX_ENTRY
    QVariant returnValue = QVariant();
    if ( !index.isValid() ) {
        return returnValue;
    }

    int row = index.row();
    TX_LOG_ARGS("index=" << row << ", role=" << role);
    if ( role == Qt::DisplayRole ) {
        // Fetch the primary text, which is the title, if available.
        QString songTitle = mCollectionData->albumSongData(row, MpMpxCollectionData::Title);
        if ( !songTitle.isEmpty() ) {
            returnValue = songTitle;
        }
        else {
            returnValue = hbTrId("txt_mus_other_unknown4");
        }
    }
    else if ( role == Qt::DecorationRole ) {
        if ( mCollectionData->hasAlbumSongProperty(row, MpMpxCollectionData::Corrupted) ) {
                QList<QVariant> iconList;
                iconList << QVariant();
                iconList << HbIcon("qtg_mono_corrupted");
                returnValue = iconList;
        }
        else if ( mCollectionData->hasAlbumSongProperty(row, MpMpxCollectionData::DrmExpired) ) {
            QList<QVariant> iconList;
            iconList << QVariant();
            iconList << HbIcon("qtg_small_drm_rights_expired");
            returnValue = iconList;
        }
        else if ( mPlaybackActive && mPlaybackIndicatorEnabled
                && mPlaybackData->id() == mCollectionData->albumSongId( row ) ) {
            QList<QVariant> iconList;
            iconList << QVariant(); //primary icon is not used.
            if ( mPlaybackData->playbackState() == MpPlaybackData::Playing ) {
                iconList << HbIcon("qtg_mono_play");
            }
            else {
                iconList << HbIcon("qtg_mono_pause");
            }
            returnValue = iconList;
        }
    }
    TX_EXIT
    return returnValue;
}
/*!
 Returns the data stored for the item referred to by the \a index.

 \reimp
 */
QVariant MpCollectionDataModel::data(const QModelIndex &index, int role) const
{
    TX_ENTRY
    QVariant returnValue = QVariant();
    if ( !index.isValid() ) {
        return returnValue;
    }

    int row = index.row() + mAlbumIndexOffset;
    TX_LOG_ARGS("index=" << row << ", role=" << role);
    TCollectionContext context = mCollectionData->context();
    if ( role == Qt::DisplayRole ) {
        QStringList display;
        // Fetch the primary text, which is the title, if available.
        QString primaryText;
        switch ( context ) {
            case ECollectionContextAllSongs:
            case ECollectionContextArtists:
            case ECollectionContextAlbums:
            case ECollectionContextArtistAlbums:
            case ECollectionContextPlaylists:
            case ECollectionContextPlaylistSongs:
            case ECollectionContextAlbumsTBone:
            case ECollectionContextArtistAlbumsTBone:
            case ECollectionContextArtistAllSongs:
                primaryText = mCollectionData->itemData(row, MpMpxCollectionData::Title);
                if ( !primaryText.isEmpty() ) {
                    display << primaryText;
                }
                else {
                    switch ( context ) {
                        case ECollectionContextArtists:
                            display << hbTrId("txt_mus_list_unknown");
                            break;
                        case ECollectionContextArtistAlbums:
                        case ECollectionContextAlbums:
                            display << hbTrId("txt_mus_dblist_unknown");
                            break;
                        case ECollectionContextAlbumsTBone:
                        case ECollectionContextArtistAlbumsTBone:
                            display << hbTrId("txt_mus_other_unknown8");
                            break;
                        default:
                            // Otherwise the primary text should be the Song Title or File Name
                            // but can not be empty, if so there is an error.
                            TX_LOG_ARGS("Error: Song title empty.");
                            break;
                    }
                }
                break;
            case ECollectionContextAlbumsMediaWall:
                primaryText = mCollectionData->itemData(row, MpMpxCollectionData::Artist);
                if ( !primaryText.isEmpty() ) {
                    display << primaryText;
                }
                else {
                    display << hbTrId("txt_mus_other_unknown2");
                }    
                break;
            default:
                break;
        }
        
        // Fetch the secondary text, which depends on the current context, if available.
        QString secondaryText;
        switch ( context ) {
            case ECollectionContextAllSongs:
            case ECollectionContextAlbums:
            case ECollectionContextPlaylistSongs:
            case ECollectionContextAlbumsTBone:
                secondaryText = mCollectionData->itemData(row, MpMpxCollectionData::Artist);
                if ( !secondaryText.isEmpty() ) {
                    display << secondaryText;
                }
                else {
                    switch ( context ) {
                        case ECollectionContextAllSongs:
                        case ECollectionContextPlaylistSongs:
                            if ( mCollectionLayout == ECollectionSelectionDialog ) {
                                display << hbTrId("txt_mus_dblist_val_unknown4");
                            }
                            else if ( mCollectionLayout == ECollectionArrangeSongsDialog ) {
                                display << hbTrId("txt_mus_other_unknown9");
                            }
                            else {
                                display << hbTrId("txt_mus_dblist_val_unknown");
                            }
                            break;
                        case ECollectionContextAlbums:
                            display << hbTrId("txt_mus_dblist_val_unknown2");
                            break;
                        case ECollectionContextAlbumsTBone:
                            display << hbTrId("txt_mus_other_unknown5");
                            break;
                    }
                }
                break;
            case ECollectionContextArtistAlbumsTBone:
                secondaryText = mCollectionData->collectionTitle();
                if ( !secondaryText.isEmpty() ) {
                    display << secondaryText;
                }
                else {
                    display << hbTrId("txt_mus_other_unknown5");
                }
                break;
            case ECollectionContextArtistAllSongs:
                secondaryText = mCollectionData->itemData(row, MpMpxCollectionData::Album);
                if ( !secondaryText.isEmpty() ) {
                    display << secondaryText;
                }
                else {
                    display << hbTrId("txt_mus_dblist_val_unknown3");
                }
                break;
            case ECollectionContextAlbumsMediaWall:
                secondaryText = mCollectionData->itemData(row, MpMpxCollectionData::Title);
                if ( !secondaryText.isEmpty() ) {
                    display << secondaryText;
                }
                else {
                    display << hbTrId("txt_mus_other_unknown1");
                }
                break;
            default:
                break;
        }
        returnValue = display;
    }
    else if ( role == Qt::DecorationRole ) {
        switch ( context ) {
            case ECollectionContextAlbums:
            case ECollectionContextAlbumsMediaWall:
            case ECollectionContextArtistAlbumsTBone:
            case ECollectionContextAlbumsTBone:
                    returnValue = mAlbumArtManager->albumArt( row ) ;
                break;
            case ECollectionContextArtistAlbums:
                if ( row == 0 ) {
                    returnValue = HbIcon( "qtg_small_sound" );
                }
                else {
                    returnValue = mAlbumArtManager->albumArt( row );
                }
                break;
            case ECollectionContextAllSongs:
            case ECollectionContextArtistAllSongs:
            case ECollectionContextPlaylistSongs:
                if( mCollectionData->hasItemProperty(row, MpMpxCollectionData::Corrupted) ){
					QList<QVariant> iconList;
                    iconList << QVariant();
                    iconList << HbIcon("qtg_mono_corrupted");
                    returnValue = iconList;
                }
                else if ( mCollectionData->hasItemProperty(row, MpMpxCollectionData::DrmExpired) ) {
                    QList<QVariant> iconList;
                    iconList << QVariant();
                    iconList << HbIcon("qtg_small_drm_rights_expired");
                    returnValue = iconList;
                } 
                break;
            default:
                break;
        }
    }
    else if ( role == Hb::IndexFeedbackRole ) {
        QString feedbackIndex;
        switch ( context ) {
            case ECollectionContextAllSongs:
            case ECollectionContextArtists:
            case ECollectionContextAlbums:
            case ECollectionContextArtistAlbums:
            case ECollectionContextPlaylists:
            case ECollectionContextPlaylistSongs:
            case ECollectionContextAlbumsTBone:
            case ECollectionContextArtistAlbumsTBone:
            case ECollectionContextArtistAllSongs:
                feedbackIndex = mCollectionData->itemData(row, MpMpxCollectionData::Title);
                break;
            case ECollectionContextAlbumsMediaWall:
                feedbackIndex = mCollectionData->itemData(row, MpMpxCollectionData::Artist);
                break;
            default:
                break;
        }
        returnValue = feedbackIndex;
    }
    else if ( role == HgWidget::HgVisibilityRole 
        && context == ECollectionContextAlbumsMediaWall) {
        returnValue = !( row == mHiddenItemIndex );
        }
    TX_EXIT
    return returnValue;
}
void MpSongData::setMpxMedia( const CMPXMedia& aMedia )
{
    TX_LOG_ARGS("Stub")
    Q_UNUSED( aMedia );
    iSetMedia = true;
}
*/

#include <mpxmedia.h>
#include "stub/inc/mpsongdata.h"
#include "mptrace.h"

/*!
 Stub function.
*/
MpSongData::MpSongData( QObject *parent )
    : QObject( parent ),
      iSetMedia( false )
{
    TX_LOG_ARGS("Stub")
}

/*!
 Stub function.
*/
MpSongData::~MpSongData()
{
    TX_LOG_ARGS("Stub")
}

void MpSongData::setMpxMedia( const CMPXMedia& aMedia )
{
    TX_LOG_ARGS("Stub")
    Q_UNUSED( aMedia );
    iSetMedia = true;
}
/*!
 \internal
 Constructs the now playing widget private.
 */
MpNowPlayingWidgetPrivate::MpNowPlayingWidgetPrivate( MpNowPlayingWidget *qq )
    : q_ptr( qq ),
      mPrimaryText(0),
      mSecondaryText(0),
      mState( MpPlaybackData::NotPlaying ),
      mPlaybackData(0),
      mMpEngine(0),
      mIcon(0),
      mDocumentLoader(0),
      mCurrentPressedState( BannerNone )
{
    TX_ENTRY_ARGS( " Q pointer=" << ( void * )qq )
    QGraphicsWidget *widget;
    bool widgetsOk = false;
    
    HbStyleLoader::registerFilePath(NOW_PLAYING_CSS);  
    
    mPlayIcon = new HbIcon( QString( "qtg_mono_play" ) );
    mPauseIcon = new HbIcon( QString( "qtg_mono_pause" ) );

    mDocumentLoader = new HbDocumentLoader();
    if (mDocumentLoader) {
            mDocumentLoader->load( NOW_PLAYING_XML, &widgetsOk);
    }

    if (widgetsOk) {

        // find the main widget container and all of its child items
        widget = mDocumentLoader->findWidget(QString("nowPlayingContainer"));
        HbWidget* container = qobject_cast<HbWidget*>(widget);
        container->setParentItem(q_ptr);

        widget = mDocumentLoader->findWidget(QString("primaryText"));
        mPrimaryText = qobject_cast<HbLabel*>(widget);
        mPrimaryText->setObjectName( "bannerLabel" );
        mPrimaryText->setProperty( "state", "normal" );
        

        widget = mDocumentLoader->findWidget(QString("secondaryText"));
        mSecondaryText = qobject_cast<HbLabel*>(widget);
        mSecondaryText->setObjectName( "bannerLabel" );
        mSecondaryText->setProperty( "state", "normal" );
        
        
        widget = mDocumentLoader->findWidget(QString("playPause"));
        mIcon = qobject_cast<HbLabel*>(widget);
        mIcon->setObjectName( "bannerLabel" );
        mIcon->setProperty( "state", "normal" );
        
        HbStackedLayout *mylayout;
        mylayout = new HbStackedLayout(q_ptr);
        mylayout->addItem( container );

        q_ptr->setLayout( mylayout );
    }
    else {
        TX_LOG_ARGS("Error: invalid xml file.");
        Q_ASSERT_X(widgetsOk, "MpNowPlayingWidgetPrivate", "invalid xml file");
    }

    mMpEngine = MpEngineFactory::sharedEngine();
    mPlaybackData = mMpEngine->playbackData();
    setEnabled(true);
    TX_EXIT
}