void TestAmazonMetaFactory::testCreateAlbum() { QStringList list, list2; list << "id" << "name" << "description" << "artistID" << "price" << "coverUrl" << "ASIN"; list2 << "23" << "name" << "description" << "42" << "price" << "coverUrl" << "ASIN"; AmazonMetaFactory factory( "Amazontest" ); Meta::AlbumPtr albumPtr = factory.createAlbum( list ); Meta::AlbumPtr albumPtr2 = factory.createAlbum( list2 ); QVERIFY( albumPtr ); QVERIFY( albumPtr2 ); Meta::AmazonAlbum* amazonAlbum = dynamic_cast<Meta::AmazonAlbum*>( albumPtr.data() ); Meta::AmazonAlbum* amazonAlbum2 = dynamic_cast<Meta::AmazonAlbum*>( albumPtr2.data() ); QVERIFY( amazonAlbum ); QVERIFY( amazonAlbum2 ); QCOMPARE( amazonAlbum->id(), 0 ); QCOMPARE( amazonAlbum->name(), QString( "name" ) ); QCOMPARE( amazonAlbum->description(), QString( "description" ) ); QCOMPARE( amazonAlbum->artistId(), 0 ); QCOMPARE( amazonAlbum->price(), QString( "price" ) ); QCOMPARE( amazonAlbum->coverUrl(), QString( "coverUrl" ) ); QCOMPARE( amazonAlbum->asin(), QString( "ASIN" ) ); QCOMPARE( amazonAlbum2->id(), 23 ); QCOMPARE( amazonAlbum2->artistId(), 42 ); }
void AmazonStore::addToCart() { QString asin, name, price; int id = m_itemModel->idForIndex( m_selectedIndex );; // get item from collection if( m_itemModel->isAlbum( m_selectedIndex ) ) // album { Meta::AmazonAlbum* album; album = dynamic_cast<Meta::AmazonAlbum*>( m_collection->albumById( id ).data() ); if( !album ) return; name = m_collection->artistById( album->artistId() )->name() + " - " + album->name(); asin = album->asin(); price = album->price(); } else // track { Meta::AmazonTrack* track; track = dynamic_cast<Meta::AmazonTrack*>( m_collection->trackById( id ).data() ); if( !track ) return; name = m_collection->artistById( track->artistId() )->name() + " - " + track->name(); asin = track->asin(); price = track->price(); } AmazonShoppingCart::instance()->add( asin, price, name ); m_checkoutButton->setEnabled( true ); }
QVariant AmazonItemTreeModel::data( const QModelIndex &index, int role ) const { if( !index.isValid() ) return QVariant(); int id; if( role == Qt::DisplayRole ) // text { if( index.row() < m_collection->albumIDMap().size() - m_hiddenAlbums ) // we have to take data from the album map { id = index.row() + 1; // collection IDs start with 1 if( index.column() == 0 ) // name return prettyNameByIndex( index ); else if( index.column() == 1 ) // price { if( m_collection->albumById( id ) ) return Amazon::prettyPrice( dynamic_cast<Meta::AmazonAlbum*>( m_collection->albumById( id ).data() )->price() ); } } else // track map { if( index.column() == 0 ) // name return prettyNameByIndex( index ); else if( index.column() == 1 ) // price { id = index.row() - m_collection->albumIDMap().size() + 1 + m_hiddenAlbums; if( m_collection->trackById( id ) ) return Amazon::prettyPrice( dynamic_cast<Meta::AmazonTrack*>( m_collection->trackById( id ).data() )->price() ); } } } else if( role == Qt::DecorationRole ) // icon { if( index.row() < m_collection->albumIDMap().size() - m_hiddenAlbums ) // album { if( index.column() == 0 ) return KIcon( "media-optical-amarok" ); } else // track { if( index.column() == 0 ) return KIcon( "media-album-track" ); } } else if( role == Qt::ToolTipRole ) { // TODO: maybe we could also show the cover here QString toolTip; toolTip = "<center><b>" + prettyNameByIndex( index ) + "</b></center><br/>"; if( isAlbum( index ) ) { id = index.row() + 1; Meta::AmazonAlbum* album; album = dynamic_cast<Meta::AmazonAlbum*>( m_collection->albumById( id ).data() ); if( !album ) return QString(); toolTip += i18n( "<b>Artist:</b> " ); toolTip += m_collection->artistById( album->artistId() )->name(); toolTip += "<br/>"; toolTip += i18n( "<b>Album:</b> " ); toolTip += album->name(); toolTip += "<br/>"; toolTip += i18n( "<b>Price:</b> " ); toolTip += Amazon::prettyPrice( album->price() ); } else // track { id = index.row() - m_collection->albumIDMap().size() + 1 + m_hiddenAlbums; Meta::AmazonTrack* track; track = dynamic_cast<Meta::AmazonTrack*>( m_collection->trackById( id ).data() ); if( !track ) return QString(); toolTip += i18n( "<b>Artist:</b> " ); toolTip += m_collection->artistById( track->artistId() )->name(); toolTip += "<br/>"; toolTip += i18n( "<b>Album:</b> " ); toolTip += m_collection->albumById( track->albumId() )->name(); toolTip += "<br/>"; toolTip += i18n( "<b>Track:</b> " ); toolTip += track->name(); toolTip += "<br/>"; toolTip += i18n( "<b>Price:</b> " ); toolTip += Amazon::prettyPrice( track->price() ); } return toolTip; } return QVariant(); }