From 4e30aad46496377f3482461ffcddc37d37370cd6 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 5 Aug 2010 15:01:40 +0000 Subject: [PATCH] (trunk qt) #3489 "Qt client should have up/down speeds in the tray icon's tooltip" -- fixed --- qt/mainwin.cc | 22 ++++++++++++++++++++++ qt/mainwin.h | 1 + qt/torrent-model.h | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/qt/mainwin.cc b/qt/mainwin.cc index 846c98b63..8c9359fa5 100644 --- a/qt/mainwin.cc +++ b/qt/mainwin.cc @@ -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: diff --git a/qt/mainwin.h b/qt/mainwin.h index 39815b172..c25ac4912 100644 --- a/qt/mainwin.h +++ b/qt/mainwin.h @@ -104,6 +104,7 @@ class TrMainWindow: public QMainWindow void refreshVisibleCount( ); void refreshTitle( ); void refreshStatusBar( ); + void refreshTrayIcon( ); void openTorrent( ); void openURL( ); void newTorrent( ); diff --git a/qt/torrent-model.h b/qt/torrent-model.h index 590d1c786..271cf4eb1 100644 --- a/qt/torrent-model.h +++ b/qt/torrent-model.h @@ -51,9 +51,9 @@ class TorrentModel: public QAbstractListModel public: Torrent* getTorrentFromId( int id ); const Torrent* getTorrentFromId( int id ) const; + QSet getIds( ) const; private: - QSet getIds( ) const; void addTorrent( Torrent * ); public: -- 2.40.0