From 6f86e5d080ac31bb80372e73819a55c3eb86f4a8 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 10 Apr 2009 03:48:19 +0000 Subject: [PATCH] (trunk qt) remember sorting & filtering mode between sessions --- qt/mainwin.cc | 42 +++++++++++++------- qt/prefs-dialog.cc | 1 - qt/prefs.cc | 2 + qt/prefs.h | 1 + qt/torrent-filter.cc | 95 ++++++++++++++++++++++++++++++++++++-------- qt/torrent-filter.h | 6 ++- 6 files changed, 114 insertions(+), 33 deletions(-) diff --git a/qt/mainwin.cc b/qt/mainwin.cc index 19ec7143b..125d711ee 100644 --- a/qt/mainwin.cc +++ b/qt/mainwin.cc @@ -285,6 +285,7 @@ TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& mode << Prefs :: SHOW_TRAY_ICON << Prefs :: SORT_REVERSED << Prefs :: SORT_MODE + << Prefs :: FILTER_MODE << Prefs :: FILTERBAR << Prefs :: STATUSBAR << Prefs :: STATUSBAR_STATS @@ -513,11 +514,11 @@ TrMainWindow :: reannounceSelected( ) void TrMainWindow :: setShowMode( TorrentFilter :: ShowMode mode ) { - ui.filterAll->setChecked( mode == TorrentFilter::SHOW_ALL ); - ui.filterActive->setChecked( mode == TorrentFilter::SHOW_ACTIVE ); - ui.filterDownloading->setChecked( mode == TorrentFilter::SHOW_DOWNLOADING ); - ui.filterSeeding->setChecked( mode == TorrentFilter::SHOW_SEEDING ); - ui.filterPaused->setChecked( mode == TorrentFilter::SHOW_PAUSED ); + ui.filterAll->setChecked ( mode == TorrentFilter :: SHOW_ALL ); + ui.filterActive->setChecked ( mode == TorrentFilter :: SHOW_ACTIVE ); + ui.filterDownloading->setChecked ( mode == TorrentFilter :: SHOW_DOWNLOADING ); + ui.filterSeeding->setChecked ( mode == TorrentFilter :: SHOW_SEEDING ); + ui.filterPaused->setChecked ( mode == TorrentFilter :: SHOW_PAUSED ); myFilterModel.setShowMode( mode ); } @@ -610,6 +611,7 @@ void TrMainWindow :: refreshPref( int key ) { bool b; + int i; QString str; switch( key ) @@ -628,18 +630,28 @@ TrMainWindow :: refreshPref( int key ) break; case Prefs::SORT_MODE: - str = myPrefs.getString( key ); - ui.action_SortByActivity->setChecked ( str == "sort-by-activity" ); - ui.action_SortByAge->setChecked ( str == "sort-by-age" ); - ui.action_SortByETA->setChecked ( str == "sort-by-eta" ); - ui.action_SortByName->setChecked ( str == "sort-by-name" ); - ui.action_SortByProgress->setChecked ( str == "sort-by-progress" ); - ui.action_SortByRatio->setChecked ( str == "sort-by-ratio" ); - ui.action_SortBySize->setChecked ( str == "sort-by-size" ); - ui.action_SortByState->setChecked ( str == "sort-by-state" ); - ui.action_SortByTracker->setChecked ( str == "sort-by-tracker" ); + i = myFilterModel.getSortModeFromName( myPrefs.getString( key ) ); + ui.action_SortByActivity->setChecked ( i == TorrentFilter::SORT_BY_ACTIVITY ); + ui.action_SortByAge->setChecked ( i == TorrentFilter::SORT_BY_AGE ); + ui.action_SortByETA->setChecked ( i == TorrentFilter::SORT_BY_ETA ); + ui.action_SortByName->setChecked ( i == TorrentFilter::SORT_BY_NAME ); + ui.action_SortByProgress->setChecked ( i == TorrentFilter::SORT_BY_PROGRESS ); + ui.action_SortByRatio->setChecked ( i == TorrentFilter::SORT_BY_RATIO ); + ui.action_SortBySize->setChecked ( i == TorrentFilter::SORT_BY_SIZE ); + ui.action_SortByState->setChecked ( i == TorrentFilter::SORT_BY_STATE ); + ui.action_SortByTracker->setChecked ( i == TorrentFilter::SORT_BY_TRACKER ); break; + case Prefs::FILTER_MODE: + i = myFilterModel.getShowModeFromName( myPrefs.getString( key ) ); + ui.filterAll->setChecked ( i == TorrentFilter::SHOW_ALL ); + ui.filterActive->setChecked ( i == TorrentFilter::SHOW_ACTIVE ); + ui.filterDownloading->setChecked ( i == TorrentFilter::SHOW_DOWNLOADING ); + ui.filterSeeding->setChecked ( i == TorrentFilter::SHOW_SEEDING ); + ui.filterPaused->setChecked ( i == TorrentFilter::SHOW_PAUSED ); + break; + + case Prefs::FILTERBAR: b = myPrefs.getBool( key ); ui.filterbar->setVisible( b ); diff --git a/qt/prefs-dialog.cc b/qt/prefs-dialog.cc index e095b7377..0f10cb4c0 100644 --- a/qt/prefs-dialog.cc +++ b/qt/prefs-dialog.cc @@ -666,7 +666,6 @@ PrefsDialog :: updatePref( int key ) case Prefs :: BLOCKLIST_ENABLED: { const bool enabled = myPrefs.getBool( key ); - std::cerr << " setting " << myBlockWidgets.size() << " block widgets to " << enabled << std::endl; foreach( QWidget * w, myBlockWidgets ) w->setEnabled( enabled ); break; } diff --git a/qt/prefs.cc b/qt/prefs.cc index 36ae4f082..514459a8c 100644 --- a/qt/prefs.cc +++ b/qt/prefs.cc @@ -54,6 +54,7 @@ Prefs::PrefItem Prefs::myItems[] = { MAIN_WINDOW_WIDTH, "main-window-width", QVariant::Int }, { MAIN_WINDOW_X, "main-window-x", QVariant::Int }, { MAIN_WINDOW_Y, "main-window-y", QVariant::Int }, + { FILTER_MODE, "filter-mode", QVariant::String }, /* libtransmission settings */ { ALT_SPEED_LIMIT_UP, TR_PREFS_KEY_ALT_SPEED_UP, QVariant::Int }, @@ -231,6 +232,7 @@ Prefs :: initDefaults( tr_benc * d ) tr_bencDictAddInt( d, keyStr(MAIN_WINDOW_WIDTH), 300 ); tr_bencDictAddInt( d, keyStr(MAIN_WINDOW_X), 50 ); tr_bencDictAddInt( d, keyStr(MAIN_WINDOW_Y), 50 ); + tr_bencDictAddStr( d, keyStr(FILTER_MODE), "all" ); tr_bencDictAddStr( d, keyStr(MAIN_WINDOW_LAYOUT_ORDER), "menu,toolbar,filter,list,statusbar" ); tr_bencDictAddStr( d, keyStr(DOWNLOAD_DIR), tr_getDefaultDownloadDir( ) ); tr_bencDictAddInt( d, keyStr(ASKQUIT), true ); diff --git a/qt/prefs.h b/qt/prefs.h index 484ae46fc..1ab03d63f 100644 --- a/qt/prefs.h +++ b/qt/prefs.h @@ -54,6 +54,7 @@ class Prefs: public QObject MAIN_WINDOW_WIDTH, MAIN_WINDOW_X, MAIN_WINDOW_Y, + FILTER_MODE, /* core prefs */ FIRST_CORE_PREF, diff --git a/qt/torrent-filter.cc b/qt/torrent-filter.cc index d23071521..5fd54eb51 100644 --- a/qt/torrent-filter.cc +++ b/qt/torrent-filter.cc @@ -19,10 +19,10 @@ TorrentFilter :: TorrentFilter( Prefs& prefs ): myPrefs( prefs ), - myShowMode( SHOW_ALL ), + myShowMode( getShowModeFromName( prefs.getString( Prefs::FILTER_MODE ) ) ), myTextMode( FILTER_BY_NAME ), - mySortMode( SORT_BY_ID ), - myIsAscending( FALSE ) + mySortMode( getSortModeFromName( prefs.getString( Prefs::SORT_MODE ) ) ), + myIsAscending( prefs.getBool( Prefs::SORT_REVERSED ) ) { } @@ -39,6 +39,7 @@ TorrentFilter :: setShowMode( int showMode ) { if( myShowMode != showMode ) { + myPrefs.set( Prefs :: FILTER_MODE, getShowName( showMode ) ); myShowMode = ShowMode( showMode ); invalidateFilter( ); } @@ -113,23 +114,85 @@ TorrentFilter :: filterAcceptsRow( int sourceRow, const QModelIndex& sourceParen **** ***/ -const char* -TorrentFilter :: getSortKey( int modeIn ) +namespace { - switch( modeIn < 0 ? getSortMode( ) : SortMode( modeIn ) ) + struct NameAndNum { - case SORT_BY_ACTIVITY: return "sort-by-activity"; - case SORT_BY_AGE: return "sort-by-age"; - case SORT_BY_ETA: return "sort-by-eta"; - case SORT_BY_PROGRESS: return "sort-by-progress"; - case SORT_BY_RATIO: return "sort-by-ratio"; - case SORT_BY_SIZE: return "sort-by-size"; - case SORT_BY_STATE: return "sort-by-state"; - case SORT_BY_TRACKER: return "sort-by-tracker"; - default: return "sort-by-name"; + const char * name; + int num; + }; + + const struct NameAndNum showModes[] = { + { "show-all", TorrentFilter::SHOW_ALL }, + { "show-active", TorrentFilter::SHOW_ACTIVE }, + { "show-downloading", TorrentFilter::SHOW_DOWNLOADING }, + { "show-seeding", TorrentFilter::SHOW_SEEDING }, + { "show-paused", TorrentFilter::SHOW_PAUSED } + }; + + const int showModeCount = sizeof(showModes) / sizeof(showModes[0]); + + const struct NameAndNum sortModes[] = { + { "sort-by-name", TorrentFilter::SORT_BY_NAME }, + { "sort-by-activity", TorrentFilter::SORT_BY_ACTIVITY }, + { "sort-by-age", TorrentFilter::SORT_BY_AGE }, + { "sort-by-eta", TorrentFilter::SORT_BY_ETA }, + { "sort-by-progress", TorrentFilter::SORT_BY_PROGRESS }, + { "sort-by-ratio", TorrentFilter::SORT_BY_RATIO }, + { "sort-by-size", TorrentFilter::SORT_BY_SIZE }, + { "sort-by-state", TorrentFilter::SORT_BY_STATE }, + { "sort-by-tracker", TorrentFilter::SORT_BY_TRACKER } + }; + + const int sortModeCount = sizeof(sortModes) / sizeof(sortModes[0]); + + int getNum( const struct NameAndNum * rows, int numRows, const QString& name ) + { + for( int i=0; i struct Prefs; +struct QString; class TorrentFilter: public QSortFilterProxyModel { @@ -28,6 +29,8 @@ class TorrentFilter: public QSortFilterProxyModel public: enum ShowMode { SHOW_ALL, SHOW_ACTIVE, SHOW_DOWNLOADING, SHOW_SEEDING, SHOW_PAUSED }; ShowMode getShowMode( ) const { return myShowMode; } + ShowMode getShowModeFromName( const QString& name ) const; + const char * getShowName( int mode=-1 ) const; enum TextMode { FILTER_BY_NAME, FILTER_BY_FILES, FILTER_BY_TRACKER }; TextMode getTextMode( ) const { return myTextMode; } @@ -35,8 +38,9 @@ class TorrentFilter: public QSortFilterProxyModel enum SortMode{ SORT_BY_ACTIVITY, SORT_BY_AGE, SORT_BY_ETA, SORT_BY_NAME, SORT_BY_PROGRESS, SORT_BY_RATIO, SORT_BY_SIZE, SORT_BY_STATE, SORT_BY_TRACKER, SORT_BY_ID }; - const char * getSortKey( int mode=-1 ); SortMode getSortMode( ) const { return mySortMode; } + SortMode getSortModeFromName( const QString& name) const; + const char * getSortName( int mode=-1 ) const; bool isAscending( ) const { return myIsAscending; }