@ -29,6 +29,7 @@
@@ -29,6 +29,7 @@
# include <QCloseEvent>
# include <QShortcut>
# include <QStandardItemModel>
# include <QMutexLocker>
# include "GUI.h"
# include "misc.h"
@ -179,10 +180,6 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){
@@ -179,10 +180,6 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){
connect ( downloadList , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayDLListMenu ( const QPoint & ) ) ) ;
// connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayGUIMenu(const QPoint&)));
connect ( infoBar , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayInfoBarMenu ( const QPoint & ) ) ) ;
// Start download list refresher
refresher = new QTimer ( this ) ;
connect ( refresher , SIGNAL ( timeout ( ) ) , this , SLOT ( updateDlList ( ) ) ) ;
refresher - > start ( 2000 ) ;
// Use a tcp server to allow only one instance of qBittorrent
tcpServer = new QTcpServer ( ) ;
if ( ! tcpServer - > listen ( QHostAddress : : LocalHost , 1666 ) ) {
@ -195,6 +192,9 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){
@@ -195,6 +192,9 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){
checkConnect - > start ( 5000 ) ;
previewProcess = new QProcess ( this ) ;
connect ( previewProcess , SIGNAL ( finished ( int , QProcess : : ExitStatus ) ) , this , SLOT ( cleanTempPreviewFile ( int , QProcess : : ExitStatus ) ) ) ;
// Download list refresher thread
refresher = new DownloadListRefresher ( this ) ;
refresher - > start ( ) ;
// Accept drag 'n drops
setAcceptDrops ( true ) ;
// Set info Bar infos
@ -231,6 +231,14 @@ GUI::~GUI(){
@@ -231,6 +231,14 @@ GUI::~GUI(){
delete switchRSSShortcut ;
}
int GUI : : getCurrentTab ( ) const {
if ( isHidden ( ) | | isMinimized ( ) ) {
return - 1 ;
} else {
return tabs - > currentIndex ( ) ;
}
}
void GUI : : on_actionWebsite_triggered ( ) {
QDesktopServices : : openUrl ( QUrl ( " http://www.qbittorrent.org " ) ) ;
}
@ -554,17 +562,14 @@ void GUI::updateDlList(bool force){
@@ -554,17 +562,14 @@ void GUI::updateDlList(bool force){
if ( systrayIntegration ) {
myTrayIcon - > setToolTip ( " <b> " + tr ( " qBittorrent " ) + " </b><br> " + tr ( " DL speed: %1 KiB/s " , " e.g: Download speed: 10 KiB/s " ) . arg ( QString ( tmp2 ) ) + " <br> " + tr ( " UP speed: %1 KiB/s " , " e.g: Upload speed: 10 KiB/s " ) . arg ( QString ( tmp ) ) ) ; // tray icon
}
if ( ! force & & ( isMinimized ( ) | | isHidden ( ) | | tabs - > currentIndex ( ) > 1 ) ) {
if ( ! force & & getCurrentTab ( ) ) {
// No need to update if qBittorrent DL list is hidden
return ;
}
if ( tabs - > currentIndex ( ) ) {
finishedTorrentTab - > updateFinishedList ( ) ;
return ;
}
// qDebug("Updating download list");
LCD_UpSpeed - > display ( tmp ) ; // UP LCD
LCD_DownSpeed - > display ( tmp2 ) ; // DL LCD
QMutexLocker locker ( & DLListAccess ) ;
// browse handles
std : : vector < torrent_handle > handles = BTSession - > getTorrentHandles ( ) ;
QStringList finishedSHAs = finishedTorrentTab - > getFinishedSHAs ( ) ;
@ -658,6 +663,7 @@ void GUI::updateDlList(bool force){
@@ -658,6 +663,7 @@ void GUI::updateDlList(bool force){
}
void GUI : : restoreInDownloadList ( torrent_handle h ) {
QMutexLocker locker ( & DLListAccess ) ;
unsigned int row = DLListModel - > rowCount ( ) ;
QString hash = QString ( misc : : toString ( h . info_hash ( ) ) . c_str ( ) ) ;
// Adding torrent to download list
@ -732,6 +738,7 @@ void GUI::sortDownloadListString(int index, Qt::SortOrder sortOrder){
@@ -732,6 +738,7 @@ void GUI::sortDownloadListString(int index, Qt::SortOrder sortOrder){
void GUI : : sortDownloadList ( int index , Qt : : SortOrder startSortOrder , bool fromLoadColWidth ) {
qDebug ( " Called sort download list " ) ;
QMutexLocker locker ( & DLListAccess ) ;
static Qt : : SortOrder sortOrder = startSortOrder ;
if ( ! fromLoadColWidth & & downloadList - > header ( ) - > sortIndicatorSection ( ) = = index ) {
if ( sortOrder = = Qt : : AscendingOrder ) {
@ -987,6 +994,7 @@ void GUI::on_actionOpen_triggered(){
@@ -987,6 +994,7 @@ void GUI::on_actionOpen_triggered(){
// delete from download list AND from hard drive
void GUI : : on_actionDelete_Permanently_triggered ( ) {
if ( tabs - > currentIndex ( ) > 1 ) return ;
QMutexLocker locker ( & DLListAccess ) ;
QModelIndexList selectedIndexes ;
bool inDownloadList ;
if ( tabs - > currentIndex ( ) = = 0 ) {
@ -1058,6 +1066,7 @@ void GUI::on_actionDelete_Permanently_triggered(){
@@ -1058,6 +1066,7 @@ void GUI::on_actionDelete_Permanently_triggered(){
// delete selected items in the list
void GUI : : on_actionDelete_triggered ( ) {
QMutexLocker locker ( & DLListAccess ) ;
if ( tabs - > currentIndex ( ) > 1 ) return ;
QModelIndexList selectedIndexes ;
bool inDownloadList = true ;
@ -1129,6 +1138,7 @@ void GUI::on_actionDelete_triggered(){
@@ -1129,6 +1138,7 @@ void GUI::on_actionDelete_triggered(){
// Called when a torrent is added
void GUI : : torrentAdded ( QString path , torrent_handle & h , bool fastResume ) {
QMutexLocker locker ( & DLListAccess ) ;
QString hash = QString ( misc : : toString ( h . info_hash ( ) ) . c_str ( ) ) ;
if ( QFile : : exists ( misc : : qBittorrentPath ( ) + " BT_backup " + QDir : : separator ( ) + hash + " .finished " ) ) {
finishedTorrentTab - > addFinishedSHA ( hash ) ;
@ -1371,6 +1381,7 @@ void GUI::configureSession(bool deleteOptions){
@@ -1371,6 +1381,7 @@ void GUI::configureSession(bool deleteOptions){
// Pause All Downloads in DL list
void GUI : : on_actionPause_All_triggered ( ) {
QMutexLocker locker ( & DLListAccess ) ;
QString fileHash ;
// Pause all torrents
if ( BTSession - > pauseAllTorrents ( ) ) {
@ -1396,6 +1407,7 @@ void GUI::on_actionPause_All_triggered(){
@@ -1396,6 +1407,7 @@ void GUI::on_actionPause_All_triggered(){
// pause selected items in the list
void GUI : : on_actionPause_triggered ( ) {
QMutexLocker locker ( & DLListAccess ) ;
QModelIndexList selectedIndexes = downloadList - > selectionModel ( ) - > selectedIndexes ( ) ;
QModelIndex index ;
foreach ( index , selectedIndexes ) {
@ -1421,6 +1433,7 @@ void GUI::on_actionPause_triggered(){
@@ -1421,6 +1433,7 @@ void GUI::on_actionPause_triggered(){
// Resume All Downloads in DL list
void GUI : : on_actionStart_All_triggered ( ) {
QMutexLocker locker ( & DLListAccess ) ;
QString fileHash ;
// Pause all torrents
if ( BTSession - > resumeAllTorrents ( ) ) {
@ -1440,6 +1453,7 @@ void GUI::on_actionStart_All_triggered(){
@@ -1440,6 +1453,7 @@ void GUI::on_actionStart_All_triggered(){
// start selected items in the list
void GUI : : on_actionStart_triggered ( ) {
QMutexLocker locker ( & DLListAccess ) ;
QModelIndexList selectedIndexes = downloadList - > selectionModel ( ) - > selectedIndexes ( ) ;
QModelIndex index ;
foreach ( index , selectedIndexes ) {
@ -1486,6 +1500,7 @@ void GUI::on_actionTorrent_Properties_triggered(){
@@ -1486,6 +1500,7 @@ void GUI::on_actionTorrent_Properties_triggered(){
// called when a torrent has finished
void GUI : : finishedTorrent ( torrent_handle & h ) {
QMutexLocker locker ( & DLListAccess ) ;
QSettings settings ( " qBittorrent " , " qBittorrent " ) ;
QString fileName = QString ( h . name ( ) . c_str ( ) ) ;
int useOSD = settings . value ( " Options/OSDEnabled " , 1 ) . toInt ( ) ;