1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 10:07:40 +00:00

(qt) experiment with making the statusbar's speed/ratio, the desktop icon's tooltip, and the delegate's shortTransferString() all behave the same wrt when to show which transfer speeds

This commit is contained in:
Jordan Lee 2013-02-07 21:07:16 +00:00
parent 51c1daeb9a
commit 716a2f2c5c
3 changed files with 51 additions and 24 deletions

View file

@ -746,21 +746,40 @@ TrMainWindow :: refreshTrayIconSoon ()
void void
TrMainWindow :: refreshTrayIcon () TrMainWindow :: refreshTrayIcon ()
{ {
const QString idle = tr ("Idle"); Speed upSpeed, downSpeed;
const Speed u (myModel.getUploadSpeed ()); size_t upCount, downCount;
const Speed d (myModel.getDownloadSpeed ()); QString tip;
myTrayIcon.setToolTip (tr ("Transmission\nUp: %1\nDown: %2") myModel.getTransferSpeed (upSpeed, upCount, downSpeed, downCount);
.arg (u.isZero () ? idle : Formatter::speedToString (u))
.arg (d.isZero () ? idle : Formatter::speedToString (d))); if (!upCount && !downCount)
{
tip = tr ("Idle");
}
else if (downCount)
{
tip = tr( "%1 %2" ).arg(Formatter::downloadSpeedToString(downSpeed))
.arg(Formatter::uploadSpeedToString(upSpeed));
}
else if (upCount)
{
tip = Formatter::uploadSpeedToString(upSpeed);
}
myTrayIcon.setToolTip (tip);
} }
void void
TrMainWindow :: refreshStatusBar () TrMainWindow :: refreshStatusBar ()
{ {
myUploadSpeedLabel->setText (Formatter::uploadSpeedToString(myModel.getUploadSpeed())); Speed upSpeed, downSpeed;
size_t upCount, downCount;
myModel.getTransferSpeed (upSpeed, upCount, downSpeed, downCount);
myDownloadSpeedLabel->setText (Formatter::downloadSpeedToString(myModel.getDownloadSpeed())); myUploadSpeedLabel->setText (Formatter::uploadSpeedToString(upSpeed));
myUploadSpeedLabel->setVisible (downCount || upCount);
myDownloadSpeedLabel->setText (Formatter::downloadSpeedToString(downSpeed));
myDownloadSpeedLabel->setVisible (downCount);
myNetworkLabel->setVisible (!mySession.isServer ()); myNetworkLabel->setVisible (!mySession.isServer ());

View file

@ -230,22 +230,28 @@ TorrentModel :: removeTorrent( int id )
} }
} }
Speed void
TorrentModel :: getUploadSpeed( ) const TorrentModel :: getTransferSpeed (Speed & uploadSpeed,
size_t & uploadPeerCount,
Speed & downloadSpeed,
size_t & downloadPeerCount)
{ {
Speed up; Speed upSpeed, downSpeed;
foreach( const Torrent * tor, myTorrents ) size_t upCount=0, downCount=0;
up += tor->uploadSpeed( );
return up;
}
Speed foreach (const Torrent * const tor, myTorrents)
TorrentModel :: getDownloadSpeed( ) const {
{ upSpeed += tor->uploadSpeed ();
Speed down; upCount += tor->peersWeAreUploadingTo ();
foreach( const Torrent * tor, myTorrents ) downSpeed += tor->downloadSpeed ();
down += tor->downloadSpeed( ); downCount += tor->webseedsWeAreDownloadingFrom();
return down; downCount += tor->peersWeAreDownloadingFrom();
}
uploadSpeed = upSpeed;
uploadPeerCount = upCount;
downloadSpeed = downSpeed;
downloadPeerCount = downCount;
} }
QSet<int> QSet<int>

View file

@ -57,8 +57,10 @@ class TorrentModel: public QAbstractListModel
QSet<int> getIds( ) const; QSet<int> getIds( ) const;
public: public:
Speed getUploadSpeed( ) const; void getTransferSpeed (Speed & uploadSpeed,
Speed getDownloadSpeed( ) const; size_t & uploadPeerCount,
Speed & downloadSpeed,
size_t & downloadPeerCount);
signals: signals:
void torrentsAdded( QSet<int> ); void torrentsAdded( QSet<int> );