Parcourir la source

Merge branch 'us27-gui-file-listing' into 'develop'

US27: Make GUI file listing proper list

See merge request tobias.wach/ccats!43
Serdyukov, Denys il y a 4 ans
Parent
commit
d160819ef7

+ 1 - 1
gui/CMakeLists.txt

@@ -9,7 +9,7 @@ set(CMAKE_CXX_STANDARD 11)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 
 find_package(Threads)
-find_package(Boost 1.67 REQUIRED COMPONENTS system)
+find_package(Boost 1.67 REQUIRED COMPONENTS system filesystem)
 find_package(Qt5 COMPONENTS Core Quick REQUIRED)
 find_package(PkgConfig REQUIRED)
 pkg_check_modules(JSONCPP REQUIRED jsoncpp)

+ 77 - 0
gui/src/ReceivingFileTemplate.ui.qml

@@ -0,0 +1,77 @@
+import QtQuick 2.12
+import QtQuick.Controls 2.5
+import QtQuick.Layouts 1.3
+
+Item {
+    width: 1250
+    height: 50
+    property string fileNameText: "Name Placeholder"
+    property string fileSizeText: "Size Placeholder"
+    property string fileDecryptableText: "Decryptable Placeholder"
+    property bool fileExists: false
+
+    Connections {
+        target: _qmlHandler
+        onReceivingDisableDownloadButton: {
+          if (fileNameText == fileName) {
+            fileExists = true
+          }
+        }
+    }
+
+    RowLayout {
+        id: rowLayout
+        anchors.fill: parent
+
+        Text {
+            id: fileTemplateFileName
+            Layout.alignment: Qt.AlignCenter
+            Layout.preferredHeight: parent.height
+            Layout.preferredWidth: 400
+            verticalAlignment: Text.AlignVCenter
+            text: fileNameText
+            color: "#ffffff"
+        }
+
+        Text {
+            id: fileTemplateFileSize
+            Layout.alignment: Qt.AlignCenter
+            Layout.preferredHeight: parent.height
+            Layout.preferredWidth: 200
+            verticalAlignment: Text.AlignVCenter
+            horizontalAlignment: Text.AlignHCenter
+            text: fileSizeText
+            color: "#ffffff"
+        }
+
+        Text {
+            id: fileTemplateFileDecryptable
+            Layout.alignment: Qt.AlignCenter
+            Layout.preferredHeight: parent.height
+            Layout.preferredWidth: 200
+            verticalAlignment: Text.AlignVCenter
+            horizontalAlignment: Text.AlignHCenter
+            text: fileDecryptableText
+            color: "#ffffff"
+        }
+
+        Button {
+            id: fileTemplateDownloadButton
+            Layout.alignment: Qt.AlignCenter
+            Layout.preferredHeight: parent.height
+            Layout.preferredWidth: 200
+            enabled: !fileExists;
+            text: fileExists ? qsTr("Already Downloaded") : qsTr("Download")
+
+            onClicked: _qmlHandler.onReceivingDownloadFileButton(fileNameText)
+        }
+
+        Button {
+            id: fileTemplateDeleteButton
+            Layout.alignment: Qt.AlignCenter
+            Layout.preferredHeight: parent.height
+            Layout.preferredWidth: 200
+            text: qsTr("Delete from server")
+        }
+    }
+}

+ 22 - 47
gui/src/ReceivingForm.ui.qml

@@ -11,56 +11,51 @@ Page {
     Connections {
         target: _qmlHandler
         onReceivingListFile: {
-            receivingFileList.append(fileName)
-            receivingFlickable.contentY = receivingFileList.height - receivingFlickable.height
+            fileList.append({"fileName" : fileName,
+                           "fileSize" : "42 kb",
+                           "fileDecryptable" : "Decryptable?: Yes",
+                           "fileExistsLocally" : existsLocally})
         }
 
         onReceivingClearFileList: {
-            receivingFileList.text = ""
+            fileList.clear()
         }
     }
 
     ColumnLayout {
         anchors.fill: parent
 
-        Flickable {
-            id: receivingFlickable
-            flickableDirection: Flickable.VerticalFlick
-            Layout.preferredHeight: 400
+        ScrollView {
             Layout.preferredWidth: parent.width
+            Layout.preferredHeight: 400
 
-            TextArea.flickable: TextArea {
-                selectByMouse: true
-                readOnly: true
-                id: receivingFileList
-                wrapMode: TextArea.Wrap
-                text: qsTr("")
-                font.pointSize: 15
-            }
+            ListView {
+                anchors.fill: parent
+                model: fileList
+                clip: true
 
-            ScrollBar.vertical: ScrollBar {
+                delegate: ReceivingFileTemplate {
+                    fileNameText: fileName
+                    fileSizeText: fileSize
+                    fileDecryptableText: fileDecryptable
+                    fileExists: fileExistsLocally
+                }
             }
         }
 
+        ListModel {
+            id: fileList
+        }
+
         RowLayout {
             Layout.preferredWidth: parent.width
             Layout.preferredHeight: 70
 
-            TextField {
-                id: receivingFileNameField
-                selectByMouse: true
-                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")
+                text: qsTr("Refresh File List")
 
                 // @disable-check M223
                 onClicked: {
@@ -68,26 +63,6 @@ Page {
                     _qmlHandler.onReceivingListFilesButton()
                 }
             }
-
-            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 = ""
-                    }
-                }
-            }
         }
     }
 }

