Browse Source

adjusted gui to work with the new protocol + fixed typos

Cyamond 4 years ago
parent
commit
0530563f17
2 changed files with 45 additions and 15 deletions
  1. 2 2
      GUI-CLI Protocol.md
  2. 43 13
      gui/src/qmlhandler.cpp

+ 2 - 2
GUI-CLI Protocol.md

@@ -1,4 +1,4 @@
-# Client-Server Protocol
+# GUI-CLI Protocol
 
 Protocol version: <b>"0.2"</b>
 
@@ -178,7 +178,7 @@ If `accept` is `true` the connection is valid and the server can start sending t
 CLI:
 ```
 {
-	"command": "putdata",
+	"command": "getdata",
 	"file": string,
 	"speed": float,
 	"cancel": bool,

+ 43 - 13
gui/src/qmlhandler.cpp

@@ -48,26 +48,30 @@ void QMLHandler::handleJSON(string buffer) {
   const Json::Value command = root["command"];
   string cmd = command.asString();
 
-  if (cmd == "status") {
+  if (cmd.compare("status")) {
     emit footerSetStatus(root["response"].asString().c_str());
   }
 
-  else if (cmd == "close") {
+  else if (cmd.compare("close")) {
     programActive = false;
   }
 
-  else if (cmd == "list") {
-    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 == "connect") {
+  else if (cmd.compare("connect")) {
     if (root["accept"] == false) {
       emit ipPopupSetStatus(root["error"].asString().c_str());
       close(outpipefd[1]);
@@ -75,7 +79,7 @@ void QMLHandler::handleJSON(string buffer) {
     }
   }
 
-  else if (cmd == "version") {
+  else if (cmd.compare("version")) {
     if (root["accept"] == true) {
       write(outpipefd[1], _USERNAME.toUtf8().constData(),
             strlen(_USERNAME.toUtf8().constData()));
@@ -91,7 +95,7 @@ void QMLHandler::handleJSON(string buffer) {
     }
   }
 
-  else if (cmd == "login") {
+  else if (cmd.compare("login")) {
     if (root["accept"] == true) {
       emit ipPopupClose();
     } else {
@@ -100,6 +104,32 @@ void QMLHandler::handleJSON(string buffer) {
       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
+  }
 }
 
 void QMLHandler::readPipeLoop() {