|
@@ -22,6 +22,8 @@ int inpipefd[2];
|
|
|
int outpipefd[2];
|
|
|
char buf[1025];
|
|
|
QUrl sendFileUrl = QUrl("");
|
|
|
+QString _USERNAME;
|
|
|
+QString _PASSWORD;
|
|
|
|
|
|
bool programActive = true;
|
|
|
|
|
@@ -60,20 +62,79 @@ void QMLHandler::handleJSON(string buffer) {
|
|
|
programActive = false;
|
|
|
}
|
|
|
|
|
|
- else if (cmd.compare("listdata")) {
|
|
|
- emit receivingClearFileList();
|
|
|
- // Get the array of file Names
|
|
|
- auto fileNames = root["names"];
|
|
|
- for (int i = 0; i < fileNames.size(); i++) {
|
|
|
- emit receivingListFile(
|
|
|
- QString::fromStdString(fileNames[i].asString().c_str()));
|
|
|
+ else if (cmd.compare("list")) {
|
|
|
+ if (root["accept"] == true) {
|
|
|
+ emit receivingClearFileList();
|
|
|
+
|
|
|
+ // Get the array of file Names
|
|
|
+ auto fileNames = root["names"];
|
|
|
+ for (int i = 0; i < fileNames.size(); i++) {
|
|
|
+ emit receivingListFile(
|
|
|
+ QString::fromStdString(fileNames[i].asString().c_str()));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ emit log(root["error"].asString().c_str());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (cmd.compare("connect")) {
|
|
|
+ if (root["accept"] == false) {
|
|
|
+ emit ipPopupSetStatus(root["error"].asString().c_str());
|
|
|
+ close(outpipefd[1]);
|
|
|
+ close(inpipefd[0]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
else if (cmd.compare("version")) {
|
|
|
- // TODO: Change hardcoded login details to input values
|
|
|
- write(outpipefd[1], "user\n", strlen("user\n"));
|
|
|
- write(outpipefd[1], "pass\n", strlen("pass\n"));
|
|
|
+ if (root["accept"] == true) {
|
|
|
+ write(outpipefd[1], _USERNAME.toUtf8().constData(),
|
|
|
+ strlen(_USERNAME.toUtf8().constData()));
|
|
|
+ write(outpipefd[1], _PASSWORD.toUtf8().constData(),
|
|
|
+ strlen(_PASSWORD.toUtf8().constData()));
|
|
|
+ } else {
|
|
|
+ QString errorMessage = QString::fromStdString(string(
|
|
|
+ "Version mismatch: \nClient: " + root["clientversion"].asString() +
|
|
|
+ "\nServer: " + root["serverversion"].asString()));
|
|
|
+ emit ipPopupSetStatus(errorMessage);
|
|
|
+ close(outpipefd[1]);
|
|
|
+ close(inpipefd[0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (cmd.compare("login")) {
|
|
|
+ if (root["accept"] == true) {
|
|
|
+ emit ipPopupClose();
|
|
|
+ } else {
|
|
|
+ emit ipPopupSetStatus(root["error"].asString().c_str());
|
|
|
+ close(outpipefd[1]);
|
|
|
+ close(inpipefd[0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (cmd.compare("put")) {
|
|
|
+ if (root["accept"] == false) {
|
|
|
+ QString errorMessage = QString::fromStdString(
|
|
|
+ string("Error when uploading file " + root["file"].asString() +
|
|
|
+ ":\n" + root["error"].asString()));
|
|
|
+ emit log(errorMessage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (cmd.compare("putdata")) {
|
|
|
+ // TODO: Show speed and handle Error
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (cmd.compare("get")) {
|
|
|
+ if (root["accept"] == false) {
|
|
|
+ QString errorMessage = QString::fromStdString(
|
|
|
+ string("Error when downloading file " + root["file"].asString() +
|
|
|
+ ":\n" + root["error"].asString()));
|
|
|
+ emit log(errorMessage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (cmd.compare("getdata")) {
|
|
|
+ // TODO: Show speed and handle Error
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -172,7 +233,8 @@ void QMLHandler::onSettingsSwitchServerButton() {
|
|
|
}
|
|
|
|
|
|
// Ip Popup
|
|
|
-void QMLHandler::onIpPopupEnterIp(QString ip) {
|
|
|
+void QMLHandler::onIpPopupConnectButton(QString ip, QString username,
|
|
|
+ QString password) {
|
|
|
pid_t pid = 0;
|
|
|
|
|
|
pipe(inpipefd);
|
|
@@ -198,6 +260,9 @@ void QMLHandler::onIpPopupEnterIp(QString ip) {
|
|
|
// TODO: Not hardcoded
|
|
|
emit footerSetStatus("Connected to " + ip);
|
|
|
|
|
|
+ _USERNAME = username;
|
|
|
+ _PASSWORD = password;
|
|
|
+
|
|
|
close(outpipefd[0]);
|
|
|
close(inpipefd[1]);
|
|
|
|