]> granicus.if.org Git - transmission/commitdiff
(trunk qt) #4369 "Typing text into the main window's filter field causes high CPU...
authorJordan Lee <jordan@transmissionbt.com>
Tue, 19 Jul 2011 21:19:18 +0000 (21:19 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Tue, 19 Jul 2011 21:19:18 +0000 (21:19 +0000)
qt/mainwin.cc
qt/mainwin.h

index f5ca4b159cb5cb43cf18e54f211942d29e962c62..aa91c855bd9ac3f32a5f95eb2d89d10967a909c5 100644 (file)
@@ -91,7 +91,8 @@ TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& mode
     myLastSendTime( 0 ),
     myLastReadTime( 0 ),
     myNetworkTimer( this ),
-    myRefreshTrayIconTimer( this )
+    myRefreshTrayIconTimer( this ),
+    myRefreshActionSensitivityTimer( this )
 {
     setAcceptDrops( true );
 
@@ -190,8 +191,8 @@ TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& mode
 
     connect( &myFilterModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(refreshVisibleCount()));
     connect( &myFilterModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), this, SLOT(refreshVisibleCount()));
-    connect( &myFilterModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(refreshActionSensitivity()));
-    connect( &myFilterModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), this, SLOT(refreshActionSensitivity()));
+    connect( &myFilterModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(refreshActionSensitivitySoon()));
+    connect( &myFilterModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), this, SLOT(refreshActionSensitivitySoon()));
 
     connect( ui.action_Quit, SIGNAL(triggered()), QCoreApplication::instance(), SLOT(quit()) );
 
@@ -203,7 +204,7 @@ TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& mode
     connect( &myModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), this, SLOT(refreshTrayIconSoon()));
 
     ui.listView->setModel( &myFilterModel );
-    connect( ui.listView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), this, SLOT(refreshActionSensitivity()));
+    connect( ui.listView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), this, SLOT(refreshActionSensitivitySoon()));
 
     QActionGroup * actionGroup = new QActionGroup( this );
     actionGroup->addAction( ui.action_SortByActivity );
@@ -275,9 +276,10 @@ TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& mode
     }
 
     connect( &myRefreshTrayIconTimer, SIGNAL(timeout()), this, SLOT(refreshTrayIcon()) );
+    connect( &myRefreshActionSensitivityTimer, SIGNAL(timeout()), this, SLOT(refreshActionSensitivity()) );
 
 
-    refreshActionSensitivity( );
+    refreshActionSensitivitySoon( );
     refreshTrayIconSoon( );
     refreshStatusBar( );
     refreshTitle( );
@@ -320,7 +322,7 @@ TrMainWindow :: onModelReset( )
 {
     refreshTitle( );
     refreshVisibleCount( );
-    refreshActionSensitivity( );
+    refreshActionSensitivitySoon( );
     refreshStatusBar( );
     refreshTrayIconSoon( );
 }
@@ -707,6 +709,17 @@ TrMainWindow :: refreshStatusBar( )
     myStatsLabel->setText( str );
 }
 
+
+
+void
+TrMainWindow :: refreshActionSensitivitySoon( )
+{
+    if( !myRefreshActionSensitivityTimer.isActive( ) )
+    {
+        myRefreshActionSensitivityTimer.setSingleShot( true );
+        myRefreshActionSensitivityTimer.start( 500 );
+    }
+}
 void
 TrMainWindow :: refreshActionSensitivity( )
 {
index 4eea853b0987f38e919706379cfe5f32dfa589b4..fe96c1aad2561415e9ad1626d66395e7e756213d 100644 (file)
@@ -76,6 +76,7 @@ class TrMainWindow: public QMainWindow
         time_t myLastReadTime;
         QTimer myNetworkTimer;
         QTimer myRefreshTrayIconTimer;
+        QTimer myRefreshActionSensitivityTimer;
         QAction * myDlimitOffAction;
         QAction * myDlimitOnAction;
         QAction * myUlimitOffAction;
@@ -178,6 +179,7 @@ class TrMainWindow: public QMainWindow
         void setStatusbarVisible( bool );
         void setCompactView( bool );
         void refreshActionSensitivity( );
+        void refreshActionSensitivitySoon( );
         void wrongAuthentication( );
 
     public: