@ -121,13 +121,13 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
BTSession = new bittorrent ( ) ;
BTSession = new bittorrent ( ) ;
connect ( BTSession , SIGNAL ( fullDiskError ( QTorrentHandle & ) ) , this , SLOT ( fullDiskError ( QTorrentHandle & ) ) ) ;
connect ( BTSession , SIGNAL ( fullDiskError ( QTorrentHandle & ) ) , this , SLOT ( fullDiskError ( QTorrentHandle & ) ) ) ;
connect ( BTSession , SIGNAL ( finishedTorrent ( QTorrentHandle & ) ) , this , SLOT ( finishedTorrent ( QTorrentHandle & ) ) ) ;
connect ( BTSession , SIGNAL ( finishedTorrent ( QTorrentHandle & ) ) , this , SLOT ( finishedTorrent ( QTorrentHandle & ) ) ) ;
connect ( BTSession , SIGNAL ( addedTorrent ( QTorrentHandle & ) ) , this , SLOT ( addedTorrent ( QTorrentHandle & ) ) ) ;
connect ( BTSession , SIGNAL ( torrentFinishedChecking ( QTorrentHandle & ) ) , this , SLOT ( checkedTorrent ( QTorrentHandle & ) ) ) ;
connect ( BTSession , SIGNAL ( trackerAuthenticationRequired ( QTorrentHandle & ) ) , this , SLOT ( trackerAuthenticationRequired ( QTorrentHandle & ) ) ) ;
connect ( BTSession , SIGNAL ( trackerAuthenticationRequired ( QTorrentHandle & ) ) , this , SLOT ( trackerAuthenticationRequired ( QTorrentHandle & ) ) ) ;
connect ( BTSession , SIGNAL ( newDownloadedTorrent ( QString , QString ) ) , this , SLOT ( processDownloadedFiles ( QString , QString ) ) ) ;
connect ( BTSession , SIGNAL ( newDownloadedTorrent ( QString , QString ) ) , this , SLOT ( processDownloadedFiles ( QString , QString ) ) ) ;
connect ( BTSession , SIGNAL ( downloadFromUrlFailure ( QString , QString ) ) , this , SLOT ( handleDownloadFromUrlFailure ( QString , QString ) ) ) ;
connect ( BTSession , SIGNAL ( downloadFromUrlFailure ( QString , QString ) ) , this , SLOT ( handleDownloadFromUrlFailure ( QString , QString ) ) ) ;
connect ( BTSession , SIGNAL ( deletedTorrent ( QString ) ) , this , SLOT ( deleteTorrent ( QString ) ) ) ;
connect ( BTSession , SIGNAL ( deletedTorrent ( QString ) ) , this , SLOT ( deleteTorrent ( QString ) ) ) ;
connect ( BTSession , SIGNAL ( pausedTorrent ( QString ) ) , this , SLOT ( pauseTorrent ( QString ) ) ) ;
connect ( BTSession , SIGNAL ( pausedTorrent ( QString ) ) , this , SLOT ( pauseTorrent ( QString ) ) ) ;
connect ( BTSession , SIGNAL ( updateUnfinishedTorrentNumber ( ) ) , this , SLOT ( updateUnfinishedTorrentNumberCalc ( ) ) ) ;
connect ( BTSession , SIGNAL ( updateFinishedTorrentNumber ( ) ) , this , SLOT ( updateFinishedTorrentNumberCalc ( ) ) ) ;
qDebug ( " create tabWidget " ) ;
qDebug ( " create tabWidget " ) ;
tabs = new QTabWidget ( ) ;
tabs = new QTabWidget ( ) ;
// Download torrents tab
// Download torrents tab
@ -348,14 +348,12 @@ void GUI::finishedTorrent(QTorrentHandle& h) const {
qDebug ( " In GUI, a torrent has finished " ) ;
qDebug ( " In GUI, a torrent has finished " ) ;
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
bool show_msg = true ;
bool show_msg = true ;
if ( QFile : : exists ( misc : : qBittorrentPath ( ) + " BT_backup " + QDir : : separator ( ) + h . hash ( ) + " .finished " ) )
show_msg = false ;
QString fileName = h . name ( ) ;
QString fileName = h . name ( ) ;
bool useNotificationBalloons = settings . value ( QString : : fromUtf8 ( " Preferences/General/NotificationBaloons " ) , true ) . toBool ( ) ;
bool useNotificationBalloons = settings . value ( QString : : fromUtf8 ( " Preferences/General/NotificationBaloons " ) , true ) . toBool ( ) ;
// Add it to finished tab
// Add it to finished tab
QString hash = h . hash ( ) ;
QString hash = h . hash ( ) ;
if ( QFile : : exists ( misc : : qBittorrentPath ( ) + QString : : fromUtf8 ( " BT_backup " ) + QDir : : separator ( ) + hash + QString : : fromUtf8 ( " .finished " ) ) ) {
show_msg = false ;
qDebug ( " We received a finished signal for torrent %s, but it already has a .finished file " , hash . toUtf8 ( ) . data ( ) ) ;
}
if ( show_msg )
if ( show_msg )
BTSession - > addConsoleMessage ( tr ( " %1 has finished downloading. " , " e.g: xxx.avi has finished downloading. " ) . arg ( fileName ) ) ;
BTSession - > addConsoleMessage ( tr ( " %1 has finished downloading. " , " e.g: xxx.avi has finished downloading. " ) . arg ( fileName ) ) ;
downloadingTorrentTab - > deleteTorrent ( hash ) ;
downloadingTorrentTab - > deleteTorrent ( hash ) ;
@ -365,6 +363,22 @@ void GUI::finishedTorrent(QTorrentHandle& h) const {
}
}
}
}
void GUI : : addedTorrent ( QTorrentHandle & h ) const {
if ( h . is_seed ( ) ) {
finishedTorrentTab - > addTorrent ( h . hash ( ) ) ;
} else {
downloadingTorrentTab - > addTorrent ( h . hash ( ) ) ;
}
}
void GUI : : checkedTorrent ( QTorrentHandle & h ) const {
if ( h . is_seed ( ) ) {
// Move torrent to finished tab
downloadingTorrentTab - > deleteTorrent ( h . hash ( ) ) ;
finishedTorrentTab - > addTorrent ( h . hash ( ) ) ;
}
}
// Notification when disk is full
// Notification when disk is full
void GUI : : fullDiskError ( QTorrentHandle & h ) const {
void GUI : : fullDiskError ( QTorrentHandle & h ) const {
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
@ -1117,23 +1131,11 @@ void GUI::updateUnfinishedTorrentNumber(unsigned int nb) {
tabs - > setTabText ( 0 , tr ( " Downloads " ) + QString : : fromUtf8 ( " ( " ) + misc : : toQString ( nb - paused ) + " / " + misc : : toQString ( nb ) + QString : : fromUtf8 ( " ) " ) ) ;
tabs - > setTabText ( 0 , tr ( " Downloads " ) + QString : : fromUtf8 ( " ( " ) + misc : : toQString ( nb - paused ) + " / " + misc : : toQString ( nb ) + QString : : fromUtf8 ( " ) " ) ) ;
}
}
void GUI : : updateUnfinishedTorrentNumberCalc ( ) {
unsigned int paused = BTSession - > getUnfinishedPausedTorrentsNb ( ) ;
unsigned int nb = BTSession - > getUnfinishedTorrents ( ) . size ( ) ;
tabs - > setTabText ( 0 , tr ( " Downloads " ) + QString : : fromUtf8 ( " ( " ) + misc : : toQString ( nb - paused ) + " / " + misc : : toQString ( nb ) + QString : : fromUtf8 ( " ) " ) ) ;
}
void GUI : : updateFinishedTorrentNumber ( unsigned int nb ) {
void GUI : : updateFinishedTorrentNumber ( unsigned int nb ) {
unsigned int paused = BTSession - > getFinishedPausedTorrentsNb ( ) ;
unsigned int paused = BTSession - > getFinishedPausedTorrentsNb ( ) ;
tabs - > setTabText ( 1 , tr ( " Finished " ) + QString : : fromUtf8 ( " ( " ) + misc : : toQString ( nb - paused ) + " / " + misc : : toQString ( nb ) + QString : : fromUtf8 ( " ) " ) ) ;
tabs - > setTabText ( 1 , tr ( " Finished " ) + QString : : fromUtf8 ( " ( " ) + misc : : toQString ( nb - paused ) + " / " + misc : : toQString ( nb ) + QString : : fromUtf8 ( " ) " ) ) ;
}
}
void GUI : : updateFinishedTorrentNumberCalc ( ) {
unsigned int paused = BTSession - > getFinishedPausedTorrentsNb ( ) ;
unsigned int nb = BTSession - > getFinishedTorrents ( ) . size ( ) ;
tabs - > setTabText ( 1 , tr ( " Finished " ) + QString : : fromUtf8 ( " ( " ) + misc : : toQString ( nb - paused ) + " / " + misc : : toQString ( nb ) + QString : : fromUtf8 ( " ) " ) ) ;
}
// Allow to change action on double-click
// Allow to change action on double-click
void GUI : : torrentDoubleClicked ( QString hash , bool finished ) {
void GUI : : torrentDoubleClicked ( QString hash , bool finished ) {
int action ;
int action ;
@ -1197,19 +1199,18 @@ void GUI::togglePausedState(QString hash) {
// Pause All Downloads in DL list
// Pause All Downloads in DL list
void GUI : : on_actionPause_All_triggered ( ) {
void GUI : : on_actionPause_All_triggered ( ) {
bool change = false ;
bool change = false ;
QStringList DL_hashe s = BTSession - > getUnfinished Torrents ( ) ;
std : : vector < torrent_handle > torrent s = BTSession - > getTorrents ( ) ;
QStringList F_hashes = BTSession - > getFinishedTorrents ( ) ;
std : : vector < torrent_handle > : : iterator torrentIT ;
QString hash ;
for ( torrentIT = torrents . begin ( ) ; torrentIT ! = torrents . end ( ) ; torrentIT + + ) {
foreach ( hash , DL_hashes ) {
QTorrentHandle h = QTorrentHandle ( * torrentIT ) ;
if ( BTSession - > pauseTorrent ( hash ) ) {
if ( ! h . is_valid ( ) | | h . is_paused ( ) ) continue ;
change = true ;
change = true ;
downloadingTorrentTab - > pauseTorrent ( hash ) ;
if ( h . is_seed ( ) ) {
}
// Update in finished list
}
finishedTorrentTab - > pauseTorrent ( h . hash ( ) ) ;
foreach ( hash , F_hashes ) {
} else {
if ( BTSession - > pauseTorrent ( hash ) ) {
// Update in download list
change = true ;
downloadingTorrentTab - > pauseTorrent ( h . hash ( ) ) ;
finishedTorrentTab - > pauseTorrent ( hash ) ;
}
}
}
}
if ( change ) {
if ( change ) {
@ -1219,42 +1220,21 @@ void GUI::on_actionPause_All_triggered() {
}
}
void GUI : : on_actionIncreasePriority_triggered ( ) {
void GUI : : on_actionIncreasePriority_triggered ( ) {
bool inDownloadList = true ;
Q_ASSERT ( tabs - > currentIndex ( ) = = 0 ) ;
if ( tabs - > currentIndex ( ) > 1 ) return ;
QStringList hashes = downloadingTorrentTab - > getSelectedTorrents ( ) ;
if ( tabs - > currentIndex ( ) = = 1 )
inDownloadList = false ;
QStringList hashes ;
if ( inDownloadList ) {
hashes = downloadingTorrentTab - > getSelectedTorrents ( ) ;
} else {
hashes = finishedTorrentTab - > getSelectedTorrents ( ) ;
}
foreach ( QString hash , hashes ) {
foreach ( QString hash , hashes ) {
if ( inDownloadList ) {
BTSession - > increaseDlTorrentPriority ( hash ) ;
BTSession - > increaseDlTorrentPriority ( hash ) ;
downloadingTorrentTab - > updateDlList ( ) ;
}
}
}
updateLists ( ) ;
}
}
void GUI : : on_actionDecreasePriority_triggered ( ) {
void GUI : : on_actionDecreasePriority_triggered ( ) {
bool inDownloadList = true ;
Q_ASSERT ( tabs - > currentIndex ( ) = = 0 ) ;
if ( tabs - > currentIndex ( ) > 1 ) return ;
QStringList hashes = downloadingTorrentTab - > getSelectedTorrents ( ) ;
if ( tabs - > currentIndex ( ) = = 1 )
inDownloadList = false ;
QStringList hashes ;
if ( inDownloadList ) {
hashes = downloadingTorrentTab - > getSelectedTorrents ( ) ;
} else {
hashes = finishedTorrentTab - > getSelectedTorrents ( ) ;
}
QString hash ;
foreach ( QString hash , hashes ) {
foreach ( QString hash , hashes ) {
if ( inDownloadList ) {
BTSession - > decreaseDlTorrentPriority ( hash ) ;
BTSession - > decreaseDlTorrentPriority ( hash ) ;
downloadingTorrentTab - > updateDlList ( ) ;
}
}
}
updateLists ( ) ;
}
}
// pause selected items in the list
// pause selected items in the list
@ -1293,19 +1273,18 @@ void GUI::pauseTorrent(QString hash) {
// Resume All Downloads in DL list
// Resume All Downloads in DL list
void GUI : : on_actionStart_All_triggered ( ) {
void GUI : : on_actionStart_All_triggered ( ) {
bool change = false ;
bool change = false ;
QStringList DL_hashe s = BTSession - > getUnfinished Torrents ( ) ;
std : : vector < torrent_handle > torrent s = BTSession - > getTorrents ( ) ;
QStringList F_hashes = BTSession - > getFinishedTorrents ( ) ;
std : : vector < torrent_handle > : : iterator torrentIT ;
QString hash ;
for ( torrentIT = torrents . begin ( ) ; torrentIT ! = torrents . end ( ) ; torrentIT + + ) {
foreach ( hash , DL_hashes ) {
QTorrentHandle h = QTorrentHandle ( * torrentIT ) ;
if ( BTSession - > resumeTorrent ( hash ) ) {
if ( ! h . is_valid ( ) | | ! h . is_paused ( ) ) continue ;
change = true ;
change = true ;
downloadingTorrentTab - > resumeTorrent ( hash ) ;
if ( h . is_seed ( ) ) {
}
// Update in finished list
}
finishedTorrentTab - > resumeTorrent ( h . hash ( ) ) ;
foreach ( hash , F_hashes ) {
} else {
if ( BTSession - > resumeTorrent ( hash ) ) {
// Update in download list
change = true ;
downloadingTorrentTab - > resumeTorrent ( h . hash ( ) ) ;
finishedTorrentTab - > resumeTorrent ( hash ) ;
}
}
}
}
if ( change ) {
if ( change ) {
@ -1363,15 +1342,25 @@ void GUI::updateLists() {
// update global informations
// update global informations
dlSpeedLbl - > setText ( tr ( " DL: %1 KiB/s " ) . arg ( QString ( QByteArray : : number ( BTSession - > getPayloadDownloadRate ( ) / 1024. , ' f ' , 1 ) ) ) ) ;
dlSpeedLbl - > setText ( tr ( " DL: %1 KiB/s " ) . arg ( QString ( QByteArray : : number ( BTSession - > getPayloadDownloadRate ( ) / 1024. , ' f ' , 1 ) ) ) ) ;
upSpeedLbl - > setText ( tr ( " UP: %1 KiB/s " ) . arg ( QString ( QByteArray : : number ( BTSession - > getPayloadUploadRate ( ) / 1024. , ' f ' , 1 ) ) ) ) ;
upSpeedLbl - > setText ( tr ( " UP: %1 KiB/s " ) . arg ( QString ( QByteArray : : number ( BTSession - > getPayloadUploadRate ( ) / 1024. , ' f ' , 1 ) ) ) ) ;
switch ( getCurrentTabIndex ( ) ) {
std : : vector < torrent_handle > torrents = BTSession - > getTorrents ( ) ;
case 0 :
std : : vector < torrent_handle > : : iterator torrentIT ;
downloadingTorrentTab - > updateDlList ( ) ;
for ( torrentIT = torrents . begin ( ) ; torrentIT ! = torrents . end ( ) ; torrentIT + + ) {
break ;
QTorrentHandle h = QTorrentHandle ( * torrentIT ) ;
case 1 :
if ( ! h . is_valid ( ) ) continue ;
finishedTorrentTab - > updateFinishedList ( ) ;
if ( h . is_seed ( ) ) {
break ;
// Update in finished list
default :
finishedTorrentTab - > updateTorrent ( h ) ;
return ;
} else {
// Delete from finished list, if it moved back
if ( QFile : : exists ( misc : : qBittorrentPath ( ) + " BT_backup " + QDir : : separator ( ) + h . hash ( ) + " .finished " ) ) {
if ( h . state ( ) ! = torrent_status : : checking_files & & h . state ( ) ! = torrent_status : : queued_for_checking ) {
finishedTorrentTab - > deleteTorrent ( h . hash ( ) ) ;
QFile : : remove ( misc : : qBittorrentPath ( ) + " BT_backup " + QDir : : separator ( ) + h . hash ( ) + " .finished " ) ;
}
}
// Update in download list
downloadingTorrentTab - > updateTorrent ( h ) ;
}
}
}
if ( displaySpeedInTitle ) {
if ( displaySpeedInTitle ) {
QString dl_rate = QByteArray : : number ( BTSession - > getSessionStatus ( ) . payload_download_rate / 1024 , ' f ' , 1 ) ;
QString dl_rate = QByteArray : : number ( BTSession - > getSessionStatus ( ) . payload_download_rate / 1024 , ' f ' , 1 ) ;