Exemplo n.º 1
0
StreamConnection::StreamConnection( Servent* s, ControlConnection* cc, QString fid, const Tomahawk::result_ptr& result )
    : Connection( s )
    , m_cc( cc )
    , m_fid( fid )
    , m_type( RECEIVING )
    , m_curBlock( 0 )
    , m_badded( 0 )
    , m_bsent( 0 )
    , m_allok( false )
    , m_result( result )
    , m_transferRate( 0 )
{
    qDebug() << Q_FUNC_INFO;

    BufferIODevice* bio = new BufferIODevice( result->size() );
    m_iodev = QSharedPointer<QIODevice>( bio, &QObject::deleteLater ); // device audio data gets written to
    m_iodev->open( QIODevice::ReadWrite );

    Servent::instance()->registerStreamConnection( this );

    // if the audioengine closes the iodev (skip/stop/etc) then kill the connection
    // immediately to avoid unnecessary network transfer
    connect( m_iodev.data(), SIGNAL( aboutToClose() ), SLOT( shutdown() ), Qt::QueuedConnection );
    connect( m_iodev.data(), SIGNAL( blockRequest( int ) ), SLOT( onBlockRequest( int ) ) );

    // auto delete when connection closes:
    connect( this, SIGNAL( finished() ), SLOT( deleteLater() ), Qt::QueuedConnection );

    // don't f**k with our messages at all. No compression, no parsing, nothing:
    this->setMsgProcessorModeIn ( MsgProcessor::NOTHING );
    this->setMsgProcessorModeOut( MsgProcessor::NOTHING );
}
Exemplo n.º 2
0
bool
PlayableProxyModel::lessThan( int column, const Tomahawk::query_ptr& q1, const Tomahawk::query_ptr& q2 ) const
{
    // Attention: This function may be called very often!
    // So be aware of its performance.
    const Tomahawk::track_ptr& t1 = q1->track();
    const Tomahawk::track_ptr& t2 = q2->track();
    const QString& artist1 = t1->artistSortname();
    const QString& artist2 = t2->artistSortname();
    const QString& album1 = t1->albumSortname();
    const QString& album2 = t2->albumSortname();
    const unsigned int albumpos1 = t1->albumpos();
    const unsigned int albumpos2 = t2->albumpos();
    const unsigned int discnumber1 = t1->discnumber();
    const unsigned int discnumber2 = t2->discnumber();
    const qint64 id1 = (qint64)&q1;
    const qint64 id2 = (qint64)&q2;

    if ( column == PlayableModel::Artist ) // sort by artist
    {
        if ( artist1 == artist2 )
        {
            if ( album1 == album2 )
            {
                if ( discnumber1 == discnumber2 )
                {
                    if ( albumpos1 == albumpos2 )
                        return id1 < id2;

                    return albumpos1 < albumpos2;
                }

                return discnumber1 < discnumber2;
            }

            return QString::localeAwareCompare( album1, album2 ) < 0;
        }

        return QString::localeAwareCompare( artist1, artist2 ) < 0;
    }

    // Sort by Composer
    const QString& composer1 = t1->composerSortname();
    const QString& composer2 = t2->composerSortname();
    if ( column == PlayableModel::Composer )
    {
        if ( composer1 == composer2 )
        {
            if ( album1 == album2 )
            {
                if ( discnumber1 == discnumber2 )
                {
                    if ( albumpos1 == albumpos2 )
                        return id1 < id2;

                    return albumpos1 < albumpos2;
                }

                return discnumber1 < discnumber2;
            }

            return QString::localeAwareCompare( album1, album2 ) < 0;
        }

        return QString::localeAwareCompare( composer1, composer2 ) < 0;
    }

    // Sort by Album
    if ( column == PlayableModel::Album ) // sort by album
    {
        if ( album1 == album2 )
        {
            if ( discnumber1 == discnumber2 )
            {
                if ( albumpos1 == albumpos2 )
                    return id1 < id2;

                return albumpos1 < albumpos2;
            }

            return discnumber1 < discnumber2;
        }

        return QString::localeAwareCompare( album1, album2 ) < 0;
    }

    // Lazy load these variables, they are not used before.
    unsigned int bitrate1 = 0, bitrate2 = 0;
    unsigned int mtime1 = 0, mtime2 = 0;
    unsigned int size1 = 0, size2 = 0;
    unsigned int year1 = 0, year2 = 0;
    float score1 = 0, score2 = 0;
    QString origin1;
    QString origin2;
    if ( !q1->results().isEmpty() )
    {
        Tomahawk::result_ptr r = q1->results().first();
        bitrate1 = r->bitrate();
        mtime1 = r->modificationTime();
        size1 = r->size();
        year1 = r->track()->year();
        score1 = q1->score();
        origin1 = r->friendlySource().toLower();
    }
    if ( !q2->results().isEmpty() )
    {
        Tomahawk::result_ptr r = q2->results().first();
        bitrate2 = r->bitrate();
        mtime2 = r->modificationTime();
        size2 = r->size();
        year2 = r->track()->year();
        score2 = q2->score();
        origin2 = r->friendlySource().toLower();
    }

    // Sort by bitrate
    if ( column == PlayableModel::Bitrate )
    {
        if ( bitrate1 == bitrate2 )
            return id1 < id2;

        return bitrate1 < bitrate2;
    }
    else if ( column == PlayableModel::Duration ) // sort by duration
    {
        unsigned int duration1 = t1->duration();
        unsigned int duration2 = t2->duration();

        if ( duration1 == duration2 )
            return id1 < id2;

        return duration1 < duration2;
    }
    else if ( column == PlayableModel::Age ) // sort by mtime
    {
        if ( mtime1 == mtime2 )
            return id1 < id2;

        return mtime1 < mtime2;
    }
    else if ( column == PlayableModel::Year ) // sort by release year
    {
        if ( year1 == year2 )
            return id1 < id2;

        return year1 < year2;
    }
    else if ( column == PlayableModel::Filesize ) // sort by file size
    {
        if ( size1 == size2 )
            return id1 < id2;

        return size1 < size2;
    }
    else if ( column == PlayableModel::Score ) // sort by file score
    {
        if ( score1 == score2 )
            return id1 < id2;

        return score1 < score2;
    }
    else if ( column == PlayableModel::Origin ) // sort by file origin
    {
        if ( origin1 == origin2 )
            return id1 < id2;

        return origin1 < origin2;
    }
    else if ( column == PlayableModel::AlbumPos ) // sort by album pos
    {
        if ( discnumber1 != discnumber2 )
        {
            return discnumber1 < discnumber2;
        }
        else
        {
            if ( albumpos1 != albumpos2 )
                return albumpos1 < albumpos2;
        }
    }

    const QString& lefts = t1->track();
    const QString& rights = t2->track();
    if ( lefts == rights )
        return id1 < id2;

    return QString::localeAwareCompare( lefts, rights ) < 0;
}