1ère version fonctionnelle
This commit is contained in:
parent
a76f32ea30
commit
789317ea12
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 4.14.2, 2023-01-05T23:51:06. -->
|
<!-- Written by QtCreator 4.14.2, 2023-01-11T01:16:59. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
@ -141,7 +141,7 @@
|
|||||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
|
||||||
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
|
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
|
||||||
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
|
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">true</value>
|
||||||
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
|
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
|
||||||
@ -183,7 +183,7 @@
|
|||||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
|
||||||
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
|
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
|
||||||
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
|
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">true</value>
|
||||||
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
|
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
|
||||||
@ -292,8 +292,9 @@
|
|||||||
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/daniel/develope/RsyncUI/RsyncUI.pro</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">RsyncUI2</value>
|
||||||
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">/home/daniel/develope/RsyncUI/RsyncUI.pro</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/daniel/develop/RsyncUI/RsyncUI.pro</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">/home/daniel/develop/RsyncUI/RsyncUI.pro</value>
|
||||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
|
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -21,66 +23,47 @@ downloadFile::downloadFile()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void downloadFile::cancelled()
|
void downloadFile::cancelled(int pid)
|
||||||
{
|
{
|
||||||
this->canceled = true;
|
if (kill(pid, SIGTERM) == -1)
|
||||||
|
{
|
||||||
|
//TODO gestion erreur kill
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void downloadFile::download(QString savePath, MainWindow *mw)
|
void downloadFile::download(MainWindow *mw)
|
||||||
{
|
{
|
||||||
string server;
|
|
||||||
string service;
|
|
||||||
string path;
|
|
||||||
string line;
|
string line;
|
||||||
string errorRsync;
|
string errorRsync;
|
||||||
char cmd[4096];
|
|
||||||
int portN;
|
|
||||||
int pos;
|
int pos;
|
||||||
int pid;
|
array<string, 7> argv;
|
||||||
QTreeWidgetItem * item;
|
|
||||||
stringstream output;
|
stringstream output;
|
||||||
// QString savePath = ".";
|
|
||||||
vector<string> v;
|
vector<string> v;
|
||||||
int value;
|
int value;
|
||||||
//char command_out[1024] = {0};
|
char buffer[4096];
|
||||||
array<char, 2048> buffer;
|
argv[0] = "/usr/bin/rsync";
|
||||||
|
argv[1] = "--bwlimit=" + mw->connexion.bandwidthLimit;
|
||||||
|
argv[2] = "--port=" + to_string(mw->connexion.port);
|
||||||
|
argv[3] = "-P";
|
||||||
|
argv[4] = mw->connexion.server + "::" + mw->downloading.service + "/" + mw->downloading.path;
|
||||||
|
argv[5] = mw->downloading.savePath + "/";
|
||||||
|
|
||||||
server.assign(mw->ui->khistorycombobox->currentText().toStdString());
|
//unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd "r"), pclose);
|
||||||
portN = mw->ui->portEdit->text().toInt();
|
FILE * fp = popen2(argv, "r", mw->downloading.pid);
|
||||||
service = mw->ui->listWidget->currentItem()->text().toStdString();
|
|
||||||
pos = service.find_first_of('\n');
|
|
||||||
service.resize(pos);
|
|
||||||
|
|
||||||
item = mw->ui->treeWidget->currentItem();
|
|
||||||
path = item->text(0).toStdString();
|
|
||||||
while(item->parent() != NULL)
|
|
||||||
{
|
|
||||||
item = item->parent();
|
|
||||||
path = item->text(0).toStdString() + "/" + path;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
sprintf(cmd, "rsync --bwlimit=100K --port %i -P %s::\"%s/%s\" \"%s/\" 2>&1", portN, server.c_str(), service.c_str(), path.c_str(), savePath.toStdString().c_str());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
|
|
||||||
FILE * fp = popen2(cmd, "r", pid);
|
|
||||||
|
|
||||||
if (!fp)
|
if (!fp)
|
||||||
{
|
{
|
||||||
throw runtime_error("popen2() failed!");
|
throw runtime_error("popen2() failed!");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fgets(buffer.data(), buffer.size(), fp) != nullptr)
|
while (fgets(buffer, 4096, fp) != nullptr)
|
||||||
{
|
{
|
||||||
buffer.data();
|
|
||||||
if (this->canceled == true)
|
if (this->canceled == true)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
line = buffer.data();
|
line = buffer;
|
||||||
//cout << line << endl;
|
//cout << line << endl;
|
||||||
pos = line.find('%');
|
pos = line.find('%');
|
||||||
if (pos != -1)
|
if (pos != -1)
|
||||||
@ -95,9 +78,10 @@ void downloadFile::download(QString savePath, MainWindow *mw)
|
|||||||
emit progressSignal(value);
|
emit progressSignal(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buffer.empty();
|
|
||||||
}
|
}
|
||||||
|
pclose2(fp, mw->downloading.pid);
|
||||||
|
emit progressSignal(100);
|
||||||
|
emit finishedSignal(true);
|
||||||
//cout << path << endl;
|
//cout << path << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,14 +11,15 @@ class downloadFile : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
downloadFile();
|
downloadFile();
|
||||||
void download(QString savePath, MainWindow *parent = nullptr);
|
void download(MainWindow *parent = nullptr);
|
||||||
bool canceled;
|
bool canceled;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void progressSignal(int);
|
void progressSignal(int);
|
||||||
|
void finishedSignal(bool = true);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void cancelled();
|
void cancelled(int pid);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DOWNLOADFILE_H
|
#endif // DOWNLOADFILE_H
|
||||||
|
1
main.cpp
1
main.cpp
@ -1,5 +1,6 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
217
mainwindow.cpp
217
mainwindow.cpp
@ -10,6 +10,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <cstdio>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
@ -19,6 +20,9 @@
|
|||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QProgressDialog>
|
#include <QProgressDialog>
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <QGuiApplication>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -29,67 +33,85 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
connect(&downloadO, &downloadFile::progressSignal, ui->progressBar, &QProgressBar::setValue);
|
||||||
|
connect(&downloadO, &downloadFile::finishedSignal, this, &MainWindow::downloadFinished);
|
||||||
|
connect(this, &MainWindow::stopDownloading, &downloadO, &downloadFile::cancelled);
|
||||||
|
|
||||||
ui->ktreewidgetsearchline->setTreeWidget(ui->treeWidget);
|
ui->ktreewidgetsearchline->setTreeWidget(ui->treeWidget);
|
||||||
ui->ktreewidgetsearchline->setCaseSensitivity(Qt::CaseInsensitive);
|
ui->ktreewidgetsearchline->setCaseSensitivity(Qt::CaseInsensitive);
|
||||||
ui->treeWidget->setHeaderLabels({tr("Path"), tr("Size")} );
|
ui->treeWidget->setHeaderLabels({tr("Path"), tr("Size")} );
|
||||||
ui->progressBar->hide();
|
ui->progressBar->hide();
|
||||||
|
loadSettings();
|
||||||
|
|
||||||
populateList();
|
populateList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
|
QMessageBox::StandardButton reply;
|
||||||
|
|
||||||
|
|
||||||
|
if (ui->listDownload->count() != 0)
|
||||||
|
{
|
||||||
|
reply = QMessageBox::question(
|
||||||
|
this,
|
||||||
|
"RsyncUI",
|
||||||
|
tr("Exiting will stop downloading, and will clear the download queue.\n Do you want to exit ?"),
|
||||||
|
QMessageBox::Yes|QMessageBox::No,
|
||||||
|
QMessageBox::No);
|
||||||
|
if (reply == QMessageBox::Yes)
|
||||||
|
{
|
||||||
|
emit (stopDownloading(this->downloading.pid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this->downloading.pid != 0)
|
||||||
|
{
|
||||||
|
waitpid(this->downloading.pid, NULL, WUNTRACED);
|
||||||
|
}
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::populateTree()
|
void MainWindow::populateTree()
|
||||||
{
|
{
|
||||||
string server;
|
|
||||||
string port;
|
|
||||||
int portN;
|
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
vector<string> path;
|
vector<string> path;
|
||||||
|
|
||||||
server.assign(ui->khistorycombobox->currentText().toStdString());
|
if (!this->connexion.server.empty() and this->connexion.port > 0 and this->connexion.port < 65536)
|
||||||
port.assign(ui->portEdit->text().toStdString());
|
|
||||||
ss << port;
|
|
||||||
ss >> portN;
|
|
||||||
if (!server.empty() and !port.empty() and portN < 65536)
|
|
||||||
{
|
{
|
||||||
if (validateServer(server))
|
if (validateServer(this->connexion.server))
|
||||||
{
|
{
|
||||||
ui->treeWidget->cursor().setShape(Qt::WaitCursor);
|
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
path = explode(ui->listWidget->currentItem()->text().toStdString(), '\n', 2);
|
path = explode(ui->listWidget->currentItem()->text().toStdString(), '\n', 2);
|
||||||
scanDir(server, portN, NULL, path[0].append("/") );
|
scanDir(this->connexion.server, this->connexion.port, NULL, path[0].append("/") );
|
||||||
ui->treeWidget->cursor().setShape(Qt::ArrowCursor);
|
this->unsetCursor();
|
||||||
|
QGuiApplication::setOverrideCursor(Qt::ArrowCursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::populateList()
|
void MainWindow::populateList()
|
||||||
{
|
{
|
||||||
string server;
|
|
||||||
string port;
|
|
||||||
int portN;
|
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
|
|
||||||
server.assign(ui->khistorycombobox->currentText().toStdString());
|
this->connexion.server.assign(ui->khistorycombobox->currentText().toStdString());
|
||||||
port.assign(ui->portEdit->text().toStdString());
|
ss << ui->portEdit->text().toStdString();
|
||||||
ss << port;
|
ss >> this->connexion.port;
|
||||||
ss >> portN;
|
if (!this->connexion.server.empty() and this->connexion.port > 0 and this->connexion.port < 65536)
|
||||||
if (!server.empty() and !port.empty() and portN < 65536)
|
|
||||||
{
|
{
|
||||||
if (validateServer(server))
|
if (validateServer(this->connexion.server))
|
||||||
{
|
{
|
||||||
|
ui->khistorycombobox->addItem(this->connexion.server.c_str());
|
||||||
ui->centralwidget->cursor().setShape(Qt::WaitCursor);
|
ui->centralwidget->cursor().setShape(Qt::WaitCursor);
|
||||||
listServices(server, portN);
|
listServices();
|
||||||
ui->centralwidget->cursor().setShape(Qt::ArrowCursor);
|
ui->centralwidget->cursor().setShape(Qt::ArrowCursor);
|
||||||
|
QStringList test = ui->khistorycombobox->historyItems();
|
||||||
|
sleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::listServices(string server, int portN)
|
void MainWindow::listServices()
|
||||||
{
|
{
|
||||||
char cmd[4096];
|
char cmd[4096];
|
||||||
string line;
|
string line;
|
||||||
@ -97,7 +119,7 @@ void MainWindow::listServices(string server, int portN)
|
|||||||
vector<string> v;
|
vector<string> v;
|
||||||
char service[4096];
|
char service[4096];
|
||||||
|
|
||||||
sprintf(cmd, "rsync --contimeout=10 -P \"%s::\" --port %d ", server.c_str(), portN );
|
sprintf(cmd, "rsync --contimeout=10 -P \"%s::\" --port %d ", this->connexion.server.c_str(), this->connexion.port );
|
||||||
redi::ipstream in(cmd, redi::pstreams::pstdout | redi::pstreams::pstderr);
|
redi::ipstream in(cmd, redi::pstreams::pstdout | redi::pstreams::pstderr);
|
||||||
while (getline(in.out(), line))
|
while (getline(in.out(), line))
|
||||||
{
|
{
|
||||||
@ -167,25 +189,24 @@ void MainWindow::scanDir(string server, int portN, QTreeWidgetItem *parent, stri
|
|||||||
|
|
||||||
bool MainWindow::isIpAddress(string server)
|
bool MainWindow::isIpAddress(string server)
|
||||||
{
|
{
|
||||||
bool returnCode = false;
|
|
||||||
vector<string> r;
|
vector<string> r;
|
||||||
stringstream ss;
|
|
||||||
int elementN;
|
int elementN;
|
||||||
|
QString qr;
|
||||||
|
bool ok;
|
||||||
|
|
||||||
r = explode(server, '.');
|
r = explode(server, '.', 5);
|
||||||
if (r.size() == 4)
|
if (r.size() == 4)
|
||||||
{
|
{
|
||||||
for (auto element : r)
|
for (auto element : r)
|
||||||
{
|
{
|
||||||
ss << element;
|
elementN = QString::fromStdString(element).toInt(&ok);
|
||||||
ss >> elementN;
|
if (elementN < 0 or elementN > 255 or ok == false)
|
||||||
if (elementN >0 and elementN < 256)
|
|
||||||
{
|
{
|
||||||
returnCode &= true;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnCode;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::validateServer(string server)
|
bool MainWindow::validateServer(string server)
|
||||||
@ -227,6 +248,9 @@ bool MainWindow::validateServer(string server)
|
|||||||
if ( flag == false)
|
if ( flag == false)
|
||||||
{
|
{
|
||||||
flag = isIpAddress(server);
|
flag = isIpAddress(server);
|
||||||
|
}
|
||||||
|
if ( flag == false)
|
||||||
|
{
|
||||||
QMessageBox::warning(
|
QMessageBox::warning(
|
||||||
this,
|
this,
|
||||||
"RsyncUI",
|
"RsyncUI",
|
||||||
@ -247,21 +271,11 @@ void MainWindow::on_khistorycombobox_returnPressed()
|
|||||||
populateList();
|
populateList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*void MainWindow::on_portEdit_userTextChanged()
|
|
||||||
{
|
|
||||||
populateTree();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
void MainWindow::on_portEdit_returnPressed()
|
void MainWindow::on_portEdit_returnPressed()
|
||||||
{
|
{
|
||||||
populateList();
|
populateList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_khistorycombobox_textActivated()
|
|
||||||
{
|
|
||||||
populateList();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column)
|
void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -304,41 +318,110 @@ QTreeWidgetItem * MainWindow::addTreeChild(QTreeWidgetItem *parent, QString name
|
|||||||
|
|
||||||
void MainWindow::on_listWidget_clicked(const QModelIndex &index)
|
void MainWindow::on_listWidget_clicked(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
|
vector<string> v;
|
||||||
|
v = explode(ui->listWidget->currentItem()->text().toStdString(), '\n', 2);
|
||||||
|
this->downloading.service = v[0];
|
||||||
populateTree();
|
populateTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_listDownload_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
|
|
||||||
{
|
|
||||||
cout << current->text().toStdString() << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column)
|
void MainWindow::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column)
|
||||||
{
|
{
|
||||||
string path;
|
|
||||||
QFuture<void> future;
|
QFuture<void> future;
|
||||||
QFutureWatcher<void> watcher;
|
|
||||||
QString savePath;
|
|
||||||
QFileDialog dialog;
|
QFileDialog dialog;
|
||||||
QString dirPath;
|
QCheckBox *cb = new QCheckBox("Okay I understand");
|
||||||
/*int p[2];
|
|
||||||
|
|
||||||
if (pipe(p) < 0)
|
item = ui->treeWidget->currentItem();
|
||||||
|
this->downloading.path = item->text(0).toStdString();
|
||||||
|
while(item->parent() != NULL)
|
||||||
{
|
{
|
||||||
return;
|
item = item->parent();
|
||||||
}*/
|
this->downloading.path = item->text(0).toStdString() + "/" + this->downloading.path;
|
||||||
dirPath = getenv("HOME");
|
|
||||||
dirPath.append("/Vidéos/");
|
|
||||||
savePath = dialog.getExistingDirectory(this, tr("Choose directory to save file"), dirPath, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
|
||||||
downloadFile downloadO;
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
//QProgressDialog progress("Downloading file ...", "Abort Download", 0, 100, this);
|
//dirPath.append("/Vidéos/");
|
||||||
|
if (this->downloading.savePath.empty())
|
||||||
|
{
|
||||||
|
if (this->downloading.dirPath.toStdString().empty())
|
||||||
|
{
|
||||||
|
this->downloading.dirPath = getenv("HOME");
|
||||||
|
}
|
||||||
|
|
||||||
ui->progressBar->setWindowModality(Qt::WindowModal);
|
this->downloading.savePath = dialog.getExistingDirectory(this, tr("Choose directory to save file"), this->downloading.dirPath, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks).toStdString();
|
||||||
|
if (!this->downloading.savePath.empty() && this->downloading.pid == 0)
|
||||||
|
{
|
||||||
|
startDownloading();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ui->listDownload->addItem(QString::fromStdString(this->downloading.path));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::startDownloading()
|
||||||
|
{
|
||||||
ui->progressBar->setValue(0);
|
ui->progressBar->setValue(0);
|
||||||
ui->progressBar->show();
|
ui->progressBar->show();
|
||||||
connect(&watcher, &QFutureWatcherBase::finished, ui->progressBar, &QProgressBar::hide);
|
|
||||||
connect(&downloadO, &downloadFile::progressSignal, ui->progressBar, &QProgressBar::setValue);
|
QtConcurrent::run(&this->downloadO, &downloadFile::download, this);
|
||||||
future = QtConcurrent::run(&this->MyObject, &downloadFile::download, savePath, this);
|
|
||||||
watcher.setFuture(future);
|
}
|
||||||
|
|
||||||
|
void MainWindow::stoppingDownload()
|
||||||
|
{
|
||||||
|
emit (stopDownloading(this->downloading.pid));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::downloadFinished()
|
||||||
|
{
|
||||||
|
ui->progressBar->hide();
|
||||||
|
delete ui->listDownload->takeItem(0);
|
||||||
|
this->downloading.pid = 0;
|
||||||
|
if (ui->listDownload->count() != 0)
|
||||||
|
{
|
||||||
|
this->downloading.path = ui->listDownload->item(0)->text().toStdString();
|
||||||
|
startDownloading();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_listDownload_itemClicked(QListWidgetItem *item)
|
||||||
|
{
|
||||||
|
QFileDialog dialog;
|
||||||
|
QMessageBox::StandardButton reply;
|
||||||
|
|
||||||
|
cout << item->text().toStdString() << endl;
|
||||||
|
if (item->listWidget()->row(item) == 0)
|
||||||
|
{
|
||||||
|
reply = QMessageBox::question(
|
||||||
|
this,
|
||||||
|
"RsyncUI",
|
||||||
|
tr("Do you want to stop downloading and delete this file from download queue ?"),
|
||||||
|
QMessageBox::Yes|QMessageBox::No,
|
||||||
|
QMessageBox::No);
|
||||||
|
if (reply == QMessageBox::Yes)
|
||||||
|
{
|
||||||
|
emit (stopDownloading(this->downloading.pid));
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
reply = QMessageBox::question(
|
||||||
|
this,
|
||||||
|
"RsyncUI",
|
||||||
|
tr("Do you want to delete this file from download queue ?"),
|
||||||
|
QMessageBox::Yes|QMessageBox::No,
|
||||||
|
QMessageBox::No);
|
||||||
|
if (reply == QMessageBox::Yes)
|
||||||
|
{
|
||||||
|
ui->listDownload->removeItemWidget(item);
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::loadSettings()
|
||||||
|
{
|
||||||
|
this->settings.value("serverlist");
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::saveSettings()
|
||||||
|
{
|
||||||
|
//ui->khistorycombobox->
|
||||||
}
|
}
|
||||||
|
87
mainwindow.h
87
mainwindow.h
@ -7,55 +7,86 @@
|
|||||||
#include <QListWidgetItem>
|
#include <QListWidgetItem>
|
||||||
#include "downloadfile.h"
|
#include "downloadfile.h"
|
||||||
#include <QProgressDialog>
|
#include <QProgressDialog>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui { class MainWindow; }
|
namespace Ui { class MainWindow; }
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class Connexion
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::string bandwidthLimit = "1M";
|
||||||
|
std::string server;
|
||||||
|
int port = 873;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Downloading
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::string service;
|
||||||
|
std::string path;
|
||||||
|
std::string defaultSavePath;
|
||||||
|
std::string savePath;
|
||||||
|
QString dirPath;
|
||||||
|
int pid = 0;
|
||||||
|
};
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
MainWindow(QWidget *parent = nullptr);
|
MainWindow(QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
QProgressDialog *progress;
|
QProgressDialog *progress;
|
||||||
void displayTree();
|
void displayTree();
|
||||||
void populateTree();
|
void populateTree();
|
||||||
void populateList();
|
void populateList();
|
||||||
void listServices(std::string server, int portN);
|
void listServices();
|
||||||
bool validateServer(std::string server);
|
bool validateServer(std::string server);
|
||||||
bool isIpAddress(std::string server);
|
bool isIpAddress(std::string server);
|
||||||
QTreeWidgetItem * addTreeRoot(QString name, QString description);
|
QTreeWidgetItem * addTreeRoot(QString name, QString description);
|
||||||
QTreeWidgetItem * addTreeChild(QTreeWidgetItem *parent, QString name, QString size);
|
QTreeWidgetItem * addTreeChild(QTreeWidgetItem *parent, QString name, QString size);
|
||||||
void scanDir(std::string server, int portN, QTreeWidgetItem *parent = NULL, std::string path = "" );
|
void scanDir(std::string server, int portN, QTreeWidgetItem *parent = NULL, std::string path = "" );
|
||||||
|
void startDownloading();
|
||||||
|
void loadSettings();
|
||||||
|
void saveSettings();
|
||||||
|
|
||||||
private slots:
|
Connexion connexion;
|
||||||
void on_khistorycombobox_returnPressed();
|
Downloading downloading;
|
||||||
|
downloadFile downloadO;
|
||||||
|
QSettings settings;
|
||||||
|
|
||||||
//void on_portEdit_userTextChanged();
|
private slots:
|
||||||
|
void on_khistorycombobox_returnPressed();
|
||||||
|
|
||||||
void on_portEdit_returnPressed();
|
//void on_portEdit_userTextChanged();
|
||||||
|
|
||||||
void on_khistorycombobox_textActivated();
|
void on_portEdit_returnPressed();
|
||||||
|
|
||||||
void on_treeWidget_itemClicked(QTreeWidgetItem *item, int column);
|
void on_treeWidget_itemClicked(QTreeWidgetItem *item, int column);
|
||||||
|
|
||||||
void on_treeWidget_customContextMenuRequested();
|
void on_treeWidget_customContextMenuRequested();
|
||||||
|
|
||||||
void on_actionDownload_triggered();
|
void on_actionDownload_triggered();
|
||||||
|
|
||||||
void on_listWidget_clicked(const QModelIndex &index);
|
void on_listWidget_clicked(const QModelIndex &index);
|
||||||
|
|
||||||
void on_listDownload_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
|
void on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column);
|
||||||
|
|
||||||
void on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column);
|
void downloadFinished();
|
||||||
|
|
||||||
public slots:
|
void stoppingDownload();
|
||||||
|
|
||||||
|
void on_listDownload_itemClicked(QListWidgetItem *item);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void stopDownloading(int);
|
||||||
|
|
||||||
private:
|
|
||||||
downloadFile MyObject;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
@ -226,7 +226,7 @@
|
|||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="selectionMode">
|
<property name="selectionMode">
|
||||||
<enum>QAbstractItemView::MultiSelection</enum>
|
<enum>QAbstractItemView::SingleSelection</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="selectionBehavior">
|
<property name="selectionBehavior">
|
||||||
<enum>QAbstractItemView::SelectItems</enum>
|
<enum>QAbstractItemView::SelectItems</enum>
|
||||||
@ -290,14 +290,33 @@
|
|||||||
<height>30</height>
|
<height>30</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menudebug">
|
<widget class="QMenu" name="menu">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>debug</string>
|
<string>Menu</string>
|
||||||
</property>
|
</property>
|
||||||
|
<addaction name="DefaultSaveFolder"/>
|
||||||
</widget>
|
</widget>
|
||||||
<addaction name="menudebug"/>
|
<addaction name="menu"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar"/>
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
<action name="actionMenu">
|
||||||
|
<property name="text">
|
||||||
|
<string>Menu</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="DefaultSaveFolder">
|
||||||
|
<property name="text">
|
||||||
|
<string>Default save folder</string>
|
||||||
|
</property>
|
||||||
|
<property name="iconText">
|
||||||
|
<string>Default save folder</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionBandwidth_limit">
|
||||||
|
<property name="text">
|
||||||
|
<string>Bandwidth limit</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
@ -42,7 +42,7 @@ const vector<string> explode(const string& s, const char& c, int n = 0)
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE * popen2(char * cmd, string type, int & pid)
|
FILE * popen2(array<string, 7> argv, string type, int & pid)
|
||||||
{
|
{
|
||||||
pid_t child_pid;
|
pid_t child_pid;
|
||||||
int fd[2];
|
int fd[2];
|
||||||
@ -69,8 +69,11 @@ FILE * popen2(char * cmd, string type, int & pid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
setpgid(child_pid, child_pid); //Needed so negative PIDs can kill children of /bin/sh
|
setpgid(child_pid, child_pid); //Needed so negative PIDs can kill children of /bin/sh
|
||||||
execl(cmd, "");
|
if (execl(argv[0].c_str(), argv[0].c_str(), argv[1].c_str(), argv[2].c_str(), argv[3].c_str(), argv[4].c_str(), argv[5].c_str(), NULL ) == -1)
|
||||||
exit(0);
|
{
|
||||||
|
perror("execl error => ");
|
||||||
|
}
|
||||||
|
exit (0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
2
tools.h
2
tools.h
@ -8,7 +8,7 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
const vector<string> explode(const string& s, const char& c, int n = 0);
|
const vector<string> explode(const string& s, const char& c, int n = 0);
|
||||||
FILE * popen2(char * command, string type, int & pid);
|
FILE * popen2(array<string, 7> argv, string type, int & pid);
|
||||||
int pclose2(FILE * fp, pid_t pid);
|
int pclose2(FILE * fp, pid_t pid);
|
||||||
|
|
||||||
#endif // TOOLS_H
|
#endif // TOOLS_H
|
||||||
|
Loading…
Reference in New Issue
Block a user