Cyamond 5 роки тому
батько
коміт
6275334011
2 змінених файлів з 18 додано та 1 видалено
  1. 8 0
      gui/src/main.cpp
  2. 10 1
      gui/src/qmlhandler.cpp

+ 8 - 0
gui/src/main.cpp

@@ -29,14 +29,22 @@ int main(int argc, char *argv[]) {
 
   QMLHandler qmlHandler;
 
+  // Set the context for the window, so that the qml files can be connected to
+  // the qmlHandler
   engine.rootContext()->setContextProperty("_qmlHandler", &qmlHandler);
 
+  // Load the main window
   QQmlComponent component(&engine, QUrl(QStringLiteral("qrc:/main.qml")));
 
   QObject *object = component.create();
 
+  // Run the main window and save the return of the application in an integer
+  // ret This is blocking, which means it will block the main program until the
+  // window is closed
   int ret = app.exec();
 
+  // If we land here, the window has been closed. Properly disconnect from the
+  // server now
   qmlHandler.onExit();
 
   return ret;

+ 10 - 1
gui/src/qmlhandler.cpp

@@ -31,18 +31,24 @@ void QMLHandler::onExit() {
   write(outpipefd[1], "disconnect\n", strlen("disconnect\n"));
 }
 
+// This method gets a string and tries to read it as Json
+// If it fails to do so, return and do nothing, else handle the content
 void QMLHandler::handleJSON(string buffer) {
   Json::Value root;
   Json::CharReaderBuilder builder;
   Json::CharReader *reader = builder.newCharReader();
   string jsonError;
 
+  // Try to parse the string as Json and store the result of the pasring in a
+  // boolean
   bool parsingSuccessful = reader->parse(
       buffer.c_str(), buffer.c_str() + buffer.size(), &root, &jsonError);
 
+  // If the string is not correct Json, return
   if (!parsingSuccessful) {
     return;
   }
+
   const Json::Value command = root["command"];
   string cmd = command.asString();
 
@@ -56,7 +62,6 @@ void QMLHandler::handleJSON(string buffer) {
 
   else if (cmd == "list") {
     emit receivingClearFileList();
-
     // Get the array of file Names
     auto fileNames = root["names"];
     for (int i = 0; i < fileNames.size(); i++) {
@@ -66,6 +71,10 @@ void QMLHandler::handleJSON(string buffer) {
   }
 }
 
+// This method is a loop which runs in a seperate thread.
+// If will read the Input Pipe, which containts the string that get printed
+// on stdout by the CLI/Server, and calls handleJSON with the read content
+// one it reads a newline.
 void QMLHandler::readPipeLoop() {
   unsigned int readOffset = 0;
   unsigned int pollCount = 0;