rsyncui/tools.cpp

81 lines
1.8 KiB
C++
Raw 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;
//Take a string and explode it in array
// s => string to explode
// c => character separator
// n => number of results in array, the last is the rest of string to end
2023-01-07 12:44:45 +01:00
const vector<string> explode(const string& s, const char& c, int n = 0)
{
string buff;
vector<string> v;
size_t pos = 0;
size_t ppos = 0;
int i = 0;
while (i < n - 1)
{
pos = s.find(c, ppos);
if (pos != string::npos)
{
buff = s.substr(ppos, pos - ppos);
if (buff != "")
{
i++;
v.push_back(s.substr(ppos, pos - ppos));
}
ppos = pos + 1;
}else
{
break;
}
}
if (ppos < s.size())
{
v.push_back(s.substr(ppos));
}
return v;
}
// test return code of rsync
bool testRsyncReturn(MainWindow * w, QProcess * myProcess)
2023-01-07 12:44:45 +01:00
{
2023-02-10 21:32:20 +01:00
if (myProcess->exitStatus() != 0)
2023-01-07 12:44:45 +01:00
{
2023-01-18 23:12:21 +01:00
QMessageBox::warning(
2023-02-10 21:32:20 +01:00
NULL,
"RsyncUI",
myProcess->errorString(),
QMessageBox::Ok,
QMessageBox::Ok);
return true;
}else if (myProcess->exitCode() == 5)
{
w->loginDialog.show();
2023-02-10 21:32:20 +01:00
}else if (myProcess->exitCode() != 0)
2023-01-07 12:44:45 +01:00
{
2023-02-10 21:32:20 +01:00
QMessageBox::warning(
NULL,
"RsyncUI",
rsyncErrorStrings[myProcess->exitCode()],
QMessageBox::Ok,
QMessageBox::Ok);
return true;
2023-01-07 12:44:45 +01:00
}
2023-02-10 21:32:20 +01:00
return false;
2023-01-07 12:44:45 +01:00
}
2023-03-04 19:12:13 +01:00
QString getFileType(QString filename)
{
QMimeDatabase db;
QMimeType mime = db.mimeTypeForFile(filename);
QString returnValue = mime.name().section('/',1 ,1);
return returnValue;
}