From 029be91dc852a294d0c35f53df5d4da48cbf5230 Mon Sep 17 00:00:00 2001 From: Daniel Tartavel Date: Fri, 18 Oct 2024 22:39:09 +0200 Subject: [PATCH] added 'suspend' button --- mainwindow.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++------- mainwindow.h | 39 ++++++++++++++++++-------------- mainwindow.ui | 15 +++++++++++++ 3 files changed, 90 insertions(+), 25 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 5420a52..5d4e9c2 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -7,12 +7,8 @@ #include "tools.h" #include "password.h" #include - -/* -#include -#include -#include -*/ +#include +#include using namespace std; @@ -1622,12 +1618,61 @@ void MainWindow::on_actionHiddenService_triggered() void MainWindow::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column) { - void(); + (void) item; + (void) column; } void MainWindow::on_treeWidget_doubleClicked(const QModelIndex &index) { - void(); + (void) index; } + +void MainWindow::on_actionPause_downloads_triggered() +{ + quint64 processID = this->downloading.process->processId(); + QString fileStr = "/proc/" + QString::number(processID) + "/task/" + QString::number(processID) + "/children"; + static QMessageBox *msgBox; + + info (DEBUGMACRO, "downloading state : " + QString::fromUtf8((this->downloading.paused==0)?"running":"paused")); + info (DEBUGMACRO, "Downloading process ID : " + QString::number(processID)); + info (DEBUGMACRO, fileStr); + + QFile file(fileStr); + if(!file.open(QIODevice::ReadOnly)) + { + QMessageBox::information(0, "error", file.errorString()); + } + + QTextStream in(&file); + QString children = in.readLine(); + info (DEBUGMACRO, "Child process is : " + children); + if (this->downloading.paused) + { + info(DEBUGMACRO, "resuming Download"); + if (kill(children.toLongLong(), SIGCONT)) + { + info(DEBUGMACRO, "resuming failed : " + QString::number(errno)); + } + + msgBox->close(); + this->downloading.paused = false; + }else + { + info(DEBUGMACRO, "pausing Download"); + if (kill(children.toLongLong(), SIGTSTP)) + { + info(DEBUGMACRO, "resuming failed : " + QString::number(errno)); + } + msgBox = new QMessageBox(this); + msgBox->setIcon( QMessageBox::Warning ); + msgBox->setText("Download suspended"); + //QPushButton *btnCancel = msgBox->addButton( "Cancel", QMessageBox::RejectRole ); + msgBox->setAttribute(Qt::WA_DeleteOnClose); // delete pointer after close + msgBox->setModal(false); + msgBox->show(); + + this->downloading.paused = true; + } +} diff --git a/mainwindow.h b/mainwindow.h index cb90e4a..97d2ab9 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -56,16 +56,17 @@ class Connexion int bandwidthLimitUnit; int contimeout = 20; QString server; - QString service; - QString path; - QString savePath; - QString user; - QString password; - QProcess * process = nullptr; - int ipversion = 4; - uint port = 873; - bool quit = false; - void clear(); + QString service; + QString path; + QString savePath; + QString user; + QString password; + QProcess * process = nullptr; + int ipversion = 4; + uint port = 873; + bool quit = false; + void clear(); + bool paused = false; }; class Downloading @@ -75,13 +76,15 @@ class Downloading QString service; QString path; QString savePath; - QString user; - QString password; - int ipversion = 4; - int port = 873; - QProcess * process = nullptr; - bool quit = false; - void clear(); + QString user; + QString password; + int ipversion = 4; + int port = 873; + QProcess * process = nullptr; + bool quit = false; + bool paused = false; + + void clear(); }; class About @@ -223,6 +226,8 @@ class MainWindow : public QMainWindow void on_treeWidget_doubleClicked(const QModelIndex &index); + void on_actionPause_downloads_triggered(); + signals: void stopDownloading(QProcess *); void progressSignal(int); diff --git a/mainwindow.ui b/mainwindow.ui index 7b0be36..871c77c 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -407,6 +407,7 @@ + @@ -479,6 +480,20 @@ hidden service + + + + + + Stop/resume downloads + + + Stop/resume downloading + + + P + +