Beispiel #1
0
void
AudioEngine::playItem( Tomahawk::playlistinterface_ptr playlist, const Tomahawk::result_ptr& result, const Tomahawk::query_ptr& fromQuery )
{
    tDebug( LOGEXTRA ) << Q_FUNC_INFO << ( result.isNull() ? QString() : result->url() );

    if ( !m_playlist.isNull() )
        m_playlist.data()->reset();

    setPlaylist( playlist );

    if ( playlist.isNull() && !fromQuery.isNull() )
        m_currentTrackPlaylist = playlistinterface_ptr( new SingleTrackPlaylistInterface( fromQuery ) );
    else
        m_currentTrackPlaylist = playlist;

    if ( !result.isNull() )
    {
        loadTrack( result );
    }
    else if ( !m_playlist.isNull() && m_playlist.data()->retryMode() == PlaylistModes::Retry )
    {
        m_waitingOnNewTrack = true;
        if ( isStopped() )
            emit sendWaitingNotification();
        else
            stop();
    }
}
Beispiel #2
0
void
M3uLoader::getTags( const QFileInfo& info )
{
    QByteArray fileName = QFile::encodeName( info.canonicalFilePath() );
    const char *encodedName = fileName.constData();

    TagLib::FileRef f( encodedName );
    TagLib::Tag *tag = f.tag();

    QString artist = TStringToQString( tag->artist() ).trimmed();
    QString album  = TStringToQString( tag->album() ).trimmed();
    QString track  = TStringToQString( tag->title() ).trimmed();

    if ( artist.isEmpty() || track.isEmpty() )
    {
        qDebug() << "Error parsing" << info.fileName();
        return;
    }
    else
    {
        qDebug() << Q_FUNC_INFO << artist << track << album;
        Tomahawk::query_ptr q = Tomahawk::Query::get( artist, track, album, uuid(), !m_createNewPlaylist );
        if ( !q.isNull() )
            m_tracks << q;
    }
}
PipelineStatusItem::PipelineStatusItem( const Tomahawk::query_ptr& q )
    : JobStatusItem()
{
    connect( Tomahawk::Pipeline::instance(), SIGNAL( resolving( Tomahawk::query_ptr ) ), this, SLOT( resolving( Tomahawk::query_ptr ) ) );
    connect( Tomahawk::Pipeline::instance(), SIGNAL( idle() ), this, SLOT( idle() ) );

    if ( !q.isNull() )
        resolving( q );
}
Beispiel #4
0
void
PlaylistModel::append( const Tomahawk::query_ptr& query )
{
    if ( query.isNull() )
        return;

    if ( !query->resolvingFinished() )
        Pipeline::instance()->resolve( query );

    TrackModel::append( query );
}
Beispiel #5
0
void
TrackModel::insert( const Tomahawk::query_ptr& query, int row )
{
    if ( query.isNull() )
        return;

    QList< Tomahawk::query_ptr > ql;
    ql << query;

    insert( ql, row );
}
Beispiel #6
0
void
SourceTreeView::dropEvent( QDropEvent* event )
{
    bool accept = false;
    const QPoint pos = event->pos();
    const QModelIndex index = indexAt( pos );

    if ( event->mimeData()->hasFormat( "application/tomahawk.query.list" ) )
    {
        const QPoint pos = event->pos();
        const QModelIndex index = indexAt( pos );

        if ( index.isValid() )
        {
            if ( SourcesModel::indexType( index ) == SourcesModel::PlaylistSource )
            {
                playlist_ptr playlist = SourcesModel::indexToPlaylist( index );
                if ( !playlist.isNull() && playlist->author()->isLocal() )
                {
                    accept = true;
                    QByteArray itemData = event->mimeData()->data( "application/tomahawk.query.list" );
                    QDataStream stream( &itemData, QIODevice::ReadOnly );
                    QList<Tomahawk::query_ptr> queries;

                    while ( !stream.atEnd() )
                    {
                        qlonglong qptr;
                        stream >> qptr;

                        Tomahawk::query_ptr* query = reinterpret_cast<Tomahawk::query_ptr*>(qptr);
                        if ( query && !query->isNull() )
                        {
                            qDebug() << "Dropped query item:" << query->data()->artist() << "-" << query->data()->track();
                            queries << *query;
                        }
                    }

                    qDebug() << "on playlist:" << playlist->title() << playlist->guid();

                    SourceTreeItem* treeItem = SourcesModel::indexToTreeItem( index );
                    if ( treeItem )
                    {
                        QString rev = treeItem->currentlyLoadedPlaylistRevision( playlist->guid() );
                        playlist->addEntries( queries, rev );
                    }
                }
            }
        }
Beispiel #7
0
void
QueryLabel::setQuery( const Tomahawk::query_ptr& query )
{
    if ( query.isNull() )
        return;

    setContentsMargins( BOXMARGIN * 2, BOXMARGIN / 2, BOXMARGIN * 2, BOXMARGIN / 2 );

    if ( m_query.isNull() || m_query.data() != query.data() )
    {
        m_query = query;
        m_result.clear();
        updateLabel();

        emit textChanged( text() );
        emit queryChanged( m_query );
    }
}
Beispiel #8
0
void
MetadataEditor::loadQuery( const Tomahawk::query_ptr& query )
{
    if ( query.isNull() )
        return;

    if ( query->numResults() )
    {
        loadResult( query->results().first() );
        return;
    }

    m_result = Tomahawk::result_ptr();
    m_query = query;
    setEditable( false );

    setTitle( query->track()->track() );
    setArtist( query->track()->artist() );
    setAlbum( query->track()->album() );
    setAlbumPos( query->track()->albumpos() );
    setDuration( query->track()->duration() );
    setYear( 0 );
    setBitrate( 0 );

    setFileName( QString() );
    setFileSize( 0 );

    setWindowTitle( query->track()->track() );

    if ( m_interface )
    {
        m_index = m_interface->indexOfQuery( query );

        if ( m_index >= 0 )
            enablePushButtons();
    }
}
void
DatabaseCommand_LoadPlaylistEntries::generateEntries( DatabaseImpl* dbi )
{
    TomahawkSqlQuery query_entries = dbi->newquery();
    query_entries.prepare( "SELECT entries, playlist, author, timestamp, previous_revision "
                           "FROM playlist_revision "
                           "WHERE guid = :guid" );
    query_entries.bindValue( ":guid", m_revguid );
    query_entries.exec();

    tLog( LOGVERBOSE ) << "trying to load playlist entries for guid:" << m_revguid;
    QString prevrev;
    bool ok;

    if ( query_entries.next() )
    {
        if ( !query_entries.value( 0 ).isNull() )
        {
            // entries should be a list of strings:
            QVariant v = TomahawkUtils::parseJson( query_entries.value( 0 ).toByteArray(), &ok );
            Q_ASSERT( ok && v.type() == QVariant::List ); //TODO

            m_guids = v.toStringList();
            QString inclause = QString( "('%1')" ).arg( m_guids.join( "', '" ) );

            TomahawkSqlQuery query = dbi->newquery();
            QString sql = QString( "SELECT guid, trackname, artistname, albumname, annotation, "
                                "duration, addedon, addedby, result_hint "
                                "FROM playlist_item "
                                "WHERE guid IN %1" ).arg( inclause );

            query.exec( sql );
            while ( query.next() )
            {
                plentry_ptr e( new PlaylistEntry );
                e->setGuid( query.value( 0 ).toString() );
                e->setAnnotation( query.value( 4 ).toString() );
                e->setDuration( query.value( 5 ).toUInt() );
                e->setLastmodified( 0 ); // TODO e->lastmodified = query.value( 6 ).toInt();
                const QString resultHint = query.value( 8 ).toString();
                e->setResultHint( resultHint );

                Tomahawk::query_ptr q = Tomahawk::Query::get( query.value( 2 ).toString(), query.value( 1 ).toString(), query.value( 3 ).toString() );
                if ( q.isNull() )
                    continue;

                q->setResultHint( resultHint );
                if ( resultHint.startsWith( "http" ) )
                    q->setSaveHTTPResultHint( true );

                q->setProperty( "annotation", e->annotation() );
                e->setQuery( q );

                m_entrymap.insert( e->guid(), e );
            }
        }

        prevrev = query_entries.value( 4 ).toString();
    }
    else
    {
//        qDebug() << "Playlist has no current revision data";
    }

    if ( prevrev.length() )
    {
        TomahawkSqlQuery query_entries_old = dbi->newquery();
        query_entries_old.prepare( "SELECT entries, "
                                   "(SELECT currentrevision = ? FROM playlist WHERE guid = ?) "
                                   "FROM playlist_revision "
                                   "WHERE guid = ?" );
        query_entries_old.addBindValue( m_revguid );
        query_entries_old.addBindValue( query_entries.value( 1 ).toString() );
        query_entries_old.addBindValue( prevrev );

        query_entries_old.exec();
        if ( !query_entries_old.next() )
        {
            return;
            Q_ASSERT( false );
        }

        if ( !query_entries_old.value( 0 ).isNull() )
        {
            QVariant v = TomahawkUtils::parseJson( query_entries_old.value( 0 ).toByteArray(), &ok );
            Q_ASSERT( ok && v.type() == QVariant::List ); //TODO
            m_oldentries = v.toStringList();
        }
        m_islatest = query_entries_old.value( 1 ).toBool();
    }

//    qDebug() << Q_FUNC_INFO << "entrymap:" << m_entrymap;
}