void TestAmazonMetaFactory::testCreateTrack() { QStringList list, list2; list << "id" << "name" << "trackNumber" << "length" << "playableUrl" << "albumId" << "artistId" << "price" << "ASIN"; list2 << "23" << "name" << "5" << "300" << "http://www.amazon.de/gp/dmusic/get_sample_url.html?ASIN=B007NV28OK" << "42" << "12" << "99" << "B007NV28OK"; AmazonMetaFactory factory( "Amazontest" ); Meta::TrackPtr trackPtr = factory.createTrack( list ); Meta::TrackPtr trackPtr2 = factory.createTrack( list2 ); QVERIFY( trackPtr ); QVERIFY( trackPtr2 ); Meta::AmazonTrack* amazonTrack = dynamic_cast<Meta::AmazonTrack*>( trackPtr.data() ); Meta::AmazonTrack* amazonTrack2 = dynamic_cast<Meta::AmazonTrack*>( trackPtr2.data() ); QVERIFY( amazonTrack ); QVERIFY( amazonTrack2 ); QCOMPARE( amazonTrack->id(), 0 ); QCOMPARE( amazonTrack->name(), QString( "name" ) ); QCOMPARE( amazonTrack->trackNumber(), 0 ); QCOMPARE( amazonTrack->length(), (qint64)0 ); QCOMPARE( amazonTrack->playableUrl(), KUrl( "playableUrl" ) ); QCOMPARE( amazonTrack->albumId(), 0 ); QCOMPARE( amazonTrack->artistId(), 0 ); QCOMPARE( amazonTrack->price(), QString( "price" ) ); QCOMPARE( amazonTrack->asin(), QString( "ASIN" ) ); QCOMPARE( amazonTrack2->id(), 23 ); QCOMPARE( amazonTrack2->trackNumber(), 5 ); QCOMPARE( amazonTrack2->length(), (qint64)300 ); QCOMPARE( amazonTrack2->playableUrl(), KUrl( "http://www.amazon.de/gp/dmusic/get_sample_url.html?ASIN=B007NV28OK" ) ); QCOMPARE( amazonTrack2->albumId(), 42 ); QCOMPARE( amazonTrack2->artistId(), 12 ); QCOMPARE( amazonTrack2->price(), QString( "99" ) ); QCOMPARE( amazonTrack2->asin(), QString( "B007NV28OK" ) ); }
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(); }