~kklimonda/transmission/packaging

« back to all changes in this revision

Viewing changes to qt/details.cc

  • Committer: Krzysztof Klimonda
  • Date: 2010-09-23 20:04:00 UTC
  • mfrom: (9411.1.187)
  • Revision ID: kklimonda@syntaxhighlighted.com-20100923200400-aluw4on6lcr409pl
mergeĀ upstreamĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
#include <libtransmission/transmission.h>
47
47
#include <libtransmission/bencode.h>
 
48
#include <libtransmission/utils.h> // tr_getRatio()
48
49
 
49
50
#include "details.h"
50
51
#include "file-tree.h"
228
229
 
229
230
    switch( key )
230
231
    {
231
 
        case Prefs :: SHOW_TRACKER_SCRAPES:
 
232
        case Prefs :: SHOW_TRACKER_SCRAPES: {
 
233
            QItemSelectionModel * selectionModel( myTrackerView->selectionModel( ) );
 
234
            const QItemSelection selection( selectionModel->selection( ) );
 
235
            const QModelIndex currentIndex( selectionModel->currentIndex( ) );
232
236
            myTrackerDelegate->setShowMore( myPrefs.getBool( key ) );
 
237
            selectionModel->clear( );
233
238
            myTrackerView->reset( );
 
239
            selectionModel->select( selection, QItemSelectionModel::Select );
 
240
            selectionModel->setCurrentIndex( currentIndex, QItemSelectionModel::NoUpdate );
234
241
            break;
 
242
        }
235
243
 
236
244
        case Prefs :: SHOW_BACKUP_TRACKERS:
237
245
            myTrackerFilter->setShowBackupTrackers( myPrefs.getBool( key ) );
362
370
                available += t->sizeWhenDone() - t->leftUntilDone() + t->desiredAvailable();
363
371
            }
364
372
        }
365
 
        if( !haveVerified && !haveUnverified )
366
 
            string = none;
367
 
        else {
 
373
        {
368
374
            const double d = 100.0 * ( sizeWhenDone ? ( sizeWhenDone - leftUntilDone ) / sizeWhenDone : 1 );
369
375
            QString pct = Formatter::percentToString( d );
370
 
            if( !haveUnverified )
 
376
            QString astr;
 
377
 
 
378
            if( sizeWhenDone )
 
379
                astr = Formatter::percentToString( ( 100.0 * available ) / sizeWhenDone );
 
380
            else
 
381
                astr = "100";
 
382
 
 
383
            if( !haveUnverified && !leftUntilDone )
 
384
            {
371
385
                string = tr( "%1 (%2%)" )
372
386
                             .arg( Formatter::sizeToString( haveVerified + haveUnverified ) )
373
387
                             .arg( pct );
 
388
            }
 
389
            else if( !haveUnverified )
 
390
            {
 
391
                string = tr( "%1 (%2% of %3% Available)" )
 
392
                             .arg( Formatter::sizeToString( haveVerified + haveUnverified ) )
 
393
                             .arg( pct )
 
394
                             .arg( astr );
 
395
            }
374
396
            else
375
 
                string = tr( "%1 (%2%); %3 Unverified" )
 
397
            {
 
398
                string = tr( "%1 (%2% of %3% Available) + %4 Unverified" )
376
399
                             .arg( Formatter::sizeToString( haveVerified + haveUnverified ) )
377
400
                             .arg( pct )
 
401
                             .arg( astr )
378
402
                             .arg( Formatter::sizeToString( haveUnverified ) );
 
403
            }
379
404
        }
380
405
    }
381
406
    myHaveLabel->setText( string );
409
434
    }
410
435
    myDownloadedLabel->setText( string );
411
436
 
412
 
    uint64_t u = 0;
413
437
    if( torrents.empty( ) )
414
438
        string = none;
415
439
    else {
416
 
        foreach( const Torrent * t, torrents ) u += t->uploadedEver( );
417
 
        string = QString( Formatter::sizeToString( u ) );
 
440
        uint64_t u = 0;
 
441
        uint64_t d = 0;
 
442
        foreach( const Torrent * t, torrents ) {
 
443
            u += t->uploadedEver( );
 
444
            d += t->downloadedEver( );
 
445
        }
 
446
        string = tr( "%1 (Ratio: %2)" )
 
447
                   .arg( Formatter::sizeToString( u ) )
 
448
                   .arg( Formatter::ratioToString( tr_getRatio( u, d ) ) );
418
449
    }
419
450
    myUploadedLabel->setText( string );
420
451
 
421
 
    if( torrents.empty( ) )
422
 
        string = none;
423
 
    else if( torrents.count() == 1 )
424
 
        string = Formatter::ratioToString( torrents.first()->ratio() );
