Prechádzať zdrojové kódy

GUI DeleteMe Confirmation Popup

Wach, Tobias Alexander 4 rokov pred
rodič
commit
b9efe62ccd

+ 107 - 0
gui/src/DeleteMePopup.ui.qml

@@ -0,0 +1,107 @@
+import QtQuick 2.4
+import QtQuick.Controls 2.3
+import QtQuick.Layouts 1.3
+
+Popup {
+    id: popup
+    height: 300
+    dim: true
+    clip: false
+    width: 400
+    modal: true
+    focus: true
+    closePolicy: Popup.NoAutoClose
+    anchors.centerIn: Overlay.overlay
+
+    signal resetStatus
+
+    onClosed: {
+        resetStatus()
+    }
+
+    Connections {
+        target: _qmlHandler
+        onDeleteMePopupSetStatus: {
+            deleteMePopupStatusText.text = status
+        }
+    }
+
+    ColumnLayout {
+        anchors.fill: parent
+
+        Text {
+            Layout.alignment: Qt.AlignCenter
+            Layout.preferredWidth: parent.width
+            Layout.preferredHeight: 100
+            color: "#ffffff"
+            text: qsTr("Are you sure you want to delete your account on the server?\nThe application will restart.")
+            wrapMode: Text.WordWrap
+            horizontalAlignment: Text.AlignHCenter
+            verticalAlignment: Text.AlignVCenter
+            font.pixelSize: 20
+        }
+
+        Text {
+            id: deleteMePopupStatusText
+            Layout.alignment: Qt.AlignCenter
+            Layout.preferredWidth: parent.width
+            Layout.preferredHeight: 50
+            color: "#df3f3f"
+            text: ""
+            horizontalAlignment: Text.AlignHCenter
+            verticalAlignment: Text.AlignVCenter
+            font.pixelSize: 20
+            Connections {
+                target: popup
+                onResetStatus: deleteMePopupStatusText.text = ""
+            }
+        }
+
+        TextField {
+            id: deleteMePopupPasswordInput
+            Layout.alignment: Qt.AlignCenter
+            Layout.preferredWidth: 300
+            Layout.preferredHeight: 50
+            selectByMouse: true
+            echoMode: TextInput.Password
+            text: ""
+            horizontalAlignment: Text.AlignHCenter
+            placeholderText: "Enter password to confirm"
+        }
+
+        RowLayout {
+            spacing: 0
+            Layout.alignment: Qt.AlignCenter
+            Layout.preferredWidth: parent.width
+            Layout.preferredHeight: 50
+
+            Button {
+                Layout.alignment: Qt.AlignCenter
+                Layout.preferredHeight: parent.height
+                Layout.preferredWidth: 150
+                text: "Confirm"
+                enabled: !(deleteMePopupPasswordInput.text == "")
+                font.pointSize: 16
+                // @disable-check M223
+                onClicked: {
+                    // @disable-check M222
+                    _qmlHandler.onSettingsDeleteMeButton(
+                                deleteMePopupPasswordInput.text)
+                }
+            }
+
+            Button {
+                Layout.alignment: Qt.AlignCenter
+                Layout.preferredHeight: parent.height
+                Layout.preferredWidth: 150
+                text: "Cancel"
+                font.pointSize: 16
+                // @disable-check M223
+                onClicked: {
+                    // @disable-check M222
+                    popup.close()
+                }
+            }
+        }
+    }
+}

+ 5 - 1
gui/src/SettingsForm.ui.qml

@@ -163,7 +163,7 @@ Page {
                     // @disable-check M223
                     onClicked: {
                         // @disable-check M222
-                        _qmlHandler.onSettingsDeleteMeButton()
+                        deleteMePopup.open()
                     }
                 }
             }
@@ -237,4 +237,8 @@ Page {
             settingsCliPath.text = "CLI-Path:   " + path
         }
     }
+    
+    DeleteMePopup {
+        id: deleteMePopup
+    }
 }

+ 1 - 0
gui/src/qml.qrc

@@ -17,5 +17,6 @@
         <file>NoConfigFoundPopup.ui.qml</file>
         <file>InvalidCliPathPopup.ui.qml</file>
         <file>InvalidConfigPopup.ui.qml</file>
+        <file>DeleteMePopup.ui.qml</file>
     </qresource>
 </RCC>

+ 7 - 2
gui/src/qmlhandler.cpp

@@ -217,6 +217,9 @@ void QMLHandler::handleJSON(string buffer) {
 		if (root["accept"] == true) {
 			_RESTART = true;
 			emit closeWindow();
+		} else {
+			QString errorMessage = QString::fromStdString(root["error"].asString());
+			emit deleteMePopupSetStatus(errorMessage);
 		}
 	}
 
@@ -299,7 +302,6 @@ void QMLHandler::onStart() {
 				// Invalid CLI Path
 				emit invalidCliPathPopupOpen();
 			}
-
 			if (Config::getValue("Autofill-IP") == "1") {
 				emit ipPopupSetIP(QString::fromStdString(Config::getValue("Default-IP")));
 				emit ipPopupCheckSaveCheckbox();
@@ -378,7 +380,10 @@ void QMLHandler::onReceivingConfirmDeleteFileButton(QString fileName) {
 void QMLHandler::onMessagesSendButton(QString msg) { emit message(msg); }
 
 // Settings
-void QMLHandler::onSettingsDeleteMeButton() { write(outpipefd[1], "deleteme\n", strlen("deleteme\n")); }
+void QMLHandler::onSettingsDeleteMeButton(QString password) {
+	QString command = "deleteme " + password + "\n";
+	write(outpipefd[1], command.toUtf8().constData(), strlen(command.toUtf8().constData()));
+}
 
 void QMLHandler::onSettingsRevertChangesButton() {
 	loadSettingsToGUI();

+ 4 - 1
gui/src/qmlhandler.h

@@ -53,6 +53,9 @@ signals:
   // Settings
   void closeWindow();
   void loadSettings(int covertMethod, bool saveIP, bool saveUsername, QString cliPath);
+  
+  // Delete Me Popup
+  void deleteMePopupSetStatus(QString status);
 
   // Ip Popup
   void ipPopupSetStatus(QString status);
@@ -113,7 +116,7 @@ public slots:
   void onMessagesSendButton(QString msg);
 
   // Settings
-  void onSettingsDeleteMeButton();
+  void onSettingsDeleteMeButton(QString password);
   void onSettingsRevertChangesButton();
   void onSettingsResetButton();
   void onSettingsSaveButton(int covertMethod, bool saveIP, bool saveUsername, QString cliPath);