]> granicus.if.org Git - transmission/commitdiff
(qt) experiment with making the statusbar's speed/ratio, the desktop icon's tooltip...
authorJordan Lee <jordan@transmissionbt.com>
Thu, 7 Feb 2013 21:07:16 +0000 (21:07 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Thu, 7 Feb 2013 21:07:16 +0000 (21:07 +0000)
qt/mainwin.cc
qt/torrent-model.cc
qt/torrent-model.h

index 207e1c86bd23a928c65b4823f438e4d461e0eaa8..2670f1be7684f3aa840484170f9e3260f20a91ca 100644 (file)
@@ -746,21 +746,40 @@ TrMainWindow :: refreshTrayIconSoon ()
 void
 TrMainWindow :: refreshTrayIcon ()
 {
-  const QString idle = tr ("Idle");
-  const Speed u (myModel.getUploadSpeed ());
-  const Speed d (myModel.getDownloadSpeed ());
+  Speed upSpeed, downSpeed;
+  size_t upCount, downCount;
+  QString tip;
+
+  myModel.getTransferSpeed (upSpeed, upCount, downSpeed, downCount);
+
+  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 (tr ("Transmission\nUp: %1\nDown: %2")
-                         .arg (u.isZero () ? idle : Formatter::speedToString (u))
-                         .arg (d.isZero () ? idle : Formatter::speedToString (d)));
+  myTrayIcon.setToolTip (tip);
 }
 
 void
 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 ());
 
index af74f64c7b24e1660eef1c1c2214c617aefad55c..c99ea833b4f7d388f295677cdc4bcdb3fc7b1ed1 100644 (file)
@@ -230,22 +230,28 @@ TorrentModel :: removeTorrent( int id )
     }
 }
 
-Speed
-TorrentModel :: getUploadSpeed( ) const
+void
+TorrentModel :: getTransferSpeed (Speed   & uploadSpeed,
+                                  size_t  & uploadPeerCount,
+                                  Speed   & downloadSpeed,
+                                  size_t  & downloadPeerCount)
 {
-    Speed up;
-    foreach( const Torrent * tor, myTorrents )
-        up += tor->uploadSpeed( );
-    return up;
-}
+  Speed upSpeed, downSpeed;
+  size_t upCount=0, downCount=0;
 
-Speed
-TorrentModel :: getDownloadSpeed( ) const
-{
-    Speed down;
-    foreach( const Torrent * tor, myTorrents )
-        down += tor->downloadSpeed( );
-    return down;
+  foreach (const Torrent * const tor, myTorrents)
+    {
+      upSpeed += tor->uploadSpeed ();
+      upCount += tor->peersWeAreUploadingTo ();
+      downSpeed += tor->downloadSpeed ();
+      downCount += tor->webseedsWeAreDownloadingFrom();
+      downCount += tor->peersWeAreDownloadingFrom();
+    }
+
+  uploadSpeed = upSpeed;
+  uploadPeerCount = upCount;
+  downloadSpeed = downSpeed;
+  downloadPeerCount = downCount;
 }
 
 QSet<int>
index 5e512e9db54d6336e5b64524599a52ab798dc326..408970cb75e3b13720d3dbb76dab8c8539d081ea 100644 (file)
@@ -57,8 +57,10 @@ class TorrentModel: public QAbstractListModel
         QSet<int> getIds( ) const;
 
     public:
-        Speed getUploadSpeed( ) const;
-        Speed getDownloadSpeed( ) const;
+        void getTransferSpeed (Speed   & uploadSpeed,
+                               size_t  & uploadPeerCount,
+                               Speed   & downloadSpeed,
+                               size_t  & downloadPeerCount);
 
     signals:
         void torrentsAdded( QSet<int> );