@ -47,6 +47,10 @@ FinishedTorrents::FinishedTorrents(QObject *parent, bittorrent *BTSession){
@@ -47,6 +47,10 @@ FinishedTorrents::FinishedTorrents(QObject *parent, bittorrent *BTSession){
if ( ! loadColWidthFinishedList ( ) ) {
finishedList - > header ( ) - > resizeSection ( 0 , 200 ) ;
}
// Make download list header clickable for sorting
finishedList - > header ( ) - > setClickable ( true ) ;
finishedList - > header ( ) - > setSortIndicatorShown ( true ) ;
connect ( finishedList - > header ( ) , SIGNAL ( sectionPressed ( int ) ) , this , SLOT ( sortFinishedList ( int ) ) ) ;
finishedListDelegate = new DLListDelegate ( ) ;
finishedList - > setItemDelegate ( finishedListDelegate ) ;
connect ( finishedList , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayFinishedListMenu ( const QPoint & ) ) ) ;
@ -111,6 +115,75 @@ void FinishedTorrents::setRowColor(int row, const QString& color){
@@ -111,6 +115,75 @@ void FinishedTorrents::setRowColor(int row, const QString& color){
}
}
void FinishedTorrents : : sortFinishedList ( int index ) {
static Qt : : SortOrder sortOrder = Qt : : AscendingOrder ;
if ( finishedList - > header ( ) - > sortIndicatorSection ( ) = = index ) {
if ( sortOrder = = Qt : : AscendingOrder ) {
sortOrder = Qt : : DescendingOrder ;
} else {
sortOrder = Qt : : AscendingOrder ;
}
}
finishedList - > header ( ) - > setSortIndicator ( index , sortOrder ) ;
switch ( index ) {
case SIZE :
case ETA :
case UPSPEED :
case DLSPEED :
case PROGRESS :
sortFinishedListFloat ( index , sortOrder ) ;
break ;
default :
sortFinishedListString ( index , sortOrder ) ;
}
}
void FinishedTorrents : : sortFinishedListFloat ( int index , Qt : : SortOrder sortOrder ) {
QList < QPair < int , double > > lines ;
// insertion sorting
unsigned int nbRows = finishedListModel - > rowCount ( ) ;
for ( unsigned int i = 0 ; i < nbRows ; + + i ) {
misc : : insertSort ( lines , QPair < int , double > ( i , finishedListModel - > data ( finishedListModel - > index ( i , index ) ) . toDouble ( ) ) , sortOrder ) ;
}
// Insert items in new model, in correct order
unsigned int nbRows_old = lines . size ( ) ;
for ( unsigned int row = 0 ; row < nbRows_old ; + + row ) {
finishedListModel - > insertRow ( finishedListModel - > rowCount ( ) ) ;
unsigned int sourceRow = lines [ row ] . first ;
unsigned int nbColumns = finishedListModel - > columnCount ( ) ;
for ( unsigned int col = 0 ; col < nbColumns ; + + col ) {
finishedListModel - > setData ( finishedListModel - > index ( nbRows_old + row , col ) , finishedListModel - > data ( finishedListModel - > index ( sourceRow , col ) ) ) ;
finishedListModel - > setData ( finishedListModel - > index ( nbRows_old + row , col ) , finishedListModel - > data ( finishedListModel - > index ( sourceRow , col ) , Qt : : DecorationRole ) , Qt : : DecorationRole ) ;
finishedListModel - > setData ( finishedListModel - > index ( nbRows_old + row , col ) , finishedListModel - > data ( finishedListModel - > index ( sourceRow , col ) , Qt : : TextColorRole ) , Qt : : TextColorRole ) ;
}
}
// Remove old rows
finishedListModel - > removeRows ( 0 , nbRows_old ) ;
}
void FinishedTorrents : : sortFinishedListString ( int index , Qt : : SortOrder sortOrder ) {
QList < QPair < int , QString > > lines ;
// Insertion sorting
unsigned int nbRows = finishedListModel - > rowCount ( ) ;
for ( unsigned int i = 0 ; i < nbRows ; + + i ) {
misc : : insertSortString ( lines , QPair < int , QString > ( i , finishedListModel - > data ( finishedListModel - > index ( i , index ) ) . toString ( ) ) , sortOrder ) ;
}
// Insert items in new model, in correct order
unsigned int nbRows_old = lines . size ( ) ;
for ( unsigned int row = 0 ; row < nbRows_old ; + + row ) {
finishedListModel - > insertRow ( finishedListModel - > rowCount ( ) ) ;
unsigned int sourceRow = lines [ row ] . first ;
unsigned int nbColumns = finishedListModel - > columnCount ( ) ;
for ( unsigned int col = 0 ; col < nbColumns ; + + col ) {
finishedListModel - > setData ( finishedListModel - > index ( nbRows_old + row , col ) , finishedListModel - > data ( finishedListModel - > index ( sourceRow , col ) ) ) ;
finishedListModel - > setData ( finishedListModel - > index ( nbRows_old + row , col ) , finishedListModel - > data ( finishedListModel - > index ( sourceRow , col ) , Qt : : DecorationRole ) , Qt : : DecorationRole ) ;
finishedListModel - > setData ( finishedListModel - > index ( nbRows_old + row , col ) , finishedListModel - > data ( finishedListModel - > index ( sourceRow , col ) , Qt : : TextColorRole ) , Qt : : TextColorRole ) ;
}
}
// Remove old rows
finishedListModel - > removeRows ( 0 , nbRows_old ) ;
}
// Load columns width in a file that were saved previously
// (finished list)
bool FinishedTorrents : : loadColWidthFinishedList ( ) {