Compare commits

..

16 Commits

10 changed files with 324 additions and 134 deletions

View File

@ -2,6 +2,7 @@ QT += core gui
QT += KItemViews QT += KItemViews
QT += KCompletion QT += KCompletion
QT += widgets QT += widgets
QT += network
LIBS += -lqt5keychain LIBS += -lqt5keychain
@ -14,29 +15,29 @@ CONFIG += c++17
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \ SOURCES += \
downloadfile.cpp \ downloadfile.cpp \
main.cpp \ main.cpp \
mainwindow.cpp \ mainwindow.cpp \
password.cpp \ password.cpp \
tools.cpp tools.cpp
HEADERS += \ HEADERS += \
version.h\ version.h\
downloadfile.h \ downloadfile.h \
mainwindow.h \ mainwindow.h \
password.h \ password.h \
tools.h tools.h
FORMS += \ FORMS += \
about.ui \ about.ui \
configuration.ui \ configuration.ui \
mainwindow.ui mainwindow.ui
TRANSLATIONS += \ TRANSLATIONS += \
RsyncUI_fr_FR.ts RsyncUI_fr_FR.ts
INCLUDEPATH += \ INCLUDEPATH += \
/usr/include/KF5 \ /usr/include/KF5 \
/usr/include/qt5keychain \ /usr/include/qt5keychain \
# Default rules for deployment. # Default rules for deployment.
@ -52,7 +53,7 @@ INSTALLS += icon
#RESOURCES += #RESOURCES +=
DISTFILES += \ DISTFILES += \
RsyncUI.desktop RsyncUI.desktop
lang.path = /languages/fr_FR/LC_MESSAGES/ lang.path = /languages/fr_FR/LC_MESSAGES/
lang.path = /usr/share/locale/ lang.path = /usr/share/locale/

View File

@ -2,7 +2,7 @@
Name: rsyncui Name: rsyncui
Summary: Client for rsync server Summary: Client for rsync server
Version: 2.12.6 Version: 2.13.2
Release: %mkrel 1 Release: %mkrel 1
License: GPLv3 License: GPLv3
Group: Networking/Remote access Group: Networking/Remote access

View File

@ -64,7 +64,7 @@ void MainWindow::download()
param << "--bwlimit=" + QString::number(this->connexion.bandwidthLimit) + bwUnitChar[this->connexion.bandwidthLimitUnit]; param << "--bwlimit=" + QString::number(this->connexion.bandwidthLimit) + bwUnitChar[this->connexion.bandwidthLimitUnit];
} }
ipversion = validateServer(server); ipversion = validateServer(&server);
if (downloading.ipversion == 4 || downloading.ipversion == 6) if (downloading.ipversion == 4 || downloading.ipversion == 6)
{ {
@ -74,7 +74,7 @@ void MainWindow::download()
param << "--port" << QString::number(this->downloading.port).trimmed(); param << "--port" << QString::number(this->downloading.port).trimmed();
param << "-aXP"; 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(" ")); info(DEBUGMACRO, cmd + " " + param.join(" "));

View File

@ -1,6 +1,7 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "tools.h" #include "tools.h"
#include <QTranslator> #include <QTranslator>
#include <QHostInfo>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -29,5 +30,6 @@ int main(int argc, char *argv[])
MainWindow w; MainWindow w;
info(DEBUGMACRO, "RsyncUI begining"); info(DEBUGMACRO, "RsyncUI begining");
w.show(); w.show();
return a.exec(); return a.exec();
} }

View File

