@ -33,7 +33,7 @@
# include <QTime>
# include <QTime>
# include <QMenu>
# include <QMenu>
DownloadingTorrents : : DownloadingTorrents ( QObject * parent , bittorrent * BTSession ) : parent ( parent ) , BTSession ( BTSession ) , delayedSorting ( false ) , nbTorrents ( 0 ) {
DownloadingTorrents : : DownloadingTorrents ( QObject * parent , bittorrent * BTSession ) : parent ( parent ) , BTSession ( BTSession ) , nbTorrents ( 0 ) {
setupUi ( this ) ;
setupUi ( this ) ;
// Setting icons
// Setting icons
actionStart - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/play.png " ) ) ) ;
actionStart - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/play.png " ) ) ) ;
@ -79,7 +79,7 @@ DownloadingTorrents::DownloadingTorrents(QObject *parent, bittorrent *BTSession)
downloadList - > header ( ) - > setSortIndicatorShown ( true ) ;
downloadList - > header ( ) - > setSortIndicatorShown ( true ) ;
// Connecting Actions to slots
// Connecting Actions to slots
connect ( downloadList , SIGNAL ( doubleClicked ( const QModelIndex & ) ) , this , SLOT ( notifyTorrentDoubleClicked ( const QModelIndex & ) ) ) ;
connect ( downloadList , SIGNAL ( doubleClicked ( const QModelIndex & ) ) , this , SLOT ( notifyTorrentDoubleClicked ( const QModelIndex & ) ) ) ;
connect ( downloadList - > header ( ) , SIGNAL ( sectionPressed ( int ) ) , this , SLOT ( sor tDownloadList( int ) ) ) ;
connect ( downloadList - > header ( ) , SIGNAL ( sectionPressed ( int ) ) , this , SLOT ( toggle DownloadListSortOrder ( int ) ) ) ;
connect ( downloadList , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayDLListMenu ( const QPoint & ) ) ) ;
connect ( downloadList , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayDLListMenu ( const QPoint & ) ) ) ;
downloadList - > header ( ) - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
downloadList - > header ( ) - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( downloadList - > header ( ) , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayDLHoSMenu ( const QPoint & ) ) ) ;
connect ( downloadList - > header ( ) , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayDLHoSMenu ( const QPoint & ) ) ) ;
@ -146,7 +146,7 @@ void DownloadingTorrents::pauseTorrent(QString hash) {
DLListModel - > setData ( DLListModel - > index ( row , NAME ) , QIcon ( QString : : fromUtf8 ( " :/Icons/skin/paused.png " ) ) , Qt : : DecorationRole ) ;
DLListModel - > setData ( DLListModel - > index ( row , NAME ) , QIcon ( QString : : fromUtf8 ( " :/Icons/skin/paused.png " ) ) , Qt : : DecorationRole ) ;
DLListModel - > setData ( DLListModel - > index ( row , SEEDSLEECH ) , QVariant ( QString : : fromUtf8 ( " 0/0 " ) ) ) ;
DLListModel - > setData ( DLListModel - > index ( row , SEEDSLEECH ) , QVariant ( QString : : fromUtf8 ( " 0/0 " ) ) ) ;
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
DLListModel - > setData ( DLListModel - > index ( row , PROGRESS ) , QVariant ( ( double ) h . progress ( ) ) ) ;
//DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)h.progress()));
setRowColor ( row , QString : : fromUtf8 ( " red " ) ) ;
setRowColor ( row , QString : : fromUtf8 ( " red " ) ) ;
}
}
@ -476,13 +476,6 @@ QStringList DownloadingTorrents::getSelectedTorrents(bool only_one) const{
return res ;
return res ;
}
}
void DownloadingTorrents : : sortProgressColumnDelayed ( ) {
if ( delayedSorting ) {
sortDownloadListFloat ( PROGRESS , delayedSortingOrder ) ;
qDebug ( " Delayed sorting of progress column " ) ;
}
}
// get information from torrent handles and
// get information from torrent handles and
// update download list accordingly
// update download list accordingly
void DownloadingTorrents : : updateDlList ( ) {
void DownloadingTorrents : : updateDlList ( ) {
@ -517,12 +510,6 @@ void DownloadingTorrents::updateDlList() {
}
}
// No need to update a paused torrent
// No need to update a paused torrent
if ( h . is_paused ( ) ) continue ;
if ( h . is_paused ( ) ) continue ;
if ( BTSession - > getTorrentsToPauseAfterChecking ( ) . indexOf ( hash ) ! = - 1 ) {
if ( ! downloadList - > isColumnHidden ( PROGRESS ) ) {
DLListModel - > setData ( DLListModel - > index ( row , PROGRESS ) , QVariant ( ( double ) h . progress ( ) ) ) ;
}
continue ;
}
// Parse download state
// Parse download state
// Setting download state
// Setting download state
switch ( h . state ( ) ) {
switch ( h . state ( ) ) {
@ -630,6 +617,7 @@ void DownloadingTorrents::addTorrent(QString hash) {
DLListModel - > setData ( DLListModel - > index ( row , HASH ) , QVariant ( hash ) ) ;
DLListModel - > setData ( DLListModel - > index ( row , HASH ) , QVariant ( hash ) ) ;
// Pause torrent if it was paused last time
// Pause torrent if it was paused last time
if ( BTSession - > isPaused ( hash ) ) {
if ( BTSession - > isPaused ( hash ) ) {
DLListModel - > setData ( DLListModel - > index ( row , PROGRESS ) , QVariant ( ( double ) BTSession - > getUncheckedTorrentProgress ( hash ) ) ) ;
DLListModel - > setData ( DLListModel - > index ( row , NAME ) , QVariant ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/paused.png " ) ) ) , Qt : : DecorationRole ) ;
DLListModel - > setData ( DLListModel - > index ( row , NAME ) , QVariant ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/paused.png " ) ) ) , Qt : : DecorationRole ) ;
setRowColor ( row , QString : : fromUtf8 ( " red " ) ) ;
setRowColor ( row , QString : : fromUtf8 ( " red " ) ) ;
} else {
} else {
@ -638,6 +626,7 @@ void DownloadingTorrents::addTorrent(QString hash) {
}
}
+ + nbTorrents ;
+ + nbTorrents ;
emit unfinishedTorrentsNumberChanged ( nbTorrents ) ;
emit unfinishedTorrentsNumberChanged ( nbTorrents ) ;
sortDownloadList ( ) ;
}
}
void DownloadingTorrents : : sortDownloadListFloat ( int index , Qt : : SortOrder sortOrder ) {
void DownloadingTorrents : : sortDownloadListFloat ( int index , Qt : : SortOrder sortOrder ) {
@ -686,27 +675,36 @@ void DownloadingTorrents::sortDownloadListString(int index, Qt::SortOrder sortOr
DLListModel - > removeRows ( 0 , nbRows_old ) ;
DLListModel - > removeRows ( 0 , nbRows_old ) ;
}
}
void DownloadingTorrents : : sortDownloadList ( int index , Qt : : SortOrder startSortOrder , bool fromLoadColWidth ) {
void DownloadingTorrents : : toggleDownloadListSortOrder ( int index ) {
qDebug ( " Called sort download list " ) ;
Qt : : SortOrder sortOrder = Qt : : AscendingOrder ;
static Qt : : SortOrder sortOrder = startSortOrder ;
qDebug ( " Toggling column sort order " ) ;
if ( ! fromLoadColWidth & & downloadList - > header ( ) - > sortIndicatorSection ( ) = = index ) {
if ( downloadList - > header ( ) - > sortIndicatorSection ( ) = = index ) {
if ( sortOrder = = Qt : : AscendingOrder ) {
sortOrder = ( Qt : : SortOrder ) ! ( bool ) downloadList - > header ( ) - > sortIndicatorOrder ( ) ;
sortOrder = Qt : : DescendingOrder ;
} else {
sortOrder = Qt : : AscendingOrder ;
}
}
switch ( index ) {
case SIZE :
case ETA :
case UPSPEED :
case DLSPEED :
case PROGRESS :
sortDownloadListFloat ( index , sortOrder ) ;
break ;
default :
sortDownloadListString ( index , sortOrder ) ;
}
}
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
QString sortOrderLetter ;
QString sortOrderLetter ;
if ( sortOrder = = Qt : : AscendingOrder )
if ( sortOrder = = Qt : : AscendingOrder )
sortOrderLetter = QString : : fromUtf8 ( " a " ) ;
sortOrderLetter = QString : : fromUtf8 ( " a " ) ;
else
else
sortOrderLetter = QString : : fromUtf8 ( " d " ) ;
sortOrderLetter = QString : : fromUtf8 ( " d " ) ;
if ( fromLoadColWidth ) {
settings . setValue ( QString : : fromUtf8 ( " DownloadListSortedCol " ) , misc : : toQString ( index ) + sortOrderLetter ) ;
// XXX: Why is this needed?
}
if ( sortOrder = = Qt : : DescendingOrder )
downloadList - > header ( ) - > setSortIndicator ( index , Qt : : AscendingOrder ) ;
void DownloadingTorrents : : sortDownloadList ( int index , Qt : : SortOrder sortOrder ) {
else
if ( index = = - 1 ) {
downloadList - > header ( ) - > setSortIndicator ( index , Qt : : DescendingOrder ) ;
index = downloadList - > header ( ) - > sortIndicatorSection ( ) ;
sortOrder = downloadList - > header ( ) - > sortIndicatorOrder ( ) ;
} else {
} else {
downloadList - > header ( ) - > setSortIndicator ( index , sortOrder ) ;
downloadList - > header ( ) - > setSortIndicator ( index , sortOrder ) ;
}
}
@ -716,23 +714,12 @@ void DownloadingTorrents::sortDownloadList(int index, Qt::SortOrder startSortOrd
case UPSPEED :
case UPSPEED :
case DLSPEED :
case DLSPEED :
case PRIORITY :
case PRIORITY :
sortDownloadListFloat ( index , sortOrder ) ;
break ;
case PROGRESS :
case PROGRESS :
if ( fromLoadColWidth ) {
// Progress sorting must be delayed until files are checked (on startup)
delayedSorting = true ;
qDebug ( " Delayed sorting of the progress column " ) ;
delayedSortingOrder = sortOrder ;
} else {
sortDownloadListFloat ( index , sortOrder ) ;
sortDownloadListFloat ( index , sortOrder ) ;
}
break ;
break ;
default :
default :
sortDownloadListString ( index , sortOrder ) ;
sortDownloadListString ( index , sortOrder ) ;
}
}
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
settings . setValue ( QString : : fromUtf8 ( " DownloadListSortedCol " ) , misc : : toQString ( index ) + sortOrderLetter ) ;
}
}
// Save columns width in a file to remember them
// Save columns width in a file to remember them
@ -781,7 +768,14 @@ bool DownloadingTorrents::loadColWidthDLList() {
for ( unsigned int i = 0 ; i < listSize ; + + i ) {
for ( unsigned int i = 0 ; i < listSize ; + + i ) {
downloadList - > header ( ) - > resizeSection ( i , width_list . at ( i ) . toInt ( ) ) ;
downloadList - > header ( ) - > resizeSection ( i , width_list . at ( i ) . toInt ( ) ) ;
}
}
loadLastSortedColumn ( ) ;
qDebug ( " Download list columns width loaded " ) ;
return true ;
}
void DownloadingTorrents : : loadLastSortedColumn ( ) {
// Loading last sorted column
// Loading last sorted column
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
QString sortedCol = settings . value ( QString : : fromUtf8 ( " DownloadListSortedCol " ) , QString ( ) ) . toString ( ) ;
QString sortedCol = settings . value ( QString : : fromUtf8 ( " DownloadListSortedCol " ) , QString ( ) ) . toString ( ) ;
if ( ! sortedCol . isEmpty ( ) ) {
if ( ! sortedCol . isEmpty ( ) ) {
Qt : : SortOrder sortOrder ;
Qt : : SortOrder sortOrder ;
@ -791,10 +785,8 @@ bool DownloadingTorrents::loadColWidthDLList() {
sortOrder = Qt : : AscendingOrder ;
sortOrder = Qt : : AscendingOrder ;
sortedCol = sortedCol . left ( sortedCol . size ( ) - 1 ) ;
sortedCol = sortedCol . left ( sortedCol . size ( ) - 1 ) ;
int index = sortedCol . toInt ( ) ;
int index = sortedCol . toInt ( ) ;
sortDownloadList ( index , sortOrder , true ) ;
sortDownloadList ( index , sortOrder ) ;
}
}
qDebug ( " Download list columns width loaded " ) ;
return true ;
}
}
// Called when a torrent is added
// Called when a torrent is added
@ -818,6 +810,7 @@ void DownloadingTorrents::torrentAdded(QTorrentHandle& h) {
// Pause torrent if it was paused last time
// Pause torrent if it was paused last time
// Not using isPaused function because torrents are paused after checking now
// Not using isPaused function because torrents are paused after checking now
if ( QFile : : exists ( misc : : qBittorrentPath ( ) + QString : : fromUtf8 ( " BT_backup " ) + QDir : : separator ( ) + hash + QString : : fromUtf8 ( " .paused " ) ) ) {
if ( QFile : : exists ( misc : : qBittorrentPath ( ) + QString : : fromUtf8 ( " BT_backup " ) + QDir : : separator ( ) + hash + QString : : fromUtf8 ( " .paused " ) ) ) {
DLListModel - > setData ( DLListModel - > index ( row , PROGRESS ) , QVariant ( ( double ) BTSession - > getUncheckedTorrentProgress ( hash ) ) ) ;
DLListModel - > setData ( DLListModel - > index ( row , NAME ) , QVariant ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/paused.png " ) ) ) , Qt : : DecorationRole ) ;
DLListModel - > setData ( DLListModel - > index ( row , NAME ) , QVariant ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/paused.png " ) ) ) , Qt : : DecorationRole ) ;
setRowColor ( row , QString : : fromUtf8 ( " red " ) ) ;
setRowColor ( row , QString : : fromUtf8 ( " red " ) ) ;
} else {
} else {
@ -826,6 +819,7 @@ void DownloadingTorrents::torrentAdded(QTorrentHandle& h) {
}
}
+ + nbTorrents ;
+ + nbTorrents ;
emit unfinishedTorrentsNumberChanged ( nbTorrents ) ;
emit unfinishedTorrentsNumberChanged ( nbTorrents ) ;
sortDownloadList ( ) ;
}
}
void DownloadingTorrents : : updateFileSizeAndProgress ( QString hash ) {
void DownloadingTorrents : : updateFileSizeAndProgress ( QString hash ) {
@ -833,7 +827,7 @@ void DownloadingTorrents::updateFileSizeAndProgress(QString hash) {
Q_ASSERT ( row ! = - 1 ) ;
Q_ASSERT ( row ! = - 1 ) ;
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
DLListModel - > setData ( DLListModel - > index ( row , SIZE ) , QVariant ( ( qlonglong ) h . actual_size ( ) ) ) ;
DLListModel - > setData ( DLListModel - > index ( row , SIZE ) , QVariant ( ( qlonglong ) h . actual_size ( ) ) ) ;
DLListModel - > setData ( DLListModel - > index ( row , PROGRESS ) , QVariant ( ( double ) h . progress ( ) ) ) ;
//DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)h.progress()));
}
}
// Set the color of a row in data model
// Set the color of a row in data model