rsyncui/tools.cpp

77 lines
1.4 KiB
C++
Raw Permalink Normal View History

#include "mainwindow.h"
2023-01-07 12:44:45 +01:00
using namespace std;
#define READ 0
#define WRITE 1
2023-02-10 21:32:20 +01:00
extern QMap<int, QString> rsyncErrorStrings;
2023-03-09 18:13:46 +01:00
extern QApplication a;
2023-02-10 21:32:20 +01:00
// test return code of rsync
2023-03-08 16:03:24 +01:00
// return true in case of error
bool testRsyncReturn(MainWindow * w, QProcess * myProcess)
2023-01-07 12:44:45 +01:00
{
2024-08-03 15:22:35 +02:00
if (myProcess->exitStatus() != 0 and w->stopDlAsked != true)
{
qInfo("rsync error %i : %s ", + myProcess->error(), myProcess->errorString().toStdString().c_str());
QMessageBox::warning(
w,
a.applicationName(),
rsyncErrorStrings[myProcess->error()],
//myProcess->errorString(),
QMessageBox::Ok,
QMessageBox::Ok);
return true;
}
w->stopDlAsked = false;
return false;
2023-01-07 12:44:45 +01:00
}
2023-03-04 19:12:13 +01:00
QString getFileType(QString filename)
{
2024-08-03 15:22:35 +02:00
QMimeDatabase db;
QMimeType mime = db.mimeTypeForFile(filename);
QString returnValue = mime.name().section('/',0 ,0);
return returnValue;
2023-03-04 19:12:13 +01:00
}
2023-03-08 16:03:24 +01:00
2024-08-03 15:22:35 +02:00
int whatIpVersion(QString ipAddress)
{
QStringList fieldList;
ulong field;
uint i;
qInfo("ipVersion %s", ipAddress.toStdString().c_str());
fieldList = ipAddress.split(":");
if (fieldList.count() == 8)
{
for (i=0;i<8;i++)
{
field = fieldList[i].toUInt();
if (field > 65535)
{
return 0;
}
}
qInfo("Address is Ip V6");
return 6;
}
fieldList = ipAddress.split(".");
if(fieldList.count() == 4)
{
for (i=0;i<4;i++)
{
field = fieldList[i].toUInt();
if (field > 255)
{
return 0;
}
}
qInfo("Address is ip V4");
return 4;
}
return 0;
}