mirror of
https://github.com/transmission/transmission
synced 2025-01-03 05:25:52 +00:00
(trunk qt) remember sorting & filtering mode between sessions
This commit is contained in:
parent
2877eddd58
commit
6f86e5d080
6 changed files with 114 additions and 33 deletions
|
@ -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 );
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -54,6 +54,7 @@ class Prefs: public QObject
|
|||
MAIN_WINDOW_WIDTH,
|
||||
MAIN_WINDOW_X,
|
||||
MAIN_WINDOW_Y,
|
||||
FILTER_MODE,
|
||||
|
||||
/* core prefs */
|
||||
FIRST_CORE_PREF,
|
||||
|
|
|
@ -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<numRows; ++i )
|
||||
if( name == rows[i].name )
|
||||
return rows[i].num;
|
||||
return rows[0].num; // fallback value
|
||||
}
|
||||
|
||||
const char* getName( const struct NameAndNum * rows, int numRows, int num )
|
||||
{
|
||||
for( int i=0; i<numRows; ++i )
|
||||
if( num == rows[i].num )
|
||||
return rows[i].name;
|
||||
return rows[0].name; // fallback value
|
||||
}
|
||||
}
|
||||
|
||||
TorrentFilter :: ShowMode
|
||||
TorrentFilter :: getShowModeFromName( const QString& key ) const
|
||||
{
|
||||
return ShowMode( getNum( showModes, showModeCount, key ) );
|
||||
}
|
||||
|
||||
const char*
|
||||
TorrentFilter :: getShowName( int mode ) const
|
||||
{
|
||||
if( mode < 0 ) mode = getShowMode( );
|
||||
return getName( showModes, showModeCount, mode );
|
||||
}
|
||||
|
||||
TorrentFilter :: SortMode
|
||||
TorrentFilter :: getSortModeFromName( const QString& key ) const
|
||||
{
|
||||
return SortMode( getNum( sortModes, sortModeCount, key ) );
|
||||
}
|
||||
|
||||
const char*
|
||||
TorrentFilter :: getSortName( int mode ) const
|
||||
{
|
||||
if( mode < 0 ) mode = getSortMode( );
|
||||
return getName( sortModes, sortModeCount, mode );
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
void
|
||||
TorrentFilter :: resort( )
|
||||
{
|
||||
|
@ -152,7 +215,7 @@ TorrentFilter :: setSortMode( int sortMode )
|
|||
{
|
||||
if( mySortMode != sortMode )
|
||||
{
|
||||
myPrefs.set( Prefs :: SORT_MODE, getSortKey( sortMode ) );
|
||||
myPrefs.set( Prefs :: SORT_MODE, getSortName( sortMode ) );
|
||||
mySortMode = SortMode( sortMode );
|
||||
setDynamicSortFilter ( true );
|
||||
resort( );
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <QSortFilterProxyModel>
|
||||
|
||||
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; }
|
||||
|
||||
|
|
Loading…
Reference in a new issue