Example #1
0
void
AmazonStore::itemDoubleClicked( QModelIndex index )
{
    // for albums: search for the album ASIN to get details about it
    // for tracks: add it to the playlist

    int id = m_itemModel->idForIndex( index );

    if( m_itemModel->isAlbum( index ) ) // album
    {
        Meta::AmazonAlbum* album;
        album = dynamic_cast<Meta::AmazonAlbum*>( m_collection->albumById( id ).data() );

        if( !album )
            return;

        m_searchWidget->setSearchString( "asin:" + album->asin() );
    }
    else // track
    {
        Meta::AmazonTrack* track;
        track = dynamic_cast<Meta::AmazonTrack*>( m_collection->trackById( id ).data() );

        if( !track )
            return;

        Meta::TrackPtr trackPtr( track );

        The::playlistController()->instance()->insertOptioned( trackPtr, Playlist::OnDoubleClickOnSelectedItems );
    }
}
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 );
}
Example #3
0
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 );
}