|
|
|
@ -7,12 +7,9 @@
|
|
|
|
|
#include "tools.h"
|
|
|
|
|
#include "password.h"
|
|
|
|
|
#include <kcombobox.h>
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
#include <klineedit.h>
|
|
|
|
|
#include <khistorycombobox.h>
|
|
|
|
|
#include <kcompletion.h>
|
|
|
|
|
*/
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
#include <QHostInfo>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
@ -104,15 +101,15 @@ MainWindow::MainWindow(QWidget *parent)
|
|
|
|
|
// if last server exists in settings
|
|
|
|
|
if (this->settings.contains("connexion/lastServer"))
|
|
|
|
|
{
|
|
|
|
|
info(DEBUGMACRO, "Setting previous server");
|
|
|
|
|
// set window to previous server/port configuration
|
|
|
|
|
ui->portEdit->setText(this->settings.value("connexion/lastPort").toString());
|
|
|
|
|
ui->khistorycombobox->setCurrentText(this->settings.value("connexion/lastServer").toString());
|
|
|
|
|
info(DEBUGMACRO, "Setting previous server");
|
|
|
|
|
// set window to previous server/port configuration
|
|
|
|
|
ui->portEdit->setText(this->settings.value("connexion/lastPort").toString());
|
|
|
|
|
ui->khistorycombobox->setCurrentText(this->settings.value("connexion/lastServer").toString());
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
info(DEBUGMACRO, "No previous server, so setting only default port");
|
|
|
|
|
ui->portEdit->setText(QString::number(this->connexion.port));
|
|
|
|
|
ui->khistorycombobox->clear();
|
|
|
|
|
info(DEBUGMACRO, "No previous server, so setting only default port");
|
|
|
|
|
ui->portEdit->setText(QString::number(this->connexion.port));
|
|
|
|
|
ui->khistorycombobox->clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// connectors
|
|
|
|
@ -149,11 +146,11 @@ void MainWindow::init()
|
|
|
|
|
info(DEBUGMACRO, "reply text is : " + reply->text());
|
|
|
|
|
if(reply == yes)
|
|
|
|
|
{
|
|
|
|
|
loadDownloadList();
|
|
|
|
|
loadDownloadList();
|
|
|
|
|
}else if (reply == deleteButton)
|
|
|
|
|
{
|
|
|
|
|
// delete saved download list
|
|
|
|
|
deleteDownloadList();
|
|
|
|
|
// delete saved download list
|
|
|
|
|
deleteDownloadList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -323,7 +320,7 @@ void MainWindow::populateTree()
|
|
|
|
|
|
|
|
|
|
info(DEBUGMACRO, "Validating server");
|
|
|
|
|
// validating server's address
|
|
|
|
|
this->connexion.ipversion = validateServer(this->connexion.server);
|
|
|
|
|
this->connexion.ipversion = validateServer(&this->connexion.server);
|
|
|
|
|
if (this->connexion.ipversion != 0)
|
|
|
|
|
{
|
|
|
|
|
// server is validated, scanning directory
|
|
|
|
@ -350,18 +347,22 @@ void MainWindow::populateList(QString server, uint port)
|
|
|
|
|
info(DEBUGMACRO, "populateList() => Populating list of services");
|
|
|
|
|
|
|
|
|
|
info(DEBUGMACRO, "port: " + QString::number(port) + " - server: " + server);
|
|
|
|
|
|
|
|
|
|
if (server.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
ui->listWidget->clear();
|
|
|
|
|
ui->treeWidget->clear();
|
|
|
|
|
return;
|
|
|
|
|
ui->listWidget->clear();
|
|
|
|
|
ui->treeWidget->clear();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ((server != this->connexion.server))
|
|
|
|
|
|
|
|
|
|
if (server != this->connexion.server)
|
|
|
|
|
{
|
|
|
|
|
// Determine version of Ip Protocol
|
|
|
|
|
info(DEBUGMACRO, "Server changed");
|
|
|
|
|
|
|
|
|
|
this->connexion.ipversion = validateServer(&server);
|
|
|
|
|
this->connexion.server = server;
|
|
|
|
|
|
|
|
|
|
if (port != false)
|
|
|
|
|
{
|
|
|
|
|
this->connexion.port = port;
|
|
|
|
@ -370,13 +371,14 @@ void MainWindow::populateList(QString server, uint port)
|
|
|
|
|
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
|
|
|
|
|
|
|
|
|
// verify if server is in history
|
|
|
|
|
this->settings.beginGroup("connexion/server");
|
|
|
|
|
this->settings.beginGroup("connexion/Servers");
|
|
|
|
|
if (this->settings.contains(server))
|
|
|
|
|
{
|
|
|
|
|
this->settings.beginGroup(server);
|
|
|
|
|
info(DEBUGMACRO, "Server configuration exists in settings");
|
|
|
|
|
|
|
|
|
|
// server is in history => setting port value
|
|
|
|
|
port = this->settings.value(server).toUInt();
|
|
|
|
|
port = this->settings.value("port").toUInt();
|
|
|
|
|
this->connexion.ipversion = this->settings.value("ipversion").toUInt();
|
|
|
|
|
ui->portEdit->setText(QString::number(port));
|
|
|
|
|
this->connexion.port = port;
|
|
|
|
@ -384,8 +386,10 @@ void MainWindow::populateList(QString server, uint port)
|
|
|
|
|
ok = true;
|
|
|
|
|
//display list of services
|
|
|
|
|
//listServices(); // TODO clear in listServices
|
|
|
|
|
this->settings.endGroup();
|
|
|
|
|
}
|
|
|
|
|
this->settings.endGroup();
|
|
|
|
|
this->settings.endGroup();
|
|
|
|
|
}
|
|
|
|
|
if (port != this->connexion.port)
|
|
|
|
|
{
|
|
|
|
@ -400,8 +404,8 @@ void MainWindow::populateList(QString server, uint port)
|
|
|
|
|
{
|
|
|
|
|
if (this->connexion.ipversion == 0)
|
|
|
|
|
{
|
|
|
|
|
this->connexion.ipversion = validateServer(server);
|
|
|
|
|
info(DEBUGMACRO, QString::number(this->connexion.ipversion));
|
|
|
|
|
this->connexion.ipversion = validateServer(&server);
|
|
|
|
|
info(DEBUGMACRO, "IP version : " + QString::number(this->connexion.ipversion));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this->connexion.ipversion != 0)
|
|
|
|
@ -411,17 +415,27 @@ void MainWindow::populateList(QString server, uint port)
|
|
|
|
|
info(DEBUGMACRO,"Saving server configuration in settings");
|
|
|
|
|
|
|
|
|
|
// storing serverURL and port in settings
|
|
|
|
|
this->settings.setValue(server, port);
|
|
|
|
|
this->settings.setValue(server, this->connexion.ipversion);
|
|
|
|
|
this->settings.beginGroup("connnexion");
|
|
|
|
|
this->settings.beginGroup("Servers");
|
|
|
|
|
this->settings.beginGroup(server);
|
|
|
|
|
this->settings.setValue("port", port);
|
|
|
|
|
this->settings.setValue("ipversion", this->connexion.ipversion);
|
|
|
|
|
this->settings.endGroup();
|
|
|
|
|
this->settings.endGroup();
|
|
|
|
|
this->settings.endGroup();
|
|
|
|
|
|
|
|
|
|
this->settings.sync();
|
|
|
|
|
this->downloading.server = server;
|
|
|
|
|
this->downloading.port = port;
|
|
|
|
|
this->downloading.ipversion = this->connexion.ipversion;
|
|
|
|
|
|
|
|
|
|
// storing in history of combobox
|
|
|
|
|
ui->khistorycombobox->addToHistory(server);
|
|
|
|
|
|
|
|
|
|
// load and display rsync services of the rsync server
|
|
|
|
|
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
info(DEBUGMACRO, "ERROR : Unknown IP version");
|
|
|
|
|
}
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
@ -429,7 +443,8 @@ void MainWindow::populateList(QString server, uint port)
|
|
|
|
|
}
|
|
|
|
|
listServices();
|
|
|
|
|
|
|
|
|
|
this->settings.beginGroup("Hidden/" + server);
|
|
|
|
|
this->settings.beginGroup("Hidden");
|
|
|
|
|
this->settings.beginGroup(server);
|
|
|
|
|
hidden = this->settings.allKeys();
|
|
|
|
|
if (hidden.count() > 0)
|
|
|
|
|
{
|
|
|
|
@ -444,6 +459,7 @@ void MainWindow::populateList(QString server, uint port)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this->settings.endGroup();
|
|
|
|
|
this->settings.endGroup();
|
|
|
|
|
// clearing listview
|
|
|
|
|
ui->treeWidget->clear();
|
|
|
|
|
QGuiApplication::restoreOverrideCursor(); //setting cursor to default
|
|
|
|
@ -471,7 +487,7 @@ bool MainWindow::testServerPresence(QString service, bool askPassword)
|
|
|
|
|
{
|
|
|
|
|
param << "-" + QString::number(this->connexion.ipversion);
|
|
|
|
|
}
|
|
|
|
|
param << "--contimeout=10" << "-nq" << "--port=" + QString::number(this->connexion.port) << + "[" + this->connexion.server + "]::" + service;
|
|
|
|
|
param << "--contimeout=10" << "-nq" << "--port=" + QString::number(this->connexion.port) << + "[" + this->connexion.server + "]::" + preparePath(service);
|
|
|
|
|
myProcess = new QProcess(this);
|
|
|
|
|
myProcess->setProcessChannelMode(QProcess::MergedChannels);
|
|
|
|
|
myProcess->start(cmd, param);
|
|
|
|
@ -509,7 +525,7 @@ bool MainWindow::testServerPresence(QString service, bool askPassword)
|
|
|
|
|
//list services of the rsync server
|
|
|
|
|
void MainWindow::listServices()
|
|
|
|
|
{
|
|
|
|
|
QString cmd;
|
|
|
|
|
QString cmd = "/usr/bin/rsync";
|
|
|
|
|
QStringList param;
|
|
|
|
|
QString line;
|
|
|
|
|
QString errorRsync;
|
|
|
|
@ -524,7 +540,6 @@ void MainWindow::listServices()
|
|
|
|
|
// clearing listwidget
|
|
|
|
|
ui->listWidget->clear();
|
|
|
|
|
|
|
|
|
|
cmd = "/usr/bin/rsync";
|
|
|
|
|
if (this->connexion.ipversion == 0)
|
|
|
|
|
{
|
|
|
|
|
this->connexion.ipversion = whatIpVersion(this->connexion.server);
|
|
|
|
@ -538,7 +553,12 @@ void MainWindow::listServices()
|
|
|
|
|
{
|
|
|
|
|
param << "-" + QString::number(this->connexion.ipversion).trimmed();
|
|
|
|
|
server = "[" + this->connexion.server + "]";
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
error(tr("Error : Unknown IP version"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
param << "--contimeout=20" << "--port=" + QString::number(this->connexion.port) << server + "::";
|
|
|
|
|
myProcess = new QProcess(this);
|
|
|
|
|
|
|
|
|
@ -561,7 +581,7 @@ void MainWindow::listServices()
|
|
|
|
|
flag = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
info(DEBUGMACRO, "extracting services inforamtions");
|
|
|
|
|
info(DEBUGMACRO, "extracting services informations");
|
|
|
|
|
// extracting name and comment of the service
|
|
|
|
|
v = line.split("\t");
|
|
|
|
|
v[0].replace(" ", "");
|
|
|
|
@ -583,7 +603,7 @@ void MainWindow::listServices()
|
|
|
|
|
// connect to rsync server to get list of files
|
|
|
|
|
bool MainWindow::scanDir(Connexion * connexion, QTreeWidgetItem *parent, QString path)
|
|
|
|
|
{
|
|
|
|
|
QString cmd;
|
|
|
|
|
QString cmd = "rsync";
|
|
|
|
|
QStringList param;
|
|
|
|
|
QStringList sizeA;
|
|
|
|
|
QString line;
|
|
|
|
@ -593,6 +613,7 @@ bool MainWindow::scanDir(Connexion * connexion, QTreeWidgetItem *parent, QString
|
|
|
|
|
QString fileType;
|
|
|
|
|
QString date;
|
|
|
|
|
QString dirName = "";
|
|
|
|
|
QString user;
|
|
|
|
|
QProcess * myProcess;
|
|
|
|
|
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
|
|
|
bool isDir = false;
|
|
|
|
@ -603,9 +624,12 @@ bool MainWindow::scanDir(Connexion * connexion, QTreeWidgetItem *parent, QString
|
|
|
|
|
static uint looping;
|
|
|
|
|
QStringList dirs;
|
|
|
|
|
QString server = connexion->server;
|
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
|
|
info(DEBUGMACRO, "scandir() => connect to rsync server to get list of files");
|
|
|
|
|
|
|
|
|
|
ui->listWidget->setCursor(Qt::WaitCursor);
|
|
|
|
|
|
|
|
|
|
myProcess = new QProcess(this);
|
|
|
|
|
myProcess->setProcessChannelMode(QProcess::MergedChannels);
|
|
|
|
|
|
|
|
|
@ -615,219 +639,249 @@ bool MainWindow::scanDir(Connexion * connexion, QTreeWidgetItem *parent, QString
|
|
|
|
|
}
|
|
|
|
|
if (nChild == 0)
|
|
|
|
|
{
|
|
|
|
|
if (!connexion->user.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
server.prepend(connexion->user + "@");
|
|
|
|
|
env.insert("RSYNC_PASSWORD", connexion->password); // Add an environment variable
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
server.prepend("anonymous@");
|
|
|
|
|
env.insert("RSYNC_PASSWORD", "anonymous"); // Add an environment variable
|
|
|
|
|
}
|
|
|
|
|
myProcess->setProcessEnvironment(env);
|
|
|
|
|
|
|
|
|
|
info(DEBUGMACRO, "ipversion => " + QString::number(connexion->ipversion));
|
|
|
|
|
cmd = "rsync";
|
|
|
|
|
if(this->connexion.ipversion == 4 || this->connexion.ipversion == 6)
|
|
|
|
|
{
|
|
|
|
|
param << "-" + QString::number(connexion->ipversion).trimmed();
|
|
|
|
|
}
|
|
|
|
|
param << "--contimeout=20" << "--port=" + QString::number(connexion->port) << "[" + server + "]::" + path;
|
|
|
|
|
myProcess->setProcessEnvironment(env);
|
|
|
|
|
|
|
|
|
|
info(DEBUGMACRO, cmd + " " + param.join(" "));
|
|
|
|
|
|
|
|
|
|
myProcess->start(cmd, param);
|
|
|
|
|
this->rescan = true;
|
|
|
|
|
|
|
|
|
|
info(DEBUGMACRO, "Waiting server response");
|
|
|
|
|
// waiting for response of the server with a timeout of 10 seconds
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
readOk = myProcess->waitForReadyRead(10000);
|
|
|
|
|
if (readOk)
|
|
|
|
|
info(DEBUGMACRO, "ipversion => " + QString::number(connexion->ipversion));
|
|
|
|
|
if(this->connexion.ipversion == 4 || this->connexion.ipversion == 6)
|
|
|
|
|
{
|
|
|
|
|
while (!flag)
|
|
|
|
|
{
|
|
|
|
|
line = QString::fromUtf8(myProcess->readLine());
|
|
|
|
|
// line empty then buffer is empty so returning to wait new datas
|
|
|
|
|
if (line.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
flag = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (line.contains("auth failed"))
|
|
|
|
|
{
|
|
|
|
|
myProcess->readAllStandardOutput();
|
|
|
|
|
getUserPassword(connexion);
|
|
|
|
|
if (looping <= 1)
|
|
|
|
|
{
|
|
|
|
|
this->rescan = true;
|
|
|
|
|
looping++;
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
this->rescan = false;
|
|
|
|
|
looping = 0;
|
|
|
|
|
warning(tr("Authentication failed" ));
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// extracting name, size and is dir/file
|
|
|
|
|
line = line.simplified();
|
|
|
|
|
filename = line.section(" ", 4);
|
|
|
|
|
if (filename != '.')
|
|
|
|
|
{
|
|
|
|
|
size = line.section(" ", 1, 1);
|
|
|
|
|
fullsize = size;
|
|
|
|
|
fullsize.remove(",");
|
|
|
|
|
sizeA = size.split(',');
|
|
|
|
|
if (sizeA.count() <= 1)
|
|
|
|
|
{
|
|
|
|
|
size = sizeA.at(0) + " " + UnitText[0] + " ";
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
myProcess->setProcessEnvironment(env);
|
|
|
|
|
size = sizeA.at(0) + "," + sizeA.at(1).left(2) + " " + UnitText[sizeA.count()-1] + " ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (line[0] == "d")
|
|
|
|
|
{
|
|
|
|
|
isDir = true;
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
isDir = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
date = line.section(' ', 2, 2);
|
|
|
|
|
fileType = getFileType(filename);
|
|
|
|
|
if (!path.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
if (path.endsWith('/'))
|
|
|
|
|
{
|
|
|
|
|
path.chop(1);
|
|
|
|
|
}
|
|
|
|
|
dirs = path.split('/');
|
|
|
|
|
dirName = dirs[dirs.size()-1];
|
|
|
|
|
}
|
|
|
|
|
addTreeItem(filename, size, fullsize, fileType, date, isDir, dirName, parent);
|
|
|
|
|
if (passwdOk == false and !connexion->password.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
this->settings.setValue("Passwords/" + connexion->server + "/" + connexion->service + "/" + connexion->user, true);
|
|
|
|
|
setPassword(connexion->user, connexion->password);
|
|
|
|
|
this->settings.sync();
|
|
|
|
|
}
|
|
|
|
|
this->rescan = false;
|
|
|
|
|
}
|
|
|
|
|
param << "-" + QString::number(connexion->ipversion).trimmed();
|
|
|
|
|
}
|
|
|
|
|
flag = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!connexion->user.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
user = connexion->user + "@";
|
|
|
|
|
env.insert("RSYNC_PASSWORD", connexion->password); // Add an environment variable
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
if (myProcess->state() == QProcess::Running)
|
|
|
|
|
user = "anonymous@";
|
|
|
|
|
env.insert("RSYNC_PASSWORD", "anonymous"); // Add an environment variable
|
|
|
|
|
}
|
|
|
|
|
param << "--contimeout=20" << "--port=" + QString::number(connexion->port) << user + "[" + server + "]::" + preparePath(path) ;
|
|
|
|
|
|
|
|
|
|
info(DEBUGMACRO, cmd + " " + param.join(" "));
|
|
|
|
|
|
|
|
|
|
myProcess->start(cmd, param);
|
|
|
|
|
this->rescan = true;
|
|
|
|
|
|
|
|
|
|
info(DEBUGMACRO, "Waiting server response");
|
|
|
|
|
// waiting for response of the server with a timeout of 10 seconds
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
if (myProcess->waitForFinished(10000) == 0)
|
|
|
|
|
readOk = myProcess->waitForReadyRead(10000);
|
|
|
|
|
if (readOk)
|
|
|
|
|
{
|
|
|
|
|
warning(tr("The processus does'nt respond: ") + myProcess->errorString());
|
|
|
|
|
while (!flag)
|
|
|
|
|
{
|
|
|
|
|
line = QString::fromUtf8(myProcess->readLine());
|
|
|
|
|
// line empty then buffer is empty so returning to wait new datas
|
|
|
|
|
if (line.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
flag = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (line.contains("auth failed"))
|
|
|
|
|
{
|
|
|
|
|
myProcess->readAllStandardOutput();
|
|
|
|
|
getUserPassword(connexion);
|
|
|
|
|
if (looping <= 1)
|
|
|
|
|
{
|
|
|
|
|
this->rescan = true;
|
|
|
|
|
looping++;
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
this->rescan = false;
|
|
|
|
|
looping = 0;
|
|
|
|
|
warning(tr("Authentication failed" ));
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// extracting name, size and is dir/file
|
|
|
|
|
line = line.simplified();
|
|
|
|
|
filename = line.section(" ", 4);
|
|
|
|
|
if (filename != '.')
|
|
|
|
|
{
|
|
|
|
|
size = line.section(" ", 1, 1);
|
|
|
|
|
fullsize = size;
|
|
|
|
|
fullsize.remove(",");
|
|
|
|
|
sizeA = size.split(',');
|
|
|
|
|
if (sizeA.count() <= 1)
|
|
|
|
|
{
|
|
|
|
|
size = sizeA.at(0) + " " + UnitText[0] + " ";
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
myProcess->setProcessEnvironment(env);
|
|
|
|
|
size = sizeA.at(0) + "," + sizeA.at(1).left(2) + " " + UnitText[sizeA.count()-1] + " ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (line[0] == "d")
|
|
|
|
|
{
|
|
|
|
|
isDir = true;
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
isDir = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
date = line.section(' ', 2, 2);
|
|
|
|
|
fileType = getFileType(filename);
|
|
|
|
|
if (!path.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
if (path.endsWith('/'))
|
|
|
|
|
{
|
|
|
|
|
path.chop(1);
|
|
|
|
|
}
|
|
|
|
|
dirs = path.split('/');
|
|
|
|
|
dirName = dirs[dirs.size()-1];
|
|
|
|
|
}
|
|
|
|
|
addTreeItem(filename, size, fullsize, fileType, date, isDir, dirName, parent);
|
|
|
|
|
if (passwdOk == false and !connexion->password.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
this->settings.setValue("Passwords/" + connexion->server + "/" + connexion->service + "/" + connexion->user, true);
|
|
|
|
|
setPassword(connexion->user, connexion->password);
|
|
|
|
|
this->settings.sync();
|
|
|
|
|
}
|
|
|
|
|
this->rescan = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
flag = false;
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
if (myProcess->state() == QProcess::Running)
|
|
|
|
|
{
|
|
|
|
|
if (myProcess->waitForFinished(10000) == 0)
|
|
|
|
|
{
|
|
|
|
|
warning(tr("The processus does'nt respond: ") + myProcess->errorString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}while(readOk);
|
|
|
|
|
}while(readOk);
|
|
|
|
|
// buffer empty go to waiting new datas
|
|
|
|
|
|
|
|
|
|
testRsyncReturn(this, myProcess);
|
|
|
|
|
ret = testRsyncReturn(this, myProcess);
|
|
|
|
|
myProcess->close();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
ui->listWidget->setCursor(Qt::ArrowCursor);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// validate address server
|
|
|
|
|
uint MainWindow::validateServer(QString server)
|
|
|
|
|
uint MainWindow::validateServer(QString *server)
|
|
|
|
|
{
|
|
|
|
|
QString cmd;
|
|
|
|
|
QStringList param;
|
|
|
|
|
QString line;
|
|
|
|
|
QProcess * myProcess;
|
|
|
|
|
QStringList responseList;
|
|
|
|
|
QFile fileHandle("/etc/hosts");
|
|
|
|
|
|
|
|
|
|
uint ipversion;
|
|
|
|
|
uint ipversion = 0;
|
|
|
|
|
int answerFound = 0;
|
|
|
|
|
int queryPos = 0;
|
|
|
|
|
QHostAddress serverAddress;
|
|
|
|
|
|
|
|
|
|
info(DEBUGMACRO, "ValidateServer() => Validating server address");
|
|
|
|
|
|
|
|
|
|
ipversion = whatIpVersion(server);
|
|
|
|
|
//if (ipversion == 0) // not an Ip address, perhaps a server name
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
|
|
if (ipversion == 0) // not an Ip address, perhaps a server name
|
|
|
|
|
serverAddress = searchHosts(*server);
|
|
|
|
|
if (!serverAddress.isNull())
|
|
|
|
|
{
|
|
|
|
|
info(DEBUGMACRO, "Digging server name");
|
|
|
|
|
|
|
|
|
|
cmd = "dig";
|
|
|
|
|
param << "-t A"; // IP V4 query
|
|
|
|
|
param << "-t AAAA"; // IP V6 query
|
|
|
|
|
param << server.trimmed() ;
|
|
|
|
|
|
|
|
|
|
info(DEBUGMACRO, cmd + " " + param.join(" "));
|
|
|
|
|
|
|
|
|
|
myProcess = new QProcess(this);
|
|
|
|
|
myProcess->start(cmd, param);
|
|
|
|
|
|
|
|
|
|
// making a dig on the server's address
|
|
|
|
|
while(myProcess->waitForReadyRead())
|
|
|
|
|
server->clear();
|
|
|
|
|
server->append(serverAddress.toString());
|
|
|
|
|
info(DEBUGMACRO, "Server address : " + *server);
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
if (!serverAddress.setAddress(*server))
|
|
|
|
|
{
|
|
|
|
|
while (1) //!bflag)
|
|
|
|
|
{
|
|
|
|
|
line = QString::fromUtf8(myProcess->readAllStandardOutput());
|
|
|
|
|
info(DEBUGMACRO, line);
|
|
|
|
|
// line empty then buffer is empty so returning to wait new datas
|
|
|
|
|
if (line.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
answerFound = line.indexOf(";; ANSWER SECTION:") +19;
|
|
|
|
|
info(DEBUGMACRO, "Position of answer line is : " + QString::number(answerFound));
|
|
|
|
|
|
|
|
|
|
if (answerFound != -1)
|
|
|
|
|
info(DEBUGMACRO, "Digging server name");
|
|
|
|
|
|
|
|
|
|
cmd = "dig";
|
|
|
|
|
param << server->trimmed() ;
|
|
|
|
|
if (ipversion == IPV4)
|
|
|
|
|
{
|
|
|
|
|
param << "A"; // IP V4 query
|
|
|
|
|
}else if (ipversion == IPV6)
|
|
|
|
|
{
|
|
|
|
|
param << "AAAA"; // IP V6 query
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
error("Protocol is not IPV4 or IPV6 !!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info(DEBUGMACRO, cmd + " " + param.join(" "));
|
|
|
|
|
|
|
|
|
|
myProcess = new QProcess(this);
|
|
|
|
|
myProcess->start(cmd, param);
|
|
|
|
|
|
|
|
|
|
// making a dig on the server's address
|
|
|
|
|
while(myProcess->waitForReadyRead())
|
|
|
|
|
{
|
|
|
|
|
while (1) //!bflag)
|
|
|
|
|
{
|
|
|
|
|
line = QString::fromUtf8(myProcess->readAllStandardOutput());
|
|
|
|
|
info(DEBUGMACRO, line);
|
|
|
|
|
// line empty then buffer is empty so returning to wait new datas
|
|
|
|
|
if (line.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
info(DEBUGMACRO, "Serching IP address");
|
|
|
|
|
queryPos = line.indexOf(";; Query");
|
|
|
|
|
info(DEBUGMACRO, "Position of Query line is : " + QString::number(queryPos));
|
|
|
|
|
if (answerFound < queryPos)
|
|
|
|
|
break;
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
answerFound = line.indexOf(";; ANSWER SECTION:") + 19;
|
|
|
|
|
info(DEBUGMACRO, "Position of answer line is : " + QString::number(answerFound));
|
|
|
|
|
|
|
|
|
|
if (answerFound != -1)
|
|
|
|
|
{
|
|
|
|
|
line = line.mid(answerFound, queryPos - answerFound);
|
|
|
|
|
info(DEBUGMACRO, "line is:\n" + line);
|
|
|
|
|
responseList = line.split(QRegExp("\\s+"));
|
|
|
|
|
info(DEBUGMACRO, "ip Address is => " + responseList.at(4));
|
|
|
|
|
if(responseList.at(3) == "A")
|
|
|
|
|
info(DEBUGMACRO, "Serching IP address");
|
|
|
|
|
queryPos = line.indexOf(";; Query");
|
|
|
|
|
info(DEBUGMACRO, "Position of Query line is : " + QString::number(queryPos));
|
|
|
|
|
if (answerFound < queryPos)
|
|
|
|
|
{
|
|
|
|
|
return 4;
|
|
|
|
|
}else if(responseList.at(3) == "AAAA")
|
|
|
|
|
{
|
|
|
|
|
return 6;
|
|
|
|
|
line = line.mid(answerFound, queryPos - answerFound);
|
|
|
|
|
info(DEBUGMACRO, "line is:\n" + line);
|
|
|
|
|
responseList = line.split(QRegExp("\\s+"));
|
|
|
|
|
info(DEBUGMACRO, "ip Address is => " + responseList.at(4));
|
|
|
|
|
if (serverAddress.setAddress(responseList.at(4)))
|
|
|
|
|
{
|
|
|
|
|
//error ("Address " + responseList.at(4) + " is bad");
|
|
|
|
|
server->clear();
|
|
|
|
|
server->append(serverAddress.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
myProcess->close();
|
|
|
|
|
}
|
|
|
|
|
myProcess->close();
|
|
|
|
|
}
|
|
|
|
|
info(DEBUGMACRO, "Returning ip version: " + QString::number(ipversion));
|
|
|
|
|
return ipversion;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
info(DEBUGMACRO, "Returning ip version: " + QString::number(ipversion));
|
|
|
|
|
//ipversion = whatIpVersion(*server);
|
|
|
|
|
|
|
|
|
|
ipversion = serverAddress.protocol();
|
|
|
|
|
|
|
|
|
|
return (ipversion==IPV4?4:6);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// slot activated when button connection is clicked
|
|
|
|
|
void MainWindow::on_connectButton_clicked()
|
|
|
|
|
{
|
|
|
|
|
QString server;
|
|
|
|
|
uint port;
|
|
|
|
|
//uint ipversion;
|
|
|
|
|
|
|
|
|
|
info(DEBUGMACRO, "on_connectButton_clicked() => Connexion button clicked");
|
|
|
|
|
port = ui->portEdit->text().toUInt();
|
|
|
|
|
if (port > 0 and port < 65535)
|
|
|
|
|
{
|
|
|
|
|
server = ui->khistorycombobox->currentText();
|
|
|
|
|
//ipversion = validateServer(&server);
|
|
|
|
|
populateList(server, port);
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
@ -874,7 +928,8 @@ void MainWindow::addTreeItem(QString name, QString fileSize, QString fullsize, Q
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
// item is a file
|
|
|
|
|
this->settings.beginGroup("Downloaded/");
|
|
|
|
|
this->settings.beginGroup("Downloaded");
|
|
|
|
|
//TODO add to settings
|
|
|
|
|
this->settings.endGroup();
|
|
|
|
|
treeItem->setText(1,type);
|
|
|
|
|
}
|
|
|
|
@ -999,6 +1054,7 @@ void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, bool downloadD
|
|
|
|
|
QString str;
|
|
|
|
|
QMessageBox::StandardButton reply;
|
|
|
|
|
int sizeFromRsync;
|
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
|
|
info(DEBUGMACRO, "on_treeWidget_itemClicked() => Slot activated when a file is clicked in the treeview");
|
|
|
|
|
|
|
|
|
@ -1029,23 +1085,26 @@ void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, bool downloadD
|
|
|
|
|
str = "Folder/" + this->connexion.server + "/" + this->connexion.service;
|
|
|
|
|
if(!this->settings.contains(str))
|
|
|
|
|
{
|
|
|
|
|
info(DEBUGMACRO, "saving path do not exists, asking for it");
|
|
|
|
|
// saving path do not exists, asking for it
|
|
|
|
|
if(!on_DefaultSaveFolder_triggered())
|
|
|
|
|
{
|
|
|
|
|
cout << "no directory selectioned, ignoring download request" << endl;
|
|
|
|
|
info(DEBUGMACRO, "no directory selectioned, ignoring download request");
|
|
|
|
|
this->treeviewClicked = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
this->downloading.savePath = this->settings.value(str).toString();
|
|
|
|
|
info(DEBUGMACRO, "saving folder : " + this->downloading.savePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Item is a file
|
|
|
|
|
// searching if file exists in savepath
|
|
|
|
|
info(DEBUGMACRO, "searching if file exists in savepath");
|
|
|
|
|
if (QFile::exists(this->downloading.savePath + "/" + path))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
info(DEBUGMACRO, "file exists in savepath");
|
|
|
|
|
QFileInfo fileinfo(this->downloading.savePath + "/" + path);
|
|
|
|
|
if (fileinfo.size() < sizeFromRsync)
|
|
|
|
|
{
|
|
|
|
@ -1089,9 +1148,11 @@ void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, bool downloadD
|
|
|
|
|
if(ui->listDownload->findItems(path, Qt::MatchStartsWith).empty())
|
|
|
|
|
{
|
|
|
|
|
// is there a downloading process ?
|
|
|
|
|
info(DEBUGMACRO, "is there a downloading process ?");
|
|
|
|
|
if (this->downloading.process == nullptr)
|
|
|
|
|
{
|
|
|
|
|
// no downloading process launching it
|
|
|
|
|
info(DEBUGMACRO, "no downloading process launching it");
|
|
|
|
|
this->downloading.path = path;
|
|
|
|
|
this->downloading.server = this->connexion.server;
|
|
|
|
|
this->downloading.port = this->connexion.port;
|
|
|
|
@ -1100,8 +1161,8 @@ void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, bool downloadD
|
|
|
|
|
// wait 1 second to process start
|
|
|
|
|
//sleep(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adding download in download list
|
|
|
|
|
info(DEBUGMACRO, "Downloading process exist, adding download to download list");
|
|
|
|
|
// Adding download to download list
|
|
|
|
|
str = path + " => " + this->connexion.server + "/" + this->connexion.service;
|
|
|
|
|
ui->listDownload->addItem(str);
|
|
|
|
|
}else
|
|
|
|
@ -1111,21 +1172,32 @@ void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, bool downloadD
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
//Item is a Directory
|
|
|
|
|
info(DEBUGMACRO, "Item is a Directory");
|
|
|
|
|
if (item->isExpanded() == false)
|
|
|
|
|
{
|
|
|
|
|
while (this->rescan)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
scanDir(&this->connexion, item, this->connexion.service + "/" + path +"/");
|
|
|
|
|
item->setExpanded(true);
|
|
|
|
|
}
|
|
|
|
|
info(DEBUGMACRO, "Item is not expanded");
|
|
|
|
|
//if (this->rescan)
|
|
|
|
|
//{
|
|
|
|
|
info(DEBUGMACRO, "Re-scanning path: " + this->connexion.service + "/" + path +"/");
|
|
|
|
|
ret = scanDir(&this->connexion, item, this->connexion.service + "/" + path +"/");
|
|
|
|
|
if(!ret)
|
|
|
|
|
{
|
|
|
|
|
item->setExpanded(true);
|
|
|
|
|
}
|
|
|
|
|
//}
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
item->setExpanded(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (config.autosaveCheckbox->checkState() == Qt::Checked)
|
|
|
|
|
{
|
|
|
|
|
info(DEBUGMACRO, "Saving download list");
|
|
|
|
|
saveDownloadList();
|
|
|
|
|
}
|
|
|
|
|
info(DEBUGMACRO, "Exiting");
|
|
|
|
|
this->treeviewClicked = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1228,7 +1300,7 @@ void MainWindow::downloadFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
|
|
|
|
pos = path.lastIndexOf(" => ");
|
|
|
|
|
this->downloading.server = path.midRef(pos+4).toString();
|
|
|
|
|
path.resize(pos);
|
|
|
|
|
this->downloading.port = this->settings.value("connexion/server/" + this->downloading.server).toInt();
|
|
|
|
|
this->downloading.port = this->settings.value("connexion/Servers/" + this->downloading.server + "/port").toInt();
|
|
|
|
|
this->downloading.path = path;
|
|
|
|
|
|
|
|
|
|
//getUserPassword(true);
|
|
|
|
@ -1322,7 +1394,7 @@ void MainWindow::loadSettings()
|
|
|
|
|
// loading connexion settings
|
|
|
|
|
// loading servers history
|
|
|
|
|
info(DEBUGMACRO, "Restoring server combobox history");
|
|
|
|
|
this->settings.beginGroup("connexion/server");
|
|
|
|
|
this->settings.beginGroup("connexion/Servers");
|
|
|
|
|
QStringList servers = this->settings.allKeys();
|
|
|
|
|
this->settings.endGroup();
|
|
|
|
|
ui->khistorycombobox->insertItems(1,this->settings.value("kHistoryComboBox").toStringList());
|
|
|
|
@ -1489,7 +1561,7 @@ void MainWindow::loadDownloadList()
|
|
|
|
|
path.resize(pos);
|
|
|
|
|
pos = path.lastIndexOf(" => ");
|
|
|
|
|
this->downloading.server = path.midRef(pos+4).toString();
|
|
|
|
|
this->downloading.port = this->settings.value("connexion/server/" + this->downloading.server).toInt();
|
|
|
|
|
this->downloading.port = this->settings.value("connexion/Servers/" + this->downloading.server+ "/port").toInt();
|
|
|
|
|
path.resize(pos);
|
|
|
|
|
this->downloading.path = path;
|
|
|
|
|
str = "Folder/" + this->downloading.server + "/" + this->downloading.service;
|
|
|
|
@ -1573,3 +1645,69 @@ void MainWindow::on_actionHiddenService_triggered()
|
|
|
|
|
preparePopulateTree();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column)
|
|
|
|
|
{
|
|
|
|
|
(void) item;
|
|
|
|
|
(void) column;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_treeWidget_doubleClicked(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
(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;
|
|
|
|
|
|
|
|
|
|
//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);
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msgBox.isVisible())
|
|
|
|
|
{
|
|
|
|
|
msgBox.close();
|
|
|
|
|
}
|
|
|
|
|
this->downloading.paused = false;
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
info(DEBUGMACRO, "pausing Download");
|
|
|
|
|
if (kill(children.toLongLong(), SIGTSTP))
|
|
|
|
|
{
|
|
|
|
|
info(DEBUGMACRO, "resuming failed : " + QString::number(errno));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
msgBox.show();
|
|
|
|
|
|
|
|
|
|
this->downloading.paused = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|