]> granicus.if.org Git - transmission/commitdiff
(trunk qt) #3489 "Qt client should have up/down speeds in the tray icon's tooltip...
authorCharles Kerr <charles@transmissionbt.com>
Thu, 5 Aug 2010 15:01:40 +0000 (15:01 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Thu, 5 Aug 2010 15:01:40 +0000 (15:01 +0000)
qt/mainwin.cc
qt/mainwin.h
qt/torrent-model.h

index 846c98b632e41fc8210c2e267e17378f1a6cb6d3..8c9359fa5cde95570563a284349a1477ebb6db24 100644 (file)
@@ -200,6 +200,8 @@ TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& mode
     connect( &myModel, SIGNAL(modelReset()), this, SLOT(onModelReset()));
     connect( &myModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), this, SLOT(onModelReset()));
     connect( &myModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(onModelReset()));
+    connect( &myModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), this, SLOT(refreshTrayIcon()));
+
     ui.listView->setModel( &myFilterModel );
     connect( ui.listView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), this, SLOT(refreshActionSensitivity()));
 
@@ -274,6 +276,7 @@ TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& mode
     }
 
     refreshActionSensitivity( );
+    refreshTrayIcon( );
     refreshStatusBar( );
     refreshTitle( );
     refreshVisibleCount( );
@@ -317,6 +320,7 @@ TrMainWindow :: onModelReset( )
     refreshVisibleCount( );
     refreshActionSensitivity( );
     refreshStatusBar( );
+    refreshTrayIcon( );
 }
 
 /****
@@ -648,6 +652,23 @@ TrMainWindow :: refreshVisibleCount( )
     myVisibleCountLabel->setVisible( totalCount > 0 );
 }
 
+void
+TrMainWindow :: refreshTrayIcon( )
+{
+    Speed u, d;
+    const QString idle = tr( "Idle" );
+
+    foreach( int id, myModel.getIds( ) ) {
+        const Torrent * tor = myModel.getTorrentFromId( id );
+        u += tor->uploadSpeed( );
+        d += tor->downloadSpeed( );
+    }
+
+    myTrayIcon.setToolTip( tr( "Transmission\nUp: %1\nDown: %2" )
+                           .arg( u.isZero() ? idle : Formatter::speedToString( u ) )
+                           .arg( d.isZero() ? idle : Formatter::speedToString( d ) ) );
+}
+
 void
 TrMainWindow :: refreshStatusBar( )
 {
@@ -957,6 +978,7 @@ TrMainWindow :: refreshPref( int key )
             b = myPrefs.getBool( key );
             ui.action_TrayIcon->setChecked( b );
             myTrayIcon.setVisible( b );
+            refreshTrayIcon( );
             break;
 
         case Prefs::COMPACT_VIEW:
index 39815b172b15a3cce0bb0407246f59fb6b631975..c25ac49127ecd2896b63a9c51432ee3fe60b051d 100644 (file)
@@ -104,6 +104,7 @@ class TrMainWindow: public QMainWindow
         void refreshVisibleCount( );
         void refreshTitle( );
         void refreshStatusBar( );
+        void refreshTrayIcon( );
         void openTorrent( );
         void openURL( );
         void newTorrent( );
index 590d1c78660a7a107b735ef608bf232edadd58bf..271cf4eb103ba2a72c3c03305e90386a55317eaf 100644 (file)
@@ -51,9 +51,9 @@ class TorrentModel: public QAbstractListModel
     public:
         Torrent* getTorrentFromId( int id );
         const Torrent* getTorrentFromId( int id ) const;
+        QSet<int> getIds( ) const;
 
     private:
-        QSet<int> getIds( ) const;
         void addTorrent( Torrent * );
 
     public: