Changeset 8194


Ignore:
Timestamp:
Apr 10, 2009, 3:48:19 AM (13 years ago)
Author:
charles
Message:

(trunk qt) remember sorting & filtering mode between sessions

Location:
trunk/qt
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/mainwin.cc

    r8188 r8194  
    286286             << Prefs :: SORT_REVERSED
    287287             << Prefs :: SORT_MODE
     288             << Prefs :: FILTER_MODE
    288289             << Prefs :: FILTERBAR
    289290             << Prefs :: STATUSBAR
     
    514515TrMainWindow :: setShowMode( TorrentFilter :: ShowMode mode )
    515516{
    516     ui.filterAll->setChecked( mode == TorrentFilter::SHOW_ALL );
    517     ui.filterActive->setChecked( mode == TorrentFilter::SHOW_ACTIVE );
    518     ui.filterDownloading->setChecked( mode == TorrentFilter::SHOW_DOWNLOADING );
    519     ui.filterSeeding->setChecked( mode == TorrentFilter::SHOW_SEEDING );
    520     ui.filterPaused->setChecked( mode == TorrentFilter::SHOW_PAUSED );
     517    ui.filterAll->setChecked         ( mode == TorrentFilter :: SHOW_ALL );
     518    ui.filterActive->setChecked      ( mode == TorrentFilter :: SHOW_ACTIVE );
     519    ui.filterDownloading->setChecked ( mode == TorrentFilter :: SHOW_DOWNLOADING );
     520    ui.filterSeeding->setChecked     ( mode == TorrentFilter :: SHOW_SEEDING );
     521    ui.filterPaused->setChecked      ( mode == TorrentFilter :: SHOW_PAUSED );
    521522
    522523    myFilterModel.setShowMode( mode );
     
    611612{
    612613    bool b;
     614    int i;
    613615    QString str;
    614616
     
    629631
    630632        case Prefs::SORT_MODE:
    631             str = myPrefs.getString( key );
    632             ui.action_SortByActivity->setChecked ( str == "sort-by-activity" );
    633             ui.action_SortByAge->setChecked      ( str == "sort-by-age" );
    634             ui.action_SortByETA->setChecked      ( str == "sort-by-eta" );
    635             ui.action_SortByName->setChecked     ( str == "sort-by-name" );
    636             ui.action_SortByProgress->setChecked ( str == "sort-by-progress" );
    637             ui.action_SortByRatio->setChecked    ( str == "sort-by-ratio" );
    638             ui.action_SortBySize->setChecked     ( str == "sort-by-size" );
    639             ui.action_SortByState->setChecked    ( str == "sort-by-state" );
    640             ui.action_SortByTracker->setChecked  ( str == "sort-by-tracker" );
    641             break;
     633            i = myFilterModel.getSortModeFromName( myPrefs.getString( key ) );
     634            ui.action_SortByActivity->setChecked ( i == TorrentFilter::SORT_BY_ACTIVITY );
     635            ui.action_SortByAge->setChecked      ( i == TorrentFilter::SORT_BY_AGE );
     636            ui.action_SortByETA->setChecked      ( i == TorrentFilter::SORT_BY_ETA );
     637            ui.action_SortByName->setChecked     ( i == TorrentFilter::SORT_BY_NAME );
     638            ui.action_SortByProgress->setChecked ( i == TorrentFilter::SORT_BY_PROGRESS );
     639            ui.action_SortByRatio->setChecked    ( i == TorrentFilter::SORT_BY_RATIO );
     640            ui.action_SortBySize->setChecked     ( i == TorrentFilter::SORT_BY_SIZE );
     641            ui.action_SortByState->setChecked    ( i == TorrentFilter::SORT_BY_STATE );
     642            ui.action_SortByTracker->setChecked  ( i == TorrentFilter::SORT_BY_TRACKER );
     643            break;
     644
     645        case Prefs::FILTER_MODE:
     646            i = myFilterModel.getShowModeFromName( myPrefs.getString( key ) );
     647            ui.filterAll->setChecked         ( i == TorrentFilter::SHOW_ALL );
     648            ui.filterActive->setChecked      ( i == TorrentFilter::SHOW_ACTIVE );
     649            ui.filterDownloading->setChecked ( i == TorrentFilter::SHOW_DOWNLOADING );
     650            ui.filterSeeding->setChecked     ( i == TorrentFilter::SHOW_SEEDING );
     651            ui.filterPaused->setChecked      ( i == TorrentFilter::SHOW_PAUSED );
     652            break;
     653
    642654
    643655        case Prefs::FILTERBAR:
  • trunk/qt/prefs-dialog.cc

    r8192 r8194  
    667667        case Prefs :: BLOCKLIST_ENABLED: {
    668668            const bool enabled = myPrefs.getBool( key );
    669             std::cerr << " setting " << myBlockWidgets.size() << " block widgets to " << enabled << std::endl;
    670669            foreach( QWidget * w, myBlockWidgets ) w->setEnabled( enabled );
    671670            break;
  • trunk/qt/prefs.cc

    r8188 r8194  
    5555    { MAIN_WINDOW_X, "main-window-x", QVariant::Int },
    5656    { MAIN_WINDOW_Y, "main-window-y", QVariant::Int },
     57    { FILTER_MODE, "filter-mode", QVariant::String },
    5758
    5859    /* libtransmission settings */
     
    232233    tr_bencDictAddInt( d, keyStr(MAIN_WINDOW_X), 50 );
    233234    tr_bencDictAddInt( d, keyStr(MAIN_WINDOW_Y), 50 );
     235    tr_bencDictAddStr( d, keyStr(FILTER_MODE), "all" );
    234236    tr_bencDictAddStr( d, keyStr(MAIN_WINDOW_LAYOUT_ORDER), "menu,toolbar,filter,list,statusbar" );
    235237    tr_bencDictAddStr( d, keyStr(DOWNLOAD_DIR), tr_getDefaultDownloadDir( ) );
  • trunk/qt/prefs.h

    r8188 r8194  
    5555            MAIN_WINDOW_X,
    5656            MAIN_WINDOW_Y,
     57            FILTER_MODE,
    5758
    5859            /* core prefs */
  • trunk/qt/torrent-filter.cc

    r8192 r8194  
    2020TorrentFilter :: TorrentFilter( Prefs& prefs ):
    2121    myPrefs( prefs ),
    22     myShowMode( SHOW_ALL ),
     22    myShowMode( getShowModeFromName( prefs.getString( Prefs::FILTER_MODE ) ) ),
    2323    myTextMode( FILTER_BY_NAME ),
    24     mySortMode( SORT_BY_ID ),
    25     myIsAscending( FALSE )
     24    mySortMode( getSortModeFromName( prefs.getString( Prefs::SORT_MODE ) ) ),
     25    myIsAscending( prefs.getBool( Prefs::SORT_REVERSED ) )
    2626{
    2727}
     
    4040    if( myShowMode != showMode )
    4141    {
     42        myPrefs.set( Prefs :: FILTER_MODE, getShowName( showMode ) );
    4243        myShowMode = ShowMode( showMode );
    4344        invalidateFilter( );
     
    114115***/
    115116
     117namespace
     118{
     119    struct NameAndNum
     120    {
     121        const char * name;
     122        int num;
     123    };
     124
     125    const struct NameAndNum showModes[] = {
     126        { "show-all",         TorrentFilter::SHOW_ALL },
     127        { "show-active",      TorrentFilter::SHOW_ACTIVE },
     128        { "show-downloading", TorrentFilter::SHOW_DOWNLOADING },
     129        { "show-seeding",     TorrentFilter::SHOW_SEEDING },
     130        { "show-paused",      TorrentFilter::SHOW_PAUSED }
     131    };
     132
     133    const int showModeCount = sizeof(showModes) / sizeof(showModes[0]);
     134
     135    const struct NameAndNum sortModes[] = {
     136        { "sort-by-name",     TorrentFilter::SORT_BY_NAME },
     137        { "sort-by-activity", TorrentFilter::SORT_BY_ACTIVITY },
     138        { "sort-by-age",      TorrentFilter::SORT_BY_AGE },
     139        { "sort-by-eta",      TorrentFilter::SORT_BY_ETA },
     140        { "sort-by-progress", TorrentFilter::SORT_BY_PROGRESS },
     141        { "sort-by-ratio",    TorrentFilter::SORT_BY_RATIO },
     142        { "sort-by-size",     TorrentFilter::SORT_BY_SIZE },
     143        { "sort-by-state",    TorrentFilter::SORT_BY_STATE },
     144        { "sort-by-tracker",  TorrentFilter::SORT_BY_TRACKER }
     145    };
     146
     147    const int sortModeCount = sizeof(sortModes) / sizeof(sortModes[0]);
     148
     149    int getNum( const struct NameAndNum * rows, int numRows, const QString& name )
     150    {
     151        for( int i=0; i<numRows; ++i )
     152            if( name == rows[i].name )
     153                return rows[i].num;
     154        return rows[0].num; // fallback value
     155    }
     156
     157    const char* getName( const struct NameAndNum * rows, int numRows, int num )
     158    {
     159        for( int i=0; i<numRows; ++i )
     160            if( num == rows[i].num )
     161                return rows[i].name;
     162        return rows[0].name; // fallback value
     163    }
     164}
     165
     166TorrentFilter :: ShowMode
     167TorrentFilter :: getShowModeFromName( const QString& key ) const
     168{
     169    return ShowMode( getNum( showModes, showModeCount, key ) );
     170}
     171
    116172const char*
    117 TorrentFilter :: getSortKey( int modeIn )
    118 {
    119     switch( modeIn < 0 ? getSortMode( ) : SortMode( modeIn ) )
    120     {
    121         case SORT_BY_ACTIVITY: return "sort-by-activity";
    122         case SORT_BY_AGE:      return "sort-by-age";
    123         case SORT_BY_ETA:      return "sort-by-eta";
    124         case SORT_BY_PROGRESS: return "sort-by-progress";
    125         case SORT_BY_RATIO:    return "sort-by-ratio";
    126         case SORT_BY_SIZE:     return "sort-by-size";
    127         case SORT_BY_STATE:    return "sort-by-state";
    128         case SORT_BY_TRACKER:  return "sort-by-tracker";
    129         default:               return "sort-by-name";
    130     }
    131 }
     173TorrentFilter :: getShowName( int mode ) const
     174{
     175    if( mode < 0 ) mode = getShowMode( );
     176    return getName( showModes, showModeCount, mode );
     177}
     178
     179TorrentFilter :: SortMode
     180TorrentFilter :: getSortModeFromName( const QString& key ) const
     181{
     182    return SortMode( getNum( sortModes, sortModeCount, key ) );
     183}
     184
     185const char*
     186TorrentFilter :: getSortName( int mode ) const
     187{
     188    if( mode < 0 ) mode = getSortMode( );
     189    return getName( sortModes, sortModeCount, mode );
     190}
     191
     192/***
     193****
     194***/
    132195
    133196void
     
    153216    if( mySortMode != sortMode )
    154217    {
    155         myPrefs.set( Prefs :: SORT_MODE, getSortKey( sortMode ) );
     218        myPrefs.set( Prefs :: SORT_MODE, getSortName( sortMode ) );
    156219        mySortMode = SortMode( sortMode );
    157220        setDynamicSortFilter ( true );
  • trunk/qt/torrent-filter.h

    r8188 r8194  
    1717
    1818struct Prefs;
     19struct QString;
    1920
    2021class TorrentFilter: public QSortFilterProxyModel
     
    2930        enum ShowMode { SHOW_ALL, SHOW_ACTIVE, SHOW_DOWNLOADING, SHOW_SEEDING, SHOW_PAUSED };
    3031        ShowMode getShowMode( ) const { return myShowMode; }
     32        ShowMode getShowModeFromName( const QString& name ) const;
     33        const char * getShowName( int mode=-1 ) const;
    3134
    3235        enum TextMode { FILTER_BY_NAME, FILTER_BY_FILES, FILTER_BY_TRACKER };
     
    3639                       SORT_BY_PROGRESS, SORT_BY_RATIO, SORT_BY_SIZE,
    3740                       SORT_BY_STATE, SORT_BY_TRACKER, SORT_BY_ID };
    38         const char * getSortKey( int mode=-1 );
    3941        SortMode getSortMode( ) const { return mySortMode; }
     42        SortMode getSortModeFromName( const QString& name) const;
     43        const char * getSortName( int mode=-1 ) const;
    4044
    4145        bool isAscending( ) const { return myIsAscending; }
Note: See TracChangeset for help on using the changeset viewer.