Changeset 8216
- Timestamp:
- Apr 11, 2009, 6:25:12 PM (14 years ago)
- Location:
- trunk/qt
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/qt/mainwin.cc
r8194 r8216 22 22 #include <QSystemTrayIcon> 23 23 #include <QUrl> 24 #include <QSignalMapper> 24 25 25 26 #include "about.h" 26 27 #include "details.h" 28 #include "filters.h" 27 29 #include "mainwin.h" 28 30 #include "make-dialog.h" … … 140 142 141 143 // ui signals 142 // ccc143 144 connect( ui.action_Toolbar, SIGNAL(toggled(bool)), this, SLOT(setToolbarVisible(bool))); 144 145 connect( ui.action_TrayIcon, SIGNAL(toggled(bool)), this, SLOT(setTrayIconVisible(bool))); … … 146 147 connect( ui.action_Statusbar, SIGNAL(toggled(bool)), this, SLOT(setStatusbarVisible(bool))); 147 148 connect( ui.action_MinimalView, SIGNAL(toggled(bool)), this, SLOT(setMinimalView(bool))); 148 connect( ui.action_SortByActivity, SIGNAL(toggled(bool)), &myFilterModel, SLOT(sortByActivity()));149 connect( ui.action_SortByAge, SIGNAL(toggled(bool)), &myFilterModel, SLOT(sortByAge()));150 connect( ui.action_SortByETA, SIGNAL(toggled(bool)), &myFilterModel, SLOT(sortByETA()));151 connect( ui.action_SortByName, SIGNAL(toggled(bool)), &myFilterModel, SLOT(sortByName()));152 connect( ui.action_SortByProgress, SIGNAL(toggled(bool)), &myFilterModel, SLOT(sortByProgress()));153 connect( ui.action_SortByRatio, SIGNAL(toggled(bool)), &myFilterModel, SLOT(sortByRatio()));154 connect( ui.action_SortBySize, SIGNAL(toggled(bool)), &myFilterModel, SLOT(sortBySize()));155 connect( ui.action_SortByState, SIGNAL(toggled(bool)), &myFilterModel, SLOT(sortByState()));156 connect( ui.action_SortByTracker, SIGNAL(toggled(bool)), &myFilterModel, SLOT(sortByTracker()));157 connect( ui.action_ReverseSortOrder, SIGNAL(toggled(bool)), &myFilterModel, SLOT(setAscending(bool)));149 connect( ui.action_SortByActivity, SIGNAL(toggled(bool)), this, SLOT(onSortByActivityToggled(bool))); 150 connect( ui.action_SortByAge, SIGNAL(toggled(bool)), this, SLOT(onSortByAgeToggled(bool))); 151 connect( ui.action_SortByETA, SIGNAL(toggled(bool)), this, SLOT(onSortByETAToggled(bool))); 152 connect( ui.action_SortByName, SIGNAL(toggled(bool)), this, SLOT(onSortByNameToggled(bool))); 153 connect( ui.action_SortByProgress, SIGNAL(toggled(bool)), this, SLOT(onSortByProgressToggled(bool))); 154 connect( ui.action_SortByRatio, SIGNAL(toggled(bool)), this, SLOT(onSortByRatioToggled(bool))); 155 connect( ui.action_SortBySize, SIGNAL(toggled(bool)), this, SLOT(onSortBySizeToggled(bool))); 156 connect( ui.action_SortByState, SIGNAL(toggled(bool)), this, SLOT(onSortByStateToggled(bool))); 157 connect( ui.action_SortByTracker, SIGNAL(toggled(bool)), this, SLOT(onSortByTrackerToggled(bool))); 158 connect( ui.action_ReverseSortOrder, SIGNAL(toggled(bool)), this, SLOT(setSortAscendingPref(bool))); 158 159 connect( ui.action_Start, SIGNAL(triggered()), this, SLOT(startSelected())); 159 160 connect( ui.action_Pause, SIGNAL(triggered()), this, SLOT(pauseSelected())); … … 205 206 setTextButtonSizeHint( ui.filterSeeding ); 206 207 setTextButtonSizeHint( ui.filterPaused ); 207 setShowMode( myFilterModel.getShowMode( ) );208 208 209 209 connect( &myFilterModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(refreshVisibleCount())); … … 321 321 322 322 void 323 TrMainWindow :: setSortPref( int i ) 324 { 325 myPrefs.set( Prefs::SORT_MODE, SortMode( i ) ); 326 } 327 void TrMainWindow :: onSortByActivityToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_ACTIVITY ); } 328 void TrMainWindow :: onSortByAgeToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_AGE ); } 329 void TrMainWindow :: onSortByETAToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_ETA ); } 330 void TrMainWindow :: onSortByNameToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_NAME ); } 331 void TrMainWindow :: onSortByProgressToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_PROGRESS ); } 332 void TrMainWindow :: onSortByRatioToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_RATIO ); } 333 void TrMainWindow :: onSortBySizeToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_SIZE ); } 334 void TrMainWindow :: onSortByStateToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_STATE ); } 335 void TrMainWindow :: onSortByTrackerToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_TRACKER ); } 336 337 void 338 TrMainWindow :: setSortAscendingPref( bool b ) 339 { 340 myPrefs.set( Prefs::SORT_REVERSED, b ); 341 } 342 343 /**** 344 ***** 345 ****/ 346 347 void 323 348 TrMainWindow :: openProperties( ) 324 349 { … … 512 537 **/ 513 538 514 void 515 TrMainWindow :: setShowMode( TorrentFilter :: ShowMode mode ) 516 { 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 ); 522 523 myFilterModel.setShowMode( mode ); 524 } 525 526 void TrMainWindow :: showAll ( ) { setShowMode( TorrentFilter :: SHOW_ALL ); } 527 void TrMainWindow :: showActive ( ) { setShowMode( TorrentFilter :: SHOW_ACTIVE ); } 528 void TrMainWindow :: showDownloading ( ) { setShowMode( TorrentFilter :: SHOW_DOWNLOADING ); } 529 void TrMainWindow :: showSeeding ( ) { setShowMode( TorrentFilter :: SHOW_SEEDING ); } 530 void TrMainWindow :: showPaused ( ) { setShowMode( TorrentFilter :: SHOW_PAUSED ); } 539 void TrMainWindow :: setShowMode ( int i ) { myPrefs.set( Prefs::FILTER_MODE, FilterMode( i ) ); } 540 void TrMainWindow :: showAll ( ) { setShowMode( FilterMode :: SHOW_ALL ); } 541 void TrMainWindow :: showActive ( ) { setShowMode( FilterMode :: SHOW_ACTIVE ); } 542 void TrMainWindow :: showDownloading ( ) { setShowMode( FilterMode :: SHOW_DOWNLOADING ); } 543 void TrMainWindow :: showSeeding ( ) { setShowMode( FilterMode :: SHOW_SEEDING ); } 544 void TrMainWindow :: showPaused ( ) { setShowMode( FilterMode :: SHOW_PAUSED ); } 531 545 532 546 void TrMainWindow :: filterByName ( ) { myFilterModel.setTextMode( TorrentFilter :: FILTER_BY_NAME ); } … … 534 548 void TrMainWindow :: filterByFiles ( ) { myFilterModel.setTextMode( TorrentFilter :: FILTER_BY_FILES ); } 535 549 536 void 537 TrMainWindow :: showTotalRatio( ) 538 { 539 myPrefs.set( Prefs::STATUSBAR_STATS, "total-ratio" ); 540 } 541 void 542 TrMainWindow :: showTotalTransfer( ) 543 { 544 myPrefs.set( Prefs::STATUSBAR_STATS, "total-transfer" ); 545 } 546 void 547 TrMainWindow :: showSessionRatio( ) 548 { 549 myPrefs.set( Prefs::STATUSBAR_STATS, "session-ratio" ); 550 } 551 void 552 TrMainWindow :: showSessionTransfer( ) 553 { 554 myPrefs.set( Prefs::STATUSBAR_STATS, "session-transfer" ); 555 } 550 void TrMainWindow :: showTotalRatio ( ) { myPrefs.set( Prefs::STATUSBAR_STATS, "total-ratio"); } 551 void TrMainWindow :: showTotalTransfer ( ) { myPrefs.set( Prefs::STATUSBAR_STATS, "total-transfer"); } 552 void TrMainWindow :: showSessionRatio ( ) { myPrefs.set( Prefs::STATUSBAR_STATS, "session-ratio"); } 553 void TrMainWindow :: showSessionTransfer ( ) { myPrefs.set( Prefs::STATUSBAR_STATS, "session-transfer"); } 556 554 557 555 /** … … 631 629 632 630 case Prefs::SORT_MODE: 633 i = my FilterModel.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 );631 i = myPrefs.get<SortMode>(key).mode( ); 632 ui.action_SortByActivity->setChecked ( i == SortMode::SORT_BY_ACTIVITY ); 633 ui.action_SortByAge->setChecked ( i == SortMode::SORT_BY_AGE ); 634 ui.action_SortByETA->setChecked ( i == SortMode::SORT_BY_ETA ); 635 ui.action_SortByName->setChecked ( i == SortMode::SORT_BY_NAME ); 636 ui.action_SortByProgress->setChecked ( i == SortMode::SORT_BY_PROGRESS ); 637 ui.action_SortByRatio->setChecked ( i == SortMode::SORT_BY_RATIO ); 638 ui.action_SortBySize->setChecked ( i == SortMode::SORT_BY_SIZE ); 639 ui.action_SortByState->setChecked ( i == SortMode::SORT_BY_STATE ); 640 ui.action_SortByTracker->setChecked ( i == SortMode::SORT_BY_TRACKER ); 643 641 break; 644 642 645 643 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 644 i = myPrefs.get<FilterMode>(key).mode( ); 645 ui.filterAll->setChecked ( i == FilterMode::SHOW_ALL ); 646 ui.filterActive->setChecked ( i == FilterMode::SHOW_ACTIVE ); 647 ui.filterDownloading->setChecked ( i == FilterMode::SHOW_DOWNLOADING ); 648 ui.filterSeeding->setChecked ( i == FilterMode::SHOW_SEEDING ); 649 ui.filterPaused->setChecked ( i == FilterMode::SHOW_PAUSED ); 650 break; 654 651 655 652 case Prefs::FILTERBAR: -
trunk/qt/mainwin.h
r8188 r8216 69 69 70 70 private: 71 void setShowMode( TorrentFilter::ShowMode);71 void setShowMode( int ); 72 72 QSet<int> getSelectedTorrents( ) const; 73 73 void updateNetworkIcon( ); … … 102 102 void toggleWindows( ); 103 103 104 private slots: 105 void setSortPref( int ); 106 void setSortAscendingPref( bool ); 107 void onSortByActivityToggled ( bool b ); 108 void onSortByAgeToggled ( bool b ); 109 void onSortByETAToggled ( bool b ); 110 void onSortByNameToggled ( bool b ); 111 void onSortByProgressToggled ( bool b ); 112 void onSortByRatioToggled ( bool b ); 113 void onSortBySizeToggled ( bool b ); 114 void onSortByStateToggled ( bool b ); 115 void onSortByTrackerToggled ( bool b ); 116 117 104 118 public slots: 105 119 void startAll( ); -
trunk/qt/prefs-dialog.cc
r8211 r8216 172 172 { 173 173 const int key( sender()->property( PREF_KEY ).toInt( ) ); 174 myPrefs.set( key, qPrintable(text));174 myPrefs.set( key, text ); 175 175 } 176 176 -
trunk/qt/prefs.cc
r8197 r8216 23 23 #include <libtransmission/utils.h> 24 24 #include "prefs.h" 25 #include "types.h" 25 26 26 27 /*** … … 41 42 { TRASH_ORIGINAL, "trash-original-torrent-files", QVariant::Bool }, 42 43 { ASKQUIT, "prompt-before-exit", QVariant::Bool }, 43 { SORT_MODE, "sort-mode", QVariant::String},44 { SORT_MODE, "sort-mode", TrTypes::SortModeType }, 44 45 { SORT_REVERSED, "sort-reversed", QVariant::Bool }, 45 46 { MINIMAL_VIEW, "minimal-view", QVariant::Bool }, … … 55 56 { MAIN_WINDOW_X, "main-window-x", QVariant::Int }, 56 57 { MAIN_WINDOW_Y, "main-window-y", QVariant::Int }, 57 { FILTER_MODE, "filter-mode", QVariant::String},58 { FILTER_MODE, "filter-mode", TrTypes::FilterModeType }, 58 59 59 60 /* libtransmission settings */ … … 135 136 myValues[i].setValue( qlonglong(intVal) ); 136 137 break; 138 case TrTypes::SortModeType: 139 if( tr_bencGetStr( b, &str ) ) 140 myValues[i] = QVariant::fromValue( SortMode( str ) ); 141 break; 142 case TrTypes::FilterModeType: 143 if( tr_bencGetStr( b, &str ) ) 144 myValues[i] = QVariant::fromValue( FilterMode( str ) ); 145 break; 137 146 case QVariant::String: 138 147 if( tr_bencGetStr( b, &str ) ) … … 179 188 case QVariant::Int: 180 189 tr_bencDictAddInt( &top, key, val.toInt() ); 190 break; 191 case TrTypes::SortModeType: 192 tr_bencDictAddStr( &top, key, val.value<SortMode>().name().toUtf8().constData() ); 193 break; 194 case TrTypes::FilterModeType: 195 tr_bencDictAddStr( &top, key, val.value<FilterMode>().name().toUtf8().constData() ); 181 196 break; 182 197 case QVariant::String: -
trunk/qt/prefs.h
r8194 r8216 21 21 #include <libtransmission/transmission.h> 22 22 #include <libtransmission/bencode.h> 23 24 #include "filters.h" 23 25 24 26 class Prefs: public QObject … … 115 117 int id; 116 118 const char * key; 117 QVariant::Typetype;119 int type; 118 120 }; 119 121 … … 129 131 bool isClient( int key ) const { return !isCore( key ); } 130 132 const char * keyStr( int i ) const { return myItems[i].key; } 131 QVariant::Typetype( int i ) const { return myItems[i].type; }133 int type( int i ) const { return myItems[i].type; } 132 134 const QVariant& variant( int i ) const { return myValues[i]; } 133 135 … … 141 143 QDateTime getDateTime( int key ) const; 142 144 145 template<typename T> T get( int key ) const { 146 return myValues[key].value<T>(); 147 } 148 149 void set( int key, char * value ) { set( key, QString::fromUtf8(value) ); } 150 void set( int key, const char * value ) { set( key, QString::fromUtf8(value) ); } 151 143 152 template<typename T> void set( int key, const T& value ) { 144 153 QVariant& v( myValues[key] ); 145 const QVariant tmp ( value);154 const QVariant tmp = QVariant::fromValue(value); 146 155 if( v.isNull() || (v!=tmp) ) { 147 156 v = tmp; -
trunk/qt/qtransmission.pro
r8188 r8216 21 21 details.h \ 22 22 file-tree.h \ 23 filters.h \ 23 24 hig.h \ 24 25 mainwin.h \ … … 45 46 details.cc \ 46 47 file-tree.cc \ 48 filters.cc \ 47 49 hig.cc \ 48 50 mainwin.cc \ -
trunk/qt/session.cc
r8196 r8216 658 658 break; 659 659 } 660 case TrTypes :: FilterModeType: 661 case TrTypes :: SortModeType: 660 662 case QVariant :: String: { 661 663 const char * val; -
trunk/qt/torrent-filter.cc
r8213 r8216 13 13 #include <iostream> 14 14 15 #include "filters.h" 15 16 #include "prefs.h" 16 17 #include "torrent.h" … … 20 21 TorrentFilter :: TorrentFilter( Prefs& prefs ): 21 22 myPrefs( prefs ), 22 myShowMode( getShowModeFromName( prefs.getString( Prefs::FILTER_MODE ) ) ), 23 myTextMode( FILTER_BY_NAME ), 24 mySortMode( getSortModeFromName( prefs.getString( Prefs::SORT_MODE ) ) ), 25 myIsAscending( prefs.getBool( Prefs::SORT_REVERSED ) ) 23 myTextMode( FILTER_BY_NAME ) 26 24 { 27 resort( ); 25 // listen for changes to the preferences to know when to refilter / resort 26 connect( &myPrefs, SIGNAL(changed(int)), this, SLOT(refreshPref(int))); 27 28 // initialize our state from the current prefs 29 QList<int> initKeys; 30 initKeys << Prefs :: SORT_MODE 31 << Prefs :: FILTER_MODE; 32 foreach( int key, initKeys ) 33 refreshPref( key ); 28 34 } 29 35 30 36 TorrentFilter :: ~TorrentFilter( ) 31 37 { 38 } 39 40 void 41 TorrentFilter :: refreshPref( int key ) 42 { 43 switch( key ) 44 { 45 case Prefs :: SORT_MODE: 46 case Prefs :: SORT_REVERSED: 47 sort( 0, myPrefs.getBool(Prefs::SORT_REVERSED) ? Qt::AscendingOrder : Qt::DescendingOrder ); 48 invalidate( ); 49 break; 50 case Prefs :: FILTER_MODE: 51 invalidateFilter( ); 52 break; 53 } 32 54 } 33 55 … … 37 59 38 60 void 39 TorrentFilter :: set ShowMode( int showMode)61 TorrentFilter :: setTextMode( int i ) 40 62 { 41 if( my ShowMode != showMode)63 if( myTextMode != i ) 42 64 { 43 myPrefs.set( Prefs :: FILTER_MODE, getShowName( showMode ) ); 44 myShowMode = ShowMode( showMode ); 45 invalidateFilter( ); 46 } 47 } 48 49 void 50 TorrentFilter :: setTextMode( int textMode ) 51 { 52 if( myTextMode != textMode ) 53 { 54 myTextMode = TextMode( textMode ); 65 myTextMode = TextMode( i ); 55 66 invalidateFilter( ); 56 67 } … … 69 80 } 70 81 82 /*** 83 **** 84 ***/ 85 86 bool 87 TorrentFilter :: lessThan( const QModelIndex& left, const QModelIndex& right ) const 88 { 89 const Torrent * a = sourceModel()->data( left, TorrentModel::TorrentRole ).value<const Torrent*>(); 90 const Torrent * b = sourceModel()->data( right, TorrentModel::TorrentRole ).value<const Torrent*>(); 91 bool less; 92 93 switch( myPrefs.get<SortMode>(Prefs::SORT_MODE).mode() ) 94 { 95 case SortMode :: SORT_BY_SIZE: 96 less = a->sizeWhenDone() < b->sizeWhenDone(); 97 break; 98 case SortMode :: SORT_BY_ACTIVITY: 99 less = a->downloadSpeed() + a->uploadSpeed() < b->downloadSpeed() + b->uploadSpeed(); 100 break; 101 case SortMode :: SORT_BY_AGE: 102 less = a->dateAdded() < b->dateAdded(); 103 break; 104 case SortMode :: SORT_BY_ID: 105 less = a->id() < b->id(); 106 break; 107 case SortMode :: SORT_BY_RATIO: 108 less = a->compareRatio( *b ) < 0; 109 break; 110 case SortMode :: SORT_BY_PROGRESS: 111 less = a->percentDone() < b->percentDone(); 112 break; 113 case SortMode :: SORT_BY_ETA: 114 less = a->compareETA( *b ) < 0; 115 break; 116 case SortMode :: SORT_BY_STATE: 117 if( a->hasError() != b->hasError() ) 118 less = a->hasError(); 119 else 120 less = a->getActivity() < b->getActivity(); 121 break; 122 case SortMode :: SORT_BY_TRACKER: 123 less = a->compareTracker( *b ) < 0; 124 break; 125 default: 126 less = a->name().compare( b->name(), Qt::CaseInsensitive ) > 0; 127 break; 128 } 129 130 return less; 131 } 132 133 134 /*** 135 **** 136 ***/ 137 71 138 bool 72 139 TorrentFilter :: filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const … … 77 144 bool accepts; 78 145 79 switch( my ShowMode)146 switch( myPrefs.get<FilterMode>(Prefs::FILTER_MODE).mode() ) 80 147 { 81 case SHOW_ALL:148 case FilterMode::SHOW_ALL: 82 149 accepts = true; 83 150 break; 84 case SHOW_ACTIVE:151 case FilterMode::SHOW_ACTIVE: 85 152 accepts = tor->peersWeAreUploadingTo( ) > 0 || tor->peersWeAreDownloadingFrom( ) > 0 || tor->isVerifying( ); 86 153 break; 87 case SHOW_DOWNLOADING:154 case FilterMode::SHOW_DOWNLOADING: 88 155 accepts = activity == TR_STATUS_DOWNLOAD; 89 156 break; 90 case SHOW_SEEDING:157 case FilterMode::SHOW_SEEDING: 91 158 accepts = activity == TR_STATUS_SEED; 92 159 break; 93 case SHOW_PAUSED:160 case FilterMode::SHOW_PAUSED: 94 161 accepts = activity == TR_STATUS_STOPPED; 95 162 break; … … 112 179 } 113 180 114 /***115 ****116 ***/117 118 namespace119 {120 struct NameAndNum121 {122 const char * name;123 int num;124 };125 126 const struct NameAndNum showModes[] = {127 { "show-all", TorrentFilter::SHOW_ALL },128 { "show-active", TorrentFilter::SHOW_ACTIVE },129 { "show-downloading", TorrentFilter::SHOW_DOWNLOADING },130 { "show-seeding", TorrentFilter::SHOW_SEEDING },131 { "show-paused", TorrentFilter::SHOW_PAUSED }132 };133 134 const int showModeCount = sizeof(showModes) / sizeof(showModes[0]);135 136 const struct NameAndNum sortModes[] = {137 { "sort-by-name", TorrentFilter::SORT_BY_NAME },138 { "sort-by-activity", TorrentFilter::SORT_BY_ACTIVITY },139 { "sort-by-age", TorrentFilter::SORT_BY_AGE },140 { "sort-by-eta", TorrentFilter::SORT_BY_ETA },141 { "sort-by-progress", TorrentFilter::SORT_BY_PROGRESS },142 { "sort-by-ratio", TorrentFilter::SORT_BY_RATIO },143 { "sort-by-size", TorrentFilter::SORT_BY_SIZE },144 { "sort-by-state", TorrentFilter::SORT_BY_STATE },145 { "sort-by-tracker", TorrentFilter::SORT_BY_TRACKER }146 };147 148 const int sortModeCount = sizeof(sortModes) / sizeof(sortModes[0]);149 150 int getNum( const struct NameAndNum * rows, int numRows, const QString& name )151 {152 for( int i=0; i<numRows; ++i )153 if( name == rows[i].name )154 return rows[i].num;155 return rows[0].num; // fallback value156 }157 158 const char* getName( const struct NameAndNum * rows, int numRows, int num )159 {160 for( int i=0; i<numRows; ++i )161 if( num == rows[i].num )162 return rows[i].name;163 return rows[0].name; // fallback value164 }165 }166 167 TorrentFilter :: ShowMode168 TorrentFilter :: getShowModeFromName( const QString& key ) const169 {170 return ShowMode( getNum( showModes, showModeCount, key ) );171 }172 173 const char*174 TorrentFilter :: getShowName( int mode ) const175 {176 if( mode < 0 ) mode = getShowMode( );177 return getName( showModes, showModeCount, mode );178 }179 180 TorrentFilter :: SortMode181 TorrentFilter :: getSortModeFromName( const QString& key ) const182 {183 return SortMode( getNum( sortModes, sortModeCount, key ) );184 }185 186 const char*187 TorrentFilter :: getSortName( int mode ) const188 {189 if( mode < 0 ) mode = getSortMode( );190 return getName( sortModes, sortModeCount, mode );191 }192 193 /***194 ****195 ***/196 197 void198 TorrentFilter :: resort( )199 {200 invalidate( );201 sort( 0, myIsAscending ? Qt::AscendingOrder : Qt::DescendingOrder );202 }203 204 void205 TorrentFilter :: setAscending( bool b )206 {207 if( myIsAscending != b )208 {209 myIsAscending = b;210 resort( );211 }212 }213 214 void215 TorrentFilter :: setSortMode( int sortMode )216 {217 if( mySortMode != sortMode )218 {219 myPrefs.set( Prefs :: SORT_MODE, getSortName( sortMode ) );220 mySortMode = SortMode( sortMode );221 setDynamicSortFilter ( true );222 resort( );223 }224 }225 226 void TorrentFilter :: sortByActivity ( ) { setSortMode( SORT_BY_ACTIVITY ); }227 void TorrentFilter :: sortByAge ( ) { setSortMode( SORT_BY_AGE ); }228 void TorrentFilter :: sortByETA ( ) { setSortMode( SORT_BY_ETA ); }229 void TorrentFilter :: sortById ( ) { setSortMode( SORT_BY_ID ); }230 void TorrentFilter :: sortByName ( ) { setSortMode( SORT_BY_NAME ); }231 void TorrentFilter :: sortByProgress ( ) { setSortMode( SORT_BY_PROGRESS ); }232 void TorrentFilter :: sortByRatio ( ) { setSortMode( SORT_BY_RATIO ); }233 void TorrentFilter :: sortBySize ( ) { setSortMode( SORT_BY_SIZE ); }234 void TorrentFilter :: sortByState ( ) { setSortMode( SORT_BY_STATE ); }235 void TorrentFilter :: sortByTracker ( ) { setSortMode( SORT_BY_TRACKER ); }236 237 bool238 TorrentFilter :: lessThan( const QModelIndex& left, const QModelIndex& right ) const239 {240 const Torrent * a = sourceModel()->data( left, TorrentModel::TorrentRole ).value<const Torrent*>();241 const Torrent * b = sourceModel()->data( right, TorrentModel::TorrentRole ).value<const Torrent*>();242 bool less;243 244 switch( getSortMode( ) )245 {246 case SORT_BY_SIZE:247 less = a->sizeWhenDone() < b->sizeWhenDone();248 break;249 case SORT_BY_ACTIVITY:250 less = a->downloadSpeed() + a->uploadSpeed() < b->downloadSpeed() + b->uploadSpeed();251 break;252 case SORT_BY_AGE:253 less = a->dateAdded() < b->dateAdded();254 break;255 case SORT_BY_ID:256 less = a->id() < b->id();257 break;258 case SORT_BY_RATIO:259 less = a->compareRatio( *b ) < 0;260 break;261 case SORT_BY_PROGRESS:262 less = a->percentDone() < b->percentDone();263 break;264 case SORT_BY_ETA:265 less = a->compareETA( *b ) < 0;266 break;267 case SORT_BY_STATE:268 if( a->hasError() != b->hasError() )269 less = a->hasError();270 else271 less = a->getActivity() < b->getActivity();272 break;273 case SORT_BY_TRACKER:274 less = a->compareTracker( *b ) < 0;275 break;276 default:277 less = a->name().compare( b->name(), Qt::CaseInsensitive ) > 0;278 break;279 }280 281 return less;282 }283 284 181 int 285 182 TorrentFilter :: hiddenRowCount( ) const … … 287 184 return sourceModel()->rowCount( ) - rowCount( ); 288 185 } 289 -
trunk/qt/torrent-filter.h
r8194 r8216 15 15 16 16 #include <QSortFilterProxyModel> 17 #include <QMetaType> 18 #include <QVariant> 19 17 20 18 21 struct Prefs; … … 28 31 29 32 public: 30 enum ShowMode { SHOW_ALL, SHOW_ACTIVE, SHOW_DOWNLOADING, SHOW_SEEDING, SHOW_PAUSED };31 ShowMode getShowMode( ) const { return myShowMode; }32 ShowMode getShowModeFromName( const QString& name ) const;33 const char * getShowName( int mode=-1 ) const;34 35 33 enum TextMode { FILTER_BY_NAME, FILTER_BY_FILES, FILTER_BY_TRACKER }; 36 34 TextMode getTextMode( ) const { return myTextMode; } 37 38 enum SortMode{ SORT_BY_ACTIVITY, SORT_BY_AGE, SORT_BY_ETA, SORT_BY_NAME,39 SORT_BY_PROGRESS, SORT_BY_RATIO, SORT_BY_SIZE,40 SORT_BY_STATE, SORT_BY_TRACKER, SORT_BY_ID };41 SortMode getSortMode( ) const { return mySortMode; }42 SortMode getSortModeFromName( const QString& name) const;43 const char * getSortName( int mode=-1 ) const;44 45 bool isAscending( ) const { return myIsAscending; }46 47 35 int hiddenRowCount( ) const; 48 36 37 public slots: 38 void setTextMode( int textMode ); 39 void setText( QString ); 49 40 50 public slots: 51 void setShowMode( int showMode ); 52 void setTextMode( int textMode ); 53 void setSortMode( int sortMode ); 54 void setText( QString ); 55 void sortByActivity( ); 56 void sortByAge( ); 57 void sortByETA( ); 58 void sortById( ); 59 void sortByName( ); 60 void sortByProgress( ); 61 void sortByRatio( ); 62 void sortBySize( ); 63 void sortByState( ); 64 void sortByTracker( ); 65 void setAscending( bool ); 66 void resort( ); 41 private slots: 42 void refreshPref( int key ); 67 43 68 44 protected: … … 72 48 private: 73 49 Prefs& myPrefs; 74 ShowMode myShowMode;75 50 TextMode myTextMode; 76 SortMode mySortMode;77 bool myIsAscending;78 51 QString myText; 79 52 }; -
trunk/qt/types.h
r8188 r8216 23 23 { 24 24 PeerList = QVariant::UserType, 25 FileList 25 FileList, 26 FilterModeType, 27 SortModeType 26 28 }; 27 29 };
Note: See TracChangeset
for help on using the changeset viewer.