+ 1 - 0
gui/src/qml.qrc

@@ -12,5 +12,6 @@
         <file>IpPopup.ui.qml</file>
         <file>LoginForm.ui.qml</file>
         <file>SignupForm.ui.qml</file>
+        <file>ReceivingFileTemplate.ui.qml</file>
     </qresource>
 </RCC>

+ 9 - 2
gui/src/qmlhandler.cpp

@@ -7,12 +7,14 @@
 #include <poll.h>
 #include <string>
 #include <sys/prctl.h>
+#include <sys/stat.h>
 #include <sys/wait.h>
 #include <thread>
 #include <unistd.h>
 
 #include "qmlhandler.h"
 #include <boost/asio.hpp>
+#include <boost/filesystem.hpp>
 #include <iostream>
 #include <json/json.h>
 
@@ -122,7 +124,7 @@ void QMLHandler::handleJSON(string buffer) {
 			// 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()));
+				emit receivingListFile(QString::fromStdString(fileNames[i].asString().c_str()), boost::filesystem::exists(fileNames[i].asString()));
 			}
 		} else {
 			emit log(root["error"].asString().c_str());
@@ -154,6 +156,7 @@ void QMLHandler::handleJSON(string buffer) {
 	else if (!cmd.compare("login")) {
 		if (root["accept"] == true) {
 			emit loginSignupPopupClose();
+			write(outpipefd[1], "list\n", strlen("list\n"));
 		} else {
 			emit loginSetStatus(root["error"].asString().c_str());
 			reopenCLI(_IP);
@@ -186,6 +189,10 @@ void QMLHandler::handleJSON(string buffer) {
 		if (root["accept"] == false) {
 			QString errorMessage = QString::fromStdString(string("Error when downloading file " + root["file"].asString() + ":\n" + root["error"].asString()));
 			emit log(errorMessage);
+		} else {
+			string fileName = root["file"].asString();
+			// TODO: Only do this in getdata when remaining is 0 (when the file is fully downloaded) - maybe set text to "downloading.." in between
+			emit receivingDisableDownloadButton(QString::fromStdString(string(fileName)));
 		}
 	}
 
@@ -279,7 +286,7 @@ void QMLHandler::onSendingClearSelectionButton() {
 // Receiving
 void QMLHandler::onReceivingListFilesButton() { write(outpipefd[1], "list\n", strlen("list\n")); }
 
-void QMLHandler::onReceivingGetFileButton(QString fileName) {
+void QMLHandler::onReceivingDownloadFileButton(QString fileName) {
 	QString command = "get " + fileName + "\n";
 	write(outpipefd[1], command.toUtf8().constData(), strlen(command.toUtf8().constData()));
 }

+ 4 - 2
gui/src/qmlhandler.h

@@ -14,6 +14,7 @@ private:
   void readPipeLoop();
   void reopenCLI(QString ip);
   void closeCLI();
+  void fileExists(std::string name);
 
 public:
   explicit QMLHandler(QObject *parent = 0);
@@ -29,7 +30,8 @@ signals:
 
   // Receiving
   void receivingClearFileList();
-  void receivingListFile(QString fileName);
+  void receivingListFile(QString fileName, bool existsLocally);
+  void receivingDisableDownloadButton(QString fileName);
 
   // Messages
   void message(QString msg);
@@ -72,7 +74,7 @@ public slots:
 
   // Receiving
   void onReceivingListFilesButton();
-  void onReceivingGetFileButton(QString fileName);
+  void onReceivingDownloadFileButton(QString fileName);
 
   // Messages
   void onMessagesSendButton(QString msg);