@ -7,12 +7,9 @@
#include "tools.h" #include "tools.h"
#include "password.h" #include "password.h"
#include <kcombobox.h> #include <kcombobox.h>
#include <signal.h>
/* #include <QTextStream>
#include <klineedit.h> #include <QHostInfo>
#include <khistorycombobox.h>
#include <kcompletion.h>
*/
using namespace std; using namespace std;
@ -104,15 +101,15 @@ MainWindow::MainWindow(QWidget *parent)
// if last server exists in settings // if last server exists in settings
if (this->settings.contains("connexion/lastServer")) if (this->settings.contains("connexion/lastServer"))
{ {
info(DEBUGMACRO, "Setting previous server"); info(DEBUGMACRO, "Setting previous server");
// set window to previous server/port configuration // set window to previous server/port configuration
ui->portEdit->setText(this->settings.value("connexion/lastPort").toString()); ui->portEdit->setText(this->settings.value("connexion/lastPort").toString());
ui->khistorycombobox->setCurrentText(this->settings.value("connexion/lastServer").toString()); ui->khistorycombobox->setCurrentText(this->settings.value("connexion/lastServer").toString());
}else }else
{ {
info(DEBUGMACRO, "No previous server, so setting only default port"); info(DEBUGMACRO, "No previous server, so setting only default port");
ui->portEdit->setText(QString::number(this->connexion.port)); ui->portEdit->setText(QString::number(this->connexion.port));
ui->khistorycombobox->clear(); ui->khistorycombobox->clear();
} }
// connectors // connectors
@ -149,11 +146,11 @@ void MainWindow::init()
info(DEBUGMACRO, "reply text is : " + reply->text()); info(DEBUGMACRO, "reply text is : " + reply->text());
if(reply == yes) if(reply == yes)
{ {
loadDownloadList(); loadDownloadList();
}else if (reply == deleteButton) }else if (reply == deleteButton)
{ {
// delete saved download list // delete saved download list
deleteDownloadList(); deleteDownloadList();
} }
} }
} }
@ -323,7 +320,7 @@ void MainWindow::populateTree()
info(DEBUGMACRO, "Validating server"); info(DEBUGMACRO, "Validating server");
// validating server's address // validating server's address
this->connexion.ipversion = validateServer(this->connexion.server); this->connexion.ipversion = validateServer(&this->connexion.server);
if (this->connexion.ipversion != 0) if (this->connexion.ipversion != 0)
{ {
// server is validated, scanning directory // 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, "populateList() => Populating list of services");
info(DEBUGMACRO, "port: " + QString::number(port) + " - server: " + server); info(DEBUGMACRO, "port: " + QString::number(port) + " - server: " + server);
if (server.isEmpty()) if (server.isEmpty())
{ {
ui->listWidget->clear(); ui->listWidget->clear();
ui->treeWidget->clear(); ui->treeWidget->clear();
return; return;
} }
if ((server != this->connexion.server))
if (server != this->connexion.server)
{ {
// Determine version of Ip Protocol // Determine version of Ip Protocol
info(DEBUGMACRO, "Server changed"); info(DEBUGMACRO, "Server changed");
this->connexion.ipversion = validateServer(&server);
this->connexion.server = server; this->connexion.server = server;
if (port != false) if (port != false)
{ {
this->connexion.port = port; this->connexion.port = port;
@ -403,7 +404,7 @@ void MainWindow::populateList(QString server, uint port)
{ {
if (this->connexion.ipversion == 0) if (this->connexion.ipversion == 0)
{ {
this->connexion.ipversion = validateServer(server); this->connexion.ipversion = validateServer(&server);
info(DEBUGMACRO, "IP version : " + QString::number(this->connexion.ipversion)); info(DEBUGMACRO, "IP version : " + QString::number(this->connexion.ipversion));
} }
@ -486,7 +487,7 @@ bool MainWindow::testServerPresence(QString service, bool askPassword)
{ {
param << "-" + QString::number(this->connexion.ipversion); 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 = new QProcess(this);
myProcess->setProcessChannelMode(QProcess::MergedChannels); myProcess->setProcessChannelMode(QProcess::MergedChannels);
myProcess->start(cmd, param); myProcess->start(cmd, param);
@ -623,9 +624,12 @@ bool MainWindow::scanDir(Connexion * connexion, QTreeWidgetItem *parent, QString
static uint looping; static uint looping;
QStringList dirs; QStringList dirs;
QString server = connexion->server; QString server = connexion->server;
bool ret = false;
info(DEBUGMACRO, "scandir() => connect to rsync server to get list of files"); info(DEBUGMACRO, "scandir() => connect to rsync server to get list of files");
ui->listWidget->setCursor(Qt::WaitCursor);
myProcess = new QProcess(this); myProcess = new QProcess(this);
myProcess->setProcessChannelMode(QProcess::MergedChannels); myProcess->setProcessChannelMode(QProcess::MergedChannels);
@ -654,7 +658,7 @@ bool MainWindow::scanDir(Connexion * connexion, QTreeWidgetItem *parent, QString
user = "anonymous@"; user = "anonymous@";
env.insert("RSYNC_PASSWORD", "anonymous"); // Add an environment variable env.insert("RSYNC_PASSWORD", "anonymous"); // Add an environment variable
} }
param << "--contimeout=20" << "--port=" + QString::number(connexion->port) << user + "[" + server + "]::" + path; param << "--contimeout=20" << "--port=" + QString::number(connexion->port) << user + "[" + server + "]::" + preparePath(path) ;
info(DEBUGMACRO, cmd + " " + param.join(" ")); info(DEBUGMACRO, cmd + " " + param.join(" "));
@ -755,102 +759,129 @@ bool MainWindow::scanDir(Connexion * connexion, QTreeWidgetItem *parent, QString
}while(readOk); }while(readOk);
// buffer empty go to waiting new datas // buffer empty go to waiting new datas
testRsyncReturn(this, myProcess); ret = testRsyncReturn(this, myProcess);
myProcess->close(); myProcess->close();
} }
return false; ui->listWidget->setCursor(Qt::ArrowCursor);
return ret;
} }
// validate address server // validate address server
uint MainWindow::validateServer(QString server) uint MainWindow::validateServer(QString *server)
{ {
QString cmd; QString cmd;
QStringList param; QStringList param;
QString line; QString line;
QProcess * myProcess; QProcess * myProcess;
QStringList responseList; QStringList responseList;
QFile fileHandle("/etc/hosts");
uint ipversion; uint ipversion = 0;
int answerFound = 0; int answerFound = 0;
int queryPos = 0; int queryPos = 0;
QHostAddress serverAddress;
info(DEBUGMACRO, "ValidateServer() => Validating server address"); 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"); server->clear();
server->append(serverAddress.toString());
cmd = "dig"; info(DEBUGMACRO, "Server address : " + *server);
param << server.trimmed() ; }else
param << "A"; // IP V4 query {
param << server.trimmed() ; if (!serverAddress.setAddress(*server))
param << "AAAA"; // IP V6 query
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())
{
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"); break;
queryPos = line.indexOf(";; Query"); }else
info(DEBUGMACRO, "Position of Query line is : " + QString::number(queryPos)); {
if (answerFound < queryPos) 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, "Serching IP address");
info(DEBUGMACRO, "line is:\n" + line); queryPos = line.indexOf(";; Query");
responseList = line.split(QRegExp("\\s+")); info(DEBUGMACRO, "Position of Query line is : " + QString::number(queryPos));
info(DEBUGMACRO, "ip Address is => " + responseList.at(4)); if (answerFound < queryPos)
if(responseList.at(3) == "A")
{ {
return 4; line = line.mid(answerFound, queryPos - answerFound);
}else if(responseList.at(3) == "AAAA") info(DEBUGMACRO, "line is:\n" + line);
{ responseList = line.split(QRegExp("\\s+"));
return 6; 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 // slot activated when button connection is clicked
void MainWindow::on_connectButton_clicked() void MainWindow::on_connectButton_clicked()
{ {
QString server; QString server;
uint port; uint port;
//uint ipversion;
info(DEBUGMACRO, "on_connectButton_clicked() => Connexion button clicked"); info(DEBUGMACRO, "on_connectButton_clicked() => Connexion button clicked");
port = ui->portEdit->text().toUInt(); port = ui->portEdit->text().toUInt();
if (port > 0 and port < 65535) if (port > 0 and port < 65535)
{ {
server = ui->khistorycombobox->currentText(); server = ui->khistorycombobox->currentText();
//ipversion = validateServer(&server);
populateList(server, port); populateList(server, port);
}else }else
{ {
@ -1023,11 +1054,13 @@ void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, bool downloadD
QString str; QString str;
QMessageBox::StandardButton reply; QMessageBox::StandardButton reply;
int sizeFromRsync; int sizeFromRsync;
bool ret = false;
info(DEBUGMACRO, "on_treeWidget_itemClicked() => Slot activated when a file is clicked in the treeview"); info(DEBUGMACRO, "on_treeWidget_itemClicked() => Slot activated when a file is clicked in the treeview");
if (this->treeviewClicked == true) if (this->treeviewClicked == true)
{ {
info(DEBUGMACRO, "double click ignored");
return; return;
} }
@ -1144,13 +1177,20 @@ void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, bool downloadD
if (item->isExpanded() == false) if (item->isExpanded() == false)
{ {
info(DEBUGMACRO, "Item is not expanded"); info(DEBUGMACRO, "Item is not expanded");
while (this->rescan) //if (this->rescan)
{ //{
info(DEBUGMACRO, "Re-scanning path: " + this->connexion.service + "/" + path +"/"); 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 +"/");
item->setExpanded(true); if(!ret)
} {
item->setExpanded(true);
}
//}
}else
{
item->setExpanded(false);
} }
} }
if (config.autosaveCheckbox->checkState() == Qt::Checked) if (config.autosaveCheckbox->checkState() == Qt::Checked)
@ -1606,3 +1646,69 @@ void MainWindow::on_actionHiddenService_triggered()
preparePopulateTree(); 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;
}
}

View File

@ -51,42 +51,45 @@ extern QMap<int, QString> rsyncErrorStrings;
class Connexion class Connexion
{ {
public: public:
int bandwidthLimit = 0; int bandwidthLimit = 0;
int bandwidthLimitUnit; int bandwidthLimitUnit;
int contimeout = 20; int contimeout = 20;
QString server; QString server;
QString service; QString service;
QString path; QString path;
QString savePath; QString savePath;
QString user; QString user;
QString password; QString password;
QProcess * process = nullptr; QProcess * process = nullptr;
int ipversion = 4; int ipversion = 4;
uint port = 873; uint port = 873;
bool quit = false; bool quit = false;
void clear(); void clear();
bool paused = false;
}; };
class Downloading class Downloading
{ {
public: public:
QString server; QString server;
QString service; QString service;
QString path; QString path;
QString savePath; QString savePath;
QString user; QString user;
QString password; QString password;
int ipversion = 4; int ipversion = 4;
int port = 873; int port = 873;
QProcess * process = nullptr; QProcess * process = nullptr;
bool quit = false; bool quit = false;
void clear(); bool paused = false;
void clear();
}; };
class About class About
{ {
public: public:
QString version; QString version;
QString author = "Daniel TARTAVEL-JEANNOT"; QString author = "Daniel TARTAVEL-JEANNOT";
QString licence = "GPL_V3"; QString licence = "GPL_V3";
@ -99,7 +102,7 @@ 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();
@ -117,27 +120,27 @@ class MainWindow : public QMainWindow
QSystemTrayIcon * trayIcon; QSystemTrayIcon * trayIcon;
QString icon = "/usr/share/icons/RsyncUI.png"; QString icon = "/usr/share/icons/RsyncUI.png";
bool rescan = false; bool rescan = false;
bool stopDlAsked; bool stopDlAsked = false;
bool treeviewClicked; bool treeviewClicked = false;
bool initialization = true; bool initialization = true;
bool exiting = false; bool exiting = false;
QList<QString> UnitText QList<QString> UnitText
{ {
tr("B"), tr("B"),
tr("KB"), tr("KB"),
tr("MB"), tr("MB"),
tr("GB"), tr("GB"),
tr("TB"), tr("TB"),
tr("PB") tr("PB")
}; };
QList<QChar> bwUnitChar QList<QChar> bwUnitChar
{ {
'K', 'K',
'M', 'M',
'T', 'T',
'G', 'G',
'P' 'P'
}; };
QVector<QString> downloadProcessErrorString = QVector<QString> downloadProcessErrorString =
@ -154,7 +157,7 @@ class MainWindow : public QMainWindow
void populateTree(); void populateTree();
void populateList(QString server, uint port); void populateList(QString server, uint port);
void listServices(); 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); 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 = "" ); bool scanDir(Connexion * connexion, QTreeWidgetItem *parent = NULL, QString path = "" );
void startDownloading(); void startDownloading();
@ -175,7 +178,7 @@ class MainWindow : public QMainWindow
void passwordStore (QString account, QString password); void passwordStore (QString account, QString password);
QString passwordGet (QString account); QString passwordGet (QString account);
private slots: private slots:
void on_listWidget_clicked(); void on_listWidget_clicked();
@ -219,7 +222,13 @@ class MainWindow : public QMainWindow
//void on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column); //void on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column);
signals: 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 stopDownloading(QProcess *);
void progressSignal(int); void progressSignal(int);
void speed(QString); void speed(QString);

View File

@ -407,6 +407,7 @@
<addaction name="actionAbout"/> <addaction name="actionAbout"/>
<addaction name="actionAbout_Qt"/> <addaction name="actionAbout_Qt"/>
<addaction name="actionExit"/> <addaction name="actionExit"/>
<addaction name="actionPause_downloads"/>
</widget> </widget>
<action name="DefaultSaveFolder"> <action name="DefaultSaveFolder">
<property name="icon"> <property name="icon">
@ -479,6 +480,20 @@
<string>hidden service</string> <string>hidden service</string>
</property> </property>
</action> </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> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -1,6 +1,8 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "tools.h" #include "tools.h"
#include "password.h" #include "password.h"
#include <QTextStream>
#include <QHostAddress>
using namespace std; using namespace std;
@ -53,15 +55,31 @@ QString getFileType(QString filename)
return returnValue; return returnValue;
} }
QString preparePath(QString path)
{
return path.trimmed().replace(' ', "\ ");
}
int whatIpVersion(QString ipAddress) int whatIpVersion(QString ipAddress)
{ {
QStringList fieldList; QStringList fieldList;
ulong field; // ulong field;
uint i; // uint i;
uint ipversion;
QHostAddress serverAddress;
info(DEBUGMACRO, "ipVersion of server at " + ipAddress); 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) if (fieldList.count() == 8)
{ {
for (i=0;i<8;i++) for (i=0;i<8;i++)
@ -88,8 +106,41 @@ int whatIpVersion(QString ipAddress)
} }
info(DEBUGMACRO, "Address is ip V4"); info(DEBUGMACRO, "Address is ip V4");
return 4; return 4;
}*/
}
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 0; return serverAddress;
} }
void warning(QString message) void warning(QString message)

View File

@ -3,6 +3,10 @@
#define DEBUGMACRO QString(__FILE__) + "->" + QString(Q_FUNC_INFO) + ": " + QString::number(__LINE__) + " -" #define DEBUGMACRO QString(__FILE__) + "->" + QString(Q_FUNC_INFO) + ": " + QString::number(__LINE__) + " -"
#define IPV4 0
#define IPV6 1
#include <QHostAddress>
#include <string> #include <string>
#include <vector> #include <vector>
#include <array> #include <array>
@ -22,5 +26,7 @@ int whatIpVersion(QString server);
void warning(QString message); void warning(QString message);
void error(QString message); void error(QString message);
void info(QString debugHeader, QString message); void info(QString debugHeader, QString message);
QString preparePath(QString path);
QHostAddress searchHosts(QString server);
#endif // TOOLS_H #endif // TOOLS_H

View File

@ -3,6 +3,6 @@
#include <QString> #include <QString>
QString version = "2.12.6"; QString version = "2.13.2";
#endif // VERSION_H #endif // VERSION_H