(trunk GTK+, Qt) #2645 "add torrent availability to Properties->Information" -- added for 1.90
This commit is contained in:
parent
2ff4c36fda
commit
803225bf10
|
@ -65,6 +65,7 @@ struct DetailsImpl
|
|||
GtkWidget * size_lb;
|
||||
GtkWidget * state_lb;
|
||||
GtkWidget * have_lb;
|
||||
GtkWidget * availability_lb;
|
||||
GtkWidget * dl_lb;
|
||||
GtkWidget * ul_lb;
|
||||
GtkWidget * ratio_lb;
|
||||
|
@ -624,6 +625,8 @@ refreshInfo( struct DetailsImpl * di, tr_torrent ** torrents, int n )
|
|||
const char * none = _( "None" );
|
||||
const char * mixed = _( "Mixed" );
|
||||
char buf[512];
|
||||
double available = 0;
|
||||
double sizeWhenDone = 0;
|
||||
const tr_stat ** stats = g_new( const tr_stat*, n );
|
||||
const tr_info ** infos = g_new( const tr_info*, n );
|
||||
for( i=0; i<n; ++i ) {
|
||||
|
@ -800,18 +803,19 @@ refreshInfo( struct DetailsImpl * di, tr_torrent ** torrents, int n )
|
|||
if( n <= 0 )
|
||||
str = none;
|
||||
else {
|
||||
double sizeWhenDone = 0;
|
||||
double leftUntilDone = 0;
|
||||
double haveUnchecked = 0;
|
||||
double haveValid = 0;
|
||||
double verifiedPieces = 0;
|
||||
for( i=0; i<n; ++i ) {
|
||||
const double v = stats[i]->haveValid;
|
||||
haveUnchecked += stats[i]->haveUnchecked;
|
||||
const tr_stat * st = stats[i];
|
||||
const double v = st->haveValid;
|
||||
haveUnchecked += st->haveUnchecked;
|
||||
haveValid += v;
|
||||
verifiedPieces += v / tr_torrentInfo(torrents[i])->pieceSize;
|
||||
sizeWhenDone += stats[i]->sizeWhenDone;
|
||||
leftUntilDone += stats[i]->leftUntilDone;
|
||||
sizeWhenDone += st->sizeWhenDone;
|
||||
leftUntilDone += st->leftUntilDone;
|
||||
available += st->sizeWhenDone - st->leftUntilDone + st->desiredAvailable;
|
||||
}
|
||||
if( !haveValid && !haveUnchecked )
|
||||
str = none;
|
||||
|
@ -829,6 +833,15 @@ refreshInfo( struct DetailsImpl * di, tr_torrent ** torrents, int n )
|
|||
}
|
||||
gtr_label_set_text( GTK_LABEL( di->have_lb ), str );
|
||||
|
||||
/* availability_lb */
|
||||
if( sizeWhenDone )
|
||||
str = none;
|
||||
else {
|
||||
const double d = ( 100.0 * available ) / sizeWhenDone;
|
||||
g_snprintf( buf, sizeof( buf ), _( "%1$.1f%%" ), d );
|
||||
str = buf;
|
||||
}
|
||||
gtr_label_set_text( GTK_LABEL( di->availability_lb ), str );
|
||||
|
||||
/* dl_lb */
|
||||
if( n <= 0 )
|
||||
|
@ -949,6 +962,10 @@ info_page_new( struct DetailsImpl * di )
|
|||
l = di->have_lb = gtk_label_new( NULL );
|
||||
hig_workarea_add_row( t, &row, _( "Have:" ), l, NULL );
|
||||
|
||||
/* availability */
|
||||
l = di->availability_lb = gtk_label_new( NULL );
|
||||
hig_workarea_add_row( t, &row, _( "Availability:" ), l, NULL );
|
||||
|
||||
/* downloaded */
|
||||
l = di->dl_lb = gtk_label_new( NULL );
|
||||
hig_workarea_add_row( t, &row, _( "Downloaded:" ), l, NULL );
|
||||
|
|
|
@ -249,6 +249,7 @@ Details :: refresh( )
|
|||
// myHaveLabel
|
||||
double sizeWhenDone = 0;
|
||||
double leftUntilDone = 0;
|
||||
double available = 0;
|
||||
int64_t haveTotal = 0;
|
||||
int64_t haveVerified = 0;
|
||||
int64_t haveUnverified = 0;
|
||||
|
@ -262,6 +263,7 @@ Details :: refresh( )
|
|||
verifiedPieces += v / t->pieceSize( );
|
||||
sizeWhenDone += t->sizeWhenDone( );
|
||||
leftUntilDone += t->leftUntilDone( );
|
||||
available += t->sizeWhenDone() - t->leftUntilDone() + t->desiredAvailable();
|
||||
}
|
||||
}
|
||||
if( !haveVerified && !haveUnverified )
|
||||
|
@ -281,6 +283,13 @@ Details :: refresh( )
|
|||
}
|
||||
myHaveLabel->setText( string );
|
||||
|
||||
// myAvailabilityLabel
|
||||
if( sizeWhenDone < 1 )
|
||||
string = none;
|
||||
else
|
||||
string.sprintf( "%'.1f%%", ( 100.0 * available ) / sizeWhenDone );
|
||||
myAvailabilityLabel->setText( string );
|
||||
|
||||
// myDownloadedLabel
|
||||
if( torrents.empty( ) )
|
||||
string = none;
|
||||
|
@ -809,6 +818,7 @@ Details :: createInfoTab( )
|
|||
hig->addSectionTitle( tr( "Activity" ) );
|
||||
hig->addRow( tr( "Torrent size:" ), mySizeLabel = new SqueezeLabel );
|
||||
hig->addRow( tr( "Have:" ), myHaveLabel = new SqueezeLabel );
|
||||
hig->addRow( tr( "Availability:" ), myAvailabilityLabel = new SqueezeLabel );
|
||||
hig->addRow( tr( "Downloaded:" ), myDownloadedLabel = new SqueezeLabel );
|
||||
hig->addRow( tr( "Uploaded:" ), myUploadedLabel = new SqueezeLabel );
|
||||
hig->addRow( tr( "Ratio:" ), myRatioLabel = new SqueezeLabel );
|
||||
|
|
|
@ -71,6 +71,7 @@ class Details: public QDialog
|
|||
|
||||
QLabel * myStateLabel;
|
||||
QLabel * myHaveLabel;
|
||||
QLabel * myAvailabilityLabel;
|
||||
QLabel * myDownloadedLabel;
|
||||
QLabel * myUploadedLabel;
|
||||
QLabel * myRatioLabel;
|
||||
|
|
|
@ -64,6 +64,7 @@ Torrent :: myProperties[] =
|
|||
{ LEFT_UNTIL_DONE, "leftUntilDone", QVariant::ULongLong, STAT },
|
||||
{ HAVE_UNCHECKED, "haveUnchecked", QVariant::ULongLong, STAT },
|
||||
{ HAVE_VERIFIED, "haveValid", QVariant::ULongLong, STAT },
|
||||
{ DESIRED_AVAILABLE, "desiredAvailable", QVariant::ULongLong, STAT },
|
||||
{ TOTAL_SIZE, "totalSize", QVariant::ULongLong, INFO },
|
||||
{ PIECE_SIZE, "pieceSize", QVariant::ULongLong, INFO },
|
||||
{ PIECE_COUNT, "pieceCount", QVariant::Int, INFO },
|
||||
|
|
|
@ -94,6 +94,7 @@ class Torrent: public QObject
|
|||
LEFT_UNTIL_DONE,
|
||||
HAVE_UNCHECKED,
|
||||
HAVE_VERIFIED,
|
||||
DESIRED_AVAILABLE,
|
||||
TOTAL_SIZE,
|
||||
PIECE_SIZE,
|
||||
PIECE_COUNT,
|
||||
|
@ -218,6 +219,7 @@ class Torrent: public QObject
|
|||
bool getSeedRatio( double& setme ) const;
|
||||
uint64_t haveVerified( ) const { return getSize( HAVE_VERIFIED ); }
|
||||
uint64_t haveUnverified( ) const { return getSize( HAVE_UNCHECKED ); }
|
||||
uint64_t desiredAvailable( ) const { return getSize( DESIRED_AVAILABLE ); }
|
||||
uint64_t haveTotal( ) const { return haveVerified( ) + haveUnverified(); }
|
||||
uint64_t totalSize( ) const { return getSize( TOTAL_SIZE ); }
|
||||
uint64_t sizeWhenDone( ) const { return getSize( SIZE_WHEN_DONE ); }
|
||||
|
|
Loading…
Reference in New Issue