瀏覽代碼

Implemented simple List Files on GUI

Cyamond 5 年之前
父節點
當前提交
2fd8cc768e
共有 5 個文件被更改,包括 67 次插入3 次删除
  1. 1 0
      gui/src/FooterForm.ui.qml
  2. 1 0
      gui/src/MessagesForm.ui.qml
  3. 45 1
      gui/src/ReceivingForm.ui.qml
  4. 17 2
      gui/src/qmlhandler.cpp
  5. 3 0
      gui/src/qmlhandler.h

+ 1 - 0
gui/src/FooterForm.ui.qml

@@ -63,6 +63,7 @@ Page {
                 TextArea.flickable: TextArea {
                     selectByMouse: true
                     id: footerLog
+                    readOnly: true
                     wrapMode: TextArea.Wrap
                     text: qsTr("")
                     font.pointSize: 15

+ 1 - 0
gui/src/MessagesForm.ui.qml

@@ -27,6 +27,7 @@ Page {
 
             TextArea.flickable: TextArea {
                 id: messagesLog
+                readOnly: true
                 selectByMouse: true
                 wrapMode: TextArea.Wrap
                 font.pointSize: 15

+ 45 - 1
gui/src/ReceivingForm.ui.qml

@@ -8,9 +8,40 @@ Page {
 
     font.capitalization: Font.MixedCase
 
+    Connections {
+        target: _qmlHandler
+        onReceivingListFile: {
+            receivingFileList.append(fileName)
+            receivingFlickable.contentY = receivingFileList.height - receivingFlickable.height
+        }
+
+        onReceivingClearFileList: {
+            receivingFileList.text = ""
+        }
+    }
+
     ColumnLayout {
         anchors.fill: parent
 
+        Flickable {
+            id: receivingFlickable
+            flickableDirection: Flickable.VerticalFlick
+            Layout.preferredHeight: 400
+            Layout.preferredWidth: parent.width
+
+            TextArea.flickable: TextArea {
+                selectByMouse: true
+                readOnly: true
+                id: receivingFileList
+                wrapMode: TextArea.Wrap
+                text: qsTr("")
+                font.pointSize: 15
+            }
+
+            ScrollBar.vertical: ScrollBar {
+            }
+        }
+
         RowLayout {
             Layout.preferredWidth: parent.width
             Layout.preferredHeight: 70
@@ -18,13 +49,26 @@ Page {
             TextField {
                 id: receivingFileNameField
                 selectByMouse: true
-                Layout.preferredWidth: 1060
+                Layout.preferredWidth: 880
                 Layout.preferredHeight: parent.height
                 placeholderText: "Enter File Name to download..."
                 text: qsTr("")
                 font.pixelSize: 20
             }
 
+            Button {
+                id: receivingListFilesButton
+                Layout.preferredWidth: 180
+                Layout.preferredHeight: parent.height
+                text: qsTr("List Files")
+
+                // @disable-check M223
+                onClicked: {
+                    // @disable-check M223
+                    _qmlHandler.onReceivingListFilesButton()
+                }
+            }
+
             Button {
                 id: receivingGetFileButton
                 Layout.preferredWidth: 180

+ 17 - 2
gui/src/qmlhandler.cpp

@@ -20,7 +20,7 @@ using namespace std;
 
 int inpipefd[2];
 int outpipefd[2];
-char buf[1024];
+char buf[1025];
 QUrl sendFileUrl = QUrl("");
 
 bool programActive = true;
@@ -53,6 +53,17 @@ void QMLHandler::handleJSON(string buffer) {
   else if (cmd == "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()));
+    }
+  }
 }
 
 void QMLHandler::readPipeLoop() {
@@ -75,7 +86,7 @@ void QMLHandler::readPipeLoop() {
     }
 
     if (pollCount > 9 && buf[0]) {
-      buf[1023] = 0;
+      buf[1024] = 0;
       buf[strlen(buf)] = 0;
 
       string cleanBuffer = buf + strcspn(buf, "\n") + 1;
@@ -115,6 +126,10 @@ void QMLHandler::onSendingClearSelectionButton() {
 }
 
 // Receiving
+void QMLHandler::onReceivingListFilesButton() {
+  write(outpipefd[1], "list\n", strlen("list\n"));
+}
+
 void QMLHandler::onReceivingGetFileButton(QString fileName) {
   QString command = "get " + fileName + "\n";
   write(outpipefd[1], command.toUtf8().constData(),

+ 3 - 0
gui/src/qmlhandler.h

@@ -27,6 +27,8 @@ signals:
   void sendingDisableSendButton();
 
   // Receiving
+  void receivingClearFileList();
+  void receivingListFile(QString fileName);
 
   // Messages
   void message(QString msg);
@@ -51,6 +53,7 @@ public slots:
   void onSendingClearSelectionButton();
 
   // Receiving
+  void onReceivingListFilesButton();
   void onReceivingGetFileButton(QString fileName);
 
   // Messages