Browse Source

added get and put support

Cyamond 5 năm trước cách đây
mục cha
commit
4bd3280ebb

+ 2 - 2
gui/src/FooterForm.ui.qml

@@ -34,7 +34,7 @@ Page {
                 Text {
                     id: footerStatusText
                     Layout.preferredHeight: parent.height
-                    Layout.preferredWidth: 1100
+                    Layout.preferredWidth: 1000
                     color: "#ffffff"
                     text: qsTr("")
                     font.pixelSize: 23
@@ -43,7 +43,7 @@ Page {
                 Button {
                     id: footerGetStatusButton
                     Layout.preferredHeight: 30
-                    Layout.preferredWidth: 180
+                    Layout.preferredWidth: 250
                     text: qsTr("Get Status")
                     // @disable-check M223
                     onClicked: {

+ 40 - 7
gui/src/ReceivingForm.ui.qml

@@ -1,16 +1,49 @@
 import QtQuick 2.12
 import QtQuick.Controls 2.5
+import QtQuick.Layouts 1.3
 
 Page {
     width: 1280
     height: 470
 
-    Text {
-        id: receivingPlaceholder
-        x: 154
-        y: 212
-        color: "#ffffff"
-        text: qsTr("This will be implemented with the actual functionality")
-        font.pixelSize: 40
+    font.capitalization: Font.MixedCase
+
+    ColumnLayout {
+        anchors.fill: parent
+
+        RowLayout {
+            Layout.preferredWidth: parent.width
+            Layout.preferredHeight: 70
+
+            TextField {
+                id: receivingFileNameField
+                selectByMouse: true
+                Layout.preferredWidth: 1060
+                Layout.preferredHeight: parent.height
+                placeholderText: "Enter File Name to download..."
+                text: qsTr("")
+                font.pixelSize: 20
+            }
+
+            Button {
+                id: receivingGetFileButton
+                Layout.preferredWidth: 180
+                Layout.preferredHeight: parent.height
+                text: qsTr("Download")
+
+                enabled: receivingFileNameField.text != ""
+
+                // @disable-check M223
+                onClicked: {
+                    // @disable-check M223
+                    if (receivingFileNameField.text != "") {
+                        // @disable-check M222
+                        _qmlHandler.onReceivingGetFileButton(
+                                    receivingFileNameField.text)
+                        receivingFileNameField.text = ""
+                    }
+                }
+            }
+        }
     }
 }

+ 4 - 0
gui/src/SendingForm.ui.qml

@@ -14,6 +14,9 @@ Page {
         onSendingSetFileUrlText: {
             sendingSelectedFileText.text = signalText
         }
+        onSendingEnableSendButton: {
+            sendingSendFileButton.enabled = true
+        }
     }
 
     Button {
@@ -69,6 +72,7 @@ Page {
         id: sendingSendFileButton
         x: 510
         y: 304
+        enabled: false
         width: 260
         height: 90
         text: qsTr("Send File")

+ 13 - 3
gui/src/qmlhandler.cpp

@@ -21,6 +21,7 @@ using namespace std;
 int inpipefd[2];
 int outpipefd[2];
 char buf[1024];
+QUrl sendFileUrl = QUrl("");
 
 bool programActive = true;
 
@@ -90,13 +91,22 @@ QMLHandler::QMLHandler(QObject *parent) : QObject(parent) {}
 
 // Sending
 void QMLHandler::onSendingSelectFileButton(QUrl url) {
-  emit log("File Selected: " + url.toString());
-  emit sendingSetFileUrlText("Selected File: " + url.toString());
+  sendFileUrl = url.toLocalFile();
+  emit log("File Selected: " + sendFileUrl.toString());
+  emit sendingSetFileUrlText("Selected File: " + sendFileUrl.toString());
+  emit sendingEnableSendButton();
 }
 
-void QMLHandler::onSendingSendFileButton() { emit log("Sending File !"); }
+void QMLHandler::onSendingSendFileButton() {
+  QString command = "put " + sendFileUrl.toString() + "\n";
+  write(outpipefd[1], command.toUtf8().constData(), strlen(command.toUtf8().constData()));
+}
 
 // Receiving
+void QMLHandler::onReceivingGetFileButton(QString fileName) {
+    QString command = "get " + fileName + "\n";
+    write(outpipefd[1], command.toUtf8().constData(), strlen(command.toUtf8().constData()));
+}
 
 // Messages
 void QMLHandler::onMessagesSendButton(QString msg) { emit message(msg); }

+ 2 - 0
gui/src/qmlhandler.h

@@ -21,6 +21,7 @@ public:
 signals:
   // Sending
   void sendingSetFileUrlText(QString signalText);
+  void sendingEnableSendButton();
 
   // Receiving
 
@@ -44,6 +45,7 @@ public slots:
   void onSendingSendFileButton();
 
   // Receiving
+  void onReceivingGetFileButton(QString fileName);
 
   // Messages
   void onMessagesSendButton(QString msg);