(qt) #3277: Crash after getting magnet torrent metadata
This commit is contained in:
parent
c944af72eb
commit
0bc8314809
|
@ -207,8 +207,18 @@ void
|
|||
Details :: onTimer( )
|
||||
{
|
||||
if( !myIds.empty( ) )
|
||||
{
|
||||
QSet<int> infos;
|
||||
foreach( int id, myIds ) {
|
||||
const Torrent * tor = myModel.getTorrentFromId( id );
|
||||
if( tor->isMagnet() )
|
||||
infos.insert( tor->id() );
|
||||
}
|
||||
if( !infos.isEmpty() )
|
||||
mySession.initTorrents( infos );
|
||||
mySession.refreshExtraStats( myIds );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Details :: onTorrentChanged( )
|
||||
|
|
|
@ -52,7 +52,8 @@ TorrentDelegateMin :: sizeHint( const QStyleOptionViewItem& option, const Torren
|
|||
|
||||
QFont nameFont( option.font );
|
||||
const QFontMetrics nameFM( nameFont );
|
||||
const QString nameStr( tor.name( ) );
|
||||
const bool isMagnet( !tor.hasMetadata( ) );
|
||||
const QString nameStr = (isMagnet ? progressString( tor ) : tor.name( ) );
|
||||
const QSize nameSize( nameFM.size( 0, nameStr ) );
|
||||
|
||||
QFont statusFont( option.font );
|
||||
|
@ -76,7 +77,8 @@ TorrentDelegateMin :: drawTorrent( QPainter * painter, const QStyleOptionViewIte
|
|||
|
||||
QFont nameFont( option.font );
|
||||
const QFontMetrics nameFM( nameFont );
|
||||
const QString nameStr( tor.name( ) );
|
||||
const bool isMagnet( !tor.hasMetadata( ) );
|
||||
const QString nameStr = (isMagnet ? progressString( tor ) : tor.name( ) );
|
||||
const QSize nameSize( nameFM.size( 0, nameStr ) );
|
||||
|
||||
QFont statusFont( option.font );
|
||||
|
@ -153,7 +155,7 @@ TorrentDelegateMin :: drawTorrent( QPainter * painter, const QStyleOptionViewIte
|
|||
myProgressBarStyle->palette = option.palette;
|
||||
myProgressBarStyle->palette.setCurrentColorGroup( cg );
|
||||
myProgressBarStyle->state = progressBarState;
|
||||
myProgressBarStyle->progress = int(myProgressBarStyle->minimum + ((tor.percentDone() * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
|
||||
myProgressBarStyle->progress = int(myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() : tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
|
||||
style->drawControl( QStyle::CE_ProgressBar, myProgressBarStyle, painter );
|
||||
|
||||
painter->restore( );
|
||||
|
|
|
@ -62,6 +62,7 @@ TorrentDelegate :: margin( const QStyle& style ) const
|
|||
QString
|
||||
TorrentDelegate :: progressString( const Torrent& tor ) const
|
||||
{
|
||||
const bool isMagnet( !tor.hasMetadata( ) );
|
||||
const bool isDone( tor.isDone( ) );
|
||||
const bool isSeed( tor.isSeed( ) );
|
||||
const uint64_t haveTotal( tor.haveTotal( ) );
|
||||
|
@ -69,7 +70,13 @@ TorrentDelegate :: progressString( const Torrent& tor ) const
|
|||
double seedRatio;
|
||||
const bool hasSeedRatio( tor.getSeedRatio( seedRatio ) );
|
||||
|
||||
if( !isDone ) // downloading
|
||||
if( isMagnet ) // magnet link with no metadata
|
||||
{
|
||||
/* %1 is the percentage of torrent metadata downloaded */
|
||||
str = tr( "Magnetized transfer - retrieving metadata ( %1% )" )
|
||||
.arg( tor.metadataPercentDone() );
|
||||
}
|
||||
else if( !isDone ) // downloading
|
||||
{
|
||||
/* %1 is how much we've got,
|
||||
%2 is how much we'll have when done,
|
||||
|
@ -386,12 +393,13 @@ TorrentDelegate :: drawTorrent( QPainter * painter, const QStyleOptionViewItem&
|
|||
painter->drawText( statusArea, 0, statusFM.elidedText( statusStr, Qt::ElideRight, statusArea.width( ) ) );
|
||||
painter->setFont( progressFont );
|
||||
painter->drawText( progArea, 0, progressFM.elidedText( progressStr, Qt::ElideRight, progArea.width( ) ) );
|
||||
const bool isMagnet( !tor.hasMetadata( ) );
|
||||
myProgressBarStyle->rect = barArea;
|
||||
myProgressBarStyle->direction = option.direction;
|
||||
myProgressBarStyle->palette = option.palette;
|
||||
myProgressBarStyle->palette.setCurrentColorGroup( cg );
|
||||
myProgressBarStyle->state = progressBarState;
|
||||
myProgressBarStyle->progress = int(myProgressBarStyle->minimum + ((tor.percentDone() * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
|
||||
myProgressBarStyle->progress = int(myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() : tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
|
||||
style->drawControl( QStyle::CE_ProgressBar, myProgressBarStyle, painter );
|
||||
|
||||
painter->restore( );
|
||||
|
|
|
@ -140,6 +140,7 @@ TorrentModel :: updateTorrents( tr_benc * torrents, bool isCompleteList )
|
|||
{
|
||||
QList<Torrent*> newTorrents;
|
||||
QSet<int> oldIds( getIds( ) );
|
||||
QSet<int> addIds;
|
||||
QSet<int> newIds;
|
||||
int updatedCount = 0;
|
||||
|
||||
|
@ -159,6 +160,8 @@ TorrentModel :: updateTorrents( tr_benc * torrents, bool isCompleteList )
|
|||
{
|
||||
tor = new Torrent( myPrefs, id );
|
||||
tor->update( child );
|
||||
if( !tor->hasMetadata() )
|
||||
tor->setMagnet( true );
|
||||
newTorrents.append( tor );
|
||||
connect( tor, SIGNAL(torrentChanged(int)), this, SLOT(onTorrentChanged(int)));
|
||||
}
|
||||
|
@ -166,6 +169,11 @@ TorrentModel :: updateTorrents( tr_benc * torrents, bool isCompleteList )
|
|||
{
|
||||
tor->update( child );
|
||||
++updatedCount;
|
||||
if( tor->isMagnet() && tor->hasMetadata() )
|
||||
{
|
||||
addIds.insert( tor->id() );
|
||||
tor->setMagnet( false );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -181,13 +189,14 @@ TorrentModel :: updateTorrents( tr_benc * torrents, bool isCompleteList )
|
|||
|
||||
foreach( Torrent * tor, newTorrents ) {
|
||||
addTorrent( tor );
|
||||
ids.insert( tor->id( ) );
|
||||
addIds.insert( tor->id( ) );
|
||||
}
|
||||
endInsertRows( );
|
||||
|
||||
emit torrentsAdded( ids );
|
||||
}
|
||||
|
||||
if( !addIds.isEmpty() )
|
||||
emit torrentsAdded( addIds );
|
||||
|
||||
if( isCompleteList )
|
||||
{
|
||||
QSet<int> removedIds( oldIds );
|
||||
|
|
|
@ -198,6 +198,8 @@ class Torrent: public QObject
|
|||
|
||||
static Property myProperties[];
|
||||
|
||||
bool magnetTorrent;
|
||||
|
||||
public:
|
||||
typedef QList<const char*> KeyList;
|
||||
static const KeyList& getInfoKeys( );
|
||||
|
@ -251,6 +253,7 @@ class Torrent: public QObject
|
|||
uint64_t leftUntilDone( ) const { return getSize( LEFT_UNTIL_DONE ); }
|
||||
uint64_t pieceSize( ) const { return getSize( PIECE_SIZE ); }
|
||||
bool hasMetadata( ) const { return getDouble( METADATA_PERCENT_DONE ) >= 1.0; }
|
||||
bool isMagnet( ) const { return magnetTorrent; }
|
||||
int pieceCount( ) const { return getInt( PIECE_COUNT ); }
|
||||
double ratio( ) const { return getDouble( RATIO ); }
|
||||
double percentComplete( ) const { return haveTotal() / (double)totalSize(); }
|
||||
|
@ -305,6 +308,7 @@ class Torrent: public QObject
|
|||
|
||||
public:
|
||||
void update( tr_benc * dict );
|
||||
void setMagnet( bool magnet ) { magnetTorrent = magnet; }
|
||||
|
||||
private:
|
||||
const char * getMimeTypeString( ) const;
|
||||
|
|
Loading…
Reference in New Issue