sauvegarde

This commit is contained in:
Daniel Tartavel 2025-03-21 13:44:27 +01:00
parent 00e428c5b6
commit a235d2f745
5 changed files with 60 additions and 13 deletions

View File

@ -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();
}

View File

@ -9,6 +9,7 @@
#include <kcombobox.h>
#include <signal.h>
#include <QTextStream>
#include <QHostInfo>
using namespace std;
@ -348,9 +349,9 @@ void MainWindow::populateList(QString server, uint port)
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))
{
@ -763,30 +764,41 @@ bool MainWindow::scanDir(Connexion * connexion, QTreeWidgetItem *parent, QString
}
// 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);
ipversion = whatIpVersion(*server);
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, "Digging server name");
cmd = "dig";
param << server.trimmed() ;
param << server->trimmed() ;
param << "A"; // IP V4 query
param << server.trimmed() ;
param << server->trimmed() ;
param << "AAAA"; // IP V6 query
info(DEBUGMACRO, cmd + " " + param.join(" "));
@ -807,7 +819,7 @@ uint MainWindow::validateServer(QString server)
break;
}else
{
answerFound = line.indexOf(";; ANSWER SECTION:") +19;
answerFound = line.indexOf(";; ANSWER SECTION:") + 19;
info(DEBUGMACRO, "Position of answer line is : " + QString::number(answerFound));
if (answerFound != -1)
@ -837,10 +849,9 @@ uint MainWindow::validateServer(QString server)
}
info(DEBUGMACRO, "Returning ip version: " + QString::number(ipversion));
return ipversion;
return 0;
}
// slot activated when button connection is clicked
void MainWindow::on_connectButton_clicked()
{

View File

@ -157,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();

View File

@ -1,6 +1,8 @@
#include "mainwindow.h"
#include "tools.h"
#include "password.h"
#include <QTextStream>
#include <QHostAddress>
using namespace std;
@ -97,6 +99,36 @@ int whatIpVersion(QString ipAddress)
return 0;
}
QHostAddress searchHosts(QString server)
{
QString line = "";
QStringList hosts;
QFile fileHandle;
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(' ');
if (hosts.contains(server))
{
if (!serverAddress.isNull() and serverAddress.protocol() == QAbstractSocket::IPv4Protocol)
{
serverAddress.setAddress(hosts.first());
}
}
}
}
}
void warning(QString message)
{
QMessageBox::warning(

View File

@ -3,6 +3,7 @@
#define DEBUGMACRO QString(__FILE__) + "->" + QString(Q_FUNC_INFO) + ": " + QString::number(__LINE__) + " -"
#include <QHostAddress>
#include <string>
#include <vector>
#include <array>
@ -23,5 +24,6 @@ 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