Browse Source

US26.3: Delete command (GUI)

Wach, Tobias Alexander 4 years ago
parent
commit
39387be497

+ 3 - 3
GUI-CLI Protocol.md

@@ -187,9 +187,9 @@ CLI:
 If `cancel` is `true` then the download of the file is canceled and an error message should be in `error`.
 `speed` shall contain a float describing the download speed in kB/s.
 
-
 ### 2.5 Deletefile command
-`deletefile` to request the deletion of a file on the server.
+
+Requests the deletion of a file from the server.
 
 #### 2.5.1  - request file list download
 GUI:
@@ -205,7 +205,7 @@ CLI:
 	"error": string
 }
 ```
-
+If `accept` is `true` the command is valid and the server has deleted the file. Else the request was rejected no changes have been made. `error` should contain an error string in that case.
 
 
 ### TODO

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

@@ -11,6 +11,7 @@ Popup {
     modal: true
     focus: true
     closePolicy: Popup.NoAutoClose
+    anchors.centerIn: Overlay.overlay
 
     Connections {
         target: _qmlHandler

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

@@ -11,6 +11,7 @@ Popup {
     modal: true
     focus: true
     closePolicy: Popup.NoAutoClose
+    anchors.centerIn: Overlay.overlay
 
     Connections {
         target: _qmlHandler

+ 14 - 4
gui/src/ReceivingFileTemplate.ui.qml

@@ -13,9 +13,13 @@ Item {
     Connections {
         target: _qmlHandler
         onReceivingDisableDownloadButton: {
-          if (fileNameText == fileName) {
-            fileExists = true
-          }
+            if (fileNameText == fileName) {
+                fileExists = true
+            }
+        }
+
+        onReceivingCloseConfirmDeletePopup: {
+            confirmDeletePopup.close()
         }
     }
 
@@ -60,7 +64,7 @@ Item {
             Layout.alignment: Qt.AlignCenter
             Layout.preferredHeight: parent.height
             Layout.preferredWidth: 200
-            enabled: !fileExists;
+            enabled: !fileExists
             text: fileExists ? qsTr("Already Downloaded") : qsTr("Download")
 
             onClicked: _qmlHandler.onReceivingDownloadFileButton(fileNameText)
@@ -72,6 +76,12 @@ Item {
             Layout.preferredHeight: parent.height
             Layout.preferredWidth: 200
             text: qsTr("Delete from server")
+
+            onClicked: confirmDeletePopup.open()
         }
     }
+
+    ReceivingFileTemplateDeletePopup {
+        id: confirmDeletePopup
+    }
 }

+ 56 - 0
gui/src/ReceivingFileTemplateDeletePopup.ui.qml

@@ -0,0 +1,56 @@
+import QtQuick 2.4
+import QtQuick.Controls 2.3
+import QtQuick.Layouts 1.3
+
+Popup {
+    id: confirmDeletePopup
+    height: 150
+    dim: true
+    clip: false
+    width: 400
+    modal: true
+    focus: true
+    closePolicy: Popup.NoAutoClose
+    anchors.centerIn: Overlay.overlay
+
+    ColumnLayout {
+        anchors.fill: parent
+
+        Text {
+            id: confirmDeletePopupConfirmationText
+            Layout.alignment: Qt.AlignCenter
+            Layout.preferredHeight: 80
+            Layout.preferredWidth: parent.width
+            text: "Are you sure you want to delete this file from the Server?"
+            verticalAlignment: Text.AlignTop
+            horizontalAlignment: Text.AlignHCenter
+            wrapMode: Text.WordWrap
+            font.pointSize: 15
+            color: "#ffffff"
+        }
+        RowLayout {
+            Layout.preferredHeight: 80
+            Layout.preferredWidth: parent.width
+            Button {
+                id: confirmDeleteButton
+                Layout.alignment: Qt.AlignCenter
+                Layout.preferredWidth: 100
+                text: qsTr("Delete")
+                // @disable-check M223
+                onClicked: {
+                    // @disable-check M222
+                    _qmlHandler.onReceivingConfirmDeleteFileButton(fileNameText)
+                }
+            }
+
+            Button {
+                id: cancelDeleteButton
+                Layout.alignment: Qt.AlignCenter
+                Layout.preferredWidth: 100
+                text: qsTr("Cancel")
+                // @disable-check M222
+                onClicked: confirmDeletePopup.close()
+            }
+        }
+    }
+}

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

@@ -5,6 +5,7 @@ import QtQuick.Layouts 1.3
 Page {
     width: 1280
     height: 470
+    id: receivingForm
 
     font.capitalization: Font.MixedCase
 

+ 1 - 4
gui/src/main.qml

@@ -8,6 +8,7 @@ ApplicationWindow {
     height: 720
     maximumHeight: height
     maximumWidth: width
+    font.capitalization: Font.MixedCase
 
     minimumHeight: height
     minimumWidth: width
@@ -71,14 +72,10 @@ ApplicationWindow {
 
     LoginSignupPopup {
         id: loginSignupPopup
-        x: Math.round((parent.width - width) / 2)
-        y: Math.round((parent.height - height) / 2)
     }
 
     IpPopup {
         id: ipPopup
-        x: Math.round((parent.width - width) / 2)
-        y: Math.round((parent.height - height) / 2)
         onClosed: loginSignupPopup.open()
     }
 

+ 1 - 0
gui/src/qml.qrc

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

+ 16 - 0
gui/src/qmlhandler.cpp

@@ -206,6 +206,17 @@ void QMLHandler::handleJSON(string buffer) {
 			emit closeWindow();
 		}
 	}
+
+	else if (!cmd.compare("deletefile")) {
+		emit receivingCloseConfirmDeletePopup();
+		if (root["accept"] == false) {
+			QString errorMessage = QString::fromStdString(string("Error when deleting file " + root["file"].asString() + ":\n" + root["error"].asString()));
+			emit log(errorMessage);
+		} else {
+			QString message = QString::fromStdString(string("Deleted file " + root["file"].asString() + " from the server!"));
+			emit log(message);
+		}
+	}
 }
 
 // This method is a loop which runs in a seperate thread.
@@ -291,6 +302,11 @@ void QMLHandler::onReceivingDownloadFileButton(QString fileName) {
 	write(outpipefd[1], command.toUtf8().constData(), strlen(command.toUtf8().constData()));
 }
 
+void QMLHandler::onReceivingConfirmDeleteFileButton(QString fileName) {
+	QString command = "deletefile " + 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

@@ -32,6 +32,7 @@ signals:
   void receivingClearFileList();
   void receivingListFile(QString fileName, bool existsLocally);
   void receivingDisableDownloadButton(QString fileName);
+  void receivingCloseConfirmDeletePopup();
 
   // Messages
   void message(QString msg);
@@ -75,6 +76,7 @@ public slots:
   // Receiving
   void onReceivingListFilesButton();
   void onReceivingDownloadFileButton(QString fileName);
+  void onReceivingConfirmDeleteFileButton(QString fileName);
 
   // Messages
   void onMessagesSendButton(QString msg);