From 48304add97e01981da08e6fb2c6402de3414163f Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 31 Jul 2010 00:03:59 +0000 Subject: [PATCH] (trunk qt) fix filterbar issue reported by Lacrocivious --- qt/filterbar.cc | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/qt/filterbar.cc b/qt/filterbar.cc index 33a8f9a9d..081b538f5 100644 --- a/qt/filterbar.cc +++ b/qt/filterbar.cc @@ -10,6 +10,8 @@ * $Id$ */ +#include + #include #include @@ -464,11 +466,14 @@ FilterBar :: refreshPref( int key ) case Prefs :: FILTER_TRACKERS: { const QString tracker = myPrefs.getString( key ); - QList rows = myTrackerModel->findItems( tracker ); - if( !rows.isEmpty( ) ) - myTrackerCombo->setCurrentIndex( rows.first()->row() ); - else if( myTorrents.rowCount( ) > 0 ) // uh-oh... we don't have this tracker anymore. best use "show all" as a fallback - myPrefs.set( key, "" ); + QModelIndexList indices = myTrackerModel->match( myTrackerModel->index(0,0), TrackerRole, tracker, 1, Qt::MatchFixedString ); + if( !indices.isEmpty( ) ) + myTrackerCombo->setCurrentIndex( indices.first().row() ); + else { // hm, we don't seem to have this tracker anymore... + const bool isBootstrapping = myTrackerModel->rowCount( ) <= 2; + if( !isBootstrapping ) + myPrefs.set( key, "" ); + } break; } @@ -489,7 +494,15 @@ void FilterBar :: onTrackerIndexChanged( int i ) { if( !myIsBootstrapping ) - myPrefs.set( Prefs::FILTER_TRACKERS, myTrackerCombo->itemData( i, Qt::DisplayRole ).toString( ) ); + { + QString str; + const bool isTracker = !myTrackerCombo->itemData(i,TrackerRole).toString().isEmpty(); + if( isTracker ) + str = myTrackerCombo->itemData(i,TrackerRole).toString(); + else // show all + str = ""; + myPrefs.set( Prefs::FILTER_TRACKERS, str ); + } } void