425
 
    else {
426
 
        bool isMixed = false;
427
 
        int ratioType = (int) torrents.first()->ratio();
428
 
        if( ratioType > 0 ) ratioType = 0;
429
 
        foreach( const Torrent *t, torrents )
430
 
        {
431
 
            if( ratioType != ( t->ratio() >= 0 ? 0 : t->ratio() ) )
432
 
            {
433
 
                isMixed = true;
434
 
                break;
435
 
            }
436
 
        }
437
 
        if( isMixed )
438
 
            string = mixed;
439
 
        else if( ratioType < 0 )
440
 
            string = Formatter::ratioToString( ratioType );
441
 
        else
442
 
            string = Formatter::ratioToString( (double)u / d );
443
 
    }
444
 
    myRatioLabel->setText( string );
445
 
 
446
452
    const QDateTime qdt_now = QDateTime::currentDateTime( );
447
453
 
448
454
    // myRunTimeLabel
499
505
            if( latest < dt )
500
506
                latest = dt;
501
507
        }
502
 
        const int seconds = latest.secsTo( qdt_now );
503
 
        if( seconds < 5 )
 
508
        const int seconds = latest.isValid() ? latest.secsTo( qdt_now ) : -1;
 
509
        if( seconds < 0 )
 
510
            string = none;
 
511
        else if( seconds < 5 )
504
512
            string = tr( "Active now" );
505
513
        else
506
514
            string = tr( "%1 ago" ).arg( Formatter::timeToString( seconds ) );
691
699
        myPeerLimitSpin->blockSignals( false );
692
700
    }
693
701
 
 
702
    if( !torrents.empty( ) )
694
703
    {
695
704
        const Torrent * tor;
696
705
 
840
849
    hig->addRow( tr( "Availability:" ), myAvailabilityLabel = new SqueezeLabel );
841
850
    hig->addRow( tr( "Downloaded:" ), myDownloadedLabel = new SqueezeLabel );
842
851
    hig->addRow( tr( "Uploaded:" ), myUploadedLabel = new SqueezeLabel );
843
 
    hig->addRow( tr( "Ratio:" ), myRatioLabel = new SqueezeLabel );
844
852
    hig->addRow( tr( "State:" ), myStateLabel = new SqueezeLabel );
845
853
    hig->addRow( tr( "Running time:" ), myRunTimeLabel = new SqueezeLabel );
846
854
    hig->addRow( tr( "Remaining time:" ), myETALabel = new SqueezeLabel );
1033
1041
        QSet<int> ids;
1034
1042
        ids << trackerInfo.torrentId;
1035
1043
 
1036
 
        QStringList urls;
1037
 
        urls << trackerInfo.st.announce;
1038
 
        urls << newval;
 
1044
        const QPair<int,QString> idUrl = qMakePair( trackerInfo.st.id, newval );
1039
1045
 
1040
 
        mySession.torrentSet( ids, "trackerReplace", urls );
 
1046
        mySession.torrentSet( ids, "trackerReplace", idUrl );
1041
1047
        getNewData( );
1042
1048
    }
1043
1049
}
1048
1054
    // make a map of torrentIds to announce URLs to remove
1049
1055
    QItemSelectionModel * selectionModel = myTrackerView->selectionModel( );
1050
1056
    QModelIndexList selectedRows = selectionModel->selectedRows( );
1051
 
    QMap<int,QStringList> torrentId_to_urls;
 
1057
    QMap<int,int> torrentId_to_trackerIds;
1052
1058
    foreach( QModelIndex i, selectedRows )
1053
1059
    {
1054
1060
        const TrackerInfo inf = myTrackerView->model()->data( i, TrackerModel::TrackerRole ).value<TrackerInfo>();
1055
 
        torrentId_to_urls[ inf.torrentId ].append( inf.st.announce );
 
1061
        torrentId_to_trackerIds.insertMulti( inf.torrentId, inf.st.id );
1056
1062
    }
1057
1063
 
1058
1064
    // batch all of a tracker's torrents into one command
1059
 
    foreach( int id, torrentId_to_urls.keys( ) )
 
1065
    foreach( int id, torrentId_to_trackerIds.uniqueKeys( ) )
1060
1066
    {
1061
1067
        QSet<int> ids;
1062
1068
        ids << id;
1063
 
        mySession.torrentSet( ids, "trackerRemove", torrentId_to_urls.value( id ) );
1064
 
        getNewData( );
 
1069
        mySession.torrentSet( ids, "trackerRemove", torrentId_to_trackerIds.values( id ) );
1065
1070
    }
 
1071
 
 
1072
    selectionModel->clearSelection( );
 
1073
    getNewData( );
1066
1074
}
1067
1075
 
1068
1076
QWidget *