Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
64ef7d9c87 | |||
381054b340 | |||
470b88f422 | |||
a235d2f745 | |||
00e428c5b6 | |||
a766bffd85 | |||
200006e50f | |||
029be91dc8 | |||
fe3e68d205 | |||
51021023fc | |||
8ccab25a98 | |||
74e2283aa0 | |||
67fb0a4b7e | |||
317a6b8010 | |||
e278a58aae | |||
afe4c6e9c9 | |||
fb126c8b66 | |||
571da3d8a3 |
@ -2,6 +2,7 @@ QT += core gui
|
||||
QT += KItemViews
|
||||
QT += KCompletion
|
||||
QT += widgets
|
||||
QT += network
|
||||
|
||||
LIBS += -lqt5keychain
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
Name: rsyncui
|
||||
Summary: Client for rsync server
|
||||
Version: 2.12.5
|
||||
Version: 2.13.2
|
||||
Release: %mkrel 1
|
||||
License: GPLv3
|
||||
Group: Networking/Remote access
|
||||
|
@ -52,7 +52,7 @@ void MainWindow::download()
|
||||
{
|
||||
info(DEBUGMACRO, "Adding user to server (user@server");
|
||||
this->downloading.user = this->connexion.user;
|
||||
server = this->connexion.user + "@" + this->downloading.server;
|
||||
server = this->connexion.user + "@" + "[" + this->downloading.server + "]";
|
||||
env.insert("RSYNC_PASSWORD", this->downloading.password); // Add an environment variable
|
||||
this->downloading.process->setProcessEnvironment(env);
|
||||
}
|
||||
@ -64,7 +64,7 @@ void MainWindow::download()
|
||||
param << "--bwlimit=" + QString::number(this->connexion.bandwidthLimit) + bwUnitChar[this->connexion.bandwidthLimitUnit];
|
||||
}
|
||||
|
||||
ipversion = validateServer(server);
|
||||
ipversion = validateServer(&server);
|
||||
|
||||
if (downloading.ipversion == 4 || downloading.ipversion == 6)
|
||||
{
|
||||
@ -74,7 +74,7 @@ void MainWindow::download()
|
||||
|
||||
param << "--port" << QString::number(this->downloading.port).trimmed();
|
||||
param << "-aXP";
|
||||
param << "[" + server + "]::" + this->downloading.service.trimmed() + "/" + this->downloading.path.trimmed() << this->downloading.savePath.trimmed() + "/";
|
||||
param << "[" + server + "]::" + this->downloading.service.trimmed() + "/" + preparePath(this->downloading.path) << preparePath(this->downloading.savePath) + "/";
|
||||
|
||||
info(DEBUGMACRO, cmd + " " + param.join(" "));
|
||||
|
||||
@ -102,6 +102,7 @@ void MainWindow::readRsyncOutput()
|
||||
{
|
||||
list.clear();
|
||||
line = QString::fromUtf8(this->downloading.process->readLine());
|
||||
info(DEBUGMACRO, "downloading progress : " + line);
|
||||
if (line.isEmpty())
|
||||
{
|
||||
break;
|
||||
|
2
main.cpp
2
main.cpp
@ -1,6 +1,7 @@
|
||||
#include "mainwindow.h"
|
||||
#include "tools.h"
|
||||
#include <QTranslator>
|
||||
#include <QHostInfo>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -29,5 +30,6 @@ int main(int argc, char *argv[])
|
||||
MainWindow w;
|
||||
info(DEBUGMACRO, "RsyncUI begining");
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
244
mainwindow.cpp
244
mainwindow.cpp
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
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);
|
||||
|
||||
@ -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,24 +639,26 @@ 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;
|
||||
|
||||
|
||||
if (!connexion->user.isEmpty())
|
||||
{
|
||||
user = connexion->user + "@";
|
||||
env.insert("RSYNC_PASSWORD", connexion->password); // Add an environment variable
|
||||
}else
|
||||
{
|
||||
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(" "));
|
||||
|
||||
@ -733,37 +759,59 @@ bool MainWindow::scanDir(Connexion * connexion, QTreeWidgetItem *parent, QString
|
||||
}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())
|
||||
{
|
||||
server->clear();
|
||||
server->append(serverAddress.toString());
|
||||
info(DEBUGMACRO, "Server address : " + *server);
|
||||
}else
|
||||
{
|
||||
if (!serverAddress.setAddress(*server))
|
||||
{
|
||||
|
||||
info(DEBUGMACRO, "Digging server name");
|
||||
|
||||
cmd = "dig";
|
||||
param << "-t A"; // IP V4 query
|
||||
param << "-t AAAA"; // IP V6 query
|
||||
param << server.trimmed() ;
|
||||
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(" "));
|
||||
|
||||
@ -797,12 +845,11 @@ uint MainWindow::validateServer(QString server)
|
||||
info(DEBUGMACRO, "line is:\n" + line);
|
||||
responseList = line.split(QRegExp("\\s+"));
|
||||
info(DEBUGMACRO, "ip Address is => " + responseList.at(4));
|
||||
if(responseList.at(3) == "A")
|
||||
if (serverAddress.setAddress(responseList.at(4)))
|
||||
{
|
||||
return 4;
|
||||
}else if(responseList.at(3) == "AAAA")
|
||||
{
|
||||
return 6;
|
||||
//error ("Address " + responseList.at(4) + " is bad");
|
||||
server->clear();
|
||||
server->append(serverAddress.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -811,23 +858,30 @@ uint MainWindow::validateServer(QString server)
|
||||
}
|
||||
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,11 +1054,13 @@ 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");
|
||||
|
||||
if (this->treeviewClicked == true)
|
||||
{
|
||||
info(DEBUGMACRO, "double click ignored");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1040,7 +1097,7 @@ void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, bool downloadD
|
||||
}else
|
||||
{
|
||||
this->downloading.savePath = this->settings.value(str).toString();
|
||||
info(DEBUGMACRO, "saving folder" + this->downloading.savePath);
|
||||
info(DEBUGMACRO, "saving folder : " + this->downloading.savePath);
|
||||
}
|
||||
|
||||
// Item is a file
|
||||
@ -1120,13 +1177,20 @@ void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, bool downloadD
|
||||
if (item->isExpanded() == false)
|
||||
{
|
||||
info(DEBUGMACRO, "Item is not expanded");
|
||||
while (this->rescan)
|
||||
{
|
||||
//if (this->rescan)
|
||||
//{
|
||||
info(DEBUGMACRO, "Re-scanning path: " + this->connexion.service + "/" + path +"/");
|
||||
scanDir(&this->connexion, item, 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)
|
||||
@ -1237,7 +1301,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);
|
||||
@ -1331,7 +1395,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());
|
||||
@ -1498,7 +1562,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;
|
||||
@ -1582,3 +1646,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;
|
||||
}
|
||||
}
|
||||
|
15
mainwindow.h
15
mainwindow.h
@ -66,6 +66,7 @@ class Connexion
|
||||
uint port = 873;
|
||||
bool quit = false;
|
||||
void clear();
|
||||
bool paused = false;
|
||||
};
|
||||
|
||||
class Downloading
|
||||
@ -81,6 +82,8 @@ class Downloading
|
||||
int port = 873;
|
||||
QProcess * process = nullptr;
|
||||
bool quit = false;
|
||||
bool paused = false;
|
||||
|
||||
void clear();
|
||||
};
|
||||
|
||||
@ -117,8 +120,8 @@ class MainWindow : public QMainWindow
|
||||
QSystemTrayIcon * trayIcon;
|
||||
QString icon = "/usr/share/icons/RsyncUI.png";
|
||||
bool rescan = false;
|
||||
bool stopDlAsked;
|
||||
bool treeviewClicked;
|
||||
bool stopDlAsked = false;
|
||||
bool treeviewClicked = false;
|
||||
bool initialization = true;
|
||||
bool exiting = false;
|
||||
|
||||
@ -154,7 +157,7 @@ class MainWindow : public QMainWindow
|
||||
void populateTree();
|
||||
void populateList(QString server, uint port);
|
||||
void listServices();
|
||||
uint validateServer(QString server);
|
||||
uint validateServer(QString * server);
|
||||
void addTreeItem(QString name, QString fileSize, QString fullsize, QString type, QString date, bool isDir, QString dirName, QTreeWidgetItem *parent);
|
||||
bool scanDir(Connexion * connexion, QTreeWidgetItem *parent = NULL, QString path = "" );
|
||||
void startDownloading();
|
||||
@ -219,6 +222,12 @@ class MainWindow : public QMainWindow
|
||||
|
||||
//void on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column);
|
||||
|
||||
void on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column);
|
||||
|
||||
void on_treeWidget_doubleClicked(const QModelIndex &index);
|
||||
|
||||
void on_actionPause_downloads_triggered();
|
||||
|
||||
signals:
|
||||
void stopDownloading(QProcess *);
|
||||
void progressSignal(int);
|
||||
|
@ -407,6 +407,7 @@
|
||||
<addaction name="actionAbout"/>
|
||||
<addaction name="actionAbout_Qt"/>
|
||||
<addaction name="actionExit"/>
|
||||
<addaction name="actionPause_downloads"/>
|
||||
</widget>
|
||||
<action name="DefaultSaveFolder">
|
||||
<property name="icon">
|
||||
@ -479,6 +480,20 @@
|
||||
<string>hidden service</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPause_downloads">
|
||||
<property name="icon">
|
||||
<iconset theme="media-playback-pause"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Stop/resume downloads</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Stop/resume downloading </string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>P</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
59
tools.cpp
59
tools.cpp
@ -1,6 +1,8 @@
|
||||
#include "mainwindow.h"
|
||||
#include "tools.h"
|
||||
#include "password.h"
|
||||
#include <QTextStream>
|
||||
#include <QHostAddress>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -53,15 +55,31 @@ QString getFileType(QString filename)
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
QString preparePath(QString path)
|
||||
{
|
||||
return path.trimmed().replace(' ', "\ ");
|
||||
}
|
||||
|
||||
int whatIpVersion(QString ipAddress)
|
||||
{
|
||||
QStringList fieldList;
|
||||
ulong field;
|
||||
uint i;
|
||||
// ulong field;
|
||||
// uint i;
|
||||
uint ipversion;
|
||||
QHostAddress serverAddress;
|
||||
|
||||
info(DEBUGMACRO, "ipVersion of server at " + ipAddress);
|
||||
|
||||
fieldList = ipAddress.split(":");
|
||||
if (!serverAddress.setAddress(ipAddress))
|
||||
{
|
||||
error ("Address " + ipAddress + " is bad");
|
||||
}
|
||||
ipversion = serverAddress.protocol();
|
||||
|
||||
return (ipversion==IPV4?4:6);
|
||||
|
||||
|
||||
/*fieldList = ipAddress.split(":");
|
||||
if (fieldList.count() == 8)
|
||||
{
|
||||
for (i=0;i<8;i++)
|
||||
@ -88,8 +106,41 @@ int whatIpVersion(QString ipAddress)
|
||||
}
|
||||
info(DEBUGMACRO, "Address is ip V4");
|
||||
return 4;
|
||||
}*/
|
||||
}
|
||||
return 0;
|
||||
|
||||
QHostAddress searchHosts(QString server)
|
||||
{
|
||||
QString line = "";
|
||||
QStringList hosts;
|
||||
QFile fileHandle("/etc/hosts");
|
||||
QHostAddress serverAddress;
|
||||
|
||||
info(DEBUGMACRO, "reading /etc/hosts");
|
||||
if (!fileHandle.open(QIODevice::ReadOnly))
|
||||
{
|
||||
QMessageBox::information(0,MainWindow::tr("Error"), fileHandle.errorString());
|
||||
}else
|
||||
{
|
||||
QTextStream in(&fileHandle);
|
||||
|
||||
while(!in.atEnd())
|
||||
{
|
||||
line = in.readLine();
|
||||
hosts = line.split(QRegularExpression("\\s+"));
|
||||
if (hosts.contains(server))
|
||||
{
|
||||
//if (!serverAddress.isNull()) // and serverAddress.protocol() == QAbstractSocket::IPv4Protocol)
|
||||
//{
|
||||
if (!serverAddress.setAddress(hosts.first()))
|
||||
{
|
||||
error("Error setting address " + hosts.first());
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
return serverAddress;
|
||||
}
|
||||
|
||||
void warning(QString message)
|
||||
|
6
tools.h
6
tools.h
@ -3,6 +3,10 @@
|
||||
|
||||
#define DEBUGMACRO QString(__FILE__) + "->" + QString(Q_FUNC_INFO) + ": " + QString::number(__LINE__) + " -"
|
||||
|
||||
#define IPV4 0
|
||||
#define IPV6 1
|
||||
|
||||
#include <QHostAddress>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
@ -22,5 +26,7 @@ int whatIpVersion(QString server);
|
||||
void warning(QString message);
|
||||
void error(QString message);
|
||||
void info(QString debugHeader, QString message);
|
||||
QString preparePath(QString path);
|
||||
QHostAddress searchHosts(QString server);
|
||||
|
||||
#endif // TOOLS_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user