Changeset 10771


Ignore:
Timestamp:
Jun 16, 2010, 3:02:17 AM (12 years ago)
Author:
Longinus00
Message:

(qt) #3277: Crash after getting magnet torrent metadata

Location:
trunk/qt
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/details.cc

    r10721 r10771  
    208208{
    209209    if( !myIds.empty( ) )
     210    {
     211        QSet<int> infos;
     212        foreach( int id, myIds ) {
     213            const Torrent * tor = myModel.getTorrentFromId( id );
     214            if( tor->isMagnet() )
     215                infos.insert( tor->id() );
     216        }
     217        if( !infos.isEmpty() )
     218            mySession.initTorrents( infos );
    210219        mySession.refreshExtraStats( myIds );
     220    }
    211221}
    212222
  • trunk/qt/torrent-delegate-min.cc

    r9890 r10771  
    5353    QFont nameFont( option.font );
    5454    const QFontMetrics nameFM( nameFont );
    55     const QString nameStr( tor.name( ) );
     55    const bool isMagnet( !tor.hasMetadata( ) );
     56    const QString nameStr = (isMagnet ? progressString( tor ) : tor.name( ) );
    5657    const QSize nameSize( nameFM.size( 0, nameStr ) );
    5758
     
    7778    QFont nameFont( option.font );
    7879    const QFontMetrics nameFM( nameFont );
    79     const QString nameStr( tor.name( ) );
     80    const bool isMagnet( !tor.hasMetadata( ) );
     81    const QString nameStr = (isMagnet ? progressString( tor ) : tor.name( ) );
    8082    const QSize nameSize( nameFM.size( 0, nameStr ) );
    8183
     
    154156    myProgressBarStyle->palette.setCurrentColorGroup( cg );
    155157    myProgressBarStyle->state = progressBarState;
    156     myProgressBarStyle->progress = int(myProgressBarStyle->minimum + ((tor.percentDone() * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
     158    myProgressBarStyle->progress = int(myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() : tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
    157159    style->drawControl( QStyle::CE_ProgressBar, myProgressBarStyle, painter );
    158160
  • trunk/qt/torrent-delegate.cc

    r10713 r10771  
    6363TorrentDelegate :: progressString( const Torrent& tor ) const
    6464{
     65    const bool isMagnet( !tor.hasMetadata( ) );
    6566    const bool isDone( tor.isDone( ) );
    6667    const bool isSeed( tor.isSeed( ) );
     
    7071    const bool hasSeedRatio( tor.getSeedRatio( seedRatio ) );
    7172
    72     if( !isDone ) // downloading
     73    if( isMagnet ) // magnet link with no metadata
     74    {
     75        /* %1 is the percentage of torrent metadata downloaded */
     76        str = tr( "Magnetized transfer - retrieving metadata ( %1% )" )
     77            .arg( tor.metadataPercentDone() );
     78    }
     79    else if( !isDone ) // downloading
    7380    {
    7481        /* %1 is how much we've got,
     
    387394    painter->setFont( progressFont );
    388395    painter->drawText( progArea, 0, progressFM.elidedText( progressStr, Qt::ElideRight, progArea.width( ) ) );
     396    const bool isMagnet( !tor.hasMetadata( ) );
    389397    myProgressBarStyle->rect = barArea;
    390398    myProgressBarStyle->direction = option.direction;
     
    392400    myProgressBarStyle->palette.setCurrentColorGroup( cg );
    393401    myProgressBarStyle->state = progressBarState;
    394     myProgressBarStyle->progress = int(myProgressBarStyle->minimum + ((tor.percentDone() * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
     402    myProgressBarStyle->progress = int(myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() : tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
    395403    style->drawControl( QStyle::CE_ProgressBar, myProgressBarStyle, painter );
    396404
  • trunk/qt/torrent-model.cc

    r10486 r10771  
    141141    QList<Torrent*> newTorrents;
    142142    QSet<int> oldIds( getIds( ) );
     143    QSet<int> addIds;
    143144    QSet<int> newIds;
    144145    int updatedCount = 0;
     
    160161                    tor = new Torrent( myPrefs, id );
    161162                    tor->update( child );
     163                    if( !tor->hasMetadata() )
     164                        tor->setMagnet( true );
    162165                    newTorrents.append( tor );
    163166                    connect( tor, SIGNAL(torrentChanged(int)), this, SLOT(onTorrentChanged(int)));
     
    167170                    tor->update( child );
    168171                    ++updatedCount;
     172                    if( tor->isMagnet() && tor->hasMetadata() )
     173                    {
     174                        addIds.insert( tor->id() );
     175                        tor->setMagnet( false );
     176                    }
    169177                }
    170178            }
     
    182190        foreach( Torrent * tor, newTorrents ) {
    183191            addTorrent( tor );
    184             ids.insert( tor->id( ) );
     192            addIds.insert( tor->id( ) );
    185193        }
    186194        endInsertRows( );
    187 
    188         emit torrentsAdded( ids );
    189     }
     195    }
     196
     197    if( !addIds.isEmpty() )
     198        emit torrentsAdded( addIds );
    190199
    191200    if( isCompleteList )
  • trunk/qt/torrent.h

    r10713 r10771  
    199199        static Property myProperties[];
    200200
     201        bool magnetTorrent;
     202
    201203    public:
    202204        typedef QList<const char*> KeyList;
     
    252254        uint64_t pieceSize( ) const { return getSize( PIECE_SIZE ); }
    253255        bool hasMetadata( ) const { return getDouble( METADATA_PERCENT_DONE ) >= 1.0; }
     256        bool isMagnet( ) const { return magnetTorrent; }
    254257        int  pieceCount( ) const { return getInt( PIECE_COUNT ); }
    255258        double ratio( ) const { return getDouble( RATIO ); }
     
    306309    public:
    307310        void update( tr_benc * dict );
     311        void setMagnet( bool magnet ) { magnetTorrent = magnet; }
    308312
    309313    private:
Note: See TracChangeset for help on using the changeset viewer.