@ -777,21 +777,35 @@ void GUI::processDownloadedFiles(QString path, QString url) {
@@ -777,21 +777,35 @@ void GUI::processDownloadedFiles(QString path, QString url) {
// Set BT session configuration
void GUI : : configureSession ( bool deleteOptions ) {
qDebug ( " Configuring session " ) ;
QPair < int , int > limits ;
unsigned short old_listenPort , new_listenPort ;
proxy_settings proxySettings ;
session_settings sessionSettings ;
pe_settings encryptionSettings ;
// Downloads
BTSession - > preAllocateAllFiles ( options - > preAllocateAllFiles ( ) ) ;
BTSession - > startTorrentsInPause ( options - > addTorrentsInPause ( ) ) ;
// Connection
old_listenPort = BTSession - > getListenPort ( ) ;
// * Ports binding
unsigned short old_listenPort = BTSession - > getListenPort ( ) ;
BTSession - > setListeningPortsRange ( options - > getPorts ( ) ) ;
new_listenPort = BTSession - > getListenPort ( ) ;
unsigned short new_listenPort = BTSession - > getListenPort ( ) ;
if ( new_listenPort ! = old_listenPort ) {
downloadingTorrentTab - > setInfoBar ( tr ( " qBittorrent is bind to port: %1 " , " e.g: qBittorrent is bind to port: 1666 " ) . arg ( misc : : toQString ( new_listenPort ) ) ) ;
}
// * Global download limit
QPair < int , int > limits = options - > getGlobalBandwidthLimits ( ) ;
if ( limits . first < = 0 ) {
// Download limit disabled
BTSession - > setDownloadRateLimit ( - 1 ) ;
} else {
// Enabled
BTSession - > setDownloadRateLimit ( limits . first * 1024 ) ;
}
// * Global Upload limit
if ( limits . second < = 0 ) {
// Upload limit disabled
BTSession - > setUploadRateLimit ( - 1 ) ;
} else {
// Enabled
BTSession - > setUploadRateLimit ( limits . second * 1024 ) ;
}
// * UPnP
if ( options - > isUPnPEnabled ( ) ) {
BTSession - > enableUPnP ( true ) ;
downloadingTorrentTab - > setInfoBar ( tr ( " UPnP support [ON] " ) , QString : : fromUtf8 ( " blue " ) ) ;
@ -799,6 +813,7 @@ void GUI::configureSession(bool deleteOptions) {
@@ -799,6 +813,7 @@ void GUI::configureSession(bool deleteOptions) {
BTSession - > enableUPnP ( false ) ;
downloadingTorrentTab - > setInfoBar ( tr ( " UPnP support [OFF] " ) , QString : : fromUtf8 ( " blue " ) ) ;
}
// * NAT-PMP
if ( options - > isNATPMPEnabled ( ) ) {
BTSession - > enableNATPMP ( true ) ;
downloadingTorrentTab - > setInfoBar ( tr ( " NAT-PMP support [ON] " ) , QString : : fromUtf8 ( " blue " ) ) ;
@ -806,14 +821,43 @@ void GUI::configureSession(bool deleteOptions) {
@@ -806,14 +821,43 @@ void GUI::configureSession(bool deleteOptions) {
BTSession - > enableNATPMP ( false ) ;
downloadingTorrentTab - > setInfoBar ( tr ( " NAT-PMP support [OFF] " ) , QString : : fromUtf8 ( " blue " ) ) ;
}
// Bittorrent
if ( options - > isLSDEnabled ( ) ) {
BTSession - > enableLSD ( true ) ;
downloadingTorrentTab - > setInfoBar ( tr ( " Local Peer Discovery [ON] " ) , QString : : fromUtf8 ( " blue " ) ) ;
} else {
BTSession - > enableLSD ( false ) ;
downloadingTorrentTab - > setInfoBar ( tr ( " Local Peer Discovery support [OFF] " ) , QString : : fromUtf8 ( " blue " ) ) ;
// * Proxy settings
proxy_settings proxySettings ;
if ( options - > isProxyEnabled ( ) ) {
switch ( options - > getProxyType ( ) ) {
case HTTP :
proxySettings . type = proxy_settings : : http ;
break ;
case HTTP_PW :
proxySettings . type = proxy_settings : : http_pw ;
break ;
case SOCKS5 :
proxySettings . type = proxy_settings : : socks5 ;
break ;
default :
proxySettings . type = proxy_settings : : socks5_pw ;
break ;
}
proxySettings . hostname = options - > getProxyIp ( ) . toStdString ( ) ;
proxySettings . port = options - > getProxyPort ( ) ;
if ( options - > isProxyAuthEnabled ( ) ) {
proxySettings . username = options - > getProxyUsername ( ) . toStdString ( ) ;
proxySettings . password = options - > getProxyPassword ( ) . toStdString ( ) ;
}
}
BTSession - > setProxySettings ( proxySettings , options - > useProxyForTrackers ( ) , options - > useProxyForPeers ( ) , options - > useProxyForWebseeds ( ) , options - > useProxyForDHT ( ) ) ;
// * Session settings
session_settings sessionSettings ;
sessionSettings . user_agent = " qBittorrent " VERSION ;
BTSession - > setSessionSettings ( sessionSettings ) ;
// Bittorrent
// * Max connections limit
BTSession - > setMaxConnections ( options - > getMaxConnecs ( ) ) ;
// * Max connections per torrent limit
BTSession - > setMaxConnectionsPerTorrent ( options - > getMaxConnecsPerTorrent ( ) ) ;
// * Max uploads per torrent limit
BTSession - > setMaxUploadsPerTorrent ( options - > getMaxUploadsPerTorrent ( ) ) ;
// * DHT
if ( options - > isDHTEnabled ( ) ) {
BTSession - > enableDHT ( true ) ;
downloadingTorrentTab - > setInfoBar ( tr ( " DHT support [ON], port: %1 " ) . arg ( new_listenPort ) , QString : : fromUtf8 ( " blue " ) ) ;
@ -823,33 +867,26 @@ void GUI::configureSession(bool deleteOptions) {
@@ -823,33 +867,26 @@ void GUI::configureSession(bool deleteOptions) {
BTSession - > enableDHT ( false ) ;
downloadingTorrentTab - > setInfoBar ( tr ( " DHT support [OFF] " ) , QString : : fromUtf8 ( " blue " ) ) ;
}
// IP Filter
// Configure session regarding options
BTSession - > setDefaultSavePath ( options - > getSavePath ( ) ) ;
// Apply max connec limit (-1 if disabled)
BTSession - > setMaxConnections ( options - > getMaxConnecs ( ) ) ;
limits = options - > getGlobalBandwidthLimits ( ) ;
switch ( limits . first ) {
case - 1 : // Download limit disabled
case 0 :
BTSession - > setDownloadRateLimit ( - 1 ) ;
break ;
default :
BTSession - > setDownloadRateLimit ( limits . first * 1024 ) ;
// * PeX
if ( options - > isPeXEnabled ( ) ) {
downloadingTorrentTab - > setInfoBar ( tr ( " PeX support [ON] " ) , QString : : fromUtf8 ( " blue " ) ) ;
BTSession - > enablePeerExchange ( ) ;
} else {
// TODO: How can we remove the extension?
downloadingTorrentTab - > setInfoBar ( tr ( " PeX support [OFF] " ) , QString : : fromUtf8 ( " blue " ) ) ;
}
switch ( limits . second ) {
case - 1 : // Upload limit disabled
case 0 :
BTSession - > setUploadRateLimit ( - 1 ) ;
break ;
default :
BTSession - > setUploadRateLimit ( limits . second * 1024 ) ;
// * LSD
if ( options - > isLSDEnabled ( ) ) {
BTSession - > enableLSD ( true ) ;
downloadingTorrentTab - > setInfoBar ( tr ( " Local Peer Discovery [ON] " ) , QString : : fromUtf8 ( " blue " ) ) ;
} else {
BTSession - > enableLSD ( false ) ;
downloadingTorrentTab - > setInfoBar ( tr ( " Local Peer Discovery support [OFF] " ) , QString : : fromUtf8 ( " blue " ) ) ;
}
// Apply ratio (0 if disabled)
BTSession - > setGlobalRatio ( options - > getDesiredRatio ( ) ) ;
// Encryption settings
// * Encryption
int encryptionState = options - > getEncryptionSetting ( ) ;
// The most secure, rc4 only so that all streams and encrypted
pe_settings encryptionSettings ;
encryptionSettings . allowed_enc_level = pe_settings : : rc4 ;
encryptionSettings . prefer_rc4 = true ;
switch ( encryptionState ) {
@ -869,15 +906,11 @@ void GUI::configureSession(bool deleteOptions) {
@@ -869,15 +906,11 @@ void GUI::configureSession(bool deleteOptions) {
downloadingTorrentTab - > setInfoBar ( tr ( " Encryption support [OFF] " ) , QString : : fromUtf8 ( " blue " ) ) ;
}
BTSession - > applyEncryptionSettings ( encryptionSettings ) ;
// PeX
if ( options - > isPeXEnabled ( ) ) {
qDebug ( " Enabling Peer eXchange (PeX) " ) ;
downloadingTorrentTab - > setInfoBar ( tr ( " PeX support [ON] " ) , QString : : fromUtf8 ( " blue " ) ) ;
BTSession - > enablePeerExchange ( ) ;
} else {
downloadingTorrentTab - > setInfoBar ( tr ( " PeX support [OFF] " ) , QString : : fromUtf8 ( " blue " ) ) ;
qDebug ( " Peer eXchange (PeX) disabled " ) ;
}
// IP Filter
// Configure session regarding options
BTSession - > setDefaultSavePath ( options - > getSavePath ( ) ) ;
// Apply ratio (0 if disabled)
BTSession - > setGlobalRatio ( options - > getDesiredRatio ( ) ) ;
// Apply filtering settings
if ( options - > isFilteringEnabled ( ) ) {
BTSession - > enableIPFilter ( options - > getFilter ( ) ) ;
@ -886,32 +919,6 @@ void GUI::configureSession(bool deleteOptions) {
@@ -886,32 +919,6 @@ void GUI::configureSession(bool deleteOptions) {
BTSession - > disableIPFilter ( ) ;
downloadingTorrentTab - > setBottomTabEnabled ( 1 , false ) ;
}
// Apply Proxy settings
if ( options - > isProxyEnabled ( ) ) {
switch ( options - > getProxyType ( ) ) {
case HTTP :
proxySettings . type = proxy_settings : : http ;
break ;
case HTTP_PW :
proxySettings . type = proxy_settings : : http_pw ;
break ;
case SOCKS5 :
proxySettings . type = proxy_settings : : socks5 ;
break ;
default :
proxySettings . type = proxy_settings : : socks5_pw ;
break ;
}
proxySettings . hostname = options - > getProxyIp ( ) . toStdString ( ) ;
proxySettings . port = options - > getProxyPort ( ) ;
if ( options - > isProxyAuthEnabled ( ) ) {
proxySettings . username = options - > getProxyUsername ( ) . toStdString ( ) ;
proxySettings . password = options - > getProxyPassword ( ) . toStdString ( ) ;
}
}
BTSession - > setProxySettings ( proxySettings , options - > useProxyForTrackers ( ) , options - > useProxyForPeers ( ) , options - > useProxyForWebseeds ( ) , options - > useProxyForDHT ( ) ) ;
sessionSettings . user_agent = " qBittorrent " VERSION ;
BTSession - > setSessionSettings ( sessionSettings ) ;
// Scan dir stuff
if ( options - > getScanDir ( ) . isNull ( ) ) {
BTSession - > disableDirectoryScanning ( ) ;